clif.c 476 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125
  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. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  63. }
  64. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  65. p += pos;
  66. p[0] = (uint8)(x>>2);
  67. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  68. p[2] = (uint8)((y<<4) | (dir&0xf));
  69. }
  70. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  71. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  72. p += pos;
  73. p[0] = (uint8)(x0>>2);
  74. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  75. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  76. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  77. p[4] = (uint8)y1;
  78. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  79. }
  80. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  81. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  82. }
  83. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  84. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  85. }
  86. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  87. p += pos;
  88. if( x ) {
  89. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  90. }
  91. if( y ) {
  92. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  93. }
  94. if( dir ) {
  95. dir[0] = ( p[2] & 0x0f );
  96. }
  97. }
  98. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  99. p += pos;
  100. if( x0 ) {
  101. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  102. }
  103. if( y0 ) {
  104. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  105. }
  106. if( x1 ) {
  107. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  108. }
  109. if( y1 ) {
  110. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  111. }
  112. if( sx0 ) {
  113. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  114. }
  115. if( sy0 ) {
  116. sy0[0] = ( p[5] & 0x0f ) >> 0;
  117. }
  118. }
  119. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  120. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  121. }
  122. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  123. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  124. }
  125. //To idenfity disguised characters.
  126. static inline bool disguised(struct block_list* bl) {
  127. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  128. }
  129. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  130. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  131. if( len > max )
  132. len = max;
  133. mes[len-1] = '\0';
  134. return len;
  135. }
  136. static char map_ip_str[128];
  137. static uint32 map_ip;
  138. static uint32 bind_ip = INADDR_ANY;
  139. static uint16 map_port = 5121;
  140. int map_fd;
  141. static int clif_parse (int fd);
  142. /*==========================================
  143. * Ip setting of map-server
  144. *------------------------------------------*/
  145. int clif_setip(const char* ip) {
  146. char ip_str[16];
  147. map_ip = host2ip(ip);
  148. if (!map_ip) {
  149. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  150. return 0;
  151. }
  152. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  153. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  154. return 1;
  155. }
  156. void clif_setbindip(const char* ip)
  157. {
  158. bind_ip = host2ip(ip);
  159. if (bind_ip) {
  160. char ip_str[16];
  161. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  162. } else {
  163. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  164. }
  165. }
  166. /*==========================================
  167. * Sets map port to 'port'
  168. * is run from map.c upon loading map server configuration
  169. *------------------------------------------*/
  170. void clif_setport(uint16 port)
  171. {
  172. map_port = port;
  173. }
  174. /*==========================================
  175. * Returns map server IP
  176. *------------------------------------------*/
  177. uint32 clif_getip(void)
  178. {
  179. return map_ip;
  180. }
  181. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  182. uint32 clif_refresh_ip(void)
  183. {
  184. uint32 new_ip;
  185. new_ip = host2ip(map_ip_str);
  186. if (new_ip && new_ip != map_ip) {
  187. map_ip = new_ip;
  188. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  189. return map_ip;
  190. }
  191. return 0;
  192. }
  193. /*==========================================
  194. * Returns map port which is set by clif_setport()
  195. *------------------------------------------*/
  196. uint16 clif_getport(void)
  197. {
  198. return map_port;
  199. }
  200. #if PACKETVER >= 20071106
  201. static inline unsigned char clif_bl_type(struct block_list *bl) {
  202. switch (bl->type) {
  203. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  204. case BL_ITEM: return 0x2; //ITEM_TYPE
  205. case BL_SKILL: return 0x3; //SKILL_TYPE
  206. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  207. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  208. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  209. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  210. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  211. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  212. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  213. default: return 0x1; //NPC_TYPE
  214. }
  215. }
  216. #endif
  217. /*==========================================
  218. * sub process of clif_send
  219. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  220. * In order to send area-wise packets, such as:
  221. * - AREA : everyone nearby your area
  222. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  223. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  224. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  225. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  226. *------------------------------------------*/
  227. static int clif_send_sub(struct block_list *bl, va_list ap)
  228. {
  229. struct block_list *src_bl;
  230. struct map_session_data *sd;
  231. unsigned char *buf;
  232. int len, type, fd;
  233. nullpo_ret(bl);
  234. nullpo_ret(sd = (struct map_session_data *)bl);
  235. fd = sd->fd;
  236. if (!fd) //Don't send to disconnected clients.
  237. return 0;
  238. buf = va_arg(ap,unsigned char*);
  239. len = va_arg(ap,int);
  240. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  241. type = va_arg(ap,int);
  242. switch(type) {
  243. case AREA_WOS:
  244. if (bl == src_bl)
  245. return 0;
  246. break;
  247. case AREA_WOC:
  248. if (sd->chatID || bl == src_bl)
  249. return 0;
  250. break;
  251. case AREA_WOSC:
  252. {
  253. if(src_bl->type == BL_PC){
  254. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  255. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  256. return 0;
  257. }
  258. else if(src_bl->type == BL_NPC) {
  259. struct npc_data *nd = (struct npc_data *)src_bl;
  260. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  261. return 0;
  262. }
  263. }
  264. break;
  265. }
  266. if (session[fd] == NULL)
  267. return 0;
  268. WFIFOHEAD(fd, len);
  269. if (WFIFOP(fd,0) == buf) {
  270. ShowError("WARNING: Invalid use of clif_send function\n");
  271. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  272. ShowError(" Please correct your code.\n");
  273. // don't send to not move the pointer of the packet for next sessions in the loop
  274. //WFIFOSET(fd,0);//## TODO is this ok?
  275. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  276. return 0;
  277. }
  278. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  279. memcpy(WFIFOP(fd,0), buf, len);
  280. WFIFOSET(fd,len);
  281. }
  282. return 0;
  283. }
  284. /*==========================================
  285. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  286. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  287. *------------------------------------------*/
  288. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  289. {
  290. int i;
  291. struct map_session_data *sd, *tsd;
  292. struct party_data *p = NULL;
  293. struct guild *g = NULL;
  294. struct battleground_data *bg = NULL;
  295. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  296. struct s_mapiterator* iter;
  297. if( type != ALL_CLIENT )
  298. nullpo_ret(bl);
  299. sd = BL_CAST(BL_PC, bl);
  300. switch(type) {
  301. case ALL_CLIENT: //All player clients.
  302. iter = mapit_getallusers();
  303. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  304. {
  305. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  306. { // packet must exist for the client version
  307. WFIFOHEAD(tsd->fd, len);
  308. memcpy(WFIFOP(tsd->fd,0), buf, len);
  309. WFIFOSET(tsd->fd,len);
  310. }
  311. }
  312. mapit_free(iter);
  313. break;
  314. case ALL_SAMEMAP: //All players on the same map
  315. iter = mapit_getallusers();
  316. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  317. {
  318. if( bl->m == tsd->bl.m && 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 AREA:
  328. case AREA_WOSC:
  329. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  330. clif_send (buf, len, bl, SELF);
  331. case AREA_WOC:
  332. case AREA_WOS:
  333. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  334. BL_PC, buf, len, bl, type);
  335. break;
  336. case AREA_CHAT_WOC:
  337. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  338. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  339. break;
  340. case CHAT:
  341. case CHAT_WOS:
  342. {
  343. struct chat_data *cd;
  344. if (sd) {
  345. cd = (struct chat_data*)map_id2bl(sd->chatID);
  346. } else if (bl->type == BL_CHAT) {
  347. cd = (struct chat_data*)bl;
  348. } else break;
  349. if (cd == NULL)
  350. break;
  351. for(i = 0; i < cd->users; i++) {
  352. if (type == CHAT_WOS && cd->usersd[i] == sd)
  353. continue;
  354. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  355. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  356. {
  357. WFIFOHEAD(fd,len);
  358. memcpy(WFIFOP(fd,0), buf, len);
  359. WFIFOSET(fd,len);
  360. }
  361. }
  362. }
  363. }
  364. break;
  365. case PARTY_AREA:
  366. case PARTY_AREA_WOS:
  367. x0 = bl->x - AREA_SIZE;
  368. y0 = bl->y - AREA_SIZE;
  369. x1 = bl->x + AREA_SIZE;
  370. y1 = bl->y + AREA_SIZE;
  371. case PARTY:
  372. case PARTY_WOS:
  373. case PARTY_SAMEMAP:
  374. case PARTY_SAMEMAP_WOS:
  375. if (sd && sd->status.party_id)
  376. p = party_search(sd->status.party_id);
  377. if (p) {
  378. for(i=0;i<MAX_PARTY;i++){
  379. if( (sd = p->data[i].sd) == NULL )
  380. continue;
  381. if( !(fd=sd->fd) )
  382. continue;
  383. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  384. continue;
  385. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  386. continue;
  387. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  388. continue;
  389. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  390. { // packet must exist for the client version
  391. WFIFOHEAD(fd,len);
  392. memcpy(WFIFOP(fd,0), buf, len);
  393. WFIFOSET(fd,len);
  394. }
  395. }
  396. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  397. break;
  398. iter = mapit_getallusers();
  399. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  400. {
  401. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  402. { // packet must exist for the client version
  403. WFIFOHEAD(tsd->fd, len);
  404. memcpy(WFIFOP(tsd->fd,0), buf, len);
  405. WFIFOSET(tsd->fd,len);
  406. }
  407. }
  408. mapit_free(iter);
  409. }
  410. break;
  411. case DUEL:
  412. case DUEL_WOS:
  413. if (!sd || !sd->duel_group) break; //Invalid usage.
  414. iter = mapit_getallusers();
  415. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  416. {
  417. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  418. continue;
  419. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  420. { // packet must exist for the client version
  421. WFIFOHEAD(tsd->fd, len);
  422. memcpy(WFIFOP(tsd->fd,0), buf, len);
  423. WFIFOSET(tsd->fd,len);
  424. }
  425. }
  426. mapit_free(iter);
  427. break;
  428. case SELF:
  429. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  430. WFIFOHEAD(fd,len);
  431. memcpy(WFIFOP(fd,0), buf, len);
  432. WFIFOSET(fd,len);
  433. }
  434. break;
  435. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  436. case GUILD_AREA:
  437. case GUILD_AREA_WOS:
  438. x0 = bl->x - AREA_SIZE;
  439. y0 = bl->y - AREA_SIZE;
  440. x1 = bl->x + AREA_SIZE;
  441. y1 = bl->y + AREA_SIZE;
  442. case GUILD_SAMEMAP:
  443. case GUILD_SAMEMAP_WOS:
  444. case GUILD:
  445. case GUILD_WOS:
  446. case GUILD_NOBG:
  447. if (sd && sd->status.guild_id)
  448. g = sd->guild;
  449. if (g) {
  450. for(i = 0; i < g->max_member; i++) {
  451. if( (sd = g->member[i].sd) != NULL )
  452. {
  453. if( !(fd=sd->fd) )
  454. continue;
  455. if( type == GUILD_NOBG && sd->bg_id )
  456. continue;
  457. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  458. continue;
  459. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  460. continue;
  461. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  462. continue;
  463. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  464. { // packet must exist for the client version
  465. WFIFOHEAD(fd,len);
  466. memcpy(WFIFOP(fd,0), buf, len);
  467. WFIFOSET(fd,len);
  468. }
  469. }
  470. }
  471. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  472. break;
  473. iter = mapit_getallusers();
  474. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  475. {
  476. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  477. { // packet must exist for the client version
  478. WFIFOHEAD(tsd->fd, len);
  479. memcpy(WFIFOP(tsd->fd,0), buf, len);
  480. WFIFOSET(tsd->fd,len);
  481. }
  482. }
  483. mapit_free(iter);
  484. }
  485. break;
  486. case BG_AREA:
  487. case BG_AREA_WOS:
  488. x0 = bl->x - AREA_SIZE;
  489. y0 = bl->y - AREA_SIZE;
  490. x1 = bl->x + AREA_SIZE;
  491. y1 = bl->y + AREA_SIZE;
  492. case BG_SAMEMAP:
  493. case BG_SAMEMAP_WOS:
  494. case BG:
  495. case BG_WOS:
  496. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  497. {
  498. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  499. {
  500. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  501. continue;
  502. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  503. continue;
  504. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  505. continue;
  506. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  507. continue;
  508. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  509. { // packet must exist for the client version
  510. WFIFOHEAD(fd,len);
  511. memcpy(WFIFOP(fd,0), buf, len);
  512. WFIFOSET(fd,len);
  513. }
  514. }
  515. }
  516. break;
  517. default:
  518. ShowError("clif_send: Unrecognized type %d\n",type);
  519. return -1;
  520. }
  521. return 0;
  522. }
  523. /// Notifies the client, that it's connection attempt was accepted.
  524. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  525. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  526. void clif_authok(struct map_session_data *sd)
  527. {
  528. #if PACKETVER < 20080102
  529. const int cmd = 0x73;
  530. #else
  531. const int cmd = 0x2eb;
  532. #endif
  533. int fd = sd->fd;
  534. WFIFOHEAD(fd,packet_len(cmd));
  535. WFIFOW(fd, 0) = cmd;
  536. WFIFOL(fd, 2) = gettick();
  537. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  538. WFIFOB(fd, 9) = 5; // ignored
  539. WFIFOB(fd,10) = 5; // ignored
  540. #if PACKETVER >= 20080102
  541. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  542. #endif
  543. WFIFOSET(fd,packet_len(cmd));
  544. }
  545. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  546. /// 0074 <error code>.B
  547. /// error code:
  548. /// 0 = client type mismatch
  549. /// 1 = ID mismatch
  550. /// 2 = mobile - out of available time
  551. /// 3 = mobile - already logged in
  552. /// 4 = mobile - waiting state
  553. void clif_authrefuse(int fd, uint8 error_code)
  554. {
  555. WFIFOHEAD(fd,packet_len(0x74));
  556. WFIFOW(fd,0) = 0x74;
  557. WFIFOB(fd,2) = error_code;
  558. WFIFOSET(fd,packet_len(0x74));
  559. }
  560. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  561. /// 0081 <error code>.B
  562. /// error code:
  563. /// 0 = BAN_UNFAIR
  564. /// 1 = server closed -> MsgStringTable[4]
  565. /// 2 = ID already logged in -> MsgStringTable[5]
  566. /// 3 = timeout/too much lag -> MsgStringTable[241]
  567. /// 4 = server full -> MsgStringTable[264]
  568. /// 5 = underaged -> MsgStringTable[305]
  569. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  570. /// 9 = too many connections from this ip -> MsgStringTable[529]
  571. /// 10 = out of available time paid for -> MsgStringTable[530]
  572. /// 11 = BAN_PAY_SUSPEND
  573. /// 12 = BAN_PAY_CHANGE
  574. /// 13 = BAN_PAY_WRONGIP
  575. /// 14 = BAN_PAY_PNGAMEROOM
  576. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  577. /// 16 = BAN_JAPAN_REFUSE1
  578. /// 17 = BAN_JAPAN_REFUSE2
  579. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  580. /// 100 = BAN_PC_IP_UNFAIR
  581. /// 101 = BAN_PC_IP_COUNT_ALL
  582. /// 102 = BAN_PC_IP_COUNT
  583. /// 103 = BAN_GRAVITY_MEM_AGREE
  584. /// 104 = BAN_GAME_MEM_AGREE
  585. /// 105 = BAN_HAN_VALID
  586. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  587. /// 107 = BAN_OVER_CHARACTER_LIST
  588. /// 108 = BAN_IP_BLOCK
  589. /// 109 = BAN_INVALID_PWD_CNT
  590. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  591. /// ? = disconnected -> MsgStringTable[3]
  592. void clif_authfail_fd(int fd, int type)
  593. {
  594. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  595. return;
  596. WFIFOHEAD(fd, packet_len(0x81));
  597. WFIFOW(fd,0) = 0x81;
  598. WFIFOB(fd,2) = type;
  599. WFIFOSET(fd,packet_len(0x81));
  600. set_eof(fd);
  601. }
  602. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  603. /// 00b3 <type>.B
  604. /// type:
  605. /// 1 = disconnect, char-select
  606. /// ? = nothing
  607. void clif_charselectok(int id, uint8 ok)
  608. {
  609. struct map_session_data* sd;
  610. int fd;
  611. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  612. return;
  613. fd = sd->fd;
  614. WFIFOHEAD(fd,packet_len(0xb3));
  615. WFIFOW(fd,0) = 0xb3;
  616. WFIFOB(fd,2) = ok;
  617. WFIFOSET(fd,packet_len(0xb3));
  618. }
  619. /// Makes an item appear on the ground.
  620. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  621. /// 084b(2013) <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  622. void clif_dropflooritem(struct flooritem_data* fitem)
  623. {
  624. #if PACKETVER >= 20130000
  625. uint8 buf[19];
  626. uint32 header=0x84b;
  627. #else
  628. uint8 buf[17];
  629. uint32 header=0x09e;
  630. #endif
  631. int view, offset=0;
  632. nullpo_retv(fitem);
  633. if (fitem->item_data.nameid <= 0)
  634. return;
  635. WBUFW(buf, offset+0) = header;
  636. WBUFL(buf, offset+2) = fitem->bl.id;
  637. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  638. #if PACKETVER >= 20130000
  639. WBUFW(buf, offset+8) = itemtype(itemdb_type(fitem->item_data.nameid));
  640. offset +=2;
  641. #endif
  642. WBUFB(buf, offset+8) = fitem->item_data.identify;
  643. WBUFW(buf, offset+9) = fitem->bl.x;
  644. WBUFW(buf, offset+11) = fitem->bl.y;
  645. WBUFB(buf, offset+13) = fitem->subx;
  646. WBUFB(buf, offset+14) = fitem->suby;
  647. WBUFW(buf, offset+15) = fitem->item_data.amount;
  648. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  649. }
  650. /// Makes an item disappear from the ground.
  651. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  652. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  653. {
  654. unsigned char buf[16];
  655. nullpo_retv(fitem);
  656. WBUFW(buf,0) = 0xa1;
  657. WBUFL(buf,2) = fitem->bl.id;
  658. if (fd == 0) {
  659. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  660. } else {
  661. WFIFOHEAD(fd,packet_len(0xa1));
  662. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  663. WFIFOSET(fd,packet_len(0xa1));
  664. }
  665. }
  666. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  667. /// 0080 <id>.L <type>.B
  668. /// type:
  669. /// 0 = out of sight
  670. /// 1 = died
  671. /// 2 = logged out
  672. /// 3 = teleport
  673. /// 4 = trickdead
  674. void clif_clearunit_single(int id, clr_type type, int fd)
  675. {
  676. WFIFOHEAD(fd, packet_len(0x80));
  677. WFIFOW(fd,0) = 0x80;
  678. WFIFOL(fd,2) = id;
  679. WFIFOB(fd,6) = type;
  680. WFIFOSET(fd, packet_len(0x80));
  681. }
  682. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  683. /// 0080 <id>.L <type>.B
  684. /// type:
  685. /// 0 = out of sight
  686. /// 1 = died
  687. /// 2 = logged out
  688. /// 3 = teleport
  689. /// 4 = trickdead
  690. void clif_clearunit_area(struct block_list* bl, clr_type type)
  691. {
  692. unsigned char buf[8];
  693. nullpo_retv(bl);
  694. WBUFW(buf,0) = 0x80;
  695. WBUFL(buf,2) = bl->id;
  696. WBUFB(buf,6) = type;
  697. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  698. if(disguised(bl)) {
  699. WBUFL(buf,2) = -bl->id;
  700. clif_send(buf, packet_len(0x80), bl, SELF);
  701. }
  702. }
  703. /// Used to make monsters with player-sprites disappear after dying
  704. /// like normal monsters, because the client does not remove those
  705. /// automatically.
  706. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  707. {
  708. struct block_list *bl = (struct block_list *)data;
  709. clif_clearunit_area(bl, (clr_type) id);
  710. ers_free(delay_clearunit_ers,bl);
  711. return 0;
  712. }
  713. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  714. {
  715. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  716. memcpy (tbl, bl, sizeof (struct block_list));
  717. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  718. }
  719. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  720. {
  721. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK))
  722. {
  723. *rhand = *lhand = 0;
  724. return;
  725. }
  726. #if PACKETVER < 4
  727. *rhand = sd->status.weapon;
  728. *lhand = sd->status.shield;
  729. #else
  730. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  731. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  732. {
  733. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  734. if (id->view_id > 0)
  735. *rhand = id->view_id;
  736. else
  737. *rhand = id->nameid;
  738. } else
  739. *rhand = 0;
  740. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  741. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  742. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  743. {
  744. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  745. if (id->view_id > 0)
  746. *lhand = id->view_id;
  747. else
  748. *lhand = id->nameid;
  749. } else
  750. *lhand = 0;
  751. #endif
  752. }
  753. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  754. static int clif_setlevel_sub(int lv) {
  755. if( lv < battle_config.max_lv ) {
  756. ;
  757. } else if( lv < battle_config.aura_lv ) {
  758. lv = battle_config.max_lv - 1;
  759. } else {
  760. lv = battle_config.max_lv;
  761. }
  762. return lv;
  763. }
  764. static int clif_setlevel(struct block_list* bl) {
  765. int lv = status_get_lv(bl);
  766. if( battle_config.client_limit_unit_lv&bl->type )
  767. return clif_setlevel_sub(lv);
  768. switch( bl->type ) {
  769. case BL_NPC:
  770. case BL_PET:
  771. // npcs and pets do not have level
  772. return 0;
  773. }
  774. return lv;
  775. }
  776. /*==========================================
  777. * Prepares 'unit standing/spawning' packet
  778. *------------------------------------------*/
  779. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  780. {
  781. struct map_session_data* sd;
  782. struct status_change* sc = status_get_sc(bl);
  783. struct view_data* vd = status_get_viewdata(bl);
  784. unsigned char *buf = WBUFP(buffer,0);
  785. #if PACKETVER < 20091103
  786. bool type = !pcdb_checkid(vd->class_);
  787. #endif
  788. unsigned short offset = 0;
  789. #if PACKETVER >= 20091103
  790. const char *name;
  791. #endif
  792. sd = BL_CAST(BL_PC, bl);
  793. #if PACKETVER < 20091103
  794. if(type)
  795. WBUFW(buf,0) = spawn?0x7c:0x78;
  796. else
  797. #endif
  798. #if PACKETVER < 4
  799. WBUFW(buf,0) = spawn?0x79:0x78;
  800. #elif PACKETVER < 7
  801. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  802. #elif PACKETVER < 20080102
  803. WBUFW(buf,0) = spawn?0x22b:0x22a;
  804. #elif PACKETVER < 20091103
  805. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  806. #elif PACKETVER < 20101124
  807. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  808. #else
  809. WBUFW(buf,0) = spawn?0x858:0x857;
  810. #endif
  811. #if PACKETVER >= 20091103
  812. name = status_get_name(bl);
  813. #if PACKETVER < 20110111
  814. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  815. #else
  816. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  817. #endif
  818. WBUFB(buf,4) = clif_bl_type(bl);
  819. offset+=3;
  820. buf = WBUFP(buffer,offset);
  821. #elif PACKETVER >= 20071106
  822. if (type) { //Non-player packets
  823. WBUFB(buf,2) = clif_bl_type(bl);
  824. offset++;
  825. buf = WBUFP(buffer,offset);
  826. }
  827. #endif
  828. WBUFL(buf, 2) = bl->id;
  829. WBUFW(buf, 6) = status_get_speed(bl);
  830. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  831. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  832. #if PACKETVER < 20091103
  833. if (type&&spawn) { //uses an older and different packet structure
  834. WBUFW(buf,12) = (sc)? sc->option : 0;
  835. WBUFW(buf,14) = vd->hair_style;
  836. WBUFW(buf,16) = vd->weapon;
  837. WBUFW(buf,18) = vd->head_bottom;
  838. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  839. WBUFW(buf,22) = vd->shield;
  840. } else {
  841. #endif
  842. #if PACKETVER >= 20091103
  843. WBUFL(buf,12) = (sc)? sc->option : 0;
  844. offset+=2;
  845. buf = WBUFP(buffer,offset);
  846. #elif PACKETVER >= 7
  847. if (!type) {
  848. WBUFL(buf,12) = (sc)? sc->option : 0;
  849. offset+=2;
  850. buf = WBUFP(buffer,offset);
  851. } else
  852. WBUFW(buf,12) = (sc)? sc->option : 0;
  853. #else
  854. WBUFW(buf,12) = (sc)? sc->option : 0;
  855. #endif
  856. WBUFW(buf,14) = vd->class_;
  857. WBUFW(buf,16) = vd->hair_style;
  858. WBUFW(buf,18) = vd->weapon;
  859. #if PACKETVER < 4
  860. WBUFW(buf,20) = vd->head_bottom;
  861. WBUFW(buf,22) = vd->shield;
  862. #else
  863. WBUFW(buf,20) = vd->shield;
  864. WBUFW(buf,22) = vd->head_bottom;
  865. #endif
  866. #if PACKETVER < 20091103
  867. }
  868. #endif
  869. WBUFW(buf,24) = vd->head_top;
  870. WBUFW(buf,26) = vd->head_mid;
  871. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  872. { //The hell, why flags work like this?
  873. WBUFW(buf,22) = status_get_emblem_id(bl);
  874. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  875. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  876. }
  877. WBUFW(buf,28) = vd->hair_color;
  878. WBUFW(buf,30) = vd->cloth_color;
  879. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  880. #if PACKETVER < 20091103
  881. if (type&&spawn) { //End of packet 0x7c
  882. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  883. WBUFB(buf,35) = vd->sex;
  884. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  885. WBUFB(buf,39) = 0;
  886. WBUFB(buf,40) = 0;
  887. return packet_len(0x7c);
  888. }
  889. #endif
  890. #if PACKETVER >= 20110111
  891. WBUFW(buf,34) = vd->robe;
  892. offset+= 2;
  893. buf = WBUFP(buffer,offset);
  894. #endif
  895. WBUFL(buf,34) = status_get_guild_id(bl);
  896. WBUFW(buf,38) = status_get_emblem_id(bl);
  897. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  898. #if PACKETVER >= 20091103
  899. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  900. offset+=2;
  901. buf = WBUFP(buffer,offset);
  902. #elif PACKETVER >= 7
  903. if (!type) {
  904. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  905. offset+=2;
  906. buf = WBUFP(buffer,offset);
  907. } else
  908. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  909. #else
  910. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  911. #endif
  912. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  913. WBUFB(buf,45) = vd->sex;
  914. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  915. WBUFB(buf,49) = (sd)? 5 : 0;
  916. WBUFB(buf,50) = (sd)? 5 : 0;
  917. if (!spawn) {
  918. WBUFB(buf,51) = vd->dead_sit;
  919. offset++;
  920. buf = WBUFP(buffer,offset);
  921. }
  922. WBUFW(buf,51) = clif_setlevel(bl);
  923. #if PACKETVER < 20091103
  924. if (type) //End for non-player packet
  925. return packet_len(WBUFW(buffer,0));
  926. #endif
  927. #if PACKETVER >= 20080102
  928. WBUFW(buf,53) = sd?sd->user_font:0;
  929. #endif
  930. #if PACKETVER >= 20091103
  931. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  932. return WBUFW(buffer,2);
  933. #else
  934. return packet_len(WBUFW(buffer,0));
  935. #endif
  936. }
  937. /*==========================================
  938. * Prepares 'unit walking' packet
  939. *------------------------------------------*/
  940. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  941. {
  942. struct map_session_data* sd;
  943. struct status_change* sc = status_get_sc(bl);
  944. struct view_data* vd = status_get_viewdata(bl);
  945. unsigned char* buf = WBUFP(buffer,0);
  946. #if PACKETVER >= 7
  947. unsigned short offset = 0;
  948. #endif
  949. #if PACKETVER >= 20091103
  950. const char *name;
  951. #endif
  952. sd = BL_CAST(BL_PC, bl);
  953. #if PACKETVER < 4
  954. WBUFW(buf, 0) = 0x7b;
  955. #elif PACKETVER < 7
  956. WBUFW(buf, 0) = 0x1da;
  957. #elif PACKETVER < 20080102
  958. WBUFW(buf, 0) = 0x22c;
  959. #elif PACKETVER < 20091103
  960. WBUFW(buf, 0) = 0x2ec;
  961. #elif PACKETVER < 20101124
  962. WBUFW(buf, 0) = 0x7f7;
  963. #else
  964. WBUFW(buf, 0) = 0x856;
  965. #endif
  966. #if PACKETVER >= 20091103
  967. name = status_get_name(bl);
  968. #if PACKETVER < 20110111
  969. WBUFW(buf, 2) = 69+strlen(name);
  970. #else
  971. WBUFW(buf, 2) = 71+strlen(name);
  972. #endif
  973. offset+=2;
  974. buf = WBUFP(buffer,offset);
  975. #endif
  976. #if PACKETVER >= 20071106
  977. WBUFB(buf, 2) = clif_bl_type(bl);
  978. offset++;
  979. buf = WBUFP(buffer,offset);
  980. #endif
  981. WBUFL(buf, 2) = bl->id;
  982. WBUFW(buf, 6) = status_get_speed(bl);
  983. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  984. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  985. #if PACKETVER < 7
  986. WBUFW(buf,12) = (sc)? sc->option : 0;
  987. #else
  988. WBUFL(buf,12) = (sc)? sc->option : 0;
  989. offset+=2; //Shift the rest of elements by 2 bytes.
  990. buf = WBUFP(buffer,offset);
  991. #endif
  992. WBUFW(buf,14) = vd->class_;
  993. WBUFW(buf,16) = vd->hair_style;
  994. WBUFW(buf,18) = vd->weapon;
  995. #if PACKETVER < 4
  996. WBUFW(buf,20) = vd->head_bottom;
  997. WBUFL(buf,22) = gettick();
  998. WBUFW(buf,26) = vd->shield;
  999. #else
  1000. WBUFW(buf,20) = vd->shield;
  1001. WBUFW(buf,22) = vd->head_bottom;
  1002. WBUFL(buf,24) = gettick();
  1003. #endif
  1004. WBUFW(buf,28) = vd->head_top;
  1005. WBUFW(buf,30) = vd->head_mid;
  1006. WBUFW(buf,32) = vd->hair_color;
  1007. WBUFW(buf,34) = vd->cloth_color;
  1008. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1009. #if PACKETVER >= 20110111
  1010. WBUFW(buf,38) = vd->robe;
  1011. offset+= 2;
  1012. buf = WBUFP(buffer,offset);
  1013. #endif
  1014. WBUFL(buf,38) = status_get_guild_id(bl);
  1015. WBUFW(buf,42) = status_get_emblem_id(bl);
  1016. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1017. #if PACKETVER < 7
  1018. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1019. #else
  1020. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1021. offset+=2; //Shift the rest of elements by 2 bytes.
  1022. buf = WBUFP(buffer,offset);
  1023. #endif
  1024. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1025. WBUFB(buf,49) = vd->sex;
  1026. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1027. WBUFB(buf,56) = (sd)? 5 : 0;
  1028. WBUFB(buf,57) = (sd)? 5 : 0;
  1029. WBUFW(buf,58) = clif_setlevel(bl);
  1030. #if PACKETVER >= 20080102
  1031. WBUFW(buf,60) = sd?sd->user_font:0;
  1032. #endif
  1033. #if PACKETVER >= 20091103
  1034. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1035. return WBUFW(buffer,2);
  1036. #else
  1037. return packet_len(WBUFW(buffer,0));
  1038. #endif
  1039. }
  1040. //Modifies the buffer for disguise characters and sends it to self.
  1041. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1042. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1043. {
  1044. #if PACKETVER >= 20091103
  1045. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1046. WBUFL(buf,5)=-bl->id;
  1047. #elif PACKETVER >= 20071106
  1048. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1049. WBUFL(buf,3)=-bl->id;
  1050. #else
  1051. WBUFL(buf,2)=-bl->id;
  1052. #endif
  1053. clif_send(buf, len, bl, SELF);
  1054. }
  1055. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1056. /// 01b0 <id>.L <type>.B <value>.L
  1057. /// type:
  1058. /// unused
  1059. void clif_class_change(struct block_list *bl,int class_,int type)
  1060. {
  1061. nullpo_retv(bl);
  1062. if(!pcdb_checkid(class_))
  1063. {// player classes yield missing sprites
  1064. unsigned char buf[16];
  1065. WBUFW(buf,0)=0x1b0;
  1066. WBUFL(buf,2)=bl->id;
  1067. WBUFB(buf,6)=type;
  1068. WBUFL(buf,7)=class_;
  1069. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1070. }
  1071. }
  1072. /// Notifies the client of an object's spirits.
  1073. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1074. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1075. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1076. {
  1077. WFIFOHEAD(fd, packet_len(0x1e1));
  1078. WFIFOW(fd,0)=0x1e1;
  1079. WFIFOL(fd,2)=sd->bl.id;
  1080. WFIFOW(fd,6)=sd->spiritball;
  1081. WFIFOSET(fd, packet_len(0x1e1));
  1082. }
  1083. /*==========================================
  1084. * Kagerou/Oboro amulet spirit
  1085. *------------------------------------------*/
  1086. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1087. {
  1088. WFIFOHEAD(fd, packet_len(0x08cf));
  1089. WFIFOW(fd,0)=0x08cf;
  1090. WFIFOL(fd,2)=sd->bl.id;
  1091. WFIFOW(fd,6)=type;
  1092. WFIFOW(fd,8)=sd->talisman[type];
  1093. WFIFOSET(fd, packet_len(0x08cf));
  1094. }
  1095. /*==========================================
  1096. * Run when player changes map / refreshes
  1097. * Tells its client to display all weather settings being used by this map
  1098. *------------------------------------------*/
  1099. static void clif_weather_check(struct map_session_data *sd)
  1100. {
  1101. int16 m = sd->bl.m;
  1102. int fd = sd->fd;
  1103. if (map[m].flag.snow
  1104. || map[m].flag.clouds
  1105. || map[m].flag.fog
  1106. || map[m].flag.fireworks
  1107. || map[m].flag.sakura
  1108. || map[m].flag.leaves
  1109. || map[m].flag.clouds2)
  1110. {
  1111. if (map[m].flag.snow)
  1112. clif_specialeffect_single(&sd->bl, 162, fd);
  1113. if (map[m].flag.clouds)
  1114. clif_specialeffect_single(&sd->bl, 233, fd);
  1115. if (map[m].flag.clouds2)
  1116. clif_specialeffect_single(&sd->bl, 516, fd);
  1117. if (map[m].flag.fog)
  1118. clif_specialeffect_single(&sd->bl, 515, fd);
  1119. if (map[m].flag.fireworks) {
  1120. clif_specialeffect_single(&sd->bl, 297, fd);
  1121. clif_specialeffect_single(&sd->bl, 299, fd);
  1122. clif_specialeffect_single(&sd->bl, 301, fd);
  1123. }
  1124. if (map[m].flag.sakura)
  1125. clif_specialeffect_single(&sd->bl, 163, fd);
  1126. if (map[m].flag.leaves)
  1127. clif_specialeffect_single(&sd->bl, 333, fd);
  1128. /**
  1129. * No longer available, keeping here just in case it's back someday. [Ind]
  1130. **/
  1131. //if (map[m].flag.rain)
  1132. // clif_specialeffect_single(&sd->bl, 161, fd);
  1133. }
  1134. }
  1135. /**
  1136. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1137. **/
  1138. void clif_weather(int16 m)
  1139. {
  1140. struct s_mapiterator* iter;
  1141. struct map_session_data *sd=NULL;
  1142. iter = mapit_getallusers();
  1143. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1144. {
  1145. if( sd->bl.m == m )
  1146. clif_weather_check(sd);
  1147. }
  1148. mapit_free(iter);
  1149. }
  1150. /**
  1151. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1152. **/
  1153. int clif_spawn(struct block_list *bl)
  1154. {
  1155. unsigned char buf[128];
  1156. struct view_data *vd;
  1157. int len;
  1158. vd = status_get_viewdata(bl);
  1159. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1160. return 0;
  1161. /**
  1162. * Hide NPC from maya purple card.
  1163. **/
  1164. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1165. return 0;
  1166. len = clif_set_unit_idle(bl, buf,true);
  1167. clif_send(buf, len, bl, AREA_WOS);
  1168. if (disguised(bl))
  1169. clif_setdisguise(bl, buf, len);
  1170. if (vd->cloth_color)
  1171. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1172. switch (bl->type)
  1173. {
  1174. case BL_PC:
  1175. {
  1176. TBL_PC *sd = ((TBL_PC*)bl);
  1177. int i;
  1178. if (sd->spiritball > 0)
  1179. clif_spiritball(&sd->bl);
  1180. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1181. clif_specialeffect(bl,423,AREA);
  1182. else if(sd->state.size==SZ_MEDIUM)
  1183. clif_specialeffect(bl,421,AREA);
  1184. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1185. clif_sendbgemblem_area(sd);
  1186. if( sd->sc.option&OPTION_MOUNTING ) {
  1187. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1188. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1189. }
  1190. for(i = 1; i < 5; i++){
  1191. if( sd->talisman[i] > 0 )
  1192. clif_talisman(sd, i);
  1193. }
  1194. #ifdef NEW_CARTS
  1195. if( sd->sc.data[SC_PUSH_CART] )
  1196. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1197. #endif
  1198. if (sd->status.robe)
  1199. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1200. }
  1201. break;
  1202. case BL_MOB:
  1203. {
  1204. TBL_MOB *md = ((TBL_MOB*)bl);
  1205. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1206. clif_specialeffect(&md->bl,423,AREA);
  1207. else if(md->special_state.size==SZ_MEDIUM)
  1208. clif_specialeffect(&md->bl,421,AREA);
  1209. }
  1210. break;
  1211. case BL_NPC:
  1212. {
  1213. TBL_NPC *nd = ((TBL_NPC*)bl);
  1214. if( nd->size == SZ_BIG )
  1215. clif_specialeffect(&nd->bl,423,AREA);
  1216. else if( nd->size == SZ_MEDIUM )
  1217. clif_specialeffect(&nd->bl,421,AREA);
  1218. }
  1219. break;
  1220. case BL_PET:
  1221. if (vd->head_bottom)
  1222. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1223. break;
  1224. }
  1225. return 0;
  1226. }
  1227. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1228. /// 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
  1229. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1230. {
  1231. struct status_data *status;
  1232. unsigned char buf[128];
  1233. int m_class;
  1234. nullpo_retv(hd);
  1235. status = &hd->battle_status;
  1236. m_class = hom_class2mapid(hd->homunculus.class_);
  1237. memset(buf,0,packet_len(0x22e));
  1238. WBUFW(buf,0)=0x22e;
  1239. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1240. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1241. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1242. WBUFW(buf,27)=hd->homunculus.level;
  1243. WBUFW(buf,29)=hd->homunculus.hunger;
  1244. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1245. WBUFW(buf,33)=0; // equip id
  1246. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1247. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1248. WBUFW(buf,39)=status->hit;
  1249. if (battle_config.hom_setting&0x10)
  1250. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1251. else
  1252. WBUFW(buf,41)=status->cri/10;
  1253. WBUFW(buf,43)=status->def + status->vit ;
  1254. WBUFW(buf,45)=status->mdef;
  1255. WBUFW(buf,47)=status->flee;
  1256. WBUFW(buf,49)=(flag)?0:status->amotion;
  1257. if (status->max_hp > INT16_MAX) {
  1258. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1259. WBUFW(buf,53) = 100;
  1260. } else {
  1261. WBUFW(buf,51)=status->hp;
  1262. WBUFW(buf,53)=status->max_hp;
  1263. }
  1264. if (status->max_sp > INT16_MAX) {
  1265. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1266. WBUFW(buf,57) = 100;
  1267. } else {
  1268. WBUFW(buf,55)=status->sp;
  1269. WBUFW(buf,57)=status->max_sp;
  1270. }
  1271. WBUFL(buf,59)=hd->homunculus.exp;
  1272. 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) )
  1273. WBUFL(buf,63)=0;
  1274. else
  1275. WBUFL(buf,63)=hd->exp_next;
  1276. WBUFW(buf,67)=hd->homunculus.skillpts;
  1277. WBUFW(buf,69)=status_get_range(&hd->bl);
  1278. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1279. }
  1280. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1281. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1282. /// type:
  1283. /// unused
  1284. /// state:
  1285. /// 0 = pre-init
  1286. /// 1 = intimacy
  1287. /// 2 = hunger
  1288. /// 3 = accessory?
  1289. /// ? = ignored
  1290. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1291. { //[orn]
  1292. int fd = sd->fd;
  1293. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1294. merc_hom_calc_skilltree(sd->hd, 0);
  1295. WFIFOHEAD(fd, packet_len(0x230));
  1296. WFIFOW(fd,0)=0x230;
  1297. WFIFOB(fd,2)=0;
  1298. WFIFOB(fd,3)=state;
  1299. WFIFOL(fd,4)=sd->hd->bl.id;
  1300. WFIFOL(fd,8)=param;
  1301. WFIFOSET(fd,packet_len(0x230));
  1302. }
  1303. int clif_homskillinfoblock(struct map_session_data *sd)
  1304. { //[orn]
  1305. struct homun_data *hd;
  1306. int fd = sd->fd;
  1307. int i,j,len=4,id;
  1308. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1309. hd = sd->hd;
  1310. if ( !hd )
  1311. return 0 ;
  1312. WFIFOW(fd,0)=0x235;
  1313. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1314. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1315. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1316. j = id - HM_SKILLBASE;
  1317. WFIFOW(fd,len ) = id;
  1318. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1319. WFIFOW(fd,len+4) = 0;
  1320. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1321. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1322. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1323. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1324. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1325. len+=37;
  1326. }
  1327. }
  1328. WFIFOW(fd,2)=len;
  1329. WFIFOSET(fd,len);
  1330. return 0;
  1331. }
  1332. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1333. { //[orn]
  1334. struct homun_data *hd;
  1335. int fd, idx;
  1336. nullpo_retv(sd);
  1337. idx = skill_id - HM_SKILLBASE;
  1338. fd=sd->fd;
  1339. hd=sd->hd;
  1340. WFIFOHEAD(fd, packet_len(0x239));
  1341. WFIFOW(fd,0) = 0x239;
  1342. WFIFOW(fd,2) = skill_id;
  1343. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1344. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1345. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1346. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1347. WFIFOSET(fd,packet_len(0x239));
  1348. }
  1349. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1350. {
  1351. int fd=sd->fd;
  1352. WFIFOHEAD(fd,packet_len(0x22f));
  1353. WFIFOW(fd,0)=0x22f;
  1354. WFIFOB(fd,2)=fail;
  1355. WFIFOW(fd,3)=foodid;
  1356. WFIFOSET(fd,packet_len(0x22f));
  1357. return 0;
  1358. }
  1359. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1360. /// 0087 <walk start time>.L <walk data>.6B
  1361. void clif_walkok(struct map_session_data *sd)
  1362. {
  1363. int fd=sd->fd;
  1364. WFIFOHEAD(fd, packet_len(0x87));
  1365. WFIFOW(fd,0)=0x87;
  1366. WFIFOL(fd,2)=gettick();
  1367. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1368. WFIFOSET(fd,packet_len(0x87));
  1369. }
  1370. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1371. {
  1372. uint8 buf[128];
  1373. int len;
  1374. len = clif_set_unit_walking(bl,ud,buf);
  1375. clif_send(buf,len,bl,AREA_WOS);
  1376. if (disguised(bl))
  1377. clif_setdisguise(bl, buf, len);
  1378. if(vd->cloth_color)
  1379. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1380. switch(bl->type)
  1381. {
  1382. case BL_PC:
  1383. {
  1384. TBL_PC *sd = ((TBL_PC*)bl);
  1385. // clif_movepc(sd);
  1386. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1387. clif_specialeffect(&sd->bl,423,AREA);
  1388. else if(sd->state.size==SZ_MEDIUM)
  1389. clif_specialeffect(&sd->bl,421,AREA);
  1390. }
  1391. break;
  1392. case BL_MOB:
  1393. {
  1394. TBL_MOB *md = ((TBL_MOB*)bl);
  1395. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1396. clif_specialeffect(&md->bl,423,AREA);
  1397. else if(md->special_state.size==SZ_MEDIUM)
  1398. clif_specialeffect(&md->bl,421,AREA);
  1399. }
  1400. break;
  1401. case BL_PET:
  1402. if( vd->head_bottom )
  1403. {// needed to display pet equip properly
  1404. clif_pet_equip_area((TBL_PET*)bl);
  1405. }
  1406. break;
  1407. }
  1408. }
  1409. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1410. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1411. /// Note: unit must not be self
  1412. void clif_move(struct unit_data *ud)
  1413. {
  1414. unsigned char buf[16];
  1415. struct view_data* vd;
  1416. struct block_list* bl = ud->bl;
  1417. vd = status_get_viewdata(bl);
  1418. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1419. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1420. /**
  1421. * Hide NPC from maya purple card.
  1422. **/
  1423. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1424. return;
  1425. if (ud->state.speed_changed) {
  1426. // Since we don't know how to update the speed of other objects,
  1427. // use the old walk packet to update the data.
  1428. ud->state.speed_changed = 0;
  1429. clif_move2(bl, vd, ud);
  1430. return;
  1431. }
  1432. WBUFW(buf,0)=0x86;
  1433. WBUFL(buf,2)=bl->id;
  1434. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1435. WBUFL(buf,12)=gettick();
  1436. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1437. if (disguised(bl))
  1438. {
  1439. WBUFL(buf,2)=-bl->id;
  1440. clif_send(buf, packet_len(0x86), bl, SELF);
  1441. }
  1442. }
  1443. /*==========================================
  1444. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1445. *------------------------------------------*/
  1446. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1447. {
  1448. struct map_session_data *sd = NULL;
  1449. //Remove player from map server
  1450. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1451. map_quit(sd);
  1452. return 0;
  1453. }
  1454. /*==========================================
  1455. *
  1456. *------------------------------------------*/
  1457. void clif_quitsave(int fd,struct map_session_data *sd) {
  1458. if (!battle_config.prevent_logout ||
  1459. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1460. map_quit(sd);
  1461. else if (sd->fd) {
  1462. //Disassociate session from player (session is deleted after this function was called)
  1463. //And set a timer to make him quit later.
  1464. session[sd->fd]->session_data = NULL;
  1465. sd->fd = 0;
  1466. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1467. }
  1468. }
  1469. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1470. /// 0091 <map name>.16B <x>.W <y>.W
  1471. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1472. {
  1473. int fd;
  1474. nullpo_retv(sd);
  1475. fd = sd->fd;
  1476. WFIFOHEAD(fd,packet_len(0x91));
  1477. WFIFOW(fd,0) = 0x91;
  1478. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1479. WFIFOW(fd,18) = x;
  1480. WFIFOW(fd,20) = y;
  1481. WFIFOSET(fd,packet_len(0x91));
  1482. }
  1483. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1484. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1485. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1486. {
  1487. int fd;
  1488. nullpo_retv(sd);
  1489. fd = sd->fd;
  1490. WFIFOHEAD(fd,packet_len(0x92));
  1491. WFIFOW(fd,0) = 0x92;
  1492. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1493. WFIFOW(fd,18) = x;
  1494. WFIFOW(fd,20) = y;
  1495. WFIFOL(fd,22) = htonl(ip);
  1496. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1497. WFIFOSET(fd,packet_len(0x92));
  1498. }
  1499. void clif_blown(struct block_list *bl)
  1500. {
  1501. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1502. // clif_fixpos(bl);
  1503. clif_slide(bl, bl->x, bl->y);
  1504. }
  1505. /// Visually moves(slides) a character to x,y. If the target cell
  1506. /// isn't walkable, the char doesn't move at all. If the char is
  1507. /// sitting it will stand up (ZC_STOPMOVE).
  1508. /// 0088 <id>.L <x>.W <y>.W
  1509. void clif_fixpos(struct block_list *bl)
  1510. {
  1511. unsigned char buf[10];
  1512. nullpo_retv(bl);
  1513. WBUFW(buf,0) = 0x88;
  1514. WBUFL(buf,2) = bl->id;
  1515. WBUFW(buf,6) = bl->x;
  1516. WBUFW(buf,8) = bl->y;
  1517. clif_send(buf, packet_len(0x88), bl, AREA);
  1518. if( disguised(bl) )
  1519. {
  1520. WBUFL(buf,2) = -bl->id;
  1521. clif_send(buf, packet_len(0x88), bl, SELF);
  1522. }
  1523. }
  1524. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1525. /// 00c4 <shop id>.L
  1526. void clif_npcbuysell(struct map_session_data* sd, int id)
  1527. {
  1528. int fd;
  1529. nullpo_retv(sd);
  1530. fd=sd->fd;
  1531. WFIFOHEAD(fd, packet_len(0xc4));
  1532. WFIFOW(fd,0)=0xc4;
  1533. WFIFOL(fd,2)=id;
  1534. WFIFOSET(fd,packet_len(0xc4));
  1535. }
  1536. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1537. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1538. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1539. {
  1540. int fd,i,c;
  1541. nullpo_retv(sd);
  1542. nullpo_retv(nd);
  1543. fd = sd->fd;
  1544. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1545. WFIFOW(fd,0) = 0xc6;
  1546. c = 0;
  1547. for( i = 0; i < nd->u.shop.count; i++ )
  1548. {
  1549. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1550. int val = nd->u.shop.shop_item[i].value;
  1551. if( id == NULL )
  1552. continue;
  1553. WFIFOL(fd, 4+c*11) = val;
  1554. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1555. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1556. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1557. c++;
  1558. }
  1559. WFIFOW(fd,2) = 4 + c*11;
  1560. WFIFOSET(fd,WFIFOW(fd,2));
  1561. }
  1562. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1563. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1564. void clif_selllist(struct map_session_data *sd)
  1565. {
  1566. int fd,i,c=0,val;
  1567. nullpo_retv(sd);
  1568. fd=sd->fd;
  1569. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1570. WFIFOW(fd,0)=0xc7;
  1571. for( i = 0; i < MAX_INVENTORY; i++ )
  1572. {
  1573. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1574. {
  1575. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1576. continue;
  1577. if( sd->status.inventory[i].expire_time )
  1578. continue; // Cannot Sell Rental Items
  1579. val=sd->inventory_data[i]->value_sell;
  1580. if( val < 0 )
  1581. continue;
  1582. WFIFOW(fd,4+c*10)=i+2;
  1583. WFIFOL(fd,6+c*10)=val;
  1584. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1585. c++;
  1586. }
  1587. }
  1588. WFIFOW(fd,2)=c*10+4;
  1589. WFIFOSET(fd,WFIFOW(fd,2));
  1590. }
  1591. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1592. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1593. /// Client behavior (dialog window):
  1594. /// - disable mouse targeting
  1595. /// - open the dialog window
  1596. /// - set npcid of dialog window (0 by default)
  1597. /// - if set to clear on next mes, clear contents
  1598. /// - append this text
  1599. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1600. {
  1601. int fd = sd->fd;
  1602. int slen = strlen(mes) + 9;
  1603. WFIFOHEAD(fd, slen);
  1604. WFIFOW(fd,0)=0xb4;
  1605. WFIFOW(fd,2)=slen;
  1606. WFIFOL(fd,4)=npcid;
  1607. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1608. WFIFOSET(fd,WFIFOW(fd,2));
  1609. }
  1610. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1611. /// 00b5 <npc id>.L
  1612. /// Client behavior (dialog window):
  1613. /// - disable mouse targeting
  1614. /// - open the dialog window
  1615. /// - add 'next' button
  1616. /// When 'next' is pressed:
  1617. /// - 00B9 <npcid of dialog window>.L
  1618. /// - set to clear on next mes
  1619. /// - remove 'next' button
  1620. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1621. {
  1622. int fd;
  1623. nullpo_retv(sd);
  1624. fd=sd->fd;
  1625. WFIFOHEAD(fd, packet_len(0xb5));
  1626. WFIFOW(fd,0)=0xb5;
  1627. WFIFOL(fd,2)=npcid;
  1628. WFIFOSET(fd,packet_len(0xb5));
  1629. }
  1630. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1631. /// 00b6 <npc id>.L
  1632. /// Client behavior:
  1633. /// - if dialog window is open:
  1634. /// - remove 'next' button
  1635. /// - add 'close' button
  1636. /// - else:
  1637. /// - enable mouse targeting
  1638. /// - close the dialog window
  1639. /// - close the menu window
  1640. /// When 'close' is pressed:
  1641. /// - enable mouse targeting
  1642. /// - close the dialog window
  1643. /// - close the menu window
  1644. /// - 0146 <npcid of dialog window>.L
  1645. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1646. {
  1647. int fd;
  1648. nullpo_retv(sd);
  1649. fd=sd->fd;
  1650. WFIFOHEAD(fd, packet_len(0xb6));
  1651. WFIFOW(fd,0)=0xb6;
  1652. WFIFOL(fd,2)=npcid;
  1653. WFIFOSET(fd,packet_len(0xb6));
  1654. }
  1655. /*==========================================
  1656. *
  1657. *------------------------------------------*/
  1658. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1659. {
  1660. unsigned char *buf;
  1661. int fd = sd->fd;
  1662. sd->state.using_fake_npc = 1;
  1663. WFIFOHEAD(fd, packet_len(0x78));
  1664. buf = WFIFOP(fd,0);
  1665. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1666. WBUFW(buf,0)=0x78;
  1667. #if PACKETVER >= 20071106
  1668. WBUFB(buf,2) = 0; // object type
  1669. buf = WFIFOP(fd,1);
  1670. #endif
  1671. WBUFL(buf,2)=npcid;
  1672. WBUFW(buf,14)=111;
  1673. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1674. WBUFB(buf,49)=5;
  1675. WBUFB(buf,50)=5;
  1676. WFIFOSET(fd, packet_len(0x78));
  1677. }
  1678. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1679. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1680. /// Client behavior:
  1681. /// - disable mouse targeting
  1682. /// - close the menu window
  1683. /// - open the menu window
  1684. /// - add options to the menu (separated in the text by ":")
  1685. /// - set npcid of menu window
  1686. /// - if dialog window is open:
  1687. /// - remove 'next' button
  1688. /// When 'ok' is pressed:
  1689. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1690. /// - close the menu window
  1691. /// When 'cancel' is pressed:
  1692. /// - 00B8 <npcid of menu window>.L <-1>.B
  1693. /// - enable mouse targeting
  1694. /// - close a bunch of windows...
  1695. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1696. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1697. /// TODO investigate behavior of other windows [FlavioJS]
  1698. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1699. {
  1700. int fd = sd->fd;
  1701. int slen = strlen(mes) + 9;
  1702. struct block_list *bl = NULL;
  1703. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1704. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1705. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1706. clif_sendfakenpc(sd, npcid);
  1707. WFIFOHEAD(fd, slen);
  1708. WFIFOW(fd,0)=0xb7;
  1709. WFIFOW(fd,2)=slen;
  1710. WFIFOL(fd,4)=npcid;
  1711. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1712. WFIFOSET(fd,WFIFOW(fd,2));
  1713. }
  1714. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1715. /// 0142 <npc id>.L
  1716. /// Client behavior (inputnum window):
  1717. /// - if npcid exists in the client:
  1718. /// - open the inputnum window
  1719. /// - set npcid of inputnum window
  1720. /// When 'ok' is pressed:
  1721. /// - if inputnum window has text:
  1722. /// - if npcid exists in the client:
  1723. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1724. /// - close inputnum window
  1725. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1726. {
  1727. int fd;
  1728. struct block_list *bl = NULL;
  1729. nullpo_retv(sd);
  1730. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1731. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1732. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1733. clif_sendfakenpc(sd, npcid);
  1734. fd=sd->fd;
  1735. WFIFOHEAD(fd, packet_len(0x142));
  1736. WFIFOW(fd,0)=0x142;
  1737. WFIFOL(fd,2)=npcid;
  1738. WFIFOSET(fd,packet_len(0x142));
  1739. }
  1740. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1741. /// 01d4 <npc id>.L
  1742. /// Client behavior (inputstr window):
  1743. /// - if npcid is 0 or npcid exists in the client:
  1744. /// - open the inputstr window
  1745. /// - set npcid of inputstr window
  1746. /// When 'ok' is pressed:
  1747. /// - if inputstr window has text and isn't an insult(manner.txt):
  1748. /// - if npcid is 0 or npcid exists in the client:
  1749. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1750. /// - close inputstr window
  1751. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1752. {
  1753. int fd;
  1754. struct block_list *bl = NULL;
  1755. nullpo_retv(sd);
  1756. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1757. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1758. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1759. clif_sendfakenpc(sd, npcid);
  1760. fd=sd->fd;
  1761. WFIFOHEAD(fd, packet_len(0x1d4));
  1762. WFIFOW(fd,0)=0x1d4;
  1763. WFIFOL(fd,2)=npcid;
  1764. WFIFOSET(fd,packet_len(0x1d4));
  1765. }
  1766. /// Marks a position on client's minimap (ZC_COMPASS).
  1767. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1768. /// npc id:
  1769. /// is ignored in the client
  1770. /// type:
  1771. /// 0 = display mark for 15 seconds
  1772. /// 1 = display mark until dead or teleported
  1773. /// 2 = remove mark
  1774. /// color:
  1775. /// 0x00RRGGBB
  1776. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1777. {
  1778. int fd;
  1779. nullpo_retv(sd);
  1780. fd=sd->fd;
  1781. WFIFOHEAD(fd, packet_len(0x144));
  1782. WFIFOW(fd,0)=0x144;
  1783. WFIFOL(fd,2)=npc_id;
  1784. WFIFOL(fd,6)=type;
  1785. WFIFOL(fd,10)=x;
  1786. WFIFOL(fd,14)=y;
  1787. WFIFOB(fd,18)=id;
  1788. WFIFOL(fd,19)=color;
  1789. WFIFOSET(fd,packet_len(0x144));
  1790. }
  1791. /// Displays an illustration image.
  1792. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1793. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1794. /// type:
  1795. /// 0 = bottom left corner
  1796. /// 1 = bottom middle
  1797. /// 2 = bottom right corner
  1798. /// 3 = middle of screen, inside a movable window
  1799. /// 4 = middle of screen, movable with a close button, chrome-less
  1800. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1801. {
  1802. int fd;
  1803. nullpo_retv(sd);
  1804. fd=sd->fd;
  1805. WFIFOHEAD(fd, packet_len(0x1b3));
  1806. WFIFOW(fd,0)=0x1b3;
  1807. strncpy((char*)WFIFOP(fd,2),image,64);
  1808. WFIFOB(fd,66)=type;
  1809. WFIFOSET(fd,packet_len(0x1b3));
  1810. }
  1811. /*==========================================
  1812. * Fills in card data from the given item and into the buffer. [Skotlex]
  1813. *------------------------------------------*/
  1814. static void clif_addcards(unsigned char* buf, struct item* item)
  1815. {
  1816. int i=0,j;
  1817. if( item == NULL ) { //Blank data
  1818. WBUFW(buf,0) = 0;
  1819. WBUFW(buf,2) = 0;
  1820. WBUFW(buf,4) = 0;
  1821. WBUFW(buf,6) = 0;
  1822. return;
  1823. }
  1824. if( item->card[0] == CARD0_PET ) { //pet eggs
  1825. WBUFW(buf,0) = 0;
  1826. WBUFW(buf,2) = 0;
  1827. WBUFW(buf,4) = 0;
  1828. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1829. return;
  1830. }
  1831. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1832. WBUFW(buf,0) = item->card[0];
  1833. WBUFW(buf,2) = item->card[1];
  1834. WBUFW(buf,4) = item->card[2];
  1835. WBUFW(buf,6) = item->card[3];
  1836. return;
  1837. }
  1838. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1839. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1840. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1841. //Normal items.
  1842. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1843. WBUFW(buf,0) = j;
  1844. else
  1845. WBUFW(buf,0) = item->card[i];
  1846. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1847. WBUFW(buf,2) = j;
  1848. else
  1849. WBUFW(buf,2) = item->card[i];
  1850. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1851. WBUFW(buf,4) = j;
  1852. else
  1853. WBUFW(buf,4) = item->card[i];
  1854. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1855. WBUFW(buf,6) = j;
  1856. else
  1857. WBUFW(buf,6) = item->card[i];
  1858. }
  1859. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1860. /// 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)
  1861. /// 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)
  1862. /// 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)
  1863. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1864. {
  1865. int fd;
  1866. #if PACKETVER < 20061218
  1867. const int cmd = 0xa0;
  1868. #elif PACKETVER < 20071002
  1869. const int cmd = 0x29a;
  1870. #else
  1871. const int cmd = 0x2d4;
  1872. #endif
  1873. nullpo_retv(sd);
  1874. fd = sd->fd;
  1875. if( !session_isActive(fd) ) //Sasuke-
  1876. return;
  1877. WFIFOHEAD(fd,packet_len(cmd));
  1878. if( fail )
  1879. {
  1880. WFIFOW(fd,0)=cmd;
  1881. WFIFOW(fd,2)=n+2;
  1882. WFIFOW(fd,4)=amount;
  1883. WFIFOW(fd,6)=0;
  1884. WFIFOB(fd,8)=0;
  1885. WFIFOB(fd,9)=0;
  1886. WFIFOB(fd,10)=0;
  1887. WFIFOW(fd,11)=0;
  1888. WFIFOW(fd,13)=0;
  1889. WFIFOW(fd,15)=0;
  1890. WFIFOW(fd,17)=0;
  1891. WFIFOW(fd,19)=0;
  1892. WFIFOB(fd,21)=0;
  1893. WFIFOB(fd,22)=fail;
  1894. #if PACKETVER >= 20061218
  1895. WFIFOL(fd,23)=0;
  1896. #endif
  1897. #if PACKETVER >= 20071002
  1898. WFIFOW(fd,27)=0; // unknown
  1899. #endif
  1900. }
  1901. else
  1902. {
  1903. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1904. return;
  1905. WFIFOW(fd,0)=cmd;
  1906. WFIFOW(fd,2)=n+2;
  1907. WFIFOW(fd,4)=amount;
  1908. if (sd->inventory_data[n]->view_id > 0)
  1909. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1910. else
  1911. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1912. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1913. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1914. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1915. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1916. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1917. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1918. WFIFOB(fd,22)=fail;
  1919. #if PACKETVER >= 20061218
  1920. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1921. #endif
  1922. #if PACKETVER >= 20071002
  1923. WFIFOW(fd,27)=0; // unknown
  1924. #endif
  1925. }
  1926. WFIFOSET(fd,packet_len(cmd));
  1927. }
  1928. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1929. /// 00af <index>.W <amount>.W
  1930. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1931. {
  1932. int fd;
  1933. nullpo_retv(sd);
  1934. fd=sd->fd;
  1935. WFIFOHEAD(fd, packet_len(0xaf));
  1936. WFIFOW(fd,0)=0xaf;
  1937. WFIFOW(fd,2)=n+2;
  1938. WFIFOW(fd,4)=amount;
  1939. WFIFOSET(fd,packet_len(0xaf));
  1940. }
  1941. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1942. /// 07fa <delete type>.W <index>.W <amount>.W
  1943. /// delete type:
  1944. /// 0 = Normal
  1945. /// 1 = Item used for a skill
  1946. /// 2 = Refine failed
  1947. /// 3 = Material changed
  1948. /// 4 = Moved to storage
  1949. /// 5 = Moved to cart
  1950. /// 6 = Item sold
  1951. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1952. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1953. {
  1954. #if PACKETVER < 20091117
  1955. clif_dropitem(sd,n,amount);
  1956. #else
  1957. int fd;
  1958. nullpo_retv(sd);
  1959. fd=sd->fd;
  1960. WFIFOHEAD(fd, packet_len(0x7fa));
  1961. WFIFOW(fd,0)=0x7fa;
  1962. WFIFOW(fd,2)=reason;
  1963. WFIFOW(fd,4)=n+2;
  1964. WFIFOW(fd,6)=amount;
  1965. WFIFOSET(fd,packet_len(0x7fa));
  1966. #endif
  1967. }
  1968. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1969. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1970. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1971. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1972. {
  1973. if (id->view_id > 0)
  1974. WBUFW(buf,n)=id->view_id;
  1975. else
  1976. WBUFW(buf,n)=i->nameid;
  1977. WBUFB(buf,n+2)=itemtype(id->type);
  1978. WBUFB(buf,n+3)=i->identify;
  1979. if (equip >= 0) { //Equippable item
  1980. WBUFW(buf,n+4)=equip;
  1981. WBUFW(buf,n+6)=i->equip;
  1982. WBUFB(buf,n+8)=i->attribute;
  1983. WBUFB(buf,n+9)=i->refine;
  1984. } else { //Stackable item.
  1985. WBUFW(buf,n+4)=i->amount;
  1986. if (equip == -2 && id->equip == EQP_AMMO)
  1987. WBUFW(buf,n+6)=EQP_AMMO;
  1988. else
  1989. WBUFW(buf,n+6)=0;
  1990. }
  1991. }
  1992. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  1993. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1994. void clif_inventorylist(struct map_session_data *sd)
  1995. {
  1996. int i,n,ne,arrow=-1;
  1997. unsigned char *buf;
  1998. unsigned char *bufe;
  1999. #if PACKETVER < 5
  2000. const int s = 10; //Entry size.
  2001. #elif PACKETVER < 20080102
  2002. const int s = 18;
  2003. #else
  2004. const int s = 22;
  2005. #endif
  2006. #if PACKETVER < 20071002
  2007. const int se = 20;
  2008. #elif PACKETVER < 20100629
  2009. const int se = 26;
  2010. #else
  2011. const int se = 28;
  2012. #endif
  2013. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2014. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2015. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2016. {
  2017. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2018. continue;
  2019. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2020. { //Non-stackable (Equippable)
  2021. WBUFW(bufe,ne*se+4)=i+2;
  2022. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2023. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  2024. #if PACKETVER >= 20071002
  2025. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  2026. WBUFW(bufe,ne*se+28)=0; //Unknown
  2027. #endif
  2028. #if PACKETVER >= 20100629
  2029. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2030. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  2031. else
  2032. WBUFW(bufe,ne*se+30)=0;
  2033. #endif
  2034. ne++;
  2035. }
  2036. else
  2037. { //Stackable.
  2038. WBUFW(buf,n*s+4)=i+2;
  2039. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2040. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2041. arrow=i;
  2042. #if PACKETVER >= 5
  2043. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2044. #endif
  2045. #if PACKETVER >= 20080102
  2046. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  2047. #endif
  2048. n++;
  2049. }
  2050. }
  2051. if( n )
  2052. {
  2053. #if PACKETVER < 5
  2054. WBUFW(buf,0)=0xa3;
  2055. #elif PACKETVER < 20080102
  2056. WBUFW(buf,0)=0x1ee;
  2057. #else
  2058. WBUFW(buf,0)=0x2e8;
  2059. #endif
  2060. WBUFW(buf,2)=4+n*s;
  2061. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2062. }
  2063. if( arrow >= 0 )
  2064. clif_arrowequip(sd,arrow);
  2065. if( ne )
  2066. {
  2067. #if PACKETVER < 20071002
  2068. WBUFW(bufe,0)=0xa4;
  2069. #else
  2070. WBUFW(bufe,0)=0x2d0;
  2071. #endif
  2072. WBUFW(bufe,2)=4+ne*se;
  2073. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2074. }
  2075. #if PACKETVER >= 20111122
  2076. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2077. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2078. continue;
  2079. if ( sd->status.inventory[i].favorite )
  2080. clif_favorite_item(sd, i);
  2081. }
  2082. #endif
  2083. if( buf ) aFree(buf);
  2084. if( bufe ) aFree(bufe);
  2085. }
  2086. //Required when items break/get-repaired. Only sends equippable item list.
  2087. void clif_equiplist(struct map_session_data *sd)
  2088. {
  2089. int i,n,fd = sd->fd;
  2090. unsigned char *buf;
  2091. #if PACKETVER < 20071002
  2092. const int cmd = 20;
  2093. #elif PACKETVER < 20100629
  2094. const int cmd = 26;
  2095. #else
  2096. const int cmd = 28;
  2097. #endif
  2098. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2099. buf = WFIFOP(fd,0);
  2100. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2101. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2102. continue;
  2103. if(itemdb_isstackable2(sd->inventory_data[i]))
  2104. continue;
  2105. //Equippable
  2106. WBUFW(buf,n*cmd+4)=i+2;
  2107. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2108. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  2109. #if PACKETVER >= 20071002
  2110. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  2111. WBUFW(buf,n*cmd+28)=0; //Unknown
  2112. #endif
  2113. #if PACKETVER >= 20100629
  2114. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2115. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  2116. else
  2117. WBUFW(buf,n*cmd+30)=0;
  2118. #endif
  2119. n++;
  2120. }
  2121. if (n) {
  2122. #if PACKETVER < 20071002
  2123. WBUFW(buf,0)=0xa4;
  2124. #else
  2125. WBUFW(buf,0)=0x2d0;
  2126. #endif
  2127. WBUFW(buf,2)=4+n*cmd;
  2128. WFIFOSET(fd,WFIFOW(fd,2));
  2129. }
  2130. }
  2131. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2132. {
  2133. struct item_data *id;
  2134. int i,n,ne;
  2135. unsigned char *buf;
  2136. unsigned char *bufe;
  2137. #if PACKETVER < 5
  2138. const int s = 10; //Entry size.
  2139. #elif PACKETVER < 20080102
  2140. const int s = 18;
  2141. #else
  2142. const int s = 22;
  2143. #endif
  2144. #if PACKETVER < 20071002
  2145. const int cmd = 20;
  2146. #elif PACKETVER < 20100629
  2147. const int cmd = 26;
  2148. #else
  2149. const int cmd = 28;
  2150. #endif
  2151. buf = (unsigned char*)aMalloc(items_length * s + 4);
  2152. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  2153. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2154. {
  2155. if( items[i].nameid <= 0 )
  2156. continue;
  2157. id = itemdb_search(items[i].nameid);
  2158. if( !itemdb_isstackable2(id) )
  2159. { //Equippable
  2160. WBUFW(bufe,ne*cmd+4)=i+1;
  2161. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2162. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2163. #if PACKETVER >= 20071002
  2164. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2165. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2166. #endif
  2167. ne++;
  2168. }
  2169. else
  2170. { //Stackable
  2171. WBUFW(buf,n*s+4)=i+1;
  2172. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2173. #if PACKETVER >= 5
  2174. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2175. #endif
  2176. #if PACKETVER >= 20080102
  2177. WBUFL(buf,n*s+22)=items[i].expire_time;
  2178. #endif
  2179. n++;
  2180. }
  2181. }
  2182. if( n )
  2183. {
  2184. #if PACKETVER < 5
  2185. WBUFW(buf,0)=0xa5;
  2186. #elif PACKETVER < 20080102
  2187. WBUFW(buf,0)=0x1f0;
  2188. #else
  2189. WBUFW(buf,0)=0x2ea;
  2190. #endif
  2191. WBUFW(buf,2)=4+n*s;
  2192. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2193. }
  2194. if( ne )
  2195. {
  2196. #if PACKETVER < 20071002
  2197. WBUFW(bufe,0)=0xa6;
  2198. #else
  2199. WBUFW(bufe,0)=0x2d1;
  2200. #endif
  2201. WBUFW(bufe,2)=4+ne*cmd;
  2202. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2203. }
  2204. if( buf ) aFree(buf);
  2205. if( bufe ) aFree(bufe);
  2206. }
  2207. void clif_cartlist(struct map_session_data *sd)
  2208. {
  2209. struct item_data *id;
  2210. int i,n,ne;
  2211. unsigned char *buf;
  2212. unsigned char *bufe;
  2213. #if PACKETVER < 5
  2214. const int s = 10; //Entry size.
  2215. #elif PACKETVER < 20080102
  2216. const int s = 18;
  2217. #else
  2218. const int s = 22;
  2219. #endif
  2220. #if PACKETVER < 20071002
  2221. const int cmd = 20;
  2222. #elif PACKETVER < 20100629
  2223. const int cmd = 26;
  2224. #else
  2225. const int cmd = 28;
  2226. #endif
  2227. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2228. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2229. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2230. {
  2231. if( sd->status.cart[i].nameid <= 0 )
  2232. continue;
  2233. id = itemdb_search(sd->status.cart[i].nameid);
  2234. if( !itemdb_isstackable2(id) )
  2235. { //Equippable
  2236. WBUFW(bufe,ne*cmd+4)=i+2;
  2237. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2238. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2239. #if PACKETVER >= 20071002
  2240. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2241. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2242. #endif
  2243. ne++;
  2244. }
  2245. else
  2246. { //Stackable
  2247. WBUFW(buf,n*s+4)=i+2;
  2248. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2249. #if PACKETVER >= 5
  2250. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2251. #endif
  2252. #if PACKETVER >= 20080102
  2253. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2254. #endif
  2255. n++;
  2256. }
  2257. }
  2258. if( n )
  2259. {
  2260. #if PACKETVER < 5
  2261. WBUFW(buf,0)=0x123;
  2262. #elif PACKETVER < 20080102
  2263. WBUFW(buf,0)=0x1ef;
  2264. #else
  2265. WBUFW(buf,0)=0x2e9;
  2266. #endif
  2267. WBUFW(buf,2)=4+n*s;
  2268. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2269. }
  2270. if( ne )
  2271. {
  2272. #if PACKETVER < 20071002
  2273. WBUFW(bufe,0)=0x122;
  2274. #else
  2275. WBUFW(bufe,0)=0x2d2;
  2276. #endif
  2277. WBUFW(bufe,2)=4+ne*cmd;
  2278. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2279. }
  2280. if( buf ) aFree(buf);
  2281. if( bufe ) aFree(bufe);
  2282. }
  2283. /// Removes cart (ZC_CARTOFF).
  2284. /// 012b
  2285. /// Client behaviour:
  2286. /// Closes the cart storage and removes all it's items from memory.
  2287. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2288. void clif_clearcart(int fd)
  2289. {
  2290. WFIFOHEAD(fd, packet_len(0x12b));
  2291. WFIFOW(fd,0) = 0x12b;
  2292. WFIFOSET(fd, packet_len(0x12b));
  2293. }
  2294. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2295. /// 01eb <account id>.L <x>.W <y>.W
  2296. void clif_guild_xy(struct map_session_data *sd)
  2297. {
  2298. unsigned char buf[10];
  2299. nullpo_retv(sd);
  2300. WBUFW(buf,0)=0x1eb;
  2301. WBUFL(buf,2)=sd->status.account_id;
  2302. WBUFW(buf,6)=sd->bl.x;
  2303. WBUFW(buf,8)=sd->bl.y;
  2304. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2305. }
  2306. /*==========================================
  2307. * Sends x/y dot to a single fd. [Skotlex]
  2308. *------------------------------------------*/
  2309. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2310. {
  2311. if( sd->bg_id )
  2312. return;
  2313. WFIFOHEAD(fd,packet_len(0x1eb));
  2314. WFIFOW(fd,0)=0x1eb;
  2315. WFIFOL(fd,2)=sd->status.account_id;
  2316. WFIFOW(fd,6)=sd->bl.x;
  2317. WFIFOW(fd,8)=sd->bl.y;
  2318. WFIFOSET(fd,packet_len(0x1eb));
  2319. }
  2320. // Guild XY locators [Valaris]
  2321. void clif_guild_xy_remove(struct map_session_data *sd)
  2322. {
  2323. unsigned char buf[10];
  2324. nullpo_retv(sd);
  2325. WBUFW(buf,0)=0x1eb;
  2326. WBUFL(buf,2)=sd->status.account_id;
  2327. WBUFW(buf,6)=-1;
  2328. WBUFW(buf,8)=-1;
  2329. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2330. }
  2331. /*==========================================
  2332. *
  2333. *------------------------------------------*/
  2334. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2335. {
  2336. struct map_session_data *sd, *tsd;
  2337. #if PACKETVER < 20100126
  2338. const int cmd = 0x106;
  2339. #else
  2340. const int cmd = 0x80e;
  2341. #endif
  2342. sd = va_arg(ap, struct map_session_data *);
  2343. tsd = (TBL_PC *)bl;
  2344. nullpo_ret(sd);
  2345. nullpo_ret(tsd);
  2346. if( !tsd->fd || tsd == sd )
  2347. return 0;
  2348. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2349. return 0;
  2350. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2351. WFIFOW(tsd->fd,0) = cmd;
  2352. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2353. #if PACKETVER < 20100126
  2354. if( sd->battle_status.max_hp > INT16_MAX )
  2355. { //To correctly display the %hp bar. [Skotlex]
  2356. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2357. WFIFOW(tsd->fd,8) = 100;
  2358. } else {
  2359. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2360. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2361. }
  2362. #else
  2363. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2364. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2365. #endif
  2366. WFIFOSET(tsd->fd,packet_len(cmd));
  2367. return 0;
  2368. }
  2369. /*==========================================
  2370. * Server tells all players that are allowed to view HP bars
  2371. * and are nearby 'sd' that 'sd' hp bar was updated.
  2372. *------------------------------------------*/
  2373. static int clif_hpmeter(struct map_session_data *sd)
  2374. {
  2375. nullpo_ret(sd);
  2376. 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);
  2377. return 0;
  2378. }
  2379. /// Notifies client of a character parameter change.
  2380. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2381. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2382. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2383. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2384. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2385. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2386. /// TODO: Extract individual packets.
  2387. /// FIXME: Packet lengths from packet_len(cmd)
  2388. void clif_updatestatus(struct map_session_data *sd,int type)
  2389. {
  2390. int fd,len=8;
  2391. nullpo_retv(sd);
  2392. fd=sd->fd;
  2393. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2394. return;
  2395. WFIFOHEAD(fd, 14);
  2396. WFIFOW(fd,0)=0xb0;
  2397. WFIFOW(fd,2)=type;
  2398. switch(type){
  2399. // 00b0
  2400. case SP_WEIGHT:
  2401. pc_updateweightstatus(sd);
  2402. WFIFOHEAD(fd,14);
  2403. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2404. WFIFOW(fd,2)=type;
  2405. WFIFOL(fd,4)=sd->weight;
  2406. break;
  2407. case SP_MAXWEIGHT:
  2408. WFIFOL(fd,4)=sd->max_weight;
  2409. break;
  2410. case SP_SPEED:
  2411. WFIFOL(fd,4)=sd->battle_status.speed;
  2412. break;
  2413. case SP_BASELEVEL:
  2414. WFIFOL(fd,4)=sd->status.base_level;
  2415. break;
  2416. case SP_JOBLEVEL:
  2417. WFIFOL(fd,4)=sd->status.job_level;
  2418. break;
  2419. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2420. WFIFOL(fd,4)=sd->status.karma;
  2421. break;
  2422. case SP_MANNER:
  2423. WFIFOL(fd,4)=sd->status.manner;
  2424. break;
  2425. case SP_STATUSPOINT:
  2426. WFIFOL(fd,4)=sd->status.status_point;
  2427. break;
  2428. case SP_SKILLPOINT:
  2429. WFIFOL(fd,4)=sd->status.skill_point;
  2430. break;
  2431. case SP_HIT:
  2432. WFIFOL(fd,4)=sd->battle_status.hit;
  2433. break;
  2434. case SP_FLEE1:
  2435. WFIFOL(fd,4)=sd->battle_status.flee;
  2436. break;
  2437. case SP_FLEE2:
  2438. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2439. break;
  2440. case SP_MAXHP:
  2441. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2442. break;
  2443. case SP_MAXSP:
  2444. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2445. break;
  2446. case SP_HP:
  2447. WFIFOL(fd,4)=sd->battle_status.hp;
  2448. // TODO: Won't these overwrite the current packet?
  2449. clif_hpmeter(sd);
  2450. if( !battle_config.party_hp_mode && sd->status.party_id )
  2451. clif_party_hp(sd);
  2452. if( sd->bg_id )
  2453. clif_bg_hp(sd);
  2454. break;
  2455. case SP_SP:
  2456. WFIFOL(fd,4)=sd->battle_status.sp;
  2457. break;
  2458. case SP_ASPD:
  2459. WFIFOL(fd,4)=sd->battle_status.amotion;
  2460. break;
  2461. case SP_ATK1:
  2462. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2463. break;
  2464. case SP_DEF1:
  2465. WFIFOL(fd,4)=pc_leftside_def(sd);
  2466. break;
  2467. case SP_MDEF1:
  2468. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2469. break;
  2470. case SP_ATK2:
  2471. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2472. break;
  2473. case SP_DEF2:
  2474. WFIFOL(fd,4)=pc_rightside_def(sd);
  2475. break;
  2476. case SP_MDEF2: {
  2477. //negative check (in case you have something like Berserk active)
  2478. int mdef2 = pc_rightside_mdef(sd);
  2479. WFIFOL(fd,4)=
  2480. #ifndef RENEWAL
  2481. ( mdef2 < 0 ) ? 0 :
  2482. #endif
  2483. mdef2;
  2484. }
  2485. break;
  2486. case SP_CRITICAL:
  2487. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2488. break;
  2489. case SP_MATK1:
  2490. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2491. break;
  2492. case SP_MATK2:
  2493. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2494. break;
  2495. case SP_ZENY:
  2496. WFIFOW(fd,0)=0xb1;
  2497. WFIFOL(fd,4)=sd->status.zeny;
  2498. break;
  2499. case SP_BASEEXP:
  2500. WFIFOW(fd,0)=0xb1;
  2501. WFIFOL(fd,4)=sd->status.base_exp;
  2502. break;
  2503. case SP_JOBEXP:
  2504. WFIFOW(fd,0)=0xb1;
  2505. WFIFOL(fd,4)=sd->status.job_exp;
  2506. break;
  2507. case SP_NEXTBASEEXP:
  2508. WFIFOW(fd,0)=0xb1;
  2509. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2510. break;
  2511. case SP_NEXTJOBEXP:
  2512. WFIFOW(fd,0)=0xb1;
  2513. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2514. break;
  2515. /**
  2516. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2517. **/
  2518. case SP_USTR:
  2519. case SP_UAGI:
  2520. case SP_UVIT:
  2521. case SP_UINT:
  2522. case SP_UDEX:
  2523. case SP_ULUK:
  2524. WFIFOW(fd,0)=0xbe;
  2525. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2526. len=5;
  2527. break;
  2528. /**
  2529. * Tells the client how far it is allowed to attack (weapon range)
  2530. **/
  2531. case SP_ATTACKRANGE:
  2532. WFIFOW(fd,0)=0x13a;
  2533. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2534. len=4;
  2535. break;
  2536. case SP_STR:
  2537. WFIFOW(fd,0)=0x141;
  2538. WFIFOL(fd,2)=type;
  2539. WFIFOL(fd,6)=sd->status.str;
  2540. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2541. len=14;
  2542. break;
  2543. case SP_AGI:
  2544. WFIFOW(fd,0)=0x141;
  2545. WFIFOL(fd,2)=type;
  2546. WFIFOL(fd,6)=sd->status.agi;
  2547. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2548. len=14;
  2549. break;
  2550. case SP_VIT:
  2551. WFIFOW(fd,0)=0x141;
  2552. WFIFOL(fd,2)=type;
  2553. WFIFOL(fd,6)=sd->status.vit;
  2554. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2555. len=14;
  2556. break;
  2557. case SP_INT:
  2558. WFIFOW(fd,0)=0x141;
  2559. WFIFOL(fd,2)=type;
  2560. WFIFOL(fd,6)=sd->status.int_;
  2561. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2562. len=14;
  2563. break;
  2564. case SP_DEX:
  2565. WFIFOW(fd,0)=0x141;
  2566. WFIFOL(fd,2)=type;
  2567. WFIFOL(fd,6)=sd->status.dex;
  2568. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2569. len=14;
  2570. break;
  2571. case SP_LUK:
  2572. WFIFOW(fd,0)=0x141;
  2573. WFIFOL(fd,2)=type;
  2574. WFIFOL(fd,6)=sd->status.luk;
  2575. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2576. len=14;
  2577. break;
  2578. case SP_CARTINFO:
  2579. WFIFOW(fd,0)=0x121;
  2580. WFIFOW(fd,2)=sd->cart_num;
  2581. WFIFOW(fd,4)=MAX_CART;
  2582. WFIFOL(fd,6)=sd->cart_weight;
  2583. WFIFOL(fd,10)=sd->cart_weight_max;
  2584. len=14;
  2585. break;
  2586. default:
  2587. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2588. return;
  2589. }
  2590. WFIFOSET(fd,len);
  2591. }
  2592. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2593. /// 01ab <account id>.L <var id>.W <value>.L
  2594. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2595. {
  2596. unsigned char buf[12];
  2597. nullpo_retv(sd);
  2598. WBUFW(buf,0)=0x1ab;
  2599. WBUFL(buf,2)=sd->bl.id;
  2600. WBUFW(buf,6)=type;
  2601. switch(type)
  2602. {
  2603. case SP_MANNER:
  2604. WBUFL(buf,8)=val;
  2605. break;
  2606. default:
  2607. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2608. return;
  2609. }
  2610. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2611. }
  2612. /// Updates sprite/style properties of an object.
  2613. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2614. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2615. void clif_changelook(struct block_list *bl,int type,int val)
  2616. {
  2617. unsigned char buf[16];
  2618. struct map_session_data* sd;
  2619. struct status_change* sc;
  2620. struct view_data* vd;
  2621. enum send_target target = AREA;
  2622. nullpo_retv(bl);
  2623. sd = BL_CAST(BL_PC, bl);
  2624. sc = status_get_sc(bl);
  2625. vd = status_get_viewdata(bl);
  2626. //nullpo_ret(vd);
  2627. if( vd ) //temp hack to let Warp Portal change appearance
  2628. switch(type)
  2629. {
  2630. case LOOK_WEAPON:
  2631. if (sd)
  2632. {
  2633. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2634. val = vd->weapon;
  2635. }
  2636. else vd->weapon = val;
  2637. break;
  2638. case LOOK_SHIELD:
  2639. if (sd)
  2640. {
  2641. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2642. val = vd->shield;
  2643. }
  2644. else vd->shield = val;
  2645. break;
  2646. case LOOK_BASE:
  2647. vd->class_ = val;
  2648. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER || vd->class_ == JOB_HANBOK)
  2649. vd->weapon = vd->shield = 0;
  2650. if (vd->cloth_color && (
  2651. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2652. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2653. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2654. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette)
  2655. ))
  2656. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2657. break;
  2658. case LOOK_HAIR:
  2659. vd->hair_style = val;
  2660. break;
  2661. case LOOK_HEAD_BOTTOM:
  2662. vd->head_bottom = val;
  2663. break;
  2664. case LOOK_HEAD_TOP:
  2665. vd->head_top = val;
  2666. break;
  2667. case LOOK_HEAD_MID:
  2668. vd->head_mid = val;
  2669. break;
  2670. case LOOK_HAIR_COLOR:
  2671. vd->hair_color = val;
  2672. break;
  2673. case LOOK_CLOTHES_COLOR:
  2674. if (val && (
  2675. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2676. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2677. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2678. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette)
  2679. ))
  2680. val = 0;
  2681. vd->cloth_color = val;
  2682. break;
  2683. case LOOK_SHOES:
  2684. #if PACKETVER > 3
  2685. if (sd) {
  2686. int n;
  2687. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2688. if(sd->inventory_data[n]->view_id > 0)
  2689. val = sd->inventory_data[n]->view_id;
  2690. else
  2691. val = sd->status.inventory[n].nameid;
  2692. } else
  2693. val = 0;
  2694. }
  2695. #endif
  2696. //Shoes? No packet uses this....
  2697. break;
  2698. case LOOK_BODY:
  2699. // unknown purpose
  2700. break;
  2701. case LOOK_ROBE:
  2702. #if PACKETVER < 20110111
  2703. return;
  2704. #else
  2705. vd->robe = val;
  2706. #endif
  2707. break;
  2708. }
  2709. // prevent leaking the presence of GM-hidden objects
  2710. if( sc && sc->option&OPTION_INVISIBLE )
  2711. target = SELF;
  2712. #if PACKETVER < 4
  2713. WBUFW(buf,0)=0xc3;
  2714. WBUFL(buf,2)=bl->id;
  2715. WBUFB(buf,6)=type;
  2716. WBUFB(buf,7)=val;
  2717. clif_send(buf,packet_len(0xc3),bl,target);
  2718. #else
  2719. WBUFW(buf,0)=0x1d7;
  2720. WBUFL(buf,2)=bl->id;
  2721. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2722. WBUFB(buf,6)=LOOK_WEAPON;
  2723. WBUFW(buf,7)=vd->weapon;
  2724. WBUFW(buf,9)=vd->shield;
  2725. } else {
  2726. WBUFB(buf,6)=type;
  2727. WBUFL(buf,7)=val;
  2728. }
  2729. clif_send(buf,packet_len(0x1d7),bl,target);
  2730. #endif
  2731. }
  2732. //Sends a change-base-look packet required for traps as they are triggered.
  2733. void clif_changetraplook(struct block_list *bl,int val)
  2734. {
  2735. unsigned char buf[32];
  2736. #if PACKETVER < 4
  2737. WBUFW(buf,0)=0xc3;
  2738. WBUFL(buf,2)=bl->id;
  2739. WBUFB(buf,6)=LOOK_BASE;
  2740. WBUFB(buf,7)=val;
  2741. clif_send(buf,packet_len(0xc3),bl,AREA);
  2742. #else
  2743. WBUFW(buf,0)=0x1d7;
  2744. WBUFL(buf,2)=bl->id;
  2745. WBUFB(buf,6)=LOOK_BASE;
  2746. WBUFW(buf,7)=val;
  2747. WBUFW(buf,9)=0;
  2748. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2749. #endif
  2750. }
  2751. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2752. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2753. {
  2754. unsigned char buf[32];
  2755. #if PACKETVER < 4
  2756. WBUFW(buf,0)=0xc3;
  2757. WBUFL(buf,2)=id;
  2758. WBUFB(buf,6)=type;
  2759. WBUFB(buf,7)=val;
  2760. clif_send(buf,packet_len(0xc3),bl,target);
  2761. #else
  2762. WBUFW(buf,0)=0x1d7;
  2763. WBUFL(buf,2)=id;
  2764. WBUFB(buf,6)=type;
  2765. WBUFW(buf,7)=val;
  2766. WBUFW(buf,9)=0;
  2767. clif_send(buf,packet_len(0x1d7),bl,target);
  2768. #endif
  2769. }
  2770. /// Character status (ZC_STATUS).
  2771. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2772. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2773. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2774. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2775. void clif_initialstatus(struct map_session_data *sd)
  2776. {
  2777. int fd, mdef2;
  2778. unsigned char *buf;
  2779. nullpo_retv(sd);
  2780. fd=sd->fd;
  2781. WFIFOHEAD(fd,packet_len(0xbd));
  2782. buf=WFIFOP(fd,0);
  2783. WBUFW(buf,0)=0xbd;
  2784. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2785. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2786. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2787. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2788. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2789. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2790. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2791. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2792. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2793. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2794. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2795. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2796. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2797. WBUFW(buf,16) = pc_leftside_atk(sd);
  2798. WBUFW(buf,18) = pc_rightside_atk(sd);
  2799. WBUFW(buf,20) = pc_rightside_matk(sd);
  2800. WBUFW(buf,22) = pc_leftside_matk(sd);
  2801. WBUFW(buf,24) = pc_leftside_def(sd);
  2802. WBUFW(buf,26) = pc_rightside_def(sd);
  2803. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2804. mdef2 = pc_rightside_mdef(sd);
  2805. WBUFW(buf,30) =
  2806. #ifndef RENEWAL
  2807. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2808. #endif
  2809. mdef2;
  2810. WBUFW(buf,32) = sd->battle_status.hit;
  2811. WBUFW(buf,34) = sd->battle_status.flee;
  2812. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2813. WBUFW(buf,38) = sd->battle_status.cri/10;
  2814. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2815. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2816. WFIFOSET(fd,packet_len(0xbd));
  2817. clif_updatestatus(sd,SP_STR);
  2818. clif_updatestatus(sd,SP_AGI);
  2819. clif_updatestatus(sd,SP_VIT);
  2820. clif_updatestatus(sd,SP_INT);
  2821. clif_updatestatus(sd,SP_DEX);
  2822. clif_updatestatus(sd,SP_LUK);
  2823. clif_updatestatus(sd,SP_ATTACKRANGE);
  2824. clif_updatestatus(sd,SP_ASPD);
  2825. }
  2826. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2827. /// 013c <index>.W
  2828. void clif_arrowequip(struct map_session_data *sd,int val)
  2829. {
  2830. int fd;
  2831. nullpo_retv(sd);
  2832. pc_stop_attack(sd); // [Valaris]
  2833. fd=sd->fd;
  2834. WFIFOHEAD(fd, packet_len(0x013c));
  2835. WFIFOW(fd,0)=0x013c;
  2836. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2837. WFIFOSET(fd,packet_len(0x013c));
  2838. }
  2839. /// Ammunition action message (ZC_ACTION_FAILURE).
  2840. /// 013b <type>.W
  2841. /// type:
  2842. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2843. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2844. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2845. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2846. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2847. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2848. void clif_arrow_fail(struct map_session_data *sd,int type)
  2849. {
  2850. int fd;
  2851. nullpo_retv(sd);
  2852. fd=sd->fd;
  2853. WFIFOHEAD(fd, packet_len(0x013b));
  2854. WFIFOW(fd,0)=0x013b;
  2855. WFIFOW(fd,2)=type;
  2856. WFIFOSET(fd,packet_len(0x013b));
  2857. }
  2858. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2859. /// 01ad <packet len>.W { <name id>.W }*
  2860. void clif_arrow_create_list(struct map_session_data *sd)
  2861. {
  2862. int i, c, j;
  2863. int fd;
  2864. nullpo_retv(sd);
  2865. fd = sd->fd;
  2866. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2867. WFIFOW(fd,0) = 0x1ad;
  2868. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2869. if (skill_arrow_db[i].nameid > 0 &&
  2870. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2871. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2872. {
  2873. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2874. WFIFOW(fd,c*2+4) = j;
  2875. else
  2876. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2877. c++;
  2878. }
  2879. }
  2880. WFIFOW(fd,2) = c*2+4;
  2881. WFIFOSET(fd, WFIFOW(fd,2));
  2882. if (c > 0) {
  2883. sd->menuskill_id = AC_MAKINGARROW;
  2884. sd->menuskill_val = c;
  2885. }
  2886. }
  2887. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2888. /// 00bc <status id>.W <result>.B <value>.B
  2889. /// status id:
  2890. /// SP_STR ~ SP_LUK
  2891. /// result:
  2892. /// 0 = failure
  2893. /// 1 = success
  2894. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2895. {
  2896. int fd;
  2897. nullpo_retv(sd);
  2898. fd=sd->fd;
  2899. WFIFOHEAD(fd,packet_len(0xbc));
  2900. WFIFOW(fd,0)=0xbc;
  2901. WFIFOW(fd,2)=type;
  2902. WFIFOB(fd,4)=ok;
  2903. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2904. WFIFOSET(fd,packet_len(0xbc));
  2905. }
  2906. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2907. /// 00aa <index>.W <equip location>.W <result>.B
  2908. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2909. /// result:
  2910. /// 0 = failure
  2911. /// 1 = success
  2912. /// 2 = failure due to low level
  2913. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2914. {
  2915. int fd;
  2916. nullpo_retv(sd);
  2917. fd=sd->fd;
  2918. WFIFOHEAD(fd,packet_len(0xaa));
  2919. WFIFOW(fd,0)=0xaa;
  2920. WFIFOW(fd,2)=n+2;
  2921. WFIFOW(fd,4)=pos;
  2922. #if PACKETVER < 20100629
  2923. WFIFOB(fd,6)=ok;
  2924. #else
  2925. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2926. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2927. else
  2928. WFIFOW(fd,6)=0;
  2929. WFIFOB(fd,8)=ok;
  2930. #endif
  2931. WFIFOSET(fd,packet_len(0xaa));
  2932. }
  2933. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2934. /// 00ac <index>.W <equip location>.W <result>.B
  2935. /// result:
  2936. /// 0 = failure
  2937. /// 1 = success
  2938. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2939. {
  2940. int fd;
  2941. nullpo_retv(sd);
  2942. fd=sd->fd;
  2943. WFIFOHEAD(fd,packet_len(0xac));
  2944. WFIFOW(fd,0)=0xac;
  2945. WFIFOW(fd,2)=n+2;
  2946. WFIFOW(fd,4)=pos;
  2947. WFIFOB(fd,6)=ok;
  2948. WFIFOSET(fd,packet_len(0xac));
  2949. }
  2950. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2951. /// 019b <id>.L <effect id>.L
  2952. /// effect id:
  2953. /// 0 = base level up
  2954. /// 1 = job level up
  2955. /// 2 = refine failure
  2956. /// 3 = refine success
  2957. /// 4 = game over
  2958. /// 5 = pharmacy success
  2959. /// 6 = pharmacy failure
  2960. /// 7 = base level up (super novice)
  2961. /// 8 = job level up (super novice)
  2962. /// 9 = base level up (taekwon)
  2963. void clif_misceffect(struct block_list* bl,int type)
  2964. {
  2965. unsigned char buf[32];
  2966. nullpo_retv(bl);
  2967. WBUFW(buf,0) = 0x19b;
  2968. WBUFL(buf,2) = bl->id;
  2969. WBUFL(buf,6) = type;
  2970. clif_send(buf,packet_len(0x19b),bl,AREA);
  2971. }
  2972. /// Notifies clients in the area of a state change.
  2973. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  2974. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  2975. void clif_changeoption(struct block_list* bl)
  2976. {
  2977. unsigned char buf[32];
  2978. struct status_change *sc;
  2979. struct map_session_data* sd;
  2980. nullpo_retv(bl);
  2981. sc = status_get_sc(bl);
  2982. if (!sc) return; //How can an option change if there's no sc?
  2983. sd = BL_CAST(BL_PC, bl);
  2984. #if PACKETVER >= 7
  2985. WBUFW(buf,0) = 0x229;
  2986. WBUFL(buf,2) = bl->id;
  2987. WBUFW(buf,6) = sc->opt1;
  2988. WBUFW(buf,8) = sc->opt2;
  2989. WBUFL(buf,10) = sc->option;
  2990. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2991. if(disguised(bl)) {
  2992. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2993. WBUFL(buf,2) = -bl->id;
  2994. clif_send(buf,packet_len(0x229),bl,SELF);
  2995. WBUFL(buf,2) = bl->id;
  2996. WBUFL(buf,10) = OPTION_INVISIBLE;
  2997. clif_send(buf,packet_len(0x229),bl,SELF);
  2998. } else
  2999. clif_send(buf,packet_len(0x229),bl,AREA);
  3000. #else
  3001. WBUFW(buf,0) = 0x119;
  3002. WBUFL(buf,2) = bl->id;
  3003. WBUFW(buf,6) = sc->opt1;
  3004. WBUFW(buf,8) = sc->opt2;
  3005. WBUFW(buf,10) = sc->option;
  3006. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3007. if(disguised(bl)) {
  3008. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3009. WBUFL(buf,2) = -bl->id;
  3010. clif_send(buf,packet_len(0x119),bl,SELF);
  3011. WBUFL(buf,2) = bl->id;
  3012. WBUFW(buf,10) = OPTION_INVISIBLE;
  3013. clif_send(buf,packet_len(0x119),bl,SELF);
  3014. } else
  3015. clif_send(buf,packet_len(0x119),bl,AREA);
  3016. #endif
  3017. }
  3018. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3019. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3020. void clif_changeoption2(struct block_list* bl)
  3021. {
  3022. unsigned char buf[20];
  3023. struct status_change *sc;
  3024. sc = status_get_sc(bl);
  3025. if (!sc) return; //How can an option change if there's no sc?
  3026. WBUFW(buf,0) = 0x28a;
  3027. WBUFL(buf,2) = bl->id;
  3028. WBUFL(buf,6) = sc->option;
  3029. WBUFL(buf,10) = clif_setlevel(bl);
  3030. WBUFL(buf,14) = sc->opt3;
  3031. if(disguised(bl)) {
  3032. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3033. WBUFL(buf,2) = -bl->id;
  3034. clif_send(buf,packet_len(0x28a),bl,SELF);
  3035. WBUFL(buf,2) = bl->id;
  3036. WBUFL(buf,6) = OPTION_INVISIBLE;
  3037. clif_send(buf,packet_len(0x28a),bl,SELF);
  3038. } else
  3039. clif_send(buf,packet_len(0x28a),bl,AREA);
  3040. }
  3041. /// Notifies the client about the result of an item use request.
  3042. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3043. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3044. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3045. {
  3046. nullpo_retv(sd);
  3047. if(!ok) {
  3048. int fd=sd->fd;
  3049. WFIFOHEAD(fd,packet_len(0xa8));
  3050. WFIFOW(fd,0)=0xa8;
  3051. WFIFOW(fd,2)=index+2;
  3052. WFIFOW(fd,4)=amount;
  3053. WFIFOB(fd,6)=ok;
  3054. WFIFOSET(fd,packet_len(0xa8));
  3055. }
  3056. else {
  3057. #if PACKETVER < 3
  3058. int fd=sd->fd;
  3059. WFIFOHEAD(fd,packet_len(0xa8));
  3060. WFIFOW(fd,0)=0xa8;
  3061. WFIFOW(fd,2)=index+2;
  3062. WFIFOW(fd,4)=amount;
  3063. WFIFOB(fd,6)=ok;
  3064. WFIFOSET(fd,packet_len(0xa8));
  3065. #else
  3066. unsigned char buf[32];
  3067. WBUFW(buf,0)=0x1c8;
  3068. WBUFW(buf,2)=index+2;
  3069. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3070. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3071. else
  3072. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3073. WBUFL(buf,6)=sd->bl.id;
  3074. WBUFW(buf,10)=amount;
  3075. WBUFB(buf,12)=ok;
  3076. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3077. #endif
  3078. }
  3079. }
  3080. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3081. /// 00d6 <flag>.B
  3082. /// flag:
  3083. /// 0 = Room has been successfully created (opens chat room)
  3084. /// 1 = Room limit exceeded
  3085. /// 2 = Same room already exists
  3086. void clif_createchat(struct map_session_data* sd, int flag)
  3087. {
  3088. int fd;
  3089. nullpo_retv(sd);
  3090. fd = sd->fd;
  3091. WFIFOHEAD(fd,packet_len(0xd6));
  3092. WFIFOW(fd,0) = 0xd6;
  3093. WFIFOB(fd,2) = flag;
  3094. WFIFOSET(fd,packet_len(0xd6));
  3095. }
  3096. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3097. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3098. /// type:
  3099. /// 0 = private (password protected)
  3100. /// 1 = public
  3101. /// 2 = arena (npc waiting room)
  3102. /// 3 = PK zone (non-clickable)
  3103. void clif_dispchat(struct chat_data* cd, int fd)
  3104. {
  3105. unsigned char buf[128];
  3106. uint8 type;
  3107. if( cd == NULL || cd->owner == NULL )
  3108. return;
  3109. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3110. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3111. : 1;
  3112. WBUFW(buf, 0) = 0xd7;
  3113. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3114. WBUFL(buf, 4) = cd->owner->id;
  3115. WBUFL(buf, 8) = cd->bl.id;
  3116. WBUFW(buf,12) = cd->limit;
  3117. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3118. WBUFB(buf,16) = type;
  3119. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3120. if( fd ) {
  3121. WFIFOHEAD(fd,WBUFW(buf,2));
  3122. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3123. WFIFOSET(fd,WBUFW(buf,2));
  3124. } else {
  3125. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3126. }
  3127. }
  3128. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3129. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3130. /// type:
  3131. /// 0 = private (password protected)
  3132. /// 1 = public
  3133. /// 2 = arena (npc waiting room)
  3134. /// 3 = PK zone (non-clickable)
  3135. void clif_changechatstatus(struct chat_data* cd)
  3136. {
  3137. unsigned char buf[128];
  3138. uint8 type;
  3139. if( cd == NULL || cd->usersd[0] == NULL )
  3140. return;
  3141. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3142. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3143. : 1;
  3144. WBUFW(buf, 0) = 0xdf;
  3145. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3146. WBUFL(buf, 4) = cd->owner->id;
  3147. WBUFL(buf, 8) = cd->bl.id;
  3148. WBUFW(buf,12) = cd->limit;
  3149. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3150. WBUFB(buf,16) = type;
  3151. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3152. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3153. }
  3154. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3155. /// 00d8 <chat id>.L
  3156. void clif_clearchat(struct chat_data *cd,int fd)
  3157. {
  3158. unsigned char buf[32];
  3159. nullpo_retv(cd);
  3160. WBUFW(buf,0) = 0xd8;
  3161. WBUFL(buf,2) = cd->bl.id;
  3162. if( fd ) {
  3163. WFIFOHEAD(fd,packet_len(0xd8));
  3164. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3165. WFIFOSET(fd,packet_len(0xd8));
  3166. } else {
  3167. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3168. }
  3169. }
  3170. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3171. /// 00da <result>.B
  3172. /// result:
  3173. /// 0 = room full
  3174. /// 1 = wrong password
  3175. /// 2 = kicked
  3176. /// 3 = success (no message)
  3177. /// 4 = no enough zeny
  3178. /// 5 = too low level
  3179. /// 6 = too high level
  3180. /// 7 = unsuitable job class
  3181. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3182. {
  3183. int fd;
  3184. nullpo_retv(sd);
  3185. fd = sd->fd;
  3186. WFIFOHEAD(fd,packet_len(0xda));
  3187. WFIFOW(fd,0) = 0xda;
  3188. WFIFOB(fd,2) = flag;
  3189. WFIFOSET(fd,packet_len(0xda));
  3190. }
  3191. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3192. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3193. /// role:
  3194. /// 0 = owner (menu)
  3195. /// 1 = normal
  3196. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3197. {
  3198. int fd;
  3199. int i,t;
  3200. nullpo_retv(sd);
  3201. nullpo_retv(cd);
  3202. fd = sd->fd;
  3203. if (!session_isActive(fd))
  3204. return;
  3205. t = (int)(cd->owner->type == BL_NPC);
  3206. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3207. WFIFOW(fd, 0) = 0xdb;
  3208. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3209. WFIFOL(fd, 4) = cd->bl.id;
  3210. if(cd->owner->type == BL_NPC){
  3211. WFIFOL(fd, 30) = 1;
  3212. WFIFOL(fd, 8) = 0;
  3213. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3214. for (i = 0; i < cd->users; i++) {
  3215. WFIFOL(fd, 8+(i+1)*28) = 1;
  3216. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3217. }
  3218. } else
  3219. for (i = 0; i < cd->users; i++) {
  3220. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3221. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3222. }
  3223. WFIFOSET(fd, WFIFOW(fd, 2));
  3224. }
  3225. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3226. /// 00dc <users>.W <name>.24B
  3227. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3228. {
  3229. unsigned char buf[32];
  3230. nullpo_retv(sd);
  3231. nullpo_retv(cd);
  3232. WBUFW(buf, 0) = 0xdc;
  3233. WBUFW(buf, 2) = cd->users;
  3234. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3235. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3236. }
  3237. /// Announce the new owner (ZC_ROLE_CHANGE).
  3238. /// 00e1 <role>.L <nick>.24B
  3239. /// role:
  3240. /// 0 = owner (menu)
  3241. /// 1 = normal
  3242. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3243. {
  3244. unsigned char buf[64];
  3245. nullpo_retv(sd);
  3246. nullpo_retv(cd);
  3247. WBUFW(buf, 0) = 0xe1;
  3248. WBUFL(buf, 2) = 1;
  3249. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3250. WBUFW(buf,30) = 0xe1;
  3251. WBUFL(buf,32) = 0;
  3252. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3253. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3254. }
  3255. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3256. /// 00dd <users>.W <nick>.24B <flag>.B
  3257. /// flag:
  3258. /// 0 = left
  3259. /// 1 = kicked
  3260. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3261. {
  3262. unsigned char buf[32];
  3263. nullpo_retv(sd);
  3264. nullpo_retv(cd);
  3265. WBUFW(buf, 0) = 0xdd;
  3266. WBUFW(buf, 2) = cd->users-1;
  3267. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3268. WBUFB(buf,28) = flag;
  3269. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3270. }
  3271. /// Opens a trade request window from char 'name'.
  3272. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3273. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3274. void clif_traderequest(struct map_session_data* sd, const char* name)
  3275. {
  3276. int fd = sd->fd;
  3277. #if PACKETVER < 6
  3278. WFIFOHEAD(fd,packet_len(0xe5));
  3279. WFIFOW(fd,0) = 0xe5;
  3280. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3281. WFIFOSET(fd,packet_len(0xe5));
  3282. #else
  3283. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3284. if( !tsd ) return;
  3285. WFIFOHEAD(fd,packet_len(0x1f4));
  3286. WFIFOW(fd,0) = 0x1f4;
  3287. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3288. WFIFOL(fd,26) = tsd->status.char_id;
  3289. WFIFOW(fd,30) = tsd->status.base_level;
  3290. WFIFOSET(fd,packet_len(0x1f4));
  3291. #endif
  3292. }
  3293. /// Reply to a trade-request.
  3294. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3295. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3296. /// result:
  3297. /// 0 = Char is too far
  3298. /// 1 = Character does not exist
  3299. /// 2 = Trade failed
  3300. /// 3 = Accept
  3301. /// 4 = Cancel
  3302. /// 5 = Busy
  3303. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3304. {
  3305. int fd = sd->fd;
  3306. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3307. if( PACKETVER < 6 || !tsd ) {
  3308. WFIFOHEAD(fd,packet_len(0xe7));
  3309. WFIFOW(fd,0) = 0xe7;
  3310. WFIFOB(fd,2) = type;
  3311. WFIFOSET(fd,packet_len(0xe7));
  3312. } else {
  3313. WFIFOHEAD(fd,packet_len(0x1f5));
  3314. WFIFOW(fd,0) = 0x1f5;
  3315. WFIFOB(fd,2) = type;
  3316. WFIFOL(fd,3) = tsd->status.char_id;
  3317. WFIFOW(fd,7) = tsd->status.base_level;
  3318. WFIFOSET(fd,packet_len(0x1f5));
  3319. }
  3320. }
  3321. /// Notifies the client about an item from other player in current trade.
  3322. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3323. /// 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)
  3324. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3325. {
  3326. int fd;
  3327. unsigned char *buf;
  3328. #if PACKETVER < 20100223
  3329. const int cmd = 0xe9;
  3330. #else
  3331. const int cmd = 0x80f;
  3332. #endif
  3333. nullpo_retv(sd);
  3334. nullpo_retv(tsd);
  3335. fd = tsd->fd;
  3336. buf = WFIFOP(fd,0);
  3337. WFIFOHEAD(fd,packet_len(cmd));
  3338. WBUFW(buf,0) = cmd;
  3339. if( index == 0 )
  3340. {
  3341. #if PACKETVER < 20100223
  3342. WBUFL(buf,2) = amount; //amount
  3343. WBUFW(buf,6) = 0; // type id
  3344. #else
  3345. WBUFW(buf,2) = 0; // type id
  3346. WBUFB(buf,4) = 0; // item type
  3347. WBUFL(buf,5) = amount; // amount
  3348. buf = WBUFP(buf,1); //Advance 1B
  3349. #endif
  3350. WBUFB(buf,8) = 0; //identify flag
  3351. WBUFB(buf,9) = 0; // attribute
  3352. WBUFB(buf,10)= 0; //refine
  3353. WBUFW(buf,11)= 0; //card (4w)
  3354. WBUFW(buf,13)= 0; //card (4w)
  3355. WBUFW(buf,15)= 0; //card (4w)
  3356. WBUFW(buf,17)= 0; //card (4w)
  3357. }
  3358. else
  3359. {
  3360. index -= 2; //index fix
  3361. #if PACKETVER < 20100223
  3362. WBUFL(buf,2) = amount; //amount
  3363. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3364. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3365. else
  3366. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3367. #else
  3368. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3369. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3370. else
  3371. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3372. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3373. WBUFL(buf,5) = amount; // amount
  3374. buf = WBUFP(buf,1); //Advance 1B
  3375. #endif
  3376. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3377. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3378. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3379. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3380. }
  3381. WFIFOSET(fd,packet_len(cmd));
  3382. }
  3383. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3384. /// 00ea <index>.W <result>.B
  3385. /// result:
  3386. /// 0 = success
  3387. /// 1 = overweight
  3388. /// 2 = trade canceled
  3389. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3390. {
  3391. int fd;
  3392. nullpo_retv(sd);
  3393. fd = sd->fd;
  3394. WFIFOHEAD(fd,packet_len(0xea));
  3395. WFIFOW(fd,0) = 0xea;
  3396. WFIFOW(fd,2) = index;
  3397. WFIFOB(fd,4) = fail;
  3398. WFIFOSET(fd,packet_len(0xea));
  3399. }
  3400. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3401. /// 00ec <who>.B
  3402. /// who:
  3403. /// 0 = self
  3404. /// 1 = other player
  3405. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3406. {
  3407. int fd;
  3408. nullpo_retv(sd);
  3409. fd = sd->fd;
  3410. WFIFOHEAD(fd,packet_len(0xec));
  3411. WFIFOW(fd,0) = 0xec;
  3412. WFIFOB(fd,2) = fail;
  3413. WFIFOSET(fd,packet_len(0xec));
  3414. }
  3415. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3416. /// 00ee
  3417. void clif_tradecancelled(struct map_session_data* sd)
  3418. {
  3419. int fd;
  3420. nullpo_retv(sd);
  3421. fd = sd->fd;
  3422. WFIFOHEAD(fd,packet_len(0xee));
  3423. WFIFOW(fd,0) = 0xee;
  3424. WFIFOSET(fd,packet_len(0xee));
  3425. }
  3426. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3427. /// 00f0 <result>.B
  3428. /// result:
  3429. /// 0 = success
  3430. /// 1 = failure
  3431. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3432. {
  3433. int fd;
  3434. nullpo_retv(sd);
  3435. fd = sd->fd;
  3436. WFIFOHEAD(fd,packet_len(0xf0));
  3437. WFIFOW(fd,0) = 0xf0;
  3438. WFIFOB(fd,2) = fail;
  3439. WFIFOSET(fd,packet_len(0xf0));
  3440. }
  3441. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3442. /// 00f1
  3443. /// NOTE: Unknown purpose. Items are not removed until the window is
  3444. /// refreshed (ex. by putting another item in there).
  3445. void clif_tradeundo(struct map_session_data* sd)
  3446. {
  3447. int fd = sd->fd;
  3448. WFIFOHEAD(fd,packet_len(0xf1));
  3449. WFIFOW(fd,0) = 0xf1;
  3450. WFIFOSET(fd,packet_len(0xf1));
  3451. }
  3452. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3453. /// 00f2 <current count>.W <max count>.W
  3454. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3455. {
  3456. int fd;
  3457. nullpo_retv(sd);
  3458. fd=sd->fd;
  3459. WFIFOHEAD(fd,packet_len(0xf2));
  3460. WFIFOW(fd,0) = 0xf2;
  3461. WFIFOW(fd,2) = amount;
  3462. WFIFOW(fd,4) = max_amount;
  3463. WFIFOSET(fd,packet_len(0xf2));
  3464. }
  3465. /// Notifies the client of an item being added to the storage.
  3466. /// 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)
  3467. /// 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)
  3468. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3469. {
  3470. int view,fd;
  3471. nullpo_retv(sd);
  3472. nullpo_retv(i);
  3473. fd=sd->fd;
  3474. view = itemdb_viewid(i->nameid);
  3475. #if PACKETVER < 5
  3476. WFIFOHEAD(fd,packet_len(0xf4));
  3477. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3478. WFIFOW(fd, 2) = index+1; // index
  3479. WFIFOL(fd, 4) = amount; // amount
  3480. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3481. WFIFOB(fd,10) = i->identify; //identify flag
  3482. WFIFOB(fd,11) = i->attribute; // attribute
  3483. WFIFOB(fd,12) = i->refine; //refine
  3484. clif_addcards(WFIFOP(fd,13), i);
  3485. WFIFOSET(fd,packet_len(0xf4));
  3486. #else
  3487. WFIFOHEAD(fd,packet_len(0x1c4));
  3488. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3489. WFIFOW(fd, 2) = index+1; // index
  3490. WFIFOL(fd, 4) = amount; // amount
  3491. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3492. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3493. WFIFOB(fd,11) = i->identify; //identify flag
  3494. WFIFOB(fd,12) = i->attribute; // attribute
  3495. WFIFOB(fd,13) = i->refine; //refine
  3496. clif_addcards(WFIFOP(fd,14), i);
  3497. WFIFOSET(fd,packet_len(0x1c4));
  3498. #endif
  3499. }
  3500. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3501. /// 00f6 <index>.W <amount>.L
  3502. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3503. {
  3504. int fd;
  3505. nullpo_retv(sd);
  3506. fd=sd->fd;
  3507. WFIFOHEAD(fd,packet_len(0xf6));
  3508. WFIFOW(fd,0)=0xf6; // Storage item removed
  3509. WFIFOW(fd,2)=index+1;
  3510. WFIFOL(fd,4)=amount;
  3511. WFIFOSET(fd,packet_len(0xf6));
  3512. }
  3513. /// Closes storage (ZC_CLOSE_STORE).
  3514. /// 00f8
  3515. void clif_storageclose(struct map_session_data* sd)
  3516. {
  3517. int fd;
  3518. nullpo_retv(sd);
  3519. fd=sd->fd;
  3520. WFIFOHEAD(fd,packet_len(0xf8));
  3521. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3522. WFIFOSET(fd,packet_len(0xf8));
  3523. }
  3524. /*==========================================
  3525. * Server tells 'sd' player client the abouts of 'dstsd' player
  3526. *------------------------------------------*/
  3527. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3528. {
  3529. struct block_list *d_bl;
  3530. int i;
  3531. if( dstsd->chatID ) {
  3532. struct chat_data *cd = NULL;
  3533. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3534. clif_dispchat(cd,sd->fd);
  3535. } else if( dstsd->state.vending )
  3536. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3537. else if( dstsd->state.buyingstore )
  3538. clif_buyingstore_entry_single(sd, dstsd);
  3539. if(dstsd->spiritball > 0)
  3540. clif_spiritball_single(sd->fd, dstsd);
  3541. for(i = 1; i < 5; i++){
  3542. if( dstsd->talisman[i] > 0 )
  3543. clif_talisman_single(sd->fd, dstsd, i);
  3544. }
  3545. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3546. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3547. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3548. }
  3549. #ifdef NEW_CARTS
  3550. if( dstsd->sc.data[SC_PUSH_CART] )
  3551. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3552. #endif
  3553. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3554. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3555. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3556. )
  3557. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3558. // display link (sd - dstsd) to sd
  3559. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3560. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3561. // display links (dstsd - devotees) to sd
  3562. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3563. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3564. // display link (dstsd - crusader) to sd
  3565. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3566. clif_devotion(d_bl, sd);
  3567. }
  3568. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3569. {
  3570. uint8 buf[128];
  3571. struct unit_data *ud;
  3572. struct view_data *vd;
  3573. int len;
  3574. vd = status_get_viewdata(bl);
  3575. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3576. return;
  3577. /**
  3578. * Hide NPC from maya purple card.
  3579. **/
  3580. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3581. return;
  3582. ud = unit_bl2ud(bl);
  3583. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3584. clif_send(buf,len,&sd->bl,SELF);
  3585. if (vd->cloth_color)
  3586. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3587. switch (bl->type)
  3588. {
  3589. case BL_PC:
  3590. {
  3591. TBL_PC* tsd = (TBL_PC*)bl;
  3592. clif_getareachar_pc(sd, tsd);
  3593. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3594. clif_specialeffect_single(bl,423,sd->fd);
  3595. else if(tsd->state.size==SZ_MEDIUM)
  3596. clif_specialeffect_single(bl,421,sd->fd);
  3597. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3598. clif_sendbgemblem_single(sd->fd,tsd);
  3599. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3600. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3601. if ( tsd->status.robe )
  3602. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3603. }
  3604. break;
  3605. case BL_MER: // Devotion Effects
  3606. if( ((TBL_MER*)bl)->devotion_flag )
  3607. clif_devotion(bl, sd);
  3608. break;
  3609. case BL_NPC:
  3610. {
  3611. TBL_NPC* nd = (TBL_NPC*)bl;
  3612. if( nd->chat_id )
  3613. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3614. if( nd->size == SZ_BIG )
  3615. clif_specialeffect_single(bl,423,sd->fd);
  3616. else if( nd->size == SZ_MEDIUM )
  3617. clif_specialeffect_single(bl,421,sd->fd);
  3618. }
  3619. break;
  3620. case BL_MOB:
  3621. {
  3622. TBL_MOB* md = (TBL_MOB*)bl;
  3623. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3624. clif_specialeffect_single(bl,423,sd->fd);
  3625. else if(md->special_state.size==SZ_MEDIUM)
  3626. clif_specialeffect_single(bl,421,sd->fd);
  3627. #if PACKETVER >= 20120404
  3628. if( !(md->status.mode&MD_BOSS) ){
  3629. int i;
  3630. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3631. if( md->dmglog[i].id == sd->status.char_id )
  3632. clif_monster_hp_bar(md, sd->fd);
  3633. }
  3634. #endif
  3635. }
  3636. break;
  3637. case BL_PET:
  3638. if (vd->head_bottom)
  3639. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3640. break;
  3641. }
  3642. }
  3643. //Modifies the type of damage according to status changes [Skotlex]
  3644. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3645. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3646. {
  3647. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3648. }
  3649. /*==========================================
  3650. * Estimates walk delay based on the damage criteria. [Skotlex]
  3651. *------------------------------------------*/
  3652. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3653. {
  3654. if (type == 4 || type == 9 || damage <=0)
  3655. return 0;
  3656. if (bl->type == BL_PC) {
  3657. if (battle_config.pc_walk_delay_rate != 100)
  3658. delay = delay*battle_config.pc_walk_delay_rate/100;
  3659. } else
  3660. if (battle_config.walk_delay_rate != 100)
  3661. delay = delay*battle_config.walk_delay_rate/100;
  3662. if (div_ > 1) //Multi-hit skills mean higher delays.
  3663. delay += battle_config.multihit_delay*(div_-1);
  3664. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3665. }
  3666. /// Sends a 'damage' packet (src performs action on dst)
  3667. /// 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)
  3668. /// 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)
  3669. /// type:
  3670. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3671. /// 1 = pick up item
  3672. /// 2 = sit down
  3673. /// 3 = stand up
  3674. /// 4 = damage (endure)
  3675. /// 5 = (splash?)
  3676. /// 6 = (skill?)
  3677. /// 7 = (repeat damage?)
  3678. /// 8 = multi-hit damage
  3679. /// 9 = multi-hit damage (endure)
  3680. /// 10 = critical hit
  3681. /// 11 = lucky dodge
  3682. /// 12 = (touch skill?)
  3683. 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)
  3684. {
  3685. unsigned char buf[33];
  3686. struct status_change *sc;
  3687. #if PACKETVER < 20071113
  3688. const int cmd = 0x8a;
  3689. #else
  3690. const int cmd = 0x2e1;
  3691. #endif
  3692. nullpo_ret(src);
  3693. nullpo_ret(dst);
  3694. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3695. sc = status_get_sc(dst);
  3696. if(sc && sc->count) {
  3697. if(sc->data[SC_HALLUCINATION]) {
  3698. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3699. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3700. }
  3701. }
  3702. WBUFW(buf,0)=cmd;
  3703. WBUFL(buf,2)=src->id;
  3704. WBUFL(buf,6)=dst->id;
  3705. WBUFL(buf,10)=tick;
  3706. WBUFL(buf,14)=sdelay;
  3707. WBUFL(buf,18)=ddelay;
  3708. #if PACKETVER < 20071113
  3709. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3710. WBUFW(buf,22)=damage?div:0;
  3711. WBUFW(buf,27)=damage2?div:0;
  3712. } else {
  3713. WBUFW(buf,22)=min(damage, INT16_MAX);
  3714. WBUFW(buf,27)=damage2;
  3715. }
  3716. WBUFW(buf,24)=div;
  3717. WBUFB(buf,26)=type;
  3718. #else
  3719. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3720. WBUFL(buf,22)=damage?div:0;
  3721. WBUFL(buf,29)=damage2?div:0;
  3722. } else {
  3723. WBUFL(buf,22)=damage;
  3724. WBUFL(buf,29)=damage2;
  3725. }
  3726. WBUFW(buf,26)=div;
  3727. WBUFB(buf,28)=type;
  3728. #endif
  3729. if(disguised(dst)) {
  3730. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3731. WBUFL(buf,6) = -dst->id;
  3732. clif_send(buf,packet_len(cmd),dst,SELF);
  3733. } else
  3734. clif_send(buf,packet_len(cmd),dst,AREA);
  3735. if(disguised(src)) {
  3736. WBUFL(buf,2) = -src->id;
  3737. if (disguised(dst))
  3738. WBUFL(buf,6) = dst->id;
  3739. #if PACKETVER < 20071113
  3740. if(damage > 0) WBUFW(buf,22) = -1;
  3741. if(damage2 > 0) WBUFW(buf,27) = -1;
  3742. #else
  3743. if(damage > 0) WBUFL(buf,22) = -1;
  3744. if(damage2 > 0) WBUFL(buf,29) = -1;
  3745. #endif
  3746. clif_send(buf,packet_len(cmd),src,SELF);
  3747. }
  3748. if(src == dst) {
  3749. unit_setdir(src,unit_getdir(src));
  3750. }
  3751. //Return adjusted can't walk delay for further processing.
  3752. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3753. }
  3754. /*==========================================
  3755. * src picks up dst
  3756. *------------------------------------------*/
  3757. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3758. {
  3759. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3760. unsigned char buf[32];
  3761. nullpo_retv(src);
  3762. nullpo_retv(dst);
  3763. WBUFW(buf, 0) = 0x8a;
  3764. WBUFL(buf, 2) = src->id;
  3765. WBUFL(buf, 6) = dst->id;
  3766. WBUFB(buf,26) = 1;
  3767. clif_send(buf, packet_len(0x8a), src, AREA);
  3768. }
  3769. /*==========================================
  3770. * inform clients in area that `bl` is sitting
  3771. *------------------------------------------*/
  3772. void clif_sitting(struct block_list* bl)
  3773. {
  3774. unsigned char buf[32];
  3775. nullpo_retv(bl);
  3776. WBUFW(buf, 0) = 0x8a;
  3777. WBUFL(buf, 2) = bl->id;
  3778. WBUFB(buf,26) = 2;
  3779. clif_send(buf, packet_len(0x8a), bl, AREA);
  3780. if(disguised(bl)) {
  3781. WBUFL(buf, 2) = - bl->id;
  3782. clif_send(buf, packet_len(0x8a), bl, SELF);
  3783. }
  3784. }
  3785. /*==========================================
  3786. * inform clients in area that `bl` is standing
  3787. *------------------------------------------*/
  3788. void clif_standing(struct block_list* bl)
  3789. {
  3790. unsigned char buf[32];
  3791. nullpo_retv(bl);
  3792. WBUFW(buf, 0) = 0x8a;
  3793. WBUFL(buf, 2) = bl->id;
  3794. WBUFB(buf,26) = 3;
  3795. clif_send(buf, packet_len(0x8a), bl, AREA);
  3796. if(disguised(bl)) {
  3797. WBUFL(buf, 2) = - bl->id;
  3798. clif_send(buf, packet_len(0x8a), bl, SELF);
  3799. }
  3800. }
  3801. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3802. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3803. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3804. {
  3805. unsigned char buf[32];
  3806. WBUFW(buf,0) = 0x192;
  3807. WBUFW(buf,2) = x;
  3808. WBUFW(buf,4) = y;
  3809. WBUFW(buf,6) = type;
  3810. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3811. if( fd )
  3812. {
  3813. WFIFOHEAD(fd,packet_len(0x192));
  3814. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3815. WFIFOSET(fd,packet_len(0x192));
  3816. }
  3817. else
  3818. {
  3819. struct block_list dummy_bl;
  3820. dummy_bl.type = BL_NUL;
  3821. dummy_bl.x = x;
  3822. dummy_bl.y = y;
  3823. dummy_bl.m = m;
  3824. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3825. }
  3826. }
  3827. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3828. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3829. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3830. {
  3831. int view,fd;
  3832. fd=sd->fd;
  3833. WFIFOHEAD(fd,packet_len(0x9d));
  3834. WFIFOW(fd,0)=0x9d;
  3835. WFIFOL(fd,2)=fitem->bl.id;
  3836. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3837. WFIFOW(fd,6)=view;
  3838. else
  3839. WFIFOW(fd,6)=fitem->item_data.nameid;
  3840. WFIFOB(fd,8)=fitem->item_data.identify;
  3841. WFIFOW(fd,9)=fitem->bl.x;
  3842. WFIFOW(fd,11)=fitem->bl.y;
  3843. WFIFOW(fd,13)=fitem->item_data.amount;
  3844. WFIFOB(fd,15)=fitem->subx;
  3845. WFIFOB(fd,16)=fitem->suby;
  3846. WFIFOSET(fd,packet_len(0x9d));
  3847. }
  3848. /// Notifies the client of a skill unit.
  3849. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3850. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3851. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  3852. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  3853. static void clif_getareachar_skillunit(int type,struct map_session_data *sd, struct skill_unit *unit)
  3854. {
  3855. int fd = sd->fd;
  3856. int header=0, unit_id=0, pos=0;
  3857. if( unit->group->state.guildaura )
  3858. return;
  3859. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3860. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3861. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  3862. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  3863. else
  3864. unit_id=unit->group->unit_id;
  3865. #if PACKETVER >= 3
  3866. if(unit->group->unit_id==UNT_GRAFFITI) // Graffiti [Valaris]
  3867. type = 2;
  3868. #endif
  3869. switch(type){
  3870. case 2: header=0x1c9; break;
  3871. case 3: header=0x8c7; break;
  3872. case 4: header=0x99f; break;
  3873. default:
  3874. case 1: header=0x11f; break;
  3875. }
  3876. WFIFOHEAD(fd,packet_len(header));
  3877. WFIFOW(fd,pos)=header;
  3878. if(type==3 || type==4){
  3879. WFIFOW(fd, pos+2)=packet_len(header);
  3880. pos +=2;
  3881. }
  3882. WFIFOL(fd,pos+2)=unit->bl.id;
  3883. WFIFOL(fd,pos+6)=unit->group->src_id;
  3884. WFIFOW(fd,pos+10)=unit->bl.x;
  3885. WFIFOW(fd,pos+12)=unit->bl.y;
  3886. switch(type){
  3887. case 1: WFIFOB(fd,pos+14)=unit_id;
  3888. WFIFOB(fd,pos+15)=1;
  3889. break;
  3890. case 2: WFIFOB(fd,pos+14)=unit_id;
  3891. WFIFOB(fd,pos+15)=1;
  3892. WFIFOB(fd,pos+16)=1;
  3893. safestrncpy((char*)WFIFOP(fd,pos+17),unit->group->valstr,MESSAGE_SIZE);
  3894. break;
  3895. case 3: WFIFOB(fd,pos+14)=unit_id;
  3896. WFIFOW(fd,pos+15)=unit->range;
  3897. WFIFOB(fd,pos+17)=1; //visible
  3898. break;
  3899. case 4: WFIFOL(fd,pos+14)=unit_id; pos += 3;
  3900. WFIFOW(fd,pos+15)=unit->range;
  3901. WFIFOB(fd,pos+17)=1;
  3902. break;
  3903. }
  3904. WFIFOSET(fd,packet_len(header));
  3905. if(unit->group->skill_id == WZ_ICEWALL)
  3906. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3907. }
  3908. /*==========================================
  3909. * Server tells client to remove unit of id 'unit->bl.id'
  3910. *------------------------------------------*/
  3911. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3912. {
  3913. nullpo_retv(unit);
  3914. WFIFOHEAD(fd,packet_len(0x120));
  3915. WFIFOW(fd, 0)=0x120;
  3916. WFIFOL(fd, 2)=unit->bl.id;
  3917. WFIFOSET(fd,packet_len(0x120));
  3918. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3919. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3920. }
  3921. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3922. /// 0120 <id>.L
  3923. void clif_skill_delunit(struct skill_unit *unit)
  3924. {
  3925. unsigned char buf[16];
  3926. nullpo_retv(unit);
  3927. WBUFW(buf, 0)=0x120;
  3928. WBUFL(buf, 2)=unit->bl.id;
  3929. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3930. }
  3931. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3932. /// 01ac <id>.L
  3933. /// Only affects units with class [139,153] client-side.
  3934. void clif_skillunit_update(struct block_list* bl)
  3935. {
  3936. unsigned char buf[6];
  3937. nullpo_retv(bl);
  3938. WBUFW(buf,0) = 0x1ac;
  3939. WBUFL(buf,2) = bl->id;
  3940. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3941. }
  3942. /*==========================================
  3943. *
  3944. *------------------------------------------*/
  3945. static int clif_getareachar(struct block_list* bl,va_list ap)
  3946. {
  3947. struct map_session_data *sd;
  3948. nullpo_ret(bl);
  3949. sd=va_arg(ap,struct map_session_data*);
  3950. if (sd == NULL || !sd->fd)
  3951. return 0;
  3952. switch(bl->type){
  3953. case BL_ITEM:
  3954. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3955. break;
  3956. case BL_SKILL:
  3957. clif_getareachar_skillunit(1,sd,(TBL_SKILL*)bl);
  3958. break;
  3959. default:
  3960. if(&sd->bl == bl)
  3961. break;
  3962. clif_getareachar_unit(sd,bl);
  3963. break;
  3964. }
  3965. return 0;
  3966. }
  3967. /*==========================================
  3968. * tbl has gone out of view-size of bl
  3969. *------------------------------------------*/
  3970. int clif_outsight(struct block_list *bl,va_list ap)
  3971. {
  3972. struct block_list *tbl;
  3973. struct view_data *vd;
  3974. TBL_PC *sd, *tsd;
  3975. tbl=va_arg(ap,struct block_list*);
  3976. if(bl == tbl) return 0;
  3977. sd = BL_CAST(BL_PC, bl);
  3978. tsd = BL_CAST(BL_PC, tbl);
  3979. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  3980. switch(bl->type){
  3981. case BL_PC:
  3982. if (sd->vd.class_ != INVISIBLE_CLASS)
  3983. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3984. if(sd->chatID){
  3985. struct chat_data *cd;
  3986. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3987. if(cd->usersd[0]==sd)
  3988. clif_dispchat(cd,tsd->fd);
  3989. }
  3990. if( sd->state.vending )
  3991. clif_closevendingboard(bl,tsd->fd);
  3992. if( sd->state.buyingstore )
  3993. clif_buyingstore_disappear_entry_single(tsd, sd);
  3994. break;
  3995. case BL_ITEM:
  3996. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3997. break;
  3998. case BL_SKILL:
  3999. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4000. break;
  4001. case BL_NPC:
  4002. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4003. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4004. break;
  4005. default:
  4006. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4007. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4008. break;
  4009. }
  4010. }
  4011. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4012. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4013. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4014. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4015. }
  4016. return 0;
  4017. }
  4018. /*==========================================
  4019. * tbl has come into view of bl
  4020. *------------------------------------------*/
  4021. int clif_insight(struct block_list *bl,va_list ap)
  4022. {
  4023. struct block_list *tbl;
  4024. TBL_PC *sd, *tsd;
  4025. tbl=va_arg(ap,struct block_list*);
  4026. if (bl == tbl) return 0;
  4027. sd = BL_CAST(BL_PC, bl);
  4028. tsd = BL_CAST(BL_PC, tbl);
  4029. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4030. switch(bl->type){
  4031. case BL_ITEM:
  4032. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4033. break;
  4034. case BL_SKILL:
  4035. clif_getareachar_skillunit(1,tsd,(TBL_SKILL*)bl);
  4036. break;
  4037. default:
  4038. clif_getareachar_unit(tsd,bl);
  4039. break;
  4040. }
  4041. }
  4042. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4043. clif_getareachar_unit(sd,tbl);
  4044. }
  4045. return 0;
  4046. }
  4047. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4048. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4049. void clif_skillinfoblock(struct map_session_data *sd)
  4050. {
  4051. int fd;
  4052. int i,len,id;
  4053. nullpo_retv(sd);
  4054. fd=sd->fd;
  4055. if (!fd) return;
  4056. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4057. WFIFOW(fd,0) = 0x10f;
  4058. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4059. {
  4060. if( (id = sd->status.skill[i].id) != 0 )
  4061. {
  4062. // workaround for bugreport:5348
  4063. if (len + 37 > 8192)
  4064. break;
  4065. WFIFOW(fd,len) = id;
  4066. WFIFOL(fd,len+2) = skill_get_inf(id);
  4067. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4068. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4069. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4070. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4071. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4072. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4073. else
  4074. WFIFOB(fd,len+36) = 0;
  4075. len += 37;
  4076. }
  4077. }
  4078. WFIFOW(fd,2)=len;
  4079. WFIFOSET(fd,len);
  4080. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4081. for ( ; i < MAX_SKILL; i++)
  4082. {
  4083. if( (id = sd->status.skill[i].id) != 0 )
  4084. {
  4085. clif_addskill(sd, id);
  4086. clif_skillinfo(sd, id, 0);
  4087. }
  4088. }
  4089. }
  4090. /**
  4091. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4092. **/
  4093. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4094. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4095. void clif_addskill(struct map_session_data *sd, int id)
  4096. {
  4097. int fd;
  4098. nullpo_retv(sd);
  4099. fd = sd->fd;
  4100. if (!fd) return;
  4101. if( sd->status.skill[id].id <= 0 )
  4102. return;
  4103. WFIFOHEAD(fd, packet_len(0x111));
  4104. WFIFOW(fd,0) = 0x111;
  4105. WFIFOW(fd,2) = id;
  4106. WFIFOL(fd,4) = skill_get_inf(id);
  4107. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4108. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4109. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4110. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4111. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4112. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4113. else
  4114. WFIFOB(fd,38) = 0;
  4115. WFIFOSET(fd,packet_len(0x111));
  4116. }
  4117. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4118. /// 0441 <skill id>.W
  4119. void clif_deleteskill(struct map_session_data *sd, int id)
  4120. {
  4121. #if PACKETVER >= 20081217
  4122. int fd;
  4123. nullpo_retv(sd);
  4124. fd = sd->fd;
  4125. if( !fd ) return;
  4126. WFIFOHEAD(fd,packet_len(0x441));
  4127. WFIFOW(fd,0) = 0x441;
  4128. WFIFOW(fd,2) = id;
  4129. WFIFOSET(fd,packet_len(0x441));
  4130. #endif
  4131. clif_skillinfoblock(sd);
  4132. }
  4133. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4134. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4135. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4136. int fd;
  4137. nullpo_retv(sd);
  4138. fd = sd->fd;
  4139. WFIFOHEAD(fd, packet_len(0x10e));
  4140. WFIFOW(fd, 0) = 0x10e;
  4141. WFIFOW(fd, 2) = skill_id;
  4142. WFIFOW(fd, 4) = lv;
  4143. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4144. WFIFOW(fd, 8) = range;
  4145. WFIFOB(fd, 10) = upgradable;
  4146. WFIFOSET(fd, packet_len(0x10e));
  4147. }
  4148. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4149. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4150. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4151. {
  4152. const int fd = sd->fd;
  4153. WFIFOHEAD(fd,packet_len(0x7e1));
  4154. WFIFOW(fd,0) = 0x7e1;
  4155. WFIFOW(fd,2) = skill;
  4156. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4157. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4158. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4159. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4160. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4161. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4162. else
  4163. WFIFOB(fd,14) = 0;
  4164. WFIFOSET(fd,packet_len(0x7e1));
  4165. }
  4166. /// Notifies clients in area, that an object is about to use a skill.
  4167. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4168. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4169. /// property:
  4170. /// 0 = Yellow cast aura
  4171. /// 1 = Water elemental cast aura
  4172. /// 2 = Earth elemental cast aura
  4173. /// 3 = Fire elemental cast aura
  4174. /// 4 = Wind elemental cast aura
  4175. /// 5 = Poison elemental cast aura
  4176. /// 6 = Holy elemental cast aura
  4177. /// ? = like 0
  4178. /// is disposable:
  4179. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4180. /// 1 = no text
  4181. 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)
  4182. {
  4183. #if PACKETVER < 20091124
  4184. const int cmd = 0x13e;
  4185. #else
  4186. const int cmd = 0x7fb;
  4187. #endif
  4188. unsigned char buf[32];
  4189. WBUFW(buf,0) = cmd;
  4190. WBUFL(buf,2) = src_id;
  4191. WBUFL(buf,6) = dst_id;
  4192. WBUFW(buf,10) = dst_x;
  4193. WBUFW(buf,12) = dst_y;
  4194. WBUFW(buf,14) = skill_id;
  4195. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4196. WBUFL(buf,20) = casttime;
  4197. #if PACKETVER >= 20091124
  4198. WBUFB(buf,24) = 0; // isDisposable
  4199. #endif
  4200. if (disguised(bl)) {
  4201. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4202. WBUFL(buf,2) = -src_id;
  4203. clif_send(buf,packet_len(cmd), bl, SELF);
  4204. } else
  4205. clif_send(buf,packet_len(cmd), bl, AREA);
  4206. }
  4207. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4208. /// 01b9 <id>.L
  4209. void clif_skillcastcancel(struct block_list* bl)
  4210. {
  4211. unsigned char buf[16];
  4212. nullpo_retv(bl);
  4213. WBUFW(buf,0) = 0x1b9;
  4214. WBUFL(buf,2) = bl->id;
  4215. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4216. }
  4217. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4218. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4219. /// num (only used when skill id = NV_BASIC and cause = 0):
  4220. /// 0 = "skill failed" MsgStringTable[159]
  4221. /// 1 = "no emotions" MsgStringTable[160]
  4222. /// 2 = "no sit" MsgStringTable[161]
  4223. /// 3 = "no chat" MsgStringTable[162]
  4224. /// 4 = "no party" MsgStringTable[163]
  4225. /// 5 = "no shout" MsgStringTable[164]
  4226. /// 6 = "no PKing" MsgStringTable[165]
  4227. /// 7 = "no alligning" MsgStringTable[383]
  4228. /// ? = ignored
  4229. /// cause:
  4230. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4231. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4232. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4233. /// "skill failed" MsgStringTable[204] (otherwise)
  4234. /// ... = @see enum useskill_fail_cause
  4235. /// ? = ignored
  4236. ///
  4237. /// if(result!=0) doesn't display any of the previous messages
  4238. /// Note: when this packet is received an unknown flag is always set to 0,
  4239. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4240. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4241. {
  4242. int fd;
  4243. if (!sd) { //Since this is the most common nullpo....
  4244. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4245. return;
  4246. }
  4247. fd=sd->fd;
  4248. if (!fd) return;
  4249. if(battle_config.display_skill_fail&1)
  4250. return; //Disable all skill failed messages
  4251. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4252. return; //Disable delay failed messages
  4253. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4254. return;
  4255. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4256. return;
  4257. WFIFOHEAD(fd,packet_len(0x110));
  4258. WFIFOW(fd,0) = 0x110;
  4259. WFIFOW(fd,2) = skill_id;
  4260. WFIFOL(fd,4) = btype;
  4261. WFIFOB(fd,8) = 0;// success
  4262. WFIFOB(fd,9) = cause;
  4263. WFIFOSET(fd,packet_len(0x110));
  4264. }
  4265. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4266. /// 043d <skill ID>.W <tick>.L
  4267. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4268. {
  4269. #if PACKETVER>=20081112
  4270. int fd;
  4271. nullpo_retv(sd);
  4272. fd=sd->fd;
  4273. WFIFOHEAD(fd,packet_len(0x43d));
  4274. WFIFOW(fd,0) = 0x43d;
  4275. WFIFOW(fd,2) = skill_id;
  4276. WFIFOL(fd,4) = tick;
  4277. WFIFOSET(fd,packet_len(0x43d));
  4278. #endif
  4279. }
  4280. /// Skill attack effect and damage.
  4281. /// 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)
  4282. /// 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)
  4283. 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)
  4284. {
  4285. unsigned char buf[64];
  4286. struct status_change *sc;
  4287. nullpo_ret(src);
  4288. nullpo_ret(dst);
  4289. type = clif_calc_delay(type,div,damage,ddelay);
  4290. sc = status_get_sc(dst);
  4291. if(sc && sc->count) {
  4292. if(sc->data[SC_HALLUCINATION] && damage)
  4293. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4294. }
  4295. #if PACKETVER < 3
  4296. WBUFW(buf,0)=0x114;
  4297. WBUFW(buf,2)=skill_id;
  4298. WBUFL(buf,4)=src->id;
  4299. WBUFL(buf,8)=dst->id;
  4300. WBUFL(buf,12)=tick;
  4301. WBUFL(buf,16)=sdelay;
  4302. WBUFL(buf,20)=ddelay;
  4303. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4304. WBUFW(buf,24)=damage?div:0;
  4305. } else {
  4306. WBUFW(buf,24)=damage;
  4307. }
  4308. WBUFW(buf,26)=skill_lv;
  4309. WBUFW(buf,28)=div;
  4310. WBUFB(buf,30)=type;
  4311. if (disguised(dst)) {
  4312. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4313. WBUFL(buf,8)=-dst->id;
  4314. clif_send(buf,packet_len(0x114),dst,SELF);
  4315. } else
  4316. clif_send(buf,packet_len(0x114),dst,AREA);
  4317. if(disguised(src)) {
  4318. WBUFL(buf,4)=-src->id;
  4319. if (disguised(dst))
  4320. WBUFL(buf,8)=dst->id;
  4321. if(damage > 0)
  4322. WBUFW(buf,24)=-1;
  4323. clif_send(buf,packet_len(0x114),src,SELF);
  4324. }
  4325. #else
  4326. WBUFW(buf,0)=0x1de;
  4327. WBUFW(buf,2)=skill_id;
  4328. WBUFL(buf,4)=src->id;
  4329. WBUFL(buf,8)=dst->id;
  4330. WBUFL(buf,12)=tick;
  4331. WBUFL(buf,16)=sdelay;
  4332. WBUFL(buf,20)=ddelay;
  4333. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4334. WBUFL(buf,24)=damage?div:0;
  4335. } else {
  4336. WBUFL(buf,24)=damage;
  4337. }
  4338. WBUFW(buf,28)=skill_lv;
  4339. WBUFW(buf,30)=div;
  4340. WBUFB(buf,32)=type;
  4341. if (disguised(dst)) {
  4342. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4343. WBUFL(buf,8)=-dst->id;
  4344. clif_send(buf,packet_len(0x1de),dst,SELF);
  4345. } else
  4346. clif_send(buf,packet_len(0x1de),dst,AREA);
  4347. if(disguised(src)) {
  4348. WBUFL(buf,4)=-src->id;
  4349. if (disguised(dst))
  4350. WBUFL(buf,8)=dst->id;
  4351. if(damage > 0)
  4352. WBUFL(buf,24)=-1;
  4353. clif_send(buf,packet_len(0x1de),src,SELF);
  4354. }
  4355. #endif
  4356. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4357. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4358. }
  4359. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4360. /// 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
  4361. /*
  4362. 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)
  4363. {
  4364. unsigned char buf[64];
  4365. struct status_change *sc;
  4366. nullpo_ret(src);
  4367. nullpo_ret(dst);
  4368. type = (type>0)?type:skill_get_hit(skill_id);
  4369. type = clif_calc_delay(type,div,damage,ddelay);
  4370. sc = status_get_sc(dst);
  4371. if(sc && sc->count) {
  4372. if(sc->data[SC_HALLUCINATION] && damage)
  4373. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4374. }
  4375. WBUFW(buf,0)=0x115;
  4376. WBUFW(buf,2)=skill_id;
  4377. WBUFL(buf,4)=src->id;
  4378. WBUFL(buf,8)=dst->id;
  4379. WBUFL(buf,12)=tick;
  4380. WBUFL(buf,16)=sdelay;
  4381. WBUFL(buf,20)=ddelay;
  4382. WBUFW(buf,24)=dst->x;
  4383. WBUFW(buf,26)=dst->y;
  4384. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4385. WBUFW(buf,28)=damage?div:0;
  4386. } else {
  4387. WBUFW(buf,28)=damage;
  4388. }
  4389. WBUFW(buf,30)=skill_lv;
  4390. WBUFW(buf,32)=div;
  4391. WBUFB(buf,34)=type;
  4392. clif_send(buf,packet_len(0x115),src,AREA);
  4393. if(disguised(src)) {
  4394. WBUFL(buf,4)=-src->id;
  4395. if(damage > 0)
  4396. WBUFW(buf,28)=-1;
  4397. clif_send(buf,packet_len(0x115),src,SELF);
  4398. }
  4399. if (disguised(dst)) {
  4400. WBUFL(buf,8)=-dst->id;
  4401. if (disguised(src))
  4402. WBUFL(buf,4)=src->id;
  4403. else if(damage > 0)
  4404. WBUFW(buf,28)=-1;
  4405. clif_send(buf,packet_len(0x115),dst,SELF);
  4406. }
  4407. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4408. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4409. }
  4410. */
  4411. /// Non-damaging skill effect (ZC_USE_SKILL).
  4412. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4413. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4414. {
  4415. unsigned char buf[32];
  4416. nullpo_ret(dst);
  4417. WBUFW(buf,0)=0x11a;
  4418. WBUFW(buf,2)=skill_id;
  4419. WBUFW(buf,4)=min(heal, INT16_MAX);
  4420. WBUFL(buf,6)=dst->id;
  4421. WBUFL(buf,10)=src?src->id:0;
  4422. WBUFB(buf,14)=fail;
  4423. if (disguised(dst)) {
  4424. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4425. WBUFL(buf,6)=-dst->id;
  4426. clif_send(buf,packet_len(0x11a),dst,SELF);
  4427. } else
  4428. clif_send(buf,packet_len(0x11a),dst,AREA);
  4429. if(src && disguised(src)) {
  4430. WBUFL(buf,10)=-src->id;
  4431. if (disguised(dst))
  4432. WBUFL(buf,6)=dst->id;
  4433. clif_send(buf,packet_len(0x11a),src,SELF);
  4434. }
  4435. return fail;
  4436. }
  4437. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4438. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4439. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4440. {
  4441. unsigned char buf[32];
  4442. nullpo_retv(src);
  4443. WBUFW(buf,0)=0x117;
  4444. WBUFW(buf,2)=skill_id;
  4445. WBUFL(buf,4)=src->id;
  4446. WBUFW(buf,8)=val;
  4447. WBUFW(buf,10)=x;
  4448. WBUFW(buf,12)=y;
  4449. WBUFL(buf,14)=tick;
  4450. if(disguised(src)) {
  4451. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4452. WBUFL(buf,4)=-src->id;
  4453. clif_send(buf,packet_len(0x117),src,SELF);
  4454. } else
  4455. clif_send(buf,packet_len(0x117),src,AREA);
  4456. }
  4457. /*==========================================
  4458. * Tells all client's nearby 'unit' sight range that it spawned
  4459. *------------------------------------------*/
  4460. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4461. void clif_skill_setunit(struct skill_unit *unit)
  4462. {
  4463. unsigned char buf[128];
  4464. nullpo_retv(unit);
  4465. if( unit->group->state.guildaura )
  4466. return;
  4467. #if PACKETVER >= 3
  4468. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4469. WBUFW(buf, 0)=0x1c9;
  4470. WBUFL(buf, 2)=unit->bl.id;
  4471. WBUFL(buf, 6)=unit->group->src_id;
  4472. WBUFW(buf,10)=unit->bl.x;
  4473. WBUFW(buf,12)=unit->bl.y;
  4474. WBUFB(buf,14)=unit->group->unit_id;
  4475. WBUFB(buf,15)=1;
  4476. WBUFB(buf,16)=1;
  4477. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4478. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4479. return;
  4480. }
  4481. #endif
  4482. WBUFW(buf, 0)=0x11f;
  4483. WBUFL(buf, 2)=unit->bl.id;
  4484. WBUFL(buf, 6)=unit->group->src_id;
  4485. WBUFW(buf,10)=unit->bl.x;
  4486. WBUFW(buf,12)=unit->bl.y;
  4487. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4488. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4489. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4490. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4491. else
  4492. WBUFB(buf,14)=unit->group->unit_id;
  4493. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4494. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4495. }
  4496. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4497. /// 011c <skill id>.W { <map name>.16B }*4
  4498. 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)
  4499. {
  4500. int fd;
  4501. nullpo_retv(sd);
  4502. fd = sd->fd;
  4503. WFIFOHEAD(fd,packet_len(0x11c));
  4504. WFIFOW(fd,0) = 0x11c;
  4505. WFIFOW(fd,2) = skill_id;
  4506. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4507. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4508. else // normal map name
  4509. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4510. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4511. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4512. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4513. WFIFOSET(fd,packet_len(0x11c));
  4514. sd->menuskill_id = skill_id;
  4515. if (skill_id == AL_WARP)
  4516. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4517. else
  4518. sd->menuskill_val = skill_lv;
  4519. }
  4520. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4521. /// 011e <type>.B
  4522. /// type:
  4523. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4524. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4525. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4526. ///
  4527. /// @param sd Who receives the message
  4528. /// @param type What message
  4529. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4530. {
  4531. int fd;
  4532. nullpo_retv(sd);
  4533. fd=sd->fd;
  4534. WFIFOHEAD(fd,packet_len(0x11e));
  4535. WFIFOW(fd,0)=0x11e;
  4536. WFIFOB(fd,2)=type;
  4537. WFIFOSET(fd,packet_len(0x11e));
  4538. }
  4539. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4540. /// 0189 <type>.W
  4541. /// type:
  4542. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4543. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4544. ///
  4545. /// @param sd Who receives the message
  4546. /// @param type What message
  4547. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4548. {
  4549. int fd;
  4550. nullpo_retv(sd);
  4551. fd=sd->fd;
  4552. WFIFOHEAD(fd,packet_len(0x189));
  4553. WFIFOW(fd,0)=0x189;
  4554. WFIFOW(fd,2)=type;
  4555. WFIFOSET(fd,packet_len(0x189));
  4556. }
  4557. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4558. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4559. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4560. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4561. {
  4562. struct status_data *status;
  4563. unsigned char buf[64];
  4564. int i;//, fix;
  4565. nullpo_retv(sd);
  4566. nullpo_retv(dst);
  4567. if( dst->type != BL_MOB )
  4568. return;
  4569. status = status_get_status_data(dst);
  4570. WBUFW(buf, 0)=0x18c;
  4571. WBUFW(buf, 2)=status_get_class(dst);
  4572. WBUFW(buf, 4)=status_get_lv(dst);
  4573. WBUFW(buf, 6)=status->size;
  4574. WBUFL(buf, 8)=status->hp;
  4575. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4576. +(battle_config.estimation_type&2?status->def2:0);
  4577. WBUFW(buf,14)=status->race;
  4578. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4579. +(battle_config.estimation_type&2?status->mdef2:0);
  4580. WBUFW(buf,18)= status->def_ele;
  4581. for(i=0;i<9;i++)
  4582. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4583. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4584. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4585. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4586. }
  4587. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4588. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4589. /// material id:
  4590. /// unused by the client
  4591. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4592. {
  4593. int i,c,view,fd;
  4594. nullpo_retv(sd);
  4595. if(sd->menuskill_id == skill_id)
  4596. return; //Avoid resending the menu twice or more times...
  4597. if( skill_id == GC_CREATENEWPOISON )
  4598. skill_id = GC_RESEARCHNEWPOISON;
  4599. fd=sd->fd;
  4600. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4601. WFIFOW(fd, 0)=0x18d;
  4602. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4603. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4604. ( ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4605. ){
  4606. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4607. WFIFOW(fd,c*8+ 4)= view;
  4608. else
  4609. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4610. WFIFOW(fd,c*8+ 6)= 0;
  4611. WFIFOW(fd,c*8+ 8)= 0;
  4612. WFIFOW(fd,c*8+10)= 0;
  4613. c++;
  4614. }
  4615. }
  4616. WFIFOW(fd, 2)=c*8+8;
  4617. WFIFOSET(fd,WFIFOW(fd,2));
  4618. if(c > 0) {
  4619. sd->menuskill_id = skill_id;
  4620. sd->menuskill_val = trigger;
  4621. return;
  4622. }
  4623. }
  4624. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4625. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4626. /// mk type:
  4627. /// 1 = cooking
  4628. /// 2 = arrow
  4629. /// 3 = elemental
  4630. /// 4 = GN_MIX_COOKING
  4631. /// 5 = GN_MAKEBOMB
  4632. /// 6 = GN_S_PHARMACY
  4633. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4634. {
  4635. int fd;
  4636. int i, c;
  4637. int view;
  4638. nullpo_retv(sd);
  4639. fd = sd->fd;
  4640. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4641. WFIFOW(fd,0) = 0x25a;
  4642. WFIFOW(fd,4) = list_type; // list type
  4643. c = 0;
  4644. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4645. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4646. continue;
  4647. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4648. WFIFOW(fd, 6 + 2 * c) = view;
  4649. else
  4650. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4651. c++;
  4652. }
  4653. if( skill_id == AM_PHARMACY ) { // Only send it while Cooking else check for c.
  4654. WFIFOW(fd,2) = 6 + 2 * c;
  4655. WFIFOSET(fd,WFIFOW(fd,2));
  4656. }
  4657. if( c > 0 ) {
  4658. sd->menuskill_id = skill_id;
  4659. sd->menuskill_val = trigger;
  4660. if( skill_id != AM_PHARMACY ) {
  4661. sd->menuskill_val2 = qty; // amount.
  4662. WFIFOW(fd,2) = 6 + 2 * c;
  4663. WFIFOSET(fd,WFIFOW(fd,2));
  4664. }
  4665. } else {
  4666. clif_menuskill_clear(sd);
  4667. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4668. // It fails.
  4669. #if PACKETVER >= 20090922
  4670. clif_msg_skill(sd,skill_id,0x625);
  4671. #else
  4672. WFIFOW(fd,2) = 6 + 2 * c;
  4673. WFIFOSET(fd,WFIFOW(fd,2));
  4674. #endif
  4675. }
  4676. }
  4677. }
  4678. /// Notifies clients of a status change.
  4679. /// 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)]
  4680. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4681. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4682. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4683. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4684. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4685. {
  4686. unsigned char buf[32];
  4687. struct map_session_data *sd;
  4688. if (type == SI_BLANK) //It shows nothing on the client...
  4689. return;
  4690. nullpo_retv(bl);
  4691. sd = BL_CAST(BL_PC, bl);
  4692. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4693. return;
  4694. #if PACKETVER >= 20120618
  4695. if(flag && battle_config.display_status_timers && sd)
  4696. WBUFW(buf,0)=0x983;
  4697. else
  4698. #elif PACKETVER >= 20090121
  4699. if(flag && battle_config.display_status_timers && sd)
  4700. WBUFW(buf,0)=0x43f;
  4701. else
  4702. #endif
  4703. WBUFW(buf,0)=0x196;
  4704. WBUFW(buf,2)=type;
  4705. WBUFL(buf,4)=bl->id;
  4706. WBUFB(buf,8)=flag;
  4707. #if PACKETVER >= 20120618
  4708. if(flag && battle_config.display_status_timers && sd) {
  4709. if (tick <= 0)
  4710. tick = 9999; // this is indeed what official servers do
  4711. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4712. WBUFL(buf,13)=tick;
  4713. WBUFL(buf,17) = val1;
  4714. WBUFL(buf,21) = val2;
  4715. WBUFL(buf,25) = val3;
  4716. }
  4717. #elif PACKETVER >= 20090121
  4718. if(flag && battle_config.display_status_timers && sd) {
  4719. if (tick <= 0)
  4720. tick = 9999; // this is indeed what official servers do
  4721. WBUFL(buf,9) = tick;
  4722. WBUFL(buf,13) = val1;
  4723. WBUFL(buf,17) = val2;
  4724. WBUFL(buf,21) = val3;
  4725. }
  4726. #endif
  4727. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4728. }
  4729. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4730. /// 008e <packet len>.W <message>.?B
  4731. void clif_displaymessage(const int fd, const char* mes)
  4732. {
  4733. nullpo_retv(mes);
  4734. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4735. if (fd == 0)
  4736. ;
  4737. else {
  4738. char *message, *line;
  4739. message = aStrdup(mes);
  4740. line = strtok(message, "\n");
  4741. while(line != NULL) {
  4742. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4743. int len = strnlen(line, 255);
  4744. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4745. WFIFOHEAD(fd, 5 + len);
  4746. WFIFOW(fd,0) = 0x8e;
  4747. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4748. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4749. WFIFOSET(fd, 5 + len);
  4750. }
  4751. line = strtok(NULL, "\n");
  4752. }
  4753. aFree(message);
  4754. }
  4755. }
  4756. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4757. /// 009a <packet len>.W <message>.?B
  4758. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4759. {
  4760. int lp = type ? 4 : 0;
  4761. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4762. WBUFW(buf,0) = 0x9a;
  4763. WBUFW(buf,2) = 4 + lp + len;
  4764. if (type == 0x10) // bc_blue
  4765. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4766. else if (type == 0x20) // bc_woe
  4767. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4768. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4769. clif_send(buf, WBUFW(buf,2), bl, target);
  4770. if (buf)
  4771. aFree(buf);
  4772. }
  4773. /*==========================================
  4774. * Displays a message on a 'bl' to all it's nearby clients
  4775. * Used by npc_globalmessage
  4776. *------------------------------------------*/
  4777. void clif_GlobalMessage(struct block_list* bl, const char* message) {
  4778. char buf[100];
  4779. int len;
  4780. nullpo_retv(bl);
  4781. if(!message)
  4782. return;
  4783. len = strlen(message)+1;
  4784. if( len > sizeof(buf)-8 ) {
  4785. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4786. len = sizeof(buf)-8;
  4787. }
  4788. WBUFW(buf,0)=0x8d;
  4789. WBUFW(buf,2)=len+8;
  4790. WBUFL(buf,4)=bl->id;
  4791. safestrncpy((char *) WBUFP(buf,8),message,len);
  4792. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4793. }
  4794. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4795. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4796. 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)
  4797. {
  4798. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4799. WBUFW(buf,0) = 0x1c3;
  4800. WBUFW(buf,2) = len + 16;
  4801. WBUFL(buf,4) = fontColor;
  4802. WBUFW(buf,8) = fontType;
  4803. WBUFW(buf,10) = fontSize;
  4804. WBUFW(buf,12) = fontAlign;
  4805. WBUFW(buf,14) = fontY;
  4806. memcpy(WBUFP(buf,16), mes, len);
  4807. clif_send(buf, WBUFW(buf,2), bl, target);
  4808. if (buf)
  4809. aFree(buf);
  4810. }
  4811. /*
  4812. * Display *msg from *sd to all *users in channel
  4813. */
  4814. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg) {
  4815. DBIterator *iter;
  4816. struct map_session_data *user;
  4817. unsigned short msg_len = strlen(msg) + 1;
  4818. WFIFOHEAD(sd->fd,msg_len + 12);
  4819. WFIFOW(sd->fd,0) = 0x2C1;
  4820. WFIFOW(sd->fd,2) = msg_len + 12;
  4821. WFIFOL(sd->fd,4) = 0;
  4822. WFIFOL(sd->fd,8) = Channel_Config.colors[channel->color];
  4823. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4824. iter = db_iterator(channel->users);
  4825. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4826. if( user->fd == sd->fd )
  4827. continue;
  4828. WFIFOHEAD(user->fd,msg_len + 12);
  4829. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4830. WFIFOSET(user->fd, msg_len + 12);
  4831. }
  4832. dbi_destroy(iter);
  4833. WFIFOSET(sd->fd, msg_len + 12);
  4834. }
  4835. /// Displays heal effect (ZC_RECOVERY).
  4836. /// 013d <var id>.W <amount>.W
  4837. /// var id:
  4838. /// 5 = HP (SP_HP)
  4839. /// 7 = SP (SP_SP)
  4840. /// ? = ignored
  4841. void clif_heal(int fd,int type,int val)
  4842. {
  4843. WFIFOHEAD(fd,packet_len(0x13d));
  4844. WFIFOW(fd,0)=0x13d;
  4845. WFIFOW(fd,2)=type;
  4846. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4847. WFIFOSET(fd,packet_len(0x13d));
  4848. }
  4849. /// Displays resurrection effect (ZC_RESURRECTION).
  4850. /// 0148 <id>.L <type>.W
  4851. /// type:
  4852. /// ignored
  4853. void clif_resurrection(struct block_list *bl,int type)
  4854. {
  4855. unsigned char buf[16];
  4856. nullpo_retv(bl);
  4857. WBUFW(buf,0)=0x148;
  4858. WBUFL(buf,2)=bl->id;
  4859. WBUFW(buf,6)=0;
  4860. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4861. if (disguised(bl))
  4862. clif_spawn(bl);
  4863. }
  4864. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4865. /// 0199 <type>.W
  4866. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4867. {
  4868. int fd;
  4869. nullpo_retv(sd);
  4870. fd=sd->fd;
  4871. WFIFOHEAD(fd,packet_len(0x199));
  4872. WFIFOW(fd,0)=0x199;
  4873. WFIFOW(fd,2)=property;
  4874. WFIFOSET(fd,packet_len(0x199));
  4875. }
  4876. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  4877. #if PACKETVER >= 20130000 /* not entirely sure when this started */
  4878. uint8 buf[8];
  4879. WBUFW(buf,0)=0x99b; //2
  4880. WBUFW(buf,2)=0x28; //2
  4881. WBUFB(buf,4) |= 0x01; //party
  4882. WBUFB(buf,4) |= 0x02; //guild
  4883. WBUFB(buf,4) |= ((map_flag_gvg2(bl->m))?0x04:0); //siege
  4884. WBUFB(buf,4) |= 0x08; //mineffect
  4885. WBUFB(buf,4) |= 0; //nolockon 0x10
  4886. WBUFB(buf,4) |= ((map[bl->m].flag.pvp)?0x20:0); //countpk
  4887. WBUFB(buf,4) |= 0; //nopartyformation 0x40
  4888. WBUFB(buf,4) |= ((map[bl->m].flag.battleground)?0x80:0); //battleground
  4889. WBUFB(buf,5) |= 0; //noitemconsumption
  4890. WBUFB(buf,5) |= 0x02; //cart
  4891. WBUFB(buf,5) |= 0x04; //summonstarmiracle
  4892. // WBUFB(buf,5) |= RBUFB(buf,5)&0xf8; //sparebit[0-4]
  4893. WBUFW(buf,6) = 0; //sparebit [5-15], + extra[4]
  4894. clif_send(buf,packet_len(0x99b),bl,t);
  4895. #endif
  4896. }
  4897. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4898. /// 01d6 <type>.W
  4899. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4900. {
  4901. int fd;
  4902. nullpo_retv(sd);
  4903. fd=sd->fd;
  4904. WFIFOHEAD(fd,packet_len(0x1D6));
  4905. WFIFOW(fd,0)=0x1D6;
  4906. WFIFOW(fd,2)=type;
  4907. WFIFOSET(fd,packet_len(0x1D6));
  4908. }
  4909. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4910. /// 019a <id>.L <ranking>.L <total>.L
  4911. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4912. {
  4913. if(type == 2) {
  4914. int fd = sd->fd;
  4915. WFIFOHEAD(fd,packet_len(0x19a));
  4916. WFIFOW(fd,0) = 0x19a;
  4917. WFIFOL(fd,2) = sd->bl.id;
  4918. WFIFOL(fd,6) = pvprank;
  4919. WFIFOL(fd,10) = pvpnum;
  4920. WFIFOSET(fd,packet_len(0x19a));
  4921. } else {
  4922. unsigned char buf[32];
  4923. WBUFW(buf,0) = 0x19a;
  4924. WBUFL(buf,2) = sd->bl.id;
  4925. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4926. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4927. else
  4928. WBUFL(buf,6) = pvprank;
  4929. WBUFL(buf,10) = pvpnum;
  4930. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4931. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4932. else if(!type)
  4933. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4934. else
  4935. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4936. }
  4937. }
  4938. /*==========================================
  4939. *
  4940. *------------------------------------------*/
  4941. void clif_map_property_mapall(int map, enum map_property property)
  4942. {
  4943. struct block_list bl;
  4944. unsigned char buf[16];
  4945. bl.id = 0;
  4946. bl.type = BL_NUL;
  4947. bl.m = map;
  4948. WBUFW(buf,0)=0x199;
  4949. WBUFW(buf,2)=property;
  4950. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4951. }
  4952. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4953. /// 0188 <result>.W <index>.W <refine>.W
  4954. /// result:
  4955. /// 0 = success
  4956. /// 1 = failure
  4957. /// 2 = downgrade
  4958. void clif_refine(int fd, int fail, int index, int val)
  4959. {
  4960. WFIFOHEAD(fd,packet_len(0x188));
  4961. WFIFOW(fd,0)=0x188;
  4962. WFIFOW(fd,2)=fail;
  4963. WFIFOW(fd,4)=index+2;
  4964. WFIFOW(fd,6)=val;
  4965. WFIFOSET(fd,packet_len(0x188));
  4966. }
  4967. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4968. /// 0223 <result>.L <nameid>.W
  4969. /// result:
  4970. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4971. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4972. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4973. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4974. void clif_upgrademessage(int fd, int result, int item_id)
  4975. {
  4976. WFIFOHEAD(fd,packet_len(0x223));
  4977. WFIFOW(fd,0)=0x223;
  4978. WFIFOL(fd,2)=result;
  4979. WFIFOW(fd,6)=item_id;
  4980. WFIFOSET(fd,packet_len(0x223));
  4981. }
  4982. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4983. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4984. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4985. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4986. {
  4987. #if PACKETVER < 20091104
  4988. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4989. WFIFOW(fd,0) = 0x97;
  4990. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4991. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4992. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4993. WFIFOSET(fd,WFIFOW(fd,2));
  4994. #else
  4995. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4996. WFIFOW(fd,0) = 0x97;
  4997. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4998. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4999. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  5000. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  5001. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5002. WFIFOSET(fd,WFIFOW(fd,2));
  5003. #endif
  5004. }
  5005. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5006. /// 0098 <result>.B
  5007. /// result:
  5008. /// 0 = success to send wisper
  5009. /// 1 = target character is not loged in
  5010. /// 2 = ignored by target
  5011. /// 3 = everyone ignored by target
  5012. void clif_wis_end(int fd, int flag)
  5013. {
  5014. WFIFOHEAD(fd,packet_len(0x98));
  5015. WFIFOW(fd,0) = 0x98;
  5016. WFIFOW(fd,2) = flag;
  5017. WFIFOSET(fd,packet_len(0x98));
  5018. }
  5019. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5020. /// 0194 <char id>.L <name>.24B
  5021. void clif_solved_charname(int fd, int charid, const char* name)
  5022. {
  5023. WFIFOHEAD(fd,packet_len(0x194));
  5024. WFIFOW(fd,0)=0x194;
  5025. WFIFOL(fd,2)=charid;
  5026. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5027. WFIFOSET(fd,packet_len(0x194));
  5028. }
  5029. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5030. /// 017b <packet len>.W { <name id>.W }*
  5031. void clif_use_card(struct map_session_data *sd,int idx)
  5032. {
  5033. int i,c,ep;
  5034. int fd=sd->fd;
  5035. nullpo_retv(sd);
  5036. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5037. return;
  5038. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5039. return; //Avoid parsing invalid item indexes (no card/no item)
  5040. ep=sd->inventory_data[idx]->equip;
  5041. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5042. WFIFOW(fd,0)=0x17b;
  5043. for(i=c=0;i<MAX_INVENTORY;i++){
  5044. int j;
  5045. if(sd->inventory_data[i] == NULL)
  5046. continue;
  5047. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5048. continue;
  5049. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5050. continue;
  5051. if(sd->status.inventory[i].identify==0 ) //Not identified
  5052. continue;
  5053. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5054. continue;
  5055. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5056. continue;
  5057. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5058. if( j == sd->inventory_data[i]->slot ) // No room
  5059. continue;
  5060. WFIFOW(fd,4+c*2)=i+2;
  5061. c++;
  5062. }
  5063. WFIFOW(fd,2)=4+c*2;
  5064. WFIFOSET(fd,WFIFOW(fd,2));
  5065. }
  5066. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5067. /// 017d <equip index>.W <card index>.W <result>.B
  5068. /// result:
  5069. /// 0 = success
  5070. /// 1 = failure
  5071. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5072. {
  5073. int fd;
  5074. nullpo_retv(sd);
  5075. fd=sd->fd;
  5076. WFIFOHEAD(fd,packet_len(0x17d));
  5077. WFIFOW(fd,0)=0x17d;
  5078. WFIFOW(fd,2)=idx_equip+2;
  5079. WFIFOW(fd,4)=idx_card+2;
  5080. WFIFOB(fd,6)=flag;
  5081. WFIFOSET(fd,packet_len(0x17d));
  5082. }
  5083. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5084. /// 0177 <packet len>.W { <name id>.W }*
  5085. void clif_item_identify_list(struct map_session_data *sd)
  5086. {
  5087. int i,c;
  5088. int fd;
  5089. nullpo_retv(sd);
  5090. fd=sd->fd;
  5091. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5092. WFIFOW(fd,0)=0x177;
  5093. for(i=c=0;i<MAX_INVENTORY;i++){
  5094. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5095. WFIFOW(fd,c*2+4)=i+2;
  5096. c++;
  5097. }
  5098. }
  5099. if(c > 0) {
  5100. WFIFOW(fd,2)=c*2+4;
  5101. WFIFOSET(fd,WFIFOW(fd,2));
  5102. sd->menuskill_id = MC_IDENTIFY;
  5103. sd->menuskill_val = c;
  5104. }
  5105. }
  5106. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5107. /// 0179 <index>.W <result>.B
  5108. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5109. {
  5110. int fd;
  5111. nullpo_retv(sd);
  5112. fd=sd->fd;
  5113. WFIFOHEAD(fd,packet_len(0x179));
  5114. WFIFOW(fd, 0)=0x179;
  5115. WFIFOW(fd, 2)=idx+2;
  5116. WFIFOB(fd, 4)=flag;
  5117. WFIFOSET(fd,packet_len(0x179));
  5118. }
  5119. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5120. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5121. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5122. {
  5123. int i,c;
  5124. int fd;
  5125. int nameid;
  5126. nullpo_retv(sd);
  5127. nullpo_retv(dstsd);
  5128. fd=sd->fd;
  5129. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5130. WFIFOW(fd,0)=0x1fc;
  5131. for(i=c=0;i<MAX_INVENTORY;i++){
  5132. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5133. WFIFOW(fd,c*13+4) = i;
  5134. WFIFOW(fd,c*13+6) = nameid;
  5135. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5136. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5137. c++;
  5138. }
  5139. }
  5140. if(c > 0) {
  5141. WFIFOW(fd,2)=c*13+4;
  5142. WFIFOSET(fd,WFIFOW(fd,2));
  5143. sd->menuskill_id = BS_REPAIRWEAPON;
  5144. sd->menuskill_val = dstsd->bl.id;
  5145. sd->menuskill_val2 = lv;
  5146. }else
  5147. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5148. }
  5149. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5150. /// 01fe <index>.W <result>.B
  5151. /// index:
  5152. /// ignored (inventory index)
  5153. /// result:
  5154. /// 0 = Item repair success.
  5155. /// 1 = Item repair failure.
  5156. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5157. {
  5158. int fd;
  5159. nullpo_retv(sd);
  5160. fd = sd->fd;
  5161. WFIFOHEAD(fd,packet_len(0x1fe));
  5162. WFIFOW(fd, 0)=0x1fe;
  5163. WFIFOW(fd, 2)=idx+2;
  5164. WFIFOB(fd, 4)=flag;
  5165. WFIFOSET(fd,packet_len(0x1fe));
  5166. }
  5167. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5168. /// 02bb <equip location>.W <account id>.L
  5169. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5170. {
  5171. int fd = sd->fd;
  5172. WFIFOHEAD(fd,packet_len(0x2bb));
  5173. WFIFOW(fd,0) = 0x2bb;
  5174. WFIFOW(fd,2) = position;
  5175. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5176. WFIFOSET(fd,packet_len(0x2bb));
  5177. }
  5178. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5179. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5180. void clif_item_refine_list(struct map_session_data *sd)
  5181. {
  5182. int i,c;
  5183. int fd;
  5184. uint16 skill_lv;
  5185. int wlv;
  5186. int refine_item[5];
  5187. nullpo_retv(sd);
  5188. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5189. fd=sd->fd;
  5190. refine_item[0] = -1;
  5191. refine_item[1] = pc_search_inventory(sd,1010);
  5192. refine_item[2] = pc_search_inventory(sd,1011);
  5193. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5194. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5195. WFIFOW(fd,0)=0x221;
  5196. for(i=c=0;i<MAX_INVENTORY;i++){
  5197. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5198. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5199. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5200. WFIFOW(fd,c*13+ 4)=i+2;
  5201. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5202. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5203. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5204. c++;
  5205. }
  5206. }
  5207. WFIFOW(fd,2)=c*13+4;
  5208. WFIFOSET(fd,WFIFOW(fd,2));
  5209. if (c > 0) {
  5210. sd->menuskill_id = WS_WEAPONREFINE;
  5211. sd->menuskill_val = skill_lv;
  5212. }
  5213. }
  5214. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5215. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5216. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5217. {
  5218. int fd;
  5219. nullpo_retv(sd);
  5220. fd=sd->fd;
  5221. WFIFOHEAD(fd,packet_len(0x147));
  5222. WFIFOW(fd, 0)=0x147;
  5223. WFIFOW(fd, 2)=skill_id;
  5224. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5225. WFIFOW(fd, 6)=0;
  5226. WFIFOW(fd, 8)=skill_lv;
  5227. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5228. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5229. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5230. WFIFOB(fd,38)=0;
  5231. WFIFOSET(fd,packet_len(0x147));
  5232. }
  5233. /// Adds an item to character's cart.
  5234. /// 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)
  5235. /// 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)
  5236. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5237. {
  5238. int view,fd;
  5239. unsigned char *buf;
  5240. nullpo_retv(sd);
  5241. fd=sd->fd;
  5242. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5243. return;
  5244. #if PACKETVER < 5
  5245. WFIFOHEAD(fd,packet_len(0x124));
  5246. buf=WFIFOP(fd,0);
  5247. WBUFW(buf,0)=0x124;
  5248. WBUFW(buf,2)=n+2;
  5249. WBUFL(buf,4)=amount;
  5250. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5251. WBUFW(buf,8)=view;
  5252. else
  5253. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5254. WBUFB(buf,10)=sd->status.cart[n].identify;
  5255. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5256. WBUFB(buf,12)=sd->status.cart[n].refine;
  5257. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5258. WFIFOSET(fd,packet_len(0x124));
  5259. #else
  5260. WFIFOHEAD(fd,packet_len(0x1c5));
  5261. buf=WFIFOP(fd,0);
  5262. WBUFW(buf,0)=0x1c5;
  5263. WBUFW(buf,2)=n+2;
  5264. WBUFL(buf,4)=amount;
  5265. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5266. WBUFW(buf,8)=view;
  5267. else
  5268. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5269. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5270. WBUFB(buf,11)=sd->status.cart[n].identify;
  5271. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5272. WBUFB(buf,13)=sd->status.cart[n].refine;
  5273. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5274. WFIFOSET(fd,packet_len(0x1c5));
  5275. #endif
  5276. }
  5277. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5278. /// 0125 <index>.W <amount>.L
  5279. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5280. {
  5281. int fd;
  5282. nullpo_retv(sd);
  5283. fd=sd->fd;
  5284. WFIFOHEAD(fd,packet_len(0x125));
  5285. WFIFOW(fd,0)=0x125;
  5286. WFIFOW(fd,2)=n+2;
  5287. WFIFOL(fd,4)=amount;
  5288. WFIFOSET(fd,packet_len(0x125));
  5289. }
  5290. /// Opens the shop creation menu (ZC_OPENSTORE).
  5291. /// 012d <num>.W
  5292. /// num:
  5293. /// number of allowed item slots
  5294. void clif_openvendingreq(struct map_session_data* sd, int num)
  5295. {
  5296. int fd;
  5297. nullpo_retv(sd);
  5298. fd = sd->fd;
  5299. WFIFOHEAD(fd,packet_len(0x12d));
  5300. WFIFOW(fd,0) = 0x12d;
  5301. WFIFOW(fd,2) = num;
  5302. WFIFOSET(fd,packet_len(0x12d));
  5303. }
  5304. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5305. /// 0131 <owner id>.L <message>.80B
  5306. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5307. {
  5308. unsigned char buf[128];
  5309. nullpo_retv(bl);
  5310. WBUFW(buf,0) = 0x131;
  5311. WBUFL(buf,2) = bl->id;
  5312. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5313. if( fd ) {
  5314. WFIFOHEAD(fd,packet_len(0x131));
  5315. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5316. WFIFOSET(fd,packet_len(0x131));
  5317. } else {
  5318. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5319. }
  5320. }
  5321. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5322. /// 0132 <owner id>.L
  5323. void clif_closevendingboard(struct block_list* bl, int fd)
  5324. {
  5325. unsigned char buf[16];
  5326. nullpo_retv(bl);
  5327. WBUFW(buf,0) = 0x132;
  5328. WBUFL(buf,2) = bl->id;
  5329. if( fd ) {
  5330. WFIFOHEAD(fd,packet_len(0x132));
  5331. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5332. WFIFOSET(fd,packet_len(0x132));
  5333. } else {
  5334. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5335. }
  5336. }
  5337. /// Sends a list of items in a shop.
  5338. /// 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)
  5339. /// 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)
  5340. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5341. {
  5342. int i,fd;
  5343. int count;
  5344. struct map_session_data* vsd;
  5345. #if PACKETVER < 20100105
  5346. const int cmd = 0x133;
  5347. const int offset = 8;
  5348. #else
  5349. const int cmd = 0x800;
  5350. const int offset = 12;
  5351. #endif
  5352. nullpo_retv(sd);
  5353. nullpo_retv(vending);
  5354. nullpo_retv(vsd=map_id2sd(id));
  5355. fd = sd->fd;
  5356. count = vsd->vend_num;
  5357. WFIFOHEAD(fd, offset+count*22);
  5358. WFIFOW(fd,0) = cmd;
  5359. WFIFOW(fd,2) = offset+count*22;
  5360. WFIFOL(fd,4) = id;
  5361. #if PACKETVER >= 20100105
  5362. WFIFOL(fd,8) = vsd->vender_id;
  5363. #endif
  5364. for( i = 0; i < count; i++ )
  5365. {
  5366. int index = vending[i].index;
  5367. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5368. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5369. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5370. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5371. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5372. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5373. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5374. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5375. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5376. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5377. }
  5378. WFIFOSET(fd,WFIFOW(fd,2));
  5379. }
  5380. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5381. /// 0135 <index>.W <amount>.W <result>.B
  5382. /// result:
  5383. /// 0 = success
  5384. /// 1 = not enough zeny
  5385. /// 2 = overweight
  5386. /// 4 = out of stock
  5387. /// 5 = "cannot use an npc shop while in a trade"
  5388. /// 6 = Because the store information was incorrect the item was not purchased.
  5389. /// 7 = No sales information.
  5390. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5391. {
  5392. int fd;
  5393. nullpo_retv(sd);
  5394. fd = sd->fd;
  5395. WFIFOHEAD(fd,packet_len(0x135));
  5396. WFIFOW(fd,0) = 0x135;
  5397. WFIFOW(fd,2) = index+2;
  5398. WFIFOW(fd,4) = amount;
  5399. WFIFOB(fd,6) = fail;
  5400. WFIFOSET(fd,packet_len(0x135));
  5401. }
  5402. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5403. /// 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 }*
  5404. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5405. {
  5406. int i,fd;
  5407. int count;
  5408. nullpo_retv(sd);
  5409. fd = sd->fd;
  5410. count = sd->vend_num;
  5411. WFIFOHEAD(fd, 8+count*22);
  5412. WFIFOW(fd,0) = 0x136;
  5413. WFIFOW(fd,2) = 8+count*22;
  5414. WFIFOL(fd,4) = id;
  5415. for( i = 0; i < count; i++ ) {
  5416. int index = vending[i].index;
  5417. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5418. WFIFOL(fd, 8+i*22) = vending[i].value;
  5419. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5420. WFIFOW(fd,14+i*22) = vending[i].amount;
  5421. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5422. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5423. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5424. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5425. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5426. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5427. }
  5428. WFIFOSET(fd,WFIFOW(fd,2));
  5429. }
  5430. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5431. /// 0137 <index>.W <amount>.W
  5432. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5433. {
  5434. int fd;
  5435. nullpo_retv(sd);
  5436. fd = sd->fd;
  5437. WFIFOHEAD(fd,packet_len(0x137));
  5438. WFIFOW(fd,0) = 0x137;
  5439. WFIFOW(fd,2) = index+2;
  5440. WFIFOW(fd,4) = amount;
  5441. WFIFOSET(fd,packet_len(0x137));
  5442. }
  5443. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5444. /// 00fa <result>.B
  5445. /// result:
  5446. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5447. /// 1 = MsgStringTable[78]="party name already exists"
  5448. /// 2 = MsgStringTable[79]="already in a party"
  5449. /// 3 = cannot organize parties on this map
  5450. /// ? = nothing
  5451. void clif_party_created(struct map_session_data *sd,int result)
  5452. {
  5453. int fd;
  5454. nullpo_retv(sd);
  5455. fd=sd->fd;
  5456. WFIFOHEAD(fd,packet_len(0xfa));
  5457. WFIFOW(fd,0)=0xfa;
  5458. WFIFOB(fd,2)=result;
  5459. WFIFOSET(fd,packet_len(0xfa));
  5460. }
  5461. /// Adds new member to a party.
  5462. /// 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)
  5463. /// 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)
  5464. /// role:
  5465. /// 0 = leader
  5466. /// 1 = normal
  5467. /// state:
  5468. /// 0 = connected
  5469. /// 1 = disconnected
  5470. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5471. {
  5472. unsigned char buf[81];
  5473. int i;
  5474. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5475. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5476. } else {
  5477. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5478. }
  5479. if (i >= MAX_PARTY) return; //Should never happen...
  5480. sd = p->data[i].sd;
  5481. WBUFW(buf, 0) = 0x1e9;
  5482. WBUFL(buf, 2) = sd->status.account_id;
  5483. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5484. WBUFW(buf,10) = sd->bl.x;
  5485. WBUFW(buf,12) = sd->bl.y;
  5486. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5487. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5488. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5489. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5490. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5491. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5492. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5493. }
  5494. /// Sends party information (ZC_GROUP_LIST).
  5495. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5496. /// role:
  5497. /// 0 = leader
  5498. /// 1 = normal
  5499. /// state:
  5500. /// 0 = connected
  5501. /// 1 = disconnected
  5502. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5503. {
  5504. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5505. struct map_session_data* party_sd = NULL;
  5506. int i, c;
  5507. nullpo_retv(p);
  5508. WBUFW(buf,0) = 0xfb;
  5509. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5510. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5511. {
  5512. struct party_member* m = &p->party.member[i];
  5513. if(!m->account_id) continue;
  5514. if(party_sd == NULL) party_sd = p->data[i].sd;
  5515. WBUFL(buf,28+c*46) = m->account_id;
  5516. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5517. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5518. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5519. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5520. c++;
  5521. }
  5522. WBUFW(buf,2) = 28+c*46;
  5523. if(sd) { // send only to self
  5524. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5525. } else if (party_sd) { // send to whole party
  5526. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5527. }
  5528. }
  5529. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5530. /// 02c9 <flag>.B
  5531. /// flag:
  5532. /// 0 = allow party invites
  5533. /// 1 = auto-deny party invites
  5534. void clif_partyinvitationstate(struct map_session_data* sd)
  5535. {
  5536. int fd;
  5537. nullpo_retv(sd);
  5538. fd = sd->fd;
  5539. WFIFOHEAD(fd, packet_len(0x2c9));
  5540. WFIFOW(fd, 0) = 0x2c9;
  5541. WFIFOB(fd, 2) = 0; // not implemented
  5542. WFIFOSET(fd, packet_len(0x2c9));
  5543. }
  5544. /// Party invitation request.
  5545. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5546. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5547. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5548. {
  5549. #if PACKETVER < 20070821
  5550. const int cmd = 0xfe;
  5551. #else
  5552. const int cmd = 0x2c6;
  5553. #endif
  5554. int fd;
  5555. struct party_data *p;
  5556. nullpo_retv(sd);
  5557. nullpo_retv(tsd);
  5558. fd=tsd->fd;
  5559. if( (p=party_search(sd->status.party_id))==NULL )
  5560. return;
  5561. WFIFOHEAD(fd,packet_len(cmd));
  5562. WFIFOW(fd,0)=cmd;
  5563. WFIFOL(fd,2)=sd->status.party_id;
  5564. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5565. WFIFOSET(fd,packet_len(cmd));
  5566. }
  5567. /// Party invite result.
  5568. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5569. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5570. /// result=0 : char is already in a party -> MsgStringTable[80]
  5571. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5572. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5573. /// result=3 : party is full -> MsgStringTable[83]
  5574. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5575. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5576. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5577. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5578. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5579. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5580. {
  5581. int fd;
  5582. nullpo_retv(sd);
  5583. fd=sd->fd;
  5584. #if PACKETVER < 20070904
  5585. if( result == 7 ) {
  5586. clif_displaymessage(fd, msg_txt(sd,3));
  5587. return;
  5588. }
  5589. #endif
  5590. #if PACKETVER < 20070821
  5591. WFIFOHEAD(fd,packet_len(0xfd));
  5592. WFIFOW(fd,0) = 0xfd;
  5593. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5594. WFIFOB(fd,26) = result;
  5595. WFIFOSET(fd,packet_len(0xfd));
  5596. #else
  5597. WFIFOHEAD(fd,packet_len(0x2c5));
  5598. WFIFOW(fd,0) = 0x2c5;
  5599. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5600. WFIFOL(fd,26) = result;
  5601. WFIFOSET(fd,packet_len(0x2c5));
  5602. #endif
  5603. }
  5604. /// Updates party settings.
  5605. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5606. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5607. /// exp option:
  5608. /// 0 = exp sharing disabled
  5609. /// 1 = exp sharing enabled
  5610. /// 2 = cannot change exp sharing
  5611. ///
  5612. /// flag:
  5613. /// 0 = send to party
  5614. /// 1 = send to sd
  5615. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5616. {
  5617. unsigned char buf[16];
  5618. #if PACKETVER < 20090603
  5619. const int cmd = 0x101;
  5620. #else
  5621. const int cmd = 0x7d8;
  5622. #endif
  5623. nullpo_retv(p);
  5624. if(!sd && flag==0){
  5625. int i;
  5626. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5627. if (i < MAX_PARTY)
  5628. sd = p->data[i].sd;
  5629. }
  5630. if(!sd) return;
  5631. WBUFW(buf,0)=cmd;
  5632. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5633. #if PACKETVER >= 20090603
  5634. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5635. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5636. #endif
  5637. if(flag==0)
  5638. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5639. else
  5640. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5641. }
  5642. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5643. /// result:
  5644. /// 0 = leave
  5645. /// 1 = expel
  5646. /// 2 = cannot leave party on this map
  5647. /// 3 = cannot expel from party on this map
  5648. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5649. {
  5650. unsigned char buf[64];
  5651. nullpo_retv(p);
  5652. if(!sd && (flag&0xf0)==0)
  5653. {
  5654. int i;
  5655. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5656. if (i < MAX_PARTY)
  5657. sd = p->data[i].sd;
  5658. }
  5659. if(!sd) return;
  5660. WBUFW(buf,0)=0x105;
  5661. WBUFL(buf,2)=account_id;
  5662. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5663. WBUFB(buf,30)=flag&0x0f;
  5664. if((flag&0xf0)==0)
  5665. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5666. else
  5667. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5668. }
  5669. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5670. /// 0109 <packet len>.W <account id>.L <message>.?B
  5671. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5672. {
  5673. struct map_session_data *sd;
  5674. int i;
  5675. nullpo_retv(p);
  5676. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5677. if(i < MAX_PARTY){
  5678. unsigned char buf[1024];
  5679. if( len > sizeof(buf)-8 )
  5680. {
  5681. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  5682. len = sizeof(buf)-8;
  5683. }
  5684. sd = p->data[i].sd;
  5685. WBUFW(buf,0)=0x109;
  5686. WBUFW(buf,2)=len+8;
  5687. WBUFL(buf,4)=account_id;
  5688. safestrncpy((char *)WBUFP(buf,8), mes, len);
  5689. clif_send(buf,len+8,&sd->bl,PARTY);
  5690. }
  5691. }
  5692. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5693. /// 0107 <account id>.L <x>.W <y>.W
  5694. void clif_party_xy(struct map_session_data *sd)
  5695. {
  5696. unsigned char buf[16];
  5697. nullpo_retv(sd);
  5698. WBUFW(buf,0)=0x107;
  5699. WBUFL(buf,2)=sd->status.account_id;
  5700. WBUFW(buf,6)=sd->bl.x;
  5701. WBUFW(buf,8)=sd->bl.y;
  5702. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5703. }
  5704. /*==========================================
  5705. * Sends x/y dot to a single fd. [Skotlex]
  5706. *------------------------------------------*/
  5707. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5708. {
  5709. WFIFOHEAD(fd,packet_len(0x107));
  5710. WFIFOW(fd,0)=0x107;
  5711. WFIFOL(fd,2)=sd->status.account_id;
  5712. WFIFOW(fd,6)=sd->bl.x;
  5713. WFIFOW(fd,8)=sd->bl.y;
  5714. WFIFOSET(fd,packet_len(0x107));
  5715. }
  5716. /// Updates HP bar of a party member.
  5717. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5718. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5719. void clif_party_hp(struct map_session_data *sd)
  5720. {
  5721. unsigned char buf[16];
  5722. #if PACKETVER < 20100126
  5723. const int cmd = 0x106;
  5724. #else
  5725. const int cmd = 0x80e;
  5726. #endif
  5727. nullpo_retv(sd);
  5728. WBUFW(buf,0)=cmd;
  5729. WBUFL(buf,2)=sd->status.account_id;
  5730. #if PACKETVER < 20100126
  5731. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5732. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5733. WBUFW(buf,8) = 100;
  5734. } else {
  5735. WBUFW(buf,6) = sd->battle_status.hp;
  5736. WBUFW(buf,8) = sd->battle_status.max_hp;
  5737. }
  5738. #else
  5739. WBUFL(buf,6) = sd->battle_status.hp;
  5740. WBUFL(buf,10) = sd->battle_status.max_hp;
  5741. #endif
  5742. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5743. }
  5744. /*==========================================
  5745. * Sends HP bar to a single fd. [Skotlex]
  5746. *------------------------------------------*/
  5747. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5748. {
  5749. #if PACKETVER < 20100126
  5750. const int cmd = 0x106;
  5751. #else
  5752. const int cmd = 0x80e;
  5753. #endif
  5754. WFIFOHEAD(fd,packet_len(cmd));
  5755. WFIFOW(fd,0) = cmd;
  5756. WFIFOL(fd,2) = id;
  5757. #if PACKETVER < 20100126
  5758. if( maxhp > INT16_MAX )
  5759. {// To correctly display the %hp bar. [Skotlex]
  5760. WFIFOW(fd,6) = hp/(maxhp/100);
  5761. WFIFOW(fd,8) = 100;
  5762. } else {
  5763. WFIFOW(fd,6) = hp;
  5764. WFIFOW(fd,8) = maxhp;
  5765. }
  5766. #else
  5767. WFIFOL(fd,6) = hp;
  5768. WFIFOL(fd,10) = maxhp;
  5769. #endif
  5770. WFIFOSET(fd, packet_len(cmd));
  5771. }
  5772. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5773. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5774. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5775. {
  5776. int fd;
  5777. nullpo_retv(sd);
  5778. nullpo_retv(bl);
  5779. fd=sd->fd;
  5780. WFIFOHEAD(fd,packet_len(0x139));
  5781. WFIFOW(fd, 0)=0x139;
  5782. WFIFOL(fd, 2)=bl->id;
  5783. WFIFOW(fd, 6)=bl->x;
  5784. WFIFOW(fd, 8)=bl->y;
  5785. WFIFOW(fd,10)=sd->bl.x;
  5786. WFIFOW(fd,12)=sd->bl.y;
  5787. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5788. WFIFOSET(fd,packet_len(0x139));
  5789. }
  5790. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5791. /// 018f <result>.W <name id>.W
  5792. /// result:
  5793. /// 0 = success
  5794. /// 1 = failure
  5795. /// 2 = success (alchemist)
  5796. /// 3 = failure (alchemist)
  5797. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5798. {
  5799. int view,fd;
  5800. nullpo_retv(sd);
  5801. fd = sd->fd;
  5802. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5803. WFIFOHEAD(fd,packet_len(0x18f));
  5804. WFIFOW(fd, 0)=0x18f;
  5805. WFIFOW(fd, 2)=flag;
  5806. if((view = itemdb_viewid(nameid)) > 0)
  5807. WFIFOW(fd, 4)=view;
  5808. else
  5809. WFIFOW(fd, 4)=nameid;
  5810. WFIFOSET(fd,packet_len(0x18f));
  5811. }
  5812. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5813. /// 019e
  5814. void clif_catch_process(struct map_session_data *sd)
  5815. {
  5816. int fd;
  5817. nullpo_retv(sd);
  5818. fd=sd->fd;
  5819. WFIFOHEAD(fd,packet_len(0x19e));
  5820. WFIFOW(fd,0)=0x19e;
  5821. WFIFOSET(fd,packet_len(0x19e));
  5822. }
  5823. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5824. /// 01a0 <result>.B
  5825. /// 0 = failure
  5826. /// 1 = success
  5827. void clif_pet_roulette(struct map_session_data *sd,int data)
  5828. {
  5829. int fd;
  5830. nullpo_retv(sd);
  5831. fd=sd->fd;
  5832. WFIFOHEAD(fd,packet_len(0x1a0));
  5833. WFIFOW(fd,0)=0x1a0;
  5834. WFIFOB(fd,2)=data;
  5835. WFIFOSET(fd,packet_len(0x1a0));
  5836. }
  5837. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5838. /// 01a6 <packet len>.W { <index>.W }*
  5839. void clif_sendegg(struct map_session_data *sd)
  5840. {
  5841. int i,n=0,fd;
  5842. nullpo_retv(sd);
  5843. fd=sd->fd;
  5844. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5845. clif_displaymessage(fd, msg_txt(sd,666));
  5846. return;
  5847. }
  5848. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5849. WFIFOW(fd,0)=0x1a6;
  5850. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5851. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5852. sd->inventory_data[i]->type!=IT_PETEGG ||
  5853. sd->status.inventory[i].amount<=0)
  5854. continue;
  5855. WFIFOW(fd,n*2+4)=i+2;
  5856. n++;
  5857. }
  5858. WFIFOW(fd,2)=4+n*2;
  5859. WFIFOSET(fd,WFIFOW(fd,2));
  5860. sd->menuskill_id = SA_TAMINGMONSTER;
  5861. sd->menuskill_val = -1;
  5862. }
  5863. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5864. /// 01a4 <type>.B <id>.L <data>.L
  5865. /// type:
  5866. /// 0 = pre-init (data = 0)
  5867. /// 1 = intimacy (data = 0~4)
  5868. /// 2 = hunger (data = 0~4)
  5869. /// 3 = accessory
  5870. /// 4 = performance (data = 1~3: normal, 4: special)
  5871. /// 5 = hairstyle
  5872. ///
  5873. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5874. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5875. {
  5876. uint8 buf[16];
  5877. nullpo_retv(pd);
  5878. WBUFW(buf,0) = 0x1a4;
  5879. WBUFB(buf,2) = type;
  5880. WBUFL(buf,3) = pd->bl.id;
  5881. WBUFL(buf,7) = param;
  5882. if (sd)
  5883. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5884. else
  5885. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5886. }
  5887. /// Pet's base data (ZC_PROPERTY_PET).
  5888. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5889. void clif_send_petstatus(struct map_session_data *sd)
  5890. {
  5891. int fd;
  5892. struct s_pet *pet;
  5893. nullpo_retv(sd);
  5894. nullpo_retv(sd->pd);
  5895. fd=sd->fd;
  5896. pet = &sd->pd->pet;
  5897. WFIFOHEAD(fd,packet_len(0x1a2));
  5898. WFIFOW(fd,0)=0x1a2;
  5899. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5900. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5901. WFIFOW(fd,27)=pet->level;
  5902. WFIFOW(fd,29)=pet->hungry;
  5903. WFIFOW(fd,31)=pet->intimate;
  5904. WFIFOW(fd,33)=pet->equip;
  5905. #if PACKETVER >= 20081126
  5906. WFIFOW(fd,35)=pet->class_;
  5907. #endif
  5908. WFIFOSET(fd,packet_len(0x1a2));
  5909. }
  5910. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5911. /// 01aa <id>.L <data>.L
  5912. /// data:
  5913. /// @see CZ_PET_ACT.
  5914. void clif_pet_emotion(struct pet_data *pd,int param)
  5915. {
  5916. unsigned char buf[16];
  5917. nullpo_retv(pd);
  5918. memset(buf,0,packet_len(0x1aa));
  5919. WBUFW(buf,0)=0x1aa;
  5920. WBUFL(buf,2)=pd->bl.id;
  5921. if(param >= 100 && pd->petDB->talk_convert_class) {
  5922. if(pd->petDB->talk_convert_class < 0)
  5923. return;
  5924. else if(pd->petDB->talk_convert_class > 0) {
  5925. // replace mob_id component of talk/act data
  5926. param -= (pd->pet.class_ - 100)*100;
  5927. param += (pd->petDB->talk_convert_class - 100)*100;
  5928. }
  5929. }
  5930. WBUFL(buf,6)=param;
  5931. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5932. }
  5933. /// Result of request to feed a pet (ZC_FEED_PET).
  5934. /// 01a3 <result>.B <name id>.W
  5935. /// result:
  5936. /// 0 = failure
  5937. /// 1 = success
  5938. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5939. {
  5940. int fd;
  5941. nullpo_retv(sd);
  5942. fd=sd->fd;
  5943. WFIFOHEAD(fd,packet_len(0x1a3));
  5944. WFIFOW(fd,0)=0x1a3;
  5945. WFIFOB(fd,2)=fail;
  5946. WFIFOW(fd,3)=foodid;
  5947. WFIFOSET(fd,packet_len(0x1a3));
  5948. }
  5949. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5950. /// 01cd { <skill id>.L }*7
  5951. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  5952. {
  5953. int fd;
  5954. nullpo_retv(sd);
  5955. fd=sd->fd;
  5956. WFIFOHEAD(fd,packet_len(0x1cd));
  5957. WFIFOW(fd, 0)=0x1cd;
  5958. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5959. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5960. else
  5961. WFIFOL(fd,2)= 0x00000000;
  5962. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5963. WFIFOL(fd,6)= MG_COLDBOLT;
  5964. else
  5965. WFIFOL(fd,6)= 0x00000000;
  5966. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5967. WFIFOL(fd,10)= MG_FIREBOLT;
  5968. else
  5969. WFIFOL(fd,10)= 0x00000000;
  5970. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5971. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5972. else
  5973. WFIFOL(fd,14)= 0x00000000;
  5974. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5975. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5976. else
  5977. WFIFOL(fd,18)= 0x00000000;
  5978. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5979. WFIFOL(fd,22)= MG_FIREBALL;
  5980. else
  5981. WFIFOL(fd,22)= 0x00000000;
  5982. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5983. WFIFOL(fd,26)= MG_FROSTDIVER;
  5984. else
  5985. WFIFOL(fd,26)= 0x00000000;
  5986. WFIFOSET(fd,packet_len(0x1cd));
  5987. sd->menuskill_id = SA_AUTOSPELL;
  5988. sd->menuskill_val = skill_lv;
  5989. }
  5990. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5991. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5992. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5993. {
  5994. unsigned char buf[56];
  5995. nullpo_retv(src);
  5996. memset(buf,0,packet_len(0x1cf));
  5997. WBUFW(buf,0) = 0x1cf;
  5998. WBUFL(buf,2) = src->id;
  5999. if( src->type == BL_MER )
  6000. {
  6001. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6002. if( md && md->master && md->devotion_flag )
  6003. WBUFL(buf,6) = md->master->bl.id;
  6004. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6005. }
  6006. else
  6007. {
  6008. int i;
  6009. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6010. if( sd == NULL )
  6011. return;
  6012. for( i = 0; i < 5; i++ )
  6013. WBUFL(buf,6+4*i) = sd->devotion[i];
  6014. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6015. }
  6016. if( tsd )
  6017. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6018. else
  6019. clif_send(buf, packet_len(0x1cf), src, AREA);
  6020. }
  6021. /*==========================================
  6022. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6023. * Notifies clients in an area of an object's spirits.
  6024. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6025. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6026. *------------------------------------------*/
  6027. void clif_spiritball(struct block_list *bl) {
  6028. unsigned char buf[16];
  6029. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6030. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6031. nullpo_retv(bl);
  6032. WBUFW(buf, 0) = 0x1d0;
  6033. WBUFL(buf, 2) = bl->id;
  6034. WBUFW(buf, 6) = 0; //init to 0
  6035. switch(bl->type){
  6036. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6037. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6038. }
  6039. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6040. }
  6041. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6042. /// 01d2 <account id>.L <delay>.L
  6043. void clif_combo_delay(struct block_list *bl,int wait)
  6044. {
  6045. unsigned char buf[32];
  6046. nullpo_retv(bl);
  6047. WBUFW(buf,0)=0x1d2;
  6048. WBUFL(buf,2)=bl->id;
  6049. WBUFL(buf,6)=wait;
  6050. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6051. }
  6052. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6053. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6054. /// flag:
  6055. /// 0 = inactive
  6056. /// 1 = active
  6057. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6058. {
  6059. unsigned char buf[32];
  6060. nullpo_retv(src);
  6061. WBUFW(buf,0)=0x1d1;
  6062. WBUFL(buf,2)=src->id;
  6063. WBUFL(buf,6)=dst_id;
  6064. WBUFL(buf,10)=active;
  6065. clif_send(buf,packet_len(0x1d1),src,AREA);
  6066. }
  6067. /// MVP effect (ZC_MVP).
  6068. /// 010c <account id>.L
  6069. void clif_mvp_effect(struct map_session_data *sd)
  6070. {
  6071. unsigned char buf[16];
  6072. nullpo_retv(sd);
  6073. WBUFW(buf,0)=0x10c;
  6074. WBUFL(buf,2)=sd->bl.id;
  6075. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6076. }
  6077. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6078. /// 010a <name id>.W
  6079. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6080. {
  6081. int view,fd;
  6082. nullpo_retv(sd);
  6083. fd=sd->fd;
  6084. WFIFOHEAD(fd,packet_len(0x10a));
  6085. WFIFOW(fd,0)=0x10a;
  6086. if((view = itemdb_viewid(nameid)) > 0)
  6087. WFIFOW(fd,2)=view;
  6088. else
  6089. WFIFOW(fd,2)=nameid;
  6090. WFIFOSET(fd,packet_len(0x10a));
  6091. }
  6092. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6093. /// 010b <exp>.L
  6094. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6095. {
  6096. int fd;
  6097. nullpo_retv(sd);
  6098. fd=sd->fd;
  6099. WFIFOHEAD(fd,packet_len(0x10b));
  6100. WFIFOW(fd,0)=0x10b;
  6101. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6102. WFIFOSET(fd,packet_len(0x10b));
  6103. }
  6104. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6105. /// 010d
  6106. ///
  6107. /// "You are the MVP, but cannot obtain the reward because
  6108. /// you are overweight."
  6109. void clif_mvp_noitem(struct map_session_data* sd)
  6110. {
  6111. int fd = sd->fd;
  6112. WFIFOHEAD(fd,packet_len(0x10d));
  6113. WFIFOW(fd,0) = 0x10d;
  6114. WFIFOSET(fd,packet_len(0x10d));
  6115. }
  6116. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6117. /// 0167 <result>.B
  6118. /// result:
  6119. /// 0 = "Guild has been created."
  6120. /// 1 = "You are already in a Guild."
  6121. /// 2 = "That Guild Name already exists."
  6122. /// 3 = "You need the neccessary item to create a Guild."
  6123. void clif_guild_created(struct map_session_data *sd,int flag)
  6124. {
  6125. int fd;
  6126. nullpo_retv(sd);
  6127. fd=sd->fd;
  6128. WFIFOHEAD(fd,packet_len(0x167));
  6129. WFIFOW(fd,0)=0x167;
  6130. WFIFOB(fd,2)=flag;
  6131. WFIFOSET(fd,packet_len(0x167));
  6132. }
  6133. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6134. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6135. /// mode:
  6136. /// &0x01 = allow invite
  6137. /// &0x10 = allow expel
  6138. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6139. {
  6140. int ps,fd;
  6141. nullpo_retv(sd);
  6142. nullpo_retv(g);
  6143. fd=sd->fd;
  6144. ps=guild_getposition(g,sd);
  6145. WFIFOHEAD(fd,packet_len(0x16c));
  6146. WFIFOW(fd,0)=0x16c;
  6147. WFIFOL(fd,2)=g->guild_id;
  6148. WFIFOL(fd,6)=g->emblem_id;
  6149. WFIFOL(fd,10)=g->position[ps].mode;
  6150. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6151. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6152. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6153. WFIFOSET(fd,packet_len(0x16c));
  6154. }
  6155. /// Guild member login notice.
  6156. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6157. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6158. /// status:
  6159. /// 0 = offline
  6160. /// 1 = online
  6161. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6162. {
  6163. unsigned char buf[64];
  6164. struct map_session_data* sd;
  6165. nullpo_retv(g);
  6166. WBUFW(buf, 0)=0x1f2;
  6167. WBUFL(buf, 2)=g->member[idx].account_id;
  6168. WBUFL(buf, 6)=g->member[idx].char_id;
  6169. WBUFL(buf,10)=flag;
  6170. if( ( sd = g->member[idx].sd ) != NULL )
  6171. {
  6172. WBUFW(buf,14) = sd->status.sex;
  6173. WBUFW(buf,16) = sd->status.hair;
  6174. WBUFW(buf,18) = sd->status.hair_color;
  6175. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6176. }
  6177. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6178. {
  6179. WBUFW(buf,14) = 0;
  6180. WBUFW(buf,16) = 0;
  6181. WBUFW(buf,18) = 0;
  6182. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6183. }
  6184. }
  6185. // Function `clif_guild_memberlogin_notice` sends info about
  6186. // logins and logouts of a guild member to the rest members.
  6187. // But at the 1st time (after a player login or map changing)
  6188. // the client won't show the message.
  6189. // So I suggest use this function for sending "first-time-info"
  6190. // to some player on entering the game or changing location.
  6191. // At next time the client would always show the message.
  6192. // The function sends all the statuses in the single packet
  6193. // to economize traffic. [LuzZza]
  6194. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6195. {
  6196. struct guild *g;
  6197. unsigned char buf[14*128];
  6198. int i, count=0, p_len;
  6199. nullpo_retv(sd);
  6200. p_len = packet_len(0x16d);
  6201. if(!(g = sd->guild))
  6202. return;
  6203. for(i=0; i<g->max_member; i++) {
  6204. if(g->member[i].account_id > 0 &&
  6205. g->member[i].account_id != sd->status.account_id) {
  6206. WBUFW(buf,count*p_len) = 0x16d;
  6207. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6208. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6209. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6210. count++;
  6211. }
  6212. }
  6213. clif_send(buf, p_len*count, &sd->bl, SELF);
  6214. }
  6215. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6216. /// 014e <menu flag>.L
  6217. /// menu flag:
  6218. /// 0x00 = Basic Info (always on)
  6219. /// &0x01 = Member manager
  6220. /// &0x02 = Positions
  6221. /// &0x04 = Skills
  6222. /// &0x10 = Expulsion list
  6223. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6224. /// &0x80 = Notice
  6225. void clif_guild_masterormember(struct map_session_data *sd)
  6226. {
  6227. int fd;
  6228. nullpo_retv(sd);
  6229. fd=sd->fd;
  6230. WFIFOHEAD(fd,packet_len(0x14e));
  6231. WFIFOW(fd,0) = 0x14e;
  6232. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6233. WFIFOSET(fd,packet_len(0x14e));
  6234. }
  6235. /// Guild basic information (Territories [Valaris])
  6236. /// 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)
  6237. /// 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)
  6238. void clif_guild_basicinfo(struct map_session_data *sd) {
  6239. int fd;
  6240. struct guild *g;
  6241. nullpo_retv(sd);
  6242. fd = sd->fd;
  6243. if( (g = sd->guild) == NULL )
  6244. return;
  6245. WFIFOHEAD(fd,packet_len(0x1b6));
  6246. WFIFOW(fd, 0)=0x1b6;//0x150;
  6247. WFIFOL(fd, 2)=g->guild_id;
  6248. WFIFOL(fd, 6)=g->guild_lv;
  6249. WFIFOL(fd,10)=g->connect_member;
  6250. WFIFOL(fd,14)=g->max_member;
  6251. WFIFOL(fd,18)=g->average_lv;
  6252. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6253. WFIFOL(fd,26)=g->next_exp;
  6254. WFIFOL(fd,30)=0; // Tax Points
  6255. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6256. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6257. WFIFOL(fd,42)=g->emblem_id;
  6258. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6259. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6260. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6261. WFIFOL(fd,110) = 0; // zeny
  6262. WFIFOSET(fd,packet_len(0x1b6));
  6263. }
  6264. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6265. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6266. void clif_guild_allianceinfo(struct map_session_data *sd)
  6267. {
  6268. int fd,i,c;
  6269. struct guild *g;
  6270. nullpo_retv(sd);
  6271. if( (g = sd->guild) == NULL )
  6272. return;
  6273. fd = sd->fd;
  6274. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6275. WFIFOW(fd, 0)=0x14c;
  6276. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6277. struct guild_alliance *a=&g->alliance[i];
  6278. if(a->guild_id>0){
  6279. WFIFOL(fd,c*32+4)=a->opposition;
  6280. WFIFOL(fd,c*32+8)=a->guild_id;
  6281. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6282. c++;
  6283. }
  6284. }
  6285. WFIFOW(fd, 2)=c*32+4;
  6286. WFIFOSET(fd,WFIFOW(fd,2));
  6287. }
  6288. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6289. /// 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 }*
  6290. /// state:
  6291. /// 0 = offline
  6292. /// 1 = online
  6293. /// memo:
  6294. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6295. void clif_guild_memberlist(struct map_session_data *sd)
  6296. {
  6297. int fd;
  6298. int i,c;
  6299. struct guild *g;
  6300. nullpo_retv(sd);
  6301. if( (fd = sd->fd) == 0 )
  6302. return;
  6303. if( (g = sd->guild) == NULL )
  6304. return;
  6305. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6306. WFIFOW(fd, 0)=0x154;
  6307. for(i=0,c=0;i<g->max_member;i++){
  6308. struct guild_member *m=&g->member[i];
  6309. if(m->account_id==0)
  6310. continue;
  6311. WFIFOL(fd,c*104+ 4)=m->account_id;
  6312. WFIFOL(fd,c*104+ 8)=m->char_id;
  6313. WFIFOW(fd,c*104+12)=m->hair;
  6314. WFIFOW(fd,c*104+14)=m->hair_color;
  6315. WFIFOW(fd,c*104+16)=m->gender;
  6316. WFIFOW(fd,c*104+18)=m->class_;
  6317. WFIFOW(fd,c*104+20)=m->lv;
  6318. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6319. WFIFOL(fd,c*104+26)=m->online;
  6320. WFIFOL(fd,c*104+30)=m->position;
  6321. 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.
  6322. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6323. c++;
  6324. }
  6325. WFIFOW(fd, 2)=c*104+4;
  6326. WFIFOSET(fd,WFIFOW(fd,2));
  6327. }
  6328. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6329. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6330. void clif_guild_positionnamelist(struct map_session_data *sd)
  6331. {
  6332. int i,fd;
  6333. struct guild *g;
  6334. nullpo_retv(sd);
  6335. if( (g = sd->guild) == NULL )
  6336. return;
  6337. fd = sd->fd;
  6338. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6339. WFIFOW(fd, 0)=0x166;
  6340. for(i=0;i<MAX_GUILDPOSITION;i++){
  6341. WFIFOL(fd,i*28+4)=i;
  6342. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6343. }
  6344. WFIFOW(fd,2)=i*28+4;
  6345. WFIFOSET(fd,WFIFOW(fd,2));
  6346. }
  6347. /// Guild position information (ZC_POSITION_INFO).
  6348. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6349. /// mode:
  6350. /// &0x01 = allow invite
  6351. /// &0x10 = allow expel
  6352. /// ranking:
  6353. /// TODO
  6354. void clif_guild_positioninfolist(struct map_session_data *sd)
  6355. {
  6356. int i,fd;
  6357. struct guild *g;
  6358. nullpo_retv(sd);
  6359. if( (g = sd->guild) == NULL )
  6360. return;
  6361. fd = sd->fd;
  6362. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6363. WFIFOW(fd, 0)=0x160;
  6364. for(i=0;i<MAX_GUILDPOSITION;i++){
  6365. struct guild_position *p=&g->position[i];
  6366. WFIFOL(fd,i*16+ 4)=i;
  6367. WFIFOL(fd,i*16+ 8)=p->mode;
  6368. WFIFOL(fd,i*16+12)=i;
  6369. WFIFOL(fd,i*16+16)=p->exp_mode;
  6370. }
  6371. WFIFOW(fd, 2)=i*16+4;
  6372. WFIFOSET(fd,WFIFOW(fd,2));
  6373. }
  6374. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6375. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6376. /// mode:
  6377. /// &0x01 = allow invite
  6378. /// &0x10 = allow expel
  6379. /// ranking:
  6380. /// TODO
  6381. void clif_guild_positionchanged(struct guild *g,int idx)
  6382. {
  6383. // FIXME: This packet is intended to update the clients after a
  6384. // commit of position info changes, not sending one packet per
  6385. // position.
  6386. struct map_session_data *sd;
  6387. unsigned char buf[128];
  6388. nullpo_retv(g);
  6389. WBUFW(buf, 0)=0x174;
  6390. WBUFW(buf, 2)=44; // packet len
  6391. // GUILD_REG_POSITION_INFO{
  6392. WBUFL(buf, 4)=idx;
  6393. WBUFL(buf, 8)=g->position[idx].mode;
  6394. WBUFL(buf,12)=idx;
  6395. WBUFL(buf,16)=g->position[idx].exp_mode;
  6396. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6397. // }*
  6398. if( (sd=guild_getavailablesd(g))!=NULL )
  6399. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6400. }
  6401. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6402. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6403. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6404. {
  6405. // FIXME: This packet is intended to update the clients after a
  6406. // commit of member position assignment changes, not sending one
  6407. // packet per position.
  6408. struct map_session_data *sd;
  6409. unsigned char buf[64];
  6410. nullpo_retv(g);
  6411. WBUFW(buf, 0)=0x156;
  6412. WBUFW(buf, 2)=16; // packet len
  6413. // MEMBER_POSITION_INFO{
  6414. WBUFL(buf, 4)=g->member[idx].account_id;
  6415. WBUFL(buf, 8)=g->member[idx].char_id;
  6416. WBUFL(buf,12)=g->member[idx].position;
  6417. // }*
  6418. if( (sd=guild_getavailablesd(g))!=NULL )
  6419. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6420. }
  6421. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6422. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6423. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6424. {
  6425. int fd;
  6426. nullpo_retv(sd);
  6427. nullpo_retv(g);
  6428. fd = sd->fd;
  6429. if( g->emblem_len <= 0 )
  6430. return;
  6431. WFIFOHEAD(fd,g->emblem_len+12);
  6432. WFIFOW(fd,0)=0x152;
  6433. WFIFOW(fd,2)=g->emblem_len+12;
  6434. WFIFOL(fd,4)=g->guild_id;
  6435. WFIFOL(fd,8)=g->emblem_id;
  6436. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6437. WFIFOSET(fd,WFIFOW(fd,2));
  6438. }
  6439. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6440. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6441. void clif_guild_emblem_area(struct block_list* bl)
  6442. {
  6443. uint8 buf[12];
  6444. nullpo_retv(bl);
  6445. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6446. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6447. WBUFW(buf,0) = 0x1b4;
  6448. WBUFL(buf,2) = bl->id;
  6449. WBUFL(buf,6) = status_get_guild_id(bl);
  6450. WBUFW(buf,10) = status_get_emblem_id(bl);
  6451. clif_send(buf, 12, bl, AREA_WOS);
  6452. }
  6453. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6454. /// 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 }*
  6455. void clif_guild_skillinfo(struct map_session_data* sd)
  6456. {
  6457. int fd;
  6458. struct guild* g;
  6459. int i,c;
  6460. nullpo_retv(sd);
  6461. if( (g = sd->guild) == NULL )
  6462. return;
  6463. fd = sd->fd;
  6464. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6465. WFIFOW(fd,0) = 0x0162;
  6466. WFIFOW(fd,4) = g->skill_point;
  6467. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6468. {
  6469. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6470. {
  6471. int id = g->skill[i].id;
  6472. int p = 6 + c*37;
  6473. WFIFOW(fd,p+0) = id;
  6474. WFIFOL(fd,p+2) = skill_get_inf(id);
  6475. WFIFOW(fd,p+6) = g->skill[i].lv;
  6476. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6477. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6478. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6479. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6480. c++;
  6481. }
  6482. }
  6483. WFIFOW(fd,2) = 6 + c*37;
  6484. WFIFOSET(fd,WFIFOW(fd,2));
  6485. }
  6486. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6487. /// 016f <subject>.60B <notice>.120B
  6488. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6489. {
  6490. int fd;
  6491. nullpo_retv(sd);
  6492. nullpo_retv(g);
  6493. fd = sd->fd;
  6494. if ( !session_isActive(fd) )
  6495. return;
  6496. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6497. return;
  6498. WFIFOHEAD(fd,packet_len(0x16f));
  6499. WFIFOW(fd,0) = 0x16f;
  6500. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6501. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6502. WFIFOSET(fd,packet_len(0x16f));
  6503. }
  6504. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6505. /// 016a <guild id>.L <guild name>.24B
  6506. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6507. {
  6508. int fd;
  6509. nullpo_retv(sd);
  6510. nullpo_retv(g);
  6511. fd=sd->fd;
  6512. WFIFOHEAD(fd,packet_len(0x16a));
  6513. WFIFOW(fd,0)=0x16a;
  6514. WFIFOL(fd,2)=g->guild_id;
  6515. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6516. WFIFOSET(fd,packet_len(0x16a));
  6517. }
  6518. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6519. /// 0169 <answer>.B
  6520. /// answer:
  6521. /// 0 = Already in guild.
  6522. /// 1 = Offer rejected.
  6523. /// 2 = Offer accepted.
  6524. /// 3 = Guild full.
  6525. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6526. {
  6527. int fd;
  6528. nullpo_retv(sd);
  6529. fd=sd->fd;
  6530. WFIFOHEAD(fd,packet_len(0x169));
  6531. WFIFOW(fd,0)=0x169;
  6532. WFIFOB(fd,2)=flag;
  6533. WFIFOSET(fd,packet_len(0x169));
  6534. }
  6535. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6536. /// 015a <char name>.24B <reason>.40B
  6537. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6538. {
  6539. unsigned char buf[128];
  6540. nullpo_retv(sd);
  6541. WBUFW(buf, 0)=0x15a;
  6542. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6543. memcpy(WBUFP(buf,26),mes,40);
  6544. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6545. }
  6546. /// Notifies clients of a guild of an expelled member.
  6547. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6548. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6549. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6550. {
  6551. unsigned char buf[128];
  6552. #if PACKETVER < 20100803
  6553. const unsigned short cmd = 0x15c;
  6554. #else
  6555. const unsigned short cmd = 0x839;
  6556. #endif
  6557. nullpo_retv(sd);
  6558. WBUFW(buf,0) = cmd;
  6559. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6560. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6561. #if PACKETVER < 20100803
  6562. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6563. #endif
  6564. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6565. }
  6566. /// Guild expulsion list (ZC_BAN_LIST).
  6567. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6568. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6569. void clif_guild_expulsionlist(struct map_session_data* sd)
  6570. {
  6571. #if PACKETVER < 20100803
  6572. const int offset = NAME_LENGTH*2+40;
  6573. #else
  6574. const int offset = NAME_LENGTH+40;
  6575. #endif
  6576. int fd, i, c = 0;
  6577. struct guild* g;
  6578. nullpo_retv(sd);
  6579. if( (g = sd->guild) == NULL )
  6580. return;
  6581. fd = sd->fd;
  6582. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6583. WFIFOW(fd,0) = 0x163;
  6584. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6585. {
  6586. struct guild_expulsion* e = &g->expulsion[i];
  6587. if( e->account_id > 0 )
  6588. {
  6589. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6590. #if PACKETVER < 20100803
  6591. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6592. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6593. #else
  6594. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6595. #endif
  6596. c++;
  6597. }
  6598. }
  6599. WFIFOW(fd,2) = 4 + c*offset;
  6600. WFIFOSET(fd,WFIFOW(fd,2));
  6601. }
  6602. /// Guild chat message (ZC_GUILD_CHAT).
  6603. /// 017f <packet len>.W <message>.?B
  6604. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6605. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6606. struct map_session_data *sd;
  6607. uint8 buf[256];
  6608. if( len == 0 )
  6609. {
  6610. return;
  6611. }
  6612. else if( len > sizeof(buf)-5 )
  6613. {
  6614. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6615. len = sizeof(buf)-5;
  6616. }
  6617. WBUFW(buf, 0) = 0x17f;
  6618. WBUFW(buf, 2) = len + 5;
  6619. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6620. if ((sd = guild_getavailablesd(g)) != NULL)
  6621. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6622. }
  6623. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6624. /// 0171 <inviter account id>.L <guild name>.24B
  6625. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6626. {
  6627. int fd;
  6628. nullpo_retv(sd);
  6629. fd=sd->fd;
  6630. WFIFOHEAD(fd,packet_len(0x171));
  6631. WFIFOW(fd,0)=0x171;
  6632. WFIFOL(fd,2)=account_id;
  6633. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6634. WFIFOSET(fd,packet_len(0x171));
  6635. }
  6636. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6637. /// 0173 <answer>.B
  6638. /// answer:
  6639. /// 0 = Already allied.
  6640. /// 1 = You rejected the offer.
  6641. /// 2 = You accepted the offer.
  6642. /// 3 = They have too any alliances.
  6643. /// 4 = You have too many alliances.
  6644. /// 5 = Alliances are disabled.
  6645. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6646. {
  6647. int fd;
  6648. nullpo_retv(sd);
  6649. fd=sd->fd;
  6650. WFIFOHEAD(fd,packet_len(0x173));
  6651. WFIFOW(fd,0)=0x173;
  6652. WFIFOL(fd,2)=flag;
  6653. WFIFOSET(fd,packet_len(0x173));
  6654. }
  6655. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6656. /// 0184 <other guild id>.L <relation>.L
  6657. /// relation:
  6658. /// 0 = Ally
  6659. /// 1 = Enemy
  6660. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6661. {
  6662. int fd;
  6663. nullpo_retv(sd);
  6664. fd = sd->fd;
  6665. if (fd <= 0)
  6666. return;
  6667. WFIFOHEAD(fd,packet_len(0x184));
  6668. WFIFOW(fd,0)=0x184;
  6669. WFIFOL(fd,2)=guild_id;
  6670. WFIFOL(fd,6)=flag;
  6671. WFIFOSET(fd,packet_len(0x184));
  6672. }
  6673. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6674. /// 0181 <result>.B
  6675. /// result:
  6676. /// 0 = Antagonist has been set.
  6677. /// 1 = Guild has too many Antagonists.
  6678. /// 2 = Already set as an Antagonist.
  6679. /// 3 = Antagonists are disabled.
  6680. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6681. {
  6682. int fd;
  6683. nullpo_retv(sd);
  6684. fd=sd->fd;
  6685. WFIFOHEAD(fd,packet_len(0x181));
  6686. WFIFOW(fd,0)=0x181;
  6687. WFIFOB(fd,2)=flag;
  6688. WFIFOSET(fd,packet_len(0x181));
  6689. }
  6690. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6691. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6692. /*
  6693. void clif_guild_allianceadded(struct guild *g,int idx)
  6694. {
  6695. unsigned char buf[64];
  6696. WBUFW(buf,0)=0x185;
  6697. WBUFL(buf,2)=g->alliance[idx].opposition;
  6698. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6699. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6700. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6701. }
  6702. */
  6703. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6704. /// 015e <reason>.L
  6705. /// 0 = success
  6706. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6707. /// 2 = there are still members in the guild
  6708. void clif_guild_broken(struct map_session_data *sd,int flag)
  6709. {
  6710. int fd;
  6711. nullpo_retv(sd);
  6712. fd=sd->fd;
  6713. WFIFOHEAD(fd,packet_len(0x15e));
  6714. WFIFOW(fd,0)=0x15e;
  6715. WFIFOL(fd,2)=flag;
  6716. WFIFOSET(fd,packet_len(0x15e));
  6717. }
  6718. /// Displays emotion on an object (ZC_EMOTION).
  6719. /// 00c0 <id>.L <type>.B
  6720. /// type:
  6721. /// enum emotion_type
  6722. void clif_emotion(struct block_list *bl,int type)
  6723. {
  6724. unsigned char buf[8];
  6725. nullpo_retv(bl);
  6726. WBUFW(buf,0)=0xc0;
  6727. WBUFL(buf,2)=bl->id;
  6728. WBUFB(buf,6)=type;
  6729. clif_send(buf,packet_len(0xc0),bl,AREA);
  6730. }
  6731. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6732. /// 0191 <id>.L <contents>.80B
  6733. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6734. {
  6735. unsigned char buf[MESSAGE_SIZE+6];
  6736. nullpo_retv(bl);
  6737. WBUFW(buf,0) = 0x191;
  6738. WBUFL(buf,2) = bl->id;
  6739. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6740. clif_send(buf,packet_len(0x191),bl,AREA);
  6741. }
  6742. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6743. /// 01ea <id>.L
  6744. void clif_wedding_effect(struct block_list *bl)
  6745. {
  6746. unsigned char buf[6];
  6747. nullpo_retv(bl);
  6748. WBUFW(buf,0) = 0x1ea;
  6749. WBUFL(buf,2) = bl->id;
  6750. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6751. }
  6752. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6753. /// 01e6 <partner name>.24B
  6754. void clif_callpartner(struct map_session_data *sd)
  6755. {
  6756. unsigned char buf[26];
  6757. nullpo_retv(sd);
  6758. WBUFW(buf,0) = 0x1e6;
  6759. if( sd->status.partner_id )
  6760. {
  6761. const char *p;
  6762. if( ( p = map_charid2nick(sd->status.partner_id) ) != NULL )
  6763. {
  6764. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  6765. }
  6766. else
  6767. {
  6768. WBUFB(buf,2) = 0;
  6769. }
  6770. }
  6771. else
  6772. {// Send zero-length name if no partner, to initialize the client buffer.
  6773. WBUFB(buf,2) = 0;
  6774. }
  6775. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  6776. }
  6777. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6778. /// 01e4
  6779. /// This packet while still implemented by the client is no longer being officially used.
  6780. /*
  6781. void clif_marriage_process(struct map_session_data *sd)
  6782. {
  6783. int fd;
  6784. nullpo_retv(sd);
  6785. fd=sd->fd;
  6786. WFIFOHEAD(fd,packet_len(0x1e4));
  6787. WFIFOW(fd,0)=0x1e4;
  6788. WFIFOSET(fd,packet_len(0x1e4));
  6789. }
  6790. */
  6791. /// Notice of divorce (ZC_DIVORCE).
  6792. /// 0205 <partner name>.24B
  6793. void clif_divorced(struct map_session_data* sd, const char* name)
  6794. {
  6795. int fd;
  6796. nullpo_retv(sd);
  6797. fd=sd->fd;
  6798. WFIFOHEAD(fd,packet_len(0x205));
  6799. WFIFOW(fd,0)=0x205;
  6800. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6801. WFIFOSET(fd, packet_len(0x205));
  6802. }
  6803. /// Marriage proposal (ZC_REQ_COUPLE).
  6804. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6805. /// This packet while still implemented by the client is no longer being officially used.
  6806. /*
  6807. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6808. {
  6809. nullpo_retv(sd);
  6810. WFIFOHEAD(fd,packet_len(0x1e2));
  6811. WFIFOW(fd,0) = 0x1e2;
  6812. WFIFOL(fd,2) = ssd->status.account_id;
  6813. WFIFOL(fd,6) = ssd->status.char_id;
  6814. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6815. WFIFOSET(fd, packet_len(0x1e2));
  6816. }
  6817. */
  6818. /*==========================================
  6819. *
  6820. *------------------------------------------*/
  6821. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6822. {
  6823. clif_disp_message(&sd->bl, mes, len, SELF);
  6824. }
  6825. /*==========================================
  6826. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6827. *------------------------------------------*/
  6828. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6829. {
  6830. unsigned char buf[256];
  6831. if( len == 0 ) {
  6832. return;
  6833. } else if( len > sizeof(buf)-5 ) {
  6834. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6835. len = sizeof(buf)-5;
  6836. }
  6837. WBUFW(buf, 0) = 0x17f;
  6838. WBUFW(buf, 2) = len + 5;
  6839. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6840. clif_send(buf, WBUFW(buf,2), src, target);
  6841. }
  6842. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6843. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6844. /// 00cd <result>.B
  6845. /// result:
  6846. /// 0 = failure
  6847. /// 1 = success
  6848. void clif_GM_kickack(struct map_session_data *sd, int id)
  6849. {
  6850. int fd;
  6851. nullpo_retv(sd);
  6852. fd = sd->fd;
  6853. WFIFOHEAD(fd,packet_len(0xcd));
  6854. WFIFOW(fd,0) = 0xcd;
  6855. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6856. WFIFOSET(fd, packet_len(0xcd));
  6857. }
  6858. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6859. {
  6860. int fd = tsd->fd;
  6861. if( fd > 0 )
  6862. clif_authfail_fd(fd, 15);
  6863. else
  6864. map_quit(tsd);
  6865. if( sd )
  6866. clif_GM_kickack(sd,tsd->status.account_id);
  6867. }
  6868. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6869. /// 014a <result>.L
  6870. /// result:
  6871. /// 0 = "A manner point has been successfully aligned."
  6872. /// 1 = MP_FAILURE_EXHAUST
  6873. /// 2 = MP_FAILURE_ALREADY_GIVING
  6874. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6875. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6876. /// 5 = "You got a good point from %s."
  6877. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6878. {
  6879. int fd;
  6880. nullpo_retv(sd);
  6881. fd = sd->fd;
  6882. WFIFOHEAD(fd,packet_len(0x14a));
  6883. WFIFOW(fd,0) = 0x14a;
  6884. WFIFOL(fd,2) = type;
  6885. WFIFOSET(fd, packet_len(0x14a));
  6886. }
  6887. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6888. /// 014b <type>.B <GM name>.24B
  6889. /// type:
  6890. /// 0 = positive (unmute)
  6891. /// 1 = negative (mute)
  6892. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6893. {
  6894. int fd;
  6895. nullpo_retv(sd);
  6896. nullpo_retv(tsd);
  6897. fd = tsd->fd;
  6898. WFIFOHEAD(fd,packet_len(0x14b));
  6899. WFIFOW(fd,0) = 0x14b;
  6900. WFIFOB(fd,2) = type;
  6901. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6902. WFIFOSET(fd, packet_len(0x14b));
  6903. }
  6904. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6905. /// 00d1 <type>.B <result>.B
  6906. /// type:
  6907. /// 0 = /ex (deny)
  6908. /// 1 = /in (allow)
  6909. /// result:
  6910. /// 0 = success
  6911. /// 1 = failure
  6912. /// 2 = too many blocks
  6913. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6914. {
  6915. int fd;
  6916. nullpo_retv(sd);
  6917. fd=sd->fd;
  6918. WFIFOHEAD(fd,packet_len(0xd1));
  6919. WFIFOW(fd,0)=0xd1;
  6920. WFIFOB(fd,2)=type;
  6921. WFIFOB(fd,3)=flag;
  6922. WFIFOSET(fd,packet_len(0xd1));
  6923. }
  6924. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6925. /// 00d2 <type>.B <result>.B
  6926. /// type:
  6927. /// 0 = /exall (deny)
  6928. /// 1 = /inall (allow)
  6929. /// result:
  6930. /// 0 = success
  6931. /// 1 = failure
  6932. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6933. {
  6934. int fd;
  6935. nullpo_retv(sd);
  6936. fd=sd->fd;
  6937. WFIFOHEAD(fd,packet_len(0xd2));
  6938. WFIFOW(fd,0)=0xd2;
  6939. WFIFOB(fd,2)=type;
  6940. WFIFOB(fd,3)=flag;
  6941. WFIFOSET(fd,packet_len(0xd2));
  6942. }
  6943. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6944. /// 07fe <bgm>.24B
  6945. void clif_playBGM(struct map_session_data* sd, const char* name)
  6946. {
  6947. int fd;
  6948. nullpo_retv(sd);
  6949. fd = sd->fd;
  6950. WFIFOHEAD(fd,packet_len(0x7fe));
  6951. WFIFOW(fd,0) = 0x7fe;
  6952. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6953. WFIFOSET(fd,packet_len(0x7fe));
  6954. }
  6955. /// Plays/stops a wave sound (ZC_SOUND).
  6956. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6957. /// file name:
  6958. /// relative to data\wav
  6959. /// act:
  6960. /// 0 = play (once)
  6961. /// 1 = play (repeat, does not work)
  6962. /// 2 = stops all sound instances of file name (does not work)
  6963. /// term:
  6964. /// unknown purpose, only relevant to act = 1
  6965. /// npc id:
  6966. /// The accustic direction of the sound is determined by the
  6967. /// relative position of the NPC to the player (3D sound).
  6968. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6969. {
  6970. int fd;
  6971. nullpo_retv(sd);
  6972. nullpo_retv(bl);
  6973. fd = sd->fd;
  6974. WFIFOHEAD(fd,packet_len(0x1d3));
  6975. WFIFOW(fd,0) = 0x1d3;
  6976. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6977. WFIFOB(fd,26) = type;
  6978. WFIFOL(fd,27) = 0;
  6979. WFIFOL(fd,31) = bl->id;
  6980. WFIFOSET(fd,packet_len(0x1d3));
  6981. }
  6982. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6983. {
  6984. unsigned char buf[40];
  6985. nullpo_retv(bl);
  6986. WBUFW(buf,0) = 0x1d3;
  6987. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6988. WBUFB(buf,26) = type;
  6989. WBUFL(buf,27) = 0;
  6990. WBUFL(buf,31) = bl->id;
  6991. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6992. }
  6993. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6994. /// 01f3 <id>.L <effect id>.L
  6995. /// effect id:
  6996. /// @see doc/effect_list.txt
  6997. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6998. {
  6999. unsigned char buf[24];
  7000. nullpo_retv(bl);
  7001. memset(buf, 0, packet_len(0x1f3));
  7002. WBUFW(buf,0) = 0x1f3;
  7003. WBUFL(buf,2) = bl->id;
  7004. WBUFL(buf,6) = type;
  7005. clif_send(buf, packet_len(0x1f3), bl, target);
  7006. if (disguised(bl)) {
  7007. WBUFL(buf,2) = -bl->id;
  7008. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7009. }
  7010. }
  7011. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7012. {
  7013. WFIFOHEAD(fd,10);
  7014. WFIFOW(fd,0) = 0x1f3;
  7015. WFIFOL(fd,2) = bl->id;
  7016. WFIFOL(fd,6) = type;
  7017. WFIFOSET(fd,10);
  7018. }
  7019. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7020. /// 0284 <id>.L <effect id>.L <num data>.L
  7021. /// effect id:
  7022. /// @see doc/effect_list.txt
  7023. /// num data:
  7024. /// effect-dependent value
  7025. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7026. {
  7027. uint8 buf[14];
  7028. WBUFW(buf,0) = 0x284;
  7029. WBUFL(buf,2) = bl->id;
  7030. WBUFL(buf,6) = effect_id;
  7031. WBUFL(buf,10) = num;
  7032. clif_send(buf, packet_len(0x284), bl, target);
  7033. if( disguised(bl) )
  7034. {
  7035. WBUFL(buf,2) = -bl->id;
  7036. clif_send(buf, packet_len(0x284), bl, SELF);
  7037. }
  7038. }
  7039. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7040. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7041. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  7042. unsigned short msg_len = strlen(msg) + 1;
  7043. WFIFOHEAD(sd->fd,msg_len + 12);
  7044. WFIFOW(sd->fd,0) = 0x2C1;
  7045. WFIFOW(sd->fd,2) = msg_len + 12;
  7046. WFIFOL(sd->fd,4) = 0;
  7047. WFIFOL(sd->fd,8) = color_table[color];
  7048. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7049. WFIFOSET(sd->fd, msg_len + 12);
  7050. return 0;
  7051. }
  7052. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7053. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7054. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7055. unsigned short msg_len = strlen(msg) + 1;
  7056. uint8 buf[256];
  7057. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7058. nullpo_retv(bl);
  7059. if( msg_len > sizeof(buf)-12 ) {
  7060. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7061. msg_len = sizeof(buf)-12;
  7062. }
  7063. WBUFW(buf,0) = 0x2C1;
  7064. WBUFW(buf,2) = msg_len + 12;
  7065. WBUFL(buf,4) = bl->id;
  7066. WBUFL(buf,8) = color;
  7067. memcpy(WBUFP(buf,12), msg, msg_len);
  7068. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7069. }
  7070. // refresh the client's screen, getting rid of any effects
  7071. void clif_refresh(struct map_session_data *sd)
  7072. {
  7073. int i;
  7074. nullpo_retv(sd);
  7075. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7076. clif_inventorylist(sd);
  7077. if(pc_iscarton(sd)) {
  7078. clif_cartlist(sd);
  7079. clif_updatestatus(sd,SP_CARTINFO);
  7080. }
  7081. clif_updatestatus(sd,SP_WEIGHT);
  7082. clif_updatestatus(sd,SP_MAXWEIGHT);
  7083. clif_updatestatus(sd,SP_STR);
  7084. clif_updatestatus(sd,SP_AGI);
  7085. clif_updatestatus(sd,SP_VIT);
  7086. clif_updatestatus(sd,SP_INT);
  7087. clif_updatestatus(sd,SP_DEX);
  7088. clif_updatestatus(sd,SP_LUK);
  7089. if (sd->spiritball)
  7090. clif_spiritball_single(sd->fd, sd);
  7091. for(i = 1; i < 5; i++){
  7092. if( sd->talisman[i] > 0 )
  7093. clif_talisman_single(sd->fd, sd, i);
  7094. }
  7095. if (sd->vd.cloth_color)
  7096. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7097. if(merc_is_hom_active(sd->hd))
  7098. clif_send_homdata(sd,SP_ACK,0);
  7099. if( sd->md ) {
  7100. clif_mercenary_info(sd);
  7101. clif_mercenary_skillblock(sd);
  7102. }
  7103. if( sd->ed )
  7104. clif_elemental_info(sd);
  7105. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7106. clif_weather_check(sd);
  7107. if( sd->chatID )
  7108. chat_leavechat(sd,0);
  7109. if( sd->state.vending )
  7110. clif_openvending(sd, sd->bl.id, sd->vending);
  7111. if( pc_issit(sd) )
  7112. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7113. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7114. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7115. else
  7116. clif_changed_dir(&sd->bl, SELF);
  7117. // unlike vending, resuming buyingstore crashes the client.
  7118. buyingstore_close(sd);
  7119. mail_clear(sd);
  7120. if( disguised(&sd->bl) ) {/* refresh-da */
  7121. short disguise = sd->disguise;
  7122. pc_disguise(sd, 0);
  7123. pc_disguise(sd, disguise);
  7124. }
  7125. }
  7126. /// Updates the object's (bl) name on client.
  7127. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7128. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7129. void clif_charnameack (int fd, struct block_list *bl)
  7130. {
  7131. unsigned char buf[103];
  7132. int cmd = 0x95, i, ps = -1;
  7133. nullpo_retv(bl);
  7134. WBUFW(buf,0) = cmd;
  7135. WBUFL(buf,2) = bl->id;
  7136. switch( bl->type )
  7137. {
  7138. case BL_PC:
  7139. {
  7140. struct map_session_data *ssd = (struct map_session_data *)bl;
  7141. struct party_data *p = NULL;
  7142. struct guild *g = NULL;
  7143. //Requesting your own "shadow" name. [Skotlex]
  7144. if (ssd->fd == fd && ssd->disguise)
  7145. WBUFL(buf,2) = -bl->id;
  7146. if( ssd->fakename[0] ) {
  7147. WBUFW(buf, 0) = cmd = 0x195;
  7148. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7149. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7150. break;
  7151. }
  7152. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7153. if( ssd->status.party_id ) {
  7154. p = party_search(ssd->status.party_id);
  7155. }
  7156. if( ssd->status.guild_id ) {
  7157. if( ( g = ssd->guild ) != NULL ) {
  7158. 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);
  7159. if( i < g->max_member ) ps = g->member[i].position;
  7160. }
  7161. }
  7162. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7163. p = NULL;
  7164. }
  7165. if (p == NULL && g == NULL)
  7166. break;
  7167. WBUFW(buf, 0) = cmd = 0x195;
  7168. if (p)
  7169. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7170. else
  7171. WBUFB(buf,30) = 0;
  7172. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7173. {
  7174. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7175. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7176. } else { //Assume no guild.
  7177. WBUFB(buf,54) = 0;
  7178. WBUFB(buf,78) = 0;
  7179. }
  7180. }
  7181. break;
  7182. //[blackhole89]
  7183. case BL_HOM:
  7184. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7185. break;
  7186. case BL_MER:
  7187. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7188. break;
  7189. case BL_PET:
  7190. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7191. break;
  7192. case BL_NPC:
  7193. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7194. break;
  7195. case BL_MOB:
  7196. {
  7197. struct mob_data *md = (struct mob_data *)bl;
  7198. nullpo_retv(md);
  7199. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7200. if( md->guardian_data && md->guardian_data->guild_id )
  7201. {
  7202. WBUFW(buf, 0) = cmd = 0x195;
  7203. WBUFB(buf,30) = 0;
  7204. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7205. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7206. }
  7207. else if( battle_config.show_mob_info )
  7208. {
  7209. char mobhp[50], *str_p = mobhp;
  7210. WBUFW(buf, 0) = cmd = 0x195;
  7211. if( battle_config.show_mob_info&4 )
  7212. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7213. if( battle_config.show_mob_info&1 )
  7214. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7215. if( battle_config.show_mob_info&2 )
  7216. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7217. //Even thought mobhp ain't a name, we send it as one so the client
  7218. //can parse it. [Skotlex]
  7219. if( str_p != mobhp )
  7220. {
  7221. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7222. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7223. WBUFB(buf,54) = 0;
  7224. WBUFB(buf,78) = 0;
  7225. }
  7226. }
  7227. }
  7228. break;
  7229. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7230. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7231. // break;
  7232. return;
  7233. case BL_ELEM:
  7234. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7235. break;
  7236. default:
  7237. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7238. return;
  7239. }
  7240. // if no receipient specified just update nearby clients
  7241. if (fd == 0)
  7242. clif_send(buf, packet_len(cmd), bl, AREA);
  7243. else {
  7244. WFIFOHEAD(fd, packet_len(cmd));
  7245. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7246. WFIFOSET(fd, packet_len(cmd));
  7247. }
  7248. }
  7249. //Used to update when a char leaves a party/guild. [Skotlex]
  7250. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7251. void clif_charnameupdate (struct map_session_data *ssd)
  7252. {
  7253. unsigned char buf[103];
  7254. int cmd = 0x195, ps = -1;
  7255. struct party_data *p = NULL;
  7256. struct guild *g = NULL;
  7257. nullpo_retv(ssd);
  7258. if( ssd->fakename[0] )
  7259. return; //No need to update as the party/guild was not displayed anyway.
  7260. WBUFW(buf,0) = cmd;
  7261. WBUFL(buf,2) = ssd->bl.id;
  7262. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7263. if (!battle_config.display_party_name) {
  7264. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7265. p = party_search(ssd->status.party_id);
  7266. }else{
  7267. if (ssd->status.party_id > 0)
  7268. p = party_search(ssd->status.party_id);
  7269. }
  7270. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7271. {
  7272. int i;
  7273. 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);
  7274. if( i < g->max_member ) ps = g->member[i].position;
  7275. }
  7276. if( p )
  7277. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7278. else
  7279. WBUFB(buf,30) = 0;
  7280. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7281. {
  7282. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7283. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7284. }
  7285. else
  7286. {
  7287. WBUFB(buf,54) = 0;
  7288. WBUFB(buf,78) = 0;
  7289. }
  7290. // Update nearby clients
  7291. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7292. }
  7293. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7294. /// 01ff <id>.L <x>.W <y>.W
  7295. ///
  7296. /// Visually moves(instant) a character to x,y. The char moves even
  7297. /// when the target cell isn't walkable. If the char is sitting it
  7298. /// stays that way.
  7299. void clif_slide(struct block_list *bl, int x, int y)
  7300. {
  7301. unsigned char buf[10];
  7302. nullpo_retv(bl);
  7303. WBUFW(buf, 0) = 0x01ff;
  7304. WBUFL(buf, 2) = bl->id;
  7305. WBUFW(buf, 6) = x;
  7306. WBUFW(buf, 8) = y;
  7307. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7308. if( disguised(bl) )
  7309. {
  7310. WBUFL(buf,2) = -bl->id;
  7311. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7312. }
  7313. }
  7314. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7315. /// 008d <packet len>.W <id>.L <message>.?B
  7316. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7317. {
  7318. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7319. int len_mes = strlen(mes)+1; //Account for \0
  7320. if (len_mes > sizeof(buf)-8) {
  7321. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7322. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7323. }
  7324. // send message to others
  7325. WBUFW(buf,0) = 0x8d;
  7326. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7327. WBUFL(buf,4) = bl->id;
  7328. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7329. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7330. // send back message to the speaker
  7331. if( bl->type == BL_PC ) {
  7332. WBUFW(buf,0) = 0x8e;
  7333. WBUFW(buf, 2) = len_mes + 4;
  7334. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7335. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7336. }
  7337. }
  7338. /*==========================
  7339. * Minimap fix [Kevin]
  7340. * Remove dot from minimap
  7341. *--------------------------*/
  7342. void clif_party_xy_remove(struct map_session_data *sd)
  7343. {
  7344. unsigned char buf[16];
  7345. nullpo_retv(sd);
  7346. WBUFW(buf,0)=0x107;
  7347. WBUFL(buf,2)=sd->status.account_id;
  7348. WBUFW(buf,6)=-1;
  7349. WBUFW(buf,8)=-1;
  7350. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7351. }
  7352. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7353. /// 0215 <msg id>.L
  7354. /// msg id:
  7355. /// 0x15 = End all negative status (PA_GOSPEL)
  7356. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7357. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7358. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7359. /// 0x19 = All stats +20 (PA_GOSPEL)
  7360. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7361. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7362. /// 0x1e = DEF +25% (PA_GOSPEL)
  7363. /// 0x1f = ATK +100% (PA_GOSPEL)
  7364. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7365. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7366. /// ? = nothing
  7367. void clif_gospel_info(struct map_session_data *sd, int type)
  7368. {
  7369. int fd=sd->fd;
  7370. WFIFOHEAD(fd,packet_len(0x215));
  7371. WFIFOW(fd,0)=0x215;
  7372. WFIFOL(fd,2)=type;
  7373. WFIFOSET(fd, packet_len(0x215));
  7374. }
  7375. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7376. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7377. /// result:
  7378. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7379. /// star:
  7380. /// 0 = Place of the Sun
  7381. /// 1 = Place of the Moon
  7382. /// 2 = Place of the Stars
  7383. /// 1 = Star Gladiator %s's %s: <mapname>
  7384. /// star:
  7385. /// 0 = Place of the Sun
  7386. /// 1 = Place of the Moon
  7387. /// 2 = Place of the Stars
  7388. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7389. /// star:
  7390. /// 0 = Target of the Sun
  7391. /// 1 = Target of the Moon
  7392. /// 2 = Target of the Stars
  7393. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7394. /// star:
  7395. /// 0 = Monster of the Sun
  7396. /// 1 = Monster of the Moon
  7397. /// 2 = Monster of the Stars
  7398. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7399. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7400. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7401. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7402. /// 40 = Target HP : <monster_id used as HP>
  7403. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7404. {
  7405. int fd = sd->fd;
  7406. WFIFOHEAD(fd,packet_len(0x20e));
  7407. WFIFOW(fd,0) = 0x20e;
  7408. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7409. WFIFOL(fd,26) = monster_id;
  7410. WFIFOB(fd,30) = star;
  7411. WFIFOB(fd,31) = result;
  7412. WFIFOSET(fd,packet_len(0x20e));
  7413. }
  7414. /*==========================================
  7415. * Info about Star Glaldiator save map [Komurka]
  7416. * type: 1: Information, 0: Map registered
  7417. *------------------------------------------*/
  7418. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7419. {
  7420. char mapname[MAP_NAME_LENGTH_EXT];
  7421. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7422. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7423. }
  7424. /*==========================================
  7425. * Info about Star Glaldiator hate mob [Komurka]
  7426. * type: 1: Register mob, 0: Information.
  7427. *------------------------------------------*/
  7428. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7429. {
  7430. if( pcdb_checkid(class_) ) {
  7431. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7432. } else if( mobdb_checkid(class_) ) {
  7433. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7434. } else {
  7435. 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);
  7436. }
  7437. }
  7438. /*==========================================
  7439. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7440. *------------------------------------------*/
  7441. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7442. {
  7443. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7444. }
  7445. /*==========================================
  7446. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7447. *------------------------------------------*/
  7448. void clif_feel_hate_reset(struct map_session_data *sd)
  7449. {
  7450. clif_starskill(sd, "", 0, 0, 30);
  7451. }
  7452. /// Equip window (un)tick ack (ZC_CONFIG).
  7453. /// 02d9 <type>.L <value>.L
  7454. /// type:
  7455. /// 0 = open equip window
  7456. /// value:
  7457. /// 0 = disabled
  7458. /// 1 = enabled
  7459. void clif_equiptickack(struct map_session_data* sd, int flag)
  7460. {
  7461. int fd;
  7462. nullpo_retv(sd);
  7463. fd = sd->fd;
  7464. WFIFOHEAD(fd, packet_len(0x2d9));
  7465. WFIFOW(fd, 0) = 0x2d9;
  7466. WFIFOL(fd, 2) = 0;
  7467. WFIFOL(fd, 6) = flag;
  7468. WFIFOSET(fd, packet_len(0x2d9));
  7469. }
  7470. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7471. /// 02da <open equip window>.B
  7472. /// open equip window:
  7473. /// 0 = disabled
  7474. /// 1 = enabled
  7475. void clif_equipcheckbox(struct map_session_data* sd)
  7476. {
  7477. int fd;
  7478. nullpo_retv(sd);
  7479. fd = sd->fd;
  7480. WFIFOHEAD(fd, packet_len(0x2da));
  7481. WFIFOW(fd, 0) = 0x2da;
  7482. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7483. WFIFOSET(fd, packet_len(0x2da));
  7484. }
  7485. /// Sends info about a player's equipped items.
  7486. /// 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)
  7487. /// 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)
  7488. /// 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)
  7489. /// 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)
  7490. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7491. {
  7492. uint8* buf;
  7493. int i, n, fd, offset = 0;
  7494. #if PACKETVER < 20100629
  7495. const int s = 26;
  7496. #else
  7497. const int s = 28;
  7498. #endif
  7499. nullpo_retv(sd);
  7500. nullpo_retv(tsd);
  7501. fd = sd->fd;
  7502. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7503. buf = WFIFOP(fd,0);
  7504. #if PACKETVER < 20101124
  7505. WBUFW(buf, 0) = 0x2d7;
  7506. #else
  7507. WBUFW(buf, 0) = 0x859;
  7508. #endif
  7509. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7510. WBUFW(buf,28) = tsd->status.class_;
  7511. WBUFW(buf,30) = tsd->vd.hair_style;
  7512. WBUFW(buf,32) = tsd->vd.head_bottom;
  7513. WBUFW(buf,34) = tsd->vd.head_mid;
  7514. WBUFW(buf,36) = tsd->vd.head_top;
  7515. #if PACKETVER >= 20110111
  7516. WBUFW(buf,38) = tsd->vd.robe;
  7517. offset+= 2;
  7518. buf = WBUFP(buf,2);
  7519. #endif
  7520. WBUFW(buf,38) = tsd->vd.hair_color;
  7521. WBUFW(buf,40) = tsd->vd.cloth_color;
  7522. WBUFB(buf,42) = tsd->vd.sex;
  7523. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7524. {
  7525. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7526. continue;
  7527. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7528. continue;
  7529. // Inventory position
  7530. WBUFW(buf, n*s+43) = i + 2;
  7531. // Add refine, identify flag, element, etc.
  7532. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7533. // Add cards
  7534. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7535. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7536. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7537. WBUFW(buf, n*s+67) = 0;
  7538. #if PACKETVER >= 20100629
  7539. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7540. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7541. else
  7542. WBUFW(buf, n*s+69) = 0;
  7543. #endif
  7544. n++;
  7545. }
  7546. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7547. WFIFOSET(fd, WFIFOW(fd, 2));
  7548. }
  7549. /// Display msgstringtable.txt string (ZC_MSG).
  7550. /// 0291 <message>.W
  7551. void clif_msg(struct map_session_data* sd, unsigned short id)
  7552. {
  7553. int fd;
  7554. nullpo_retv(sd);
  7555. fd = sd->fd;
  7556. WFIFOHEAD(fd, packet_len(0x291));
  7557. WFIFOW(fd, 0) = 0x291;
  7558. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7559. WFIFOSET(fd, packet_len(0x291));
  7560. }
  7561. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7562. /// 0x7e2 <message>.W <value>.L
  7563. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7564. {
  7565. int fd = sd->fd;
  7566. WFIFOHEAD(fd, packet_len(0x7e2));
  7567. WFIFOW(fd,0) = 0x7e2;
  7568. WFIFOW(fd,2) = id;
  7569. WFIFOL(fd,4) = value;
  7570. WFIFOSET(fd, packet_len(0x7e2));
  7571. }
  7572. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7573. /// 07e6 <skill id>.W <msg id>.L
  7574. ///
  7575. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7576. /// "[SkillName] Message"
  7577. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7578. {
  7579. int fd = sd->fd;
  7580. WFIFOHEAD(fd, packet_len(0x7e6));
  7581. WFIFOW(fd,0) = 0x7e6;
  7582. WFIFOW(fd,2) = skill_id;
  7583. WFIFOL(fd,4) = msg_id;
  7584. WFIFOSET(fd, packet_len(0x7e6));
  7585. }
  7586. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7587. /// Returns true if the packet was parsed successfully.
  7588. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7589. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7590. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7591. {
  7592. char *text, *name, *message;
  7593. unsigned int packetlen, textlen, namelen, messagelen;
  7594. int fd = sd->fd;
  7595. *name_ = NULL;
  7596. *namelen_ = 0;
  7597. *message_ = NULL;
  7598. *messagelen_ = 0;
  7599. packetlen = RFIFOW(fd,2);
  7600. // basic structure checks
  7601. if( packetlen < 4 + 1 )
  7602. { // 4-byte header and at least an empty string is expected
  7603. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7604. return false;
  7605. }
  7606. text = (char*)RFIFOP(fd,4);
  7607. textlen = packetlen - 4;
  7608. // process <name> part of the packet
  7609. if( format == 0 )
  7610. {// name and message are separated by ' : '
  7611. // validate name
  7612. name = text;
  7613. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7614. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7615. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7616. {
  7617. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7618. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7619. set_eof(fd); // Just kick them out to correct it.
  7620. return false;
  7621. }
  7622. message = name + namelen + 3;
  7623. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7624. }
  7625. else
  7626. {// name has fixed width
  7627. if( textlen < NAME_LENGTH + 1 )
  7628. {
  7629. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7630. return false;
  7631. }
  7632. // validate name
  7633. name = text;
  7634. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7635. if( name[namelen] != '\0' )
  7636. { // only restriction is that the name must be zero-terminated
  7637. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7638. return false;
  7639. }
  7640. message = name + NAME_LENGTH;
  7641. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7642. }
  7643. if( messagelen != strnlen(message, messagelen)+1 )
  7644. { // the declared length must match real length
  7645. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7646. return false;
  7647. }
  7648. // verify <message> part of the packet
  7649. if( message[messagelen-1] != '\0' )
  7650. { // message must be zero-terminated
  7651. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7652. return false;
  7653. }
  7654. if( messagelen > CHAT_SIZE_MAX-1 )
  7655. { // messages mustn't be too long
  7656. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7657. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7658. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7659. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7660. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7661. return false;
  7662. }
  7663. *name_ = name;
  7664. *namelen_ = namelen;
  7665. *message_ = message;
  7666. *messagelen_ = messagelen;
  7667. return true;
  7668. }
  7669. // ---------------------
  7670. // clif_guess_PacketVer
  7671. // ---------------------
  7672. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7673. // error codes:
  7674. // 0 - Success
  7675. // 1 - Unknown packet_ver
  7676. // 2 - Invalid account_id
  7677. // 3 - Invalid char_id
  7678. // 4 - Invalid login_id1 (reserved)
  7679. // 5 - Invalid client_tick (reserved)
  7680. // 6 - Invalid sex
  7681. // Only the first 'invalid' error that appears is used.
  7682. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7683. {
  7684. static int err = 1;
  7685. static int packet_ver = -1;
  7686. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7687. if (get_previous)
  7688. {//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]
  7689. if( error )
  7690. *error = err;
  7691. return packet_ver;
  7692. }
  7693. //By default, start searching on the default one.
  7694. err = 1;
  7695. packet_ver = clif_config.packet_db_ver;
  7696. cmd = RFIFOW(fd,0);
  7697. packet_len = RFIFOREST(fd);
  7698. #define SET_ERROR(n) \
  7699. if( err == 1 )\
  7700. err = n;\
  7701. //define SET_ERROR
  7702. // FIXME: If the packet is not received at once, this will FAIL.
  7703. // Figure out, when it happens, that only part of the packet is
  7704. // received, or fix the function to be able to deal with that
  7705. // case.
  7706. #define CHECK_PACKET_VER() \
  7707. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7708. ;/* not wanttoconnection or wrong length */\
  7709. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7710. { SET_ERROR(2); }/* invalid account_id */\
  7711. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7712. { SET_ERROR(3); }/* invalid char_id */\
  7713. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7714. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7715. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7716. { SET_ERROR(6); }/* invalid sex */\
  7717. else\
  7718. {\
  7719. err = 0;\
  7720. if( error )\
  7721. *error = 0;\
  7722. return packet_ver;\
  7723. }\
  7724. //define CHECK_PACKET_VER
  7725. CHECK_PACKET_VER();//Default packet version found.
  7726. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7727. CHECK_PACKET_VER();
  7728. }
  7729. if( error )
  7730. *error = err;
  7731. packet_ver = -1;
  7732. return -1;
  7733. #undef SET_ERROR
  7734. #undef CHECK_PACKET_VER
  7735. }
  7736. // ------------
  7737. // clif_parse_*
  7738. // ------------
  7739. // Parses incoming (player) connection
  7740. /// Request to connect to map-server.
  7741. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7742. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7743. /// There are various variants of this packet, some of them have padding between fields.
  7744. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  7745. {
  7746. struct block_list* bl;
  7747. struct auth_node* node;
  7748. int cmd, account_id, char_id, login_id1, sex;
  7749. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7750. 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])
  7751. if (sd) {
  7752. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7753. return;
  7754. }
  7755. // Only valid packet version get here
  7756. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7757. cmd = RFIFOW(fd,0);
  7758. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7759. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7760. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7761. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7762. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7763. if( packet_ver < 5 || // reject really old client versions
  7764. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7765. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7766. {// packet version rejected
  7767. 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));
  7768. WFIFOHEAD(fd,packet_len(0x6a));
  7769. WFIFOW(fd,0) = 0x6a;
  7770. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7771. WFIFOSET(fd,packet_len(0x6a));
  7772. set_eof(fd);
  7773. return;
  7774. }
  7775. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  7776. clif_authfail_fd(fd,1);// server closed
  7777. return;
  7778. }
  7779. //Check for double login.
  7780. bl = map_id2bl(account_id);
  7781. if(bl && bl->type != BL_PC) {
  7782. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7783. WFIFOHEAD(fd,packet_len(0x6a));
  7784. WFIFOW(fd,0) = 0x6a;
  7785. WFIFOB(fd,2) = 3; // Rejected by server
  7786. WFIFOSET(fd,packet_len(0x6a));
  7787. set_eof(fd);
  7788. return;
  7789. }
  7790. if (bl ||
  7791. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7792. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7793. {
  7794. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7795. return;
  7796. }
  7797. CREATE(sd, TBL_PC, 1);
  7798. sd->fd = fd;
  7799. sd->packet_ver = packet_ver;
  7800. session[fd]->session_data = sd;
  7801. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7802. #if PACKETVER < 20070521
  7803. WFIFOHEAD(fd,4);
  7804. WFIFOL(fd,0) = sd->bl.id;
  7805. WFIFOSET(fd,4);
  7806. #else
  7807. WFIFOHEAD(fd,packet_len(0x283));
  7808. WFIFOW(fd,0) = 0x283;
  7809. WFIFOL(fd,2) = sd->bl.id;
  7810. WFIFOSET(fd,packet_len(0x283));
  7811. #endif
  7812. chrif_authreq(sd);
  7813. }
  7814. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7815. /// 007d
  7816. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7817. {
  7818. if(sd->bl.prev != NULL)
  7819. return;
  7820. if (!sd->state.active) { //Character loading is not complete yet!
  7821. //Let pc_reg_received reinvoke this when ready.
  7822. sd->state.connect_new = 0;
  7823. return;
  7824. }
  7825. if (sd->state.rewarp) { //Rewarp player.
  7826. sd->state.rewarp = 0;
  7827. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7828. return;
  7829. }
  7830. sd->state.warping = 0;
  7831. // look
  7832. #if PACKETVER < 4
  7833. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7834. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7835. #else
  7836. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7837. #endif
  7838. if(sd->vd.cloth_color)
  7839. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7840. // item
  7841. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7842. pc_checkitem(sd);
  7843. // cart
  7844. if(pc_iscarton(sd)) {
  7845. clif_cartlist(sd);
  7846. clif_updatestatus(sd,SP_CARTINFO);
  7847. }
  7848. // weight
  7849. clif_updatestatus(sd,SP_WEIGHT);
  7850. clif_updatestatus(sd,SP_MAXWEIGHT);
  7851. // guild
  7852. // (needs to go before clif_spawn() to show guild emblems correctly)
  7853. if(sd->status.guild_id)
  7854. guild_send_memberinfoshort(sd,1);
  7855. if(battle_config.pc_invincible_time > 0) {
  7856. if(map_flag_gvg(sd->bl.m))
  7857. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7858. else
  7859. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7860. }
  7861. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7862. map_spawnmobs(sd->bl.m);
  7863. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  7864. map[sd->bl.m].users_pvp++;
  7865. }
  7866. if( map[sd->bl.m].instance_id ) {
  7867. instance[map[sd->bl.m].instance_id].users++;
  7868. instance_check_idle(map[sd->bl.m].instance_id);
  7869. }
  7870. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7871. // reset the callshop flag if the player changes map
  7872. sd->state.callshop = 0;
  7873. map_addblock(&sd->bl);
  7874. clif_spawn(&sd->bl);
  7875. // Party
  7876. // (needs to go after clif_spawn() to show hp bars correctly)
  7877. if(sd->status.party_id) {
  7878. party_send_movemap(sd);
  7879. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7880. }
  7881. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7882. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7883. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7884. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7885. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7886. sd->pvp_rank = 0;
  7887. sd->pvp_lastusers = 0;
  7888. sd->pvp_point = 5;
  7889. sd->pvp_won = 0;
  7890. sd->pvp_lost = 0;
  7891. }
  7892. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7893. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  7894. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7895. if (map[sd->bl.m].flag.gvg_dungeon)
  7896. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7897. if( map_flag_gvg(sd->bl.m) )
  7898. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7899. // info about nearby objects
  7900. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7901. 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);
  7902. // pet
  7903. if( sd->pd ) {
  7904. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  7905. clif_displaymessage(sd->fd, msg_txt(sd,666));
  7906. pet_menu(sd, 3); //Option 3 is return to egg.
  7907. } else {
  7908. map_addblock(&sd->pd->bl);
  7909. clif_spawn(&sd->pd->bl);
  7910. clif_send_petdata(sd,sd->pd,0,0);
  7911. clif_send_petstatus(sd);
  7912. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7913. }
  7914. }
  7915. //homunculus [blackhole89]
  7916. if( merc_is_hom_active(sd->hd) ) {
  7917. map_addblock(&sd->hd->bl);
  7918. clif_spawn(&sd->hd->bl);
  7919. clif_send_homdata(sd,SP_ACK,0);
  7920. clif_hominfo(sd,sd->hd,1);
  7921. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7922. clif_homskillinfoblock(sd);
  7923. if( battle_config.hom_setting&0x8 )
  7924. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7925. if( !(battle_config.hom_setting&0x2) )
  7926. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7927. }
  7928. if( sd->md ) {
  7929. map_addblock(&sd->md->bl);
  7930. clif_spawn(&sd->md->bl);
  7931. clif_mercenary_info(sd);
  7932. clif_mercenary_skillblock(sd);
  7933. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  7934. }
  7935. if( sd->ed ) {
  7936. map_addblock(&sd->ed->bl);
  7937. clif_spawn(&sd->ed->bl);
  7938. clif_elemental_info(sd);
  7939. clif_elemental_updatestatus(sd,SP_HP);
  7940. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  7941. clif_elemental_updatestatus(sd,SP_SP);
  7942. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  7943. }
  7944. if(sd->state.connect_new) {
  7945. int lv;
  7946. sd->state.connect_new = 0;
  7947. clif_skillinfoblock(sd);
  7948. clif_hotkeys_send(sd);
  7949. clif_updatestatus(sd,SP_BASEEXP);
  7950. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7951. clif_updatestatus(sd,SP_JOBEXP);
  7952. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7953. clif_updatestatus(sd,SP_SKILLPOINT);
  7954. clif_initialstatus(sd);
  7955. if (sd->sc.option&OPTION_FALCON)
  7956. clif_status_load(&sd->bl, SI_FALCON, 1);
  7957. if (sd->sc.option&OPTION_RIDING)
  7958. clif_status_load(&sd->bl, SI_RIDING, 1);
  7959. else if (sd->sc.option&OPTION_WUGRIDER)
  7960. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  7961. if(sd->status.manner < 0)
  7962. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  7963. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7964. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7965. if(sd->bl.m == sd->feel_map[0].m
  7966. || sd->bl.m == sd->feel_map[1].m
  7967. || sd->bl.m == sd->feel_map[2].m)
  7968. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7969. }
  7970. if(sd->pd && sd->pd->pet.intimate > 900)
  7971. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7972. if(merc_is_hom_active(sd->hd))
  7973. merc_hom_init_timers(sd->hd);
  7974. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  7975. sd->state.night = 1;
  7976. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7977. }
  7978. // Notify everyone that this char logged in [Skotlex].
  7979. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7980. //Login Event
  7981. npc_script_event(sd, NPCE_LOGIN);
  7982. } else {
  7983. //For some reason the client "loses" these on warp/map-change.
  7984. clif_updatestatus(sd,SP_STR);
  7985. clif_updatestatus(sd,SP_AGI);
  7986. clif_updatestatus(sd,SP_VIT);
  7987. clif_updatestatus(sd,SP_INT);
  7988. clif_updatestatus(sd,SP_DEX);
  7989. clif_updatestatus(sd,SP_LUK);
  7990. // abort currently running script
  7991. sd->state.using_fake_npc = 0;
  7992. sd->state.menu_or_input = 0;
  7993. sd->npc_menu = 0;
  7994. if(sd->npc_id)
  7995. npc_event_dequeue(sd);
  7996. }
  7997. if( sd->state.changemap ) {// restore information that gets lost on map-change
  7998. #if PACKETVER >= 20070918
  7999. clif_partyinvitationstate(sd);
  8000. clif_equipcheckbox(sd);
  8001. #endif
  8002. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8003. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8004. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8005. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8006. { //Display night.
  8007. if( !sd->state.night )
  8008. {
  8009. sd->state.night = 1;
  8010. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8011. }
  8012. }
  8013. else if( sd->state.night )
  8014. { //Clear night display.
  8015. sd->state.night = 0;
  8016. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8017. }
  8018. if( map[sd->bl.m].flag.battleground )
  8019. {
  8020. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8021. if( map[sd->bl.m].flag.battleground == 2 )
  8022. clif_bg_updatescore_single(sd);
  8023. }
  8024. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8025. {
  8026. char output[128];
  8027. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8028. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8029. }
  8030. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8031. status_calc_pc(sd, false); // Some conditions are map-dependent so we must recalculate
  8032. sd->state.changemap = false;
  8033. if( Channel_Config.map_enable && Channel_Config.map_autojoin && !map[sd->bl.m].flag.chmautojoin) {
  8034. channel_mjoin(sd); //join new map
  8035. }
  8036. }
  8037. mail_clear(sd);
  8038. clif_maptypeproperty2(&sd->bl,SELF);
  8039. /* Guild Aura Init */
  8040. if( sd->state.gmaster_flag ) {
  8041. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8042. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8043. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8044. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8045. }
  8046. if( sd->state.vending ) { /* show we have a vending */
  8047. clif_openvending(sd,sd->bl.id,sd->vending);
  8048. clif_showvendingboard(&sd->bl,sd->message,0);
  8049. }
  8050. if(map[sd->bl.m].flag.loadevent) // Lance
  8051. npc_script_event(sd, NPCE_LOADMAP);
  8052. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8053. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8054. if (sd->sc.opt2) //Client loses these on warp.
  8055. clif_changeoption(&sd->bl);
  8056. clif_weather_check(sd);
  8057. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8058. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8059. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8060. else
  8061. sd->areanpc_id = 0;
  8062. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8063. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8064. pc_setdead(sd);
  8065. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8066. if(pc_isdead(sd))
  8067. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8068. else {
  8069. skill_usave_trigger(sd);
  8070. clif_changed_dir(&sd->bl, SELF);
  8071. }
  8072. // Trigger skill effects if you appear standing on them
  8073. if(!battle_config.pc_invincible_time)
  8074. skill_unit_move(&sd->bl,gettick(),1);
  8075. }
  8076. /// Server's tick (ZC_NOTIFY_TIME).
  8077. /// 007f <time>.L
  8078. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8079. {
  8080. int fd = sd->fd;
  8081. WFIFOHEAD(fd,packet_len(0x7f));
  8082. WFIFOW(fd,0) = 0x7f;
  8083. WFIFOL(fd,2) = time;
  8084. WFIFOSET(fd,packet_len(0x7f));
  8085. }
  8086. /// Request for server's tick.
  8087. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8088. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8089. /// There are various variants of this packet, some of them have padding between fields.
  8090. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8091. {
  8092. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8093. clif_notify_time(sd, gettick());
  8094. }
  8095. /// Sends hotkey bar.
  8096. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8097. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8098. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8099. void clif_hotkeys_send(struct map_session_data *sd) {
  8100. #ifdef HOTKEY_SAVING
  8101. const int fd = sd->fd;
  8102. int i;
  8103. #if PACKETVER < 20090603
  8104. const int cmd = 0x2b9;
  8105. #else
  8106. const int cmd = 0x7d9;
  8107. #endif
  8108. if (!fd) return;
  8109. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8110. WFIFOW(fd, 0) = cmd;
  8111. for(i = 0; i < MAX_HOTKEYS; i++) {
  8112. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8113. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8114. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8115. }
  8116. WFIFOSET(fd, packet_len(cmd));
  8117. #endif
  8118. }
  8119. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8120. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8121. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8122. #ifdef HOTKEY_SAVING
  8123. unsigned short idx;
  8124. int cmd;
  8125. cmd = RFIFOW(fd, 0);
  8126. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8127. if (idx >= MAX_HOTKEYS) return;
  8128. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8129. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8130. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8131. #endif
  8132. }
  8133. /// Displays cast-like progress bar (ZC_PROGRESS).
  8134. /// 02f0 <color>.L <time>.L
  8135. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8136. {
  8137. int fd = sd->fd;
  8138. WFIFOHEAD(fd,packet_len(0x2f0));
  8139. WFIFOW(fd,0) = 0x2f0;
  8140. WFIFOL(fd,2) = color;
  8141. WFIFOL(fd,6) = second;
  8142. WFIFOSET(fd,packet_len(0x2f0));
  8143. }
  8144. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8145. /// 02f2
  8146. void clif_progressbar_abort(struct map_session_data * sd)
  8147. {
  8148. int fd = sd->fd;
  8149. WFIFOHEAD(fd,packet_len(0x2f2));
  8150. WFIFOW(fd,0) = 0x2f2;
  8151. WFIFOSET(fd,packet_len(0x2f2));
  8152. }
  8153. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8154. /// 02f1
  8155. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8156. {
  8157. int npc_id = sd->progressbar.npc_id;
  8158. if( gettick() < sd->progressbar.timeout && sd->st )
  8159. sd->st->state = END;
  8160. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8161. npc_scriptcont(sd, npc_id, false);
  8162. }
  8163. /// Request to walk to a certain position on the current map.
  8164. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8165. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8166. /// There are various variants of this packet, some of them have padding between fields.
  8167. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8168. {
  8169. short x, y;
  8170. if (pc_isdead(sd)) {
  8171. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8172. return;
  8173. }
  8174. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8175. ; //You CAN walk on this OPT1 value.
  8176. else if( sd->progressbar.npc_id )
  8177. clif_progressbar_abort(sd);
  8178. else if (pc_cant_act(sd))
  8179. return;
  8180. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8181. return;
  8182. pc_delinvincibletimer(sd);
  8183. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8184. //Set last idle time... [Skotlex]
  8185. sd->idletime = last_tick;
  8186. unit_walktoxy(&sd->bl, x, y, 4);
  8187. }
  8188. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8189. /// 018b <result>.W
  8190. /// result:
  8191. /// 0 = disconnect (quit)
  8192. /// 1 = cannot disconnect (wait 10 seconds)
  8193. /// ? = ignored
  8194. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8195. {
  8196. int fd = sd->fd;
  8197. WFIFOHEAD(fd,packet_len(0x18b));
  8198. WFIFOW(fd,0) = 0x18b;
  8199. WFIFOW(fd,2) = result;
  8200. WFIFOSET(fd,packet_len(0x18b));
  8201. }
  8202. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8203. /// 018a <type>.W
  8204. /// type:
  8205. /// 0 = quit
  8206. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8207. {
  8208. /* Rovert's prevent logout option fixed [Valaris] */
  8209. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8210. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8211. {
  8212. set_eof(fd);
  8213. clif_disconnect_ack(sd, 0);
  8214. } else {
  8215. clif_disconnect_ack(sd, 1);
  8216. }
  8217. }
  8218. /// Requesting unit's name.
  8219. /// 0094 <id>.L (CZ_REQNAME)
  8220. /// 0368 <id>.L (CZ_REQNAME2)
  8221. /// There are various variants of this packet, some of them have padding between fields.
  8222. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8223. {
  8224. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8225. struct block_list* bl;
  8226. //struct status_change *sc;
  8227. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8228. id = sd->bl.id;
  8229. bl = map_id2bl(id);
  8230. if( bl == NULL )
  8231. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8232. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8233. return; // Block namerequests past view range
  8234. // 'see people in GM hide' cheat detection
  8235. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8236. sc = status_get_sc(bl);
  8237. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8238. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8239. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8240. ) {
  8241. char gm_msg[256];
  8242. 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);
  8243. ShowWarning(gm_msg);
  8244. // information is sent to all online GMs
  8245. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8246. return;
  8247. }
  8248. */
  8249. clif_charnameack(fd, bl);
  8250. }
  8251. /// Validates and processes global messages
  8252. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8253. /// There are various variants of this packet.
  8254. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8255. {
  8256. const char* text = (char*)RFIFOP(fd,4);
  8257. int textlen = RFIFOW(fd,2) - 4;
  8258. char *name, *message, *fakename = NULL;
  8259. int namelen, messagelen;
  8260. bool is_fake;
  8261. // validate packet and retrieve name and message
  8262. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8263. return;
  8264. if( is_atcommand(fd, sd, message, 1) )
  8265. return;
  8266. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8267. return;
  8268. if( battle_config.min_chat_delay ) { //[Skotlex]
  8269. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8270. return;
  8271. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8272. }
  8273. if( sd->gcbind ) {
  8274. channel_send(sd->gcbind,sd,message);
  8275. return;
  8276. } else if ( sd->fontcolor && !sd->chatID ) {
  8277. char mout[200];
  8278. snprintf(mout, 200, "%s : %s",sd->fakename[0]?sd->fakename:sd->status.name,message);
  8279. clif_colormes(sd,sd->fontcolor-1,mout);
  8280. return;
  8281. }
  8282. /**
  8283. * Fake Name Design by FatalEror (bug report #9)
  8284. **/
  8285. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8286. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8287. strcpy(fakename, sd->fakename);
  8288. strcat(fakename, " : ");
  8289. strcat(fakename, message);
  8290. textlen = strlen(fakename) + 1;
  8291. }
  8292. // send message to others (using the send buffer for temp. storage)
  8293. WFIFOHEAD(fd, 8 + textlen);
  8294. WFIFOW(fd,0) = 0x8d;
  8295. WFIFOW(fd,2) = 8 + textlen;
  8296. WFIFOL(fd,4) = sd->bl.id;
  8297. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8298. //FIXME: chat has range of 9 only
  8299. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8300. // send back message to the speaker
  8301. if( is_fake ) {
  8302. WFIFOW(fd,0) = 0x8e;
  8303. WFIFOW(fd,2) = textlen + 4;
  8304. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8305. aFree(fakename);
  8306. } else {
  8307. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8308. WFIFOW(fd,0) = 0x8e;
  8309. }
  8310. WFIFOSET(fd, WFIFOW(fd,2));
  8311. #ifdef PCRE_SUPPORT
  8312. // trigger listening npcs
  8313. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8314. #endif
  8315. // Reset idle time when using normal chat.
  8316. sd->idletime = last_tick;
  8317. // Chat logging type 'O' / Global Chat
  8318. 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);
  8319. }
  8320. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8321. /// Request to warp to a map on given coordinates.
  8322. /// 0140 <map name>.16B <x>.W <y>.W
  8323. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8324. {
  8325. char command[MAP_NAME_LENGTH_EXT+25];
  8326. char* map_name;
  8327. map_name = (char*)RFIFOP(fd,2);
  8328. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8329. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8330. is_atcommand(fd, sd, command, 1);
  8331. }
  8332. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8333. /// 009c <id>.L <head dir>.W <dir>.B
  8334. /// head dir:
  8335. /// 0 = straight
  8336. /// 1 = turned CW
  8337. /// 2 = turned CCW
  8338. /// dir:
  8339. /// 0 = north
  8340. /// 1 = northwest
  8341. /// 2 = west
  8342. /// 3 = southwest
  8343. /// 4 = south
  8344. /// 5 = southeast
  8345. /// 6 = east
  8346. /// 7 = northeast
  8347. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8348. {
  8349. unsigned char buf[64];
  8350. WBUFW(buf,0) = 0x9c;
  8351. WBUFL(buf,2) = bl->id;
  8352. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8353. WBUFB(buf,8) = unit_getdir(bl);
  8354. clif_send(buf, packet_len(0x9c), bl, target);
  8355. if (disguised(bl)) {
  8356. WBUFL(buf,2) = -bl->id;
  8357. WBUFW(buf,6) = 0;
  8358. clif_send(buf, packet_len(0x9c), bl, SELF);
  8359. }
  8360. }
  8361. /// Request to change own body and head direction.
  8362. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8363. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8364. /// There are various variants of this packet, some of them have padding between fields.
  8365. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8366. {
  8367. unsigned char headdir, dir;
  8368. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8369. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8370. pc_setdir(sd, dir, headdir);
  8371. clif_changed_dir(&sd->bl, AREA_WOS);
  8372. }
  8373. /// Request to show an emotion (CZ_REQ_EMOTION).
  8374. /// 00bf <type>.B
  8375. /// type:
  8376. /// @see enum emotion_type
  8377. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8378. {
  8379. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8380. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8381. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8382. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8383. return;
  8384. }
  8385. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8386. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8387. sd->emotionlasttime = time(NULL);
  8388. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8389. return;
  8390. }
  8391. sd->emotionlasttime = time(NULL);
  8392. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8393. emoticon = rnd()%6+E_DICE1;
  8394. }
  8395. clif_emotion(&sd->bl, emoticon);
  8396. } else
  8397. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8398. }
  8399. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8400. /// 00c2 <count>.L
  8401. void clif_user_count(struct map_session_data* sd, int count)
  8402. {
  8403. int fd = sd->fd;
  8404. WFIFOHEAD(fd,packet_len(0xc2));
  8405. WFIFOW(fd,0) = 0xc2;
  8406. WFIFOL(fd,2) = count;
  8407. WFIFOSET(fd,packet_len(0xc2));
  8408. }
  8409. /// /w /who (CZ_REQ_USER_COUNT).
  8410. /// Request to display amount of currently connected players.
  8411. /// 00c1
  8412. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8413. {
  8414. clif_user_count(sd, map_getusers());
  8415. }
  8416. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8417. {
  8418. if (pc_isdead(sd)) {
  8419. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8420. return;
  8421. }
  8422. if (sd->sc.count &&
  8423. (sd->sc.data[SC_TRICKDEAD] ||
  8424. sd->sc.data[SC_AUTOCOUNTER] ||
  8425. sd->sc.data[SC_BLADESTOP] ||
  8426. sd->sc.data[SC__MANHOLE] ||
  8427. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8428. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8429. return;
  8430. pc_stop_walking(sd, 1);
  8431. pc_stop_attack(sd);
  8432. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8433. target_id = sd->bl.id;
  8434. switch(action_type)
  8435. {
  8436. case 0x00: // once attack
  8437. case 0x07: // continuous attack
  8438. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8439. return;
  8440. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  8441. return;
  8442. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8443. return;
  8444. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8445. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8446. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8447. return;
  8448. }
  8449. }
  8450. pc_delinvincibletimer(sd);
  8451. sd->idletime = last_tick;
  8452. unit_attack(&sd->bl, target_id, action_type != 0);
  8453. break;
  8454. case 0x02: // sitdown
  8455. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8456. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8457. break;
  8458. }
  8459. if(pc_issit(sd)) {
  8460. //Bugged client? Just refresh them.
  8461. clif_sitting(&sd->bl);
  8462. return;
  8463. }
  8464. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8465. break;
  8466. if (sd->sc.count && (
  8467. sd->sc.data[SC_DANCING] ||
  8468. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8469. )) //No sitting during these states either.
  8470. break;
  8471. sd->idletime = last_tick;
  8472. pc_setsit(sd);
  8473. skill_sit(sd,1);
  8474. clif_sitting(&sd->bl);
  8475. break;
  8476. case 0x03: // standup
  8477. if (!pc_issit(sd)) {
  8478. //Bugged client? Just refresh them.
  8479. clif_standing(&sd->bl);
  8480. return;
  8481. }
  8482. sd->idletime = last_tick;
  8483. pc_setstand(sd);
  8484. skill_sit(sd,0);
  8485. clif_standing(&sd->bl);
  8486. break;
  8487. }
  8488. }
  8489. /// Request for an action.
  8490. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8491. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8492. /// action:
  8493. /// 0 = attack
  8494. /// 1 = pick up item
  8495. /// 2 = sit down
  8496. /// 3 = stand up
  8497. /// 7 = continous attack
  8498. /// 12 = (touch skill?)
  8499. /// There are various variants of this packet, some of them have padding between fields.
  8500. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8501. {
  8502. clif_parse_ActionRequest_sub(sd,
  8503. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8504. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8505. gettick()
  8506. );
  8507. }
  8508. /// Response to the death/system menu (CZ_RESTART).
  8509. /// 00b2 <type>.B
  8510. /// type:
  8511. /// 0 = restart (respawn)
  8512. /// 1 = char-select (disconnect)
  8513. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8514. {
  8515. switch(RFIFOB(fd,2)) {
  8516. case 0x00:
  8517. pc_respawn(sd,CLR_RESPAWN);
  8518. break;
  8519. case 0x01:
  8520. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8521. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8522. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8523. { //Send to char-server for character selection.
  8524. chrif_charselectreq(sd, session[fd]->client_addr);
  8525. } else {
  8526. clif_disconnect_ack(sd, 1);
  8527. }
  8528. break;
  8529. }
  8530. }
  8531. /// Validates and processes whispered messages (CZ_WHISPER).
  8532. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8533. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8534. {
  8535. struct map_session_data* dstsd;
  8536. int i;
  8537. char *target, *message;
  8538. int namelen, messagelen;
  8539. // validate packet and retrieve name and message
  8540. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8541. return;
  8542. if ( is_atcommand(fd, sd, message, 1) )
  8543. return;
  8544. if (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8545. return;
  8546. if (battle_config.min_chat_delay) { //[Skotlex]
  8547. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8548. return;
  8549. }
  8550. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8551. }
  8552. // Reset idle time when using whisper/main chat.
  8553. sd->idletime = last_tick;
  8554. // Chat logging type 'W' / Whisper
  8555. 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);
  8556. //-------------------------------------------------------//
  8557. // Lordalfa - Paperboy - To whisper NPC commands //
  8558. //-------------------------------------------------------//
  8559. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8560. {
  8561. char* str = target+4; //Skip the NPC: string part.
  8562. struct npc_data* npc;
  8563. if ((npc = npc_name2id(str))) {
  8564. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8565. char *split;
  8566. char output[256];
  8567. str = message;
  8568. // skip codepage indicator, if detected
  8569. if( str[0] == '|' && strlen(str) >= 4 )
  8570. str += 3;
  8571. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8572. split = strchr(str,'#');
  8573. if( split == NULL ) { // use the remaining string
  8574. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8575. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8576. split_data[i][0] = '\0';
  8577. break;
  8578. }
  8579. *split = '\0';
  8580. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8581. str = split+1;
  8582. }
  8583. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8584. sprintf(output, "@whispervar%d$", i);
  8585. set_var(sd,output,(char *) split_data[i]);
  8586. }
  8587. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8588. npc_event(sd,output,0); // Calls the NPC label
  8589. return;
  8590. }
  8591. } else if( target[0] == '#' ) {
  8592. struct Channel *channel = NULL;
  8593. char* chname = target;
  8594. channel = channel_name2channel(chname,sd,3);
  8595. if(channel){
  8596. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  8597. channel_send(channel,sd,message);
  8598. }
  8599. else if( channel->pass[0] == '\0') { //no pass needed
  8600. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  8601. }
  8602. else {
  8603. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  8604. }
  8605. return;
  8606. }
  8607. }
  8608. // searching destination character
  8609. dstsd = map_nick2sd(target);
  8610. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8611. // player is not on this map-server
  8612. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8613. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8614. // and if we ask for 'Test', we must not contact 'test' player
  8615. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8616. intif_wis_message(sd, target, message, messagelen);
  8617. return;
  8618. }
  8619. // if player ignores everyone
  8620. if (dstsd->state.ignoreAll) {
  8621. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8622. clif_wis_end(fd, 1); // 1: target character is not loged in
  8623. else
  8624. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8625. return;
  8626. }
  8627. // if player is autotrading
  8628. if( dstsd->state.autotrade == 1 ) {
  8629. char output[256];
  8630. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8631. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8632. return;
  8633. }
  8634. // if player ignores the source character
  8635. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8636. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8637. clif_wis_end(fd, 2); // 2: ignored by target
  8638. return;
  8639. }
  8640. // notify sender of success
  8641. clif_wis_end(fd, 0); // 0: success to send wisper
  8642. // Normal message
  8643. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8644. }
  8645. /// /b /nb (CZ_BROADCAST).
  8646. /// Request to broadcast a message on whole server.
  8647. /// 0099 <packet len>.W <text>.?B 00
  8648. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  8649. char command[CHAT_SIZE_MAX+11];
  8650. char* msg = (char*)RFIFOP(fd,4);
  8651. unsigned int len = RFIFOW(fd,2)-4;
  8652. // as the length varies depending on the command used, just block unreasonably long strings
  8653. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8654. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8655. is_atcommand(fd, sd, command, 1);
  8656. }
  8657. /// Request to pick up an item.
  8658. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8659. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8660. /// There are various variants of this packet, some of them have padding between fields.
  8661. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8662. {
  8663. struct flooritem_data *fitem;
  8664. int map_object_id;
  8665. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8666. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8667. do {
  8668. if (pc_isdead(sd)) {
  8669. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8670. break;
  8671. }
  8672. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8673. break;
  8674. if( sd->sc.cant.pickup )
  8675. break;
  8676. if (pc_cant_act(sd))
  8677. break;
  8678. if (!pc_takeitem(sd, fitem))
  8679. break;
  8680. return;
  8681. } while (0);
  8682. // Client REQUIRES a fail packet or you can no longer pick items.
  8683. clif_additem(sd,0,0,6);
  8684. }
  8685. /// Request to drop an item.
  8686. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8687. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8688. /// There are various variants of this packet, some of them have padding between fields.
  8689. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8690. {
  8691. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8692. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8693. for(;;) {
  8694. if (pc_isdead(sd))
  8695. break;
  8696. if (pc_cant_act2(sd))
  8697. break;
  8698. if (sd->sc.count && (
  8699. sd->sc.data[SC_AUTOCOUNTER] ||
  8700. sd->sc.data[SC_BLADESTOP] ||
  8701. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8702. ))
  8703. break;
  8704. if (!pc_dropitem(sd, item_index, item_amount))
  8705. break;
  8706. return;
  8707. }
  8708. //Because the client does not like being ignored.
  8709. clif_dropitem(sd, item_index,0);
  8710. }
  8711. /// Request to use an item.
  8712. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8713. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8714. /// There are various variants of this packet, some of them have padding between fields.
  8715. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8716. {
  8717. int n;
  8718. if (pc_isdead(sd)) {
  8719. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8720. return;
  8721. }
  8722. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  8723. return;
  8724. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8725. sd->idletime = last_tick;
  8726. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8727. if(n <0 || n >= MAX_INVENTORY)
  8728. return;
  8729. if (!pc_useitem(sd,n))
  8730. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8731. }
  8732. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8733. /// 00a9 <index>.W <position>.W
  8734. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8735. {
  8736. int index;
  8737. if(pc_isdead(sd)) {
  8738. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8739. return;
  8740. }
  8741. index = RFIFOW(fd,2)-2;
  8742. if (index < 0 || index >= MAX_INVENTORY)
  8743. return; //Out of bounds check.
  8744. if(sd->npc_id) {
  8745. if (!sd->npc_item_flag)
  8746. return;
  8747. } else if (sd->state.storage_flag || sd->sc.opt1)
  8748. ; //You can equip/unequip stuff while storage is open/under status changes
  8749. else if (pc_cant_act2(sd))
  8750. return;
  8751. if(!sd->status.inventory[index].identify) {
  8752. clif_equipitemack(sd,index,0,0); // fail
  8753. return;
  8754. }
  8755. if(!sd->inventory_data[index])
  8756. return;
  8757. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8758. pet_equipitem(sd,index);
  8759. return;
  8760. }
  8761. //Client doesn't send the position for ammo.
  8762. if(sd->inventory_data[index]->type == IT_AMMO)
  8763. pc_equipitem(sd,index,EQP_AMMO);
  8764. else
  8765. pc_equipitem(sd,index,RFIFOW(fd,4));
  8766. }
  8767. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8768. /// 00ab <index>.W
  8769. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8770. {
  8771. int index;
  8772. if(pc_isdead(sd)) {
  8773. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8774. return;
  8775. }
  8776. if (sd->npc_id) {
  8777. if (!sd->npc_item_flag)
  8778. return;
  8779. } else if (sd->state.storage_flag || sd->sc.opt1)
  8780. ; //You can equip/unequip stuff while storage is open/under status changes
  8781. else if (pc_cant_act2(sd))
  8782. return;
  8783. index = RFIFOW(fd,2)-2;
  8784. pc_unequipitem(sd,index,1);
  8785. }
  8786. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8787. /// 0090 <id>.L <type>.B
  8788. /// type:
  8789. /// 1 = click
  8790. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8791. {
  8792. struct block_list *bl;
  8793. if(pc_isdead(sd)) {
  8794. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8795. return;
  8796. }
  8797. if (pc_cant_act2(sd))
  8798. return;
  8799. bl = map_id2bl(RFIFOL(fd,2));
  8800. if (!bl) return;
  8801. switch (bl->type) {
  8802. case BL_MOB:
  8803. case BL_PC:
  8804. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8805. break;
  8806. case BL_NPC:
  8807. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8808. npc_click(sd,(TBL_NPC*)bl);
  8809. break;
  8810. }
  8811. }
  8812. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8813. /// 00c5 <id>.L <type>.B
  8814. /// type:
  8815. /// 0 = buy
  8816. /// 1 = sell
  8817. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8818. {
  8819. if (sd->state.trading)
  8820. return;
  8821. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8822. }
  8823. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  8824. /// 00ca <result>.B
  8825. /// result:
  8826. /// 0 = "The deal has successfully completed."
  8827. /// 1 = "You do not have enough zeny."
  8828. /// 2 = "You are over your Weight Limit."
  8829. /// 3 = "Out of the maximum capacity, you have too many items."
  8830. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  8831. {
  8832. int fd = sd->fd;
  8833. WFIFOHEAD(fd,packet_len(0xca));
  8834. WFIFOW(fd,0) = 0xca;
  8835. WFIFOB(fd,2) = result;
  8836. WFIFOSET(fd,packet_len(0xca));
  8837. }
  8838. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8839. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8840. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8841. {
  8842. int n = (RFIFOW(fd,2)-4) /4;
  8843. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8844. int result;
  8845. if( sd->state.trading || !sd->npc_shopid )
  8846. result = 1;
  8847. else
  8848. result = npc_buylist(sd,n,item_list);
  8849. sd->npc_shopid = 0; //Clear shop data.
  8850. clif_npc_buy_result(sd, result);
  8851. }
  8852. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  8853. /// 00cb <result>.B
  8854. /// result:
  8855. /// 0 = "The deal has successfully completed."
  8856. /// 1 = "The deal has failed."
  8857. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  8858. {
  8859. int fd = sd->fd;
  8860. WFIFOHEAD(fd,packet_len(0xcb));
  8861. WFIFOW(fd,0) = 0xcb;
  8862. WFIFOB(fd,2) = result;
  8863. WFIFOSET(fd,packet_len(0xcb));
  8864. }
  8865. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8866. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8867. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8868. {
  8869. int fail=0,n;
  8870. unsigned short *item_list;
  8871. n = (RFIFOW(fd,2)-4) /4;
  8872. item_list = (unsigned short*)RFIFOP(fd,4);
  8873. if (sd->state.trading || !sd->npc_shopid)
  8874. fail = 1;
  8875. else
  8876. fail = npc_selllist(sd,n,item_list);
  8877. sd->npc_shopid = 0; //Clear shop data.
  8878. clif_npc_sell_result(sd, fail);
  8879. }
  8880. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8881. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8882. /// type:
  8883. /// 0 = private
  8884. /// 1 = public
  8885. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8886. {
  8887. int len = RFIFOW(fd,2)-15;
  8888. int limit = RFIFOW(fd,4);
  8889. bool pub = (RFIFOB(fd,6) != 0);
  8890. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8891. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8892. char s_password[CHATROOM_PASS_SIZE];
  8893. char s_title[CHATROOM_TITLE_SIZE];
  8894. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8895. return;
  8896. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8897. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8898. return;
  8899. }
  8900. if( npc_isnear(&sd->bl) ) {
  8901. // uncomment to send msg_txt.
  8902. //char output[150];
  8903. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  8904. //clif_displaymessage(sd->fd, output);
  8905. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  8906. return;
  8907. }
  8908. if( len <= 0 )
  8909. return; // invalid input
  8910. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8911. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8912. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8913. }
  8914. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8915. /// 00d9 <chat ID>.L <passwd>.8B
  8916. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8917. {
  8918. int chatid = RFIFOL(fd,2);
  8919. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8920. chat_joinchat(sd,chatid,password);
  8921. }
  8922. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8923. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8924. /// type:
  8925. /// 0 = private
  8926. /// 1 = public
  8927. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8928. {
  8929. int len = RFIFOW(fd,2)-15;
  8930. int limit = RFIFOW(fd,4);
  8931. bool pub = (RFIFOB(fd,6) != 0);
  8932. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8933. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8934. char s_password[CHATROOM_PASS_SIZE];
  8935. char s_title[CHATROOM_TITLE_SIZE];
  8936. if( len <= 0 )
  8937. return; // invalid input
  8938. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8939. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8940. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8941. }
  8942. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8943. /// 00e0 <role>.L <nick>.24B
  8944. /// role:
  8945. /// 0 = owner
  8946. /// 1 = normal
  8947. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8948. {
  8949. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8950. }
  8951. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8952. /// 00e2 <name>.24B
  8953. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8954. {
  8955. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8956. }
  8957. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8958. /// 00e3
  8959. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8960. {
  8961. chat_leavechat(sd,0);
  8962. }
  8963. //Handles notifying asker and rejecter of what has just ocurred.
  8964. //Type is used to determine the correct msg_txt to use:
  8965. //0:
  8966. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  8967. {
  8968. const char* msg;
  8969. char output[256];
  8970. // Your request has been rejected by autoreject option.
  8971. msg = msg_txt(sd,392);
  8972. clif_disp_onlyself(sd, msg, strlen(msg));
  8973. //Notice that a request was rejected.
  8974. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  8975. clif_disp_onlyself(tsd, output, strlen(output));
  8976. }
  8977. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8978. /// 00e4 <account id>.L
  8979. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8980. {
  8981. struct map_session_data *t_sd;
  8982. t_sd = map_id2sd(RFIFOL(fd,2));
  8983. if(!sd->chatID && pc_cant_act(sd))
  8984. return; //You can trade while in a chatroom.
  8985. // @noask [LuzZza]
  8986. if(t_sd && t_sd->state.noask) {
  8987. clif_noask_sub(sd, t_sd, 0);
  8988. return;
  8989. }
  8990. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  8991. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8992. return;
  8993. }
  8994. trade_traderequest(sd,t_sd);
  8995. }
  8996. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8997. /// 00e6 <result>.B
  8998. /// result:
  8999. /// 3 = accepted
  9000. /// 4 = rejected
  9001. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9002. {
  9003. trade_tradeack(sd,RFIFOB(fd,2));
  9004. }
  9005. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9006. /// 00e8 <index>.W <amount>.L
  9007. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9008. {
  9009. short index = RFIFOW(fd,2);
  9010. int amount = RFIFOL(fd,4);
  9011. if( index == 0 )
  9012. trade_tradeaddzeny(sd, amount);
  9013. else
  9014. trade_tradeadditem(sd, index, (short)amount);
  9015. }
  9016. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9017. /// 00eb
  9018. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9019. {
  9020. trade_tradeok(sd);
  9021. }
  9022. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9023. /// 00ed
  9024. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9025. {
  9026. trade_tradecancel(sd);
  9027. }
  9028. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9029. /// 00ef
  9030. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9031. {
  9032. trade_tradecommit(sd);
  9033. }
  9034. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9035. /// 0118
  9036. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9037. {
  9038. pc_stop_attack(sd);
  9039. }
  9040. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9041. /// 0126 <index>.W <amount>.L
  9042. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9043. {
  9044. if (pc_istrading(sd))
  9045. return;
  9046. if (!pc_iscarton(sd))
  9047. return;
  9048. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9049. }
  9050. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9051. /// 0127 <index>.W <amount>.L
  9052. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9053. {
  9054. if (!pc_iscarton(sd))
  9055. return;
  9056. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9057. }
  9058. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9059. /// 012a
  9060. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9061. {
  9062. /**
  9063. * Attempts to remove these options when this function is called (will remove all available)
  9064. **/
  9065. #ifdef NEW_CARTS
  9066. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9067. if( sd->sc.data[SC_PUSH_CART] )
  9068. pc_setcart(sd,0);
  9069. #else
  9070. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9071. #endif
  9072. }
  9073. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9074. /// 01af <num>.W
  9075. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9076. {// TODO: State tracking?
  9077. int type;
  9078. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  9079. return;
  9080. type = (int)RFIFOW(fd,2);
  9081. #ifdef NEW_CARTS
  9082. if( (type == 9 && sd->status.base_level > 131) ||
  9083. (type == 8 && sd->status.base_level > 121) ||
  9084. (type == 7 && sd->status.base_level > 111) ||
  9085. (type == 6 && sd->status.base_level > 101) ||
  9086. (type == 5 && sd->status.base_level > 90) ||
  9087. (type == 4 && sd->status.base_level > 80) ||
  9088. (type == 3 && sd->status.base_level > 65) ||
  9089. (type == 2 && sd->status.base_level > 40) ||
  9090. (type == 1))
  9091. #else
  9092. if( (type == 5 && sd->status.base_level > 90) ||
  9093. (type == 4 && sd->status.base_level > 80) ||
  9094. (type == 3 && sd->status.base_level > 65) ||
  9095. (type == 2 && sd->status.base_level > 40) ||
  9096. (type == 1))
  9097. #endif
  9098. pc_setcart(sd,type);
  9099. }
  9100. /// Request to increase status (CZ_STATUS_CHANGE).
  9101. /// 00bb <status id>.W <amount>.B
  9102. /// status id:
  9103. /// SP_STR ~ SP_LUK
  9104. /// amount:
  9105. /// client sends always 1 for this, even when using /str+ and
  9106. /// the like
  9107. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9108. {
  9109. pc_statusup(sd,RFIFOW(fd,2));
  9110. }
  9111. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9112. /// 0112 <skill id>.W
  9113. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9114. {
  9115. pc_skillup(sd,RFIFOW(fd,2));
  9116. }
  9117. 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)
  9118. {
  9119. int lv;
  9120. if( !hd )
  9121. return;
  9122. if( skillnotok_hom(skill_id, hd) )
  9123. return;
  9124. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9125. target_id = hd->bl.id;
  9126. if( hd->ud.skilltimer != INVALID_TIMER )
  9127. {
  9128. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9129. }
  9130. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9131. return;
  9132. lv = merc_hom_checkskill(hd, skill_id);
  9133. if( skill_lv > lv )
  9134. skill_lv = lv;
  9135. if( skill_lv )
  9136. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9137. }
  9138. 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)
  9139. {
  9140. int lv;
  9141. if( !hd )
  9142. return;
  9143. if( skillnotok_hom(skill_id, hd) )
  9144. return;
  9145. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9146. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9147. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9148. return;
  9149. if( hd->sc.data[SC_BASILICA] )
  9150. return;
  9151. lv = merc_hom_checkskill(hd, skill_id);
  9152. if( skill_lv > lv )
  9153. skill_lv = lv;
  9154. if( skill_lv )
  9155. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9156. }
  9157. 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)
  9158. {
  9159. int lv;
  9160. if( !md )
  9161. return;
  9162. if( skillnotok_mercenary(skill_id, md) )
  9163. return;
  9164. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9165. target_id = md->bl.id;
  9166. if( md->ud.skilltimer != INVALID_TIMER )
  9167. {
  9168. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9169. }
  9170. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9171. return;
  9172. lv = mercenary_checkskill(md, skill_id);
  9173. if( skill_lv > lv )
  9174. skill_lv = lv;
  9175. if( skill_lv )
  9176. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9177. }
  9178. 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)
  9179. {
  9180. int lv;
  9181. if( !md )
  9182. return;
  9183. if( skillnotok_mercenary(skill_id, md) )
  9184. return;
  9185. if( md->ud.skilltimer != INVALID_TIMER )
  9186. return;
  9187. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9188. {
  9189. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9190. return;
  9191. }
  9192. if( md->sc.data[SC_BASILICA] )
  9193. return;
  9194. lv = mercenary_checkskill(md, skill_id);
  9195. if( skill_lv > lv )
  9196. skill_lv = lv;
  9197. if( skill_lv )
  9198. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9199. }
  9200. /// Request to use a targeted skill.
  9201. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9202. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9203. /// There are various variants of this packet, some of them have padding between fields.
  9204. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9205. {
  9206. uint16 skill_id, skill_lv;
  9207. int tmp, target_id;
  9208. unsigned int tick = gettick();
  9209. skill_lv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9210. skill_id = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9211. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9212. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9213. tmp = skill_get_inf(skill_id);
  9214. if (tmp&INF_GROUND_SKILL || !tmp)
  9215. return; //Using a ground/passive skill on a target? WRONG.
  9216. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9217. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9218. return;
  9219. }
  9220. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9221. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9222. return;
  9223. }
  9224. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9225. sd->idletime = last_tick;
  9226. if( sd->npc_id ){
  9227. #ifdef RENEWAL
  9228. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9229. #endif
  9230. return;
  9231. }
  9232. 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)) )
  9233. return;
  9234. if( pc_issit(sd) )
  9235. return;
  9236. if( skillnotok(skill_id, sd) )
  9237. return;
  9238. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9239. target_id = sd->bl.id; // never trust the client
  9240. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9241. target_id = sd->bl.id;
  9242. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9243. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9244. return;
  9245. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9246. if( sd->skillitem != skill_id ) {
  9247. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9248. return;
  9249. }
  9250. }
  9251. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  9252. return;
  9253. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9254. return; // On basilica only caster can use Basilica again to stop it.
  9255. if( sd->menuskill_id ) {
  9256. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9257. clif_menuskill_clear(sd); //Cancel pet capture.
  9258. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9259. return; //Can't use skills while a menu is open.
  9260. }
  9261. if( sd->skillitem == skill_id ) {
  9262. if( skill_lv != sd->skillitemlv )
  9263. skill_lv = sd->skillitemlv;
  9264. if( !(tmp&INF_SELF_SKILL) )
  9265. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9266. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9267. return;
  9268. }
  9269. sd->skillitem = sd->skillitemlv = 0;
  9270. if( skill_id >= GD_SKILLBASE ) {
  9271. if( sd->state.gmaster_flag )
  9272. skill_lv = guild_checkskill(sd->state.gmaster_flag, skill_id);
  9273. else
  9274. skill_lv = 0;
  9275. } else {
  9276. tmp = pc_checkskill(sd, skill_id);
  9277. if( skill_lv > tmp )
  9278. skill_lv = tmp;
  9279. }
  9280. pc_delinvincibletimer(sd);
  9281. if( skill_lv )
  9282. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9283. }
  9284. /*==========================================
  9285. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9286. *------------------------------------------*/
  9287. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9288. {
  9289. unsigned int tick = gettick();
  9290. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9291. return; //Using a target skill on the ground? WRONG.
  9292. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9293. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9294. return;
  9295. }
  9296. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9297. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9298. return;
  9299. }
  9300. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9301. sd->idletime = last_tick;
  9302. if( skillnotok(skill_id, sd) )
  9303. return;
  9304. if( skillmoreinfo != -1 ) {
  9305. if( pc_issit(sd) ) {
  9306. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9307. return;
  9308. }
  9309. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9310. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9311. }
  9312. if( sd->ud.skilltimer != INVALID_TIMER )
  9313. return;
  9314. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9315. if( sd->skillitem != skill_id ) {
  9316. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9317. return;
  9318. }
  9319. }
  9320. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  9321. return;
  9322. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9323. return; // On basilica only caster can use Basilica again to stop it.
  9324. if( sd->menuskill_id ) {
  9325. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9326. clif_menuskill_clear(sd); //Cancel pet capture.
  9327. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9328. return; //Can't use skills while a menu is open.
  9329. }
  9330. pc_delinvincibletimer(sd);
  9331. if( sd->skillitem == skill_id ) {
  9332. if( skill_lv != sd->skillitemlv )
  9333. skill_lv = sd->skillitemlv;
  9334. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9335. } else {
  9336. int lv;
  9337. sd->skillitem = sd->skillitemlv = 0;
  9338. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9339. if( skill_lv > lv )
  9340. skill_lv = lv;
  9341. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9342. }
  9343. }
  9344. }
  9345. /// Request to use a ground skill.
  9346. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9347. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9348. /// There are various variants of this packet, some of them have padding between fields.
  9349. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9350. {
  9351. if (pc_cant_act(sd))
  9352. return;
  9353. if (pc_issit(sd))
  9354. return;
  9355. clif_parse_UseSkillToPosSub(fd, sd,
  9356. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9357. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9358. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9359. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9360. -1 //Skill more info.
  9361. );
  9362. }
  9363. /// Request to use a ground skill with text.
  9364. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9365. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9366. /// There are various variants of this packet, some of them have padding between fields.
  9367. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9368. {
  9369. if (pc_cant_act(sd))
  9370. return;
  9371. if (pc_issit(sd))
  9372. return;
  9373. clif_parse_UseSkillToPosSub(fd, sd,
  9374. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9375. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9376. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9377. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9378. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9379. );
  9380. }
  9381. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9382. /// 011b <skill id>.W <map name>.16B
  9383. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9384. {
  9385. uint16 skill_id = RFIFOW(fd,2);
  9386. char map_name[MAP_NAME_LENGTH];
  9387. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9388. if(skill_id != sd->menuskill_id)
  9389. return;
  9390. if( pc_cant_act(sd) ) {
  9391. clif_menuskill_clear(sd);
  9392. return;
  9393. }
  9394. pc_delinvincibletimer(sd);
  9395. skill_castend_map(sd,skill_id,map_name);
  9396. }
  9397. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9398. /// 011d
  9399. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9400. {
  9401. if (!pc_isdead(sd))
  9402. pc_memo(sd,-1);
  9403. }
  9404. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9405. /// 018e <name id>.W { <material id>.W }*3
  9406. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9407. {
  9408. switch( sd->menuskill_id ) {
  9409. case -1:
  9410. case AM_PHARMACY:
  9411. case RK_RUNEMASTERY:
  9412. case GC_RESEARCHNEWPOISON:
  9413. break;
  9414. default:
  9415. return;
  9416. }
  9417. if (pc_istrading(sd)) {
  9418. //Make it fail to avoid shop exploits where you sell something different than you see.
  9419. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9420. clif_menuskill_clear(sd);
  9421. return;
  9422. }
  9423. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9424. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9425. clif_menuskill_clear(sd);
  9426. }
  9427. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9428. /// 025b <mk type>.W <name id>.W
  9429. /// mk type:
  9430. /// 1 = cooking
  9431. /// 2 = arrow
  9432. /// 3 = elemental
  9433. /// 4 = GN_MIX_COOKING
  9434. /// 5 = GN_MAKEBOMB
  9435. /// 6 = GN_S_PHARMACY
  9436. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9437. int type = RFIFOW(fd,2);
  9438. int nameid = RFIFOW(fd,4);
  9439. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9440. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  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. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9449. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9450. clif_menuskill_clear(sd);
  9451. }
  9452. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9453. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9454. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9455. {
  9456. if (sd->menuskill_id != BS_REPAIRWEAPON)
  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. skill_repairweapon(sd,RFIFOW(fd,2));
  9465. clif_menuskill_clear(sd);
  9466. }
  9467. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9468. /// 0222 <index>.L
  9469. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9470. {
  9471. int idx;
  9472. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9473. return;
  9474. if (pc_istrading(sd)) {
  9475. //Make it fail to avoid shop exploits where you sell something different than you see.
  9476. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9477. clif_menuskill_clear(sd);
  9478. return;
  9479. }
  9480. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9481. skill_weaponrefine(sd, idx-2);
  9482. clif_menuskill_clear(sd);
  9483. }
  9484. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9485. /// 00b8 <npc id>.L <choice>.B
  9486. /// choice:
  9487. /// 1~254 = menu item
  9488. /// 255 = cancel
  9489. /// NOTE: If there were more than 254 items in the list, choice
  9490. /// overflows to choice%256.
  9491. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9492. {
  9493. int npc_id = RFIFOL(fd,2);
  9494. uint8 select = RFIFOB(fd,6);
  9495. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9496. #ifdef SECURE_NPCTIMEOUT
  9497. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9498. #endif
  9499. TBL_NPC* nd = map_id2nd(npc_id);
  9500. 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);
  9501. clif_GM_kick(NULL,sd);
  9502. #ifdef SECURE_NPCTIMEOUT
  9503. }
  9504. #endif
  9505. return;
  9506. }
  9507. sd->npc_menu = select;
  9508. npc_scriptcont(sd,npc_id, false);
  9509. }
  9510. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9511. /// 00b9 <npc id>.L
  9512. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9513. {
  9514. npc_scriptcont(sd,RFIFOL(fd,2), false);
  9515. }
  9516. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9517. /// 0143 <npc id>.L <value>.L
  9518. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9519. {
  9520. int npcid = RFIFOL(fd,2);
  9521. int amount = (int)RFIFOL(fd,6);
  9522. sd->npc_amount = amount;
  9523. npc_scriptcont(sd, npcid, false);
  9524. }
  9525. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9526. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9527. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9528. {
  9529. int message_len = RFIFOW(fd,2)-8;
  9530. int npcid = RFIFOL(fd,4);
  9531. const char* message = (char*)RFIFOP(fd,8);
  9532. if( message_len <= 0 )
  9533. return; // invalid input
  9534. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9535. npc_scriptcont(sd, npcid, false);
  9536. }
  9537. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9538. /// 0146 <npc id>.L
  9539. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9540. {
  9541. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9542. return;
  9543. npc_scriptcont(sd, RFIFOL(fd,2), true);
  9544. }
  9545. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9546. /// 0178 <index>.W
  9547. /// index:
  9548. /// -1 = cancel
  9549. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9550. {
  9551. short idx = RFIFOW(fd,2);
  9552. if (sd->menuskill_id != MC_IDENTIFY)
  9553. return;
  9554. if( idx == -1 ) {// cancel pressed
  9555. clif_menuskill_clear(sd);
  9556. return;
  9557. }
  9558. skill_identify(sd,idx-2);
  9559. clif_menuskill_clear(sd);
  9560. }
  9561. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9562. /// 01ae <name id>.W
  9563. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9564. {
  9565. if (pc_istrading(sd)) {
  9566. //Make it fail to avoid shop exploits where you sell something different than you see.
  9567. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9568. clif_menuskill_clear(sd);
  9569. return;
  9570. }
  9571. switch( sd->menuskill_id ) {
  9572. case AC_MAKINGARROW:
  9573. skill_arrow_create(sd,RFIFOW(fd,2));
  9574. break;
  9575. case SA_CREATECON:
  9576. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9577. break;
  9578. case WL_READING_SB:
  9579. skill_spellbook(sd,RFIFOW(fd,2));
  9580. break;
  9581. case GC_POISONINGWEAPON:
  9582. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9583. break;
  9584. case NC_MAGICDECOY:
  9585. skill_magicdecoy(sd,RFIFOW(fd,2));
  9586. break;
  9587. }
  9588. clif_menuskill_clear(sd);
  9589. }
  9590. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9591. /// 01ce <skill id>.L
  9592. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9593. {
  9594. if (sd->menuskill_id != SA_AUTOSPELL)
  9595. return;
  9596. skill_autospell(sd,RFIFOL(fd,2));
  9597. clif_menuskill_clear(sd);
  9598. }
  9599. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9600. /// 017a <card index>.W
  9601. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9602. {
  9603. if (sd->state.trading != 0)
  9604. return;
  9605. clif_use_card(sd,RFIFOW(fd,2)-2);
  9606. }
  9607. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9608. /// 017c <card index>.W <equip index>.W
  9609. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9610. {
  9611. if (sd->state.trading != 0)
  9612. return;
  9613. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9614. }
  9615. /// Request of character's name by char ID.
  9616. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9617. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9618. /// There are various variants of this packet, some of them have padding between fields.
  9619. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9620. {
  9621. int charid;
  9622. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9623. map_reqnickdb(sd, charid);
  9624. }
  9625. /// /resetskill /resetstate (CZ_RESET).
  9626. /// Request to reset stats or skills.
  9627. /// 0197 <type>.W
  9628. /// type:
  9629. /// 0 = state
  9630. /// 1 = skill
  9631. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9632. char cmd[15];
  9633. if( RFIFOW(fd,2) )
  9634. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9635. else
  9636. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9637. is_atcommand(fd, sd, cmd, 1);
  9638. }
  9639. /// /lb /nlb (CZ_LOCALBROADCAST).
  9640. /// Request to broadcast a message on current map.
  9641. /// 019c <packet len>.W <text>.?B
  9642. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9643. {
  9644. char command[CHAT_SIZE_MAX+16];
  9645. char* msg = (char*)RFIFOP(fd,4);
  9646. unsigned int len = RFIFOW(fd,2)-4;
  9647. // as the length varies depending on the command used, just block unreasonably long strings
  9648. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9649. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9650. is_atcommand(fd, sd, command, 1);
  9651. }
  9652. /// Request to move an item from inventory to storage.
  9653. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9654. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9655. /// There are various variants of this packet, some of them have padding between fields.
  9656. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9657. {
  9658. int item_index, item_amount;
  9659. if (pc_istrading(sd))
  9660. return;
  9661. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9662. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9663. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9664. return;
  9665. if (sd->state.storage_flag == 1)
  9666. storage_storageadd(sd, item_index, item_amount);
  9667. else
  9668. if (sd->state.storage_flag == 2)
  9669. storage_guild_storageadd(sd, item_index, item_amount);
  9670. }
  9671. /// Request to move an item from storage to inventory.
  9672. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9673. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9674. /// There are various variants of this packet, some of them have padding between fields.
  9675. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9676. {
  9677. int item_index, item_amount;
  9678. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9679. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9680. if (sd->state.storage_flag == 1)
  9681. storage_storageget(sd, item_index, item_amount);
  9682. else if(sd->state.storage_flag == 2)
  9683. storage_guild_storageget(sd, item_index, item_amount);
  9684. }
  9685. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9686. /// 0129 <index>.W <amount>.L
  9687. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9688. {
  9689. if( sd->state.vending )
  9690. return;
  9691. if (!pc_iscarton(sd))
  9692. return;
  9693. if (sd->state.storage_flag == 1)
  9694. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9695. else if (sd->state.storage_flag == 2)
  9696. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9697. }
  9698. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9699. /// 0128 <index>.W <amount>.L
  9700. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9701. {
  9702. if( sd->state.vending )
  9703. return;
  9704. if (!pc_iscarton(sd))
  9705. return;
  9706. if (sd->state.storage_flag == 1)
  9707. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9708. else
  9709. if (sd->state.storage_flag == 2)
  9710. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9711. }
  9712. /// Request to close storage (CZ_CLOSE_STORE).
  9713. /// 00f7
  9714. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9715. {
  9716. if( sd->state.storage_flag == 1 )
  9717. storage_storageclose(sd);
  9718. else
  9719. if( sd->state.storage_flag == 2 )
  9720. storage_guild_storageclose(sd);
  9721. }
  9722. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9723. /// 023a <info>.W
  9724. /// info:
  9725. /// 0 = password has not been set yet
  9726. /// 1 = storage is password-protected
  9727. /// 8 = too many wrong passwords
  9728. /// ? = ignored
  9729. /// NOTE: This packet is only available on certain non-kRO clients.
  9730. void clif_storagepassword(struct map_session_data* sd, short info)
  9731. {
  9732. int fd = sd->fd;
  9733. WFIFOHEAD(fd,packet_len(0x23a));
  9734. WFIFOW(fd,0) = 0x23a;
  9735. WFIFOW(fd,2) = info;
  9736. WFIFOSET(fd,packet_len(0x23a));
  9737. }
  9738. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9739. /// 023b <type>.W <password>.16B <new password>.16B
  9740. /// type:
  9741. /// 2 = change password
  9742. /// 3 = check password
  9743. /// NOTE: This packet is only available on certain non-kRO clients.
  9744. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9745. {
  9746. //TODO
  9747. }
  9748. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9749. /// 023c <result>.W <error count>.W
  9750. /// result:
  9751. /// 4 = password change success
  9752. /// 5 = password change failure
  9753. /// 6 = password check success
  9754. /// 7 = password check failure
  9755. /// 8 = too many wrong passwords
  9756. /// ? = ignored
  9757. /// NOTE: This packet is only available on certain non-kRO clients.
  9758. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9759. {
  9760. int fd = sd->fd;
  9761. WFIFOHEAD(fd,packet_len(0x23c));
  9762. WFIFOW(fd,0) = 0x23c;
  9763. WFIFOW(fd,2) = result;
  9764. WFIFOW(fd,4) = error_count;
  9765. WFIFOSET(fd,packet_len(0x23c));
  9766. }
  9767. /// Party creation request
  9768. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9769. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9770. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9771. {
  9772. char* name = (char*)RFIFOP(fd,2);
  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,0,0);
  9783. }
  9784. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9785. {
  9786. char* name = (char*)RFIFOP(fd,2);
  9787. int item1 = RFIFOB(fd,26);
  9788. int item2 = RFIFOB(fd,27);
  9789. name[NAME_LENGTH-1] = '\0';
  9790. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  9791. clif_displaymessage(fd, msg_txt(sd,227));
  9792. return;
  9793. }
  9794. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  9795. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9796. return;
  9797. }
  9798. party_create(sd,name,item1,item2);
  9799. }
  9800. /// Party invitation request
  9801. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9802. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9803. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9804. {
  9805. struct map_session_data *t_sd;
  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_id2sd(RFIFOL(fd,2));
  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. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9818. {
  9819. struct map_session_data *t_sd;
  9820. char *name = (char*)RFIFOP(fd,2);
  9821. name[NAME_LENGTH-1] = '\0';
  9822. if(map[sd->bl.m].flag.partylock) {// Party locked.
  9823. clif_displaymessage(fd, msg_txt(sd,227));
  9824. return;
  9825. }
  9826. t_sd = map_nick2sd(name);
  9827. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  9828. clif_noask_sub(sd, t_sd, 1);
  9829. return;
  9830. }
  9831. party_invite(sd, t_sd);
  9832. }
  9833. /// Party invitation reply
  9834. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9835. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9836. /// flag:
  9837. /// 0 = reject
  9838. /// 1 = accept
  9839. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9840. {
  9841. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9842. }
  9843. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9844. {
  9845. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9846. }
  9847. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9848. /// 0100
  9849. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9850. {
  9851. if(map[sd->bl.m].flag.partylock) { //Guild locked.
  9852. clif_displaymessage(fd, msg_txt(sd,227));
  9853. return;
  9854. }
  9855. party_leave(sd);
  9856. }
  9857. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9858. /// 0103 <account id>.L <char name>.24B
  9859. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9860. {
  9861. if(map[sd->bl.m].flag.partylock) { //Guild locked.
  9862. clif_displaymessage(fd, msg_txt(sd,227));
  9863. return;
  9864. }
  9865. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9866. }
  9867. /// Request to change party options.
  9868. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9869. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9870. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9871. {
  9872. struct party_data *p;
  9873. int i;
  9874. if( !sd->status.party_id )
  9875. return;
  9876. p = party_search(sd->status.party_id);
  9877. if( p == NULL )
  9878. return;
  9879. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9880. if( i == MAX_PARTY )
  9881. return; //Shouldn't happen
  9882. if( !p->party.member[i].leader )
  9883. return;
  9884. #if PACKETVER < 20090603
  9885. //Client can't change the item-field
  9886. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9887. #else
  9888. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9889. #endif
  9890. }
  9891. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9892. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9893. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9894. {
  9895. const char* text = (char*)RFIFOP(fd,4);
  9896. int textlen = RFIFOW(fd,2) - 4;
  9897. char *name, *message;
  9898. int namelen, messagelen;
  9899. // validate packet and retrieve name and message
  9900. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9901. return;
  9902. if( is_atcommand(fd, sd, message, 1) )
  9903. return;
  9904. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9905. return;
  9906. if( battle_config.min_chat_delay )
  9907. { //[Skotlex]
  9908. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9909. return;
  9910. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9911. }
  9912. // Reset idle time when using party chat.
  9913. sd->idletime = last_tick;
  9914. party_send_message(sd, text, textlen);
  9915. }
  9916. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9917. /// 07da <account id>.L
  9918. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9919. {
  9920. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9921. }
  9922. /// Party Booking in KRO [Spiria]
  9923. ///
  9924. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9925. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9926. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9927. {
  9928. short level = RFIFOW(fd,2);
  9929. short mapid = RFIFOW(fd,4);
  9930. short job[PARTY_BOOKING_JOBS];
  9931. int i;
  9932. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9933. job[i] = RFIFOB(fd,6+i*2);
  9934. party_booking_register(sd, level, mapid, job);
  9935. }
  9936. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9937. /// 0803 <result>.W
  9938. /// result:
  9939. /// 0 = success
  9940. /// 1 = failure
  9941. /// 2 = already registered
  9942. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9943. {
  9944. int fd = sd->fd;
  9945. WFIFOHEAD(fd,packet_len(0x803));
  9946. WFIFOW(fd,0) = 0x803;
  9947. WFIFOW(fd,2) = flag;
  9948. WFIFOSET(fd,packet_len(0x803));
  9949. }
  9950. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9951. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9952. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9953. {
  9954. short level = RFIFOW(fd,2);
  9955. short mapid = RFIFOW(fd,4);
  9956. short job = RFIFOW(fd,6);
  9957. unsigned long lastindex = RFIFOL(fd,8);
  9958. short resultcount = RFIFOW(fd,12);
  9959. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9960. }
  9961. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9962. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9963. /// more results:
  9964. /// 0 = no
  9965. /// 1 = yes
  9966. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9967. {
  9968. int i, j;
  9969. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9970. struct party_booking_ad_info *pb_ad;
  9971. WFIFOHEAD(fd,size*count + 5);
  9972. WFIFOW(fd,0) = 0x805;
  9973. WFIFOW(fd,2) = size*count + 5;
  9974. WFIFOB(fd,4) = more_result;
  9975. for(i=0; i<count; i++)
  9976. {
  9977. pb_ad = results[i];
  9978. WFIFOL(fd,i*size+5) = pb_ad->index;
  9979. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9980. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9981. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9982. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9983. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9984. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9985. }
  9986. WFIFOSET(fd,WFIFOW(fd,2));
  9987. }
  9988. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9989. /// 0806
  9990. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9991. {
  9992. if(party_booking_delete(sd))
  9993. clif_PartyBookingDeleteAck(sd, 0);
  9994. }
  9995. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9996. /// 0807 <result>.W
  9997. /// result:
  9998. /// 0 = success
  9999. /// 1 = success (auto-removed expired ad)
  10000. /// 2 = failure
  10001. /// 3 = nothing registered
  10002. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10003. {
  10004. int fd = sd->fd;
  10005. WFIFOHEAD(fd,packet_len(0x807));
  10006. WFIFOW(fd,0) = 0x807;
  10007. WFIFOW(fd,2) = flag;
  10008. WFIFOSET(fd,packet_len(0x807));
  10009. }
  10010. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10011. /// 0808 { <job>.W }*6
  10012. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10013. {
  10014. short job[PARTY_BOOKING_JOBS];
  10015. int i;
  10016. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10017. job[i] = RFIFOW(fd,2+i*2);
  10018. party_booking_update(sd, job);
  10019. }
  10020. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10021. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10022. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10023. {
  10024. int i;
  10025. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10026. if(pb_ad == NULL) return;
  10027. WBUFW(buf,0) = 0x809;
  10028. WBUFL(buf,2) = pb_ad->index;
  10029. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10030. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10031. WBUFW(buf,34) = pb_ad->p_detail.level;
  10032. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10033. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10034. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10035. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10036. }
  10037. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10038. /// 080a <index>.L { <job>.W }*6
  10039. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10040. {
  10041. int i;
  10042. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10043. if(pb_ad == NULL) return;
  10044. WBUFW(buf,0) = 0x80a;
  10045. WBUFL(buf,2) = pb_ad->index;
  10046. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10047. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10048. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10049. }
  10050. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10051. /// 080b <index>.L
  10052. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10053. {
  10054. uint8 buf[6];
  10055. WBUFW(buf,0) = 0x80b;
  10056. WBUFL(buf,2) = index;
  10057. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10058. }
  10059. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10060. /// 012e
  10061. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10062. {
  10063. vending_closevending(sd);
  10064. }
  10065. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10066. /// 0130 <account id>.L
  10067. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10068. {
  10069. if( sd->npc_id ) {// using an NPC
  10070. return;
  10071. }
  10072. vending_vendinglistreq(sd,RFIFOL(fd,2));
  10073. }
  10074. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10075. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10076. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  10077. {
  10078. int len = (int)RFIFOW(fd,2) - 8;
  10079. int id = (int)RFIFOL(fd,4);
  10080. const uint8* data = (uint8*)RFIFOP(fd,8);
  10081. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10082. // whether it fails or not, the buy window is closed
  10083. sd->vended_id = 0;
  10084. }
  10085. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10086. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10087. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  10088. {
  10089. int len = (int)RFIFOW(fd,2) - 12;
  10090. int aid = (int)RFIFOL(fd,4);
  10091. int uid = (int)RFIFOL(fd,8);
  10092. const uint8* data = (uint8*)RFIFOP(fd,12);
  10093. vending_purchasereq(sd, aid, uid, data, len/4);
  10094. // whether it fails or not, the buy window is closed
  10095. sd->vended_id = 0;
  10096. }
  10097. /// Confirm or cancel the shop preparation window.
  10098. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10099. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10100. /// result:
  10101. /// 0 = canceled
  10102. /// 1 = open
  10103. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  10104. {
  10105. short len = (short)RFIFOW(fd,2) - 85;
  10106. const char* message = (char*)RFIFOP(fd,4);
  10107. bool flag = (bool)RFIFOB(fd,84);
  10108. const uint8* data = (uint8*)RFIFOP(fd,85);
  10109. if( !flag )
  10110. sd->state.prevend = 0;
  10111. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10112. return;
  10113. if( map[sd->bl.m].flag.novending ) {
  10114. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10115. return;
  10116. }
  10117. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10118. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10119. return;
  10120. }
  10121. if( message[0] == '\0' ) // invalid input
  10122. return;
  10123. vending_openvending(sd, message, data, len/8);
  10124. }
  10125. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10126. /// 0165 <char id>.L <guild name>.24B
  10127. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  10128. {
  10129. char* name = (char*)RFIFOP(fd,6);
  10130. name[NAME_LENGTH-1] = '\0';
  10131. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10132. clif_displaymessage(fd, msg_txt(sd,228));
  10133. return;
  10134. }
  10135. guild_create(sd, name);
  10136. }
  10137. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10138. /// 014d
  10139. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10140. {
  10141. clif_guild_masterormember(sd);
  10142. }
  10143. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10144. /// 014f <type>.L
  10145. /// type:
  10146. /// 0 = basic info
  10147. /// 1 = member manager
  10148. /// 2 = positions
  10149. /// 3 = skills
  10150. /// 4 = expulsion list
  10151. /// 5 = unknown (GM_ALLGUILDLIST)
  10152. /// 6 = notice
  10153. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10154. {
  10155. if( !sd->status.guild_id && !sd->bg_id )
  10156. return;
  10157. switch( RFIFOL(fd,2) )
  10158. {
  10159. case 0: // Basic Information Guild, hostile alliance information
  10160. clif_guild_basicinfo(sd);
  10161. clif_guild_allianceinfo(sd);
  10162. break;
  10163. case 1: // Members list, list job title
  10164. clif_guild_positionnamelist(sd);
  10165. clif_guild_memberlist(sd);
  10166. break;
  10167. case 2: // List job title, title information list
  10168. clif_guild_positionnamelist(sd);
  10169. clif_guild_positioninfolist(sd);
  10170. break;
  10171. case 3: // Skill list
  10172. clif_guild_skillinfo(sd);
  10173. break;
  10174. case 4: // Expulsion list
  10175. clif_guild_expulsionlist(sd);
  10176. break;
  10177. default:
  10178. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10179. break;
  10180. }
  10181. }
  10182. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10183. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10184. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10185. {
  10186. int i;
  10187. if(!sd->state.gmaster_flag)
  10188. return;
  10189. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  10190. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10191. }
  10192. }
  10193. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10194. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10195. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10196. {
  10197. int i;
  10198. if(!sd->state.gmaster_flag)
  10199. return;
  10200. for(i=4;i<RFIFOW(fd,2);i+=12){
  10201. guild_change_memberposition(sd->status.guild_id,
  10202. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10203. }
  10204. }
  10205. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10206. /// 0151 <guild id>.L
  10207. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10208. {
  10209. struct guild* g;
  10210. int guild_id = RFIFOL(fd,2);
  10211. if( (g = guild_search(guild_id)) != NULL )
  10212. clif_guild_emblem(sd,g);
  10213. }
  10214. /// Validates data of a guild emblem (compressed bitmap)
  10215. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10216. {
  10217. bool success;
  10218. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10219. unsigned long buf_len = sizeof(buf);
  10220. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10221. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10222. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10223. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10224. ;
  10225. return success;
  10226. }
  10227. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10228. /// 0153 <packet len>.W <emblem data>.?B
  10229. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10230. {
  10231. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10232. const uint8* emblem = RFIFOP(fd,4);
  10233. if( !emblem_len || !sd->state.gmaster_flag )
  10234. return;
  10235. if( !clif_validate_emblem(emblem, emblem_len) )
  10236. {
  10237. 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);
  10238. return;
  10239. }
  10240. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10241. }
  10242. /// Guild notice update request (CZ_GUILD_NOTICE).
  10243. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10244. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10245. {
  10246. int guild_id = RFIFOL(fd,2);
  10247. char* msg1 = (char*)RFIFOP(fd,6);
  10248. char* msg2 = (char*)RFIFOP(fd,66);
  10249. if(!sd->state.gmaster_flag)
  10250. return;
  10251. // compensate for some client defects when using multilanguage mode
  10252. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10253. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10254. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10255. guild_change_notice(sd, guild_id, msg1, msg2);
  10256. }
  10257. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10258. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10259. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10260. {
  10261. struct map_session_data *t_sd;
  10262. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10263. clif_displaymessage(fd, msg_txt(sd,228));
  10264. return;
  10265. }
  10266. t_sd = map_id2sd(RFIFOL(fd,2));
  10267. // @noask [LuzZza]
  10268. if(t_sd && t_sd->state.noask) {
  10269. clif_noask_sub(sd, t_sd, 2);
  10270. return;
  10271. }
  10272. guild_invite(sd,t_sd);
  10273. }
  10274. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10275. /// 016b <guild id>.L <answer>.L
  10276. /// answer:
  10277. /// 0 = refuse
  10278. /// 1 = accept
  10279. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10280. {
  10281. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10282. }
  10283. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10284. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10285. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10286. {
  10287. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10288. clif_displaymessage(fd, msg_txt(sd,228));
  10289. return;
  10290. }
  10291. if( sd->bg_id ) {
  10292. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10293. return;
  10294. }
  10295. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10296. }
  10297. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10298. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10299. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10300. {
  10301. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10302. { // Guild locked.
  10303. clif_displaymessage(fd, msg_txt(sd,228));
  10304. return;
  10305. }
  10306. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10307. }
  10308. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10309. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10310. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10311. {
  10312. const char* text = (char*)RFIFOP(fd,4);
  10313. int textlen = RFIFOW(fd,2) - 4;
  10314. char *name, *message;
  10315. int namelen, messagelen;
  10316. // validate packet and retrieve name and message
  10317. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10318. return;
  10319. if( is_atcommand(fd, sd, message, 1) )
  10320. return;
  10321. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10322. return;
  10323. if( battle_config.min_chat_delay )
  10324. { //[Skotlex]
  10325. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10326. return;
  10327. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10328. }
  10329. // Reset idle time when using guild chat.
  10330. sd->idletime = last_tick;
  10331. if( sd->bg_id )
  10332. bg_send_message(sd, text, textlen);
  10333. else
  10334. guild_send_message(sd, text, textlen);
  10335. }
  10336. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10337. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10338. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10339. {
  10340. struct map_session_data *t_sd;
  10341. if(!sd->state.gmaster_flag)
  10342. return;
  10343. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10344. clif_displaymessage(fd, msg_txt(sd,228));
  10345. return;
  10346. }
  10347. t_sd = map_id2sd(RFIFOL(fd,2));
  10348. // @noask [LuzZza]
  10349. if(t_sd && t_sd->state.noask) {
  10350. clif_noask_sub(sd, t_sd, 3);
  10351. return;
  10352. }
  10353. guild_reqalliance(sd,t_sd);
  10354. }
  10355. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10356. /// 0172 <inviter account id>.L <answer>.L
  10357. /// answer:
  10358. /// 0 = refuse
  10359. /// 1 = accept
  10360. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10361. {
  10362. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10363. }
  10364. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10365. /// 0183 <opponent guild id>.L <relation>.L
  10366. /// relation:
  10367. /// 0 = Ally
  10368. /// 1 = Enemy
  10369. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10370. {
  10371. if(!sd->state.gmaster_flag)
  10372. return;
  10373. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10374. clif_displaymessage(fd, msg_txt(sd,228));
  10375. return;
  10376. }
  10377. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10378. }
  10379. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10380. /// 0180 <account id>.L
  10381. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10382. {
  10383. struct map_session_data *t_sd;
  10384. if(!sd->state.gmaster_flag)
  10385. return;
  10386. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10387. clif_displaymessage(fd, msg_txt(sd,228));
  10388. return;
  10389. }
  10390. t_sd = map_id2sd(RFIFOL(fd,2));
  10391. // @noask [LuzZza]
  10392. if(t_sd && t_sd->state.noask) {
  10393. clif_noask_sub(sd, t_sd, 4);
  10394. return;
  10395. }
  10396. guild_opposition(sd,t_sd);
  10397. }
  10398. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10399. /// 015d <key>.40B
  10400. /// key:
  10401. /// now guild name; might have been (intended) email, since the
  10402. /// field name and size is same as the one in CH_DELETE_CHAR.
  10403. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10404. {
  10405. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10406. clif_displaymessage(fd, msg_txt(sd,228));
  10407. return;
  10408. }
  10409. guild_break(sd,(char*)RFIFOP(fd,2));
  10410. }
  10411. /// Pet
  10412. ///
  10413. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10414. /// 01a1 <type>.B
  10415. /// type:
  10416. /// 0 = pet information
  10417. /// 1 = feed
  10418. /// 2 = performance
  10419. /// 3 = return to egg
  10420. /// 4 = unequip accessory
  10421. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10422. {
  10423. pet_menu(sd,RFIFOB(fd,2));
  10424. }
  10425. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10426. /// 019f <id>.L
  10427. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10428. {
  10429. pet_catch_process2(sd,RFIFOL(fd,2));
  10430. }
  10431. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10432. /// 01a7 <index>.W
  10433. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10434. {
  10435. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1) {
  10436. //Forged packet, disconnect them [Kevin]
  10437. clif_authfail_fd(fd, 0);
  10438. return;
  10439. }
  10440. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10441. clif_menuskill_clear(sd);
  10442. }
  10443. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10444. /// 01a9 <data>.L
  10445. /// data:
  10446. /// is either emotion (@see enum emotion_type) or a compound value
  10447. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10448. /// entry (given in parentheses) in data\pettalktable.xml
  10449. /// act id:
  10450. /// 0 = feeding
  10451. /// 1 = hunting
  10452. /// 2 = danger
  10453. /// 3 = dead
  10454. /// 4 = normal (stand)
  10455. /// 5 = special performance (perfor_s)
  10456. /// 6 = level up (levelup)
  10457. /// 7 = performance 1 (perfor_1)
  10458. /// 8 = performance 2 (perfor_2)
  10459. /// 9 = performance 3 (perfor_3)
  10460. /// 10 = log-in greeting (connect)
  10461. /// hungry value:
  10462. /// 0 = very hungry (hungry)
  10463. /// 1 = hungry (bit_hungry)
  10464. /// 2 = satisfied (noting)
  10465. /// 3 = stuffed (full)
  10466. /// 4 = full (so_full)
  10467. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10468. {
  10469. if(sd->pd)
  10470. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10471. }
  10472. /// Request to change pet's name (CZ_RENAME_PET).
  10473. /// 01a5 <name>.24B
  10474. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10475. {
  10476. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10477. }
  10478. /// /kill (CZ_DISCONNECT_CHARACTER).
  10479. /// Request to disconnect a character.
  10480. /// 00cc <account id>.L
  10481. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10482. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10483. {
  10484. struct block_list *target;
  10485. int tid;
  10486. tid = RFIFOL(fd,2);
  10487. target = map_id2bl(tid);
  10488. if (!target) {
  10489. clif_GM_kickack(sd, 0);
  10490. return;
  10491. }
  10492. switch (target->type) {
  10493. case BL_PC:
  10494. {
  10495. char command[NAME_LENGTH+6];
  10496. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10497. is_atcommand(fd, sd, command, 1);
  10498. }
  10499. break;
  10500. /**
  10501. * This one does not invoke any atcommand, so we need to check for permissions.
  10502. */
  10503. case BL_MOB:
  10504. {
  10505. char command[100];
  10506. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10507. clif_GM_kickack(sd, 0);
  10508. return;
  10509. }
  10510. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10511. log_atcommand(sd, command);
  10512. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10513. }
  10514. break;
  10515. case BL_NPC:
  10516. {
  10517. char command[NAME_LENGTH+11];
  10518. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10519. is_atcommand(fd, sd, command, 1);
  10520. }
  10521. break;
  10522. default:
  10523. clif_GM_kickack(sd, 0);
  10524. }
  10525. }
  10526. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10527. /// Request to disconnect all characters.
  10528. /// 00ce
  10529. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10530. char cmd[15];
  10531. sprintf(cmd,"%ckickall",atcommand_symbol);
  10532. is_atcommand(fd, sd, cmd, 1);
  10533. }
  10534. /// /remove (CZ_REMOVE_AID).
  10535. /// Request to warp to a character with given login ID.
  10536. /// 01ba <account name>.24B
  10537. /// /shift (CZ_SHIFT).
  10538. /// Request to warp to a character with given name.
  10539. /// 01bb <char name>.24B
  10540. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10541. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10542. char *player_name;
  10543. char command[NAME_LENGTH+8];
  10544. player_name = (char*)RFIFOP(fd,2);
  10545. player_name[NAME_LENGTH-1] = '\0';
  10546. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10547. is_atcommand(fd, sd, command, 1);
  10548. }
  10549. /// /remove (CZ_REMOVE_AID_SSO).
  10550. /// Request to warp to a character with given account ID.
  10551. /// 0843 <account id>.L
  10552. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10553. {
  10554. int account_id;
  10555. struct map_session_data* pl_sd;
  10556. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10557. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  10558. char command[NAME_LENGTH+8];
  10559. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10560. is_atcommand(fd, sd, command, 1);
  10561. }
  10562. }
  10563. /// /recall (CZ_RECALL).
  10564. /// Request to summon a player with given login ID to own position.
  10565. /// 01bc <account name>.24B
  10566. /// /summon (CZ_RECALL_GID).
  10567. /// Request to summon a player with given name to own position.
  10568. /// 01bd <char name>.24B
  10569. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10570. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10571. char *player_name;
  10572. char command [NAME_LENGTH+8];
  10573. player_name = (char*)RFIFOP(fd,2);
  10574. player_name[NAME_LENGTH-1] = '\0';
  10575. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10576. is_atcommand(fd, sd, command, 1);
  10577. }
  10578. /// /recall (CZ_RECALL_SSO).
  10579. /// Request to summon a player with given account ID to own position.
  10580. /// 0842 <account id>.L
  10581. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10582. {
  10583. int account_id;
  10584. struct map_session_data* pl_sd;
  10585. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10586. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  10587. char command[NAME_LENGTH+8];
  10588. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10589. is_atcommand(fd, sd, command, 1);
  10590. }
  10591. }
  10592. /// /item /monster (CZ_ITEM_CREATE).
  10593. /// Request to make items or spawn monsters.
  10594. /// 013f <item/mob name>.24B
  10595. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10596. {
  10597. char *monster_item_name;
  10598. char command[NAME_LENGTH+10];
  10599. monster_item_name = (char*)RFIFOP(fd,2);
  10600. monster_item_name[NAME_LENGTH-1] = '\0';
  10601. // FIXME: Should look for item first, then for monster.
  10602. // FIXME: /monster takes mob_db Sprite_Name as argument
  10603. if( mobdb_searchname(monster_item_name) ) {
  10604. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10605. is_atcommand(fd, sd, command, 1);
  10606. return;
  10607. }
  10608. // FIXME: Stackables have a quantity of 20.
  10609. // FIXME: Equips are supposed to be unidentified.
  10610. if( itemdb_searchname(monster_item_name) ) {
  10611. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10612. is_atcommand(fd, sd, command, 1);
  10613. return;
  10614. }
  10615. }
  10616. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10617. /// 019d <effect state>.L
  10618. /// effect state:
  10619. /// TODO: Any OPTION_* ?
  10620. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10621. char cmd[6];
  10622. sprintf(cmd,"%chide",atcommand_symbol);
  10623. is_atcommand(fd, sd, cmd, 1);
  10624. }
  10625. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10626. /// 0149 <account id>.L <type>.B <value>.W
  10627. /// type:
  10628. /// 0 = positive points
  10629. /// 1 = negative points
  10630. /// 2 = self mute (+10 minutes)
  10631. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10632. {
  10633. int id, type, value;
  10634. struct map_session_data *dstsd;
  10635. char command[NAME_LENGTH+15];
  10636. id = RFIFOL(fd,2);
  10637. type = RFIFOB(fd,6);
  10638. value = RFIFOW(fd,7);
  10639. if( type == 0 )
  10640. value = -value;
  10641. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10642. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10643. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10644. return;
  10645. dstsd = map_id2sd(id);
  10646. if( dstsd == NULL )
  10647. return;
  10648. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10649. is_atcommand(fd, sd, command, 1);
  10650. }
  10651. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10652. /// GM adjustment of a player's manner value by -60.
  10653. /// 0212 <char name>.24B
  10654. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10655. {
  10656. char command[NAME_LENGTH+15];
  10657. char *name = (char*)RFIFOP(fd,2);
  10658. name[NAME_LENGTH-1] = '\0';
  10659. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10660. is_atcommand(fd, sd, command, 1);
  10661. }
  10662. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10663. /// 01e0 <account id>.L <account name>.24B
  10664. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  10665. {
  10666. int fd = sd->fd;
  10667. WFIFOHEAD(fd,packet_len(0x1e0));
  10668. WFIFOW(fd,0) = 0x1e0;
  10669. WFIFOL(fd,2) = account_id;
  10670. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  10671. WFIFOSET(fd,packet_len(0x1e0));
  10672. }
  10673. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10674. /// 01df <account id>.L
  10675. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10676. {
  10677. int account_id = RFIFOL(fd,2);
  10678. //TODO: find out if this works for any player or only for authorized GMs
  10679. clif_account_name(sd, account_id, ""); // insert account name here >_<
  10680. }
  10681. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10682. /// GM single cell type change request.
  10683. /// 0198 <x>.W <y>.W <type>.W
  10684. /// type:
  10685. /// 0 = not walkable
  10686. /// 1 = walkable
  10687. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10688. {
  10689. int x,y,type;
  10690. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10691. return;
  10692. x = RFIFOW(fd,2);
  10693. y = RFIFOW(fd,4);
  10694. type = RFIFOW(fd,6);
  10695. map_setgatcell(sd->bl.m,x,y,type);
  10696. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10697. //FIXME: once players leave the map, the client 'forgets' this information.
  10698. }
  10699. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10700. /// Request to allow/deny whispers from a nick.
  10701. /// 00cf <nick>.24B <type>.B
  10702. /// type:
  10703. /// 0 = (/ex nick) deny speech from nick
  10704. /// 1 = (/in nick) allow speech from nick
  10705. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10706. {
  10707. char* nick;
  10708. uint8 type;
  10709. int i;
  10710. nick = (char*)RFIFOP(fd,2); // speed up
  10711. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10712. type = RFIFOB(fd,26);
  10713. if( type == 0 ) { // Add name to ignore list (block)
  10714. if (strcmp(wisp_server_name, nick) == 0) {
  10715. clif_wisexin(sd, type, 1); // fail
  10716. return;
  10717. }
  10718. // try to find a free spot, while checking for duplicates at the same time
  10719. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10720. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  10721. clif_wisexin(sd, type, 2); // too many blocks
  10722. return;
  10723. }
  10724. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  10725. clif_wisexin(sd, type, 0); // Aegis reports success.
  10726. return;
  10727. }
  10728. //Insert in position i
  10729. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10730. } else { // Remove name from ignore list (unblock)
  10731. // find entry
  10732. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10733. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  10734. clif_wisexin(sd, type, 1); // fail
  10735. return;
  10736. }
  10737. // move everything one place down to overwrite removed entry
  10738. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10739. // wipe last entry
  10740. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10741. }
  10742. clif_wisexin(sd, type, 0); // success
  10743. }
  10744. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10745. /// Request to allow/deny all whispers.
  10746. /// 00d0 <type>.B
  10747. /// type:
  10748. /// 0 = (/exall) deny all speech
  10749. /// 1 = (/inall) allow all speech
  10750. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10751. {
  10752. int type = RFIFOB(fd,2), flag;
  10753. if( type == 0 ) {// Deny all
  10754. if( sd->state.ignoreAll ) {
  10755. flag = 1; // fail
  10756. } else {
  10757. sd->state.ignoreAll = 1;
  10758. flag = 0; // success
  10759. }
  10760. } else {//Unblock everyone
  10761. if( sd->state.ignoreAll ) {
  10762. sd->state.ignoreAll = 0;
  10763. flag = 0; // success
  10764. } else {
  10765. if (sd->ignore[0].name[0] != '\0')
  10766. { //Wipe the ignore list.
  10767. memset(sd->ignore, 0, sizeof(sd->ignore));
  10768. flag = 0; // success
  10769. } else {
  10770. flag = 1; // fail
  10771. }
  10772. }
  10773. }
  10774. clif_wisall(sd, type, flag);
  10775. }
  10776. /// Whisper ignore list (ZC_WHISPER_LIST).
  10777. /// 00d4 <packet len>.W { <char name>.24B }*
  10778. void clif_PMIgnoreList(struct map_session_data* sd)
  10779. {
  10780. int i, fd = sd->fd;
  10781. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  10782. WFIFOW(fd,0) = 0xd4;
  10783. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  10784. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  10785. }
  10786. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  10787. WFIFOSET(fd,WFIFOW(fd,2));
  10788. }
  10789. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10790. /// 00d3
  10791. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10792. {
  10793. clif_PMIgnoreList(sd);
  10794. }
  10795. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10796. /// 01e7
  10797. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10798. {
  10799. if (sd->state.doridori) return;
  10800. switch (sd->class_&MAPID_UPPERMASK) {
  10801. case MAPID_SOUL_LINKER:
  10802. case MAPID_STAR_GLADIATOR:
  10803. case MAPID_TAEKWON:
  10804. if (!sd->state.rest)
  10805. break;
  10806. case MAPID_SUPER_NOVICE:
  10807. sd->state.doridori=1;
  10808. break;
  10809. }
  10810. }
  10811. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10812. /// 01ed
  10813. /// Note: This packet is caused by 7 lines of any text, followed by
  10814. /// the prayer and an another line of any text. The prayer is
  10815. /// defined by lines 790~793 in data\msgstringtable.txt
  10816. /// "Dear angel, can you hear my voice?"
  10817. /// "I am" (space separated player name) "Super Novice~"
  10818. /// "Help me out~ Please~ T_T"
  10819. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10820. {
  10821. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  10822. unsigned int next = pc_nextbaseexp(sd);
  10823. if( next == 0 ) next = pc_thisbaseexp(sd);
  10824. if( next ) {
  10825. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10826. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  10827. 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]
  10828. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10829. }
  10830. }
  10831. }
  10832. }
  10833. /// Friends List
  10834. ///
  10835. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10836. /// 0206 <account id>.L <char id>.L <state>.B
  10837. /// state:
  10838. /// 0 = online
  10839. /// 1 = offline
  10840. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10841. {
  10842. int i, fd = sd->fd;
  10843. //Seek friend.
  10844. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10845. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10846. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10847. return; //Not found
  10848. WFIFOHEAD(fd,packet_len(0x206));
  10849. WFIFOW(fd, 0) = 0x206;
  10850. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10851. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10852. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10853. WFIFOSET(fd, packet_len(0x206));
  10854. }
  10855. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10856. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10857. {
  10858. int account_id, char_id, online;
  10859. account_id = va_arg(ap, int);
  10860. char_id = va_arg(ap, int);
  10861. online = va_arg(ap, int);
  10862. clif_friendslist_toggle(sd, account_id, char_id, online);
  10863. return 0;
  10864. }
  10865. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10866. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10867. void clif_friendslist_send(struct map_session_data *sd)
  10868. {
  10869. int i = 0, n, fd = sd->fd;
  10870. // Send friends list
  10871. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10872. WFIFOW(fd, 0) = 0x201;
  10873. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  10874. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10875. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10876. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10877. }
  10878. if (i) {
  10879. WFIFOW(fd,2) = 4 + 32 * i;
  10880. WFIFOSET(fd, WFIFOW(fd,2));
  10881. }
  10882. for (n = 0; n < i; n++) { //Sending the online players
  10883. if (map_charid2sd(sd->status.friends[n].char_id))
  10884. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10885. }
  10886. }
  10887. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10888. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10889. /// result:
  10890. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10891. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10892. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10893. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10894. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10895. {
  10896. int fd;
  10897. nullpo_retv(sd);
  10898. fd = sd->fd;
  10899. WFIFOHEAD(fd,packet_len(0x209));
  10900. WFIFOW(fd,0) = 0x209;
  10901. WFIFOW(fd,2) = type;
  10902. if (f_sd) {
  10903. WFIFOL(fd,4) = f_sd->status.account_id;
  10904. WFIFOL(fd,8) = f_sd->status.char_id;
  10905. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10906. }
  10907. WFIFOSET(fd, packet_len(0x209));
  10908. }
  10909. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  10910. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  10911. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  10912. {
  10913. int fd = sd->fd;
  10914. WFIFOHEAD(fd,packet_len(0x207));
  10915. WFIFOW(fd,0) = 0x207;
  10916. WFIFOL(fd,2) = account_id;
  10917. WFIFOL(fd,6) = char_id;
  10918. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  10919. WFIFOSET(fd,packet_len(0x207));
  10920. }
  10921. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10922. /// 0202 <name>.24B
  10923. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10924. {
  10925. struct map_session_data *f_sd;
  10926. int i;
  10927. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10928. // ensure that the request player's friend list is not full
  10929. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10930. if( i == MAX_FRIENDS ) {
  10931. clif_friendslist_reqack(sd, f_sd, 2);
  10932. return;
  10933. }
  10934. // Friend doesn't exist (no player with this name)
  10935. if (f_sd == NULL) {
  10936. clif_displaymessage(fd, msg_txt(sd,3));
  10937. return;
  10938. }
  10939. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  10940. return;
  10941. }
  10942. // @noask [LuzZza]
  10943. if(f_sd->state.noask) {
  10944. clif_noask_sub(sd, f_sd, 5);
  10945. return;
  10946. }
  10947. // Friend already exists
  10948. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10949. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10950. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  10951. return;
  10952. }
  10953. }
  10954. f_sd->friend_req = sd->status.char_id;
  10955. sd->friend_req = f_sd->status.char_id;
  10956. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  10957. }
  10958. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10959. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10960. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10961. /// result:
  10962. /// 0 = rejected
  10963. /// 1 = accepted
  10964. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10965. {
  10966. struct map_session_data *f_sd;
  10967. int account_id;
  10968. char reply;
  10969. account_id = RFIFOL(fd,2);
  10970. //char_id = RFIFOL(fd,6);
  10971. #if PACKETVER < 6
  10972. reply = RFIFOB(fd,10);
  10973. #else
  10974. reply = RFIFOL(fd,10);
  10975. #endif
  10976. if( sd->bl.id == account_id ) {// adding oneself as friend
  10977. return;
  10978. }
  10979. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10980. if (f_sd == NULL)
  10981. return;
  10982. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10983. clif_friendslist_reqack(f_sd, sd, 1);
  10984. else {
  10985. int i;
  10986. // Find an empty slot
  10987. for (i = 0; i < MAX_FRIENDS; i++)
  10988. if (f_sd->status.friends[i].char_id == 0)
  10989. break;
  10990. if (i == MAX_FRIENDS) {
  10991. clif_friendslist_reqack(f_sd, sd, 2);
  10992. return;
  10993. }
  10994. f_sd->status.friends[i].account_id = sd->status.account_id;
  10995. f_sd->status.friends[i].char_id = sd->status.char_id;
  10996. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10997. clif_friendslist_reqack(f_sd, sd, 0);
  10998. if (battle_config.friend_auto_add) {
  10999. // Also add f_sd to sd's friendlist.
  11000. for (i = 0; i < MAX_FRIENDS; i++) {
  11001. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11002. return; //No need to add anything.
  11003. if (sd->status.friends[i].char_id == 0)
  11004. break;
  11005. }
  11006. if (i == MAX_FRIENDS) {
  11007. clif_friendslist_reqack(sd, f_sd, 2);
  11008. return;
  11009. }
  11010. sd->status.friends[i].account_id = f_sd->status.account_id;
  11011. sd->status.friends[i].char_id = f_sd->status.char_id;
  11012. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11013. clif_friendslist_reqack(sd, f_sd, 0);
  11014. }
  11015. }
  11016. }
  11017. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11018. /// 0203 <account id>.L <char id>.L
  11019. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11020. {
  11021. struct map_session_data *f_sd = NULL;
  11022. int account_id, char_id;
  11023. int i, j;
  11024. account_id = RFIFOL(fd,2);
  11025. char_id = RFIFOL(fd,6);
  11026. // Search friend
  11027. for (i = 0; i < MAX_FRIENDS &&
  11028. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11029. if (i == MAX_FRIENDS) {
  11030. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11031. return;
  11032. }
  11033. //remove from friend's list first
  11034. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11035. for (i = 0; i < MAX_FRIENDS &&
  11036. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11037. if (i != MAX_FRIENDS) {
  11038. // move all chars up
  11039. for(j = i + 1; j < MAX_FRIENDS; j++)
  11040. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11041. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11042. //should the guy be notified of some message? we should add it here if so
  11043. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11044. WFIFOW(f_sd->fd,0) = 0x20a;
  11045. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11046. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11047. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11048. }
  11049. } else { //friend not online -- ask char server to delete from his friendlist
  11050. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11051. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11052. return;
  11053. }
  11054. }
  11055. // We can now delete from original requester
  11056. for (i = 0; i < MAX_FRIENDS &&
  11057. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11058. // move all chars up
  11059. for(j = i + 1; j < MAX_FRIENDS; j++)
  11060. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11061. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11062. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11063. WFIFOHEAD(fd,packet_len(0x20a));
  11064. WFIFOW(fd,0) = 0x20a;
  11065. WFIFOL(fd,2) = account_id;
  11066. WFIFOL(fd,6) = char_id;
  11067. WFIFOSET(fd, packet_len(0x20a));
  11068. }
  11069. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11070. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11071. void clif_PVPInfo(struct map_session_data* sd)
  11072. {
  11073. int fd = sd->fd;
  11074. WFIFOHEAD(fd,packet_len(0x210));
  11075. WFIFOW(fd,0) = 0x210;
  11076. WFIFOL(fd,2) = sd->status.char_id;
  11077. WFIFOL(fd,6) = sd->status.account_id;
  11078. WFIFOL(fd,10) = sd->pvp_won; // times won
  11079. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11080. WFIFOL(fd,18) = sd->pvp_point;
  11081. WFIFOSET(fd, packet_len(0x210));
  11082. }
  11083. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11084. /// 020f <char id>.L <account id>.L
  11085. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11086. {
  11087. // TODO: Is there a way to use this on an another player (char/acc id)?
  11088. clif_PVPInfo(sd);
  11089. }
  11090. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11091. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11092. void clif_blacksmith(struct map_session_data* sd)
  11093. {
  11094. int i, fd = sd->fd;
  11095. const char* name;
  11096. WFIFOHEAD(fd,packet_len(0x219));
  11097. WFIFOW(fd,0) = 0x219;
  11098. //Packet size limits this list to 10 elements. [Skotlex]
  11099. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11100. if (smith_fame_list[i].id > 0) {
  11101. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11102. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11103. {
  11104. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11105. } else
  11106. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11107. } else
  11108. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11109. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11110. }
  11111. for(;i < 10; i++) { //In case the MAX is less than 10.
  11112. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11113. WFIFOL(fd, 242 + i * 4) = 0;
  11114. }
  11115. WFIFOSET(fd, packet_len(0x219));
  11116. }
  11117. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11118. /// 0217
  11119. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11120. {
  11121. clif_blacksmith(sd);
  11122. }
  11123. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11124. /// 021b <points>.L <total points>.L
  11125. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11126. {
  11127. int fd = sd->fd;
  11128. WFIFOHEAD(fd,packet_len(0x21b));
  11129. WFIFOW(fd,0) = 0x21b;
  11130. WFIFOL(fd,2) = points;
  11131. WFIFOL(fd,6) = sd->status.fame;
  11132. WFIFOSET(fd, packet_len(0x21b));
  11133. }
  11134. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11135. /// 021a { <name>.24B }*10 { <point>.L }*10
  11136. void clif_alchemist(struct map_session_data* sd)
  11137. {
  11138. int i, fd = sd->fd;
  11139. const char* name;
  11140. WFIFOHEAD(fd,packet_len(0x21a));
  11141. WFIFOW(fd,0) = 0x21a;
  11142. //Packet size limits this list to 10 elements. [Skotlex]
  11143. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11144. if (chemist_fame_list[i].id > 0) {
  11145. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11146. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11147. {
  11148. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11149. } else
  11150. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11151. } else
  11152. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11153. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11154. }
  11155. for(;i < 10; i++) { //In case the MAX is less than 10.
  11156. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11157. WFIFOL(fd, 242 + i * 4) = 0;
  11158. }
  11159. WFIFOSET(fd, packet_len(0x21a));
  11160. }
  11161. /// /alchemist (CZ_ALCHEMIST_RANK).
  11162. /// 0218
  11163. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11164. {
  11165. clif_alchemist(sd);
  11166. }
  11167. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11168. /// 021c <points>.L <total points>.L
  11169. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11170. {
  11171. int fd = sd->fd;
  11172. WFIFOHEAD(fd,packet_len(0x21c));
  11173. WFIFOW(fd,0) = 0x21c;
  11174. WFIFOL(fd,2) = points;
  11175. WFIFOL(fd,6) = sd->status.fame;
  11176. WFIFOSET(fd, packet_len(0x21c));
  11177. }
  11178. /// /taekwon list (ZC_TAEKWON_RANK).
  11179. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11180. void clif_taekwon(struct map_session_data* sd)
  11181. {
  11182. int i, fd = sd->fd;
  11183. const char* name;
  11184. WFIFOHEAD(fd,packet_len(0x226));
  11185. WFIFOW(fd,0) = 0x226;
  11186. //Packet size limits this list to 10 elements. [Skotlex]
  11187. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11188. if (taekwon_fame_list[i].id > 0) {
  11189. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11190. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11191. {
  11192. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11193. } else
  11194. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11195. } else
  11196. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11197. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11198. }
  11199. for(;i < 10; i++) { //In case the MAX is less than 10.
  11200. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11201. WFIFOL(fd, 242 + i * 4) = 0;
  11202. }
  11203. WFIFOSET(fd, packet_len(0x226));
  11204. }
  11205. /// /taekwon (CZ_TAEKWON_RANK).
  11206. /// 0225
  11207. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11208. {
  11209. clif_taekwon(sd);
  11210. }
  11211. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11212. /// 0224 <points>.L <total points>.L
  11213. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11214. {
  11215. int fd = sd->fd;
  11216. WFIFOHEAD(fd,packet_len(0x224));
  11217. WFIFOW(fd,0) = 0x224;
  11218. WFIFOL(fd,2) = points;
  11219. WFIFOL(fd,6) = sd->status.fame;
  11220. WFIFOSET(fd, packet_len(0x224));
  11221. }
  11222. /// /pk list (ZC_KILLER_RANK).
  11223. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11224. void clif_ranking_pk(struct map_session_data* sd)
  11225. {
  11226. int i, fd = sd->fd;
  11227. WFIFOHEAD(fd,packet_len(0x238));
  11228. WFIFOW(fd,0) = 0x238;
  11229. for(i=0;i<10;i++){
  11230. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11231. WFIFOL(fd,i*4+242) = 0;
  11232. }
  11233. WFIFOSET(fd, packet_len(0x238));
  11234. }
  11235. /// /pk (CZ_KILLER_RANK).
  11236. /// 0237
  11237. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11238. {
  11239. clif_ranking_pk(sd);
  11240. }
  11241. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11242. /// 0254 <which>.B
  11243. /// which:
  11244. /// 0 = sun
  11245. /// 1 = moon
  11246. /// 2 = star
  11247. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11248. {
  11249. int i;
  11250. if (sd->menuskill_id != SG_FEEL)
  11251. return;
  11252. i = sd->menuskill_val-1;
  11253. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11254. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11255. sd->feel_map[i].m = sd->bl.m;
  11256. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11257. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11258. // clif_misceffect2(&sd->bl, 0x1b0);
  11259. // clif_misceffect2(&sd->bl, 0x21f);
  11260. clif_feel_info(sd, i, 0);
  11261. clif_menuskill_clear(sd);
  11262. }
  11263. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11264. /// 0253 <which>.B
  11265. /// which:
  11266. /// 0 = sun
  11267. /// 1 = moon
  11268. /// 2 = star
  11269. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11270. {
  11271. WFIFOHEAD(fd,packet_len(0x253));
  11272. WFIFOW(fd,0)=0x253;
  11273. WFIFOB(fd,2)=TOB(skill_lv-1);
  11274. WFIFOSET(fd, packet_len(0x253));
  11275. sd->menuskill_id = SG_FEEL;
  11276. sd->menuskill_val = skill_lv;
  11277. }
  11278. /// Request to change homunculus' name (CZ_RENAME_MER).
  11279. /// 0231 <name>.24B
  11280. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11281. {
  11282. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11283. }
  11284. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11285. /// 0234 <id>.L
  11286. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11287. {
  11288. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11289. struct block_list *bl = NULL;
  11290. struct unit_data *ud = NULL;
  11291. if( sd->md && sd->md->bl.id == id )
  11292. bl = &sd->md->bl;
  11293. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11294. bl = &sd->hd->bl; // Moving Homunculus
  11295. else
  11296. return;
  11297. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11298. ud = unit_bl2ud(bl);
  11299. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11300. }
  11301. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11302. /// 0232 <id>.L <position data>.3B
  11303. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11304. {
  11305. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11306. struct block_list *bl = NULL;
  11307. short x, y;
  11308. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11309. if( sd->md && sd->md->bl.id == id )
  11310. bl = &sd->md->bl; // Moving Mercenary
  11311. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11312. bl = &sd->hd->bl; // Moving Homunculus
  11313. else
  11314. return;
  11315. unit_walktoxy(bl, x, y, 4);
  11316. }
  11317. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11318. /// 0233 <id>.L <target id>.L <action>.B
  11319. /// action:
  11320. /// always 0
  11321. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11322. {
  11323. struct block_list *bl = NULL;
  11324. int id = RFIFOL(fd,2),
  11325. target_id = RFIFOL(fd,6),
  11326. action_type = RFIFOB(fd,10);
  11327. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11328. bl = &sd->hd->bl;
  11329. else if( sd->md && sd->md->bl.id == id )
  11330. bl = &sd->md->bl;
  11331. else return;
  11332. unit_stop_attack(bl);
  11333. unit_attack(bl, target_id, action_type != 0);
  11334. }
  11335. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11336. /// 022d <type>.W <command>.B
  11337. /// type:
  11338. /// always 0
  11339. /// command:
  11340. /// 0 = homunculus information
  11341. /// 1 = feed
  11342. /// 2 = delete
  11343. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11344. { //[orn]
  11345. int cmd;
  11346. cmd = RFIFOW(fd,0);
  11347. if(!merc_is_hom_active(sd->hd))
  11348. return;
  11349. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11350. }
  11351. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11352. /// 0292
  11353. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11354. {
  11355. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11356. if (item_position < 0)
  11357. return;
  11358. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11359. return;
  11360. if (!status_revive(&sd->bl, 100, 100))
  11361. return;
  11362. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11363. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11364. }
  11365. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11366. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11367. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11368. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11369. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11370. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11371. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11372. void clif_check(int fd, struct map_session_data* pl_sd)
  11373. {
  11374. WFIFOHEAD(fd,packet_len(0x214));
  11375. WFIFOW(fd, 0) = 0x214;
  11376. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11377. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11378. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11379. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11380. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11381. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11382. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11383. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11384. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11385. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11386. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11387. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11388. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11389. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11390. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11391. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11392. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11393. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11394. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11395. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11396. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11397. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11398. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11399. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11400. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11401. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11402. WFIFOSET(fd,packet_len(0x214));
  11403. }
  11404. /// /check (CZ_REQ_STATUS_GM).
  11405. /// Request character's status values.
  11406. /// 0213 <char name>.24B
  11407. void clif_parse_Check(int fd, struct map_session_data *sd)
  11408. {
  11409. char charname[NAME_LENGTH];
  11410. struct map_session_data* pl_sd;
  11411. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11412. return;
  11413. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11414. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11415. {
  11416. return;
  11417. }
  11418. clif_check(fd, pl_sd);
  11419. }
  11420. /// MAIL SYSTEM
  11421. /// By Zephyrus
  11422. ///
  11423. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11424. /// 0255 <index>.W <result>.B
  11425. /// result:
  11426. /// 0 = success
  11427. /// 1 = failure
  11428. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11429. {
  11430. WFIFOHEAD(fd,packet_len(0x255));
  11431. WFIFOW(fd,0) = 0x255;
  11432. WFIFOW(fd,2) = index;
  11433. WFIFOB(fd,4) = flag;
  11434. WFIFOSET(fd,packet_len(0x255));
  11435. }
  11436. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11437. /// 0245 <result>.B
  11438. /// result:
  11439. /// 0 = success
  11440. /// 1 = failure
  11441. /// 2 = too many items
  11442. void clif_Mail_getattachment(int fd, uint8 flag)
  11443. {
  11444. WFIFOHEAD(fd,packet_len(0x245));
  11445. WFIFOW(fd,0) = 0x245;
  11446. WFIFOB(fd,2) = flag;
  11447. WFIFOSET(fd,packet_len(0x245));
  11448. }
  11449. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11450. /// 0249 <result>.B
  11451. /// result:
  11452. /// 0 = success
  11453. /// 1 = recipinent does not exist
  11454. void clif_Mail_send(int fd, bool fail)
  11455. {
  11456. WFIFOHEAD(fd,packet_len(0x249));
  11457. WFIFOW(fd,0) = 0x249;
  11458. WFIFOB(fd,2) = fail;
  11459. WFIFOSET(fd,packet_len(0x249));
  11460. }
  11461. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11462. /// 0257 <mail id>.L <result>.W
  11463. /// result:
  11464. /// 0 = success
  11465. /// 1 = failure
  11466. void clif_Mail_delete(int fd, int mail_id, short fail)
  11467. {
  11468. WFIFOHEAD(fd, packet_len(0x257));
  11469. WFIFOW(fd,0) = 0x257;
  11470. WFIFOL(fd,2) = mail_id;
  11471. WFIFOW(fd,6) = fail;
  11472. WFIFOSET(fd, packet_len(0x257));
  11473. }
  11474. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11475. /// 0274 <mail id>.L <result>.W
  11476. /// result:
  11477. /// 0 = success
  11478. /// 1 = failure
  11479. void clif_Mail_return(int fd, int mail_id, short fail)
  11480. {
  11481. WFIFOHEAD(fd,packet_len(0x274));
  11482. WFIFOW(fd,0) = 0x274;
  11483. WFIFOL(fd,2) = mail_id;
  11484. WFIFOW(fd,6) = fail;
  11485. WFIFOSET(fd,packet_len(0x274));
  11486. }
  11487. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11488. /// 024a <mail id>.L <title>.40B <sender>.24B
  11489. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11490. {
  11491. WFIFOHEAD(fd,packet_len(0x24a));
  11492. WFIFOW(fd,0) = 0x24a;
  11493. WFIFOL(fd,2) = mail_id;
  11494. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11495. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11496. WFIFOSET(fd,packet_len(0x24a));
  11497. }
  11498. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11499. /// 0260 <type>.L
  11500. /// type:
  11501. /// 0 = open
  11502. /// 1 = close
  11503. void clif_Mail_window(int fd, int flag)
  11504. {
  11505. WFIFOHEAD(fd,packet_len(0x260));
  11506. WFIFOW(fd,0) = 0x260;
  11507. WFIFOL(fd,2) = flag;
  11508. WFIFOSET(fd,packet_len(0x260));
  11509. }
  11510. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11511. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11512. /// read:
  11513. /// 0 = unread
  11514. /// 1 = read
  11515. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11516. {
  11517. int fd = sd->fd;
  11518. struct mail_data *md = &sd->mail.inbox;
  11519. struct mail_message *msg;
  11520. int len, i, j;
  11521. len = 8 + (73 * md->amount);
  11522. WFIFOHEAD(fd,len);
  11523. WFIFOW(fd,0) = 0x240;
  11524. WFIFOW(fd,2) = len;
  11525. WFIFOL(fd,4) = md->amount;
  11526. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11527. {
  11528. msg = &md->msg[i];
  11529. if (msg->id < 1)
  11530. continue;
  11531. WFIFOL(fd,8+73*j) = msg->id;
  11532. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11533. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11534. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11535. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11536. j++;
  11537. }
  11538. WFIFOSET(fd,len);
  11539. if( md->full ) {// TODO: is this official?
  11540. char output[100];
  11541. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11542. clif_disp_onlyself(sd, output, strlen(output));
  11543. }
  11544. }
  11545. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11546. /// 023f
  11547. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11548. {
  11549. struct mail_data* md = &sd->mail.inbox;
  11550. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11551. intif_Mail_requestinbox(sd->status.char_id, 1);
  11552. else
  11553. clif_Mail_refreshinbox(sd);
  11554. mail_removeitem(sd, 0);
  11555. mail_removezeny(sd, 0);
  11556. }
  11557. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11558. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11559. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11560. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11561. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11562. {
  11563. int i, fd = sd->fd;
  11564. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11565. if( i == MAIL_MAX_INBOX ) {
  11566. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11567. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11568. return;
  11569. } else {
  11570. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11571. struct item *item = &msg->item;
  11572. struct item_data *data;
  11573. int msg_len = strlen(msg->body), len;
  11574. if( msg_len == 0 ) {
  11575. strcpy(msg->body, "(no message)");
  11576. msg_len = strlen(msg->body);
  11577. }
  11578. len = 101 + msg_len;
  11579. WFIFOHEAD(fd,len);
  11580. WFIFOW(fd,0) = 0x242;
  11581. WFIFOW(fd,2) = len;
  11582. WFIFOL(fd,4) = msg->id;
  11583. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11584. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11585. WFIFOL(fd,72) = 0;
  11586. WFIFOL(fd,76) = msg->zeny;
  11587. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  11588. WFIFOL(fd,80) = item->amount;
  11589. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11590. WFIFOW(fd,86) = data->type;
  11591. WFIFOB(fd,88) = item->identify;
  11592. WFIFOB(fd,89) = item->attribute;
  11593. WFIFOB(fd,90) = item->refine;
  11594. WFIFOW(fd,91) = item->card[0];
  11595. WFIFOW(fd,93) = item->card[1];
  11596. WFIFOW(fd,95) = item->card[2];
  11597. WFIFOW(fd,97) = item->card[3];
  11598. } else // no item, set all to zero
  11599. memset(WFIFOP(fd,80), 0x00, 19);
  11600. WFIFOB(fd,99) = (unsigned char)msg_len;
  11601. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11602. WFIFOSET(fd,len);
  11603. if (msg->status == MAIL_UNREAD) {
  11604. msg->status = MAIL_READ;
  11605. intif_Mail_read(mail_id);
  11606. clif_parse_Mail_refreshinbox(fd, sd);
  11607. }
  11608. }
  11609. }
  11610. /// Request to open a mail (CZ_MAIL_OPEN).
  11611. /// 0241 <mail id>.L
  11612. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11613. {
  11614. int mail_id = RFIFOL(fd,2);
  11615. if( mail_id <= 0 )
  11616. return;
  11617. if( mail_invalid_operation(sd) )
  11618. return;
  11619. clif_Mail_read(sd, RFIFOL(fd,2));
  11620. }
  11621. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11622. /// 0244 <mail id>.L
  11623. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11624. {
  11625. int mail_id = RFIFOL(fd,2);
  11626. int i;
  11627. bool fail = false;
  11628. if( !chrif_isconnected() )
  11629. return;
  11630. if( mail_id <= 0 )
  11631. return;
  11632. if( mail_invalid_operation(sd) )
  11633. return;
  11634. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11635. if( i == MAIL_MAX_INBOX )
  11636. return;
  11637. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11638. return;
  11639. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  11640. clif_Mail_getattachment(fd, 1);
  11641. return;
  11642. }
  11643. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  11644. struct item_data *data;
  11645. unsigned int weight;
  11646. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11647. return;
  11648. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  11649. case CHKADDITEM_NEW:
  11650. fail = ( pc_inventoryblank(sd) == 0 );
  11651. break;
  11652. case CHKADDITEM_OVERAMOUNT:
  11653. fail = true;
  11654. }
  11655. if( fail ) {
  11656. clif_Mail_getattachment(fd, 1);
  11657. return;
  11658. }
  11659. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11660. if( sd->weight + weight > sd->max_weight ) {
  11661. clif_Mail_getattachment(fd, 2);
  11662. return;
  11663. }
  11664. }
  11665. sd->mail.inbox.msg[i].zeny = 0;
  11666. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11667. clif_Mail_read(sd, mail_id);
  11668. intif_Mail_getattach(sd->status.char_id, mail_id);
  11669. }
  11670. /// Request to delete a mail (CZ_MAIL_DELETE).
  11671. /// 0243 <mail id>.L
  11672. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11673. {
  11674. int mail_id = RFIFOL(fd,2);
  11675. int i;
  11676. if( !chrif_isconnected() )
  11677. return;
  11678. if( mail_id <= 0 )
  11679. return;
  11680. if( mail_invalid_operation(sd) )
  11681. return;
  11682. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11683. if (i < MAIL_MAX_INBOX) {
  11684. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11685. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  11686. clif_Mail_delete(sd->fd, mail_id, 1);
  11687. return;
  11688. }
  11689. intif_Mail_delete(sd->status.char_id, mail_id);
  11690. }
  11691. }
  11692. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11693. /// 0273 <mail id>.L <receive name>.24B
  11694. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11695. {
  11696. int mail_id = RFIFOL(fd,2);
  11697. int i;
  11698. if( mail_id <= 0 )
  11699. return;
  11700. if( mail_invalid_operation(sd) )
  11701. return;
  11702. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11703. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11704. intif_Mail_return(sd->status.char_id, mail_id);
  11705. else
  11706. clif_Mail_return(sd->fd, mail_id, 1);
  11707. }
  11708. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11709. /// 0247 <index>.W <amount>.L
  11710. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11711. {
  11712. int idx = RFIFOW(fd,2);
  11713. int amount = RFIFOL(fd,4);
  11714. unsigned char flag;
  11715. if( !chrif_isconnected() )
  11716. return;
  11717. if (idx < 0 || amount < 0)
  11718. return;
  11719. flag = mail_setitem(sd, idx, amount);
  11720. clif_Mail_setattachment(fd,idx,flag);
  11721. }
  11722. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11723. /// 0246 <type>.W
  11724. /// type:
  11725. /// 0 = reset all
  11726. /// 1 = remove item
  11727. /// 2 = remove zeny
  11728. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11729. {
  11730. int flag = RFIFOW(fd,2);
  11731. if (flag == 0 || flag == 1)
  11732. mail_removeitem(sd, 0);
  11733. if (flag == 0 || flag == 2)
  11734. mail_removezeny(sd, 0);
  11735. }
  11736. /// Request to send mail (CZ_MAIL_SEND).
  11737. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11738. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11739. {
  11740. struct mail_message msg;
  11741. int body_len;
  11742. if( !chrif_isconnected() )
  11743. return;
  11744. if( sd->state.trading )
  11745. return;
  11746. if( RFIFOW(fd,2) < 69 ) {
  11747. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11748. return;
  11749. }
  11750. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 ) {
  11751. clif_displaymessage(sd->fd,msg_txt(sd,675)); //"Cannot send mails too fast!!."
  11752. clif_Mail_send(fd, true); // fail
  11753. return;
  11754. }
  11755. body_len = RFIFOB(fd,68);
  11756. if (body_len > MAIL_BODY_LENGTH)
  11757. body_len = MAIL_BODY_LENGTH;
  11758. if( !mail_setattachment(sd, &msg) ) { // Invalid Append condition
  11759. clif_Mail_send(sd->fd, true); // fail
  11760. mail_removeitem(sd,0);
  11761. mail_removezeny(sd,0);
  11762. return;
  11763. }
  11764. msg.id = 0; // id will be assigned by charserver
  11765. msg.send_id = sd->status.char_id;
  11766. msg.dest_id = 0; // will attempt to resolve name
  11767. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11768. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11769. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11770. if (msg.title[0] == '\0') {
  11771. return; // Message has no length and somehow client verification was skipped.
  11772. }
  11773. if (body_len)
  11774. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11775. else
  11776. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11777. msg.timestamp = time(NULL);
  11778. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11779. mail_deliveryfail(sd, &msg);
  11780. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11781. }
  11782. /// AUCTION SYSTEM
  11783. /// By Zephyrus
  11784. ///
  11785. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11786. /// 025f <type>.L
  11787. /// type:
  11788. /// 0 = open
  11789. /// 1 = close
  11790. void clif_Auction_openwindow(struct map_session_data *sd)
  11791. {
  11792. int fd = sd->fd;
  11793. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11794. return;
  11795. WFIFOHEAD(fd,packet_len(0x25f));
  11796. WFIFOW(fd,0) = 0x25f;
  11797. WFIFOL(fd,2) = 0;
  11798. WFIFOSET(fd,packet_len(0x25f));
  11799. }
  11800. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11801. /// 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 }*
  11802. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11803. {
  11804. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11805. struct auction_data auction;
  11806. struct item_data *item;
  11807. int k;
  11808. WFIFOHEAD(fd,12 + (count * 83));
  11809. WFIFOW(fd,0) = 0x252;
  11810. WFIFOW(fd,2) = 12 + (count * 83);
  11811. WFIFOL(fd,4) = pages;
  11812. WFIFOL(fd,8) = count;
  11813. for( i = 0; i < count; i++ ) {
  11814. memcpy(&auction, RBUFP(buf,i * len), len);
  11815. k = 12 + (i * 83);
  11816. WFIFOL(fd,k) = auction.auction_id;
  11817. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11818. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11819. WFIFOW(fd,28+k) = item->view_id;
  11820. else
  11821. WFIFOW(fd,28+k) = auction.item.nameid;
  11822. WFIFOL(fd,30+k) = auction.type;
  11823. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11824. WFIFOB(fd,36+k) = auction.item.identify;
  11825. WFIFOB(fd,37+k) = auction.item.attribute;
  11826. WFIFOB(fd,38+k) = auction.item.refine;
  11827. WFIFOW(fd,39+k) = auction.item.card[0];
  11828. WFIFOW(fd,41+k) = auction.item.card[1];
  11829. WFIFOW(fd,43+k) = auction.item.card[2];
  11830. WFIFOW(fd,45+k) = auction.item.card[3];
  11831. WFIFOL(fd,47+k) = auction.price;
  11832. WFIFOL(fd,51+k) = auction.buynow;
  11833. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11834. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11835. }
  11836. WFIFOSET(fd,WFIFOW(fd,2));
  11837. }
  11838. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11839. /// 0256 <index>.W <result>.B
  11840. /// result:
  11841. /// 0 = success
  11842. /// 1 = failure
  11843. static void clif_Auction_setitem(int fd, int index, bool fail)
  11844. {
  11845. WFIFOHEAD(fd,packet_len(0x256));
  11846. WFIFOW(fd,0) = 0x256;
  11847. WFIFOW(fd,2) = index;
  11848. WFIFOB(fd,4) = fail;
  11849. WFIFOSET(fd,packet_len(0x256));
  11850. }
  11851. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11852. /// 024b <type>.W
  11853. /// type:
  11854. /// 0 = create (any other action in auction window)
  11855. /// 1 = cancel (cancel pressed on register tab)
  11856. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11857. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11858. {
  11859. if( sd->auction.amount > 0 )
  11860. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11861. sd->auction.amount = 0;
  11862. }
  11863. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11864. /// 024c <index>.W <count>.L
  11865. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11866. {
  11867. int idx = RFIFOW(fd,2) - 2;
  11868. int amount = RFIFOL(fd,4); // Always 1
  11869. struct item_data *item;
  11870. if( sd->auction.amount > 0 )
  11871. sd->auction.amount = 0;
  11872. if( idx < 0 || idx >= MAX_INVENTORY ) {
  11873. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11874. return;
  11875. }
  11876. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  11877. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11878. return;
  11879. }
  11880. 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) )
  11881. { // Consumable or pets are not allowed
  11882. clif_Auction_setitem(sd->fd, idx, true);
  11883. return;
  11884. }
  11885. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11886. !sd->status.inventory[idx].identify ||
  11887. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11888. clif_Auction_setitem(sd->fd, idx, true);
  11889. return;
  11890. }
  11891. sd->auction.index = idx;
  11892. sd->auction.amount = amount;
  11893. clif_Auction_setitem(fd, idx + 2, false);
  11894. }
  11895. /// Result from an auction action (ZC_AUCTION_RESULT).
  11896. /// 0250 <result>.B
  11897. /// result:
  11898. /// 0 = You have failed to bid into the auction
  11899. /// 1 = You have successfully bid in the auction
  11900. /// 2 = The auction has been canceled
  11901. /// 3 = An auction with at least one bidder cannot be canceled
  11902. /// 4 = You cannot register more than 5 items in an auction at a time
  11903. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11904. /// 6 = You have won the auction
  11905. /// 7 = You have failed to win the auction
  11906. /// 8 = You do not have enough Zeny
  11907. /// 9 = You cannot place more than 5 bids at a time
  11908. void clif_Auction_message(int fd, unsigned char flag)
  11909. {
  11910. WFIFOHEAD(fd,packet_len(0x250));
  11911. WFIFOW(fd,0) = 0x250;
  11912. WFIFOB(fd,2) = flag;
  11913. WFIFOSET(fd,packet_len(0x250));
  11914. }
  11915. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11916. /// 025e <result>.W
  11917. /// result:
  11918. /// 0 = You have ended the auction
  11919. /// 1 = You cannot end the auction
  11920. /// 2 = Auction ID is incorrect
  11921. void clif_Auction_close(int fd, unsigned char flag)
  11922. {
  11923. WFIFOHEAD(fd,packet_len(0x25e));
  11924. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11925. WFIFOW(fd,2) = flag;
  11926. WFIFOSET(fd,packet_len(0x25e));
  11927. }
  11928. /// Request to add an auction (CZ_AUCTION_ADD).
  11929. /// 024d <now money>.L <max money>.L <delete hour>.W
  11930. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11931. {
  11932. struct auction_data auction;
  11933. struct item_data *item;
  11934. auction.price = RFIFOL(fd,2);
  11935. auction.buynow = RFIFOL(fd,6);
  11936. auction.hours = RFIFOW(fd,10);
  11937. // Invalid Situations...
  11938. if( sd->auction.amount < 1 ) {
  11939. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11940. return;
  11941. }
  11942. if( auction.price >= auction.buynow ) {
  11943. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11944. return;
  11945. }
  11946. if( auction.hours < 1 || auction.hours > 48 ) {
  11947. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11948. return;
  11949. }
  11950. // Auction checks...
  11951. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  11952. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11953. return;
  11954. }
  11955. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  11956. auction.buynow = battle_config.auction_maximumprice;
  11957. if( auction.price >= auction.buynow )
  11958. auction.price = auction.buynow - 1;
  11959. }
  11960. auction.auction_id = 0;
  11961. auction.seller_id = sd->status.char_id;
  11962. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11963. auction.buyer_id = 0;
  11964. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11965. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11966. {
  11967. clif_Auction_message(fd, 2); // The auction has been canceled
  11968. return;
  11969. }
  11970. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11971. { // Just in case
  11972. clif_Auction_message(fd, 2); // The auction has been canceled
  11973. return;
  11974. }
  11975. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11976. auction.type = item->type;
  11977. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11978. auction.item.amount = 1;
  11979. auction.timestamp = 0;
  11980. if( !intif_Auction_register(&auction) )
  11981. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11982. else
  11983. {
  11984. int zeny = auction.hours*battle_config.auction_feeperhour;
  11985. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11986. sd->auction.amount = 0;
  11987. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  11988. }
  11989. }
  11990. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11991. /// 024e <auction id>.L
  11992. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11993. {
  11994. unsigned int auction_id = RFIFOL(fd,2);
  11995. intif_Auction_cancel(sd->status.char_id, auction_id);
  11996. }
  11997. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11998. /// 025d <auction id>.L
  11999. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  12000. {
  12001. unsigned int auction_id = RFIFOL(fd,2);
  12002. intif_Auction_close(sd->status.char_id, auction_id);
  12003. }
  12004. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12005. /// 024f <auction id>.L <money>.L
  12006. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  12007. {
  12008. unsigned int auction_id = RFIFOL(fd,2);
  12009. int bid = RFIFOL(fd,6);
  12010. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12011. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12012. return;
  12013. }
  12014. if( bid <= 0 )
  12015. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12016. else if( bid > sd->status.zeny )
  12017. clif_Auction_message(fd, 8); // You do not have enough zeny
  12018. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12019. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12020. else {
  12021. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12022. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12023. }
  12024. }
  12025. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12026. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12027. /// search type:
  12028. /// 0 = armor
  12029. /// 1 = weapon
  12030. /// 2 = card
  12031. /// 3 = misc
  12032. /// 4 = name search
  12033. /// 5 = auction id search
  12034. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  12035. {
  12036. char search_text[NAME_LENGTH];
  12037. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  12038. int price = RFIFOL(fd,4); // FIXME: bug #5071
  12039. clif_parse_Auction_cancelreg(fd, sd);
  12040. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  12041. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12042. }
  12043. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12044. /// 025c <type>.W
  12045. /// type:
  12046. /// 0 = sell (own auctions)
  12047. /// 1 = buy (own bids)
  12048. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12049. {
  12050. short type = RFIFOW(fd,2) + 6;
  12051. clif_parse_Auction_cancelreg(fd, sd);
  12052. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12053. }
  12054. /// CASH/POINT SHOP
  12055. ///
  12056. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12057. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12058. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12059. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12060. {
  12061. int fd,i;
  12062. #if PACKETVER < 20070711
  12063. const int offset = 8;
  12064. #else
  12065. const int offset = 12;
  12066. #endif
  12067. nullpo_retv(sd);
  12068. nullpo_retv(nd);
  12069. fd = sd->fd;
  12070. sd->npc_shopid = nd->bl.id;
  12071. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12072. WFIFOW(fd,0) = 0x287;
  12073. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12074. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12075. #if PACKETVER >= 20070711
  12076. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12077. #endif
  12078. for( i = 0; i < nd->u.shop.count; i++ ) {
  12079. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12080. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12081. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12082. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  12083. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12084. }
  12085. WFIFOSET(fd,WFIFOW(fd,2));
  12086. }
  12087. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12088. /// 0289 <cash point>.L <error>.W
  12089. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12090. /// error:
  12091. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12092. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12093. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12094. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12095. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12096. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12097. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12098. /// 7 = You can purchase up to 10 items.
  12099. /// 8 = Some items could not be purchased.
  12100. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12101. {
  12102. int fd = sd->fd;
  12103. WFIFOHEAD(fd, packet_len(0x289));
  12104. WFIFOW(fd,0) = 0x289;
  12105. WFIFOL(fd,2) = sd->cashPoints;
  12106. #if PACKETVER < 20070711
  12107. WFIFOW(fd,6) = TOW(error);
  12108. #else
  12109. WFIFOL(fd,6) = sd->kafraPoints;
  12110. WFIFOW(fd,10) = TOW(error);
  12111. #endif
  12112. WFIFOSET(fd, packet_len(0x289));
  12113. }
  12114. // TODO: find a more accurate date for this
  12115. #if PACKETVER < 20130320
  12116. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12117. /// 0288 <name id>.W <amount>.W
  12118. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12119. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12120. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  12121. int fail = 0;
  12122. nullpo_retv(sd);
  12123. if( sd->state.trading || !sd->npc_shopid )
  12124. fail = 1;
  12125. else {
  12126. #if PACKETVER < 20101116
  12127. short nameid = RFIFOW(fd,2);
  12128. short amount = RFIFOW(fd,4);
  12129. int points = RFIFOL(fd,6);
  12130. fail = npc_cashshop_buy(sd, nameid, amount, points);
  12131. #else
  12132. int len = RFIFOW(fd,2);
  12133. int points = RFIFOL(fd,4);
  12134. int count = RFIFOW(fd,8);
  12135. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  12136. if( len < 10 || len != 10 + count * 4)
  12137. {
  12138. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  12139. return;
  12140. }
  12141. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12142. #endif
  12143. }
  12144. clif_cashshop_ack(sd,fail);
  12145. }
  12146. #endif
  12147. /// Adoption System
  12148. ///
  12149. /// Adoption message (ZC_BABYMSG).
  12150. /// 0216 <msg>.L
  12151. /// msg:
  12152. /// 0 = "You cannot adopt more than 1 child."
  12153. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12154. /// 2 = "You cannot adopt a married person."
  12155. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12156. {
  12157. int fd = sd->fd;
  12158. WFIFOHEAD(fd,6);
  12159. WFIFOW(fd,0) = 0x216;
  12160. WFIFOL(fd,2) = type;
  12161. WFIFOSET(fd,6);
  12162. }
  12163. /// Adoption confirmation (ZC_REQ_BABY).
  12164. /// 01f6 <account id>.L <char id>.L <name>.B
  12165. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12166. {
  12167. int fd = sd->fd;
  12168. WFIFOHEAD(fd,34);
  12169. WFIFOW(fd,0) = 0x1f6;
  12170. WFIFOL(fd,2) = src->status.account_id;
  12171. WFIFOL(fd,6) = p_id;
  12172. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12173. WFIFOSET(fd,34);
  12174. }
  12175. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12176. /// 01f9 <account id>.L
  12177. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12178. {
  12179. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12180. if( pc_can_Adopt(sd, p_sd, tsd) )
  12181. {
  12182. tsd->adopt_invite = sd->status.account_id;
  12183. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12184. }
  12185. }
  12186. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12187. /// 01f7 <account id>.L <char id>.L <answer>.L
  12188. /// answer:
  12189. /// 0 = rejected
  12190. /// 1 = accepted
  12191. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12192. {
  12193. int p1_id = RFIFOL(fd,2);
  12194. int p2_id = RFIFOL(fd,6);
  12195. int result = RFIFOL(fd,10);
  12196. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12197. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12198. int pid = sd->adopt_invite;
  12199. sd->adopt_invite = 0;
  12200. if( p1_sd == NULL || p2_sd == NULL )
  12201. return; // Both players need to be online
  12202. if( pid != p1_sd->status.account_id )
  12203. return; // Incorrect values
  12204. if( result == 0 )
  12205. return; // Rejected
  12206. pc_adoption(p1_sd, p2_sd, sd);
  12207. }
  12208. /// Convex Mirror (ZC_BOSS_INFO).
  12209. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12210. /// infoType:
  12211. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12212. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12213. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12214. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12215. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12216. {
  12217. WFIFOHEAD(fd,70);
  12218. memset(WFIFOP(fd,0),0,70);
  12219. WFIFOW(fd,0) = 0x293;
  12220. if( md != NULL ) {
  12221. if( md->bl.prev != NULL ) { // Boss on This Map
  12222. if( flag ) {
  12223. WFIFOB(fd,2) = 1;
  12224. WFIFOL(fd,3) = md->bl.x;
  12225. WFIFOL(fd,7) = md->bl.y;
  12226. } else
  12227. WFIFOB(fd,2) = 2; // First Time
  12228. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12229. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12230. unsigned int seconds;
  12231. int hours, minutes;
  12232. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12233. hours = seconds / (60 * 60);
  12234. seconds = seconds - (60 * 60 * hours);
  12235. minutes = seconds / 60;
  12236. WFIFOB(fd,2) = 3;
  12237. WFIFOW(fd,11) = hours; // Hours
  12238. WFIFOW(fd,13) = minutes; // Minutes
  12239. }
  12240. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12241. }
  12242. WFIFOSET(fd,70);
  12243. }
  12244. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12245. /// 02d6 <account id>.L
  12246. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12247. {
  12248. int charid = RFIFOL(fd, 2);
  12249. struct map_session_data* tsd = map_id2sd(charid);
  12250. if (!tsd)
  12251. return;
  12252. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12253. clif_viewequip_ack(sd, tsd);
  12254. else
  12255. clif_msg(sd, VIEW_EQUIP_FAIL);
  12256. }
  12257. /// Request to change equip window tick (CZ_CONFIG).
  12258. /// 02d8 <type>.L <value>.L
  12259. /// type:
  12260. /// 0 = open equip window
  12261. /// value:
  12262. /// 0 = disabled
  12263. /// 1 = enabled
  12264. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12265. {
  12266. bool flag = (bool)RFIFOL(fd,6);
  12267. sd->status.show_equip = flag;
  12268. clif_equiptickack(sd, flag);
  12269. }
  12270. /// Questlog System [Kevin] [Inkfish]
  12271. ///
  12272. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12273. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12274. void clif_quest_send_list(struct map_session_data * sd)
  12275. {
  12276. int fd = sd->fd;
  12277. int i;
  12278. int len = sd->avail_quests*5+8;
  12279. WFIFOHEAD(fd,len);
  12280. WFIFOW(fd, 0) = 0x2b1;
  12281. WFIFOW(fd, 2) = len;
  12282. WFIFOL(fd, 4) = sd->avail_quests;
  12283. for( i = 0; i < sd->avail_quests; i++ ) {
  12284. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12285. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12286. }
  12287. WFIFOSET(fd, len);
  12288. }
  12289. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12290. /// 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
  12291. void clif_quest_send_mission(struct map_session_data * sd)
  12292. {
  12293. int fd = sd->fd;
  12294. int i, j;
  12295. int len = sd->avail_quests*104+8;
  12296. struct mob_db *mob;
  12297. WFIFOHEAD(fd, len);
  12298. WFIFOW(fd, 0) = 0x2b2;
  12299. WFIFOW(fd, 2) = len;
  12300. WFIFOL(fd, 4) = sd->avail_quests;
  12301. for( i = 0; i < sd->avail_quests; i++ ) {
  12302. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12303. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12304. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12305. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12306. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ ) {
  12307. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12308. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12309. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12310. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12311. }
  12312. }
  12313. WFIFOSET(fd, len);
  12314. }
  12315. /// Notification about a new quest (ZC_ADD_QUEST).
  12316. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12317. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12318. {
  12319. int fd = sd->fd;
  12320. int i;
  12321. struct mob_db *mob;
  12322. WFIFOHEAD(fd, packet_len(0x2b3));
  12323. WFIFOW(fd, 0) = 0x2b3;
  12324. WFIFOL(fd, 2) = qd->quest_id;
  12325. WFIFOB(fd, 6) = qd->state;
  12326. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12327. WFIFOL(fd, 11) = qd->time;
  12328. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12329. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12330. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12331. WFIFOW(fd, i*30+21) = qd->count[i];
  12332. mob = mob_db(quest_db[index].mob[i]);
  12333. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12334. }
  12335. WFIFOSET(fd, packet_len(0x2b3));
  12336. }
  12337. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12338. /// 02b4 <quest id>.L
  12339. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12340. {
  12341. int fd = sd->fd;
  12342. WFIFOHEAD(fd, packet_len(0x2b4));
  12343. WFIFOW(fd, 0) = 0x2b4;
  12344. WFIFOL(fd, 2) = quest_id;
  12345. WFIFOSET(fd, packet_len(0x2b4));
  12346. }
  12347. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12348. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12349. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12350. {
  12351. int fd = sd->fd;
  12352. int i;
  12353. int len = quest_db[index].num_objectives*12+6;
  12354. WFIFOHEAD(fd, len);
  12355. WFIFOW(fd, 0) = 0x2b5;
  12356. WFIFOW(fd, 2) = len;
  12357. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12358. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12359. WFIFOL(fd, i*12+6) = qd->quest_id;
  12360. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12361. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12362. WFIFOW(fd, i*12+16) = qd->count[i];
  12363. }
  12364. WFIFOSET(fd, len);
  12365. }
  12366. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12367. /// 02b6 <quest id>.L <active>.B
  12368. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12369. {
  12370. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12371. }
  12372. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12373. /// 02b7 <quest id>.L <active>.B
  12374. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12375. {
  12376. int fd = sd->fd;
  12377. WFIFOHEAD(fd, packet_len(0x2b7));
  12378. WFIFOW(fd, 0) = 0x2b7;
  12379. WFIFOL(fd, 2) = quest_id;
  12380. WFIFOB(fd, 6) = active;
  12381. WFIFOSET(fd, packet_len(0x2b7));
  12382. }
  12383. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12384. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12385. /// effect:
  12386. /// 0 = none
  12387. /// 1 = exclamation mark icon
  12388. /// 2 = question mark icon
  12389. /// type:
  12390. /// 0 = yellow
  12391. /// 1 = orange
  12392. /// 2 = green
  12393. /// 3 = purple
  12394. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12395. {
  12396. #if PACKETVER >= 20090218
  12397. int fd = sd->fd;
  12398. WFIFOHEAD(fd, packet_len(0x446));
  12399. WFIFOW(fd, 0) = 0x446;
  12400. WFIFOL(fd, 2) = bl->id;
  12401. WFIFOW(fd, 6) = bl->x;
  12402. WFIFOW(fd, 8) = bl->y;
  12403. WFIFOW(fd, 10) = state;
  12404. WFIFOW(fd, 12) = color;
  12405. WFIFOSET(fd, packet_len(0x446));
  12406. #endif
  12407. }
  12408. /// Mercenary System
  12409. ///
  12410. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12411. /// 02a2 <var id>.W <value>.L
  12412. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12413. {
  12414. struct mercenary_data *md;
  12415. struct status_data *status;
  12416. int fd;
  12417. if( sd == NULL || (md = sd->md) == NULL )
  12418. return;
  12419. fd = sd->fd;
  12420. status = &md->battle_status;
  12421. WFIFOHEAD(fd,packet_len(0x2a2));
  12422. WFIFOW(fd,0) = 0x2a2;
  12423. WFIFOW(fd,2) = type;
  12424. switch( type ) {
  12425. case SP_ATK1:
  12426. {
  12427. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12428. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12429. }
  12430. break;
  12431. case SP_MATK1:
  12432. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12433. break;
  12434. case SP_HIT:
  12435. WFIFOL(fd,4) = status->hit;
  12436. break;
  12437. case SP_CRITICAL:
  12438. WFIFOL(fd,4) = status->cri/10;
  12439. break;
  12440. case SP_DEF1:
  12441. WFIFOL(fd,4) = status->def;
  12442. break;
  12443. case SP_MDEF1:
  12444. WFIFOL(fd,4) = status->mdef;
  12445. break;
  12446. case SP_MERCFLEE:
  12447. WFIFOL(fd,4) = status->flee;
  12448. break;
  12449. case SP_ASPD:
  12450. WFIFOL(fd,4) = status->amotion;
  12451. break;
  12452. case SP_HP:
  12453. WFIFOL(fd,4) = status->hp;
  12454. break;
  12455. case SP_MAXHP:
  12456. WFIFOL(fd,4) = status->max_hp;
  12457. break;
  12458. case SP_SP:
  12459. WFIFOL(fd,4) = status->sp;
  12460. break;
  12461. case SP_MAXSP:
  12462. WFIFOL(fd,4) = status->max_sp;
  12463. break;
  12464. case SP_MERCKILLS:
  12465. WFIFOL(fd,4) = md->mercenary.kill_count;
  12466. break;
  12467. case SP_MERCFAITH:
  12468. WFIFOL(fd,4) = mercenary_get_faith(md);
  12469. break;
  12470. }
  12471. WFIFOSET(fd,packet_len(0x2a2));
  12472. }
  12473. /// Mercenary base status data (ZC_MER_INIT).
  12474. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12475. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12476. /// <calls>.L <kills>.L <atk range>.W
  12477. void clif_mercenary_info(struct map_session_data *sd)
  12478. {
  12479. int fd;
  12480. struct mercenary_data *md;
  12481. struct status_data *status;
  12482. int atk;
  12483. if( sd == NULL || (md = sd->md) == NULL )
  12484. return;
  12485. fd = sd->fd;
  12486. status = &md->battle_status;
  12487. WFIFOHEAD(fd,packet_len(0x29b));
  12488. WFIFOW(fd,0) = 0x29b;
  12489. WFIFOL(fd,2) = md->bl.id;
  12490. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12491. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12492. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12493. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12494. WFIFOW(fd,10) = status->hit;
  12495. WFIFOW(fd,12) = status->cri/10;
  12496. WFIFOW(fd,14) = status->def;
  12497. WFIFOW(fd,16) = status->mdef;
  12498. WFIFOW(fd,18) = status->flee;
  12499. WFIFOW(fd,20) = status->amotion;
  12500. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12501. WFIFOW(fd,46) = md->db->lv;
  12502. WFIFOL(fd,48) = status->hp;
  12503. WFIFOL(fd,52) = status->max_hp;
  12504. WFIFOL(fd,56) = status->sp;
  12505. WFIFOL(fd,60) = status->max_sp;
  12506. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12507. WFIFOW(fd,68) = mercenary_get_faith(md);
  12508. WFIFOL(fd,70) = mercenary_get_calls(md);
  12509. WFIFOL(fd,74) = md->mercenary.kill_count;
  12510. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12511. WFIFOSET(fd,packet_len(0x29b));
  12512. }
  12513. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12514. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12515. void clif_mercenary_skillblock(struct map_session_data *sd)
  12516. {
  12517. struct mercenary_data *md;
  12518. int fd, i, len = 4, id, j;
  12519. if( sd == NULL || (md = sd->md) == NULL )
  12520. return;
  12521. fd = sd->fd;
  12522. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12523. WFIFOW(fd,0) = 0x29d;
  12524. for( i = 0; i < MAX_MERCSKILL; i++ )
  12525. {
  12526. if( (id = md->db->skill[i].id) == 0 )
  12527. continue;
  12528. j = id - MC_SKILLBASE;
  12529. WFIFOW(fd,len) = id;
  12530. WFIFOL(fd,len+2) = skill_get_inf(id);
  12531. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12532. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12533. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12534. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12535. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12536. len += 37;
  12537. }
  12538. WFIFOW(fd,2) = len;
  12539. WFIFOSET(fd,len);
  12540. }
  12541. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12542. /// 029f <command>.B
  12543. /// 1 = mercenary information
  12544. /// 2 = delete
  12545. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12546. {
  12547. int option = RFIFOB(fd,2);
  12548. if( sd->md == NULL )
  12549. return;
  12550. if( option == 2 ) merc_delete(sd->md, 2);
  12551. }
  12552. /// Mercenary Message
  12553. /// message:
  12554. /// 0 = Mercenary soldier's duty hour is over.
  12555. /// 1 = Your mercenary soldier has been killed.
  12556. /// 2 = Your mercenary soldier has been fired.
  12557. /// 3 = Your mercenary soldier has ran away.
  12558. void clif_mercenary_message(struct map_session_data* sd, int message){
  12559. clif_msg(sd, MERC_MSG_BASE + message);
  12560. }
  12561. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12562. /// 0298 <name id>.W <seconds>.L
  12563. void clif_rental_time(int fd, int nameid, int seconds)
  12564. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12565. WFIFOHEAD(fd,packet_len(0x298));
  12566. WFIFOW(fd,0) = 0x298;
  12567. WFIFOW(fd,2) = nameid;
  12568. WFIFOL(fd,4) = seconds;
  12569. WFIFOSET(fd,packet_len(0x298));
  12570. }
  12571. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12572. /// 0299 <index>.W <name id>.W
  12573. void clif_rental_expired(int fd, int index, int nameid)
  12574. { // '<ItemName>' item has been deleted from the Inventory
  12575. WFIFOHEAD(fd,packet_len(0x299));
  12576. WFIFOW(fd,0) = 0x299;
  12577. WFIFOW(fd,2) = index+2;
  12578. WFIFOW(fd,4) = nameid;
  12579. WFIFOSET(fd,packet_len(0x299));
  12580. }
  12581. /// Book Reading (ZC_READ_BOOK).
  12582. /// 0294 <book id>.L <page>.L
  12583. void clif_readbook(int fd, int book_id, int page)
  12584. {
  12585. WFIFOHEAD(fd,packet_len(0x294));
  12586. WFIFOW(fd,0) = 0x294;
  12587. WFIFOL(fd,2) = book_id;
  12588. WFIFOL(fd,6) = page;
  12589. WFIFOSET(fd,packet_len(0x294));
  12590. }
  12591. /// Battlegrounds
  12592. ///
  12593. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12594. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12595. void clif_bg_hp(struct map_session_data *sd)
  12596. {
  12597. unsigned char buf[34];
  12598. const int cmd = 0x2e0;
  12599. nullpo_retv(sd);
  12600. WBUFW(buf,0) = cmd;
  12601. WBUFL(buf,2) = sd->status.account_id;
  12602. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12603. if( sd->battle_status.max_hp > INT16_MAX )
  12604. { // To correctly display the %hp bar. [Skotlex]
  12605. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12606. WBUFW(buf,32) = 100;
  12607. }
  12608. else
  12609. {
  12610. WBUFW(buf,30) = sd->battle_status.hp;
  12611. WBUFW(buf,32) = sd->battle_status.max_hp;
  12612. }
  12613. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12614. }
  12615. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12616. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12617. void clif_bg_xy(struct map_session_data *sd)
  12618. {
  12619. unsigned char buf[36];
  12620. nullpo_retv(sd);
  12621. WBUFW(buf,0)=0x2df;
  12622. WBUFL(buf,2)=sd->status.account_id;
  12623. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12624. WBUFW(buf,30)=sd->status.class_;
  12625. WBUFW(buf,32)=sd->bl.x;
  12626. WBUFW(buf,34)=sd->bl.y;
  12627. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12628. }
  12629. void clif_bg_xy_remove(struct map_session_data *sd)
  12630. {
  12631. unsigned char buf[36];
  12632. nullpo_retv(sd);
  12633. WBUFW(buf,0)=0x2df;
  12634. WBUFL(buf,2)=sd->status.account_id;
  12635. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12636. WBUFW(buf,30)=0;
  12637. WBUFW(buf,32)=-1;
  12638. WBUFW(buf,34)=-1;
  12639. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12640. }
  12641. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12642. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12643. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12644. {
  12645. struct map_session_data *sd;
  12646. unsigned char *buf;
  12647. if( (sd = bg_getavailablesd(bg)) == NULL )
  12648. return;
  12649. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12650. WBUFW(buf,0) = 0x2dc;
  12651. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12652. WBUFL(buf,4) = src_id;
  12653. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12654. memcpy(WBUFP(buf,32), mes, len);
  12655. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12656. if( buf )
  12657. aFree(buf);
  12658. }
  12659. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12660. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12661. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12662. {
  12663. const char* text = (char*)RFIFOP(fd,4);
  12664. int textlen = RFIFOW(fd,2) - 4;
  12665. char *name, *message;
  12666. int namelen, messagelen;
  12667. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12668. return;
  12669. if( is_atcommand(fd, sd, message, 1) )
  12670. return;
  12671. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12672. return;
  12673. if( battle_config.min_chat_delay ) {
  12674. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12675. return;
  12676. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12677. }
  12678. // Reset idle time when using battleground chat.
  12679. sd->idletime = last_tick;
  12680. bg_send_message(sd, text, textlen);
  12681. }
  12682. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12683. /// 02de <camp A points>.W <camp B points>.W
  12684. void clif_bg_updatescore(int16 m)
  12685. {
  12686. struct block_list bl;
  12687. unsigned char buf[6];
  12688. bl.id = 0;
  12689. bl.type = BL_NUL;
  12690. bl.m = m;
  12691. WBUFW(buf,0) = 0x2de;
  12692. WBUFW(buf,2) = map[m].bgscore_lion;
  12693. WBUFW(buf,4) = map[m].bgscore_eagle;
  12694. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12695. }
  12696. void clif_bg_updatescore_single(struct map_session_data *sd)
  12697. {
  12698. int fd;
  12699. nullpo_retv(sd);
  12700. fd = sd->fd;
  12701. WFIFOHEAD(fd,packet_len(0x2de));
  12702. WFIFOW(fd,0) = 0x2de;
  12703. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12704. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12705. WFIFOSET(fd,packet_len(0x2de));
  12706. }
  12707. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12708. /// 02dd <account id>.L <name>.24B <camp>.W
  12709. void clif_sendbgemblem_area(struct map_session_data *sd)
  12710. {
  12711. unsigned char buf[33];
  12712. nullpo_retv(sd);
  12713. WBUFW(buf, 0) = 0x2dd;
  12714. WBUFL(buf,2) = sd->bl.id;
  12715. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12716. WBUFW(buf,30) = sd->bg_id;
  12717. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12718. }
  12719. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12720. {
  12721. nullpo_retv(sd);
  12722. WFIFOHEAD(fd,32);
  12723. WFIFOW(fd,0) = 0x2dd;
  12724. WFIFOL(fd,2) = sd->bl.id;
  12725. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12726. WFIFOW(fd,30) = sd->bg_id;
  12727. WFIFOSET(fd,packet_len(0x2dd));
  12728. }
  12729. /// Custom Fonts (ZC_NOTIFY_FONT).
  12730. /// 02ef <account_id>.L <font id>.W
  12731. void clif_font(struct map_session_data *sd)
  12732. {
  12733. #if PACKETVER >= 20080102
  12734. unsigned char buf[8];
  12735. nullpo_retv(sd);
  12736. WBUFW(buf,0) = 0x2ef;
  12737. WBUFL(buf,2) = sd->bl.id;
  12738. WBUFW(buf,6) = sd->user_font;
  12739. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12740. #endif
  12741. }
  12742. /*==========================================
  12743. * Instancing Window
  12744. *------------------------------------------*/
  12745. int clif_instance(int instance_id, int type, int flag)
  12746. {
  12747. struct map_session_data *sd;
  12748. struct party_data *p;
  12749. unsigned char buf[255];
  12750. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12751. return 0;
  12752. switch( type )
  12753. {
  12754. case 1:
  12755. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12756. // Required to start the instancing information window on Client
  12757. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12758. WBUFW(buf,0) = 0x02CB;
  12759. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12760. WBUFW(buf,63) = flag;
  12761. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12762. break;
  12763. case 2:
  12764. // S 0x2cc <Standby Position>.W
  12765. // To announce Instancing queue creation if no maps available
  12766. WBUFW(buf,0) = 0x02CC;
  12767. WBUFW(buf,2) = flag;
  12768. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12769. break;
  12770. case 3:
  12771. case 4:
  12772. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12773. WBUFW(buf,0) = 0x02CD;
  12774. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12775. if( type == 3 )
  12776. {
  12777. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12778. WBUFL(buf,67) = 0;
  12779. }
  12780. else
  12781. {
  12782. WBUFL(buf,63) = 0;
  12783. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12784. }
  12785. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12786. break;
  12787. case 5:
  12788. // S 0x2ce <Message ID>.L
  12789. // 0 = Notification (EnterLimitDate update?)
  12790. // 1 = The Memorial Dungeon expired; it has been destroyed
  12791. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12792. // 3 = The Memorial Dungeon has been removed.
  12793. // 4 = Create failure (removes the instance window)
  12794. WBUFW(buf,0) = 0x02CE;
  12795. WBUFL(buf,2) = flag;
  12796. //WBUFL(buf,6) = EnterLimitDate;
  12797. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12798. break;
  12799. }
  12800. return 0;
  12801. }
  12802. void clif_instance_join(int fd, int instance_id)
  12803. {
  12804. if( instance[instance_id].idle_timer != INVALID_TIMER ) {
  12805. WFIFOHEAD(fd,packet_len(0x02CD));
  12806. WFIFOW(fd,0) = 0x02CD;
  12807. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12808. WFIFOL(fd,63) = 0;
  12809. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12810. WFIFOSET(fd,packet_len(0x02CD));
  12811. } else if( instance[instance_id].progress_timer != INVALID_TIMER ) {
  12812. WFIFOHEAD(fd,packet_len(0x02CD));
  12813. WFIFOW(fd,0) = 0x02CD;
  12814. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12815. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12816. WFIFOL(fd,67) = 0;
  12817. WFIFOSET(fd,packet_len(0x02CD));
  12818. } else {
  12819. WFIFOHEAD(fd,packet_len(0x02CB));
  12820. WFIFOW(fd,0) = 0x02CB;
  12821. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12822. WFIFOW(fd,63) = 0;
  12823. WFIFOSET(fd,packet_len(0x02CB));
  12824. }
  12825. }
  12826. void clif_instance_leave(int fd)
  12827. {
  12828. WFIFOHEAD(fd,packet_len(0x02CE));
  12829. WFIFOW(fd,0) = 0x02ce;
  12830. WFIFOL(fd,2) = 4;
  12831. WFIFOSET(fd,packet_len(0x02CE));
  12832. }
  12833. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12834. /// 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
  12835. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12836. {
  12837. #if PACKETVER >= 20071002
  12838. unsigned char buf[22];
  12839. struct item_data* id = itemdb_search(item_data->nameid);
  12840. WBUFW(buf,0) = 0x2b8;
  12841. WBUFL(buf,2) = sd->status.account_id;
  12842. WBUFW(buf,6) = item_data->nameid;
  12843. WBUFB(buf,8) = item_data->identify;
  12844. WBUFB(buf,9) = item_data->attribute;
  12845. WBUFB(buf,10) = item_data->refine;
  12846. clif_addcards(WBUFP(buf,11), item_data);
  12847. WBUFW(buf,19) = id->equip; // equip location
  12848. WBUFB(buf,21) = itemtype(id->type); // item type
  12849. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12850. #endif
  12851. }
  12852. /// Display gained exp (ZC_NOTIFY_EXP).
  12853. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12854. /// var id:
  12855. /// SP_BASEEXP, SP_JOBEXP
  12856. /// exp type:
  12857. /// 0 = normal exp gain/loss
  12858. /// 1 = quest exp gain/loss
  12859. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12860. {
  12861. int fd;
  12862. nullpo_retv(sd);
  12863. fd = sd->fd;
  12864. WFIFOHEAD(fd, packet_len(0x7f6));
  12865. WFIFOW(fd,0) = 0x7f6;
  12866. WFIFOL(fd,2) = sd->bl.id;
  12867. WFIFOL(fd,6) = exp;
  12868. WFIFOW(fd,10) = type;
  12869. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12870. WFIFOSET(fd,packet_len(0x7f6));
  12871. }
  12872. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12873. /// type:
  12874. /// 0 = Displays 'value' for 5 seconds.
  12875. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12876. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12877. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12878. /// value:
  12879. /// 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).
  12880. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12881. {
  12882. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12883. WFIFOW(sd->fd,0) = 0x1b1;
  12884. WFIFOB(sd->fd,2) = type;
  12885. WFIFOL(sd->fd,3) = value;
  12886. WFIFOSET(sd->fd, packet_len(0x1b1));
  12887. }
  12888. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12889. /// 021d <state>.L
  12890. /// state:
  12891. /// 0 = Full effects
  12892. /// 1 = Reduced effects
  12893. ///
  12894. /// NOTE: The state is used on Aegis for sending skill unit packet
  12895. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12896. /// whenever possible. Due to the way the decision check is
  12897. /// constructed, this state tracking was rendered useless,
  12898. /// as the only skill unit, that is sent with 0x1c9 is
  12899. /// Graffiti.
  12900. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12901. {
  12902. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12903. sd->state.lesseffect = ( isLess != 0 );
  12904. }
  12905. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12906. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12907. int n = (RFIFOW(fd,2)-12) / 4;
  12908. int type = RFIFOL(fd,4);
  12909. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12910. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12911. if( sd->state.trading || sd->npc_shopid )
  12912. return;
  12913. if( flag == 0 || n == 0) {
  12914. clif_menuskill_clear(sd);
  12915. return; // Canceled by player.
  12916. }
  12917. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12918. clif_menuskill_clear(sd);
  12919. return; // Prevent hacking.
  12920. }
  12921. switch( type ) {
  12922. case 0: // Change Material
  12923. skill_changematerial(sd,n,item_list);
  12924. break;
  12925. case 1: // Level 1: Pure to Rough
  12926. case 2: // Level 2: Rough to Pure
  12927. skill_elementalanalysis(sd,n,type,item_list);
  12928. break;
  12929. }
  12930. clif_menuskill_clear(sd);
  12931. return;
  12932. }
  12933. /*==========================================
  12934. * Elemental System
  12935. *==========================================*/
  12936. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  12937. struct elemental_data *ed;
  12938. struct status_data *status;
  12939. int fd;
  12940. if( sd == NULL || (ed = sd->ed) == NULL )
  12941. return;
  12942. fd = sd->fd;
  12943. status = &ed->battle_status;
  12944. WFIFOHEAD(fd,8);
  12945. WFIFOW(fd,0) = 0x81e;
  12946. WFIFOW(fd,2) = type;
  12947. switch( type ) {
  12948. case SP_HP:
  12949. WFIFOL(fd,4) = status->hp;
  12950. break;
  12951. case SP_MAXHP:
  12952. WFIFOL(fd,4) = status->max_hp;
  12953. break;
  12954. case SP_SP:
  12955. WFIFOL(fd,4) = status->sp;
  12956. break;
  12957. case SP_MAXSP:
  12958. WFIFOL(fd,4) = status->max_sp;
  12959. break;
  12960. }
  12961. WFIFOSET(fd,8);
  12962. }
  12963. void clif_elemental_info(struct map_session_data *sd) {
  12964. int fd;
  12965. struct elemental_data *ed;
  12966. struct status_data *status;
  12967. if( sd == NULL || (ed = sd->ed) == NULL )
  12968. return;
  12969. fd = sd->fd;
  12970. status = &ed->battle_status;
  12971. WFIFOHEAD(fd,22);
  12972. WFIFOW(fd, 0) = 0x81d;
  12973. WFIFOL(fd, 2) = ed->bl.id;
  12974. WFIFOL(fd, 6) = status->hp;
  12975. WFIFOL(fd,10) = status->max_hp;
  12976. WFIFOL(fd,14) = status->sp;
  12977. WFIFOL(fd,18) = status->max_sp;
  12978. WFIFOSET(fd,22);
  12979. }
  12980. /// Buying Store System
  12981. ///
  12982. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12983. /// 0810 <slots>.B
  12984. void clif_buyingstore_open(struct map_session_data* sd)
  12985. {
  12986. int fd = sd->fd;
  12987. WFIFOHEAD(fd,packet_len(0x810));
  12988. WFIFOW(fd,0) = 0x810;
  12989. WFIFOB(fd,2) = sd->buyingstore.slots;
  12990. WFIFOSET(fd,packet_len(0x810));
  12991. }
  12992. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12993. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12994. /// result:
  12995. /// 0 = cancel
  12996. /// 1 = open
  12997. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12998. {
  12999. const unsigned int blocksize = 8;
  13000. uint8* itemlist;
  13001. char storename[MESSAGE_SIZE];
  13002. unsigned char result;
  13003. int zenylimit;
  13004. unsigned int count, packet_len;
  13005. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13006. packet_len = RFIFOW(fd,info->pos[0]);
  13007. // TODO: Make this check global for all variable length packets.
  13008. if( packet_len < 89 )
  13009. {// minimum packet length
  13010. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13011. return;
  13012. }
  13013. zenylimit = RFIFOL(fd,info->pos[1]);
  13014. result = RFIFOL(fd,info->pos[2]);
  13015. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13016. itemlist = RFIFOP(fd,info->pos[4]);
  13017. // so that buyingstore_create knows, how many elements it has access to
  13018. packet_len-= info->pos[4];
  13019. if( packet_len%blocksize )
  13020. {
  13021. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13022. return;
  13023. }
  13024. count = packet_len/blocksize;
  13025. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13026. }
  13027. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13028. /// 0812 <result>.W <total weight>.L
  13029. /// result:
  13030. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13031. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13032. /// 8 = "No sale (purchase) information available." (0x705)
  13033. /// ? = nothing
  13034. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13035. {
  13036. int fd = sd->fd;
  13037. WFIFOHEAD(fd,packet_len(0x812));
  13038. WFIFOW(fd,0) = 0x812;
  13039. WFIFOW(fd,2) = result;
  13040. WFIFOL(fd,4) = weight;
  13041. WFIFOSET(fd,packet_len(0x812));
  13042. }
  13043. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13044. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13045. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13046. {
  13047. int fd = sd->fd;
  13048. unsigned int i;
  13049. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13050. WFIFOW(fd,0) = 0x813;
  13051. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13052. WFIFOL(fd,4) = sd->bl.id;
  13053. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13054. for( i = 0; i < sd->buyingstore.slots; i++ )
  13055. {
  13056. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13057. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13058. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  13059. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13060. }
  13061. WFIFOSET(fd,WFIFOW(fd,2));
  13062. }
  13063. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13064. /// 0814 <account id>.L <store name>.80B
  13065. void clif_buyingstore_entry(struct map_session_data* sd)
  13066. {
  13067. uint8 buf[86];
  13068. WBUFW(buf,0) = 0x814;
  13069. WBUFL(buf,2) = sd->bl.id;
  13070. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13071. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13072. }
  13073. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13074. {
  13075. int fd = sd->fd;
  13076. WFIFOHEAD(fd,packet_len(0x814));
  13077. WFIFOW(fd,0) = 0x814;
  13078. WFIFOL(fd,2) = pl_sd->bl.id;
  13079. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13080. WFIFOSET(fd,packet_len(0x814));
  13081. }
  13082. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13083. /// 0815
  13084. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13085. {
  13086. buyingstore_close(sd);
  13087. }
  13088. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13089. /// 0816 <account id>.L
  13090. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13091. {
  13092. uint8 buf[6];
  13093. WBUFW(buf,0) = 0x816;
  13094. WBUFL(buf,2) = sd->bl.id;
  13095. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13096. }
  13097. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13098. {
  13099. int fd = sd->fd;
  13100. WFIFOHEAD(fd,packet_len(0x816));
  13101. WFIFOW(fd,0) = 0x816;
  13102. WFIFOL(fd,2) = pl_sd->bl.id;
  13103. WFIFOSET(fd,packet_len(0x816));
  13104. }
  13105. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13106. /// 0817 <account id>.L
  13107. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13108. {
  13109. int account_id;
  13110. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13111. buyingstore_open(sd, account_id);
  13112. }
  13113. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13114. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13115. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13116. {
  13117. int fd = sd->fd;
  13118. unsigned int i;
  13119. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13120. WFIFOW(fd,0) = 0x818;
  13121. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13122. WFIFOL(fd,4) = pl_sd->bl.id;
  13123. WFIFOL(fd,8) = pl_sd->buyer_id;
  13124. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13125. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13126. {
  13127. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13128. 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.
  13129. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13130. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13131. }
  13132. WFIFOSET(fd,WFIFOW(fd,2));
  13133. }
  13134. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13135. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13136. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13137. {
  13138. const unsigned int blocksize = 6;
  13139. uint8* itemlist;
  13140. int account_id;
  13141. unsigned int count, packet_len, buyer_id;
  13142. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13143. packet_len = RFIFOW(fd,info->pos[0]);
  13144. if( packet_len < 12 )
  13145. {// minimum packet length
  13146. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13147. return;
  13148. }
  13149. account_id = RFIFOL(fd,info->pos[1]);
  13150. buyer_id = RFIFOL(fd,info->pos[2]);
  13151. itemlist = RFIFOP(fd,info->pos[3]);
  13152. // so that buyingstore_trade knows, how many elements it has access to
  13153. packet_len-= info->pos[3];
  13154. if( packet_len%blocksize )
  13155. {
  13156. 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);
  13157. return;
  13158. }
  13159. count = packet_len/blocksize;
  13160. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13161. }
  13162. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13163. /// 081a <result>.W
  13164. /// result:
  13165. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13166. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13167. /// ? = nothing
  13168. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13169. {
  13170. int fd = sd->fd;
  13171. WFIFOHEAD(fd,packet_len(0x81a));
  13172. WFIFOW(fd,0) = 0x81a;
  13173. WFIFOW(fd,2) = result;
  13174. WFIFOSET(fd,packet_len(0x81a));
  13175. }
  13176. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13177. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13178. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13179. {
  13180. int fd = sd->fd;
  13181. WFIFOHEAD(fd,packet_len(0x81b));
  13182. WFIFOW(fd,0) = 0x81b;
  13183. WFIFOW(fd,2) = nameid;
  13184. WFIFOW(fd,4) = amount; // amount of nameid received
  13185. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13186. WFIFOSET(fd,packet_len(0x81b));
  13187. }
  13188. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13189. /// 081c <index>.W <amount>.W <price>.L
  13190. /// message:
  13191. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13192. ///
  13193. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13194. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13195. {
  13196. int fd = sd->fd;
  13197. WFIFOHEAD(fd,packet_len(0x81c));
  13198. WFIFOW(fd,0) = 0x81c;
  13199. WFIFOW(fd,2) = index+2;
  13200. WFIFOW(fd,4) = amount;
  13201. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13202. WFIFOSET(fd,packet_len(0x81c));
  13203. }
  13204. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13205. /// 0824 <result>.W <name id>.W
  13206. /// result:
  13207. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13208. /// 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)
  13209. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13210. /// ? = nothing
  13211. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13212. {
  13213. int fd = sd->fd;
  13214. WFIFOHEAD(fd,packet_len(0x824));
  13215. WFIFOW(fd,0) = 0x824;
  13216. WFIFOW(fd,2) = result;
  13217. WFIFOW(fd,4) = nameid;
  13218. WFIFOSET(fd,packet_len(0x824));
  13219. }
  13220. /// Search Store Info System
  13221. ///
  13222. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13223. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13224. /// type:
  13225. /// 0 = Vending
  13226. /// 1 = Buying Store
  13227. ///
  13228. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13229. /// amount of card slots. If the client does not know about the item it
  13230. /// cannot be searched.
  13231. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13232. {
  13233. const unsigned int blocksize = 2;
  13234. const uint8* itemlist;
  13235. const uint8* cardlist;
  13236. unsigned char type;
  13237. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13238. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13239. packet_len = RFIFOW(fd,info->pos[0]);
  13240. if( packet_len < 15 )
  13241. {// minimum packet length
  13242. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13243. return;
  13244. }
  13245. type = RFIFOB(fd,info->pos[1]);
  13246. max_price = RFIFOL(fd,info->pos[2]);
  13247. min_price = RFIFOL(fd,info->pos[3]);
  13248. item_count = RFIFOB(fd,info->pos[4]);
  13249. card_count = RFIFOB(fd,info->pos[5]);
  13250. itemlist = RFIFOP(fd,info->pos[6]);
  13251. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13252. // check, if there is enough data for the claimed count of items
  13253. packet_len-= info->pos[6];
  13254. if( packet_len%blocksize )
  13255. {
  13256. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13257. return;
  13258. }
  13259. count = packet_len/blocksize;
  13260. if( count < item_count+card_count )
  13261. {
  13262. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13263. return;
  13264. }
  13265. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13266. }
  13267. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13268. /// 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 }*
  13269. /// is first page:
  13270. /// 0 = appends to existing results
  13271. /// 1 = clears previous results before displaying this result set
  13272. /// is next page:
  13273. /// 0 = no "next" label
  13274. /// 1 = "next" label to retrieve more results
  13275. void clif_search_store_info_ack(struct map_session_data* sd)
  13276. {
  13277. const unsigned int blocksize = MESSAGE_SIZE+26;
  13278. int fd = sd->fd;
  13279. unsigned int i, start, end;
  13280. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13281. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13282. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13283. WFIFOW(fd,0) = 0x836;
  13284. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13285. WFIFOB(fd,4) = !sd->searchstore.pages;
  13286. WFIFOB(fd,5) = searchstore_querynext(sd);
  13287. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13288. for( i = start; i < end; i++ ) {
  13289. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13290. struct item it;
  13291. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13292. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13293. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13294. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13295. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13296. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13297. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13298. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13299. // make-up an item for clif_addcards
  13300. memset(&it, 0, sizeof(it));
  13301. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13302. it.nameid = ssitem->nameid;
  13303. it.amount = ssitem->amount;
  13304. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13305. }
  13306. WFIFOSET(fd,WFIFOW(fd,2));
  13307. }
  13308. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13309. /// 0837 <reason>.B
  13310. /// reason:
  13311. /// 0 = "No matching stores were found." (0x70b)
  13312. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13313. /// 2 = "You cannot search anymore." (0x706)
  13314. /// 3 = "You cannot search yet." (0x708)
  13315. /// 4 = "No sale (purchase) information available." (0x705)
  13316. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13317. {
  13318. int fd = sd->fd;
  13319. WFIFOHEAD(fd,packet_len(0x837));
  13320. WFIFOW(fd,0) = 0x837;
  13321. WFIFOB(fd,2) = reason;
  13322. WFIFOSET(fd,packet_len(0x837));
  13323. }
  13324. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13325. /// 0838
  13326. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13327. {
  13328. searchstore_next(sd);
  13329. }
  13330. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13331. /// 083a <type>.W <remaining uses>.B
  13332. /// type:
  13333. /// 0 = Search Stores
  13334. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13335. void clif_open_search_store_info(struct map_session_data* sd)
  13336. {
  13337. int fd = sd->fd;
  13338. WFIFOHEAD(fd,packet_len(0x83a));
  13339. WFIFOW(fd,0) = 0x83a;
  13340. WFIFOW(fd,2) = sd->searchstore.effect;
  13341. #if PACKETVER > 20100701
  13342. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13343. #endif
  13344. WFIFOSET(fd,packet_len(0x83a));
  13345. }
  13346. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13347. /// 083b
  13348. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13349. {
  13350. searchstore_close(sd);
  13351. }
  13352. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13353. /// 083c <account id>.L <store id>.L <nameid>.W
  13354. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13355. {
  13356. unsigned short nameid;
  13357. int account_id, store_id;
  13358. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13359. account_id = RFIFOL(fd,info->pos[0]);
  13360. store_id = RFIFOL(fd,info->pos[1]);
  13361. nameid = RFIFOW(fd,info->pos[2]);
  13362. searchstore_click(sd, account_id, store_id, nameid);
  13363. }
  13364. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13365. /// 083d <xPos>.W <yPos>.W
  13366. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13367. {
  13368. int fd = sd->fd;
  13369. WFIFOHEAD(fd,packet_len(0x83d));
  13370. WFIFOW(fd,0) = 0x83d;
  13371. WFIFOW(fd,2) = x;
  13372. WFIFOW(fd,4) = y;
  13373. WFIFOSET(fd,packet_len(0x83d));
  13374. }
  13375. /// Parse function for packet debugging.
  13376. void clif_parse_debug(int fd,struct map_session_data *sd)
  13377. {
  13378. int cmd, packet_len;
  13379. // clif_parse ensures, that there is at least 2 bytes of data
  13380. cmd = RFIFOW(fd,0);
  13381. if( sd ) {
  13382. packet_len = packet_db[sd->packet_ver][cmd].len;
  13383. if( packet_len == 0 )
  13384. {// unknown
  13385. packet_len = RFIFOREST(fd);
  13386. }
  13387. else if( packet_len == -1 )
  13388. {// variable length
  13389. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13390. }
  13391. 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);
  13392. }
  13393. else
  13394. {
  13395. packet_len = RFIFOREST(fd);
  13396. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13397. }
  13398. ShowDump(RFIFOP(fd,0), packet_len);
  13399. }
  13400. /*==========================================
  13401. * Server tells client to display a window similar to Magnifier (item) one
  13402. * Server populates the window with avilable elemental converter options according to player's inventory
  13403. *------------------------------------------*/
  13404. int clif_elementalconverter_list(struct map_session_data *sd) {
  13405. int i,c,view,fd;
  13406. nullpo_ret(sd);
  13407. /// Main client packet processing function
  13408. fd=sd->fd;
  13409. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13410. WFIFOW(fd, 0)=0x1ad;
  13411. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13412. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13413. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13414. WFIFOW(fd,c*2+ 4)= view;
  13415. else
  13416. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13417. c++;
  13418. }
  13419. }
  13420. WFIFOW(fd,2) = c*2+4;
  13421. WFIFOSET(fd, WFIFOW(fd,2));
  13422. if (c > 0) {
  13423. sd->menuskill_id = SA_CREATECON;
  13424. sd->menuskill_val = c;
  13425. }
  13426. return 0;
  13427. }
  13428. /**
  13429. * Rune Knight
  13430. **/
  13431. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13432. #if PACKETVER >= 20081217
  13433. unsigned char buf[10];
  13434. WBUFW(buf,0) = 0x440;
  13435. WBUFL(buf,2) = sd->bl.id;
  13436. WBUFW(buf,6) = shields;
  13437. WBUFW(buf,8) = 0;
  13438. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13439. #endif
  13440. }
  13441. /**
  13442. * Warlock
  13443. **/
  13444. /*==========================================
  13445. * Spellbook list [LimitLine/3CeAM]
  13446. *------------------------------------------*/
  13447. int clif_spellbook_list(struct map_session_data *sd)
  13448. {
  13449. int i, c;
  13450. int fd;
  13451. nullpo_ret(sd);
  13452. fd = sd->fd;
  13453. WFIFOHEAD(fd, 8 * 8 + 8);
  13454. WFIFOW(fd,0) = 0x1ad;
  13455. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13456. {
  13457. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13458. {
  13459. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13460. c ++;
  13461. }
  13462. }
  13463. if( c > 0 )
  13464. {
  13465. WFIFOW(fd,2) = c * 2 + 4;
  13466. WFIFOSET(fd, WFIFOW(fd, 2));
  13467. sd->menuskill_id = WL_READING_SB;
  13468. sd->menuskill_val = c;
  13469. }
  13470. else{
  13471. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13472. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  13473. }
  13474. return 1;
  13475. }
  13476. /**
  13477. * Mechanic
  13478. **/
  13479. /*==========================================
  13480. * Magic Decoy Material List
  13481. *------------------------------------------*/
  13482. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  13483. int i, c;
  13484. int fd;
  13485. nullpo_ret(sd);
  13486. fd = sd->fd;
  13487. WFIFOHEAD(fd, 8 * 8 + 8);
  13488. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13489. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13490. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13491. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13492. c ++;
  13493. }
  13494. }
  13495. if( c > 0 ) {
  13496. sd->menuskill_id = NC_MAGICDECOY;
  13497. sd->menuskill_val = skill_lv;
  13498. sd->sc.comet_x = x;
  13499. sd->sc.comet_y = y;
  13500. WFIFOW(fd,2) = c * 2 + 4;
  13501. WFIFOSET(fd, WFIFOW(fd, 2));
  13502. } else {
  13503. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13504. return 0;
  13505. }
  13506. return 1;
  13507. }
  13508. /**
  13509. * Guilotine Cross
  13510. **/
  13511. /*==========================================
  13512. * Guillotine Cross Poisons List
  13513. *------------------------------------------*/
  13514. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  13515. int i, c;
  13516. int fd;
  13517. nullpo_ret(sd);
  13518. fd = sd->fd;
  13519. WFIFOHEAD(fd, 8 * 8 + 8);
  13520. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13521. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13522. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13523. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13524. c ++;
  13525. }
  13526. }
  13527. if( c > 0 ) {
  13528. sd->menuskill_id = GC_POISONINGWEAPON;
  13529. sd->menuskill_val = skill_lv;
  13530. WFIFOW(fd,2) = c * 2 + 4;
  13531. WFIFOSET(fd, WFIFOW(fd, 2));
  13532. } else {
  13533. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13534. return 0;
  13535. }
  13536. return 1;
  13537. }
  13538. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13539. int fd, i, c;
  13540. nullpo_ret(sd);
  13541. fd = sd->fd;
  13542. if( !fd ) return 0;
  13543. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13544. return 0;
  13545. WFIFOHEAD(fd, 2 * 6 + 4);
  13546. WFIFOW(fd,0) = 0x442;
  13547. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13548. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13549. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13550. { // Can't auto cast both Extended class and 3rd class skills.
  13551. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13552. c++;
  13553. }
  13554. if( c > 0 ) {
  13555. WFIFOW(fd,2) = 8 + c * 2;
  13556. WFIFOL(fd,4) = c;
  13557. WFIFOSET(fd,WFIFOW(fd,2));
  13558. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13559. sd->menuskill_val = c;
  13560. } else {
  13561. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13562. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13563. }
  13564. return 1;
  13565. }
  13566. /*===========================================
  13567. * Skill list for Four Elemental Analysis
  13568. * and Change Material skills.
  13569. *------------------------------------------*/
  13570. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  13571. {
  13572. #if PACKETVER >= 20090922
  13573. int fd;
  13574. nullpo_ret(sd);
  13575. sd->menuskill_id = skill_id; // To prevent hacking.
  13576. sd->menuskill_val = skill_lv;
  13577. if( skill_id == GN_CHANGEMATERIAL )
  13578. skill_lv = 0; // Changematerial
  13579. fd = sd->fd;
  13580. WFIFOHEAD(fd,packet_len(0x7e3));
  13581. WFIFOW(fd,0) = 0x7e3;
  13582. WFIFOL(fd,2) = skill_lv;
  13583. WFIFOL(fd,4) = 0;
  13584. WFIFOSET(fd,packet_len(0x7e3));
  13585. #endif
  13586. return 1;
  13587. }
  13588. /**
  13589. * Sends a new status without a tick (currently used by the new mounts)
  13590. **/
  13591. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13592. unsigned char buf[32];
  13593. nullpo_ret(bl);
  13594. WBUFW(buf,0)=0x043f;
  13595. WBUFW(buf,2)=type;
  13596. WBUFL(buf,4)=bl->id;
  13597. WBUFB(buf,8)=flag;
  13598. WBUFL(buf,9) = 0;
  13599. WBUFL(buf,13) = val1;
  13600. WBUFL(buf,17) = val2;
  13601. WBUFL(buf,21) = val3;
  13602. clif_send(buf,packet_len(0x043f),bl,AREA);
  13603. return 0;
  13604. }
  13605. //Notifies FD of ID's type
  13606. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13607. WFIFOHEAD(fd, packet_len(0x043f));
  13608. WFIFOW(fd,0)=0x043f;
  13609. WFIFOW(fd,2)=type;
  13610. WFIFOL(fd,4)=id;
  13611. WFIFOB(fd,8)=flag;
  13612. WFIFOL(fd,9) = 0;
  13613. WFIFOL(fd,13) = val1;
  13614. WFIFOL(fd,17) = val2;
  13615. WFIFOL(fd,21) = val3;
  13616. WFIFOSET(fd, packet_len(0x043f));
  13617. return 0;
  13618. }
  13619. // msgstringtable.txt
  13620. // 0x291 <line>.W
  13621. void clif_msgtable(int fd, int line) {
  13622. WFIFOHEAD(fd, packet_len(0x291));
  13623. WFIFOW(fd, 0) = 0x291;
  13624. WFIFOW(fd, 2) = line;
  13625. WFIFOSET(fd, packet_len(0x291));
  13626. }
  13627. // msgstringtable.txt
  13628. // 0x7e2 <line>.W <value>.L
  13629. void clif_msgtable_num(int fd, int line, int num) {
  13630. #if PACKETVER >= 20090805
  13631. WFIFOHEAD(fd, packet_len(0x7e2));
  13632. WFIFOW(fd, 0) = 0x7e2;
  13633. WFIFOW(fd, 2) = line;
  13634. WFIFOL(fd, 4) = num;
  13635. WFIFOSET(fd, packet_len(0x7e2));
  13636. #endif
  13637. }
  13638. /*==========================================
  13639. * used by SC_AUTOSHADOWSPELL
  13640. * RFIFOL(fd,2) - flag (currently not used)
  13641. *------------------------------------------*/
  13642. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13643. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13644. return;
  13645. if( pc_istrading(sd) ) {
  13646. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  13647. clif_menuskill_clear(sd);
  13648. return;
  13649. }
  13650. skill_select_menu(sd,RFIFOW(fd,6));
  13651. clif_menuskill_clear(sd);
  13652. }
  13653. /*==========================================
  13654. * Kagerou/Oboro amulet spirit
  13655. *------------------------------------------*/
  13656. void clif_talisman(struct map_session_data *sd,short type)
  13657. {
  13658. unsigned char buf[10];
  13659. nullpo_retv(sd);
  13660. WBUFW(buf,0)=0x08cf;
  13661. WBUFL(buf,2)=sd->bl.id;
  13662. WBUFW(buf,6)=type;
  13663. WBUFW(buf,8)=sd->talisman[type];
  13664. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  13665. }
  13666. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  13667. /// 0907 <index>.W
  13668. ///
  13669. /// R 0908 <index>.w <type>.b
  13670. /// type:
  13671. /// 0 = move item to personal tab
  13672. /// 1 = move item to normal tab
  13673. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  13674. #if PACKETVER >= 20111122
  13675. int index;
  13676. /* can't move while dead. */
  13677. if(pc_isdead(sd)) {
  13678. return;
  13679. }
  13680. index = RFIFOW(fd,2)-2;
  13681. if (index < 0 || index >= MAX_INVENTORY)
  13682. return;
  13683. if ( sd->status.inventory[index].favorite && RFIFOB(fd, 4) == 1 )
  13684. sd->status.inventory[index].favorite = 0;
  13685. else if( RFIFOB(fd, 4) == 0 )
  13686. sd->status.inventory[index].favorite = 1;
  13687. else
  13688. return;/* nothing to do. */
  13689. clif_favorite_item(sd, index);
  13690. #endif
  13691. }
  13692. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  13693. /// 0900 <index>.W <favorite>.B
  13694. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  13695. int fd = sd->fd;
  13696. WFIFOHEAD(fd,packet_len(0x908));
  13697. WFIFOW(fd,0) = 0x908;
  13698. WFIFOW(fd,2) = index+2;
  13699. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  13700. WFIFOSET(fd,packet_len(0x908));
  13701. }
  13702. void clif_snap( struct block_list *bl, short x, short y ) {
  13703. unsigned char buf[10];
  13704. WBUFW(buf,0) = 0x8d2;
  13705. WBUFL(buf,2) = bl->id;
  13706. WBUFW(buf,6) = x;
  13707. WBUFW(buf,8) = y;
  13708. clif_send(buf,packet_len(0x8d2),bl,AREA);
  13709. }
  13710. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  13711. #if PACKETVER >= 20120404
  13712. WFIFOHEAD(fd,packet_len(0x977));
  13713. WFIFOW(fd,0) = 0x977;
  13714. WFIFOL(fd,2) = md->bl.id;
  13715. WFIFOL(fd,6) = md->status.hp;
  13716. WFIFOL(fd,10) = md->status.max_hp;
  13717. WFIFOSET(fd,packet_len(0x977));
  13718. #endif
  13719. }
  13720. void clif_cashshop_open( struct map_session_data* sd ){
  13721. WFIFOHEAD( sd->fd, 10 );
  13722. WFIFOW( sd->fd, 0 ) = 0x845;
  13723. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13724. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13725. WFIFOSET( sd->fd, 10 );
  13726. }
  13727. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13728. clif_cashshop_open( sd );
  13729. }
  13730. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13731. // No need to do anything here
  13732. }
  13733. void clif_cashshop_list( int fd ){
  13734. int tab;
  13735. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13736. int length = 8 + cash_shop_items->count * 6;
  13737. int i, offset;
  13738. WFIFOHEAD( fd, length );
  13739. WFIFOW( fd, 0 ) = 0x8ca;
  13740. WFIFOW( fd, 2 ) = length;
  13741. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13742. WFIFOW( fd, 6 ) = tab;
  13743. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13744. WFIFOW( fd, offset ) = cash_shop_items[tab].item[i]->nameid;
  13745. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13746. }
  13747. WFIFOSET( fd, length );
  13748. }
  13749. }
  13750. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13751. clif_cashshop_list( fd );
  13752. }
  13753. // TODO: find a more accurate date for this
  13754. #if PACKETVER >= 20130320
  13755. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  13756. uint16 length = RFIFOW( fd, 2 );
  13757. uint16 count = RFIFOL( fd, 4 );
  13758. if( length < 10 || length < ( 10 + count * 6 ) ){
  13759. return;
  13760. }
  13761. cashshop_buylist( sd, RFIFOL( fd, 6 ), count, (uint16 *)RFIFOP( fd, 10 ) );
  13762. }
  13763. #endif
  13764. void clif_cashshop_result( struct map_session_data *sd, uint16 item_id, uint16 result ){
  13765. WFIFOHEAD( sd->fd, 16 );
  13766. WFIFOW( sd->fd, 0 ) = 0x849;
  13767. WFIFOL( sd->fd, 2 ) = item_id;
  13768. WFIFOW( sd->fd, 6 ) = result;
  13769. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13770. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13771. WFIFOSET( sd->fd, 16 );
  13772. }
  13773. /*==========================================
  13774. * Main client packet processing function
  13775. *------------------------------------------*/
  13776. static int clif_parse(int fd)
  13777. {
  13778. int cmd, packet_ver, packet_len, err;
  13779. TBL_PC* sd;
  13780. int pnum;
  13781. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13782. // Note: "click masters" can do 80+ clicks in 10 seconds
  13783. 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]
  13784. { // begin main client packet processing loop
  13785. sd = (TBL_PC *)session[fd]->session_data;
  13786. if (session[fd]->flag.eof) {
  13787. if (sd) {
  13788. if (sd->state.autotrade) {
  13789. //Disassociate character from the socket connection.
  13790. session[fd]->session_data = NULL;
  13791. sd->fd = 0;
  13792. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13793. } else
  13794. if (sd->state.active) {
  13795. // Player logout display [Valaris]
  13796. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13797. clif_quitsave(fd, sd);
  13798. } else {
  13799. //Unusual logout (during log on/off/map-changer procedure)
  13800. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13801. map_quit(sd);
  13802. }
  13803. } else {
  13804. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13805. }
  13806. do_close(fd);
  13807. return 0;
  13808. }
  13809. if (RFIFOREST(fd) < 2)
  13810. return 0;
  13811. cmd = RFIFOW(fd,0);
  13812. // identify client's packet version
  13813. if (sd) {
  13814. packet_ver = sd->packet_ver;
  13815. } else {
  13816. // check authentification packet to know packet version
  13817. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13818. if( err ) {// failed to identify packet version
  13819. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  13820. err == 1 ? "" :
  13821. err == 2 ? ", possibly for having an invalid account_id" :
  13822. err == 3 ? ", possibly for having an invalid char_id." :
  13823. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13824. err == 4 ? ", possibly for having an invalid login_id1." :
  13825. err == 5 ? ", possibly for having an invalid client_tick." :
  13826. */
  13827. err == 6 ? ", possibly for having an invalid sex." :
  13828. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  13829. WFIFOHEAD(fd,packet_len(0x6a));
  13830. WFIFOW(fd,0) = 0x6a;
  13831. WFIFOB(fd,2) = 3; // Rejected from Server
  13832. WFIFOSET(fd,packet_len(0x6a));
  13833. #ifdef DUMP_INVALID_PACKET
  13834. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13835. #endif
  13836. RFIFOSKIP(fd, RFIFOREST(fd));
  13837. set_eof(fd);
  13838. return 0;
  13839. }
  13840. }
  13841. // filter out invalid / unsupported packets
  13842. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13843. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13844. #ifdef DUMP_INVALID_PACKET
  13845. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13846. #endif
  13847. set_eof(fd);
  13848. return 0;
  13849. }
  13850. // determine real packet length
  13851. packet_len = packet_db[packet_ver][cmd].len;
  13852. if (packet_len == -1) { // variable-length packet
  13853. if (RFIFOREST(fd) < 4)
  13854. return 0;
  13855. packet_len = RFIFOW(fd,2);
  13856. if (packet_len < 4 || packet_len > 32768) {
  13857. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13858. #ifdef DUMP_INVALID_PACKET
  13859. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13860. #endif
  13861. set_eof(fd);
  13862. return 0;
  13863. }
  13864. }
  13865. if ((int)RFIFOREST(fd) < packet_len)
  13866. return 0; // not enough data received to form the packet
  13867. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13868. packet_db[packet_ver][cmd].func(fd, sd);
  13869. else if( packet_db[packet_ver][cmd].func != NULL ) {
  13870. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13871. ; //Only valid packet when there is no session
  13872. else
  13873. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13874. ; //Only valid packet when player is not on a map
  13875. else
  13876. packet_db[packet_ver][cmd].func(fd, sd);
  13877. }
  13878. #ifdef DUMP_UNKNOWN_PACKET
  13879. else {
  13880. const char* packet_txt = "save/packet.txt";
  13881. FILE* fp;
  13882. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  13883. if( sd ) {
  13884. 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);
  13885. } else {
  13886. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13887. }
  13888. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13889. fprintf(fp, "\n");
  13890. fclose(fp);
  13891. } else {
  13892. ShowError("Failed to write '%s'.\n", packet_txt);
  13893. // Dump on console instead
  13894. if( sd ) {
  13895. 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);
  13896. } else {
  13897. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13898. }
  13899. ShowDump(RFIFOP(fd,0), packet_len);
  13900. }
  13901. }
  13902. #endif
  13903. RFIFOSKIP(fd, packet_len);
  13904. }; // main loop end
  13905. return 0;
  13906. }
  13907. /*==========================================
  13908. * Reads packet_db.txt and setups its array reference
  13909. *------------------------------------------*/
  13910. static int packetdb_readdb(void)
  13911. {
  13912. FILE *fp;
  13913. char line[1024];
  13914. int ln=0;
  13915. int cmd,i,j,packet_ver;
  13916. int max_cmd=-1;
  13917. int skip_ver = 0;
  13918. int warned = 0;
  13919. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13920. int packet_len_table[MAX_PACKET_DB] = {
  13921. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13925. //#0x0040
  13926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13928. #if PACKETVER <= 20081217
  13929. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13930. #else
  13931. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13932. #endif
  13933. #if PACKETVER < 2
  13934. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13935. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  13936. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13937. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13938. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13939. #else
  13940. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13941. #endif
  13942. //#0x0080
  13943. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13944. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13945. #if PACKETVER <= 20100622
  13946. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13947. #else
  13948. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13949. #endif
  13950. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13951. //#0x00C0
  13952. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13953. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13954. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13955. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13956. //#0x0100
  13957. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13958. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13959. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13960. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13961. //#0x0140
  13962. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13963. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13964. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13965. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13966. //#0x0180
  13967. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13968. #if PACKETVER < 1
  13969. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13970. #else // 196 comodo icon status display for later
  13971. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13972. #endif
  13973. #if PACKETVER < 20081126
  13974. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13975. #else // 0x1a2 changed (35->37)
  13976. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13977. #endif
  13978. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13979. //#0x01C0, Set 0x1d5=-1
  13980. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13981. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13982. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13983. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13984. //#0x0200
  13985. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13986. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13987. #if PACKETVER < 20071106
  13988. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13989. #else // 0x22c changed
  13990. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13991. #endif
  13992. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13993. //#0x0240
  13994. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13995. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13996. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13997. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13998. //#0x0280
  13999. #if PACKETVER < 20070711
  14000. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14001. #else
  14002. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14003. #endif
  14004. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14005. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14006. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14007. //#0x02C0
  14008. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14009. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14010. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14011. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14012. //#0x0300
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14017. //#0x0340
  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, 0, 0, 0,
  14021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14022. //#0x0380
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14027. //#0x03C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14032. //#0x0400
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14037. //#0x0440
  14038. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 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, 0,
  14041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14042. //#0x0480
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14047. //#0x04C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14052. //#0x0500
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14057. //#0x0540
  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, 0,
  14061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14062. //#0x0580
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14067. //#0x05C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14072. //#0x0600
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14077. //#0x0640
  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, 0,
  14081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14082. //#0x0680
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14087. //#0x06C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14092. //#0x0700
  14093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14097. //#0x0740
  14098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14102. //#0x0780
  14103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14107. //#0x07C0
  14108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14109. #if PACKETVER < 20090617
  14110. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  14111. #else // 0x7d9 changed
  14112. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  14113. #endif
  14114. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  14115. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  14116. //#0x0800
  14117. #if PACKETVER < 20091229
  14118. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  14119. #else // for Party booking ( PACKETVER >= 20091229 )
  14120. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  14121. #endif
  14122. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  14123. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14124. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  14125. //#0x0840
  14126. #if PACKETVER < 20130000
  14127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14128. #else
  14129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0,
  14130. #endif
  14131. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14134. //#0x0880
  14135. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14139. //#0x08C0
  14140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  14141. 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14144. //#0x0900
  14145. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14149. //#0x0940
  14150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14153. 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0,
  14154. //#0x0980
  14155. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0,
  14157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14158. 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0,
  14159. };
  14160. struct {
  14161. void (*func)(int, struct map_session_data *);
  14162. char *name;
  14163. } clif_parse_func[]={
  14164. {clif_parse_WantToConnection,"wanttoconnection"},
  14165. {clif_parse_LoadEndAck,"loadendack"},
  14166. {clif_parse_TickSend,"ticksend"},
  14167. {clif_parse_WalkToXY,"walktoxy"},
  14168. {clif_parse_QuitGame,"quitgame"},
  14169. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14170. {clif_parse_GlobalMessage,"globalmessage"},
  14171. {clif_parse_MapMove,"mapmove"},
  14172. {clif_parse_ChangeDir,"changedir"},
  14173. {clif_parse_Emotion,"emotion"},
  14174. {clif_parse_HowManyConnections,"howmanyconnections"},
  14175. {clif_parse_ActionRequest,"actionrequest"},
  14176. {clif_parse_Restart,"restart"},
  14177. {clif_parse_WisMessage,"wis"},
  14178. {clif_parse_Broadcast,"broadcast"},
  14179. {clif_parse_TakeItem,"takeitem"},
  14180. {clif_parse_DropItem,"dropitem"},
  14181. {clif_parse_UseItem,"useitem"},
  14182. {clif_parse_EquipItem,"equipitem"},
  14183. {clif_parse_UnequipItem,"unequipitem"},
  14184. {clif_parse_NpcClicked,"npcclicked"},
  14185. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14186. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14187. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14188. {clif_parse_CreateChatRoom,"createchatroom"},
  14189. {clif_parse_ChatAddMember,"chataddmember"},
  14190. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14191. {clif_parse_ChangeChatOwner,"changechatowner"},
  14192. {clif_parse_KickFromChat,"kickfromchat"},
  14193. {clif_parse_ChatLeave,"chatleave"},
  14194. {clif_parse_TradeRequest,"traderequest"},
  14195. {clif_parse_TradeAck,"tradeack"},
  14196. {clif_parse_TradeAddItem,"tradeadditem"},
  14197. {clif_parse_TradeOk,"tradeok"},
  14198. {clif_parse_TradeCancel,"tradecancel"},
  14199. {clif_parse_TradeCommit,"tradecommit"},
  14200. {clif_parse_StopAttack,"stopattack"},
  14201. {clif_parse_PutItemToCart,"putitemtocart"},
  14202. {clif_parse_GetItemFromCart,"getitemfromcart"},
  14203. {clif_parse_RemoveOption,"removeoption"},
  14204. {clif_parse_ChangeCart,"changecart"},
  14205. {clif_parse_StatusUp,"statusup"},
  14206. {clif_parse_SkillUp,"skillup"},
  14207. {clif_parse_UseSkillToId,"useskilltoid"},
  14208. {clif_parse_UseSkillToPos,"useskilltopos"},
  14209. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  14210. {clif_parse_UseSkillMap,"useskillmap"},
  14211. {clif_parse_RequestMemo,"requestmemo"},
  14212. {clif_parse_ProduceMix,"producemix"},
  14213. {clif_parse_Cooking,"cooking"},
  14214. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  14215. {clif_parse_NpcNextClicked,"npcnextclicked"},
  14216. {clif_parse_NpcAmountInput,"npcamountinput"},
  14217. {clif_parse_NpcStringInput,"npcstringinput"},
  14218. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  14219. {clif_parse_ItemIdentify,"itemidentify"},
  14220. {clif_parse_SelectArrow,"selectarrow"},
  14221. {clif_parse_AutoSpell,"autospell"},
  14222. {clif_parse_UseCard,"usecard"},
  14223. {clif_parse_InsertCard,"insertcard"},
  14224. {clif_parse_RepairItem,"repairitem"},
  14225. {clif_parse_WeaponRefine,"weaponrefine"},
  14226. {clif_parse_SolveCharName,"solvecharname"},
  14227. {clif_parse_ResetChar,"resetchar"},
  14228. {clif_parse_LocalBroadcast,"localbroadcast"},
  14229. {clif_parse_MoveToKafra,"movetokafra"},
  14230. {clif_parse_MoveFromKafra,"movefromkafra"},
  14231. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  14232. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  14233. {clif_parse_CloseKafra,"closekafra"},
  14234. {clif_parse_CreateParty,"createparty"},
  14235. {clif_parse_CreateParty2,"createparty2"},
  14236. {clif_parse_PartyInvite,"partyinvite"},
  14237. {clif_parse_PartyInvite2,"partyinvite2"},
  14238. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  14239. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  14240. {clif_parse_LeaveParty,"leaveparty"},
  14241. {clif_parse_RemovePartyMember,"removepartymember"},
  14242. {clif_parse_PartyChangeOption,"partychangeoption"},
  14243. {clif_parse_PartyMessage,"partymessage"},
  14244. {clif_parse_PartyChangeLeader,"partychangeleader"},
  14245. {clif_parse_CloseVending,"closevending"},
  14246. {clif_parse_VendingListReq,"vendinglistreq"},
  14247. {clif_parse_PurchaseReq,"purchasereq"},
  14248. {clif_parse_PurchaseReq2,"purchasereq2"},
  14249. {clif_parse_OpenVending,"openvending"},
  14250. {clif_parse_CreateGuild,"createguild"},
  14251. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  14252. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  14253. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  14254. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  14255. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  14256. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  14257. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  14258. {clif_parse_GuildInvite,"guildinvite"},
  14259. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  14260. {clif_parse_GuildLeave,"guildleave"},
  14261. {clif_parse_GuildExpulsion,"guildexpulsion"},
  14262. {clif_parse_GuildMessage,"guildmessage"},
  14263. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  14264. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  14265. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  14266. {clif_parse_GuildOpposition,"guildopposition"},
  14267. {clif_parse_GuildBreak,"guildbreak"},
  14268. {clif_parse_PetMenu,"petmenu"},
  14269. {clif_parse_CatchPet,"catchpet"},
  14270. {clif_parse_SelectEgg,"selectegg"},
  14271. {clif_parse_SendEmotion,"sendemotion"},
  14272. {clif_parse_ChangePetName,"changepetname"},
  14273. {clif_parse_GMKick,"gmkick"},
  14274. {clif_parse_GMHide,"gmhide"},
  14275. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14276. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14277. {clif_parse_GMKickAll,"killall"},
  14278. {clif_parse_GMRecall,"recall"},
  14279. {clif_parse_GMRecall,"summon"},
  14280. {clif_parse_GM_Monster_Item,"itemmonster"},
  14281. {clif_parse_GMShift,"remove"},
  14282. {clif_parse_GMShift,"shift"},
  14283. {clif_parse_GMChangeMapType,"changemaptype"},
  14284. {clif_parse_GMRc,"rc"},
  14285. {clif_parse_GMRecall2,"recall2"},
  14286. {clif_parse_GMRemove2,"remove2"},
  14287. {clif_parse_NoviceDoriDori,"sndoridori"},
  14288. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14289. {clif_parse_PMIgnore,"wisexin"},
  14290. {clif_parse_PMIgnoreList,"wisexlist"},
  14291. {clif_parse_PMIgnoreAll,"wisall"},
  14292. {clif_parse_FriendsListAdd,"friendslistadd"},
  14293. {clif_parse_FriendsListRemove,"friendslistremove"},
  14294. {clif_parse_FriendsListReply,"friendslistreply"},
  14295. {clif_parse_Blacksmith,"blacksmith"},
  14296. {clif_parse_Alchemist,"alchemist"},
  14297. {clif_parse_Taekwon,"taekwon"},
  14298. {clif_parse_RankingPk,"rankingpk"},
  14299. {clif_parse_FeelSaveOk,"feelsaveok"},
  14300. {clif_parse_debug,"debug"},
  14301. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14302. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14303. {clif_parse_HomMoveTo,"hommoveto"},
  14304. {clif_parse_HomAttack,"homattack"},
  14305. {clif_parse_HomMenu,"hommenu"},
  14306. {clif_parse_StoragePassword,"storagepassword"},
  14307. {clif_parse_Hotkey,"hotkey"},
  14308. {clif_parse_AutoRevive,"autorevive"},
  14309. {clif_parse_Check,"check"},
  14310. {clif_parse_Adopt_request,"adoptrequest"},
  14311. {clif_parse_Adopt_reply,"adoptreply"},
  14312. // MAIL SYSTEM
  14313. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14314. {clif_parse_Mail_read,"mailread"},
  14315. {clif_parse_Mail_getattach,"mailgetattach"},
  14316. {clif_parse_Mail_delete,"maildelete"},
  14317. {clif_parse_Mail_return,"mailreturn"},
  14318. {clif_parse_Mail_setattach,"mailsetattach"},
  14319. {clif_parse_Mail_winopen,"mailwinopen"},
  14320. {clif_parse_Mail_send,"mailsend"},
  14321. // AUCTION SYSTEM
  14322. {clif_parse_Auction_search,"auctionsearch"},
  14323. {clif_parse_Auction_buysell,"auctionbuysell"},
  14324. {clif_parse_Auction_setitem,"auctionsetitem"},
  14325. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14326. {clif_parse_Auction_register,"auctionregister"},
  14327. {clif_parse_Auction_cancel,"auctioncancel"},
  14328. {clif_parse_Auction_close,"auctionclose"},
  14329. {clif_parse_Auction_bid,"auctionbid"},
  14330. // Quest Log System
  14331. {clif_parse_questStateAck,"queststate"},
  14332. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14333. {clif_parse_EquipTick,"equiptickbox"},
  14334. {clif_parse_BattleChat,"battlechat"},
  14335. {clif_parse_mercenary_action,"mermenu"},
  14336. {clif_parse_progressbar,"progressbar"},
  14337. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14338. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14339. #if PACKETVER >= 20091229
  14340. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14341. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14342. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14343. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14344. #endif
  14345. {clif_parse_PVPInfo,"pvpinfo"},
  14346. {clif_parse_LessEffect,"lesseffect"},
  14347. // Buying Store
  14348. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14349. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14350. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14351. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14352. // Store Search
  14353. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14354. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14355. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14356. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14357. // Cashshop
  14358. { clif_parse_cashshop_open_request, "cashshopopen" },
  14359. { clif_parse_cashshop_close, "cashshopclose" },
  14360. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  14361. { clif_parse_cashshop_buy, "cashshopbuy" },
  14362. /* */
  14363. { clif_parse_MoveItem , "moveitem" },
  14364. {NULL,NULL}
  14365. };
  14366. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14367. memset(packet_db,0,sizeof(packet_db));
  14368. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14369. packet_len(i) = packet_len_table[i];
  14370. sprintf(line, "%s/packet_db.txt", db_path);
  14371. if( (fp=fopen(line,"r"))==NULL ){
  14372. ShowFatalError("can't read %s\n", line);
  14373. exit(EXIT_FAILURE);
  14374. }
  14375. clif_config.packet_db_ver = MAX_PACKET_VER;
  14376. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14377. while( fgets(line, sizeof(line), fp) )
  14378. {
  14379. ln++;
  14380. if(line[0]=='/' && line[1]=='/')
  14381. continue;
  14382. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14383. {
  14384. if(strcmpi(w1,"packet_ver")==0) {
  14385. int prev_ver = packet_ver;
  14386. skip_ver = 0;
  14387. packet_ver = atoi(w2);
  14388. if ( packet_ver > MAX_PACKET_VER )
  14389. { //Check to avoid overflowing. [Skotlex]
  14390. if( (warned&1) == 0 )
  14391. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14392. warned &= 1;
  14393. skip_ver = 1;
  14394. }
  14395. else if( packet_ver < 0 )
  14396. {
  14397. if( (warned&2) == 0 )
  14398. ShowWarning("Negative packet versions are not supported.\n");
  14399. warned &= 2;
  14400. skip_ver = 1;
  14401. }
  14402. else if( packet_ver == SERVER )
  14403. {
  14404. if( (warned&4) == 0 )
  14405. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14406. warned &= 4;
  14407. skip_ver = 1;
  14408. }
  14409. if( skip_ver )
  14410. {
  14411. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14412. packet_ver = prev_ver;
  14413. continue;
  14414. }
  14415. // copy from previous version into new version and continue
  14416. // - indicating all following packets should be read into the newer version
  14417. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14418. continue;
  14419. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14420. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14421. clif_config.packet_db_ver = MAX_PACKET_VER;
  14422. else // to manually set the packet DB version
  14423. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14424. continue;
  14425. }
  14426. }
  14427. if( skip_ver != 0 )
  14428. continue; // Skipping current packet version
  14429. memset(str,0,sizeof(str));
  14430. for(j=0,p=line;j<4 && p; ++j)
  14431. {
  14432. str[j]=p;
  14433. p=strchr(p,',');
  14434. if(p) *p++=0;
  14435. }
  14436. if(str[0]==NULL)
  14437. continue;
  14438. cmd=strtol(str[0],(char **)NULL,0);
  14439. if(max_cmd < cmd)
  14440. max_cmd = cmd;
  14441. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14442. continue;
  14443. if(str[1]==NULL){
  14444. ShowError("packet_db: packet len error\n");
  14445. continue;
  14446. }
  14447. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14448. if(str[2]==NULL){
  14449. packet_db[packet_ver][cmd].func = NULL;
  14450. ln++;
  14451. continue;
  14452. }
  14453. // look up processing function by name
  14454. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14455. if( j < ARRAYLENGTH(clif_parse_func) )
  14456. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14457. // set the identifying cmd for the packet_db version
  14458. if (strcmp(str[2],"wanttoconnection")==0)
  14459. clif_config.connect_cmd[packet_ver] = cmd;
  14460. if(str[3]==NULL){
  14461. ShowError("packet_db: packet error\n");
  14462. exit(EXIT_FAILURE);
  14463. }
  14464. for(j=0,p2=str[3];p2;j++){
  14465. short k;
  14466. str2[j]=p2;
  14467. p2=strchr(p2,':');
  14468. if(p2) *p2++=0;
  14469. k = atoi(str2[j]);
  14470. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14471. if( j >= MAX_PACKET_POS )
  14472. {
  14473. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14474. break;
  14475. }
  14476. packet_db[packet_ver][cmd].pos[j] = k;
  14477. }
  14478. }
  14479. fclose(fp);
  14480. if(max_cmd > MAX_PACKET_DB)
  14481. {
  14482. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14483. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14484. }
  14485. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14486. { //Locate the nearest version that we still support. [Skotlex]
  14487. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14488. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14489. }
  14490. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'.\n","packet_db.txt");
  14491. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  14492. return 0;
  14493. }
  14494. /*==========================================
  14495. *
  14496. *------------------------------------------*/
  14497. int do_init_clif(void) {
  14498. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14499. int i;
  14500. /**
  14501. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14502. **/
  14503. for(i = 0; i < COLOR_MAX; i++) {
  14504. color_table[i] = strtoul(colors[i],NULL,0);
  14505. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14506. }
  14507. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14508. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14509. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14510. packetdb_readdb();
  14511. set_defaultparse(clif_parse);
  14512. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14513. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  14514. exit(EXIT_FAILURE);
  14515. }
  14516. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14517. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14518. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  14519. return 0;
  14520. }
  14521. void do_final_clif(void) {
  14522. ers_destroy(delay_clearunit_ers);
  14523. }