clif.c 513 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/grfio.h"
  7. #include "../common/malloc.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/random.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "../common/ers.h"
  14. #include "../common/conf.h"
  15. #include "map.h"
  16. #include "chrif.h"
  17. #include "pc.h"
  18. #include "status.h"
  19. #include "npc.h"
  20. #include "itemdb.h"
  21. #include "chat.h"
  22. #include "trade.h"
  23. #include "storage.h"
  24. #include "script.h"
  25. #include "skill.h"
  26. #include "atcommand.h"
  27. #include "intif.h"
  28. #include "battle.h"
  29. #include "battleground.h"
  30. #include "mob.h"
  31. #include "party.h"
  32. #include "unit.h"
  33. #include "guild.h"
  34. #include "vending.h"
  35. #include "pet.h"
  36. #include "homunculus.h"
  37. #include "instance.h"
  38. #include "mercenary.h"
  39. #include "elemental.h"
  40. #include "log.h"
  41. #include "clif.h"
  42. #include "mail.h"
  43. #include "quest.h"
  44. #include "cashshop.h"
  45. #include "channel.h"
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stdarg.h>
  50. #include <time.h>
  51. /* for clif_clearunit_delayed */
  52. static struct eri *delay_clearunit_ers;
  53. //#define DUMP_UNKNOWN_PACKET
  54. //#define DUMP_INVALID_PACKET
  55. struct Clif_Config {
  56. int packet_db_ver; //Preferred packet version.
  57. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  58. } clif_config;
  59. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  60. int packet_db_ack[MAX_PACKET_VER + 1][MAX_ACK_FUNC + 1];
  61. //Converts item type in case of pet eggs.
  62. static inline int itemtype(int type) {
  63. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  64. }
  65. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  66. p += pos;
  67. p[0] = (uint8)(x>>2);
  68. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  69. p[2] = (uint8)((y<<4) | (dir&0xf));
  70. }
  71. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  72. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  73. p += pos;
  74. p[0] = (uint8)(x0>>2);
  75. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  76. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  77. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  78. p[4] = (uint8)y1;
  79. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  80. }
  81. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  82. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  83. }
  84. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  85. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  86. }
  87. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  88. p += pos;
  89. if( x ) {
  90. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  91. }
  92. if( y ) {
  93. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  94. }
  95. if( dir ) {
  96. dir[0] = ( p[2] & 0x0f );
  97. }
  98. }
  99. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  100. p += pos;
  101. if( x0 ) {
  102. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  103. }
  104. if( y0 ) {
  105. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  106. }
  107. if( x1 ) {
  108. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  109. }
  110. if( y1 ) {
  111. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  112. }
  113. if( sx0 ) {
  114. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  115. }
  116. if( sy0 ) {
  117. sy0[0] = ( p[5] & 0x0f ) >> 0;
  118. }
  119. }
  120. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  121. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  122. }
  123. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  124. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  125. }
  126. //To idenfity disguised characters.
  127. static inline bool disguised(struct block_list* bl) {
  128. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  129. }
  130. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  131. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  132. if( len > max )
  133. len = max;
  134. mes[len-1] = '\0';
  135. return len;
  136. }
  137. static char map_ip_str[128];
  138. static uint32 map_ip;
  139. static uint32 bind_ip = INADDR_ANY;
  140. static uint16 map_port = 5121;
  141. static bool clif_ally_only = false;
  142. int map_fd;
  143. static int clif_parse (int fd);
  144. /*==========================================
  145. * Ip setting of map-server
  146. *------------------------------------------*/
  147. int clif_setip(const char* ip) {
  148. char ip_str[16];
  149. map_ip = host2ip(ip);
  150. if (!map_ip) {
  151. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  152. return 0;
  153. }
  154. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  155. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  156. return 1;
  157. }
  158. void clif_setbindip(const char* ip)
  159. {
  160. bind_ip = host2ip(ip);
  161. if (bind_ip) {
  162. char ip_str[16];
  163. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  164. } else {
  165. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  166. }
  167. }
  168. /*==========================================
  169. * Sets map port to 'port'
  170. * is run from map.c upon loading map server configuration
  171. *------------------------------------------*/
  172. void clif_setport(uint16 port)
  173. {
  174. map_port = port;
  175. }
  176. /*==========================================
  177. * Returns map server IP
  178. *------------------------------------------*/
  179. uint32 clif_getip(void)
  180. {
  181. return map_ip;
  182. }
  183. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  184. uint32 clif_refresh_ip(void)
  185. {
  186. uint32 new_ip;
  187. new_ip = host2ip(map_ip_str);
  188. if (new_ip && new_ip != map_ip) {
  189. map_ip = new_ip;
  190. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  191. return map_ip;
  192. }
  193. return 0;
  194. }
  195. /*==========================================
  196. * Returns map port which is set by clif_setport()
  197. *------------------------------------------*/
  198. uint16 clif_getport(void)
  199. {
  200. return map_port;
  201. }
  202. #if PACKETVER >= 20071106
  203. static inline unsigned char clif_bl_type(struct block_list *bl) {
  204. switch (bl->type) {
  205. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  206. case BL_ITEM: return 0x2; //ITEM_TYPE
  207. case BL_SKILL: return 0x3; //SKILL_TYPE
  208. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  209. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  210. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  211. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  212. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  213. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  214. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  215. default: return 0x1; //NPC_TYPE
  216. }
  217. }
  218. #endif
  219. /*==========================================
  220. * sub process of clif_send
  221. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  222. * In order to send area-wise packets, such as:
  223. * - AREA : everyone nearby your area
  224. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  225. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  226. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  227. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  228. *------------------------------------------*/
  229. static int clif_send_sub(struct block_list *bl, va_list ap)
  230. {
  231. struct block_list *src_bl;
  232. struct map_session_data *sd;
  233. unsigned char *buf;
  234. int len, type, fd;
  235. nullpo_ret(bl);
  236. nullpo_ret(sd = (struct map_session_data *)bl);
  237. fd = sd->fd;
  238. if (!fd) //Don't send to disconnected clients.
  239. return 0;
  240. buf = va_arg(ap,unsigned char*);
  241. len = va_arg(ap,int);
  242. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  243. type = va_arg(ap,int);
  244. switch(type) {
  245. case AREA_WOS:
  246. if (bl == src_bl)
  247. return 0;
  248. break;
  249. case AREA_WOC:
  250. if (sd->chatID || bl == src_bl)
  251. return 0;
  252. break;
  253. case AREA_WOSC:
  254. {
  255. if(src_bl->type == BL_PC) {
  256. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  257. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  258. return 0;
  259. }
  260. else if(src_bl->type == BL_NPC) {
  261. struct npc_data *nd = (struct npc_data *)src_bl;
  262. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  263. return 0;
  264. }
  265. }
  266. break;
  267. }
  268. if (session[fd] == NULL)
  269. return 0;
  270. /* unless visible, hold it here */
  271. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  272. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  273. return 0;
  274. WFIFOHEAD(fd, len);
  275. if (WFIFOP(fd,0) == buf) {
  276. ShowError("WARNING: Invalid use of clif_send function\n");
  277. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  278. ShowError(" Please correct your code.\n");
  279. // don't send to not move the pointer of the packet for next sessions in the loop
  280. //WFIFOSET(fd,0);//## TODO is this ok?
  281. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  282. return 0;
  283. }
  284. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  285. memcpy(WFIFOP(fd,0), buf, len);
  286. WFIFOSET(fd,len);
  287. }
  288. return 0;
  289. }
  290. /*==========================================
  291. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  292. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  293. *------------------------------------------*/
  294. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  295. {
  296. int i;
  297. struct map_session_data *sd, *tsd;
  298. struct party_data *p = NULL;
  299. struct guild *g = NULL;
  300. struct battleground_data *bg = NULL;
  301. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  302. struct s_mapiterator* iter;
  303. if( type != ALL_CLIENT )
  304. nullpo_ret(bl);
  305. sd = BL_CAST(BL_PC, bl);
  306. switch(type) {
  307. case ALL_CLIENT: //All player clients.
  308. iter = mapit_getallusers();
  309. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  310. {
  311. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  312. { // packet must exist for the client version
  313. WFIFOHEAD(tsd->fd, len);
  314. memcpy(WFIFOP(tsd->fd,0), buf, len);
  315. WFIFOSET(tsd->fd,len);
  316. }
  317. }
  318. mapit_free(iter);
  319. break;
  320. case ALL_SAMEMAP: //All players on the same map
  321. iter = mapit_getallusers();
  322. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  323. {
  324. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  325. { // packet must exist for the client version
  326. WFIFOHEAD(tsd->fd, len);
  327. memcpy(WFIFOP(tsd->fd,0), buf, len);
  328. WFIFOSET(tsd->fd,len);
  329. }
  330. }
  331. mapit_free(iter);
  332. break;
  333. case AREA:
  334. case AREA_WOSC:
  335. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  336. clif_send (buf, len, bl, SELF);
  337. case AREA_WOC:
  338. case AREA_WOS:
  339. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  340. BL_PC, buf, len, bl, type);
  341. break;
  342. case AREA_CHAT_WOC:
  343. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  344. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  345. break;
  346. case CHAT:
  347. case CHAT_WOS:
  348. {
  349. struct chat_data *cd;
  350. if (sd) {
  351. cd = (struct chat_data*)map_id2bl(sd->chatID);
  352. } else if (bl->type == BL_CHAT) {
  353. cd = (struct chat_data*)bl;
  354. } else break;
  355. if (cd == NULL)
  356. break;
  357. for(i = 0; i < cd->users; i++) {
  358. if (type == CHAT_WOS && cd->usersd[i] == sd)
  359. continue;
  360. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  361. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  362. {
  363. WFIFOHEAD(fd,len);
  364. memcpy(WFIFOP(fd,0), buf, len);
  365. WFIFOSET(fd,len);
  366. }
  367. }
  368. }
  369. }
  370. break;
  371. case PARTY_AREA:
  372. case PARTY_AREA_WOS:
  373. x0 = bl->x - AREA_SIZE;
  374. y0 = bl->y - AREA_SIZE;
  375. x1 = bl->x + AREA_SIZE;
  376. y1 = bl->y + AREA_SIZE;
  377. case PARTY:
  378. case PARTY_WOS:
  379. case PARTY_SAMEMAP:
  380. case PARTY_SAMEMAP_WOS:
  381. if (sd && sd->status.party_id)
  382. p = party_search(sd->status.party_id);
  383. if (p) {
  384. for(i=0;i<MAX_PARTY;i++){
  385. if( (sd = p->data[i].sd) == NULL )
  386. continue;
  387. if( !(fd=sd->fd) )
  388. continue;
  389. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  390. continue;
  391. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  392. continue;
  393. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  394. continue;
  395. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  396. { // packet must exist for the client version
  397. WFIFOHEAD(fd,len);
  398. memcpy(WFIFOP(fd,0), buf, len);
  399. WFIFOSET(fd,len);
  400. }
  401. }
  402. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  403. break;
  404. iter = mapit_getallusers();
  405. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  406. {
  407. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  408. { // packet must exist for the client version
  409. WFIFOHEAD(tsd->fd, len);
  410. memcpy(WFIFOP(tsd->fd,0), buf, len);
  411. WFIFOSET(tsd->fd,len);
  412. }
  413. }
  414. mapit_free(iter);
  415. }
  416. break;
  417. case DUEL:
  418. case DUEL_WOS:
  419. if (!sd || !sd->duel_group) break; //Invalid usage.
  420. iter = mapit_getallusers();
  421. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  422. {
  423. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  424. continue;
  425. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  426. { // packet must exist for the client version
  427. WFIFOHEAD(tsd->fd, len);
  428. memcpy(WFIFOP(tsd->fd,0), buf, len);
  429. WFIFOSET(tsd->fd,len);
  430. }
  431. }
  432. mapit_free(iter);
  433. break;
  434. case SELF:
  435. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  436. WFIFOHEAD(fd,len);
  437. memcpy(WFIFOP(fd,0), buf, len);
  438. WFIFOSET(fd,len);
  439. }
  440. break;
  441. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  442. case GUILD_AREA:
  443. case GUILD_AREA_WOS:
  444. x0 = bl->x - AREA_SIZE;
  445. y0 = bl->y - AREA_SIZE;
  446. x1 = bl->x + AREA_SIZE;
  447. y1 = bl->y + AREA_SIZE;
  448. case GUILD_SAMEMAP:
  449. case GUILD_SAMEMAP_WOS:
  450. case GUILD:
  451. case GUILD_WOS:
  452. case GUILD_NOBG:
  453. if (sd && sd->status.guild_id)
  454. g = sd->guild;
  455. if (g) {
  456. for(i = 0; i < g->max_member; i++) {
  457. if( (sd = g->member[i].sd) != NULL )
  458. {
  459. if( !(fd=sd->fd) )
  460. continue;
  461. if( type == GUILD_NOBG && sd->bg_id )
  462. continue;
  463. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  464. continue;
  465. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  466. continue;
  467. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  468. continue;
  469. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  470. { // packet must exist for the client version
  471. WFIFOHEAD(fd,len);
  472. memcpy(WFIFOP(fd,0), buf, len);
  473. WFIFOSET(fd,len);
  474. }
  475. }
  476. }
  477. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  478. break;
  479. iter = mapit_getallusers();
  480. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  481. {
  482. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  483. { // packet must exist for the client version
  484. WFIFOHEAD(tsd->fd, len);
  485. memcpy(WFIFOP(tsd->fd,0), buf, len);
  486. WFIFOSET(tsd->fd,len);
  487. }
  488. }
  489. mapit_free(iter);
  490. }
  491. break;
  492. case BG_AREA:
  493. case BG_AREA_WOS:
  494. x0 = bl->x - AREA_SIZE;
  495. y0 = bl->y - AREA_SIZE;
  496. x1 = bl->x + AREA_SIZE;
  497. y1 = bl->y + AREA_SIZE;
  498. case BG_SAMEMAP:
  499. case BG_SAMEMAP_WOS:
  500. case BG:
  501. case BG_WOS:
  502. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  503. {
  504. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  505. {
  506. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  507. continue;
  508. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  509. continue;
  510. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  511. continue;
  512. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  513. continue;
  514. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  515. { // packet must exist for the client version
  516. WFIFOHEAD(fd,len);
  517. memcpy(WFIFOP(fd,0), buf, len);
  518. WFIFOSET(fd,len);
  519. }
  520. }
  521. }
  522. break;
  523. default:
  524. ShowError("clif_send: Unrecognized type %d\n",type);
  525. return -1;
  526. }
  527. return 0;
  528. }
  529. /// Notifies the client, that it's connection attempt was accepted.
  530. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  531. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  532. void clif_authok(struct map_session_data *sd)
  533. {
  534. #if PACKETVER < 20080102
  535. const int cmd = 0x73;
  536. #else
  537. const int cmd = 0x2eb;
  538. #endif
  539. int fd = sd->fd;
  540. WFIFOHEAD(fd,packet_len(cmd));
  541. WFIFOW(fd, 0) = cmd;
  542. WFIFOL(fd, 2) = gettick();
  543. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  544. WFIFOB(fd, 9) = 5; // ignored
  545. WFIFOB(fd,10) = 5; // ignored
  546. #if PACKETVER >= 20080102
  547. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  548. #endif
  549. WFIFOSET(fd,packet_len(cmd));
  550. }
  551. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  552. /// 0074 <error code>.B
  553. /// error code:
  554. /// 0 = client type mismatch
  555. /// 1 = ID mismatch
  556. /// 2 = mobile - out of available time
  557. /// 3 = mobile - already logged in
  558. /// 4 = mobile - waiting state
  559. void clif_authrefuse(int fd, uint8 error_code)
  560. {
  561. WFIFOHEAD(fd,packet_len(0x74));
  562. WFIFOW(fd,0) = 0x74;
  563. WFIFOB(fd,2) = error_code;
  564. WFIFOSET(fd,packet_len(0x74));
  565. }
  566. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  567. /// 0081 <error code>.B
  568. /// error code:
  569. /// 0 = BAN_UNFAIR
  570. /// 1 = server closed -> MsgStringTable[4]
  571. /// 2 = ID already logged in -> MsgStringTable[5]
  572. /// 3 = timeout/too much lag -> MsgStringTable[241]
  573. /// 4 = server full -> MsgStringTable[264]
  574. /// 5 = underaged -> MsgStringTable[305]
  575. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  576. /// 9 = too many connections from this ip -> MsgStringTable[529]
  577. /// 10 = out of available time paid for -> MsgStringTable[530]
  578. /// 11 = BAN_PAY_SUSPEND
  579. /// 12 = BAN_PAY_CHANGE
  580. /// 13 = BAN_PAY_WRONGIP
  581. /// 14 = BAN_PAY_PNGAMEROOM
  582. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  583. /// 16 = BAN_JAPAN_REFUSE1
  584. /// 17 = BAN_JAPAN_REFUSE2
  585. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  586. /// 100 = BAN_PC_IP_UNFAIR
  587. /// 101 = BAN_PC_IP_COUNT_ALL
  588. /// 102 = BAN_PC_IP_COUNT
  589. /// 103 = BAN_GRAVITY_MEM_AGREE
  590. /// 104 = BAN_GAME_MEM_AGREE
  591. /// 105 = BAN_HAN_VALID
  592. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  593. /// 107 = BAN_OVER_CHARACTER_LIST
  594. /// 108 = BAN_IP_BLOCK
  595. /// 109 = BAN_INVALID_PWD_CNT
  596. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  597. /// ? = disconnected -> MsgStringTable[3]
  598. void clif_authfail_fd(int fd, int type)
  599. {
  600. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  601. return;
  602. WFIFOHEAD(fd, packet_len(0x81));
  603. WFIFOW(fd,0) = 0x81;
  604. WFIFOB(fd,2) = type;
  605. WFIFOSET(fd,packet_len(0x81));
  606. set_eof(fd);
  607. }
  608. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  609. /// 00b3 <type>.B
  610. /// type:
  611. /// 1 = disconnect, char-select
  612. /// ? = nothing
  613. void clif_charselectok(int id, uint8 ok)
  614. {
  615. struct map_session_data* sd;
  616. int fd;
  617. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  618. return;
  619. fd = sd->fd;
  620. WFIFOHEAD(fd,packet_len(0xb3));
  621. WFIFOW(fd,0) = 0xb3;
  622. WFIFOB(fd,2) = ok;
  623. WFIFOSET(fd,packet_len(0xb3));
  624. }
  625. /// Makes an item appear on the ground.
  626. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  627. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  628. void clif_dropflooritem(struct flooritem_data* fitem)
  629. {
  630. #if PACKETVER >= 20130000
  631. uint8 buf[19];
  632. uint32 header=0x84b;
  633. #else
  634. uint8 buf[17];
  635. uint32 header=0x09e;
  636. #endif
  637. int view, offset=0;
  638. nullpo_retv(fitem);
  639. if (fitem->item_data.nameid <= 0)
  640. return;
  641. WBUFW(buf, offset+0) = header;
  642. WBUFL(buf, offset+2) = fitem->bl.id;
  643. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  644. #if PACKETVER >= 20130000
  645. WBUFW(buf, offset+8) = itemtype(itemdb_type(fitem->item_data.nameid));
  646. offset +=2;
  647. #endif
  648. WBUFB(buf, offset+8) = fitem->item_data.identify;
  649. WBUFW(buf, offset+9) = fitem->bl.x;
  650. WBUFW(buf, offset+11) = fitem->bl.y;
  651. WBUFB(buf, offset+13) = fitem->subx;
  652. WBUFB(buf, offset+14) = fitem->suby;
  653. WBUFW(buf, offset+15) = fitem->item_data.amount;
  654. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  655. }
  656. /// Makes an item disappear from the ground.
  657. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  658. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  659. {
  660. unsigned char buf[16];
  661. nullpo_retv(fitem);
  662. WBUFW(buf,0) = 0xa1;
  663. WBUFL(buf,2) = fitem->bl.id;
  664. if (fd == 0) {
  665. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  666. } else {
  667. WFIFOHEAD(fd,packet_len(0xa1));
  668. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  669. WFIFOSET(fd,packet_len(0xa1));
  670. }
  671. }
  672. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  673. /// 0080 <id>.L <type>.B
  674. /// type:
  675. /// 0 = out of sight
  676. /// 1 = died
  677. /// 2 = logged out
  678. /// 3 = teleport
  679. /// 4 = trickdead
  680. void clif_clearunit_single(int id, clr_type type, int fd)
  681. {
  682. WFIFOHEAD(fd, packet_len(0x80));
  683. WFIFOW(fd,0) = 0x80;
  684. WFIFOL(fd,2) = id;
  685. WFIFOB(fd,6) = type;
  686. WFIFOSET(fd, packet_len(0x80));
  687. }
  688. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  689. /// 0080 <id>.L <type>.B
  690. /// type:
  691. /// 0 = out of sight
  692. /// 1 = died
  693. /// 2 = logged out
  694. /// 3 = teleport
  695. /// 4 = trickdead
  696. void clif_clearunit_area(struct block_list* bl, clr_type type)
  697. {
  698. unsigned char buf[8];
  699. nullpo_retv(bl);
  700. WBUFW(buf,0) = 0x80;
  701. WBUFL(buf,2) = bl->id;
  702. WBUFB(buf,6) = type;
  703. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  704. if(disguised(bl)) {
  705. WBUFL(buf,2) = -bl->id;
  706. clif_send(buf, packet_len(0x80), bl, SELF);
  707. }
  708. }
  709. /// Used to make monsters with player-sprites disappear after dying
  710. /// like normal monsters, because the client does not remove those
  711. /// automatically.
  712. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  713. {
  714. struct block_list *bl = (struct block_list *)data;
  715. clif_clearunit_area(bl, (clr_type) id);
  716. ers_free(delay_clearunit_ers,bl);
  717. return 0;
  718. }
  719. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  720. {
  721. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  722. memcpy (tbl, bl, sizeof (struct block_list));
  723. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  724. }
  725. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  726. {
  727. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK))
  728. {
  729. *rhand = *lhand = 0;
  730. return;
  731. }
  732. #if PACKETVER < 4
  733. *rhand = sd->status.weapon;
  734. *lhand = sd->status.shield;
  735. #else
  736. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  737. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  738. {
  739. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  740. if (id->view_id > 0)
  741. *rhand = id->view_id;
  742. else
  743. *rhand = id->nameid;
  744. } else
  745. *rhand = 0;
  746. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  747. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  748. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  749. {
  750. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  751. if (id->view_id > 0)
  752. *lhand = id->view_id;
  753. else
  754. *lhand = id->nameid;
  755. } else
  756. *lhand = 0;
  757. #endif
  758. }
  759. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  760. static int clif_setlevel_sub(int lv) {
  761. if( lv < battle_config.max_lv ) {
  762. ;
  763. } else if( lv < battle_config.aura_lv ) {
  764. lv = battle_config.max_lv - 1;
  765. } else {
  766. lv = battle_config.max_lv;
  767. }
  768. return lv;
  769. }
  770. static int clif_setlevel(struct block_list* bl) {
  771. int lv = status_get_lv(bl);
  772. if( battle_config.client_limit_unit_lv&bl->type )
  773. return clif_setlevel_sub(lv);
  774. switch( bl->type ) {
  775. case BL_NPC:
  776. case BL_PET:
  777. // npcs and pets do not have level
  778. return 0;
  779. }
  780. return lv;
  781. }
  782. /*==========================================
  783. * Prepares 'unit standing/spawning' packet
  784. *------------------------------------------*/
  785. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  786. {
  787. struct map_session_data* sd;
  788. struct status_change* sc = status_get_sc(bl);
  789. struct view_data* vd = status_get_viewdata(bl);
  790. unsigned char *buf = WBUFP(buffer,0);
  791. #if PACKETVER < 20091103
  792. bool type = !pcdb_checkid(vd->class_);
  793. #endif
  794. unsigned short offset = 0;
  795. #if PACKETVER >= 20091103
  796. const char *name;
  797. #endif
  798. sd = BL_CAST(BL_PC, bl);
  799. #if PACKETVER < 20091103
  800. if(type)
  801. WBUFW(buf,0) = spawn?0x7c:0x78;
  802. else
  803. #endif
  804. #if PACKETVER < 4
  805. WBUFW(buf,0) = spawn?0x79:0x78;
  806. #elif PACKETVER < 7
  807. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  808. #elif PACKETVER < 20080102
  809. WBUFW(buf,0) = spawn?0x22b:0x22a;
  810. #elif PACKETVER < 20091103
  811. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  812. #elif PACKETVER < 20101124
  813. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  814. #else
  815. WBUFW(buf,0) = spawn?0x858:0x857;
  816. #endif
  817. #if PACKETVER >= 20091103
  818. name = status_get_name(bl);
  819. #if PACKETVER < 20110111
  820. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  821. #else
  822. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  823. #endif
  824. WBUFB(buf,4) = clif_bl_type(bl);
  825. offset+=3;
  826. buf = WBUFP(buffer,offset);
  827. #elif PACKETVER >= 20071106
  828. if (type) { //Non-player packets
  829. WBUFB(buf,2) = clif_bl_type(bl);
  830. offset++;
  831. buf = WBUFP(buffer,offset);
  832. }
  833. #endif
  834. WBUFL(buf, 2) = bl->id;
  835. WBUFW(buf, 6) = status_get_speed(bl);
  836. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  837. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  838. #if PACKETVER < 20091103
  839. if (type&&spawn) { //uses an older and different packet structure
  840. WBUFW(buf,12) = (sc)? sc->option : 0;
  841. WBUFW(buf,14) = vd->hair_style;
  842. WBUFW(buf,16) = vd->weapon;
  843. WBUFW(buf,18) = vd->head_bottom;
  844. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  845. WBUFW(buf,22) = vd->shield;
  846. } else {
  847. #endif
  848. #if PACKETVER >= 20091103
  849. WBUFL(buf,12) = (sc)? sc->option : 0;
  850. offset+=2;
  851. buf = WBUFP(buffer,offset);
  852. #elif PACKETVER >= 7
  853. if (!type) {
  854. WBUFL(buf,12) = (sc)? sc->option : 0;
  855. offset+=2;
  856. buf = WBUFP(buffer,offset);
  857. } else
  858. WBUFW(buf,12) = (sc)? sc->option : 0;
  859. #else
  860. WBUFW(buf,12) = (sc)? sc->option : 0;
  861. #endif
  862. WBUFW(buf,14) = vd->class_;
  863. WBUFW(buf,16) = vd->hair_style;
  864. WBUFW(buf,18) = vd->weapon;
  865. #if PACKETVER < 4
  866. WBUFW(buf,20) = vd->head_bottom;
  867. WBUFW(buf,22) = vd->shield;
  868. #else
  869. WBUFW(buf,20) = vd->shield;
  870. WBUFW(buf,22) = vd->head_bottom;
  871. #endif
  872. #if PACKETVER < 20091103
  873. }
  874. #endif
  875. WBUFW(buf,24) = vd->head_top;
  876. WBUFW(buf,26) = vd->head_mid;
  877. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  878. { //The hell, why flags work like this?
  879. WBUFW(buf,22) = status_get_emblem_id(bl);
  880. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  881. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  882. }
  883. WBUFW(buf,28) = vd->hair_color;
  884. WBUFW(buf,30) = vd->cloth_color;
  885. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  886. #if PACKETVER < 20091103
  887. if (type&&spawn) { //End of packet 0x7c
  888. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  889. WBUFB(buf,35) = vd->sex;
  890. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  891. WBUFB(buf,39) = 0;
  892. WBUFB(buf,40) = 0;
  893. return packet_len(0x7c);
  894. }
  895. #endif
  896. #if PACKETVER >= 20110111
  897. WBUFW(buf,34) = vd->robe;
  898. offset+= 2;
  899. buf = WBUFP(buffer,offset);
  900. #endif
  901. WBUFL(buf,34) = status_get_guild_id(bl);
  902. WBUFW(buf,38) = status_get_emblem_id(bl);
  903. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  904. #if PACKETVER >= 20091103
  905. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  906. offset+=2;
  907. buf = WBUFP(buffer,offset);
  908. #elif PACKETVER >= 7
  909. if (!type) {
  910. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  911. offset+=2;
  912. buf = WBUFP(buffer,offset);
  913. } else
  914. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  915. #else
  916. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  917. #endif
  918. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  919. WBUFB(buf,45) = vd->sex;
  920. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  921. WBUFB(buf,49) = (sd)? 5 : 0;
  922. WBUFB(buf,50) = (sd)? 5 : 0;
  923. if (!spawn) {
  924. WBUFB(buf,51) = vd->dead_sit;
  925. offset++;
  926. buf = WBUFP(buffer,offset);
  927. }
  928. WBUFW(buf,51) = clif_setlevel(bl);
  929. #if PACKETVER < 20091103
  930. if (type) //End for non-player packet
  931. return packet_len(WBUFW(buffer,0));
  932. #endif
  933. #if PACKETVER >= 20080102
  934. WBUFW(buf,53) = sd?sd->user_font:0;
  935. #endif
  936. #if PACKETVER >= 20091103
  937. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  938. return WBUFW(buffer,2);
  939. #else
  940. return packet_len(WBUFW(buffer,0));
  941. #endif
  942. }
  943. /*==========================================
  944. * Prepares 'unit walking' packet
  945. *------------------------------------------*/
  946. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  947. {
  948. struct map_session_data* sd;
  949. struct status_change* sc = status_get_sc(bl);
  950. struct view_data* vd = status_get_viewdata(bl);
  951. unsigned char* buf = WBUFP(buffer,0);
  952. #if PACKETVER >= 7
  953. unsigned short offset = 0;
  954. #endif
  955. #if PACKETVER >= 20091103
  956. const char *name;
  957. #endif
  958. sd = BL_CAST(BL_PC, bl);
  959. #if PACKETVER < 4
  960. WBUFW(buf, 0) = 0x7b;
  961. #elif PACKETVER < 7
  962. WBUFW(buf, 0) = 0x1da;
  963. #elif PACKETVER < 20080102
  964. WBUFW(buf, 0) = 0x22c;
  965. #elif PACKETVER < 20091103
  966. WBUFW(buf, 0) = 0x2ec;
  967. #elif PACKETVER < 20101124
  968. WBUFW(buf, 0) = 0x7f7;
  969. #else
  970. WBUFW(buf, 0) = 0x856;
  971. #endif
  972. #if PACKETVER >= 20091103
  973. name = status_get_name(bl);
  974. #if PACKETVER < 20110111
  975. WBUFW(buf, 2) = 69+strlen(name);
  976. #else
  977. WBUFW(buf, 2) = 71+strlen(name);
  978. #endif
  979. offset+=2;
  980. buf = WBUFP(buffer,offset);
  981. #endif
  982. #if PACKETVER >= 20071106
  983. WBUFB(buf, 2) = clif_bl_type(bl);
  984. offset++;
  985. buf = WBUFP(buffer,offset);
  986. #endif
  987. WBUFL(buf, 2) = bl->id;
  988. WBUFW(buf, 6) = status_get_speed(bl);
  989. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  990. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  991. #if PACKETVER < 7
  992. WBUFW(buf,12) = (sc)? sc->option : 0;
  993. #else
  994. WBUFL(buf,12) = (sc)? sc->option : 0;
  995. offset+=2; //Shift the rest of elements by 2 bytes.
  996. buf = WBUFP(buffer,offset);
  997. #endif
  998. WBUFW(buf,14) = vd->class_;
  999. WBUFW(buf,16) = vd->hair_style;
  1000. WBUFW(buf,18) = vd->weapon;
  1001. #if PACKETVER < 4
  1002. WBUFW(buf,20) = vd->head_bottom;
  1003. WBUFL(buf,22) = gettick();
  1004. WBUFW(buf,26) = vd->shield;
  1005. #else
  1006. WBUFW(buf,20) = vd->shield;
  1007. WBUFW(buf,22) = vd->head_bottom;
  1008. WBUFL(buf,24) = gettick();
  1009. #endif
  1010. WBUFW(buf,28) = vd->head_top;
  1011. WBUFW(buf,30) = vd->head_mid;
  1012. WBUFW(buf,32) = vd->hair_color;
  1013. WBUFW(buf,34) = vd->cloth_color;
  1014. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1015. #if PACKETVER >= 20110111
  1016. WBUFW(buf,38) = vd->robe;
  1017. offset+= 2;
  1018. buf = WBUFP(buffer,offset);
  1019. #endif
  1020. WBUFL(buf,38) = status_get_guild_id(bl);
  1021. WBUFW(buf,42) = status_get_emblem_id(bl);
  1022. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1023. #if PACKETVER < 7
  1024. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1025. #else
  1026. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1027. offset+=2; //Shift the rest of elements by 2 bytes.
  1028. buf = WBUFP(buffer,offset);
  1029. #endif
  1030. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1031. WBUFB(buf,49) = vd->sex;
  1032. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1033. WBUFB(buf,56) = (sd)? 5 : 0;
  1034. WBUFB(buf,57) = (sd)? 5 : 0;
  1035. WBUFW(buf,58) = clif_setlevel(bl);
  1036. #if PACKETVER >= 20080102
  1037. WBUFW(buf,60) = sd?sd->user_font:0;
  1038. #endif
  1039. #if PACKETVER >= 20091103
  1040. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1041. return WBUFW(buffer,2);
  1042. #else
  1043. return packet_len(WBUFW(buffer,0));
  1044. #endif
  1045. }
  1046. //Modifies the buffer for disguise characters and sends it to self.
  1047. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1048. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1049. {
  1050. #if PACKETVER >= 20091103
  1051. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1052. WBUFL(buf,5)=-bl->id;
  1053. #elif PACKETVER >= 20071106
  1054. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1055. WBUFL(buf,3)=-bl->id;
  1056. #else
  1057. WBUFL(buf,2)=-bl->id;
  1058. #endif
  1059. clif_send(buf, len, bl, SELF);
  1060. }
  1061. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1062. /// 01b0 <id>.L <type>.B <value>.L
  1063. /// type:
  1064. /// unused
  1065. void clif_class_change(struct block_list *bl,int class_,int type)
  1066. {
  1067. nullpo_retv(bl);
  1068. if(!pcdb_checkid(class_))
  1069. {// player classes yield missing sprites
  1070. unsigned char buf[16];
  1071. WBUFW(buf,0)=0x1b0;
  1072. WBUFL(buf,2)=bl->id;
  1073. WBUFB(buf,6)=type;
  1074. WBUFL(buf,7)=class_;
  1075. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1076. }
  1077. }
  1078. /// Notifies the client of an object's spirits.
  1079. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1080. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1081. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1082. {
  1083. WFIFOHEAD(fd, packet_len(0x1e1));
  1084. WFIFOW(fd,0)=0x1e1;
  1085. WFIFOL(fd,2)=sd->bl.id;
  1086. WFIFOW(fd,6)=sd->spiritball;
  1087. WFIFOSET(fd, packet_len(0x1e1));
  1088. }
  1089. /*==========================================
  1090. * Kagerou/Oboro amulet spirit
  1091. *------------------------------------------*/
  1092. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1093. {
  1094. WFIFOHEAD(fd, packet_len(0x08cf));
  1095. WFIFOW(fd,0)=0x08cf;
  1096. WFIFOL(fd,2)=sd->bl.id;
  1097. WFIFOW(fd,6)=type;
  1098. WFIFOW(fd,8)=sd->talisman[type];
  1099. WFIFOSET(fd, packet_len(0x08cf));
  1100. }
  1101. /*==========================================
  1102. * Run when player changes map / refreshes
  1103. * Tells its client to display all weather settings being used by this map
  1104. *------------------------------------------*/
  1105. static void clif_weather_check(struct map_session_data *sd)
  1106. {
  1107. int16 m = sd->bl.m;
  1108. int fd = sd->fd;
  1109. if (map[m].flag.snow
  1110. || map[m].flag.clouds
  1111. || map[m].flag.fog
  1112. || map[m].flag.fireworks
  1113. || map[m].flag.sakura
  1114. || map[m].flag.leaves
  1115. || map[m].flag.clouds2)
  1116. {
  1117. if (map[m].flag.snow)
  1118. clif_specialeffect_single(&sd->bl, 162, fd);
  1119. if (map[m].flag.clouds)
  1120. clif_specialeffect_single(&sd->bl, 233, fd);
  1121. if (map[m].flag.clouds2)
  1122. clif_specialeffect_single(&sd->bl, 516, fd);
  1123. if (map[m].flag.fog)
  1124. clif_specialeffect_single(&sd->bl, 515, fd);
  1125. if (map[m].flag.fireworks) {
  1126. clif_specialeffect_single(&sd->bl, 297, fd);
  1127. clif_specialeffect_single(&sd->bl, 299, fd);
  1128. clif_specialeffect_single(&sd->bl, 301, fd);
  1129. }
  1130. if (map[m].flag.sakura)
  1131. clif_specialeffect_single(&sd->bl, 163, fd);
  1132. if (map[m].flag.leaves)
  1133. clif_specialeffect_single(&sd->bl, 333, fd);
  1134. }
  1135. }
  1136. /**
  1137. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1138. **/
  1139. void clif_weather(int16 m)
  1140. {
  1141. struct s_mapiterator* iter;
  1142. struct map_session_data *sd=NULL;
  1143. iter = mapit_getallusers();
  1144. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1145. {
  1146. if( sd->bl.m == m )
  1147. clif_weather_check(sd);
  1148. }
  1149. mapit_free(iter);
  1150. }
  1151. /**
  1152. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1153. **/
  1154. int clif_spawn(struct block_list *bl)
  1155. {
  1156. unsigned char buf[128];
  1157. struct view_data *vd;
  1158. int len;
  1159. vd = status_get_viewdata(bl);
  1160. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1161. return 0;
  1162. /**
  1163. * Hide NPC from maya purple card.
  1164. **/
  1165. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1166. return 0;
  1167. len = clif_set_unit_idle(bl, buf,true);
  1168. clif_send(buf, len, bl, AREA_WOS);
  1169. if (disguised(bl))
  1170. clif_setdisguise(bl, buf, len);
  1171. if (vd->cloth_color)
  1172. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1173. switch (bl->type)
  1174. {
  1175. case BL_PC:
  1176. {
  1177. TBL_PC *sd = ((TBL_PC*)bl);
  1178. int i;
  1179. if (sd->spiritball > 0)
  1180. clif_spiritball(&sd->bl);
  1181. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1182. clif_specialeffect(bl,423,AREA);
  1183. else if(sd->state.size==SZ_MEDIUM)
  1184. clif_specialeffect(bl,421,AREA);
  1185. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1186. clif_sendbgemblem_area(sd);
  1187. if( sd->sc.option&OPTION_MOUNTING ) {
  1188. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1189. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1190. }
  1191. for(i = 1; i < 5; i++){
  1192. if( sd->talisman[i] > 0 )
  1193. clif_talisman(sd, i);
  1194. }
  1195. #ifdef NEW_CARTS
  1196. if( sd->sc.data[SC_PUSH_CART] )
  1197. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1198. #endif
  1199. if (sd->status.robe)
  1200. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1201. if( sd->sc.data[SC_CAMOUFLAGE] )
  1202. clif_status_load(bl,SI_CAMOUFLAGE,1);
  1203. if( sd->sc.data[SC_MONSTER_TRANSFORM] )
  1204. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,sd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  1205. if( sd->sc.data[SC_MOONSTAR] )
  1206. clif_status_load(bl,SI_MOONSTAR,1);
  1207. if( sd->sc.data[SC_SUPER_STAR] )
  1208. clif_status_load(bl,SI_SUPER_STAR,1);
  1209. }
  1210. break;
  1211. case BL_MOB:
  1212. {
  1213. TBL_MOB *md = ((TBL_MOB*)bl);
  1214. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1215. clif_specialeffect(&md->bl,423,AREA);
  1216. else if(md->special_state.size==SZ_MEDIUM)
  1217. clif_specialeffect(&md->bl,421,AREA);
  1218. }
  1219. break;
  1220. case BL_NPC:
  1221. {
  1222. TBL_NPC *nd = ((TBL_NPC*)bl);
  1223. if( nd->size == SZ_BIG )
  1224. clif_specialeffect(&nd->bl,423,AREA);
  1225. else if( nd->size == SZ_MEDIUM )
  1226. clif_specialeffect(&nd->bl,421,AREA);
  1227. }
  1228. break;
  1229. case BL_PET:
  1230. if (vd->head_bottom)
  1231. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1232. break;
  1233. }
  1234. return 0;
  1235. }
  1236. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1237. /// 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
  1238. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1239. {
  1240. struct status_data *status;
  1241. unsigned char buf[128];
  1242. int htype;
  1243. nullpo_retv(hd);
  1244. status = &hd->battle_status;
  1245. htype = hom_class2type(hd->homunculus.class_);
  1246. memset(buf,0,packet_len(0x22e));
  1247. WBUFW(buf,0)=0x22e;
  1248. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1249. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1250. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1251. WBUFW(buf,27)=hd->homunculus.level;
  1252. WBUFW(buf,29)=hd->homunculus.hunger;
  1253. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1254. WBUFW(buf,33)=0; // equip id
  1255. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1256. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1257. WBUFW(buf,39)=status->hit;
  1258. if (battle_config.hom_setting&0x10)
  1259. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1260. else
  1261. WBUFW(buf,41)=status->cri/10;
  1262. WBUFW(buf,43)=status->def + status->vit ;
  1263. WBUFW(buf,45)=status->mdef;
  1264. WBUFW(buf,47)=status->flee;
  1265. WBUFW(buf,49)=(flag)?0:status->amotion;
  1266. if (status->max_hp > INT16_MAX) {
  1267. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1268. WBUFW(buf,53) = 100;
  1269. } else {
  1270. WBUFW(buf,51)=status->hp;
  1271. WBUFW(buf,53)=status->max_hp;
  1272. }
  1273. if (status->max_sp > INT16_MAX) {
  1274. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1275. WBUFW(buf,57) = 100;
  1276. } else {
  1277. WBUFW(buf,55)=status->sp;
  1278. WBUFW(buf,57)=status->max_sp;
  1279. }
  1280. WBUFL(buf,59)=hd->homunculus.exp;
  1281. WBUFL(buf,63)=hd->exp_next;
  1282. switch( htype ) {
  1283. case HT_REG:
  1284. case HT_EVO:
  1285. if( hd->homunculus.level >= battle_config.hom_max_level )
  1286. WBUFL(buf,63)=0;
  1287. break;
  1288. case HT_S:
  1289. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1290. WBUFL(buf,63)=0;
  1291. break;
  1292. }
  1293. WBUFW(buf,67)=hd->homunculus.skillpts;
  1294. WBUFW(buf,69)=status_get_range(&hd->bl);
  1295. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1296. }
  1297. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1298. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1299. /// type:
  1300. /// unused
  1301. /// state:
  1302. /// 0 = pre-init
  1303. /// 1 = intimacy
  1304. /// 2 = hunger
  1305. /// 3 = accessory?
  1306. /// ? = ignored
  1307. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1308. { //[orn]
  1309. int fd = sd->fd;
  1310. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1311. merc_hom_calc_skilltree(sd->hd, 0);
  1312. WFIFOHEAD(fd, packet_len(0x230));
  1313. WFIFOW(fd,0)=0x230;
  1314. WFIFOB(fd,2)=0;
  1315. WFIFOB(fd,3)=state;
  1316. WFIFOL(fd,4)=sd->hd->bl.id;
  1317. WFIFOL(fd,8)=param;
  1318. WFIFOSET(fd,packet_len(0x230));
  1319. }
  1320. int clif_homskillinfoblock(struct map_session_data *sd)
  1321. { //[orn]
  1322. struct homun_data *hd;
  1323. int fd = sd->fd;
  1324. int i,j,len=4,id;
  1325. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1326. hd = sd->hd;
  1327. if ( !hd )
  1328. return 0 ;
  1329. WFIFOW(fd,0)=0x235;
  1330. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1331. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1332. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1333. j = id - HM_SKILLBASE;
  1334. WFIFOW(fd,len ) = id;
  1335. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1336. WFIFOW(fd,len+4) = 0;
  1337. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1338. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1339. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1340. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1341. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1342. len+=37;
  1343. }
  1344. }
  1345. WFIFOW(fd,2)=len;
  1346. WFIFOSET(fd,len);
  1347. return 0;
  1348. }
  1349. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1350. { //[orn]
  1351. struct homun_data *hd;
  1352. int fd, idx;
  1353. nullpo_retv(sd);
  1354. idx = skill_id - HM_SKILLBASE;
  1355. fd=sd->fd;
  1356. hd=sd->hd;
  1357. WFIFOHEAD(fd, packet_len(0x239));
  1358. WFIFOW(fd,0) = 0x239;
  1359. WFIFOW(fd,2) = skill_id;
  1360. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1361. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1362. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1363. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1364. WFIFOSET(fd,packet_len(0x239));
  1365. }
  1366. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1367. {
  1368. int fd=sd->fd;
  1369. WFIFOHEAD(fd,packet_len(0x22f));
  1370. WFIFOW(fd,0)=0x22f;
  1371. WFIFOB(fd,2)=fail;
  1372. WFIFOW(fd,3)=foodid;
  1373. WFIFOSET(fd,packet_len(0x22f));
  1374. return 0;
  1375. }
  1376. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1377. /// 0087 <walk start time>.L <walk data>.6B
  1378. void clif_walkok(struct map_session_data *sd)
  1379. {
  1380. int fd=sd->fd;
  1381. WFIFOHEAD(fd, packet_len(0x87));
  1382. WFIFOW(fd,0)=0x87;
  1383. WFIFOL(fd,2)=gettick();
  1384. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1385. WFIFOSET(fd,packet_len(0x87));
  1386. }
  1387. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1388. {
  1389. uint8 buf[128];
  1390. int len;
  1391. struct status_change *sc = NULL;
  1392. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1393. clif_ally_only = true;
  1394. len = clif_set_unit_walking(bl,ud,buf);
  1395. clif_send(buf,len,bl,AREA_WOS);
  1396. if (disguised(bl))
  1397. clif_setdisguise(bl, buf, len);
  1398. if(vd->cloth_color)
  1399. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1400. switch(bl->type) {
  1401. case BL_PC:
  1402. {
  1403. TBL_PC *sd = ((TBL_PC*)bl);
  1404. // clif_movepc(sd);
  1405. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1406. clif_specialeffect(&sd->bl,423,AREA);
  1407. else if(sd->state.size==SZ_MEDIUM)
  1408. clif_specialeffect(&sd->bl,421,AREA);
  1409. }
  1410. break;
  1411. case BL_MOB:
  1412. {
  1413. TBL_MOB *md = ((TBL_MOB*)bl);
  1414. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1415. clif_specialeffect(&md->bl,423,AREA);
  1416. else if(md->special_state.size==SZ_MEDIUM)
  1417. clif_specialeffect(&md->bl,421,AREA);
  1418. }
  1419. break;
  1420. case BL_PET:
  1421. if(vd->head_bottom) // needed to display pet equip properly
  1422. clif_pet_equip_area((TBL_PET*)bl);
  1423. break;
  1424. }
  1425. clif_ally_only = false;
  1426. }
  1427. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1428. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1429. /// Note: unit must not be self
  1430. void clif_move(struct unit_data *ud)
  1431. {
  1432. unsigned char buf[16];
  1433. struct view_data* vd;
  1434. struct block_list* bl = ud->bl;
  1435. struct status_change *sc = NULL;
  1436. vd = status_get_viewdata(bl);
  1437. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1438. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1439. /**
  1440. * Hide NPC from maya purple card.
  1441. **/
  1442. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1443. return;
  1444. if (ud->state.speed_changed) {
  1445. // Since we don't know how to update the speed of other objects,
  1446. // use the old walk packet to update the data.
  1447. ud->state.speed_changed = 0;
  1448. clif_move2(bl, vd, ud);
  1449. return;
  1450. }
  1451. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1452. clif_ally_only = true;
  1453. WBUFW(buf,0)=0x86;
  1454. WBUFL(buf,2)=bl->id;
  1455. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1456. WBUFL(buf,12)=gettick();
  1457. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1458. if (disguised(bl)) {
  1459. WBUFL(buf,2)=-bl->id;
  1460. clif_send(buf, packet_len(0x86), bl, SELF);
  1461. }
  1462. clif_ally_only = false;
  1463. }
  1464. /*==========================================
  1465. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1466. *------------------------------------------*/
  1467. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1468. {
  1469. struct map_session_data *sd = NULL;
  1470. //Remove player from map server
  1471. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1472. map_quit(sd);
  1473. return 0;
  1474. }
  1475. /*==========================================
  1476. *
  1477. *------------------------------------------*/
  1478. void clif_quitsave(int fd,struct map_session_data *sd) {
  1479. if (!battle_config.prevent_logout ||
  1480. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1481. map_quit(sd);
  1482. else if (sd->fd) {
  1483. //Disassociate session from player (session is deleted after this function was called)
  1484. //And set a timer to make him quit later.
  1485. session[sd->fd]->session_data = NULL;
  1486. sd->fd = 0;
  1487. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1488. }
  1489. }
  1490. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1491. /// 0091 <map name>.16B <x>.W <y>.W
  1492. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1493. {
  1494. int fd;
  1495. nullpo_retv(sd);
  1496. fd = sd->fd;
  1497. WFIFOHEAD(fd,packet_len(0x91));
  1498. WFIFOW(fd,0) = 0x91;
  1499. if(map[m].instance_id) { // Instance map check to send client source map name so we don't crash player
  1500. struct instance_data *im = &instance_data[map[m].instance_id];
  1501. int i;
  1502. if(!im) // This shouldn't happen but if it does give them the map we intended to give
  1503. mapindex_getmapname_ext(map[m].name, (char*)WFIFOP(fd,2));
  1504. for(i = 0; i < MAX_MAP_PER_INSTANCE; i++) // Loop to find the src map we want
  1505. if(im->map[i].m == m) {
  1506. mapindex_getmapname_ext(map[im->map[i].src_m].name, (char*)WFIFOP(fd,2));
  1507. break;
  1508. }
  1509. } else
  1510. mapindex_getmapname_ext(map[m].name, (char*)WFIFOP(fd,2));
  1511. WFIFOW(fd,18) = x;
  1512. WFIFOW(fd,20) = y;
  1513. WFIFOSET(fd,packet_len(0x91));
  1514. }
  1515. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1516. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1517. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1518. {
  1519. int fd;
  1520. nullpo_retv(sd);
  1521. fd = sd->fd;
  1522. WFIFOHEAD(fd,packet_len(0x92));
  1523. WFIFOW(fd,0) = 0x92;
  1524. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1525. WFIFOW(fd,18) = x;
  1526. WFIFOW(fd,20) = y;
  1527. WFIFOL(fd,22) = htonl(ip);
  1528. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1529. WFIFOSET(fd,packet_len(0x92));
  1530. }
  1531. void clif_blown(struct block_list *bl) //FIXME: This needs a better behaviour than just sending 2 position fixes
  1532. {
  1533. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1534. clif_fixpos(bl);
  1535. clif_slide(bl, bl->x, bl->y);
  1536. }
  1537. /// Visually moves(slides) a character to x,y. If the target cell
  1538. /// isn't walkable, the char doesn't move at all. If the char is
  1539. /// sitting it will stand up (ZC_STOPMOVE).
  1540. /// 0088 <id>.L <x>.W <y>.W
  1541. void clif_fixpos(struct block_list *bl)
  1542. {
  1543. unsigned char buf[10];
  1544. nullpo_retv(bl);
  1545. WBUFW(buf,0) = 0x88;
  1546. WBUFL(buf,2) = bl->id;
  1547. WBUFW(buf,6) = bl->x;
  1548. WBUFW(buf,8) = bl->y;
  1549. clif_send(buf, packet_len(0x88), bl, AREA);
  1550. if( disguised(bl) ) {
  1551. WBUFL(buf,2) = -bl->id;
  1552. clif_send(buf, packet_len(0x88), bl, SELF);
  1553. }
  1554. }
  1555. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1556. /// 00c4 <shop id>.L
  1557. void clif_npcbuysell(struct map_session_data* sd, int id)
  1558. {
  1559. int fd;
  1560. nullpo_retv(sd);
  1561. fd=sd->fd;
  1562. WFIFOHEAD(fd, packet_len(0xc4));
  1563. WFIFOW(fd,0)=0xc4;
  1564. WFIFOL(fd,2)=id;
  1565. WFIFOSET(fd,packet_len(0xc4));
  1566. }
  1567. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1568. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1569. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1570. {
  1571. int fd,i,c;
  1572. bool discount;
  1573. nullpo_retv(sd);
  1574. nullpo_retv(nd);
  1575. fd = sd->fd;
  1576. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1577. WFIFOW(fd,0) = 0xc6;
  1578. c = 0;
  1579. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1580. for( i = 0; i < nd->u.shop.count; i++ )
  1581. {
  1582. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1583. int val = nd->u.shop.shop_item[i].value;
  1584. if( id == NULL )
  1585. continue;
  1586. WFIFOL(fd, 4+c*11) = val;
  1587. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1588. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1589. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1590. c++;
  1591. }
  1592. WFIFOW(fd,2) = 4 + c*11;
  1593. WFIFOSET(fd,WFIFOW(fd,2));
  1594. }
  1595. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1596. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1597. void clif_selllist(struct map_session_data *sd)
  1598. {
  1599. int fd,i,c=0,val;
  1600. nullpo_retv(sd);
  1601. fd=sd->fd;
  1602. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1603. WFIFOW(fd,0)=0xc7;
  1604. for( i = 0; i < MAX_INVENTORY; i++ )
  1605. {
  1606. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1607. {
  1608. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1609. continue;
  1610. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1611. continue; // Cannot Sell Rental Items or Account Bounded Items
  1612. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1613. continue; // Don't allow sale of bound items
  1614. val=sd->inventory_data[i]->value_sell;
  1615. if( val < 0 )
  1616. continue;
  1617. WFIFOW(fd,4+c*10)=i+2;
  1618. WFIFOL(fd,6+c*10)=val;
  1619. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1620. c++;
  1621. }
  1622. }
  1623. WFIFOW(fd,2)=c*10+4;
  1624. WFIFOSET(fd,WFIFOW(fd,2));
  1625. }
  1626. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1627. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1628. /// Client behavior (dialog window):
  1629. /// - disable mouse targeting
  1630. /// - open the dialog window
  1631. /// - set npcid of dialog window (0 by default)
  1632. /// - if set to clear on next mes, clear contents
  1633. /// - append this text
  1634. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1635. {
  1636. int fd = sd->fd;
  1637. int slen = strlen(mes) + 9;
  1638. WFIFOHEAD(fd, slen);
  1639. WFIFOW(fd,0)=0xb4;
  1640. WFIFOW(fd,2)=slen;
  1641. WFIFOL(fd,4)=npcid;
  1642. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1643. WFIFOSET(fd,WFIFOW(fd,2));
  1644. }
  1645. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1646. /// 00b5 <npc id>.L
  1647. /// Client behavior (dialog window):
  1648. /// - disable mouse targeting
  1649. /// - open the dialog window
  1650. /// - add 'next' button
  1651. /// When 'next' is pressed:
  1652. /// - 00B9 <npcid of dialog window>.L
  1653. /// - set to clear on next mes
  1654. /// - remove 'next' button
  1655. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1656. {
  1657. int fd;
  1658. nullpo_retv(sd);
  1659. fd=sd->fd;
  1660. WFIFOHEAD(fd, packet_len(0xb5));
  1661. WFIFOW(fd,0)=0xb5;
  1662. WFIFOL(fd,2)=npcid;
  1663. WFIFOSET(fd,packet_len(0xb5));
  1664. }
  1665. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1666. /// 00b6 <npc id>.L
  1667. /// Client behavior:
  1668. /// - if dialog window is open:
  1669. /// - remove 'next' button
  1670. /// - add 'close' button
  1671. /// - else:
  1672. /// - enable mouse targeting
  1673. /// - close the dialog window
  1674. /// - close the menu window
  1675. /// When 'close' is pressed:
  1676. /// - enable mouse targeting
  1677. /// - close the dialog window
  1678. /// - close the menu window
  1679. /// - 0146 <npcid of dialog window>.L
  1680. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1681. {
  1682. int fd;
  1683. nullpo_retv(sd);
  1684. fd=sd->fd;
  1685. WFIFOHEAD(fd, packet_len(0xb6));
  1686. WFIFOW(fd,0)=0xb6;
  1687. WFIFOL(fd,2)=npcid;
  1688. WFIFOSET(fd,packet_len(0xb6));
  1689. }
  1690. /*==========================================
  1691. *
  1692. *------------------------------------------*/
  1693. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1694. unsigned char *buf;
  1695. int fd = sd->fd;
  1696. sd->state.using_fake_npc = 1;
  1697. WFIFOHEAD(fd, packet_len(0x78));
  1698. buf = WFIFOP(fd,0);
  1699. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1700. WBUFW(buf,0)=0x78;
  1701. #if PACKETVER >= 20071106
  1702. WBUFB(buf,2) = 0; // object type
  1703. buf = WFIFOP(fd,1);
  1704. #endif
  1705. WBUFL(buf,2)=npcid;
  1706. WBUFW(buf,14)=111;
  1707. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1708. WBUFB(buf,49)=5;
  1709. WBUFB(buf,50)=5;
  1710. WFIFOSET(fd, packet_len(0x78));
  1711. }
  1712. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1713. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1714. /// Client behavior:
  1715. /// - disable mouse targeting
  1716. /// - close the menu window
  1717. /// - open the menu window
  1718. /// - add options to the menu (separated in the text by ":")
  1719. /// - set npcid of menu window
  1720. /// - if dialog window is open:
  1721. /// - remove 'next' button
  1722. /// When 'ok' is pressed:
  1723. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1724. /// - close the menu window
  1725. /// When 'cancel' is pressed:
  1726. /// - 00B8 <npcid of menu window>.L <-1>.B
  1727. /// - enable mouse targeting
  1728. /// - close a bunch of windows...
  1729. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1730. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1731. /// TODO investigate behavior of other windows [FlavioJS]
  1732. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1733. {
  1734. int fd = sd->fd;
  1735. int slen = strlen(mes) + 9;
  1736. struct block_list *bl = NULL;
  1737. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1738. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1739. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1740. clif_sendfakenpc(sd, npcid);
  1741. WFIFOHEAD(fd, slen);
  1742. WFIFOW(fd,0)=0xb7;
  1743. WFIFOW(fd,2)=slen;
  1744. WFIFOL(fd,4)=npcid;
  1745. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1746. WFIFOSET(fd,WFIFOW(fd,2));
  1747. }
  1748. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1749. /// 0142 <npc id>.L
  1750. /// Client behavior (inputnum window):
  1751. /// - if npcid exists in the client:
  1752. /// - open the inputnum window
  1753. /// - set npcid of inputnum window
  1754. /// When 'ok' is pressed:
  1755. /// - if inputnum window has text:
  1756. /// - if npcid exists in the client:
  1757. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1758. /// - close inputnum window
  1759. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1760. {
  1761. int fd;
  1762. struct block_list *bl = NULL;
  1763. nullpo_retv(sd);
  1764. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1765. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1766. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1767. clif_sendfakenpc(sd, npcid);
  1768. fd=sd->fd;
  1769. WFIFOHEAD(fd, packet_len(0x142));
  1770. WFIFOW(fd,0)=0x142;
  1771. WFIFOL(fd,2)=npcid;
  1772. WFIFOSET(fd,packet_len(0x142));
  1773. }
  1774. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1775. /// 01d4 <npc id>.L
  1776. /// Client behavior (inputstr window):
  1777. /// - if npcid is 0 or npcid exists in the client:
  1778. /// - open the inputstr window
  1779. /// - set npcid of inputstr window
  1780. /// When 'ok' is pressed:
  1781. /// - if inputstr window has text and isn't an insult(manner.txt):
  1782. /// - if npcid is 0 or npcid exists in the client:
  1783. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1784. /// - close inputstr window
  1785. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1786. {
  1787. int fd;
  1788. struct block_list *bl = NULL;
  1789. nullpo_retv(sd);
  1790. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1791. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1792. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1793. clif_sendfakenpc(sd, npcid);
  1794. fd=sd->fd;
  1795. WFIFOHEAD(fd, packet_len(0x1d4));
  1796. WFIFOW(fd,0)=0x1d4;
  1797. WFIFOL(fd,2)=npcid;
  1798. WFIFOSET(fd,packet_len(0x1d4));
  1799. }
  1800. /// Marks a position on client's minimap (ZC_COMPASS).
  1801. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1802. /// npc id:
  1803. /// is ignored in the client
  1804. /// type:
  1805. /// 0 = display mark for 15 seconds
  1806. /// 1 = display mark until dead or teleported
  1807. /// 2 = remove mark
  1808. /// color:
  1809. /// 0x00RRGGBB
  1810. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1811. {
  1812. int fd;
  1813. nullpo_retv(sd);
  1814. fd=sd->fd;
  1815. WFIFOHEAD(fd, packet_len(0x144));
  1816. WFIFOW(fd,0)=0x144;
  1817. WFIFOL(fd,2)=npc_id;
  1818. WFIFOL(fd,6)=type;
  1819. WFIFOL(fd,10)=x;
  1820. WFIFOL(fd,14)=y;
  1821. WFIFOB(fd,18)=id;
  1822. WFIFOL(fd,19)=color;
  1823. WFIFOSET(fd,packet_len(0x144));
  1824. }
  1825. /// Displays an illustration image.
  1826. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1827. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1828. /// type:
  1829. /// 0 = bottom left corner
  1830. /// 1 = bottom middle
  1831. /// 2 = bottom right corner
  1832. /// 3 = middle of screen, inside a movable window
  1833. /// 4 = middle of screen, movable with a close button, chrome-less
  1834. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1835. {
  1836. int fd;
  1837. nullpo_retv(sd);
  1838. fd=sd->fd;
  1839. WFIFOHEAD(fd, packet_len(0x1b3));
  1840. WFIFOW(fd,0)=0x1b3;
  1841. strncpy((char*)WFIFOP(fd,2),image,64);
  1842. WFIFOB(fd,66)=type;
  1843. WFIFOSET(fd,packet_len(0x1b3));
  1844. }
  1845. /*==========================================
  1846. * Fills in card data from the given item and into the buffer. [Skotlex]
  1847. *------------------------------------------*/
  1848. static void clif_addcards(unsigned char* buf, struct item* item)
  1849. {
  1850. int i=0,j;
  1851. if( item == NULL ) { //Blank data
  1852. WBUFW(buf,0) = 0;
  1853. WBUFW(buf,2) = 0;
  1854. WBUFW(buf,4) = 0;
  1855. WBUFW(buf,6) = 0;
  1856. return;
  1857. }
  1858. if( item->card[0] == CARD0_PET ) { //pet eggs
  1859. WBUFW(buf,0) = 0;
  1860. WBUFW(buf,2) = 0;
  1861. WBUFW(buf,4) = 0;
  1862. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1863. return;
  1864. }
  1865. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1866. WBUFW(buf,0) = item->card[0];
  1867. WBUFW(buf,2) = item->card[1];
  1868. WBUFW(buf,4) = item->card[2];
  1869. WBUFW(buf,6) = item->card[3];
  1870. return;
  1871. }
  1872. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1873. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1874. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1875. //Normal items.
  1876. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1877. WBUFW(buf,0) = j;
  1878. else
  1879. WBUFW(buf,0) = item->card[i];
  1880. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1881. WBUFW(buf,2) = j;
  1882. else
  1883. WBUFW(buf,2) = item->card[i];
  1884. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1885. WBUFW(buf,4) = j;
  1886. else
  1887. WBUFW(buf,4) = item->card[i];
  1888. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1889. WBUFW(buf,6) = j;
  1890. else
  1891. WBUFW(buf,6) = item->card[i];
  1892. }
  1893. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1894. /// 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)
  1895. /// 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)
  1896. /// 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)
  1897. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  1898. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1899. {
  1900. int fd, header, offs=0;
  1901. #if PACKETVER < 20061218
  1902. header = 0xa0;
  1903. #elif PACKETVER < 20071002
  1904. header = 0x29a;
  1905. #elif PACKETVER < 20120925
  1906. header = 0x2d4;
  1907. #else
  1908. header = 0x990;
  1909. #endif
  1910. nullpo_retv(sd);
  1911. fd = sd->fd;
  1912. if( !session_isActive(fd) ) //Sasuke-
  1913. return;
  1914. WFIFOHEAD(fd,packet_len(header));
  1915. if( fail )
  1916. {
  1917. WFIFOW(fd,offs+0)=header;
  1918. WFIFOW(fd,offs+2)=n+2;
  1919. WFIFOW(fd,offs+4)=amount;
  1920. WFIFOW(fd,offs+6)=0;
  1921. WFIFOB(fd,offs+8)=0;
  1922. WFIFOB(fd,offs+9)=0;
  1923. WFIFOB(fd,offs+10)=0;
  1924. WFIFOW(fd,offs+11)=0;
  1925. WFIFOW(fd,offs+13)=0;
  1926. WFIFOW(fd,offs+15)=0;
  1927. WFIFOW(fd,offs+17)=0;
  1928. #if PACKETVER < 20120925
  1929. WFIFOW(fd,offs+19)=0;
  1930. #else
  1931. WFIFOL(fd,offs+19)=0;
  1932. offs += 2;
  1933. #endif
  1934. WFIFOB(fd,offs+21)=0;
  1935. WFIFOB(fd,offs+22)=fail;
  1936. #if PACKETVER >= 20061218
  1937. WFIFOL(fd,offs+23)=0;
  1938. #endif
  1939. #if PACKETVER >= 20071002
  1940. WFIFOW(fd,offs+27)=0; // HireExpireDate
  1941. #endif
  1942. }
  1943. else
  1944. {
  1945. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1946. return;
  1947. WFIFOW(fd,offs+0)=header;
  1948. WFIFOW(fd,offs+2)=n+2;
  1949. WFIFOW(fd,offs+4)=amount;
  1950. if (sd->inventory_data[n]->view_id > 0)
  1951. WFIFOW(fd,offs+6)=sd->inventory_data[n]->view_id;
  1952. else
  1953. WFIFOW(fd,offs+6)=sd->status.inventory[n].nameid;
  1954. WFIFOB(fd,offs+8)=sd->status.inventory[n].identify;
  1955. WFIFOB(fd,offs+9)=sd->status.inventory[n].attribute;
  1956. WFIFOB(fd,offs+10)=sd->status.inventory[n].refine;
  1957. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  1958. #if PACKETVER < 20120925
  1959. WFIFOW(fd,offs+19)=pc_equippoint(sd,n);
  1960. #else
  1961. WFIFOL(fd,offs+19)=pc_equippoint(sd,n);
  1962. offs += 2;
  1963. #endif
  1964. WFIFOB(fd,offs+21)=itemtype(sd->inventory_data[n]->type);
  1965. WFIFOB(fd,offs+22)=fail;
  1966. #if PACKETVER >= 20061218
  1967. WFIFOL(fd,offs+23)=sd->status.inventory[n].expire_time;
  1968. #endif
  1969. #if PACKETVER >= 20071002
  1970. WFIFOW(fd,offs+27)=sd->status.inventory[n].bound ? 2 : 0;
  1971. #endif
  1972. }
  1973. WFIFOSET(fd,packet_len(header));
  1974. }
  1975. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1976. /// 00af <index>.W <amount>.W
  1977. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1978. {
  1979. int fd;
  1980. nullpo_retv(sd);
  1981. fd=sd->fd;
  1982. WFIFOHEAD(fd, packet_len(0xaf));
  1983. WFIFOW(fd,0)=0xaf;
  1984. WFIFOW(fd,2)=n+2;
  1985. WFIFOW(fd,4)=amount;
  1986. WFIFOSET(fd,packet_len(0xaf));
  1987. }
  1988. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1989. /// 07fa <delete type>.W <index>.W <amount>.W
  1990. /// delete type:
  1991. /// 0 = Normal
  1992. /// 1 = Item used for a skill
  1993. /// 2 = Refine failed
  1994. /// 3 = Material changed
  1995. /// 4 = Moved to storage
  1996. /// 5 = Moved to cart
  1997. /// 6 = Item sold
  1998. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1999. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2000. {
  2001. #if PACKETVER < 20091117
  2002. clif_dropitem(sd,n,amount);
  2003. #else
  2004. int fd;
  2005. nullpo_retv(sd);
  2006. fd=sd->fd;
  2007. WFIFOHEAD(fd, packet_len(0x7fa));
  2008. WFIFOW(fd,0)=0x7fa;
  2009. WFIFOW(fd,2)=reason;
  2010. WFIFOW(fd,4)=n+2;
  2011. WFIFOW(fd,6)=amount;
  2012. WFIFOSET(fd,packet_len(0x7fa));
  2013. #endif
  2014. }
  2015. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2016. char normal = (equip < 0);
  2017. WBUFW(buf,n)=idx; //index
  2018. WBUFW(buf,n+2)= (id->view_id > 0)?id->view_id:i->nameid;
  2019. WBUFB(buf,n+4)=itemtype(id->type);
  2020. if(!normal){ //equip 31B
  2021. WBUFL(buf,n+5)= equip; //location
  2022. WBUFL(buf,n+9)= i->equip; //wear state
  2023. WBUFB(buf,n+13)= i->refine; //refine lvl
  2024. clif_addcards(WBUFP(buf, n+14), i); //EQUIPSLOTINFO 8B
  2025. WBUFL(buf,n+22) = i->expire_time;
  2026. WBUFW(buf,n+26)= 0; //bindOnEquipType
  2027. WBUFW(buf,n+28)= (id->equip&EQP_VISIBLE)?id->look:0;
  2028. //V5_ITEM_flag
  2029. WBUFB(buf,n+30)=i->identify; //0x1 IsIdentified
  2030. WBUFB(buf,n+30)|=(i->attribute)?0x2:0; //0x2 IsDamaged
  2031. WBUFB(buf,n+30)|= (i->favorite)?0x4:0; //0x4 PlaceETCTab
  2032. }
  2033. else { //normal 24B
  2034. WBUFW(buf,n+5)=i->amount;
  2035. WBUFL(buf,n+7)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2036. clif_addcards(WBUFP(buf, n+11), i); //EQUIPSLOTINFO 8B
  2037. WBUFL(buf,n+19) = i->expire_time;
  2038. //V5_ITEM_flag
  2039. WBUFB(buf,n+23)=i->identify; //0x1 IsIdentified
  2040. WBUFB(buf,n+23)|= (i->favorite)?0x2:0; //0x4,0x2 PlaceETCTab
  2041. }
  2042. }
  2043. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2044. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2045. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2046. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2047. #if PACKETVER >= 20120925
  2048. clif_item_sub_v5(buf, n, idx, i, id, equip);
  2049. #else
  2050. WBUFW(buf,n)=idx; //index
  2051. WBUFW(buf,n+2)=(id->view_id > 0)?id->view_id:i->nameid; //itid
  2052. WBUFB(buf,n+4)=itemtype(id->type);
  2053. WBUFB(buf,n+5)=i->identify;
  2054. if (equip >= 0) { //Equippable item 28.B
  2055. WBUFW(buf,n+6)=equip;
  2056. WBUFW(buf,n+8)=i->equip;
  2057. WBUFB(buf,n+10)=i->attribute;
  2058. WBUFB(buf,n+11)=i->refine;
  2059. clif_addcards(WBUFP(buf, n+12), i); //8B
  2060. #if PACKETVER >= 20071002
  2061. WBUFL(buf,n+20)=i->expire_time;
  2062. WBUFW(buf,n+24)=i->bound ? 2 : 0;
  2063. #endif
  2064. #if PACKETVER >= 20100629
  2065. WBUFW(buf,n+26)= (id->equip&EQP_VISIBLE)?id->look:0;
  2066. #endif
  2067. } else { //Stackable item. 22.B
  2068. WBUFW(buf,n+6)=i->amount;
  2069. WBUFW(buf,n+8)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0;
  2070. clif_addcards(WBUFP(buf, n+10), i); //8B
  2071. #if PACKETVER >= 20071002
  2072. WBUFL(buf,n+18)=i->expire_time;
  2073. #endif
  2074. }
  2075. #endif
  2076. }
  2077. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2078. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2079. void clif_inventorylist(struct map_session_data *sd) {
  2080. int i,n,ne,arrow=-1;
  2081. unsigned char *buf;
  2082. unsigned char *bufe;
  2083. #if PACKETVER < 5
  2084. const int s = 10; //Entry size
  2085. #elif PACKETVER < 20080102
  2086. const int s = 18;
  2087. #elif PACKETVER < 20120925
  2088. const int s = 22;
  2089. #else
  2090. const int s = 24;
  2091. #endif
  2092. #if PACKETVER < 20071002
  2093. const int se = 20;
  2094. #elif PACKETVER < 20100629
  2095. const int se = 26;
  2096. #elif PACKETVER < 20120925
  2097. const int se = 28;
  2098. #else
  2099. const int se = 31;
  2100. #endif
  2101. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2102. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2103. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2104. {
  2105. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2106. continue;
  2107. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2108. { //Non-stackable (Equippable)
  2109. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2110. ne++;
  2111. }
  2112. else { //Stackable.
  2113. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2114. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2115. arrow=i;
  2116. n++;
  2117. }
  2118. }
  2119. if( n )
  2120. {
  2121. #if PACKETVER < 5
  2122. WBUFW(buf,0)=0xa3;
  2123. #elif PACKETVER < 20080102
  2124. WBUFW(buf,0)=0x1ee;
  2125. #elif PACKETVER < 20120925
  2126. WBUFW(buf,0)=0x2e8;
  2127. #else
  2128. WBUFW(buf,0)=0x991;
  2129. #endif
  2130. WBUFW(buf,2)=4+n*s;
  2131. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2132. }
  2133. if( arrow >= 0 )
  2134. clif_arrowequip(sd,arrow);
  2135. if( ne ) {
  2136. #if PACKETVER < 20071002
  2137. WBUFW(bufe,0)=0xa4;
  2138. #elif PACKETVER < 20120925
  2139. WBUFW(bufe,0)=0x2d0;
  2140. #else
  2141. WBUFW(bufe,0)=0x992;
  2142. #endif
  2143. WBUFW(bufe,2)=4+ne*se;
  2144. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2145. }
  2146. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2147. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2148. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2149. continue;
  2150. if ( sd->status.inventory[i].favorite )
  2151. clif_favorite_item(sd, i);
  2152. }
  2153. #endif
  2154. if( buf ) aFree(buf);
  2155. if( bufe ) aFree(bufe);
  2156. }
  2157. //Required when items break/get-repaired. Only sends equippable item list.
  2158. void clif_equiplist(struct map_session_data *sd)
  2159. {
  2160. int i,n,fd = sd->fd;
  2161. unsigned char *buf;
  2162. #if PACKETVER < 20071002
  2163. const int cmd = 20;
  2164. #elif PACKETVER < 20100629
  2165. const int cmd = 26;
  2166. #elif PACKETVER < 20120925
  2167. const int cmd = 28;
  2168. #else
  2169. const int cmd = 31;
  2170. #endif
  2171. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2172. buf = WFIFOP(fd,0);
  2173. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2174. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2175. continue;
  2176. if(itemdb_isstackable2(sd->inventory_data[i]))
  2177. continue;
  2178. //Equippable
  2179. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2180. n++;
  2181. }
  2182. if (n) {
  2183. #if PACKETVER < 20071002
  2184. WBUFW(buf,0)=0xa4;
  2185. #elif PACKETVER < 20120925
  2186. WBUFW(buf,0)=0x2d0;
  2187. #else
  2188. WBUFW(buf,0)=0x992;
  2189. #endif
  2190. WBUFW(buf,2)=4+n*cmd;
  2191. WFIFOSET(fd,WFIFOW(fd,2));
  2192. }
  2193. }
  2194. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2195. {
  2196. static const int client_buf = 0x5000; // Max buffer to send
  2197. struct item_data *id;
  2198. int i,n,ne,nn;
  2199. unsigned char *buf;
  2200. unsigned char *bufe;
  2201. unsigned char *bufn;
  2202. #if PACKETVER < 5
  2203. const int s = 10; //Entry size.normal item
  2204. const int sidx=4; //start itemlist idx
  2205. #elif PACKETVER < 20080102
  2206. const int s = 18;
  2207. const int sidx=4;
  2208. #elif PACKETVER < 20120925
  2209. const int s = 22;
  2210. const int sidx=4;
  2211. #else
  2212. const int s = 24;
  2213. const int sidx = 4+24;
  2214. #endif
  2215. #if PACKETVER < 20071002
  2216. const int se = 20; //entry size equip
  2217. const int sidxe = 4; //start itemlist idx
  2218. #elif PACKETVER < 20100629
  2219. const int se = 26;
  2220. const int sidxe = 4;
  2221. #elif PACKETVER < 20120925
  2222. const int se = 28;
  2223. const int sidxe = 4;
  2224. #else
  2225. const int se = 31;
  2226. const int sidxe = 4+24;
  2227. #endif
  2228. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2229. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2230. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2231. {
  2232. if( items[i].nameid <= 0 )
  2233. continue;
  2234. id = itemdb_search(items[i].nameid);
  2235. if( !itemdb_isstackable2(id) ) { //Equippable
  2236. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2237. ne++;
  2238. }
  2239. else { //Stackable
  2240. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2241. n++;
  2242. }
  2243. }
  2244. for (i = 0; i < n;) // Loop through non-equipable items
  2245. {
  2246. nn = n - i < (client_buf - 4)/s ? n - i : (client_buf - 4)/s; // Split up non-equipable items
  2247. bufn = buf + i*s; // Update buffer to new index range
  2248. i += nn;
  2249. #if PACKETVER < 5
  2250. WBUFW(bufn,0)=0xa5;
  2251. #elif PACKETVER < 20080102
  2252. WBUFW(bufn,0)=0x1f0;
  2253. #elif PACKETVER < 20120925
  2254. WBUFW(bufn,0)=0x2ea;
  2255. #else
  2256. WBUFW(bufn,0)=0x995;
  2257. memset((char*)WBUFP(buf,4),0,24); //storename
  2258. #endif
  2259. WBUFW(bufn,2)=4+nn*s;
  2260. clif_send(bufn, WBUFW(bufn,2), &sd->bl, SELF);
  2261. }
  2262. for (i = 0; i < ne;) // Loop through equipable items
  2263. {
  2264. nn = ne - i < (client_buf - 4)/se ? ne - i : (client_buf - 4)/se; // Split up equipable items
  2265. bufn = bufe + i*se; // Update buffer to new index range
  2266. i += nn;
  2267. #if PACKETVER < 20071002
  2268. WBUFW(bufn,0)=0xa6;
  2269. #elif PACKETVER < 20120925
  2270. WBUFW(bufn,0)=0x2d1;
  2271. #else
  2272. WBUFW(bufn,0)=0x996;
  2273. memset((char*)WBUFP(bufn,4),0,24); //storename
  2274. #endif
  2275. WBUFW(bufn,2)=4+nn*se;
  2276. clif_send(bufn, WBUFW(bufn,2), &sd->bl, SELF);
  2277. }
  2278. if( buf ) aFree(buf);
  2279. if( bufe ) aFree(bufe);
  2280. }
  2281. void clif_cartlist(struct map_session_data *sd)
  2282. {
  2283. struct item_data *id;
  2284. int i,n,ne;
  2285. unsigned char *buf;
  2286. unsigned char *bufe;
  2287. #if PACKETVER < 5
  2288. const int s = 10; //Entry size.
  2289. #elif PACKETVER < 20080102
  2290. const int s = 18;
  2291. #elif PACKETVER < 20120925
  2292. const int s = 22;
  2293. #else
  2294. const int s = 24;
  2295. #endif
  2296. #if PACKETVER < 20071002
  2297. const int cmd = 20;
  2298. #elif PACKETVER < 20100629
  2299. const int cmd = 26;
  2300. #elif PACKETVER < 20120925
  2301. const int cmd = 28;
  2302. #else
  2303. const int cmd = 31;
  2304. #endif
  2305. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2306. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2307. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2308. {
  2309. if( sd->status.cart[i].nameid <= 0 )
  2310. continue;
  2311. id = itemdb_search(sd->status.cart[i].nameid);
  2312. if( !itemdb_isstackable2(id) ) { //Equippable
  2313. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2314. ne++;
  2315. }
  2316. else { //Stackable
  2317. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2318. n++;
  2319. }
  2320. }
  2321. if( n )
  2322. {
  2323. #if PACKETVER < 5
  2324. WBUFW(buf,0)=0x123;
  2325. #elif PACKETVER < 20080102
  2326. WBUFW(buf,0)=0x1ef;
  2327. #elif PACKETVER < 20120925
  2328. WBUFW(buf,0)=0x2e9;
  2329. #else
  2330. WBUFW(buf,0)=0x993;
  2331. #endif
  2332. WBUFW(buf,2)=4+n*s;
  2333. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2334. }
  2335. if( ne )
  2336. {
  2337. #if PACKETVER < 20071002
  2338. WBUFW(bufe,0)=0x122;
  2339. #elif PACKETVER < 20120925
  2340. WBUFW(bufe,0)=0x2d2;
  2341. #else
  2342. WBUFW(bufe,0)=0x994;
  2343. #endif
  2344. WBUFW(bufe,2)=4+ne*cmd;
  2345. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2346. }
  2347. if( buf ) aFree(buf);
  2348. if( bufe ) aFree(bufe);
  2349. }
  2350. /// Removes cart (ZC_CARTOFF).
  2351. /// 012b
  2352. /// Client behaviour:
  2353. /// Closes the cart storage and removes all it's items from memory.
  2354. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2355. void clif_clearcart(int fd)
  2356. {
  2357. WFIFOHEAD(fd, packet_len(0x12b));
  2358. WFIFOW(fd,0) = 0x12b;
  2359. WFIFOSET(fd, packet_len(0x12b));
  2360. }
  2361. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2362. /// 01eb <account id>.L <x>.W <y>.W
  2363. void clif_guild_xy(struct map_session_data *sd)
  2364. {
  2365. unsigned char buf[10];
  2366. nullpo_retv(sd);
  2367. WBUFW(buf,0)=0x1eb;
  2368. WBUFL(buf,2)=sd->status.account_id;
  2369. WBUFW(buf,6)=sd->bl.x;
  2370. WBUFW(buf,8)=sd->bl.y;
  2371. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2372. }
  2373. /*==========================================
  2374. * Sends x/y dot to a single fd. [Skotlex]
  2375. *------------------------------------------*/
  2376. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2377. {
  2378. if( sd->bg_id )
  2379. return;
  2380. WFIFOHEAD(fd,packet_len(0x1eb));
  2381. WFIFOW(fd,0)=0x1eb;
  2382. WFIFOL(fd,2)=sd->status.account_id;
  2383. WFIFOW(fd,6)=sd->bl.x;
  2384. WFIFOW(fd,8)=sd->bl.y;
  2385. WFIFOSET(fd,packet_len(0x1eb));
  2386. }
  2387. // Guild XY locators [Valaris]
  2388. void clif_guild_xy_remove(struct map_session_data *sd)
  2389. {
  2390. unsigned char buf[10];
  2391. nullpo_retv(sd);
  2392. WBUFW(buf,0)=0x1eb;
  2393. WBUFL(buf,2)=sd->status.account_id;
  2394. WBUFW(buf,6)=-1;
  2395. WBUFW(buf,8)=-1;
  2396. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2397. }
  2398. /*==========================================
  2399. *
  2400. *------------------------------------------*/
  2401. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2402. {
  2403. struct map_session_data *sd, *tsd;
  2404. #if PACKETVER < 20100126
  2405. const int cmd = 0x106;
  2406. #else
  2407. const int cmd = 0x80e;
  2408. #endif
  2409. sd = va_arg(ap, struct map_session_data *);
  2410. tsd = (TBL_PC *)bl;
  2411. nullpo_ret(sd);
  2412. nullpo_ret(tsd);
  2413. if( !tsd->fd || tsd == sd )
  2414. return 0;
  2415. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2416. return 0;
  2417. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2418. WFIFOW(tsd->fd,0) = cmd;
  2419. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2420. #if PACKETVER < 20100126
  2421. if( sd->battle_status.max_hp > INT16_MAX )
  2422. { //To correctly display the %hp bar. [Skotlex]
  2423. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2424. WFIFOW(tsd->fd,8) = 100;
  2425. } else {
  2426. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2427. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2428. }
  2429. #else
  2430. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2431. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2432. #endif
  2433. WFIFOSET(tsd->fd,packet_len(cmd));
  2434. return 0;
  2435. }
  2436. /*==========================================
  2437. * Server tells all players that are allowed to view HP bars
  2438. * and are nearby 'sd' that 'sd' hp bar was updated.
  2439. *------------------------------------------*/
  2440. static int clif_hpmeter(struct map_session_data *sd)
  2441. {
  2442. nullpo_ret(sd);
  2443. 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);
  2444. return 0;
  2445. }
  2446. /// Notifies client of a character parameter change.
  2447. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2448. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2449. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2450. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2451. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2452. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2453. /// TODO: Extract individual packets.
  2454. /// FIXME: Packet lengths from packet_len(cmd)
  2455. void clif_updatestatus(struct map_session_data *sd,int type)
  2456. {
  2457. int fd,len=8;
  2458. nullpo_retv(sd);
  2459. fd=sd->fd;
  2460. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2461. return;
  2462. WFIFOHEAD(fd, 14);
  2463. WFIFOW(fd,0)=0xb0;
  2464. WFIFOW(fd,2)=type;
  2465. switch(type){
  2466. // 00b0
  2467. case SP_WEIGHT:
  2468. pc_updateweightstatus(sd);
  2469. WFIFOHEAD(fd,14);
  2470. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2471. WFIFOW(fd,2)=type;
  2472. WFIFOL(fd,4)=sd->weight;
  2473. break;
  2474. case SP_MAXWEIGHT:
  2475. WFIFOL(fd,4)=sd->max_weight;
  2476. break;
  2477. case SP_SPEED:
  2478. WFIFOL(fd,4)=sd->battle_status.speed;
  2479. break;
  2480. case SP_BASELEVEL:
  2481. WFIFOL(fd,4)=sd->status.base_level;
  2482. break;
  2483. case SP_JOBLEVEL:
  2484. WFIFOL(fd,4)=sd->status.job_level;
  2485. break;
  2486. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2487. WFIFOL(fd,4)=sd->status.karma;
  2488. break;
  2489. case SP_MANNER:
  2490. WFIFOL(fd,4)=sd->status.manner;
  2491. break;
  2492. case SP_STATUSPOINT:
  2493. WFIFOL(fd,4)=sd->status.status_point;
  2494. break;
  2495. case SP_SKILLPOINT:
  2496. WFIFOL(fd,4)=sd->status.skill_point;
  2497. break;
  2498. case SP_HIT:
  2499. WFIFOL(fd,4)=sd->battle_status.hit;
  2500. break;
  2501. case SP_FLEE1:
  2502. WFIFOL(fd,4)=sd->battle_status.flee;
  2503. break;
  2504. case SP_FLEE2:
  2505. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2506. break;
  2507. case SP_MAXHP:
  2508. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2509. break;
  2510. case SP_MAXSP:
  2511. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2512. break;
  2513. case SP_HP:
  2514. WFIFOL(fd,4)=sd->battle_status.hp;
  2515. // TODO: Won't these overwrite the current packet?
  2516. if( map[sd->bl.m].hpmeter_visible )
  2517. clif_hpmeter(sd);
  2518. if( !battle_config.party_hp_mode && sd->status.party_id )
  2519. clif_party_hp(sd);
  2520. if( sd->bg_id )
  2521. clif_bg_hp(sd);
  2522. break;
  2523. case SP_SP:
  2524. WFIFOL(fd,4)=sd->battle_status.sp;
  2525. break;
  2526. case SP_ASPD:
  2527. WFIFOL(fd,4)=sd->battle_status.amotion;
  2528. break;
  2529. case SP_ATK1:
  2530. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2531. break;
  2532. case SP_DEF1:
  2533. WFIFOL(fd,4)=pc_leftside_def(sd);
  2534. break;
  2535. case SP_MDEF1:
  2536. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2537. break;
  2538. case SP_ATK2:
  2539. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2540. break;
  2541. case SP_DEF2:
  2542. WFIFOL(fd,4)=pc_rightside_def(sd);
  2543. break;
  2544. case SP_MDEF2: {
  2545. //negative check (in case you have something like Berserk active)
  2546. int mdef2 = pc_rightside_mdef(sd);
  2547. WFIFOL(fd,4)=
  2548. #ifndef RENEWAL
  2549. ( mdef2 < 0 ) ? 0 :
  2550. #endif
  2551. mdef2;
  2552. }
  2553. break;
  2554. case SP_CRITICAL:
  2555. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2556. break;
  2557. case SP_MATK1:
  2558. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2559. break;
  2560. case SP_MATK2:
  2561. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2562. break;
  2563. case SP_ZENY:
  2564. WFIFOW(fd,0)=0xb1;
  2565. WFIFOL(fd,4)=sd->status.zeny;
  2566. break;
  2567. case SP_BASEEXP:
  2568. WFIFOW(fd,0)=0xb1;
  2569. WFIFOL(fd,4)=sd->status.base_exp;
  2570. break;
  2571. case SP_JOBEXP:
  2572. WFIFOW(fd,0)=0xb1;
  2573. WFIFOL(fd,4)=sd->status.job_exp;
  2574. break;
  2575. case SP_NEXTBASEEXP:
  2576. WFIFOW(fd,0)=0xb1;
  2577. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2578. break;
  2579. case SP_NEXTJOBEXP:
  2580. WFIFOW(fd,0)=0xb1;
  2581. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2582. break;
  2583. /**
  2584. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2585. **/
  2586. case SP_USTR:
  2587. case SP_UAGI:
  2588. case SP_UVIT:
  2589. case SP_UINT:
  2590. case SP_UDEX:
  2591. case SP_ULUK:
  2592. WFIFOW(fd,0)=0xbe;
  2593. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2594. len=5;
  2595. break;
  2596. /**
  2597. * Tells the client how far it is allowed to attack (weapon range)
  2598. **/
  2599. case SP_ATTACKRANGE:
  2600. WFIFOW(fd,0)=0x13a;
  2601. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2602. len=4;
  2603. break;
  2604. case SP_STR:
  2605. WFIFOW(fd,0)=0x141;
  2606. WFIFOL(fd,2)=type;
  2607. WFIFOL(fd,6)=sd->status.str;
  2608. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2609. len=14;
  2610. break;
  2611. case SP_AGI:
  2612. WFIFOW(fd,0)=0x141;
  2613. WFIFOL(fd,2)=type;
  2614. WFIFOL(fd,6)=sd->status.agi;
  2615. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2616. len=14;
  2617. break;
  2618. case SP_VIT:
  2619. WFIFOW(fd,0)=0x141;
  2620. WFIFOL(fd,2)=type;
  2621. WFIFOL(fd,6)=sd->status.vit;
  2622. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2623. len=14;
  2624. break;
  2625. case SP_INT:
  2626. WFIFOW(fd,0)=0x141;
  2627. WFIFOL(fd,2)=type;
  2628. WFIFOL(fd,6)=sd->status.int_;
  2629. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2630. len=14;
  2631. break;
  2632. case SP_DEX:
  2633. WFIFOW(fd,0)=0x141;
  2634. WFIFOL(fd,2)=type;
  2635. WFIFOL(fd,6)=sd->status.dex;
  2636. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2637. len=14;
  2638. break;
  2639. case SP_LUK:
  2640. WFIFOW(fd,0)=0x141;
  2641. WFIFOL(fd,2)=type;
  2642. WFIFOL(fd,6)=sd->status.luk;
  2643. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2644. len=14;
  2645. break;
  2646. case SP_CARTINFO:
  2647. WFIFOW(fd,0)=0x121;
  2648. WFIFOW(fd,2)=sd->cart_num;
  2649. WFIFOW(fd,4)=MAX_CART;
  2650. WFIFOL(fd,6)=sd->cart_weight;
  2651. WFIFOL(fd,10)=sd->cart_weight_max;
  2652. len=14;
  2653. break;
  2654. default:
  2655. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2656. return;
  2657. }
  2658. WFIFOSET(fd,len);
  2659. }
  2660. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2661. /// 01ab <account id>.L <var id>.W <value>.L
  2662. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2663. {
  2664. unsigned char buf[12];
  2665. nullpo_retv(sd);
  2666. WBUFW(buf,0)=0x1ab;
  2667. WBUFL(buf,2)=sd->bl.id;
  2668. WBUFW(buf,6)=type;
  2669. switch(type)
  2670. {
  2671. case SP_MANNER:
  2672. WBUFL(buf,8)=val;
  2673. break;
  2674. default:
  2675. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2676. return;
  2677. }
  2678. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2679. }
  2680. /// Updates sprite/style properties of an object.
  2681. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2682. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2683. void clif_changelook(struct block_list *bl,int type,int val)
  2684. {
  2685. unsigned char buf[16];
  2686. struct map_session_data* sd;
  2687. struct status_change* sc;
  2688. struct view_data* vd;
  2689. enum send_target target = AREA;
  2690. nullpo_retv(bl);
  2691. sd = BL_CAST(BL_PC, bl);
  2692. sc = status_get_sc(bl);
  2693. vd = status_get_viewdata(bl);
  2694. //nullpo_ret(vd);
  2695. if( vd ) //temp hack to let Warp Portal change appearance
  2696. switch(type)
  2697. {
  2698. case LOOK_WEAPON:
  2699. if (sd)
  2700. {
  2701. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2702. val = vd->weapon;
  2703. }
  2704. else vd->weapon = val;
  2705. break;
  2706. case LOOK_SHIELD:
  2707. if (sd)
  2708. {
  2709. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2710. val = vd->shield;
  2711. }
  2712. else vd->shield = val;
  2713. break;
  2714. case LOOK_BASE:
  2715. vd->class_ = val;
  2716. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER || vd->class_ == JOB_HANBOK)
  2717. vd->weapon = vd->shield = 0;
  2718. if (vd->cloth_color && (
  2719. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2720. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2721. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2722. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette)
  2723. ))
  2724. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2725. break;
  2726. case LOOK_HAIR:
  2727. vd->hair_style = val;
  2728. break;
  2729. case LOOK_HEAD_BOTTOM:
  2730. vd->head_bottom = val;
  2731. break;
  2732. case LOOK_HEAD_TOP:
  2733. vd->head_top = val;
  2734. break;
  2735. case LOOK_HEAD_MID:
  2736. vd->head_mid = val;
  2737. break;
  2738. case LOOK_HAIR_COLOR:
  2739. vd->hair_color = val;
  2740. break;
  2741. case LOOK_CLOTHES_COLOR:
  2742. if (val && (
  2743. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2744. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2745. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2746. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette)
  2747. ))
  2748. val = 0;
  2749. vd->cloth_color = val;
  2750. break;
  2751. case LOOK_SHOES:
  2752. #if PACKETVER > 3
  2753. if (sd) {
  2754. int n;
  2755. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2756. if(sd->inventory_data[n]->view_id > 0)
  2757. val = sd->inventory_data[n]->view_id;
  2758. else
  2759. val = sd->status.inventory[n].nameid;
  2760. } else
  2761. val = 0;
  2762. }
  2763. #endif
  2764. //Shoes? No packet uses this....
  2765. break;
  2766. case LOOK_BODY:
  2767. // unknown purpose
  2768. break;
  2769. case LOOK_ROBE:
  2770. #if PACKETVER < 20110111
  2771. return;
  2772. #else
  2773. vd->robe = val;
  2774. #endif
  2775. break;
  2776. }
  2777. // prevent leaking the presence of GM-hidden objects
  2778. if( sc && sc->option&OPTION_INVISIBLE )
  2779. target = SELF;
  2780. #if PACKETVER < 4
  2781. WBUFW(buf,0)=0xc3;
  2782. WBUFL(buf,2)=bl->id;
  2783. WBUFB(buf,6)=type;
  2784. WBUFB(buf,7)=val;
  2785. clif_send(buf,packet_len(0xc3),bl,target);
  2786. #else
  2787. WBUFW(buf,0)=0x1d7;
  2788. WBUFL(buf,2)=bl->id;
  2789. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2790. WBUFB(buf,6)=LOOK_WEAPON;
  2791. WBUFW(buf,7)=vd->weapon;
  2792. WBUFW(buf,9)=vd->shield;
  2793. } else {
  2794. WBUFB(buf,6)=type;
  2795. WBUFL(buf,7)=val;
  2796. }
  2797. clif_send(buf,packet_len(0x1d7),bl,target);
  2798. #endif
  2799. }
  2800. //Sends a change-base-look packet required for traps as they are triggered.
  2801. void clif_changetraplook(struct block_list *bl,int val)
  2802. {
  2803. unsigned char buf[32];
  2804. #if PACKETVER < 4
  2805. WBUFW(buf,0)=0xc3;
  2806. WBUFL(buf,2)=bl->id;
  2807. WBUFB(buf,6)=LOOK_BASE;
  2808. WBUFB(buf,7)=val;
  2809. clif_send(buf,packet_len(0xc3),bl,AREA);
  2810. #else
  2811. WBUFW(buf,0)=0x1d7;
  2812. WBUFL(buf,2)=bl->id;
  2813. WBUFB(buf,6)=LOOK_BASE;
  2814. WBUFW(buf,7)=val;
  2815. WBUFW(buf,9)=0;
  2816. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2817. #endif
  2818. }
  2819. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2820. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2821. {
  2822. unsigned char buf[32];
  2823. #if PACKETVER < 4
  2824. WBUFW(buf,0)=0xc3;
  2825. WBUFL(buf,2)=id;
  2826. WBUFB(buf,6)=type;
  2827. WBUFB(buf,7)=val;
  2828. clif_send(buf,packet_len(0xc3),bl,target);
  2829. #else
  2830. WBUFW(buf,0)=0x1d7;
  2831. WBUFL(buf,2)=id;
  2832. WBUFB(buf,6)=type;
  2833. WBUFW(buf,7)=val;
  2834. WBUFW(buf,9)=0;
  2835. clif_send(buf,packet_len(0x1d7),bl,target);
  2836. #endif
  2837. }
  2838. /// Character status (ZC_STATUS).
  2839. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2840. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2841. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2842. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2843. void clif_initialstatus(struct map_session_data *sd) {
  2844. int fd, mdef2;
  2845. unsigned char *buf;
  2846. nullpo_retv(sd);
  2847. fd=sd->fd;
  2848. WFIFOHEAD(fd,packet_len(0xbd));
  2849. buf=WFIFOP(fd,0);
  2850. WBUFW(buf,0)=0xbd;
  2851. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2852. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2853. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2854. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2855. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2856. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2857. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2858. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2859. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2860. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2861. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2862. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2863. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2864. WBUFW(buf,16) = pc_leftside_atk(sd);
  2865. WBUFW(buf,18) = pc_rightside_atk(sd);
  2866. WBUFW(buf,20) = pc_rightside_matk(sd);
  2867. WBUFW(buf,22) = pc_leftside_matk(sd);
  2868. WBUFW(buf,24) = pc_leftside_def(sd);
  2869. WBUFW(buf,26) = pc_rightside_def(sd);
  2870. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2871. mdef2 = pc_rightside_mdef(sd);
  2872. WBUFW(buf,30) =
  2873. #ifndef RENEWAL
  2874. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2875. #endif
  2876. mdef2;
  2877. WBUFW(buf,32) = sd->battle_status.hit;
  2878. WBUFW(buf,34) = sd->battle_status.flee;
  2879. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2880. WBUFW(buf,38) = sd->battle_status.cri/10;
  2881. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2882. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2883. WFIFOSET(fd,packet_len(0xbd));
  2884. clif_updatestatus(sd,SP_STR);
  2885. clif_updatestatus(sd,SP_AGI);
  2886. clif_updatestatus(sd,SP_VIT);
  2887. clif_updatestatus(sd,SP_INT);
  2888. clif_updatestatus(sd,SP_DEX);
  2889. clif_updatestatus(sd,SP_LUK);
  2890. clif_updatestatus(sd,SP_ATTACKRANGE);
  2891. clif_updatestatus(sd,SP_ASPD);
  2892. }
  2893. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2894. /// 013c <index>.W
  2895. void clif_arrowequip(struct map_session_data *sd,int val)
  2896. {
  2897. int fd;
  2898. nullpo_retv(sd);
  2899. pc_stop_attack(sd); // [Valaris]
  2900. #if PACKETVER >= 20121128
  2901. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2902. #endif
  2903. fd=sd->fd;
  2904. WFIFOHEAD(fd, packet_len(0x013c));
  2905. WFIFOW(fd,0)=0x013c;
  2906. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2907. WFIFOSET(fd,packet_len(0x013c));
  2908. }
  2909. /// Ammunition action message (ZC_ACTION_FAILURE).
  2910. /// 013b <type>.W
  2911. /// type:
  2912. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2913. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2914. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2915. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2916. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2917. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2918. void clif_arrow_fail(struct map_session_data *sd,int type)
  2919. {
  2920. int fd;
  2921. nullpo_retv(sd);
  2922. fd=sd->fd;
  2923. WFIFOHEAD(fd, packet_len(0x013b));
  2924. WFIFOW(fd,0)=0x013b;
  2925. WFIFOW(fd,2)=type;
  2926. WFIFOSET(fd,packet_len(0x013b));
  2927. }
  2928. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2929. /// 01ad <packet len>.W { <name id>.W }*
  2930. void clif_arrow_create_list(struct map_session_data *sd)
  2931. {
  2932. int i, c, j;
  2933. int fd;
  2934. nullpo_retv(sd);
  2935. fd = sd->fd;
  2936. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2937. WFIFOW(fd,0) = 0x1ad;
  2938. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2939. if (skill_arrow_db[i].nameid > 0 &&
  2940. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2941. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2942. {
  2943. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2944. WFIFOW(fd,c*2+4) = j;
  2945. else
  2946. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2947. c++;
  2948. }
  2949. }
  2950. WFIFOW(fd,2) = c*2+4;
  2951. WFIFOSET(fd, WFIFOW(fd,2));
  2952. if (c > 0) {
  2953. sd->menuskill_id = AC_MAKINGARROW;
  2954. sd->menuskill_val = c;
  2955. }
  2956. }
  2957. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2958. /// 00bc <status id>.W <result>.B <value>.B
  2959. /// status id:
  2960. /// SP_STR ~ SP_LUK
  2961. /// result:
  2962. /// 0 = failure
  2963. /// 1 = success
  2964. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2965. {
  2966. int fd;
  2967. nullpo_retv(sd);
  2968. fd=sd->fd;
  2969. WFIFOHEAD(fd,packet_len(0xbc));
  2970. WFIFOW(fd,0)=0xbc;
  2971. WFIFOW(fd,2)=type;
  2972. WFIFOB(fd,4)=ok;
  2973. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2974. WFIFOSET(fd,packet_len(0xbc));
  2975. }
  2976. /// Notifies the client about the result of a request to equip an item.
  2977. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  2978. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2979. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  2980. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  2981. /// @ok: //inversed forv2 v5
  2982. /// 0 = failure
  2983. /// 1 = success
  2984. /// 2 = failure due to low level
  2985. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2986. {
  2987. int fd,header,offs=0,success;
  2988. #if PACKETVER < 20110824
  2989. header = 0xaa;
  2990. success = (ok==1);
  2991. #elif PACKETVER < 20120925
  2992. header = 0x8d0;
  2993. success = ok ? 0:1;
  2994. #else
  2995. header = 0x999;
  2996. success = ok ? 0:1;
  2997. #endif
  2998. nullpo_retv(sd);
  2999. fd=sd->fd;
  3000. WFIFOHEAD(fd,packet_len(header));
  3001. WFIFOW(fd,offs+0)=header;
  3002. WFIFOW(fd,offs+2)=n+2;
  3003. #if PACKETVER >= 20120925
  3004. WFIFOL(fd,offs+4)=pos;
  3005. offs+=2;
  3006. #else
  3007. WFIFOW(fd,offs+4)=(int)pos;
  3008. #endif
  3009. #if PACKETVER < 20100629
  3010. WFIFOB(fd,offs+6)=success;
  3011. #else
  3012. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3013. WFIFOW(fd,offs+6)=sd->inventory_data[n]->look;
  3014. else
  3015. WFIFOW(fd,offs+6)=0;
  3016. WFIFOB(fd,offs+8)=success;
  3017. #endif
  3018. WFIFOSET(fd,packet_len(header));
  3019. }
  3020. /// Notifies the client about the result of a request to take off an item.
  3021. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3022. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3023. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3024. /// @ok : //inversed for v2 v5
  3025. /// 0 = failure
  3026. /// 1 = success
  3027. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3028. {
  3029. int fd,header,offs=0;
  3030. #if PACKETVER >= 20130000
  3031. header = 0x99a;
  3032. ok = ok ? 0:1;
  3033. #elif PACKETVER >= 20110824
  3034. header = 0x8d1;
  3035. ok = ok ? 0:1;
  3036. #else
  3037. header = 0xac;
  3038. #endif
  3039. nullpo_retv(sd);
  3040. fd=sd->fd;
  3041. WFIFOHEAD(fd,packet_len(header));
  3042. WFIFOW(fd,offs+0)=header;
  3043. WFIFOW(fd,offs+2)=n+2;
  3044. #if PACKETVER >= 20130000
  3045. WFIFOL(fd,offs+4)=pos;
  3046. offs +=2;
  3047. #else
  3048. WFIFOW(fd,offs+4)=pos;
  3049. #endif
  3050. WFIFOB(fd,offs+6)=ok;
  3051. WFIFOSET(fd,packet_len(header));
  3052. }
  3053. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3054. /// 019b <id>.L <effect id>.L
  3055. /// effect id:
  3056. /// 0 = base level up
  3057. /// 1 = job level up
  3058. /// 2 = refine failure
  3059. /// 3 = refine success
  3060. /// 4 = game over
  3061. /// 5 = pharmacy success
  3062. /// 6 = pharmacy failure
  3063. /// 7 = base level up (super novice)
  3064. /// 8 = job level up (super novice)
  3065. /// 9 = base level up (taekwon)
  3066. void clif_misceffect(struct block_list* bl,int type)
  3067. {
  3068. unsigned char buf[32];
  3069. nullpo_retv(bl);
  3070. WBUFW(buf,0) = 0x19b;
  3071. WBUFL(buf,2) = bl->id;
  3072. WBUFL(buf,6) = type;
  3073. clif_send(buf,packet_len(0x19b),bl,AREA);
  3074. }
  3075. /// Notifies clients in the area of a state change.
  3076. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3077. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3078. void clif_changeoption(struct block_list* bl)
  3079. {
  3080. unsigned char buf[32];
  3081. struct status_change *sc;
  3082. struct map_session_data* sd;
  3083. nullpo_retv(bl);
  3084. sc = status_get_sc(bl);
  3085. if (!sc) return; //How can an option change if there's no sc?
  3086. sd = BL_CAST(BL_PC, bl);
  3087. #if PACKETVER >= 7
  3088. WBUFW(buf,0) = 0x229;
  3089. WBUFL(buf,2) = bl->id;
  3090. WBUFW(buf,6) = sc->opt1;
  3091. WBUFW(buf,8) = sc->opt2;
  3092. WBUFL(buf,10) = sc->option;
  3093. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3094. if(disguised(bl)) {
  3095. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3096. WBUFL(buf,2) = -bl->id;
  3097. clif_send(buf,packet_len(0x229),bl,SELF);
  3098. WBUFL(buf,2) = bl->id;
  3099. WBUFL(buf,10) = OPTION_INVISIBLE;
  3100. clif_send(buf,packet_len(0x229),bl,SELF);
  3101. } else
  3102. clif_send(buf,packet_len(0x229),bl,AREA);
  3103. #else
  3104. WBUFW(buf,0) = 0x119;
  3105. WBUFL(buf,2) = bl->id;
  3106. WBUFW(buf,6) = sc->opt1;
  3107. WBUFW(buf,8) = sc->opt2;
  3108. WBUFW(buf,10) = sc->option;
  3109. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3110. if(disguised(bl)) {
  3111. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3112. WBUFL(buf,2) = -bl->id;
  3113. clif_send(buf,packet_len(0x119),bl,SELF);
  3114. WBUFL(buf,2) = bl->id;
  3115. WBUFW(buf,10) = OPTION_INVISIBLE;
  3116. clif_send(buf,packet_len(0x119),bl,SELF);
  3117. } else
  3118. clif_send(buf,packet_len(0x119),bl,AREA);
  3119. #endif
  3120. }
  3121. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3122. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3123. void clif_changeoption2(struct block_list* bl)
  3124. {
  3125. unsigned char buf[20];
  3126. struct status_change *sc;
  3127. sc = status_get_sc(bl);
  3128. if (!sc) return; //How can an option change if there's no sc?
  3129. WBUFW(buf,0) = 0x28a;
  3130. WBUFL(buf,2) = bl->id;
  3131. WBUFL(buf,6) = sc->option;
  3132. WBUFL(buf,10) = clif_setlevel(bl);
  3133. WBUFL(buf,14) = sc->opt3;
  3134. if(disguised(bl)) {
  3135. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3136. WBUFL(buf,2) = -bl->id;
  3137. clif_send(buf,packet_len(0x28a),bl,SELF);
  3138. WBUFL(buf,2) = bl->id;
  3139. WBUFL(buf,6) = OPTION_INVISIBLE;
  3140. clif_send(buf,packet_len(0x28a),bl,SELF);
  3141. } else
  3142. clif_send(buf,packet_len(0x28a),bl,AREA);
  3143. }
  3144. /// Notifies the client about the result of an item use request.
  3145. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3146. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3147. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3148. {
  3149. nullpo_retv(sd);
  3150. if(!ok) {
  3151. int fd=sd->fd;
  3152. WFIFOHEAD(fd,packet_len(0xa8));
  3153. WFIFOW(fd,0)=0xa8;
  3154. WFIFOW(fd,2)=index+2;
  3155. WFIFOW(fd,4)=amount;
  3156. WFIFOB(fd,6)=ok;
  3157. WFIFOSET(fd,packet_len(0xa8));
  3158. }
  3159. else {
  3160. #if PACKETVER < 3
  3161. int fd=sd->fd;
  3162. WFIFOHEAD(fd,packet_len(0xa8));
  3163. WFIFOW(fd,0)=0xa8;
  3164. WFIFOW(fd,2)=index+2;
  3165. WFIFOW(fd,4)=amount;
  3166. WFIFOB(fd,6)=ok;
  3167. WFIFOSET(fd,packet_len(0xa8));
  3168. #else
  3169. unsigned char buf[32];
  3170. WBUFW(buf,0)=0x1c8;
  3171. WBUFW(buf,2)=index+2;
  3172. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3173. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3174. else
  3175. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3176. WBUFL(buf,6)=sd->bl.id;
  3177. WBUFW(buf,10)=amount;
  3178. WBUFB(buf,12)=ok;
  3179. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3180. #endif
  3181. }
  3182. }
  3183. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3184. /// 00d6 <flag>.B
  3185. /// flag:
  3186. /// 0 = Room has been successfully created (opens chat room)
  3187. /// 1 = Room limit exceeded
  3188. /// 2 = Same room already exists
  3189. void clif_createchat(struct map_session_data* sd, int flag)
  3190. {
  3191. int fd;
  3192. nullpo_retv(sd);
  3193. fd = sd->fd;
  3194. WFIFOHEAD(fd,packet_len(0xd6));
  3195. WFIFOW(fd,0) = 0xd6;
  3196. WFIFOB(fd,2) = flag;
  3197. WFIFOSET(fd,packet_len(0xd6));
  3198. }
  3199. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3200. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3201. /// type:
  3202. /// 0 = private (password protected)
  3203. /// 1 = public
  3204. /// 2 = arena (npc waiting room)
  3205. /// 3 = PK zone (non-clickable)
  3206. void clif_dispchat(struct chat_data* cd, int fd)
  3207. {
  3208. unsigned char buf[128];
  3209. uint8 type;
  3210. if( cd == NULL || cd->owner == NULL )
  3211. return;
  3212. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3213. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3214. : 1;
  3215. WBUFW(buf, 0) = 0xd7;
  3216. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3217. WBUFL(buf, 4) = cd->owner->id;
  3218. WBUFL(buf, 8) = cd->bl.id;
  3219. WBUFW(buf,12) = cd->limit;
  3220. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3221. WBUFB(buf,16) = type;
  3222. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3223. if( fd ) {
  3224. WFIFOHEAD(fd,WBUFW(buf,2));
  3225. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3226. WFIFOSET(fd,WBUFW(buf,2));
  3227. } else {
  3228. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3229. }
  3230. }
  3231. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3232. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3233. /// type:
  3234. /// 0 = private (password protected)
  3235. /// 1 = public
  3236. /// 2 = arena (npc waiting room)
  3237. /// 3 = PK zone (non-clickable)
  3238. void clif_changechatstatus(struct chat_data* cd)
  3239. {
  3240. unsigned char buf[128];
  3241. uint8 type;
  3242. if( cd == NULL || cd->usersd[0] == NULL )
  3243. return;
  3244. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3245. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3246. : 1;
  3247. WBUFW(buf, 0) = 0xdf;
  3248. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3249. WBUFL(buf, 4) = cd->owner->id;
  3250. WBUFL(buf, 8) = cd->bl.id;
  3251. WBUFW(buf,12) = cd->limit;
  3252. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3253. WBUFB(buf,16) = type;
  3254. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3255. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3256. }
  3257. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3258. /// 00d8 <chat id>.L
  3259. void clif_clearchat(struct chat_data *cd,int fd)
  3260. {
  3261. unsigned char buf[32];
  3262. nullpo_retv(cd);
  3263. WBUFW(buf,0) = 0xd8;
  3264. WBUFL(buf,2) = cd->bl.id;
  3265. if( fd ) {
  3266. WFIFOHEAD(fd,packet_len(0xd8));
  3267. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3268. WFIFOSET(fd,packet_len(0xd8));
  3269. } else {
  3270. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3271. }
  3272. }
  3273. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3274. /// 00da <result>.B
  3275. /// result:
  3276. /// 0 = room full
  3277. /// 1 = wrong password
  3278. /// 2 = kicked
  3279. /// 3 = success (no message)
  3280. /// 4 = no enough zeny
  3281. /// 5 = too low level
  3282. /// 6 = too high level
  3283. /// 7 = unsuitable job class
  3284. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3285. {
  3286. int fd;
  3287. nullpo_retv(sd);
  3288. fd = sd->fd;
  3289. WFIFOHEAD(fd,packet_len(0xda));
  3290. WFIFOW(fd,0) = 0xda;
  3291. WFIFOB(fd,2) = flag;
  3292. WFIFOSET(fd,packet_len(0xda));
  3293. }
  3294. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3295. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3296. /// role:
  3297. /// 0 = owner (menu)
  3298. /// 1 = normal
  3299. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3300. {
  3301. int fd;
  3302. int i,t;
  3303. nullpo_retv(sd);
  3304. nullpo_retv(cd);
  3305. fd = sd->fd;
  3306. if (!session_isActive(fd))
  3307. return;
  3308. t = (int)(cd->owner->type == BL_NPC);
  3309. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3310. WFIFOW(fd, 0) = 0xdb;
  3311. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3312. WFIFOL(fd, 4) = cd->bl.id;
  3313. if(cd->owner->type == BL_NPC){
  3314. WFIFOL(fd, 30) = 1;
  3315. WFIFOL(fd, 8) = 0;
  3316. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3317. for (i = 0; i < cd->users; i++) {
  3318. WFIFOL(fd, 8+(i+1)*28) = 1;
  3319. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3320. }
  3321. } else
  3322. for (i = 0; i < cd->users; i++) {
  3323. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3324. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3325. }
  3326. WFIFOSET(fd, WFIFOW(fd, 2));
  3327. }
  3328. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3329. /// 00dc <users>.W <name>.24B
  3330. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3331. {
  3332. unsigned char buf[32];
  3333. nullpo_retv(sd);
  3334. nullpo_retv(cd);
  3335. WBUFW(buf, 0) = 0xdc;
  3336. WBUFW(buf, 2) = cd->users;
  3337. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3338. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3339. }
  3340. /// Announce the new owner (ZC_ROLE_CHANGE).
  3341. /// 00e1 <role>.L <nick>.24B
  3342. /// role:
  3343. /// 0 = owner (menu)
  3344. /// 1 = normal
  3345. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3346. {
  3347. unsigned char buf[64];
  3348. nullpo_retv(sd);
  3349. nullpo_retv(cd);
  3350. WBUFW(buf, 0) = 0xe1;
  3351. WBUFL(buf, 2) = 1;
  3352. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3353. WBUFW(buf,30) = 0xe1;
  3354. WBUFL(buf,32) = 0;
  3355. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3356. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3357. }
  3358. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3359. /// 00dd <users>.W <nick>.24B <flag>.B
  3360. /// flag:
  3361. /// 0 = left
  3362. /// 1 = kicked
  3363. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3364. {
  3365. unsigned char buf[32];
  3366. nullpo_retv(sd);
  3367. nullpo_retv(cd);
  3368. WBUFW(buf, 0) = 0xdd;
  3369. WBUFW(buf, 2) = cd->users-1;
  3370. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3371. WBUFB(buf,28) = flag;
  3372. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3373. }
  3374. /// Opens a trade request window from char 'name'.
  3375. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3376. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3377. void clif_traderequest(struct map_session_data* sd, const char* name)
  3378. {
  3379. int fd = sd->fd;
  3380. #if PACKETVER < 6
  3381. WFIFOHEAD(fd,packet_len(0xe5));
  3382. WFIFOW(fd,0) = 0xe5;
  3383. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3384. WFIFOSET(fd,packet_len(0xe5));
  3385. #else
  3386. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3387. if( !tsd ) return;
  3388. WFIFOHEAD(fd,packet_len(0x1f4));
  3389. WFIFOW(fd,0) = 0x1f4;
  3390. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3391. WFIFOL(fd,26) = tsd->status.char_id;
  3392. WFIFOW(fd,30) = tsd->status.base_level;
  3393. WFIFOSET(fd,packet_len(0x1f4));
  3394. #endif
  3395. }
  3396. /// Reply to a trade-request.
  3397. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3398. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3399. /// result:
  3400. /// 0 = Char is too far
  3401. /// 1 = Character does not exist
  3402. /// 2 = Trade failed
  3403. /// 3 = Accept
  3404. /// 4 = Cancel
  3405. /// 5 = Busy
  3406. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3407. {
  3408. int fd = sd->fd;
  3409. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3410. if( PACKETVER < 6 || !tsd ) {
  3411. WFIFOHEAD(fd,packet_len(0xe7));
  3412. WFIFOW(fd,0) = 0xe7;
  3413. WFIFOB(fd,2) = type;
  3414. WFIFOSET(fd,packet_len(0xe7));
  3415. } else {
  3416. WFIFOHEAD(fd,packet_len(0x1f5));
  3417. WFIFOW(fd,0) = 0x1f5;
  3418. WFIFOB(fd,2) = type;
  3419. WFIFOL(fd,3) = tsd->status.char_id;
  3420. WFIFOW(fd,7) = tsd->status.base_level;
  3421. WFIFOSET(fd,packet_len(0x1f5));
  3422. }
  3423. }
  3424. /// Notifies the client about an item from other player in current trade.
  3425. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3426. /// 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)
  3427. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3428. {
  3429. int fd;
  3430. unsigned char *buf;
  3431. #if PACKETVER < 20100223
  3432. const int cmd = 0xe9;
  3433. #else
  3434. const int cmd = 0x80f;
  3435. #endif
  3436. nullpo_retv(sd);
  3437. nullpo_retv(tsd);
  3438. fd = tsd->fd;
  3439. buf = WFIFOP(fd,0);
  3440. WFIFOHEAD(fd,packet_len(cmd));
  3441. WBUFW(buf,0) = cmd;
  3442. if( index == 0 )
  3443. {
  3444. #if PACKETVER < 20100223
  3445. WBUFL(buf,2) = amount; //amount
  3446. WBUFW(buf,6) = 0; // type id
  3447. #else
  3448. WBUFW(buf,2) = 0; // type id
  3449. WBUFB(buf,4) = 0; // item type
  3450. WBUFL(buf,5) = amount; // amount
  3451. buf = WBUFP(buf,1); //Advance 1B
  3452. #endif
  3453. WBUFB(buf,8) = 0; //identify flag
  3454. WBUFB(buf,9) = 0; // attribute
  3455. WBUFB(buf,10)= 0; //refine
  3456. WBUFW(buf,11)= 0; //card (4w)
  3457. WBUFW(buf,13)= 0; //card (4w)
  3458. WBUFW(buf,15)= 0; //card (4w)
  3459. WBUFW(buf,17)= 0; //card (4w)
  3460. }
  3461. else
  3462. {
  3463. index -= 2; //index fix
  3464. #if PACKETVER < 20100223
  3465. WBUFL(buf,2) = amount; //amount
  3466. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3467. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3468. else
  3469. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3470. #else
  3471. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3472. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3473. else
  3474. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3475. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3476. WBUFL(buf,5) = amount; // amount
  3477. buf = WBUFP(buf,1); //Advance 1B
  3478. #endif
  3479. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3480. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3481. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3482. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3483. }
  3484. WFIFOSET(fd,packet_len(cmd));
  3485. }
  3486. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3487. /// 00ea <index>.W <result>.B
  3488. /// result:
  3489. /// 0 = success
  3490. /// 1 = overweight
  3491. /// 2 = trade canceled
  3492. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3493. {
  3494. int fd;
  3495. nullpo_retv(sd);
  3496. fd = sd->fd;
  3497. WFIFOHEAD(fd,packet_len(0xea));
  3498. WFIFOW(fd,0) = 0xea;
  3499. WFIFOW(fd,2) = index;
  3500. WFIFOB(fd,4) = fail;
  3501. WFIFOSET(fd,packet_len(0xea));
  3502. }
  3503. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3504. /// 00ec <who>.B
  3505. /// who:
  3506. /// 0 = self
  3507. /// 1 = other player
  3508. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3509. {
  3510. int fd;
  3511. nullpo_retv(sd);
  3512. fd = sd->fd;
  3513. WFIFOHEAD(fd,packet_len(0xec));
  3514. WFIFOW(fd,0) = 0xec;
  3515. WFIFOB(fd,2) = fail;
  3516. WFIFOSET(fd,packet_len(0xec));
  3517. }
  3518. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3519. /// 00ee
  3520. void clif_tradecancelled(struct map_session_data* sd)
  3521. {
  3522. int fd;
  3523. nullpo_retv(sd);
  3524. fd = sd->fd;
  3525. WFIFOHEAD(fd,packet_len(0xee));
  3526. WFIFOW(fd,0) = 0xee;
  3527. WFIFOSET(fd,packet_len(0xee));
  3528. }
  3529. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3530. /// 00f0 <result>.B
  3531. /// result:
  3532. /// 0 = success
  3533. /// 1 = failure
  3534. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3535. {
  3536. int fd;
  3537. nullpo_retv(sd);
  3538. fd = sd->fd;
  3539. WFIFOHEAD(fd,packet_len(0xf0));
  3540. WFIFOW(fd,0) = 0xf0;
  3541. WFIFOB(fd,2) = fail;
  3542. WFIFOSET(fd,packet_len(0xf0));
  3543. }
  3544. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3545. /// 00f1
  3546. /// NOTE: Unknown purpose. Items are not removed until the window is
  3547. /// refreshed (ex. by putting another item in there).
  3548. void clif_tradeundo(struct map_session_data* sd)
  3549. {
  3550. int fd = sd->fd;
  3551. WFIFOHEAD(fd,packet_len(0xf1));
  3552. WFIFOW(fd,0) = 0xf1;
  3553. WFIFOSET(fd,packet_len(0xf1));
  3554. }
  3555. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3556. /// 00f2 <current count>.W <max count>.W
  3557. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3558. {
  3559. int fd;
  3560. nullpo_retv(sd);
  3561. fd=sd->fd;
  3562. WFIFOHEAD(fd,packet_len(0xf2));
  3563. WFIFOW(fd,0) = 0xf2;
  3564. WFIFOW(fd,2) = amount;
  3565. WFIFOW(fd,4) = max_amount;
  3566. WFIFOSET(fd,packet_len(0xf2));
  3567. }
  3568. /// Notifies the client of an item being added to the storage.
  3569. /// 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)
  3570. /// 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)
  3571. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3572. {
  3573. int view,fd;
  3574. nullpo_retv(sd);
  3575. nullpo_retv(i);
  3576. fd=sd->fd;
  3577. view = itemdb_viewid(i->nameid);
  3578. #if PACKETVER < 5
  3579. WFIFOHEAD(fd,packet_len(0xf4));
  3580. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3581. WFIFOW(fd, 2) = index+1; // index
  3582. WFIFOL(fd, 4) = amount; // amount
  3583. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3584. WFIFOB(fd,10) = i->identify; //identify flag
  3585. WFIFOB(fd,11) = i->attribute; // attribute
  3586. WFIFOB(fd,12) = i->refine; //refine
  3587. clif_addcards(WFIFOP(fd,13), i);
  3588. WFIFOSET(fd,packet_len(0xf4));
  3589. #else
  3590. WFIFOHEAD(fd,packet_len(0x1c4));
  3591. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3592. WFIFOW(fd, 2) = index+1; // index
  3593. WFIFOL(fd, 4) = amount; // amount
  3594. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3595. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3596. WFIFOB(fd,11) = i->identify; //identify flag
  3597. WFIFOB(fd,12) = i->attribute; // attribute
  3598. WFIFOB(fd,13) = i->refine; //refine
  3599. clif_addcards(WFIFOP(fd,14), i);
  3600. WFIFOSET(fd,packet_len(0x1c4));
  3601. #endif
  3602. }
  3603. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3604. /// 00f6 <index>.W <amount>.L
  3605. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3606. {
  3607. int fd;
  3608. nullpo_retv(sd);
  3609. fd=sd->fd;
  3610. WFIFOHEAD(fd,packet_len(0xf6));
  3611. WFIFOW(fd,0)=0xf6; // Storage item removed
  3612. WFIFOW(fd,2)=index+1;
  3613. WFIFOL(fd,4)=amount;
  3614. WFIFOSET(fd,packet_len(0xf6));
  3615. }
  3616. /// Closes storage (ZC_CLOSE_STORE).
  3617. /// 00f8
  3618. void clif_storageclose(struct map_session_data* sd)
  3619. {
  3620. int fd;
  3621. nullpo_retv(sd);
  3622. fd=sd->fd;
  3623. WFIFOHEAD(fd,packet_len(0xf8));
  3624. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3625. WFIFOSET(fd,packet_len(0xf8));
  3626. }
  3627. /*==========================================
  3628. * Server tells 'sd' player client the abouts of 'dstsd' player
  3629. *------------------------------------------*/
  3630. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3631. {
  3632. struct block_list *d_bl;
  3633. int i;
  3634. if( dstsd->chatID ) {
  3635. struct chat_data *cd = NULL;
  3636. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3637. clif_dispchat(cd,sd->fd);
  3638. } else if( dstsd->state.vending )
  3639. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3640. else if( dstsd->state.buyingstore )
  3641. clif_buyingstore_entry_single(sd, dstsd);
  3642. if(dstsd->spiritball > 0)
  3643. clif_spiritball_single(sd->fd, dstsd);
  3644. for(i = 1; i < 5; i++){
  3645. if( dstsd->talisman[i] > 0 )
  3646. clif_talisman_single(sd->fd, dstsd, i);
  3647. }
  3648. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3649. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3650. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3651. }
  3652. #ifdef NEW_CARTS
  3653. if( dstsd->sc.data[SC_PUSH_CART] )
  3654. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3655. #endif
  3656. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3657. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3658. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3659. )
  3660. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3661. // display link (sd - dstsd) to sd
  3662. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3663. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3664. // display links (dstsd - devotees) to sd
  3665. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3666. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3667. // display link (dstsd - crusader) to sd
  3668. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3669. clif_devotion(d_bl, sd);
  3670. }
  3671. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3672. {
  3673. uint8 buf[128];
  3674. struct unit_data *ud;
  3675. struct view_data *vd;
  3676. int len;
  3677. vd = status_get_viewdata(bl);
  3678. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3679. return;
  3680. /**
  3681. * Hide NPC from maya purple card.
  3682. **/
  3683. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3684. return;
  3685. ud = unit_bl2ud(bl);
  3686. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3687. clif_send(buf,len,&sd->bl,SELF);
  3688. if (vd->cloth_color)
  3689. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3690. switch (bl->type)
  3691. {
  3692. case BL_PC:
  3693. {
  3694. TBL_PC* tsd = (TBL_PC*)bl;
  3695. clif_getareachar_pc(sd, tsd);
  3696. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3697. clif_specialeffect_single(bl,423,sd->fd);
  3698. else if(tsd->state.size==SZ_MEDIUM)
  3699. clif_specialeffect_single(bl,421,sd->fd);
  3700. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3701. clif_sendbgemblem_single(sd->fd,tsd);
  3702. if ( tsd->status.robe )
  3703. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3704. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3705. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3706. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3707. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3708. if( tsd->sc.data[SC_MOONSTAR] )
  3709. clif_status_load(bl,SI_MOONSTAR,1);
  3710. if( tsd->sc.data[SC_SUPER_STAR] )
  3711. clif_status_load(bl,SI_SUPER_STAR,1);
  3712. }
  3713. break;
  3714. case BL_MER: // Devotion Effects
  3715. if( ((TBL_MER*)bl)->devotion_flag )
  3716. clif_devotion(bl, sd);
  3717. break;
  3718. case BL_NPC:
  3719. {
  3720. TBL_NPC* nd = (TBL_NPC*)bl;
  3721. if( nd->chat_id )
  3722. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3723. if( nd->size == SZ_BIG )
  3724. clif_specialeffect_single(bl,423,sd->fd);
  3725. else if( nd->size == SZ_MEDIUM )
  3726. clif_specialeffect_single(bl,421,sd->fd);
  3727. }
  3728. break;
  3729. case BL_MOB:
  3730. {
  3731. TBL_MOB* md = (TBL_MOB*)bl;
  3732. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3733. clif_specialeffect_single(bl,423,sd->fd);
  3734. else if(md->special_state.size==SZ_MEDIUM)
  3735. clif_specialeffect_single(bl,421,sd->fd);
  3736. #if PACKETVER >= 20120404
  3737. if( !(md->status.mode&MD_BOSS) ){
  3738. int i;
  3739. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3740. if( md->dmglog[i].id == sd->status.char_id )
  3741. clif_monster_hp_bar(md, sd->fd);
  3742. }
  3743. #endif
  3744. }
  3745. break;
  3746. case BL_PET:
  3747. if (vd->head_bottom)
  3748. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3749. break;
  3750. }
  3751. }
  3752. //Modifies the type of damage according to status changes [Skotlex]
  3753. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3754. static inline int clif_calc_delay(int type, int div, int64 damage, int delay)
  3755. {
  3756. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3757. }
  3758. /*==========================================
  3759. * Estimates walk delay based on the damage criteria. [Skotlex]
  3760. *------------------------------------------*/
  3761. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int64 damage, int div_)
  3762. {
  3763. if (type == 4 || type == 9 || damage <=0)
  3764. return 0;
  3765. if (bl->type == BL_PC) {
  3766. if (battle_config.pc_walk_delay_rate != 100)
  3767. delay = delay*battle_config.pc_walk_delay_rate/100;
  3768. } else
  3769. if (battle_config.walk_delay_rate != 100)
  3770. delay = delay*battle_config.walk_delay_rate/100;
  3771. if (div_ > 1) //Multi-hit skills mean higher delays.
  3772. delay += battle_config.multihit_delay*(div_-1);
  3773. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3774. }
  3775. /// Sends a 'damage' packet (src performs action on dst)
  3776. /// 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)
  3777. /// 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)
  3778. /// type:
  3779. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3780. /// 1 = pick up item
  3781. /// 2 = sit down
  3782. /// 3 = stand up
  3783. /// 4 = damage (endure)
  3784. /// 5 = (splash?)
  3785. /// 6 = (skill?)
  3786. /// 7 = (repeat damage?)
  3787. /// 8 = multi-hit damage
  3788. /// 9 = multi-hit damage (endure)
  3789. /// 10 = critical hit
  3790. /// 11 = lucky dodge
  3791. /// 12 = (touch skill?)
  3792. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, int type, int64 sdamage2)
  3793. {
  3794. unsigned char buf[33];
  3795. struct status_change *sc;
  3796. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3797. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3798. #if PACKETVER < 20071113
  3799. const int cmd = 0x8a;
  3800. #else
  3801. const int cmd = 0x2e1;
  3802. #endif
  3803. nullpo_ret(src);
  3804. nullpo_ret(dst);
  3805. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3806. sc = status_get_sc(dst);
  3807. if(sc && sc->count) {
  3808. if(sc->data[SC_HALLUCINATION]) {
  3809. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3810. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3811. }
  3812. }
  3813. WBUFW(buf,0)=cmd;
  3814. WBUFL(buf,2)=src->id;
  3815. WBUFL(buf,6)=dst->id;
  3816. WBUFL(buf,10)=tick;
  3817. WBUFL(buf,14)=sdelay;
  3818. WBUFL(buf,18)=ddelay;
  3819. #if PACKETVER < 20071113
  3820. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3821. WBUFW(buf,22)=damage?div:0;
  3822. WBUFW(buf,27)=damage2?div:0;
  3823. } else {
  3824. WBUFW(buf,22)=min(damage, INT16_MAX);
  3825. WBUFW(buf,27)=damage2;
  3826. }
  3827. WBUFW(buf,24)=div;
  3828. WBUFB(buf,26)=type;
  3829. #else
  3830. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3831. WBUFL(buf,22)=damage?div:0;
  3832. WBUFL(buf,29)=damage2?div:0;
  3833. } else {
  3834. WBUFL(buf,22)=damage;
  3835. WBUFL(buf,29)=damage2;
  3836. }
  3837. WBUFW(buf,26)=div;
  3838. WBUFB(buf,28)=type;
  3839. #endif
  3840. if(disguised(dst)) {
  3841. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3842. WBUFL(buf,6) = -dst->id;
  3843. clif_send(buf,packet_len(cmd),dst,SELF);
  3844. } else
  3845. clif_send(buf,packet_len(cmd),dst,AREA);
  3846. if(disguised(src)) {
  3847. WBUFL(buf,2) = -src->id;
  3848. if (disguised(dst))
  3849. WBUFL(buf,6) = dst->id;
  3850. #if PACKETVER < 20071113
  3851. if(damage > 0) WBUFW(buf,22) = -1;
  3852. if(damage2 > 0) WBUFW(buf,27) = -1;
  3853. #else
  3854. if(damage > 0) WBUFL(buf,22) = -1;
  3855. if(damage2 > 0) WBUFL(buf,29) = -1;
  3856. #endif
  3857. clif_send(buf,packet_len(cmd),src,SELF);
  3858. }
  3859. if(src == dst) {
  3860. unit_setdir(src,unit_getdir(src));
  3861. }
  3862. //Return adjusted can't walk delay for further processing.
  3863. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3864. }
  3865. /*==========================================
  3866. * src picks up dst
  3867. *------------------------------------------*/
  3868. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3869. {
  3870. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3871. unsigned char buf[32];
  3872. nullpo_retv(src);
  3873. nullpo_retv(dst);
  3874. WBUFW(buf, 0) = 0x8a;
  3875. WBUFL(buf, 2) = src->id;
  3876. WBUFL(buf, 6) = dst->id;
  3877. WBUFB(buf,26) = 1;
  3878. clif_send(buf, packet_len(0x8a), src, AREA);
  3879. }
  3880. /*==========================================
  3881. * inform clients in area that `bl` is sitting
  3882. *------------------------------------------*/
  3883. void clif_sitting(struct block_list* bl)
  3884. {
  3885. unsigned char buf[32];
  3886. nullpo_retv(bl);
  3887. WBUFW(buf, 0) = 0x8a;
  3888. WBUFL(buf, 2) = bl->id;
  3889. WBUFB(buf,26) = 2;
  3890. clif_send(buf, packet_len(0x8a), bl, AREA);
  3891. if(disguised(bl)) {
  3892. WBUFL(buf, 2) = - bl->id;
  3893. clif_send(buf, packet_len(0x8a), bl, SELF);
  3894. }
  3895. }
  3896. /*==========================================
  3897. * inform clients in area that `bl` is standing
  3898. *------------------------------------------*/
  3899. void clif_standing(struct block_list* bl)
  3900. {
  3901. unsigned char buf[32];
  3902. nullpo_retv(bl);
  3903. WBUFW(buf, 0) = 0x8a;
  3904. WBUFL(buf, 2) = bl->id;
  3905. WBUFB(buf,26) = 3;
  3906. clif_send(buf, packet_len(0x8a), bl, AREA);
  3907. if(disguised(bl)) {
  3908. WBUFL(buf, 2) = - bl->id;
  3909. clif_send(buf, packet_len(0x8a), bl, SELF);
  3910. }
  3911. }
  3912. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3913. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3914. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3915. {
  3916. unsigned char buf[32];
  3917. WBUFW(buf,0) = 0x192;
  3918. WBUFW(buf,2) = x;
  3919. WBUFW(buf,4) = y;
  3920. WBUFW(buf,6) = type;
  3921. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3922. if( fd )
  3923. {
  3924. WFIFOHEAD(fd,packet_len(0x192));
  3925. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3926. WFIFOSET(fd,packet_len(0x192));
  3927. }
  3928. else
  3929. {
  3930. struct block_list dummy_bl;
  3931. dummy_bl.type = BL_NUL;
  3932. dummy_bl.x = x;
  3933. dummy_bl.y = y;
  3934. dummy_bl.m = m;
  3935. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3936. }
  3937. }
  3938. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3939. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3940. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3941. {
  3942. int view,fd;
  3943. fd=sd->fd;
  3944. WFIFOHEAD(fd,packet_len(0x9d));
  3945. WFIFOW(fd,0)=0x9d;
  3946. WFIFOL(fd,2)=fitem->bl.id;
  3947. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3948. WFIFOW(fd,6)=view;
  3949. else
  3950. WFIFOW(fd,6)=fitem->item_data.nameid;
  3951. WFIFOB(fd,8)=fitem->item_data.identify;
  3952. WFIFOW(fd,9)=fitem->bl.x;
  3953. WFIFOW(fd,11)=fitem->bl.y;
  3954. WFIFOW(fd,13)=fitem->item_data.amount;
  3955. WFIFOB(fd,15)=fitem->subx;
  3956. WFIFOB(fd,16)=fitem->suby;
  3957. WFIFOSET(fd,packet_len(0x9d));
  3958. }
  3959. /// Notifies the client of a skill unit.
  3960. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3961. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3962. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  3963. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  3964. static void clif_getareachar_skillunit(int type,struct map_session_data *sd, struct skill_unit *unit)
  3965. {
  3966. int fd = sd->fd;
  3967. int header=0, unit_id=0, pos=0;
  3968. if( unit->group->state.guildaura )
  3969. return;
  3970. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3971. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3972. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  3973. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  3974. else
  3975. unit_id=unit->group->unit_id;
  3976. #if PACKETVER >= 3
  3977. if(unit->group->unit_id==UNT_GRAFFITI) // Graffiti [Valaris]
  3978. type = 2;
  3979. #endif
  3980. switch(type){
  3981. case 2: header=0x1c9; break;
  3982. case 3: header=0x8c7; break;
  3983. case 4: header=0x99f; break;
  3984. default:
  3985. case 1: header=0x11f; break;
  3986. }
  3987. WFIFOHEAD(fd,packet_len(header));
  3988. WFIFOW(fd,pos)=header;
  3989. if(type==3 || type==4){
  3990. WFIFOW(fd, pos+2)=packet_len(header);
  3991. pos +=2;
  3992. }
  3993. WFIFOL(fd,pos+2)=unit->bl.id;
  3994. WFIFOL(fd,pos+6)=unit->group->src_id;
  3995. WFIFOW(fd,pos+10)=unit->bl.x;
  3996. WFIFOW(fd,pos+12)=unit->bl.y;
  3997. switch(type){
  3998. case 1: WFIFOB(fd,pos+14)=unit_id;
  3999. WFIFOB(fd,pos+15)=1;
  4000. break;
  4001. case 2: WFIFOB(fd,pos+14)=unit_id;
  4002. WFIFOB(fd,pos+15)=1;
  4003. WFIFOB(fd,pos+16)=1;
  4004. safestrncpy((char*)WFIFOP(fd,pos+17),unit->group->valstr,MESSAGE_SIZE);
  4005. break;
  4006. case 3: WFIFOB(fd,pos+14)=unit_id;
  4007. WFIFOW(fd,pos+15)=unit->range;
  4008. WFIFOB(fd,pos+17)=1; //visible
  4009. break;
  4010. case 4: WFIFOL(fd,pos+14)=unit_id; pos += 3;
  4011. WFIFOW(fd,pos+15)=unit->range;
  4012. WFIFOB(fd,pos+17)=1;
  4013. break;
  4014. }
  4015. WFIFOSET(fd,packet_len(header));
  4016. if(unit->group->skill_id == WZ_ICEWALL)
  4017. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  4018. }
  4019. /*==========================================
  4020. * Server tells client to remove unit of id 'unit->bl.id'
  4021. *------------------------------------------*/
  4022. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4023. {
  4024. nullpo_retv(unit);
  4025. WFIFOHEAD(fd,packet_len(0x120));
  4026. WFIFOW(fd, 0)=0x120;
  4027. WFIFOL(fd, 2)=unit->bl.id;
  4028. WFIFOSET(fd,packet_len(0x120));
  4029. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4030. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4031. }
  4032. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4033. /// 0120 <id>.L
  4034. void clif_skill_delunit(struct skill_unit *unit)
  4035. {
  4036. unsigned char buf[16];
  4037. nullpo_retv(unit);
  4038. WBUFW(buf, 0)=0x120;
  4039. WBUFL(buf, 2)=unit->bl.id;
  4040. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4041. }
  4042. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4043. /// 01ac <id>.L
  4044. /// Only affects units with class [139,153] client-side.
  4045. void clif_skillunit_update(struct block_list* bl)
  4046. {
  4047. unsigned char buf[6];
  4048. nullpo_retv(bl);
  4049. WBUFW(buf,0) = 0x1ac;
  4050. WBUFL(buf,2) = bl->id;
  4051. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4052. }
  4053. /*==========================================
  4054. *
  4055. *------------------------------------------*/
  4056. static int clif_getareachar(struct block_list* bl,va_list ap)
  4057. {
  4058. struct map_session_data *sd;
  4059. nullpo_ret(bl);
  4060. sd=va_arg(ap,struct map_session_data*);
  4061. if (sd == NULL || !sd->fd)
  4062. return 0;
  4063. switch(bl->type){
  4064. case BL_ITEM:
  4065. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4066. break;
  4067. case BL_SKILL:
  4068. clif_getareachar_skillunit(1,sd,(TBL_SKILL*)bl);
  4069. break;
  4070. default:
  4071. if(&sd->bl == bl)
  4072. break;
  4073. clif_getareachar_unit(sd,bl);
  4074. break;
  4075. }
  4076. return 0;
  4077. }
  4078. /*==========================================
  4079. * tbl has gone out of view-size of bl
  4080. *------------------------------------------*/
  4081. int clif_outsight(struct block_list *bl,va_list ap)
  4082. {
  4083. struct block_list *tbl;
  4084. struct view_data *vd;
  4085. TBL_PC *sd, *tsd;
  4086. tbl=va_arg(ap,struct block_list*);
  4087. if(bl == tbl) return 0;
  4088. sd = BL_CAST(BL_PC, bl);
  4089. tsd = BL_CAST(BL_PC, tbl);
  4090. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4091. switch(bl->type){
  4092. case BL_PC:
  4093. if (sd->vd.class_ != INVISIBLE_CLASS)
  4094. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4095. if(sd->chatID){
  4096. struct chat_data *cd;
  4097. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4098. if(cd->usersd[0]==sd)
  4099. clif_dispchat(cd,tsd->fd);
  4100. }
  4101. if( sd->state.vending )
  4102. clif_closevendingboard(bl,tsd->fd);
  4103. if( sd->state.buyingstore )
  4104. clif_buyingstore_disappear_entry_single(tsd, sd);
  4105. break;
  4106. case BL_ITEM:
  4107. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4108. break;
  4109. case BL_SKILL:
  4110. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4111. break;
  4112. case BL_NPC:
  4113. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4114. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4115. break;
  4116. default:
  4117. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4118. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4119. break;
  4120. }
  4121. }
  4122. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4123. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4124. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4125. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4126. }
  4127. return 0;
  4128. }
  4129. /*==========================================
  4130. * tbl has come into view of bl
  4131. *------------------------------------------*/
  4132. int clif_insight(struct block_list *bl,va_list ap)
  4133. {
  4134. struct block_list *tbl;
  4135. TBL_PC *sd, *tsd;
  4136. tbl=va_arg(ap,struct block_list*);
  4137. if (bl == tbl) return 0;
  4138. sd = BL_CAST(BL_PC, bl);
  4139. tsd = BL_CAST(BL_PC, tbl);
  4140. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4141. switch(bl->type){
  4142. case BL_ITEM:
  4143. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4144. break;
  4145. case BL_SKILL:
  4146. clif_getareachar_skillunit(1,tsd,(TBL_SKILL*)bl);
  4147. break;
  4148. default:
  4149. clif_getareachar_unit(tsd,bl);
  4150. break;
  4151. }
  4152. }
  4153. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4154. clif_getareachar_unit(sd,tbl);
  4155. }
  4156. return 0;
  4157. }
  4158. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4159. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4160. void clif_skillinfoblock(struct map_session_data *sd)
  4161. {
  4162. int fd;
  4163. int i,len,id;
  4164. nullpo_retv(sd);
  4165. fd=sd->fd;
  4166. if (!fd) return;
  4167. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4168. WFIFOW(fd,0) = 0x10f;
  4169. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4170. {
  4171. if( (id = sd->status.skill[i].id) != 0 )
  4172. {
  4173. // workaround for bugreport:5348
  4174. if (len + 37 > 8192)
  4175. break;
  4176. WFIFOW(fd,len) = id;
  4177. WFIFOL(fd,len+2) = skill_get_inf(id);
  4178. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4179. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4180. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4181. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4182. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4183. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4184. else
  4185. WFIFOB(fd,len+36) = 0;
  4186. len += 37;
  4187. }
  4188. }
  4189. WFIFOW(fd,2)=len;
  4190. WFIFOSET(fd,len);
  4191. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4192. for ( ; i < MAX_SKILL; i++)
  4193. {
  4194. if( (id = sd->status.skill[i].id) != 0 )
  4195. {
  4196. clif_addskill(sd, id);
  4197. clif_skillinfo(sd, id, 0);
  4198. }
  4199. }
  4200. }
  4201. /**
  4202. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4203. **/
  4204. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4205. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4206. void clif_addskill(struct map_session_data *sd, int id)
  4207. {
  4208. int fd;
  4209. nullpo_retv(sd);
  4210. fd = sd->fd;
  4211. if (!fd) return;
  4212. if( sd->status.skill[id].id <= 0 )
  4213. return;
  4214. WFIFOHEAD(fd, packet_len(0x111));
  4215. WFIFOW(fd,0) = 0x111;
  4216. WFIFOW(fd,2) = id;
  4217. WFIFOL(fd,4) = skill_get_inf(id);
  4218. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4219. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4220. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4221. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4222. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4223. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4224. else
  4225. WFIFOB(fd,38) = 0;
  4226. WFIFOSET(fd,packet_len(0x111));
  4227. }
  4228. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4229. /// 0441 <skill id>.W
  4230. void clif_deleteskill(struct map_session_data *sd, int id)
  4231. {
  4232. #if PACKETVER >= 20081217
  4233. int fd;
  4234. nullpo_retv(sd);
  4235. fd = sd->fd;
  4236. if( !fd ) return;
  4237. WFIFOHEAD(fd,packet_len(0x441));
  4238. WFIFOW(fd,0) = 0x441;
  4239. WFIFOW(fd,2) = id;
  4240. WFIFOSET(fd,packet_len(0x441));
  4241. #endif
  4242. clif_skillinfoblock(sd);
  4243. }
  4244. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4245. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4246. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4247. int fd;
  4248. nullpo_retv(sd);
  4249. fd = sd->fd;
  4250. WFIFOHEAD(fd, packet_len(0x10e));
  4251. WFIFOW(fd, 0) = 0x10e;
  4252. WFIFOW(fd, 2) = skill_id;
  4253. WFIFOW(fd, 4) = lv;
  4254. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4255. WFIFOW(fd, 8) = range;
  4256. WFIFOB(fd, 10) = upgradable;
  4257. WFIFOSET(fd, packet_len(0x10e));
  4258. }
  4259. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4260. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4261. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4262. {
  4263. const int fd = sd->fd;
  4264. WFIFOHEAD(fd,packet_len(0x7e1));
  4265. WFIFOW(fd,0) = 0x7e1;
  4266. WFIFOW(fd,2) = skill;
  4267. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4268. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4269. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4270. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4271. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4272. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4273. else
  4274. WFIFOB(fd,14) = 0;
  4275. WFIFOSET(fd,packet_len(0x7e1));
  4276. }
  4277. /// Notifies clients in area, that an object is about to use a skill.
  4278. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4279. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4280. /// property:
  4281. /// 0 = Yellow cast aura
  4282. /// 1 = Water elemental cast aura
  4283. /// 2 = Earth elemental cast aura
  4284. /// 3 = Fire elemental cast aura
  4285. /// 4 = Wind elemental cast aura
  4286. /// 5 = Poison elemental cast aura
  4287. /// 6 = Holy elemental cast aura
  4288. /// ? = like 0
  4289. /// is disposable:
  4290. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4291. /// 1 = no text
  4292. 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)
  4293. {
  4294. #if PACKETVER < 20091124
  4295. const int cmd = 0x13e;
  4296. #else
  4297. const int cmd = 0x7fb;
  4298. #endif
  4299. unsigned char buf[32];
  4300. WBUFW(buf,0) = cmd;
  4301. WBUFL(buf,2) = src_id;
  4302. WBUFL(buf,6) = dst_id;
  4303. WBUFW(buf,10) = dst_x;
  4304. WBUFW(buf,12) = dst_y;
  4305. WBUFW(buf,14) = skill_id;
  4306. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4307. WBUFL(buf,20) = casttime;
  4308. #if PACKETVER >= 20091124
  4309. WBUFB(buf,24) = 0; // isDisposable
  4310. #endif
  4311. if (disguised(bl)) {
  4312. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4313. WBUFL(buf,2) = -src_id;
  4314. clif_send(buf,packet_len(cmd), bl, SELF);
  4315. } else
  4316. clif_send(buf,packet_len(cmd), bl, AREA);
  4317. }
  4318. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4319. /// 01b9 <id>.L
  4320. void clif_skillcastcancel(struct block_list* bl)
  4321. {
  4322. unsigned char buf[16];
  4323. nullpo_retv(bl);
  4324. WBUFW(buf,0) = 0x1b9;
  4325. WBUFL(buf,2) = bl->id;
  4326. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4327. }
  4328. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4329. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4330. /// num (only used when skill id = NV_BASIC and cause = 0):
  4331. /// 0 = "skill failed" MsgStringTable[159]
  4332. /// 1 = "no emotions" MsgStringTable[160]
  4333. /// 2 = "no sit" MsgStringTable[161]
  4334. /// 3 = "no chat" MsgStringTable[162]
  4335. /// 4 = "no party" MsgStringTable[163]
  4336. /// 5 = "no shout" MsgStringTable[164]
  4337. /// 6 = "no PKing" MsgStringTable[165]
  4338. /// 7 = "no alligning" MsgStringTable[383]
  4339. /// ? = ignored
  4340. /// cause:
  4341. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4342. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4343. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4344. /// "skill failed" MsgStringTable[204] (otherwise)
  4345. /// ... = @see enum useskill_fail_cause
  4346. /// ? = ignored
  4347. ///
  4348. /// if(result!=0) doesn't display any of the previous messages
  4349. /// Note: when this packet is received an unknown flag is always set to 0,
  4350. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4351. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4352. {
  4353. int fd;
  4354. if (!sd) { //Since this is the most common nullpo....
  4355. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4356. return;
  4357. }
  4358. fd=sd->fd;
  4359. if (!fd) return;
  4360. if(battle_config.display_skill_fail&1)
  4361. return; //Disable all skill failed messages
  4362. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4363. return; //Disable delay failed messages
  4364. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4365. return;
  4366. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4367. return;
  4368. WFIFOHEAD(fd,packet_len(0x110));
  4369. WFIFOW(fd,0) = 0x110;
  4370. WFIFOW(fd,2) = skill_id;
  4371. WFIFOL(fd,4) = btype;
  4372. WFIFOB(fd,8) = 0;// success
  4373. WFIFOB(fd,9) = cause;
  4374. WFIFOSET(fd,packet_len(0x110));
  4375. }
  4376. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4377. /// 043d <skill ID>.W <tick>.L
  4378. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4379. {
  4380. #if PACKETVER>=20081112
  4381. int fd;
  4382. nullpo_retv(sd);
  4383. fd=sd->fd;
  4384. WFIFOHEAD(fd,packet_len(0x43d));
  4385. WFIFOW(fd,0) = 0x43d;
  4386. WFIFOW(fd,2) = skill_id;
  4387. WFIFOL(fd,4) = tick;
  4388. WFIFOSET(fd,packet_len(0x43d));
  4389. #endif
  4390. }
  4391. /// Skill attack effect and damage.
  4392. /// 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)
  4393. /// 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)
  4394. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4395. {
  4396. unsigned char buf[64];
  4397. struct status_change *sc;
  4398. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4399. nullpo_ret(src);
  4400. nullpo_ret(dst);
  4401. type = clif_calc_delay(type,div,damage,ddelay);
  4402. sc = status_get_sc(dst);
  4403. if(sc && sc->count) {
  4404. if(sc->data[SC_HALLUCINATION] && damage)
  4405. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4406. }
  4407. #if PACKETVER < 3
  4408. WBUFW(buf,0)=0x114;
  4409. WBUFW(buf,2)=skill_id;
  4410. WBUFL(buf,4)=src->id;
  4411. WBUFL(buf,8)=dst->id;
  4412. WBUFL(buf,12)=tick;
  4413. WBUFL(buf,16)=sdelay;
  4414. WBUFL(buf,20)=ddelay;
  4415. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4416. WBUFW(buf,24)=damage?div:0;
  4417. } else {
  4418. WBUFW(buf,24)=damage;
  4419. }
  4420. WBUFW(buf,26)=skill_lv;
  4421. WBUFW(buf,28)=div;
  4422. WBUFB(buf,30)=type;
  4423. if (disguised(dst)) {
  4424. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4425. WBUFL(buf,8)=-dst->id;
  4426. clif_send(buf,packet_len(0x114),dst,SELF);
  4427. } else
  4428. clif_send(buf,packet_len(0x114),dst,AREA);
  4429. if(disguised(src)) {
  4430. WBUFL(buf,4)=-src->id;
  4431. if (disguised(dst))
  4432. WBUFL(buf,8)=dst->id;
  4433. if(damage > 0)
  4434. WBUFW(buf,24)=-1;
  4435. clif_send(buf,packet_len(0x114),src,SELF);
  4436. }
  4437. #else
  4438. WBUFW(buf,0)=0x1de;
  4439. WBUFW(buf,2)=skill_id;
  4440. WBUFL(buf,4)=src->id;
  4441. WBUFL(buf,8)=dst->id;
  4442. WBUFL(buf,12)=tick;
  4443. WBUFL(buf,16)=sdelay;
  4444. WBUFL(buf,20)=ddelay;
  4445. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4446. WBUFL(buf,24)=damage?div:0;
  4447. } else {
  4448. WBUFL(buf,24)=damage;
  4449. }
  4450. WBUFW(buf,28)=skill_lv;
  4451. WBUFW(buf,30)=div;
  4452. WBUFB(buf,32)=type;
  4453. if (disguised(dst)) {
  4454. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4455. WBUFL(buf,8)=-dst->id;
  4456. clif_send(buf,packet_len(0x1de),dst,SELF);
  4457. } else
  4458. clif_send(buf,packet_len(0x1de),dst,AREA);
  4459. if(disguised(src)) {
  4460. WBUFL(buf,4)=-src->id;
  4461. if (disguised(dst))
  4462. WBUFL(buf,8)=dst->id;
  4463. if(damage > 0)
  4464. WBUFL(buf,24)=-1;
  4465. clif_send(buf,packet_len(0x1de),src,SELF);
  4466. }
  4467. #endif
  4468. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4469. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4470. }
  4471. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4472. /// 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
  4473. /*
  4474. 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)
  4475. {
  4476. unsigned char buf[64];
  4477. struct status_change *sc;
  4478. nullpo_ret(src);
  4479. nullpo_ret(dst);
  4480. type = (type>0)?type:skill_get_hit(skill_id);
  4481. type = clif_calc_delay(type,div,damage,ddelay);
  4482. sc = status_get_sc(dst);
  4483. if(sc && sc->count) {
  4484. if(sc->data[SC_HALLUCINATION] && damage)
  4485. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4486. }
  4487. WBUFW(buf,0)=0x115;
  4488. WBUFW(buf,2)=skill_id;
  4489. WBUFL(buf,4)=src->id;
  4490. WBUFL(buf,8)=dst->id;
  4491. WBUFL(buf,12)=tick;
  4492. WBUFL(buf,16)=sdelay;
  4493. WBUFL(buf,20)=ddelay;
  4494. WBUFW(buf,24)=dst->x;
  4495. WBUFW(buf,26)=dst->y;
  4496. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4497. WBUFW(buf,28)=damage?div:0;
  4498. } else {
  4499. WBUFW(buf,28)=damage;
  4500. }
  4501. WBUFW(buf,30)=skill_lv;
  4502. WBUFW(buf,32)=div;
  4503. WBUFB(buf,34)=type;
  4504. clif_send(buf,packet_len(0x115),src,AREA);
  4505. if(disguised(src)) {
  4506. WBUFL(buf,4)=-src->id;
  4507. if(damage > 0)
  4508. WBUFW(buf,28)=-1;
  4509. clif_send(buf,packet_len(0x115),src,SELF);
  4510. }
  4511. if (disguised(dst)) {
  4512. WBUFL(buf,8)=-dst->id;
  4513. if (disguised(src))
  4514. WBUFL(buf,4)=src->id;
  4515. else if(damage > 0)
  4516. WBUFW(buf,28)=-1;
  4517. clif_send(buf,packet_len(0x115),dst,SELF);
  4518. }
  4519. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4520. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4521. }
  4522. */
  4523. /// Non-damaging skill effect (ZC_USE_SKILL).
  4524. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4525. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4526. {
  4527. unsigned char buf[32];
  4528. nullpo_ret(dst);
  4529. WBUFW(buf,0)=0x11a;
  4530. WBUFW(buf,2)=skill_id;
  4531. WBUFW(buf,4)=min(heal, INT16_MAX);
  4532. WBUFL(buf,6)=dst->id;
  4533. WBUFL(buf,10)=src?src->id:0;
  4534. WBUFB(buf,14)=fail;
  4535. if (disguised(dst)) {
  4536. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4537. WBUFL(buf,6)=-dst->id;
  4538. clif_send(buf,packet_len(0x11a),dst,SELF);
  4539. } else
  4540. clif_send(buf,packet_len(0x11a),dst,AREA);
  4541. if(src && disguised(src)) {
  4542. WBUFL(buf,10)=-src->id;
  4543. if (disguised(dst))
  4544. WBUFL(buf,6)=dst->id;
  4545. clif_send(buf,packet_len(0x11a),src,SELF);
  4546. }
  4547. return fail;
  4548. }
  4549. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4550. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4551. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4552. {
  4553. unsigned char buf[32];
  4554. nullpo_retv(src);
  4555. WBUFW(buf,0)=0x117;
  4556. WBUFW(buf,2)=skill_id;
  4557. WBUFL(buf,4)=src->id;
  4558. WBUFW(buf,8)=val;
  4559. WBUFW(buf,10)=x;
  4560. WBUFW(buf,12)=y;
  4561. WBUFL(buf,14)=tick;
  4562. if(disguised(src)) {
  4563. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4564. WBUFL(buf,4)=-src->id;
  4565. clif_send(buf,packet_len(0x117),src,SELF);
  4566. } else
  4567. clif_send(buf,packet_len(0x117),src,AREA);
  4568. }
  4569. /*==========================================
  4570. * Tells all client's nearby 'unit' sight range that it spawned
  4571. *------------------------------------------*/
  4572. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4573. void clif_skill_setunit(struct skill_unit *unit)
  4574. {
  4575. unsigned char buf[128];
  4576. nullpo_retv(unit);
  4577. if( unit->group->state.guildaura )
  4578. return;
  4579. #if PACKETVER >= 3
  4580. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4581. WBUFW(buf, 0)=0x1c9;
  4582. WBUFL(buf, 2)=unit->bl.id;
  4583. WBUFL(buf, 6)=unit->group->src_id;
  4584. WBUFW(buf,10)=unit->bl.x;
  4585. WBUFW(buf,12)=unit->bl.y;
  4586. WBUFB(buf,14)=unit->group->unit_id;
  4587. WBUFB(buf,15)=1;
  4588. WBUFB(buf,16)=1;
  4589. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4590. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4591. return;
  4592. }
  4593. #endif
  4594. WBUFW(buf, 0)=0x11f;
  4595. WBUFL(buf, 2)=unit->bl.id;
  4596. WBUFL(buf, 6)=unit->group->src_id;
  4597. WBUFW(buf,10)=unit->bl.x;
  4598. WBUFW(buf,12)=unit->bl.y;
  4599. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4600. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4601. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4602. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4603. else
  4604. WBUFB(buf,14)=unit->group->unit_id;
  4605. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4606. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4607. }
  4608. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4609. /// 011c <skill id>.W { <map name>.16B }*4
  4610. 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)
  4611. {
  4612. int fd;
  4613. nullpo_retv(sd);
  4614. fd = sd->fd;
  4615. WFIFOHEAD(fd,packet_len(0x11c));
  4616. WFIFOW(fd,0) = 0x11c;
  4617. WFIFOW(fd,2) = skill_id;
  4618. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4619. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4620. else // normal map name
  4621. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4622. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4623. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4624. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4625. WFIFOSET(fd,packet_len(0x11c));
  4626. sd->menuskill_id = skill_id;
  4627. if (skill_id == AL_WARP)
  4628. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4629. else
  4630. sd->menuskill_val = skill_lv;
  4631. }
  4632. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4633. /// 011e <type>.B
  4634. /// type:
  4635. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4636. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4637. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4638. ///
  4639. /// @param sd Who receives the message
  4640. /// @param type What message
  4641. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4642. {
  4643. int fd;
  4644. nullpo_retv(sd);
  4645. fd=sd->fd;
  4646. WFIFOHEAD(fd,packet_len(0x11e));
  4647. WFIFOW(fd,0)=0x11e;
  4648. WFIFOB(fd,2)=type;
  4649. WFIFOSET(fd,packet_len(0x11e));
  4650. }
  4651. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4652. /// 0189 <type>.W
  4653. /// type:
  4654. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4655. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4656. ///
  4657. /// @param sd Who receives the message
  4658. /// @param type What message
  4659. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4660. {
  4661. int fd;
  4662. nullpo_retv(sd);
  4663. fd=sd->fd;
  4664. WFIFOHEAD(fd,packet_len(0x189));
  4665. WFIFOW(fd,0)=0x189;
  4666. WFIFOW(fd,2)=type;
  4667. WFIFOSET(fd,packet_len(0x189));
  4668. }
  4669. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4670. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4671. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4672. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4673. {
  4674. struct status_data *status;
  4675. unsigned char buf[64];
  4676. int i;//, fix;
  4677. nullpo_retv(sd);
  4678. nullpo_retv(dst);
  4679. if( dst->type != BL_MOB )
  4680. return;
  4681. status = status_get_status_data(dst);
  4682. WBUFW(buf, 0)=0x18c;
  4683. WBUFW(buf, 2)=status_get_class(dst);
  4684. WBUFW(buf, 4)=status_get_lv(dst);
  4685. WBUFW(buf, 6)=status->size;
  4686. WBUFL(buf, 8)=status->hp;
  4687. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4688. +(battle_config.estimation_type&2?status->def2:0);
  4689. WBUFW(buf,14)=status->race;
  4690. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4691. +(battle_config.estimation_type&2?status->mdef2:0);
  4692. WBUFW(buf,18)= status->def_ele;
  4693. for(i=0;i<9;i++)
  4694. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4695. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4696. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4697. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4698. }
  4699. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4700. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4701. /// material id:
  4702. /// unused by the client
  4703. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4704. {
  4705. int i,c,view,fd;
  4706. nullpo_retv(sd);
  4707. if(sd->menuskill_id == skill_id)
  4708. return; //Avoid resending the menu twice or more times...
  4709. if( skill_id == GC_CREATENEWPOISON )
  4710. skill_id = GC_RESEARCHNEWPOISON;
  4711. fd=sd->fd;
  4712. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4713. WFIFOW(fd, 0)=0x18d;
  4714. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4715. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4716. ( ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4717. ){
  4718. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4719. WFIFOW(fd,c*8+ 4)= view;
  4720. else
  4721. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4722. WFIFOW(fd,c*8+ 6)= 0;
  4723. WFIFOW(fd,c*8+ 8)= 0;
  4724. WFIFOW(fd,c*8+10)= 0;
  4725. c++;
  4726. }
  4727. }
  4728. WFIFOW(fd, 2)=c*8+8;
  4729. WFIFOSET(fd,WFIFOW(fd,2));
  4730. if(c > 0) {
  4731. sd->menuskill_id = skill_id;
  4732. sd->menuskill_val = trigger;
  4733. return;
  4734. }
  4735. }
  4736. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4737. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4738. /// mk type:
  4739. /// 1 = cooking
  4740. /// 2 = arrow
  4741. /// 3 = elemental
  4742. /// 4 = GN_MIX_COOKING
  4743. /// 5 = GN_MAKEBOMB
  4744. /// 6 = GN_S_PHARMACY
  4745. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4746. {
  4747. int fd;
  4748. int i, c;
  4749. int view;
  4750. nullpo_retv(sd);
  4751. fd = sd->fd;
  4752. if(sd->menuskill_id == skill_id)
  4753. return; //Avoid resending the menu twice or more times...
  4754. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4755. WFIFOW(fd,0) = 0x25a;
  4756. WFIFOW(fd,4) = list_type; // list type
  4757. c = 0;
  4758. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4759. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4760. continue;
  4761. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4762. WFIFOW(fd, 6 + 2 * c) = view;
  4763. else
  4764. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4765. c++;
  4766. }
  4767. if( c > 0 || skill_id == AM_PHARMACY) {
  4768. sd->menuskill_id = skill_id;
  4769. sd->menuskill_val = trigger;
  4770. sd->menuskill_val2 = qty; // amount.
  4771. WFIFOW(fd,2) = 6 + 2 * c;
  4772. WFIFOSET(fd,WFIFOW(fd,2));
  4773. } else {
  4774. clif_menuskill_clear(sd);
  4775. #if PACKETVER >= 20090922
  4776. clif_msg_skill(sd,skill_id,0x625);
  4777. #else
  4778. WFIFOW(fd,2) = 6 + 2 * c;
  4779. WFIFOSET(fd,WFIFOW(fd,2));
  4780. #endif
  4781. }
  4782. }
  4783. /// Notifies clients of a status change.
  4784. /// 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)]
  4785. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4786. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4787. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4788. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4789. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4790. {
  4791. unsigned char buf[32];
  4792. struct map_session_data *sd;
  4793. if (type == SI_BLANK) //It shows nothing on the client...
  4794. return;
  4795. nullpo_retv(bl);
  4796. sd = BL_CAST(BL_PC, bl);
  4797. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4798. return;
  4799. #if PACKETVER >= 20120618
  4800. if(flag && battle_config.display_status_timers && sd)
  4801. WBUFW(buf,0)=0x983;
  4802. else
  4803. #elif PACKETVER >= 20090121
  4804. if(flag && battle_config.display_status_timers && sd)
  4805. WBUFW(buf,0)=0x43f;
  4806. else
  4807. #endif
  4808. WBUFW(buf,0)=0x196;
  4809. WBUFW(buf,2)=type;
  4810. WBUFL(buf,4)=bl->id;
  4811. WBUFB(buf,8)=flag;
  4812. #if PACKETVER >= 20120618
  4813. if(flag && battle_config.display_status_timers && sd) {
  4814. if (tick <= 0)
  4815. tick = 9999; // this is indeed what official servers do
  4816. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4817. WBUFL(buf,13)=tick;
  4818. WBUFL(buf,17) = val1;
  4819. WBUFL(buf,21) = val2;
  4820. WBUFL(buf,25) = val3;
  4821. }
  4822. #elif PACKETVER >= 20090121
  4823. if(flag && battle_config.display_status_timers && sd) {
  4824. if (tick <= 0)
  4825. tick = 9999; // this is indeed what official servers do
  4826. WBUFL(buf,9) = tick;
  4827. WBUFL(buf,13) = val1;
  4828. WBUFL(buf,17) = val2;
  4829. WBUFL(buf,21) = val3;
  4830. }
  4831. #endif
  4832. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4833. }
  4834. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4835. /// 008e <packet len>.W <message>.?B
  4836. void clif_displaymessage(const int fd, const char* mes)
  4837. {
  4838. nullpo_retv(mes);
  4839. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4840. if (fd == 0)
  4841. ;
  4842. else {
  4843. char *message, *line;
  4844. message = aStrdup(mes);
  4845. line = strtok(message, "\n");
  4846. while(line != NULL) {
  4847. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4848. int len = strnlen(line, 255);
  4849. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4850. WFIFOHEAD(fd, 5 + len);
  4851. WFIFOW(fd,0) = 0x8e;
  4852. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4853. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4854. WFIFOSET(fd, 5 + len);
  4855. }
  4856. line = strtok(NULL, "\n");
  4857. }
  4858. aFree(message);
  4859. }
  4860. }
  4861. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4862. /// 009a <packet len>.W <message>.?B
  4863. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4864. {
  4865. int lp = type ? 4 : 0;
  4866. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4867. WBUFW(buf,0) = 0x9a;
  4868. WBUFW(buf,2) = 4 + lp + len;
  4869. if (type == 0x10) // bc_blue
  4870. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4871. else if (type == 0x20) // bc_woe
  4872. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4873. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4874. clif_send(buf, WBUFW(buf,2), bl, target);
  4875. if (buf)
  4876. aFree(buf);
  4877. }
  4878. /*==========================================
  4879. * Displays a message on a 'bl' to all it's nearby clients
  4880. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4881. *------------------------------------------*/
  4882. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4883. char buf[100];
  4884. int len;
  4885. nullpo_retv(bl);
  4886. if(!message)
  4887. return;
  4888. len = strlen(message)+1;
  4889. if( len > sizeof(buf)-8 ) {
  4890. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4891. len = sizeof(buf)-8;
  4892. }
  4893. WBUFW(buf,0)=0x8d;
  4894. WBUFW(buf,2)=len+8;
  4895. WBUFL(buf,4)=bl->id;
  4896. safestrncpy((char *) WBUFP(buf,8),message,len);
  4897. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4898. }
  4899. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4900. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4901. 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)
  4902. {
  4903. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4904. WBUFW(buf,0) = 0x1c3;
  4905. WBUFW(buf,2) = len + 16;
  4906. WBUFL(buf,4) = fontColor;
  4907. WBUFW(buf,8) = fontType;
  4908. WBUFW(buf,10) = fontSize;
  4909. WBUFW(buf,12) = fontAlign;
  4910. WBUFW(buf,14) = fontY;
  4911. memcpy(WBUFP(buf,16), mes, len);
  4912. clif_send(buf, WBUFW(buf,2), bl, target);
  4913. if (buf)
  4914. aFree(buf);
  4915. }
  4916. /*
  4917. * Display *msg from *sd to all *users in channel
  4918. */
  4919. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4920. DBIterator *iter;
  4921. struct map_session_data *user;
  4922. unsigned short msg_len = strlen(msg) + 1;
  4923. WFIFOHEAD(sd->fd,msg_len + 12);
  4924. WFIFOW(sd->fd,0) = 0x2C1;
  4925. WFIFOW(sd->fd,2) = msg_len + 12;
  4926. WFIFOL(sd->fd,4) = 0;
  4927. WFIFOL(sd->fd,8) = Channel_Config.colors[color];
  4928. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4929. iter = db_iterator(channel->users);
  4930. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4931. if( user->fd == sd->fd )
  4932. continue;
  4933. WFIFOHEAD(user->fd,msg_len + 12);
  4934. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4935. WFIFOSET(user->fd, msg_len + 12);
  4936. }
  4937. dbi_destroy(iter);
  4938. WFIFOSET(sd->fd, msg_len + 12);
  4939. }
  4940. /// Displays heal effect (ZC_RECOVERY).
  4941. /// 013d <var id>.W <amount>.W
  4942. /// var id:
  4943. /// 5 = HP (SP_HP)
  4944. /// 7 = SP (SP_SP)
  4945. /// ? = ignored
  4946. void clif_heal(int fd,int type,int val)
  4947. {
  4948. WFIFOHEAD(fd,packet_len(0x13d));
  4949. WFIFOW(fd,0)=0x13d;
  4950. WFIFOW(fd,2)=type;
  4951. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4952. WFIFOSET(fd,packet_len(0x13d));
  4953. }
  4954. /// Displays resurrection effect (ZC_RESURRECTION).
  4955. /// 0148 <id>.L <type>.W
  4956. /// type:
  4957. /// ignored
  4958. void clif_resurrection(struct block_list *bl,int type)
  4959. {
  4960. unsigned char buf[16];
  4961. nullpo_retv(bl);
  4962. WBUFW(buf,0)=0x148;
  4963. WBUFL(buf,2)=bl->id;
  4964. WBUFW(buf,6)=0;
  4965. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4966. if (disguised(bl))
  4967. clif_spawn(bl);
  4968. }
  4969. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4970. /// 0199 <type>.W
  4971. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4972. {
  4973. int fd;
  4974. nullpo_retv(sd);
  4975. fd=sd->fd;
  4976. WFIFOHEAD(fd,packet_len(0x199));
  4977. WFIFOW(fd,0)=0x199;
  4978. WFIFOW(fd,2)=property;
  4979. WFIFOSET(fd,packet_len(0x199));
  4980. }
  4981. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  4982. #if PACKETVER >= 20130000
  4983. uint8 buf[8];
  4984. WBUFW(buf,0)=0x99b; //2
  4985. WBUFW(buf,2)=0x28; //2
  4986. WBUFB(buf,4) = ((map_flag_vs(bl->m))?0x01:0); //tvt ?
  4987. WBUFB(buf,4) |= ((map_flag_gvg(bl->m))?0x02:0); //gvg
  4988. WBUFB(buf,4) |= ((map_flag_gvg2(bl->m))?0x04:0); //siege
  4989. WBUFB(buf,4) |= ((map[bl->m].flag.nomineeffect)?0:0x08); //mineffect @FIXME what this do
  4990. WBUFB(buf,4) |= ((map[bl->m].flag.nolockon)?0x10:0); //nolockon 0x10 @FIXME what this do
  4991. WBUFB(buf,4) |= ((map[bl->m].flag.pvp)?0x20:0); //countpk
  4992. WBUFB(buf,4) |= 0; //nopartyformation 0x40
  4993. WBUFB(buf,4) |= ((map[bl->m].flag.battleground)?0x80:0); //battleground
  4994. WBUFB(buf,5) = ((map[bl->m].flag.noitemconsumption)?0x01:0); //noitemconsumption
  4995. WBUFB(buf,5) |= ((map[bl->m].flag.nousecart)?0:0x02); // usecart
  4996. WBUFB(buf,5) |= ((map[bl->m].flag.nosumstarmiracle)?0:0x04); //summonstarmiracle
  4997. // WBUFB(buf,5) |= RBUFB(buf,5)&0xf8; //sparebit[0-4]
  4998. WBUFW(buf,6) = 0; //sparebit [5-15], + extra[4]
  4999. clif_send(buf,packet_len(0x99b),bl,t);
  5000. #endif
  5001. }
  5002. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5003. /// 01d6 <type>.W
  5004. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5005. {
  5006. int fd;
  5007. nullpo_retv(sd);
  5008. fd=sd->fd;
  5009. WFIFOHEAD(fd,packet_len(0x1D6));
  5010. WFIFOW(fd,0)=0x1D6;
  5011. WFIFOW(fd,2)=type;
  5012. WFIFOSET(fd,packet_len(0x1D6));
  5013. }
  5014. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5015. /// 019a <id>.L <ranking>.L <total>.L
  5016. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5017. {
  5018. if(type == 2) {
  5019. int fd = sd->fd;
  5020. WFIFOHEAD(fd,packet_len(0x19a));
  5021. WFIFOW(fd,0) = 0x19a;
  5022. WFIFOL(fd,2) = sd->bl.id;
  5023. WFIFOL(fd,6) = pvprank;
  5024. WFIFOL(fd,10) = pvpnum;
  5025. WFIFOSET(fd,packet_len(0x19a));
  5026. } else {
  5027. unsigned char buf[32];
  5028. WBUFW(buf,0) = 0x19a;
  5029. WBUFL(buf,2) = sd->bl.id;
  5030. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5031. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5032. else
  5033. WBUFL(buf,6) = pvprank;
  5034. WBUFL(buf,10) = pvpnum;
  5035. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5036. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5037. else if(!type)
  5038. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5039. else
  5040. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5041. }
  5042. }
  5043. /*==========================================
  5044. *
  5045. *------------------------------------------*/
  5046. void clif_map_property_mapall(int map, enum map_property property)
  5047. {
  5048. struct block_list bl;
  5049. unsigned char buf[16];
  5050. bl.id = 0;
  5051. bl.type = BL_NUL;
  5052. bl.m = map;
  5053. WBUFW(buf,0)=0x199;
  5054. WBUFW(buf,2)=property;
  5055. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5056. }
  5057. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5058. /// 0188 <result>.W <index>.W <refine>.W
  5059. /// result:
  5060. /// 0 = success
  5061. /// 1 = failure
  5062. /// 2 = downgrade
  5063. void clif_refine(int fd, int fail, int index, int val)
  5064. {
  5065. WFIFOHEAD(fd,packet_len(0x188));
  5066. WFIFOW(fd,0)=0x188;
  5067. WFIFOW(fd,2)=fail;
  5068. WFIFOW(fd,4)=index+2;
  5069. WFIFOW(fd,6)=val;
  5070. WFIFOSET(fd,packet_len(0x188));
  5071. }
  5072. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5073. /// 0223 <result>.L <nameid>.W
  5074. /// result:
  5075. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5076. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5077. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5078. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5079. void clif_upgrademessage(int fd, int result, int item_id)
  5080. {
  5081. WFIFOHEAD(fd,packet_len(0x223));
  5082. WFIFOW(fd,0)=0x223;
  5083. WFIFOL(fd,2)=result;
  5084. WFIFOW(fd,6)=item_id;
  5085. WFIFOSET(fd,packet_len(0x223));
  5086. }
  5087. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5088. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5089. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5090. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5091. {
  5092. #if PACKETVER < 20091104
  5093. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5094. WFIFOW(fd,0) = 0x97;
  5095. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5096. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5097. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5098. WFIFOSET(fd,WFIFOW(fd,2));
  5099. #else
  5100. struct map_session_data *ssd = map_nick2sd(nick);
  5101. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5102. WFIFOW(fd,0) = 0x97;
  5103. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5104. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5105. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5106. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5107. WFIFOSET(fd,WFIFOW(fd,2));
  5108. #endif
  5109. }
  5110. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5111. /// 0098 <result>.B
  5112. /// result:
  5113. /// 0 = success to send wisper
  5114. /// 1 = target character is not loged in
  5115. /// 2 = ignored by target
  5116. /// 3 = everyone ignored by target
  5117. void clif_wis_end(int fd, int flag)
  5118. {
  5119. WFIFOHEAD(fd,packet_len(0x98));
  5120. WFIFOW(fd,0) = 0x98;
  5121. WFIFOW(fd,2) = flag;
  5122. WFIFOSET(fd,packet_len(0x98));
  5123. }
  5124. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5125. /// 0194 <char id>.L <name>.24B
  5126. void clif_solved_charname(int fd, int charid, const char* name)
  5127. {
  5128. WFIFOHEAD(fd,packet_len(0x194));
  5129. WFIFOW(fd,0)=0x194;
  5130. WFIFOL(fd,2)=charid;
  5131. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5132. WFIFOSET(fd,packet_len(0x194));
  5133. }
  5134. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5135. /// 017b <packet len>.W { <name id>.W }*
  5136. void clif_use_card(struct map_session_data *sd,int idx)
  5137. {
  5138. int i,c,ep;
  5139. int fd=sd->fd;
  5140. nullpo_retv(sd);
  5141. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5142. return;
  5143. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5144. return; //Avoid parsing invalid item indexes (no card/no item)
  5145. ep=sd->inventory_data[idx]->equip;
  5146. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5147. WFIFOW(fd,0)=0x17b;
  5148. for(i=c=0;i<MAX_INVENTORY;i++){
  5149. int j;
  5150. if(sd->inventory_data[i] == NULL)
  5151. continue;
  5152. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5153. continue;
  5154. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5155. continue;
  5156. if(sd->status.inventory[i].identify==0 ) //Not identified
  5157. continue;
  5158. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5159. continue;
  5160. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5161. continue;
  5162. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5163. if( j == sd->inventory_data[i]->slot ) // No room
  5164. continue;
  5165. WFIFOW(fd,4+c*2)=i+2;
  5166. c++;
  5167. }
  5168. WFIFOW(fd,2)=4+c*2;
  5169. WFIFOSET(fd,WFIFOW(fd,2));
  5170. }
  5171. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5172. /// 017d <equip index>.W <card index>.W <result>.B
  5173. /// result:
  5174. /// 0 = success
  5175. /// 1 = failure
  5176. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5177. {
  5178. int fd;
  5179. nullpo_retv(sd);
  5180. fd=sd->fd;
  5181. WFIFOHEAD(fd,packet_len(0x17d));
  5182. WFIFOW(fd,0)=0x17d;
  5183. WFIFOW(fd,2)=idx_equip+2;
  5184. WFIFOW(fd,4)=idx_card+2;
  5185. WFIFOB(fd,6)=flag;
  5186. WFIFOSET(fd,packet_len(0x17d));
  5187. }
  5188. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5189. /// 0177 <packet len>.W { <name id>.W }*
  5190. void clif_item_identify_list(struct map_session_data *sd)
  5191. {
  5192. int i,c;
  5193. int fd;
  5194. nullpo_retv(sd);
  5195. fd=sd->fd;
  5196. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5197. WFIFOW(fd,0)=0x177;
  5198. for(i=c=0;i<MAX_INVENTORY;i++){
  5199. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5200. WFIFOW(fd,c*2+4)=i+2;
  5201. c++;
  5202. }
  5203. }
  5204. if(c > 0) {
  5205. WFIFOW(fd,2)=c*2+4;
  5206. WFIFOSET(fd,WFIFOW(fd,2));
  5207. sd->menuskill_id = MC_IDENTIFY;
  5208. sd->menuskill_val = c;
  5209. }
  5210. }
  5211. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5212. /// 0179 <index>.W <result>.B
  5213. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5214. {
  5215. int fd;
  5216. nullpo_retv(sd);
  5217. fd=sd->fd;
  5218. WFIFOHEAD(fd,packet_len(0x179));
  5219. WFIFOW(fd, 0)=0x179;
  5220. WFIFOW(fd, 2)=idx+2;
  5221. WFIFOB(fd, 4)=flag;
  5222. WFIFOSET(fd,packet_len(0x179));
  5223. }
  5224. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5225. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5226. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5227. {
  5228. int i,c;
  5229. int fd;
  5230. int nameid;
  5231. nullpo_retv(sd);
  5232. nullpo_retv(dstsd);
  5233. fd=sd->fd;
  5234. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5235. WFIFOW(fd,0)=0x1fc;
  5236. for(i=c=0;i<MAX_INVENTORY;i++){
  5237. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5238. WFIFOW(fd,c*13+4) = i;
  5239. WFIFOW(fd,c*13+6) = nameid;
  5240. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5241. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5242. c++;
  5243. }
  5244. }
  5245. if(c > 0) {
  5246. WFIFOW(fd,2)=c*13+4;
  5247. WFIFOSET(fd,WFIFOW(fd,2));
  5248. sd->menuskill_id = BS_REPAIRWEAPON;
  5249. sd->menuskill_val = dstsd->bl.id;
  5250. sd->menuskill_val2 = lv;
  5251. }else
  5252. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5253. }
  5254. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5255. /// 01fe <index>.W <result>.B
  5256. /// index:
  5257. /// ignored (inventory index)
  5258. /// result:
  5259. /// 0 = Item repair success.
  5260. /// 1 = Item repair failure.
  5261. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5262. {
  5263. int fd;
  5264. nullpo_retv(sd);
  5265. fd = sd->fd;
  5266. WFIFOHEAD(fd,packet_len(0x1fe));
  5267. WFIFOW(fd, 0)=0x1fe;
  5268. WFIFOW(fd, 2)=idx+2;
  5269. WFIFOB(fd, 4)=flag;
  5270. WFIFOSET(fd,packet_len(0x1fe));
  5271. }
  5272. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5273. /// 02bb <equip location>.W <account id>.L
  5274. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5275. {
  5276. int fd = sd->fd;
  5277. WFIFOHEAD(fd,packet_len(0x2bb));
  5278. WFIFOW(fd,0) = 0x2bb;
  5279. WFIFOW(fd,2) = position;
  5280. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5281. WFIFOSET(fd,packet_len(0x2bb));
  5282. }
  5283. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5284. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5285. void clif_item_refine_list(struct map_session_data *sd)
  5286. {
  5287. int i,c;
  5288. int fd;
  5289. uint16 skill_lv;
  5290. int wlv;
  5291. int refine_item[5];
  5292. nullpo_retv(sd);
  5293. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5294. fd=sd->fd;
  5295. refine_item[0] = -1;
  5296. refine_item[1] = pc_search_inventory(sd,1010);
  5297. refine_item[2] = pc_search_inventory(sd,1011);
  5298. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5299. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5300. WFIFOW(fd,0)=0x221;
  5301. for(i=c=0;i<MAX_INVENTORY;i++){
  5302. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5303. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5304. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5305. WFIFOW(fd,c*13+ 4)=i+2;
  5306. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5307. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5308. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5309. c++;
  5310. }
  5311. }
  5312. WFIFOW(fd,2)=c*13+4;
  5313. WFIFOSET(fd,WFIFOW(fd,2));
  5314. if (c > 0) {
  5315. sd->menuskill_id = WS_WEAPONREFINE;
  5316. sd->menuskill_val = skill_lv;
  5317. }
  5318. }
  5319. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5320. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5321. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5322. {
  5323. int fd;
  5324. nullpo_retv(sd);
  5325. fd=sd->fd;
  5326. WFIFOHEAD(fd,packet_len(0x147));
  5327. WFIFOW(fd, 0)=0x147;
  5328. WFIFOW(fd, 2)=skill_id;
  5329. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5330. WFIFOW(fd, 6)=0;
  5331. WFIFOW(fd, 8)=skill_lv;
  5332. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5333. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5334. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5335. WFIFOB(fd,38)=0;
  5336. WFIFOSET(fd,packet_len(0x147));
  5337. }
  5338. /// Adds an item to character's cart.
  5339. /// 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)
  5340. /// 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)
  5341. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5342. {
  5343. int view,fd;
  5344. unsigned char *buf;
  5345. nullpo_retv(sd);
  5346. fd=sd->fd;
  5347. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5348. return;
  5349. #if PACKETVER < 5
  5350. WFIFOHEAD(fd,packet_len(0x124));
  5351. buf=WFIFOP(fd,0);
  5352. WBUFW(buf,0)=0x124;
  5353. WBUFW(buf,2)=n+2;
  5354. WBUFL(buf,4)=amount;
  5355. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5356. WBUFW(buf,8)=view;
  5357. else
  5358. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5359. WBUFB(buf,10)=sd->status.cart[n].identify;
  5360. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5361. WBUFB(buf,12)=sd->status.cart[n].refine;
  5362. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5363. WFIFOSET(fd,packet_len(0x124));
  5364. #else
  5365. WFIFOHEAD(fd,packet_len(0x1c5));
  5366. buf=WFIFOP(fd,0);
  5367. WBUFW(buf,0)=0x1c5;
  5368. WBUFW(buf,2)=n+2;
  5369. WBUFL(buf,4)=amount;
  5370. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5371. WBUFW(buf,8)=view;
  5372. else
  5373. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5374. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5375. WBUFB(buf,11)=sd->status.cart[n].identify;
  5376. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5377. WBUFB(buf,13)=sd->status.cart[n].refine;
  5378. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5379. WFIFOSET(fd,packet_len(0x1c5));
  5380. #endif
  5381. }
  5382. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5383. /* Acknowledge an item have been added to cart
  5384. * 012c <result>B
  5385. * result :
  5386. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5387. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5388. */
  5389. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5390. {
  5391. int fd;
  5392. unsigned char *buf;
  5393. nullpo_retv(sd);
  5394. fd = sd->fd;
  5395. buf = WFIFOP(fd,0);
  5396. WBUFW(buf,0) = 0x12c;
  5397. WBUFB(buf,2) = flag;
  5398. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5399. }
  5400. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5401. void clif_bank_open(struct map_session_data *sd){
  5402. int fd;
  5403. nullpo_retv(sd);
  5404. fd = sd->fd;
  5405. WFIFOHEAD(fd,4);
  5406. WFIFOW(fd,0) = 0x09b7;
  5407. WFIFOW(fd,2) = 0;
  5408. WFIFOSET(fd,4);
  5409. }
  5410. /*
  5411. * Request to Open the banking system
  5412. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5413. */
  5414. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5415. //TODO check if preventing trade or stuff like that
  5416. //also mark something in case char ain't available for saving, should we check now ?
  5417. nullpo_retv(sd);
  5418. if( !battle_config.feature_banking ) {
  5419. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5420. return;
  5421. }
  5422. else {
  5423. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5424. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5425. if(sd->status.account_id == aid){
  5426. sd->state.banking = 1;
  5427. //request save ?
  5428. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5429. //on succes open bank ?
  5430. clif_bank_open(sd);
  5431. }
  5432. }
  5433. }
  5434. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5435. void clif_bank_close(struct map_session_data *sd){
  5436. int fd;
  5437. nullpo_retv(sd);
  5438. fd = sd->fd;
  5439. WFIFOHEAD(fd,4);
  5440. WFIFOW(fd,0) = 0x09B9;
  5441. WFIFOW(fd,2) = 0;
  5442. WFIFOSET(fd,4);
  5443. }
  5444. /*
  5445. * Request to close the banking system
  5446. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5447. */
  5448. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5449. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5450. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5451. nullpo_retv(sd);
  5452. if( !battle_config.feature_banking ) {
  5453. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5454. //still allow to go trough to not stuck player if we have disable it while they was in
  5455. }
  5456. if(sd->status.account_id == aid){
  5457. sd->state.banking = 0;
  5458. clif_bank_close(sd);
  5459. }
  5460. }
  5461. /*
  5462. * Display how much we got in bank (I suppose)
  5463. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5464. */
  5465. void clif_Bank_Check(struct map_session_data* sd) {
  5466. unsigned char buf[13];
  5467. struct s_packet_db* info;
  5468. int16 len;
  5469. int cmd = 0;
  5470. nullpo_retv(sd);
  5471. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5472. if(!cmd) cmd = 0x09A6; //default
  5473. info = &packet_db[sd->packet_ver][cmd];
  5474. len = info->len;
  5475. if(!len) return; //version as packet disable
  5476. // sd->state.banking = 1; //mark opening and closing
  5477. WBUFW(buf,0) = cmd;
  5478. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5479. WBUFW(buf,info->pos[1]) = 0; //reason
  5480. clif_send(buf,len,&sd->bl,SELF);
  5481. }
  5482. /*
  5483. * Requesting the data in bank
  5484. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5485. */
  5486. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5487. nullpo_retv(sd);
  5488. if( !battle_config.feature_banking ) {
  5489. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5490. return;
  5491. }
  5492. else {
  5493. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5494. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5495. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5496. clif_Bank_Check(sd);
  5497. }
  5498. }
  5499. /*
  5500. * Acknowledge of deposit some money in bank
  5501. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5502. */
  5503. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5504. unsigned char buf[17];
  5505. struct s_packet_db* info;
  5506. int16 len;
  5507. int cmd =0;
  5508. nullpo_retv(sd);
  5509. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5510. if(!cmd) cmd = 0x09A8;
  5511. info = &packet_db[sd->packet_ver][cmd];
  5512. len = info->len;
  5513. if(!len) return; //version as packet disable
  5514. WBUFW(buf,0) = cmd;
  5515. WBUFW(buf,info->pos[0]) = (short)reason;
  5516. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5517. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5518. clif_send(buf,len,&sd->bl,SELF);
  5519. }
  5520. /*
  5521. * Request saving some money in bank
  5522. * @author : original [Yommy/Hercules]
  5523. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5524. */
  5525. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5526. nullpo_retv(sd);
  5527. if( !battle_config.feature_banking ) {
  5528. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5529. return;
  5530. }
  5531. else {
  5532. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5533. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5534. int money = RFIFOL(fd,info->pos[1]);
  5535. if(sd->status.account_id == aid){
  5536. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5537. clif_bank_deposit(sd,reason);
  5538. }
  5539. }
  5540. }
  5541. /*
  5542. * Acknowledge of withdrawing some money from bank
  5543. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5544. */
  5545. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5546. unsigned char buf[17];
  5547. struct s_packet_db* info;
  5548. int16 len;
  5549. int cmd;
  5550. nullpo_retv(sd);
  5551. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5552. if(!cmd) cmd = 0x09AA;
  5553. info = &packet_db[sd->packet_ver][cmd];
  5554. len = info->len;
  5555. if(!len) return; //version as packet disable
  5556. WBUFW(buf,0) = cmd;
  5557. WBUFW(buf,info->pos[0]) = (short)reason;
  5558. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5559. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5560. clif_send(buf,len,&sd->bl,SELF);
  5561. }
  5562. /*
  5563. * Request Withdrawing some money from bank
  5564. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5565. */
  5566. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5567. nullpo_retv(sd);
  5568. if( !battle_config.feature_banking ) {
  5569. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5570. return;
  5571. }
  5572. else {
  5573. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5574. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5575. int money = RFIFOL(fd,info->pos[1]);
  5576. if(sd->status.account_id == aid){
  5577. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5578. clif_bank_withdraw(sd,reason);
  5579. }
  5580. }
  5581. }
  5582. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5583. /// 0125 <index>.W <amount>.L
  5584. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5585. {
  5586. int fd;
  5587. nullpo_retv(sd);
  5588. fd=sd->fd;
  5589. WFIFOHEAD(fd,packet_len(0x125));
  5590. WFIFOW(fd,0)=0x125;
  5591. WFIFOW(fd,2)=n+2;
  5592. WFIFOL(fd,4)=amount;
  5593. WFIFOSET(fd,packet_len(0x125));
  5594. }
  5595. /// Opens the shop creation menu (ZC_OPENSTORE).
  5596. /// 012d <num>.W
  5597. /// num:
  5598. /// number of allowed item slots
  5599. void clif_openvendingreq(struct map_session_data* sd, int num)
  5600. {
  5601. int fd;
  5602. nullpo_retv(sd);
  5603. fd = sd->fd;
  5604. WFIFOHEAD(fd,packet_len(0x12d));
  5605. WFIFOW(fd,0) = 0x12d;
  5606. WFIFOW(fd,2) = num;
  5607. WFIFOSET(fd,packet_len(0x12d));
  5608. }
  5609. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5610. /// 0131 <owner id>.L <message>.80B
  5611. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5612. {
  5613. unsigned char buf[128];
  5614. nullpo_retv(bl);
  5615. WBUFW(buf,0) = 0x131;
  5616. WBUFL(buf,2) = bl->id;
  5617. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5618. if( fd ) {
  5619. WFIFOHEAD(fd,packet_len(0x131));
  5620. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5621. WFIFOSET(fd,packet_len(0x131));
  5622. } else {
  5623. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5624. }
  5625. }
  5626. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5627. /// 0132 <owner id>.L
  5628. void clif_closevendingboard(struct block_list* bl, int fd)
  5629. {
  5630. unsigned char buf[16];
  5631. nullpo_retv(bl);
  5632. WBUFW(buf,0) = 0x132;
  5633. WBUFL(buf,2) = bl->id;
  5634. if( fd ) {
  5635. WFIFOHEAD(fd,packet_len(0x132));
  5636. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5637. WFIFOSET(fd,packet_len(0x132));
  5638. } else {
  5639. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5640. }
  5641. }
  5642. /// Sends a list of items in a shop.
  5643. /// 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)
  5644. /// 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)
  5645. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5646. {
  5647. int i,fd;
  5648. int count;
  5649. struct map_session_data* vsd;
  5650. #if PACKETVER < 20100105
  5651. const int cmd = 0x133;
  5652. const int offset = 8;
  5653. #else
  5654. const int cmd = 0x800;
  5655. const int offset = 12;
  5656. #endif
  5657. nullpo_retv(sd);
  5658. nullpo_retv(vending);
  5659. nullpo_retv(vsd=map_id2sd(id));
  5660. fd = sd->fd;
  5661. count = vsd->vend_num;
  5662. WFIFOHEAD(fd, offset+count*22);
  5663. WFIFOW(fd,0) = cmd;
  5664. WFIFOW(fd,2) = offset+count*22;
  5665. WFIFOL(fd,4) = id;
  5666. #if PACKETVER >= 20100105
  5667. WFIFOL(fd,8) = vsd->vender_id;
  5668. #endif
  5669. for( i = 0; i < count; i++ )
  5670. {
  5671. int index = vending[i].index;
  5672. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5673. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5674. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5675. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5676. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5677. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5678. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5679. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5680. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5681. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5682. }
  5683. WFIFOSET(fd,WFIFOW(fd,2));
  5684. }
  5685. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5686. /// 0135 <index>.W <amount>.W <result>.B
  5687. /// result:
  5688. /// 0 = success
  5689. /// 1 = not enough zeny
  5690. /// 2 = overweight
  5691. /// 4 = out of stock
  5692. /// 5 = "cannot use an npc shop while in a trade"
  5693. /// 6 = Because the store information was incorrect the item was not purchased.
  5694. /// 7 = No sales information.
  5695. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5696. {
  5697. int fd;
  5698. nullpo_retv(sd);
  5699. fd = sd->fd;
  5700. WFIFOHEAD(fd,packet_len(0x135));
  5701. WFIFOW(fd,0) = 0x135;
  5702. WFIFOW(fd,2) = index+2;
  5703. WFIFOW(fd,4) = amount;
  5704. WFIFOB(fd,6) = fail;
  5705. WFIFOSET(fd,packet_len(0x135));
  5706. }
  5707. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5708. /// 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 }*
  5709. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5710. {
  5711. int i,fd;
  5712. int count;
  5713. nullpo_retv(sd);
  5714. fd = sd->fd;
  5715. count = sd->vend_num;
  5716. WFIFOHEAD(fd, 8+count*22);
  5717. WFIFOW(fd,0) = 0x136;
  5718. WFIFOW(fd,2) = 8+count*22;
  5719. WFIFOL(fd,4) = id;
  5720. for( i = 0; i < count; i++ ) {
  5721. int index = vending[i].index;
  5722. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5723. WFIFOL(fd, 8+i*22) = vending[i].value;
  5724. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5725. WFIFOW(fd,14+i*22) = vending[i].amount;
  5726. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5727. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5728. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5729. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5730. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5731. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5732. }
  5733. WFIFOSET(fd,WFIFOW(fd,2));
  5734. }
  5735. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5736. /// 0137 <index>.W <amount>.W
  5737. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5738. {
  5739. int fd;
  5740. nullpo_retv(sd);
  5741. fd = sd->fd;
  5742. WFIFOHEAD(fd,packet_len(0x137));
  5743. WFIFOW(fd,0) = 0x137;
  5744. WFIFOW(fd,2) = index+2;
  5745. WFIFOW(fd,4) = amount;
  5746. WFIFOSET(fd,packet_len(0x137));
  5747. }
  5748. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5749. /// 00fa <result>.B
  5750. /// result:
  5751. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5752. /// 1 = MsgStringTable[78]="party name already exists"
  5753. /// 2 = MsgStringTable[79]="already in a party"
  5754. /// 3 = cannot organize parties on this map
  5755. /// ? = nothing
  5756. void clif_party_created(struct map_session_data *sd,int result)
  5757. {
  5758. int fd;
  5759. nullpo_retv(sd);
  5760. fd=sd->fd;
  5761. WFIFOHEAD(fd,packet_len(0xfa));
  5762. WFIFOW(fd,0)=0xfa;
  5763. WFIFOB(fd,2)=result;
  5764. WFIFOSET(fd,packet_len(0xfa));
  5765. }
  5766. /// Adds new member to a party.
  5767. /// 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)
  5768. /// 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)
  5769. /// role:
  5770. /// 0 = leader
  5771. /// 1 = normal
  5772. /// state:
  5773. /// 0 = connected
  5774. /// 1 = disconnected
  5775. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5776. {
  5777. unsigned char buf[81];
  5778. int i;
  5779. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5780. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5781. } else {
  5782. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5783. }
  5784. if (i >= MAX_PARTY) return; //Should never happen...
  5785. sd = p->data[i].sd;
  5786. WBUFW(buf, 0) = 0x1e9;
  5787. WBUFL(buf, 2) = sd->status.account_id;
  5788. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5789. WBUFW(buf,10) = sd->bl.x;
  5790. WBUFW(buf,12) = sd->bl.y;
  5791. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5792. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5793. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5794. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5795. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5796. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5797. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5798. }
  5799. /// Sends party information (ZC_GROUP_LIST).
  5800. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5801. /// role:
  5802. /// 0 = leader
  5803. /// 1 = normal
  5804. /// state:
  5805. /// 0 = connected
  5806. /// 1 = disconnected
  5807. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5808. {
  5809. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5810. struct map_session_data* party_sd = NULL;
  5811. int i, c;
  5812. nullpo_retv(p);
  5813. WBUFW(buf,0) = 0xfb;
  5814. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5815. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5816. {
  5817. struct party_member* m = &p->party.member[i];
  5818. if(!m->account_id) continue;
  5819. if(party_sd == NULL) party_sd = p->data[i].sd;
  5820. WBUFL(buf,28+c*46) = m->account_id;
  5821. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5822. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5823. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5824. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5825. c++;
  5826. }
  5827. WBUFW(buf,2) = 28+c*46;
  5828. if(sd) { // send only to self
  5829. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5830. } else if (party_sd) { // send to whole party
  5831. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5832. }
  5833. }
  5834. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5835. /// 02c9 <flag>.B
  5836. /// flag:
  5837. /// 0 = allow party invites
  5838. /// 1 = auto-deny party invites
  5839. void clif_partyinvitationstate(struct map_session_data* sd)
  5840. {
  5841. int fd;
  5842. nullpo_retv(sd);
  5843. fd = sd->fd;
  5844. WFIFOHEAD(fd, packet_len(0x2c9));
  5845. WFIFOW(fd, 0) = 0x2c9;
  5846. WFIFOB(fd, 2) = 0; // not implemented
  5847. WFIFOSET(fd, packet_len(0x2c9));
  5848. }
  5849. /// Party invitation request.
  5850. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5851. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5852. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5853. {
  5854. #if PACKETVER < 20070821
  5855. const int cmd = 0xfe;
  5856. #else
  5857. const int cmd = 0x2c6;
  5858. #endif
  5859. int fd;
  5860. struct party_data *p;
  5861. nullpo_retv(sd);
  5862. nullpo_retv(tsd);
  5863. fd=tsd->fd;
  5864. if( (p=party_search(sd->status.party_id))==NULL )
  5865. return;
  5866. WFIFOHEAD(fd,packet_len(cmd));
  5867. WFIFOW(fd,0)=cmd;
  5868. WFIFOL(fd,2)=sd->status.party_id;
  5869. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5870. WFIFOSET(fd,packet_len(cmd));
  5871. }
  5872. /// Party invite result.
  5873. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5874. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5875. /// result=0 : char is already in a party -> MsgStringTable[80]
  5876. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5877. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5878. /// result=3 : party is full -> MsgStringTable[83]
  5879. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5880. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5881. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5882. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5883. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5884. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5885. {
  5886. int fd;
  5887. nullpo_retv(sd);
  5888. fd=sd->fd;
  5889. #if PACKETVER < 20070904
  5890. if( result == 7 ) {
  5891. clif_displaymessage(fd, msg_txt(sd,3));
  5892. return;
  5893. }
  5894. #endif
  5895. #if PACKETVER < 20070821
  5896. WFIFOHEAD(fd,packet_len(0xfd));
  5897. WFIFOW(fd,0) = 0xfd;
  5898. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5899. WFIFOB(fd,26) = result;
  5900. WFIFOSET(fd,packet_len(0xfd));
  5901. #else
  5902. WFIFOHEAD(fd,packet_len(0x2c5));
  5903. WFIFOW(fd,0) = 0x2c5;
  5904. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5905. WFIFOL(fd,26) = result;
  5906. WFIFOSET(fd,packet_len(0x2c5));
  5907. #endif
  5908. }
  5909. /// Updates party settings.
  5910. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5911. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5912. /// exp option:
  5913. /// 0 = exp sharing disabled
  5914. /// 1 = exp sharing enabled
  5915. /// 2 = cannot change exp sharing
  5916. ///
  5917. /// flag:
  5918. /// 0 = send to party
  5919. /// 1 = send to sd
  5920. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5921. {
  5922. unsigned char buf[16];
  5923. #if PACKETVER < 20090603
  5924. const int cmd = 0x101;
  5925. #else
  5926. const int cmd = 0x7d8;
  5927. #endif
  5928. nullpo_retv(p);
  5929. if(!sd && flag==0){
  5930. int i;
  5931. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5932. if (i < MAX_PARTY)
  5933. sd = p->data[i].sd;
  5934. }
  5935. if(!sd) return;
  5936. WBUFW(buf,0)=cmd;
  5937. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5938. #if PACKETVER >= 20090603
  5939. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5940. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5941. #endif
  5942. if(flag==0)
  5943. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5944. else
  5945. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5946. }
  5947. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5948. /// result:
  5949. /// 0 = leave
  5950. /// 1 = expel
  5951. /// 2 = cannot leave party on this map
  5952. /// 3 = cannot expel from party on this map
  5953. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5954. {
  5955. unsigned char buf[64];
  5956. nullpo_retv(p);
  5957. if(!sd && (flag&0xf0)==0)
  5958. {
  5959. int i;
  5960. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5961. if (i < MAX_PARTY)
  5962. sd = p->data[i].sd;
  5963. }
  5964. if(!sd) return;
  5965. WBUFW(buf,0)=0x105;
  5966. WBUFL(buf,2)=account_id;
  5967. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5968. WBUFB(buf,30)=flag&0x0f;
  5969. if((flag&0xf0)==0)
  5970. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5971. else
  5972. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5973. }
  5974. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5975. /// 0109 <packet len>.W <account id>.L <message>.?B
  5976. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5977. {
  5978. struct map_session_data *sd;
  5979. int i;
  5980. nullpo_retv(p);
  5981. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5982. if(i < MAX_PARTY){
  5983. unsigned char buf[1024];
  5984. if( len > sizeof(buf)-8 )
  5985. {
  5986. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  5987. len = sizeof(buf)-8;
  5988. }
  5989. sd = p->data[i].sd;
  5990. WBUFW(buf,0)=0x109;
  5991. WBUFW(buf,2)=len+8;
  5992. WBUFL(buf,4)=account_id;
  5993. safestrncpy((char *)WBUFP(buf,8), mes, len);
  5994. clif_send(buf,len+8,&sd->bl,PARTY);
  5995. }
  5996. }
  5997. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5998. /// 0107 <account id>.L <x>.W <y>.W
  5999. void clif_party_xy(struct map_session_data *sd)
  6000. {
  6001. unsigned char buf[16];
  6002. nullpo_retv(sd);
  6003. WBUFW(buf,0)=0x107;
  6004. WBUFL(buf,2)=sd->status.account_id;
  6005. WBUFW(buf,6)=sd->bl.x;
  6006. WBUFW(buf,8)=sd->bl.y;
  6007. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6008. }
  6009. /*==========================================
  6010. * Sends x/y dot to a single fd. [Skotlex]
  6011. *------------------------------------------*/
  6012. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6013. {
  6014. WFIFOHEAD(fd,packet_len(0x107));
  6015. WFIFOW(fd,0)=0x107;
  6016. WFIFOL(fd,2)=sd->status.account_id;
  6017. WFIFOW(fd,6)=sd->bl.x;
  6018. WFIFOW(fd,8)=sd->bl.y;
  6019. WFIFOSET(fd,packet_len(0x107));
  6020. }
  6021. /// Updates HP bar of a party member.
  6022. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6023. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6024. void clif_party_hp(struct map_session_data *sd)
  6025. {
  6026. unsigned char buf[16];
  6027. #if PACKETVER < 20100126
  6028. const int cmd = 0x106;
  6029. #else
  6030. const int cmd = 0x80e;
  6031. #endif
  6032. nullpo_retv(sd);
  6033. WBUFW(buf,0)=cmd;
  6034. WBUFL(buf,2)=sd->status.account_id;
  6035. #if PACKETVER < 20100126
  6036. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6037. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6038. WBUFW(buf,8) = 100;
  6039. } else {
  6040. WBUFW(buf,6) = sd->battle_status.hp;
  6041. WBUFW(buf,8) = sd->battle_status.max_hp;
  6042. }
  6043. #else
  6044. WBUFL(buf,6) = sd->battle_status.hp;
  6045. WBUFL(buf,10) = sd->battle_status.max_hp;
  6046. #endif
  6047. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6048. }
  6049. /*==========================================
  6050. * Sends HP bar to a single fd. [Skotlex]
  6051. *------------------------------------------*/
  6052. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6053. {
  6054. #if PACKETVER < 20100126
  6055. const int cmd = 0x106;
  6056. #else
  6057. const int cmd = 0x80e;
  6058. #endif
  6059. WFIFOHEAD(fd,packet_len(cmd));
  6060. WFIFOW(fd,0) = cmd;
  6061. WFIFOL(fd,2) = id;
  6062. #if PACKETVER < 20100126
  6063. if( maxhp > INT16_MAX )
  6064. {// To correctly display the %hp bar. [Skotlex]
  6065. WFIFOW(fd,6) = hp/(maxhp/100);
  6066. WFIFOW(fd,8) = 100;
  6067. } else {
  6068. WFIFOW(fd,6) = hp;
  6069. WFIFOW(fd,8) = maxhp;
  6070. }
  6071. #else
  6072. WFIFOL(fd,6) = hp;
  6073. WFIFOL(fd,10) = maxhp;
  6074. #endif
  6075. WFIFOSET(fd, packet_len(cmd));
  6076. }
  6077. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6078. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6079. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6080. {
  6081. int fd;
  6082. nullpo_retv(sd);
  6083. nullpo_retv(bl);
  6084. fd=sd->fd;
  6085. WFIFOHEAD(fd,packet_len(0x139));
  6086. WFIFOW(fd, 0)=0x139;
  6087. WFIFOL(fd, 2)=bl->id;
  6088. WFIFOW(fd, 6)=bl->x;
  6089. WFIFOW(fd, 8)=bl->y;
  6090. WFIFOW(fd,10)=sd->bl.x;
  6091. WFIFOW(fd,12)=sd->bl.y;
  6092. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6093. WFIFOSET(fd,packet_len(0x139));
  6094. }
  6095. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6096. /// 018f <result>.W <name id>.W
  6097. /// result:
  6098. /// 0 = success
  6099. /// 1 = failure
  6100. /// 2 = success (alchemist)
  6101. /// 3 = failure (alchemist)
  6102. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  6103. {
  6104. int view,fd;
  6105. nullpo_retv(sd);
  6106. fd = sd->fd;
  6107. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6108. WFIFOHEAD(fd,packet_len(0x18f));
  6109. WFIFOW(fd, 0)=0x18f;
  6110. WFIFOW(fd, 2)=flag;
  6111. if((view = itemdb_viewid(nameid)) > 0)
  6112. WFIFOW(fd, 4)=view;
  6113. else
  6114. WFIFOW(fd, 4)=nameid;
  6115. WFIFOSET(fd,packet_len(0x18f));
  6116. }
  6117. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6118. /// 019e
  6119. void clif_catch_process(struct map_session_data *sd)
  6120. {
  6121. int fd;
  6122. nullpo_retv(sd);
  6123. fd=sd->fd;
  6124. WFIFOHEAD(fd,packet_len(0x19e));
  6125. WFIFOW(fd,0)=0x19e;
  6126. WFIFOSET(fd,packet_len(0x19e));
  6127. }
  6128. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6129. /// 01a0 <result>.B
  6130. /// 0 = failure
  6131. /// 1 = success
  6132. void clif_pet_roulette(struct map_session_data *sd,int data)
  6133. {
  6134. int fd;
  6135. nullpo_retv(sd);
  6136. fd=sd->fd;
  6137. WFIFOHEAD(fd,packet_len(0x1a0));
  6138. WFIFOW(fd,0)=0x1a0;
  6139. WFIFOB(fd,2)=data;
  6140. WFIFOSET(fd,packet_len(0x1a0));
  6141. }
  6142. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6143. /// 01a6 <packet len>.W { <index>.W }*
  6144. void clif_sendegg(struct map_session_data *sd)
  6145. {
  6146. int i,n=0,fd;
  6147. nullpo_retv(sd);
  6148. fd=sd->fd;
  6149. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6150. clif_displaymessage(fd, msg_txt(sd,666));
  6151. return;
  6152. }
  6153. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6154. WFIFOW(fd,0)=0x1a6;
  6155. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6156. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6157. sd->inventory_data[i]->type!=IT_PETEGG ||
  6158. sd->status.inventory[i].amount<=0)
  6159. continue;
  6160. WFIFOW(fd,n*2+4)=i+2;
  6161. n++;
  6162. }
  6163. WFIFOW(fd,2)=4+n*2;
  6164. WFIFOSET(fd,WFIFOW(fd,2));
  6165. sd->menuskill_id = SA_TAMINGMONSTER;
  6166. sd->menuskill_val = -1;
  6167. }
  6168. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6169. /// 01a4 <type>.B <id>.L <data>.L
  6170. /// type:
  6171. /// 0 = pre-init (data = 0)
  6172. /// 1 = intimacy (data = 0~4)
  6173. /// 2 = hunger (data = 0~4)
  6174. /// 3 = accessory
  6175. /// 4 = performance (data = 1~3: normal, 4: special)
  6176. /// 5 = hairstyle
  6177. ///
  6178. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6179. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6180. {
  6181. uint8 buf[16];
  6182. nullpo_retv(pd);
  6183. WBUFW(buf,0) = 0x1a4;
  6184. WBUFB(buf,2) = type;
  6185. WBUFL(buf,3) = pd->bl.id;
  6186. WBUFL(buf,7) = param;
  6187. if (sd)
  6188. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6189. else
  6190. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6191. }
  6192. /// Pet's base data (ZC_PROPERTY_PET).
  6193. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6194. void clif_send_petstatus(struct map_session_data *sd)
  6195. {
  6196. int fd;
  6197. struct s_pet *pet;
  6198. nullpo_retv(sd);
  6199. nullpo_retv(sd->pd);
  6200. fd=sd->fd;
  6201. pet = &sd->pd->pet;
  6202. WFIFOHEAD(fd,packet_len(0x1a2));
  6203. WFIFOW(fd,0)=0x1a2;
  6204. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6205. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6206. WFIFOW(fd,27)=pet->level;
  6207. WFIFOW(fd,29)=pet->hungry;
  6208. WFIFOW(fd,31)=pet->intimate;
  6209. WFIFOW(fd,33)=pet->equip;
  6210. #if PACKETVER >= 20081126
  6211. WFIFOW(fd,35)=pet->class_;
  6212. #endif
  6213. WFIFOSET(fd,packet_len(0x1a2));
  6214. }
  6215. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6216. /// 01aa <id>.L <data>.L
  6217. /// data:
  6218. /// @see CZ_PET_ACT.
  6219. void clif_pet_emotion(struct pet_data *pd,int param)
  6220. {
  6221. unsigned char buf[16];
  6222. nullpo_retv(pd);
  6223. memset(buf,0,packet_len(0x1aa));
  6224. WBUFW(buf,0)=0x1aa;
  6225. WBUFL(buf,2)=pd->bl.id;
  6226. if(param >= 100 && pd->petDB->talk_convert_class) {
  6227. if(pd->petDB->talk_convert_class < 0)
  6228. return;
  6229. else if(pd->petDB->talk_convert_class > 0) {
  6230. // replace mob_id component of talk/act data
  6231. param -= (pd->pet.class_ - 100)*100;
  6232. param += (pd->petDB->talk_convert_class - 100)*100;
  6233. }
  6234. }
  6235. WBUFL(buf,6)=param;
  6236. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6237. }
  6238. /// Result of request to feed a pet (ZC_FEED_PET).
  6239. /// 01a3 <result>.B <name id>.W
  6240. /// result:
  6241. /// 0 = failure
  6242. /// 1 = success
  6243. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6244. {
  6245. int fd;
  6246. nullpo_retv(sd);
  6247. fd=sd->fd;
  6248. WFIFOHEAD(fd,packet_len(0x1a3));
  6249. WFIFOW(fd,0)=0x1a3;
  6250. WFIFOB(fd,2)=fail;
  6251. WFIFOW(fd,3)=foodid;
  6252. WFIFOSET(fd,packet_len(0x1a3));
  6253. }
  6254. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6255. /// 01cd { <skill id>.L }*7
  6256. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6257. {
  6258. int fd;
  6259. nullpo_retv(sd);
  6260. fd=sd->fd;
  6261. WFIFOHEAD(fd,packet_len(0x1cd));
  6262. WFIFOW(fd, 0)=0x1cd;
  6263. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6264. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6265. else
  6266. WFIFOL(fd,2)= 0x00000000;
  6267. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6268. WFIFOL(fd,6)= MG_COLDBOLT;
  6269. else
  6270. WFIFOL(fd,6)= 0x00000000;
  6271. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6272. WFIFOL(fd,10)= MG_FIREBOLT;
  6273. else
  6274. WFIFOL(fd,10)= 0x00000000;
  6275. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6276. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6277. else
  6278. WFIFOL(fd,14)= 0x00000000;
  6279. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6280. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6281. else
  6282. WFIFOL(fd,18)= 0x00000000;
  6283. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6284. WFIFOL(fd,22)= MG_FIREBALL;
  6285. else
  6286. WFIFOL(fd,22)= 0x00000000;
  6287. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6288. WFIFOL(fd,26)= MG_FROSTDIVER;
  6289. else
  6290. WFIFOL(fd,26)= 0x00000000;
  6291. WFIFOSET(fd,packet_len(0x1cd));
  6292. sd->menuskill_id = SA_AUTOSPELL;
  6293. sd->menuskill_val = skill_lv;
  6294. }
  6295. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6296. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6297. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6298. {
  6299. unsigned char buf[56];
  6300. nullpo_retv(src);
  6301. memset(buf,0,packet_len(0x1cf));
  6302. WBUFW(buf,0) = 0x1cf;
  6303. WBUFL(buf,2) = src->id;
  6304. if( src->type == BL_MER )
  6305. {
  6306. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6307. if( md && md->master && md->devotion_flag )
  6308. WBUFL(buf,6) = md->master->bl.id;
  6309. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6310. }
  6311. else
  6312. {
  6313. int i;
  6314. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6315. if( sd == NULL )
  6316. return;
  6317. for( i = 0; i < 5; i++ )
  6318. WBUFL(buf,6+4*i) = sd->devotion[i];
  6319. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6320. }
  6321. if( tsd )
  6322. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6323. else
  6324. clif_send(buf, packet_len(0x1cf), src, AREA);
  6325. }
  6326. /*==========================================
  6327. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6328. * Notifies clients in an area of an object's spirits.
  6329. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6330. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6331. *------------------------------------------*/
  6332. void clif_spiritball(struct block_list *bl) {
  6333. unsigned char buf[16];
  6334. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6335. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6336. nullpo_retv(bl);
  6337. WBUFW(buf, 0) = 0x1d0;
  6338. WBUFL(buf, 2) = bl->id;
  6339. WBUFW(buf, 6) = 0; //init to 0
  6340. switch(bl->type){
  6341. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6342. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6343. }
  6344. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6345. }
  6346. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6347. /// 01d2 <account id>.L <delay>.L
  6348. void clif_combo_delay(struct block_list *bl,int wait)
  6349. {
  6350. unsigned char buf[32];
  6351. nullpo_retv(bl);
  6352. WBUFW(buf,0)=0x1d2;
  6353. WBUFL(buf,2)=bl->id;
  6354. WBUFL(buf,6)=wait;
  6355. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6356. }
  6357. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6358. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6359. /// flag:
  6360. /// 0 = inactive
  6361. /// 1 = active
  6362. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6363. {
  6364. unsigned char buf[32];
  6365. nullpo_retv(src);
  6366. WBUFW(buf,0)=0x1d1;
  6367. WBUFL(buf,2)=src->id;
  6368. WBUFL(buf,6)=dst_id;
  6369. WBUFL(buf,10)=active;
  6370. clif_send(buf,packet_len(0x1d1),src,AREA);
  6371. }
  6372. /// MVP effect (ZC_MVP).
  6373. /// 010c <account id>.L
  6374. void clif_mvp_effect(struct map_session_data *sd)
  6375. {
  6376. unsigned char buf[16];
  6377. nullpo_retv(sd);
  6378. WBUFW(buf,0)=0x10c;
  6379. WBUFL(buf,2)=sd->bl.id;
  6380. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6381. }
  6382. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6383. /// 010a <name id>.W
  6384. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6385. {
  6386. int view,fd;
  6387. nullpo_retv(sd);
  6388. fd=sd->fd;
  6389. WFIFOHEAD(fd,packet_len(0x10a));
  6390. WFIFOW(fd,0)=0x10a;
  6391. if((view = itemdb_viewid(nameid)) > 0)
  6392. WFIFOW(fd,2)=view;
  6393. else
  6394. WFIFOW(fd,2)=nameid;
  6395. WFIFOSET(fd,packet_len(0x10a));
  6396. }
  6397. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6398. /// 010b <exp>.L
  6399. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6400. {
  6401. int fd;
  6402. nullpo_retv(sd);
  6403. fd=sd->fd;
  6404. WFIFOHEAD(fd,packet_len(0x10b));
  6405. WFIFOW(fd,0)=0x10b;
  6406. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6407. WFIFOSET(fd,packet_len(0x10b));
  6408. }
  6409. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6410. /// 010d
  6411. ///
  6412. /// "You are the MVP, but cannot obtain the reward because
  6413. /// you are overweight."
  6414. void clif_mvp_noitem(struct map_session_data* sd)
  6415. {
  6416. int fd = sd->fd;
  6417. WFIFOHEAD(fd,packet_len(0x10d));
  6418. WFIFOW(fd,0) = 0x10d;
  6419. WFIFOSET(fd,packet_len(0x10d));
  6420. }
  6421. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6422. /// 0167 <result>.B
  6423. /// result:
  6424. /// 0 = "Guild has been created."
  6425. /// 1 = "You are already in a Guild."
  6426. /// 2 = "That Guild Name already exists."
  6427. /// 3 = "You need the neccessary item to create a Guild."
  6428. void clif_guild_created(struct map_session_data *sd,int flag)
  6429. {
  6430. int fd;
  6431. nullpo_retv(sd);
  6432. fd=sd->fd;
  6433. WFIFOHEAD(fd,packet_len(0x167));
  6434. WFIFOW(fd,0)=0x167;
  6435. WFIFOB(fd,2)=flag;
  6436. WFIFOSET(fd,packet_len(0x167));
  6437. }
  6438. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6439. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6440. /// mode:
  6441. /// &0x01 = allow invite
  6442. /// &0x10 = allow expel
  6443. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6444. {
  6445. int ps,fd;
  6446. nullpo_retv(sd);
  6447. nullpo_retv(g);
  6448. fd=sd->fd;
  6449. ps=guild_getposition(g,sd);
  6450. WFIFOHEAD(fd,packet_len(0x16c));
  6451. WFIFOW(fd,0)=0x16c;
  6452. WFIFOL(fd,2)=g->guild_id;
  6453. WFIFOL(fd,6)=g->emblem_id;
  6454. WFIFOL(fd,10)=g->position[ps].mode;
  6455. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6456. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6457. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6458. WFIFOSET(fd,packet_len(0x16c));
  6459. }
  6460. /// Guild member login notice.
  6461. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6462. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6463. /// status:
  6464. /// 0 = offline
  6465. /// 1 = online
  6466. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6467. {
  6468. unsigned char buf[64];
  6469. struct map_session_data* sd;
  6470. nullpo_retv(g);
  6471. WBUFW(buf, 0)=0x1f2;
  6472. WBUFL(buf, 2)=g->member[idx].account_id;
  6473. WBUFL(buf, 6)=g->member[idx].char_id;
  6474. WBUFL(buf,10)=flag;
  6475. if( ( sd = g->member[idx].sd ) != NULL )
  6476. {
  6477. WBUFW(buf,14) = sd->status.sex;
  6478. WBUFW(buf,16) = sd->status.hair;
  6479. WBUFW(buf,18) = sd->status.hair_color;
  6480. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6481. }
  6482. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6483. {
  6484. WBUFW(buf,14) = 0;
  6485. WBUFW(buf,16) = 0;
  6486. WBUFW(buf,18) = 0;
  6487. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6488. }
  6489. }
  6490. // Function `clif_guild_memberlogin_notice` sends info about
  6491. // logins and logouts of a guild member to the rest members.
  6492. // But at the 1st time (after a player login or map changing)
  6493. // the client won't show the message.
  6494. // So I suggest use this function for sending "first-time-info"
  6495. // to some player on entering the game or changing location.
  6496. // At next time the client would always show the message.
  6497. // The function sends all the statuses in the single packet
  6498. // to economize traffic. [LuzZza]
  6499. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6500. {
  6501. struct guild *g;
  6502. unsigned char buf[14*128];
  6503. int i, count=0, p_len;
  6504. nullpo_retv(sd);
  6505. p_len = packet_len(0x16d);
  6506. if(!(g = sd->guild))
  6507. return;
  6508. for(i=0; i<g->max_member; i++) {
  6509. if(g->member[i].account_id > 0 &&
  6510. g->member[i].account_id != sd->status.account_id) {
  6511. WBUFW(buf,count*p_len) = 0x16d;
  6512. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6513. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6514. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6515. count++;
  6516. }
  6517. }
  6518. clif_send(buf, p_len*count, &sd->bl, SELF);
  6519. }
  6520. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6521. /// 014e <menu flag>.L
  6522. /// menu flag:
  6523. /// 0x00 = Basic Info (always on)
  6524. /// &0x01 = Member manager
  6525. /// &0x02 = Positions
  6526. /// &0x04 = Skills
  6527. /// &0x10 = Expulsion list
  6528. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6529. /// &0x80 = Notice
  6530. void clif_guild_masterormember(struct map_session_data *sd)
  6531. {
  6532. int fd;
  6533. nullpo_retv(sd);
  6534. fd=sd->fd;
  6535. WFIFOHEAD(fd,packet_len(0x14e));
  6536. WFIFOW(fd,0) = 0x14e;
  6537. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6538. WFIFOSET(fd,packet_len(0x14e));
  6539. }
  6540. /// Guild basic information (Territories [Valaris])
  6541. /// 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)
  6542. /// 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)
  6543. void clif_guild_basicinfo(struct map_session_data *sd) {
  6544. int fd;
  6545. struct guild *g;
  6546. nullpo_retv(sd);
  6547. fd = sd->fd;
  6548. if( (g = sd->guild) == NULL )
  6549. return;
  6550. WFIFOHEAD(fd,packet_len(0x1b6));
  6551. WFIFOW(fd, 0)=0x1b6;//0x150;
  6552. WFIFOL(fd, 2)=g->guild_id;
  6553. WFIFOL(fd, 6)=g->guild_lv;
  6554. WFIFOL(fd,10)=g->connect_member;
  6555. WFIFOL(fd,14)=g->max_member;
  6556. WFIFOL(fd,18)=g->average_lv;
  6557. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6558. WFIFOL(fd,26)=g->next_exp;
  6559. WFIFOL(fd,30)=0; // Tax Points
  6560. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6561. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6562. WFIFOL(fd,42)=g->emblem_id;
  6563. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6564. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6565. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6566. WFIFOL(fd,110) = 0; // zeny
  6567. WFIFOSET(fd,packet_len(0x1b6));
  6568. }
  6569. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6570. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6571. void clif_guild_allianceinfo(struct map_session_data *sd)
  6572. {
  6573. int fd,i,c;
  6574. struct guild *g;
  6575. nullpo_retv(sd);
  6576. if( (g = sd->guild) == NULL )
  6577. return;
  6578. fd = sd->fd;
  6579. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6580. WFIFOW(fd, 0)=0x14c;
  6581. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6582. struct guild_alliance *a=&g->alliance[i];
  6583. if(a->guild_id>0){
  6584. WFIFOL(fd,c*32+4)=a->opposition;
  6585. WFIFOL(fd,c*32+8)=a->guild_id;
  6586. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6587. c++;
  6588. }
  6589. }
  6590. WFIFOW(fd, 2)=c*32+4;
  6591. WFIFOSET(fd,WFIFOW(fd,2));
  6592. }
  6593. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6594. /// 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 }*
  6595. /// state:
  6596. /// 0 = offline
  6597. /// 1 = online
  6598. /// memo:
  6599. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6600. void clif_guild_memberlist(struct map_session_data *sd)
  6601. {
  6602. int fd;
  6603. int i,c;
  6604. struct guild *g;
  6605. nullpo_retv(sd);
  6606. if( (fd = sd->fd) == 0 )
  6607. return;
  6608. if( (g = sd->guild) == NULL )
  6609. return;
  6610. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6611. WFIFOW(fd, 0)=0x154;
  6612. for(i=0,c=0;i<g->max_member;i++){
  6613. struct guild_member *m=&g->member[i];
  6614. if(m->account_id==0)
  6615. continue;
  6616. WFIFOL(fd,c*104+ 4)=m->account_id;
  6617. WFIFOL(fd,c*104+ 8)=m->char_id;
  6618. WFIFOW(fd,c*104+12)=m->hair;
  6619. WFIFOW(fd,c*104+14)=m->hair_color;
  6620. WFIFOW(fd,c*104+16)=m->gender;
  6621. WFIFOW(fd,c*104+18)=m->class_;
  6622. WFIFOW(fd,c*104+20)=m->lv;
  6623. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6624. WFIFOL(fd,c*104+26)=m->online;
  6625. WFIFOL(fd,c*104+30)=m->position;
  6626. 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.
  6627. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6628. c++;
  6629. }
  6630. WFIFOW(fd, 2)=c*104+4;
  6631. WFIFOSET(fd,WFIFOW(fd,2));
  6632. }
  6633. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6634. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6635. void clif_guild_positionnamelist(struct map_session_data *sd)
  6636. {
  6637. int i,fd;
  6638. struct guild *g;
  6639. nullpo_retv(sd);
  6640. if( (g = sd->guild) == NULL )
  6641. return;
  6642. fd = sd->fd;
  6643. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6644. WFIFOW(fd, 0)=0x166;
  6645. for(i=0;i<MAX_GUILDPOSITION;i++){
  6646. WFIFOL(fd,i*28+4)=i;
  6647. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6648. }
  6649. WFIFOW(fd,2)=i*28+4;
  6650. WFIFOSET(fd,WFIFOW(fd,2));
  6651. }
  6652. /// Guild position information (ZC_POSITION_INFO).
  6653. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6654. /// mode:
  6655. /// &0x01 = allow invite
  6656. /// &0x10 = allow expel
  6657. /// ranking:
  6658. /// TODO
  6659. void clif_guild_positioninfolist(struct map_session_data *sd)
  6660. {
  6661. int i,fd;
  6662. struct guild *g;
  6663. nullpo_retv(sd);
  6664. if( (g = sd->guild) == NULL )
  6665. return;
  6666. fd = sd->fd;
  6667. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6668. WFIFOW(fd, 0)=0x160;
  6669. for(i=0;i<MAX_GUILDPOSITION;i++){
  6670. struct guild_position *p=&g->position[i];
  6671. WFIFOL(fd,i*16+ 4)=i;
  6672. WFIFOL(fd,i*16+ 8)=p->mode;
  6673. WFIFOL(fd,i*16+12)=i;
  6674. WFIFOL(fd,i*16+16)=p->exp_mode;
  6675. }
  6676. WFIFOW(fd, 2)=i*16+4;
  6677. WFIFOSET(fd,WFIFOW(fd,2));
  6678. }
  6679. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6680. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6681. /// mode:
  6682. /// &0x01 = allow invite
  6683. /// &0x10 = allow expel
  6684. /// ranking:
  6685. /// TODO
  6686. void clif_guild_positionchanged(struct guild *g,int idx)
  6687. {
  6688. // FIXME: This packet is intended to update the clients after a
  6689. // commit of position info changes, not sending one packet per
  6690. // position.
  6691. struct map_session_data *sd;
  6692. unsigned char buf[128];
  6693. nullpo_retv(g);
  6694. WBUFW(buf, 0)=0x174;
  6695. WBUFW(buf, 2)=44; // packet len
  6696. // GUILD_REG_POSITION_INFO{
  6697. WBUFL(buf, 4)=idx;
  6698. WBUFL(buf, 8)=g->position[idx].mode;
  6699. WBUFL(buf,12)=idx;
  6700. WBUFL(buf,16)=g->position[idx].exp_mode;
  6701. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6702. // }*
  6703. if( (sd=guild_getavailablesd(g))!=NULL )
  6704. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6705. }
  6706. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6707. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6708. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6709. {
  6710. // FIXME: This packet is intended to update the clients after a
  6711. // commit of member position assignment changes, not sending one
  6712. // packet per position.
  6713. struct map_session_data *sd;
  6714. unsigned char buf[64];
  6715. nullpo_retv(g);
  6716. WBUFW(buf, 0)=0x156;
  6717. WBUFW(buf, 2)=16; // packet len
  6718. // MEMBER_POSITION_INFO{
  6719. WBUFL(buf, 4)=g->member[idx].account_id;
  6720. WBUFL(buf, 8)=g->member[idx].char_id;
  6721. WBUFL(buf,12)=g->member[idx].position;
  6722. // }*
  6723. if( (sd=guild_getavailablesd(g))!=NULL )
  6724. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6725. }
  6726. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6727. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6728. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6729. {
  6730. int fd;
  6731. nullpo_retv(sd);
  6732. nullpo_retv(g);
  6733. fd = sd->fd;
  6734. if( g->emblem_len <= 0 )
  6735. return;
  6736. WFIFOHEAD(fd,g->emblem_len+12);
  6737. WFIFOW(fd,0)=0x152;
  6738. WFIFOW(fd,2)=g->emblem_len+12;
  6739. WFIFOL(fd,4)=g->guild_id;
  6740. WFIFOL(fd,8)=g->emblem_id;
  6741. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6742. WFIFOSET(fd,WFIFOW(fd,2));
  6743. }
  6744. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6745. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6746. void clif_guild_emblem_area(struct block_list* bl)
  6747. {
  6748. uint8 buf[12];
  6749. nullpo_retv(bl);
  6750. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6751. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6752. WBUFW(buf,0) = 0x1b4;
  6753. WBUFL(buf,2) = bl->id;
  6754. WBUFL(buf,6) = status_get_guild_id(bl);
  6755. WBUFW(buf,10) = status_get_emblem_id(bl);
  6756. clif_send(buf, 12, bl, AREA_WOS);
  6757. }
  6758. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6759. /// 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 }*
  6760. void clif_guild_skillinfo(struct map_session_data* sd)
  6761. {
  6762. int fd;
  6763. struct guild* g;
  6764. int i,c;
  6765. nullpo_retv(sd);
  6766. if( (g = sd->guild) == NULL )
  6767. return;
  6768. fd = sd->fd;
  6769. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6770. WFIFOW(fd,0) = 0x0162;
  6771. WFIFOW(fd,4) = g->skill_point;
  6772. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6773. {
  6774. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6775. {
  6776. int id = g->skill[i].id;
  6777. int p = 6 + c*37;
  6778. WFIFOW(fd,p+0) = id;
  6779. WFIFOL(fd,p+2) = skill_get_inf(id);
  6780. WFIFOW(fd,p+6) = g->skill[i].lv;
  6781. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6782. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6783. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6784. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6785. c++;
  6786. }
  6787. }
  6788. WFIFOW(fd,2) = 6 + c*37;
  6789. WFIFOSET(fd,WFIFOW(fd,2));
  6790. }
  6791. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6792. /// 016f <subject>.60B <notice>.120B
  6793. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6794. {
  6795. int fd;
  6796. nullpo_retv(sd);
  6797. nullpo_retv(g);
  6798. fd = sd->fd;
  6799. if ( !session_isActive(fd) )
  6800. return;
  6801. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6802. return;
  6803. WFIFOHEAD(fd,packet_len(0x16f));
  6804. WFIFOW(fd,0) = 0x16f;
  6805. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6806. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6807. WFIFOSET(fd,packet_len(0x16f));
  6808. }
  6809. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6810. /// 016a <guild id>.L <guild name>.24B
  6811. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6812. {
  6813. int fd;
  6814. nullpo_retv(sd);
  6815. nullpo_retv(g);
  6816. fd=sd->fd;
  6817. WFIFOHEAD(fd,packet_len(0x16a));
  6818. WFIFOW(fd,0)=0x16a;
  6819. WFIFOL(fd,2)=g->guild_id;
  6820. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6821. WFIFOSET(fd,packet_len(0x16a));
  6822. }
  6823. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6824. /// 0169 <answer>.B
  6825. /// answer:
  6826. /// 0 = Already in guild.
  6827. /// 1 = Offer rejected.
  6828. /// 2 = Offer accepted.
  6829. /// 3 = Guild full.
  6830. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6831. {
  6832. int fd;
  6833. nullpo_retv(sd);
  6834. fd=sd->fd;
  6835. WFIFOHEAD(fd,packet_len(0x169));
  6836. WFIFOW(fd,0)=0x169;
  6837. WFIFOB(fd,2)=flag;
  6838. WFIFOSET(fd,packet_len(0x169));
  6839. }
  6840. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6841. /// 015a <char name>.24B <reason>.40B
  6842. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6843. {
  6844. unsigned char buf[128];
  6845. nullpo_retv(sd);
  6846. WBUFW(buf, 0)=0x15a;
  6847. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6848. memcpy(WBUFP(buf,26),mes,40);
  6849. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6850. }
  6851. /// Notifies clients of a guild of an expelled member.
  6852. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6853. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6854. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6855. {
  6856. unsigned char buf[128];
  6857. #if PACKETVER < 20100803
  6858. const unsigned short cmd = 0x15c;
  6859. #else
  6860. const unsigned short cmd = 0x839;
  6861. #endif
  6862. nullpo_retv(sd);
  6863. WBUFW(buf,0) = cmd;
  6864. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6865. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6866. #if PACKETVER < 20100803
  6867. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6868. #endif
  6869. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6870. }
  6871. /// Guild expulsion list (ZC_BAN_LIST).
  6872. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6873. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6874. void clif_guild_expulsionlist(struct map_session_data* sd)
  6875. {
  6876. #if PACKETVER < 20100803
  6877. const int offset = NAME_LENGTH*2+40;
  6878. #else
  6879. const int offset = NAME_LENGTH+40;
  6880. #endif
  6881. int fd, i, c = 0;
  6882. struct guild* g;
  6883. nullpo_retv(sd);
  6884. if( (g = sd->guild) == NULL )
  6885. return;
  6886. fd = sd->fd;
  6887. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6888. WFIFOW(fd,0) = 0x163;
  6889. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6890. {
  6891. struct guild_expulsion* e = &g->expulsion[i];
  6892. if( e->account_id > 0 )
  6893. {
  6894. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6895. #if PACKETVER < 20100803
  6896. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6897. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6898. #else
  6899. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6900. #endif
  6901. c++;
  6902. }
  6903. }
  6904. WFIFOW(fd,2) = 4 + c*offset;
  6905. WFIFOSET(fd,WFIFOW(fd,2));
  6906. }
  6907. /// Guild chat message (ZC_GUILD_CHAT).
  6908. /// 017f <packet len>.W <message>.?B
  6909. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6910. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6911. struct map_session_data *sd;
  6912. uint8 buf[256];
  6913. if( len == 0 )
  6914. {
  6915. return;
  6916. }
  6917. else if( len > sizeof(buf)-5 )
  6918. {
  6919. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6920. len = sizeof(buf)-5;
  6921. }
  6922. WBUFW(buf, 0) = 0x17f;
  6923. WBUFW(buf, 2) = len + 5;
  6924. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6925. if ((sd = guild_getavailablesd(g)) != NULL)
  6926. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6927. }
  6928. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6929. /// 0171 <inviter account id>.L <guild name>.24B
  6930. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6931. {
  6932. int fd;
  6933. nullpo_retv(sd);
  6934. fd=sd->fd;
  6935. WFIFOHEAD(fd,packet_len(0x171));
  6936. WFIFOW(fd,0)=0x171;
  6937. WFIFOL(fd,2)=account_id;
  6938. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6939. WFIFOSET(fd,packet_len(0x171));
  6940. }
  6941. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6942. /// 0173 <answer>.B
  6943. /// answer:
  6944. /// 0 = Already allied.
  6945. /// 1 = You rejected the offer.
  6946. /// 2 = You accepted the offer.
  6947. /// 3 = They have too any alliances.
  6948. /// 4 = You have too many alliances.
  6949. /// 5 = Alliances are disabled.
  6950. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6951. {
  6952. int fd;
  6953. nullpo_retv(sd);
  6954. fd=sd->fd;
  6955. WFIFOHEAD(fd,packet_len(0x173));
  6956. WFIFOW(fd,0)=0x173;
  6957. WFIFOL(fd,2)=flag;
  6958. WFIFOSET(fd,packet_len(0x173));
  6959. }
  6960. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6961. /// 0184 <other guild id>.L <relation>.L
  6962. /// relation:
  6963. /// 0 = Ally
  6964. /// 1 = Enemy
  6965. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6966. {
  6967. int fd;
  6968. nullpo_retv(sd);
  6969. fd = sd->fd;
  6970. if (fd <= 0)
  6971. return;
  6972. WFIFOHEAD(fd,packet_len(0x184));
  6973. WFIFOW(fd,0)=0x184;
  6974. WFIFOL(fd,2)=guild_id;
  6975. WFIFOL(fd,6)=flag;
  6976. WFIFOSET(fd,packet_len(0x184));
  6977. }
  6978. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6979. /// 0181 <result>.B
  6980. /// result:
  6981. /// 0 = Antagonist has been set.
  6982. /// 1 = Guild has too many Antagonists.
  6983. /// 2 = Already set as an Antagonist.
  6984. /// 3 = Antagonists are disabled.
  6985. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6986. {
  6987. int fd;
  6988. nullpo_retv(sd);
  6989. fd=sd->fd;
  6990. WFIFOHEAD(fd,packet_len(0x181));
  6991. WFIFOW(fd,0)=0x181;
  6992. WFIFOB(fd,2)=flag;
  6993. WFIFOSET(fd,packet_len(0x181));
  6994. }
  6995. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6996. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6997. /*
  6998. void clif_guild_allianceadded(struct guild *g,int idx)
  6999. {
  7000. unsigned char buf[64];
  7001. WBUFW(buf,0)=0x185;
  7002. WBUFL(buf,2)=g->alliance[idx].opposition;
  7003. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7004. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7005. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7006. }
  7007. */
  7008. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7009. /// 015e <reason>.L
  7010. /// 0 = success
  7011. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7012. /// 2 = there are still members in the guild
  7013. void clif_guild_broken(struct map_session_data *sd,int flag)
  7014. {
  7015. int fd;
  7016. nullpo_retv(sd);
  7017. fd=sd->fd;
  7018. WFIFOHEAD(fd,packet_len(0x15e));
  7019. WFIFOW(fd,0)=0x15e;
  7020. WFIFOL(fd,2)=flag;
  7021. WFIFOSET(fd,packet_len(0x15e));
  7022. }
  7023. /// Displays emotion on an object (ZC_EMOTION).
  7024. /// 00c0 <id>.L <type>.B
  7025. /// type:
  7026. /// enum emotion_type
  7027. void clif_emotion(struct block_list *bl,int type)
  7028. {
  7029. unsigned char buf[8];
  7030. nullpo_retv(bl);
  7031. WBUFW(buf,0)=0xc0;
  7032. WBUFL(buf,2)=bl->id;
  7033. WBUFB(buf,6)=type;
  7034. clif_send(buf,packet_len(0xc0),bl,AREA);
  7035. }
  7036. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7037. /// 0191 <id>.L <contents>.80B
  7038. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7039. {
  7040. unsigned char buf[MESSAGE_SIZE+6];
  7041. nullpo_retv(bl);
  7042. WBUFW(buf,0) = 0x191;
  7043. WBUFL(buf,2) = bl->id;
  7044. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7045. clif_send(buf,packet_len(0x191),bl,AREA);
  7046. }
  7047. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7048. /// 01ea <id>.L
  7049. void clif_wedding_effect(struct block_list *bl)
  7050. {
  7051. unsigned char buf[6];
  7052. nullpo_retv(bl);
  7053. WBUFW(buf,0) = 0x1ea;
  7054. WBUFL(buf,2) = bl->id;
  7055. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7056. }
  7057. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7058. /// 01e6 <partner name>.24B
  7059. void clif_callpartner(struct map_session_data *sd)
  7060. {
  7061. unsigned char buf[26];
  7062. nullpo_retv(sd);
  7063. WBUFW(buf,0) = 0x1e6;
  7064. if( sd->status.partner_id )
  7065. {
  7066. const char *p;
  7067. if( ( p = map_charid2nick(sd->status.partner_id) ) != NULL )
  7068. {
  7069. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7070. }
  7071. else
  7072. {
  7073. WBUFB(buf,2) = 0;
  7074. }
  7075. }
  7076. else
  7077. {// Send zero-length name if no partner, to initialize the client buffer.
  7078. WBUFB(buf,2) = 0;
  7079. }
  7080. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7081. }
  7082. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7083. /// 01e4
  7084. /// This packet while still implemented by the client is no longer being officially used.
  7085. /*
  7086. void clif_marriage_process(struct map_session_data *sd)
  7087. {
  7088. int fd;
  7089. nullpo_retv(sd);
  7090. fd=sd->fd;
  7091. WFIFOHEAD(fd,packet_len(0x1e4));
  7092. WFIFOW(fd,0)=0x1e4;
  7093. WFIFOSET(fd,packet_len(0x1e4));
  7094. }
  7095. */
  7096. /// Notice of divorce (ZC_DIVORCE).
  7097. /// 0205 <partner name>.24B
  7098. void clif_divorced(struct map_session_data* sd, const char* name)
  7099. {
  7100. int fd;
  7101. nullpo_retv(sd);
  7102. fd=sd->fd;
  7103. WFIFOHEAD(fd,packet_len(0x205));
  7104. WFIFOW(fd,0)=0x205;
  7105. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7106. WFIFOSET(fd, packet_len(0x205));
  7107. }
  7108. /// Marriage proposal (ZC_REQ_COUPLE).
  7109. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7110. /// This packet while still implemented by the client is no longer being officially used.
  7111. /*
  7112. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7113. {
  7114. nullpo_retv(sd);
  7115. WFIFOHEAD(fd,packet_len(0x1e2));
  7116. WFIFOW(fd,0) = 0x1e2;
  7117. WFIFOL(fd,2) = ssd->status.account_id;
  7118. WFIFOL(fd,6) = ssd->status.char_id;
  7119. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7120. WFIFOSET(fd, packet_len(0x1e2));
  7121. }
  7122. */
  7123. /*==========================================
  7124. *
  7125. *------------------------------------------*/
  7126. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7127. {
  7128. clif_disp_message(&sd->bl, mes, len, SELF);
  7129. }
  7130. /*==========================================
  7131. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7132. *------------------------------------------*/
  7133. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7134. {
  7135. unsigned char buf[256];
  7136. if( len == 0 ) {
  7137. return;
  7138. } else if( len > sizeof(buf)-5 ) {
  7139. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7140. len = sizeof(buf)-5;
  7141. }
  7142. WBUFW(buf, 0) = 0x17f;
  7143. WBUFW(buf, 2) = len + 5;
  7144. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7145. clif_send(buf, WBUFW(buf,2), src, target);
  7146. }
  7147. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7148. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7149. /// 00cd <result>.B
  7150. /// result:
  7151. /// 0 = failure
  7152. /// 1 = success
  7153. void clif_GM_kickack(struct map_session_data *sd, int id)
  7154. {
  7155. int fd;
  7156. nullpo_retv(sd);
  7157. fd = sd->fd;
  7158. WFIFOHEAD(fd,packet_len(0xcd));
  7159. WFIFOW(fd,0) = 0xcd;
  7160. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7161. WFIFOSET(fd, packet_len(0xcd));
  7162. }
  7163. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7164. {
  7165. int fd = tsd->fd;
  7166. if( fd > 0 )
  7167. clif_authfail_fd(fd, 15);
  7168. else
  7169. map_quit(tsd);
  7170. if( sd )
  7171. clif_GM_kickack(sd,tsd->status.account_id);
  7172. }
  7173. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7174. /// 014a <result>.L
  7175. /// result:
  7176. /// 0 = "A manner point has been successfully aligned."
  7177. /// 1 = MP_FAILURE_EXHAUST
  7178. /// 2 = MP_FAILURE_ALREADY_GIVING
  7179. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7180. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7181. /// 5 = "You got a good point from %s."
  7182. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7183. {
  7184. int fd;
  7185. nullpo_retv(sd);
  7186. fd = sd->fd;
  7187. WFIFOHEAD(fd,packet_len(0x14a));
  7188. WFIFOW(fd,0) = 0x14a;
  7189. WFIFOL(fd,2) = type;
  7190. WFIFOSET(fd, packet_len(0x14a));
  7191. }
  7192. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7193. /// 014b <type>.B <GM name>.24B
  7194. /// type:
  7195. /// 0 = positive (unmute)
  7196. /// 1 = negative (mute)
  7197. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7198. {
  7199. int fd;
  7200. nullpo_retv(sd);
  7201. nullpo_retv(tsd);
  7202. fd = tsd->fd;
  7203. WFIFOHEAD(fd,packet_len(0x14b));
  7204. WFIFOW(fd,0) = 0x14b;
  7205. WFIFOB(fd,2) = type;
  7206. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7207. WFIFOSET(fd, packet_len(0x14b));
  7208. }
  7209. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7210. /// 00d1 <type>.B <result>.B
  7211. /// type:
  7212. /// 0 = /ex (deny)
  7213. /// 1 = /in (allow)
  7214. /// result:
  7215. /// 0 = success
  7216. /// 1 = failure
  7217. /// 2 = too many blocks
  7218. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7219. {
  7220. int fd;
  7221. nullpo_retv(sd);
  7222. fd=sd->fd;
  7223. WFIFOHEAD(fd,packet_len(0xd1));
  7224. WFIFOW(fd,0)=0xd1;
  7225. WFIFOB(fd,2)=type;
  7226. WFIFOB(fd,3)=flag;
  7227. WFIFOSET(fd,packet_len(0xd1));
  7228. }
  7229. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7230. /// 00d2 <type>.B <result>.B
  7231. /// type:
  7232. /// 0 = /exall (deny)
  7233. /// 1 = /inall (allow)
  7234. /// result:
  7235. /// 0 = success
  7236. /// 1 = failure
  7237. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7238. {
  7239. int fd;
  7240. nullpo_retv(sd);
  7241. fd=sd->fd;
  7242. WFIFOHEAD(fd,packet_len(0xd2));
  7243. WFIFOW(fd,0)=0xd2;
  7244. WFIFOB(fd,2)=type;
  7245. WFIFOB(fd,3)=flag;
  7246. WFIFOSET(fd,packet_len(0xd2));
  7247. }
  7248. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7249. /// 07fe <bgm>.24B
  7250. void clif_playBGM(struct map_session_data* sd, const char* name)
  7251. {
  7252. int fd;
  7253. nullpo_retv(sd);
  7254. fd = sd->fd;
  7255. WFIFOHEAD(fd,packet_len(0x7fe));
  7256. WFIFOW(fd,0) = 0x7fe;
  7257. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7258. WFIFOSET(fd,packet_len(0x7fe));
  7259. }
  7260. /// Plays/stops a wave sound (ZC_SOUND).
  7261. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7262. /// file name:
  7263. /// relative to data\wav
  7264. /// act:
  7265. /// 0 = play (once)
  7266. /// 1 = play (repeat, does not work)
  7267. /// 2 = stops all sound instances of file name (does not work)
  7268. /// term:
  7269. /// unknown purpose, only relevant to act = 1
  7270. /// npc id:
  7271. /// The accustic direction of the sound is determined by the
  7272. /// relative position of the NPC to the player (3D sound).
  7273. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7274. {
  7275. int fd;
  7276. nullpo_retv(sd);
  7277. nullpo_retv(bl);
  7278. fd = sd->fd;
  7279. WFIFOHEAD(fd,packet_len(0x1d3));
  7280. WFIFOW(fd,0) = 0x1d3;
  7281. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7282. WFIFOB(fd,26) = type;
  7283. WFIFOL(fd,27) = 0;
  7284. WFIFOL(fd,31) = bl->id;
  7285. WFIFOSET(fd,packet_len(0x1d3));
  7286. }
  7287. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7288. {
  7289. unsigned char buf[40];
  7290. nullpo_retv(bl);
  7291. WBUFW(buf,0) = 0x1d3;
  7292. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7293. WBUFB(buf,26) = type;
  7294. WBUFL(buf,27) = 0;
  7295. WBUFL(buf,31) = bl->id;
  7296. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7297. }
  7298. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7299. /// 01f3 <id>.L <effect id>.L
  7300. /// effect id:
  7301. /// @see doc/effect_list.txt
  7302. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7303. {
  7304. unsigned char buf[24];
  7305. nullpo_retv(bl);
  7306. memset(buf, 0, packet_len(0x1f3));
  7307. WBUFW(buf,0) = 0x1f3;
  7308. WBUFL(buf,2) = bl->id;
  7309. WBUFL(buf,6) = type;
  7310. clif_send(buf, packet_len(0x1f3), bl, target);
  7311. if (disguised(bl)) {
  7312. WBUFL(buf,2) = -bl->id;
  7313. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7314. }
  7315. }
  7316. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7317. {
  7318. WFIFOHEAD(fd,10);
  7319. WFIFOW(fd,0) = 0x1f3;
  7320. WFIFOL(fd,2) = bl->id;
  7321. WFIFOL(fd,6) = type;
  7322. WFIFOSET(fd,10);
  7323. }
  7324. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7325. /// 0284 <id>.L <effect id>.L <num data>.L
  7326. /// effect id:
  7327. /// @see doc/effect_list.txt
  7328. /// num data:
  7329. /// effect-dependent value
  7330. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7331. {
  7332. uint8 buf[14];
  7333. WBUFW(buf,0) = 0x284;
  7334. WBUFL(buf,2) = bl->id;
  7335. WBUFL(buf,6) = effect_id;
  7336. WBUFL(buf,10) = num;
  7337. clif_send(buf, packet_len(0x284), bl, target);
  7338. if( disguised(bl) )
  7339. {
  7340. WBUFL(buf,2) = -bl->id;
  7341. clif_send(buf, packet_len(0x284), bl, SELF);
  7342. }
  7343. }
  7344. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7345. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7346. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7347. unsigned short msg_len = strlen(msg) + 1;
  7348. WFIFOHEAD(sd->fd,msg_len + 12);
  7349. WFIFOW(sd->fd,0) = 0x2C1;
  7350. WFIFOW(sd->fd,2) = msg_len + 12;
  7351. WFIFOL(sd->fd,4) = 0;
  7352. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7353. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7354. WFIFOSET(sd->fd, msg_len + 12);
  7355. return 0;
  7356. }
  7357. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7358. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7359. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7360. unsigned short msg_len = strlen(msg) + 1;
  7361. uint8 buf[256];
  7362. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7363. nullpo_retv(bl);
  7364. if( msg_len > sizeof(buf)-12 ) {
  7365. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7366. msg_len = sizeof(buf)-12;
  7367. }
  7368. WBUFW(buf,0) = 0x2C1;
  7369. WBUFW(buf,2) = msg_len + 12;
  7370. WBUFL(buf,4) = bl->id;
  7371. WBUFL(buf,8) = color;
  7372. memcpy(WBUFP(buf,12), msg, msg_len);
  7373. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7374. }
  7375. // refresh the client's screen, getting rid of any effects
  7376. void clif_refresh(struct map_session_data *sd)
  7377. {
  7378. int i;
  7379. nullpo_retv(sd);
  7380. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7381. clif_inventorylist(sd);
  7382. if(pc_iscarton(sd)) {
  7383. clif_cartlist(sd);
  7384. clif_updatestatus(sd,SP_CARTINFO);
  7385. }
  7386. clif_updatestatus(sd,SP_WEIGHT);
  7387. clif_updatestatus(sd,SP_MAXWEIGHT);
  7388. clif_updatestatus(sd,SP_STR);
  7389. clif_updatestatus(sd,SP_AGI);
  7390. clif_updatestatus(sd,SP_VIT);
  7391. clif_updatestatus(sd,SP_INT);
  7392. clif_updatestatus(sd,SP_DEX);
  7393. clif_updatestatus(sd,SP_LUK);
  7394. if (sd->spiritball)
  7395. clif_spiritball_single(sd->fd, sd);
  7396. for(i = 1; i < 5; i++){
  7397. if( sd->talisman[i] > 0 )
  7398. clif_talisman_single(sd->fd, sd, i);
  7399. }
  7400. if (sd->vd.cloth_color)
  7401. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7402. if(merc_is_hom_active(sd->hd))
  7403. clif_send_homdata(sd,SP_ACK,0);
  7404. if( sd->md ) {
  7405. clif_mercenary_info(sd);
  7406. clif_mercenary_skillblock(sd);
  7407. }
  7408. if( sd->ed )
  7409. clif_elemental_info(sd);
  7410. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7411. clif_weather_check(sd);
  7412. if( sd->chatID )
  7413. chat_leavechat(sd,0);
  7414. if( sd->state.vending )
  7415. clif_openvending(sd, sd->bl.id, sd->vending);
  7416. if( pc_issit(sd) )
  7417. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7418. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7419. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7420. else
  7421. clif_changed_dir(&sd->bl, SELF);
  7422. // unlike vending, resuming buyingstore crashes the client.
  7423. buyingstore_close(sd);
  7424. mail_clear(sd);
  7425. if( disguised(&sd->bl) ) {/* refresh-da */
  7426. short disguise = sd->disguise;
  7427. pc_disguise(sd, 0);
  7428. pc_disguise(sd, disguise);
  7429. }
  7430. }
  7431. /// Updates the object's (bl) name on client.
  7432. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7433. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7434. void clif_charnameack (int fd, struct block_list *bl)
  7435. {
  7436. unsigned char buf[103];
  7437. int cmd = 0x95, i, ps = -1;
  7438. nullpo_retv(bl);
  7439. WBUFW(buf,0) = cmd;
  7440. WBUFL(buf,2) = bl->id;
  7441. switch( bl->type )
  7442. {
  7443. case BL_PC:
  7444. {
  7445. struct map_session_data *ssd = (struct map_session_data *)bl;
  7446. struct party_data *p = NULL;
  7447. struct guild *g = NULL;
  7448. //Requesting your own "shadow" name. [Skotlex]
  7449. if (ssd->fd == fd && ssd->disguise)
  7450. WBUFL(buf,2) = -bl->id;
  7451. if( ssd->fakename[0] ) {
  7452. WBUFW(buf, 0) = cmd = 0x195;
  7453. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7454. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7455. break;
  7456. }
  7457. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7458. if( ssd->status.party_id ) {
  7459. p = party_search(ssd->status.party_id);
  7460. }
  7461. if( ssd->status.guild_id ) {
  7462. if( ( g = ssd->guild ) != NULL ) {
  7463. 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);
  7464. if( i < g->max_member ) ps = g->member[i].position;
  7465. }
  7466. }
  7467. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7468. p = NULL;
  7469. }
  7470. if (p == NULL && g == NULL)
  7471. break;
  7472. WBUFW(buf, 0) = cmd = 0x195;
  7473. if (p)
  7474. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7475. else
  7476. WBUFB(buf,30) = 0;
  7477. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7478. {
  7479. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7480. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7481. } else { //Assume no guild.
  7482. WBUFB(buf,54) = 0;
  7483. WBUFB(buf,78) = 0;
  7484. }
  7485. }
  7486. break;
  7487. //[blackhole89]
  7488. case BL_HOM:
  7489. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7490. break;
  7491. case BL_MER:
  7492. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7493. break;
  7494. case BL_PET:
  7495. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7496. break;
  7497. case BL_NPC:
  7498. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7499. break;
  7500. case BL_MOB:
  7501. {
  7502. struct mob_data *md = (struct mob_data *)bl;
  7503. nullpo_retv(md);
  7504. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7505. if( md->guardian_data && md->guardian_data->guild_id )
  7506. {
  7507. WBUFW(buf, 0) = cmd = 0x195;
  7508. WBUFB(buf,30) = 0;
  7509. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7510. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7511. }
  7512. else if( battle_config.show_mob_info )
  7513. {
  7514. char mobhp[50], *str_p = mobhp;
  7515. WBUFW(buf, 0) = cmd = 0x195;
  7516. if( battle_config.show_mob_info&4 )
  7517. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7518. if( battle_config.show_mob_info&1 )
  7519. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7520. if( battle_config.show_mob_info&2 )
  7521. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7522. //Even thought mobhp ain't a name, we send it as one so the client
  7523. //can parse it. [Skotlex]
  7524. if( str_p != mobhp )
  7525. {
  7526. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7527. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7528. WBUFB(buf,54) = 0;
  7529. WBUFB(buf,78) = 0;
  7530. }
  7531. }
  7532. }
  7533. break;
  7534. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7535. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7536. // break;
  7537. return;
  7538. case BL_ELEM:
  7539. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7540. break;
  7541. default:
  7542. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7543. return;
  7544. }
  7545. // if no receipient specified just update nearby clients
  7546. if (fd == 0)
  7547. clif_send(buf, packet_len(cmd), bl, AREA);
  7548. else {
  7549. WFIFOHEAD(fd, packet_len(cmd));
  7550. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7551. WFIFOSET(fd, packet_len(cmd));
  7552. }
  7553. }
  7554. //Used to update when a char leaves a party/guild. [Skotlex]
  7555. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7556. void clif_charnameupdate (struct map_session_data *ssd)
  7557. {
  7558. unsigned char buf[103];
  7559. int cmd = 0x195, ps = -1;
  7560. struct party_data *p = NULL;
  7561. struct guild *g = NULL;
  7562. nullpo_retv(ssd);
  7563. if( ssd->fakename[0] )
  7564. return; //No need to update as the party/guild was not displayed anyway.
  7565. WBUFW(buf,0) = cmd;
  7566. WBUFL(buf,2) = ssd->bl.id;
  7567. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7568. if (!battle_config.display_party_name) {
  7569. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7570. p = party_search(ssd->status.party_id);
  7571. }else{
  7572. if (ssd->status.party_id > 0)
  7573. p = party_search(ssd->status.party_id);
  7574. }
  7575. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7576. {
  7577. int i;
  7578. 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);
  7579. if( i < g->max_member ) ps = g->member[i].position;
  7580. }
  7581. if( p )
  7582. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7583. else
  7584. WBUFB(buf,30) = 0;
  7585. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7586. {
  7587. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7588. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7589. }
  7590. else
  7591. {
  7592. WBUFB(buf,54) = 0;
  7593. WBUFB(buf,78) = 0;
  7594. }
  7595. // Update nearby clients
  7596. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7597. }
  7598. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7599. /// 01ff <id>.L <x>.W <y>.W
  7600. ///
  7601. /// Visually moves(instant) a character to x,y. The char moves even
  7602. /// when the target cell isn't walkable. If the char is sitting it
  7603. /// stays that way.
  7604. void clif_slide(struct block_list *bl, int x, int y)
  7605. {
  7606. unsigned char buf[10];
  7607. nullpo_retv(bl);
  7608. WBUFW(buf, 0) = 0x01ff;
  7609. WBUFL(buf, 2) = bl->id;
  7610. WBUFW(buf, 6) = x;
  7611. WBUFW(buf, 8) = y;
  7612. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7613. if( disguised(bl) )
  7614. {
  7615. WBUFL(buf,2) = -bl->id;
  7616. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7617. }
  7618. }
  7619. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7620. /// 008d <packet len>.W <id>.L <message>.?B
  7621. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7622. {
  7623. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7624. int len_mes = strlen(mes)+1; //Account for \0
  7625. if (len_mes > sizeof(buf)-8) {
  7626. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7627. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7628. }
  7629. // send message to others
  7630. WBUFW(buf,0) = 0x8d;
  7631. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7632. WBUFL(buf,4) = bl->id;
  7633. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7634. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7635. // send back message to the speaker
  7636. if( bl->type == BL_PC ) {
  7637. WBUFW(buf,0) = 0x8e;
  7638. WBUFW(buf, 2) = len_mes + 4;
  7639. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7640. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7641. }
  7642. }
  7643. /*==========================
  7644. * Minimap fix [Kevin]
  7645. * Remove dot from minimap
  7646. *--------------------------*/
  7647. void clif_party_xy_remove(struct map_session_data *sd)
  7648. {
  7649. unsigned char buf[16];
  7650. nullpo_retv(sd);
  7651. WBUFW(buf,0)=0x107;
  7652. WBUFL(buf,2)=sd->status.account_id;
  7653. WBUFW(buf,6)=-1;
  7654. WBUFW(buf,8)=-1;
  7655. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7656. }
  7657. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7658. /// 0215 <msg id>.L
  7659. /// msg id:
  7660. /// 0x15 = End all negative status (PA_GOSPEL)
  7661. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7662. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7663. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7664. /// 0x19 = All stats +20 (PA_GOSPEL)
  7665. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7666. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7667. /// 0x1e = DEF +25% (PA_GOSPEL)
  7668. /// 0x1f = ATK +100% (PA_GOSPEL)
  7669. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7670. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7671. /// ? = nothing
  7672. void clif_gospel_info(struct map_session_data *sd, int type)
  7673. {
  7674. int fd=sd->fd;
  7675. WFIFOHEAD(fd,packet_len(0x215));
  7676. WFIFOW(fd,0)=0x215;
  7677. WFIFOL(fd,2)=type;
  7678. WFIFOSET(fd, packet_len(0x215));
  7679. }
  7680. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7681. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7682. /// result:
  7683. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7684. /// star:
  7685. /// 0 = Place of the Sun
  7686. /// 1 = Place of the Moon
  7687. /// 2 = Place of the Stars
  7688. /// 1 = Star Gladiator %s's %s: <mapname>
  7689. /// star:
  7690. /// 0 = Place of the Sun
  7691. /// 1 = Place of the Moon
  7692. /// 2 = Place of the Stars
  7693. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7694. /// star:
  7695. /// 0 = Target of the Sun
  7696. /// 1 = Target of the Moon
  7697. /// 2 = Target of the Stars
  7698. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7699. /// star:
  7700. /// 0 = Monster of the Sun
  7701. /// 1 = Monster of the Moon
  7702. /// 2 = Monster of the Stars
  7703. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7704. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7705. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7706. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7707. /// 40 = Target HP : <monster_id used as HP>
  7708. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7709. {
  7710. int fd = sd->fd;
  7711. WFIFOHEAD(fd,packet_len(0x20e));
  7712. WFIFOW(fd,0) = 0x20e;
  7713. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7714. WFIFOL(fd,26) = monster_id;
  7715. WFIFOB(fd,30) = star;
  7716. WFIFOB(fd,31) = result;
  7717. WFIFOSET(fd,packet_len(0x20e));
  7718. }
  7719. /*==========================================
  7720. * Info about Star Glaldiator save map [Komurka]
  7721. * type: 1: Information, 0: Map registered
  7722. *------------------------------------------*/
  7723. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7724. {
  7725. char mapname[MAP_NAME_LENGTH_EXT];
  7726. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7727. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7728. }
  7729. /*==========================================
  7730. * Info about Star Glaldiator hate mob [Komurka]
  7731. * type: 1: Register mob, 0: Information.
  7732. *------------------------------------------*/
  7733. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7734. {
  7735. if( pcdb_checkid(class_) ) {
  7736. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7737. } else if( mobdb_checkid(class_) ) {
  7738. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7739. } else {
  7740. 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);
  7741. }
  7742. }
  7743. /*==========================================
  7744. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7745. *------------------------------------------*/
  7746. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7747. {
  7748. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7749. }
  7750. /*==========================================
  7751. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7752. *------------------------------------------*/
  7753. void clif_feel_hate_reset(struct map_session_data *sd)
  7754. {
  7755. clif_starskill(sd, "", 0, 0, 30);
  7756. }
  7757. /// Equip window (un)tick ack (ZC_CONFIG).
  7758. /// 02d9 <type>.L <value>.L
  7759. /// type:
  7760. /// 0 = open equip window
  7761. /// value:
  7762. /// 0 = disabled
  7763. /// 1 = enabled
  7764. void clif_equiptickack(struct map_session_data* sd, int flag)
  7765. {
  7766. int fd;
  7767. nullpo_retv(sd);
  7768. fd = sd->fd;
  7769. WFIFOHEAD(fd, packet_len(0x2d9));
  7770. WFIFOW(fd, 0) = 0x2d9;
  7771. WFIFOL(fd, 2) = 0;
  7772. WFIFOL(fd, 6) = flag;
  7773. WFIFOSET(fd, packet_len(0x2d9));
  7774. }
  7775. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7776. /// 02da <open equip window>.B
  7777. /// open equip window:
  7778. /// 0 = disabled
  7779. /// 1 = enabled
  7780. void clif_equipcheckbox(struct map_session_data* sd)
  7781. {
  7782. int fd;
  7783. nullpo_retv(sd);
  7784. fd = sd->fd;
  7785. WFIFOHEAD(fd, packet_len(0x2da));
  7786. WFIFOW(fd, 0) = 0x2da;
  7787. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7788. WFIFOSET(fd, packet_len(0x2da));
  7789. }
  7790. /// Sends info about a player's equipped items.
  7791. /// 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)
  7792. /// 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)
  7793. /// 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)
  7794. /// 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)
  7795. /// 0997 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.31B* (ZC_EQUIPWIN_MICROSCOPE_V5, PACKETVER >= 20120925)
  7796. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7797. {
  7798. uint8* buf;
  7799. int i, n, fd, offset = 0;
  7800. #if PACKETVER < 20100629
  7801. const int s = 26;
  7802. #elif PACKETVER < 20120925
  7803. const int s = 28;
  7804. #else
  7805. const int s = 31;
  7806. #endif
  7807. nullpo_retv(sd);
  7808. nullpo_retv(tsd);
  7809. fd = sd->fd;
  7810. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7811. buf = WFIFOP(fd,0);
  7812. #if PACKETVER < 20101124
  7813. WBUFW(buf, 0) = 0x2d7;
  7814. #elif PACKETVER < 20120925
  7815. WBUFW(buf, 0) = 0x859;
  7816. #else
  7817. WBUFW(buf, 0) = 0x997;
  7818. #endif
  7819. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7820. WBUFW(buf,28) = tsd->status.class_;
  7821. WBUFW(buf,30) = tsd->vd.hair_style;
  7822. WBUFW(buf,32) = tsd->vd.head_bottom;
  7823. WBUFW(buf,34) = tsd->vd.head_mid;
  7824. WBUFW(buf,36) = tsd->vd.head_top;
  7825. #if PACKETVER >= 20110111
  7826. WBUFW(buf,38) = tsd->vd.robe;
  7827. offset+= 2;
  7828. buf = WBUFP(buf,2);
  7829. #endif
  7830. WBUFW(buf,38) = tsd->vd.hair_color;
  7831. WBUFW(buf,40) = tsd->vd.cloth_color;
  7832. WBUFB(buf,42) = tsd->vd.sex;
  7833. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7834. {
  7835. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7836. continue;
  7837. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7838. continue;
  7839. // Add item info : refine, identify flag, element, etc.
  7840. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7841. n++;
  7842. }
  7843. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7844. WFIFOSET(fd, WFIFOW(fd, 2));
  7845. }
  7846. /// Display msgstringtable.txt string (ZC_MSG).
  7847. /// 0291 <message>.W
  7848. void clif_msg(struct map_session_data* sd, unsigned short id)
  7849. {
  7850. int fd;
  7851. nullpo_retv(sd);
  7852. fd = sd->fd;
  7853. WFIFOHEAD(fd, packet_len(0x291));
  7854. WFIFOW(fd, 0) = 0x291;
  7855. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7856. WFIFOSET(fd, packet_len(0x291));
  7857. }
  7858. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7859. /// 0x7e2 <message>.W <value>.L
  7860. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7861. {
  7862. int fd = sd->fd;
  7863. WFIFOHEAD(fd, packet_len(0x7e2));
  7864. WFIFOW(fd,0) = 0x7e2;
  7865. WFIFOW(fd,2) = id;
  7866. WFIFOL(fd,4) = value;
  7867. WFIFOSET(fd, packet_len(0x7e2));
  7868. }
  7869. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7870. /// 07e6 <skill id>.W <msg id>.L
  7871. ///
  7872. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7873. /// "[SkillName] Message"
  7874. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7875. {
  7876. int fd = sd->fd;
  7877. WFIFOHEAD(fd, packet_len(0x7e6));
  7878. WFIFOW(fd,0) = 0x7e6;
  7879. WFIFOW(fd,2) = skill_id;
  7880. WFIFOL(fd,4) = msg_id;
  7881. WFIFOSET(fd, packet_len(0x7e6));
  7882. }
  7883. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7884. /// Returns true if the packet was parsed successfully.
  7885. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7886. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7887. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7888. {
  7889. char *text, *name, *message;
  7890. unsigned int packetlen, textlen, namelen, messagelen;
  7891. int fd = sd->fd;
  7892. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  7893. *name_ = NULL;
  7894. *namelen_ = 0;
  7895. *message_ = NULL;
  7896. *messagelen_ = 0;
  7897. packetlen = RFIFOW(fd,info->pos[0]);
  7898. // basic structure checks
  7899. if( packetlen < 4 + 1 )
  7900. { // 4-byte header and at least an empty string is expected
  7901. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7902. return false;
  7903. }
  7904. text = (char*)RFIFOP(fd,info->pos[1]);
  7905. textlen = packetlen - 4;
  7906. // process <name> part of the packet
  7907. if( format == 0 )
  7908. {// name and message are separated by ' : '
  7909. // validate name
  7910. name = text;
  7911. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7912. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7913. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7914. {
  7915. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7916. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7917. set_eof(fd); // Just kick them out to correct it.
  7918. return false;
  7919. }
  7920. message = name + namelen + 3;
  7921. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7922. }
  7923. else
  7924. {// name has fixed width
  7925. if( textlen < NAME_LENGTH + 1 )
  7926. {
  7927. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7928. return false;
  7929. }
  7930. // validate name
  7931. name = text;
  7932. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7933. if( name[namelen] != '\0' )
  7934. { // only restriction is that the name must be zero-terminated
  7935. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7936. return false;
  7937. }
  7938. message = name + NAME_LENGTH;
  7939. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7940. }
  7941. if( messagelen != strnlen(message, messagelen)+1 )
  7942. { // the declared length must match real length
  7943. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7944. return false;
  7945. }
  7946. // verify <message> part of the packet
  7947. if( message[messagelen-1] != '\0' )
  7948. { // message must be zero-terminated
  7949. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7950. return false;
  7951. }
  7952. if( messagelen > CHAT_SIZE_MAX-1 )
  7953. { // messages mustn't be too long
  7954. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7955. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7956. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7957. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7958. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7959. return false;
  7960. }
  7961. *name_ = name;
  7962. *namelen_ = namelen;
  7963. *message_ = message;
  7964. *messagelen_ = messagelen;
  7965. return true;
  7966. }
  7967. // ---------------------
  7968. // clif_guess_PacketVer
  7969. // ---------------------
  7970. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7971. // error codes:
  7972. // 0 - Success
  7973. // 1 - Unknown packet_ver
  7974. // 2 - Invalid account_id
  7975. // 3 - Invalid char_id
  7976. // 4 - Invalid login_id1 (reserved)
  7977. // 5 - Invalid client_tick (reserved)
  7978. // 6 - Invalid sex
  7979. // Only the first 'invalid' error that appears is used.
  7980. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7981. {
  7982. static int err = 1;
  7983. static int packet_ver = -1;
  7984. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7985. if (get_previous)
  7986. {//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]
  7987. if( error )
  7988. *error = err;
  7989. return packet_ver;
  7990. }
  7991. //By default, start searching on the default one.
  7992. err = 1;
  7993. packet_ver = clif_config.packet_db_ver;
  7994. cmd = RFIFOW(fd,0);
  7995. packet_len = RFIFOREST(fd);
  7996. #define SET_ERROR(n) \
  7997. if( err == 1 )\
  7998. err = n;\
  7999. //define SET_ERROR
  8000. // FIXME: If the packet is not received at once, this will FAIL.
  8001. // Figure out, when it happens, that only part of the packet is
  8002. // received, or fix the function to be able to deal with that
  8003. // case.
  8004. #define CHECK_PACKET_VER() \
  8005. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8006. ;/* not wanttoconnection or wrong length */\
  8007. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8008. { SET_ERROR(2); }/* invalid account_id */\
  8009. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8010. { SET_ERROR(3); }/* invalid char_id */\
  8011. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8012. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8013. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8014. { SET_ERROR(6); }/* invalid sex */\
  8015. else\
  8016. {\
  8017. err = 0;\
  8018. if( error )\
  8019. *error = 0;\
  8020. return packet_ver;\
  8021. }\
  8022. //define CHECK_PACKET_VER
  8023. CHECK_PACKET_VER();//Default packet version found.
  8024. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8025. CHECK_PACKET_VER();
  8026. }
  8027. if( error )
  8028. *error = err;
  8029. packet_ver = -1;
  8030. return -1;
  8031. #undef SET_ERROR
  8032. #undef CHECK_PACKET_VER
  8033. }
  8034. // ------------
  8035. // clif_parse_*
  8036. // ------------
  8037. // Parses incoming (player) connection
  8038. /// Request to connect to map-server.
  8039. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8040. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8041. /// There are various variants of this packet, some of them have padding between fields.
  8042. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8043. {
  8044. struct block_list* bl;
  8045. struct auth_node* node;
  8046. int cmd, account_id, char_id, login_id1, sex;
  8047. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8048. 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])
  8049. if (sd) {
  8050. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8051. return;
  8052. }
  8053. // Only valid packet version get here
  8054. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8055. cmd = RFIFOW(fd,0);
  8056. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8057. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8058. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8059. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8060. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8061. if( packet_ver < 5 || // reject really old client versions
  8062. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8063. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8064. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8065. {// packet version rejected
  8066. 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));
  8067. WFIFOHEAD(fd,packet_len(0x6a));
  8068. WFIFOW(fd,0) = 0x6a;
  8069. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8070. WFIFOSET(fd,packet_len(0x6a));
  8071. set_eof(fd);
  8072. return;
  8073. }
  8074. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8075. clif_authfail_fd(fd,1);// server closed
  8076. return;
  8077. }
  8078. //Check for double login.
  8079. bl = map_id2bl(account_id);
  8080. if(bl && bl->type != BL_PC) {
  8081. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8082. WFIFOHEAD(fd,packet_len(0x6a));
  8083. WFIFOW(fd,0) = 0x6a;
  8084. WFIFOB(fd,2) = 3; // Rejected by server
  8085. WFIFOSET(fd,packet_len(0x6a));
  8086. set_eof(fd);
  8087. return;
  8088. }
  8089. if (bl ||
  8090. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8091. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8092. {
  8093. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8094. return;
  8095. }
  8096. CREATE(sd, TBL_PC, 1);
  8097. sd->fd = fd;
  8098. sd->packet_ver = packet_ver;
  8099. session[fd]->session_data = sd;
  8100. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8101. #if PACKETVER < 20070521
  8102. WFIFOHEAD(fd,4);
  8103. WFIFOL(fd,0) = sd->bl.id;
  8104. WFIFOSET(fd,4);
  8105. #else
  8106. WFIFOHEAD(fd,packet_len(0x283));
  8107. WFIFOW(fd,0) = 0x283;
  8108. WFIFOL(fd,2) = sd->bl.id;
  8109. WFIFOSET(fd,packet_len(0x283));
  8110. #endif
  8111. chrif_authreq(sd);
  8112. }
  8113. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8114. /// 007d
  8115. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8116. {
  8117. if(sd->bl.prev != NULL)
  8118. return;
  8119. if (!sd->state.active) { //Character loading is not complete yet!
  8120. //Let pc_reg_received reinvoke this when ready.
  8121. sd->state.connect_new = 0;
  8122. return;
  8123. }
  8124. if (sd->state.rewarp) { //Rewarp player.
  8125. sd->state.rewarp = 0;
  8126. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8127. return;
  8128. }
  8129. sd->state.warping = 0;
  8130. // look
  8131. #if PACKETVER < 4
  8132. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8133. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8134. #else
  8135. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8136. #endif
  8137. if(sd->vd.cloth_color)
  8138. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8139. // item
  8140. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8141. pc_checkitem(sd);
  8142. // cart
  8143. if(pc_iscarton(sd)) {
  8144. clif_cartlist(sd);
  8145. clif_updatestatus(sd,SP_CARTINFO);
  8146. }
  8147. // weight
  8148. clif_updatestatus(sd,SP_WEIGHT);
  8149. clif_updatestatus(sd,SP_MAXWEIGHT);
  8150. // guild
  8151. // (needs to go before clif_spawn() to show guild emblems correctly)
  8152. if(sd->status.guild_id)
  8153. guild_send_memberinfoshort(sd,1);
  8154. if(battle_config.pc_invincible_time > 0) {
  8155. if(map_flag_gvg(sd->bl.m))
  8156. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8157. else
  8158. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8159. }
  8160. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8161. map_spawnmobs(sd->bl.m);
  8162. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8163. map[sd->bl.m].users_pvp++;
  8164. }
  8165. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8166. // reset the callshop flag if the player changes map
  8167. sd->state.callshop = 0;
  8168. map_addblock(&sd->bl);
  8169. clif_spawn(&sd->bl);
  8170. // Party
  8171. // (needs to go after clif_spawn() to show hp bars correctly)
  8172. if(sd->status.party_id) {
  8173. party_send_movemap(sd);
  8174. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8175. }
  8176. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8177. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8178. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8179. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8180. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8181. sd->pvp_rank = 0;
  8182. sd->pvp_lastusers = 0;
  8183. sd->pvp_point = 5;
  8184. sd->pvp_won = 0;
  8185. sd->pvp_lost = 0;
  8186. }
  8187. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8188. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8189. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8190. if (map[sd->bl.m].flag.gvg_dungeon)
  8191. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8192. if( map_flag_gvg(sd->bl.m) )
  8193. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8194. // info about nearby objects
  8195. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8196. 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);
  8197. // pet
  8198. if( sd->pd ) {
  8199. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8200. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8201. pet_menu(sd, 3); //Option 3 is return to egg.
  8202. } else {
  8203. map_addblock(&sd->pd->bl);
  8204. clif_spawn(&sd->pd->bl);
  8205. clif_send_petdata(sd,sd->pd,0,0);
  8206. clif_send_petstatus(sd);
  8207. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8208. }
  8209. }
  8210. //homunculus [blackhole89]
  8211. if( merc_is_hom_active(sd->hd) ) {
  8212. map_addblock(&sd->hd->bl);
  8213. clif_spawn(&sd->hd->bl);
  8214. clif_send_homdata(sd,SP_ACK,0);
  8215. clif_hominfo(sd,sd->hd,1);
  8216. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8217. clif_homskillinfoblock(sd);
  8218. if( battle_config.hom_setting&0x8 )
  8219. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8220. if( !(battle_config.hom_setting&0x2) )
  8221. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8222. }
  8223. if( sd->md ) {
  8224. map_addblock(&sd->md->bl);
  8225. clif_spawn(&sd->md->bl);
  8226. clif_mercenary_info(sd);
  8227. clif_mercenary_skillblock(sd);
  8228. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8229. }
  8230. if( sd->ed ) {
  8231. map_addblock(&sd->ed->bl);
  8232. clif_spawn(&sd->ed->bl);
  8233. clif_elemental_info(sd);
  8234. clif_elemental_updatestatus(sd,SP_HP);
  8235. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8236. clif_elemental_updatestatus(sd,SP_SP);
  8237. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8238. }
  8239. if(sd->state.connect_new) {
  8240. int lv;
  8241. sd->state.connect_new = 0;
  8242. clif_skillinfoblock(sd);
  8243. clif_hotkeys_send(sd);
  8244. clif_updatestatus(sd,SP_BASEEXP);
  8245. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8246. clif_updatestatus(sd,SP_JOBEXP);
  8247. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8248. clif_updatestatus(sd,SP_SKILLPOINT);
  8249. clif_initialstatus(sd);
  8250. if (sd->sc.option&OPTION_FALCON)
  8251. clif_status_load(&sd->bl, SI_FALCON, 1);
  8252. if (sd->sc.option&OPTION_RIDING)
  8253. clif_status_load(&sd->bl, SI_RIDING, 1);
  8254. else if (sd->sc.option&OPTION_WUGRIDER)
  8255. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8256. if(sd->status.manner < 0)
  8257. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8258. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8259. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8260. if(sd->bl.m == sd->feel_map[0].m
  8261. || sd->bl.m == sd->feel_map[1].m
  8262. || sd->bl.m == sd->feel_map[2].m)
  8263. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8264. }
  8265. if(sd->pd && sd->pd->pet.intimate > 900)
  8266. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8267. if(merc_is_hom_active(sd->hd))
  8268. merc_hom_init_timers(sd->hd);
  8269. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8270. sd->state.night = 1;
  8271. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8272. }
  8273. // Notify everyone that this char logged in [Skotlex].
  8274. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8275. // Set the initial idle time
  8276. sd->idletime = last_tick;
  8277. //Login Event
  8278. npc_script_event(sd, NPCE_LOGIN);
  8279. } else {
  8280. //For some reason the client "loses" these on warp/map-change.
  8281. clif_updatestatus(sd,SP_STR);
  8282. clif_updatestatus(sd,SP_AGI);
  8283. clif_updatestatus(sd,SP_VIT);
  8284. clif_updatestatus(sd,SP_INT);
  8285. clif_updatestatus(sd,SP_DEX);
  8286. clif_updatestatus(sd,SP_LUK);
  8287. // abort currently running script
  8288. sd->state.using_fake_npc = 0;
  8289. sd->state.menu_or_input = 0;
  8290. sd->npc_menu = 0;
  8291. if(sd->npc_id)
  8292. npc_event_dequeue(sd);
  8293. }
  8294. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8295. #if PACKETVER >= 20070918
  8296. clif_partyinvitationstate(sd);
  8297. clif_equipcheckbox(sd);
  8298. #endif
  8299. #ifdef VIP_ENABLE
  8300. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8301. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8302. #endif
  8303. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8304. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8305. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8306. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8307. { //Display night.
  8308. if( !sd->state.night )
  8309. {
  8310. sd->state.night = 1;
  8311. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8312. }
  8313. }
  8314. else if( sd->state.night )
  8315. { //Clear night display.
  8316. sd->state.night = 0;
  8317. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8318. }
  8319. if( map[sd->bl.m].flag.battleground )
  8320. {
  8321. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8322. if( map[sd->bl.m].flag.battleground == 2 )
  8323. clif_bg_updatescore_single(sd);
  8324. }
  8325. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8326. {
  8327. char output[128];
  8328. safesnprintf(output,sizeof(output),"[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8329. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8330. }
  8331. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8332. map[sd->bl.m].hpmeter_visible++;
  8333. sd->state.hpmeter_visible = 1;
  8334. }
  8335. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8336. status_calc_pc(sd, false); // Some conditions are map-dependent so we must recalculate
  8337. sd->state.changemap = false;
  8338. // Instances do not need their own channels
  8339. if( Channel_Config.map_enable && Channel_Config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id ) {
  8340. channel_mjoin(sd); //join new map
  8341. }
  8342. }
  8343. mail_clear(sd);
  8344. clif_maptypeproperty2(&sd->bl,SELF);
  8345. /* Guild Aura Init */
  8346. if( sd->state.gmaster_flag ) {
  8347. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8348. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8349. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8350. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8351. }
  8352. if( sd->state.vending ) { /* show we have a vending */
  8353. clif_openvending(sd,sd->bl.id,sd->vending);
  8354. clif_showvendingboard(&sd->bl,sd->message,0);
  8355. }
  8356. if(map[sd->bl.m].flag.loadevent) // Lance
  8357. npc_script_event(sd, NPCE_LOADMAP);
  8358. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8359. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8360. if (sd->sc.opt2) //Client loses these on warp.
  8361. clif_changeoption(&sd->bl);
  8362. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8363. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8364. clif_displaymessage(sd->fd, msg_txt(sd,1500)); // Transforming into monster is not allowed in Guild Wars.
  8365. }
  8366. clif_weather_check(sd);
  8367. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8368. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8369. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8370. else
  8371. sd->areanpc_id = 0;
  8372. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8373. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8374. pc_setdead(sd);
  8375. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8376. if(pc_isdead(sd))
  8377. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8378. else {
  8379. skill_usave_trigger(sd);
  8380. clif_changed_dir(&sd->bl, SELF);
  8381. }
  8382. // Trigger skill effects if you appear standing on them
  8383. if(!battle_config.pc_invincible_time)
  8384. skill_unit_move(&sd->bl,gettick(),1);
  8385. }
  8386. /// Server's tick (ZC_NOTIFY_TIME).
  8387. /// 007f <time>.L
  8388. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8389. {
  8390. int fd = sd->fd;
  8391. WFIFOHEAD(fd,packet_len(0x7f));
  8392. WFIFOW(fd,0) = 0x7f;
  8393. WFIFOL(fd,2) = time;
  8394. WFIFOSET(fd,packet_len(0x7f));
  8395. }
  8396. /// Request for server's tick.
  8397. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8398. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8399. /// There are various variants of this packet, some of them have padding between fields.
  8400. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8401. {
  8402. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8403. clif_notify_time(sd, gettick());
  8404. }
  8405. /// Sends hotkey bar.
  8406. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8407. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8408. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8409. void clif_hotkeys_send(struct map_session_data *sd) {
  8410. #ifdef HOTKEY_SAVING
  8411. const int fd = sd->fd;
  8412. int i;
  8413. #if PACKETVER < 20090603
  8414. const int cmd = 0x2b9;
  8415. #else
  8416. const int cmd = 0x7d9;
  8417. #endif
  8418. if (!fd) return;
  8419. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8420. WFIFOW(fd, 0) = cmd;
  8421. for(i = 0; i < MAX_HOTKEYS; i++) {
  8422. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8423. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8424. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8425. }
  8426. WFIFOSET(fd, packet_len(cmd));
  8427. #endif
  8428. }
  8429. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8430. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8431. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8432. #ifdef HOTKEY_SAVING
  8433. unsigned short idx;
  8434. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8435. idx = RFIFOW(fd, info->pos[0]);
  8436. if (idx >= MAX_HOTKEYS) return;
  8437. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8438. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8439. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8440. #endif
  8441. }
  8442. /// Displays cast-like progress bar (ZC_PROGRESS).
  8443. /// 02f0 <color>.L <time>.L
  8444. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8445. {
  8446. int fd = sd->fd;
  8447. WFIFOHEAD(fd,packet_len(0x2f0));
  8448. WFIFOW(fd,0) = 0x2f0;
  8449. WFIFOL(fd,2) = color;
  8450. WFIFOL(fd,6) = second;
  8451. WFIFOSET(fd,packet_len(0x2f0));
  8452. }
  8453. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8454. /// 02f2
  8455. void clif_progressbar_abort(struct map_session_data * sd)
  8456. {
  8457. int fd = sd->fd;
  8458. WFIFOHEAD(fd,packet_len(0x2f2));
  8459. WFIFOW(fd,0) = 0x2f2;
  8460. WFIFOSET(fd,packet_len(0x2f2));
  8461. }
  8462. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8463. /// 02f1
  8464. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8465. {
  8466. int npc_id = sd->progressbar.npc_id;
  8467. if( gettick() < sd->progressbar.timeout && sd->st )
  8468. sd->st->state = END;
  8469. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8470. npc_scriptcont(sd, npc_id, false);
  8471. }
  8472. /// Request to walk to a certain position on the current map.
  8473. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8474. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8475. /// There are various variants of this packet, some of them have padding between fields.
  8476. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8477. {
  8478. short x, y;
  8479. if (pc_isdead(sd)) {
  8480. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8481. return;
  8482. }
  8483. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8484. ; //You CAN walk on this OPT1 value.
  8485. else if( sd->progressbar.npc_id )
  8486. clif_progressbar_abort(sd);
  8487. else if (pc_cant_act(sd))
  8488. return;
  8489. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8490. return;
  8491. // Cloaking wall check is actually updated when you click to process next movement
  8492. // not when you move each cell. This is official behaviour.
  8493. if (sd->sc.data[SC_CLOAKING])
  8494. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8495. pc_delinvincibletimer(sd);
  8496. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8497. //Set last idle time... [Skotlex]
  8498. sd->idletime = last_tick;
  8499. unit_walktoxy(&sd->bl, x, y, 4);
  8500. }
  8501. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8502. /// 018b <result>.W
  8503. /// result:
  8504. /// 0 = disconnect (quit)
  8505. /// 1 = cannot disconnect (wait 10 seconds)
  8506. /// ? = ignored
  8507. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8508. {
  8509. int fd = sd->fd;
  8510. WFIFOHEAD(fd,packet_len(0x18b));
  8511. WFIFOW(fd,0) = 0x18b;
  8512. WFIFOW(fd,2) = result;
  8513. WFIFOSET(fd,packet_len(0x18b));
  8514. }
  8515. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8516. /// 018a <type>.W
  8517. /// type:
  8518. /// 0 = quit
  8519. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8520. {
  8521. /* Rovert's prevent logout option fixed [Valaris] */
  8522. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8523. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8524. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8525. {
  8526. set_eof(fd);
  8527. pc_damage_log_clear(sd,0);
  8528. clif_disconnect_ack(sd, 0);
  8529. } else {
  8530. clif_disconnect_ack(sd, 1);
  8531. }
  8532. }
  8533. /// Requesting unit's name.
  8534. /// 0094 <id>.L (CZ_REQNAME)
  8535. /// 0368 <id>.L (CZ_REQNAME2)
  8536. /// There are various variants of this packet, some of them have padding between fields.
  8537. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8538. {
  8539. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8540. struct block_list* bl;
  8541. //struct status_change *sc;
  8542. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8543. id = sd->bl.id;
  8544. bl = map_id2bl(id);
  8545. if( bl == NULL )
  8546. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8547. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8548. return; // Block namerequests past view range
  8549. // 'see people in GM hide' cheat detection
  8550. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8551. sc = status_get_sc(bl);
  8552. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8553. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8554. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8555. ) {
  8556. char gm_msg[256];
  8557. 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);
  8558. ShowWarning(gm_msg);
  8559. // information is sent to all online GMs
  8560. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8561. return;
  8562. }
  8563. */
  8564. clif_charnameack(fd, bl);
  8565. }
  8566. /// Validates and processes global messages
  8567. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8568. /// There are various variants of this packet.
  8569. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8570. {
  8571. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8572. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8573. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8574. char *name, *message, *fakename = NULL;
  8575. int namelen, messagelen;
  8576. bool is_fake;
  8577. // validate packet and retrieve name and message
  8578. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8579. return;
  8580. if( is_atcommand(fd, sd, message, 1) )
  8581. return;
  8582. if (sd->sc.cant.chat)
  8583. return; //no "chatting" while muted.
  8584. if( battle_config.min_chat_delay ) { //[Skotlex]
  8585. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8586. return;
  8587. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8588. }
  8589. if( sd->gcbind ) {
  8590. channel_send(sd->gcbind,sd,message);
  8591. return;
  8592. }
  8593. /**
  8594. * Fake Name Design by FatalEror (bug report #9)
  8595. **/
  8596. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8597. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8598. strcpy(fakename, sd->fakename);
  8599. strcat(fakename, " : ");
  8600. strcat(fakename, message);
  8601. textlen = strlen(fakename) + 1;
  8602. }
  8603. // send message to others (using the send buffer for temp. storage)
  8604. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8605. // send back message to the speaker
  8606. if( is_fake ) {
  8607. WFIFOW(fd,0) = 0x8e;
  8608. WFIFOW(fd,2) = textlen + 4;
  8609. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8610. aFree(fakename);
  8611. } else {
  8612. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8613. WFIFOW(fd,0) = 0x8e;
  8614. }
  8615. WFIFOSET(fd, WFIFOW(fd,2));
  8616. #ifdef PCRE_SUPPORT
  8617. // trigger listening npcs
  8618. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8619. #endif
  8620. // Reset idle time when using normal chat.
  8621. sd->idletime = last_tick;
  8622. // Chat logging type 'O' / Global Chat
  8623. 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);
  8624. }
  8625. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8626. /// Request to warp to a map on given coordinates.
  8627. /// 0140 <map name>.16B <x>.W <y>.W
  8628. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8629. {
  8630. char command[MAP_NAME_LENGTH_EXT+25];
  8631. char* map_name;
  8632. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8633. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8634. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8635. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8636. RFIFOW(fd,info->pos[1]), //x
  8637. RFIFOW(fd,info->pos[2])); //y
  8638. is_atcommand(fd, sd, command, 1);
  8639. }
  8640. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8641. /// 009c <id>.L <head dir>.W <dir>.B
  8642. /// head dir:
  8643. /// 0 = straight
  8644. /// 1 = turned CW
  8645. /// 2 = turned CCW
  8646. /// dir:
  8647. /// 0 = north
  8648. /// 1 = northwest
  8649. /// 2 = west
  8650. /// 3 = southwest
  8651. /// 4 = south
  8652. /// 5 = southeast
  8653. /// 6 = east
  8654. /// 7 = northeast
  8655. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8656. {
  8657. unsigned char buf[64];
  8658. WBUFW(buf,0) = 0x9c;
  8659. WBUFL(buf,2) = bl->id;
  8660. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8661. WBUFB(buf,8) = unit_getdir(bl);
  8662. clif_send(buf, packet_len(0x9c), bl, target);
  8663. if (disguised(bl)) {
  8664. WBUFL(buf,2) = -bl->id;
  8665. WBUFW(buf,6) = 0;
  8666. clif_send(buf, packet_len(0x9c), bl, SELF);
  8667. }
  8668. }
  8669. /// Request to change own body and head direction.
  8670. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8671. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8672. /// There are various variants of this packet, some of them have padding between fields.
  8673. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8674. {
  8675. unsigned char headdir, dir;
  8676. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8677. headdir = RFIFOB(fd,info->pos[0]);
  8678. dir = RFIFOB(fd,info->pos[1]);
  8679. pc_setdir(sd, dir, headdir);
  8680. clif_changed_dir(&sd->bl, AREA_WOS);
  8681. }
  8682. /// Request to show an emotion (CZ_REQ_EMOTION).
  8683. /// 00bf <type>.B
  8684. /// type:
  8685. /// @see enum emotion_type
  8686. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8687. {
  8688. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8689. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8690. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8691. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8692. return;
  8693. }
  8694. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8695. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8696. sd->emotionlasttime = time(NULL);
  8697. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8698. return;
  8699. }
  8700. sd->emotionlasttime = time(NULL);
  8701. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8702. emoticon = rnd()%6+E_DICE1;
  8703. }
  8704. clif_emotion(&sd->bl, emoticon);
  8705. } else
  8706. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8707. }
  8708. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8709. /// 00c2 <count>.L
  8710. void clif_user_count(struct map_session_data* sd, int count)
  8711. {
  8712. int fd = sd->fd;
  8713. WFIFOHEAD(fd,packet_len(0xc2));
  8714. WFIFOW(fd,0) = 0xc2;
  8715. WFIFOL(fd,2) = count;
  8716. WFIFOSET(fd,packet_len(0xc2));
  8717. }
  8718. /// /w /who (CZ_REQ_USER_COUNT).
  8719. /// Request to display amount of currently connected players.
  8720. /// 00c1
  8721. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8722. {
  8723. clif_user_count(sd, map_getusers());
  8724. }
  8725. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8726. {
  8727. if (pc_isdead(sd)) {
  8728. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8729. return;
  8730. }
  8731. if (sd->sc.count &&
  8732. (sd->sc.data[SC_TRICKDEAD] ||
  8733. sd->sc.data[SC_AUTOCOUNTER] ||
  8734. sd->sc.data[SC_BLADESTOP] ||
  8735. sd->sc.data[SC__MANHOLE] ||
  8736. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8737. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8738. return;
  8739. pc_stop_walking(sd, 1);
  8740. pc_stop_attack(sd);
  8741. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8742. target_id = sd->bl.id;
  8743. switch(action_type)
  8744. {
  8745. case 0x00: // once attack
  8746. case 0x07: // continuous attack
  8747. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8748. return;
  8749. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  8750. return;
  8751. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8752. return;
  8753. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8754. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8755. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8756. return;
  8757. }
  8758. }
  8759. pc_delinvincibletimer(sd);
  8760. sd->idletime = last_tick;
  8761. unit_attack(&sd->bl, target_id, action_type != 0);
  8762. break;
  8763. case 0x02: // sitdown
  8764. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8765. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8766. break;
  8767. }
  8768. if(pc_issit(sd)) {
  8769. //Bugged client? Just refresh them.
  8770. clif_sitting(&sd->bl);
  8771. return;
  8772. }
  8773. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8774. break;
  8775. if (sd->sc.count && (
  8776. sd->sc.data[SC_DANCING] ||
  8777. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8778. )) //No sitting during these states either.
  8779. break;
  8780. sd->idletime = last_tick;
  8781. pc_setsit(sd);
  8782. skill_sit(sd,1);
  8783. clif_sitting(&sd->bl);
  8784. break;
  8785. case 0x03: // standup
  8786. if (!pc_issit(sd)) {
  8787. //Bugged client? Just refresh them.
  8788. clif_standing(&sd->bl);
  8789. return;
  8790. }
  8791. sd->idletime = last_tick;
  8792. pc_setstand(sd);
  8793. skill_sit(sd,0);
  8794. clif_standing(&sd->bl);
  8795. break;
  8796. }
  8797. }
  8798. /// Request for an action.
  8799. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8800. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8801. /// action:
  8802. /// 0 = attack
  8803. /// 1 = pick up item
  8804. /// 2 = sit down
  8805. /// 3 = stand up
  8806. /// 7 = continous attack
  8807. /// 12 = (touch skill?)
  8808. /// There are various variants of this packet, some of them have padding between fields.
  8809. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8810. {
  8811. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8812. clif_parse_ActionRequest_sub(sd,
  8813. RFIFOB(fd,info->pos[1]),
  8814. RFIFOL(fd,info->pos[0]),
  8815. gettick()
  8816. );
  8817. }
  8818. /// Response to the death/system menu (CZ_RESTART).
  8819. /// 00b2 <type>.B
  8820. /// type:
  8821. /// 0 = restart (respawn)
  8822. /// 1 = char-select (disconnect)
  8823. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8824. {
  8825. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8826. case 0x00:
  8827. pc_respawn(sd,CLR_RESPAWN);
  8828. break;
  8829. case 0x01:
  8830. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8831. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8832. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8833. { //Send to char-server for character selection.
  8834. pc_damage_log_clear(sd,0);
  8835. chrif_charselectreq(sd, session[fd]->client_addr);
  8836. } else {
  8837. clif_disconnect_ack(sd, 1);
  8838. }
  8839. break;
  8840. }
  8841. }
  8842. /// Validates and processes whispered messages (CZ_WHISPER).
  8843. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8844. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8845. {
  8846. struct map_session_data* dstsd;
  8847. int i;
  8848. char *target, *message;
  8849. int namelen, messagelen;
  8850. // validate packet and retrieve name and message
  8851. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8852. return;
  8853. if ( is_atcommand(fd, sd, message, 1) )
  8854. return;
  8855. if (sd->sc.cant.chat)
  8856. return; //no "chatting" while muted.
  8857. if (battle_config.min_chat_delay) { //[Skotlex]
  8858. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8859. return;
  8860. }
  8861. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8862. }
  8863. // Reset idle time when using whisper/main chat.
  8864. sd->idletime = last_tick;
  8865. // Chat logging type 'W' / Whisper
  8866. 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);
  8867. //-------------------------------------------------------//
  8868. // Lordalfa - Paperboy - To whisper NPC commands //
  8869. //-------------------------------------------------------//
  8870. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8871. {
  8872. char* str = target+4; //Skip the NPC: string part.
  8873. struct npc_data* npc;
  8874. if ((npc = npc_name2id(str))) {
  8875. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8876. char *split;
  8877. char output[256];
  8878. str = message;
  8879. // skip codepage indicator, if detected
  8880. if( str[0] == '|' && strlen(str) >= 4 )
  8881. str += 3;
  8882. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8883. split = strchr(str,'#');
  8884. if( split == NULL ) { // use the remaining string
  8885. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8886. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8887. split_data[i][0] = '\0';
  8888. break;
  8889. }
  8890. *split = '\0';
  8891. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8892. str = split+1;
  8893. }
  8894. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8895. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  8896. set_var(sd,output,(char *) split_data[i]);
  8897. }
  8898. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  8899. npc_event(sd,output,0); // Calls the NPC label
  8900. return;
  8901. }
  8902. } else if( target[0] == '#' ) {
  8903. struct Channel *channel = NULL;
  8904. char* chname = target;
  8905. channel = channel_name2channel(chname,sd,3);
  8906. if(channel){
  8907. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  8908. channel_send(channel,sd,message);
  8909. }
  8910. else if( channel->pass[0] == '\0') { //no pass needed
  8911. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  8912. }
  8913. else {
  8914. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  8915. }
  8916. return;
  8917. }
  8918. }
  8919. // searching destination character
  8920. dstsd = map_nick2sd(target);
  8921. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8922. // player is not on this map-server
  8923. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8924. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8925. // and if we ask for 'Test', we must not contact 'test' player
  8926. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8927. intif_wis_message(sd, target, message, messagelen);
  8928. return;
  8929. }
  8930. // if player ignores everyone
  8931. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  8932. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8933. clif_wis_end(fd, 1); // 1: target character is not logged in
  8934. else
  8935. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8936. return;
  8937. }
  8938. // if player is autotrading
  8939. if (dstsd->state.autotrade == 1) {
  8940. char output[256];
  8941. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8942. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8943. return;
  8944. }
  8945. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  8946. // if player ignores the source character
  8947. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8948. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8949. clif_wis_end(fd, 2); // 2: ignored by target
  8950. return;
  8951. }
  8952. }
  8953. // notify sender of success
  8954. clif_wis_end(fd, 0); // 0: success to send wisper
  8955. // Normal message
  8956. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8957. }
  8958. /// /b /nb (CZ_BROADCAST).
  8959. /// Request to broadcast a message on whole server.
  8960. /// 0099 <packet len>.W <text>.?B 00
  8961. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  8962. char command[CHAT_SIZE_MAX+11];
  8963. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8964. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  8965. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  8966. // as the length varies depending on the command used, just block unreasonably long strings
  8967. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8968. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  8969. is_atcommand(fd, sd, command, 1);
  8970. }
  8971. /// Request to pick up an item.
  8972. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8973. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8974. /// There are various variants of this packet, some of them have padding between fields.
  8975. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8976. {
  8977. struct flooritem_data *fitem;
  8978. int map_object_id;
  8979. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8980. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8981. do {
  8982. if (pc_isdead(sd)) {
  8983. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8984. break;
  8985. }
  8986. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8987. break;
  8988. if (pc_cant_act(sd))
  8989. break;
  8990. if (!pc_takeitem(sd, fitem))
  8991. break;
  8992. return;
  8993. } while (0);
  8994. // Client REQUIRES a fail packet or you can no longer pick items.
  8995. clif_additem(sd,0,0,6);
  8996. }
  8997. /// Request to drop an item.
  8998. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8999. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9000. /// There are various variants of this packet, some of them have padding between fields.
  9001. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9002. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9003. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9004. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9005. for(;;) {
  9006. if (pc_isdead(sd))
  9007. break;
  9008. if (pc_cant_act2(sd) || sd->npc_id)
  9009. break;
  9010. if (sd->sc.count && (
  9011. sd->sc.data[SC_AUTOCOUNTER] ||
  9012. sd->sc.data[SC_BLADESTOP] ||
  9013. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9014. ))
  9015. break;
  9016. if (!pc_dropitem(sd, item_index, item_amount))
  9017. break;
  9018. return;
  9019. }
  9020. //Because the client does not like being ignored.
  9021. clif_dropitem(sd, item_index,0);
  9022. }
  9023. /// Request to use an item.
  9024. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9025. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9026. /// There are various variants of this packet, some of them have padding between fields.
  9027. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9028. {
  9029. int n;
  9030. if (pc_isdead(sd)) {
  9031. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9032. return;
  9033. }
  9034. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9035. return;
  9036. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9037. sd->idletime = last_tick;
  9038. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9039. if(n <0 || n >= MAX_INVENTORY)
  9040. return;
  9041. if (!pc_useitem(sd,n))
  9042. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9043. }
  9044. /// Request to equip an item
  9045. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9046. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9047. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9048. {
  9049. int index, req_pos;
  9050. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9051. if(pc_isdead(sd)) {
  9052. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9053. return;
  9054. }
  9055. index = RFIFOW(fd,info->pos[0])-2;
  9056. if (index < 0 || index >= MAX_INVENTORY)
  9057. return; //Out of bounds check.
  9058. if(sd->npc_id) {
  9059. if (!sd->npc_item_flag)
  9060. return;
  9061. } else if (sd->state.storage_flag || sd->sc.opt1)
  9062. ; //You can equip/unequip stuff while storage is open/under status changes
  9063. else if (pc_cant_act2(sd))
  9064. return;
  9065. if(!sd->status.inventory[index].identify) {
  9066. clif_equipitemack(sd,index,0,0); // fail
  9067. return;
  9068. }
  9069. if(!sd->inventory_data[index])
  9070. return;
  9071. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9072. pet_equipitem(sd,index);
  9073. return;
  9074. }
  9075. //Client doesn't send the position for ammo.
  9076. if(sd->inventory_data[index]->type == IT_AMMO)
  9077. pc_equipitem(sd,index,EQP_AMMO);
  9078. else {
  9079. #if PACKETVER >= 20120925
  9080. req_pos = RFIFOL(fd,info->pos[1]);
  9081. #else
  9082. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9083. #endif
  9084. pc_equipitem(sd,index,req_pos);
  9085. }
  9086. }
  9087. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9088. /// 00ab <index>.W
  9089. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9090. {
  9091. int index;
  9092. if(pc_isdead(sd)) {
  9093. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9094. return;
  9095. }
  9096. if (sd->npc_id) {
  9097. if (!sd->npc_item_flag)
  9098. return;
  9099. } else if (sd->state.storage_flag || sd->sc.opt1)
  9100. ; //You can equip/unequip stuff while storage is open/under status changes
  9101. else if (pc_cant_act2(sd))
  9102. return;
  9103. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9104. pc_unequipitem(sd,index,1);
  9105. }
  9106. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9107. /// 0090 <id>.L <type>.B
  9108. /// type:
  9109. /// 1 = click
  9110. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9111. {
  9112. struct block_list *bl;
  9113. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9114. if(pc_isdead(sd)) {
  9115. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9116. return;
  9117. }
  9118. if (pc_cant_act2(sd) || sd->npc_id)
  9119. return;
  9120. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9121. //type = RFIFOB(fd,info->pos[1]);
  9122. if (!bl) return;
  9123. switch (bl->type) {
  9124. case BL_MOB:
  9125. case BL_PC:
  9126. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9127. break;
  9128. case BL_NPC:
  9129. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9130. npc_click(sd,(TBL_NPC*)bl);
  9131. break;
  9132. }
  9133. }
  9134. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9135. /// 00c5 <id>.L <type>.B
  9136. /// type:
  9137. /// 0 = buy
  9138. /// 1 = sell
  9139. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9140. {
  9141. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9142. if (sd->state.trading)
  9143. return;
  9144. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9145. }
  9146. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9147. /// 00ca <result>.B
  9148. /// result:
  9149. /// 0 = "The deal has successfully completed."
  9150. /// 1 = "You do not have enough zeny."
  9151. /// 2 = "You are over your Weight Limit."
  9152. /// 3 = "Out of the maximum capacity, you have too many items."
  9153. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9154. {
  9155. int fd = sd->fd;
  9156. WFIFOHEAD(fd,packet_len(0xca));
  9157. WFIFOW(fd,0) = 0xca;
  9158. WFIFOB(fd,2) = result;
  9159. WFIFOSET(fd,packet_len(0xca));
  9160. }
  9161. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9162. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9163. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9164. {
  9165. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9166. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9167. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9168. int result;
  9169. if( sd->state.trading || !sd->npc_shopid )
  9170. result = 1;
  9171. else
  9172. result = npc_buylist(sd,n,item_list);
  9173. sd->npc_shopid = 0; //Clear shop data.
  9174. clif_npc_buy_result(sd, result);
  9175. }
  9176. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9177. /// 00cb <result>.B
  9178. /// result:
  9179. /// 0 = "The deal has successfully completed."
  9180. /// 1 = "The deal has failed."
  9181. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9182. {
  9183. int fd = sd->fd;
  9184. WFIFOHEAD(fd,packet_len(0xcb));
  9185. WFIFOW(fd,0) = 0xcb;
  9186. WFIFOB(fd,2) = result;
  9187. WFIFOSET(fd,packet_len(0xcb));
  9188. }
  9189. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9190. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9191. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9192. {
  9193. int fail=0,n;
  9194. unsigned short *item_list;
  9195. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9196. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9197. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9198. if (sd->state.trading || !sd->npc_shopid)
  9199. fail = 1;
  9200. else
  9201. fail = npc_selllist(sd,n,item_list);
  9202. sd->npc_shopid = 0; //Clear shop data.
  9203. clif_npc_sell_result(sd, fail);
  9204. }
  9205. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9206. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9207. /// type:
  9208. /// 0 = private
  9209. /// 1 = public
  9210. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9211. {
  9212. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9213. int len = RFIFOW(fd,info->pos[0])-15;
  9214. int limit = RFIFOW(fd,info->pos[1]);
  9215. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9216. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9217. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9218. char s_password[CHATROOM_PASS_SIZE];
  9219. char s_title[CHATROOM_TITLE_SIZE];
  9220. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9221. return;
  9222. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9223. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9224. return;
  9225. }
  9226. if( npc_isnear(&sd->bl) ) {
  9227. // uncomment to send msg_txt.
  9228. //char output[150];
  9229. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9230. //clif_displaymessage(sd->fd, output);
  9231. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9232. return;
  9233. }
  9234. if( len <= 0 )
  9235. return; // invalid input
  9236. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9237. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9238. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9239. }
  9240. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9241. /// 00d9 <chat ID>.L <passwd>.8B
  9242. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9243. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9244. int chatid = RFIFOL(fd,info->pos[0]);
  9245. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9246. chat_joinchat(sd,chatid,password);
  9247. }
  9248. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9249. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9250. /// type:
  9251. /// 0 = private
  9252. /// 1 = public
  9253. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9254. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9255. int len = RFIFOW(fd,info->pos[0])-15;
  9256. int limit = RFIFOW(fd,info->pos[1]);
  9257. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9258. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9259. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9260. char s_password[CHATROOM_PASS_SIZE];
  9261. char s_title[CHATROOM_TITLE_SIZE];
  9262. if( len <= 0 )
  9263. return; // invalid input
  9264. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9265. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9266. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9267. }
  9268. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9269. /// 00e0 <role>.L <nick>.24B
  9270. /// role:
  9271. /// 0 = owner
  9272. /// 1 = normal
  9273. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9274. {
  9275. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9276. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9277. }
  9278. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9279. /// 00e2 <name>.24B
  9280. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9281. {
  9282. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9283. }
  9284. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9285. /// 00e3
  9286. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9287. {
  9288. chat_leavechat(sd,0);
  9289. }
  9290. //Handles notifying asker and rejecter of what has just ocurred.
  9291. //Type is used to determine the correct msg_txt to use:
  9292. //0:
  9293. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9294. {
  9295. const char* msg;
  9296. char output[256];
  9297. // Your request has been rejected by autoreject option.
  9298. msg = msg_txt(sd,392);
  9299. clif_disp_onlyself(sd, msg, strlen(msg));
  9300. //Notice that a request was rejected.
  9301. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9302. clif_disp_onlyself(tsd, output, strlen(output));
  9303. }
  9304. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9305. /// 00e4 <account id>.L
  9306. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9307. {
  9308. struct map_session_data *t_sd;
  9309. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9310. if(!sd->chatID && pc_cant_act(sd))
  9311. return; //You can trade while in a chatroom.
  9312. // @noask [LuzZza]
  9313. if(t_sd && t_sd->state.noask) {
  9314. clif_noask_sub(sd, t_sd, 0);
  9315. return;
  9316. }
  9317. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9318. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9319. return;
  9320. }
  9321. trade_traderequest(sd,t_sd);
  9322. }
  9323. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9324. /// 00e6 <result>.B
  9325. /// result:
  9326. /// 3 = accepted
  9327. /// 4 = rejected
  9328. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9329. {
  9330. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9331. }
  9332. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9333. /// 00e8 <index>.W <amount>.L
  9334. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9335. {
  9336. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9337. short index = RFIFOW(fd,info->pos[0]);
  9338. int amount = RFIFOL(fd,info->pos[1]);
  9339. if( index == 0 )
  9340. trade_tradeaddzeny(sd, amount);
  9341. else
  9342. trade_tradeadditem(sd, index, (short)amount);
  9343. }
  9344. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9345. /// 00eb
  9346. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9347. {
  9348. trade_tradeok(sd);
  9349. }
  9350. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9351. /// 00ed
  9352. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9353. {
  9354. trade_tradecancel(sd);
  9355. }
  9356. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9357. /// 00ef
  9358. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9359. {
  9360. trade_tradecommit(sd);
  9361. }
  9362. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9363. /// 0118
  9364. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9365. {
  9366. pc_stop_attack(sd);
  9367. }
  9368. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9369. /// 0126 <index>.W <amount>.L
  9370. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9371. {
  9372. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9373. short flag = 0;
  9374. if (pc_istrading(sd))
  9375. return;
  9376. if (!pc_iscarton(sd))
  9377. return;
  9378. if ((flag = pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1])))) {
  9379. clif_dropitem(sd,RFIFOW(fd,info->pos[0])-2,0);
  9380. clif_cart_additem_ack(sd,(flag==1)?ADDITEM_TO_CART_FAIL_WEIGHT:ADDITEM_TO_CART_FAIL_COUNT);
  9381. }
  9382. }
  9383. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9384. /// 0127 <index>.W <amount>.L
  9385. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9386. {
  9387. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9388. if (!pc_iscarton(sd))
  9389. return;
  9390. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,
  9391. RFIFOL(fd,info->pos[1]));
  9392. }
  9393. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9394. /// 012a
  9395. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9396. {
  9397. /**
  9398. * Attempts to remove these options when this function is called (will remove all available)
  9399. **/
  9400. #ifdef NEW_CARTS
  9401. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9402. if( sd->sc.data[SC_PUSH_CART] )
  9403. pc_setcart(sd,0);
  9404. #else
  9405. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9406. #endif
  9407. }
  9408. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9409. /// 01af <num>.W
  9410. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9411. {// TODO: State tracking?
  9412. int type;
  9413. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  9414. return;
  9415. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9416. #ifdef NEW_CARTS
  9417. if( (type == 9 && sd->status.base_level > 131) ||
  9418. (type == 8 && sd->status.base_level > 121) ||
  9419. (type == 7 && sd->status.base_level > 111) ||
  9420. (type == 6 && sd->status.base_level > 101) ||
  9421. (type == 5 && sd->status.base_level > 90) ||
  9422. (type == 4 && sd->status.base_level > 80) ||
  9423. (type == 3 && sd->status.base_level > 65) ||
  9424. (type == 2 && sd->status.base_level > 40) ||
  9425. (type == 1))
  9426. #else
  9427. if( (type == 5 && sd->status.base_level > 90) ||
  9428. (type == 4 && sd->status.base_level > 80) ||
  9429. (type == 3 && sd->status.base_level > 65) ||
  9430. (type == 2 && sd->status.base_level > 40) ||
  9431. (type == 1))
  9432. #endif
  9433. pc_setcart(sd,type);
  9434. }
  9435. /// Request to increase status (CZ_STATUS_CHANGE).
  9436. /// 00bb <status id>.W <amount>.B
  9437. /// status id:
  9438. /// SP_STR ~ SP_LUK
  9439. /// amount:
  9440. /// client sends always 1 for this, even when using /str+ and
  9441. /// the like
  9442. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9443. {
  9444. //char amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9445. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9446. }
  9447. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9448. /// 0112 <skill id>.W
  9449. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9450. {
  9451. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9452. }
  9453. 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)
  9454. {
  9455. int lv;
  9456. if( !hd )
  9457. return;
  9458. if( skill_isNotOk_hom(skill_id, hd) )
  9459. return;
  9460. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9461. target_id = hd->bl.id;
  9462. if( hd->ud.skilltimer != INVALID_TIMER )
  9463. {
  9464. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9465. }
  9466. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9467. return;
  9468. lv = merc_hom_checkskill(hd, skill_id);
  9469. if( skill_lv > lv )
  9470. skill_lv = lv;
  9471. if( skill_lv )
  9472. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9473. }
  9474. 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)
  9475. {
  9476. int lv;
  9477. if( !hd )
  9478. return;
  9479. if( skill_isNotOk_hom(skill_id, hd) )
  9480. return;
  9481. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9482. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9483. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9484. return;
  9485. if( hd->sc.data[SC_BASILICA] )
  9486. return;
  9487. lv = merc_hom_checkskill(hd, skill_id);
  9488. if( skill_lv > lv )
  9489. skill_lv = lv;
  9490. if( skill_lv )
  9491. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9492. }
  9493. 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)
  9494. {
  9495. int lv;
  9496. if( !md )
  9497. return;
  9498. if( skill_isNotOk_mercenary(skill_id, md) )
  9499. return;
  9500. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9501. target_id = md->bl.id;
  9502. if( md->ud.skilltimer != INVALID_TIMER )
  9503. {
  9504. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9505. }
  9506. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9507. return;
  9508. lv = mercenary_checkskill(md, skill_id);
  9509. if( skill_lv > lv )
  9510. skill_lv = lv;
  9511. if( skill_lv )
  9512. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9513. }
  9514. 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)
  9515. {
  9516. int lv;
  9517. if( !md )
  9518. return;
  9519. if( skill_isNotOk_mercenary(skill_id, md) )
  9520. return;
  9521. if( md->ud.skilltimer != INVALID_TIMER )
  9522. return;
  9523. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9524. {
  9525. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9526. return;
  9527. }
  9528. if( md->sc.data[SC_BASILICA] )
  9529. return;
  9530. lv = mercenary_checkskill(md, skill_id);
  9531. if( skill_lv > lv )
  9532. skill_lv = lv;
  9533. if( skill_lv )
  9534. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9535. }
  9536. /// Request to use a targeted skill.
  9537. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9538. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9539. /// There are various variants of this packet, some of them have padding between fields.
  9540. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9541. {
  9542. uint16 skill_id, skill_lv;
  9543. int tmp, target_id;
  9544. unsigned int tick = gettick();
  9545. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9546. skill_lv = RFIFOW(fd,info->pos[0]);
  9547. skill_id = RFIFOW(fd,info->pos[1]);
  9548. target_id = RFIFOL(fd,info->pos[2]);
  9549. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9550. tmp = skill_get_inf(skill_id);
  9551. if (tmp&INF_GROUND_SKILL || !tmp)
  9552. return; //Using a ground/passive skill on a target? WRONG.
  9553. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9554. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9555. return;
  9556. }
  9557. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9558. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9559. return;
  9560. }
  9561. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9562. sd->idletime = last_tick;
  9563. if( sd->npc_id ){
  9564. #ifdef RENEWAL
  9565. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9566. return;
  9567. #else
  9568. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9569. return;
  9570. #endif
  9571. }
  9572. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9573. return;
  9574. if( pc_issit(sd) )
  9575. return;
  9576. if( skill_isNotOk(skill_id, sd) )
  9577. return;
  9578. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9579. target_id = sd->bl.id; // never trust the client
  9580. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9581. target_id = sd->bl.id;
  9582. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9583. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9584. return;
  9585. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9586. if( sd->skillitem != skill_id ) {
  9587. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9588. return;
  9589. }
  9590. }
  9591. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  9592. return;
  9593. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9594. return; // On basilica only caster can use Basilica again to stop it.
  9595. if( sd->menuskill_id ) {
  9596. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9597. clif_menuskill_clear(sd); //Cancel pet capture.
  9598. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9599. return; //Can't use skills while a menu is open.
  9600. }
  9601. if( sd->skillitem == skill_id ) {
  9602. if( skill_lv != sd->skillitemlv )
  9603. skill_lv = sd->skillitemlv;
  9604. if( !(tmp&INF_SELF_SKILL) )
  9605. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9606. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9607. return;
  9608. }
  9609. sd->skillitem = sd->skillitemlv = 0;
  9610. if( skill_id >= GD_SKILLBASE ) {
  9611. if( sd->state.gmaster_flag )
  9612. skill_lv = guild_checkskill(sd->state.gmaster_flag, skill_id);
  9613. else
  9614. skill_lv = 0;
  9615. } else {
  9616. tmp = pc_checkskill(sd, skill_id);
  9617. if( skill_lv > tmp )
  9618. skill_lv = tmp;
  9619. }
  9620. pc_delinvincibletimer(sd);
  9621. if( skill_lv )
  9622. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9623. }
  9624. /*==========================================
  9625. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9626. *------------------------------------------*/
  9627. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9628. {
  9629. unsigned int tick = gettick();
  9630. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9631. return; //Using a target skill on the ground? WRONG.
  9632. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9633. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9634. return;
  9635. }
  9636. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9637. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9638. return;
  9639. }
  9640. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9641. sd->idletime = last_tick;
  9642. if( skill_isNotOk(skill_id, sd) )
  9643. return;
  9644. if( skillmoreinfo != -1 ) {
  9645. if( pc_issit(sd) ) {
  9646. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9647. return;
  9648. }
  9649. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9650. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9651. }
  9652. if( sd->ud.skilltimer != INVALID_TIMER )
  9653. return;
  9654. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9655. if( sd->skillitem != skill_id ) {
  9656. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9657. return;
  9658. }
  9659. }
  9660. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK) )
  9661. return;
  9662. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9663. return; // On basilica only caster can use Basilica again to stop it.
  9664. if( sd->menuskill_id ) {
  9665. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9666. clif_menuskill_clear(sd); //Cancel pet capture.
  9667. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9668. return; //Can't use skills while a menu is open.
  9669. }
  9670. pc_delinvincibletimer(sd);
  9671. if( sd->skillitem == skill_id ) {
  9672. if( skill_lv != sd->skillitemlv )
  9673. skill_lv = sd->skillitemlv;
  9674. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9675. } else {
  9676. int lv;
  9677. sd->skillitem = sd->skillitemlv = 0;
  9678. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9679. if( skill_lv > lv )
  9680. skill_lv = lv;
  9681. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9682. }
  9683. }
  9684. }
  9685. /// Request to use a ground skill.
  9686. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9687. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9688. /// There are various variants of this packet, some of them have padding between fields.
  9689. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9690. {
  9691. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9692. if (pc_cant_act(sd))
  9693. return;
  9694. if (pc_issit(sd))
  9695. return;
  9696. clif_parse_UseSkillToPosSub(fd, sd,
  9697. RFIFOW(fd,info->pos[0]), //skill lv
  9698. RFIFOW(fd,info->pos[1]), //skill num
  9699. RFIFOW(fd,info->pos[2]), //pos x
  9700. RFIFOW(fd,info->pos[3]), //pos y
  9701. -1 //Skill more info.
  9702. );
  9703. }
  9704. /// Request to use a ground skill with text.
  9705. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9706. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9707. /// There are various variants of this packet, some of them have padding between fields.
  9708. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9709. {
  9710. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9711. if (pc_cant_act(sd))
  9712. return;
  9713. if (pc_issit(sd))
  9714. return;
  9715. clif_parse_UseSkillToPosSub(fd, sd,
  9716. RFIFOW(fd,info->pos[0]), //Skill lv
  9717. RFIFOW(fd,info->pos[1]), //Skill num
  9718. RFIFOW(fd,info->pos[2]), //pos x
  9719. RFIFOW(fd,info->pos[3]), //pos y
  9720. info->pos[4] //skill more info
  9721. );
  9722. }
  9723. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9724. /// 011b <skill id>.W <map name>.16B
  9725. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9726. {
  9727. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9728. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9729. char map_name[MAP_NAME_LENGTH];
  9730. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9731. if(skill_id != sd->menuskill_id)
  9732. return;
  9733. if( pc_cant_act(sd) ) {
  9734. clif_menuskill_clear(sd);
  9735. return;
  9736. }
  9737. pc_delinvincibletimer(sd);
  9738. skill_castend_map(sd,skill_id,map_name);
  9739. }
  9740. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9741. /// 011d
  9742. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9743. {
  9744. if (!pc_isdead(sd))
  9745. pc_memo(sd,-1);
  9746. }
  9747. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9748. /// 018e <name id>.W { <material id>.W }*3
  9749. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9750. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9751. int nameid = RFIFOW(fd,info->pos[0]);
  9752. int slot1 = RFIFOW(fd,info->pos[1]);
  9753. int slot2 = RFIFOW(fd,info->pos[2]);
  9754. int slot3 = RFIFOW(fd,info->pos[3]);
  9755. switch( sd->menuskill_id ) {
  9756. case -1:
  9757. case AM_PHARMACY:
  9758. case RK_RUNEMASTERY:
  9759. case GC_RESEARCHNEWPOISON:
  9760. break;
  9761. default:
  9762. return;
  9763. }
  9764. if (pc_istrading(sd)) {
  9765. //Make it fail to avoid shop exploits where you sell something different than you see.
  9766. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9767. clif_menuskill_clear(sd);
  9768. return;
  9769. }
  9770. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9771. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9772. clif_menuskill_clear(sd);
  9773. }
  9774. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9775. /// 025b <mk type>.W <name id>.W
  9776. /// mk type:
  9777. /// 1 = cooking
  9778. /// 2 = arrow
  9779. /// 3 = elemental
  9780. /// 4 = GN_MIX_COOKING
  9781. /// 5 = GN_MAKEBOMB
  9782. /// 6 = GN_S_PHARMACY
  9783. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9784. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9785. int type = RFIFOW(fd,info->pos[0]);
  9786. int nameid = RFIFOW(fd,info->pos[1]);
  9787. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9788. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9789. return;
  9790. if (pc_istrading(sd)) {
  9791. //Make it fail to avoid shop exploits where you sell something different than you see.
  9792. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9793. clif_menuskill_clear(sd);
  9794. return;
  9795. }
  9796. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9797. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9798. clif_menuskill_clear(sd);
  9799. }
  9800. /// Answer to repair weapon item selection dialog
  9801. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9802. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9803. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9804. {
  9805. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9806. return;
  9807. if (pc_istrading(sd)) {
  9808. //Make it fail to avoid shop exploits where you sell something different than you see.
  9809. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9810. clif_menuskill_clear(sd);
  9811. return;
  9812. }
  9813. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9814. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9815. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9816. //for(i = 0; i<MAX_SLOTS; i++)
  9817. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9818. clif_menuskill_clear(sd);
  9819. }
  9820. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9821. /// 0222 <index>.L
  9822. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9823. {
  9824. int idx;
  9825. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9826. return;
  9827. if (pc_istrading(sd)) {
  9828. //Make it fail to avoid shop exploits where you sell something different than you see.
  9829. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9830. clif_menuskill_clear(sd);
  9831. return;
  9832. }
  9833. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9834. skill_weaponrefine(sd, idx-2);
  9835. clif_menuskill_clear(sd);
  9836. }
  9837. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9838. /// 00b8 <npc id>.L <choice>.B
  9839. /// choice:
  9840. /// 1~254 = menu item
  9841. /// 255 = cancel
  9842. /// NOTE: If there were more than 254 items in the list, choice
  9843. /// overflows to choice%256.
  9844. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  9845. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9846. int npc_id = RFIFOL(fd,info->pos[0]);
  9847. uint8 select = RFIFOB(fd,info->pos[1]);
  9848. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9849. #ifdef SECURE_NPCTIMEOUT
  9850. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9851. #endif
  9852. TBL_NPC* nd = map_id2nd(npc_id);
  9853. 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);
  9854. clif_GM_kick(NULL,sd);
  9855. #ifdef SECURE_NPCTIMEOUT
  9856. }
  9857. #endif
  9858. return;
  9859. }
  9860. sd->npc_menu = select;
  9861. npc_scriptcont(sd,npc_id, false);
  9862. }
  9863. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9864. /// 00b9 <npc id>.L
  9865. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9866. {
  9867. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  9868. }
  9869. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9870. /// 0143 <npc id>.L <value>.L
  9871. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  9872. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9873. int npcid = RFIFOL(fd,info->pos[0]);
  9874. int amount = (int)RFIFOL(fd,info->pos[1]);
  9875. sd->npc_amount = amount;
  9876. npc_scriptcont(sd, npcid, false);
  9877. }
  9878. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9879. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9880. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  9881. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9882. int message_len = RFIFOW(fd,info->pos[0])-8;
  9883. int npcid = RFIFOL(fd,info->pos[1]);
  9884. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  9885. if( message_len <= 0 )
  9886. return; // invalid input
  9887. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9888. npc_scriptcont(sd, npcid, false);
  9889. }
  9890. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9891. /// 0146 <npc id>.L
  9892. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9893. {
  9894. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9895. return;
  9896. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  9897. }
  9898. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9899. /// 0178 <index>.W
  9900. /// index:
  9901. /// -1 = cancel
  9902. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9903. {
  9904. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9905. if (sd->menuskill_id != MC_IDENTIFY)
  9906. return;
  9907. if( idx == -1 ) {// cancel pressed
  9908. clif_menuskill_clear(sd);
  9909. return;
  9910. }
  9911. skill_identify(sd,idx-2);
  9912. clif_menuskill_clear(sd);
  9913. }
  9914. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9915. /// 01ae <name id>.W
  9916. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  9917. int nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9918. if (pc_istrading(sd)) {
  9919. //Make it fail to avoid shop exploits where you sell something different than you see.
  9920. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9921. clif_menuskill_clear(sd);
  9922. return;
  9923. }
  9924. switch( sd->menuskill_id ) {
  9925. case AC_MAKINGARROW:
  9926. skill_arrow_create(sd,nameid);
  9927. break;
  9928. case SA_CREATECON:
  9929. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  9930. break;
  9931. case WL_READING_SB:
  9932. skill_spellbook(sd,nameid);
  9933. break;
  9934. case GC_POISONINGWEAPON:
  9935. skill_poisoningweapon(sd,nameid);
  9936. break;
  9937. case NC_MAGICDECOY:
  9938. skill_magicdecoy(sd,nameid);
  9939. break;
  9940. }
  9941. clif_menuskill_clear(sd);
  9942. }
  9943. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9944. /// 01ce <skill id>.L
  9945. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9946. {
  9947. if (sd->menuskill_id != SA_AUTOSPELL)
  9948. return;
  9949. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9950. clif_menuskill_clear(sd);
  9951. }
  9952. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9953. /// 017a <card index>.W
  9954. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9955. {
  9956. if (sd->state.trading != 0)
  9957. return;
  9958. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  9959. }
  9960. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9961. /// 017c <card index>.W <equip index>.W
  9962. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9963. {
  9964. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9965. if (sd->state.trading != 0)
  9966. return;
  9967. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  9968. }
  9969. /// Request of character's name by char ID.
  9970. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9971. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9972. /// There are various variants of this packet, some of them have padding between fields.
  9973. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9974. {
  9975. int charid;
  9976. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9977. map_reqnickdb(sd, charid);
  9978. }
  9979. /// /resetskill /resetstate (CZ_RESET).
  9980. /// Request to reset stats or skills.
  9981. /// 0197 <type>.W
  9982. /// type:
  9983. /// 0 = state
  9984. /// 1 = skill
  9985. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9986. char cmd[15];
  9987. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  9988. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  9989. else
  9990. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  9991. is_atcommand(fd, sd, cmd, 1);
  9992. }
  9993. /// /lb /nlb (CZ_LOCALBROADCAST).
  9994. /// Request to broadcast a message on current map.
  9995. /// 019c <packet len>.W <text>.?B
  9996. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9997. {
  9998. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9999. char command[CHAT_SIZE_MAX+16];
  10000. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10001. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10002. // as the length varies depending on the command used, just block unreasonably long strings
  10003. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10004. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10005. is_atcommand(fd, sd, command, 1);
  10006. }
  10007. /// Request to move an item from inventory to storage.
  10008. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10009. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10010. /// There are various variants of this packet, some of them have padding between fields.
  10011. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10012. {
  10013. int item_index, item_amount;
  10014. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10015. if (pc_istrading(sd))
  10016. return;
  10017. item_index = RFIFOW(fd,info->pos[0])-2;
  10018. item_amount = RFIFOL(fd,info->pos[1]);
  10019. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10020. return;
  10021. if (sd->state.storage_flag == 1)
  10022. storage_storageadd(sd, item_index, item_amount);
  10023. else
  10024. if (sd->state.storage_flag == 2)
  10025. storage_guild_storageadd(sd, item_index, item_amount);
  10026. }
  10027. /// Request to move an item from storage to inventory.
  10028. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10029. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10030. /// There are various variants of this packet, some of them have padding between fields.
  10031. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10032. {
  10033. int item_index, item_amount;
  10034. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10035. item_index = RFIFOW(fd,info->pos[0])-1;
  10036. item_amount = RFIFOL(fd,info->pos[1]);
  10037. if (sd->state.storage_flag == 1)
  10038. storage_storageget(sd, item_index, item_amount);
  10039. else if(sd->state.storage_flag == 2)
  10040. storage_guild_storageget(sd, item_index, item_amount);
  10041. }
  10042. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10043. /// 0129 <index>.W <amount>.L
  10044. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10045. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10046. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10047. int amount = RFIFOL(fd,info->pos[1]);
  10048. if( sd->state.vending )
  10049. return;
  10050. if (!pc_iscarton(sd))
  10051. return;
  10052. if (sd->state.storage_flag == 1)
  10053. storage_storageaddfromcart(sd, idx, amount);
  10054. else if (sd->state.storage_flag == 2)
  10055. storage_guild_storageaddfromcart(sd, idx, amount);
  10056. }
  10057. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10058. /// 0128 <index>.W <amount>.L
  10059. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10060. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10061. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10062. int amount = RFIFOL(fd,info->pos[1]);
  10063. if( sd->state.vending )
  10064. return;
  10065. if (!pc_iscarton(sd))
  10066. return;
  10067. if (sd->state.storage_flag == 1)
  10068. storage_storagegettocart(sd, idx, amount);
  10069. else
  10070. if (sd->state.storage_flag == 2)
  10071. storage_guild_storagegettocart(sd, idx, amount);
  10072. }
  10073. /// Request to close storage (CZ_CLOSE_STORE).
  10074. /// 00f7
  10075. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10076. {
  10077. if( sd->state.storage_flag == 1 )
  10078. storage_storageclose(sd);
  10079. else
  10080. if( sd->state.storage_flag == 2 )
  10081. storage_guild_storageclose(sd);
  10082. }
  10083. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10084. /// 023a <info>.W
  10085. /// info:
  10086. /// 0 = password has not been set yet
  10087. /// 1 = storage is password-protected
  10088. /// 8 = too many wrong passwords
  10089. /// ? = ignored
  10090. /// NOTE: This packet is only available on certain non-kRO clients.
  10091. void clif_storagepassword(struct map_session_data* sd, short info)
  10092. {
  10093. int fd = sd->fd;
  10094. WFIFOHEAD(fd,packet_len(0x23a));
  10095. WFIFOW(fd,0) = 0x23a;
  10096. WFIFOW(fd,2) = info;
  10097. WFIFOSET(fd,packet_len(0x23a));
  10098. }
  10099. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10100. /// 023b <type>.W <password>.16B <new password>.16B
  10101. /// type:
  10102. /// 2 = change password
  10103. /// 3 = check password
  10104. /// NOTE: This packet is only available on certain non-kRO clients.
  10105. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10106. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10107. // int type = RFIFOW(fd,info->pos[0]);
  10108. // char* password = RFIFOP(fd,info->pos[1]);
  10109. // char* new_password = RFIFOP(fd,info->pos[2]);
  10110. // storage_changepass(sd,password,new_password);
  10111. }
  10112. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10113. /// 023c <result>.W <error count>.W
  10114. /// result:
  10115. /// 4 = password change success
  10116. /// 5 = password change failure
  10117. /// 6 = password check success
  10118. /// 7 = password check failure
  10119. /// 8 = too many wrong passwords
  10120. /// ? = ignored
  10121. /// NOTE: This packet is only available on certain non-kRO clients.
  10122. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10123. {
  10124. int fd = sd->fd;
  10125. WFIFOHEAD(fd,packet_len(0x23c));
  10126. WFIFOW(fd,0) = 0x23c;
  10127. WFIFOW(fd,2) = result;
  10128. WFIFOW(fd,4) = error_count;
  10129. WFIFOSET(fd,packet_len(0x23c));
  10130. }
  10131. /// Party creation request
  10132. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10133. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10134. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10135. name[NAME_LENGTH-1] = '\0';
  10136. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10137. clif_displaymessage(fd, msg_txt(sd,227));
  10138. return;
  10139. }
  10140. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10141. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10142. return;
  10143. }
  10144. party_create(sd,name,0,0);
  10145. }
  10146. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10147. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10148. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10149. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10150. int item1 = RFIFOB(fd,info->pos[1]);
  10151. int item2 = RFIFOB(fd,info->pos[2]);
  10152. name[NAME_LENGTH-1] = '\0';
  10153. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10154. clif_displaymessage(fd, msg_txt(sd,227));
  10155. return;
  10156. }
  10157. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10158. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10159. return;
  10160. }
  10161. party_create(sd,name,item1,item2);
  10162. }
  10163. /// Party invitation request
  10164. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10165. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10166. {
  10167. struct map_session_data *t_sd;
  10168. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10169. clif_displaymessage(fd, msg_txt(sd,227));
  10170. return;
  10171. }
  10172. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10173. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10174. clif_noask_sub(sd, t_sd, 1);
  10175. return;
  10176. }
  10177. party_invite(sd, t_sd);
  10178. }
  10179. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10180. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10181. struct map_session_data *t_sd;
  10182. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10183. name[NAME_LENGTH-1] = '\0';
  10184. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10185. clif_displaymessage(fd, msg_txt(sd,227));
  10186. return;
  10187. }
  10188. t_sd = map_nick2sd(name);
  10189. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10190. clif_noask_sub(sd, t_sd, 1);
  10191. return;
  10192. }
  10193. party_invite(sd, t_sd);
  10194. }
  10195. /// Party invitation reply
  10196. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10197. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10198. /// flag:
  10199. /// 0 = reject
  10200. /// 1 = accept
  10201. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10202. {
  10203. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10204. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10205. RFIFOL(fd,info->pos[1]));
  10206. }
  10207. //(CZ_PARTY_JOIN_REQ_ACK)
  10208. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10209. {
  10210. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10211. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10212. RFIFOB(fd,info->pos[1]));
  10213. }
  10214. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10215. /// 0100
  10216. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10217. {
  10218. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10219. clif_displaymessage(fd, msg_txt(sd,227));
  10220. return;
  10221. }
  10222. party_leave(sd);
  10223. }
  10224. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10225. /// 0103 <account id>.L <char name>.24B
  10226. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10227. {
  10228. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10229. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10230. clif_displaymessage(fd, msg_txt(sd,227));
  10231. return;
  10232. }
  10233. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10234. (char*)RFIFOP(fd,info->pos[1]));
  10235. }
  10236. /// Request to change party options.
  10237. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10238. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10239. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10240. {
  10241. struct party_data *p;
  10242. int i,expflag;
  10243. int cmd = RFIFOW(fd,0);
  10244. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10245. if( !sd->status.party_id )
  10246. return;
  10247. p = party_search(sd->status.party_id);
  10248. if( p == NULL )
  10249. return;
  10250. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10251. if( i == MAX_PARTY )
  10252. return; //Shouldn't happen
  10253. if( !p->party.member[i].leader )
  10254. return;
  10255. expflag = RFIFOL(fd,info->pos[0]);
  10256. if(cmd == 0x0102){ //Client can't change the item-field
  10257. party_changeoption(sd, expflag, p->party.item);
  10258. }
  10259. else {
  10260. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10261. party_changeoption(sd, expflag, itemflag);
  10262. }
  10263. }
  10264. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10265. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10266. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10267. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10268. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10269. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10270. char *name, *message;
  10271. int namelen, messagelen;
  10272. // validate packet and retrieve name and message
  10273. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10274. return;
  10275. if( is_atcommand(fd, sd, message, 1) )
  10276. return;
  10277. if (sd->sc.cant.chat)
  10278. return; //no "chatting" while muted.
  10279. if( battle_config.min_chat_delay )
  10280. { //[Skotlex]
  10281. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10282. return;
  10283. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10284. }
  10285. // Reset idle time when using party chat.
  10286. sd->idletime = last_tick;
  10287. party_send_message(sd, text, textlen);
  10288. }
  10289. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10290. /// 07da <account id>.L
  10291. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10292. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10293. }
  10294. /// Party Booking in KRO [Spiria]
  10295. ///
  10296. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10297. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10298. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10299. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10300. short level = RFIFOW(fd,info->pos[0]);
  10301. short mapid = RFIFOW(fd,info->pos[1]);
  10302. int idxpbj = info->pos[2];
  10303. short job[PARTY_BOOKING_JOBS];
  10304. int i;
  10305. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10306. job[i] = RFIFOB(fd,idxpbj+i*2);
  10307. party_booking_register(sd, level, mapid, job);
  10308. }
  10309. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10310. /// 0803 <result>.W
  10311. /// result:
  10312. /// 0 = success
  10313. /// 1 = failure
  10314. /// 2 = already registered
  10315. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10316. {
  10317. int fd = sd->fd;
  10318. WFIFOHEAD(fd,packet_len(0x803));
  10319. WFIFOW(fd,0) = 0x803;
  10320. WFIFOW(fd,2) = flag;
  10321. WFIFOSET(fd,packet_len(0x803));
  10322. }
  10323. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10324. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10325. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10326. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10327. short level = RFIFOW(fd,info->pos[0]);
  10328. short mapid = RFIFOW(fd,info->pos[1]);
  10329. short job = RFIFOW(fd,info->pos[2]);
  10330. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10331. short resultcount = RFIFOW(fd,info->pos[4]);
  10332. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10333. }
  10334. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10335. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10336. /// more results:
  10337. /// 0 = no
  10338. /// 1 = yes
  10339. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10340. {
  10341. int i, j;
  10342. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10343. struct party_booking_ad_info *pb_ad;
  10344. WFIFOHEAD(fd,size*count + 5);
  10345. WFIFOW(fd,0) = 0x805;
  10346. WFIFOW(fd,2) = size*count + 5;
  10347. WFIFOB(fd,4) = more_result;
  10348. for(i=0; i<count; i++)
  10349. {
  10350. pb_ad = results[i];
  10351. WFIFOL(fd,i*size+5) = pb_ad->index;
  10352. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10353. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10354. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10355. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10356. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10357. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10358. }
  10359. WFIFOSET(fd,WFIFOW(fd,2));
  10360. }
  10361. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10362. /// 0806
  10363. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10364. {
  10365. if(party_booking_delete(sd))
  10366. clif_PartyBookingDeleteAck(sd, 0);
  10367. }
  10368. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10369. /// 0807 <result>.W
  10370. /// result:
  10371. /// 0 = success
  10372. /// 1 = success (auto-removed expired ad)
  10373. /// 2 = failure
  10374. /// 3 = nothing registered
  10375. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10376. {
  10377. int fd = sd->fd;
  10378. WFIFOHEAD(fd,packet_len(0x807));
  10379. WFIFOW(fd,0) = 0x807;
  10380. WFIFOW(fd,2) = flag;
  10381. WFIFOSET(fd,packet_len(0x807));
  10382. }
  10383. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10384. /// 0808 { <job>.W }*6
  10385. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10386. {
  10387. short job[PARTY_BOOKING_JOBS];
  10388. int i;
  10389. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10390. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10391. job[i] = RFIFOW(fd,idxpbu+i*2);
  10392. party_booking_update(sd, job);
  10393. }
  10394. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10395. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10396. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10397. {
  10398. int i;
  10399. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10400. if(pb_ad == NULL) return;
  10401. WBUFW(buf,0) = 0x809;
  10402. WBUFL(buf,2) = pb_ad->index;
  10403. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10404. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10405. WBUFW(buf,34) = pb_ad->p_detail.level;
  10406. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10407. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10408. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10409. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10410. }
  10411. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10412. /// 080a <index>.L { <job>.W }*6
  10413. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10414. {
  10415. int i;
  10416. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10417. if(pb_ad == NULL) return;
  10418. WBUFW(buf,0) = 0x80a;
  10419. WBUFL(buf,2) = pb_ad->index;
  10420. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10421. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10422. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10423. }
  10424. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10425. /// 080b <index>.L
  10426. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10427. {
  10428. uint8 buf[6];
  10429. WBUFW(buf,0) = 0x80b;
  10430. WBUFL(buf,2) = index;
  10431. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10432. }
  10433. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10434. /// 012e
  10435. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10436. {
  10437. vending_closevending(sd);
  10438. }
  10439. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10440. /// 0130 <account id>.L
  10441. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10442. {
  10443. if( sd->npc_id ) {// using an NPC
  10444. return;
  10445. }
  10446. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10447. }
  10448. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10449. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10450. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10451. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10452. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10453. int id = (int)RFIFOL(fd,info->pos[1]);
  10454. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10455. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10456. // whether it fails or not, the buy window is closed
  10457. sd->vended_id = 0;
  10458. }
  10459. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10460. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10461. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10462. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10463. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10464. int aid = (int)RFIFOL(fd,info->pos[1]);
  10465. int uid = (int)RFIFOL(fd,info->pos[2]);
  10466. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10467. vending_purchasereq(sd, aid, uid, data, len/4);
  10468. // whether it fails or not, the buy window is closed
  10469. sd->vended_id = 0;
  10470. }
  10471. /// Confirm or cancel the shop preparation window.
  10472. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10473. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10474. /// result:
  10475. /// 0 = canceled
  10476. /// 1 = open
  10477. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10478. int cmd = RFIFOW(fd,0);
  10479. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10480. short len = (short)RFIFOW(fd,info->pos[0]);
  10481. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10482. bool flag;
  10483. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10484. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10485. len -= 84;
  10486. }
  10487. else { //(CZ_REQ_OPENSTORE2)
  10488. len -= 85;
  10489. flag = (bool)RFIFOB(fd,info->pos[2]);
  10490. if( !flag )
  10491. sd->state.prevend = 0;
  10492. }
  10493. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10494. return;
  10495. if( map[sd->bl.m].flag.novending ) {
  10496. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10497. return;
  10498. }
  10499. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10500. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10501. return;
  10502. }
  10503. if( message[0] == '\0' ) // invalid input
  10504. return;
  10505. vending_openvending(sd, message, data, len/8);
  10506. }
  10507. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10508. /// 0165 <char id>.L <guild name>.24B
  10509. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10510. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10511. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10512. name[NAME_LENGTH-1] = '\0';
  10513. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10514. clif_displaymessage(fd, msg_txt(sd,228));
  10515. return;
  10516. }
  10517. guild_create(sd, name);
  10518. }
  10519. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10520. /// 014d
  10521. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10522. {
  10523. clif_guild_masterormember(sd);
  10524. }
  10525. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10526. /// 014f <type>.L
  10527. /// type:
  10528. /// 0 = basic info
  10529. /// 1 = member manager
  10530. /// 2 = positions
  10531. /// 3 = skills
  10532. /// 4 = expulsion list
  10533. /// 5 = unknown (GM_ALLGUILDLIST)
  10534. /// 6 = notice
  10535. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10536. {
  10537. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10538. if( !sd->status.guild_id && !sd->bg_id )
  10539. return;
  10540. switch( type )
  10541. {
  10542. case 0: // Basic Information Guild, hostile alliance information
  10543. clif_guild_basicinfo(sd);
  10544. clif_guild_allianceinfo(sd);
  10545. break;
  10546. case 1: // Members list, list job title
  10547. clif_guild_positionnamelist(sd);
  10548. clif_guild_memberlist(sd);
  10549. break;
  10550. case 2: // List job title, title information list
  10551. clif_guild_positionnamelist(sd);
  10552. clif_guild_positioninfolist(sd);
  10553. break;
  10554. case 3: // Skill list
  10555. clif_guild_skillinfo(sd);
  10556. break;
  10557. case 4: // Expulsion list
  10558. clif_guild_expulsionlist(sd);
  10559. break;
  10560. default:
  10561. ShowError("clif: guild request info: unknown type %d\n", type);
  10562. break;
  10563. }
  10564. }
  10565. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10566. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10567. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10568. {
  10569. int i;
  10570. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10571. int len = RFIFOW(fd,info->pos[0]);
  10572. int idxgpos = info->pos[1];
  10573. if(!sd->state.gmaster_flag)
  10574. return;
  10575. for(i = idxgpos; i < len; i += 40 ){
  10576. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10577. }
  10578. }
  10579. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10580. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10581. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10582. {
  10583. int i;
  10584. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10585. int len = RFIFOW(fd,info->pos[0]);
  10586. int idxgpos = info->pos[1];
  10587. if(!sd->state.gmaster_flag)
  10588. return;
  10589. for(i=idxgpos;i<len;i+=12){
  10590. guild_change_memberposition(sd->status.guild_id,
  10591. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10592. }
  10593. }
  10594. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10595. /// 0151 <guild id>.L
  10596. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10597. {
  10598. struct guild* g;
  10599. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10600. if( (g = guild_search(guild_id)) != NULL )
  10601. clif_guild_emblem(sd,g);
  10602. }
  10603. /// Validates data of a guild emblem (compressed bitmap)
  10604. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len){
  10605. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10606. unsigned long buf_len = sizeof(buf);
  10607. int i,j, transcount=1, offset=0, tmp[3];
  10608. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10609. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10610. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10611. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10612. ))
  10613. return -1;
  10614. if(battle_config.emblem_transparency_limit != 100){
  10615. for(i=offset; i<buf_len-1; i++){
  10616. j = i%3;
  10617. tmp[j] = RBUFL(buf,i);
  10618. if(j==2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10619. transcount++;
  10620. }
  10621. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10622. return -2;
  10623. }
  10624. return 0;
  10625. }
  10626. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10627. /// 0153 <packet len>.W <emblem data>.?B
  10628. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10629. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10630. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10631. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10632. int emb_val=0;
  10633. if( !emblem_len || !sd->state.gmaster_flag )
  10634. return;
  10635. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10636. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10637. return;
  10638. }
  10639. emb_val = clif_validate_emblem(emblem, emblem_len);
  10640. if(emb_val ==-1 ){
  10641. 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);
  10642. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10643. return;
  10644. } else if(emb_val == -2){
  10645. char output[128];
  10646. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10647. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10648. return;
  10649. }
  10650. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10651. }
  10652. /// Guild notice update request (CZ_GUILD_NOTICE).
  10653. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10654. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10655. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10656. int guild_id = RFIFOL(fd,info->pos[0]);
  10657. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10658. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10659. if(!sd->state.gmaster_flag)
  10660. return;
  10661. // compensate for some client defects when using multilanguage mode
  10662. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10663. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10664. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10665. guild_change_notice(sd, guild_id, msg1, msg2);
  10666. }
  10667. // Helper function for guild invite functions
  10668. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10669. {
  10670. if (t_sd == NULL) // not online or does not exist
  10671. return 1;
  10672. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10673. clif_displaymessage(fd, msg_txt(sd,228));
  10674. return 1;
  10675. }
  10676. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10677. clif_noask_sub(sd, t_sd, 2);
  10678. return 1;
  10679. }
  10680. guild_invite(sd, t_sd);
  10681. return 0;
  10682. }
  10683. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10684. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10685. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10686. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10687. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10688. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10689. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10690. if (clif_sub_guild_invite(fd, sd, t_sd))
  10691. return;
  10692. }
  10693. /// Guild invite request (/guildinvite)
  10694. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10695. void
  10696. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10697. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10698. if (clif_sub_guild_invite(fd, sd, t_sd))
  10699. return;
  10700. }
  10701. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10702. /// 016b <guild id>.L <answer>.L
  10703. /// answer:
  10704. /// 0 = refuse
  10705. /// 1 = accept
  10706. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10707. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10708. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10709. RFIFOL(fd,info->pos[1]));
  10710. }
  10711. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10712. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10713. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10714. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10715. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10716. clif_displaymessage(fd, msg_txt(sd,228));
  10717. return;
  10718. }
  10719. if( sd->bg_id ) {
  10720. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10721. return;
  10722. }
  10723. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10724. RFIFOL(fd,info->pos[1]),
  10725. RFIFOL(fd,info->pos[2]),
  10726. (char*)RFIFOP(fd,info->pos[3]));
  10727. }
  10728. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10729. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10730. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10731. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10732. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10733. { // Guild locked.
  10734. clif_displaymessage(fd, msg_txt(sd,228));
  10735. return;
  10736. }
  10737. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10738. RFIFOL(fd,info->pos[1]),
  10739. RFIFOL(fd,info->pos[2]),
  10740. (char*)RFIFOP(fd,info->pos[3]));
  10741. }
  10742. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10743. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10744. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10745. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10746. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10747. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10748. char *name, *message;
  10749. int namelen, messagelen;
  10750. // validate packet and retrieve name and message
  10751. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10752. return;
  10753. if( is_atcommand(fd, sd, message, 1) )
  10754. return;
  10755. if (sd->sc.cant.chat)
  10756. return; //no "chatting" while muted.
  10757. if( battle_config.min_chat_delay )
  10758. { //[Skotlex]
  10759. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10760. return;
  10761. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10762. }
  10763. // Reset idle time when using guild chat.
  10764. sd->idletime = last_tick;
  10765. if( sd->bg_id )
  10766. bg_send_message(sd, text, textlen);
  10767. else
  10768. guild_send_message(sd, text, textlen);
  10769. }
  10770. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10771. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10772. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10773. {
  10774. struct map_session_data *t_sd;
  10775. if(!sd->state.gmaster_flag)
  10776. return;
  10777. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10778. clif_displaymessage(fd, msg_txt(sd,228));
  10779. return;
  10780. }
  10781. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10782. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10783. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10784. // @noask [LuzZza]
  10785. if(t_sd && t_sd->state.noask) {
  10786. clif_noask_sub(sd, t_sd, 3);
  10787. return;
  10788. }
  10789. guild_reqalliance(sd,t_sd);
  10790. }
  10791. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10792. /// 0172 <inviter account id>.L <answer>.L
  10793. /// answer:
  10794. /// 0 = refuse
  10795. /// 1 = accept
  10796. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10797. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10798. guild_reply_reqalliance(sd,
  10799. RFIFOL(fd,info->pos[0]),
  10800. RFIFOL(fd,info->pos[1]));
  10801. }
  10802. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10803. /// 0183 <opponent guild id>.L <relation>.L
  10804. /// relation:
  10805. /// 0 = Ally
  10806. /// 1 = Enemy
  10807. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10808. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10809. if(!sd->state.gmaster_flag)
  10810. return;
  10811. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10812. clif_displaymessage(fd, msg_txt(sd,228));
  10813. return;
  10814. }
  10815. guild_delalliance(sd,
  10816. RFIFOL(fd,info->pos[0]),
  10817. RFIFOL(fd,info->pos[1]));
  10818. }
  10819. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10820. /// 0180 <account id>.L
  10821. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10822. {
  10823. struct map_session_data *t_sd;
  10824. if(!sd->state.gmaster_flag)
  10825. return;
  10826. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10827. clif_displaymessage(fd, msg_txt(sd,228));
  10828. return;
  10829. }
  10830. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10831. // @noask [LuzZza]
  10832. if(t_sd && t_sd->state.noask) {
  10833. clif_noask_sub(sd, t_sd, 4);
  10834. return;
  10835. }
  10836. guild_opposition(sd,t_sd);
  10837. }
  10838. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10839. /// 015d <key>.40B
  10840. /// key:
  10841. /// now guild name; might have been (intended) email, since the
  10842. /// field name and size is same as the one in CH_DELETE_CHAR.
  10843. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10844. {
  10845. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10846. clif_displaymessage(fd, msg_txt(sd,228));
  10847. return;
  10848. }
  10849. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10850. }
  10851. /// Pet
  10852. ///
  10853. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10854. /// 01a1 <type>.B
  10855. /// type:
  10856. /// 0 = pet information
  10857. /// 1 = feed
  10858. /// 2 = performance
  10859. /// 3 = return to egg
  10860. /// 4 = unequip accessory
  10861. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  10862. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10863. }
  10864. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10865. /// 019f <id>.L
  10866. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  10867. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10868. }
  10869. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10870. /// 01a7 <index>.W
  10871. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  10872. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1) {
  10873. //Forged packet, disconnect them [Kevin]
  10874. clif_authfail_fd(fd, 0);
  10875. return;
  10876. }
  10877. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10878. clif_menuskill_clear(sd);
  10879. }
  10880. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10881. /// 01a9 <data>.L
  10882. /// data:
  10883. /// is either emotion (@see enum emotion_type) or a compound value
  10884. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10885. /// entry (given in parentheses) in data\pettalktable.xml
  10886. /// act id:
  10887. /// 0 = feeding
  10888. /// 1 = hunting
  10889. /// 2 = danger
  10890. /// 3 = dead
  10891. /// 4 = normal (stand)
  10892. /// 5 = special performance (perfor_s)
  10893. /// 6 = level up (levelup)
  10894. /// 7 = performance 1 (perfor_1)
  10895. /// 8 = performance 2 (perfor_2)
  10896. /// 9 = performance 3 (perfor_3)
  10897. /// 10 = log-in greeting (connect)
  10898. /// hungry value:
  10899. /// 0 = very hungry (hungry)
  10900. /// 1 = hungry (bit_hungry)
  10901. /// 2 = satisfied (noting)
  10902. /// 3 = stuffed (full)
  10903. /// 4 = full (so_full)
  10904. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10905. {
  10906. if(sd->pd)
  10907. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10908. }
  10909. /// Request to change pet's name (CZ_RENAME_PET).
  10910. /// 01a5 <name>.24B
  10911. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10912. {
  10913. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10914. }
  10915. /// /kill (CZ_DISCONNECT_CHARACTER).
  10916. /// Request to disconnect a character.
  10917. /// 00cc <account id>.L
  10918. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10919. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10920. {
  10921. struct block_list *target;
  10922. int tid;
  10923. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10924. target = map_id2bl(tid);
  10925. if (!target) {
  10926. clif_GM_kickack(sd, 0);
  10927. return;
  10928. }
  10929. switch (target->type) {
  10930. case BL_PC:
  10931. {
  10932. char command[NAME_LENGTH+6];
  10933. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  10934. is_atcommand(fd, sd, command, 1);
  10935. }
  10936. break;
  10937. /**
  10938. * This one does not invoke any atcommand, so we need to check for permissions.
  10939. */
  10940. case BL_MOB:
  10941. {
  10942. char command[100];
  10943. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10944. clif_GM_kickack(sd, 0);
  10945. return;
  10946. }
  10947. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  10948. log_atcommand(sd, command);
  10949. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10950. }
  10951. break;
  10952. case BL_NPC:
  10953. {
  10954. struct npc_data* nd = (struct npc_data *)target;
  10955. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  10956. npc_unload_duplicates(nd);
  10957. npc_unload(nd,true);
  10958. npc_read_event_script();
  10959. }
  10960. }
  10961. break;
  10962. default:
  10963. clif_GM_kickack(sd, 0);
  10964. }
  10965. }
  10966. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10967. /// Request to disconnect all characters.
  10968. /// 00ce
  10969. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10970. char cmd[15];
  10971. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  10972. is_atcommand(fd, sd, cmd, 1);
  10973. }
  10974. /// /remove (CZ_REMOVE_AID).
  10975. /// Request to warp to a character with given login ID.
  10976. /// 01ba <account name>.24B
  10977. /// /shift (CZ_SHIFT).
  10978. /// Request to warp to a character with given name.
  10979. /// 01bb <char name>.24B
  10980. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10981. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10982. char *player_name;
  10983. char command[NAME_LENGTH+8];
  10984. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10985. player_name[NAME_LENGTH-1] = '\0';
  10986. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  10987. is_atcommand(fd, sd, command, 1);
  10988. }
  10989. /// /remove (CZ_REMOVE_AID_SSO).
  10990. /// Request to warp to a character with given account ID.
  10991. /// 0843 <account id>.L
  10992. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10993. {
  10994. int account_id;
  10995. struct map_session_data* pl_sd;
  10996. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10997. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  10998. char command[NAME_LENGTH+8];
  10999. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11000. is_atcommand(fd, sd, command, 1);
  11001. }
  11002. }
  11003. /// /recall (CZ_RECALL).
  11004. /// Request to summon a player with given login ID to own position.
  11005. /// 01bc <account name>.24B
  11006. /// /summon (CZ_RECALL_GID).
  11007. /// Request to summon a player with given name to own position.
  11008. /// 01bd <char name>.24B
  11009. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11010. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11011. char *player_name;
  11012. char command [NAME_LENGTH+8];
  11013. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11014. player_name[NAME_LENGTH-1] = '\0';
  11015. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11016. is_atcommand(fd, sd, command, 1);
  11017. }
  11018. /// /recall (CZ_RECALL_SSO).
  11019. /// Request to summon a player with given account ID to own position.
  11020. /// 0842 <account id>.L
  11021. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11022. {
  11023. int account_id;
  11024. struct map_session_data* pl_sd;
  11025. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11026. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11027. char command[NAME_LENGTH+8];
  11028. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11029. is_atcommand(fd, sd, command, 1);
  11030. }
  11031. }
  11032. /// /item /monster (CZ_ITEM_CREATE).
  11033. /// Request to make items or spawn monsters.
  11034. /// 013f <item/mob name>.24B
  11035. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  11036. {
  11037. char *monster_item_name;
  11038. char command[NAME_LENGTH+10];
  11039. monster_item_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11040. monster_item_name[NAME_LENGTH-1] = '\0';
  11041. // FIXME: Should look for item first, then for monster.
  11042. // FIXME: /monster takes mob_db Sprite_Name as argument
  11043. if( mobdb_searchname(monster_item_name) ) {
  11044. safesnprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  11045. is_atcommand(fd, sd, command, 1);
  11046. return;
  11047. }
  11048. // FIXME: Stackables have a quantity of 20.
  11049. // FIXME: Equips are supposed to be unidentified.
  11050. if( itemdb_searchname(monster_item_name) ) {
  11051. safesnprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  11052. is_atcommand(fd, sd, command, 1);
  11053. return;
  11054. }
  11055. }
  11056. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11057. /// 019d <effect state>.L
  11058. /// effect state:
  11059. /// TODO: Any OPTION_* ?
  11060. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11061. char cmd[6];
  11062. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11063. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11064. is_atcommand(fd, sd, cmd, 1);
  11065. }
  11066. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11067. /// 0149 <account id>.L <type>.B <value>.W
  11068. /// type:
  11069. /// 0 = positive points
  11070. /// 1 = negative points
  11071. /// 2 = self mute (+10 minutes)
  11072. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11073. {
  11074. int id, type, value;
  11075. struct map_session_data *dstsd;
  11076. char command[NAME_LENGTH+15];
  11077. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11078. id = RFIFOL(fd,info->pos[0]);
  11079. type = RFIFOB(fd,info->pos[1]);
  11080. value = RFIFOW(fd,info->pos[2]);
  11081. if( type == 0 )
  11082. value = -value;
  11083. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11084. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11085. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11086. return;
  11087. dstsd = map_id2sd(id);
  11088. if( dstsd == NULL )
  11089. return;
  11090. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11091. is_atcommand(fd, sd, command, 1);
  11092. }
  11093. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11094. /// GM adjustment of a player's manner value by -60.
  11095. /// 0212 <char name>.24B
  11096. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11097. {
  11098. char command[NAME_LENGTH+15];
  11099. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11100. name[NAME_LENGTH-1] = '\0';
  11101. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11102. is_atcommand(fd, sd, command, 1);
  11103. }
  11104. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11105. /// 01e0 <account id>.L <account name>.24B
  11106. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  11107. {
  11108. int fd = sd->fd;
  11109. WFIFOHEAD(fd,packet_len(0x1e0));
  11110. WFIFOW(fd,0) = 0x1e0;
  11111. WFIFOL(fd,2) = account_id;
  11112. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11113. WFIFOSET(fd,packet_len(0x1e0));
  11114. }
  11115. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11116. /// 01df <account id>.L
  11117. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11118. {
  11119. char command[30];
  11120. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11121. //tmp get all display
  11122. safesnprintf(command,sizeof(command),"%caccinfo %d", atcommand_symbol, account_id);
  11123. is_atcommand(fd, sd, command, 1);
  11124. //clif_account_name(sd, account_id, ""); //! TODO request to login-serv
  11125. }
  11126. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11127. /// GM single cell type change request.
  11128. /// 0198 <x>.W <y>.W <type>.W
  11129. /// type:
  11130. /// 0 = not walkable
  11131. /// 1 = walkable
  11132. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11133. {
  11134. int x,y,type;
  11135. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11136. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11137. return;
  11138. x = RFIFOW(fd,info->pos[0]);
  11139. y = RFIFOW(fd,info->pos[1]);
  11140. type = RFIFOW(fd,info->pos[2]);
  11141. map_setgatcell(sd->bl.m,x,y,type);
  11142. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11143. //FIXME: once players leave the map, the client 'forgets' this information.
  11144. }
  11145. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11146. /// Request to allow/deny whispers from a nick.
  11147. /// 00cf <nick>.24B <type>.B
  11148. /// type:
  11149. /// 0 = (/ex nick) deny speech from nick
  11150. /// 1 = (/in nick) allow speech from nick
  11151. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11152. {
  11153. char* nick;
  11154. uint8 type;
  11155. int i;
  11156. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11157. nick = (char*)RFIFOP(fd,info->pos[0]);
  11158. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11159. type = RFIFOB(fd,info->pos[1]);
  11160. if( type == 0 ) { // Add name to ignore list (block)
  11161. if (strcmp(wisp_server_name, nick) == 0) {
  11162. clif_wisexin(sd, type, 1); // fail
  11163. return;
  11164. }
  11165. // try to find a free spot, while checking for duplicates at the same time
  11166. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11167. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11168. clif_wisexin(sd, type, 2); // too many blocks
  11169. return;
  11170. }
  11171. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11172. clif_wisexin(sd, type, 0); // Aegis reports success.
  11173. return;
  11174. }
  11175. //Insert in position i
  11176. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11177. } else { // Remove name from ignore list (unblock)
  11178. // find entry
  11179. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11180. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11181. clif_wisexin(sd, type, 1); // fail
  11182. return;
  11183. }
  11184. // move everything one place down to overwrite removed entry
  11185. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11186. // wipe last entry
  11187. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11188. }
  11189. clif_wisexin(sd, type, 0); // success
  11190. }
  11191. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11192. /// Request to allow/deny all whispers.
  11193. /// 00d0 <type>.B
  11194. /// type:
  11195. /// 0 = (/exall) deny all speech
  11196. /// 1 = (/inall) allow all speech
  11197. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11198. {
  11199. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11200. if( type == 0 ) {// Deny all
  11201. if( sd->state.ignoreAll ) {
  11202. flag = 1; // fail
  11203. } else {
  11204. sd->state.ignoreAll = 1;
  11205. flag = 0; // success
  11206. }
  11207. } else {//Unblock everyone
  11208. if( sd->state.ignoreAll ) {
  11209. sd->state.ignoreAll = 0;
  11210. flag = 0; // success
  11211. } else {
  11212. if (sd->ignore[0].name[0] != '\0')
  11213. { //Wipe the ignore list.
  11214. memset(sd->ignore, 0, sizeof(sd->ignore));
  11215. flag = 0; // success
  11216. } else {
  11217. flag = 1; // fail
  11218. }
  11219. }
  11220. }
  11221. clif_wisall(sd, type, flag);
  11222. }
  11223. /// Whisper ignore list (ZC_WHISPER_LIST).
  11224. /// 00d4 <packet len>.W { <char name>.24B }*
  11225. void clif_PMIgnoreList(struct map_session_data* sd)
  11226. {
  11227. int i, fd = sd->fd;
  11228. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11229. WFIFOW(fd,0) = 0xd4;
  11230. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11231. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11232. }
  11233. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11234. WFIFOSET(fd,WFIFOW(fd,2));
  11235. }
  11236. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11237. /// 00d3
  11238. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11239. {
  11240. clif_PMIgnoreList(sd);
  11241. }
  11242. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11243. /// 01e7
  11244. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11245. {
  11246. if (sd->state.doridori) return;
  11247. switch (sd->class_&MAPID_UPPERMASK) {
  11248. case MAPID_SOUL_LINKER:
  11249. case MAPID_STAR_GLADIATOR:
  11250. case MAPID_TAEKWON:
  11251. if (!sd->state.rest)
  11252. break;
  11253. case MAPID_SUPER_NOVICE:
  11254. sd->state.doridori=1;
  11255. break;
  11256. }
  11257. }
  11258. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11259. /// 01ed
  11260. /// Note: This packet is caused by 7 lines of any text, followed by
  11261. /// the prayer and an another line of any text. The prayer is
  11262. /// defined by lines 790~793 in data\msgstringtable.txt
  11263. /// "Dear angel, can you hear my voice?"
  11264. /// "I am" (space separated player name) "Super Novice~"
  11265. /// "Help me out~ Please~ T_T"
  11266. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11267. {
  11268. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  11269. unsigned int next = pc_nextbaseexp(sd);
  11270. if( next == 0 ) next = pc_thisbaseexp(sd);
  11271. if( next ) {
  11272. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11273. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11274. 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]
  11275. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11276. }
  11277. }
  11278. }
  11279. }
  11280. /// Friends List
  11281. ///
  11282. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11283. /// 0206 <account id>.L <char id>.L <state>.B
  11284. /// state:
  11285. /// 0 = online
  11286. /// 1 = offline
  11287. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  11288. {
  11289. int i, fd = sd->fd;
  11290. //Seek friend.
  11291. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11292. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11293. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11294. return; //Not found
  11295. WFIFOHEAD(fd,packet_len(0x206));
  11296. WFIFOW(fd, 0) = 0x206;
  11297. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11298. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11299. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11300. WFIFOSET(fd, packet_len(0x206));
  11301. }
  11302. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11303. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11304. {
  11305. int account_id, char_id, online;
  11306. account_id = va_arg(ap, int);
  11307. char_id = va_arg(ap, int);
  11308. online = va_arg(ap, int);
  11309. clif_friendslist_toggle(sd, account_id, char_id, online);
  11310. return 0;
  11311. }
  11312. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11313. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11314. void clif_friendslist_send(struct map_session_data *sd)
  11315. {
  11316. int i = 0, n, fd = sd->fd;
  11317. // Send friends list
  11318. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11319. WFIFOW(fd, 0) = 0x201;
  11320. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11321. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11322. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11323. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11324. }
  11325. if (i) {
  11326. WFIFOW(fd,2) = 4 + 32 * i;
  11327. WFIFOSET(fd, WFIFOW(fd,2));
  11328. }
  11329. for (n = 0; n < i; n++) { //Sending the online players
  11330. if (map_charid2sd(sd->status.friends[n].char_id))
  11331. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11332. }
  11333. }
  11334. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11335. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11336. /// result:
  11337. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11338. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11339. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11340. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11341. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11342. {
  11343. int fd;
  11344. nullpo_retv(sd);
  11345. fd = sd->fd;
  11346. WFIFOHEAD(fd,packet_len(0x209));
  11347. WFIFOW(fd,0) = 0x209;
  11348. WFIFOW(fd,2) = type;
  11349. if (f_sd) {
  11350. WFIFOL(fd,4) = f_sd->status.account_id;
  11351. WFIFOL(fd,8) = f_sd->status.char_id;
  11352. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11353. }
  11354. WFIFOSET(fd, packet_len(0x209));
  11355. }
  11356. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11357. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11358. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  11359. {
  11360. int fd = sd->fd;
  11361. WFIFOHEAD(fd,packet_len(0x207));
  11362. WFIFOW(fd,0) = 0x207;
  11363. WFIFOL(fd,2) = account_id;
  11364. WFIFOL(fd,6) = char_id;
  11365. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11366. WFIFOSET(fd,packet_len(0x207));
  11367. }
  11368. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11369. /// 0202 <name>.24B
  11370. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11371. {
  11372. struct map_session_data *f_sd;
  11373. int i;
  11374. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11375. // ensure that the request player's friend list is not full
  11376. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11377. if( i == MAX_FRIENDS ) {
  11378. clif_friendslist_reqack(sd, f_sd, 2);
  11379. return;
  11380. }
  11381. // Friend doesn't exist (no player with this name)
  11382. if (f_sd == NULL) {
  11383. clif_displaymessage(fd, msg_txt(sd,3));
  11384. return;
  11385. }
  11386. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11387. return;
  11388. }
  11389. // @noask [LuzZza]
  11390. if(f_sd->state.noask) {
  11391. clif_noask_sub(sd, f_sd, 5);
  11392. return;
  11393. }
  11394. // Friend already exists
  11395. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11396. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11397. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11398. return;
  11399. }
  11400. }
  11401. f_sd->friend_req = sd->status.char_id;
  11402. sd->friend_req = f_sd->status.char_id;
  11403. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11404. }
  11405. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11406. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11407. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11408. /// reply:
  11409. /// 0 = rejected
  11410. /// 1 = accepted
  11411. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11412. {
  11413. struct map_session_data *f_sd;
  11414. int account_id;
  11415. char reply;
  11416. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11417. account_id = RFIFOL(fd,info->pos[0]);
  11418. //char_id = RFIFOL(fd,info->pos[1]);
  11419. if(sd->packet_ver < 6)
  11420. reply = RFIFOB(fd,info->pos[2]);
  11421. else
  11422. reply = RFIFOL(fd,info->pos[2]);
  11423. if( sd->bl.id == account_id ) {// adding oneself as friend
  11424. return;
  11425. }
  11426. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11427. if (f_sd == NULL)
  11428. return;
  11429. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11430. clif_friendslist_reqack(f_sd, sd, 1);
  11431. else {
  11432. int i;
  11433. // Find an empty slot
  11434. for (i = 0; i < MAX_FRIENDS; i++)
  11435. if (f_sd->status.friends[i].char_id == 0)
  11436. break;
  11437. if (i == MAX_FRIENDS) {
  11438. clif_friendslist_reqack(f_sd, sd, 2);
  11439. return;
  11440. }
  11441. f_sd->status.friends[i].account_id = sd->status.account_id;
  11442. f_sd->status.friends[i].char_id = sd->status.char_id;
  11443. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11444. clif_friendslist_reqack(f_sd, sd, 0);
  11445. if (battle_config.friend_auto_add) {
  11446. // Also add f_sd to sd's friendlist.
  11447. for (i = 0; i < MAX_FRIENDS; i++) {
  11448. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11449. return; //No need to add anything.
  11450. if (sd->status.friends[i].char_id == 0)
  11451. break;
  11452. }
  11453. if (i == MAX_FRIENDS) {
  11454. clif_friendslist_reqack(sd, f_sd, 2);
  11455. return;
  11456. }
  11457. sd->status.friends[i].account_id = f_sd->status.account_id;
  11458. sd->status.friends[i].char_id = f_sd->status.char_id;
  11459. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11460. clif_friendslist_reqack(sd, f_sd, 0);
  11461. }
  11462. }
  11463. }
  11464. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11465. /// 0203 <account id>.L <char id>.L
  11466. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11467. {
  11468. struct map_session_data *f_sd = NULL;
  11469. int account_id, char_id;
  11470. int i, j;
  11471. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11472. account_id = RFIFOL(fd,info->pos[0]);
  11473. char_id = RFIFOL(fd,info->pos[1]);
  11474. // Search friend
  11475. for (i = 0; i < MAX_FRIENDS &&
  11476. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11477. if (i == MAX_FRIENDS) {
  11478. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11479. return;
  11480. }
  11481. //remove from friend's list first
  11482. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11483. for (i = 0; i < MAX_FRIENDS &&
  11484. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11485. if (i != MAX_FRIENDS) {
  11486. // move all chars up
  11487. for(j = i + 1; j < MAX_FRIENDS; j++)
  11488. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11489. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11490. //should the guy be notified of some message? we should add it here if so
  11491. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11492. WFIFOW(f_sd->fd,0) = 0x20a;
  11493. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11494. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11495. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11496. }
  11497. } else { //friend not online -- ask char server to delete from his friendlist
  11498. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11499. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11500. return;
  11501. }
  11502. }
  11503. // We can now delete from original requester
  11504. for (i = 0; i < MAX_FRIENDS &&
  11505. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11506. // move all chars up
  11507. for(j = i + 1; j < MAX_FRIENDS; j++)
  11508. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11509. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11510. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11511. WFIFOHEAD(fd,packet_len(0x20a));
  11512. WFIFOW(fd,0) = 0x20a;
  11513. WFIFOL(fd,2) = account_id;
  11514. WFIFOL(fd,6) = char_id;
  11515. WFIFOSET(fd, packet_len(0x20a));
  11516. }
  11517. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11518. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11519. void clif_PVPInfo(struct map_session_data* sd)
  11520. {
  11521. int fd = sd->fd;
  11522. WFIFOHEAD(fd,packet_len(0x210));
  11523. WFIFOW(fd,0) = 0x210;
  11524. WFIFOL(fd,2) = sd->status.char_id;
  11525. WFIFOL(fd,6) = sd->status.account_id;
  11526. WFIFOL(fd,10) = sd->pvp_won; // times won
  11527. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11528. WFIFOL(fd,18) = sd->pvp_point;
  11529. WFIFOSET(fd, packet_len(0x210));
  11530. }
  11531. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11532. /// 020f <char id>.L <account id>.L
  11533. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11534. {
  11535. // TODO: Is there a way to use this on an another player (char/acc id)?
  11536. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11537. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11538. clif_PVPInfo(sd);
  11539. }
  11540. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11541. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11542. void clif_blacksmith(struct map_session_data* sd)
  11543. {
  11544. int i, fd = sd->fd;
  11545. const char* name;
  11546. WFIFOHEAD(fd,packet_len(0x219));
  11547. WFIFOW(fd,0) = 0x219;
  11548. //Packet size limits this list to 10 elements. [Skotlex]
  11549. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11550. if (smith_fame_list[i].id > 0) {
  11551. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11552. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11553. {
  11554. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11555. } else
  11556. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11557. } else
  11558. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11559. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11560. }
  11561. for(;i < 10; i++) { //In case the MAX is less than 10.
  11562. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11563. WFIFOL(fd, 242 + i * 4) = 0;
  11564. }
  11565. WFIFOSET(fd, packet_len(0x219));
  11566. }
  11567. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11568. /// 0217
  11569. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11570. {
  11571. clif_blacksmith(sd);
  11572. }
  11573. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11574. /// 021b <points>.L <total points>.L
  11575. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11576. {
  11577. int fd = sd->fd;
  11578. WFIFOHEAD(fd,packet_len(0x21b));
  11579. WFIFOW(fd,0) = 0x21b;
  11580. WFIFOL(fd,2) = points;
  11581. WFIFOL(fd,6) = sd->status.fame;
  11582. WFIFOSET(fd, packet_len(0x21b));
  11583. }
  11584. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11585. /// 021a { <name>.24B }*10 { <point>.L }*10
  11586. void clif_alchemist(struct map_session_data* sd)
  11587. {
  11588. int i, fd = sd->fd;
  11589. const char* name;
  11590. WFIFOHEAD(fd,packet_len(0x21a));
  11591. WFIFOW(fd,0) = 0x21a;
  11592. //Packet size limits this list to 10 elements. [Skotlex]
  11593. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11594. if (chemist_fame_list[i].id > 0) {
  11595. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11596. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11597. {
  11598. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11599. } else
  11600. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11601. } else
  11602. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11603. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11604. }
  11605. for(;i < 10; i++) { //In case the MAX is less than 10.
  11606. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11607. WFIFOL(fd, 242 + i * 4) = 0;
  11608. }
  11609. WFIFOSET(fd, packet_len(0x21a));
  11610. }
  11611. /// /alchemist (CZ_ALCHEMIST_RANK).
  11612. /// 0218
  11613. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11614. {
  11615. clif_alchemist(sd);
  11616. }
  11617. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11618. /// 021c <points>.L <total points>.L
  11619. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11620. {
  11621. int fd = sd->fd;
  11622. WFIFOHEAD(fd,packet_len(0x21c));
  11623. WFIFOW(fd,0) = 0x21c;
  11624. WFIFOL(fd,2) = points;
  11625. WFIFOL(fd,6) = sd->status.fame;
  11626. WFIFOSET(fd, packet_len(0x21c));
  11627. }
  11628. /// /taekwon list (ZC_TAEKWON_RANK).
  11629. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11630. void clif_taekwon(struct map_session_data* sd)
  11631. {
  11632. int i, fd = sd->fd;
  11633. const char* name;
  11634. WFIFOHEAD(fd,packet_len(0x226));
  11635. WFIFOW(fd,0) = 0x226;
  11636. //Packet size limits this list to 10 elements. [Skotlex]
  11637. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11638. if (taekwon_fame_list[i].id > 0) {
  11639. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11640. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11641. {
  11642. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11643. } else
  11644. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11645. } else
  11646. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11647. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11648. }
  11649. for(;i < 10; i++) { //In case the MAX is less than 10.
  11650. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11651. WFIFOL(fd, 242 + i * 4) = 0;
  11652. }
  11653. WFIFOSET(fd, packet_len(0x226));
  11654. }
  11655. /// /taekwon (CZ_TAEKWON_RANK).
  11656. /// 0225
  11657. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11658. {
  11659. clif_taekwon(sd);
  11660. }
  11661. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11662. /// 0224 <points>.L <total points>.L
  11663. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11664. {
  11665. int fd = sd->fd;
  11666. WFIFOHEAD(fd,packet_len(0x224));
  11667. WFIFOW(fd,0) = 0x224;
  11668. WFIFOL(fd,2) = points;
  11669. WFIFOL(fd,6) = sd->status.fame;
  11670. WFIFOSET(fd, packet_len(0x224));
  11671. }
  11672. /// /pk list (ZC_KILLER_RANK).
  11673. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11674. void clif_ranking_pk(struct map_session_data* sd)
  11675. {
  11676. int i, fd = sd->fd;
  11677. WFIFOHEAD(fd,packet_len(0x238));
  11678. WFIFOW(fd,0) = 0x238;
  11679. for(i=0;i<10;i++){
  11680. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11681. WFIFOL(fd,i*4+242) = 0;
  11682. }
  11683. WFIFOSET(fd, packet_len(0x238));
  11684. }
  11685. /// /pk (CZ_KILLER_RANK).
  11686. /// 0237
  11687. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11688. {
  11689. clif_ranking_pk(sd);
  11690. }
  11691. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11692. /// 0254 <which>.B
  11693. /// which: (unused atm for security purpose)
  11694. /// 0 = sun
  11695. /// 1 = moon
  11696. /// 2 = star
  11697. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11698. {
  11699. int i;
  11700. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11701. if (sd->menuskill_id != SG_FEEL)
  11702. return;
  11703. i = sd->menuskill_val-1;
  11704. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11705. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11706. sd->feel_map[i].m = sd->bl.m;
  11707. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11708. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11709. // clif_misceffect2(&sd->bl, 0x1b0);
  11710. // clif_misceffect2(&sd->bl, 0x21f);
  11711. clif_feel_info(sd, i, 0);
  11712. clif_menuskill_clear(sd);
  11713. }
  11714. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11715. /// 0253 <which>.B
  11716. /// which:
  11717. /// 0 = sun
  11718. /// 1 = moon
  11719. /// 2 = star
  11720. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11721. {
  11722. WFIFOHEAD(fd,packet_len(0x253));
  11723. WFIFOW(fd,0)=0x253;
  11724. WFIFOB(fd,2)=TOB(skill_lv-1);
  11725. WFIFOSET(fd, packet_len(0x253));
  11726. sd->menuskill_id = SG_FEEL;
  11727. sd->menuskill_val = skill_lv;
  11728. }
  11729. /// Request to change homunculus' name (CZ_RENAME_MER).
  11730. /// 0231 <name>.24B
  11731. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11732. merc_hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11733. }
  11734. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11735. /// 0234 <id>.L
  11736. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11737. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11738. struct block_list *bl = NULL;
  11739. struct unit_data *ud = NULL;
  11740. if( sd->md && sd->md->bl.id == id )
  11741. bl = &sd->md->bl;
  11742. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11743. bl = &sd->hd->bl; // Moving Homunculus
  11744. else
  11745. return;
  11746. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11747. ud = unit_bl2ud(bl);
  11748. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11749. }
  11750. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11751. /// 0232 <id>.L <position data>.3B
  11752. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11753. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11754. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11755. struct block_list *bl = NULL;
  11756. short x, y;
  11757. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11758. if( sd->md && sd->md->bl.id == id )
  11759. bl = &sd->md->bl; // Moving Mercenary
  11760. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11761. bl = &sd->hd->bl; // Moving Homunculus
  11762. else
  11763. return;
  11764. unit_walktoxy(bl, x, y, 4);
  11765. }
  11766. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11767. /// 0233 <id>.L <target id>.L <action>.B
  11768. /// action:
  11769. /// always 0
  11770. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11771. {
  11772. struct block_list *bl = NULL;
  11773. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11774. int id = RFIFOL(fd,info->pos[0]);
  11775. int target_id = RFIFOL(fd,info->pos[1]);
  11776. int action_type = RFIFOB(fd,info->pos[2]);
  11777. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11778. bl = &sd->hd->bl;
  11779. else if( sd->md && sd->md->bl.id == id )
  11780. bl = &sd->md->bl;
  11781. else return;
  11782. unit_stop_attack(bl);
  11783. unit_attack(bl, target_id, action_type != 0);
  11784. }
  11785. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11786. /// 022d <type>.W <command>.B
  11787. /// type:
  11788. /// always 0
  11789. /// command:
  11790. /// 0 = homunculus information
  11791. /// 1 = feed
  11792. /// 2 = delete
  11793. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11794. { //[orn]
  11795. int cmd = RFIFOW(fd,0);
  11796. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11797. if(!merc_is_hom_active(sd->hd))
  11798. return;
  11799. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11800. }
  11801. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11802. /// 0292
  11803. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11804. {
  11805. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11806. if (item_position < 0)
  11807. return;
  11808. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11809. return;
  11810. if (!status_revive(&sd->bl, 100, 100))
  11811. return;
  11812. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11813. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11814. }
  11815. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11816. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11817. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11818. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11819. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11820. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11821. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11822. void clif_check(int fd, struct map_session_data* pl_sd)
  11823. {
  11824. WFIFOHEAD(fd,packet_len(0x214));
  11825. WFIFOW(fd, 0) = 0x214;
  11826. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11827. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11828. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11829. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11830. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11831. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11832. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11833. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11834. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11835. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11836. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11837. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11838. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11839. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11840. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11841. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11842. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11843. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11844. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11845. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11846. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11847. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11848. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11849. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11850. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11851. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11852. WFIFOSET(fd,packet_len(0x214));
  11853. }
  11854. /// /check (CZ_REQ_STATUS_GM).
  11855. /// Request character's status values.
  11856. /// 0213 <char name>.24B
  11857. void clif_parse_Check(int fd, struct map_session_data *sd)
  11858. {
  11859. char charname[NAME_LENGTH];
  11860. struct map_session_data* pl_sd;
  11861. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11862. return;
  11863. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11864. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11865. {
  11866. return;
  11867. }
  11868. clif_check(fd, pl_sd);
  11869. }
  11870. /// MAIL SYSTEM
  11871. /// By Zephyrus
  11872. ///
  11873. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11874. /// 0255 <index>.W <result>.B
  11875. /// result:
  11876. /// 0 = success
  11877. /// 1 = failure
  11878. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11879. {
  11880. WFIFOHEAD(fd,packet_len(0x255));
  11881. WFIFOW(fd,0) = 0x255;
  11882. WFIFOW(fd,2) = index;
  11883. WFIFOB(fd,4) = flag;
  11884. WFIFOSET(fd,packet_len(0x255));
  11885. }
  11886. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11887. /// 0245 <result>.B
  11888. /// result:
  11889. /// 0 = success
  11890. /// 1 = failure
  11891. /// 2 = too many items
  11892. void clif_Mail_getattachment(int fd, uint8 flag)
  11893. {
  11894. WFIFOHEAD(fd,packet_len(0x245));
  11895. WFIFOW(fd,0) = 0x245;
  11896. WFIFOB(fd,2) = flag;
  11897. WFIFOSET(fd,packet_len(0x245));
  11898. }
  11899. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11900. /// 0249 <result>.B
  11901. /// result:
  11902. /// 0 = success
  11903. /// 1 = recipinent does not exist
  11904. void clif_Mail_send(int fd, bool fail)
  11905. {
  11906. WFIFOHEAD(fd,packet_len(0x249));
  11907. WFIFOW(fd,0) = 0x249;
  11908. WFIFOB(fd,2) = fail;
  11909. WFIFOSET(fd,packet_len(0x249));
  11910. }
  11911. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11912. /// 0257 <mail id>.L <result>.W
  11913. /// result:
  11914. /// 0 = success
  11915. /// 1 = failure
  11916. void clif_Mail_delete(int fd, int mail_id, short fail)
  11917. {
  11918. WFIFOHEAD(fd, packet_len(0x257));
  11919. WFIFOW(fd,0) = 0x257;
  11920. WFIFOL(fd,2) = mail_id;
  11921. WFIFOW(fd,6) = fail;
  11922. WFIFOSET(fd, packet_len(0x257));
  11923. }
  11924. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11925. /// 0274 <mail id>.L <result>.W
  11926. /// result:
  11927. /// 0 = success
  11928. /// 1 = failure
  11929. void clif_Mail_return(int fd, int mail_id, short fail)
  11930. {
  11931. WFIFOHEAD(fd,packet_len(0x274));
  11932. WFIFOW(fd,0) = 0x274;
  11933. WFIFOL(fd,2) = mail_id;
  11934. WFIFOW(fd,6) = fail;
  11935. WFIFOSET(fd,packet_len(0x274));
  11936. }
  11937. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11938. /// 024a <mail id>.L <title>.40B <sender>.24B
  11939. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11940. {
  11941. WFIFOHEAD(fd,packet_len(0x24a));
  11942. WFIFOW(fd,0) = 0x24a;
  11943. WFIFOL(fd,2) = mail_id;
  11944. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11945. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11946. WFIFOSET(fd,packet_len(0x24a));
  11947. }
  11948. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11949. /// 0260 <type>.L
  11950. /// type:
  11951. /// 0 = open
  11952. /// 1 = close
  11953. void clif_Mail_window(int fd, int flag)
  11954. {
  11955. WFIFOHEAD(fd,packet_len(0x260));
  11956. WFIFOW(fd,0) = 0x260;
  11957. WFIFOL(fd,2) = flag;
  11958. WFIFOSET(fd,packet_len(0x260));
  11959. }
  11960. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11961. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11962. /// read:
  11963. /// 0 = unread
  11964. /// 1 = read
  11965. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11966. {
  11967. int fd = sd->fd;
  11968. struct mail_data *md = &sd->mail.inbox;
  11969. struct mail_message *msg;
  11970. int len, i, j;
  11971. len = 8 + (73 * md->amount);
  11972. WFIFOHEAD(fd,len);
  11973. WFIFOW(fd,0) = 0x240;
  11974. WFIFOW(fd,2) = len;
  11975. WFIFOL(fd,4) = md->amount;
  11976. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11977. {
  11978. msg = &md->msg[i];
  11979. if (msg->id < 1)
  11980. continue;
  11981. WFIFOL(fd,8+73*j) = msg->id;
  11982. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11983. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11984. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11985. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11986. j++;
  11987. }
  11988. WFIFOSET(fd,len);
  11989. if( md->full ) {// TODO: is this official?
  11990. char output[100];
  11991. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11992. clif_disp_onlyself(sd, output, strlen(output));
  11993. }
  11994. }
  11995. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11996. /// 023f
  11997. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11998. {
  11999. struct mail_data* md = &sd->mail.inbox;
  12000. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12001. intif_Mail_requestinbox(sd->status.char_id, 1);
  12002. else
  12003. clif_Mail_refreshinbox(sd);
  12004. mail_removeitem(sd, 0);
  12005. mail_removezeny(sd, 0);
  12006. }
  12007. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12008. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12009. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12010. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12011. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12012. {
  12013. int i, fd = sd->fd;
  12014. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12015. if( i == MAIL_MAX_INBOX ) {
  12016. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12017. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12018. return;
  12019. } else {
  12020. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12021. struct item *item = &msg->item;
  12022. struct item_data *data;
  12023. int msg_len = strlen(msg->body), len;
  12024. if( msg_len == 0 ) {
  12025. strcpy(msg->body, "(no message)");
  12026. msg_len = strlen(msg->body);
  12027. }
  12028. len = 101 + msg_len;
  12029. WFIFOHEAD(fd,len);
  12030. WFIFOW(fd,0) = 0x242;
  12031. WFIFOW(fd,2) = len;
  12032. WFIFOL(fd,4) = msg->id;
  12033. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12034. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12035. WFIFOL(fd,72) = 0;
  12036. WFIFOL(fd,76) = msg->zeny;
  12037. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12038. WFIFOL(fd,80) = item->amount;
  12039. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12040. WFIFOW(fd,86) = data->type;
  12041. WFIFOB(fd,88) = item->identify;
  12042. WFIFOB(fd,89) = item->attribute;
  12043. WFIFOB(fd,90) = item->refine;
  12044. WFIFOW(fd,91) = item->card[0];
  12045. WFIFOW(fd,93) = item->card[1];
  12046. WFIFOW(fd,95) = item->card[2];
  12047. WFIFOW(fd,97) = item->card[3];
  12048. } else // no item, set all to zero
  12049. memset(WFIFOP(fd,80), 0x00, 19);
  12050. WFIFOB(fd,99) = (unsigned char)msg_len;
  12051. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12052. WFIFOSET(fd,len);
  12053. if (msg->status == MAIL_UNREAD) {
  12054. msg->status = MAIL_READ;
  12055. intif_Mail_read(mail_id);
  12056. clif_parse_Mail_refreshinbox(fd, sd);
  12057. }
  12058. }
  12059. }
  12060. /// Request to open a mail (CZ_MAIL_OPEN).
  12061. /// 0241 <mail id>.L
  12062. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12063. {
  12064. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12065. if( mail_id <= 0 )
  12066. return;
  12067. if( mail_invalid_operation(sd) )
  12068. return;
  12069. clif_Mail_read(sd, mail_id);
  12070. }
  12071. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12072. /// 0244 <mail id>.L
  12073. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12074. {
  12075. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12076. int i;
  12077. bool fail = false;
  12078. if( !chrif_isconnected() )
  12079. return;
  12080. if( mail_id <= 0 )
  12081. return;
  12082. if( mail_invalid_operation(sd) )
  12083. return;
  12084. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12085. if( i == MAIL_MAX_INBOX )
  12086. return;
  12087. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12088. return;
  12089. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12090. clif_Mail_getattachment(fd, 1);
  12091. return;
  12092. }
  12093. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12094. struct item_data *data;
  12095. unsigned int weight;
  12096. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12097. return;
  12098. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12099. case CHKADDITEM_NEW:
  12100. fail = ( pc_inventoryblank(sd) == 0 );
  12101. break;
  12102. case CHKADDITEM_OVERAMOUNT:
  12103. fail = true;
  12104. }
  12105. if( fail ) {
  12106. clif_Mail_getattachment(fd, 1);
  12107. return;
  12108. }
  12109. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12110. if( sd->weight + weight > sd->max_weight ) {
  12111. clif_Mail_getattachment(fd, 2);
  12112. return;
  12113. }
  12114. }
  12115. sd->mail.inbox.msg[i].zeny = 0;
  12116. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12117. clif_Mail_read(sd, mail_id);
  12118. intif_Mail_getattach(sd->status.char_id, mail_id);
  12119. }
  12120. /// Request to delete a mail (CZ_MAIL_DELETE).
  12121. /// 0243 <mail id>.L
  12122. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12123. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12124. int i;
  12125. if( !chrif_isconnected() )
  12126. return;
  12127. if( mail_id <= 0 )
  12128. return;
  12129. if( mail_invalid_operation(sd) )
  12130. return;
  12131. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12132. if (i < MAIL_MAX_INBOX) {
  12133. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12134. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12135. clif_Mail_delete(sd->fd, mail_id, 1);
  12136. return;
  12137. }
  12138. intif_Mail_delete(sd->status.char_id, mail_id);
  12139. }
  12140. }
  12141. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12142. /// 0273 <mail id>.L <receive name>.24B
  12143. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12144. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12145. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12146. int i;
  12147. if( mail_id <= 0 )
  12148. return;
  12149. if( mail_invalid_operation(sd) )
  12150. return;
  12151. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12152. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12153. intif_Mail_return(sd->status.char_id, mail_id);
  12154. else
  12155. clif_Mail_return(sd->fd, mail_id, 1);
  12156. }
  12157. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12158. /// 0247 <index>.W <amount>.L
  12159. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12160. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12161. int idx = RFIFOW(fd,info->pos[0]);
  12162. int amount = RFIFOL(fd,info->pos[1]);
  12163. unsigned char flag;
  12164. if( !chrif_isconnected() )
  12165. return;
  12166. if (idx < 0 || amount < 0)
  12167. return;
  12168. flag = mail_setitem(sd, idx, amount);
  12169. clif_Mail_setattachment(fd,idx,flag);
  12170. }
  12171. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12172. /// 0246 <type>.W
  12173. /// type:
  12174. /// 0 = reset all
  12175. /// 1 = remove item
  12176. /// 2 = remove zeny
  12177. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12178. {
  12179. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12180. if (type == 0 || type == 1)
  12181. mail_removeitem(sd, 0);
  12182. if (type == 0 || type == 2)
  12183. mail_removezeny(sd, 0);
  12184. }
  12185. /// Request to send mail (CZ_MAIL_SEND).
  12186. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12187. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12188. {
  12189. struct mail_message msg;
  12190. int body_len;
  12191. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12192. if( !chrif_isconnected() )
  12193. return;
  12194. if( sd->state.trading )
  12195. return;
  12196. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12197. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12198. return;
  12199. }
  12200. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 ) {
  12201. clif_displaymessage(sd->fd,msg_txt(sd,675)); //"Cannot send mails too fast!!."
  12202. clif_Mail_send(fd, true); // fail
  12203. return;
  12204. }
  12205. body_len = RFIFOB(fd,info->pos[3]);
  12206. if (body_len > MAIL_BODY_LENGTH)
  12207. body_len = MAIL_BODY_LENGTH;
  12208. if( !mail_setattachment(sd, &msg) ) { // Invalid Append condition
  12209. clif_Mail_send(sd->fd, true); // fail
  12210. mail_removeitem(sd,0);
  12211. mail_removezeny(sd,0);
  12212. return;
  12213. }
  12214. msg.id = 0; // id will be assigned by charserver
  12215. msg.send_id = sd->status.char_id;
  12216. msg.dest_id = 0; // will attempt to resolve name
  12217. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  12218. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,info->pos[1]), NAME_LENGTH);
  12219. safestrncpy(msg.title, (char*)RFIFOP(fd,info->pos[2]), MAIL_TITLE_LENGTH);
  12220. if (msg.title[0] == '\0') {
  12221. return; // Message has no length and somehow client verification was skipped.
  12222. }
  12223. if (body_len)
  12224. safestrncpy(msg.body, (char*)RFIFOP(fd,info->pos[4]), body_len + 1);
  12225. else
  12226. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  12227. msg.timestamp = time(NULL);
  12228. if( !intif_Mail_send(sd->status.account_id, &msg) )
  12229. mail_deliveryfail(sd, &msg);
  12230. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  12231. }
  12232. /// AUCTION SYSTEM
  12233. /// By Zephyrus
  12234. ///
  12235. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12236. /// 025f <type>.L
  12237. /// type:
  12238. /// 0 = open
  12239. /// 1 = close
  12240. void clif_Auction_openwindow(struct map_session_data *sd)
  12241. {
  12242. int fd = sd->fd;
  12243. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12244. return;
  12245. WFIFOHEAD(fd,packet_len(0x25f));
  12246. WFIFOW(fd,0) = 0x25f;
  12247. WFIFOL(fd,2) = 0;
  12248. WFIFOSET(fd,packet_len(0x25f));
  12249. }
  12250. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12251. /// 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 }*
  12252. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12253. {
  12254. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12255. struct auction_data auction;
  12256. struct item_data *item;
  12257. int k;
  12258. WFIFOHEAD(fd,12 + (count * 83));
  12259. WFIFOW(fd,0) = 0x252;
  12260. WFIFOW(fd,2) = 12 + (count * 83);
  12261. WFIFOL(fd,4) = pages;
  12262. WFIFOL(fd,8) = count;
  12263. for( i = 0; i < count; i++ ) {
  12264. memcpy(&auction, RBUFP(buf,i * len), len);
  12265. k = 12 + (i * 83);
  12266. WFIFOL(fd,k) = auction.auction_id;
  12267. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12268. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12269. WFIFOW(fd,28+k) = item->view_id;
  12270. else
  12271. WFIFOW(fd,28+k) = auction.item.nameid;
  12272. WFIFOL(fd,30+k) = auction.type;
  12273. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12274. WFIFOB(fd,36+k) = auction.item.identify;
  12275. WFIFOB(fd,37+k) = auction.item.attribute;
  12276. WFIFOB(fd,38+k) = auction.item.refine;
  12277. WFIFOW(fd,39+k) = auction.item.card[0];
  12278. WFIFOW(fd,41+k) = auction.item.card[1];
  12279. WFIFOW(fd,43+k) = auction.item.card[2];
  12280. WFIFOW(fd,45+k) = auction.item.card[3];
  12281. WFIFOL(fd,47+k) = auction.price;
  12282. WFIFOL(fd,51+k) = auction.buynow;
  12283. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12284. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12285. }
  12286. WFIFOSET(fd,WFIFOW(fd,2));
  12287. }
  12288. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12289. /// 0256 <index>.W <result>.B
  12290. /// result:
  12291. /// 0 = success
  12292. /// 1 = failure
  12293. static void clif_Auction_setitem(int fd, int index, bool fail)
  12294. {
  12295. WFIFOHEAD(fd,packet_len(0x256));
  12296. WFIFOW(fd,0) = 0x256;
  12297. WFIFOW(fd,2) = index;
  12298. WFIFOB(fd,4) = fail;
  12299. WFIFOSET(fd,packet_len(0x256));
  12300. }
  12301. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12302. /// 024b <type>.W
  12303. /// type:
  12304. /// 0 = create (any other action in auction window)
  12305. /// 1 = cancel (cancel pressed on register tab)
  12306. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12307. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12308. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12309. if( sd->auction.amount > 0 )
  12310. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12311. sd->auction.amount = 0;
  12312. }
  12313. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12314. /// 024c <index>.W <count>.L
  12315. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12316. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12317. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12318. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12319. struct item_data *item;
  12320. if( sd->auction.amount > 0 )
  12321. sd->auction.amount = 0;
  12322. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12323. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12324. return;
  12325. }
  12326. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12327. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12328. return;
  12329. }
  12330. if( (item = itemdb_exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC || item->type == IT_SHADOWGEAR) )
  12331. { // Consumable or pets are not allowed
  12332. clif_Auction_setitem(sd->fd, idx, true);
  12333. return;
  12334. }
  12335. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12336. !sd->status.inventory[idx].identify ||
  12337. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12338. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  12339. clif_Auction_setitem(sd->fd, idx, true);
  12340. return;
  12341. }
  12342. sd->auction.index = idx;
  12343. sd->auction.amount = amount;
  12344. clif_Auction_setitem(fd, idx + 2, false);
  12345. }
  12346. /// Result from an auction action (ZC_AUCTION_RESULT).
  12347. /// 0250 <result>.B
  12348. /// result:
  12349. /// 0 = You have failed to bid into the auction
  12350. /// 1 = You have successfully bid in the auction
  12351. /// 2 = The auction has been canceled
  12352. /// 3 = An auction with at least one bidder cannot be canceled
  12353. /// 4 = You cannot register more than 5 items in an auction at a time
  12354. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12355. /// 6 = You have won the auction
  12356. /// 7 = You have failed to win the auction
  12357. /// 8 = You do not have enough Zeny
  12358. /// 9 = You cannot place more than 5 bids at a time
  12359. void clif_Auction_message(int fd, unsigned char flag)
  12360. {
  12361. WFIFOHEAD(fd,packet_len(0x250));
  12362. WFIFOW(fd,0) = 0x250;
  12363. WFIFOB(fd,2) = flag;
  12364. WFIFOSET(fd,packet_len(0x250));
  12365. }
  12366. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12367. /// 025e <result>.W
  12368. /// result:
  12369. /// 0 = You have ended the auction
  12370. /// 1 = You cannot end the auction
  12371. /// 2 = Auction ID is incorrect
  12372. void clif_Auction_close(int fd, unsigned char flag)
  12373. {
  12374. WFIFOHEAD(fd,packet_len(0x25e));
  12375. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12376. WFIFOW(fd,2) = flag;
  12377. WFIFOSET(fd,packet_len(0x25e));
  12378. }
  12379. /// Request to add an auction (CZ_AUCTION_ADD).
  12380. /// 024d <now money>.L <max money>.L <delete hour>.W
  12381. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12382. {
  12383. struct auction_data auction;
  12384. struct item_data *item;
  12385. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12386. auction.price = RFIFOL(fd,info->pos[0]);
  12387. auction.buynow = RFIFOL(fd,info->pos[1]);
  12388. auction.hours = RFIFOW(fd,info->pos[2]);
  12389. // Invalid Situations...
  12390. if( sd->auction.amount < 1 ) {
  12391. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12392. return;
  12393. }
  12394. if( auction.price >= auction.buynow ) {
  12395. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12396. return;
  12397. }
  12398. if( auction.hours < 1 || auction.hours > 48 ) {
  12399. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12400. return;
  12401. }
  12402. // Auction checks...
  12403. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12404. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12405. clif_Auction_message(fd, 2); // The auction has been canceled
  12406. return;
  12407. }
  12408. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12409. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12410. return;
  12411. }
  12412. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12413. auction.buynow = battle_config.auction_maximumprice;
  12414. if( auction.price >= auction.buynow )
  12415. auction.price = auction.buynow - 1;
  12416. }
  12417. auction.auction_id = 0;
  12418. auction.seller_id = sd->status.char_id;
  12419. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12420. auction.buyer_id = 0;
  12421. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12422. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12423. {
  12424. clif_Auction_message(fd, 2); // The auction has been canceled
  12425. return;
  12426. }
  12427. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12428. { // Just in case
  12429. clif_Auction_message(fd, 2); // The auction has been canceled
  12430. return;
  12431. }
  12432. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12433. auction.type = item->type;
  12434. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12435. auction.item.amount = 1;
  12436. auction.timestamp = 0;
  12437. if( !intif_Auction_register(&auction) )
  12438. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12439. else
  12440. {
  12441. int zeny = auction.hours*battle_config.auction_feeperhour;
  12442. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12443. sd->auction.amount = 0;
  12444. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12445. }
  12446. }
  12447. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12448. /// 024e <auction id>.L
  12449. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12450. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12451. intif_Auction_cancel(sd->status.char_id, auction_id);
  12452. }
  12453. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12454. /// 025d <auction id>.L
  12455. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12456. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12457. intif_Auction_close(sd->status.char_id, auction_id);
  12458. }
  12459. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12460. /// 024f <auction id>.L <money>.L
  12461. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12462. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12463. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12464. int bid = RFIFOL(fd,info->pos[1]);
  12465. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12466. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12467. return;
  12468. }
  12469. if( bid <= 0 )
  12470. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12471. else if( bid > sd->status.zeny )
  12472. clif_Auction_message(fd, 8); // You do not have enough zeny
  12473. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12474. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12475. else {
  12476. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12477. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12478. }
  12479. }
  12480. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12481. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12482. /// search type:
  12483. /// 0 = armor
  12484. /// 1 = weapon
  12485. /// 2 = card
  12486. /// 3 = misc
  12487. /// 4 = name search
  12488. /// 5 = auction id search
  12489. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12490. char search_text[NAME_LENGTH];
  12491. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12492. short type = RFIFOW(fd,info->pos[0]);
  12493. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12494. int page = RFIFOW(fd,info->pos[3]);
  12495. clif_parse_Auction_cancelreg(fd, sd);
  12496. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12497. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12498. }
  12499. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12500. /// 025c <type>.W
  12501. /// type:
  12502. /// 0 = sell (own auctions)
  12503. /// 1 = buy (own bids)
  12504. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12505. {
  12506. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12507. clif_parse_Auction_cancelreg(fd, sd);
  12508. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12509. }
  12510. /// CASH/POINT SHOP
  12511. ///
  12512. void clif_cashshop_open( struct map_session_data* sd ){
  12513. WFIFOHEAD( sd->fd, 10 );
  12514. WFIFOW( sd->fd, 0 ) = 0x845;
  12515. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12516. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12517. WFIFOSET( sd->fd, 10 );
  12518. }
  12519. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12520. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12521. clif_cashshop_open( sd );
  12522. }
  12523. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12524. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12525. // No need to do anything here
  12526. }
  12527. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12528. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12529. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12530. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12531. int j;
  12532. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12533. return;
  12534. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12535. WFIFOW(fd, 0) = 0x8c0;
  12536. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12537. WFIFOL(fd, 4) = tab;
  12538. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12539. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12540. WFIFOW(fd, 10 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->nameid;
  12541. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12542. }
  12543. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12544. }
  12545. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12546. void clif_cashshop_list( int fd ){
  12547. int tab;
  12548. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12549. int length = 8 + cash_shop_items[tab].count * 6;
  12550. int i, offset;
  12551. WFIFOHEAD( fd, length );
  12552. WFIFOW( fd, 0 ) = 0x8ca;
  12553. WFIFOW( fd, 2 ) = length;
  12554. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12555. WFIFOW( fd, 6 ) = tab;
  12556. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12557. WFIFOW( fd, offset ) = cash_shop_items[tab].item[i]->nameid;
  12558. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12559. }
  12560. WFIFOSET( fd, length );
  12561. }
  12562. }
  12563. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12564. if( !sd->status.cashshop_sent ) {
  12565. clif_cashshop_list( fd );
  12566. sd->status.cashshop_sent = true;
  12567. }
  12568. }
  12569. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12570. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12571. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12572. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12573. {
  12574. int fd,i;
  12575. #if PACKETVER < 20070711
  12576. const int offset = 8;
  12577. #else
  12578. const int offset = 12;
  12579. #endif
  12580. nullpo_retv(sd);
  12581. nullpo_retv(nd);
  12582. fd = sd->fd;
  12583. sd->npc_shopid = nd->bl.id;
  12584. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12585. WFIFOW(fd,0) = 0x287;
  12586. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12587. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12588. #if PACKETVER >= 20070711
  12589. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12590. #endif
  12591. for( i = 0; i < nd->u.shop.count; i++ ) {
  12592. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12593. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12594. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12595. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  12596. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12597. }
  12598. WFIFOSET(fd,WFIFOW(fd,2));
  12599. }
  12600. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12601. /// 0289 <cash point>.L <error>.W
  12602. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12603. /// error:
  12604. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12605. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12606. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12607. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12608. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12609. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12610. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12611. /// 7 = You can purchase up to 10 items.
  12612. /// 8 = Some items could not be purchased.
  12613. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12614. {
  12615. int fd = sd->fd;
  12616. WFIFOHEAD(fd, packet_len(0x289));
  12617. WFIFOW(fd,0) = 0x289;
  12618. WFIFOL(fd,2) = sd->cashPoints;
  12619. #if PACKETVER < 20070711
  12620. WFIFOW(fd,6) = TOW(error);
  12621. #else
  12622. WFIFOL(fd,6) = sd->kafraPoints;
  12623. WFIFOW(fd,10) = TOW(error);
  12624. #endif
  12625. WFIFOSET(fd, packet_len(0x289));
  12626. }
  12627. void clif_cashshop_result( struct map_session_data *sd, uint16 item_id, uint16 result ){
  12628. WFIFOHEAD( sd->fd, 16 );
  12629. WFIFOW( sd->fd, 0 ) = 0x849;
  12630. WFIFOL( sd->fd, 2 ) = item_id;
  12631. WFIFOW( sd->fd, 6 ) = result;
  12632. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12633. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12634. WFIFOSET( sd->fd, 16 );
  12635. }
  12636. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12637. /// 0288 <name id>.W <amount>.W
  12638. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12639. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12640. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (PACKETVER >= 20130000)
  12641. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  12642. int fail = 0;
  12643. struct s_packet_db* info;
  12644. int cmd = RFIFOW(fd,0);
  12645. nullpo_retv(sd);
  12646. info = &packet_db[sd->packet_ver][cmd];
  12647. if( sd->state.trading || !sd->npc_shopid )
  12648. fail = 1;
  12649. else {
  12650. #if PACKETVER < 20101116
  12651. short nameid = RFIFOW(fd,info->pos[0]);
  12652. short amount = RFIFOW(fd,info->pos[1]);
  12653. int points = RFIFOL(fd,info->pos[2]);
  12654. fail = npc_cashshop_buy(sd, nameid, amount, points);
  12655. clif_cashshop_ack(sd,fail);
  12656. #else
  12657. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12658. int len = RFIFOW(fd,info->pos[0]);
  12659. int points = RFIFOL(fd,info->pos[1]);
  12660. int count = RFIFOW(fd,info->pos[2]);
  12661. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12662. if( len < 10 || len != 10 + count * s_itl){
  12663. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12664. return;
  12665. }
  12666. if(cmd==0x848){
  12667. cashshop_buylist( sd, points, count, item_list);
  12668. } else {
  12669. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12670. }
  12671. #endif
  12672. }
  12673. clif_cashshop_ack(sd,fail);
  12674. }
  12675. /// Adoption System
  12676. ///
  12677. /// Adoption message (ZC_BABYMSG).
  12678. /// 0216 <msg>.L
  12679. /// msg:
  12680. /// 0 = "You cannot adopt more than 1 child."
  12681. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12682. /// 2 = "You cannot adopt a married person."
  12683. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12684. {
  12685. int fd = sd->fd;
  12686. WFIFOHEAD(fd,6);
  12687. WFIFOW(fd,0) = 0x216;
  12688. WFIFOL(fd,2) = type;
  12689. WFIFOSET(fd,6);
  12690. }
  12691. /// Adoption confirmation (ZC_REQ_BABY).
  12692. /// 01f6 <account id>.L <char id>.L <name>.B
  12693. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12694. {
  12695. int fd = sd->fd;
  12696. WFIFOHEAD(fd,34);
  12697. WFIFOW(fd,0) = 0x1f6;
  12698. WFIFOL(fd,2) = src->status.account_id;
  12699. WFIFOL(fd,6) = p_id;
  12700. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12701. WFIFOSET(fd,34);
  12702. }
  12703. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12704. /// 01f9 <account id>.L
  12705. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12706. {
  12707. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12708. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12709. if( pc_can_Adopt(sd, p_sd, tsd) )
  12710. {
  12711. tsd->adopt_invite = sd->status.account_id;
  12712. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12713. }
  12714. }
  12715. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12716. /// 01f7 <account id>.L <char id>.L <answer>.L
  12717. /// answer:
  12718. /// 0 = rejected
  12719. /// 1 = accepted
  12720. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12721. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12722. int p1_id = RFIFOL(fd,info->pos[0]);
  12723. int p2_id = RFIFOL(fd,info->pos[1]);
  12724. int result = RFIFOL(fd,info->pos[2]);
  12725. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12726. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12727. int pid = sd->adopt_invite;
  12728. sd->adopt_invite = 0;
  12729. if( p1_sd == NULL || p2_sd == NULL )
  12730. return; // Both players need to be online
  12731. if( pid != p1_sd->status.account_id )
  12732. return; // Incorrect values
  12733. if( result == 0 )
  12734. return; // Rejected
  12735. pc_adoption(p1_sd, p2_sd, sd);
  12736. }
  12737. /// Convex Mirror (ZC_BOSS_INFO).
  12738. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12739. /// infoType:
  12740. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12741. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12742. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12743. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12744. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12745. {
  12746. WFIFOHEAD(fd,70);
  12747. memset(WFIFOP(fd,0),0,70);
  12748. WFIFOW(fd,0) = 0x293;
  12749. if( md != NULL ) {
  12750. if( md->bl.prev != NULL ) { // Boss on This Map
  12751. if( flag ) {
  12752. WFIFOB(fd,2) = 1;
  12753. WFIFOL(fd,3) = md->bl.x;
  12754. WFIFOL(fd,7) = md->bl.y;
  12755. } else
  12756. WFIFOB(fd,2) = 2; // First Time
  12757. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12758. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12759. unsigned int seconds;
  12760. int hours, minutes;
  12761. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12762. hours = seconds / (60 * 60);
  12763. seconds = seconds - (60 * 60 * hours);
  12764. minutes = seconds / 60;
  12765. WFIFOB(fd,2) = 3;
  12766. WFIFOW(fd,11) = hours; // Hours
  12767. WFIFOW(fd,13) = minutes; // Minutes
  12768. }
  12769. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12770. }
  12771. WFIFOSET(fd,70);
  12772. }
  12773. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12774. /// 02d6 <account id>.L
  12775. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12776. {
  12777. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12778. struct map_session_data* tsd = map_id2sd(aid);
  12779. if (!tsd)
  12780. return;
  12781. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12782. clif_viewequip_ack(sd, tsd);
  12783. else
  12784. clif_msg(sd, VIEW_EQUIP_FAIL);
  12785. }
  12786. /// Request to change equip window tick (CZ_CONFIG).
  12787. /// 02d8 <type>.L <flag>.L
  12788. /// type:
  12789. /// 0 = open equip window
  12790. /// flag:
  12791. /// 0 = disabled
  12792. /// 1 = enabled
  12793. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12794. {
  12795. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12796. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12797. sd->status.show_equip = flag;
  12798. clif_equiptickack(sd, flag);
  12799. }
  12800. /// Questlog System [Kevin] [Inkfish]
  12801. ///
  12802. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12803. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12804. void clif_quest_send_list(struct map_session_data * sd)
  12805. {
  12806. int fd = sd->fd;
  12807. int i;
  12808. int len = sd->avail_quests*5+8;
  12809. WFIFOHEAD(fd,len);
  12810. WFIFOW(fd, 0) = 0x2b1;
  12811. WFIFOW(fd, 2) = len;
  12812. WFIFOL(fd, 4) = sd->avail_quests;
  12813. for( i = 0; i < sd->avail_quests; i++ ) {
  12814. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12815. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12816. }
  12817. WFIFOSET(fd, len);
  12818. }
  12819. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12820. /// 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
  12821. void clif_quest_send_mission(struct map_session_data * sd)
  12822. {
  12823. int fd = sd->fd;
  12824. int i, j;
  12825. int len = sd->avail_quests*104+8;
  12826. struct mob_db *mob;
  12827. WFIFOHEAD(fd, len);
  12828. WFIFOW(fd, 0) = 0x2b2;
  12829. WFIFOW(fd, 2) = len;
  12830. WFIFOL(fd, 4) = sd->avail_quests;
  12831. for( i = 0; i < sd->avail_quests; i++ ) {
  12832. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12833. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12834. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12835. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12836. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ ) {
  12837. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12838. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12839. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12840. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12841. }
  12842. }
  12843. WFIFOSET(fd, len);
  12844. }
  12845. /// Notification about a new quest (ZC_ADD_QUEST).
  12846. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12847. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12848. {
  12849. int fd = sd->fd;
  12850. int i;
  12851. struct mob_db *mob;
  12852. WFIFOHEAD(fd, packet_len(0x2b3));
  12853. WFIFOW(fd, 0) = 0x2b3;
  12854. WFIFOL(fd, 2) = qd->quest_id;
  12855. WFIFOB(fd, 6) = qd->state;
  12856. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12857. WFIFOL(fd, 11) = qd->time;
  12858. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12859. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12860. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12861. WFIFOW(fd, i*30+21) = qd->count[i];
  12862. mob = mob_db(quest_db[index].mob[i]);
  12863. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12864. }
  12865. WFIFOSET(fd, packet_len(0x2b3));
  12866. }
  12867. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12868. /// 02b4 <quest id>.L
  12869. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12870. {
  12871. int fd = sd->fd;
  12872. WFIFOHEAD(fd, packet_len(0x2b4));
  12873. WFIFOW(fd, 0) = 0x2b4;
  12874. WFIFOL(fd, 2) = quest_id;
  12875. WFIFOSET(fd, packet_len(0x2b4));
  12876. }
  12877. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12878. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12879. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12880. {
  12881. int fd = sd->fd;
  12882. int i;
  12883. int len = quest_db[index].num_objectives*12+6;
  12884. WFIFOHEAD(fd, len);
  12885. WFIFOW(fd, 0) = 0x2b5;
  12886. WFIFOW(fd, 2) = len;
  12887. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12888. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12889. WFIFOL(fd, i*12+6) = qd->quest_id;
  12890. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12891. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12892. WFIFOW(fd, i*12+16) = qd->count[i];
  12893. }
  12894. WFIFOSET(fd, len);
  12895. }
  12896. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12897. /// 02b6 <quest id>.L <active>.B
  12898. void clif_parse_questStateAck(int fd, struct map_session_data * sd){
  12899. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12900. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  12901. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  12902. }
  12903. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12904. /// 02b7 <quest id>.L <active>.B
  12905. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12906. {
  12907. int fd = sd->fd;
  12908. WFIFOHEAD(fd, packet_len(0x2b7));
  12909. WFIFOW(fd, 0) = 0x2b7;
  12910. WFIFOL(fd, 2) = quest_id;
  12911. WFIFOB(fd, 6) = active;
  12912. WFIFOSET(fd, packet_len(0x2b7));
  12913. }
  12914. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12915. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12916. /// effect:
  12917. /// 0 = none
  12918. /// 1 = exclamation mark icon
  12919. /// 2 = question mark icon
  12920. /// type:
  12921. /// 0 = yellow
  12922. /// 1 = orange
  12923. /// 2 = green
  12924. /// 3 = purple
  12925. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12926. {
  12927. #if PACKETVER >= 20090218
  12928. int fd = sd->fd;
  12929. WFIFOHEAD(fd, packet_len(0x446));
  12930. WFIFOW(fd, 0) = 0x446;
  12931. WFIFOL(fd, 2) = bl->id;
  12932. WFIFOW(fd, 6) = bl->x;
  12933. WFIFOW(fd, 8) = bl->y;
  12934. WFIFOW(fd, 10) = state;
  12935. WFIFOW(fd, 12) = color;
  12936. WFIFOSET(fd, packet_len(0x446));
  12937. #endif
  12938. }
  12939. /// Mercenary System
  12940. ///
  12941. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12942. /// 02a2 <var id>.W <value>.L
  12943. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12944. {
  12945. struct mercenary_data *md;
  12946. struct status_data *status;
  12947. int fd;
  12948. if( sd == NULL || (md = sd->md) == NULL )
  12949. return;
  12950. fd = sd->fd;
  12951. status = &md->battle_status;
  12952. WFIFOHEAD(fd,packet_len(0x2a2));
  12953. WFIFOW(fd,0) = 0x2a2;
  12954. WFIFOW(fd,2) = type;
  12955. switch( type ) {
  12956. case SP_ATK1:
  12957. {
  12958. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12959. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12960. }
  12961. break;
  12962. case SP_MATK1:
  12963. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12964. break;
  12965. case SP_HIT:
  12966. WFIFOL(fd,4) = status->hit;
  12967. break;
  12968. case SP_CRITICAL:
  12969. WFIFOL(fd,4) = status->cri/10;
  12970. break;
  12971. case SP_DEF1:
  12972. WFIFOL(fd,4) = status->def;
  12973. break;
  12974. case SP_MDEF1:
  12975. WFIFOL(fd,4) = status->mdef;
  12976. break;
  12977. case SP_MERCFLEE:
  12978. WFIFOL(fd,4) = status->flee;
  12979. break;
  12980. case SP_ASPD:
  12981. WFIFOL(fd,4) = status->amotion;
  12982. break;
  12983. case SP_HP:
  12984. WFIFOL(fd,4) = status->hp;
  12985. break;
  12986. case SP_MAXHP:
  12987. WFIFOL(fd,4) = status->max_hp;
  12988. break;
  12989. case SP_SP:
  12990. WFIFOL(fd,4) = status->sp;
  12991. break;
  12992. case SP_MAXSP:
  12993. WFIFOL(fd,4) = status->max_sp;
  12994. break;
  12995. case SP_MERCKILLS:
  12996. WFIFOL(fd,4) = md->mercenary.kill_count;
  12997. break;
  12998. case SP_MERCFAITH:
  12999. WFIFOL(fd,4) = mercenary_get_faith(md);
  13000. break;
  13001. }
  13002. WFIFOSET(fd,packet_len(0x2a2));
  13003. }
  13004. /// Mercenary base status data (ZC_MER_INIT).
  13005. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13006. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13007. /// <calls>.L <kills>.L <atk range>.W
  13008. void clif_mercenary_info(struct map_session_data *sd)
  13009. {
  13010. int fd;
  13011. struct mercenary_data *md;
  13012. struct status_data *status;
  13013. int atk;
  13014. if( sd == NULL || (md = sd->md) == NULL )
  13015. return;
  13016. fd = sd->fd;
  13017. status = &md->battle_status;
  13018. WFIFOHEAD(fd,packet_len(0x29b));
  13019. WFIFOW(fd,0) = 0x29b;
  13020. WFIFOL(fd,2) = md->bl.id;
  13021. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13022. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13023. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13024. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  13025. WFIFOW(fd,10) = status->hit;
  13026. WFIFOW(fd,12) = status->cri/10;
  13027. WFIFOW(fd,14) = status->def;
  13028. WFIFOW(fd,16) = status->mdef;
  13029. WFIFOW(fd,18) = status->flee;
  13030. WFIFOW(fd,20) = status->amotion;
  13031. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13032. WFIFOW(fd,46) = md->db->lv;
  13033. WFIFOL(fd,48) = status->hp;
  13034. WFIFOL(fd,52) = status->max_hp;
  13035. WFIFOL(fd,56) = status->sp;
  13036. WFIFOL(fd,60) = status->max_sp;
  13037. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13038. WFIFOW(fd,68) = mercenary_get_faith(md);
  13039. WFIFOL(fd,70) = mercenary_get_calls(md);
  13040. WFIFOL(fd,74) = md->mercenary.kill_count;
  13041. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13042. WFIFOSET(fd,packet_len(0x29b));
  13043. }
  13044. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13045. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13046. void clif_mercenary_skillblock(struct map_session_data *sd)
  13047. {
  13048. struct mercenary_data *md;
  13049. int fd, i, len = 4, id, j;
  13050. if( sd == NULL || (md = sd->md) == NULL )
  13051. return;
  13052. fd = sd->fd;
  13053. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13054. WFIFOW(fd,0) = 0x29d;
  13055. for( i = 0; i < MAX_MERCSKILL; i++ )
  13056. {
  13057. if( (id = md->db->skill[i].id) == 0 )
  13058. continue;
  13059. j = id - MC_SKILLBASE;
  13060. WFIFOW(fd,len) = id;
  13061. WFIFOL(fd,len+2) = skill_get_inf(id);
  13062. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13063. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13064. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13065. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13066. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13067. len += 37;
  13068. }
  13069. WFIFOW(fd,2) = len;
  13070. WFIFOSET(fd,len);
  13071. }
  13072. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13073. /// 029f <command>.B
  13074. /// 1 = mercenary information
  13075. /// 2 = delete
  13076. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13077. {
  13078. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13079. if( sd->md == NULL )
  13080. return;
  13081. if( option == 2 ) merc_delete(sd->md, 2);
  13082. }
  13083. /// Mercenary Message
  13084. /// message:
  13085. /// 0 = Mercenary soldier's duty hour is over.
  13086. /// 1 = Your mercenary soldier has been killed.
  13087. /// 2 = Your mercenary soldier has been fired.
  13088. /// 3 = Your mercenary soldier has ran away.
  13089. void clif_mercenary_message(struct map_session_data* sd, int message){
  13090. clif_msg(sd, MERC_MSG_BASE + message);
  13091. }
  13092. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13093. /// 0298 <name id>.W <seconds>.L
  13094. void clif_rental_time(int fd, int nameid, int seconds)
  13095. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13096. WFIFOHEAD(fd,packet_len(0x298));
  13097. WFIFOW(fd,0) = 0x298;
  13098. WFIFOW(fd,2) = nameid;
  13099. WFIFOL(fd,4) = seconds;
  13100. WFIFOSET(fd,packet_len(0x298));
  13101. }
  13102. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13103. /// 0299 <index>.W <name id>.W
  13104. void clif_rental_expired(int fd, int index, int nameid)
  13105. { // '<ItemName>' item has been deleted from the Inventory
  13106. WFIFOHEAD(fd,packet_len(0x299));
  13107. WFIFOW(fd,0) = 0x299;
  13108. WFIFOW(fd,2) = index+2;
  13109. WFIFOW(fd,4) = nameid;
  13110. WFIFOSET(fd,packet_len(0x299));
  13111. }
  13112. /// Book Reading (ZC_READ_BOOK).
  13113. /// 0294 <book id>.L <page>.L
  13114. void clif_readbook(int fd, int book_id, int page)
  13115. {
  13116. WFIFOHEAD(fd,packet_len(0x294));
  13117. WFIFOW(fd,0) = 0x294;
  13118. WFIFOL(fd,2) = book_id;
  13119. WFIFOL(fd,6) = page;
  13120. WFIFOSET(fd,packet_len(0x294));
  13121. }
  13122. /// Battlegrounds
  13123. ///
  13124. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13125. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13126. void clif_bg_hp(struct map_session_data *sd)
  13127. {
  13128. unsigned char buf[34];
  13129. const int cmd = 0x2e0;
  13130. nullpo_retv(sd);
  13131. WBUFW(buf,0) = cmd;
  13132. WBUFL(buf,2) = sd->status.account_id;
  13133. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13134. if( sd->battle_status.max_hp > INT16_MAX )
  13135. { // To correctly display the %hp bar. [Skotlex]
  13136. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13137. WBUFW(buf,32) = 100;
  13138. }
  13139. else
  13140. {
  13141. WBUFW(buf,30) = sd->battle_status.hp;
  13142. WBUFW(buf,32) = sd->battle_status.max_hp;
  13143. }
  13144. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13145. }
  13146. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13147. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13148. void clif_bg_xy(struct map_session_data *sd)
  13149. {
  13150. unsigned char buf[36];
  13151. nullpo_retv(sd);
  13152. WBUFW(buf,0)=0x2df;
  13153. WBUFL(buf,2)=sd->status.account_id;
  13154. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13155. WBUFW(buf,30)=sd->status.class_;
  13156. WBUFW(buf,32)=sd->bl.x;
  13157. WBUFW(buf,34)=sd->bl.y;
  13158. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13159. }
  13160. void clif_bg_xy_remove(struct map_session_data *sd)
  13161. {
  13162. unsigned char buf[36];
  13163. nullpo_retv(sd);
  13164. WBUFW(buf,0)=0x2df;
  13165. WBUFL(buf,2)=sd->status.account_id;
  13166. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13167. WBUFW(buf,30)=0;
  13168. WBUFW(buf,32)=-1;
  13169. WBUFW(buf,34)=-1;
  13170. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13171. }
  13172. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13173. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13174. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13175. {
  13176. struct map_session_data *sd;
  13177. unsigned char *buf;
  13178. if( (sd = bg_getavailablesd(bg)) == NULL )
  13179. return;
  13180. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13181. WBUFW(buf,0) = 0x2dc;
  13182. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13183. WBUFL(buf,4) = src_id;
  13184. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13185. memcpy(WBUFP(buf,32), mes, len);
  13186. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13187. if( buf )
  13188. aFree(buf);
  13189. }
  13190. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13191. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13192. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13193. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13194. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13195. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13196. char *name, *message;
  13197. int namelen, messagelen;
  13198. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13199. return;
  13200. if( is_atcommand(fd, sd, message, 1) )
  13201. return;
  13202. if (sd->sc.cant.chat)
  13203. return; //no "chatting" while muted.
  13204. if( battle_config.min_chat_delay ) {
  13205. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13206. return;
  13207. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13208. }
  13209. // Reset idle time when using battleground chat.
  13210. sd->idletime = last_tick;
  13211. bg_send_message(sd, text, textlen);
  13212. }
  13213. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13214. /// 02de <camp A points>.W <camp B points>.W
  13215. void clif_bg_updatescore(int16 m)
  13216. {
  13217. struct block_list bl;
  13218. unsigned char buf[6];
  13219. bl.id = 0;
  13220. bl.type = BL_NUL;
  13221. bl.m = m;
  13222. WBUFW(buf,0) = 0x2de;
  13223. WBUFW(buf,2) = map[m].bgscore_lion;
  13224. WBUFW(buf,4) = map[m].bgscore_eagle;
  13225. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13226. }
  13227. void clif_bg_updatescore_single(struct map_session_data *sd)
  13228. {
  13229. int fd;
  13230. nullpo_retv(sd);
  13231. fd = sd->fd;
  13232. WFIFOHEAD(fd,packet_len(0x2de));
  13233. WFIFOW(fd,0) = 0x2de;
  13234. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13235. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13236. WFIFOSET(fd,packet_len(0x2de));
  13237. }
  13238. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13239. /// 02dd <account id>.L <name>.24B <camp>.W
  13240. void clif_sendbgemblem_area(struct map_session_data *sd)
  13241. {
  13242. unsigned char buf[33];
  13243. nullpo_retv(sd);
  13244. WBUFW(buf, 0) = 0x2dd;
  13245. WBUFL(buf,2) = sd->bl.id;
  13246. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13247. WBUFW(buf,30) = sd->bg_id;
  13248. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13249. }
  13250. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13251. {
  13252. nullpo_retv(sd);
  13253. WFIFOHEAD(fd,32);
  13254. WFIFOW(fd,0) = 0x2dd;
  13255. WFIFOL(fd,2) = sd->bl.id;
  13256. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13257. WFIFOW(fd,30) = sd->bg_id;
  13258. WFIFOSET(fd,packet_len(0x2dd));
  13259. }
  13260. /// Custom Fonts (ZC_NOTIFY_FONT).
  13261. /// 02ef <account_id>.L <font id>.W
  13262. void clif_font(struct map_session_data *sd)
  13263. {
  13264. #if PACKETVER >= 20080102
  13265. unsigned char buf[8];
  13266. nullpo_retv(sd);
  13267. WBUFW(buf,0) = 0x2ef;
  13268. WBUFL(buf,2) = sd->bl.id;
  13269. WBUFW(buf,6) = sd->user_font;
  13270. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13271. #endif
  13272. }
  13273. /*==========================================
  13274. * Notifies party members of instance change
  13275. *------------------------------------------*/
  13276. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13277. {
  13278. #if PACKETVER >= 20071128
  13279. unsigned char buf[65];
  13280. nullpo_retv(sd);
  13281. WBUFW(buf,0) = 0x2cb;
  13282. safestrncpy( WBUFP(buf,2), name, 62 );
  13283. WBUFW(buf,63) = num;
  13284. if(flag) // A timer has changed or been added
  13285. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13286. else // No notification
  13287. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13288. #endif
  13289. return;
  13290. }
  13291. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13292. {
  13293. #if PACKETVER >= 20071128
  13294. unsigned char buf[4];
  13295. nullpo_retv(sd);
  13296. WBUFW(buf,0) = 0x2cc;
  13297. WBUFW(buf,2) = num;
  13298. if(flag) // A timer has changed or been added
  13299. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13300. else // No notification
  13301. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13302. #endif
  13303. return;
  13304. }
  13305. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13306. {
  13307. #if PACKETVER >= 20071128
  13308. unsigned char buf[71];
  13309. nullpo_retv(sd);
  13310. WBUFW(buf,0) = 0x2cd;
  13311. safestrncpy( WBUFP(buf,2), name, 62 );
  13312. WBUFL(buf,63) = limit1;
  13313. WBUFL(buf,67) = limit2;
  13314. if(flag) // A timer has changed or been added
  13315. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13316. else // No notification
  13317. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13318. #endif
  13319. return;
  13320. }
  13321. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13322. {
  13323. #if PACKETVER >= 20071128
  13324. unsigned char buf[10];
  13325. nullpo_retv(sd);
  13326. WBUFW(buf,0) = 0x2ce;
  13327. WBUFL(buf,2) = type;
  13328. WBUFL(buf,6) = limit;
  13329. if(flag) // A timer has changed or been added
  13330. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13331. else // No notification
  13332. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13333. #endif
  13334. return;
  13335. }
  13336. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13337. /// 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
  13338. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13339. {
  13340. #if PACKETVER >= 20071002
  13341. unsigned char buf[22];
  13342. struct item_data* id = itemdb_search(item_data->nameid);
  13343. WBUFW(buf,0) = 0x2b8;
  13344. WBUFL(buf,2) = sd->status.account_id;
  13345. WBUFW(buf,6) = item_data->nameid;
  13346. WBUFB(buf,8) = item_data->identify;
  13347. WBUFB(buf,9) = item_data->attribute;
  13348. WBUFB(buf,10) = item_data->refine;
  13349. clif_addcards(WBUFP(buf,11), item_data);
  13350. WBUFW(buf,19) = id->equip; // equip location
  13351. WBUFB(buf,21) = itemtype(id->type); // item type
  13352. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13353. #endif
  13354. }
  13355. /// Display gained exp (ZC_NOTIFY_EXP).
  13356. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13357. /// var id:
  13358. /// SP_BASEEXP, SP_JOBEXP
  13359. /// exp type:
  13360. /// 0 = normal exp gain/loss
  13361. /// 1 = quest exp gain/loss
  13362. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13363. {
  13364. int fd;
  13365. nullpo_retv(sd);
  13366. fd = sd->fd;
  13367. WFIFOHEAD(fd, packet_len(0x7f6));
  13368. WFIFOW(fd,0) = 0x7f6;
  13369. WFIFOL(fd,2) = sd->bl.id;
  13370. WFIFOL(fd,6) = exp;
  13371. WFIFOW(fd,10) = type;
  13372. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13373. WFIFOSET(fd,packet_len(0x7f6));
  13374. }
  13375. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13376. /// type:
  13377. /// 0 = Displays 'value' for 5 seconds.
  13378. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13379. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13380. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13381. /// value:
  13382. /// 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).
  13383. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13384. {
  13385. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13386. WFIFOW(sd->fd,0) = 0x1b1;
  13387. WFIFOB(sd->fd,2) = type;
  13388. WFIFOL(sd->fd,3) = value;
  13389. WFIFOSET(sd->fd, packet_len(0x1b1));
  13390. }
  13391. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13392. /// 021d <state>.L
  13393. /// state:
  13394. /// 0 = Full effects
  13395. /// 1 = Reduced effects
  13396. ///
  13397. /// NOTE: The state is used on Aegis for sending skill unit packet
  13398. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13399. /// whenever possible. Due to the way the decision check is
  13400. /// constructed, this state tracking was rendered useless,
  13401. /// as the only skill unit, that is sent with 0x1c9 is
  13402. /// Graffiti.
  13403. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13404. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13405. sd->state.lesseffect = ( isLess != 0 );
  13406. }
  13407. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13408. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13409. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13410. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13411. int type = RFIFOL(fd,info->pos[1]);
  13412. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13413. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13414. if( sd->state.trading || sd->npc_shopid )
  13415. return;
  13416. if( flag == 0 || n == 0) {
  13417. clif_menuskill_clear(sd);
  13418. return; // Canceled by player.
  13419. }
  13420. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13421. clif_menuskill_clear(sd);
  13422. return; // Prevent hacking.
  13423. }
  13424. switch( type ) {
  13425. case 0: // Change Material
  13426. skill_changematerial(sd,n,item_list);
  13427. break;
  13428. case 1: // Level 1: Pure to Rough
  13429. case 2: // Level 2: Rough to Pure
  13430. skill_elementalanalysis(sd,n,type,item_list);
  13431. break;
  13432. }
  13433. clif_menuskill_clear(sd);
  13434. return;
  13435. }
  13436. /*==========================================
  13437. * Elemental System
  13438. *==========================================*/
  13439. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13440. struct elemental_data *ed;
  13441. struct status_data *status;
  13442. int fd;
  13443. if( sd == NULL || (ed = sd->ed) == NULL )
  13444. return;
  13445. fd = sd->fd;
  13446. status = &ed->battle_status;
  13447. WFIFOHEAD(fd,8);
  13448. WFIFOW(fd,0) = 0x81e;
  13449. WFIFOW(fd,2) = type;
  13450. switch( type ) {
  13451. case SP_HP:
  13452. WFIFOL(fd,4) = status->hp;
  13453. break;
  13454. case SP_MAXHP:
  13455. WFIFOL(fd,4) = status->max_hp;
  13456. break;
  13457. case SP_SP:
  13458. WFIFOL(fd,4) = status->sp;
  13459. break;
  13460. case SP_MAXSP:
  13461. WFIFOL(fd,4) = status->max_sp;
  13462. break;
  13463. }
  13464. WFIFOSET(fd,8);
  13465. }
  13466. void clif_elemental_info(struct map_session_data *sd) {
  13467. int fd;
  13468. struct elemental_data *ed;
  13469. struct status_data *status;
  13470. if( sd == NULL || (ed = sd->ed) == NULL )
  13471. return;
  13472. fd = sd->fd;
  13473. status = &ed->battle_status;
  13474. WFIFOHEAD(fd,22);
  13475. WFIFOW(fd, 0) = 0x81d;
  13476. WFIFOL(fd, 2) = ed->bl.id;
  13477. WFIFOL(fd, 6) = status->hp;
  13478. WFIFOL(fd,10) = status->max_hp;
  13479. WFIFOL(fd,14) = status->sp;
  13480. WFIFOL(fd,18) = status->max_sp;
  13481. WFIFOSET(fd,22);
  13482. }
  13483. /// Buying Store System
  13484. ///
  13485. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13486. /// 0810 <slots>.B
  13487. void clif_buyingstore_open(struct map_session_data* sd)
  13488. {
  13489. int fd = sd->fd;
  13490. WFIFOHEAD(fd,packet_len(0x810));
  13491. WFIFOW(fd,0) = 0x810;
  13492. WFIFOB(fd,2) = sd->buyingstore.slots;
  13493. WFIFOSET(fd,packet_len(0x810));
  13494. }
  13495. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13496. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13497. /// result:
  13498. /// 0 = cancel
  13499. /// 1 = open
  13500. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13501. {
  13502. const unsigned int blocksize = 8;
  13503. uint8* itemlist;
  13504. char storename[MESSAGE_SIZE];
  13505. unsigned char result;
  13506. int zenylimit;
  13507. unsigned int count, packet_len;
  13508. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13509. packet_len = RFIFOW(fd,info->pos[0]);
  13510. // TODO: Make this check global for all variable length packets.
  13511. if( packet_len < 89 )
  13512. {// minimum packet length
  13513. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13514. return;
  13515. }
  13516. zenylimit = RFIFOL(fd,info->pos[1]);
  13517. result = RFIFOL(fd,info->pos[2]);
  13518. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13519. itemlist = RFIFOP(fd,info->pos[4]);
  13520. // so that buyingstore_create knows, how many elements it has access to
  13521. packet_len-= info->pos[4];
  13522. if( packet_len%blocksize )
  13523. {
  13524. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13525. return;
  13526. }
  13527. count = packet_len/blocksize;
  13528. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13529. }
  13530. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13531. /// 0812 <result>.W <total weight>.L
  13532. /// result:
  13533. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13534. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13535. /// 8 = "No sale (purchase) information available." (0x705)
  13536. /// ? = nothing
  13537. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13538. {
  13539. int fd = sd->fd;
  13540. WFIFOHEAD(fd,packet_len(0x812));
  13541. WFIFOW(fd,0) = 0x812;
  13542. WFIFOW(fd,2) = result;
  13543. WFIFOL(fd,4) = weight;
  13544. WFIFOSET(fd,packet_len(0x812));
  13545. }
  13546. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13547. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13548. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13549. {
  13550. int fd = sd->fd;
  13551. unsigned int i;
  13552. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13553. WFIFOW(fd,0) = 0x813;
  13554. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13555. WFIFOL(fd,4) = sd->bl.id;
  13556. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13557. for( i = 0; i < sd->buyingstore.slots; i++ )
  13558. {
  13559. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13560. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13561. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  13562. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13563. }
  13564. WFIFOSET(fd,WFIFOW(fd,2));
  13565. }
  13566. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13567. /// 0814 <account id>.L <store name>.80B
  13568. void clif_buyingstore_entry(struct map_session_data* sd)
  13569. {
  13570. uint8 buf[86];
  13571. WBUFW(buf,0) = 0x814;
  13572. WBUFL(buf,2) = sd->bl.id;
  13573. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13574. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13575. }
  13576. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13577. {
  13578. int fd = sd->fd;
  13579. WFIFOHEAD(fd,packet_len(0x814));
  13580. WFIFOW(fd,0) = 0x814;
  13581. WFIFOL(fd,2) = pl_sd->bl.id;
  13582. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13583. WFIFOSET(fd,packet_len(0x814));
  13584. }
  13585. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13586. /// 0815
  13587. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13588. {
  13589. buyingstore_close(sd);
  13590. }
  13591. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13592. /// 0816 <account id>.L
  13593. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13594. {
  13595. uint8 buf[6];
  13596. WBUFW(buf,0) = 0x816;
  13597. WBUFL(buf,2) = sd->bl.id;
  13598. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13599. }
  13600. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13601. {
  13602. int fd = sd->fd;
  13603. WFIFOHEAD(fd,packet_len(0x816));
  13604. WFIFOW(fd,0) = 0x816;
  13605. WFIFOL(fd,2) = pl_sd->bl.id;
  13606. WFIFOSET(fd,packet_len(0x816));
  13607. }
  13608. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13609. /// 0817 <account id>.L
  13610. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13611. {
  13612. int account_id;
  13613. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13614. buyingstore_open(sd, account_id);
  13615. }
  13616. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13617. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13618. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13619. {
  13620. int fd = sd->fd;
  13621. unsigned int i;
  13622. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13623. WFIFOW(fd,0) = 0x818;
  13624. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13625. WFIFOL(fd,4) = pl_sd->bl.id;
  13626. WFIFOL(fd,8) = pl_sd->buyer_id;
  13627. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13628. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13629. {
  13630. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13631. 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.
  13632. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13633. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13634. }
  13635. WFIFOSET(fd,WFIFOW(fd,2));
  13636. }
  13637. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13638. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13639. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13640. {
  13641. const unsigned int blocksize = 6;
  13642. uint8* itemlist;
  13643. int account_id;
  13644. unsigned int count, packet_len, buyer_id;
  13645. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13646. packet_len = RFIFOW(fd,info->pos[0]);
  13647. if( packet_len < 12 )
  13648. {// minimum packet length
  13649. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13650. return;
  13651. }
  13652. account_id = RFIFOL(fd,info->pos[1]);
  13653. buyer_id = RFIFOL(fd,info->pos[2]);
  13654. itemlist = RFIFOP(fd,info->pos[3]);
  13655. // so that buyingstore_trade knows, how many elements it has access to
  13656. packet_len-= info->pos[3];
  13657. if( packet_len%blocksize )
  13658. {
  13659. 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);
  13660. return;
  13661. }
  13662. count = packet_len/blocksize;
  13663. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13664. }
  13665. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13666. /// 081a <result>.W
  13667. /// result:
  13668. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13669. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13670. /// ? = nothing
  13671. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13672. {
  13673. int fd = sd->fd;
  13674. WFIFOHEAD(fd,packet_len(0x81a));
  13675. WFIFOW(fd,0) = 0x81a;
  13676. WFIFOW(fd,2) = result;
  13677. WFIFOSET(fd,packet_len(0x81a));
  13678. }
  13679. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13680. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13681. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13682. {
  13683. int fd = sd->fd;
  13684. WFIFOHEAD(fd,packet_len(0x81b));
  13685. WFIFOW(fd,0) = 0x81b;
  13686. WFIFOW(fd,2) = nameid;
  13687. WFIFOW(fd,4) = amount; // amount of nameid received
  13688. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13689. WFIFOSET(fd,packet_len(0x81b));
  13690. }
  13691. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13692. /// 081c <index>.W <amount>.W <price>.L
  13693. /// message:
  13694. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13695. ///
  13696. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13697. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13698. {
  13699. int fd = sd->fd;
  13700. WFIFOHEAD(fd,packet_len(0x81c));
  13701. WFIFOW(fd,0) = 0x81c;
  13702. WFIFOW(fd,2) = index+2;
  13703. WFIFOW(fd,4) = amount;
  13704. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13705. WFIFOSET(fd,packet_len(0x81c));
  13706. }
  13707. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13708. /// 0824 <result>.W <name id>.W
  13709. /// result:
  13710. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13711. /// 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)
  13712. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13713. /// ? = nothing
  13714. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13715. {
  13716. int fd = sd->fd;
  13717. WFIFOHEAD(fd,packet_len(0x824));
  13718. WFIFOW(fd,0) = 0x824;
  13719. WFIFOW(fd,2) = result;
  13720. WFIFOW(fd,4) = nameid;
  13721. WFIFOSET(fd,packet_len(0x824));
  13722. }
  13723. /// Search Store Info System
  13724. ///
  13725. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13726. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13727. /// type:
  13728. /// 0 = Vending
  13729. /// 1 = Buying Store
  13730. ///
  13731. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13732. /// amount of card slots. If the client does not know about the item it
  13733. /// cannot be searched.
  13734. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13735. {
  13736. const unsigned int blocksize = 2;
  13737. const uint8* itemlist;
  13738. const uint8* cardlist;
  13739. unsigned char type;
  13740. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13741. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13742. packet_len = RFIFOW(fd,info->pos[0]);
  13743. if( packet_len < 15 )
  13744. {// minimum packet length
  13745. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13746. return;
  13747. }
  13748. type = RFIFOB(fd,info->pos[1]);
  13749. max_price = RFIFOL(fd,info->pos[2]);
  13750. min_price = RFIFOL(fd,info->pos[3]);
  13751. item_count = RFIFOB(fd,info->pos[4]);
  13752. card_count = RFIFOB(fd,info->pos[5]);
  13753. itemlist = RFIFOP(fd,info->pos[6]);
  13754. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13755. // check, if there is enough data for the claimed count of items
  13756. packet_len-= info->pos[6];
  13757. if( packet_len%blocksize )
  13758. {
  13759. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13760. return;
  13761. }
  13762. count = packet_len/blocksize;
  13763. if( count < item_count+card_count )
  13764. {
  13765. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13766. return;
  13767. }
  13768. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13769. }
  13770. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13771. /// 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 }*
  13772. /// is first page:
  13773. /// 0 = appends to existing results
  13774. /// 1 = clears previous results before displaying this result set
  13775. /// is next page:
  13776. /// 0 = no "next" label
  13777. /// 1 = "next" label to retrieve more results
  13778. void clif_search_store_info_ack(struct map_session_data* sd)
  13779. {
  13780. const unsigned int blocksize = MESSAGE_SIZE+26;
  13781. int fd = sd->fd;
  13782. unsigned int i, start, end;
  13783. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13784. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13785. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13786. WFIFOW(fd,0) = 0x836;
  13787. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13788. WFIFOB(fd,4) = !sd->searchstore.pages;
  13789. WFIFOB(fd,5) = searchstore_querynext(sd);
  13790. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13791. for( i = start; i < end; i++ ) {
  13792. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13793. struct item it;
  13794. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13795. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13796. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13797. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13798. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13799. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13800. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13801. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13802. // make-up an item for clif_addcards
  13803. memset(&it, 0, sizeof(it));
  13804. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13805. it.nameid = ssitem->nameid;
  13806. it.amount = ssitem->amount;
  13807. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13808. }
  13809. WFIFOSET(fd,WFIFOW(fd,2));
  13810. }
  13811. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13812. /// 0837 <reason>.B
  13813. /// reason:
  13814. /// 0 = "No matching stores were found." (0x70b)
  13815. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13816. /// 2 = "You cannot search anymore." (0x706)
  13817. /// 3 = "You cannot search yet." (0x708)
  13818. /// 4 = "No sale (purchase) information available." (0x705)
  13819. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13820. {
  13821. int fd = sd->fd;
  13822. WFIFOHEAD(fd,packet_len(0x837));
  13823. WFIFOW(fd,0) = 0x837;
  13824. WFIFOB(fd,2) = reason;
  13825. WFIFOSET(fd,packet_len(0x837));
  13826. }
  13827. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13828. /// 0838
  13829. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13830. {
  13831. searchstore_next(sd);
  13832. }
  13833. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13834. /// 083a <type>.W <remaining uses>.B
  13835. /// type:
  13836. /// 0 = Search Stores
  13837. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13838. void clif_open_search_store_info(struct map_session_data* sd)
  13839. {
  13840. int fd = sd->fd;
  13841. WFIFOHEAD(fd,packet_len(0x83a));
  13842. WFIFOW(fd,0) = 0x83a;
  13843. WFIFOW(fd,2) = sd->searchstore.effect;
  13844. #if PACKETVER > 20100701
  13845. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13846. #endif
  13847. WFIFOSET(fd,packet_len(0x83a));
  13848. }
  13849. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13850. /// 083b
  13851. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13852. {
  13853. searchstore_close(sd);
  13854. }
  13855. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13856. /// 083c <account id>.L <store id>.L <nameid>.W
  13857. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13858. {
  13859. unsigned short nameid;
  13860. int account_id, store_id;
  13861. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13862. account_id = RFIFOL(fd,info->pos[0]);
  13863. store_id = RFIFOL(fd,info->pos[1]);
  13864. nameid = RFIFOW(fd,info->pos[2]);
  13865. searchstore_click(sd, account_id, store_id, nameid);
  13866. }
  13867. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13868. /// 083d <xPos>.W <yPos>.W
  13869. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13870. {
  13871. int fd = sd->fd;
  13872. WFIFOHEAD(fd,packet_len(0x83d));
  13873. WFIFOW(fd,0) = 0x83d;
  13874. WFIFOW(fd,2) = x;
  13875. WFIFOW(fd,4) = y;
  13876. WFIFOSET(fd,packet_len(0x83d));
  13877. }
  13878. /// Parse function for packet debugging.
  13879. void clif_parse_debug(int fd,struct map_session_data *sd)
  13880. {
  13881. int cmd, packet_len;
  13882. // clif_parse ensures, that there is at least 2 bytes of data
  13883. cmd = RFIFOW(fd,0);
  13884. if( sd ) {
  13885. packet_len = packet_db[sd->packet_ver][cmd].len;
  13886. if( packet_len == 0 )
  13887. {// unknown
  13888. packet_len = RFIFOREST(fd);
  13889. }
  13890. else if( packet_len == -1 )
  13891. {// variable length
  13892. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13893. }
  13894. 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);
  13895. }
  13896. else
  13897. {
  13898. packet_len = RFIFOREST(fd);
  13899. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13900. }
  13901. ShowDump(RFIFOP(fd,0), packet_len);
  13902. }
  13903. /*==========================================
  13904. * Server tells client to display a window similar to Magnifier (item) one
  13905. * Server populates the window with avilable elemental converter options according to player's inventory
  13906. *------------------------------------------*/
  13907. int clif_elementalconverter_list(struct map_session_data *sd) {
  13908. int i,c,view,fd;
  13909. nullpo_ret(sd);
  13910. /// Main client packet processing function
  13911. fd=sd->fd;
  13912. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13913. WFIFOW(fd, 0)=0x1ad;
  13914. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13915. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13916. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13917. WFIFOW(fd,c*2+ 4)= view;
  13918. else
  13919. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13920. c++;
  13921. }
  13922. }
  13923. WFIFOW(fd,2) = c*2+4;
  13924. WFIFOSET(fd, WFIFOW(fd,2));
  13925. if (c > 0) {
  13926. sd->menuskill_id = SA_CREATECON;
  13927. sd->menuskill_val = c;
  13928. }
  13929. return 0;
  13930. }
  13931. /**
  13932. * Rune Knight
  13933. **/
  13934. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13935. #if PACKETVER >= 20081217
  13936. unsigned char buf[10];
  13937. WBUFW(buf,0) = 0x440;
  13938. WBUFL(buf,2) = sd->bl.id;
  13939. WBUFW(buf,6) = shields;
  13940. WBUFW(buf,8) = 0;
  13941. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13942. #endif
  13943. }
  13944. /**
  13945. * Warlock
  13946. **/
  13947. /*==========================================
  13948. * Spellbook list [LimitLine/3CeAM]
  13949. *------------------------------------------*/
  13950. int clif_spellbook_list(struct map_session_data *sd)
  13951. {
  13952. int i, c;
  13953. int fd;
  13954. nullpo_ret(sd);
  13955. fd = sd->fd;
  13956. WFIFOHEAD(fd, 8 * 8 + 8);
  13957. WFIFOW(fd,0) = 0x1ad;
  13958. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13959. {
  13960. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13961. {
  13962. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13963. c ++;
  13964. }
  13965. }
  13966. if( c > 0 )
  13967. {
  13968. WFIFOW(fd,2) = c * 2 + 4;
  13969. WFIFOSET(fd, WFIFOW(fd, 2));
  13970. sd->menuskill_id = WL_READING_SB;
  13971. sd->menuskill_val = c;
  13972. }
  13973. else{
  13974. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13975. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  13976. }
  13977. return 1;
  13978. }
  13979. /**
  13980. * Mechanic
  13981. **/
  13982. /*==========================================
  13983. * Magic Decoy Material List
  13984. *------------------------------------------*/
  13985. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  13986. int i, c;
  13987. int fd;
  13988. nullpo_ret(sd);
  13989. fd = sd->fd;
  13990. WFIFOHEAD(fd, 8 * 8 + 8);
  13991. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13992. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13993. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13994. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13995. c ++;
  13996. }
  13997. }
  13998. if( c > 0 ) {
  13999. sd->menuskill_id = NC_MAGICDECOY;
  14000. sd->menuskill_val = skill_lv;
  14001. sd->sc.comet_x = x;
  14002. sd->sc.comet_y = y;
  14003. WFIFOW(fd,2) = c * 2 + 4;
  14004. WFIFOSET(fd, WFIFOW(fd, 2));
  14005. } else {
  14006. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14007. return 0;
  14008. }
  14009. return 1;
  14010. }
  14011. /*==========================================
  14012. * Guillotine Cross Poisons List
  14013. *------------------------------------------*/
  14014. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14015. int i, c;
  14016. int fd;
  14017. nullpo_ret(sd);
  14018. fd = sd->fd;
  14019. WFIFOHEAD(fd, 8 * 8 + 8);
  14020. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14021. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14022. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14023. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14024. c ++;
  14025. }
  14026. }
  14027. if( c > 0 ) {
  14028. sd->menuskill_id = GC_POISONINGWEAPON;
  14029. sd->menuskill_val = skill_lv;
  14030. WFIFOW(fd,2) = c * 2 + 4;
  14031. WFIFOSET(fd, WFIFOW(fd, 2));
  14032. } else {
  14033. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14034. return 0;
  14035. }
  14036. return 1;
  14037. }
  14038. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14039. int fd, i, c;
  14040. nullpo_ret(sd);
  14041. fd = sd->fd;
  14042. if( !fd ) return 0;
  14043. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14044. return 0;
  14045. WFIFOHEAD(fd, 2 * 6 + 4);
  14046. WFIFOW(fd,0) = 0x442;
  14047. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14048. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14049. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  14050. { // Can't auto cast both Extended class and 3rd class skills.
  14051. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14052. c++;
  14053. }
  14054. if( c > 0 ) {
  14055. WFIFOW(fd,2) = 8 + c * 2;
  14056. WFIFOL(fd,4) = c;
  14057. WFIFOSET(fd,WFIFOW(fd,2));
  14058. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14059. sd->menuskill_val = c;
  14060. } else {
  14061. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14062. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14063. }
  14064. return 1;
  14065. }
  14066. /*===========================================
  14067. * Skill list for Four Elemental Analysis
  14068. * and Change Material skills.
  14069. *------------------------------------------*/
  14070. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14071. {
  14072. #if PACKETVER >= 20090922
  14073. int fd;
  14074. nullpo_ret(sd);
  14075. sd->menuskill_id = skill_id; // To prevent hacking.
  14076. sd->menuskill_val = skill_lv;
  14077. if( skill_id == GN_CHANGEMATERIAL )
  14078. skill_lv = 0; // Changematerial
  14079. fd = sd->fd;
  14080. WFIFOHEAD(fd,packet_len(0x7e3));
  14081. WFIFOW(fd,0) = 0x7e3;
  14082. WFIFOL(fd,2) = skill_lv;
  14083. WFIFOL(fd,4) = 0;
  14084. WFIFOSET(fd,packet_len(0x7e3));
  14085. #endif
  14086. return 1;
  14087. }
  14088. /**
  14089. * Sends a new status without a tick (currently used by the new mounts)
  14090. **/
  14091. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  14092. unsigned char buf[32];
  14093. nullpo_ret(bl);
  14094. WBUFW(buf,0)=0x043f;
  14095. WBUFW(buf,2)=type;
  14096. WBUFL(buf,4)=bl->id;
  14097. WBUFB(buf,8)=flag;
  14098. WBUFL(buf,9) = 0;
  14099. WBUFL(buf,13) = val1;
  14100. WBUFL(buf,17) = val2;
  14101. WBUFL(buf,21) = val3;
  14102. clif_send(buf,packet_len(0x043f),bl,AREA);
  14103. return 0;
  14104. }
  14105. //Notifies FD of ID's type
  14106. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  14107. WFIFOHEAD(fd, packet_len(0x043f));
  14108. WFIFOW(fd,0)=0x043f;
  14109. WFIFOW(fd,2)=type;
  14110. WFIFOL(fd,4)=id;
  14111. WFIFOB(fd,8)=flag;
  14112. WFIFOL(fd,9) = 0;
  14113. WFIFOL(fd,13) = val1;
  14114. WFIFOL(fd,17) = val2;
  14115. WFIFOL(fd,21) = val3;
  14116. WFIFOSET(fd, packet_len(0x043f));
  14117. return 0;
  14118. }
  14119. // msgstringtable.txt
  14120. // 0x291 <line>.W
  14121. void clif_msgtable(int fd, int line) {
  14122. WFIFOHEAD(fd, packet_len(0x291));
  14123. WFIFOW(fd, 0) = 0x291;
  14124. WFIFOW(fd, 2) = line;
  14125. WFIFOSET(fd, packet_len(0x291));
  14126. }
  14127. // msgstringtable.txt
  14128. // 0x7e2 <line>.W <value>.L
  14129. void clif_msgtable_num(int fd, int line, int num) {
  14130. #if PACKETVER >= 20090805
  14131. WFIFOHEAD(fd, packet_len(0x7e2));
  14132. WFIFOW(fd, 0) = 0x7e2;
  14133. WFIFOW(fd, 2) = line;
  14134. WFIFOL(fd, 4) = num;
  14135. WFIFOSET(fd, packet_len(0x7e2));
  14136. #endif
  14137. }
  14138. /*==========================================
  14139. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14140. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14141. * RFIFOL(fd,2) - type (currently not used)
  14142. *------------------------------------------*/
  14143. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14144. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14145. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14146. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14147. return;
  14148. if( pc_istrading(sd) ) {
  14149. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14150. clif_menuskill_clear(sd);
  14151. return;
  14152. }
  14153. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14154. clif_menuskill_clear(sd);
  14155. }
  14156. /*==========================================
  14157. * Kagerou/Oboro amulet spirit
  14158. *------------------------------------------*/
  14159. void clif_talisman(struct map_session_data *sd,short type)
  14160. {
  14161. unsigned char buf[10];
  14162. nullpo_retv(sd);
  14163. WBUFW(buf,0)=0x08cf;
  14164. WBUFL(buf,2)=sd->bl.id;
  14165. WBUFW(buf,6)=type;
  14166. WBUFW(buf,8)=sd->talisman[type];
  14167. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14168. }
  14169. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14170. /// 0907 <index>.W
  14171. ///
  14172. /// R 0908 <index>.w <type>.b
  14173. /// type:
  14174. /// 0 = move item to personal tab
  14175. /// 1 = move item to normal tab
  14176. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14177. #if PACKETVER >= 20111122
  14178. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14179. int index = RFIFOW(fd,info->pos[0])-2;
  14180. int type = RFIFOB(fd, info->pos[1]);
  14181. /* can't move while dead. */
  14182. if(pc_isdead(sd)) {
  14183. return;
  14184. }
  14185. if (index < 0 || index >= MAX_INVENTORY)
  14186. return;
  14187. if ( sd->status.inventory[index].favorite && type == 1 )
  14188. sd->status.inventory[index].favorite = 0;
  14189. else if( type == 0 )
  14190. sd->status.inventory[index].favorite = 1;
  14191. else
  14192. return;/* nothing to do. */
  14193. clif_favorite_item(sd, index);
  14194. #endif
  14195. }
  14196. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14197. /// 0900 <index>.W <favorite>.B
  14198. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14199. int fd = sd->fd;
  14200. WFIFOHEAD(fd,packet_len(0x908));
  14201. WFIFOW(fd,0) = 0x908;
  14202. WFIFOW(fd,2) = index+2;
  14203. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14204. WFIFOSET(fd,packet_len(0x908));
  14205. }
  14206. void clif_snap( struct block_list *bl, short x, short y ) {
  14207. unsigned char buf[10];
  14208. WBUFW(buf,0) = 0x8d2;
  14209. WBUFL(buf,2) = bl->id;
  14210. WBUFW(buf,6) = x;
  14211. WBUFW(buf,8) = y;
  14212. clif_send(buf,packet_len(0x8d2),bl,AREA);
  14213. }
  14214. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14215. #if PACKETVER >= 20120404
  14216. WFIFOHEAD(fd,packet_len(0x977));
  14217. WFIFOW(fd,0) = 0x977;
  14218. WFIFOL(fd,2) = md->bl.id;
  14219. WFIFOL(fd,6) = md->status.hp;
  14220. WFIFOL(fd,10) = md->status.max_hp;
  14221. WFIFOSET(fd,packet_len(0x977));
  14222. #endif
  14223. }
  14224. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14225. /// 0979 <world name>.24B <char name>.24B
  14226. void clif_ackworldinfo(struct map_session_data* sd) {
  14227. int fd;
  14228. nullpo_retv(sd);
  14229. fd = sd->fd;
  14230. WFIFOHEAD(fd,packet_len(0x979));
  14231. WFIFOW(fd,0)=0x979;
  14232. //AID -> world name ?
  14233. safestrncpy((char*)WFIFOP(fd,2), '\0' /* World name */, 24);
  14234. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14235. WFIFOSET(fd,packet_len(0x979));
  14236. }
  14237. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14238. /// 0978 <AID>.L
  14239. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14240. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14241. if(sd) clif_ackworldinfo(sd);
  14242. }
  14243. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14244. /// 0447
  14245. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14246. //if(sd)
  14247. ;
  14248. }
  14249. /// req world info (CZ_CLIENT_VERSION)
  14250. /// 044A <version>.L
  14251. void clif_parse_client_version(int fd,struct map_session_data *sd){
  14252. //if(sd)
  14253. ;
  14254. }
  14255. /// Ranking list
  14256. /// ranking pointlist { <name>.24B <point>.L }*10
  14257. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14258. const char* name;
  14259. struct fame_list* list;
  14260. int i, skip=0;
  14261. switch(rankingtype+1) //to keep the same case as char.c
  14262. {
  14263. case 1: list = smith_fame_list; break;
  14264. case 2: list = chemist_fame_list; break;
  14265. case 3: list = taekwon_fame_list; break;
  14266. default: skip=1; break;
  14267. }
  14268. if(!skip){
  14269. //Packet size limits this list to 10 elements. [Skotlex]
  14270. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  14271. if (list[i].id > 0) {
  14272. if (strcmp(list[i].name, "-") == 0 &&
  14273. (name = map_charid2nick(list[i].id)) != NULL)
  14274. {
  14275. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14276. } else {
  14277. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14278. }
  14279. } else {
  14280. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14281. }
  14282. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14283. }
  14284. for(;i < 10; i++) { //In case the MAX is less than 10.
  14285. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14286. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14287. }
  14288. }
  14289. }
  14290. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14291. void clif_ranklist(struct map_session_data *sd, int16 rankingType){
  14292. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14293. int mypoint=0;
  14294. WBUFW(buf,0) = 0x97d;
  14295. WBUFW(buf,2) = rankingType;
  14296. clif_sub_ranklist(buf,4,sd,rankingType);
  14297. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14298. case MAPID_BLACKSMITH:
  14299. case MAPID_ALCHEMIST:
  14300. case MAPID_TAEKWON:
  14301. mypoint = sd->status.fame;
  14302. }
  14303. WBUFL(buf,284) = mypoint; //mypoint
  14304. clif_send(buf, 288, &sd->bl, SELF);
  14305. }
  14306. /*
  14307. * 097c <type> (CZ_REQ_RANKING)
  14308. * type
  14309. * 0: /blacksmith
  14310. * 1: /alchemist
  14311. * 2: /taekwon
  14312. * 3: /pk
  14313. * */
  14314. void clif_parse_ranklist(int fd,struct map_session_data *sd){
  14315. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14316. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14317. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14318. }
  14319. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14320. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point){
  14321. #if PACKETVER < 20130710
  14322. switch(rankingtype){
  14323. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14324. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14325. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14326. }
  14327. #else
  14328. int fd=sd->fd;
  14329. WFIFOHEAD(fd,14);
  14330. WFIFOW(fd,0) = 0x97e;
  14331. WFIFOW(fd,2) = rankingtype;
  14332. WFIFOL(fd,4) = point;
  14333. WFIFOL(fd,8) = sd->status.fame;
  14334. WFIFOSET(fd,12);
  14335. #endif
  14336. }
  14337. /**
  14338. * Transmit personal information to player. (rates)
  14339. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14340. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14341. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14342. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14343. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14344. * FIXME!
  14345. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14346. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14347. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14348. */
  14349. #ifdef VIP_ENABLE
  14350. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14351. if (sd) {
  14352. struct s_packet_db* info;
  14353. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14354. int cmd = 0, fd, i = 0;
  14355. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14356. int details_bexp[PINFO_MAX];
  14357. int details_drop[PINFO_MAX];
  14358. int details_penalty[PINFO_MAX];
  14359. int penalty_const;
  14360. /**
  14361. * Set for EXP
  14362. */
  14363. //0:PCRoom
  14364. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14365. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14366. details_bexp[0] = 0;
  14367. else {
  14368. if (details_bexp[0] < 100) {
  14369. details_bexp[0] = 100 - details_bexp[0];
  14370. details_bexp[0] = 0 - details_bexp[0];
  14371. }
  14372. else
  14373. details_bexp[0] = details_bexp[0] - 100;
  14374. }
  14375. //1:Premium
  14376. if (pc_isvip(sd)) {
  14377. details_bexp[1] = battle_config.vip_base_exp_increase;
  14378. if (details_bexp[1] < 0)
  14379. details_bexp[1] = 0 - details_bexp[1];
  14380. }
  14381. else
  14382. details_bexp[1] = 0;
  14383. //2:Server
  14384. details_bexp[2] = battle_config.base_exp_rate;
  14385. if (details_bexp[2] == 100)
  14386. details_bexp[2] = 0;
  14387. else {
  14388. if (details_bexp[2] < 100) {
  14389. details_bexp[2] = 100 - details_bexp[2];
  14390. details_bexp[2] = 0 - details_bexp[2];
  14391. }
  14392. else
  14393. details_bexp[2] = details_bexp[2] - 100;
  14394. }
  14395. //3:TPLUS
  14396. details_bexp[3] = 0;
  14397. /* End - EXP set*/
  14398. /**
  14399. * Set for Drop rate
  14400. */
  14401. //0:PCRoom
  14402. details_drop[0] = 0;
  14403. //1:Premium
  14404. details_drop[1] = battle_config.vip_drop_increase;
  14405. if (pc_isvip(sd)) {
  14406. if (details_drop[1] < 0)
  14407. details_drop[1] = 0 - details_drop[1];
  14408. }
  14409. else
  14410. details_drop[1] = 0;
  14411. //2:Server
  14412. details_drop[2] = battle_config.item_rate_common;
  14413. if (details_drop[2] == 100)
  14414. details_drop[2] = 0;
  14415. else {
  14416. if (details_drop[2] < 100) {
  14417. details_drop[2] = 100 - details_drop[2];
  14418. details_drop[2] = 0 - details_drop[2];
  14419. }
  14420. else
  14421. details_drop[2] = details_drop[2] - 100;
  14422. }
  14423. //3:TPLUS
  14424. details_drop[3] = 0;
  14425. /* End - Drop set*/
  14426. /**
  14427. * Set for Penalty rate
  14428. */
  14429. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14430. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14431. //0:PCRoom
  14432. details_penalty[0] = 0;
  14433. //1:Premium
  14434. if (pc_isvip(sd)) {
  14435. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14436. if (details_penalty[1] == 100)
  14437. details_penalty[1] = 0;
  14438. else {
  14439. if (details_penalty[1] < 100) {
  14440. details_penalty[1] = 100 - details_penalty[1];
  14441. details_penalty[1] = 0 - details_penalty[1];
  14442. }
  14443. else
  14444. details_penalty[1] = details_penalty[1] - 100;
  14445. }
  14446. }
  14447. else
  14448. details_penalty[1] = 0;
  14449. //2:Server
  14450. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14451. if (details_penalty[2] == 100)
  14452. details_penalty[2] = 0;
  14453. else {
  14454. if (details_penalty[2] < 100) {
  14455. details_penalty[2] = 100 - details_penalty[2];
  14456. details_penalty[2] = 0 - details_penalty[2];
  14457. }
  14458. else
  14459. details_penalty[2] = details_penalty[2] - 100;
  14460. }
  14461. //3:TPLUS
  14462. details_penalty[3] = 0;
  14463. /* End - Penalty set*/
  14464. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14465. info = &packet_db[sd->packet_ver][cmd];
  14466. len = info->len; //this is the base len without details
  14467. if(!len) return; //version as packet disable
  14468. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14469. szdetails = 7;
  14470. factor = 1;
  14471. }
  14472. else if (cmd == 0x097b) {
  14473. tot_baseexp *= factor;
  14474. tot_drop *= factor;
  14475. tot_penalty *= factor;
  14476. }
  14477. fd = sd->fd;
  14478. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14479. WFIFOW(fd,0) = cmd;
  14480. for (i = 0; i < maxinfotype; i++) {
  14481. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14482. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14483. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14484. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14485. tot_baseexp += details_bexp[i]*factor;
  14486. tot_drop += details_penalty[i]*factor;
  14487. tot_penalty += details_drop[i]*factor;
  14488. len += szdetails;
  14489. }
  14490. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14491. if (cmd == 0x08cb) { //0x08cb version
  14492. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14493. WFIFOW(fd,info->pos[2]) = tot_drop;
  14494. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14495. }
  14496. else { //2013-08-07aRagexe uses 0x097b
  14497. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14498. WFIFOL(fd,info->pos[2]) = tot_drop;
  14499. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14500. }
  14501. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14502. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14503. WFIFOSET(fd,len);
  14504. }
  14505. }
  14506. #endif
  14507. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14508. char cmd[30];
  14509. int t_aid = RFIFOL(fd,2);
  14510. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14511. is_atcommand(fd, sd, cmd, 1);
  14512. }
  14513. #ifdef DUMP_UNKNOWN_PACKET
  14514. void DumpUnknow(int fd,TBL_PC *sd,int cmd,int packet_len){
  14515. const char* packet_txt = "save/packet.txt";
  14516. FILE* fp;
  14517. time_t time_server;
  14518. struct tm *datetime;
  14519. char datestr[512];
  14520. time(&time_server); // get time in seconds since 1/1/1970
  14521. datetime = localtime(&time_server); // convert seconds in structure
  14522. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14523. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14524. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14525. if( sd ) {
  14526. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s \n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14527. } else {
  14528. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14529. }
  14530. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14531. fprintf(fp, "\n");
  14532. fclose(fp);
  14533. } else {
  14534. ShowError("Failed to write '%s'.\n", packet_txt);
  14535. // Dump on console instead
  14536. if( sd ) {
  14537. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14538. } else {
  14539. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14540. }
  14541. ShowDump(RFIFOP(fd,0), packet_len);
  14542. }
  14543. }
  14544. #endif
  14545. /*==========================================
  14546. * Main client packet processing function
  14547. *------------------------------------------*/
  14548. static int clif_parse(int fd)
  14549. {
  14550. int cmd, packet_ver, packet_len, err;
  14551. TBL_PC* sd;
  14552. int pnum;
  14553. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14554. // Note: "click masters" can do 80+ clicks in 10 seconds
  14555. 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]
  14556. { // begin main client packet processing loop
  14557. sd = (TBL_PC *)session[fd]->session_data;
  14558. if (session[fd]->flag.eof) {
  14559. if (sd) {
  14560. if (sd->state.autotrade) {
  14561. //Disassociate character from the socket connection.
  14562. session[fd]->session_data = NULL;
  14563. sd->fd = 0;
  14564. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14565. } else
  14566. if (sd->state.active) {
  14567. // Player logout display [Valaris]
  14568. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14569. clif_quitsave(fd, sd);
  14570. } else {
  14571. //Unusual logout (during log on/off/map-changer procedure)
  14572. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14573. map_quit(sd);
  14574. }
  14575. } else {
  14576. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14577. }
  14578. do_close(fd);
  14579. return 0;
  14580. }
  14581. if (RFIFOREST(fd) < 2)
  14582. return 0;
  14583. cmd = RFIFOW(fd,0);
  14584. // identify client's packet version
  14585. if (sd) {
  14586. packet_ver = sd->packet_ver;
  14587. } else {
  14588. // check authentification packet to know packet version
  14589. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14590. if( err ) {// failed to identify packet version
  14591. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14592. err == 1 ? "" :
  14593. err == 2 ? ", possibly for having an invalid account_id" :
  14594. err == 3 ? ", possibly for having an invalid char_id." :
  14595. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14596. err == 4 ? ", possibly for having an invalid login_id1." :
  14597. err == 5 ? ", possibly for having an invalid client_tick." :
  14598. */
  14599. err == 6 ? ", possibly for having an invalid sex." :
  14600. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14601. WFIFOHEAD(fd,packet_len(0x6a));
  14602. WFIFOW(fd,0) = 0x6a;
  14603. WFIFOB(fd,2) = 3; // Rejected from Server
  14604. WFIFOSET(fd,packet_len(0x6a));
  14605. #ifdef DUMP_INVALID_PACKET
  14606. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14607. #endif
  14608. RFIFOSKIP(fd, RFIFOREST(fd));
  14609. set_eof(fd);
  14610. return 0;
  14611. }
  14612. }
  14613. // filter out invalid / unsupported packets
  14614. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14615. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14616. #ifdef DUMP_INVALID_PACKET
  14617. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14618. #endif
  14619. set_eof(fd);
  14620. return 0;
  14621. }
  14622. // determine real packet length
  14623. packet_len = packet_db[packet_ver][cmd].len;
  14624. if (packet_len == -1) { // variable-length packet
  14625. if (RFIFOREST(fd) < 4)
  14626. return 0;
  14627. packet_len = RFIFOW(fd,2);
  14628. if (packet_len < 4 || packet_len > 32768) {
  14629. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14630. #ifdef DUMP_INVALID_PACKET
  14631. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14632. #endif
  14633. set_eof(fd);
  14634. return 0;
  14635. }
  14636. }
  14637. if ((int)RFIFOREST(fd) < packet_len)
  14638. return 0; // not enough data received to form the packet
  14639. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14640. packet_db[packet_ver][cmd].func(fd, sd);
  14641. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14642. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14643. ; //Only valid packet when there is no session
  14644. else
  14645. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14646. ; //Only valid packet when player is not on a map
  14647. else
  14648. packet_db[packet_ver][cmd].func(fd, sd);
  14649. }
  14650. #ifdef DUMP_UNKNOWN_PACKET
  14651. else DumpUnknow(fd,sd,cmd,packet_len);
  14652. #endif
  14653. RFIFOSKIP(fd, packet_len);
  14654. }; // main loop end
  14655. return 0;
  14656. }
  14657. /*==========================================
  14658. * Reads packet_db.txt and setups its array reference
  14659. *------------------------------------------*/
  14660. void packetdb_readdb(void)
  14661. {
  14662. FILE *fp;
  14663. char line[1024];
  14664. int ln=0, entries=0;
  14665. int cmd,i,j,packet_ver;
  14666. int max_cmd=-1;
  14667. int skip_ver = 0;
  14668. int warned = 0;
  14669. char *str[64],*p,*str2[64],*p2,w1[256],w2[256];
  14670. int packet_len_table[MAX_PACKET_DB] = {
  14671. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14675. //#0x0040
  14676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14678. #if PACKETVER <= 20081217
  14679. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14680. #else
  14681. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14682. #endif
  14683. #if PACKETVER < 2
  14684. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14685. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14686. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14687. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14688. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14689. #else
  14690. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14691. #endif
  14692. //#0x0080
  14693. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14694. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14695. #if PACKETVER <= 20100622
  14696. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14697. #else
  14698. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14699. #endif
  14700. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14701. //#0x00C0
  14702. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14703. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14704. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14705. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14706. //#0x0100
  14707. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14708. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14709. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14710. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14711. //#0x0140
  14712. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14713. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14714. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14715. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14716. //#0x0180
  14717. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14718. #if PACKETVER < 1
  14719. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14720. #else // 196 comodo icon status display for later
  14721. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14722. #endif
  14723. #if PACKETVER < 20081126
  14724. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14725. #else // 0x1a2 changed (35->37)
  14726. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14727. #endif
  14728. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14729. //#0x01C0, Set 0x1d5=-1
  14730. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14731. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14732. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14733. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14734. //#0x0200
  14735. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14736. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14737. #if PACKETVER < 20071106
  14738. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14739. #else // 0x22c changed
  14740. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14741. #endif
  14742. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14743. //#0x0240
  14744. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14745. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14746. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14747. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14748. //#0x0280
  14749. #if PACKETVER < 20070711
  14750. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14751. #else
  14752. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14753. #endif
  14754. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14755. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14756. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14757. //#0x02C0
  14758. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14759. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14760. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14761. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14762. //#0x0300
  14763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14767. //#0x0340
  14768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14772. //#0x0380
  14773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14777. //#0x03C0
  14778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14782. //#0x0400
  14783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14787. //#0x0440
  14788. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14792. //#0x0480
  14793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14797. //#0x04C0
  14798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14802. //#0x0500
  14803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14807. //#0x0540
  14808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14812. //#0x0580
  14813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14817. //#0x05C0
  14818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14822. //#0x0600
  14823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14827. //#0x0640
  14828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14832. //#0x0680
  14833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14837. //#0x06C0
  14838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14842. //#0x0700
  14843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14847. //#0x0740
  14848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14852. //#0x0780
  14853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14857. //#0x07C0
  14858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14859. #if PACKETVER < 20090617
  14860. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  14861. #else // 0x7d9 changed
  14862. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  14863. #endif
  14864. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  14865. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  14866. //#0x0800
  14867. #if PACKETVER < 20091229
  14868. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  14869. #else // for Party booking ( PACKETVER >= 20091229 )
  14870. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  14871. #endif
  14872. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  14873. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14874. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  14875. //#0x0840
  14876. #if PACKETVER < 20130000
  14877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14878. #else
  14879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  14880. #endif
  14881. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  14882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14884. //#0x0880
  14885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14889. //#0x08C0
  14890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  14891. 9, 7, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14894. //#0x0900
  14895. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14899. //#0x0940
  14900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14903. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  14904. //#0x0980
  14905. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14906. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 0,
  14907. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  14908. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  14909. };
  14910. struct {
  14911. void (*func)(int, struct map_session_data *);
  14912. char *name;
  14913. } clif_parse_func[]={
  14914. {clif_parse_WantToConnection,"wanttoconnection"},
  14915. {clif_parse_LoadEndAck,"loadendack"},
  14916. {clif_parse_TickSend,"ticksend"},
  14917. {clif_parse_WalkToXY,"walktoxy"},
  14918. {clif_parse_QuitGame,"quitgame"},
  14919. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14920. {clif_parse_GlobalMessage,"globalmessage"},
  14921. {clif_parse_MapMove,"mapmove"},
  14922. {clif_parse_ChangeDir,"changedir"},
  14923. {clif_parse_Emotion,"emotion"},
  14924. {clif_parse_HowManyConnections,"howmanyconnections"},
  14925. {clif_parse_ActionRequest,"actionrequest"},
  14926. {clif_parse_Restart,"restart"},
  14927. {clif_parse_WisMessage,"wis"},
  14928. {clif_parse_Broadcast,"broadcast"},
  14929. {clif_parse_TakeItem,"takeitem"},
  14930. {clif_parse_DropItem,"dropitem"},
  14931. {clif_parse_UseItem,"useitem"},
  14932. {clif_parse_EquipItem,"equipitem"},
  14933. {clif_parse_UnequipItem,"unequipitem"},
  14934. {clif_parse_NpcClicked,"npcclicked"},
  14935. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14936. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14937. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14938. {clif_parse_CreateChatRoom,"createchatroom"},
  14939. {clif_parse_ChatAddMember,"chataddmember"},
  14940. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14941. {clif_parse_ChangeChatOwner,"changechatowner"},
  14942. {clif_parse_KickFromChat,"kickfromchat"},
  14943. {clif_parse_ChatLeave,"chatleave"},
  14944. {clif_parse_TradeRequest,"traderequest"},
  14945. {clif_parse_TradeAck,"tradeack"},
  14946. {clif_parse_TradeAddItem,"tradeadditem"},
  14947. {clif_parse_TradeOk,"tradeok"},
  14948. {clif_parse_TradeCancel,"tradecancel"},
  14949. {clif_parse_TradeCommit,"tradecommit"},
  14950. {clif_parse_StopAttack,"stopattack"},
  14951. {clif_parse_PutItemToCart,"putitemtocart"},
  14952. {clif_parse_GetItemFromCart,"getitemfromcart"},
  14953. {clif_parse_RemoveOption,"removeoption"},
  14954. {clif_parse_ChangeCart,"changecart"},
  14955. {clif_parse_StatusUp,"statusup"},
  14956. {clif_parse_SkillUp,"skillup"},
  14957. {clif_parse_UseSkillToId,"useskilltoid"},
  14958. {clif_parse_UseSkillToPos,"useskilltopos"},
  14959. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  14960. {clif_parse_UseSkillMap,"useskillmap"},
  14961. {clif_parse_RequestMemo,"requestmemo"},
  14962. {clif_parse_ProduceMix,"producemix"},
  14963. {clif_parse_Cooking,"cooking"},
  14964. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  14965. {clif_parse_NpcNextClicked,"npcnextclicked"},
  14966. {clif_parse_NpcAmountInput,"npcamountinput"},
  14967. {clif_parse_NpcStringInput,"npcstringinput"},
  14968. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  14969. {clif_parse_ItemIdentify,"itemidentify"},
  14970. {clif_parse_SelectArrow,"selectarrow"},
  14971. {clif_parse_AutoSpell,"autospell"},
  14972. {clif_parse_UseCard,"usecard"},
  14973. {clif_parse_InsertCard,"insertcard"},
  14974. {clif_parse_RepairItem,"repairitem"},
  14975. {clif_parse_WeaponRefine,"weaponrefine"},
  14976. {clif_parse_SolveCharName,"solvecharname"},
  14977. {clif_parse_ResetChar,"resetchar"},
  14978. {clif_parse_LocalBroadcast,"localbroadcast"},
  14979. {clif_parse_MoveToKafra,"movetokafra"},
  14980. {clif_parse_MoveFromKafra,"movefromkafra"},
  14981. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  14982. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  14983. {clif_parse_CloseKafra,"closekafra"},
  14984. {clif_parse_CreateParty,"createparty"},
  14985. {clif_parse_CreateParty2,"createparty2"},
  14986. {clif_parse_PartyInvite,"partyinvite"},
  14987. {clif_parse_PartyInvite2,"partyinvite2"},
  14988. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  14989. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  14990. {clif_parse_LeaveParty,"leaveparty"},
  14991. {clif_parse_RemovePartyMember,"removepartymember"},
  14992. {clif_parse_PartyChangeOption,"partychangeoption"},
  14993. {clif_parse_PartyMessage,"partymessage"},
  14994. {clif_parse_PartyChangeLeader,"partychangeleader"},
  14995. {clif_parse_CloseVending,"closevending"},
  14996. {clif_parse_VendingListReq,"vendinglistreq"},
  14997. {clif_parse_PurchaseReq,"purchasereq"},
  14998. {clif_parse_PurchaseReq2,"purchasereq2"},
  14999. {clif_parse_OpenVending,"openvending"},
  15000. {clif_parse_CreateGuild,"createguild"},
  15001. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15002. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15003. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15004. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15005. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15006. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15007. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15008. {clif_parse_GuildInvite,"guildinvite"},
  15009. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15010. {clif_parse_GuildLeave,"guildleave"},
  15011. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15012. {clif_parse_GuildMessage,"guildmessage"},
  15013. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15014. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15015. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15016. {clif_parse_GuildOpposition,"guildopposition"},
  15017. {clif_parse_GuildBreak,"guildbreak"},
  15018. {clif_parse_PetMenu,"petmenu"},
  15019. {clif_parse_CatchPet,"catchpet"},
  15020. {clif_parse_SelectEgg,"selectegg"},
  15021. {clif_parse_SendEmotion,"sendemotion"},
  15022. {clif_parse_ChangePetName,"changepetname"},
  15023. {clif_parse_GMKick,"gmkick"},
  15024. {clif_parse_GMHide,"gmhide"},
  15025. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15026. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15027. {clif_parse_GMKickAll,"killall"},
  15028. {clif_parse_GMRecall,"recall"},
  15029. {clif_parse_GMRecall,"summon"},
  15030. {clif_parse_GM_Monster_Item,"itemmonster"},
  15031. {clif_parse_GMShift,"remove"},
  15032. {clif_parse_GMShift,"shift"},
  15033. {clif_parse_GMChangeMapType,"changemaptype"},
  15034. {clif_parse_GMRc,"rc"},
  15035. {clif_parse_GMRecall2,"recall2"},
  15036. {clif_parse_GMRemove2,"remove2"},
  15037. {clif_parse_GMFullStrip,"gmfullstrip"},
  15038. {clif_parse_NoviceDoriDori,"sndoridori"},
  15039. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15040. {clif_parse_PMIgnore,"wisexin"},
  15041. {clif_parse_PMIgnoreList,"wisexlist"},
  15042. {clif_parse_PMIgnoreAll,"wisall"},
  15043. {clif_parse_FriendsListAdd,"friendslistadd"},
  15044. {clif_parse_FriendsListRemove,"friendslistremove"},
  15045. {clif_parse_FriendsListReply,"friendslistreply"},
  15046. {clif_parse_Blacksmith,"blacksmith"},
  15047. {clif_parse_Alchemist,"alchemist"},
  15048. {clif_parse_Taekwon,"taekwon"},
  15049. {clif_parse_RankingPk,"rankingpk"},
  15050. {clif_parse_FeelSaveOk,"feelsaveok"},
  15051. {clif_parse_debug,"debug"},
  15052. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15053. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15054. {clif_parse_HomMoveTo,"hommoveto"},
  15055. {clif_parse_HomAttack,"homattack"},
  15056. {clif_parse_HomMenu,"hommenu"},
  15057. {clif_parse_StoragePassword,"storagepassword"},
  15058. {clif_parse_Hotkey,"hotkey"},
  15059. {clif_parse_AutoRevive,"autorevive"},
  15060. {clif_parse_Check,"check"},
  15061. {clif_parse_Adopt_request,"adoptrequest"},
  15062. {clif_parse_Adopt_reply,"adoptreply"},
  15063. // MAIL SYSTEM
  15064. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15065. {clif_parse_Mail_read,"mailread"},
  15066. {clif_parse_Mail_getattach,"mailgetattach"},
  15067. {clif_parse_Mail_delete,"maildelete"},
  15068. {clif_parse_Mail_return,"mailreturn"},
  15069. {clif_parse_Mail_setattach,"mailsetattach"},
  15070. {clif_parse_Mail_winopen,"mailwinopen"},
  15071. {clif_parse_Mail_send,"mailsend"},
  15072. // AUCTION SYSTEM
  15073. {clif_parse_Auction_search,"auctionsearch"},
  15074. {clif_parse_Auction_buysell,"auctionbuysell"},
  15075. {clif_parse_Auction_setitem,"auctionsetitem"},
  15076. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15077. {clif_parse_Auction_register,"auctionregister"},
  15078. {clif_parse_Auction_cancel,"auctioncancel"},
  15079. {clif_parse_Auction_close,"auctionclose"},
  15080. {clif_parse_Auction_bid,"auctionbid"},
  15081. // Quest Log System
  15082. {clif_parse_questStateAck,"queststate"},
  15083. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15084. {clif_parse_EquipTick,"equiptickbox"},
  15085. {clif_parse_BattleChat,"battlechat"},
  15086. {clif_parse_mercenary_action,"mermenu"},
  15087. {clif_parse_progressbar,"progressbar"},
  15088. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15089. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15090. #if PACKETVER >= 20091229
  15091. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15092. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15093. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15094. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15095. #endif
  15096. {clif_parse_BankCheck,"bankcheck"},
  15097. {clif_parse_BankDeposit,"bankdeposit"},
  15098. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15099. {clif_parse_BankOpen,"bankopen"},
  15100. {clif_parse_BankClose,"bankclose"},
  15101. {clif_parse_PVPInfo,"pvpinfo"},
  15102. {clif_parse_LessEffect,"lesseffect"},
  15103. // Buying Store
  15104. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15105. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15106. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15107. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15108. // Store Search
  15109. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15110. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15111. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15112. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15113. // Cashshop
  15114. { clif_parse_cashshop_open_request, "cashshopopen" },
  15115. { clif_parse_cashshop_close, "cashshopclose" },
  15116. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15117. { clif_parse_cashshop_buy, "cashshopbuy" },
  15118. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15119. /* */
  15120. { clif_parse_MoveItem , "moveitem" },
  15121. { clif_parse_GuildInvite2 , "guildinvite2" },
  15122. { clif_parse_reqworldinfo, "reqworldinfo"},
  15123. { clif_parse_client_version, "clientversion"},
  15124. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15125. { clif_parse_ranklist, "ranklist"},
  15126. {NULL,NULL}
  15127. };
  15128. struct {
  15129. char *name; //function name
  15130. int funcidx; //
  15131. } clif_ack_func[]={ //hash
  15132. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15133. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15134. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15135. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15136. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15137. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15138. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15139. };
  15140. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15141. memset(packet_db,0,sizeof(packet_db));
  15142. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15143. packet_len(i) = packet_len_table[i];
  15144. sprintf(line, "%s/packet_db.txt", db_path);
  15145. if( (fp=fopen(line,"r"))==NULL ){
  15146. ShowFatalError("can't read %s\n", line);
  15147. exit(EXIT_FAILURE);
  15148. }
  15149. clif_config.packet_db_ver = MAX_PACKET_VER;
  15150. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15151. while( fgets(line, sizeof(line), fp) )
  15152. {
  15153. ln++;
  15154. if(line[0]=='/' && line[1]=='/')
  15155. continue;
  15156. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  15157. {
  15158. if(strcmpi(w1,"packet_ver")==0) {
  15159. int prev_ver = packet_ver;
  15160. skip_ver = 0;
  15161. packet_ver = atoi(w2);
  15162. if ( packet_ver > MAX_PACKET_VER )
  15163. { //Check to avoid overflowing. [Skotlex]
  15164. if( (warned&1) == 0 )
  15165. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15166. warned &= 1;
  15167. skip_ver = 1;
  15168. }
  15169. else if( packet_ver < 0 )
  15170. {
  15171. if( (warned&2) == 0 )
  15172. ShowWarning("Negative packet versions are not supported.\n");
  15173. warned &= 2;
  15174. skip_ver = 1;
  15175. }
  15176. else if( packet_ver == SERVER )
  15177. {
  15178. if( (warned&4) == 0 )
  15179. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15180. warned &= 4;
  15181. skip_ver = 1;
  15182. }
  15183. if( skip_ver )
  15184. {
  15185. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15186. packet_ver = prev_ver;
  15187. continue;
  15188. }
  15189. // copy from previous version into new version and continue
  15190. // - indicating all following packets should be read into the newer version
  15191. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15192. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15193. continue;
  15194. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15195. if(strcmpi(w2,"default")==0) //This is the preferred version.
  15196. clif_config.packet_db_ver = MAX_PACKET_VER;
  15197. else // to manually set the packet DB version
  15198. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15199. continue;
  15200. }
  15201. }
  15202. if( skip_ver != 0 )
  15203. continue; // Skipping current packet version
  15204. memset(str,0,sizeof(str));
  15205. for(j=0,p=line;j<4 && p; ++j)
  15206. {
  15207. str[j]=p;
  15208. p=strchr(p,',');
  15209. if(p) *p++=0;
  15210. }
  15211. if(str[0]==NULL)
  15212. continue;
  15213. cmd=strtol(str[0],(char **)NULL,0);
  15214. if(max_cmd < cmd)
  15215. max_cmd = cmd;
  15216. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15217. continue;
  15218. if(str[1]==NULL){
  15219. ShowError("packet_db: packet len error\n");
  15220. continue;
  15221. }
  15222. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15223. if(str[2]==NULL){
  15224. packet_db[packet_ver][cmd].func = NULL;
  15225. ln++;
  15226. continue;
  15227. }
  15228. // look up processing function by name
  15229. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15230. if( j < ARRAYLENGTH(clif_parse_func) )
  15231. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15232. else { //search if it's a mapped ack func
  15233. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15234. if( j < ARRAYLENGTH(clif_ack_func)) {
  15235. int fidx = clif_ack_func[j].funcidx;
  15236. packet_db_ack[packet_ver][fidx] = cmd;
  15237. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15238. }
  15239. }
  15240. // set the identifying cmd for the packet_db version
  15241. if (strcmp(str[2],"wanttoconnection")==0)
  15242. clif_config.connect_cmd[packet_ver] = cmd;
  15243. if(str[3]==NULL){
  15244. ShowError("packet_db: packet error\n");
  15245. exit(EXIT_FAILURE);
  15246. }
  15247. for(j=0,p2=str[3];p2;j++){
  15248. short k;
  15249. str2[j]=p2;
  15250. p2=strchr(p2,':');
  15251. if(p2) *p2++=0;
  15252. k = atoi(str2[j]);
  15253. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15254. if( j >= MAX_PACKET_POS )
  15255. {
  15256. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15257. break;
  15258. }
  15259. packet_db[packet_ver][cmd].pos[j] = k;
  15260. }
  15261. entries++;
  15262. }
  15263. fclose(fp);
  15264. if(max_cmd > MAX_PACKET_DB)
  15265. {
  15266. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15267. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15268. }
  15269. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  15270. { //Locate the nearest version that we still support. [Skotlex]
  15271. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15272. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15273. }
  15274. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, "packet_db.txt");
  15275. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15276. }
  15277. /*==========================================
  15278. *
  15279. *------------------------------------------*/
  15280. int do_init_clif(void) {
  15281. const char* colors[COLOR_MAX] = { "0xFF0000" };
  15282. int i;
  15283. /**
  15284. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15285. **/
  15286. for(i = 0; i < COLOR_MAX; i++) {
  15287. color_table[i] = strtoul(colors[i],NULL,0);
  15288. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15289. }
  15290. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15291. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15292. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15293. packetdb_readdb();
  15294. set_defaultparse(clif_parse);
  15295. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15296. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15297. exit(EXIT_FAILURE);
  15298. }
  15299. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15300. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15301. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15302. return 0;
  15303. }
  15304. void do_final_clif(void) {
  15305. ers_destroy(delay_clearunit_ers);
  15306. }