clif.c 471 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128
  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 "map.h"
  15. #include "chrif.h"
  16. #include "pc.h"
  17. #include "status.h"
  18. #include "npc.h"
  19. #include "itemdb.h"
  20. #include "chat.h"
  21. #include "trade.h"
  22. #include "storage.h"
  23. #include "script.h"
  24. #include "skill.h"
  25. #include "atcommand.h"
  26. #include "intif.h"
  27. #include "battle.h"
  28. #include "battleground.h"
  29. #include "mob.h"
  30. #include "party.h"
  31. #include "unit.h"
  32. #include "guild.h"
  33. #include "vending.h"
  34. #include "pet.h"
  35. #include "homunculus.h"
  36. #include "instance.h"
  37. #include "mercenary.h"
  38. #include "elemental.h"
  39. #include "log.h"
  40. #include "clif.h"
  41. #include "mail.h"
  42. #include "quest.h"
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <stdarg.h>
  47. #include <time.h>
  48. /* for clif_clearunit_delayed */
  49. static struct eri *delay_clearunit_ers;
  50. //#define DUMP_UNKNOWN_PACKET
  51. //#define DUMP_INVALID_PACKET
  52. struct Clif_Config {
  53. int packet_db_ver; //Preferred packet version.
  54. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  55. } clif_config;
  56. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  57. //Converts item type in case of pet eggs.
  58. static inline int itemtype(int type)
  59. {
  60. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  61. }
  62. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
  63. {
  64. p += pos;
  65. p[0] = (uint8)(x>>2);
  66. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  67. p[2] = (uint8)((y<<4) | (dir&0xf));
  68. }
  69. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  70. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  71. {
  72. p += pos;
  73. p[0] = (uint8)(x0>>2);
  74. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  75. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  76. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  77. p[4] = (uint8)y1;
  78. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  79. }
  80. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir)
  81. {
  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. {
  86. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  87. }
  88. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir)
  89. {
  90. p += pos;
  91. if( x ) {
  92. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  93. }
  94. if( y ) {
  95. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  96. }
  97. if( dir ) {
  98. dir[0] = ( p[2] & 0x0f );
  99. }
  100. }
  101. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  102. {
  103. p += pos;
  104. if( x0 ) {
  105. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  106. }
  107. if( y0 ) {
  108. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  109. }
  110. if( x1 ) {
  111. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  112. }
  113. if( y1 ) {
  114. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  115. }
  116. if( sx0 ) {
  117. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  118. }
  119. if( sy0 ) {
  120. sy0[0] = ( p[5] & 0x0f ) >> 0;
  121. }
  122. }
  123. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir)
  124. {
  125. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  126. }
  127. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  128. {
  129. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  130. }
  131. //To idenfity disguised characters.
  132. static inline bool disguised(struct block_list* bl)
  133. {
  134. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  135. }
  136. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  137. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max)
  138. {
  139. if( len > max )
  140. len = max;
  141. mes[len-1] = '\0';
  142. return len;
  143. }
  144. static char map_ip_str[128];
  145. static uint32 map_ip;
  146. static uint32 bind_ip = INADDR_ANY;
  147. static uint16 map_port = 5121;
  148. int map_fd;
  149. static int clif_parse (int fd);
  150. /*==========================================
  151. * Ip setting of map-server
  152. *------------------------------------------*/
  153. int clif_setip(const char* ip)
  154. {
  155. char ip_str[16];
  156. map_ip = host2ip(ip);
  157. if (!map_ip) {
  158. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  159. return 0;
  160. }
  161. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  162. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  163. return 1;
  164. }
  165. void clif_setbindip(const char* ip)
  166. {
  167. char ip_str[16];
  168. bind_ip = host2ip(ip);
  169. if (bind_ip) {
  170. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  171. } else {
  172. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  173. }
  174. }
  175. /*==========================================
  176. * Sets map port to 'port'
  177. * is run from map.c upon loading map server configuration
  178. *------------------------------------------*/
  179. void clif_setport(uint16 port)
  180. {
  181. map_port = port;
  182. }
  183. /*==========================================
  184. * Returns map server IP
  185. *------------------------------------------*/
  186. uint32 clif_getip(void)
  187. {
  188. return map_ip;
  189. }
  190. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  191. uint32 clif_refresh_ip(void)
  192. {
  193. uint32 new_ip;
  194. new_ip = host2ip(map_ip_str);
  195. if (new_ip && new_ip != map_ip) {
  196. map_ip = new_ip;
  197. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  198. return map_ip;
  199. }
  200. return 0;
  201. }
  202. /*==========================================
  203. * Returns map port which is set by clif_setport()
  204. *------------------------------------------*/
  205. uint16 clif_getport(void)
  206. {
  207. return map_port;
  208. }
  209. #if PACKETVER >= 20071106
  210. static inline unsigned char clif_bl_type(struct block_list *bl) {
  211. switch (bl->type) {
  212. case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
  213. case BL_ITEM: return 0x2; //ITEM_TYPE
  214. case BL_SKILL: return 0x3; //SKILL_TYPE
  215. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  216. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  217. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  218. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  219. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  220. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  221. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  222. default: return 0x1; //NPC_TYPE
  223. }
  224. }
  225. #endif
  226. /*==========================================
  227. * sub process of clif_send
  228. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  229. * In order to send area-wise packets, such as:
  230. * - AREA : everyone nearby your area
  231. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  232. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  233. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  234. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  235. *------------------------------------------*/
  236. static int clif_send_sub(struct block_list *bl, va_list ap)
  237. {
  238. struct block_list *src_bl;
  239. struct map_session_data *sd;
  240. unsigned char *buf;
  241. int len, type, fd;
  242. nullpo_ret(bl);
  243. nullpo_ret(sd = (struct map_session_data *)bl);
  244. fd = sd->fd;
  245. if (!fd) //Don't send to disconnected clients.
  246. return 0;
  247. buf = va_arg(ap,unsigned char*);
  248. len = va_arg(ap,int);
  249. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  250. type = va_arg(ap,int);
  251. switch(type)
  252. {
  253. case AREA_WOS:
  254. if (bl == src_bl)
  255. return 0;
  256. break;
  257. case AREA_WOC:
  258. if (sd->chatID || bl == src_bl)
  259. return 0;
  260. break;
  261. case AREA_WOSC:
  262. {
  263. if(src_bl->type == BL_PC){
  264. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  265. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  266. return 0;
  267. }
  268. else if(src_bl->type == BL_NPC) {
  269. struct npc_data *nd = (struct npc_data *)src_bl;
  270. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  271. return 0;
  272. }
  273. }
  274. break;
  275. }
  276. if (session[fd] == NULL)
  277. return 0;
  278. WFIFOHEAD(fd, len);
  279. if (WFIFOP(fd,0) == buf) {
  280. ShowError("WARNING: Invalid use of clif_send function\n");
  281. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  282. ShowError(" Please correct your code.\n");
  283. // don't send to not move the pointer of the packet for next sessions in the loop
  284. //WFIFOSET(fd,0);//## TODO is this ok?
  285. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  286. return 0;
  287. }
  288. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  289. memcpy(WFIFOP(fd,0), buf, len);
  290. WFIFOSET(fd,len);
  291. }
  292. return 0;
  293. }
  294. /*==========================================
  295. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  296. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  297. *------------------------------------------*/
  298. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  299. {
  300. int i;
  301. struct map_session_data *sd, *tsd;
  302. struct party_data *p = NULL;
  303. struct guild *g = NULL;
  304. struct battleground_data *bg = NULL;
  305. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  306. struct s_mapiterator* iter;
  307. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  308. nullpo_ret(bl);
  309. sd = BL_CAST(BL_PC, bl);
  310. switch(type) {
  311. case ALL_CLIENT: //All player clients.
  312. iter = mapit_getallusers();
  313. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  314. {
  315. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  316. { // packet must exist for the client version
  317. WFIFOHEAD(tsd->fd, len);
  318. memcpy(WFIFOP(tsd->fd,0), buf, len);
  319. WFIFOSET(tsd->fd,len);
  320. }
  321. }
  322. mapit_free(iter);
  323. break;
  324. case ALL_SAMEMAP: //All players on the same map
  325. iter = mapit_getallusers();
  326. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  327. {
  328. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  329. { // packet must exist for the client version
  330. WFIFOHEAD(tsd->fd, len);
  331. memcpy(WFIFOP(tsd->fd,0), buf, len);
  332. WFIFOSET(tsd->fd,len);
  333. }
  334. }
  335. mapit_free(iter);
  336. break;
  337. case AREA:
  338. case AREA_WOSC:
  339. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  340. clif_send (buf, len, bl, SELF);
  341. case AREA_WOC:
  342. case AREA_WOS:
  343. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  344. BL_PC, buf, len, bl, type);
  345. break;
  346. case AREA_CHAT_WOC:
  347. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  348. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  349. break;
  350. case CHAT:
  351. case CHAT_WOS:
  352. {
  353. struct chat_data *cd;
  354. if (sd) {
  355. cd = (struct chat_data*)map_id2bl(sd->chatID);
  356. } else if (bl->type == BL_CHAT) {
  357. cd = (struct chat_data*)bl;
  358. } else break;
  359. if (cd == NULL)
  360. break;
  361. for(i = 0; i < cd->users; i++) {
  362. if (type == CHAT_WOS && cd->usersd[i] == sd)
  363. continue;
  364. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  365. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  366. {
  367. WFIFOHEAD(fd,len);
  368. memcpy(WFIFOP(fd,0), buf, len);
  369. WFIFOSET(fd,len);
  370. }
  371. }
  372. }
  373. }
  374. break;
  375. case CHAT_MAINCHAT: //[LuzZza]
  376. iter = mapit_getallusers();
  377. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  378. {
  379. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  380. { // packet must exist for the client version
  381. WFIFOHEAD(tsd->fd, len);
  382. memcpy(WFIFOP(tsd->fd,0), buf, len);
  383. WFIFOSET(tsd->fd,len);
  384. }
  385. }
  386. mapit_free(iter);
  387. break;
  388. case PARTY_AREA:
  389. case PARTY_AREA_WOS:
  390. x0 = bl->x - AREA_SIZE;
  391. y0 = bl->y - AREA_SIZE;
  392. x1 = bl->x + AREA_SIZE;
  393. y1 = bl->y + AREA_SIZE;
  394. case PARTY:
  395. case PARTY_WOS:
  396. case PARTY_SAMEMAP:
  397. case PARTY_SAMEMAP_WOS:
  398. if (sd && sd->status.party_id)
  399. p = party_search(sd->status.party_id);
  400. if (p) {
  401. for(i=0;i<MAX_PARTY;i++){
  402. if( (sd = p->data[i].sd) == NULL )
  403. continue;
  404. if( !(fd=sd->fd) )
  405. continue;
  406. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  407. continue;
  408. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  409. continue;
  410. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  411. continue;
  412. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  413. { // packet must exist for the client version
  414. WFIFOHEAD(fd,len);
  415. memcpy(WFIFOP(fd,0), buf, len);
  416. WFIFOSET(fd,len);
  417. }
  418. }
  419. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  420. break;
  421. iter = mapit_getallusers();
  422. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  423. {
  424. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  425. { // packet must exist for the client version
  426. WFIFOHEAD(tsd->fd, len);
  427. memcpy(WFIFOP(tsd->fd,0), buf, len);
  428. WFIFOSET(tsd->fd,len);
  429. }
  430. }
  431. mapit_free(iter);
  432. }
  433. break;
  434. case DUEL:
  435. case DUEL_WOS:
  436. if (!sd || !sd->duel_group) break; //Invalid usage.
  437. iter = mapit_getallusers();
  438. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  439. {
  440. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  441. continue;
  442. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  443. { // packet must exist for the client version
  444. WFIFOHEAD(tsd->fd, len);
  445. memcpy(WFIFOP(tsd->fd,0), buf, len);
  446. WFIFOSET(tsd->fd,len);
  447. }
  448. }
  449. mapit_free(iter);
  450. break;
  451. case SELF:
  452. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  453. WFIFOHEAD(fd,len);
  454. memcpy(WFIFOP(fd,0), buf, len);
  455. WFIFOSET(fd,len);
  456. }
  457. break;
  458. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  459. case GUILD_AREA:
  460. case GUILD_AREA_WOS:
  461. x0 = bl->x - AREA_SIZE;
  462. y0 = bl->y - AREA_SIZE;
  463. x1 = bl->x + AREA_SIZE;
  464. y1 = bl->y + AREA_SIZE;
  465. case GUILD_SAMEMAP:
  466. case GUILD_SAMEMAP_WOS:
  467. case GUILD:
  468. case GUILD_WOS:
  469. case GUILD_NOBG:
  470. if (sd && sd->status.guild_id)
  471. g = guild_search(sd->status.guild_id);
  472. if (g) {
  473. for(i = 0; i < g->max_member; i++) {
  474. if( (sd = g->member[i].sd) != NULL )
  475. {
  476. if( !(fd=sd->fd) )
  477. continue;
  478. if( type == GUILD_NOBG && sd->bg_id )
  479. continue;
  480. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  481. continue;
  482. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  483. continue;
  484. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  485. continue;
  486. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  487. { // packet must exist for the client version
  488. WFIFOHEAD(fd,len);
  489. memcpy(WFIFOP(fd,0), buf, len);
  490. WFIFOSET(fd,len);
  491. }
  492. }
  493. }
  494. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  495. break;
  496. iter = mapit_getallusers();
  497. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  498. {
  499. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  500. { // packet must exist for the client version
  501. WFIFOHEAD(tsd->fd, len);
  502. memcpy(WFIFOP(tsd->fd,0), buf, len);
  503. WFIFOSET(tsd->fd,len);
  504. }
  505. }
  506. mapit_free(iter);
  507. }
  508. break;
  509. case BG_AREA:
  510. case BG_AREA_WOS:
  511. x0 = bl->x - AREA_SIZE;
  512. y0 = bl->y - AREA_SIZE;
  513. x1 = bl->x + AREA_SIZE;
  514. y1 = bl->y + AREA_SIZE;
  515. case BG_SAMEMAP:
  516. case BG_SAMEMAP_WOS:
  517. case BG:
  518. case BG_WOS:
  519. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  520. {
  521. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  522. {
  523. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  524. continue;
  525. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  526. continue;
  527. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  528. continue;
  529. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  530. continue;
  531. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  532. { // packet must exist for the client version
  533. WFIFOHEAD(fd,len);
  534. memcpy(WFIFOP(fd,0), buf, len);
  535. WFIFOSET(fd,len);
  536. }
  537. }
  538. }
  539. break;
  540. default:
  541. ShowError("clif_send: Unrecognized type %d\n",type);
  542. return -1;
  543. }
  544. return 0;
  545. }
  546. /// Notifies the client, that it's connection attempt was accepted.
  547. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  548. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  549. void clif_authok(struct map_session_data *sd)
  550. {
  551. #if PACKETVER < 20080102
  552. const int cmd = 0x73;
  553. #else
  554. const int cmd = 0x2eb;
  555. #endif
  556. int fd = sd->fd;
  557. WFIFOHEAD(fd,packet_len(cmd));
  558. WFIFOW(fd, 0) = cmd;
  559. WFIFOL(fd, 2) = gettick();
  560. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  561. WFIFOB(fd, 9) = 5; // ignored
  562. WFIFOB(fd,10) = 5; // ignored
  563. #if PACKETVER >= 20080102
  564. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  565. #endif
  566. WFIFOSET(fd,packet_len(cmd));
  567. }
  568. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  569. /// 0074 <error code>.B
  570. /// error code:
  571. /// 0 = client type mismatch
  572. /// 1 = ID mismatch
  573. /// 2 = mobile - out of available time
  574. /// 3 = mobile - already logged in
  575. /// 4 = mobile - waiting state
  576. void clif_authrefuse(int fd, uint8 error_code)
  577. {
  578. WFIFOHEAD(fd,packet_len(0x74));
  579. WFIFOW(fd,0) = 0x74;
  580. WFIFOB(fd,2) = error_code;
  581. WFIFOSET(fd,packet_len(0x74));
  582. }
  583. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  584. /// 0081 <error code>.B
  585. /// error code:
  586. /// 0 = BAN_UNFAIR
  587. /// 1 = server closed -> MsgStringTable[4]
  588. /// 2 = ID already logged in -> MsgStringTable[5]
  589. /// 3 = timeout/too much lag -> MsgStringTable[241]
  590. /// 4 = server full -> MsgStringTable[264]
  591. /// 5 = underaged -> MsgStringTable[305]
  592. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  593. /// 9 = too many connections from this ip -> MsgStringTable[529]
  594. /// 10 = out of available time paid for -> MsgStringTable[530]
  595. /// 11 = BAN_PAY_SUSPEND
  596. /// 12 = BAN_PAY_CHANGE
  597. /// 13 = BAN_PAY_WRONGIP
  598. /// 14 = BAN_PAY_PNGAMEROOM
  599. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  600. /// 16 = BAN_JAPAN_REFUSE1
  601. /// 17 = BAN_JAPAN_REFUSE2
  602. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  603. /// 100 = BAN_PC_IP_UNFAIR
  604. /// 101 = BAN_PC_IP_COUNT_ALL
  605. /// 102 = BAN_PC_IP_COUNT
  606. /// 103 = BAN_GRAVITY_MEM_AGREE
  607. /// 104 = BAN_GAME_MEM_AGREE
  608. /// 105 = BAN_HAN_VALID
  609. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  610. /// 107 = BAN_OVER_CHARACTER_LIST
  611. /// 108 = BAN_IP_BLOCK
  612. /// 109 = BAN_INVALID_PWD_CNT
  613. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  614. /// ? = disconnected -> MsgStringTable[3]
  615. void clif_authfail_fd(int fd, int type)
  616. {
  617. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  618. return;
  619. WFIFOHEAD(fd, packet_len(0x81));
  620. WFIFOW(fd,0) = 0x81;
  621. WFIFOB(fd,2) = type;
  622. WFIFOSET(fd,packet_len(0x81));
  623. set_eof(fd);
  624. }
  625. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  626. /// 00b3 <type>.B
  627. /// type:
  628. /// 1 = disconnect, char-select
  629. /// ? = nothing
  630. void clif_charselectok(int id, uint8 ok)
  631. {
  632. struct map_session_data* sd;
  633. int fd;
  634. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  635. return;
  636. fd = sd->fd;
  637. WFIFOHEAD(fd,packet_len(0xb3));
  638. WFIFOW(fd,0) = 0xb3;
  639. WFIFOB(fd,2) = ok;
  640. WFIFOSET(fd,packet_len(0xb3));
  641. }
  642. /// Makes an item appear on the ground.
  643. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  644. /// 084b (ZC_ITEM_FALL_ENTRY4)
  645. void clif_dropflooritem(struct flooritem_data* fitem)
  646. {
  647. uint8 buf[17];
  648. int view;
  649. nullpo_retv(fitem);
  650. if (fitem->item_data.nameid <= 0)
  651. return;
  652. WBUFW(buf, 0) = 0x9e;
  653. WBUFL(buf, 2) = fitem->bl.id;
  654. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  655. WBUFB(buf, 8) = fitem->item_data.identify;
  656. WBUFW(buf, 9) = fitem->bl.x;
  657. WBUFW(buf,11) = fitem->bl.y;
  658. WBUFB(buf,13) = fitem->subx;
  659. WBUFB(buf,14) = fitem->suby;
  660. WBUFW(buf,15) = fitem->item_data.amount;
  661. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  662. }
  663. /// Makes an item disappear from the ground.
  664. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  665. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  666. {
  667. unsigned char buf[16];
  668. nullpo_retv(fitem);
  669. WBUFW(buf,0) = 0xa1;
  670. WBUFL(buf,2) = fitem->bl.id;
  671. if (fd == 0) {
  672. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  673. } else {
  674. WFIFOHEAD(fd,packet_len(0xa1));
  675. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  676. WFIFOSET(fd,packet_len(0xa1));
  677. }
  678. }
  679. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  680. /// 0080 <id>.L <type>.B
  681. /// type:
  682. /// 0 = out of sight
  683. /// 1 = died
  684. /// 2 = logged out
  685. /// 3 = teleport
  686. /// 4 = trickdead
  687. void clif_clearunit_single(int id, clr_type type, int fd)
  688. {
  689. WFIFOHEAD(fd, packet_len(0x80));
  690. WFIFOW(fd,0) = 0x80;
  691. WFIFOL(fd,2) = id;
  692. WFIFOB(fd,6) = type;
  693. WFIFOSET(fd, packet_len(0x80));
  694. }
  695. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  696. /// 0080 <id>.L <type>.B
  697. /// type:
  698. /// 0 = out of sight
  699. /// 1 = died
  700. /// 2 = logged out
  701. /// 3 = teleport
  702. /// 4 = trickdead
  703. void clif_clearunit_area(struct block_list* bl, clr_type type)
  704. {
  705. unsigned char buf[8];
  706. nullpo_retv(bl);
  707. WBUFW(buf,0) = 0x80;
  708. WBUFL(buf,2) = bl->id;
  709. WBUFB(buf,6) = type;
  710. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  711. if(disguised(bl)) {
  712. WBUFL(buf,2) = -bl->id;
  713. clif_send(buf, packet_len(0x80), bl, SELF);
  714. }
  715. }
  716. /// Used to make monsters with player-sprites disappear after dying
  717. /// like normal monsters, because the client does not remove those
  718. /// automatically.
  719. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  720. {
  721. struct block_list *bl = (struct block_list *)data;
  722. clif_clearunit_area(bl, (clr_type) id);
  723. ers_free(delay_clearunit_ers,bl);
  724. return 0;
  725. }
  726. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  727. {
  728. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  729. memcpy (tbl, bl, sizeof (struct block_list));
  730. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  731. }
  732. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  733. {
  734. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  735. {
  736. *rhand = *lhand = 0;
  737. return;
  738. }
  739. #if PACKETVER < 4
  740. *rhand = sd->status.weapon;
  741. *lhand = sd->status.shield;
  742. #else
  743. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  744. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  745. {
  746. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  747. if (id->view_id > 0)
  748. *rhand = id->view_id;
  749. else
  750. *rhand = id->nameid;
  751. } else
  752. *rhand = 0;
  753. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  754. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  755. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  756. {
  757. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  758. if (id->view_id > 0)
  759. *lhand = id->view_id;
  760. else
  761. *lhand = id->nameid;
  762. } else
  763. *lhand = 0;
  764. #endif
  765. }
  766. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  767. static int clif_setlevel_sub(int lv)
  768. {
  769. if( lv < battle_config.max_lv )
  770. {
  771. ;
  772. }
  773. else if( lv < battle_config.aura_lv )
  774. {
  775. lv = battle_config.max_lv - 1;
  776. }
  777. else
  778. {
  779. lv = battle_config.max_lv;
  780. }
  781. return lv;
  782. }
  783. static int clif_setlevel(struct block_list* bl)
  784. {
  785. int lv = status_get_lv(bl);
  786. if( battle_config.client_limit_unit_lv&bl->type )
  787. return clif_setlevel_sub(lv);
  788. switch( bl->type )
  789. {
  790. case BL_NPC:
  791. case BL_PET:
  792. // npcs and pets do not have level
  793. return 0;
  794. }
  795. return lv;
  796. }
  797. /*==========================================
  798. * Prepares 'unit standing/spawning' packet
  799. *------------------------------------------*/
  800. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  801. {
  802. struct map_session_data* sd;
  803. struct status_change* sc = status_get_sc(bl);
  804. struct view_data* vd = status_get_viewdata(bl);
  805. unsigned char *buf = WBUFP(buffer,0);
  806. #if PACKETVER < 20091103
  807. bool type = !pcdb_checkid(vd->class_);
  808. #endif
  809. unsigned short offset = 0;
  810. #if PACKETVER >= 20091103
  811. const char *name;
  812. #endif
  813. sd = BL_CAST(BL_PC, bl);
  814. #if PACKETVER < 20091103
  815. if(type)
  816. WBUFW(buf,0) = spawn?0x7c:0x78;
  817. else
  818. #endif
  819. #if PACKETVER < 4
  820. WBUFW(buf,0) = spawn?0x79:0x78;
  821. #elif PACKETVER < 7
  822. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  823. #elif PACKETVER < 20080102
  824. WBUFW(buf,0) = spawn?0x22b:0x22a;
  825. #elif PACKETVER < 20091103
  826. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  827. #elif PACKETVER < 20101124
  828. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  829. #else
  830. WBUFW(buf,0) = spawn?0x858:0x857;
  831. #endif
  832. #if PACKETVER >= 20091103
  833. name = status_get_name(bl);
  834. #if PACKETVER < 20110111
  835. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  836. #else
  837. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  838. #endif
  839. WBUFB(buf,4) = clif_bl_type(bl);
  840. offset+=3;
  841. buf = WBUFP(buffer,offset);
  842. #elif PACKETVER >= 20071106
  843. if (type) { //Non-player packets
  844. WBUFB(buf,2) = clif_bl_type(bl);
  845. offset++;
  846. buf = WBUFP(buffer,offset);
  847. }
  848. #endif
  849. WBUFL(buf, 2) = bl->id;
  850. WBUFW(buf, 6) = status_get_speed(bl);
  851. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  852. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  853. #if PACKETVER < 20091103
  854. if (type&&spawn) { //uses an older and different packet structure
  855. WBUFW(buf,12) = (sc)? sc->option : 0;
  856. WBUFW(buf,14) = vd->hair_style;
  857. WBUFW(buf,16) = vd->weapon;
  858. WBUFW(buf,18) = vd->head_bottom;
  859. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  860. WBUFW(buf,22) = vd->shield;
  861. } else {
  862. #endif
  863. #if PACKETVER >= 20091103
  864. WBUFL(buf,12) = (sc)? sc->option : 0;
  865. offset+=2;
  866. buf = WBUFP(buffer,offset);
  867. #elif PACKETVER >= 7
  868. if (!type) {
  869. WBUFL(buf,12) = (sc)? sc->option : 0;
  870. offset+=2;
  871. buf = WBUFP(buffer,offset);
  872. } else
  873. WBUFW(buf,12) = (sc)? sc->option : 0;
  874. #else
  875. WBUFW(buf,12) = (sc)? sc->option : 0;
  876. #endif
  877. WBUFW(buf,14) = vd->class_;
  878. WBUFW(buf,16) = vd->hair_style;
  879. WBUFW(buf,18) = vd->weapon;
  880. #if PACKETVER < 4
  881. WBUFW(buf,20) = vd->head_bottom;
  882. WBUFW(buf,22) = vd->shield;
  883. #else
  884. WBUFW(buf,20) = vd->shield;
  885. WBUFW(buf,22) = vd->head_bottom;
  886. #endif
  887. #if PACKETVER < 20091103
  888. }
  889. #endif
  890. WBUFW(buf,24) = vd->head_top;
  891. WBUFW(buf,26) = vd->head_mid;
  892. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  893. { //The hell, why flags work like this?
  894. WBUFW(buf,22) = status_get_emblem_id(bl);
  895. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  896. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  897. }
  898. WBUFW(buf,28) = vd->hair_color;
  899. WBUFW(buf,30) = vd->cloth_color;
  900. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  901. #if PACKETVER < 20091103
  902. if (type&&spawn) { //End of packet 0x7c
  903. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  904. WBUFB(buf,35) = vd->sex;
  905. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  906. WBUFB(buf,39) = 0;
  907. WBUFB(buf,40) = 0;
  908. return packet_len(0x7c);
  909. }
  910. #endif
  911. #if PACKETVER >= 20110111
  912. WBUFW(buf,34) = vd->robe;
  913. offset+= 2;
  914. buf = WBUFP(buffer,offset);
  915. #endif
  916. WBUFL(buf,34) = status_get_guild_id(bl);
  917. WBUFW(buf,38) = status_get_emblem_id(bl);
  918. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  919. #if PACKETVER >= 20091103
  920. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  921. offset+=2;
  922. buf = WBUFP(buffer,offset);
  923. #elif PACKETVER >= 7
  924. if (!type) {
  925. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  926. offset+=2;
  927. buf = WBUFP(buffer,offset);
  928. } else
  929. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  930. #else
  931. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  932. #endif
  933. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  934. WBUFB(buf,45) = vd->sex;
  935. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  936. WBUFB(buf,49) = (sd)? 5 : 0;
  937. WBUFB(buf,50) = (sd)? 5 : 0;
  938. if (!spawn) {
  939. WBUFB(buf,51) = vd->dead_sit;
  940. offset++;
  941. buf = WBUFP(buffer,offset);
  942. }
  943. WBUFW(buf,51) = clif_setlevel(bl);
  944. #if PACKETVER < 20091103
  945. if (type) //End for non-player packet
  946. return packet_len(WBUFW(buffer,0));
  947. #endif
  948. #if PACKETVER >= 20080102
  949. WBUFW(buf,53) = sd?sd->user_font:0;
  950. #endif
  951. #if PACKETVER >= 20091103
  952. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  953. return WBUFW(buffer,2);
  954. #else
  955. return packet_len(WBUFW(buffer,0));
  956. #endif
  957. }
  958. /*==========================================
  959. * Prepares 'unit walking' packet
  960. *------------------------------------------*/
  961. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  962. {
  963. struct map_session_data* sd;
  964. struct status_change* sc = status_get_sc(bl);
  965. struct view_data* vd = status_get_viewdata(bl);
  966. unsigned char* buf = WBUFP(buffer,0);
  967. #if PACKETVER >= 7
  968. unsigned short offset = 0;
  969. #endif
  970. #if PACKETVER >= 20091103
  971. const char *name;
  972. #endif
  973. sd = BL_CAST(BL_PC, bl);
  974. #if PACKETVER < 4
  975. WBUFW(buf, 0) = 0x7b;
  976. #elif PACKETVER < 7
  977. WBUFW(buf, 0) = 0x1da;
  978. #elif PACKETVER < 20080102
  979. WBUFW(buf, 0) = 0x22c;
  980. #elif PACKETVER < 20091103
  981. WBUFW(buf, 0) = 0x2ec;
  982. #elif PACKETVER < 20101124
  983. WBUFW(buf, 0) = 0x7f7;
  984. #else
  985. WBUFW(buf, 0) = 0x856;
  986. #endif
  987. #if PACKETVER >= 20091103
  988. name = status_get_name(bl);
  989. #if PACKETVER < 20110111
  990. WBUFW(buf, 2) = 69+strlen(name);
  991. #else
  992. WBUFW(buf, 2) = 71+strlen(name);
  993. #endif
  994. offset+=2;
  995. buf = WBUFP(buffer,offset);
  996. #endif
  997. #if PACKETVER >= 20071106
  998. WBUFB(buf, 2) = clif_bl_type(bl);
  999. offset++;
  1000. buf = WBUFP(buffer,offset);
  1001. #endif
  1002. WBUFL(buf, 2) = bl->id;
  1003. WBUFW(buf, 6) = status_get_speed(bl);
  1004. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1005. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1006. #if PACKETVER < 7
  1007. WBUFW(buf,12) = (sc)? sc->option : 0;
  1008. #else
  1009. WBUFL(buf,12) = (sc)? sc->option : 0;
  1010. offset+=2; //Shift the rest of elements by 2 bytes.
  1011. buf = WBUFP(buffer,offset);
  1012. #endif
  1013. WBUFW(buf,14) = vd->class_;
  1014. WBUFW(buf,16) = vd->hair_style;
  1015. WBUFW(buf,18) = vd->weapon;
  1016. #if PACKETVER < 4
  1017. WBUFW(buf,20) = vd->head_bottom;
  1018. WBUFL(buf,22) = gettick();
  1019. WBUFW(buf,26) = vd->shield;
  1020. #else
  1021. WBUFW(buf,20) = vd->shield;
  1022. WBUFW(buf,22) = vd->head_bottom;
  1023. WBUFL(buf,24) = gettick();
  1024. #endif
  1025. WBUFW(buf,28) = vd->head_top;
  1026. WBUFW(buf,30) = vd->head_mid;
  1027. WBUFW(buf,32) = vd->hair_color;
  1028. WBUFW(buf,34) = vd->cloth_color;
  1029. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1030. #if PACKETVER >= 20110111
  1031. WBUFW(buf,38) = vd->robe;
  1032. offset+= 2;
  1033. buf = WBUFP(buffer,offset);
  1034. #endif
  1035. WBUFL(buf,38) = status_get_guild_id(bl);
  1036. WBUFW(buf,42) = status_get_emblem_id(bl);
  1037. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1038. #if PACKETVER < 7
  1039. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1040. #else
  1041. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1042. offset+=2; //Shift the rest of elements by 2 bytes.
  1043. buf = WBUFP(buffer,offset);
  1044. #endif
  1045. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1046. WBUFB(buf,49) = vd->sex;
  1047. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1048. WBUFB(buf,56) = (sd)? 5 : 0;
  1049. WBUFB(buf,57) = (sd)? 5 : 0;
  1050. WBUFW(buf,58) = clif_setlevel(bl);
  1051. #if PACKETVER >= 20080102
  1052. WBUFW(buf,60) = sd?sd->user_font:0;
  1053. #endif
  1054. #if PACKETVER >= 20091103
  1055. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1056. return WBUFW(buffer,2);
  1057. #else
  1058. return packet_len(WBUFW(buffer,0));
  1059. #endif
  1060. }
  1061. //Modifies the buffer for disguise characters and sends it to self.
  1062. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1063. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1064. {
  1065. #if PACKETVER >= 20091103
  1066. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1067. WBUFL(buf,5)=-bl->id;
  1068. #elif PACKETVER >= 20071106
  1069. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1070. WBUFL(buf,3)=-bl->id;
  1071. #else
  1072. WBUFL(buf,2)=-bl->id;
  1073. #endif
  1074. clif_send(buf, len, bl, SELF);
  1075. }
  1076. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1077. /// 01b0 <id>.L <type>.B <value>.L
  1078. /// type:
  1079. /// unused
  1080. void clif_class_change(struct block_list *bl,int class_,int type)
  1081. {
  1082. unsigned char buf[16];
  1083. nullpo_retv(bl);
  1084. if(!pcdb_checkid(class_))
  1085. {// player classes yield missing sprites
  1086. WBUFW(buf,0)=0x1b0;
  1087. WBUFL(buf,2)=bl->id;
  1088. WBUFB(buf,6)=type;
  1089. WBUFL(buf,7)=class_;
  1090. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1091. }
  1092. }
  1093. /// Notifies the client of an object's spirits.
  1094. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1095. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1096. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1097. {
  1098. WFIFOHEAD(fd, packet_len(0x1e1));
  1099. WFIFOW(fd,0)=0x1e1;
  1100. WFIFOL(fd,2)=sd->bl.id;
  1101. WFIFOW(fd,6)=sd->spiritball;
  1102. WFIFOSET(fd, packet_len(0x1e1));
  1103. }
  1104. /*==========================================
  1105. * Kagerou/Oboro amulet spirit
  1106. *------------------------------------------*/
  1107. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1108. {
  1109. WFIFOHEAD(fd, packet_len(0x08cf));
  1110. WFIFOW(fd,0)=0x08cf;
  1111. WFIFOL(fd,2)=sd->bl.id;
  1112. WFIFOW(fd,6)=type;
  1113. WFIFOW(fd,8)=sd->talisman[type];
  1114. WFIFOSET(fd, packet_len(0x08cf));
  1115. }
  1116. /*==========================================
  1117. * Run when player changes map / refreshes
  1118. * Tells its client to display all weather settings being used by this map
  1119. *------------------------------------------*/
  1120. static void clif_weather_check(struct map_session_data *sd)
  1121. {
  1122. int16 m = sd->bl.m;
  1123. int fd = sd->fd;
  1124. if (map[m].flag.snow
  1125. || map[m].flag.clouds
  1126. || map[m].flag.fog
  1127. || map[m].flag.fireworks
  1128. || map[m].flag.sakura
  1129. || map[m].flag.leaves
  1130. /**
  1131. * No longer available, keeping here just in case it's back someday. [Ind]
  1132. **/
  1133. //|| map[m].flag.rain
  1134. || map[m].flag.clouds2)
  1135. {
  1136. if (map[m].flag.snow)
  1137. clif_specialeffect_single(&sd->bl, 162, fd);
  1138. if (map[m].flag.clouds)
  1139. clif_specialeffect_single(&sd->bl, 233, fd);
  1140. if (map[m].flag.clouds2)
  1141. clif_specialeffect_single(&sd->bl, 516, fd);
  1142. if (map[m].flag.fog)
  1143. clif_specialeffect_single(&sd->bl, 515, fd);
  1144. if (map[m].flag.fireworks) {
  1145. clif_specialeffect_single(&sd->bl, 297, fd);
  1146. clif_specialeffect_single(&sd->bl, 299, fd);
  1147. clif_specialeffect_single(&sd->bl, 301, fd);
  1148. }
  1149. if (map[m].flag.sakura)
  1150. clif_specialeffect_single(&sd->bl, 163, fd);
  1151. if (map[m].flag.leaves)
  1152. clif_specialeffect_single(&sd->bl, 333, fd);
  1153. /**
  1154. * No longer available, keeping here just in case it's back someday. [Ind]
  1155. **/
  1156. //if (map[m].flag.rain)
  1157. // clif_specialeffect_single(&sd->bl, 161, fd);
  1158. }
  1159. }
  1160. /**
  1161. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1162. **/
  1163. void clif_weather(int16 m)
  1164. {
  1165. struct s_mapiterator* iter;
  1166. struct map_session_data *sd=NULL;
  1167. iter = mapit_getallusers();
  1168. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1169. {
  1170. if( sd->bl.m == m )
  1171. clif_weather_check(sd);
  1172. }
  1173. mapit_free(iter);
  1174. }
  1175. /**
  1176. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1177. **/
  1178. int clif_spawn(struct block_list *bl)
  1179. {
  1180. unsigned char buf[128];
  1181. struct view_data *vd;
  1182. int len;
  1183. vd = status_get_viewdata(bl);
  1184. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1185. return 0;
  1186. /**
  1187. * Hide NPC from maya purple card.
  1188. **/
  1189. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1190. return 0;
  1191. len = clif_set_unit_idle(bl, buf,true);
  1192. clif_send(buf, len, bl, AREA_WOS);
  1193. if (disguised(bl))
  1194. clif_setdisguise(bl, buf, len);
  1195. if (vd->cloth_color)
  1196. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1197. switch (bl->type)
  1198. {
  1199. case BL_PC:
  1200. {
  1201. TBL_PC *sd = ((TBL_PC*)bl);
  1202. int i;
  1203. if (sd->spiritball > 0)
  1204. clif_spiritball(&sd->bl);
  1205. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1206. clif_specialeffect(bl,423,AREA);
  1207. else if(sd->state.size==SZ_MEDIUM)
  1208. clif_specialeffect(bl,421,AREA);
  1209. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1210. clif_sendbgemblem_area(sd);
  1211. if( sd->sc.option&OPTION_MOUNTING ) {
  1212. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1213. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1214. }
  1215. for(i = 1; i < 5; i++){
  1216. if( sd->talisman[i] > 0 )
  1217. clif_talisman(sd, i);
  1218. }
  1219. #ifdef NEW_CARTS
  1220. if( sd->sc.data[SC_PUSH_CART] )
  1221. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1222. #endif
  1223. #if PACKETVER <= 20120207
  1224. if (sd->status.robe)
  1225. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1226. #endif
  1227. }
  1228. break;
  1229. case BL_MOB:
  1230. {
  1231. TBL_MOB *md = ((TBL_MOB*)bl);
  1232. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1233. clif_specialeffect(&md->bl,423,AREA);
  1234. else if(md->special_state.size==SZ_MEDIUM)
  1235. clif_specialeffect(&md->bl,421,AREA);
  1236. }
  1237. break;
  1238. case BL_NPC:
  1239. {
  1240. TBL_NPC *nd = ((TBL_NPC*)bl);
  1241. if( nd->size == SZ_BIG )
  1242. clif_specialeffect(&nd->bl,423,AREA);
  1243. else if( nd->size == SZ_MEDIUM )
  1244. clif_specialeffect(&nd->bl,421,AREA);
  1245. }
  1246. break;
  1247. case BL_PET:
  1248. if (vd->head_bottom)
  1249. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1250. break;
  1251. }
  1252. return 0;
  1253. }
  1254. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1255. /// 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
  1256. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1257. {
  1258. struct status_data *status;
  1259. unsigned char buf[128];
  1260. int m_class;
  1261. nullpo_retv(hd);
  1262. status = &hd->battle_status;
  1263. m_class = hom_class2mapid(hd->homunculus.class_);
  1264. memset(buf,0,packet_len(0x22e));
  1265. WBUFW(buf,0)=0x22e;
  1266. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1267. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1268. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1269. WBUFW(buf,27)=hd->homunculus.level;
  1270. WBUFW(buf,29)=hd->homunculus.hunger;
  1271. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1272. WBUFW(buf,33)=0; // equip id
  1273. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1274. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1275. WBUFW(buf,39)=status->hit;
  1276. if (battle_config.hom_setting&0x10)
  1277. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1278. else
  1279. WBUFW(buf,41)=status->cri/10;
  1280. WBUFW(buf,43)=status->def + status->vit ;
  1281. WBUFW(buf,45)=status->mdef;
  1282. WBUFW(buf,47)=status->flee;
  1283. WBUFW(buf,49)=(flag)?0:status->amotion;
  1284. if (status->max_hp > INT16_MAX) {
  1285. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1286. WBUFW(buf,53) = 100;
  1287. } else {
  1288. WBUFW(buf,51)=status->hp;
  1289. WBUFW(buf,53)=status->max_hp;
  1290. }
  1291. if (status->max_sp > INT16_MAX) {
  1292. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1293. WBUFW(buf,57) = 100;
  1294. } else {
  1295. WBUFW(buf,55)=status->sp;
  1296. WBUFW(buf,57)=status->max_sp;
  1297. }
  1298. WBUFL(buf,59)=hd->homunculus.exp;
  1299. if( ((m_class&HOM_REG) && hd->homunculus.level >= battle_config.hom_max_level) || ((m_class&HOM_S) && hd->homunculus.level >= battle_config.hom_S_max_level) )
  1300. WBUFL(buf,63)=0;
  1301. else
  1302. WBUFL(buf,63)=hd->exp_next;
  1303. WBUFW(buf,67)=hd->homunculus.skillpts;
  1304. WBUFW(buf,69)=status_get_range(&hd->bl);
  1305. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1306. }
  1307. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1308. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1309. /// type:
  1310. /// unused
  1311. /// state:
  1312. /// 0 = pre-init
  1313. /// 1 = intimacy
  1314. /// 2 = hunger
  1315. /// 3 = accessory?
  1316. /// ? = ignored
  1317. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1318. { //[orn]
  1319. int fd = sd->fd;
  1320. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1321. merc_hom_calc_skilltree(sd->hd, 0);
  1322. WFIFOHEAD(fd, packet_len(0x230));
  1323. WFIFOW(fd,0)=0x230;
  1324. WFIFOB(fd,2)=0;
  1325. WFIFOB(fd,3)=state;
  1326. WFIFOL(fd,4)=sd->hd->bl.id;
  1327. WFIFOL(fd,8)=param;
  1328. WFIFOSET(fd,packet_len(0x230));
  1329. }
  1330. int clif_homskillinfoblock(struct map_session_data *sd)
  1331. { //[orn]
  1332. struct homun_data *hd;
  1333. int fd = sd->fd;
  1334. int i,j,len=4,id;
  1335. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1336. hd = sd->hd;
  1337. if ( !hd )
  1338. return 0 ;
  1339. WFIFOW(fd,0)=0x235;
  1340. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1341. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1342. j = id - HM_SKILLBASE;
  1343. WFIFOW(fd,len ) = id;
  1344. WFIFOW(fd,len+2) = skill_get_inf(id);
  1345. WFIFOW(fd,len+4) = 0;
  1346. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1347. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1348. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1349. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1350. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1351. len+=37;
  1352. }
  1353. }
  1354. WFIFOW(fd,2)=len;
  1355. WFIFOSET(fd,len);
  1356. return 0;
  1357. }
  1358. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1359. { //[orn]
  1360. struct homun_data *hd;
  1361. int fd, idx;
  1362. nullpo_retv(sd);
  1363. idx = skill_id - HM_SKILLBASE;
  1364. fd=sd->fd;
  1365. hd=sd->hd;
  1366. WFIFOHEAD(fd, packet_len(0x239));
  1367. WFIFOW(fd,0) = 0x239;
  1368. WFIFOW(fd,2) = skill_id;
  1369. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1370. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1371. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1372. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1373. WFIFOSET(fd,packet_len(0x239));
  1374. }
  1375. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1376. {
  1377. int fd=sd->fd;
  1378. WFIFOHEAD(fd,packet_len(0x22f));
  1379. WFIFOW(fd,0)=0x22f;
  1380. WFIFOB(fd,2)=fail;
  1381. WFIFOW(fd,3)=foodid;
  1382. WFIFOSET(fd,packet_len(0x22f));
  1383. return 0;
  1384. }
  1385. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1386. /// 0087 <walk start time>.L <walk data>.6B
  1387. void clif_walkok(struct map_session_data *sd)
  1388. {
  1389. int fd=sd->fd;
  1390. WFIFOHEAD(fd, packet_len(0x87));
  1391. WFIFOW(fd,0)=0x87;
  1392. WFIFOL(fd,2)=gettick();
  1393. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1394. WFIFOSET(fd,packet_len(0x87));
  1395. }
  1396. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1397. {
  1398. uint8 buf[128];
  1399. int len;
  1400. len = clif_set_unit_walking(bl,ud,buf);
  1401. clif_send(buf,len,bl,AREA_WOS);
  1402. if (disguised(bl))
  1403. clif_setdisguise(bl, buf, len);
  1404. if(vd->cloth_color)
  1405. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1406. switch(bl->type)
  1407. {
  1408. case BL_PC:
  1409. {
  1410. TBL_PC *sd = ((TBL_PC*)bl);
  1411. // clif_movepc(sd);
  1412. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1413. clif_specialeffect(&sd->bl,423,AREA);
  1414. else if(sd->state.size==SZ_MEDIUM)
  1415. clif_specialeffect(&sd->bl,421,AREA);
  1416. }
  1417. break;
  1418. case BL_MOB:
  1419. {
  1420. TBL_MOB *md = ((TBL_MOB*)bl);
  1421. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1422. clif_specialeffect(&md->bl,423,AREA);
  1423. else if(md->special_state.size==SZ_MEDIUM)
  1424. clif_specialeffect(&md->bl,421,AREA);
  1425. }
  1426. break;
  1427. case BL_PET:
  1428. if( vd->head_bottom )
  1429. {// needed to display pet equip properly
  1430. clif_pet_equip_area((TBL_PET*)bl);
  1431. }
  1432. break;
  1433. }
  1434. }
  1435. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1436. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1437. /// Note: unit must not be self
  1438. void clif_move(struct unit_data *ud)
  1439. {
  1440. unsigned char buf[16];
  1441. struct view_data* vd;
  1442. struct block_list* bl = ud->bl;
  1443. vd = status_get_viewdata(bl);
  1444. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1445. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1446. /**
  1447. * Hide NPC from maya purple card.
  1448. **/
  1449. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1450. return;
  1451. if (ud->state.speed_changed) {
  1452. // Since we don't know how to update the speed of other objects,
  1453. // use the old walk packet to update the data.
  1454. ud->state.speed_changed = 0;
  1455. clif_move2(bl, vd, ud);
  1456. return;
  1457. }
  1458. WBUFW(buf,0)=0x86;
  1459. WBUFL(buf,2)=bl->id;
  1460. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1461. WBUFL(buf,12)=gettick();
  1462. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1463. if (disguised(bl))
  1464. {
  1465. WBUFL(buf,2)=-bl->id;
  1466. clif_send(buf, packet_len(0x86), bl, SELF);
  1467. }
  1468. }
  1469. /*==========================================
  1470. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1471. *------------------------------------------*/
  1472. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1473. {
  1474. struct map_session_data *sd = NULL;
  1475. //Remove player from map server
  1476. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1477. map_quit(sd);
  1478. return 0;
  1479. }
  1480. /*==========================================
  1481. *
  1482. *------------------------------------------*/
  1483. void clif_quitsave(int fd,struct map_session_data *sd)
  1484. {
  1485. if (!battle_config.prevent_logout ||
  1486. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1487. map_quit(sd);
  1488. else if (sd->fd)
  1489. { //Disassociate session from player (session is deleted after this function was called)
  1490. //And set a timer to make him quit later.
  1491. session[sd->fd]->session_data = NULL;
  1492. sd->fd = 0;
  1493. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1494. }
  1495. }
  1496. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1497. /// 0091 <map name>.16B <x>.W <y>.W
  1498. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1499. {
  1500. int fd;
  1501. nullpo_retv(sd);
  1502. fd = sd->fd;
  1503. WFIFOHEAD(fd,packet_len(0x91));
  1504. WFIFOW(fd,0) = 0x91;
  1505. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1506. WFIFOW(fd,18) = x;
  1507. WFIFOW(fd,20) = y;
  1508. WFIFOSET(fd,packet_len(0x91));
  1509. }
  1510. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1511. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1512. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1513. {
  1514. int fd;
  1515. nullpo_retv(sd);
  1516. fd = sd->fd;
  1517. WFIFOHEAD(fd,packet_len(0x92));
  1518. WFIFOW(fd,0) = 0x92;
  1519. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1520. WFIFOW(fd,18) = x;
  1521. WFIFOW(fd,20) = y;
  1522. WFIFOL(fd,22) = htonl(ip);
  1523. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1524. WFIFOSET(fd,packet_len(0x92));
  1525. }
  1526. void clif_blown(struct block_list *bl)
  1527. {
  1528. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1529. // clif_fixpos(bl);
  1530. clif_slide(bl, bl->x, bl->y);
  1531. }
  1532. /// Visually moves(slides) a character to x,y. If the target cell
  1533. /// isn't walkable, the char doesn't move at all. If the char is
  1534. /// sitting it will stand up (ZC_STOPMOVE).
  1535. /// 0088 <id>.L <x>.W <y>.W
  1536. void clif_fixpos(struct block_list *bl)
  1537. {
  1538. unsigned char buf[10];
  1539. nullpo_retv(bl);
  1540. WBUFW(buf,0) = 0x88;
  1541. WBUFL(buf,2) = bl->id;
  1542. WBUFW(buf,6) = bl->x;
  1543. WBUFW(buf,8) = bl->y;
  1544. clif_send(buf, packet_len(0x88), bl, AREA);
  1545. if( disguised(bl) )
  1546. {
  1547. WBUFL(buf,2) = -bl->id;
  1548. clif_send(buf, packet_len(0x88), bl, SELF);
  1549. }
  1550. }
  1551. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1552. /// 00c4 <shop id>.L
  1553. void clif_npcbuysell(struct map_session_data* sd, int id)
  1554. {
  1555. int fd;
  1556. nullpo_retv(sd);
  1557. fd=sd->fd;
  1558. WFIFOHEAD(fd, packet_len(0xc4));
  1559. WFIFOW(fd,0)=0xc4;
  1560. WFIFOL(fd,2)=id;
  1561. WFIFOSET(fd,packet_len(0xc4));
  1562. }
  1563. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1564. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1565. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1566. {
  1567. int fd,i,c;
  1568. nullpo_retv(sd);
  1569. nullpo_retv(nd);
  1570. fd = sd->fd;
  1571. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1572. WFIFOW(fd,0) = 0xc6;
  1573. c = 0;
  1574. for( i = 0; i < nd->u.shop.count; i++ )
  1575. {
  1576. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1577. int val = nd->u.shop.shop_item[i].value;
  1578. if( id == NULL )
  1579. continue;
  1580. WFIFOL(fd, 4+c*11) = val;
  1581. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1582. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1583. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1584. c++;
  1585. }
  1586. WFIFOW(fd,2) = 4 + c*11;
  1587. WFIFOSET(fd,WFIFOW(fd,2));
  1588. }
  1589. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1590. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1591. void clif_selllist(struct map_session_data *sd)
  1592. {
  1593. int fd,i,c=0,val;
  1594. nullpo_retv(sd);
  1595. fd=sd->fd;
  1596. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1597. WFIFOW(fd,0)=0xc7;
  1598. for( i = 0; i < MAX_INVENTORY; i++ )
  1599. {
  1600. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1601. {
  1602. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1603. continue;
  1604. if( sd->status.inventory[i].expire_time )
  1605. continue; // Cannot Sell Rental Items
  1606. val=sd->inventory_data[i]->value_sell;
  1607. if( val < 0 )
  1608. continue;
  1609. WFIFOW(fd,4+c*10)=i+2;
  1610. WFIFOL(fd,6+c*10)=val;
  1611. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1612. c++;
  1613. }
  1614. }
  1615. WFIFOW(fd,2)=c*10+4;
  1616. WFIFOSET(fd,WFIFOW(fd,2));
  1617. }
  1618. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1619. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1620. /// Client behavior (dialog window):
  1621. /// - disable mouse targeting
  1622. /// - open the dialog window
  1623. /// - set npcid of dialog window (0 by default)
  1624. /// - if set to clear on next mes, clear contents
  1625. /// - append this text
  1626. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1627. {
  1628. int fd = sd->fd;
  1629. int slen = strlen(mes) + 9;
  1630. WFIFOHEAD(fd, slen);
  1631. WFIFOW(fd,0)=0xb4;
  1632. WFIFOW(fd,2)=slen;
  1633. WFIFOL(fd,4)=npcid;
  1634. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1635. WFIFOSET(fd,WFIFOW(fd,2));
  1636. }
  1637. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1638. /// 00b5 <npc id>.L
  1639. /// Client behavior (dialog window):
  1640. /// - disable mouse targeting
  1641. /// - open the dialog window
  1642. /// - add 'next' button
  1643. /// When 'next' is pressed:
  1644. /// - 00B9 <npcid of dialog window>.L
  1645. /// - set to clear on next mes
  1646. /// - remove 'next' button
  1647. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1648. {
  1649. int fd;
  1650. nullpo_retv(sd);
  1651. fd=sd->fd;
  1652. WFIFOHEAD(fd, packet_len(0xb5));
  1653. WFIFOW(fd,0)=0xb5;
  1654. WFIFOL(fd,2)=npcid;
  1655. WFIFOSET(fd,packet_len(0xb5));
  1656. }
  1657. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1658. /// 00b6 <npc id>.L
  1659. /// Client behavior:
  1660. /// - if dialog window is open:
  1661. /// - remove 'next' button
  1662. /// - add 'close' button
  1663. /// - else:
  1664. /// - enable mouse targeting
  1665. /// - close the dialog window
  1666. /// - close the menu window
  1667. /// When 'close' is pressed:
  1668. /// - enable mouse targeting
  1669. /// - close the dialog window
  1670. /// - close the menu window
  1671. /// - 0146 <npcid of dialog window>.L
  1672. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1673. {
  1674. int fd;
  1675. nullpo_retv(sd);
  1676. fd=sd->fd;
  1677. WFIFOHEAD(fd, packet_len(0xb6));
  1678. WFIFOW(fd,0)=0xb6;
  1679. WFIFOL(fd,2)=npcid;
  1680. WFIFOSET(fd,packet_len(0xb6));
  1681. }
  1682. /*==========================================
  1683. *
  1684. *------------------------------------------*/
  1685. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1686. {
  1687. unsigned char *buf;
  1688. int fd = sd->fd;
  1689. sd->state.using_fake_npc = 1;
  1690. WFIFOHEAD(fd, packet_len(0x78));
  1691. buf = WFIFOP(fd,0);
  1692. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1693. WBUFW(buf,0)=0x78;
  1694. #if PACKETVER >= 20071106
  1695. WBUFB(buf,2) = 0; // object type
  1696. buf = WFIFOP(fd,1);
  1697. #endif
  1698. WBUFL(buf,2)=npcid;
  1699. WBUFW(buf,14)=111;
  1700. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1701. WBUFB(buf,49)=5;
  1702. WBUFB(buf,50)=5;
  1703. WFIFOSET(fd, packet_len(0x78));
  1704. }
  1705. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1706. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1707. /// Client behavior:
  1708. /// - disable mouse targeting
  1709. /// - close the menu window
  1710. /// - open the menu window
  1711. /// - add options to the menu (separated in the text by ":")
  1712. /// - set npcid of menu window
  1713. /// - if dialog window is open:
  1714. /// - remove 'next' button
  1715. /// When 'ok' is pressed:
  1716. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1717. /// - close the menu window
  1718. /// When 'cancel' is pressed:
  1719. /// - 00B8 <npcid of menu window>.L <-1>.B
  1720. /// - enable mouse targeting
  1721. /// - close a bunch of windows...
  1722. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1723. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1724. /// TODO investigate behavior of other windows [FlavioJS]
  1725. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1726. {
  1727. int fd = sd->fd;
  1728. int slen = strlen(mes) + 9;
  1729. struct block_list *bl = NULL;
  1730. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1731. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1732. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1733. clif_sendfakenpc(sd, npcid);
  1734. WFIFOHEAD(fd, slen);
  1735. WFIFOW(fd,0)=0xb7;
  1736. WFIFOW(fd,2)=slen;
  1737. WFIFOL(fd,4)=npcid;
  1738. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1739. WFIFOSET(fd,WFIFOW(fd,2));
  1740. }
  1741. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1742. /// 0142 <npc id>.L
  1743. /// Client behavior (inputnum window):
  1744. /// - if npcid exists in the client:
  1745. /// - open the inputnum window
  1746. /// - set npcid of inputnum window
  1747. /// When 'ok' is pressed:
  1748. /// - if inputnum window has text:
  1749. /// - if npcid exists in the client:
  1750. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1751. /// - close inputnum window
  1752. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1753. {
  1754. int fd;
  1755. struct block_list *bl = NULL;
  1756. nullpo_retv(sd);
  1757. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1758. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1759. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1760. clif_sendfakenpc(sd, npcid);
  1761. fd=sd->fd;
  1762. WFIFOHEAD(fd, packet_len(0x142));
  1763. WFIFOW(fd,0)=0x142;
  1764. WFIFOL(fd,2)=npcid;
  1765. WFIFOSET(fd,packet_len(0x142));
  1766. }
  1767. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1768. /// 01d4 <npc id>.L
  1769. /// Client behavior (inputstr window):
  1770. /// - if npcid is 0 or npcid exists in the client:
  1771. /// - open the inputstr window
  1772. /// - set npcid of inputstr window
  1773. /// When 'ok' is pressed:
  1774. /// - if inputstr window has text and isn't an insult(manner.txt):
  1775. /// - if npcid is 0 or npcid exists in the client:
  1776. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1777. /// - close inputstr window
  1778. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1779. {
  1780. int fd;
  1781. struct block_list *bl = NULL;
  1782. nullpo_retv(sd);
  1783. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1784. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1785. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1786. clif_sendfakenpc(sd, npcid);
  1787. fd=sd->fd;
  1788. WFIFOHEAD(fd, packet_len(0x1d4));
  1789. WFIFOW(fd,0)=0x1d4;
  1790. WFIFOL(fd,2)=npcid;
  1791. WFIFOSET(fd,packet_len(0x1d4));
  1792. }
  1793. /// Marks a position on client's minimap (ZC_COMPASS).
  1794. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1795. /// npc id:
  1796. /// is ignored in the client
  1797. /// type:
  1798. /// 0 = display mark for 15 seconds
  1799. /// 1 = display mark until dead or teleported
  1800. /// 2 = remove mark
  1801. /// color:
  1802. /// 0x00RRGGBB
  1803. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1804. {
  1805. int fd;
  1806. nullpo_retv(sd);
  1807. fd=sd->fd;
  1808. WFIFOHEAD(fd, packet_len(0x144));
  1809. WFIFOW(fd,0)=0x144;
  1810. WFIFOL(fd,2)=npc_id;
  1811. WFIFOL(fd,6)=type;
  1812. WFIFOL(fd,10)=x;
  1813. WFIFOL(fd,14)=y;
  1814. WFIFOB(fd,18)=id;
  1815. WFIFOL(fd,19)=color;
  1816. WFIFOSET(fd,packet_len(0x144));
  1817. }
  1818. /// Displays an illustration image.
  1819. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1820. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1821. /// type:
  1822. /// 0 = bottom left corner
  1823. /// 1 = bottom middle
  1824. /// 2 = bottom right corner
  1825. /// 3 = middle of screen, inside a movable window
  1826. /// 4 = middle of screen, movable with a close button, chrome-less
  1827. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1828. {
  1829. int fd;
  1830. nullpo_retv(sd);
  1831. fd=sd->fd;
  1832. WFIFOHEAD(fd, packet_len(0x1b3));
  1833. WFIFOW(fd,0)=0x1b3;
  1834. strncpy((char*)WFIFOP(fd,2),image,64);
  1835. WFIFOB(fd,66)=type;
  1836. WFIFOSET(fd,packet_len(0x1b3));
  1837. }
  1838. /*==========================================
  1839. * Fills in card data from the given item and into the buffer. [Skotlex]
  1840. *------------------------------------------*/
  1841. static void clif_addcards(unsigned char* buf, struct item* item)
  1842. {
  1843. int i=0,j;
  1844. if( item == NULL ) { //Blank data
  1845. WBUFW(buf,0) = 0;
  1846. WBUFW(buf,2) = 0;
  1847. WBUFW(buf,4) = 0;
  1848. WBUFW(buf,6) = 0;
  1849. return;
  1850. }
  1851. if( item->card[0] == CARD0_PET ) { //pet eggs
  1852. WBUFW(buf,0) = 0;
  1853. WBUFW(buf,2) = 0;
  1854. WBUFW(buf,4) = 0;
  1855. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1856. return;
  1857. }
  1858. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1859. WBUFW(buf,0) = item->card[0];
  1860. WBUFW(buf,2) = item->card[1];
  1861. WBUFW(buf,4) = item->card[2];
  1862. WBUFW(buf,6) = item->card[3];
  1863. return;
  1864. }
  1865. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1866. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1867. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1868. //Normal items.
  1869. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1870. WBUFW(buf,0) = j;
  1871. else
  1872. WBUFW(buf,0) = item->card[i];
  1873. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1874. WBUFW(buf,2) = j;
  1875. else
  1876. WBUFW(buf,2) = item->card[i];
  1877. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1878. WBUFW(buf,4) = j;
  1879. else
  1880. WBUFW(buf,4) = item->card[i];
  1881. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1882. WBUFW(buf,6) = j;
  1883. else
  1884. WBUFW(buf,6) = item->card[i];
  1885. }
  1886. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1887. /// 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)
  1888. /// 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)
  1889. /// 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)
  1890. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1891. {
  1892. int fd;
  1893. #if PACKETVER < 20061218
  1894. const int cmd = 0xa0;
  1895. #elif PACKETVER < 20071002
  1896. const int cmd = 0x29a;
  1897. #else
  1898. const int cmd = 0x2d4;
  1899. #endif
  1900. nullpo_retv(sd);
  1901. fd = sd->fd;
  1902. if( !session_isActive(fd) ) //Sasuke-
  1903. return;
  1904. WFIFOHEAD(fd,packet_len(cmd));
  1905. if( fail )
  1906. {
  1907. WFIFOW(fd,0)=cmd;
  1908. WFIFOW(fd,2)=n+2;
  1909. WFIFOW(fd,4)=amount;
  1910. WFIFOW(fd,6)=0;
  1911. WFIFOB(fd,8)=0;
  1912. WFIFOB(fd,9)=0;
  1913. WFIFOB(fd,10)=0;
  1914. WFIFOW(fd,11)=0;
  1915. WFIFOW(fd,13)=0;
  1916. WFIFOW(fd,15)=0;
  1917. WFIFOW(fd,17)=0;
  1918. WFIFOW(fd,19)=0;
  1919. WFIFOB(fd,21)=0;
  1920. WFIFOB(fd,22)=fail;
  1921. #if PACKETVER >= 20061218
  1922. WFIFOL(fd,23)=0;
  1923. #endif
  1924. #if PACKETVER >= 20071002
  1925. WFIFOW(fd,27)=0; // unknown
  1926. #endif
  1927. }
  1928. else
  1929. {
  1930. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1931. return;
  1932. WFIFOW(fd,0)=cmd;
  1933. WFIFOW(fd,2)=n+2;
  1934. WFIFOW(fd,4)=amount;
  1935. if (sd->inventory_data[n]->view_id > 0)
  1936. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1937. else
  1938. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1939. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1940. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1941. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1942. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1943. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1944. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1945. WFIFOB(fd,22)=fail;
  1946. #if PACKETVER >= 20061218
  1947. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1948. #endif
  1949. #if PACKETVER >= 20071002
  1950. WFIFOW(fd,27)=0; // unknown
  1951. #endif
  1952. }
  1953. WFIFOSET(fd,packet_len(cmd));
  1954. }
  1955. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1956. /// 00af <index>.W <amount>.W
  1957. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1958. {
  1959. int fd;
  1960. nullpo_retv(sd);
  1961. fd=sd->fd;
  1962. WFIFOHEAD(fd, packet_len(0xaf));
  1963. WFIFOW(fd,0)=0xaf;
  1964. WFIFOW(fd,2)=n+2;
  1965. WFIFOW(fd,4)=amount;
  1966. WFIFOSET(fd,packet_len(0xaf));
  1967. }
  1968. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1969. /// 07fa <delete type>.W <index>.W <amount>.W
  1970. /// delete type:
  1971. /// 0 = Normal
  1972. /// 1 = Item used for a skill
  1973. /// 2 = Refine failed
  1974. /// 3 = Material changed
  1975. /// 4 = Moved to storage
  1976. /// 5 = Moved to cart
  1977. /// 6 = Item sold
  1978. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1979. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1980. {
  1981. #if PACKETVER < 20091117
  1982. clif_dropitem(sd,n,amount);
  1983. #else
  1984. int fd;
  1985. nullpo_retv(sd);
  1986. fd=sd->fd;
  1987. WFIFOHEAD(fd, packet_len(0x7fa));
  1988. WFIFOW(fd,0)=0x7fa;
  1989. WFIFOW(fd,2)=reason;
  1990. WFIFOW(fd,4)=n+2;
  1991. WFIFOW(fd,6)=amount;
  1992. WFIFOSET(fd,packet_len(0x7fa));
  1993. #endif
  1994. }
  1995. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1996. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1997. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1998. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1999. {
  2000. if (id->view_id > 0)
  2001. WBUFW(buf,n)=id->view_id;
  2002. else
  2003. WBUFW(buf,n)=i->nameid;
  2004. WBUFB(buf,n+2)=itemtype(id->type);
  2005. WBUFB(buf,n+3)=i->identify;
  2006. if (equip >= 0) { //Equippable item
  2007. WBUFW(buf,n+4)=equip;
  2008. WBUFW(buf,n+6)=i->equip;
  2009. WBUFB(buf,n+8)=i->attribute;
  2010. WBUFB(buf,n+9)=i->refine;
  2011. } else { //Stackable item.
  2012. WBUFW(buf,n+4)=i->amount;
  2013. if (equip == -2 && id->equip == EQP_AMMO)
  2014. WBUFW(buf,n+6)=EQP_AMMO;
  2015. else
  2016. WBUFW(buf,n+6)=0;
  2017. }
  2018. }
  2019. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2020. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2021. void clif_inventorylist(struct map_session_data *sd)
  2022. {
  2023. int i,n,ne,arrow=-1;
  2024. unsigned char *buf;
  2025. unsigned char *bufe;
  2026. #if PACKETVER < 5
  2027. const int s = 10; //Entry size.
  2028. #elif PACKETVER < 20080102
  2029. const int s = 18;
  2030. #else
  2031. const int s = 22;
  2032. #endif
  2033. #if PACKETVER < 20071002
  2034. const int se = 20;
  2035. #elif PACKETVER < 20100629
  2036. const int se = 26;
  2037. #else
  2038. const int se = 28;
  2039. #endif
  2040. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2041. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2042. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2043. {
  2044. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2045. continue;
  2046. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2047. { //Non-stackable (Equippable)
  2048. WBUFW(bufe,ne*se+4)=i+2;
  2049. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2050. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  2051. #if PACKETVER >= 20071002
  2052. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  2053. WBUFW(bufe,ne*se+28)=0; //Unknown
  2054. #endif
  2055. #if PACKETVER >= 20100629
  2056. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2057. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  2058. else
  2059. WBUFW(bufe,ne*se+30)=0;
  2060. #endif
  2061. ne++;
  2062. }
  2063. else
  2064. { //Stackable.
  2065. WBUFW(buf,n*s+4)=i+2;
  2066. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2067. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2068. arrow=i;
  2069. #if PACKETVER >= 5
  2070. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2071. #endif
  2072. #if PACKETVER >= 20080102
  2073. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  2074. #endif
  2075. n++;
  2076. }
  2077. }
  2078. if( n )
  2079. {
  2080. #if PACKETVER < 5
  2081. WBUFW(buf,0)=0xa3;
  2082. #elif PACKETVER < 20080102
  2083. WBUFW(buf,0)=0x1ee;
  2084. #else
  2085. WBUFW(buf,0)=0x2e8;
  2086. #endif
  2087. WBUFW(buf,2)=4+n*s;
  2088. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2089. }
  2090. if( arrow >= 0 )
  2091. clif_arrowequip(sd,arrow);
  2092. if( ne )
  2093. {
  2094. #if PACKETVER < 20071002
  2095. WBUFW(bufe,0)=0xa4;
  2096. #else
  2097. WBUFW(bufe,0)=0x2d0;
  2098. #endif
  2099. WBUFW(bufe,2)=4+ne*se;
  2100. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2101. }
  2102. #if PACKETVER >= 20111122
  2103. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2104. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2105. continue;
  2106. if ( sd->status.inventory[i].favorite )
  2107. clif_favorite_item(sd, i);
  2108. }
  2109. #endif
  2110. if( buf ) aFree(buf);
  2111. if( bufe ) aFree(bufe);
  2112. }
  2113. //Required when items break/get-repaired. Only sends equippable item list.
  2114. void clif_equiplist(struct map_session_data *sd)
  2115. {
  2116. int i,n,fd = sd->fd;
  2117. unsigned char *buf;
  2118. #if PACKETVER < 20071002
  2119. const int cmd = 20;
  2120. #elif PACKETVER < 20100629
  2121. const int cmd = 26;
  2122. #else
  2123. const int cmd = 28;
  2124. #endif
  2125. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2126. buf = WFIFOP(fd,0);
  2127. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2128. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2129. continue;
  2130. if(itemdb_isstackable2(sd->inventory_data[i]))
  2131. continue;
  2132. //Equippable
  2133. WBUFW(buf,n*cmd+4)=i+2;
  2134. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2135. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  2136. #if PACKETVER >= 20071002
  2137. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  2138. WBUFW(buf,n*cmd+28)=0; //Unknown
  2139. #endif
  2140. #if PACKETVER >= 20100629
  2141. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2142. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  2143. else
  2144. WBUFW(buf,n*cmd+30)=0;
  2145. #endif
  2146. n++;
  2147. }
  2148. if (n) {
  2149. #if PACKETVER < 20071002
  2150. WBUFW(buf,0)=0xa4;
  2151. #else
  2152. WBUFW(buf,0)=0x2d0;
  2153. #endif
  2154. WBUFW(buf,2)=4+n*cmd;
  2155. WFIFOSET(fd,WFIFOW(fd,2));
  2156. }
  2157. }
  2158. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2159. {
  2160. struct item_data *id;
  2161. int i,n,ne;
  2162. unsigned char *buf;
  2163. unsigned char *bufe;
  2164. #if PACKETVER < 5
  2165. const int s = 10; //Entry size.
  2166. #elif PACKETVER < 20080102
  2167. const int s = 18;
  2168. #else
  2169. const int s = 22;
  2170. #endif
  2171. #if PACKETVER < 20071002
  2172. const int cmd = 20;
  2173. #elif PACKETVER < 20100629
  2174. const int cmd = 26;
  2175. #else
  2176. const int cmd = 28;
  2177. #endif
  2178. buf = (unsigned char*)aMalloc(items_length * s + 4);
  2179. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  2180. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2181. {
  2182. if( items[i].nameid <= 0 )
  2183. continue;
  2184. id = itemdb_search(items[i].nameid);
  2185. if( !itemdb_isstackable2(id) )
  2186. { //Equippable
  2187. WBUFW(bufe,ne*cmd+4)=i+1;
  2188. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2189. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2190. #if PACKETVER >= 20071002
  2191. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2192. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2193. #endif
  2194. ne++;
  2195. }
  2196. else
  2197. { //Stackable
  2198. WBUFW(buf,n*s+4)=i+1;
  2199. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2200. #if PACKETVER >= 5
  2201. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2202. #endif
  2203. #if PACKETVER >= 20080102
  2204. WBUFL(buf,n*s+22)=items[i].expire_time;
  2205. #endif
  2206. n++;
  2207. }
  2208. }
  2209. if( n )
  2210. {
  2211. #if PACKETVER < 5
  2212. WBUFW(buf,0)=0xa5;
  2213. #elif PACKETVER < 20080102
  2214. WBUFW(buf,0)=0x1f0;
  2215. #else
  2216. WBUFW(buf,0)=0x2ea;
  2217. #endif
  2218. WBUFW(buf,2)=4+n*s;
  2219. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2220. }
  2221. if( ne )
  2222. {
  2223. #if PACKETVER < 20071002
  2224. WBUFW(bufe,0)=0xa6;
  2225. #else
  2226. WBUFW(bufe,0)=0x2d1;
  2227. #endif
  2228. WBUFW(bufe,2)=4+ne*cmd;
  2229. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2230. }
  2231. if( buf ) aFree(buf);
  2232. if( bufe ) aFree(bufe);
  2233. }
  2234. void clif_cartlist(struct map_session_data *sd)
  2235. {
  2236. struct item_data *id;
  2237. int i,n,ne;
  2238. unsigned char *buf;
  2239. unsigned char *bufe;
  2240. #if PACKETVER < 5
  2241. const int s = 10; //Entry size.
  2242. #elif PACKETVER < 20080102
  2243. const int s = 18;
  2244. #else
  2245. const int s = 22;
  2246. #endif
  2247. #if PACKETVER < 20071002
  2248. const int cmd = 20;
  2249. #elif PACKETVER < 20100629
  2250. const int cmd = 26;
  2251. #else
  2252. const int cmd = 28;
  2253. #endif
  2254. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2255. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2256. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2257. {
  2258. if( sd->status.cart[i].nameid <= 0 )
  2259. continue;
  2260. id = itemdb_search(sd->status.cart[i].nameid);
  2261. if( !itemdb_isstackable2(id) )
  2262. { //Equippable
  2263. WBUFW(bufe,ne*cmd+4)=i+2;
  2264. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2265. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2266. #if PACKETVER >= 20071002
  2267. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2268. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2269. #endif
  2270. ne++;
  2271. }
  2272. else
  2273. { //Stackable
  2274. WBUFW(buf,n*s+4)=i+2;
  2275. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2276. #if PACKETVER >= 5
  2277. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2278. #endif
  2279. #if PACKETVER >= 20080102
  2280. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2281. #endif
  2282. n++;
  2283. }
  2284. }
  2285. if( n )
  2286. {
  2287. #if PACKETVER < 5
  2288. WBUFW(buf,0)=0x123;
  2289. #elif PACKETVER < 20080102
  2290. WBUFW(buf,0)=0x1ef;
  2291. #else
  2292. WBUFW(buf,0)=0x2e9;
  2293. #endif
  2294. WBUFW(buf,2)=4+n*s;
  2295. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2296. }
  2297. if( ne )
  2298. {
  2299. #if PACKETVER < 20071002
  2300. WBUFW(bufe,0)=0x122;
  2301. #else
  2302. WBUFW(bufe,0)=0x2d2;
  2303. #endif
  2304. WBUFW(bufe,2)=4+ne*cmd;
  2305. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2306. }
  2307. if( buf ) aFree(buf);
  2308. if( bufe ) aFree(bufe);
  2309. }
  2310. /// Removes cart (ZC_CARTOFF).
  2311. /// 012b
  2312. /// Client behaviour:
  2313. /// Closes the cart storage and removes all it's items from memory.
  2314. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2315. void clif_clearcart(int fd)
  2316. {
  2317. WFIFOHEAD(fd, packet_len(0x12b));
  2318. WFIFOW(fd,0) = 0x12b;
  2319. WFIFOSET(fd, packet_len(0x12b));
  2320. }
  2321. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2322. /// 01eb <account id>.L <x>.W <y>.W
  2323. void clif_guild_xy(struct map_session_data *sd)
  2324. {
  2325. unsigned char buf[10];
  2326. nullpo_retv(sd);
  2327. WBUFW(buf,0)=0x1eb;
  2328. WBUFL(buf,2)=sd->status.account_id;
  2329. WBUFW(buf,6)=sd->bl.x;
  2330. WBUFW(buf,8)=sd->bl.y;
  2331. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2332. }
  2333. /*==========================================
  2334. * Sends x/y dot to a single fd. [Skotlex]
  2335. *------------------------------------------*/
  2336. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2337. {
  2338. if( sd->bg_id )
  2339. return;
  2340. WFIFOHEAD(fd,packet_len(0x1eb));
  2341. WFIFOW(fd,0)=0x1eb;
  2342. WFIFOL(fd,2)=sd->status.account_id;
  2343. WFIFOW(fd,6)=sd->bl.x;
  2344. WFIFOW(fd,8)=sd->bl.y;
  2345. WFIFOSET(fd,packet_len(0x1eb));
  2346. }
  2347. // Guild XY locators [Valaris]
  2348. void clif_guild_xy_remove(struct map_session_data *sd)
  2349. {
  2350. unsigned char buf[10];
  2351. nullpo_retv(sd);
  2352. WBUFW(buf,0)=0x1eb;
  2353. WBUFL(buf,2)=sd->status.account_id;
  2354. WBUFW(buf,6)=-1;
  2355. WBUFW(buf,8)=-1;
  2356. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2357. }
  2358. /*==========================================
  2359. *
  2360. *------------------------------------------*/
  2361. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2362. {
  2363. struct map_session_data *sd, *tsd;
  2364. #if PACKETVER < 20100126
  2365. const int cmd = 0x106;
  2366. #else
  2367. const int cmd = 0x80e;
  2368. #endif
  2369. sd = va_arg(ap, struct map_session_data *);
  2370. tsd = (TBL_PC *)bl;
  2371. nullpo_ret(sd);
  2372. nullpo_ret(tsd);
  2373. if( !tsd->fd || tsd == sd )
  2374. return 0;
  2375. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2376. return 0;
  2377. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2378. WFIFOW(tsd->fd,0) = cmd;
  2379. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2380. #if PACKETVER < 20100126
  2381. if( sd->battle_status.max_hp > INT16_MAX )
  2382. { //To correctly display the %hp bar. [Skotlex]
  2383. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2384. WFIFOW(tsd->fd,8) = 100;
  2385. } else {
  2386. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2387. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2388. }
  2389. #else
  2390. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2391. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2392. #endif
  2393. WFIFOSET(tsd->fd,packet_len(cmd));
  2394. return 0;
  2395. }
  2396. /*==========================================
  2397. * Server tells all players that are allowed to view HP bars
  2398. * and are nearby 'sd' that 'sd' hp bar was updated.
  2399. *------------------------------------------*/
  2400. static int clif_hpmeter(struct map_session_data *sd)
  2401. {
  2402. nullpo_ret(sd);
  2403. 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);
  2404. return 0;
  2405. }
  2406. /// Notifies client of a character parameter change.
  2407. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2408. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2409. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2410. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2411. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2412. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2413. /// TODO: Extract individual packets.
  2414. /// FIXME: Packet lengths from packet_len(cmd)
  2415. void clif_updatestatus(struct map_session_data *sd,int type)
  2416. {
  2417. int fd,len=8;
  2418. nullpo_retv(sd);
  2419. fd=sd->fd;
  2420. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2421. return;
  2422. WFIFOHEAD(fd, 14);
  2423. WFIFOW(fd,0)=0xb0;
  2424. WFIFOW(fd,2)=type;
  2425. switch(type){
  2426. // 00b0
  2427. case SP_WEIGHT:
  2428. pc_updateweightstatus(sd);
  2429. WFIFOHEAD(fd,14);
  2430. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2431. WFIFOW(fd,2)=type;
  2432. WFIFOL(fd,4)=sd->weight;
  2433. break;
  2434. case SP_MAXWEIGHT:
  2435. WFIFOL(fd,4)=sd->max_weight;
  2436. break;
  2437. case SP_SPEED:
  2438. WFIFOL(fd,4)=sd->battle_status.speed;
  2439. break;
  2440. case SP_BASELEVEL:
  2441. WFIFOL(fd,4)=sd->status.base_level;
  2442. break;
  2443. case SP_JOBLEVEL:
  2444. WFIFOL(fd,4)=sd->status.job_level;
  2445. break;
  2446. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2447. WFIFOL(fd,4)=sd->status.karma;
  2448. break;
  2449. case SP_MANNER:
  2450. WFIFOL(fd,4)=sd->status.manner;
  2451. break;
  2452. case SP_STATUSPOINT:
  2453. WFIFOL(fd,4)=sd->status.status_point;
  2454. break;
  2455. case SP_SKILLPOINT:
  2456. WFIFOL(fd,4)=sd->status.skill_point;
  2457. break;
  2458. case SP_HIT:
  2459. WFIFOL(fd,4)=sd->battle_status.hit;
  2460. break;
  2461. case SP_FLEE1:
  2462. WFIFOL(fd,4)=sd->battle_status.flee;
  2463. break;
  2464. case SP_FLEE2:
  2465. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2466. break;
  2467. case SP_MAXHP:
  2468. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2469. break;
  2470. case SP_MAXSP:
  2471. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2472. break;
  2473. case SP_HP:
  2474. WFIFOL(fd,4)=sd->battle_status.hp;
  2475. // TODO: Won't these overwrite the current packet?
  2476. clif_hpmeter(sd);
  2477. if( !battle_config.party_hp_mode && sd->status.party_id )
  2478. clif_party_hp(sd);
  2479. if( sd->bg_id )
  2480. clif_bg_hp(sd);
  2481. break;
  2482. case SP_SP:
  2483. WFIFOL(fd,4)=sd->battle_status.sp;
  2484. break;
  2485. case SP_ASPD:
  2486. WFIFOL(fd,4)=sd->battle_status.amotion;
  2487. break;
  2488. case SP_ATK1:
  2489. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2490. break;
  2491. case SP_DEF1:
  2492. WFIFOL(fd,4)=pc_leftside_def(sd);
  2493. break;
  2494. case SP_MDEF1:
  2495. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2496. break;
  2497. case SP_ATK2:
  2498. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2499. break;
  2500. case SP_DEF2:
  2501. WFIFOL(fd,4)=pc_rightside_def(sd);
  2502. break;
  2503. case SP_MDEF2: {
  2504. //negative check (in case you have something like Berserk active)
  2505. int mdef2 = pc_rightside_mdef(sd);
  2506. WFIFOL(fd,4)=
  2507. #ifndef RENEWAL
  2508. ( mdef2 < 0 ) ? 0 :
  2509. #endif
  2510. mdef2;
  2511. }
  2512. break;
  2513. case SP_CRITICAL:
  2514. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2515. break;
  2516. case SP_MATK1:
  2517. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2518. break;
  2519. case SP_MATK2:
  2520. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2521. break;
  2522. case SP_ZENY:
  2523. WFIFOW(fd,0)=0xb1;
  2524. WFIFOL(fd,4)=sd->status.zeny;
  2525. break;
  2526. case SP_BASEEXP:
  2527. WFIFOW(fd,0)=0xb1;
  2528. WFIFOL(fd,4)=sd->status.base_exp;
  2529. break;
  2530. case SP_JOBEXP:
  2531. WFIFOW(fd,0)=0xb1;
  2532. WFIFOL(fd,4)=sd->status.job_exp;
  2533. break;
  2534. case SP_NEXTBASEEXP:
  2535. WFIFOW(fd,0)=0xb1;
  2536. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2537. break;
  2538. case SP_NEXTJOBEXP:
  2539. WFIFOW(fd,0)=0xb1;
  2540. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2541. break;
  2542. /**
  2543. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2544. **/
  2545. case SP_USTR:
  2546. case SP_UAGI:
  2547. case SP_UVIT:
  2548. case SP_UINT:
  2549. case SP_UDEX:
  2550. case SP_ULUK:
  2551. WFIFOW(fd,0)=0xbe;
  2552. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2553. len=5;
  2554. break;
  2555. /**
  2556. * Tells the client how far it is allowed to attack (weapon range)
  2557. **/
  2558. case SP_ATTACKRANGE:
  2559. WFIFOW(fd,0)=0x13a;
  2560. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2561. len=4;
  2562. break;
  2563. case SP_STR:
  2564. WFIFOW(fd,0)=0x141;
  2565. WFIFOL(fd,2)=type;
  2566. WFIFOL(fd,6)=sd->status.str;
  2567. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2568. len=14;
  2569. break;
  2570. case SP_AGI:
  2571. WFIFOW(fd,0)=0x141;
  2572. WFIFOL(fd,2)=type;
  2573. WFIFOL(fd,6)=sd->status.agi;
  2574. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2575. len=14;
  2576. break;
  2577. case SP_VIT:
  2578. WFIFOW(fd,0)=0x141;
  2579. WFIFOL(fd,2)=type;
  2580. WFIFOL(fd,6)=sd->status.vit;
  2581. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2582. len=14;
  2583. break;
  2584. case SP_INT:
  2585. WFIFOW(fd,0)=0x141;
  2586. WFIFOL(fd,2)=type;
  2587. WFIFOL(fd,6)=sd->status.int_;
  2588. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2589. len=14;
  2590. break;
  2591. case SP_DEX:
  2592. WFIFOW(fd,0)=0x141;
  2593. WFIFOL(fd,2)=type;
  2594. WFIFOL(fd,6)=sd->status.dex;
  2595. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2596. len=14;
  2597. break;
  2598. case SP_LUK:
  2599. WFIFOW(fd,0)=0x141;
  2600. WFIFOL(fd,2)=type;
  2601. WFIFOL(fd,6)=sd->status.luk;
  2602. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2603. len=14;
  2604. break;
  2605. case SP_CARTINFO:
  2606. WFIFOW(fd,0)=0x121;
  2607. WFIFOW(fd,2)=sd->cart_num;
  2608. WFIFOW(fd,4)=MAX_CART;
  2609. WFIFOL(fd,6)=sd->cart_weight;
  2610. WFIFOL(fd,10)=sd->cart_weight_max;
  2611. len=14;
  2612. break;
  2613. default:
  2614. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2615. return;
  2616. }
  2617. WFIFOSET(fd,len);
  2618. }
  2619. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2620. /// 01ab <account id>.L <var id>.W <value>.L
  2621. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2622. {
  2623. unsigned char buf[12];
  2624. nullpo_retv(sd);
  2625. WBUFW(buf,0)=0x1ab;
  2626. WBUFL(buf,2)=sd->bl.id;
  2627. WBUFW(buf,6)=type;
  2628. switch(type)
  2629. {
  2630. case SP_MANNER:
  2631. WBUFL(buf,8)=val;
  2632. break;
  2633. default:
  2634. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2635. return;
  2636. }
  2637. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2638. }
  2639. /// Updates sprite/style properties of an object.
  2640. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2641. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2642. void clif_changelook(struct block_list *bl,int type,int val)
  2643. {
  2644. unsigned char buf[16];
  2645. struct map_session_data* sd = NULL;
  2646. struct status_change* sc;
  2647. struct view_data* vd;
  2648. enum send_target target = AREA;
  2649. nullpo_retv(bl);
  2650. sd = BL_CAST(BL_PC, bl);
  2651. sc = status_get_sc(bl);
  2652. vd = status_get_viewdata(bl);
  2653. //nullpo_ret(vd);
  2654. if( vd ) //temp hack to let Warp Portal change appearance
  2655. switch(type)
  2656. {
  2657. case LOOK_WEAPON:
  2658. if (sd)
  2659. {
  2660. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2661. val = vd->weapon;
  2662. }
  2663. else vd->weapon = val;
  2664. break;
  2665. case LOOK_SHIELD:
  2666. if (sd)
  2667. {
  2668. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2669. val = vd->shield;
  2670. }
  2671. else vd->shield = val;
  2672. break;
  2673. case LOOK_BASE:
  2674. vd->class_ = val;
  2675. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2676. vd->weapon = vd->shield = 0;
  2677. if (vd->cloth_color && (
  2678. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2679. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2680. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2681. ))
  2682. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2683. break;
  2684. case LOOK_HAIR:
  2685. vd->hair_style = val;
  2686. break;
  2687. case LOOK_HEAD_BOTTOM:
  2688. vd->head_bottom = val;
  2689. break;
  2690. case LOOK_HEAD_TOP:
  2691. vd->head_top = val;
  2692. break;
  2693. case LOOK_HEAD_MID:
  2694. vd->head_mid = val;
  2695. break;
  2696. case LOOK_HAIR_COLOR:
  2697. vd->hair_color = val;
  2698. break;
  2699. case LOOK_CLOTHES_COLOR:
  2700. if (val && (
  2701. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2702. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2703. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2704. ))
  2705. val = 0;
  2706. vd->cloth_color = val;
  2707. break;
  2708. case LOOK_SHOES:
  2709. #if PACKETVER > 3
  2710. if (sd) {
  2711. int n;
  2712. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2713. if(sd->inventory_data[n]->view_id > 0)
  2714. val = sd->inventory_data[n]->view_id;
  2715. else
  2716. val = sd->status.inventory[n].nameid;
  2717. } else
  2718. val = 0;
  2719. }
  2720. #endif
  2721. //Shoes? No packet uses this....
  2722. break;
  2723. case LOOK_BODY:
  2724. case LOOK_FLOOR:
  2725. // unknown purpose
  2726. break;
  2727. case LOOK_ROBE:
  2728. #if PACKETVER < 20110111
  2729. return;
  2730. #else
  2731. vd->robe = val;
  2732. #endif
  2733. break;
  2734. }
  2735. // prevent leaking the presence of GM-hidden objects
  2736. if( sc && sc->option&OPTION_INVISIBLE )
  2737. target = SELF;
  2738. #if PACKETVER < 4
  2739. WBUFW(buf,0)=0xc3;
  2740. WBUFL(buf,2)=bl->id;
  2741. WBUFB(buf,6)=type;
  2742. WBUFB(buf,7)=val;
  2743. clif_send(buf,packet_len(0xc3),bl,target);
  2744. #else
  2745. WBUFW(buf,0)=0x1d7;
  2746. WBUFL(buf,2)=bl->id;
  2747. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2748. WBUFB(buf,6)=LOOK_WEAPON;
  2749. WBUFW(buf,7)=vd->weapon;
  2750. WBUFW(buf,9)=vd->shield;
  2751. } else {
  2752. WBUFB(buf,6)=type;
  2753. WBUFL(buf,7)=val;
  2754. }
  2755. clif_send(buf,packet_len(0x1d7),bl,target);
  2756. #endif
  2757. }
  2758. //Sends a change-base-look packet required for traps as they are triggered.
  2759. void clif_changetraplook(struct block_list *bl,int val)
  2760. {
  2761. unsigned char buf[32];
  2762. #if PACKETVER < 4
  2763. WBUFW(buf,0)=0xc3;
  2764. WBUFL(buf,2)=bl->id;
  2765. WBUFB(buf,6)=LOOK_BASE;
  2766. WBUFB(buf,7)=val;
  2767. clif_send(buf,packet_len(0xc3),bl,AREA);
  2768. #else
  2769. WBUFW(buf,0)=0x1d7;
  2770. WBUFL(buf,2)=bl->id;
  2771. WBUFB(buf,6)=LOOK_BASE;
  2772. WBUFW(buf,7)=val;
  2773. WBUFW(buf,9)=0;
  2774. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2775. #endif
  2776. }
  2777. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2778. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2779. {
  2780. unsigned char buf[32];
  2781. #if PACKETVER < 4
  2782. WBUFW(buf,0)=0xc3;
  2783. WBUFL(buf,2)=id;
  2784. WBUFB(buf,6)=type;
  2785. WBUFB(buf,7)=val;
  2786. clif_send(buf,packet_len(0xc3),bl,target);
  2787. #else
  2788. WBUFW(buf,0)=0x1d7;
  2789. WBUFL(buf,2)=id;
  2790. WBUFB(buf,6)=type;
  2791. WBUFW(buf,7)=val;
  2792. WBUFW(buf,9)=0;
  2793. clif_send(buf,packet_len(0x1d7),bl,target);
  2794. #endif
  2795. }
  2796. /// Character status (ZC_STATUS).
  2797. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2798. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2799. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2800. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2801. void clif_initialstatus(struct map_session_data *sd)
  2802. {
  2803. int fd, mdef2;
  2804. unsigned char *buf;
  2805. nullpo_retv(sd);
  2806. fd=sd->fd;
  2807. WFIFOHEAD(fd,packet_len(0xbd));
  2808. buf=WFIFOP(fd,0);
  2809. WBUFW(buf,0)=0xbd;
  2810. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2811. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2812. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2813. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2814. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2815. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2816. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2817. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2818. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2819. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2820. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2821. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2822. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2823. WBUFW(buf,16) = pc_leftside_atk(sd);
  2824. WBUFW(buf,18) = pc_rightside_atk(sd);
  2825. WBUFW(buf,20) = pc_rightside_matk(sd);
  2826. WBUFW(buf,22) = pc_leftside_matk(sd);
  2827. WBUFW(buf,24) = pc_leftside_def(sd);
  2828. WBUFW(buf,26) = pc_rightside_def(sd);
  2829. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2830. mdef2 = pc_rightside_mdef(sd);
  2831. WBUFW(buf,30) =
  2832. #ifndef RENEWAL
  2833. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2834. #endif
  2835. mdef2;
  2836. WBUFW(buf,32) = sd->battle_status.hit;
  2837. WBUFW(buf,34) = sd->battle_status.flee;
  2838. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2839. WBUFW(buf,38) = sd->battle_status.cri/10;
  2840. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2841. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2842. WFIFOSET(fd,packet_len(0xbd));
  2843. clif_updatestatus(sd,SP_STR);
  2844. clif_updatestatus(sd,SP_AGI);
  2845. clif_updatestatus(sd,SP_VIT);
  2846. clif_updatestatus(sd,SP_INT);
  2847. clif_updatestatus(sd,SP_DEX);
  2848. clif_updatestatus(sd,SP_LUK);
  2849. clif_updatestatus(sd,SP_ATTACKRANGE);
  2850. clif_updatestatus(sd,SP_ASPD);
  2851. }
  2852. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2853. /// 013c <index>.W
  2854. void clif_arrowequip(struct map_session_data *sd,int val)
  2855. {
  2856. int fd;
  2857. nullpo_retv(sd);
  2858. pc_stop_attack(sd); // [Valaris]
  2859. fd=sd->fd;
  2860. WFIFOHEAD(fd, packet_len(0x013c));
  2861. WFIFOW(fd,0)=0x013c;
  2862. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2863. WFIFOSET(fd,packet_len(0x013c));
  2864. }
  2865. /// Ammunition action message (ZC_ACTION_FAILURE).
  2866. /// 013b <type>.W
  2867. /// type:
  2868. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2869. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2870. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2871. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2872. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2873. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2874. void clif_arrow_fail(struct map_session_data *sd,int type)
  2875. {
  2876. int fd;
  2877. nullpo_retv(sd);
  2878. fd=sd->fd;
  2879. WFIFOHEAD(fd, packet_len(0x013b));
  2880. WFIFOW(fd,0)=0x013b;
  2881. WFIFOW(fd,2)=type;
  2882. WFIFOSET(fd,packet_len(0x013b));
  2883. }
  2884. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2885. /// 01ad <packet len>.W { <name id>.W }*
  2886. void clif_arrow_create_list(struct map_session_data *sd)
  2887. {
  2888. int i, c, j;
  2889. int fd;
  2890. nullpo_retv(sd);
  2891. fd = sd->fd;
  2892. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2893. WFIFOW(fd,0) = 0x1ad;
  2894. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2895. if (skill_arrow_db[i].nameid > 0 &&
  2896. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2897. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2898. {
  2899. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2900. WFIFOW(fd,c*2+4) = j;
  2901. else
  2902. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2903. c++;
  2904. }
  2905. }
  2906. WFIFOW(fd,2) = c*2+4;
  2907. WFIFOSET(fd, WFIFOW(fd,2));
  2908. if (c > 0) {
  2909. sd->menuskill_id = AC_MAKINGARROW;
  2910. sd->menuskill_val = c;
  2911. }
  2912. }
  2913. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2914. /// 00bc <status id>.W <result>.B <value>.B
  2915. /// status id:
  2916. /// SP_STR ~ SP_LUK
  2917. /// result:
  2918. /// 0 = failure
  2919. /// 1 = success
  2920. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2921. {
  2922. int fd;
  2923. nullpo_retv(sd);
  2924. fd=sd->fd;
  2925. WFIFOHEAD(fd,packet_len(0xbc));
  2926. WFIFOW(fd,0)=0xbc;
  2927. WFIFOW(fd,2)=type;
  2928. WFIFOB(fd,4)=ok;
  2929. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2930. WFIFOSET(fd,packet_len(0xbc));
  2931. }
  2932. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2933. /// 00aa <index>.W <equip location>.W <result>.B
  2934. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2935. /// result:
  2936. /// 0 = failure
  2937. /// 1 = success
  2938. /// 2 = failure due to low level
  2939. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2940. {
  2941. int fd;
  2942. nullpo_retv(sd);
  2943. fd=sd->fd;
  2944. WFIFOHEAD(fd,packet_len(0xaa));
  2945. WFIFOW(fd,0)=0xaa;
  2946. WFIFOW(fd,2)=n+2;
  2947. WFIFOW(fd,4)=pos;
  2948. #if PACKETVER < 20100629
  2949. WFIFOB(fd,6)=ok;
  2950. #else
  2951. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2952. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2953. else
  2954. WFIFOW(fd,6)=0;
  2955. WFIFOB(fd,8)=ok;
  2956. #endif
  2957. WFIFOSET(fd,packet_len(0xaa));
  2958. }
  2959. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2960. /// 00ac <index>.W <equip location>.W <result>.B
  2961. /// result:
  2962. /// 0 = failure
  2963. /// 1 = success
  2964. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2965. {
  2966. int fd;
  2967. nullpo_retv(sd);
  2968. fd=sd->fd;
  2969. WFIFOHEAD(fd,packet_len(0xac));
  2970. WFIFOW(fd,0)=0xac;
  2971. WFIFOW(fd,2)=n+2;
  2972. WFIFOW(fd,4)=pos;
  2973. WFIFOB(fd,6)=ok;
  2974. WFIFOSET(fd,packet_len(0xac));
  2975. }
  2976. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2977. /// 019b <id>.L <effect id>.L
  2978. /// effect id:
  2979. /// 0 = base level up
  2980. /// 1 = job level up
  2981. /// 2 = refine failure
  2982. /// 3 = refine success
  2983. /// 4 = game over
  2984. /// 5 = pharmacy success
  2985. /// 6 = pharmacy failure
  2986. /// 7 = base level up (super novice)
  2987. /// 8 = job level up (super novice)
  2988. /// 9 = base level up (taekwon)
  2989. void clif_misceffect(struct block_list* bl,int type)
  2990. {
  2991. unsigned char buf[32];
  2992. nullpo_retv(bl);
  2993. WBUFW(buf,0) = 0x19b;
  2994. WBUFL(buf,2) = bl->id;
  2995. WBUFL(buf,6) = type;
  2996. clif_send(buf,packet_len(0x19b),bl,AREA);
  2997. }
  2998. /// Notifies clients in the area of a state change.
  2999. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3000. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3001. void clif_changeoption(struct block_list* bl)
  3002. {
  3003. unsigned char buf[32];
  3004. struct status_change *sc;
  3005. struct map_session_data* sd;
  3006. nullpo_retv(bl);
  3007. sc = status_get_sc(bl);
  3008. if (!sc) return; //How can an option change if there's no sc?
  3009. sd = BL_CAST(BL_PC, bl);
  3010. #if PACKETVER >= 7
  3011. WBUFW(buf,0) = 0x229;
  3012. WBUFL(buf,2) = bl->id;
  3013. WBUFW(buf,6) = sc->opt1;
  3014. WBUFW(buf,8) = sc->opt2;
  3015. WBUFL(buf,10) = sc->option;
  3016. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3017. if(disguised(bl)) {
  3018. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3019. WBUFL(buf,2) = -bl->id;
  3020. clif_send(buf,packet_len(0x229),bl,SELF);
  3021. WBUFL(buf,2) = bl->id;
  3022. WBUFL(buf,10) = OPTION_INVISIBLE;
  3023. clif_send(buf,packet_len(0x229),bl,SELF);
  3024. } else
  3025. clif_send(buf,packet_len(0x229),bl,AREA);
  3026. #else
  3027. WBUFW(buf,0) = 0x119;
  3028. WBUFL(buf,2) = bl->id;
  3029. WBUFW(buf,6) = sc->opt1;
  3030. WBUFW(buf,8) = sc->opt2;
  3031. WBUFW(buf,10) = sc->option;
  3032. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3033. if(disguised(bl)) {
  3034. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3035. WBUFL(buf,2) = -bl->id;
  3036. clif_send(buf,packet_len(0x119),bl,SELF);
  3037. WBUFL(buf,2) = bl->id;
  3038. WBUFW(buf,10) = OPTION_INVISIBLE;
  3039. clif_send(buf,packet_len(0x119),bl,SELF);
  3040. } else
  3041. clif_send(buf,packet_len(0x119),bl,AREA);
  3042. #endif
  3043. }
  3044. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3045. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3046. void clif_changeoption2(struct block_list* bl)
  3047. {
  3048. unsigned char buf[20];
  3049. struct status_change *sc;
  3050. sc = status_get_sc(bl);
  3051. if (!sc) return; //How can an option change if there's no sc?
  3052. WBUFW(buf,0) = 0x28a;
  3053. WBUFL(buf,2) = bl->id;
  3054. WBUFL(buf,6) = sc->option;
  3055. WBUFL(buf,10) = clif_setlevel(bl);
  3056. WBUFL(buf,14) = sc->opt3;
  3057. if(disguised(bl)) {
  3058. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3059. WBUFL(buf,2) = -bl->id;
  3060. clif_send(buf,packet_len(0x28a),bl,SELF);
  3061. WBUFL(buf,2) = bl->id;
  3062. WBUFL(buf,6) = OPTION_INVISIBLE;
  3063. clif_send(buf,packet_len(0x28a),bl,SELF);
  3064. } else
  3065. clif_send(buf,packet_len(0x28a),bl,AREA);
  3066. }
  3067. /// Notifies the client about the result of an item use request.
  3068. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3069. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3070. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3071. {
  3072. nullpo_retv(sd);
  3073. if(!ok) {
  3074. int fd=sd->fd;
  3075. WFIFOHEAD(fd,packet_len(0xa8));
  3076. WFIFOW(fd,0)=0xa8;
  3077. WFIFOW(fd,2)=index+2;
  3078. WFIFOW(fd,4)=amount;
  3079. WFIFOB(fd,6)=ok;
  3080. WFIFOSET(fd,packet_len(0xa8));
  3081. }
  3082. else {
  3083. #if PACKETVER < 3
  3084. int fd=sd->fd;
  3085. WFIFOHEAD(fd,packet_len(0xa8));
  3086. WFIFOW(fd,0)=0xa8;
  3087. WFIFOW(fd,2)=index+2;
  3088. WFIFOW(fd,4)=amount;
  3089. WFIFOB(fd,6)=ok;
  3090. WFIFOSET(fd,packet_len(0xa8));
  3091. #else
  3092. unsigned char buf[32];
  3093. WBUFW(buf,0)=0x1c8;
  3094. WBUFW(buf,2)=index+2;
  3095. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3096. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3097. else
  3098. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3099. WBUFL(buf,6)=sd->bl.id;
  3100. WBUFW(buf,10)=amount;
  3101. WBUFB(buf,12)=ok;
  3102. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3103. #endif
  3104. }
  3105. }
  3106. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3107. /// 00d6 <flag>.B
  3108. /// flag:
  3109. /// 0 = Room has been successfully created (opens chat room)
  3110. /// 1 = Room limit exceeded
  3111. /// 2 = Same room already exists
  3112. void clif_createchat(struct map_session_data* sd, int flag)
  3113. {
  3114. int fd;
  3115. nullpo_retv(sd);
  3116. fd = sd->fd;
  3117. WFIFOHEAD(fd,packet_len(0xd6));
  3118. WFIFOW(fd,0) = 0xd6;
  3119. WFIFOB(fd,2) = flag;
  3120. WFIFOSET(fd,packet_len(0xd6));
  3121. }
  3122. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3123. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3124. /// type:
  3125. /// 0 = private (password protected)
  3126. /// 1 = public
  3127. /// 2 = arena (npc waiting room)
  3128. /// 3 = PK zone (non-clickable)
  3129. void clif_dispchat(struct chat_data* cd, int fd)
  3130. {
  3131. unsigned char buf[128];
  3132. uint8 type;
  3133. if( cd == NULL || cd->owner == NULL )
  3134. return;
  3135. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3136. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3137. : 1;
  3138. WBUFW(buf, 0) = 0xd7;
  3139. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3140. WBUFL(buf, 4) = cd->owner->id;
  3141. WBUFL(buf, 8) = cd->bl.id;
  3142. WBUFW(buf,12) = cd->limit;
  3143. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3144. WBUFB(buf,16) = type;
  3145. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3146. if( fd ) {
  3147. WFIFOHEAD(fd,WBUFW(buf,2));
  3148. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3149. WFIFOSET(fd,WBUFW(buf,2));
  3150. } else {
  3151. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3152. }
  3153. }
  3154. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3155. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3156. /// type:
  3157. /// 0 = private (password protected)
  3158. /// 1 = public
  3159. /// 2 = arena (npc waiting room)
  3160. /// 3 = PK zone (non-clickable)
  3161. void clif_changechatstatus(struct chat_data* cd)
  3162. {
  3163. unsigned char buf[128];
  3164. uint8 type;
  3165. if( cd == NULL || cd->usersd[0] == NULL )
  3166. return;
  3167. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3168. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3169. : 1;
  3170. WBUFW(buf, 0) = 0xdf;
  3171. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3172. WBUFL(buf, 4) = cd->owner->id;
  3173. WBUFL(buf, 8) = cd->bl.id;
  3174. WBUFW(buf,12) = cd->limit;
  3175. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3176. WBUFB(buf,16) = type;
  3177. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3178. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3179. }
  3180. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3181. /// 00d8 <chat id>.L
  3182. void clif_clearchat(struct chat_data *cd,int fd)
  3183. {
  3184. unsigned char buf[32];
  3185. nullpo_retv(cd);
  3186. WBUFW(buf,0) = 0xd8;
  3187. WBUFL(buf,2) = cd->bl.id;
  3188. if( fd ) {
  3189. WFIFOHEAD(fd,packet_len(0xd8));
  3190. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3191. WFIFOSET(fd,packet_len(0xd8));
  3192. } else {
  3193. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3194. }
  3195. }
  3196. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3197. /// 00da <result>.B
  3198. /// result:
  3199. /// 0 = room full
  3200. /// 1 = wrong password
  3201. /// 2 = kicked
  3202. /// 3 = success (no message)
  3203. /// 4 = no enough zeny
  3204. /// 5 = too low level
  3205. /// 6 = too high level
  3206. /// 7 = unsuitable job class
  3207. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3208. {
  3209. int fd;
  3210. nullpo_retv(sd);
  3211. fd = sd->fd;
  3212. WFIFOHEAD(fd,packet_len(0xda));
  3213. WFIFOW(fd,0) = 0xda;
  3214. WFIFOB(fd,2) = flag;
  3215. WFIFOSET(fd,packet_len(0xda));
  3216. }
  3217. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3218. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3219. /// role:
  3220. /// 0 = owner (menu)
  3221. /// 1 = normal
  3222. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3223. {
  3224. int fd;
  3225. int i,t;
  3226. nullpo_retv(sd);
  3227. nullpo_retv(cd);
  3228. fd = sd->fd;
  3229. if (!session_isActive(fd))
  3230. return;
  3231. t = (int)(cd->owner->type == BL_NPC);
  3232. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3233. WFIFOW(fd, 0) = 0xdb;
  3234. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3235. WFIFOL(fd, 4) = cd->bl.id;
  3236. if(cd->owner->type == BL_NPC){
  3237. WFIFOL(fd, 30) = 1;
  3238. WFIFOL(fd, 8) = 0;
  3239. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3240. for (i = 0; i < cd->users; i++) {
  3241. WFIFOL(fd, 8+(i+1)*28) = 1;
  3242. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3243. }
  3244. } else
  3245. for (i = 0; i < cd->users; i++) {
  3246. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3247. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3248. }
  3249. WFIFOSET(fd, WFIFOW(fd, 2));
  3250. }
  3251. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3252. /// 00dc <users>.W <name>.24B
  3253. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3254. {
  3255. unsigned char buf[32];
  3256. nullpo_retv(sd);
  3257. nullpo_retv(cd);
  3258. WBUFW(buf, 0) = 0xdc;
  3259. WBUFW(buf, 2) = cd->users;
  3260. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3261. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3262. }
  3263. /// Announce the new owner (ZC_ROLE_CHANGE).
  3264. /// 00e1 <role>.L <nick>.24B
  3265. /// role:
  3266. /// 0 = owner (menu)
  3267. /// 1 = normal
  3268. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3269. {
  3270. unsigned char buf[64];
  3271. nullpo_retv(sd);
  3272. nullpo_retv(cd);
  3273. WBUFW(buf, 0) = 0xe1;
  3274. WBUFL(buf, 2) = 1;
  3275. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3276. WBUFW(buf,30) = 0xe1;
  3277. WBUFL(buf,32) = 0;
  3278. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3279. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3280. }
  3281. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3282. /// 00dd <users>.W <nick>.24B <flag>.B
  3283. /// flag:
  3284. /// 0 = left
  3285. /// 1 = kicked
  3286. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3287. {
  3288. unsigned char buf[32];
  3289. nullpo_retv(sd);
  3290. nullpo_retv(cd);
  3291. WBUFW(buf, 0) = 0xdd;
  3292. WBUFW(buf, 2) = cd->users-1;
  3293. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3294. WBUFB(buf,28) = flag;
  3295. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3296. }
  3297. /// Opens a trade request window from char 'name'.
  3298. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3299. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3300. void clif_traderequest(struct map_session_data* sd, const char* name)
  3301. {
  3302. int fd = sd->fd;
  3303. #if PACKETVER < 6
  3304. WFIFOHEAD(fd,packet_len(0xe5));
  3305. WFIFOW(fd,0) = 0xe5;
  3306. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3307. WFIFOSET(fd,packet_len(0xe5));
  3308. #else
  3309. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3310. if( !tsd ) return;
  3311. WFIFOHEAD(fd,packet_len(0x1f4));
  3312. WFIFOW(fd,0) = 0x1f4;
  3313. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3314. WFIFOL(fd,26) = tsd->status.char_id;
  3315. WFIFOW(fd,30) = tsd->status.base_level;
  3316. WFIFOSET(fd,packet_len(0x1f4));
  3317. #endif
  3318. }
  3319. /// Reply to a trade-request.
  3320. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3321. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3322. /// result:
  3323. /// 0 = Char is too far
  3324. /// 1 = Character does not exist
  3325. /// 2 = Trade failed
  3326. /// 3 = Accept
  3327. /// 4 = Cancel
  3328. /// 5 = Busy
  3329. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3330. {
  3331. int fd = sd->fd;
  3332. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3333. if( PACKETVER < 6 || !tsd ) {
  3334. WFIFOHEAD(fd,packet_len(0xe7));
  3335. WFIFOW(fd,0) = 0xe7;
  3336. WFIFOB(fd,2) = type;
  3337. WFIFOSET(fd,packet_len(0xe7));
  3338. } else {
  3339. WFIFOHEAD(fd,packet_len(0x1f5));
  3340. WFIFOW(fd,0) = 0x1f5;
  3341. WFIFOB(fd,2) = type;
  3342. WFIFOL(fd,3) = tsd->status.char_id;
  3343. WFIFOW(fd,7) = tsd->status.base_level;
  3344. WFIFOSET(fd,packet_len(0x1f5));
  3345. }
  3346. }
  3347. /// Notifies the client about an item from other player in current trade.
  3348. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3349. /// 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)
  3350. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3351. {
  3352. int fd;
  3353. unsigned char *buf;
  3354. #if PACKETVER < 20100223
  3355. const int cmd = 0xe9;
  3356. #else
  3357. const int cmd = 0x80f;
  3358. #endif
  3359. nullpo_retv(sd);
  3360. nullpo_retv(tsd);
  3361. fd = tsd->fd;
  3362. buf = WFIFOP(fd,0);
  3363. WFIFOHEAD(fd,packet_len(cmd));
  3364. WBUFW(buf,0) = cmd;
  3365. if( index == 0 )
  3366. {
  3367. #if PACKETVER < 20100223
  3368. WBUFL(buf,2) = amount; //amount
  3369. WBUFW(buf,6) = 0; // type id
  3370. #else
  3371. WBUFW(buf,2) = 0; // type id
  3372. WBUFB(buf,4) = 0; // item type
  3373. WBUFL(buf,5) = amount; // amount
  3374. buf = WBUFP(buf,1); //Advance 1B
  3375. #endif
  3376. WBUFB(buf,8) = 0; //identify flag
  3377. WBUFB(buf,9) = 0; // attribute
  3378. WBUFB(buf,10)= 0; //refine
  3379. WBUFW(buf,11)= 0; //card (4w)
  3380. WBUFW(buf,13)= 0; //card (4w)
  3381. WBUFW(buf,15)= 0; //card (4w)
  3382. WBUFW(buf,17)= 0; //card (4w)
  3383. }
  3384. else
  3385. {
  3386. index -= 2; //index fix
  3387. #if PACKETVER < 20100223
  3388. WBUFL(buf,2) = amount; //amount
  3389. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3390. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3391. else
  3392. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3393. #else
  3394. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3395. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3396. else
  3397. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3398. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3399. WBUFL(buf,5) = amount; // amount
  3400. buf = WBUFP(buf,1); //Advance 1B
  3401. #endif
  3402. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3403. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3404. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3405. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3406. }
  3407. WFIFOSET(fd,packet_len(cmd));
  3408. }
  3409. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3410. /// 00ea <index>.W <result>.B
  3411. /// result:
  3412. /// 0 = success
  3413. /// 1 = overweight
  3414. /// 2 = trade canceled
  3415. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3416. {
  3417. int fd;
  3418. nullpo_retv(sd);
  3419. fd = sd->fd;
  3420. WFIFOHEAD(fd,packet_len(0xea));
  3421. WFIFOW(fd,0) = 0xea;
  3422. WFIFOW(fd,2) = index;
  3423. WFIFOB(fd,4) = fail;
  3424. WFIFOSET(fd,packet_len(0xea));
  3425. }
  3426. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3427. /// 00ec <who>.B
  3428. /// who:
  3429. /// 0 = self
  3430. /// 1 = other player
  3431. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3432. {
  3433. int fd;
  3434. nullpo_retv(sd);
  3435. fd = sd->fd;
  3436. WFIFOHEAD(fd,packet_len(0xec));
  3437. WFIFOW(fd,0) = 0xec;
  3438. WFIFOB(fd,2) = fail;
  3439. WFIFOSET(fd,packet_len(0xec));
  3440. }
  3441. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3442. /// 00ee
  3443. void clif_tradecancelled(struct map_session_data* sd)
  3444. {
  3445. int fd;
  3446. nullpo_retv(sd);
  3447. fd = sd->fd;
  3448. WFIFOHEAD(fd,packet_len(0xee));
  3449. WFIFOW(fd,0) = 0xee;
  3450. WFIFOSET(fd,packet_len(0xee));
  3451. }
  3452. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3453. /// 00f0 <result>.B
  3454. /// result:
  3455. /// 0 = success
  3456. /// 1 = failure
  3457. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3458. {
  3459. int fd;
  3460. nullpo_retv(sd);
  3461. fd = sd->fd;
  3462. WFIFOHEAD(fd,packet_len(0xf0));
  3463. WFIFOW(fd,0) = 0xf0;
  3464. WFIFOB(fd,2) = fail;
  3465. WFIFOSET(fd,packet_len(0xf0));
  3466. }
  3467. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3468. /// 00f1
  3469. /// NOTE: Unknown purpose. Items are not removed until the window is
  3470. /// refreshed (ex. by putting another item in there).
  3471. void clif_tradeundo(struct map_session_data* sd)
  3472. {
  3473. int fd = sd->fd;
  3474. WFIFOHEAD(fd,packet_len(0xf1));
  3475. WFIFOW(fd,0) = 0xf1;
  3476. WFIFOSET(fd,packet_len(0xf1));
  3477. }
  3478. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3479. /// 00f2 <current count>.W <max count>.W
  3480. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3481. {
  3482. int fd;
  3483. nullpo_retv(sd);
  3484. fd=sd->fd;
  3485. WFIFOHEAD(fd,packet_len(0xf2));
  3486. WFIFOW(fd,0) = 0xf2;
  3487. WFIFOW(fd,2) = amount;
  3488. WFIFOW(fd,4) = max_amount;
  3489. WFIFOSET(fd,packet_len(0xf2));
  3490. }
  3491. /// Notifies the client of an item being added to the storage.
  3492. /// 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)
  3493. /// 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)
  3494. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3495. {
  3496. int view,fd;
  3497. nullpo_retv(sd);
  3498. nullpo_retv(i);
  3499. fd=sd->fd;
  3500. view = itemdb_viewid(i->nameid);
  3501. #if PACKETVER < 5
  3502. WFIFOHEAD(fd,packet_len(0xf4));
  3503. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3504. WFIFOW(fd, 2) = index+1; // index
  3505. WFIFOL(fd, 4) = amount; // amount
  3506. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3507. WFIFOB(fd,10) = i->identify; //identify flag
  3508. WFIFOB(fd,11) = i->attribute; // attribute
  3509. WFIFOB(fd,12) = i->refine; //refine
  3510. clif_addcards(WFIFOP(fd,13), i);
  3511. WFIFOSET(fd,packet_len(0xf4));
  3512. #else
  3513. WFIFOHEAD(fd,packet_len(0x1c4));
  3514. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3515. WFIFOW(fd, 2) = index+1; // index
  3516. WFIFOL(fd, 4) = amount; // amount
  3517. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3518. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3519. WFIFOB(fd,11) = i->identify; //identify flag
  3520. WFIFOB(fd,12) = i->attribute; // attribute
  3521. WFIFOB(fd,13) = i->refine; //refine
  3522. clif_addcards(WFIFOP(fd,14), i);
  3523. WFIFOSET(fd,packet_len(0x1c4));
  3524. #endif
  3525. }
  3526. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3527. /// 00f6 <index>.W <amount>.L
  3528. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3529. {
  3530. int fd;
  3531. nullpo_retv(sd);
  3532. fd=sd->fd;
  3533. WFIFOHEAD(fd,packet_len(0xf6));
  3534. WFIFOW(fd,0)=0xf6; // Storage item removed
  3535. WFIFOW(fd,2)=index+1;
  3536. WFIFOL(fd,4)=amount;
  3537. WFIFOSET(fd,packet_len(0xf6));
  3538. }
  3539. /// Closes storage (ZC_CLOSE_STORE).
  3540. /// 00f8
  3541. void clif_storageclose(struct map_session_data* sd)
  3542. {
  3543. int fd;
  3544. nullpo_retv(sd);
  3545. fd=sd->fd;
  3546. WFIFOHEAD(fd,packet_len(0xf8));
  3547. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3548. WFIFOSET(fd,packet_len(0xf8));
  3549. }
  3550. /*==========================================
  3551. * Server tells 'sd' player client the abouts of 'dstsd' player
  3552. *------------------------------------------*/
  3553. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3554. {
  3555. struct block_list *d_bl;
  3556. int i;
  3557. if( dstsd->chatID ) {
  3558. struct chat_data *cd = NULL;
  3559. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3560. clif_dispchat(cd,sd->fd);
  3561. } else if( dstsd->state.vending )
  3562. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3563. else if( dstsd->state.buyingstore )
  3564. clif_buyingstore_entry_single(sd, dstsd);
  3565. if(dstsd->spiritball > 0)
  3566. clif_spiritball_single(sd->fd, dstsd);
  3567. for(i = 1; i < 5; i++){
  3568. if( dstsd->talisman[i] > 0 )
  3569. clif_talisman_single(sd->fd, dstsd, i);
  3570. }
  3571. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3572. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3573. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3574. }
  3575. #ifdef NEW_CARTS
  3576. if( dstsd->sc.data[SC_PUSH_CART] )
  3577. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3578. #endif
  3579. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3580. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3581. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3582. )
  3583. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3584. // display link (sd - dstsd) to sd
  3585. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3586. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3587. // display links (dstsd - devotees) to sd
  3588. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3589. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3590. // display link (dstsd - crusader) to sd
  3591. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3592. clif_devotion(d_bl, sd);
  3593. }
  3594. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3595. {
  3596. uint8 buf[128];
  3597. struct unit_data *ud;
  3598. struct view_data *vd;
  3599. int len;
  3600. vd = status_get_viewdata(bl);
  3601. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3602. return;
  3603. /**
  3604. * Hide NPC from maya purple card.
  3605. **/
  3606. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3607. return;
  3608. ud = unit_bl2ud(bl);
  3609. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3610. clif_send(buf,len,&sd->bl,SELF);
  3611. if (vd->cloth_color)
  3612. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3613. switch (bl->type)
  3614. {
  3615. case BL_PC:
  3616. {
  3617. TBL_PC* tsd = (TBL_PC*)bl;
  3618. clif_getareachar_pc(sd, tsd);
  3619. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3620. clif_specialeffect_single(bl,423,sd->fd);
  3621. else if(tsd->state.size==SZ_MEDIUM)
  3622. clif_specialeffect_single(bl,421,sd->fd);
  3623. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3624. clif_sendbgemblem_single(sd->fd,tsd);
  3625. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3626. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3627. }
  3628. break;
  3629. case BL_MER: // Devotion Effects
  3630. if( ((TBL_MER*)bl)->devotion_flag )
  3631. clif_devotion(bl, sd);
  3632. break;
  3633. case BL_NPC:
  3634. {
  3635. TBL_NPC* nd = (TBL_NPC*)bl;
  3636. if( nd->chat_id )
  3637. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3638. if( nd->size == SZ_BIG )
  3639. clif_specialeffect_single(bl,423,sd->fd);
  3640. else if( nd->size == SZ_MEDIUM )
  3641. clif_specialeffect_single(bl,421,sd->fd);
  3642. }
  3643. break;
  3644. case BL_MOB:
  3645. {
  3646. TBL_MOB* md = (TBL_MOB*)bl;
  3647. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3648. clif_specialeffect_single(bl,423,sd->fd);
  3649. else if(md->special_state.size==SZ_MEDIUM)
  3650. clif_specialeffect_single(bl,421,sd->fd);
  3651. #if PACKETVER >= 20120404
  3652. if( !(md->status.mode&MD_BOSS) ){
  3653. int i;
  3654. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3655. if( md->dmglog[i].id == sd->status.char_id )
  3656. clif_monster_hp_bar(md, sd->fd);
  3657. }
  3658. #endif
  3659. }
  3660. break;
  3661. case BL_PET:
  3662. if (vd->head_bottom)
  3663. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3664. break;
  3665. }
  3666. }
  3667. //Modifies the type of damage according to status changes [Skotlex]
  3668. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3669. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3670. {
  3671. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3672. }
  3673. /*==========================================
  3674. * Estimates walk delay based on the damage criteria. [Skotlex]
  3675. *------------------------------------------*/
  3676. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3677. {
  3678. if (type == 4 || type == 9 || damage <=0)
  3679. return 0;
  3680. if (bl->type == BL_PC) {
  3681. if (battle_config.pc_walk_delay_rate != 100)
  3682. delay = delay*battle_config.pc_walk_delay_rate/100;
  3683. } else
  3684. if (battle_config.walk_delay_rate != 100)
  3685. delay = delay*battle_config.walk_delay_rate/100;
  3686. if (div_ > 1) //Multi-hit skills mean higher delays.
  3687. delay += battle_config.multihit_delay*(div_-1);
  3688. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3689. }
  3690. /// Sends a 'damage' packet (src performs action on dst)
  3691. /// 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)
  3692. /// 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)
  3693. /// type:
  3694. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3695. /// 1 = pick up item
  3696. /// 2 = sit down
  3697. /// 3 = stand up
  3698. /// 4 = damage (endure)
  3699. /// 5 = (splash?)
  3700. /// 6 = (skill?)
  3701. /// 7 = (repeat damage?)
  3702. /// 8 = multi-hit damage
  3703. /// 9 = multi-hit damage (endure)
  3704. /// 10 = critical hit
  3705. /// 11 = lucky dodge
  3706. /// 12 = (touch skill?)
  3707. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
  3708. {
  3709. unsigned char buf[33];
  3710. struct status_change *sc;
  3711. #if PACKETVER < 20071113
  3712. const int cmd = 0x8a;
  3713. #else
  3714. const int cmd = 0x2e1;
  3715. #endif
  3716. nullpo_ret(src);
  3717. nullpo_ret(dst);
  3718. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3719. sc = status_get_sc(dst);
  3720. if(sc && sc->count) {
  3721. if(sc->data[SC_HALLUCINATION]) {
  3722. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3723. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3724. }
  3725. }
  3726. WBUFW(buf,0)=cmd;
  3727. WBUFL(buf,2)=src->id;
  3728. WBUFL(buf,6)=dst->id;
  3729. WBUFL(buf,10)=tick;
  3730. WBUFL(buf,14)=sdelay;
  3731. WBUFL(buf,18)=ddelay;
  3732. #if PACKETVER < 20071113
  3733. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3734. WBUFW(buf,22)=damage?div:0;
  3735. WBUFW(buf,27)=damage2?div:0;
  3736. } else {
  3737. WBUFW(buf,22)=min(damage, INT16_MAX);
  3738. WBUFW(buf,27)=damage2;
  3739. }
  3740. WBUFW(buf,24)=div;
  3741. WBUFB(buf,26)=type;
  3742. #else
  3743. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3744. WBUFL(buf,22)=damage?div:0;
  3745. WBUFL(buf,29)=damage2?div:0;
  3746. } else {
  3747. WBUFL(buf,22)=damage;
  3748. WBUFL(buf,29)=damage2;
  3749. }
  3750. WBUFW(buf,26)=div;
  3751. WBUFB(buf,28)=type;
  3752. #endif
  3753. if(disguised(dst)) {
  3754. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3755. WBUFL(buf,6) = -dst->id;
  3756. clif_send(buf,packet_len(cmd),dst,SELF);
  3757. } else
  3758. clif_send(buf,packet_len(cmd),dst,AREA);
  3759. if(disguised(src)) {
  3760. WBUFL(buf,2) = -src->id;
  3761. if (disguised(dst))
  3762. WBUFL(buf,6) = dst->id;
  3763. #if PACKETVER < 20071113
  3764. if(damage > 0) WBUFW(buf,22) = -1;
  3765. if(damage2 > 0) WBUFW(buf,27) = -1;
  3766. #else
  3767. if(damage > 0) WBUFL(buf,22) = -1;
  3768. if(damage2 > 0) WBUFL(buf,29) = -1;
  3769. #endif
  3770. clif_send(buf,packet_len(cmd),src,SELF);
  3771. }
  3772. if(src == dst) {
  3773. unit_setdir(src,unit_getdir(src));
  3774. }
  3775. //Return adjusted can't walk delay for further processing.
  3776. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3777. }
  3778. /*==========================================
  3779. * src picks up dst
  3780. *------------------------------------------*/
  3781. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3782. {
  3783. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3784. unsigned char buf[32];
  3785. nullpo_retv(src);
  3786. nullpo_retv(dst);
  3787. WBUFW(buf, 0) = 0x8a;
  3788. WBUFL(buf, 2) = src->id;
  3789. WBUFL(buf, 6) = dst->id;
  3790. WBUFB(buf,26) = 1;
  3791. clif_send(buf, packet_len(0x8a), src, AREA);
  3792. }
  3793. /*==========================================
  3794. * inform clients in area that `bl` is sitting
  3795. *------------------------------------------*/
  3796. void clif_sitting(struct block_list* bl)
  3797. {
  3798. unsigned char buf[32];
  3799. nullpo_retv(bl);
  3800. WBUFW(buf, 0) = 0x8a;
  3801. WBUFL(buf, 2) = bl->id;
  3802. WBUFB(buf,26) = 2;
  3803. clif_send(buf, packet_len(0x8a), bl, AREA);
  3804. if(disguised(bl)) {
  3805. WBUFL(buf, 2) = - bl->id;
  3806. clif_send(buf, packet_len(0x8a), bl, SELF);
  3807. }
  3808. }
  3809. /*==========================================
  3810. * inform clients in area that `bl` is standing
  3811. *------------------------------------------*/
  3812. void clif_standing(struct block_list* bl)
  3813. {
  3814. unsigned char buf[32];
  3815. nullpo_retv(bl);
  3816. WBUFW(buf, 0) = 0x8a;
  3817. WBUFL(buf, 2) = bl->id;
  3818. WBUFB(buf,26) = 3;
  3819. clif_send(buf, packet_len(0x8a), bl, AREA);
  3820. if(disguised(bl)) {
  3821. WBUFL(buf, 2) = - bl->id;
  3822. clif_send(buf, packet_len(0x8a), bl, SELF);
  3823. }
  3824. }
  3825. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3826. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3827. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3828. {
  3829. unsigned char buf[32];
  3830. WBUFW(buf,0) = 0x192;
  3831. WBUFW(buf,2) = x;
  3832. WBUFW(buf,4) = y;
  3833. WBUFW(buf,6) = type;
  3834. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3835. if( fd )
  3836. {
  3837. WFIFOHEAD(fd,packet_len(0x192));
  3838. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3839. WFIFOSET(fd,packet_len(0x192));
  3840. }
  3841. else
  3842. {
  3843. struct block_list dummy_bl;
  3844. dummy_bl.type = BL_NUL;
  3845. dummy_bl.x = x;
  3846. dummy_bl.y = y;
  3847. dummy_bl.m = m;
  3848. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3849. }
  3850. }
  3851. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3852. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3853. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3854. {
  3855. int view,fd;
  3856. fd=sd->fd;
  3857. WFIFOHEAD(fd,packet_len(0x9d));
  3858. WFIFOW(fd,0)=0x9d;
  3859. WFIFOL(fd,2)=fitem->bl.id;
  3860. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3861. WFIFOW(fd,6)=view;
  3862. else
  3863. WFIFOW(fd,6)=fitem->item_data.nameid;
  3864. WFIFOB(fd,8)=fitem->item_data.identify;
  3865. WFIFOW(fd,9)=fitem->bl.x;
  3866. WFIFOW(fd,11)=fitem->bl.y;
  3867. WFIFOW(fd,13)=fitem->item_data.amount;
  3868. WFIFOB(fd,15)=fitem->subx;
  3869. WFIFOB(fd,16)=fitem->suby;
  3870. WFIFOSET(fd,packet_len(0x9d));
  3871. }
  3872. /// Notifies the client of a skill unit.
  3873. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3874. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3875. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3876. {
  3877. int fd = sd->fd;
  3878. if( unit->group->state.guildaura )
  3879. return;
  3880. #if PACKETVER >= 3
  3881. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3882. WFIFOHEAD(fd,packet_len(0x1c9));
  3883. WFIFOW(fd, 0)=0x1c9;
  3884. WFIFOL(fd, 2)=unit->bl.id;
  3885. WFIFOL(fd, 6)=unit->group->src_id;
  3886. WFIFOW(fd,10)=unit->bl.x;
  3887. WFIFOW(fd,12)=unit->bl.y;
  3888. WFIFOB(fd,14)=unit->group->unit_id;
  3889. WFIFOB(fd,15)=1;
  3890. WFIFOB(fd,16)=1;
  3891. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3892. WFIFOSET(fd,packet_len(0x1c9));
  3893. return;
  3894. }
  3895. #endif
  3896. WFIFOHEAD(fd,packet_len(0x11f));
  3897. WFIFOW(fd, 0)=0x11f;
  3898. WFIFOL(fd, 2)=unit->bl.id;
  3899. WFIFOL(fd, 6)=unit->group->src_id;
  3900. WFIFOW(fd,10)=unit->bl.x;
  3901. WFIFOW(fd,12)=unit->bl.y;
  3902. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3903. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3904. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  3905. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3906. else
  3907. WFIFOB(fd,14)=unit->group->unit_id;
  3908. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3909. WFIFOSET(fd,packet_len(0x11f));
  3910. if(unit->group->skill_id == WZ_ICEWALL)
  3911. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3912. }
  3913. /*==========================================
  3914. * Server tells client to remove unit of id 'unit->bl.id'
  3915. *------------------------------------------*/
  3916. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3917. {
  3918. nullpo_retv(unit);
  3919. WFIFOHEAD(fd,packet_len(0x120));
  3920. WFIFOW(fd, 0)=0x120;
  3921. WFIFOL(fd, 2)=unit->bl.id;
  3922. WFIFOSET(fd,packet_len(0x120));
  3923. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3924. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3925. }
  3926. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3927. /// 0120 <id>.L
  3928. void clif_skill_delunit(struct skill_unit *unit)
  3929. {
  3930. unsigned char buf[16];
  3931. nullpo_retv(unit);
  3932. WBUFW(buf, 0)=0x120;
  3933. WBUFL(buf, 2)=unit->bl.id;
  3934. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3935. }
  3936. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3937. /// 01ac <id>.L
  3938. /// Only affects units with class [139,153] client-side.
  3939. void clif_skillunit_update(struct block_list* bl)
  3940. {
  3941. unsigned char buf[6];
  3942. nullpo_retv(bl);
  3943. WBUFW(buf,0) = 0x1ac;
  3944. WBUFL(buf,2) = bl->id;
  3945. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3946. }
  3947. /*==========================================
  3948. *
  3949. *------------------------------------------*/
  3950. static int clif_getareachar(struct block_list* bl,va_list ap)
  3951. {
  3952. struct map_session_data *sd;
  3953. nullpo_ret(bl);
  3954. sd=va_arg(ap,struct map_session_data*);
  3955. if (sd == NULL || !sd->fd)
  3956. return 0;
  3957. switch(bl->type){
  3958. case BL_ITEM:
  3959. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3960. break;
  3961. case BL_SKILL:
  3962. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3963. break;
  3964. default:
  3965. if(&sd->bl == bl)
  3966. break;
  3967. clif_getareachar_unit(sd,bl);
  3968. break;
  3969. }
  3970. return 0;
  3971. }
  3972. /*==========================================
  3973. * tbl has gone out of view-size of bl
  3974. *------------------------------------------*/
  3975. int clif_outsight(struct block_list *bl,va_list ap)
  3976. {
  3977. struct block_list *tbl;
  3978. struct view_data *vd;
  3979. TBL_PC *sd, *tsd;
  3980. tbl=va_arg(ap,struct block_list*);
  3981. if(bl == tbl) return 0;
  3982. sd = BL_CAST(BL_PC, bl);
  3983. tsd = BL_CAST(BL_PC, tbl);
  3984. if (tsd && tsd->fd)
  3985. { //tsd has lost sight of the bl object.
  3986. switch(bl->type){
  3987. case BL_PC:
  3988. if (sd->vd.class_ != INVISIBLE_CLASS)
  3989. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3990. if(sd->chatID){
  3991. struct chat_data *cd;
  3992. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3993. if(cd->usersd[0]==sd)
  3994. clif_dispchat(cd,tsd->fd);
  3995. }
  3996. if( sd->state.vending )
  3997. clif_closevendingboard(bl,tsd->fd);
  3998. if( sd->state.buyingstore )
  3999. clif_buyingstore_disappear_entry_single(tsd, sd);
  4000. break;
  4001. case BL_ITEM:
  4002. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4003. break;
  4004. case BL_SKILL:
  4005. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4006. break;
  4007. case BL_NPC:
  4008. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4009. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4010. break;
  4011. default:
  4012. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4013. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4014. break;
  4015. }
  4016. }
  4017. if (sd && sd->fd)
  4018. { //sd is watching tbl go out of view.
  4019. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4020. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4021. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4022. }
  4023. return 0;
  4024. }
  4025. /*==========================================
  4026. * tbl has come into view of bl
  4027. *------------------------------------------*/
  4028. int clif_insight(struct block_list *bl,va_list ap)
  4029. {
  4030. struct block_list *tbl;
  4031. TBL_PC *sd, *tsd;
  4032. tbl=va_arg(ap,struct block_list*);
  4033. if (bl == tbl) return 0;
  4034. sd = BL_CAST(BL_PC, bl);
  4035. tsd = BL_CAST(BL_PC, tbl);
  4036. if (tsd && tsd->fd)
  4037. { //Tell tsd that bl entered into his view
  4038. switch(bl->type){
  4039. case BL_ITEM:
  4040. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4041. break;
  4042. case BL_SKILL:
  4043. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  4044. break;
  4045. default:
  4046. clif_getareachar_unit(tsd,bl);
  4047. break;
  4048. }
  4049. }
  4050. if (sd && sd->fd)
  4051. { //Tell sd that tbl walked into his view
  4052. clif_getareachar_unit(sd,tbl);
  4053. }
  4054. return 0;
  4055. }
  4056. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4057. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4058. void clif_skillinfoblock(struct map_session_data *sd)
  4059. {
  4060. int fd;
  4061. int i,len,id;
  4062. nullpo_retv(sd);
  4063. fd=sd->fd;
  4064. if (!fd) return;
  4065. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4066. WFIFOW(fd,0) = 0x10f;
  4067. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4068. {
  4069. if( (id = sd->status.skill[i].id) != 0 )
  4070. {
  4071. // workaround for bugreport:5348
  4072. if (len + 37 > 8192)
  4073. break;
  4074. WFIFOW(fd,len) = id;
  4075. WFIFOL(fd,len+2) = skill_get_inf(id);
  4076. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4077. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4078. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4079. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4080. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4081. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4082. else
  4083. WFIFOB(fd,len+36) = 0;
  4084. len += 37;
  4085. }
  4086. }
  4087. WFIFOW(fd,2)=len;
  4088. WFIFOSET(fd,len);
  4089. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4090. for ( ; i < MAX_SKILL; i++)
  4091. {
  4092. if( (id = sd->status.skill[i].id) != 0 )
  4093. {
  4094. clif_addskill(sd, id);
  4095. clif_skillinfo(sd, id, 0);
  4096. }
  4097. }
  4098. }
  4099. /**
  4100. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4101. **/
  4102. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4103. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4104. void clif_addskill(struct map_session_data *sd, int id)
  4105. {
  4106. int fd;
  4107. nullpo_retv(sd);
  4108. fd = sd->fd;
  4109. if (!fd) return;
  4110. if( sd->status.skill[id].id <= 0 )
  4111. return;
  4112. WFIFOHEAD(fd, packet_len(0x111));
  4113. WFIFOW(fd,0) = 0x111;
  4114. WFIFOW(fd,2) = id;
  4115. WFIFOL(fd,4) = skill_get_inf(id);
  4116. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4117. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4118. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4119. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4120. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4121. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4122. else
  4123. WFIFOB(fd,38) = 0;
  4124. WFIFOSET(fd,packet_len(0x111));
  4125. }
  4126. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4127. /// 0441 <skill id>.W
  4128. void clif_deleteskill(struct map_session_data *sd, int id)
  4129. {
  4130. #if PACKETVER >= 20081217
  4131. int fd;
  4132. nullpo_retv(sd);
  4133. fd = sd->fd;
  4134. if( !fd ) return;
  4135. WFIFOHEAD(fd,packet_len(0x441));
  4136. WFIFOW(fd,0) = 0x441;
  4137. WFIFOW(fd,2) = id;
  4138. WFIFOSET(fd,packet_len(0x441));
  4139. #endif
  4140. clif_skillinfoblock(sd);
  4141. }
  4142. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4143. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4144. void clif_skillup(struct map_session_data *sd,uint16 skill_id)
  4145. {
  4146. int fd;
  4147. nullpo_retv(sd);
  4148. fd=sd->fd;
  4149. WFIFOHEAD(fd,packet_len(0x10e));
  4150. WFIFOW(fd,0) = 0x10e;
  4151. WFIFOW(fd,2) = skill_id;
  4152. WFIFOW(fd,4) = sd->status.skill[skill_id].lv;
  4153. WFIFOW(fd,6) = skill_get_sp(skill_id,sd->status.skill[skill_id].lv);
  4154. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[skill_id].lv);
  4155. WFIFOB(fd,10) = (sd->status.skill[skill_id].lv < skill_tree_get_max(sd->status.skill[skill_id].id, sd->status.class_)) ? 1 : 0;
  4156. WFIFOSET(fd,packet_len(0x10e));
  4157. }
  4158. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4159. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4160. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4161. {
  4162. const int fd = sd->fd;
  4163. WFIFOHEAD(fd,packet_len(0x7e1));
  4164. WFIFOW(fd,0) = 0x7e1;
  4165. WFIFOW(fd,2) = skill;
  4166. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4167. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4168. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4169. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4170. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4171. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4172. else
  4173. WFIFOB(fd,14) = 0;
  4174. WFIFOSET(fd,packet_len(0x7e1));
  4175. }
  4176. /// Notifies clients in area, that an object is about to use a skill.
  4177. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4178. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4179. /// property:
  4180. /// 0 = Yellow cast aura
  4181. /// 1 = Water elemental cast aura
  4182. /// 2 = Earth elemental cast aura
  4183. /// 3 = Fire elemental cast aura
  4184. /// 4 = Wind elemental cast aura
  4185. /// 5 = Poison elemental cast aura
  4186. /// 6 = Holy elemental cast aura
  4187. /// ? = like 0
  4188. /// is disposable:
  4189. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4190. /// 1 = no text
  4191. 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)
  4192. {
  4193. #if PACKETVER < 20091124
  4194. const int cmd = 0x13e;
  4195. #else
  4196. const int cmd = 0x7fb;
  4197. #endif
  4198. unsigned char buf[32];
  4199. WBUFW(buf,0) = cmd;
  4200. WBUFL(buf,2) = src_id;
  4201. WBUFL(buf,6) = dst_id;
  4202. WBUFW(buf,10) = dst_x;
  4203. WBUFW(buf,12) = dst_y;
  4204. WBUFW(buf,14) = skill_id;
  4205. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4206. WBUFL(buf,20) = casttime;
  4207. #if PACKETVER >= 20091124
  4208. WBUFB(buf,24) = 0; // isDisposable
  4209. #endif
  4210. if (disguised(bl)) {
  4211. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4212. WBUFL(buf,2) = -src_id;
  4213. clif_send(buf,packet_len(cmd), bl, SELF);
  4214. } else
  4215. clif_send(buf,packet_len(cmd), bl, AREA);
  4216. }
  4217. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4218. /// 01b9 <id>.L
  4219. void clif_skillcastcancel(struct block_list* bl)
  4220. {
  4221. unsigned char buf[16];
  4222. nullpo_retv(bl);
  4223. WBUFW(buf,0) = 0x1b9;
  4224. WBUFL(buf,2) = bl->id;
  4225. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4226. }
  4227. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4228. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4229. /// num (only used when skill id = NV_BASIC and cause = 0):
  4230. /// 0 = "skill failed" MsgStringTable[159]
  4231. /// 1 = "no emotions" MsgStringTable[160]
  4232. /// 2 = "no sit" MsgStringTable[161]
  4233. /// 3 = "no chat" MsgStringTable[162]
  4234. /// 4 = "no party" MsgStringTable[163]
  4235. /// 5 = "no shout" MsgStringTable[164]
  4236. /// 6 = "no PKing" MsgStringTable[165]
  4237. /// 7 = "no alligning" MsgStringTable[383]
  4238. /// ? = ignored
  4239. /// cause:
  4240. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4241. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4242. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4243. /// "skill failed" MsgStringTable[204] (otherwise)
  4244. /// ... = @see enum useskill_fail_cause
  4245. /// ? = ignored
  4246. ///
  4247. /// if(result!=0) doesn't display any of the previous messages
  4248. /// Note: when this packet is received an unknown flag is always set to 0,
  4249. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4250. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4251. {
  4252. int fd;
  4253. if (!sd) { //Since this is the most common nullpo....
  4254. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4255. return;
  4256. }
  4257. fd=sd->fd;
  4258. if (!fd) return;
  4259. if(battle_config.display_skill_fail&1)
  4260. return; //Disable all skill failed messages
  4261. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4262. return; //Disable delay failed messages
  4263. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4264. return;
  4265. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4266. return;
  4267. WFIFOHEAD(fd,packet_len(0x110));
  4268. WFIFOW(fd,0) = 0x110;
  4269. WFIFOW(fd,2) = skill_id;
  4270. WFIFOL(fd,4) = btype;
  4271. WFIFOB(fd,8) = 0;// success
  4272. WFIFOB(fd,9) = cause;
  4273. WFIFOSET(fd,packet_len(0x110));
  4274. }
  4275. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4276. /// 043d <skill ID>.W <tick>.L
  4277. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4278. {
  4279. #if PACKETVER>=20081112
  4280. int fd;
  4281. nullpo_retv(sd);
  4282. fd=sd->fd;
  4283. WFIFOHEAD(fd,packet_len(0x43d));
  4284. WFIFOW(fd,0) = 0x43d;
  4285. WFIFOW(fd,2) = skill_id;
  4286. WFIFOL(fd,4) = tick;
  4287. WFIFOSET(fd,packet_len(0x43d));
  4288. #endif
  4289. }
  4290. /// Skill attack effect and damage.
  4291. /// 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)
  4292. /// 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)
  4293. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4294. {
  4295. unsigned char buf[64];
  4296. struct status_change *sc;
  4297. nullpo_ret(src);
  4298. nullpo_ret(dst);
  4299. type = clif_calc_delay(type,div,damage,ddelay);
  4300. sc = status_get_sc(dst);
  4301. if(sc && sc->count) {
  4302. if(sc->data[SC_HALLUCINATION] && damage)
  4303. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4304. }
  4305. #if PACKETVER < 3
  4306. WBUFW(buf,0)=0x114;
  4307. WBUFW(buf,2)=skill_id;
  4308. WBUFL(buf,4)=src->id;
  4309. WBUFL(buf,8)=dst->id;
  4310. WBUFL(buf,12)=tick;
  4311. WBUFL(buf,16)=sdelay;
  4312. WBUFL(buf,20)=ddelay;
  4313. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4314. WBUFW(buf,24)=damage?div:0;
  4315. } else {
  4316. WBUFW(buf,24)=damage;
  4317. }
  4318. WBUFW(buf,26)=skill_lv;
  4319. WBUFW(buf,28)=div;
  4320. WBUFB(buf,30)=type;
  4321. if (disguised(dst)) {
  4322. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4323. WBUFL(buf,8)=-dst->id;
  4324. clif_send(buf,packet_len(0x114),dst,SELF);
  4325. } else
  4326. clif_send(buf,packet_len(0x114),dst,AREA);
  4327. if(disguised(src)) {
  4328. WBUFL(buf,4)=-src->id;
  4329. if (disguised(dst))
  4330. WBUFL(buf,8)=dst->id;
  4331. if(damage > 0)
  4332. WBUFW(buf,24)=-1;
  4333. clif_send(buf,packet_len(0x114),src,SELF);
  4334. }
  4335. #else
  4336. WBUFW(buf,0)=0x1de;
  4337. WBUFW(buf,2)=skill_id;
  4338. WBUFL(buf,4)=src->id;
  4339. WBUFL(buf,8)=dst->id;
  4340. WBUFL(buf,12)=tick;
  4341. WBUFL(buf,16)=sdelay;
  4342. WBUFL(buf,20)=ddelay;
  4343. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4344. WBUFL(buf,24)=damage?div:0;
  4345. } else {
  4346. WBUFL(buf,24)=damage;
  4347. }
  4348. WBUFW(buf,28)=skill_lv;
  4349. WBUFW(buf,30)=div;
  4350. WBUFB(buf,32)=type;
  4351. if (disguised(dst)) {
  4352. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4353. WBUFL(buf,8)=-dst->id;
  4354. clif_send(buf,packet_len(0x1de),dst,SELF);
  4355. } else
  4356. clif_send(buf,packet_len(0x1de),dst,AREA);
  4357. if(disguised(src)) {
  4358. WBUFL(buf,4)=-src->id;
  4359. if (disguised(dst))
  4360. WBUFL(buf,8)=dst->id;
  4361. if(damage > 0)
  4362. WBUFL(buf,24)=-1;
  4363. clif_send(buf,packet_len(0x1de),src,SELF);
  4364. }
  4365. #endif
  4366. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4367. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4368. }
  4369. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4370. /// 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
  4371. /*
  4372. 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)
  4373. {
  4374. unsigned char buf[64];
  4375. struct status_change *sc;
  4376. nullpo_ret(src);
  4377. nullpo_ret(dst);
  4378. type = (type>0)?type:skill_get_hit(skill_id);
  4379. type = clif_calc_delay(type,div,damage,ddelay);
  4380. sc = status_get_sc(dst);
  4381. if(sc && sc->count) {
  4382. if(sc->data[SC_HALLUCINATION] && damage)
  4383. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4384. }
  4385. WBUFW(buf,0)=0x115;
  4386. WBUFW(buf,2)=skill_id;
  4387. WBUFL(buf,4)=src->id;
  4388. WBUFL(buf,8)=dst->id;
  4389. WBUFL(buf,12)=tick;
  4390. WBUFL(buf,16)=sdelay;
  4391. WBUFL(buf,20)=ddelay;
  4392. WBUFW(buf,24)=dst->x;
  4393. WBUFW(buf,26)=dst->y;
  4394. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4395. WBUFW(buf,28)=damage?div:0;
  4396. } else {
  4397. WBUFW(buf,28)=damage;
  4398. }
  4399. WBUFW(buf,30)=skill_lv;
  4400. WBUFW(buf,32)=div;
  4401. WBUFB(buf,34)=type;
  4402. clif_send(buf,packet_len(0x115),src,AREA);
  4403. if(disguised(src)) {
  4404. WBUFL(buf,4)=-src->id;
  4405. if(damage > 0)
  4406. WBUFW(buf,28)=-1;
  4407. clif_send(buf,packet_len(0x115),src,SELF);
  4408. }
  4409. if (disguised(dst)) {
  4410. WBUFL(buf,8)=-dst->id;
  4411. if (disguised(src))
  4412. WBUFL(buf,4)=src->id;
  4413. else if(damage > 0)
  4414. WBUFW(buf,28)=-1;
  4415. clif_send(buf,packet_len(0x115),dst,SELF);
  4416. }
  4417. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4418. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4419. }
  4420. */
  4421. /// Non-damaging skill effect (ZC_USE_SKILL).
  4422. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4423. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4424. {
  4425. unsigned char buf[32];
  4426. nullpo_ret(dst);
  4427. WBUFW(buf,0)=0x11a;
  4428. WBUFW(buf,2)=skill_id;
  4429. WBUFW(buf,4)=min(heal, INT16_MAX);
  4430. WBUFL(buf,6)=dst->id;
  4431. WBUFL(buf,10)=src?src->id:0;
  4432. WBUFB(buf,14)=fail;
  4433. if (disguised(dst)) {
  4434. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4435. WBUFL(buf,6)=-dst->id;
  4436. clif_send(buf,packet_len(0x11a),dst,SELF);
  4437. } else
  4438. clif_send(buf,packet_len(0x11a),dst,AREA);
  4439. if(src && disguised(src)) {
  4440. WBUFL(buf,10)=-src->id;
  4441. if (disguised(dst))
  4442. WBUFL(buf,6)=dst->id;
  4443. clif_send(buf,packet_len(0x11a),src,SELF);
  4444. }
  4445. return fail;
  4446. }
  4447. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4448. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4449. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4450. {
  4451. unsigned char buf[32];
  4452. nullpo_retv(src);
  4453. WBUFW(buf,0)=0x117;
  4454. WBUFW(buf,2)=skill_id;
  4455. WBUFL(buf,4)=src->id;
  4456. WBUFW(buf,8)=val;
  4457. WBUFW(buf,10)=x;
  4458. WBUFW(buf,12)=y;
  4459. WBUFL(buf,14)=tick;
  4460. if(disguised(src)) {
  4461. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4462. WBUFL(buf,4)=-src->id;
  4463. clif_send(buf,packet_len(0x117),src,SELF);
  4464. } else
  4465. clif_send(buf,packet_len(0x117),src,AREA);
  4466. }
  4467. /*==========================================
  4468. * Tells all client's nearby 'unit' sight range that it spawned
  4469. *------------------------------------------*/
  4470. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4471. void clif_skill_setunit(struct skill_unit *unit)
  4472. {
  4473. unsigned char buf[128];
  4474. nullpo_retv(unit);
  4475. if( unit->group->state.guildaura )
  4476. return;
  4477. #if PACKETVER >= 3
  4478. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4479. WBUFW(buf, 0)=0x1c9;
  4480. WBUFL(buf, 2)=unit->bl.id;
  4481. WBUFL(buf, 6)=unit->group->src_id;
  4482. WBUFW(buf,10)=unit->bl.x;
  4483. WBUFW(buf,12)=unit->bl.y;
  4484. WBUFB(buf,14)=unit->group->unit_id;
  4485. WBUFB(buf,15)=1;
  4486. WBUFB(buf,16)=1;
  4487. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4488. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4489. return;
  4490. }
  4491. #endif
  4492. WBUFW(buf, 0)=0x11f;
  4493. WBUFL(buf, 2)=unit->bl.id;
  4494. WBUFL(buf, 6)=unit->group->src_id;
  4495. WBUFW(buf,10)=unit->bl.x;
  4496. WBUFW(buf,12)=unit->bl.y;
  4497. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4498. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4499. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4500. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4501. else
  4502. WBUFB(buf,14)=unit->group->unit_id;
  4503. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4504. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4505. }
  4506. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4507. /// 011c <skill id>.W { <map name>.16B }*4
  4508. 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)
  4509. {
  4510. int fd;
  4511. nullpo_retv(sd);
  4512. fd = sd->fd;
  4513. WFIFOHEAD(fd,packet_len(0x11c));
  4514. WFIFOW(fd,0) = 0x11c;
  4515. WFIFOW(fd,2) = skill_id;
  4516. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4517. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4518. else // normal map name
  4519. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4520. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4521. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4522. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4523. WFIFOSET(fd,packet_len(0x11c));
  4524. sd->menuskill_id = skill_id;
  4525. if (skill_id == AL_WARP)
  4526. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4527. else
  4528. sd->menuskill_val = skill_lv;
  4529. }
  4530. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4531. /// 011e <type>.B
  4532. /// type:
  4533. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4534. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4535. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4536. ///
  4537. /// @param sd Who receives the message
  4538. /// @param type What message
  4539. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4540. {
  4541. int fd;
  4542. nullpo_retv(sd);
  4543. fd=sd->fd;
  4544. WFIFOHEAD(fd,packet_len(0x11e));
  4545. WFIFOW(fd,0)=0x11e;
  4546. WFIFOB(fd,2)=type;
  4547. WFIFOSET(fd,packet_len(0x11e));
  4548. }
  4549. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4550. /// 0189 <type>.W
  4551. /// type:
  4552. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4553. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4554. ///
  4555. /// @param sd Who receives the message
  4556. /// @param type What message
  4557. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4558. {
  4559. int fd;
  4560. nullpo_retv(sd);
  4561. fd=sd->fd;
  4562. WFIFOHEAD(fd,packet_len(0x189));
  4563. WFIFOW(fd,0)=0x189;
  4564. WFIFOW(fd,2)=type;
  4565. WFIFOSET(fd,packet_len(0x189));
  4566. }
  4567. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4568. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4569. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4570. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4571. {
  4572. struct status_data *status;
  4573. unsigned char buf[64];
  4574. int i;//, fix;
  4575. nullpo_retv(sd);
  4576. nullpo_retv(dst);
  4577. if( dst->type != BL_MOB )
  4578. return;
  4579. status = status_get_status_data(dst);
  4580. WBUFW(buf, 0)=0x18c;
  4581. WBUFW(buf, 2)=status_get_class(dst);
  4582. WBUFW(buf, 4)=status_get_lv(dst);
  4583. WBUFW(buf, 6)=status->size;
  4584. WBUFL(buf, 8)=status->hp;
  4585. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4586. +(battle_config.estimation_type&2?status->def2:0);
  4587. WBUFW(buf,14)=status->race;
  4588. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4589. +(battle_config.estimation_type&2?status->mdef2:0);
  4590. WBUFW(buf,18)= status->def_ele;
  4591. for(i=0;i<9;i++)
  4592. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4593. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4594. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4595. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4596. }
  4597. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4598. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4599. /// material id:
  4600. /// unused by the client
  4601. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4602. {
  4603. int i,c,view,fd;
  4604. nullpo_retv(sd);
  4605. if(sd->menuskill_id == skill_id)
  4606. return; //Avoid resending the menu twice or more times...
  4607. if( skill_id == GC_CREATENEWPOISON )
  4608. skill_id = GC_RESEARCHNEWPOISON;
  4609. fd=sd->fd;
  4610. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4611. WFIFOW(fd, 0)=0x18d;
  4612. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4613. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4614. ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id || skill_id < 0 )
  4615. ){
  4616. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4617. WFIFOW(fd,c*8+ 4)= view;
  4618. else
  4619. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4620. WFIFOW(fd,c*8+ 6)= 0;
  4621. WFIFOW(fd,c*8+ 8)= 0;
  4622. WFIFOW(fd,c*8+10)= 0;
  4623. c++;
  4624. }
  4625. }
  4626. WFIFOW(fd, 2)=c*8+8;
  4627. WFIFOSET(fd,WFIFOW(fd,2));
  4628. if(c > 0) {
  4629. sd->menuskill_id = skill_id;
  4630. sd->menuskill_val = trigger;
  4631. return;
  4632. }
  4633. }
  4634. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4635. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4636. /// mk type:
  4637. /// 1 = cooking
  4638. /// 2 = arrow
  4639. /// 3 = elemental
  4640. /// 4 = GN_MIX_COOKING
  4641. /// 5 = GN_MAKEBOMB
  4642. /// 6 = GN_S_PHARMACY
  4643. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4644. {
  4645. int fd;
  4646. int i, c;
  4647. int view;
  4648. nullpo_retv(sd);
  4649. fd = sd->fd;
  4650. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4651. WFIFOW(fd,0) = 0x25a;
  4652. WFIFOW(fd,4) = list_type; // list type
  4653. c = 0;
  4654. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4655. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4656. continue;
  4657. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4658. WFIFOW(fd, 6 + 2 * c) = view;
  4659. else
  4660. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4661. c++;
  4662. }
  4663. if( skill_id == AM_PHARMACY ) { // Only send it while Cooking else check for c.
  4664. WFIFOW(fd,2) = 6 + 2 * c;
  4665. WFIFOSET(fd,WFIFOW(fd,2));
  4666. }
  4667. if( c > 0 ) {
  4668. sd->menuskill_id = skill_id;
  4669. sd->menuskill_val = trigger;
  4670. if( skill_id != AM_PHARMACY ) {
  4671. sd->menuskill_val2 = qty; // amount.
  4672. WFIFOW(fd,2) = 6 + 2 * c;
  4673. WFIFOSET(fd,WFIFOW(fd,2));
  4674. }
  4675. } else {
  4676. clif_menuskill_clear(sd);
  4677. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4678. // It fails.
  4679. #if PACKETVER >= 20090922
  4680. clif_msg_skill(sd,skill_id,0x625);
  4681. #else
  4682. WFIFOW(fd,2) = 6 + 2 * c;
  4683. WFIFOSET(fd,WFIFOW(fd,2));
  4684. #endif
  4685. }
  4686. }
  4687. }
  4688. /// Notifies clients of a status change.
  4689. /// 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)]
  4690. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4691. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4692. {
  4693. unsigned char buf[32];
  4694. struct map_session_data *sd;
  4695. if (type == SI_BLANK) //It shows nothing on the client...
  4696. return;
  4697. nullpo_retv(bl);
  4698. sd = BL_CAST(BL_PC, bl);
  4699. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4700. return;
  4701. #if PACKETVER >= 20090121
  4702. if(flag && battle_config.display_status_timers && sd)
  4703. WBUFW(buf,0)=0x43f;
  4704. else
  4705. #endif
  4706. WBUFW(buf,0)=0x196;
  4707. WBUFW(buf,2)=type;
  4708. WBUFL(buf,4)=bl->id;
  4709. WBUFB(buf,8)=flag;
  4710. #if PACKETVER >= 20090121
  4711. if(flag && battle_config.display_status_timers && sd)
  4712. {
  4713. if (tick <= 0)
  4714. tick = 9999; // this is indeed what official servers do
  4715. WBUFL(buf,9) = tick;
  4716. WBUFL(buf,13) = val1;
  4717. WBUFL(buf,17) = val2;
  4718. WBUFL(buf,21) = val3;
  4719. }
  4720. #endif
  4721. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4722. }
  4723. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4724. /// 008e <packet len>.W <message>.?B
  4725. void clif_displaymessage(const int fd, const char* mes)
  4726. {
  4727. nullpo_retv(mes);
  4728. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4729. if (fd == 0)
  4730. ;
  4731. else {
  4732. char *message, *line;
  4733. message = aStrdup(mes);
  4734. line = strtok(message, "\n");
  4735. while(line != NULL) {
  4736. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4737. int len = strnlen(line, 255);
  4738. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4739. WFIFOHEAD(fd, 5 + len);
  4740. WFIFOW(fd,0) = 0x8e;
  4741. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4742. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4743. WFIFOSET(fd, 5 + len);
  4744. }
  4745. line = strtok(NULL, "\n");
  4746. }
  4747. aFree(message);
  4748. }
  4749. }
  4750. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4751. /// 009a <packet len>.W <message>.?B
  4752. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4753. {
  4754. int lp = type ? 4 : 0;
  4755. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4756. WBUFW(buf,0) = 0x9a;
  4757. WBUFW(buf,2) = 4 + lp + len;
  4758. if (type == 0x10) // bc_blue
  4759. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4760. else if (type == 0x20) // bc_woe
  4761. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4762. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4763. clif_send(buf, WBUFW(buf,2), bl, target);
  4764. if (buf)
  4765. aFree(buf);
  4766. }
  4767. /*==========================================
  4768. * Displays a message on a 'bl' to all it's nearby clients
  4769. * Used by npc_globalmessage
  4770. *------------------------------------------*/
  4771. void clif_GlobalMessage(struct block_list* bl, const char* message) {
  4772. char buf[100];
  4773. int len;
  4774. nullpo_retv(bl);
  4775. if(!message)
  4776. return;
  4777. len = strlen(message)+1;
  4778. if( len > sizeof(buf)-8 ) {
  4779. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4780. len = sizeof(buf)-8;
  4781. }
  4782. WBUFW(buf,0)=0x8d;
  4783. WBUFW(buf,2)=len+8;
  4784. WBUFL(buf,4)=bl->id;
  4785. safestrncpy((char *) WBUFP(buf,8),message,len);
  4786. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4787. }
  4788. /*==========================================
  4789. * Send main chat message [LuzZza]
  4790. *------------------------------------------*/
  4791. void clif_MainChatMessage(const char* message) {
  4792. uint8 buf[200];
  4793. int len;
  4794. if(!message)
  4795. return;
  4796. len = strlen(message)+1;
  4797. if (len+8 > sizeof(buf)) {
  4798. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4799. len = sizeof(buf)-8;
  4800. }
  4801. WBUFW(buf,0)=0x8d;
  4802. WBUFW(buf,2)=len+8;
  4803. WBUFL(buf,4)=0;
  4804. safestrncpy((char *) WBUFP(buf,8),message,len);
  4805. clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4806. }
  4807. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4808. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4809. 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)
  4810. {
  4811. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4812. WBUFW(buf,0) = 0x1c3;
  4813. WBUFW(buf,2) = len + 16;
  4814. WBUFL(buf,4) = fontColor;
  4815. WBUFW(buf,8) = fontType;
  4816. WBUFW(buf,10) = fontSize;
  4817. WBUFW(buf,12) = fontAlign;
  4818. WBUFW(buf,14) = fontY;
  4819. memcpy(WBUFP(buf,16), mes, len);
  4820. clif_send(buf, WBUFW(buf,2), bl, target);
  4821. if (buf)
  4822. aFree(buf);
  4823. }
  4824. /// Displays heal effect (ZC_RECOVERY).
  4825. /// 013d <var id>.W <amount>.W
  4826. /// var id:
  4827. /// 5 = HP (SP_HP)
  4828. /// 7 = SP (SP_SP)
  4829. /// ? = ignored
  4830. void clif_heal(int fd,int type,int val)
  4831. {
  4832. WFIFOHEAD(fd,packet_len(0x13d));
  4833. WFIFOW(fd,0)=0x13d;
  4834. WFIFOW(fd,2)=type;
  4835. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4836. WFIFOSET(fd,packet_len(0x13d));
  4837. }
  4838. /// Displays resurrection effect (ZC_RESURRECTION).
  4839. /// 0148 <id>.L <type>.W
  4840. /// type:
  4841. /// ignored
  4842. void clif_resurrection(struct block_list *bl,int type)
  4843. {
  4844. unsigned char buf[16];
  4845. nullpo_retv(bl);
  4846. WBUFW(buf,0)=0x148;
  4847. WBUFL(buf,2)=bl->id;
  4848. WBUFW(buf,6)=0;
  4849. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4850. if (disguised(bl))
  4851. clif_spawn(bl);
  4852. }
  4853. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4854. /// 0199 <type>.W
  4855. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4856. {
  4857. int fd;
  4858. nullpo_retv(sd);
  4859. fd=sd->fd;
  4860. WFIFOHEAD(fd,packet_len(0x199));
  4861. WFIFOW(fd,0)=0x199;
  4862. WFIFOW(fd,2)=property;
  4863. WFIFOSET(fd,packet_len(0x199));
  4864. }
  4865. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4866. /// 01d6 <type>.W
  4867. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4868. {
  4869. int fd;
  4870. nullpo_retv(sd);
  4871. fd=sd->fd;
  4872. WFIFOHEAD(fd,packet_len(0x1D6));
  4873. WFIFOW(fd,0)=0x1D6;
  4874. WFIFOW(fd,2)=type;
  4875. WFIFOSET(fd,packet_len(0x1D6));
  4876. }
  4877. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4878. /// 019a <id>.L <ranking>.L <total>.L
  4879. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4880. {
  4881. if(type == 2) {
  4882. int fd = sd->fd;
  4883. WFIFOHEAD(fd,packet_len(0x19a));
  4884. WFIFOW(fd,0) = 0x19a;
  4885. WFIFOL(fd,2) = sd->bl.id;
  4886. WFIFOL(fd,6) = pvprank;
  4887. WFIFOL(fd,10) = pvpnum;
  4888. WFIFOSET(fd,packet_len(0x19a));
  4889. } else {
  4890. unsigned char buf[32];
  4891. WBUFW(buf,0) = 0x19a;
  4892. WBUFL(buf,2) = sd->bl.id;
  4893. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4894. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4895. else
  4896. WBUFL(buf,6) = pvprank;
  4897. WBUFL(buf,10) = pvpnum;
  4898. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4899. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4900. else if(!type)
  4901. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4902. else
  4903. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4904. }
  4905. }
  4906. /*==========================================
  4907. *
  4908. *------------------------------------------*/
  4909. void clif_map_property_mapall(int map, enum map_property property)
  4910. {
  4911. struct block_list bl;
  4912. unsigned char buf[16];
  4913. bl.id = 0;
  4914. bl.type = BL_NUL;
  4915. bl.m = map;
  4916. WBUFW(buf,0)=0x199;
  4917. WBUFW(buf,2)=property;
  4918. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4919. }
  4920. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4921. /// 0188 <result>.W <index>.W <refine>.W
  4922. /// result:
  4923. /// 0 = success
  4924. /// 1 = failure
  4925. /// 2 = downgrade
  4926. void clif_refine(int fd, int fail, int index, int val)
  4927. {
  4928. WFIFOHEAD(fd,packet_len(0x188));
  4929. WFIFOW(fd,0)=0x188;
  4930. WFIFOW(fd,2)=fail;
  4931. WFIFOW(fd,4)=index+2;
  4932. WFIFOW(fd,6)=val;
  4933. WFIFOSET(fd,packet_len(0x188));
  4934. }
  4935. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4936. /// 0223 <result>.L <nameid>.W
  4937. /// result:
  4938. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4939. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4940. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4941. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4942. void clif_upgrademessage(int fd, int result, int item_id)
  4943. {
  4944. WFIFOHEAD(fd,packet_len(0x223));
  4945. WFIFOW(fd,0)=0x223;
  4946. WFIFOL(fd,2)=result;
  4947. WFIFOW(fd,6)=item_id;
  4948. WFIFOSET(fd,packet_len(0x223));
  4949. }
  4950. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4951. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4952. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4953. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4954. {
  4955. #if PACKETVER < 20091104
  4956. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4957. WFIFOW(fd,0) = 0x97;
  4958. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4959. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4960. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4961. WFIFOSET(fd,WFIFOW(fd,2));
  4962. #else
  4963. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4964. WFIFOW(fd,0) = 0x97;
  4965. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4966. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4967. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4968. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  4969. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4970. WFIFOSET(fd,WFIFOW(fd,2));
  4971. #endif
  4972. }
  4973. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  4974. /// 0098 <result>.B
  4975. /// result:
  4976. /// 0 = success to send wisper
  4977. /// 1 = target character is not loged in
  4978. /// 2 = ignored by target
  4979. /// 3 = everyone ignored by target
  4980. void clif_wis_end(int fd, int flag)
  4981. {
  4982. WFIFOHEAD(fd,packet_len(0x98));
  4983. WFIFOW(fd,0) = 0x98;
  4984. WFIFOW(fd,2) = flag;
  4985. WFIFOSET(fd,packet_len(0x98));
  4986. }
  4987. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  4988. /// 0194 <char id>.L <name>.24B
  4989. void clif_solved_charname(int fd, int charid, const char* name)
  4990. {
  4991. WFIFOHEAD(fd,packet_len(0x194));
  4992. WFIFOW(fd,0)=0x194;
  4993. WFIFOL(fd,2)=charid;
  4994. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4995. WFIFOSET(fd,packet_len(0x194));
  4996. }
  4997. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  4998. /// 017b <packet len>.W { <name id>.W }*
  4999. void clif_use_card(struct map_session_data *sd,int idx)
  5000. {
  5001. int i,c,ep;
  5002. int fd=sd->fd;
  5003. nullpo_retv(sd);
  5004. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5005. return;
  5006. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5007. return; //Avoid parsing invalid item indexes (no card/no item)
  5008. ep=sd->inventory_data[idx]->equip;
  5009. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5010. WFIFOW(fd,0)=0x17b;
  5011. for(i=c=0;i<MAX_INVENTORY;i++){
  5012. int j;
  5013. if(sd->inventory_data[i] == NULL)
  5014. continue;
  5015. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5016. continue;
  5017. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5018. continue;
  5019. if(sd->status.inventory[i].identify==0 ) //Not identified
  5020. continue;
  5021. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5022. continue;
  5023. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5024. continue;
  5025. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5026. if( j == sd->inventory_data[i]->slot ) // No room
  5027. continue;
  5028. WFIFOW(fd,4+c*2)=i+2;
  5029. c++;
  5030. }
  5031. WFIFOW(fd,2)=4+c*2;
  5032. WFIFOSET(fd,WFIFOW(fd,2));
  5033. }
  5034. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5035. /// 017d <equip index>.W <card index>.W <result>.B
  5036. /// result:
  5037. /// 0 = success
  5038. /// 1 = failure
  5039. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5040. {
  5041. int fd;
  5042. nullpo_retv(sd);
  5043. fd=sd->fd;
  5044. WFIFOHEAD(fd,packet_len(0x17d));
  5045. WFIFOW(fd,0)=0x17d;
  5046. WFIFOW(fd,2)=idx_equip+2;
  5047. WFIFOW(fd,4)=idx_card+2;
  5048. WFIFOB(fd,6)=flag;
  5049. WFIFOSET(fd,packet_len(0x17d));
  5050. }
  5051. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5052. /// 0177 <packet len>.W { <name id>.W }*
  5053. void clif_item_identify_list(struct map_session_data *sd)
  5054. {
  5055. int i,c;
  5056. int fd;
  5057. nullpo_retv(sd);
  5058. fd=sd->fd;
  5059. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5060. WFIFOW(fd,0)=0x177;
  5061. for(i=c=0;i<MAX_INVENTORY;i++){
  5062. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5063. WFIFOW(fd,c*2+4)=i+2;
  5064. c++;
  5065. }
  5066. }
  5067. if(c > 0) {
  5068. WFIFOW(fd,2)=c*2+4;
  5069. WFIFOSET(fd,WFIFOW(fd,2));
  5070. sd->menuskill_id = MC_IDENTIFY;
  5071. sd->menuskill_val = c;
  5072. }
  5073. }
  5074. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5075. /// 0179 <index>.W <result>.B
  5076. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5077. {
  5078. int fd;
  5079. nullpo_retv(sd);
  5080. fd=sd->fd;
  5081. WFIFOHEAD(fd,packet_len(0x179));
  5082. WFIFOW(fd, 0)=0x179;
  5083. WFIFOW(fd, 2)=idx+2;
  5084. WFIFOB(fd, 4)=flag;
  5085. WFIFOSET(fd,packet_len(0x179));
  5086. }
  5087. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5088. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5089. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5090. {
  5091. int i,c;
  5092. int fd;
  5093. int nameid;
  5094. nullpo_retv(sd);
  5095. nullpo_retv(dstsd);
  5096. fd=sd->fd;
  5097. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5098. WFIFOW(fd,0)=0x1fc;
  5099. for(i=c=0;i<MAX_INVENTORY;i++){
  5100. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5101. WFIFOW(fd,c*13+4) = i;
  5102. WFIFOW(fd,c*13+6) = nameid;
  5103. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5104. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5105. c++;
  5106. }
  5107. }
  5108. if(c > 0) {
  5109. WFIFOW(fd,2)=c*13+4;
  5110. WFIFOSET(fd,WFIFOW(fd,2));
  5111. sd->menuskill_id = BS_REPAIRWEAPON;
  5112. sd->menuskill_val = dstsd->bl.id;
  5113. sd->menuskill_val2 = lv;
  5114. }else
  5115. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5116. }
  5117. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5118. /// 01fe <index>.W <result>.B
  5119. /// index:
  5120. /// ignored (inventory index)
  5121. /// result:
  5122. /// 0 = Item repair success.
  5123. /// 1 = Item repair failure.
  5124. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5125. {
  5126. int fd;
  5127. nullpo_retv(sd);
  5128. fd = sd->fd;
  5129. WFIFOHEAD(fd,packet_len(0x1fe));
  5130. WFIFOW(fd, 0)=0x1fe;
  5131. WFIFOW(fd, 2)=idx+2;
  5132. WFIFOB(fd, 4)=flag;
  5133. WFIFOSET(fd,packet_len(0x1fe));
  5134. }
  5135. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5136. /// 02bb <equip location>.W <account id>.L
  5137. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5138. {
  5139. int fd = sd->fd;
  5140. WFIFOHEAD(fd,packet_len(0x2bb));
  5141. WFIFOW(fd,0) = 0x2bb;
  5142. WFIFOW(fd,2) = position;
  5143. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5144. WFIFOSET(fd,packet_len(0x2bb));
  5145. }
  5146. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5147. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5148. void clif_item_refine_list(struct map_session_data *sd)
  5149. {
  5150. int i,c;
  5151. int fd;
  5152. uint16 skill_lv;
  5153. int wlv;
  5154. int refine_item[5];
  5155. nullpo_retv(sd);
  5156. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5157. fd=sd->fd;
  5158. refine_item[0] = -1;
  5159. refine_item[1] = pc_search_inventory(sd,1010);
  5160. refine_item[2] = pc_search_inventory(sd,1011);
  5161. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5162. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5163. WFIFOW(fd,0)=0x221;
  5164. for(i=c=0;i<MAX_INVENTORY;i++){
  5165. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5166. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5167. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5168. WFIFOW(fd,c*13+ 4)=i+2;
  5169. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5170. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5171. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5172. c++;
  5173. }
  5174. }
  5175. WFIFOW(fd,2)=c*13+4;
  5176. WFIFOSET(fd,WFIFOW(fd,2));
  5177. if (c > 0) {
  5178. sd->menuskill_id = WS_WEAPONREFINE;
  5179. sd->menuskill_val = skill_lv;
  5180. }
  5181. }
  5182. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5183. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5184. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5185. {
  5186. int fd;
  5187. nullpo_retv(sd);
  5188. fd=sd->fd;
  5189. WFIFOHEAD(fd,packet_len(0x147));
  5190. WFIFOW(fd, 0)=0x147;
  5191. WFIFOW(fd, 2)=skill_id;
  5192. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5193. WFIFOW(fd, 6)=0;
  5194. WFIFOW(fd, 8)=skill_lv;
  5195. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5196. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5197. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5198. WFIFOB(fd,38)=0;
  5199. WFIFOSET(fd,packet_len(0x147));
  5200. }
  5201. /// Adds an item to character's cart.
  5202. /// 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)
  5203. /// 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)
  5204. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5205. {
  5206. int view,fd;
  5207. unsigned char *buf;
  5208. nullpo_retv(sd);
  5209. fd=sd->fd;
  5210. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5211. return;
  5212. #if PACKETVER < 5
  5213. WFIFOHEAD(fd,packet_len(0x124));
  5214. buf=WFIFOP(fd,0);
  5215. WBUFW(buf,0)=0x124;
  5216. WBUFW(buf,2)=n+2;
  5217. WBUFL(buf,4)=amount;
  5218. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5219. WBUFW(buf,8)=view;
  5220. else
  5221. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5222. WBUFB(buf,10)=sd->status.cart[n].identify;
  5223. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5224. WBUFB(buf,12)=sd->status.cart[n].refine;
  5225. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5226. WFIFOSET(fd,packet_len(0x124));
  5227. #else
  5228. WFIFOHEAD(fd,packet_len(0x1c5));
  5229. buf=WFIFOP(fd,0);
  5230. WBUFW(buf,0)=0x1c5;
  5231. WBUFW(buf,2)=n+2;
  5232. WBUFL(buf,4)=amount;
  5233. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5234. WBUFW(buf,8)=view;
  5235. else
  5236. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5237. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5238. WBUFB(buf,11)=sd->status.cart[n].identify;
  5239. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5240. WBUFB(buf,13)=sd->status.cart[n].refine;
  5241. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5242. WFIFOSET(fd,packet_len(0x1c5));
  5243. #endif
  5244. }
  5245. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5246. /// 0125 <index>.W <amount>.L
  5247. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5248. {
  5249. int fd;
  5250. nullpo_retv(sd);
  5251. fd=sd->fd;
  5252. WFIFOHEAD(fd,packet_len(0x125));
  5253. WFIFOW(fd,0)=0x125;
  5254. WFIFOW(fd,2)=n+2;
  5255. WFIFOL(fd,4)=amount;
  5256. WFIFOSET(fd,packet_len(0x125));
  5257. }
  5258. /// Opens the shop creation menu (ZC_OPENSTORE).
  5259. /// 012d <num>.W
  5260. /// num:
  5261. /// number of allowed item slots
  5262. void clif_openvendingreq(struct map_session_data* sd, int num)
  5263. {
  5264. int fd;
  5265. nullpo_retv(sd);
  5266. fd = sd->fd;
  5267. WFIFOHEAD(fd,packet_len(0x12d));
  5268. WFIFOW(fd,0) = 0x12d;
  5269. WFIFOW(fd,2) = num;
  5270. WFIFOSET(fd,packet_len(0x12d));
  5271. }
  5272. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5273. /// 0131 <owner id>.L <message>.80B
  5274. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5275. {
  5276. unsigned char buf[128];
  5277. nullpo_retv(bl);
  5278. WBUFW(buf,0) = 0x131;
  5279. WBUFL(buf,2) = bl->id;
  5280. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5281. if( fd ) {
  5282. WFIFOHEAD(fd,packet_len(0x131));
  5283. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5284. WFIFOSET(fd,packet_len(0x131));
  5285. } else {
  5286. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5287. }
  5288. }
  5289. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5290. /// 0132 <owner id>.L
  5291. void clif_closevendingboard(struct block_list* bl, int fd)
  5292. {
  5293. unsigned char buf[16];
  5294. nullpo_retv(bl);
  5295. WBUFW(buf,0) = 0x132;
  5296. WBUFL(buf,2) = bl->id;
  5297. if( fd ) {
  5298. WFIFOHEAD(fd,packet_len(0x132));
  5299. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5300. WFIFOSET(fd,packet_len(0x132));
  5301. } else {
  5302. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5303. }
  5304. }
  5305. /// Sends a list of items in a shop.
  5306. /// 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)
  5307. /// 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)
  5308. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5309. {
  5310. int i,fd;
  5311. int count;
  5312. struct map_session_data* vsd;
  5313. #if PACKETVER < 20100105
  5314. const int cmd = 0x133;
  5315. const int offset = 8;
  5316. #else
  5317. const int cmd = 0x800;
  5318. const int offset = 12;
  5319. #endif
  5320. nullpo_retv(sd);
  5321. nullpo_retv(vending);
  5322. nullpo_retv(vsd=map_id2sd(id));
  5323. fd = sd->fd;
  5324. count = vsd->vend_num;
  5325. WFIFOHEAD(fd, offset+count*22);
  5326. WFIFOW(fd,0) = cmd;
  5327. WFIFOW(fd,2) = offset+count*22;
  5328. WFIFOL(fd,4) = id;
  5329. #if PACKETVER >= 20100105
  5330. WFIFOL(fd,8) = vsd->vender_id;
  5331. #endif
  5332. for( i = 0; i < count; i++ )
  5333. {
  5334. int index = vending[i].index;
  5335. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5336. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5337. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5338. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5339. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5340. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5341. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5342. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5343. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5344. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5345. }
  5346. WFIFOSET(fd,WFIFOW(fd,2));
  5347. }
  5348. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5349. /// 0135 <index>.W <amount>.W <result>.B
  5350. /// result:
  5351. /// 0 = success
  5352. /// 1 = not enough zeny
  5353. /// 2 = overweight
  5354. /// 4 = out of stock
  5355. /// 5 = "cannot use an npc shop while in a trade"
  5356. /// 6 = Because the store information was incorrect the item was not purchased.
  5357. /// 7 = No sales information.
  5358. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5359. {
  5360. int fd;
  5361. nullpo_retv(sd);
  5362. fd = sd->fd;
  5363. WFIFOHEAD(fd,packet_len(0x135));
  5364. WFIFOW(fd,0) = 0x135;
  5365. WFIFOW(fd,2) = index+2;
  5366. WFIFOW(fd,4) = amount;
  5367. WFIFOB(fd,6) = fail;
  5368. WFIFOSET(fd,packet_len(0x135));
  5369. }
  5370. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5371. /// 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 }*
  5372. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5373. {
  5374. int i,fd;
  5375. int count;
  5376. nullpo_retv(sd);
  5377. fd = sd->fd;
  5378. count = sd->vend_num;
  5379. WFIFOHEAD(fd, 8+count*22);
  5380. WFIFOW(fd,0) = 0x136;
  5381. WFIFOW(fd,2) = 8+count*22;
  5382. WFIFOL(fd,4) = id;
  5383. for( i = 0; i < count; i++ )
  5384. {
  5385. int index = vending[i].index;
  5386. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5387. WFIFOL(fd, 8+i*22) = vending[i].value;
  5388. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5389. WFIFOW(fd,14+i*22) = vending[i].amount;
  5390. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5391. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5392. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5393. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5394. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5395. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5396. }
  5397. WFIFOSET(fd,WFIFOW(fd,2));
  5398. }
  5399. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5400. /// 0137 <index>.W <amount>.W
  5401. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5402. {
  5403. int fd;
  5404. nullpo_retv(sd);
  5405. fd = sd->fd;
  5406. WFIFOHEAD(fd,packet_len(0x137));
  5407. WFIFOW(fd,0) = 0x137;
  5408. WFIFOW(fd,2) = index+2;
  5409. WFIFOW(fd,4) = amount;
  5410. WFIFOSET(fd,packet_len(0x137));
  5411. }
  5412. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5413. /// 00fa <result>.B
  5414. /// result:
  5415. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5416. /// 1 = MsgStringTable[78]="party name already exists"
  5417. /// 2 = MsgStringTable[79]="already in a party"
  5418. /// 3 = cannot organize parties on this map
  5419. /// ? = nothing
  5420. void clif_party_created(struct map_session_data *sd,int result)
  5421. {
  5422. int fd;
  5423. nullpo_retv(sd);
  5424. fd=sd->fd;
  5425. WFIFOHEAD(fd,packet_len(0xfa));
  5426. WFIFOW(fd,0)=0xfa;
  5427. WFIFOB(fd,2)=result;
  5428. WFIFOSET(fd,packet_len(0xfa));
  5429. }
  5430. /// Adds new member to a party.
  5431. /// 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)
  5432. /// 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)
  5433. /// role:
  5434. /// 0 = leader
  5435. /// 1 = normal
  5436. /// state:
  5437. /// 0 = connected
  5438. /// 1 = disconnected
  5439. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5440. {
  5441. unsigned char buf[81];
  5442. int i;
  5443. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5444. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5445. } else {
  5446. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5447. }
  5448. if (i >= MAX_PARTY) return; //Should never happen...
  5449. sd = p->data[i].sd;
  5450. WBUFW(buf, 0) = 0x1e9;
  5451. WBUFL(buf, 2) = sd->status.account_id;
  5452. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5453. WBUFW(buf,10) = sd->bl.x;
  5454. WBUFW(buf,12) = sd->bl.y;
  5455. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5456. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5457. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5458. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5459. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5460. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5461. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5462. }
  5463. /// Sends party information (ZC_GROUP_LIST).
  5464. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5465. /// role:
  5466. /// 0 = leader
  5467. /// 1 = normal
  5468. /// state:
  5469. /// 0 = connected
  5470. /// 1 = disconnected
  5471. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5472. {
  5473. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5474. struct map_session_data* party_sd = NULL;
  5475. int i, c;
  5476. nullpo_retv(p);
  5477. WBUFW(buf,0) = 0xfb;
  5478. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5479. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5480. {
  5481. struct party_member* m = &p->party.member[i];
  5482. if(!m->account_id) continue;
  5483. if(party_sd == NULL) party_sd = p->data[i].sd;
  5484. WBUFL(buf,28+c*46) = m->account_id;
  5485. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5486. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5487. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5488. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5489. c++;
  5490. }
  5491. WBUFW(buf,2) = 28+c*46;
  5492. if(sd) { // send only to self
  5493. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5494. } else if (party_sd) { // send to whole party
  5495. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5496. }
  5497. }
  5498. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5499. /// 02c9 <flag>.B
  5500. /// flag:
  5501. /// 0 = allow party invites
  5502. /// 1 = auto-deny party invites
  5503. void clif_partyinvitationstate(struct map_session_data* sd)
  5504. {
  5505. int fd;
  5506. nullpo_retv(sd);
  5507. fd = sd->fd;
  5508. WFIFOHEAD(fd, packet_len(0x2c9));
  5509. WFIFOW(fd, 0) = 0x2c9;
  5510. WFIFOB(fd, 2) = 0; // not implemented
  5511. WFIFOSET(fd, packet_len(0x2c9));
  5512. }
  5513. /// Party invitation request.
  5514. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5515. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5516. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5517. {
  5518. #if PACKETVER < 20070821
  5519. const int cmd = 0xfe;
  5520. #else
  5521. const int cmd = 0x2c6;
  5522. #endif
  5523. int fd;
  5524. struct party_data *p;
  5525. nullpo_retv(sd);
  5526. nullpo_retv(tsd);
  5527. fd=tsd->fd;
  5528. if( (p=party_search(sd->status.party_id))==NULL )
  5529. return;
  5530. WFIFOHEAD(fd,packet_len(cmd));
  5531. WFIFOW(fd,0)=cmd;
  5532. WFIFOL(fd,2)=sd->status.party_id;
  5533. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5534. WFIFOSET(fd,packet_len(cmd));
  5535. }
  5536. /// Party invite result.
  5537. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5538. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5539. /// result=0 : char is already in a party -> MsgStringTable[80]
  5540. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5541. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5542. /// result=3 : party is full -> MsgStringTable[83]
  5543. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5544. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5545. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5546. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5547. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5548. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5549. {
  5550. int fd;
  5551. nullpo_retv(sd);
  5552. fd=sd->fd;
  5553. #if PACKETVER < 20070904
  5554. if( result == 7 ) {
  5555. clif_displaymessage(fd, msg_txt(3));
  5556. return;
  5557. }
  5558. #endif
  5559. #if PACKETVER < 20070821
  5560. WFIFOHEAD(fd,packet_len(0xfd));
  5561. WFIFOW(fd,0) = 0xfd;
  5562. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5563. WFIFOB(fd,26) = result;
  5564. WFIFOSET(fd,packet_len(0xfd));
  5565. #else
  5566. WFIFOHEAD(fd,packet_len(0x2c5));
  5567. WFIFOW(fd,0) = 0x2c5;
  5568. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5569. WFIFOL(fd,26) = result;
  5570. WFIFOSET(fd,packet_len(0x2c5));
  5571. #endif
  5572. }
  5573. /// Updates party settings.
  5574. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5575. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5576. /// exp option:
  5577. /// 0 = exp sharing disabled
  5578. /// 1 = exp sharing enabled
  5579. /// 2 = cannot change exp sharing
  5580. ///
  5581. /// flag:
  5582. /// 0 = send to party
  5583. /// 1 = send to sd
  5584. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5585. {
  5586. unsigned char buf[16];
  5587. #if PACKETVER < 20090603
  5588. const int cmd = 0x101;
  5589. #else
  5590. const int cmd = 0x7d8;
  5591. #endif
  5592. nullpo_retv(p);
  5593. if(!sd && flag==0){
  5594. int i;
  5595. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5596. if (i < MAX_PARTY)
  5597. sd = p->data[i].sd;
  5598. }
  5599. if(!sd) return;
  5600. WBUFW(buf,0)=cmd;
  5601. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5602. #if PACKETVER >= 20090603
  5603. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5604. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5605. #endif
  5606. if(flag==0)
  5607. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5608. else
  5609. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5610. }
  5611. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5612. /// result:
  5613. /// 0 = leave
  5614. /// 1 = expel
  5615. /// 2 = cannot leave party on this map
  5616. /// 3 = cannot expel from party on this map
  5617. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5618. {
  5619. unsigned char buf[64];
  5620. int i;
  5621. nullpo_retv(p);
  5622. if(!sd && (flag&0xf0)==0)
  5623. {
  5624. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5625. if (i < MAX_PARTY)
  5626. sd = p->data[i].sd;
  5627. }
  5628. if(!sd) return;
  5629. WBUFW(buf,0)=0x105;
  5630. WBUFL(buf,2)=account_id;
  5631. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5632. WBUFB(buf,30)=flag&0x0f;
  5633. if((flag&0xf0)==0)
  5634. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5635. else
  5636. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5637. }
  5638. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5639. /// 0109 <packet len>.W <account id>.L <message>.?B
  5640. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5641. {
  5642. struct map_session_data *sd;
  5643. int i;
  5644. nullpo_retv(p);
  5645. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5646. if(i < MAX_PARTY){
  5647. unsigned char buf[1024];
  5648. if( len > sizeof(buf)-8 )
  5649. {
  5650. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  5651. len = sizeof(buf)-8;
  5652. }
  5653. sd = p->data[i].sd;
  5654. WBUFW(buf,0)=0x109;
  5655. WBUFW(buf,2)=len+8;
  5656. WBUFL(buf,4)=account_id;
  5657. safestrncpy((char *)WBUFP(buf,8), mes, len);
  5658. clif_send(buf,len+8,&sd->bl,PARTY);
  5659. }
  5660. }
  5661. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5662. /// 0107 <account id>.L <x>.W <y>.W
  5663. void clif_party_xy(struct map_session_data *sd)
  5664. {
  5665. unsigned char buf[16];
  5666. nullpo_retv(sd);
  5667. WBUFW(buf,0)=0x107;
  5668. WBUFL(buf,2)=sd->status.account_id;
  5669. WBUFW(buf,6)=sd->bl.x;
  5670. WBUFW(buf,8)=sd->bl.y;
  5671. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5672. }
  5673. /*==========================================
  5674. * Sends x/y dot to a single fd. [Skotlex]
  5675. *------------------------------------------*/
  5676. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5677. {
  5678. WFIFOHEAD(fd,packet_len(0x107));
  5679. WFIFOW(fd,0)=0x107;
  5680. WFIFOL(fd,2)=sd->status.account_id;
  5681. WFIFOW(fd,6)=sd->bl.x;
  5682. WFIFOW(fd,8)=sd->bl.y;
  5683. WFIFOSET(fd,packet_len(0x107));
  5684. }
  5685. /// Updates HP bar of a party member.
  5686. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5687. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5688. void clif_party_hp(struct map_session_data *sd)
  5689. {
  5690. unsigned char buf[16];
  5691. #if PACKETVER < 20100126
  5692. const int cmd = 0x106;
  5693. #else
  5694. const int cmd = 0x80e;
  5695. #endif
  5696. nullpo_retv(sd);
  5697. WBUFW(buf,0)=cmd;
  5698. WBUFL(buf,2)=sd->status.account_id;
  5699. #if PACKETVER < 20100126
  5700. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5701. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5702. WBUFW(buf,8) = 100;
  5703. } else {
  5704. WBUFW(buf,6) = sd->battle_status.hp;
  5705. WBUFW(buf,8) = sd->battle_status.max_hp;
  5706. }
  5707. #else
  5708. WBUFL(buf,6) = sd->battle_status.hp;
  5709. WBUFL(buf,10) = sd->battle_status.max_hp;
  5710. #endif
  5711. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5712. }
  5713. /*==========================================
  5714. * Sends HP bar to a single fd. [Skotlex]
  5715. *------------------------------------------*/
  5716. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5717. {
  5718. #if PACKETVER < 20100126
  5719. const int cmd = 0x106;
  5720. #else
  5721. const int cmd = 0x80e;
  5722. #endif
  5723. WFIFOHEAD(fd,packet_len(cmd));
  5724. WFIFOW(fd,0) = cmd;
  5725. WFIFOL(fd,2) = id;
  5726. #if PACKETVER < 20100126
  5727. if( maxhp > INT16_MAX )
  5728. {// To correctly display the %hp bar. [Skotlex]
  5729. WFIFOW(fd,6) = hp/(maxhp/100);
  5730. WFIFOW(fd,8) = 100;
  5731. } else {
  5732. WFIFOW(fd,6) = hp;
  5733. WFIFOW(fd,8) = maxhp;
  5734. }
  5735. #else
  5736. WFIFOL(fd,6) = hp;
  5737. WFIFOL(fd,10) = maxhp;
  5738. #endif
  5739. WFIFOSET(fd, packet_len(cmd));
  5740. }
  5741. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5742. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5743. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5744. {
  5745. int fd;
  5746. nullpo_retv(sd);
  5747. nullpo_retv(bl);
  5748. fd=sd->fd;
  5749. WFIFOHEAD(fd,packet_len(0x139));
  5750. WFIFOW(fd, 0)=0x139;
  5751. WFIFOL(fd, 2)=bl->id;
  5752. WFIFOW(fd, 6)=bl->x;
  5753. WFIFOW(fd, 8)=bl->y;
  5754. WFIFOW(fd,10)=sd->bl.x;
  5755. WFIFOW(fd,12)=sd->bl.y;
  5756. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5757. WFIFOSET(fd,packet_len(0x139));
  5758. }
  5759. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5760. /// 018f <result>.W <name id>.W
  5761. /// result:
  5762. /// 0 = success
  5763. /// 1 = failure
  5764. /// 2 = success (alchemist)
  5765. /// 3 = failure (alchemist)
  5766. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5767. {
  5768. int view,fd;
  5769. nullpo_retv(sd);
  5770. fd = sd->fd;
  5771. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5772. WFIFOHEAD(fd,packet_len(0x18f));
  5773. WFIFOW(fd, 0)=0x18f;
  5774. WFIFOW(fd, 2)=flag;
  5775. if((view = itemdb_viewid(nameid)) > 0)
  5776. WFIFOW(fd, 4)=view;
  5777. else
  5778. WFIFOW(fd, 4)=nameid;
  5779. WFIFOSET(fd,packet_len(0x18f));
  5780. }
  5781. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5782. /// 019e
  5783. void clif_catch_process(struct map_session_data *sd)
  5784. {
  5785. int fd;
  5786. nullpo_retv(sd);
  5787. fd=sd->fd;
  5788. WFIFOHEAD(fd,packet_len(0x19e));
  5789. WFIFOW(fd,0)=0x19e;
  5790. WFIFOSET(fd,packet_len(0x19e));
  5791. }
  5792. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5793. /// 01a0 <result>.B
  5794. /// 0 = failure
  5795. /// 1 = success
  5796. void clif_pet_roulette(struct map_session_data *sd,int data)
  5797. {
  5798. int fd;
  5799. nullpo_retv(sd);
  5800. fd=sd->fd;
  5801. WFIFOHEAD(fd,packet_len(0x1a0));
  5802. WFIFOW(fd,0)=0x1a0;
  5803. WFIFOB(fd,2)=data;
  5804. WFIFOSET(fd,packet_len(0x1a0));
  5805. }
  5806. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5807. /// 01a6 <packet len>.W { <index>.W }*
  5808. void clif_sendegg(struct map_session_data *sd)
  5809. {
  5810. int i,n=0,fd;
  5811. nullpo_retv(sd);
  5812. fd=sd->fd;
  5813. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5814. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5815. clif_displaymessage(fd, msg_txt(666));
  5816. return;
  5817. }
  5818. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5819. WFIFOW(fd,0)=0x1a6;
  5820. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5821. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5822. sd->inventory_data[i]->type!=IT_PETEGG ||
  5823. sd->status.inventory[i].amount<=0)
  5824. continue;
  5825. WFIFOW(fd,n*2+4)=i+2;
  5826. n++;
  5827. }
  5828. WFIFOW(fd,2)=4+n*2;
  5829. WFIFOSET(fd,WFIFOW(fd,2));
  5830. sd->menuskill_id = SA_TAMINGMONSTER;
  5831. sd->menuskill_val = -1;
  5832. }
  5833. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5834. /// 01a4 <type>.B <id>.L <data>.L
  5835. /// type:
  5836. /// 0 = pre-init (data = 0)
  5837. /// 1 = intimacy (data = 0~4)
  5838. /// 2 = hunger (data = 0~4)
  5839. /// 3 = accessory
  5840. /// 4 = performance (data = 1~3: normal, 4: special)
  5841. /// 5 = hairstyle
  5842. ///
  5843. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5844. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5845. {
  5846. uint8 buf[16];
  5847. nullpo_retv(pd);
  5848. WBUFW(buf,0) = 0x1a4;
  5849. WBUFB(buf,2) = type;
  5850. WBUFL(buf,3) = pd->bl.id;
  5851. WBUFL(buf,7) = param;
  5852. if (sd)
  5853. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5854. else
  5855. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5856. }
  5857. /// Pet's base data (ZC_PROPERTY_PET).
  5858. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5859. void clif_send_petstatus(struct map_session_data *sd)
  5860. {
  5861. int fd;
  5862. struct s_pet *pet;
  5863. nullpo_retv(sd);
  5864. nullpo_retv(sd->pd);
  5865. fd=sd->fd;
  5866. pet = &sd->pd->pet;
  5867. WFIFOHEAD(fd,packet_len(0x1a2));
  5868. WFIFOW(fd,0)=0x1a2;
  5869. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5870. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5871. WFIFOW(fd,27)=pet->level;
  5872. WFIFOW(fd,29)=pet->hungry;
  5873. WFIFOW(fd,31)=pet->intimate;
  5874. WFIFOW(fd,33)=pet->equip;
  5875. #if PACKETVER >= 20081126
  5876. WFIFOW(fd,35)=pet->class_;
  5877. #endif
  5878. WFIFOSET(fd,packet_len(0x1a2));
  5879. }
  5880. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5881. /// 01aa <id>.L <data>.L
  5882. /// data:
  5883. /// @see CZ_PET_ACT.
  5884. void clif_pet_emotion(struct pet_data *pd,int param)
  5885. {
  5886. unsigned char buf[16];
  5887. nullpo_retv(pd);
  5888. memset(buf,0,packet_len(0x1aa));
  5889. WBUFW(buf,0)=0x1aa;
  5890. WBUFL(buf,2)=pd->bl.id;
  5891. if(param >= 100 && pd->petDB->talk_convert_class) {
  5892. if(pd->petDB->talk_convert_class < 0)
  5893. return;
  5894. else if(pd->petDB->talk_convert_class > 0) {
  5895. // replace mob_id component of talk/act data
  5896. param -= (pd->pet.class_ - 100)*100;
  5897. param += (pd->petDB->talk_convert_class - 100)*100;
  5898. }
  5899. }
  5900. WBUFL(buf,6)=param;
  5901. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5902. }
  5903. /// Result of request to feed a pet (ZC_FEED_PET).
  5904. /// 01a3 <result>.B <name id>.W
  5905. /// result:
  5906. /// 0 = failure
  5907. /// 1 = success
  5908. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5909. {
  5910. int fd;
  5911. nullpo_retv(sd);
  5912. fd=sd->fd;
  5913. WFIFOHEAD(fd,packet_len(0x1a3));
  5914. WFIFOW(fd,0)=0x1a3;
  5915. WFIFOB(fd,2)=fail;
  5916. WFIFOW(fd,3)=foodid;
  5917. WFIFOSET(fd,packet_len(0x1a3));
  5918. }
  5919. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5920. /// 01cd { <skill id>.L }*7
  5921. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  5922. {
  5923. int fd;
  5924. nullpo_retv(sd);
  5925. fd=sd->fd;
  5926. WFIFOHEAD(fd,packet_len(0x1cd));
  5927. WFIFOW(fd, 0)=0x1cd;
  5928. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5929. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5930. else
  5931. WFIFOL(fd,2)= 0x00000000;
  5932. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5933. WFIFOL(fd,6)= MG_COLDBOLT;
  5934. else
  5935. WFIFOL(fd,6)= 0x00000000;
  5936. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5937. WFIFOL(fd,10)= MG_FIREBOLT;
  5938. else
  5939. WFIFOL(fd,10)= 0x00000000;
  5940. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5941. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5942. else
  5943. WFIFOL(fd,14)= 0x00000000;
  5944. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5945. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5946. else
  5947. WFIFOL(fd,18)= 0x00000000;
  5948. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5949. WFIFOL(fd,22)= MG_FIREBALL;
  5950. else
  5951. WFIFOL(fd,22)= 0x00000000;
  5952. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5953. WFIFOL(fd,26)= MG_FROSTDIVER;
  5954. else
  5955. WFIFOL(fd,26)= 0x00000000;
  5956. WFIFOSET(fd,packet_len(0x1cd));
  5957. sd->menuskill_id = SA_AUTOSPELL;
  5958. sd->menuskill_val = skill_lv;
  5959. }
  5960. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5961. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5962. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5963. {
  5964. unsigned char buf[56];
  5965. int i;
  5966. nullpo_retv(src);
  5967. memset(buf,0,packet_len(0x1cf));
  5968. WBUFW(buf,0) = 0x1cf;
  5969. WBUFL(buf,2) = src->id;
  5970. if( src->type == BL_MER )
  5971. {
  5972. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5973. if( md && md->master && md->devotion_flag )
  5974. WBUFL(buf,6) = md->master->bl.id;
  5975. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5976. }
  5977. else
  5978. {
  5979. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5980. if( sd == NULL )
  5981. return;
  5982. for( i = 0; i < 5; i++ )
  5983. WBUFL(buf,6+4*i) = sd->devotion[i];
  5984. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5985. }
  5986. if( tsd )
  5987. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5988. else
  5989. clif_send(buf, packet_len(0x1cf), src, AREA);
  5990. }
  5991. /*==========================================
  5992. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  5993. * Notifies clients in an area of an object's spirits.
  5994. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  5995. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  5996. *------------------------------------------*/
  5997. void clif_spiritball(struct block_list *bl) {
  5998. unsigned char buf[16];
  5999. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6000. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6001. nullpo_retv(bl);
  6002. WBUFW(buf, 0) = 0x1d0;
  6003. WBUFL(buf, 2) = bl->id;
  6004. WBUFW(buf, 6) = 0; //init to 0
  6005. switch(bl->type){
  6006. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6007. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6008. }
  6009. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6010. }
  6011. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6012. /// 01d2 <account id>.L <delay>.L
  6013. void clif_combo_delay(struct block_list *bl,int wait)
  6014. {
  6015. unsigned char buf[32];
  6016. nullpo_retv(bl);
  6017. WBUFW(buf,0)=0x1d2;
  6018. WBUFL(buf,2)=bl->id;
  6019. WBUFL(buf,6)=wait;
  6020. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6021. }
  6022. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6023. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6024. /// flag:
  6025. /// 0 = inactive
  6026. /// 1 = active
  6027. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6028. {
  6029. unsigned char buf[32];
  6030. nullpo_retv(src);
  6031. WBUFW(buf,0)=0x1d1;
  6032. WBUFL(buf,2)=src->id;
  6033. WBUFL(buf,6)=dst_id;
  6034. WBUFL(buf,10)=active;
  6035. clif_send(buf,packet_len(0x1d1),src,AREA);
  6036. }
  6037. /// MVP effect (ZC_MVP).
  6038. /// 010c <account id>.L
  6039. void clif_mvp_effect(struct map_session_data *sd)
  6040. {
  6041. unsigned char buf[16];
  6042. nullpo_retv(sd);
  6043. WBUFW(buf,0)=0x10c;
  6044. WBUFL(buf,2)=sd->bl.id;
  6045. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6046. }
  6047. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6048. /// 010a <name id>.W
  6049. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6050. {
  6051. int view,fd;
  6052. nullpo_retv(sd);
  6053. fd=sd->fd;
  6054. WFIFOHEAD(fd,packet_len(0x10a));
  6055. WFIFOW(fd,0)=0x10a;
  6056. if((view = itemdb_viewid(nameid)) > 0)
  6057. WFIFOW(fd,2)=view;
  6058. else
  6059. WFIFOW(fd,2)=nameid;
  6060. WFIFOSET(fd,packet_len(0x10a));
  6061. }
  6062. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6063. /// 010b <exp>.L
  6064. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6065. {
  6066. int fd;
  6067. nullpo_retv(sd);
  6068. fd=sd->fd;
  6069. WFIFOHEAD(fd,packet_len(0x10b));
  6070. WFIFOW(fd,0)=0x10b;
  6071. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6072. WFIFOSET(fd,packet_len(0x10b));
  6073. }
  6074. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6075. /// 010d
  6076. ///
  6077. /// "You are the MVP, but cannot obtain the reward because
  6078. /// you are overweight."
  6079. void clif_mvp_noitem(struct map_session_data* sd)
  6080. {
  6081. int fd = sd->fd;
  6082. WFIFOHEAD(fd,packet_len(0x10d));
  6083. WFIFOW(fd,0) = 0x10d;
  6084. WFIFOSET(fd,packet_len(0x10d));
  6085. }
  6086. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6087. /// 0167 <result>.B
  6088. /// result:
  6089. /// 0 = "Guild has been created."
  6090. /// 1 = "You are already in a Guild."
  6091. /// 2 = "That Guild Name already exists."
  6092. /// 3 = "You need the neccessary item to create a Guild."
  6093. void clif_guild_created(struct map_session_data *sd,int flag)
  6094. {
  6095. int fd;
  6096. nullpo_retv(sd);
  6097. fd=sd->fd;
  6098. WFIFOHEAD(fd,packet_len(0x167));
  6099. WFIFOW(fd,0)=0x167;
  6100. WFIFOB(fd,2)=flag;
  6101. WFIFOSET(fd,packet_len(0x167));
  6102. }
  6103. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6104. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6105. /// mode:
  6106. /// &0x01 = allow invite
  6107. /// &0x10 = allow expel
  6108. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6109. {
  6110. int ps,fd;
  6111. nullpo_retv(sd);
  6112. nullpo_retv(g);
  6113. fd=sd->fd;
  6114. ps=guild_getposition(g,sd);
  6115. WFIFOHEAD(fd,packet_len(0x16c));
  6116. WFIFOW(fd,0)=0x16c;
  6117. WFIFOL(fd,2)=g->guild_id;
  6118. WFIFOL(fd,6)=g->emblem_id;
  6119. WFIFOL(fd,10)=g->position[ps].mode;
  6120. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6121. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6122. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6123. WFIFOSET(fd,packet_len(0x16c));
  6124. }
  6125. /// Guild member login notice.
  6126. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6127. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6128. /// status:
  6129. /// 0 = offline
  6130. /// 1 = online
  6131. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6132. {
  6133. unsigned char buf[64];
  6134. struct map_session_data* sd;
  6135. nullpo_retv(g);
  6136. WBUFW(buf, 0)=0x1f2;
  6137. WBUFL(buf, 2)=g->member[idx].account_id;
  6138. WBUFL(buf, 6)=g->member[idx].char_id;
  6139. WBUFL(buf,10)=flag;
  6140. if( ( sd = g->member[idx].sd ) != NULL )
  6141. {
  6142. WBUFW(buf,14) = sd->status.sex;
  6143. WBUFW(buf,16) = sd->status.hair;
  6144. WBUFW(buf,18) = sd->status.hair_color;
  6145. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6146. }
  6147. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6148. {
  6149. WBUFW(buf,14) = 0;
  6150. WBUFW(buf,16) = 0;
  6151. WBUFW(buf,18) = 0;
  6152. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6153. }
  6154. }
  6155. // Function `clif_guild_memberlogin_notice` sends info about
  6156. // logins and logouts of a guild member to the rest members.
  6157. // But at the 1st time (after a player login or map changing)
  6158. // the client won't show the message.
  6159. // So I suggest use this function for sending "first-time-info"
  6160. // to some player on entering the game or changing location.
  6161. // At next time the client would always show the message.
  6162. // The function sends all the statuses in the single packet
  6163. // to economize traffic. [LuzZza]
  6164. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6165. {
  6166. struct guild *g;
  6167. unsigned char buf[14*128];
  6168. int i, count=0, p_len;
  6169. nullpo_retv(sd);
  6170. p_len = packet_len(0x16d);
  6171. if(!(g = guild_search(sd->status.guild_id)))
  6172. return;
  6173. for(i=0; i<g->max_member; i++) {
  6174. if(g->member[i].account_id > 0 &&
  6175. g->member[i].account_id != sd->status.account_id) {
  6176. WBUFW(buf,count*p_len) = 0x16d;
  6177. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6178. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6179. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6180. count++;
  6181. }
  6182. }
  6183. clif_send(buf, p_len*count, &sd->bl, SELF);
  6184. }
  6185. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6186. /// 014e <menu flag>.L
  6187. /// menu flag:
  6188. /// 0x00 = Basic Info (always on)
  6189. /// &0x01 = Member manager
  6190. /// &0x02 = Positions
  6191. /// &0x04 = Skills
  6192. /// &0x10 = Expulsion list
  6193. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6194. /// &0x80 = Notice
  6195. void clif_guild_masterormember(struct map_session_data *sd)
  6196. {
  6197. int fd;
  6198. nullpo_retv(sd);
  6199. fd=sd->fd;
  6200. WFIFOHEAD(fd,packet_len(0x14e));
  6201. WFIFOW(fd,0) = 0x14e;
  6202. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6203. WFIFOSET(fd,packet_len(0x14e));
  6204. }
  6205. /// Guild basic information (Territories [Valaris])
  6206. /// 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)
  6207. /// 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)
  6208. void clif_guild_basicinfo(struct map_session_data *sd) {
  6209. int fd;
  6210. struct guild *g;
  6211. nullpo_retv(sd);
  6212. fd = sd->fd;
  6213. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6214. return;
  6215. WFIFOHEAD(fd,packet_len(0x1b6));
  6216. WFIFOW(fd, 0)=0x1b6;//0x150;
  6217. WFIFOL(fd, 2)=g->guild_id;
  6218. WFIFOL(fd, 6)=g->guild_lv;
  6219. WFIFOL(fd,10)=g->connect_member;
  6220. WFIFOL(fd,14)=g->max_member;
  6221. WFIFOL(fd,18)=g->average_lv;
  6222. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6223. WFIFOL(fd,26)=g->next_exp;
  6224. WFIFOL(fd,30)=0; // Tax Points
  6225. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6226. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6227. WFIFOL(fd,42)=g->emblem_id;
  6228. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6229. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6230. safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
  6231. WFIFOL(fd,110) = 0; // zeny
  6232. WFIFOSET(fd,packet_len(0x1b6));
  6233. }
  6234. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6235. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6236. void clif_guild_allianceinfo(struct map_session_data *sd)
  6237. {
  6238. int fd,i,c;
  6239. struct guild *g;
  6240. nullpo_retv(sd);
  6241. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6242. return;
  6243. fd = sd->fd;
  6244. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6245. WFIFOW(fd, 0)=0x14c;
  6246. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6247. struct guild_alliance *a=&g->alliance[i];
  6248. if(a->guild_id>0){
  6249. WFIFOL(fd,c*32+4)=a->opposition;
  6250. WFIFOL(fd,c*32+8)=a->guild_id;
  6251. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6252. c++;
  6253. }
  6254. }
  6255. WFIFOW(fd, 2)=c*32+4;
  6256. WFIFOSET(fd,WFIFOW(fd,2));
  6257. }
  6258. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6259. /// 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 }*
  6260. /// state:
  6261. /// 0 = offline
  6262. /// 1 = online
  6263. /// memo:
  6264. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6265. void clif_guild_memberlist(struct map_session_data *sd)
  6266. {
  6267. int fd;
  6268. int i,c;
  6269. struct guild *g;
  6270. nullpo_retv(sd);
  6271. if( (fd = sd->fd) == 0 )
  6272. return;
  6273. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6274. return;
  6275. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6276. WFIFOW(fd, 0)=0x154;
  6277. for(i=0,c=0;i<g->max_member;i++){
  6278. struct guild_member *m=&g->member[i];
  6279. if(m->account_id==0)
  6280. continue;
  6281. WFIFOL(fd,c*104+ 4)=m->account_id;
  6282. WFIFOL(fd,c*104+ 8)=m->char_id;
  6283. WFIFOW(fd,c*104+12)=m->hair;
  6284. WFIFOW(fd,c*104+14)=m->hair_color;
  6285. WFIFOW(fd,c*104+16)=m->gender;
  6286. WFIFOW(fd,c*104+18)=m->class_;
  6287. WFIFOW(fd,c*104+20)=m->lv;
  6288. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6289. WFIFOL(fd,c*104+26)=m->online;
  6290. WFIFOL(fd,c*104+30)=m->position;
  6291. 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.
  6292. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6293. c++;
  6294. }
  6295. WFIFOW(fd, 2)=c*104+4;
  6296. WFIFOSET(fd,WFIFOW(fd,2));
  6297. }
  6298. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6299. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6300. void clif_guild_positionnamelist(struct map_session_data *sd)
  6301. {
  6302. int i,fd;
  6303. struct guild *g;
  6304. nullpo_retv(sd);
  6305. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6306. return;
  6307. fd = sd->fd;
  6308. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6309. WFIFOW(fd, 0)=0x166;
  6310. for(i=0;i<MAX_GUILDPOSITION;i++){
  6311. WFIFOL(fd,i*28+4)=i;
  6312. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6313. }
  6314. WFIFOW(fd,2)=i*28+4;
  6315. WFIFOSET(fd,WFIFOW(fd,2));
  6316. }
  6317. /// Guild position information (ZC_POSITION_INFO).
  6318. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6319. /// mode:
  6320. /// &0x01 = allow invite
  6321. /// &0x10 = allow expel
  6322. /// ranking:
  6323. /// TODO
  6324. void clif_guild_positioninfolist(struct map_session_data *sd)
  6325. {
  6326. int i,fd;
  6327. struct guild *g;
  6328. nullpo_retv(sd);
  6329. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6330. return;
  6331. fd = sd->fd;
  6332. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6333. WFIFOW(fd, 0)=0x160;
  6334. for(i=0;i<MAX_GUILDPOSITION;i++){
  6335. struct guild_position *p=&g->position[i];
  6336. WFIFOL(fd,i*16+ 4)=i;
  6337. WFIFOL(fd,i*16+ 8)=p->mode;
  6338. WFIFOL(fd,i*16+12)=i;
  6339. WFIFOL(fd,i*16+16)=p->exp_mode;
  6340. }
  6341. WFIFOW(fd, 2)=i*16+4;
  6342. WFIFOSET(fd,WFIFOW(fd,2));
  6343. }
  6344. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6345. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6346. /// mode:
  6347. /// &0x01 = allow invite
  6348. /// &0x10 = allow expel
  6349. /// ranking:
  6350. /// TODO
  6351. void clif_guild_positionchanged(struct guild *g,int idx)
  6352. {
  6353. // FIXME: This packet is intended to update the clients after a
  6354. // commit of position info changes, not sending one packet per
  6355. // position.
  6356. struct map_session_data *sd;
  6357. unsigned char buf[128];
  6358. nullpo_retv(g);
  6359. WBUFW(buf, 0)=0x174;
  6360. WBUFW(buf, 2)=44; // packet len
  6361. // GUILD_REG_POSITION_INFO{
  6362. WBUFL(buf, 4)=idx;
  6363. WBUFL(buf, 8)=g->position[idx].mode;
  6364. WBUFL(buf,12)=idx;
  6365. WBUFL(buf,16)=g->position[idx].exp_mode;
  6366. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6367. // }*
  6368. if( (sd=guild_getavailablesd(g))!=NULL )
  6369. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6370. }
  6371. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6372. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6373. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6374. {
  6375. // FIXME: This packet is intended to update the clients after a
  6376. // commit of member position assignment changes, not sending one
  6377. // packet per position.
  6378. struct map_session_data *sd;
  6379. unsigned char buf[64];
  6380. nullpo_retv(g);
  6381. WBUFW(buf, 0)=0x156;
  6382. WBUFW(buf, 2)=16; // packet len
  6383. // MEMBER_POSITION_INFO{
  6384. WBUFL(buf, 4)=g->member[idx].account_id;
  6385. WBUFL(buf, 8)=g->member[idx].char_id;
  6386. WBUFL(buf,12)=g->member[idx].position;
  6387. // }*
  6388. if( (sd=guild_getavailablesd(g))!=NULL )
  6389. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6390. }
  6391. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6392. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6393. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6394. {
  6395. int fd;
  6396. nullpo_retv(sd);
  6397. nullpo_retv(g);
  6398. fd = sd->fd;
  6399. if( g->emblem_len <= 0 )
  6400. return;
  6401. WFIFOHEAD(fd,g->emblem_len+12);
  6402. WFIFOW(fd,0)=0x152;
  6403. WFIFOW(fd,2)=g->emblem_len+12;
  6404. WFIFOL(fd,4)=g->guild_id;
  6405. WFIFOL(fd,8)=g->emblem_id;
  6406. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6407. WFIFOSET(fd,WFIFOW(fd,2));
  6408. }
  6409. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6410. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6411. void clif_guild_emblem_area(struct block_list* bl)
  6412. {
  6413. uint8 buf[12];
  6414. nullpo_retv(bl);
  6415. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6416. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6417. WBUFW(buf,0) = 0x1b4;
  6418. WBUFL(buf,2) = bl->id;
  6419. WBUFL(buf,6) = status_get_guild_id(bl);
  6420. WBUFW(buf,10) = status_get_emblem_id(bl);
  6421. clif_send(buf, 12, bl, AREA_WOS);
  6422. }
  6423. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6424. /// 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 }*
  6425. void clif_guild_skillinfo(struct map_session_data* sd)
  6426. {
  6427. int fd;
  6428. struct guild* g;
  6429. int i,c;
  6430. nullpo_retv(sd);
  6431. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6432. return;
  6433. fd = sd->fd;
  6434. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6435. WFIFOW(fd,0) = 0x0162;
  6436. WFIFOW(fd,4) = g->skill_point;
  6437. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6438. {
  6439. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6440. {
  6441. int id = g->skill[i].id;
  6442. int p = 6 + c*37;
  6443. WFIFOW(fd,p+0) = id;
  6444. WFIFOL(fd,p+2) = skill_get_inf(id);
  6445. WFIFOW(fd,p+6) = g->skill[i].lv;
  6446. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6447. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6448. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6449. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6450. c++;
  6451. }
  6452. }
  6453. WFIFOW(fd,2) = 6 + c*37;
  6454. WFIFOSET(fd,WFIFOW(fd,2));
  6455. }
  6456. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6457. /// 016f <subject>.60B <notice>.120B
  6458. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6459. {
  6460. int fd;
  6461. nullpo_retv(sd);
  6462. nullpo_retv(g);
  6463. fd = sd->fd;
  6464. if ( !session_isActive(fd) )
  6465. return;
  6466. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6467. return;
  6468. WFIFOHEAD(fd,packet_len(0x16f));
  6469. WFIFOW(fd,0) = 0x16f;
  6470. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6471. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6472. WFIFOSET(fd,packet_len(0x16f));
  6473. }
  6474. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6475. /// 016a <guild id>.L <guild name>.24B
  6476. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6477. {
  6478. int fd;
  6479. nullpo_retv(sd);
  6480. nullpo_retv(g);
  6481. fd=sd->fd;
  6482. WFIFOHEAD(fd,packet_len(0x16a));
  6483. WFIFOW(fd,0)=0x16a;
  6484. WFIFOL(fd,2)=g->guild_id;
  6485. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6486. WFIFOSET(fd,packet_len(0x16a));
  6487. }
  6488. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6489. /// 0169 <answer>.B
  6490. /// answer:
  6491. /// 0 = Already in guild.
  6492. /// 1 = Offer rejected.
  6493. /// 2 = Offer accepted.
  6494. /// 3 = Guild full.
  6495. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6496. {
  6497. int fd;
  6498. nullpo_retv(sd);
  6499. fd=sd->fd;
  6500. WFIFOHEAD(fd,packet_len(0x169));
  6501. WFIFOW(fd,0)=0x169;
  6502. WFIFOB(fd,2)=flag;
  6503. WFIFOSET(fd,packet_len(0x169));
  6504. }
  6505. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6506. /// 015a <char name>.24B <reason>.40B
  6507. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6508. {
  6509. unsigned char buf[128];
  6510. nullpo_retv(sd);
  6511. WBUFW(buf, 0)=0x15a;
  6512. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6513. memcpy(WBUFP(buf,26),mes,40);
  6514. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6515. }
  6516. /// Notifies clients of a guild of an expelled member.
  6517. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6518. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6519. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6520. {
  6521. unsigned char buf[128];
  6522. #if PACKETVER < 20100803
  6523. const unsigned short cmd = 0x15c;
  6524. #else
  6525. const unsigned short cmd = 0x839;
  6526. #endif
  6527. nullpo_retv(sd);
  6528. WBUFW(buf,0) = cmd;
  6529. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6530. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6531. #if PACKETVER < 20100803
  6532. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6533. #endif
  6534. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6535. }
  6536. /// Guild expulsion list (ZC_BAN_LIST).
  6537. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6538. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6539. void clif_guild_expulsionlist(struct map_session_data* sd)
  6540. {
  6541. #if PACKETVER < 20100803
  6542. const int offset = NAME_LENGTH*2+40;
  6543. #else
  6544. const int offset = NAME_LENGTH+40;
  6545. #endif
  6546. int fd, i, c = 0;
  6547. struct guild* g;
  6548. nullpo_retv(sd);
  6549. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6550. return;
  6551. fd = sd->fd;
  6552. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6553. WFIFOW(fd,0) = 0x163;
  6554. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6555. {
  6556. struct guild_expulsion* e = &g->expulsion[i];
  6557. if( e->account_id > 0 )
  6558. {
  6559. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6560. #if PACKETVER < 20100803
  6561. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6562. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6563. #else
  6564. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6565. #endif
  6566. c++;
  6567. }
  6568. }
  6569. WFIFOW(fd,2) = 4 + c*offset;
  6570. WFIFOSET(fd,WFIFOW(fd,2));
  6571. }
  6572. /// Guild chat message (ZC_GUILD_CHAT).
  6573. /// 017f <packet len>.W <message>.?B
  6574. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6575. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6576. struct map_session_data *sd;
  6577. uint8 buf[256];
  6578. if( len == 0 )
  6579. {
  6580. return;
  6581. }
  6582. else if( len > sizeof(buf)-5 )
  6583. {
  6584. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6585. len = sizeof(buf)-5;
  6586. }
  6587. WBUFW(buf, 0) = 0x17f;
  6588. WBUFW(buf, 2) = len + 5;
  6589. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6590. if ((sd = guild_getavailablesd(g)) != NULL)
  6591. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6592. }
  6593. /*==========================================
  6594. * Server tells client 'sd' that his guild skill 'skill_id' gone to level 'lv'
  6595. *------------------------------------------*/
  6596. int clif_guild_skillup(struct map_session_data *sd,uint16 skill_id,int lv)
  6597. {// TODO: Merge with clif_skillup (same packet).
  6598. int fd;
  6599. nullpo_ret(sd);
  6600. fd=sd->fd;
  6601. WFIFOHEAD(fd,11);
  6602. WFIFOW(fd,0) = 0x10e;
  6603. WFIFOW(fd,2) = skill_id;
  6604. WFIFOW(fd,4) = lv;
  6605. WFIFOW(fd,6) = skill_get_sp(skill_id,lv);
  6606. WFIFOW(fd,8) = skill_get_range(skill_id,lv);
  6607. WFIFOB(fd,10) = 1;
  6608. WFIFOSET(fd,11);
  6609. return 0;
  6610. }
  6611. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6612. /// 0171 <inviter account id>.L <guild name>.24B
  6613. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6614. {
  6615. int fd;
  6616. nullpo_retv(sd);
  6617. fd=sd->fd;
  6618. WFIFOHEAD(fd,packet_len(0x171));
  6619. WFIFOW(fd,0)=0x171;
  6620. WFIFOL(fd,2)=account_id;
  6621. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6622. WFIFOSET(fd,packet_len(0x171));
  6623. }
  6624. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6625. /// 0173 <answer>.B
  6626. /// answer:
  6627. /// 0 = Already allied.
  6628. /// 1 = You rejected the offer.
  6629. /// 2 = You accepted the offer.
  6630. /// 3 = They have too any alliances.
  6631. /// 4 = You have too many alliances.
  6632. /// 5 = Alliances are disabled.
  6633. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6634. {
  6635. int fd;
  6636. nullpo_retv(sd);
  6637. fd=sd->fd;
  6638. WFIFOHEAD(fd,packet_len(0x173));
  6639. WFIFOW(fd,0)=0x173;
  6640. WFIFOL(fd,2)=flag;
  6641. WFIFOSET(fd,packet_len(0x173));
  6642. }
  6643. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6644. /// 0184 <other guild id>.L <relation>.L
  6645. /// relation:
  6646. /// 0 = Ally
  6647. /// 1 = Enemy
  6648. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6649. {
  6650. int fd;
  6651. nullpo_retv(sd);
  6652. fd = sd->fd;
  6653. if (fd <= 0)
  6654. return;
  6655. WFIFOHEAD(fd,packet_len(0x184));
  6656. WFIFOW(fd,0)=0x184;
  6657. WFIFOL(fd,2)=guild_id;
  6658. WFIFOL(fd,6)=flag;
  6659. WFIFOSET(fd,packet_len(0x184));
  6660. }
  6661. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6662. /// 0181 <result>.B
  6663. /// result:
  6664. /// 0 = Antagonist has been set.
  6665. /// 1 = Guild has too many Antagonists.
  6666. /// 2 = Already set as an Antagonist.
  6667. /// 3 = Antagonists are disabled.
  6668. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6669. {
  6670. int fd;
  6671. nullpo_retv(sd);
  6672. fd=sd->fd;
  6673. WFIFOHEAD(fd,packet_len(0x181));
  6674. WFIFOW(fd,0)=0x181;
  6675. WFIFOB(fd,2)=flag;
  6676. WFIFOSET(fd,packet_len(0x181));
  6677. }
  6678. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6679. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6680. /*
  6681. void clif_guild_allianceadded(struct guild *g,int idx)
  6682. {
  6683. unsigned char buf[64];
  6684. WBUFW(buf,0)=0x185;
  6685. WBUFL(buf,2)=g->alliance[idx].opposition;
  6686. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6687. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6688. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6689. }
  6690. */
  6691. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6692. /// 015e <reason>.L
  6693. /// 0 = success
  6694. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6695. /// 2 = there are still members in the guild
  6696. void clif_guild_broken(struct map_session_data *sd,int flag)
  6697. {
  6698. int fd;
  6699. nullpo_retv(sd);
  6700. fd=sd->fd;
  6701. WFIFOHEAD(fd,packet_len(0x15e));
  6702. WFIFOW(fd,0)=0x15e;
  6703. WFIFOL(fd,2)=flag;
  6704. WFIFOSET(fd,packet_len(0x15e));
  6705. }
  6706. /// Displays emotion on an object (ZC_EMOTION).
  6707. /// 00c0 <id>.L <type>.B
  6708. /// type:
  6709. /// enum emotion_type
  6710. void clif_emotion(struct block_list *bl,int type)
  6711. {
  6712. unsigned char buf[8];
  6713. nullpo_retv(bl);
  6714. WBUFW(buf,0)=0xc0;
  6715. WBUFL(buf,2)=bl->id;
  6716. WBUFB(buf,6)=type;
  6717. clif_send(buf,packet_len(0xc0),bl,AREA);
  6718. }
  6719. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6720. /// 0191 <id>.L <contents>.80B
  6721. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6722. {
  6723. unsigned char buf[MESSAGE_SIZE+6];
  6724. nullpo_retv(bl);
  6725. WBUFW(buf,0) = 0x191;
  6726. WBUFL(buf,2) = bl->id;
  6727. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6728. clif_send(buf,packet_len(0x191),bl,AREA);
  6729. }
  6730. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6731. /// 01ea <id>.L
  6732. void clif_wedding_effect(struct block_list *bl)
  6733. {
  6734. unsigned char buf[6];
  6735. nullpo_retv(bl);
  6736. WBUFW(buf,0) = 0x1ea;
  6737. WBUFL(buf,2) = bl->id;
  6738. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6739. }
  6740. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6741. /// 01e6 <partner name>.24B
  6742. void clif_callpartner(struct map_session_data *sd)
  6743. {
  6744. unsigned char buf[26];
  6745. const char *p;
  6746. nullpo_retv(sd);
  6747. WBUFW(buf,0) = 0x1e6;
  6748. if( sd->status.partner_id )
  6749. {
  6750. if( ( p = map_charid2nick(sd->status.partner_id) ) != NULL )
  6751. {
  6752. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  6753. }
  6754. else
  6755. {
  6756. WBUFB(buf,2) = 0;
  6757. }
  6758. }
  6759. else
  6760. {// Send zero-length name if no partner, to initialize the client buffer.
  6761. WBUFB(buf,2) = 0;
  6762. }
  6763. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  6764. }
  6765. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6766. /// 01e4
  6767. /// This packet while still implemented by the client is no longer being officially used.
  6768. /*
  6769. void clif_marriage_process(struct map_session_data *sd)
  6770. {
  6771. int fd;
  6772. nullpo_retv(sd);
  6773. fd=sd->fd;
  6774. WFIFOHEAD(fd,packet_len(0x1e4));
  6775. WFIFOW(fd,0)=0x1e4;
  6776. WFIFOSET(fd,packet_len(0x1e4));
  6777. }
  6778. */
  6779. /// Notice of divorce (ZC_DIVORCE).
  6780. /// 0205 <partner name>.24B
  6781. void clif_divorced(struct map_session_data* sd, const char* name)
  6782. {
  6783. int fd;
  6784. nullpo_retv(sd);
  6785. fd=sd->fd;
  6786. WFIFOHEAD(fd,packet_len(0x205));
  6787. WFIFOW(fd,0)=0x205;
  6788. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6789. WFIFOSET(fd, packet_len(0x205));
  6790. }
  6791. /// Marriage proposal (ZC_REQ_COUPLE).
  6792. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6793. /// This packet while still implemented by the client is no longer being officially used.
  6794. /*
  6795. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6796. {
  6797. nullpo_retv(sd);
  6798. WFIFOHEAD(fd,packet_len(0x1e2));
  6799. WFIFOW(fd,0) = 0x1e2;
  6800. WFIFOL(fd,2) = ssd->status.account_id;
  6801. WFIFOL(fd,6) = ssd->status.char_id;
  6802. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6803. WFIFOSET(fd, packet_len(0x1e2));
  6804. }
  6805. */
  6806. /*==========================================
  6807. *
  6808. *------------------------------------------*/
  6809. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6810. {
  6811. clif_disp_message(&sd->bl, mes, len, SELF);
  6812. }
  6813. /*==========================================
  6814. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6815. *------------------------------------------*/
  6816. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6817. {
  6818. unsigned char buf[256];
  6819. if( len == 0 )
  6820. {
  6821. return;
  6822. }
  6823. else if( len > sizeof(buf)-5 )
  6824. {
  6825. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6826. len = sizeof(buf)-5;
  6827. }
  6828. WBUFW(buf, 0) = 0x17f;
  6829. WBUFW(buf, 2) = len + 5;
  6830. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6831. clif_send(buf, WBUFW(buf,2), src, target);
  6832. }
  6833. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6834. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6835. /// 00cd <result>.B
  6836. /// result:
  6837. /// 0 = failure
  6838. /// 1 = success
  6839. void clif_GM_kickack(struct map_session_data *sd, int id)
  6840. {
  6841. int fd;
  6842. nullpo_retv(sd);
  6843. fd = sd->fd;
  6844. WFIFOHEAD(fd,packet_len(0xcd));
  6845. WFIFOW(fd,0) = 0xcd;
  6846. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6847. WFIFOSET(fd, packet_len(0xcd));
  6848. }
  6849. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6850. {
  6851. int fd = tsd->fd;
  6852. if( fd > 0 )
  6853. clif_authfail_fd(fd, 15);
  6854. else
  6855. map_quit(tsd);
  6856. if( sd )
  6857. clif_GM_kickack(sd,tsd->status.account_id);
  6858. }
  6859. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6860. /// 014a <result>.L
  6861. /// result:
  6862. /// 0 = "A manner point has been successfully aligned."
  6863. /// 1 = MP_FAILURE_EXHAUST
  6864. /// 2 = MP_FAILURE_ALREADY_GIVING
  6865. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6866. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6867. /// 5 = "You got a good point from %s."
  6868. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6869. {
  6870. int fd;
  6871. nullpo_retv(sd);
  6872. fd = sd->fd;
  6873. WFIFOHEAD(fd,packet_len(0x14a));
  6874. WFIFOW(fd,0) = 0x14a;
  6875. WFIFOL(fd,2) = type;
  6876. WFIFOSET(fd, packet_len(0x14a));
  6877. }
  6878. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6879. /// 014b <type>.B <GM name>.24B
  6880. /// type:
  6881. /// 0 = positive (unmute)
  6882. /// 1 = negative (mute)
  6883. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6884. {
  6885. int fd;
  6886. nullpo_retv(sd);
  6887. nullpo_retv(tsd);
  6888. fd = tsd->fd;
  6889. WFIFOHEAD(fd,packet_len(0x14b));
  6890. WFIFOW(fd,0) = 0x14b;
  6891. WFIFOB(fd,2) = type;
  6892. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6893. WFIFOSET(fd, packet_len(0x14b));
  6894. }
  6895. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6896. /// 00d1 <type>.B <result>.B
  6897. /// type:
  6898. /// 0 = /ex (deny)
  6899. /// 1 = /in (allow)
  6900. /// result:
  6901. /// 0 = success
  6902. /// 1 = failure
  6903. /// 2 = too many blocks
  6904. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6905. {
  6906. int fd;
  6907. nullpo_retv(sd);
  6908. fd=sd->fd;
  6909. WFIFOHEAD(fd,packet_len(0xd1));
  6910. WFIFOW(fd,0)=0xd1;
  6911. WFIFOB(fd,2)=type;
  6912. WFIFOB(fd,3)=flag;
  6913. WFIFOSET(fd,packet_len(0xd1));
  6914. }
  6915. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6916. /// 00d2 <type>.B <result>.B
  6917. /// type:
  6918. /// 0 = /exall (deny)
  6919. /// 1 = /inall (allow)
  6920. /// result:
  6921. /// 0 = success
  6922. /// 1 = failure
  6923. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6924. {
  6925. int fd;
  6926. nullpo_retv(sd);
  6927. fd=sd->fd;
  6928. WFIFOHEAD(fd,packet_len(0xd2));
  6929. WFIFOW(fd,0)=0xd2;
  6930. WFIFOB(fd,2)=type;
  6931. WFIFOB(fd,3)=flag;
  6932. WFIFOSET(fd,packet_len(0xd2));
  6933. }
  6934. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6935. /// 07fe <bgm>.24B
  6936. void clif_playBGM(struct map_session_data* sd, const char* name)
  6937. {
  6938. int fd;
  6939. nullpo_retv(sd);
  6940. fd = sd->fd;
  6941. WFIFOHEAD(fd,packet_len(0x7fe));
  6942. WFIFOW(fd,0) = 0x7fe;
  6943. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6944. WFIFOSET(fd,packet_len(0x7fe));
  6945. }
  6946. /// Plays/stops a wave sound (ZC_SOUND).
  6947. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6948. /// file name:
  6949. /// relative to data\wav
  6950. /// act:
  6951. /// 0 = play (once)
  6952. /// 1 = play (repeat, does not work)
  6953. /// 2 = stops all sound instances of file name (does not work)
  6954. /// term:
  6955. /// unknown purpose, only relevant to act = 1
  6956. /// npc id:
  6957. /// The accustic direction of the sound is determined by the
  6958. /// relative position of the NPC to the player (3D sound).
  6959. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6960. {
  6961. int fd;
  6962. nullpo_retv(sd);
  6963. nullpo_retv(bl);
  6964. fd = sd->fd;
  6965. WFIFOHEAD(fd,packet_len(0x1d3));
  6966. WFIFOW(fd,0) = 0x1d3;
  6967. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6968. WFIFOB(fd,26) = type;
  6969. WFIFOL(fd,27) = 0;
  6970. WFIFOL(fd,31) = bl->id;
  6971. WFIFOSET(fd,packet_len(0x1d3));
  6972. }
  6973. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6974. {
  6975. unsigned char buf[40];
  6976. nullpo_retv(bl);
  6977. WBUFW(buf,0) = 0x1d3;
  6978. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6979. WBUFB(buf,26) = type;
  6980. WBUFL(buf,27) = 0;
  6981. WBUFL(buf,31) = bl->id;
  6982. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6983. }
  6984. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6985. /// 01f3 <id>.L <effect id>.L
  6986. /// effect id:
  6987. /// @see doc/effect_list.txt
  6988. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6989. {
  6990. unsigned char buf[24];
  6991. nullpo_retv(bl);
  6992. memset(buf, 0, packet_len(0x1f3));
  6993. WBUFW(buf,0) = 0x1f3;
  6994. WBUFL(buf,2) = bl->id;
  6995. WBUFL(buf,6) = type;
  6996. clif_send(buf, packet_len(0x1f3), bl, target);
  6997. if (disguised(bl)) {
  6998. WBUFL(buf,2) = -bl->id;
  6999. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7000. }
  7001. }
  7002. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7003. {
  7004. WFIFOHEAD(fd,10);
  7005. WFIFOW(fd,0) = 0x1f3;
  7006. WFIFOL(fd,2) = bl->id;
  7007. WFIFOL(fd,6) = type;
  7008. WFIFOSET(fd,10);
  7009. }
  7010. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7011. /// 0284 <id>.L <effect id>.L <num data>.L
  7012. /// effect id:
  7013. /// @see doc/effect_list.txt
  7014. /// num data:
  7015. /// effect-dependent value
  7016. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7017. {
  7018. uint8 buf[14];
  7019. WBUFW(buf,0) = 0x284;
  7020. WBUFL(buf,2) = bl->id;
  7021. WBUFL(buf,6) = effect_id;
  7022. WBUFL(buf,10) = num;
  7023. clif_send(buf, packet_len(0x284), bl, target);
  7024. if( disguised(bl) )
  7025. {
  7026. WBUFL(buf,2) = -bl->id;
  7027. clif_send(buf, packet_len(0x284), bl, SELF);
  7028. }
  7029. }
  7030. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7031. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7032. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  7033. unsigned short msg_len = strlen(msg) + 1;
  7034. WFIFOHEAD(sd->fd,msg_len + 12);
  7035. WFIFOW(sd->fd,0) = 0x2C1;
  7036. WFIFOW(sd->fd,2) = msg_len + 12;
  7037. WFIFOL(sd->fd,4) = 0;
  7038. WFIFOL(sd->fd,8) = color_table[color];
  7039. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7040. clif_send(WFIFOP(sd->fd,0), WFIFOW(sd->fd,2), &sd->bl, SELF);
  7041. return 0;
  7042. }
  7043. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7044. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7045. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7046. unsigned short msg_len = strlen(msg) + 1;
  7047. uint8 buf[256];
  7048. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7049. nullpo_retv(bl);
  7050. if( msg_len > sizeof(buf)-12 )
  7051. {
  7052. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7053. msg_len = sizeof(buf)-12;
  7054. }
  7055. WBUFW(buf,0) = 0x2C1;
  7056. WBUFW(buf,2) = msg_len + 12;
  7057. WBUFL(buf,4) = bl->id;
  7058. WBUFL(buf,8) = color;
  7059. memcpy(WBUFP(buf,12), msg, msg_len);
  7060. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7061. }
  7062. /// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  7063. /// 008d <packet len>.W <id>.L <message>.?B
  7064. void clif_message(struct block_list* bl, const char* msg) {
  7065. unsigned short msg_len = strlen(msg) + 1;
  7066. uint8 buf[256];
  7067. nullpo_retv(bl);
  7068. if( msg_len > sizeof(buf)-8 ) {
  7069. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7070. msg_len = sizeof(buf)-8;
  7071. }
  7072. WBUFW(buf,0) = 0x8d;
  7073. WBUFW(buf,2) = msg_len + 8;
  7074. WBUFL(buf,4) = bl->id;
  7075. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  7076. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7077. }
  7078. // refresh the client's screen, getting rid of any effects
  7079. void clif_refresh(struct map_session_data *sd)
  7080. {
  7081. int i;
  7082. nullpo_retv(sd);
  7083. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7084. clif_inventorylist(sd);
  7085. if(pc_iscarton(sd)) {
  7086. clif_cartlist(sd);
  7087. clif_updatestatus(sd,SP_CARTINFO);
  7088. }
  7089. clif_updatestatus(sd,SP_WEIGHT);
  7090. clif_updatestatus(sd,SP_MAXWEIGHT);
  7091. clif_updatestatus(sd,SP_STR);
  7092. clif_updatestatus(sd,SP_AGI);
  7093. clif_updatestatus(sd,SP_VIT);
  7094. clif_updatestatus(sd,SP_INT);
  7095. clif_updatestatus(sd,SP_DEX);
  7096. clif_updatestatus(sd,SP_LUK);
  7097. if (sd->spiritball)
  7098. clif_spiritball_single(sd->fd, sd);
  7099. for(i = 1; i < 5; i++){
  7100. if( sd->talisman[i] > 0 )
  7101. clif_talisman_single(sd->fd, sd, i);
  7102. }
  7103. if (sd->vd.cloth_color)
  7104. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7105. if(merc_is_hom_active(sd->hd))
  7106. clif_send_homdata(sd,SP_ACK,0);
  7107. if( sd->md ) {
  7108. clif_mercenary_info(sd);
  7109. clif_mercenary_skillblock(sd);
  7110. }
  7111. if( sd->ed )
  7112. clif_elemental_info(sd);
  7113. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7114. clif_weather_check(sd);
  7115. if( sd->chatID )
  7116. chat_leavechat(sd,0);
  7117. if( sd->state.vending )
  7118. clif_openvending(sd, sd->bl.id, sd->vending);
  7119. if( pc_issit(sd) )
  7120. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7121. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7122. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7123. else
  7124. clif_changed_dir(&sd->bl, SELF);
  7125. // unlike vending, resuming buyingstore crashes the client.
  7126. buyingstore_close(sd);
  7127. mail_clear(sd);
  7128. }
  7129. /// Updates the object's (bl) name on client.
  7130. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7131. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7132. void clif_charnameack (int fd, struct block_list *bl)
  7133. {
  7134. unsigned char buf[103];
  7135. int cmd = 0x95, i, ps = -1;
  7136. nullpo_retv(bl);
  7137. WBUFW(buf,0) = cmd;
  7138. WBUFL(buf,2) = bl->id;
  7139. switch( bl->type )
  7140. {
  7141. case BL_PC:
  7142. {
  7143. struct map_session_data *ssd = (struct map_session_data *)bl;
  7144. struct party_data *p = NULL;
  7145. struct guild *g = NULL;
  7146. //Requesting your own "shadow" name. [Skotlex]
  7147. if (ssd->fd == fd && ssd->disguise)
  7148. WBUFL(buf,2) = -bl->id;
  7149. if( ssd->fakename[0] )
  7150. {
  7151. WBUFW(buf, 0) = cmd = 0x195;
  7152. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7153. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7154. break;
  7155. }
  7156. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7157. if( ssd->status.party_id )
  7158. {
  7159. p = party_search(ssd->status.party_id);
  7160. }
  7161. if( ssd->status.guild_id )
  7162. {
  7163. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  7164. {
  7165. 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);
  7166. if( i < g->max_member ) ps = g->member[i].position;
  7167. }
  7168. }
  7169. if( !battle_config.display_party_name && g == NULL )
  7170. {// do not display party unless the player is also in a guild
  7171. p = NULL;
  7172. }
  7173. if (p == NULL && g == NULL)
  7174. break;
  7175. WBUFW(buf, 0) = cmd = 0x195;
  7176. if (p)
  7177. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7178. else
  7179. WBUFB(buf,30) = 0;
  7180. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7181. {
  7182. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7183. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7184. } else { //Assume no guild.
  7185. WBUFB(buf,54) = 0;
  7186. WBUFB(buf,78) = 0;
  7187. }
  7188. }
  7189. break;
  7190. //[blackhole89]
  7191. case BL_HOM:
  7192. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7193. break;
  7194. case BL_MER:
  7195. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7196. break;
  7197. case BL_PET:
  7198. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7199. break;
  7200. case BL_NPC:
  7201. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7202. break;
  7203. case BL_MOB:
  7204. {
  7205. struct mob_data *md = (struct mob_data *)bl;
  7206. nullpo_retv(md);
  7207. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7208. if( md->guardian_data && md->guardian_data->guild_id )
  7209. {
  7210. WBUFW(buf, 0) = cmd = 0x195;
  7211. WBUFB(buf,30) = 0;
  7212. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7213. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7214. }
  7215. else if( battle_config.show_mob_info )
  7216. {
  7217. char mobhp[50], *str_p = mobhp;
  7218. WBUFW(buf, 0) = cmd = 0x195;
  7219. if( battle_config.show_mob_info&4 )
  7220. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7221. if( battle_config.show_mob_info&1 )
  7222. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7223. if( battle_config.show_mob_info&2 )
  7224. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7225. //Even thought mobhp ain't a name, we send it as one so the client
  7226. //can parse it. [Skotlex]
  7227. if( str_p != mobhp )
  7228. {
  7229. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7230. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7231. WBUFB(buf,54) = 0;
  7232. WBUFB(buf,78) = 0;
  7233. }
  7234. }
  7235. }
  7236. break;
  7237. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7238. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7239. // break;
  7240. return;
  7241. case BL_ELEM:
  7242. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7243. break;
  7244. default:
  7245. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7246. return;
  7247. }
  7248. // if no receipient specified just update nearby clients
  7249. if (fd == 0)
  7250. clif_send(buf, packet_len(cmd), bl, AREA);
  7251. else {
  7252. WFIFOHEAD(fd, packet_len(cmd));
  7253. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7254. WFIFOSET(fd, packet_len(cmd));
  7255. }
  7256. }
  7257. //Used to update when a char leaves a party/guild. [Skotlex]
  7258. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7259. void clif_charnameupdate (struct map_session_data *ssd)
  7260. {
  7261. unsigned char buf[103];
  7262. int cmd = 0x195, ps = -1, i;
  7263. struct party_data *p = NULL;
  7264. struct guild *g = NULL;
  7265. nullpo_retv(ssd);
  7266. if( ssd->fakename[0] )
  7267. return; //No need to update as the party/guild was not displayed anyway.
  7268. WBUFW(buf,0) = cmd;
  7269. WBUFL(buf,2) = ssd->bl.id;
  7270. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7271. if (!battle_config.display_party_name) {
  7272. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  7273. p = party_search(ssd->status.party_id);
  7274. }else{
  7275. if (ssd->status.party_id > 0)
  7276. p = party_search(ssd->status.party_id);
  7277. }
  7278. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  7279. {
  7280. 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);
  7281. if( i < g->max_member ) ps = g->member[i].position;
  7282. }
  7283. if( p )
  7284. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7285. else
  7286. WBUFB(buf,30) = 0;
  7287. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7288. {
  7289. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7290. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7291. }
  7292. else
  7293. {
  7294. WBUFB(buf,54) = 0;
  7295. WBUFB(buf,78) = 0;
  7296. }
  7297. // Update nearby clients
  7298. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7299. }
  7300. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7301. /// 01ff <id>.L <x>.W <y>.W
  7302. ///
  7303. /// Visually moves(instant) a character to x,y. The char moves even
  7304. /// when the target cell isn't walkable. If the char is sitting it
  7305. /// stays that way.
  7306. void clif_slide(struct block_list *bl, int x, int y)
  7307. {
  7308. unsigned char buf[10];
  7309. nullpo_retv(bl);
  7310. WBUFW(buf, 0) = 0x01ff;
  7311. WBUFL(buf, 2) = bl->id;
  7312. WBUFW(buf, 6) = x;
  7313. WBUFW(buf, 8) = y;
  7314. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7315. if( disguised(bl) )
  7316. {
  7317. WBUFL(buf,2) = -bl->id;
  7318. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7319. }
  7320. }
  7321. /*------------------------------------------
  7322. * @me command by lordalfa, rewritten implementation by Skotlex
  7323. *------------------------------------------*/
  7324. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  7325. {
  7326. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7327. int len_mes = strlen(mes)+1; //Account for \0
  7328. if (len_mes > sizeof(buf)-8) {
  7329. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7330. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7331. }
  7332. // send message to others
  7333. WBUFW(buf,0) = 0x8d;
  7334. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7335. WBUFL(buf,4) = sd->bl.id;
  7336. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7337. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7338. // send back message to the speaker
  7339. WBUFW(buf,0) = 0x8e;
  7340. WBUFW(buf, 2) = len_mes + 4;
  7341. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7342. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7343. }
  7344. /*==========================
  7345. * Minimap fix [Kevin]
  7346. * Remove dot from minimap
  7347. *--------------------------*/
  7348. void clif_party_xy_remove(struct map_session_data *sd)
  7349. {
  7350. unsigned char buf[16];
  7351. nullpo_retv(sd);
  7352. WBUFW(buf,0)=0x107;
  7353. WBUFL(buf,2)=sd->status.account_id;
  7354. WBUFW(buf,6)=-1;
  7355. WBUFW(buf,8)=-1;
  7356. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7357. }
  7358. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7359. /// 0215 <msg id>.L
  7360. /// msg id:
  7361. /// 0x15 = End all negative status (PA_GOSPEL)
  7362. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7363. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7364. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7365. /// 0x19 = All stats +20 (PA_GOSPEL)
  7366. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7367. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7368. /// 0x1e = DEF +25% (PA_GOSPEL)
  7369. /// 0x1f = ATK +100% (PA_GOSPEL)
  7370. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7371. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7372. /// ? = nothing
  7373. void clif_gospel_info(struct map_session_data *sd, int type)
  7374. {
  7375. int fd=sd->fd;
  7376. WFIFOHEAD(fd,packet_len(0x215));
  7377. WFIFOW(fd,0)=0x215;
  7378. WFIFOL(fd,2)=type;
  7379. WFIFOSET(fd, packet_len(0x215));
  7380. }
  7381. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7382. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7383. /// result:
  7384. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7385. /// star:
  7386. /// 0 = Place of the Sun
  7387. /// 1 = Place of the Moon
  7388. /// 2 = Place of the Stars
  7389. /// 1 = Star Gladiator %s's %s: <mapname>
  7390. /// star:
  7391. /// 0 = Place of the Sun
  7392. /// 1 = Place of the Moon
  7393. /// 2 = Place of the Stars
  7394. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7395. /// star:
  7396. /// 0 = Target of the Sun
  7397. /// 1 = Target of the Moon
  7398. /// 2 = Target of the Stars
  7399. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7400. /// star:
  7401. /// 0 = Monster of the Sun
  7402. /// 1 = Monster of the Moon
  7403. /// 2 = Monster of the Stars
  7404. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7405. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7406. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7407. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7408. /// 40 = Target HP : <monster_id used as HP>
  7409. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7410. {
  7411. int fd = sd->fd;
  7412. WFIFOHEAD(fd,packet_len(0x20e));
  7413. WFIFOW(fd,0) = 0x20e;
  7414. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7415. WFIFOL(fd,26) = monster_id;
  7416. WFIFOB(fd,30) = star;
  7417. WFIFOB(fd,31) = result;
  7418. WFIFOSET(fd,packet_len(0x20e));
  7419. }
  7420. /*==========================================
  7421. * Info about Star Glaldiator save map [Komurka]
  7422. * type: 1: Information, 0: Map registered
  7423. *------------------------------------------*/
  7424. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7425. {
  7426. char mapname[MAP_NAME_LENGTH_EXT];
  7427. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7428. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7429. }
  7430. /*==========================================
  7431. * Info about Star Glaldiator hate mob [Komurka]
  7432. * type: 1: Register mob, 0: Information.
  7433. *------------------------------------------*/
  7434. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7435. {
  7436. if( pcdb_checkid(class_) )
  7437. {
  7438. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7439. }
  7440. else if( mobdb_checkid(class_) )
  7441. {
  7442. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7443. }
  7444. else
  7445. {
  7446. 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);
  7447. }
  7448. }
  7449. /*==========================================
  7450. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7451. *------------------------------------------*/
  7452. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7453. {
  7454. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7455. }
  7456. /*==========================================
  7457. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7458. *------------------------------------------*/
  7459. void clif_feel_hate_reset(struct map_session_data *sd)
  7460. {
  7461. clif_starskill(sd, "", 0, 0, 30);
  7462. }
  7463. /// Equip window (un)tick ack (ZC_CONFIG).
  7464. /// 02d9 <type>.L <value>.L
  7465. /// type:
  7466. /// 0 = open equip window
  7467. /// value:
  7468. /// 0 = disabled
  7469. /// 1 = enabled
  7470. void clif_equiptickack(struct map_session_data* sd, int flag)
  7471. {
  7472. int fd;
  7473. nullpo_retv(sd);
  7474. fd = sd->fd;
  7475. WFIFOHEAD(fd, packet_len(0x2d9));
  7476. WFIFOW(fd, 0) = 0x2d9;
  7477. WFIFOL(fd, 2) = 0;
  7478. WFIFOL(fd, 6) = flag;
  7479. WFIFOSET(fd, packet_len(0x2d9));
  7480. }
  7481. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7482. /// 02da <open equip window>.B
  7483. /// open equip window:
  7484. /// 0 = disabled
  7485. /// 1 = enabled
  7486. void clif_equipcheckbox(struct map_session_data* sd)
  7487. {
  7488. int fd;
  7489. nullpo_retv(sd);
  7490. fd = sd->fd;
  7491. WFIFOHEAD(fd, packet_len(0x2da));
  7492. WFIFOW(fd, 0) = 0x2da;
  7493. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7494. WFIFOSET(fd, packet_len(0x2da));
  7495. }
  7496. /// Sends info about a player's equipped items.
  7497. /// 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)
  7498. /// 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)
  7499. /// 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)
  7500. /// 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)
  7501. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7502. {
  7503. uint8* buf;
  7504. int i, n, fd, offset = 0;
  7505. #if PACKETVER < 20100629
  7506. const int s = 26;
  7507. #else
  7508. const int s = 28;
  7509. #endif
  7510. nullpo_retv(sd);
  7511. nullpo_retv(tsd);
  7512. fd = sd->fd;
  7513. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7514. buf = WFIFOP(fd,0);
  7515. #if PACKETVER < 20101124
  7516. WBUFW(buf, 0) = 0x2d7;
  7517. #else
  7518. WBUFW(buf, 0) = 0x859;
  7519. #endif
  7520. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7521. WBUFW(buf,28) = tsd->status.class_;
  7522. WBUFW(buf,30) = tsd->vd.hair_style;
  7523. WBUFW(buf,32) = tsd->vd.head_bottom;
  7524. WBUFW(buf,34) = tsd->vd.head_mid;
  7525. WBUFW(buf,36) = tsd->vd.head_top;
  7526. #if PACKETVER >= 20110111
  7527. WBUFW(buf,38) = tsd->vd.robe;
  7528. offset+= 2;
  7529. buf = WBUFP(buf,2);
  7530. #endif
  7531. WBUFW(buf,38) = tsd->vd.hair_color;
  7532. WBUFW(buf,40) = tsd->vd.cloth_color;
  7533. WBUFB(buf,42) = tsd->vd.sex;
  7534. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7535. {
  7536. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7537. continue;
  7538. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7539. continue;
  7540. // Inventory position
  7541. WBUFW(buf, n*s+43) = i + 2;
  7542. // Add refine, identify flag, element, etc.
  7543. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7544. // Add cards
  7545. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7546. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7547. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7548. WBUFW(buf, n*s+67) = 0;
  7549. #if PACKETVER >= 20100629
  7550. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7551. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7552. else
  7553. WBUFW(buf, n*s+69) = 0;
  7554. #endif
  7555. n++;
  7556. }
  7557. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7558. WFIFOSET(fd, WFIFOW(fd, 2));
  7559. }
  7560. /// Display msgstringtable.txt string (ZC_MSG).
  7561. /// 0291 <message>.W
  7562. void clif_msg(struct map_session_data* sd, unsigned short id)
  7563. {
  7564. int fd;
  7565. nullpo_retv(sd);
  7566. fd = sd->fd;
  7567. WFIFOHEAD(fd, packet_len(0x291));
  7568. WFIFOW(fd, 0) = 0x291;
  7569. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7570. WFIFOSET(fd, packet_len(0x291));
  7571. }
  7572. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7573. /// 0x7e2 <message>.W <value>.L
  7574. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7575. {
  7576. int fd = sd->fd;
  7577. WFIFOHEAD(fd, packet_len(0x7e2));
  7578. WFIFOW(fd,0) = 0x7e2;
  7579. WFIFOW(fd,2) = id;
  7580. WFIFOL(fd,4) = value;
  7581. WFIFOSET(fd, packet_len(0x7e2));
  7582. }
  7583. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7584. /// 07e6 <skill id>.W <msg id>.L
  7585. ///
  7586. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7587. /// "[SkillName] Message"
  7588. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7589. {
  7590. int fd = sd->fd;
  7591. WFIFOHEAD(fd, packet_len(0x7e6));
  7592. WFIFOW(fd,0) = 0x7e6;
  7593. WFIFOW(fd,2) = skill_id;
  7594. WFIFOL(fd,4) = msg_id;
  7595. WFIFOSET(fd, packet_len(0x7e6));
  7596. }
  7597. /// View player equip request denied
  7598. void clif_viewequip_fail(struct map_session_data* sd)
  7599. {
  7600. clif_msg(sd, 0x54d);
  7601. }
  7602. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7603. /// Returns true if the packet was parsed successfully.
  7604. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7605. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7606. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7607. {
  7608. char *text, *name, *message;
  7609. unsigned int packetlen, textlen, namelen, messagelen;
  7610. int fd = sd->fd;
  7611. *name_ = NULL;
  7612. *namelen_ = 0;
  7613. *message_ = NULL;
  7614. *messagelen_ = 0;
  7615. packetlen = RFIFOW(fd,2);
  7616. // basic structure checks
  7617. if( packetlen < 4 + 1 )
  7618. { // 4-byte header and at least an empty string is expected
  7619. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7620. return false;
  7621. }
  7622. text = (char*)RFIFOP(fd,4);
  7623. textlen = packetlen - 4;
  7624. // process <name> part of the packet
  7625. if( format == 0 )
  7626. {// name and message are separated by ' : '
  7627. // validate name
  7628. name = text;
  7629. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7630. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7631. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7632. {
  7633. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7634. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7635. set_eof(fd); // Just kick them out to correct it.
  7636. return false;
  7637. }
  7638. message = name + namelen + 3;
  7639. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7640. }
  7641. else
  7642. {// name has fixed width
  7643. if( textlen < NAME_LENGTH + 1 )
  7644. {
  7645. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7646. return false;
  7647. }
  7648. // validate name
  7649. name = text;
  7650. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7651. if( name[namelen] != '\0' )
  7652. { // only restriction is that the name must be zero-terminated
  7653. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7654. return false;
  7655. }
  7656. message = name + NAME_LENGTH;
  7657. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7658. }
  7659. if( messagelen != strnlen(message, messagelen)+1 )
  7660. { // the declared length must match real length
  7661. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7662. return false;
  7663. }
  7664. // verify <message> part of the packet
  7665. if( message[messagelen-1] != '\0' )
  7666. { // message must be zero-terminated
  7667. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7668. return false;
  7669. }
  7670. if( messagelen > CHAT_SIZE_MAX-1 )
  7671. { // messages mustn't be too long
  7672. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7673. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7674. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7675. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7676. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7677. return false;
  7678. }
  7679. *name_ = name;
  7680. *namelen_ = namelen;
  7681. *message_ = message;
  7682. *messagelen_ = messagelen;
  7683. return true;
  7684. }
  7685. // ---------------------
  7686. // clif_guess_PacketVer
  7687. // ---------------------
  7688. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7689. // error codes:
  7690. // 0 - Success
  7691. // 1 - Unknown packet_ver
  7692. // 2 - Invalid account_id
  7693. // 3 - Invalid char_id
  7694. // 4 - Invalid login_id1 (reserved)
  7695. // 5 - Invalid client_tick (reserved)
  7696. // 6 - Invalid sex
  7697. // Only the first 'invalid' error that appears is used.
  7698. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7699. {
  7700. static int err = 1;
  7701. static int packet_ver = -1;
  7702. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7703. if (get_previous)
  7704. {//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]
  7705. if( error )
  7706. *error = err;
  7707. return packet_ver;
  7708. }
  7709. //By default, start searching on the default one.
  7710. err = 1;
  7711. packet_ver = clif_config.packet_db_ver;
  7712. cmd = RFIFOW(fd,0);
  7713. packet_len = RFIFOREST(fd);
  7714. #define SET_ERROR(n) \
  7715. if( err == 1 )\
  7716. err = n;\
  7717. //define SET_ERROR
  7718. // FIXME: If the packet is not received at once, this will FAIL.
  7719. // Figure out, when it happens, that only part of the packet is
  7720. // received, or fix the function to be able to deal with that
  7721. // case.
  7722. #define CHECK_PACKET_VER() \
  7723. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7724. ;/* not wanttoconnection or wrong length */\
  7725. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7726. { SET_ERROR(2); }/* invalid account_id */\
  7727. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7728. { SET_ERROR(3); }/* invalid char_id */\
  7729. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7730. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7731. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7732. { SET_ERROR(6); }/* invalid sex */\
  7733. else\
  7734. {\
  7735. err = 0;\
  7736. if( error )\
  7737. *error = 0;\
  7738. return packet_ver;\
  7739. }\
  7740. //define CHECK_PACKET_VER
  7741. CHECK_PACKET_VER();//Default packet version found.
  7742. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7743. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7744. CHECK_PACKET_VER();
  7745. }
  7746. if( error )
  7747. *error = err;
  7748. packet_ver = -1;
  7749. return -1;
  7750. #undef SET_ERROR
  7751. #undef CHECK_PACKET_VER
  7752. }
  7753. // ------------
  7754. // clif_parse_*
  7755. // ------------
  7756. // Parses incoming (player) connection
  7757. /// Request to connect to map-server.
  7758. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7759. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7760. /// There are various variants of this packet, some of them have padding between fields.
  7761. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7762. {
  7763. struct block_list* bl;
  7764. struct auth_node* node;
  7765. int cmd, account_id, char_id, login_id1, sex;
  7766. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7767. 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])
  7768. if (sd) {
  7769. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7770. return;
  7771. }
  7772. // Only valid packet version get here
  7773. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7774. cmd = RFIFOW(fd,0);
  7775. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7776. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7777. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7778. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7779. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7780. if( packet_ver < 5 || // reject really old client versions
  7781. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7782. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7783. {// packet version rejected
  7784. 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));
  7785. WFIFOHEAD(fd,packet_len(0x6a));
  7786. WFIFOW(fd,0) = 0x6a;
  7787. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7788. WFIFOSET(fd,packet_len(0x6a));
  7789. set_eof(fd);
  7790. return;
  7791. }
  7792. if( runflag != MAPSERVER_ST_RUNNING )
  7793. {// not allowed
  7794. clif_authfail_fd(fd,1);// server closed
  7795. return;
  7796. }
  7797. //Check for double login.
  7798. bl = map_id2bl(account_id);
  7799. if(bl && bl->type != BL_PC) {
  7800. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7801. WFIFOHEAD(fd,packet_len(0x6a));
  7802. WFIFOW(fd,0) = 0x6a;
  7803. WFIFOB(fd,2) = 3; // Rejected by server
  7804. WFIFOSET(fd,packet_len(0x6a));
  7805. set_eof(fd);
  7806. return;
  7807. }
  7808. if (bl ||
  7809. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7810. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7811. {
  7812. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7813. return;
  7814. }
  7815. CREATE(sd, TBL_PC, 1);
  7816. sd->fd = fd;
  7817. sd->packet_ver = packet_ver;
  7818. session[fd]->session_data = sd;
  7819. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7820. #if PACKETVER < 20070521
  7821. WFIFOHEAD(fd,4);
  7822. WFIFOL(fd,0) = sd->bl.id;
  7823. WFIFOSET(fd,4);
  7824. #else
  7825. WFIFOHEAD(fd,packet_len(0x283));
  7826. WFIFOW(fd,0) = 0x283;
  7827. WFIFOL(fd,2) = sd->bl.id;
  7828. WFIFOSET(fd,packet_len(0x283));
  7829. #endif
  7830. chrif_authreq(sd);
  7831. }
  7832. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7833. /// 007d
  7834. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7835. {
  7836. if(sd->bl.prev != NULL)
  7837. return;
  7838. if (!sd->state.active)
  7839. { //Character loading is not complete yet!
  7840. //Let pc_reg_received reinvoke this when ready.
  7841. sd->state.connect_new = 0;
  7842. return;
  7843. }
  7844. if (sd->state.rewarp)
  7845. { //Rewarp player.
  7846. sd->state.rewarp = 0;
  7847. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7848. return;
  7849. }
  7850. sd->state.warping = 0;
  7851. // look
  7852. #if PACKETVER < 4
  7853. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7854. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7855. #else
  7856. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7857. #endif
  7858. if(sd->vd.cloth_color)
  7859. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7860. // item
  7861. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7862. pc_checkitem(sd);
  7863. // cart
  7864. if(pc_iscarton(sd)) {
  7865. clif_cartlist(sd);
  7866. clif_updatestatus(sd,SP_CARTINFO);
  7867. }
  7868. // weight
  7869. clif_updatestatus(sd,SP_WEIGHT);
  7870. clif_updatestatus(sd,SP_MAXWEIGHT);
  7871. // guild
  7872. // (needs to go before clif_spawn() to show guild emblems correctly)
  7873. if(sd->status.guild_id)
  7874. guild_send_memberinfoshort(sd,1);
  7875. if(battle_config.pc_invincible_time > 0) {
  7876. if(map_flag_gvg(sd->bl.m))
  7877. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7878. else
  7879. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7880. }
  7881. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7882. map_spawnmobs(sd->bl.m);
  7883. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7884. {// increment the number of pvp players on the map
  7885. map[sd->bl.m].users_pvp++;
  7886. }
  7887. if( map[sd->bl.m].instance_id )
  7888. {
  7889. instance[map[sd->bl.m].instance_id].users++;
  7890. instance_check_idle(map[sd->bl.m].instance_id);
  7891. }
  7892. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7893. // reset the callshop flag if the player changes map
  7894. sd->state.callshop = 0;
  7895. map_addblock(&sd->bl);
  7896. clif_spawn(&sd->bl);
  7897. // Party
  7898. // (needs to go after clif_spawn() to show hp bars correctly)
  7899. if(sd->status.party_id) {
  7900. party_send_movemap(sd);
  7901. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7902. }
  7903. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7904. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7905. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7906. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7907. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7908. sd->pvp_rank = 0;
  7909. sd->pvp_lastusers = 0;
  7910. sd->pvp_point = 5;
  7911. sd->pvp_won = 0;
  7912. sd->pvp_lost = 0;
  7913. }
  7914. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7915. } else
  7916. // set flag, if it's a duel [LuzZza]
  7917. if(sd->duel_group)
  7918. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7919. if (map[sd->bl.m].flag.gvg_dungeon)
  7920. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7921. if( map_flag_gvg(sd->bl.m) )
  7922. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7923. // info about nearby objects
  7924. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7925. 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);
  7926. // pet
  7927. if( sd->pd )
  7928. {
  7929. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7930. { //Return the pet to egg. [Skotlex]
  7931. clif_displaymessage(sd->fd, msg_txt(666));
  7932. pet_menu(sd, 3); //Option 3 is return to egg.
  7933. }
  7934. else
  7935. {
  7936. map_addblock(&sd->pd->bl);
  7937. clif_spawn(&sd->pd->bl);
  7938. clif_send_petdata(sd,sd->pd,0,0);
  7939. clif_send_petstatus(sd);
  7940. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7941. }
  7942. }
  7943. //homunculus [blackhole89]
  7944. if( merc_is_hom_active(sd->hd) )
  7945. {
  7946. map_addblock(&sd->hd->bl);
  7947. clif_spawn(&sd->hd->bl);
  7948. clif_send_homdata(sd,SP_ACK,0);
  7949. clif_hominfo(sd,sd->hd,1);
  7950. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7951. clif_homskillinfoblock(sd);
  7952. if( battle_config.hom_setting&0x8 )
  7953. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7954. if( !(battle_config.hom_setting&0x2) )
  7955. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7956. }
  7957. if( sd->md ) {
  7958. map_addblock(&sd->md->bl);
  7959. clif_spawn(&sd->md->bl);
  7960. clif_mercenary_info(sd);
  7961. clif_mercenary_skillblock(sd);
  7962. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  7963. }
  7964. if( sd->ed ) {
  7965. map_addblock(&sd->ed->bl);
  7966. clif_spawn(&sd->ed->bl);
  7967. clif_elemental_info(sd);
  7968. clif_elemental_updatestatus(sd,SP_HP);
  7969. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  7970. clif_elemental_updatestatus(sd,SP_SP);
  7971. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  7972. }
  7973. if(sd->state.connect_new) {
  7974. int lv;
  7975. sd->state.connect_new = 0;
  7976. clif_skillinfoblock(sd);
  7977. clif_hotkeys_send(sd);
  7978. clif_updatestatus(sd,SP_BASEEXP);
  7979. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7980. clif_updatestatus(sd,SP_JOBEXP);
  7981. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7982. clif_updatestatus(sd,SP_SKILLPOINT);
  7983. clif_initialstatus(sd);
  7984. if (sd->sc.option&OPTION_FALCON)
  7985. clif_status_load(&sd->bl, SI_FALCON, 1);
  7986. if (sd->sc.option&OPTION_RIDING)
  7987. clif_status_load(&sd->bl, SI_RIDING, 1);
  7988. else if (sd->sc.option&OPTION_WUGRIDER)
  7989. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  7990. if(sd->status.manner < 0)
  7991. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7992. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7993. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7994. if(sd->bl.m == sd->feel_map[0].m
  7995. || sd->bl.m == sd->feel_map[1].m
  7996. || sd->bl.m == sd->feel_map[2].m)
  7997. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7998. }
  7999. if(sd->pd && sd->pd->pet.intimate > 900)
  8000. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8001. if(merc_is_hom_active(sd->hd))
  8002. merc_hom_init_timers(sd->hd);
  8003. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8004. sd->state.night = 1;
  8005. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8006. }
  8007. // Notify everyone that this char logged in [Skotlex].
  8008. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8009. //Login Event
  8010. npc_script_event(sd, NPCE_LOGIN);
  8011. } else {
  8012. //For some reason the client "loses" these on warp/map-change.
  8013. clif_updatestatus(sd,SP_STR);
  8014. clif_updatestatus(sd,SP_AGI);
  8015. clif_updatestatus(sd,SP_VIT);
  8016. clif_updatestatus(sd,SP_INT);
  8017. clif_updatestatus(sd,SP_DEX);
  8018. clif_updatestatus(sd,SP_LUK);
  8019. // abort currently running script
  8020. sd->state.using_fake_npc = 0;
  8021. sd->state.menu_or_input = 0;
  8022. sd->npc_menu = 0;
  8023. if(sd->npc_id)
  8024. npc_event_dequeue(sd);
  8025. }
  8026. if( sd->state.changemap )
  8027. {// restore information that gets lost on map-change
  8028. #if PACKETVER >= 20070918
  8029. clif_partyinvitationstate(sd);
  8030. clif_equipcheckbox(sd);
  8031. #endif
  8032. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8033. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8034. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8035. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8036. { //Display night.
  8037. if( !sd->state.night )
  8038. {
  8039. sd->state.night = 1;
  8040. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8041. }
  8042. }
  8043. else if( sd->state.night )
  8044. { //Clear night display.
  8045. sd->state.night = 0;
  8046. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8047. }
  8048. if( map[sd->bl.m].flag.battleground )
  8049. {
  8050. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8051. if( map[sd->bl.m].flag.battleground == 2 )
  8052. clif_bg_updatescore_single(sd);
  8053. }
  8054. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8055. {
  8056. char output[128];
  8057. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8058. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8059. }
  8060. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8061. sd->state.changemap = false;
  8062. }
  8063. mail_clear(sd);
  8064. /* Guild Aura Init */
  8065. if( sd->state.gmaster_flag ) {
  8066. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8067. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8068. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8069. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8070. }
  8071. if( sd->state.vending ) { /* show we have a vending */
  8072. clif_openvending(sd,sd->bl.id,sd->vending);
  8073. clif_showvendingboard(&sd->bl,sd->message,0);
  8074. }
  8075. if(map[sd->bl.m].flag.loadevent) // Lance
  8076. npc_script_event(sd, NPCE_LOADMAP);
  8077. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8078. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8079. if (sd->sc.opt2) //Client loses these on warp.
  8080. clif_changeoption(&sd->bl);
  8081. clif_weather_check(sd);
  8082. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8083. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8084. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8085. else
  8086. sd->areanpc_id = 0;
  8087. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8088. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8089. pc_setdead(sd);
  8090. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8091. if(pc_isdead(sd))
  8092. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8093. else {
  8094. skill_usave_trigger(sd);
  8095. clif_changed_dir(&sd->bl, SELF);
  8096. }
  8097. // Trigger skill effects if you appear standing on them
  8098. if(!battle_config.pc_invincible_time)
  8099. skill_unit_move(&sd->bl,gettick(),1);
  8100. }
  8101. /// Server's tick (ZC_NOTIFY_TIME).
  8102. /// 007f <time>.L
  8103. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8104. {
  8105. int fd = sd->fd;
  8106. WFIFOHEAD(fd,packet_len(0x7f));
  8107. WFIFOW(fd,0) = 0x7f;
  8108. WFIFOL(fd,2) = time;
  8109. WFIFOSET(fd,packet_len(0x7f));
  8110. }
  8111. /// Request for server's tick.
  8112. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8113. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8114. /// There are various variants of this packet, some of them have padding between fields.
  8115. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8116. {
  8117. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8118. clif_notify_time(sd, gettick());
  8119. }
  8120. /// Sends hotkey bar.
  8121. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8122. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8123. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8124. void clif_hotkeys_send(struct map_session_data *sd) {
  8125. #ifdef HOTKEY_SAVING
  8126. const int fd = sd->fd;
  8127. int i;
  8128. #if PACKETVER < 20090603
  8129. const int cmd = 0x2b9;
  8130. #else
  8131. const int cmd = 0x7d9;
  8132. #endif
  8133. if (!fd) return;
  8134. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8135. WFIFOW(fd, 0) = cmd;
  8136. for(i = 0; i < MAX_HOTKEYS; i++) {
  8137. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8138. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8139. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8140. }
  8141. WFIFOSET(fd, packet_len(cmd));
  8142. #endif
  8143. }
  8144. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8145. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8146. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8147. #ifdef HOTKEY_SAVING
  8148. unsigned short idx;
  8149. int cmd;
  8150. cmd = RFIFOW(fd, 0);
  8151. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8152. if (idx >= MAX_HOTKEYS) return;
  8153. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8154. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8155. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8156. #endif
  8157. }
  8158. /// Displays cast-like progress bar (ZC_PROGRESS).
  8159. /// 02f0 <color>.L <time>.L
  8160. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8161. {
  8162. int fd = sd->fd;
  8163. WFIFOHEAD(fd,packet_len(0x2f0));
  8164. WFIFOW(fd,0) = 0x2f0;
  8165. WFIFOL(fd,2) = color;
  8166. WFIFOL(fd,6) = second;
  8167. WFIFOSET(fd,packet_len(0x2f0));
  8168. }
  8169. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8170. /// 02f2
  8171. void clif_progressbar_abort(struct map_session_data * sd)
  8172. {
  8173. int fd = sd->fd;
  8174. WFIFOHEAD(fd,packet_len(0x2f2));
  8175. WFIFOW(fd,0) = 0x2f2;
  8176. WFIFOSET(fd,packet_len(0x2f2));
  8177. }
  8178. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8179. /// 02f1
  8180. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8181. {
  8182. int npc_id = sd->progressbar.npc_id;
  8183. if( gettick() < sd->progressbar.timeout && sd->st )
  8184. sd->st->state = END;
  8185. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8186. npc_scriptcont(sd, npc_id);
  8187. }
  8188. /// Request to walk to a certain position on the current map.
  8189. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8190. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8191. /// There are various variants of this packet, some of them have padding between fields.
  8192. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8193. {
  8194. short x, y;
  8195. if (pc_isdead(sd)) {
  8196. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8197. return;
  8198. }
  8199. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8200. ; //You CAN walk on this OPT1 value.
  8201. else if( sd->progressbar.npc_id )
  8202. clif_progressbar_abort(sd);
  8203. else if (pc_cant_act(sd))
  8204. return;
  8205. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8206. return;
  8207. pc_delinvincibletimer(sd);
  8208. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8209. //Set last idle time... [Skotlex]
  8210. sd->idletime = last_tick;
  8211. unit_walktoxy(&sd->bl, x, y, 4);
  8212. }
  8213. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8214. /// 018b <result>.W
  8215. /// result:
  8216. /// 0 = disconnect (quit)
  8217. /// 1 = cannot disconnect (wait 10 seconds)
  8218. /// ? = ignored
  8219. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8220. {
  8221. int fd = sd->fd;
  8222. WFIFOHEAD(fd,packet_len(0x18b));
  8223. WFIFOW(fd,0) = 0x18b;
  8224. WFIFOW(fd,2) = result;
  8225. WFIFOSET(fd,packet_len(0x18b));
  8226. }
  8227. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8228. /// 018a <type>.W
  8229. /// type:
  8230. /// 0 = quit
  8231. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8232. {
  8233. /* Rovert's prevent logout option fixed [Valaris] */
  8234. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8235. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8236. {
  8237. set_eof(fd);
  8238. clif_disconnect_ack(sd, 0);
  8239. } else {
  8240. clif_disconnect_ack(sd, 1);
  8241. }
  8242. }
  8243. /// Requesting unit's name.
  8244. /// 0094 <id>.L (CZ_REQNAME)
  8245. /// 0368 <id>.L (CZ_REQNAME2)
  8246. /// There are various variants of this packet, some of them have padding between fields.
  8247. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8248. {
  8249. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8250. struct block_list* bl;
  8251. //struct status_change *sc;
  8252. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8253. id = sd->bl.id;
  8254. bl = map_id2bl(id);
  8255. if( bl == NULL )
  8256. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8257. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8258. return; // Block namerequests past view range
  8259. // 'see people in GM hide' cheat detection
  8260. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8261. sc = status_get_sc(bl);
  8262. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8263. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8264. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8265. ) {
  8266. char gm_msg[256];
  8267. 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);
  8268. ShowWarning(gm_msg);
  8269. // information is sent to all online GMs
  8270. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8271. return;
  8272. }
  8273. */
  8274. clif_charnameack(fd, bl);
  8275. }
  8276. /// Validates and processes global messages
  8277. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8278. /// There are various variants of this packet.
  8279. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8280. {
  8281. const char* text = (char*)RFIFOP(fd,4);
  8282. int textlen = RFIFOW(fd,2) - 4;
  8283. char *name, *message, *fakename = NULL;
  8284. int namelen, messagelen;
  8285. bool is_fake;
  8286. // validate packet and retrieve name and message
  8287. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8288. return;
  8289. if( is_atcommand(fd, sd, message, 1) )
  8290. return;
  8291. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8292. return;
  8293. if( battle_config.min_chat_delay )
  8294. { //[Skotlex]
  8295. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8296. return;
  8297. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8298. }
  8299. /**
  8300. * Fake Name Design by FatalEror (bug report #9)
  8301. **/
  8302. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8303. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8304. strcpy(fakename, sd->fakename);
  8305. strcat(fakename, " : ");
  8306. strcat(fakename, message);
  8307. textlen = strlen(fakename) + 1;
  8308. }
  8309. // send message to others (using the send buffer for temp. storage)
  8310. WFIFOHEAD(fd, 8 + textlen);
  8311. WFIFOW(fd,0) = 0x8d;
  8312. WFIFOW(fd,2) = 8 + textlen;
  8313. WFIFOL(fd,4) = sd->bl.id;
  8314. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8315. //FIXME: chat has range of 9 only
  8316. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8317. // send back message to the speaker
  8318. if( is_fake ) {
  8319. WFIFOW(fd,0) = 0x8e;
  8320. WFIFOW(fd,2) = textlen + 4;
  8321. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8322. aFree(fakename);
  8323. } else {
  8324. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8325. WFIFOW(fd,0) = 0x8e;
  8326. }
  8327. WFIFOSET(fd, WFIFOW(fd,2));
  8328. #ifdef PCRE_SUPPORT
  8329. // trigger listening npcs
  8330. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8331. #endif
  8332. // Chat logging type 'O' / Global Chat
  8333. 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);
  8334. }
  8335. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8336. /// Request to warp to a map on given coordinates.
  8337. /// 0140 <map name>.16B <x>.W <y>.W
  8338. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8339. {
  8340. char command[MAP_NAME_LENGTH_EXT+25];
  8341. char* map_name;
  8342. map_name = (char*)RFIFOP(fd,2);
  8343. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8344. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8345. is_atcommand(fd, sd, command, 1);
  8346. }
  8347. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8348. /// 009c <id>.L <head dir>.W <dir>.B
  8349. /// head dir:
  8350. /// 0 = straight
  8351. /// 1 = turned CW
  8352. /// 2 = turned CCW
  8353. /// dir:
  8354. /// 0 = north
  8355. /// 1 = northwest
  8356. /// 2 = west
  8357. /// 3 = southwest
  8358. /// 4 = south
  8359. /// 5 = southeast
  8360. /// 6 = east
  8361. /// 7 = northeast
  8362. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8363. {
  8364. unsigned char buf[64];
  8365. WBUFW(buf,0) = 0x9c;
  8366. WBUFL(buf,2) = bl->id;
  8367. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8368. WBUFB(buf,8) = unit_getdir(bl);
  8369. clif_send(buf, packet_len(0x9c), bl, target);
  8370. if (disguised(bl)) {
  8371. WBUFL(buf,2) = -bl->id;
  8372. WBUFW(buf,6) = 0;
  8373. clif_send(buf, packet_len(0x9c), bl, SELF);
  8374. }
  8375. }
  8376. /// Request to change own body and head direction.
  8377. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8378. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8379. /// There are various variants of this packet, some of them have padding between fields.
  8380. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8381. {
  8382. unsigned char headdir, dir;
  8383. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8384. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8385. pc_setdir(sd, dir, headdir);
  8386. clif_changed_dir(&sd->bl, AREA_WOS);
  8387. }
  8388. /// Request to show an emotion (CZ_REQ_EMOTION).
  8389. /// 00bf <type>.B
  8390. /// type:
  8391. /// @see enum emotion_type
  8392. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8393. {
  8394. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8395. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8396. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8397. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8398. return;
  8399. }
  8400. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8401. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8402. sd->emotionlasttime = time(NULL);
  8403. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8404. return;
  8405. }
  8406. sd->emotionlasttime = time(NULL);
  8407. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  8408. {// re-roll dice
  8409. emoticon = rnd()%6+E_DICE1;
  8410. }
  8411. clif_emotion(&sd->bl, emoticon);
  8412. } else
  8413. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8414. }
  8415. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8416. /// 00c2 <count>.L
  8417. void clif_user_count(struct map_session_data* sd, int count)
  8418. {
  8419. int fd = sd->fd;
  8420. WFIFOHEAD(fd,packet_len(0xc2));
  8421. WFIFOW(fd,0) = 0xc2;
  8422. WFIFOL(fd,2) = count;
  8423. WFIFOSET(fd,packet_len(0xc2));
  8424. }
  8425. /// /w /who (CZ_REQ_USER_COUNT).
  8426. /// Request to display amount of currently connected players.
  8427. /// 00c1
  8428. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8429. {
  8430. clif_user_count(sd, map_getusers());
  8431. }
  8432. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8433. {
  8434. if (pc_isdead(sd)) {
  8435. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8436. return;
  8437. }
  8438. if (sd->sc.count &&
  8439. (sd->sc.data[SC_TRICKDEAD] ||
  8440. sd->sc.data[SC_AUTOCOUNTER] ||
  8441. sd->sc.data[SC_BLADESTOP] ||
  8442. sd->sc.data[SC__MANHOLE] ||
  8443. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8444. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8445. return;
  8446. pc_stop_walking(sd, 1);
  8447. pc_stop_attack(sd);
  8448. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8449. target_id = sd->bl.id;
  8450. switch(action_type)
  8451. {
  8452. case 0x00: // once attack
  8453. case 0x07: // continuous attack
  8454. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8455. return;
  8456. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8457. return;
  8458. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8459. return;
  8460. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8461. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8462. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8463. return;
  8464. }
  8465. }
  8466. pc_delinvincibletimer(sd);
  8467. sd->idletime = last_tick;
  8468. unit_attack(&sd->bl, target_id, action_type != 0);
  8469. break;
  8470. case 0x02: // sitdown
  8471. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8472. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8473. break;
  8474. }
  8475. if(pc_issit(sd)) {
  8476. //Bugged client? Just refresh them.
  8477. clif_sitting(&sd->bl);
  8478. return;
  8479. }
  8480. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8481. break;
  8482. if (sd->sc.count && (
  8483. sd->sc.data[SC_DANCING] ||
  8484. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8485. )) //No sitting during these states either.
  8486. break;
  8487. pc_setsit(sd);
  8488. skill_sit(sd,1);
  8489. clif_sitting(&sd->bl);
  8490. break;
  8491. case 0x03: // standup
  8492. if (!pc_issit(sd)) {
  8493. //Bugged client? Just refresh them.
  8494. clif_standing(&sd->bl);
  8495. return;
  8496. }
  8497. pc_setstand(sd);
  8498. skill_sit(sd,0);
  8499. clif_standing(&sd->bl);
  8500. break;
  8501. }
  8502. }
  8503. /// Request for an action.
  8504. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8505. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8506. /// action:
  8507. /// 0 = attack
  8508. /// 1 = pick up item
  8509. /// 2 = sit down
  8510. /// 3 = stand up
  8511. /// 7 = continous attack
  8512. /// 12 = (touch skill?)
  8513. /// There are various variants of this packet, some of them have padding between fields.
  8514. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8515. {
  8516. clif_parse_ActionRequest_sub(sd,
  8517. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8518. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8519. gettick()
  8520. );
  8521. }
  8522. /// Response to the death/system menu (CZ_RESTART).
  8523. /// 00b2 <type>.B
  8524. /// type:
  8525. /// 0 = restart (respawn)
  8526. /// 1 = char-select (disconnect)
  8527. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8528. {
  8529. switch(RFIFOB(fd,2)) {
  8530. case 0x00:
  8531. pc_respawn(sd,CLR_RESPAWN);
  8532. break;
  8533. case 0x01:
  8534. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8535. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8536. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8537. { //Send to char-server for character selection.
  8538. chrif_charselectreq(sd, session[fd]->client_addr);
  8539. } else {
  8540. clif_disconnect_ack(sd, 1);
  8541. }
  8542. break;
  8543. }
  8544. }
  8545. /// Validates and processes whispered messages (CZ_WHISPER).
  8546. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8547. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8548. {
  8549. struct map_session_data* dstsd;
  8550. int i;
  8551. char *target, *message;
  8552. int namelen, messagelen;
  8553. // validate packet and retrieve name and message
  8554. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8555. return;
  8556. if ( is_atcommand(fd, sd, message, 1) )
  8557. return;
  8558. if (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8559. return;
  8560. if (battle_config.min_chat_delay) { //[Skotlex]
  8561. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8562. return;
  8563. }
  8564. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8565. }
  8566. // Chat logging type 'W' / Whisper
  8567. 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);
  8568. //-------------------------------------------------------//
  8569. // Lordalfa - Paperboy - To whisper NPC commands //
  8570. //-------------------------------------------------------//
  8571. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8572. {
  8573. char* str = target+4; //Skip the NPC: string part.
  8574. struct npc_data* npc;
  8575. if ((npc = npc_name2id(str))) {
  8576. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8577. char *split;
  8578. char output[256];
  8579. str = message;
  8580. // skip codepage indicator, if detected
  8581. if( str[0] == '|' && strlen(str) >= 4 )
  8582. str += 3;
  8583. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8584. split = strchr(str,'#');
  8585. if( split == NULL ) { // use the remaining string
  8586. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8587. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8588. split_data[i][0] = '\0';
  8589. break;
  8590. }
  8591. *split = '\0';
  8592. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8593. str = split+1;
  8594. }
  8595. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8596. sprintf(output, "@whispervar%d$", i);
  8597. set_var(sd,output,(char *) split_data[i]);
  8598. }
  8599. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8600. npc_event(sd,output,0); // Calls the NPC label
  8601. return;
  8602. }
  8603. } else if(strcmpi(target, main_chat_nick) == 0) { // Main chat [LuzZza]
  8604. if(!sd->state.mainchat)
  8605. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8606. else {
  8607. // send the main message using inter-server system
  8608. intif_main_message( sd, message );
  8609. }
  8610. return;
  8611. }
  8612. // searching destination character
  8613. dstsd = map_nick2sd(target);
  8614. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8615. // player is not on this map-server
  8616. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8617. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8618. // and if we ask for 'Test', we must not contact 'test' player
  8619. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8620. intif_wis_message(sd, target, message, messagelen);
  8621. return;
  8622. }
  8623. // if player ignores everyone
  8624. if (dstsd->state.ignoreAll) {
  8625. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8626. clif_wis_end(fd, 1); // 1: target character is not loged in
  8627. else
  8628. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8629. return;
  8630. }
  8631. // if player is autotrading
  8632. if( dstsd->state.autotrade == 1 ) {
  8633. char output[256];
  8634. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8635. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8636. return;
  8637. }
  8638. // if player ignores the source character
  8639. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8640. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8641. clif_wis_end(fd, 2); // 2: ignored by target
  8642. return;
  8643. }
  8644. // notify sender of success
  8645. clif_wis_end(fd, 0); // 0: success to send wisper
  8646. // Normal message
  8647. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8648. }
  8649. /// /b /nb (CZ_BROADCAST).
  8650. /// Request to broadcast a message on whole server.
  8651. /// 0099 <packet len>.W <text>.?B 00
  8652. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  8653. char command[CHAT_SIZE_MAX+11];
  8654. char* msg = (char*)RFIFOP(fd,4);
  8655. unsigned int len = RFIFOW(fd,2)-4;
  8656. // as the length varies depending on the command used, just block unreasonably long strings
  8657. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8658. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8659. is_atcommand(fd, sd, command, 1);
  8660. }
  8661. /// Request to pick up an item.
  8662. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8663. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8664. /// There are various variants of this packet, some of them have padding between fields.
  8665. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8666. {
  8667. struct flooritem_data *fitem;
  8668. int map_object_id;
  8669. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8670. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8671. do {
  8672. if (pc_isdead(sd)) {
  8673. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8674. break;
  8675. }
  8676. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8677. break;
  8678. if( sd->sc.cant.pickup )
  8679. break;
  8680. if (pc_cant_act(sd))
  8681. break;
  8682. if (!pc_takeitem(sd, fitem))
  8683. break;
  8684. return;
  8685. } while (0);
  8686. // Client REQUIRES a fail packet or you can no longer pick items.
  8687. clif_additem(sd,0,0,6);
  8688. }
  8689. /// Request to drop an item.
  8690. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8691. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8692. /// There are various variants of this packet, some of them have padding between fields.
  8693. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8694. {
  8695. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8696. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8697. for(;;) {
  8698. if (pc_isdead(sd))
  8699. break;
  8700. if (pc_cant_act(sd))
  8701. break;
  8702. if (sd->sc.count && (
  8703. sd->sc.data[SC_AUTOCOUNTER] ||
  8704. sd->sc.data[SC_BLADESTOP] ||
  8705. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8706. ))
  8707. break;
  8708. if (!pc_dropitem(sd, item_index, item_amount))
  8709. break;
  8710. return;
  8711. }
  8712. //Because the client does not like being ignored.
  8713. clif_dropitem(sd, item_index,0);
  8714. }
  8715. /// Request to use an item.
  8716. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8717. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8718. /// There are various variants of this packet, some of them have padding between fields.
  8719. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8720. {
  8721. int n;
  8722. if (pc_isdead(sd)) {
  8723. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8724. return;
  8725. }
  8726. //This flag enables you to use items while in an NPC. [Skotlex]
  8727. if (sd->npc_id) {
  8728. if (sd->npc_id != sd->npc_item_flag)
  8729. return;
  8730. }
  8731. else if (pc_istrading(sd))
  8732. return;
  8733. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8734. sd->idletime = last_tick;
  8735. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8736. if(n <0 || n >= MAX_INVENTORY)
  8737. return;
  8738. if (!pc_useitem(sd,n))
  8739. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8740. }
  8741. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8742. /// 00a9 <index>.W <position>.W
  8743. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8744. {
  8745. int index;
  8746. if(pc_isdead(sd)) {
  8747. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8748. return;
  8749. }
  8750. index = RFIFOW(fd,2)-2;
  8751. if (index < 0 || index >= MAX_INVENTORY)
  8752. return; //Out of bounds check.
  8753. if(sd->npc_id) {
  8754. if (sd->npc_id != sd->npc_item_flag)
  8755. return;
  8756. } else if (sd->state.storage_flag || sd->sc.opt1)
  8757. ; //You can equip/unequip stuff while storage is open/under status changes
  8758. else if (pc_cant_act(sd))
  8759. return;
  8760. if(!sd->status.inventory[index].identify) {
  8761. clif_equipitemack(sd,index,0,0); // fail
  8762. return;
  8763. }
  8764. if(!sd->inventory_data[index])
  8765. return;
  8766. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8767. pet_equipitem(sd,index);
  8768. return;
  8769. }
  8770. //Client doesn't send the position for ammo.
  8771. if(sd->inventory_data[index]->type == IT_AMMO)
  8772. pc_equipitem(sd,index,EQP_AMMO);
  8773. else
  8774. pc_equipitem(sd,index,RFIFOW(fd,4));
  8775. }
  8776. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8777. /// 00ab <index>.W
  8778. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8779. {
  8780. int index;
  8781. if(pc_isdead(sd)) {
  8782. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8783. return;
  8784. }
  8785. if (sd->state.storage_flag || sd->sc.opt1)
  8786. ; //You can equip/unequip stuff while storage is open/under status changes
  8787. else if (pc_cant_act(sd))
  8788. return;
  8789. index = RFIFOW(fd,2)-2;
  8790. pc_unequipitem(sd,index,1);
  8791. }
  8792. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8793. /// 0090 <id>.L <type>.B
  8794. /// type:
  8795. /// 1 = click
  8796. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8797. {
  8798. struct block_list *bl;
  8799. if(pc_isdead(sd)) {
  8800. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8801. return;
  8802. }
  8803. if (pc_cant_act(sd))
  8804. return;
  8805. bl = map_id2bl(RFIFOL(fd,2));
  8806. if (!bl) return;
  8807. switch (bl->type) {
  8808. case BL_MOB:
  8809. case BL_PC:
  8810. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8811. break;
  8812. case BL_NPC:
  8813. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8814. npc_click(sd,(TBL_NPC*)bl);
  8815. break;
  8816. }
  8817. }
  8818. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8819. /// 00c5 <id>.L <type>.B
  8820. /// type:
  8821. /// 0 = buy
  8822. /// 1 = sell
  8823. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8824. {
  8825. if (sd->state.trading)
  8826. return;
  8827. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8828. }
  8829. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  8830. /// 00ca <result>.B
  8831. /// result:
  8832. /// 0 = "The deal has successfully completed."
  8833. /// 1 = "You do not have enough zeny."
  8834. /// 2 = "You are over your Weight Limit."
  8835. /// 3 = "Out of the maximum capacity, you have too many items."
  8836. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  8837. {
  8838. int fd = sd->fd;
  8839. WFIFOHEAD(fd,packet_len(0xca));
  8840. WFIFOW(fd,0) = 0xca;
  8841. WFIFOB(fd,2) = result;
  8842. WFIFOSET(fd,packet_len(0xca));
  8843. }
  8844. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8845. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8846. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8847. {
  8848. int n = (RFIFOW(fd,2)-4) /4;
  8849. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8850. int result;
  8851. if( sd->state.trading || !sd->npc_shopid )
  8852. result = 1;
  8853. else
  8854. result = npc_buylist(sd,n,item_list);
  8855. sd->npc_shopid = 0; //Clear shop data.
  8856. clif_npc_buy_result(sd, result);
  8857. }
  8858. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  8859. /// 00cb <result>.B
  8860. /// result:
  8861. /// 0 = "The deal has successfully completed."
  8862. /// 1 = "The deal has failed."
  8863. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  8864. {
  8865. int fd = sd->fd;
  8866. WFIFOHEAD(fd,packet_len(0xcb));
  8867. WFIFOW(fd,0) = 0xcb;
  8868. WFIFOB(fd,2) = result;
  8869. WFIFOSET(fd,packet_len(0xcb));
  8870. }
  8871. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8872. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8873. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8874. {
  8875. int fail=0,n;
  8876. unsigned short *item_list;
  8877. n = (RFIFOW(fd,2)-4) /4;
  8878. item_list = (unsigned short*)RFIFOP(fd,4);
  8879. if (sd->state.trading || !sd->npc_shopid)
  8880. fail = 1;
  8881. else
  8882. fail = npc_selllist(sd,n,item_list);
  8883. sd->npc_shopid = 0; //Clear shop data.
  8884. clif_npc_sell_result(sd, fail);
  8885. }
  8886. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8887. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8888. /// type:
  8889. /// 0 = private
  8890. /// 1 = public
  8891. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8892. {
  8893. int len = RFIFOW(fd,2)-15;
  8894. int limit = RFIFOW(fd,4);
  8895. bool pub = (RFIFOB(fd,6) != 0);
  8896. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8897. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8898. char s_password[CHATROOM_PASS_SIZE];
  8899. char s_title[CHATROOM_TITLE_SIZE];
  8900. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8901. return;
  8902. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8903. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8904. return;
  8905. }
  8906. if( len <= 0 )
  8907. return; // invalid input
  8908. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8909. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8910. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8911. }
  8912. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8913. /// 00d9 <chat ID>.L <passwd>.8B
  8914. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8915. {
  8916. int chatid = RFIFOL(fd,2);
  8917. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8918. chat_joinchat(sd,chatid,password);
  8919. }
  8920. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8921. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8922. /// type:
  8923. /// 0 = private
  8924. /// 1 = public
  8925. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8926. {
  8927. int len = RFIFOW(fd,2)-15;
  8928. int limit = RFIFOW(fd,4);
  8929. bool pub = (RFIFOB(fd,6) != 0);
  8930. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8931. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8932. char s_password[CHATROOM_PASS_SIZE];
  8933. char s_title[CHATROOM_TITLE_SIZE];
  8934. if( len <= 0 )
  8935. return; // invalid input
  8936. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8937. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8938. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8939. }
  8940. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8941. /// 00e0 <role>.L <nick>.24B
  8942. /// role:
  8943. /// 0 = owner
  8944. /// 1 = normal
  8945. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8946. {
  8947. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8948. }
  8949. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8950. /// 00e2 <name>.24B
  8951. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8952. {
  8953. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8954. }
  8955. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8956. /// 00e3
  8957. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8958. {
  8959. chat_leavechat(sd,0);
  8960. }
  8961. //Handles notifying asker and rejecter of what has just ocurred.
  8962. //Type is used to determine the correct msg_txt to use:
  8963. //0:
  8964. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8965. {
  8966. const char* msg;
  8967. char output[256];
  8968. // Your request has been rejected by autoreject option.
  8969. msg = msg_txt(392);
  8970. clif_disp_onlyself(src, msg, strlen(msg));
  8971. //Notice that a request was rejected.
  8972. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8973. clif_disp_onlyself(target, output, strlen(output));
  8974. }
  8975. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8976. /// 00e4 <account id>.L
  8977. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8978. {
  8979. struct map_session_data *t_sd;
  8980. t_sd = map_id2sd(RFIFOL(fd,2));
  8981. if(!sd->chatID && pc_cant_act(sd))
  8982. return; //You can trade while in a chatroom.
  8983. // @noask [LuzZza]
  8984. if(t_sd && t_sd->state.noask) {
  8985. clif_noask_sub(sd, t_sd, 0);
  8986. return;
  8987. }
  8988. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8989. {
  8990. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8991. return;
  8992. }
  8993. trade_traderequest(sd,t_sd);
  8994. }
  8995. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8996. /// 00e6 <result>.B
  8997. /// result:
  8998. /// 3 = accepted
  8999. /// 4 = rejected
  9000. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9001. {
  9002. trade_tradeack(sd,RFIFOB(fd,2));
  9003. }
  9004. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9005. /// 00e8 <index>.W <amount>.L
  9006. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9007. {
  9008. short index = RFIFOW(fd,2);
  9009. int amount = RFIFOL(fd,4);
  9010. if( index == 0 )
  9011. trade_tradeaddzeny(sd, amount);
  9012. else
  9013. trade_tradeadditem(sd, index, (short)amount);
  9014. }
  9015. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9016. /// 00eb
  9017. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9018. {
  9019. trade_tradeok(sd);
  9020. }
  9021. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9022. /// 00ed
  9023. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9024. {
  9025. trade_tradecancel(sd);
  9026. }
  9027. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9028. /// 00ef
  9029. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9030. {
  9031. trade_tradecommit(sd);
  9032. }
  9033. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9034. /// 0118
  9035. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9036. {
  9037. pc_stop_attack(sd);
  9038. }
  9039. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9040. /// 0126 <index>.W <amount>.L
  9041. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9042. {
  9043. if (pc_istrading(sd))
  9044. return;
  9045. if (!pc_iscarton(sd))
  9046. return;
  9047. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9048. }
  9049. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9050. /// 0127 <index>.W <amount>.L
  9051. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9052. {
  9053. if (!pc_iscarton(sd))
  9054. return;
  9055. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9056. }
  9057. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9058. /// 012a
  9059. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9060. {
  9061. /**
  9062. * Attempts to remove these options when this function is called (will remove all available)
  9063. **/
  9064. #ifdef NEW_CARTS
  9065. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9066. if( sd->sc.data[SC_PUSH_CART] )
  9067. pc_setcart(sd,0);
  9068. #else
  9069. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9070. #endif
  9071. }
  9072. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9073. /// 01af <num>.W
  9074. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9075. {// TODO: State tracking?
  9076. int type;
  9077. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  9078. return;
  9079. type = (int)RFIFOW(fd,2);
  9080. #ifdef NEW_CARTS
  9081. if( (type == 9 && sd->status.base_level > 131) ||
  9082. (type == 8 && sd->status.base_level > 121) ||
  9083. (type == 7 && sd->status.base_level > 111) ||
  9084. (type == 6 && sd->status.base_level > 101) ||
  9085. (type == 5 && sd->status.base_level > 90) ||
  9086. (type == 4 && sd->status.base_level > 80) ||
  9087. (type == 3 && sd->status.base_level > 65) ||
  9088. (type == 2 && sd->status.base_level > 40) ||
  9089. (type == 1))
  9090. #else
  9091. if( (type == 5 && sd->status.base_level > 90) ||
  9092. (type == 4 && sd->status.base_level > 80) ||
  9093. (type == 3 && sd->status.base_level > 65) ||
  9094. (type == 2 && sd->status.base_level > 40) ||
  9095. (type == 1))
  9096. #endif
  9097. pc_setcart(sd,type);
  9098. }
  9099. /// Request to increase status (CZ_STATUS_CHANGE).
  9100. /// 00bb <status id>.W <amount>.B
  9101. /// status id:
  9102. /// SP_STR ~ SP_LUK
  9103. /// amount:
  9104. /// client sends always 1 for this, even when using /str+ and
  9105. /// the like
  9106. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9107. {
  9108. pc_statusup(sd,RFIFOW(fd,2));
  9109. }
  9110. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9111. /// 0112 <skill id>.W
  9112. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9113. {
  9114. pc_skillup(sd,RFIFOW(fd,2));
  9115. }
  9116. 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)
  9117. {
  9118. int lv;
  9119. if( !hd )
  9120. return;
  9121. if( skillnotok_hom(skill_id, hd) )
  9122. return;
  9123. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9124. target_id = hd->bl.id;
  9125. if( hd->ud.skilltimer != INVALID_TIMER )
  9126. {
  9127. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9128. }
  9129. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9130. return;
  9131. lv = merc_hom_checkskill(hd, skill_id);
  9132. if( skill_lv > lv )
  9133. skill_lv = lv;
  9134. if( skill_lv )
  9135. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9136. }
  9137. 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)
  9138. {
  9139. int lv;
  9140. if( !hd )
  9141. return;
  9142. if( skillnotok_hom(skill_id, hd) )
  9143. return;
  9144. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9145. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9146. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9147. return;
  9148. if( hd->sc.data[SC_BASILICA] )
  9149. return;
  9150. lv = merc_hom_checkskill(hd, skill_id);
  9151. if( skill_lv > lv )
  9152. skill_lv = lv;
  9153. if( skill_lv )
  9154. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9155. }
  9156. 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)
  9157. {
  9158. int lv;
  9159. if( !md )
  9160. return;
  9161. if( skillnotok_mercenary(skill_id, md) )
  9162. return;
  9163. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9164. target_id = md->bl.id;
  9165. if( md->ud.skilltimer != INVALID_TIMER )
  9166. {
  9167. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9168. }
  9169. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9170. return;
  9171. lv = mercenary_checkskill(md, skill_id);
  9172. if( skill_lv > lv )
  9173. skill_lv = lv;
  9174. if( skill_lv )
  9175. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9176. }
  9177. 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)
  9178. {
  9179. int lv;
  9180. if( !md )
  9181. return;
  9182. if( skillnotok_mercenary(skill_id, md) )
  9183. return;
  9184. if( md->ud.skilltimer != INVALID_TIMER )
  9185. return;
  9186. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9187. {
  9188. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9189. return;
  9190. }
  9191. if( md->sc.data[SC_BASILICA] )
  9192. return;
  9193. lv = mercenary_checkskill(md, skill_id);
  9194. if( skill_lv > lv )
  9195. skill_lv = lv;
  9196. if( skill_lv )
  9197. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9198. }
  9199. /// Request to use a targeted skill.
  9200. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9201. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9202. /// There are various variants of this packet, some of them have padding between fields.
  9203. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9204. {
  9205. uint16 skill_id, skill_lv;
  9206. int tmp, target_id;
  9207. unsigned int tick = gettick();
  9208. skill_lv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9209. skill_id = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9210. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9211. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9212. tmp = skill_get_inf(skill_id);
  9213. if (tmp&INF_GROUND_SKILL || !tmp)
  9214. return; //Using a ground/passive skill on a target? WRONG.
  9215. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL )
  9216. {
  9217. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9218. return;
  9219. }
  9220. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL )
  9221. {
  9222. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9223. return;
  9224. }
  9225. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9226. sd->idletime = last_tick;
  9227. if( pc_cant_act(sd) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9228. return;
  9229. if( pc_issit(sd) )
  9230. return;
  9231. if( skillnotok(skill_id, sd) )
  9232. return;
  9233. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9234. target_id = sd->bl.id; // never trust the client
  9235. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9236. target_id = sd->bl.id;
  9237. if( sd->ud.skilltimer != INVALID_TIMER )
  9238. {
  9239. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9240. return;
  9241. }
  9242. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  9243. {
  9244. if( sd->skillitem != skill_id )
  9245. {
  9246. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9247. return;
  9248. }
  9249. }
  9250. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9251. return;
  9252. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9253. return; // On basilica only caster can use Basilica again to stop it.
  9254. if( sd->menuskill_id ) {
  9255. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9256. clif_menuskill_clear(sd); //Cancel pet capture.
  9257. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9258. return; //Can't use skills while a menu is open.
  9259. }
  9260. if( sd->skillitem == skill_id ) {
  9261. if( skill_lv != sd->skillitemlv )
  9262. skill_lv = sd->skillitemlv;
  9263. if( !(tmp&INF_SELF_SKILL) )
  9264. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9265. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9266. return;
  9267. }
  9268. sd->skillitem = sd->skillitemlv = 0;
  9269. if( skill_id >= GD_SKILLBASE ) {
  9270. if( sd->state.gmaster_flag )
  9271. skill_lv = guild_checkskill(sd->state.gmaster_flag, skill_id);
  9272. else
  9273. skill_lv = 0;
  9274. } else {
  9275. tmp = pc_checkskill(sd, skill_id);
  9276. if( skill_lv > tmp )
  9277. skill_lv = tmp;
  9278. }
  9279. pc_delinvincibletimer(sd);
  9280. if( skill_lv )
  9281. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9282. }
  9283. /*==========================================
  9284. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9285. *------------------------------------------*/
  9286. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9287. {
  9288. unsigned int tick = gettick();
  9289. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9290. return; //Using a target skill on the ground? WRONG.
  9291. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9292. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9293. return;
  9294. }
  9295. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL )
  9296. {
  9297. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9298. return;
  9299. }
  9300. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9301. sd->idletime = last_tick;
  9302. if( skillnotok(skill_id, sd) )
  9303. return;
  9304. if( skillmoreinfo != -1 )
  9305. {
  9306. if( pc_issit(sd) )
  9307. {
  9308. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9309. return;
  9310. }
  9311. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9312. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9313. }
  9314. if( sd->ud.skilltimer != INVALID_TIMER )
  9315. return;
  9316. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9317. if( sd->skillitem != skill_id ) {
  9318. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9319. return;
  9320. }
  9321. }
  9322. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9323. return;
  9324. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9325. return; // On basilica only caster can use Basilica again to stop it.
  9326. if( sd->menuskill_id ) {
  9327. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9328. clif_menuskill_clear(sd); //Cancel pet capture.
  9329. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9330. return; //Can't use skills while a menu is open.
  9331. }
  9332. pc_delinvincibletimer(sd);
  9333. if( sd->skillitem == skill_id ) {
  9334. if( skill_lv != sd->skillitemlv )
  9335. skill_lv = sd->skillitemlv;
  9336. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9337. } else {
  9338. int lv;
  9339. sd->skillitem = sd->skillitemlv = 0;
  9340. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9341. if( skill_lv > lv )
  9342. skill_lv = lv;
  9343. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9344. }
  9345. }
  9346. }
  9347. /// Request to use a ground skill.
  9348. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9349. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9350. /// There are various variants of this packet, some of them have padding between fields.
  9351. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9352. {
  9353. if (pc_cant_act(sd))
  9354. return;
  9355. if (pc_issit(sd))
  9356. return;
  9357. clif_parse_UseSkillToPosSub(fd, sd,
  9358. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9359. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9360. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9361. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9362. -1 //Skill more info.
  9363. );
  9364. }
  9365. /// Request to use a ground skill with text.
  9366. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9367. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9368. /// There are various variants of this packet, some of them have padding between fields.
  9369. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9370. {
  9371. if (pc_cant_act(sd))
  9372. return;
  9373. if (pc_issit(sd))
  9374. return;
  9375. clif_parse_UseSkillToPosSub(fd, sd,
  9376. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9377. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9378. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9379. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9380. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9381. );
  9382. }
  9383. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9384. /// 011b <skill id>.W <map name>.16B
  9385. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9386. {
  9387. uint16 skill_id = RFIFOW(fd,2);
  9388. char map_name[MAP_NAME_LENGTH];
  9389. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9390. if(skill_id != sd->menuskill_id)
  9391. return;
  9392. if( pc_cant_act(sd) ) {
  9393. clif_menuskill_clear(sd);
  9394. return;
  9395. }
  9396. pc_delinvincibletimer(sd);
  9397. skill_castend_map(sd,skill_id,map_name);
  9398. }
  9399. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9400. /// 011d
  9401. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9402. {
  9403. if (!pc_isdead(sd))
  9404. pc_memo(sd,-1);
  9405. }
  9406. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9407. /// 018e <name id>.W { <material id>.W }*3
  9408. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9409. {
  9410. switch( sd->menuskill_id ) {
  9411. case -1:
  9412. case AM_PHARMACY:
  9413. case RK_RUNEMASTERY:
  9414. case GC_RESEARCHNEWPOISON:
  9415. break;
  9416. default:
  9417. return;
  9418. }
  9419. if (pc_istrading(sd)) {
  9420. //Make it fail to avoid shop exploits where you sell something different than you see.
  9421. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9422. clif_menuskill_clear(sd);
  9423. return;
  9424. }
  9425. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9426. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9427. clif_menuskill_clear(sd);
  9428. }
  9429. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9430. /// 025b <mk type>.W <name id>.W
  9431. /// mk type:
  9432. /// 1 = cooking
  9433. /// 2 = arrow
  9434. /// 3 = elemental
  9435. /// 4 = GN_MIX_COOKING
  9436. /// 5 = GN_MAKEBOMB
  9437. /// 6 = GN_S_PHARMACY
  9438. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9439. int type = RFIFOW(fd,2);
  9440. int nameid = RFIFOW(fd,4);
  9441. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9442. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9443. return;
  9444. if (pc_istrading(sd)) {
  9445. //Make it fail to avoid shop exploits where you sell something different than you see.
  9446. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9447. clif_menuskill_clear(sd);
  9448. return;
  9449. }
  9450. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9451. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9452. clif_menuskill_clear(sd);
  9453. }
  9454. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9455. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9456. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9457. {
  9458. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9459. return;
  9460. if (pc_istrading(sd)) {
  9461. //Make it fail to avoid shop exploits where you sell something different than you see.
  9462. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9463. clif_menuskill_clear(sd);
  9464. return;
  9465. }
  9466. skill_repairweapon(sd,RFIFOW(fd,2));
  9467. clif_menuskill_clear(sd);
  9468. }
  9469. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9470. /// 0222 <index>.L
  9471. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9472. {
  9473. int idx;
  9474. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9475. return;
  9476. if (pc_istrading(sd)) {
  9477. //Make it fail to avoid shop exploits where you sell something different than you see.
  9478. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9479. clif_menuskill_clear(sd);
  9480. return;
  9481. }
  9482. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9483. skill_weaponrefine(sd, idx-2);
  9484. clif_menuskill_clear(sd);
  9485. }
  9486. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9487. /// 00b8 <npc id>.L <choice>.B
  9488. /// choice:
  9489. /// 1~254 = menu item
  9490. /// 255 = cancel
  9491. /// NOTE: If there were more than 254 items in the list, choice
  9492. /// overflows to choice%256.
  9493. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9494. {
  9495. int npc_id = RFIFOL(fd,2);
  9496. uint8 select = RFIFOB(fd,6);
  9497. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  9498. {
  9499. TBL_NPC* nd = map_id2nd(npc_id);
  9500. ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name);
  9501. clif_GM_kick(NULL,sd);
  9502. return;
  9503. }
  9504. sd->npc_menu = select;
  9505. npc_scriptcont(sd,npc_id);
  9506. }
  9507. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9508. /// 00b9 <npc id>.L
  9509. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9510. {
  9511. npc_scriptcont(sd,RFIFOL(fd,2));
  9512. }
  9513. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9514. /// 0143 <npc id>.L <value>.L
  9515. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9516. {
  9517. int npcid = RFIFOL(fd,2);
  9518. int amount = (int)RFIFOL(fd,6);
  9519. sd->npc_amount = amount;
  9520. npc_scriptcont(sd, npcid);
  9521. }
  9522. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9523. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9524. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9525. {
  9526. int message_len = RFIFOW(fd,2)-8;
  9527. int npcid = RFIFOL(fd,4);
  9528. const char* message = (char*)RFIFOP(fd,8);
  9529. if( message_len <= 0 )
  9530. return; // invalid input
  9531. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9532. npc_scriptcont(sd, npcid);
  9533. }
  9534. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9535. /// 0146 <npc id>.L
  9536. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9537. {
  9538. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9539. return;
  9540. npc_scriptcont(sd,RFIFOL(fd,2));
  9541. }
  9542. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9543. /// 0178 <index>.W
  9544. /// index:
  9545. /// -1 = cancel
  9546. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9547. {
  9548. short idx = RFIFOW(fd,2);
  9549. if (sd->menuskill_id != MC_IDENTIFY)
  9550. return;
  9551. if( idx == -1 ) {// cancel pressed
  9552. clif_menuskill_clear(sd);
  9553. return;
  9554. }
  9555. skill_identify(sd,idx-2);
  9556. clif_menuskill_clear(sd);
  9557. }
  9558. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9559. /// 01ae <name id>.W
  9560. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9561. {
  9562. if (pc_istrading(sd)) {
  9563. //Make it fail to avoid shop exploits where you sell something different than you see.
  9564. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9565. clif_menuskill_clear(sd);
  9566. return;
  9567. }
  9568. switch( sd->menuskill_id ) {
  9569. case AC_MAKINGARROW:
  9570. skill_arrow_create(sd,RFIFOW(fd,2));
  9571. break;
  9572. case SA_CREATECON:
  9573. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9574. break;
  9575. case WL_READING_SB:
  9576. skill_spellbook(sd,RFIFOW(fd,2));
  9577. break;
  9578. case GC_POISONINGWEAPON:
  9579. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9580. break;
  9581. case NC_MAGICDECOY:
  9582. skill_magicdecoy(sd,RFIFOW(fd,2));
  9583. break;
  9584. }
  9585. clif_menuskill_clear(sd);
  9586. }
  9587. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9588. /// 01ce <skill id>.L
  9589. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9590. {
  9591. if (sd->menuskill_id != SA_AUTOSPELL)
  9592. return;
  9593. skill_autospell(sd,RFIFOL(fd,2));
  9594. clif_menuskill_clear(sd);
  9595. }
  9596. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9597. /// 017a <card index>.W
  9598. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9599. {
  9600. if (sd->state.trading != 0)
  9601. return;
  9602. clif_use_card(sd,RFIFOW(fd,2)-2);
  9603. }
  9604. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9605. /// 017c <card index>.W <equip index>.W
  9606. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9607. {
  9608. if (sd->state.trading != 0)
  9609. return;
  9610. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9611. }
  9612. /// Request of character's name by char ID.
  9613. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9614. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9615. /// There are various variants of this packet, some of them have padding between fields.
  9616. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9617. {
  9618. int charid;
  9619. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9620. map_reqnickdb(sd, charid);
  9621. }
  9622. /// /resetskill /resetstate (CZ_RESET).
  9623. /// Request to reset stats or skills.
  9624. /// 0197 <type>.W
  9625. /// type:
  9626. /// 0 = state
  9627. /// 1 = skill
  9628. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9629. char cmd[15];
  9630. if( RFIFOW(fd,2) )
  9631. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9632. else
  9633. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9634. is_atcommand(fd, sd, cmd, 1);
  9635. }
  9636. /// /lb /nlb (CZ_LOCALBROADCAST).
  9637. /// Request to broadcast a message on current map.
  9638. /// 019c <packet len>.W <text>.?B
  9639. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9640. {
  9641. char command[CHAT_SIZE_MAX+16];
  9642. char* msg = (char*)RFIFOP(fd,4);
  9643. unsigned int len = RFIFOW(fd,2)-4;
  9644. // as the length varies depending on the command used, just block unreasonably long strings
  9645. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9646. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9647. is_atcommand(fd, sd, command, 1);
  9648. }
  9649. /// Request to move an item from inventory to storage.
  9650. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9651. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9652. /// There are various variants of this packet, some of them have padding between fields.
  9653. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9654. {
  9655. int item_index, item_amount;
  9656. if (pc_istrading(sd))
  9657. return;
  9658. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9659. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9660. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9661. return;
  9662. if (sd->state.storage_flag == 1)
  9663. storage_storageadd(sd, item_index, item_amount);
  9664. else
  9665. if (sd->state.storage_flag == 2)
  9666. storage_guild_storageadd(sd, item_index, item_amount);
  9667. }
  9668. /// Request to move an item from storage to inventory.
  9669. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9670. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9671. /// There are various variants of this packet, some of them have padding between fields.
  9672. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9673. {
  9674. int item_index, item_amount;
  9675. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9676. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9677. if (sd->state.storage_flag == 1)
  9678. storage_storageget(sd, item_index, item_amount);
  9679. else
  9680. if(sd->state.storage_flag == 2)
  9681. storage_guild_storageget(sd, item_index, item_amount);
  9682. }
  9683. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9684. /// 0129 <index>.W <amount>.L
  9685. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9686. {
  9687. if( sd->state.vending )
  9688. return;
  9689. if (!pc_iscarton(sd))
  9690. return;
  9691. if (sd->state.storage_flag == 1)
  9692. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9693. else
  9694. if (sd->state.storage_flag == 2)
  9695. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9696. }
  9697. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9698. /// 0128 <index>.W <amount>.L
  9699. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9700. {
  9701. if( sd->state.vending )
  9702. return;
  9703. if (!pc_iscarton(sd))
  9704. return;
  9705. if (sd->state.storage_flag == 1)
  9706. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9707. else
  9708. if (sd->state.storage_flag == 2)
  9709. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9710. }
  9711. /// Request to close storage (CZ_CLOSE_STORE).
  9712. /// 00f7
  9713. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9714. {
  9715. if( sd->state.storage_flag == 1 )
  9716. storage_storageclose(sd);
  9717. else
  9718. if( sd->state.storage_flag == 2 )
  9719. storage_guild_storageclose(sd);
  9720. }
  9721. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9722. /// 023a <info>.W
  9723. /// info:
  9724. /// 0 = password has not been set yet
  9725. /// 1 = storage is password-protected
  9726. /// 8 = too many wrong passwords
  9727. /// ? = ignored
  9728. /// NOTE: This packet is only available on certain non-kRO clients.
  9729. void clif_storagepassword(struct map_session_data* sd, short info)
  9730. {
  9731. int fd = sd->fd;
  9732. WFIFOHEAD(fd,packet_len(0x23a));
  9733. WFIFOW(fd,0) = 0x23a;
  9734. WFIFOW(fd,2) = info;
  9735. WFIFOSET(fd,packet_len(0x23a));
  9736. }
  9737. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9738. /// 023b <type>.W <password>.16B <new password>.16B
  9739. /// type:
  9740. /// 2 = change password
  9741. /// 3 = check password
  9742. /// NOTE: This packet is only available on certain non-kRO clients.
  9743. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9744. {
  9745. //TODO
  9746. }
  9747. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9748. /// 023c <result>.W <error count>.W
  9749. /// result:
  9750. /// 4 = password change success
  9751. /// 5 = password change failure
  9752. /// 6 = password check success
  9753. /// 7 = password check failure
  9754. /// 8 = too many wrong passwords
  9755. /// ? = ignored
  9756. /// NOTE: This packet is only available on certain non-kRO clients.
  9757. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9758. {
  9759. int fd = sd->fd;
  9760. WFIFOHEAD(fd,packet_len(0x23c));
  9761. WFIFOW(fd,0) = 0x23c;
  9762. WFIFOW(fd,2) = result;
  9763. WFIFOW(fd,4) = error_count;
  9764. WFIFOSET(fd,packet_len(0x23c));
  9765. }
  9766. /// Party creation request
  9767. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9768. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9769. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9770. {
  9771. char* name = (char*)RFIFOP(fd,2);
  9772. name[NAME_LENGTH-1] = '\0';
  9773. if( map[sd->bl.m].flag.partylock )
  9774. {// Party locked.
  9775. clif_displaymessage(fd, msg_txt(227));
  9776. return;
  9777. }
  9778. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9779. {
  9780. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9781. return;
  9782. }
  9783. party_create(sd,name,0,0);
  9784. }
  9785. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9786. {
  9787. char* name = (char*)RFIFOP(fd,2);
  9788. int item1 = RFIFOB(fd,26);
  9789. int item2 = RFIFOB(fd,27);
  9790. name[NAME_LENGTH-1] = '\0';
  9791. if( map[sd->bl.m].flag.partylock )
  9792. {// Party locked.
  9793. clif_displaymessage(fd, msg_txt(227));
  9794. return;
  9795. }
  9796. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9797. {
  9798. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9799. return;
  9800. }
  9801. party_create(sd,name,item1,item2);
  9802. }
  9803. /// Party invitation request
  9804. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9805. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9806. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9807. {
  9808. struct map_session_data *t_sd;
  9809. if(map[sd->bl.m].flag.partylock)
  9810. {// Party locked.
  9811. clif_displaymessage(fd, msg_txt(227));
  9812. return;
  9813. }
  9814. t_sd = map_id2sd(RFIFOL(fd,2));
  9815. if(t_sd && t_sd->state.noask)
  9816. {// @noask [LuzZza]
  9817. clif_noask_sub(sd, t_sd, 1);
  9818. return;
  9819. }
  9820. party_invite(sd, t_sd);
  9821. }
  9822. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9823. {
  9824. struct map_session_data *t_sd;
  9825. char *name = (char*)RFIFOP(fd,2);
  9826. name[NAME_LENGTH-1] = '\0';
  9827. if(map[sd->bl.m].flag.partylock)
  9828. {// Party locked.
  9829. clif_displaymessage(fd, msg_txt(227));
  9830. return;
  9831. }
  9832. t_sd = map_nick2sd(name);
  9833. if(t_sd && t_sd->state.noask)
  9834. {// @noask [LuzZza]
  9835. clif_noask_sub(sd, t_sd, 1);
  9836. return;
  9837. }
  9838. party_invite(sd, t_sd);
  9839. }
  9840. /// Party invitation reply
  9841. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9842. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9843. /// flag:
  9844. /// 0 = reject
  9845. /// 1 = accept
  9846. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9847. {
  9848. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9849. }
  9850. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9851. {
  9852. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9853. }
  9854. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9855. /// 0100
  9856. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9857. {
  9858. if(map[sd->bl.m].flag.partylock)
  9859. { //Guild locked.
  9860. clif_displaymessage(fd, msg_txt(227));
  9861. return;
  9862. }
  9863. party_leave(sd);
  9864. }
  9865. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9866. /// 0103 <account id>.L <char name>.24B
  9867. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9868. {
  9869. if(map[sd->bl.m].flag.partylock)
  9870. { //Guild locked.
  9871. clif_displaymessage(fd, msg_txt(227));
  9872. return;
  9873. }
  9874. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9875. }
  9876. /// Request to change party options.
  9877. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9878. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9879. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9880. {
  9881. struct party_data *p;
  9882. int i;
  9883. if( !sd->status.party_id )
  9884. return;
  9885. p = party_search(sd->status.party_id);
  9886. if( p == NULL )
  9887. return;
  9888. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9889. if( i == MAX_PARTY )
  9890. return; //Shouldn't happen
  9891. if( !p->party.member[i].leader )
  9892. return;
  9893. #if PACKETVER < 20090603
  9894. //Client can't change the item-field
  9895. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9896. #else
  9897. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9898. #endif
  9899. }
  9900. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9901. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9902. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9903. {
  9904. const char* text = (char*)RFIFOP(fd,4);
  9905. int textlen = RFIFOW(fd,2) - 4;
  9906. char *name, *message;
  9907. int namelen, messagelen;
  9908. // validate packet and retrieve name and message
  9909. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9910. return;
  9911. if( is_atcommand(fd, sd, message, 1) )
  9912. return;
  9913. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9914. return;
  9915. if( battle_config.min_chat_delay )
  9916. { //[Skotlex]
  9917. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9918. return;
  9919. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9920. }
  9921. party_send_message(sd, text, textlen);
  9922. }
  9923. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9924. /// 07da <account id>.L
  9925. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9926. {
  9927. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9928. }
  9929. /// Party Booking in KRO [Spiria]
  9930. ///
  9931. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9932. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9933. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9934. {
  9935. short level = RFIFOW(fd,2);
  9936. short mapid = RFIFOW(fd,4);
  9937. short job[PARTY_BOOKING_JOBS];
  9938. int i;
  9939. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9940. job[i] = RFIFOB(fd,6+i*2);
  9941. party_booking_register(sd, level, mapid, job);
  9942. }
  9943. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9944. /// 0803 <result>.W
  9945. /// result:
  9946. /// 0 = success
  9947. /// 1 = failure
  9948. /// 2 = already registered
  9949. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9950. {
  9951. int fd = sd->fd;
  9952. WFIFOHEAD(fd,packet_len(0x803));
  9953. WFIFOW(fd,0) = 0x803;
  9954. WFIFOW(fd,2) = flag;
  9955. WFIFOSET(fd,packet_len(0x803));
  9956. }
  9957. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9958. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9959. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9960. {
  9961. short level = RFIFOW(fd,2);
  9962. short mapid = RFIFOW(fd,4);
  9963. short job = RFIFOW(fd,6);
  9964. unsigned long lastindex = RFIFOL(fd,8);
  9965. short resultcount = RFIFOW(fd,12);
  9966. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9967. }
  9968. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9969. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9970. /// more results:
  9971. /// 0 = no
  9972. /// 1 = yes
  9973. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9974. {
  9975. int i, j;
  9976. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9977. struct party_booking_ad_info *pb_ad;
  9978. WFIFOHEAD(fd,size*count + 5);
  9979. WFIFOW(fd,0) = 0x805;
  9980. WFIFOW(fd,2) = size*count + 5;
  9981. WFIFOB(fd,4) = more_result;
  9982. for(i=0; i<count; i++)
  9983. {
  9984. pb_ad = results[i];
  9985. WFIFOL(fd,i*size+5) = pb_ad->index;
  9986. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9987. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9988. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9989. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9990. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9991. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9992. }
  9993. WFIFOSET(fd,WFIFOW(fd,2));
  9994. }
  9995. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9996. /// 0806
  9997. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9998. {
  9999. if(party_booking_delete(sd))
  10000. clif_PartyBookingDeleteAck(sd, 0);
  10001. }
  10002. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10003. /// 0807 <result>.W
  10004. /// result:
  10005. /// 0 = success
  10006. /// 1 = success (auto-removed expired ad)
  10007. /// 2 = failure
  10008. /// 3 = nothing registered
  10009. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10010. {
  10011. int fd = sd->fd;
  10012. WFIFOHEAD(fd,packet_len(0x807));
  10013. WFIFOW(fd,0) = 0x807;
  10014. WFIFOW(fd,2) = flag;
  10015. WFIFOSET(fd,packet_len(0x807));
  10016. }
  10017. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10018. /// 0808 { <job>.W }*6
  10019. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10020. {
  10021. short job[PARTY_BOOKING_JOBS];
  10022. int i;
  10023. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10024. job[i] = RFIFOW(fd,2+i*2);
  10025. party_booking_update(sd, job);
  10026. }
  10027. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10028. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10029. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10030. {
  10031. int i;
  10032. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10033. if(pb_ad == NULL) return;
  10034. WBUFW(buf,0) = 0x809;
  10035. WBUFL(buf,2) = pb_ad->index;
  10036. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10037. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10038. WBUFW(buf,34) = pb_ad->p_detail.level;
  10039. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10040. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10041. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10042. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10043. }
  10044. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10045. /// 080a <index>.L { <job>.W }*6
  10046. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10047. {
  10048. int i;
  10049. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10050. if(pb_ad == NULL) return;
  10051. WBUFW(buf,0) = 0x80a;
  10052. WBUFL(buf,2) = pb_ad->index;
  10053. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10054. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10055. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10056. }
  10057. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10058. /// 080b <index>.L
  10059. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10060. {
  10061. uint8 buf[6];
  10062. WBUFW(buf,0) = 0x80b;
  10063. WBUFL(buf,2) = index;
  10064. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10065. }
  10066. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10067. /// 012e
  10068. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10069. {
  10070. vending_closevending(sd);
  10071. }
  10072. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10073. /// 0130 <account id>.L
  10074. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10075. {
  10076. if( sd->npc_id )
  10077. {// using an NPC
  10078. return;
  10079. }
  10080. vending_vendinglistreq(sd,RFIFOL(fd,2));
  10081. }
  10082. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10083. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10084. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  10085. {
  10086. int len = (int)RFIFOW(fd,2) - 8;
  10087. int id = (int)RFIFOL(fd,4);
  10088. const uint8* data = (uint8*)RFIFOP(fd,8);
  10089. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10090. // whether it fails or not, the buy window is closed
  10091. sd->vended_id = 0;
  10092. }
  10093. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10094. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10095. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  10096. {
  10097. int len = (int)RFIFOW(fd,2) - 12;
  10098. int aid = (int)RFIFOL(fd,4);
  10099. int uid = (int)RFIFOL(fd,8);
  10100. const uint8* data = (uint8*)RFIFOP(fd,12);
  10101. vending_purchasereq(sd, aid, uid, data, len/4);
  10102. // whether it fails or not, the buy window is closed
  10103. sd->vended_id = 0;
  10104. }
  10105. /// Confirm or cancel the shop preparation window.
  10106. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10107. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10108. /// result:
  10109. /// 0 = canceled
  10110. /// 1 = open
  10111. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  10112. {
  10113. short len = (short)RFIFOW(fd,2) - 85;
  10114. const char* message = (char*)RFIFOP(fd,4);
  10115. bool flag = (bool)RFIFOB(fd,84);
  10116. const uint8* data = (uint8*)RFIFOP(fd,85);
  10117. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10118. return;
  10119. if( map[sd->bl.m].flag.novending ) {
  10120. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  10121. return;
  10122. }
  10123. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10124. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  10125. return;
  10126. }
  10127. if( vending_checknearnpc(&sd->bl) ) {
  10128. char output[150];
  10129. sprintf(output, msg_txt(662), battle_config.min_npc_vending_distance);
  10130. clif_displaymessage(sd->fd, output);
  10131. clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0);
  10132. return;
  10133. }
  10134. if( message[0] == '\0' ) // invalid input
  10135. return;
  10136. vending_openvending(sd, message, flag, data, len/8);
  10137. }
  10138. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10139. /// 0165 <char id>.L <guild name>.24B
  10140. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  10141. {
  10142. char* name = (char*)RFIFOP(fd,6);
  10143. name[NAME_LENGTH-1] = '\0';
  10144. if(map[sd->bl.m].flag.guildlock)
  10145. { //Guild locked.
  10146. clif_displaymessage(fd, msg_txt(228));
  10147. return;
  10148. }
  10149. guild_create(sd, name);
  10150. }
  10151. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10152. /// 014d
  10153. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10154. {
  10155. clif_guild_masterormember(sd);
  10156. }
  10157. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10158. /// 014f <type>.L
  10159. /// type:
  10160. /// 0 = basic info
  10161. /// 1 = member manager
  10162. /// 2 = positions
  10163. /// 3 = skills
  10164. /// 4 = expulsion list
  10165. /// 5 = unknown (GM_ALLGUILDLIST)
  10166. /// 6 = notice
  10167. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10168. {
  10169. if( !sd->status.guild_id && !sd->bg_id )
  10170. return;
  10171. switch( RFIFOL(fd,2) )
  10172. {
  10173. case 0: // Basic Information Guild, hostile alliance information
  10174. clif_guild_basicinfo(sd);
  10175. clif_guild_allianceinfo(sd);
  10176. break;
  10177. case 1: // Members list, list job title
  10178. clif_guild_positionnamelist(sd);
  10179. clif_guild_memberlist(sd);
  10180. break;
  10181. case 2: // List job title, title information list
  10182. clif_guild_positionnamelist(sd);
  10183. clif_guild_positioninfolist(sd);
  10184. break;
  10185. case 3: // Skill list
  10186. clif_guild_skillinfo(sd);
  10187. break;
  10188. case 4: // Expulsion list
  10189. clif_guild_expulsionlist(sd);
  10190. break;
  10191. default:
  10192. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10193. break;
  10194. }
  10195. }
  10196. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10197. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10198. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10199. {
  10200. int i;
  10201. if(!sd->state.gmaster_flag)
  10202. return;
  10203. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  10204. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10205. }
  10206. }
  10207. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10208. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10209. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10210. {
  10211. int i;
  10212. if(!sd->state.gmaster_flag)
  10213. return;
  10214. for(i=4;i<RFIFOW(fd,2);i+=12){
  10215. guild_change_memberposition(sd->status.guild_id,
  10216. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10217. }
  10218. }
  10219. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10220. /// 0151 <guild id>.L
  10221. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10222. {
  10223. struct guild* g;
  10224. int guild_id = RFIFOL(fd,2);
  10225. if( (g = guild_search(guild_id)) != NULL )
  10226. clif_guild_emblem(sd,g);
  10227. }
  10228. /// Validates data of a guild emblem (compressed bitmap)
  10229. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10230. {
  10231. bool success;
  10232. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10233. unsigned long buf_len = sizeof(buf);
  10234. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10235. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10236. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10237. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10238. ;
  10239. return success;
  10240. }
  10241. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10242. /// 0153 <packet len>.W <emblem data>.?B
  10243. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10244. {
  10245. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10246. const uint8* emblem = RFIFOP(fd,4);
  10247. if( !emblem_len || !sd->state.gmaster_flag )
  10248. return;
  10249. if( !clif_validate_emblem(emblem, emblem_len) )
  10250. {
  10251. 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);
  10252. return;
  10253. }
  10254. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10255. }
  10256. /// Guild notice update request (CZ_GUILD_NOTICE).
  10257. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10258. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10259. {
  10260. int guild_id = RFIFOL(fd,2);
  10261. char* msg1 = (char*)RFIFOP(fd,6);
  10262. char* msg2 = (char*)RFIFOP(fd,66);
  10263. if(!sd->state.gmaster_flag)
  10264. return;
  10265. // compensate for some client defects when using multilanguage mode
  10266. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10267. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10268. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10269. guild_change_notice(sd, guild_id, msg1, msg2);
  10270. }
  10271. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10272. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10273. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10274. {
  10275. struct map_session_data *t_sd;
  10276. if(map[sd->bl.m].flag.guildlock)
  10277. { //Guild locked.
  10278. clif_displaymessage(fd, msg_txt(228));
  10279. return;
  10280. }
  10281. t_sd = map_id2sd(RFIFOL(fd,2));
  10282. // @noask [LuzZza]
  10283. if(t_sd && t_sd->state.noask) {
  10284. clif_noask_sub(sd, t_sd, 2);
  10285. return;
  10286. }
  10287. guild_invite(sd,t_sd);
  10288. }
  10289. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10290. /// 016b <guild id>.L <answer>.L
  10291. /// answer:
  10292. /// 0 = refuse
  10293. /// 1 = accept
  10294. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10295. {
  10296. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10297. }
  10298. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10299. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10300. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10301. {
  10302. if(map[sd->bl.m].flag.guildlock)
  10303. { //Guild locked.
  10304. clif_displaymessage(fd, msg_txt(228));
  10305. return;
  10306. }
  10307. if( sd->bg_id )
  10308. {
  10309. clif_displaymessage(fd, msg_txt(670)); //"You can't leave battleground guilds."
  10310. return;
  10311. }
  10312. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10313. }
  10314. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10315. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10316. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10317. {
  10318. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10319. { // Guild locked.
  10320. clif_displaymessage(fd, msg_txt(228));
  10321. return;
  10322. }
  10323. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10324. }
  10325. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10326. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10327. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10328. {
  10329. const char* text = (char*)RFIFOP(fd,4);
  10330. int textlen = RFIFOW(fd,2) - 4;
  10331. char *name, *message;
  10332. int namelen, messagelen;
  10333. // validate packet and retrieve name and message
  10334. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10335. return;
  10336. if( is_atcommand(fd, sd, message, 1) )
  10337. return;
  10338. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10339. return;
  10340. if( battle_config.min_chat_delay )
  10341. { //[Skotlex]
  10342. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10343. return;
  10344. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10345. }
  10346. if( sd->bg_id )
  10347. bg_send_message(sd, text, textlen);
  10348. else
  10349. guild_send_message(sd, text, textlen);
  10350. }
  10351. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10352. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10353. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10354. {
  10355. struct map_session_data *t_sd;
  10356. if(!sd->state.gmaster_flag)
  10357. return;
  10358. if(map[sd->bl.m].flag.guildlock)
  10359. { //Guild locked.
  10360. clif_displaymessage(fd, msg_txt(228));
  10361. return;
  10362. }
  10363. t_sd = map_id2sd(RFIFOL(fd,2));
  10364. // @noask [LuzZza]
  10365. if(t_sd && t_sd->state.noask) {
  10366. clif_noask_sub(sd, t_sd, 3);
  10367. return;
  10368. }
  10369. guild_reqalliance(sd,t_sd);
  10370. }
  10371. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10372. /// 0172 <inviter account id>.L <answer>.L
  10373. /// answer:
  10374. /// 0 = refuse
  10375. /// 1 = accept
  10376. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10377. {
  10378. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10379. }
  10380. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10381. /// 0183 <opponent guild id>.L <relation>.L
  10382. /// relation:
  10383. /// 0 = Ally
  10384. /// 1 = Enemy
  10385. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10386. {
  10387. if(!sd->state.gmaster_flag)
  10388. return;
  10389. if(map[sd->bl.m].flag.guildlock)
  10390. { //Guild locked.
  10391. clif_displaymessage(fd, msg_txt(228));
  10392. return;
  10393. }
  10394. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10395. }
  10396. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10397. /// 0180 <account id>.L
  10398. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10399. {
  10400. struct map_session_data *t_sd;
  10401. if(!sd->state.gmaster_flag)
  10402. return;
  10403. if(map[sd->bl.m].flag.guildlock)
  10404. { //Guild locked.
  10405. clif_displaymessage(fd, msg_txt(228));
  10406. return;
  10407. }
  10408. t_sd = map_id2sd(RFIFOL(fd,2));
  10409. // @noask [LuzZza]
  10410. if(t_sd && t_sd->state.noask) {
  10411. clif_noask_sub(sd, t_sd, 4);
  10412. return;
  10413. }
  10414. guild_opposition(sd,t_sd);
  10415. }
  10416. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10417. /// 015d <key>.40B
  10418. /// key:
  10419. /// now guild name; might have been (intended) email, since the
  10420. /// field name and size is same as the one in CH_DELETE_CHAR.
  10421. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10422. {
  10423. if( map[sd->bl.m].flag.guildlock )
  10424. { //Guild locked.
  10425. clif_displaymessage(fd, msg_txt(228));
  10426. return;
  10427. }
  10428. guild_break(sd,(char*)RFIFOP(fd,2));
  10429. }
  10430. /// Pet
  10431. ///
  10432. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10433. /// 01a1 <type>.B
  10434. /// type:
  10435. /// 0 = pet information
  10436. /// 1 = feed
  10437. /// 2 = performance
  10438. /// 3 = return to egg
  10439. /// 4 = unequip accessory
  10440. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10441. {
  10442. pet_menu(sd,RFIFOB(fd,2));
  10443. }
  10444. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10445. /// 019f <id>.L
  10446. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10447. {
  10448. pet_catch_process2(sd,RFIFOL(fd,2));
  10449. }
  10450. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10451. /// 01a7 <index>.W
  10452. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10453. {
  10454. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10455. {
  10456. //Forged packet, disconnect them [Kevin]
  10457. clif_authfail_fd(fd, 0);
  10458. return;
  10459. }
  10460. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10461. clif_menuskill_clear(sd);
  10462. }
  10463. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10464. /// 01a9 <data>.L
  10465. /// data:
  10466. /// is either emotion (@see enum emotion_type) or a compound value
  10467. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10468. /// entry (given in parentheses) in data\pettalktable.xml
  10469. /// act id:
  10470. /// 0 = feeding
  10471. /// 1 = hunting
  10472. /// 2 = danger
  10473. /// 3 = dead
  10474. /// 4 = normal (stand)
  10475. /// 5 = special performance (perfor_s)
  10476. /// 6 = level up (levelup)
  10477. /// 7 = performance 1 (perfor_1)
  10478. /// 8 = performance 2 (perfor_2)
  10479. /// 9 = performance 3 (perfor_3)
  10480. /// 10 = log-in greeting (connect)
  10481. /// hungry value:
  10482. /// 0 = very hungry (hungry)
  10483. /// 1 = hungry (bit_hungry)
  10484. /// 2 = satisfied (noting)
  10485. /// 3 = stuffed (full)
  10486. /// 4 = full (so_full)
  10487. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10488. {
  10489. if(sd->pd)
  10490. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10491. }
  10492. /// Request to change pet's name (CZ_RENAME_PET).
  10493. /// 01a5 <name>.24B
  10494. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10495. {
  10496. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10497. }
  10498. /// /kill (CZ_DISCONNECT_CHARACTER).
  10499. /// Request to disconnect a character.
  10500. /// 00cc <account id>.L
  10501. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10502. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10503. {
  10504. struct block_list *target;
  10505. int tid;
  10506. tid = RFIFOL(fd,2);
  10507. target = map_id2bl(tid);
  10508. if (!target) {
  10509. clif_GM_kickack(sd, 0);
  10510. return;
  10511. }
  10512. switch (target->type) {
  10513. case BL_PC:
  10514. {
  10515. char command[NAME_LENGTH+6];
  10516. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10517. is_atcommand(fd, sd, command, 1);
  10518. }
  10519. break;
  10520. /**
  10521. * This one does not invoke any atcommand, so we need to check for permissions.
  10522. */
  10523. case BL_MOB:
  10524. {
  10525. char command[100];
  10526. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10527. clif_GM_kickack(sd, 0);
  10528. return;
  10529. }
  10530. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10531. log_atcommand(sd, command);
  10532. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10533. }
  10534. break;
  10535. case BL_NPC:
  10536. {
  10537. char command[NAME_LENGTH+11];
  10538. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10539. is_atcommand(fd, sd, command, 1);
  10540. }
  10541. break;
  10542. default:
  10543. clif_GM_kickack(sd, 0);
  10544. }
  10545. }
  10546. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10547. /// Request to disconnect all characters.
  10548. /// 00ce
  10549. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10550. char cmd[15];
  10551. sprintf(cmd,"%ckickall",atcommand_symbol);
  10552. is_atcommand(fd, sd, cmd, 1);
  10553. }
  10554. /// /remove (CZ_REMOVE_AID).
  10555. /// Request to warp to a character with given login ID.
  10556. /// 01ba <account name>.24B
  10557. /// /shift (CZ_SHIFT).
  10558. /// Request to warp to a character with given name.
  10559. /// 01bb <char name>.24B
  10560. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10561. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10562. char *player_name;
  10563. char command[NAME_LENGTH+8];
  10564. player_name = (char*)RFIFOP(fd,2);
  10565. player_name[NAME_LENGTH-1] = '\0';
  10566. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10567. is_atcommand(fd, sd, command, 1);
  10568. }
  10569. /// /remove (CZ_REMOVE_AID_SSO).
  10570. /// Request to warp to a character with given account ID.
  10571. /// 0843 <account id>.L
  10572. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10573. {
  10574. int account_id;
  10575. struct map_session_data* pl_sd;
  10576. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10577. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10578. {
  10579. char command[NAME_LENGTH+8];
  10580. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10581. is_atcommand(fd, sd, command, 1);
  10582. }
  10583. }
  10584. /// /recall (CZ_RECALL).
  10585. /// Request to summon a player with given login ID to own position.
  10586. /// 01bc <account name>.24B
  10587. /// /summon (CZ_RECALL_GID).
  10588. /// Request to summon a player with given name to own position.
  10589. /// 01bd <char name>.24B
  10590. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10591. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10592. char *player_name;
  10593. char command [NAME_LENGTH+8];
  10594. player_name = (char*)RFIFOP(fd,2);
  10595. player_name[NAME_LENGTH-1] = '\0';
  10596. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10597. is_atcommand(fd, sd, command, 1);
  10598. }
  10599. /// /recall (CZ_RECALL_SSO).
  10600. /// Request to summon a player with given account ID to own position.
  10601. /// 0842 <account id>.L
  10602. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10603. {
  10604. int account_id;
  10605. struct map_session_data* pl_sd;
  10606. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10607. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10608. {
  10609. char command[NAME_LENGTH+8];
  10610. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10611. is_atcommand(fd, sd, command, 1);
  10612. }
  10613. }
  10614. /// /item /monster (CZ_ITEM_CREATE).
  10615. /// Request to make items or spawn monsters.
  10616. /// 013f <item/mob name>.24B
  10617. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10618. {
  10619. char *monster_item_name;
  10620. char command[NAME_LENGTH+10];
  10621. monster_item_name = (char*)RFIFOP(fd,2);
  10622. monster_item_name[NAME_LENGTH-1] = '\0';
  10623. // FIXME: Should look for item first, then for monster.
  10624. // FIXME: /monster takes mob_db Sprite_Name as argument
  10625. if( mobdb_searchname(monster_item_name) ) {
  10626. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10627. is_atcommand(fd, sd, command, 1);
  10628. return;
  10629. }
  10630. // FIXME: Stackables have a quantity of 20.
  10631. // FIXME: Equips are supposed to be unidentified.
  10632. if( itemdb_searchname(monster_item_name) ) {
  10633. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10634. is_atcommand(fd, sd, command, 1);
  10635. return;
  10636. }
  10637. }
  10638. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10639. /// 019d <effect state>.L
  10640. /// effect state:
  10641. /// TODO: Any OPTION_* ?
  10642. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10643. char cmd[6];
  10644. sprintf(cmd,"%chide",atcommand_symbol);
  10645. is_atcommand(fd, sd, cmd, 1);
  10646. }
  10647. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10648. /// 0149 <account id>.L <type>.B <value>.W
  10649. /// type:
  10650. /// 0 = positive points
  10651. /// 1 = negative points
  10652. /// 2 = self mute (+10 minutes)
  10653. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10654. {
  10655. int id, type, value;
  10656. struct map_session_data *dstsd;
  10657. char command[NAME_LENGTH+15];
  10658. id = RFIFOL(fd,2);
  10659. type = RFIFOB(fd,6);
  10660. value = RFIFOW(fd,7);
  10661. if( type == 0 )
  10662. value = -value;
  10663. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10664. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10665. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10666. return;
  10667. dstsd = map_id2sd(id);
  10668. if( dstsd == NULL )
  10669. return;
  10670. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10671. is_atcommand(fd, sd, command, 1);
  10672. }
  10673. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10674. /// GM adjustment of a player's manner value by -60.
  10675. /// 0212 <char name>.24B
  10676. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10677. {
  10678. char command[NAME_LENGTH+15];
  10679. char *name = (char*)RFIFOP(fd,2);
  10680. name[NAME_LENGTH-1] = '\0';
  10681. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10682. is_atcommand(fd, sd, command, 1);
  10683. }
  10684. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10685. /// 01e0 <account id>.L <account name>.24B
  10686. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  10687. {
  10688. int fd = sd->fd;
  10689. WFIFOHEAD(fd,packet_len(0x1e0));
  10690. WFIFOW(fd,0) = 0x1e0;
  10691. WFIFOL(fd,2) = account_id;
  10692. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  10693. WFIFOSET(fd,packet_len(0x1e0));
  10694. }
  10695. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10696. /// 01df <account id>.L
  10697. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10698. {
  10699. int account_id = RFIFOL(fd,2);
  10700. //TODO: find out if this works for any player or only for authorized GMs
  10701. clif_account_name(sd, account_id, ""); // insert account name here >_<
  10702. }
  10703. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10704. /// GM single cell type change request.
  10705. /// 0198 <x>.W <y>.W <type>.W
  10706. /// type:
  10707. /// 0 = not walkable
  10708. /// 1 = walkable
  10709. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10710. {
  10711. int x,y,type;
  10712. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10713. return;
  10714. x = RFIFOW(fd,2);
  10715. y = RFIFOW(fd,4);
  10716. type = RFIFOW(fd,6);
  10717. map_setgatcell(sd->bl.m,x,y,type);
  10718. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10719. //FIXME: once players leave the map, the client 'forgets' this information.
  10720. }
  10721. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10722. /// Request to allow/deny whispers from a nick.
  10723. /// 00cf <nick>.24B <type>.B
  10724. /// type:
  10725. /// 0 = (/ex nick) deny speech from nick
  10726. /// 1 = (/in nick) allow speech from nick
  10727. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10728. {
  10729. char* nick;
  10730. uint8 type;
  10731. int i;
  10732. nick = (char*)RFIFOP(fd,2); // speed up
  10733. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10734. type = RFIFOB(fd,26);
  10735. if( type == 0 )
  10736. { // Add name to ignore list (block)
  10737. if (strcmp(wisp_server_name, nick) == 0) {
  10738. clif_wisexin(sd, type, 1); // fail
  10739. return;
  10740. }
  10741. // try to find a free spot, while checking for duplicates at the same time
  10742. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10743. if( i == MAX_IGNORE_LIST )
  10744. {// no space for new entry
  10745. clif_wisexin(sd, type, 2); // too many blocks
  10746. return;
  10747. }
  10748. if( sd->ignore[i].name[0] != '\0' )
  10749. {// name already exists
  10750. clif_wisexin(sd, type, 0); // Aegis reports success.
  10751. return;
  10752. }
  10753. //Insert in position i
  10754. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10755. }
  10756. else
  10757. { // Remove name from ignore list (unblock)
  10758. // find entry
  10759. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10760. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10761. { //Not found
  10762. clif_wisexin(sd, type, 1); // fail
  10763. return;
  10764. }
  10765. // move everything one place down to overwrite removed entry
  10766. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10767. // wipe last entry
  10768. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10769. }
  10770. clif_wisexin(sd, type, 0); // success
  10771. }
  10772. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10773. /// Request to allow/deny all whispers.
  10774. /// 00d0 <type>.B
  10775. /// type:
  10776. /// 0 = (/exall) deny all speech
  10777. /// 1 = (/inall) allow all speech
  10778. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10779. {
  10780. int type = RFIFOB(fd,2), flag;
  10781. if( type == 0 )
  10782. {// Deny all
  10783. if( sd->state.ignoreAll ) {
  10784. flag = 1; // fail
  10785. } else {
  10786. sd->state.ignoreAll = 1;
  10787. flag = 0; // success
  10788. }
  10789. }
  10790. else
  10791. {//Unblock everyone
  10792. if( sd->state.ignoreAll ) {
  10793. sd->state.ignoreAll = 0;
  10794. flag = 0; // success
  10795. } else {
  10796. if (sd->ignore[0].name[0] != '\0')
  10797. { //Wipe the ignore list.
  10798. memset(sd->ignore, 0, sizeof(sd->ignore));
  10799. flag = 0; // success
  10800. } else {
  10801. flag = 1; // fail
  10802. }
  10803. }
  10804. }
  10805. clif_wisall(sd, type, flag);
  10806. }
  10807. /// Whisper ignore list (ZC_WHISPER_LIST).
  10808. /// 00d4 <packet len>.W { <char name>.24B }*
  10809. void clif_PMIgnoreList(struct map_session_data* sd)
  10810. {
  10811. int i, fd = sd->fd;
  10812. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  10813. WFIFOW(fd,0) = 0xd4;
  10814. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ )
  10815. {
  10816. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  10817. }
  10818. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  10819. WFIFOSET(fd,WFIFOW(fd,2));
  10820. }
  10821. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10822. /// 00d3
  10823. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10824. {
  10825. clif_PMIgnoreList(sd);
  10826. }
  10827. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10828. /// 01e7
  10829. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10830. {
  10831. if (sd->state.doridori) return;
  10832. switch (sd->class_&MAPID_UPPERMASK)
  10833. {
  10834. case MAPID_SOUL_LINKER:
  10835. case MAPID_STAR_GLADIATOR:
  10836. case MAPID_TAEKWON:
  10837. if (!sd->state.rest)
  10838. break;
  10839. case MAPID_SUPER_NOVICE:
  10840. sd->state.doridori=1;
  10841. break;
  10842. }
  10843. }
  10844. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10845. /// 01ed
  10846. /// Note: This packet is caused by 7 lines of any text, followed by
  10847. /// the prayer and an another line of any text. The prayer is
  10848. /// defined by lines 790~793 in data\msgstringtable.txt
  10849. /// "Dear angel, can you hear my voice?"
  10850. /// "I am" (space separated player name) "Super Novice~"
  10851. /// "Help me out~ Please~ T_T"
  10852. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10853. {
  10854. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10855. {
  10856. unsigned int next = pc_nextbaseexp(sd);
  10857. if( next == 0 ) next = pc_thisbaseexp(sd);
  10858. if( next )
  10859. {
  10860. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10861. if( percent && ( percent%100 ) == 0 )
  10862. {// 10.0%, 20.0%, ..., 90.0%
  10863. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10864. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10865. }
  10866. }
  10867. }
  10868. }
  10869. /// Friends List
  10870. ///
  10871. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10872. /// 0206 <account id>.L <char id>.L <state>.B
  10873. /// state:
  10874. /// 0 = online
  10875. /// 1 = offline
  10876. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10877. {
  10878. int i, fd = sd->fd;
  10879. //Seek friend.
  10880. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10881. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10882. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10883. return; //Not found
  10884. WFIFOHEAD(fd,packet_len(0x206));
  10885. WFIFOW(fd, 0) = 0x206;
  10886. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10887. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10888. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10889. WFIFOSET(fd, packet_len(0x206));
  10890. }
  10891. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10892. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10893. {
  10894. int account_id, char_id, online;
  10895. account_id = va_arg(ap, int);
  10896. char_id = va_arg(ap, int);
  10897. online = va_arg(ap, int);
  10898. clif_friendslist_toggle(sd, account_id, char_id, online);
  10899. return 0;
  10900. }
  10901. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10902. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10903. void clif_friendslist_send(struct map_session_data *sd)
  10904. {
  10905. int i = 0, n, fd = sd->fd;
  10906. // Send friends list
  10907. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10908. WFIFOW(fd, 0) = 0x201;
  10909. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10910. {
  10911. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10912. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10913. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10914. }
  10915. if (i) {
  10916. WFIFOW(fd,2) = 4 + 32 * i;
  10917. WFIFOSET(fd, WFIFOW(fd,2));
  10918. }
  10919. for (n = 0; n < i; n++)
  10920. { //Sending the online players
  10921. if (map_charid2sd(sd->status.friends[n].char_id))
  10922. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10923. }
  10924. }
  10925. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10926. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10927. /// result:
  10928. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10929. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10930. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10931. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10932. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10933. {
  10934. int fd;
  10935. nullpo_retv(sd);
  10936. fd = sd->fd;
  10937. WFIFOHEAD(fd,packet_len(0x209));
  10938. WFIFOW(fd,0) = 0x209;
  10939. WFIFOW(fd,2) = type;
  10940. if (f_sd)
  10941. {
  10942. WFIFOL(fd,4) = f_sd->status.account_id;
  10943. WFIFOL(fd,8) = f_sd->status.char_id;
  10944. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10945. }
  10946. WFIFOSET(fd, packet_len(0x209));
  10947. }
  10948. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  10949. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  10950. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  10951. {
  10952. int fd = sd->fd;
  10953. WFIFOHEAD(fd,packet_len(0x207));
  10954. WFIFOW(fd,0) = 0x207;
  10955. WFIFOL(fd,2) = account_id;
  10956. WFIFOL(fd,6) = char_id;
  10957. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  10958. WFIFOSET(fd,packet_len(0x207));
  10959. }
  10960. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10961. /// 0202 <name>.24B
  10962. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10963. {
  10964. struct map_session_data *f_sd;
  10965. int i;
  10966. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10967. // ensure that the request player's friend list is not full
  10968. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10969. if( i == MAX_FRIENDS ) {
  10970. clif_friendslist_reqack(sd, f_sd, 2);
  10971. return;
  10972. }
  10973. // Friend doesn't exist (no player with this name)
  10974. if (f_sd == NULL) {
  10975. clif_displaymessage(fd, msg_txt(3));
  10976. return;
  10977. }
  10978. if( sd->bl.id == f_sd->bl.id )
  10979. {// adding oneself as friend
  10980. return;
  10981. }
  10982. // @noask [LuzZza]
  10983. if(f_sd->state.noask) {
  10984. clif_noask_sub(sd, f_sd, 5);
  10985. return;
  10986. }
  10987. // Friend already exists
  10988. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10989. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10990. clif_displaymessage(fd, msg_txt(671)); //"Friend already exists."
  10991. return;
  10992. }
  10993. }
  10994. f_sd->friend_req = sd->status.char_id;
  10995. sd->friend_req = f_sd->status.char_id;
  10996. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  10997. }
  10998. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10999. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  11000. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  11001. /// result:
  11002. /// 0 = rejected
  11003. /// 1 = accepted
  11004. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11005. {
  11006. struct map_session_data *f_sd;
  11007. int account_id;
  11008. char reply;
  11009. account_id = RFIFOL(fd,2);
  11010. //char_id = RFIFOL(fd,6);
  11011. #if PACKETVER < 6
  11012. reply = RFIFOB(fd,10);
  11013. #else
  11014. reply = RFIFOL(fd,10);
  11015. #endif
  11016. if( sd->bl.id == account_id )
  11017. {// adding oneself as friend
  11018. return;
  11019. }
  11020. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11021. if (f_sd == NULL)
  11022. return;
  11023. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11024. clif_friendslist_reqack(f_sd, sd, 1);
  11025. else {
  11026. int i;
  11027. // Find an empty slot
  11028. for (i = 0; i < MAX_FRIENDS; i++)
  11029. if (f_sd->status.friends[i].char_id == 0)
  11030. break;
  11031. if (i == MAX_FRIENDS) {
  11032. clif_friendslist_reqack(f_sd, sd, 2);
  11033. return;
  11034. }
  11035. f_sd->status.friends[i].account_id = sd->status.account_id;
  11036. f_sd->status.friends[i].char_id = sd->status.char_id;
  11037. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11038. clif_friendslist_reqack(f_sd, sd, 0);
  11039. if (battle_config.friend_auto_add) {
  11040. // Also add f_sd to sd's friendlist.
  11041. for (i = 0; i < MAX_FRIENDS; i++) {
  11042. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11043. return; //No need to add anything.
  11044. if (sd->status.friends[i].char_id == 0)
  11045. break;
  11046. }
  11047. if (i == MAX_FRIENDS) {
  11048. clif_friendslist_reqack(sd, f_sd, 2);
  11049. return;
  11050. }
  11051. sd->status.friends[i].account_id = f_sd->status.account_id;
  11052. sd->status.friends[i].char_id = f_sd->status.char_id;
  11053. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11054. clif_friendslist_reqack(sd, f_sd, 0);
  11055. }
  11056. }
  11057. }
  11058. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11059. /// 0203 <account id>.L <char id>.L
  11060. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11061. {
  11062. struct map_session_data *f_sd = NULL;
  11063. int account_id, char_id;
  11064. int i, j;
  11065. account_id = RFIFOL(fd,2);
  11066. char_id = RFIFOL(fd,6);
  11067. // Search friend
  11068. for (i = 0; i < MAX_FRIENDS &&
  11069. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11070. if (i == MAX_FRIENDS) {
  11071. clif_displaymessage(fd, msg_txt(672)); //"Name not found in list."
  11072. return;
  11073. }
  11074. //remove from friend's list first
  11075. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11076. for (i = 0; i < MAX_FRIENDS &&
  11077. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11078. if (i != MAX_FRIENDS) {
  11079. // move all chars up
  11080. for(j = i + 1; j < MAX_FRIENDS; j++)
  11081. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11082. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11083. //should the guy be notified of some message? we should add it here if so
  11084. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11085. WFIFOW(f_sd->fd,0) = 0x20a;
  11086. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11087. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11088. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11089. }
  11090. } else { //friend not online -- ask char server to delete from his friendlist
  11091. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11092. clif_displaymessage(fd, msg_txt(673)); //"This action can't be performed at the moment. Please try again later."
  11093. return;
  11094. }
  11095. }
  11096. // We can now delete from original requester
  11097. for (i = 0; i < MAX_FRIENDS &&
  11098. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11099. // move all chars up
  11100. for(j = i + 1; j < MAX_FRIENDS; j++)
  11101. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11102. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11103. clif_displaymessage(fd, msg_txt(674)); //"Friend removed"
  11104. WFIFOHEAD(fd,packet_len(0x20a));
  11105. WFIFOW(fd,0) = 0x20a;
  11106. WFIFOL(fd,2) = account_id;
  11107. WFIFOL(fd,6) = char_id;
  11108. WFIFOSET(fd, packet_len(0x20a));
  11109. }
  11110. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11111. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11112. void clif_PVPInfo(struct map_session_data* sd)
  11113. {
  11114. int fd = sd->fd;
  11115. WFIFOHEAD(fd,packet_len(0x210));
  11116. WFIFOW(fd,0) = 0x210;
  11117. WFIFOL(fd,2) = sd->status.char_id;
  11118. WFIFOL(fd,6) = sd->status.account_id;
  11119. WFIFOL(fd,10) = sd->pvp_won; // times won
  11120. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11121. WFIFOL(fd,18) = sd->pvp_point;
  11122. WFIFOSET(fd, packet_len(0x210));
  11123. }
  11124. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11125. /// 020f <char id>.L <account id>.L
  11126. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11127. {
  11128. // TODO: Is there a way to use this on an another player (char/acc id)?
  11129. clif_PVPInfo(sd);
  11130. }
  11131. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11132. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11133. void clif_blacksmith(struct map_session_data* sd)
  11134. {
  11135. int i, fd = sd->fd;
  11136. const char* name;
  11137. WFIFOHEAD(fd,packet_len(0x219));
  11138. WFIFOW(fd,0) = 0x219;
  11139. //Packet size limits this list to 10 elements. [Skotlex]
  11140. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11141. if (smith_fame_list[i].id > 0) {
  11142. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11143. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11144. {
  11145. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11146. } else
  11147. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11148. } else
  11149. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11150. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11151. }
  11152. for(;i < 10; i++) { //In case the MAX is less than 10.
  11153. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11154. WFIFOL(fd, 242 + i * 4) = 0;
  11155. }
  11156. WFIFOSET(fd, packet_len(0x219));
  11157. }
  11158. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11159. /// 0217
  11160. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11161. {
  11162. clif_blacksmith(sd);
  11163. }
  11164. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11165. /// 021b <points>.L <total points>.L
  11166. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11167. {
  11168. int fd = sd->fd;
  11169. WFIFOHEAD(fd,packet_len(0x21b));
  11170. WFIFOW(fd,0) = 0x21b;
  11171. WFIFOL(fd,2) = points;
  11172. WFIFOL(fd,6) = sd->status.fame;
  11173. WFIFOSET(fd, packet_len(0x21b));
  11174. }
  11175. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11176. /// 021a { <name>.24B }*10 { <point>.L }*10
  11177. void clif_alchemist(struct map_session_data* sd)
  11178. {
  11179. int i, fd = sd->fd;
  11180. const char* name;
  11181. WFIFOHEAD(fd,packet_len(0x21a));
  11182. WFIFOW(fd,0) = 0x21a;
  11183. //Packet size limits this list to 10 elements. [Skotlex]
  11184. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11185. if (chemist_fame_list[i].id > 0) {
  11186. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11187. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11188. {
  11189. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11190. } else
  11191. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11192. } else
  11193. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11194. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11195. }
  11196. for(;i < 10; i++) { //In case the MAX is less than 10.
  11197. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11198. WFIFOL(fd, 242 + i * 4) = 0;
  11199. }
  11200. WFIFOSET(fd, packet_len(0x21a));
  11201. }
  11202. /// /alchemist (CZ_ALCHEMIST_RANK).
  11203. /// 0218
  11204. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11205. {
  11206. clif_alchemist(sd);
  11207. }
  11208. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11209. /// 021c <points>.L <total points>.L
  11210. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11211. {
  11212. int fd = sd->fd;
  11213. WFIFOHEAD(fd,packet_len(0x21c));
  11214. WFIFOW(fd,0) = 0x21c;
  11215. WFIFOL(fd,2) = points;
  11216. WFIFOL(fd,6) = sd->status.fame;
  11217. WFIFOSET(fd, packet_len(0x21c));
  11218. }
  11219. /// /taekwon list (ZC_TAEKWON_RANK).
  11220. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11221. void clif_taekwon(struct map_session_data* sd)
  11222. {
  11223. int i, fd = sd->fd;
  11224. const char* name;
  11225. WFIFOHEAD(fd,packet_len(0x226));
  11226. WFIFOW(fd,0) = 0x226;
  11227. //Packet size limits this list to 10 elements. [Skotlex]
  11228. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11229. if (taekwon_fame_list[i].id > 0) {
  11230. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11231. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11232. {
  11233. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11234. } else
  11235. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11236. } else
  11237. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11238. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11239. }
  11240. for(;i < 10; i++) { //In case the MAX is less than 10.
  11241. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11242. WFIFOL(fd, 242 + i * 4) = 0;
  11243. }
  11244. WFIFOSET(fd, packet_len(0x226));
  11245. }
  11246. /// /taekwon (CZ_TAEKWON_RANK).
  11247. /// 0225
  11248. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11249. {
  11250. clif_taekwon(sd);
  11251. }
  11252. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11253. /// 0224 <points>.L <total points>.L
  11254. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11255. {
  11256. int fd = sd->fd;
  11257. WFIFOHEAD(fd,packet_len(0x224));
  11258. WFIFOW(fd,0) = 0x224;
  11259. WFIFOL(fd,2) = points;
  11260. WFIFOL(fd,6) = sd->status.fame;
  11261. WFIFOSET(fd, packet_len(0x224));
  11262. }
  11263. /// /pk list (ZC_KILLER_RANK).
  11264. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11265. void clif_ranking_pk(struct map_session_data* sd)
  11266. {
  11267. int i, fd = sd->fd;
  11268. WFIFOHEAD(fd,packet_len(0x238));
  11269. WFIFOW(fd,0) = 0x238;
  11270. for(i=0;i<10;i++){
  11271. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11272. WFIFOL(fd,i*4+242) = 0;
  11273. }
  11274. WFIFOSET(fd, packet_len(0x238));
  11275. }
  11276. /// /pk (CZ_KILLER_RANK).
  11277. /// 0237
  11278. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11279. {
  11280. clif_ranking_pk(sd);
  11281. }
  11282. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11283. /// 0254 <which>.B
  11284. /// which:
  11285. /// 0 = sun
  11286. /// 1 = moon
  11287. /// 2 = star
  11288. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11289. {
  11290. int i;
  11291. if (sd->menuskill_id != SG_FEEL)
  11292. return;
  11293. i = sd->menuskill_val-1;
  11294. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11295. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11296. sd->feel_map[i].m = sd->bl.m;
  11297. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11298. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11299. // clif_misceffect2(&sd->bl, 0x1b0);
  11300. // clif_misceffect2(&sd->bl, 0x21f);
  11301. clif_feel_info(sd, i, 0);
  11302. clif_menuskill_clear(sd);
  11303. }
  11304. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11305. /// 0253 <which>.B
  11306. /// which:
  11307. /// 0 = sun
  11308. /// 1 = moon
  11309. /// 2 = star
  11310. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11311. {
  11312. WFIFOHEAD(fd,packet_len(0x253));
  11313. WFIFOW(fd,0)=0x253;
  11314. WFIFOB(fd,2)=TOB(skill_lv-1);
  11315. WFIFOSET(fd, packet_len(0x253));
  11316. sd->menuskill_id = SG_FEEL;
  11317. sd->menuskill_val = skill_lv;
  11318. }
  11319. /// Request to change homunculus' name (CZ_RENAME_MER).
  11320. /// 0231 <name>.24B
  11321. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11322. {
  11323. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11324. }
  11325. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11326. /// 0234 <id>.L
  11327. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11328. {
  11329. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11330. struct block_list *bl = NULL;
  11331. struct unit_data *ud = NULL;
  11332. if( sd->md && sd->md->bl.id == id )
  11333. bl = &sd->md->bl;
  11334. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11335. bl = &sd->hd->bl; // Moving Homunculus
  11336. else
  11337. return;
  11338. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11339. ud = unit_bl2ud(bl);
  11340. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11341. }
  11342. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11343. /// 0232 <id>.L <position data>.3B
  11344. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11345. {
  11346. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11347. struct block_list *bl = NULL;
  11348. short x, y;
  11349. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11350. if( sd->md && sd->md->bl.id == id )
  11351. bl = &sd->md->bl; // Moving Mercenary
  11352. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11353. bl = &sd->hd->bl; // Moving Homunculus
  11354. else
  11355. return;
  11356. unit_walktoxy(bl, x, y, 4);
  11357. }
  11358. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11359. /// 0233 <id>.L <target id>.L <action>.B
  11360. /// action:
  11361. /// always 0
  11362. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11363. {
  11364. struct block_list *bl = NULL;
  11365. int id = RFIFOL(fd,2),
  11366. target_id = RFIFOL(fd,6),
  11367. action_type = RFIFOB(fd,10);
  11368. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11369. bl = &sd->hd->bl;
  11370. else if( sd->md && sd->md->bl.id == id )
  11371. bl = &sd->md->bl;
  11372. else return;
  11373. unit_stop_attack(bl);
  11374. unit_attack(bl, target_id, action_type != 0);
  11375. }
  11376. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11377. /// 022d <type>.W <command>.B
  11378. /// type:
  11379. /// always 0
  11380. /// command:
  11381. /// 0 = homunculus information
  11382. /// 1 = feed
  11383. /// 2 = delete
  11384. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11385. { //[orn]
  11386. int cmd;
  11387. cmd = RFIFOW(fd,0);
  11388. if(!merc_is_hom_active(sd->hd))
  11389. return;
  11390. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11391. }
  11392. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11393. /// 0292
  11394. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11395. {
  11396. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11397. if (item_position < 0)
  11398. return;
  11399. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11400. return;
  11401. if (!status_revive(&sd->bl, 100, 100))
  11402. return;
  11403. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11404. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11405. }
  11406. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11407. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11408. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11409. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11410. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11411. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11412. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11413. void clif_check(int fd, struct map_session_data* pl_sd)
  11414. {
  11415. WFIFOHEAD(fd,packet_len(0x214));
  11416. WFIFOW(fd, 0) = 0x214;
  11417. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11418. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11419. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11420. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11421. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11422. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11423. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11424. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11425. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11426. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11427. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11428. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11429. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11430. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11431. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11432. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11433. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11434. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11435. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11436. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11437. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11438. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11439. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11440. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11441. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11442. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11443. WFIFOSET(fd,packet_len(0x214));
  11444. }
  11445. /// /check (CZ_REQ_STATUS_GM).
  11446. /// Request character's status values.
  11447. /// 0213 <char name>.24B
  11448. void clif_parse_Check(int fd, struct map_session_data *sd)
  11449. {
  11450. char charname[NAME_LENGTH];
  11451. struct map_session_data* pl_sd;
  11452. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11453. return;
  11454. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11455. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11456. {
  11457. return;
  11458. }
  11459. clif_check(fd, pl_sd);
  11460. }
  11461. /// MAIL SYSTEM
  11462. /// By Zephyrus
  11463. ///
  11464. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11465. /// 0255 <index>.W <result>.B
  11466. /// result:
  11467. /// 0 = success
  11468. /// 1 = failure
  11469. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11470. {
  11471. WFIFOHEAD(fd,packet_len(0x255));
  11472. WFIFOW(fd,0) = 0x255;
  11473. WFIFOW(fd,2) = index;
  11474. WFIFOB(fd,4) = flag;
  11475. WFIFOSET(fd,packet_len(0x255));
  11476. }
  11477. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11478. /// 0245 <result>.B
  11479. /// result:
  11480. /// 0 = success
  11481. /// 1 = failure
  11482. /// 2 = too many items
  11483. void clif_Mail_getattachment(int fd, uint8 flag)
  11484. {
  11485. WFIFOHEAD(fd,packet_len(0x245));
  11486. WFIFOW(fd,0) = 0x245;
  11487. WFIFOB(fd,2) = flag;
  11488. WFIFOSET(fd,packet_len(0x245));
  11489. }
  11490. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11491. /// 0249 <result>.B
  11492. /// result:
  11493. /// 0 = success
  11494. /// 1 = recipinent does not exist
  11495. void clif_Mail_send(int fd, bool fail)
  11496. {
  11497. WFIFOHEAD(fd,packet_len(0x249));
  11498. WFIFOW(fd,0) = 0x249;
  11499. WFIFOB(fd,2) = fail;
  11500. WFIFOSET(fd,packet_len(0x249));
  11501. }
  11502. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11503. /// 0257 <mail id>.L <result>.W
  11504. /// result:
  11505. /// 0 = success
  11506. /// 1 = failure
  11507. void clif_Mail_delete(int fd, int mail_id, short fail)
  11508. {
  11509. WFIFOHEAD(fd, packet_len(0x257));
  11510. WFIFOW(fd,0) = 0x257;
  11511. WFIFOL(fd,2) = mail_id;
  11512. WFIFOW(fd,6) = fail;
  11513. WFIFOSET(fd, packet_len(0x257));
  11514. }
  11515. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11516. /// 0274 <mail id>.L <result>.W
  11517. /// result:
  11518. /// 0 = success
  11519. /// 1 = failure
  11520. void clif_Mail_return(int fd, int mail_id, short fail)
  11521. {
  11522. WFIFOHEAD(fd,packet_len(0x274));
  11523. WFIFOW(fd,0) = 0x274;
  11524. WFIFOL(fd,2) = mail_id;
  11525. WFIFOW(fd,6) = fail;
  11526. WFIFOSET(fd,packet_len(0x274));
  11527. }
  11528. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11529. /// 024a <mail id>.L <title>.40B <sender>.24B
  11530. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11531. {
  11532. WFIFOHEAD(fd,packet_len(0x24a));
  11533. WFIFOW(fd,0) = 0x24a;
  11534. WFIFOL(fd,2) = mail_id;
  11535. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11536. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11537. WFIFOSET(fd,packet_len(0x24a));
  11538. }
  11539. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11540. /// 0260 <type>.L
  11541. /// type:
  11542. /// 0 = open
  11543. /// 1 = close
  11544. void clif_Mail_window(int fd, int flag)
  11545. {
  11546. WFIFOHEAD(fd,packet_len(0x260));
  11547. WFIFOW(fd,0) = 0x260;
  11548. WFIFOL(fd,2) = flag;
  11549. WFIFOSET(fd,packet_len(0x260));
  11550. }
  11551. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11552. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11553. /// read:
  11554. /// 0 = unread
  11555. /// 1 = read
  11556. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11557. {
  11558. int fd = sd->fd;
  11559. struct mail_data *md = &sd->mail.inbox;
  11560. struct mail_message *msg;
  11561. int len, i, j;
  11562. len = 8 + (73 * md->amount);
  11563. WFIFOHEAD(fd,len);
  11564. WFIFOW(fd,0) = 0x240;
  11565. WFIFOW(fd,2) = len;
  11566. WFIFOL(fd,4) = md->amount;
  11567. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11568. {
  11569. msg = &md->msg[i];
  11570. if (msg->id < 1)
  11571. continue;
  11572. WFIFOL(fd,8+73*j) = msg->id;
  11573. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11574. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11575. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11576. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11577. j++;
  11578. }
  11579. WFIFOSET(fd,len);
  11580. if( md->full )
  11581. {// TODO: is this official?
  11582. char output[100];
  11583. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11584. clif_disp_onlyself(sd, output, strlen(output));
  11585. }
  11586. }
  11587. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11588. /// 023f
  11589. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11590. {
  11591. struct mail_data* md = &sd->mail.inbox;
  11592. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11593. intif_Mail_requestinbox(sd->status.char_id, 1);
  11594. else
  11595. clif_Mail_refreshinbox(sd);
  11596. mail_removeitem(sd, 0);
  11597. mail_removezeny(sd, 0);
  11598. }
  11599. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11600. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11601. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11602. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11603. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11604. {
  11605. int i, fd = sd->fd;
  11606. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11607. if( i == MAIL_MAX_INBOX )
  11608. {
  11609. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11610. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11611. return;
  11612. }
  11613. else
  11614. {
  11615. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11616. struct item *item = &msg->item;
  11617. struct item_data *data;
  11618. int msg_len = strlen(msg->body), len;
  11619. if( msg_len == 0 ) {
  11620. strcpy(msg->body, "(no message)");
  11621. msg_len = strlen(msg->body);
  11622. }
  11623. len = 101 + msg_len;
  11624. WFIFOHEAD(fd,len);
  11625. WFIFOW(fd,0) = 0x242;
  11626. WFIFOW(fd,2) = len;
  11627. WFIFOL(fd,4) = msg->id;
  11628. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11629. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11630. WFIFOL(fd,72) = 0;
  11631. WFIFOL(fd,76) = msg->zeny;
  11632. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  11633. {
  11634. WFIFOL(fd,80) = item->amount;
  11635. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11636. WFIFOW(fd,86) = data->type;
  11637. WFIFOB(fd,88) = item->identify;
  11638. WFIFOB(fd,89) = item->attribute;
  11639. WFIFOB(fd,90) = item->refine;
  11640. WFIFOW(fd,91) = item->card[0];
  11641. WFIFOW(fd,93) = item->card[1];
  11642. WFIFOW(fd,95) = item->card[2];
  11643. WFIFOW(fd,97) = item->card[3];
  11644. }
  11645. else // no item, set all to zero
  11646. memset(WFIFOP(fd,80), 0x00, 19);
  11647. WFIFOB(fd,99) = (unsigned char)msg_len;
  11648. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11649. WFIFOSET(fd,len);
  11650. if (msg->status == MAIL_UNREAD) {
  11651. msg->status = MAIL_READ;
  11652. intif_Mail_read(mail_id);
  11653. clif_parse_Mail_refreshinbox(fd, sd);
  11654. }
  11655. }
  11656. }
  11657. /// Request to open a mail (CZ_MAIL_OPEN).
  11658. /// 0241 <mail id>.L
  11659. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11660. {
  11661. int mail_id = RFIFOL(fd,2);
  11662. if( mail_id <= 0 )
  11663. return;
  11664. if( mail_invalid_operation(sd) )
  11665. return;
  11666. clif_Mail_read(sd, RFIFOL(fd,2));
  11667. }
  11668. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11669. /// 0244 <mail id>.L
  11670. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11671. {
  11672. int mail_id = RFIFOL(fd,2);
  11673. int i;
  11674. bool fail = false;
  11675. if( !chrif_isconnected() )
  11676. return;
  11677. if( mail_id <= 0 )
  11678. return;
  11679. if( mail_invalid_operation(sd) )
  11680. return;
  11681. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11682. if( i == MAIL_MAX_INBOX )
  11683. return;
  11684. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11685. return;
  11686. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY )
  11687. {
  11688. clif_Mail_getattachment(fd, 1);
  11689. return;
  11690. }
  11691. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11692. {
  11693. struct item_data *data;
  11694. unsigned int weight;
  11695. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11696. return;
  11697. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11698. {
  11699. case ADDITEM_NEW:
  11700. fail = ( pc_inventoryblank(sd) == 0 );
  11701. break;
  11702. case ADDITEM_OVERAMOUNT:
  11703. fail = true;
  11704. }
  11705. if( fail )
  11706. {
  11707. clif_Mail_getattachment(fd, 1);
  11708. return;
  11709. }
  11710. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11711. if( sd->weight + weight > sd->max_weight )
  11712. {
  11713. clif_Mail_getattachment(fd, 2);
  11714. return;
  11715. }
  11716. }
  11717. sd->mail.inbox.msg[i].zeny = 0;
  11718. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11719. clif_Mail_read(sd, mail_id);
  11720. intif_Mail_getattach(sd->status.char_id, mail_id);
  11721. }
  11722. /// Request to delete a mail (CZ_MAIL_DELETE).
  11723. /// 0243 <mail id>.L
  11724. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11725. {
  11726. int mail_id = RFIFOL(fd,2);
  11727. int i;
  11728. if( !chrif_isconnected() )
  11729. return;
  11730. if( mail_id <= 0 )
  11731. return;
  11732. if( mail_invalid_operation(sd) )
  11733. return;
  11734. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11735. if (i < MAIL_MAX_INBOX)
  11736. {
  11737. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11738. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11739. {// can't delete mail without removing attachment first
  11740. clif_Mail_delete(sd->fd, mail_id, 1);
  11741. return;
  11742. }
  11743. intif_Mail_delete(sd->status.char_id, mail_id);
  11744. }
  11745. }
  11746. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11747. /// 0273 <mail id>.L <receive name>.24B
  11748. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11749. {
  11750. int mail_id = RFIFOL(fd,2);
  11751. int i;
  11752. if( mail_id <= 0 )
  11753. return;
  11754. if( mail_invalid_operation(sd) )
  11755. return;
  11756. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11757. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11758. intif_Mail_return(sd->status.char_id, mail_id);
  11759. else
  11760. clif_Mail_return(sd->fd, mail_id, 1);
  11761. }
  11762. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11763. /// 0247 <index>.W <amount>.L
  11764. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11765. {
  11766. int idx = RFIFOW(fd,2);
  11767. int amount = RFIFOL(fd,4);
  11768. unsigned char flag;
  11769. if( !chrif_isconnected() )
  11770. return;
  11771. if (idx < 0 || amount < 0)
  11772. return;
  11773. flag = mail_setitem(sd, idx, amount);
  11774. clif_Mail_setattachment(fd,idx,flag);
  11775. }
  11776. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11777. /// 0246 <type>.W
  11778. /// type:
  11779. /// 0 = reset all
  11780. /// 1 = remove item
  11781. /// 2 = remove zeny
  11782. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11783. {
  11784. int flag = RFIFOW(fd,2);
  11785. if (flag == 0 || flag == 1)
  11786. mail_removeitem(sd, 0);
  11787. if (flag == 0 || flag == 2)
  11788. mail_removezeny(sd, 0);
  11789. }
  11790. /// Request to send mail (CZ_MAIL_SEND).
  11791. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11792. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11793. {
  11794. struct mail_message msg;
  11795. int body_len;
  11796. if( !chrif_isconnected() )
  11797. return;
  11798. if( sd->state.trading )
  11799. return;
  11800. if( RFIFOW(fd,2) < 69 ) {
  11801. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11802. return;
  11803. }
  11804. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11805. {
  11806. clif_displaymessage(sd->fd,msg_txt(675)); //"Cannot send mails too fast!!."
  11807. clif_Mail_send(fd, true); // fail
  11808. return;
  11809. }
  11810. body_len = RFIFOB(fd,68);
  11811. if (body_len > MAIL_BODY_LENGTH)
  11812. body_len = MAIL_BODY_LENGTH;
  11813. if( !mail_setattachment(sd, &msg) )
  11814. { // Invalid Append condition
  11815. clif_Mail_send(sd->fd, true); // fail
  11816. mail_removeitem(sd,0);
  11817. mail_removezeny(sd,0);
  11818. return;
  11819. }
  11820. msg.id = 0; // id will be assigned by charserver
  11821. msg.send_id = sd->status.char_id;
  11822. msg.dest_id = 0; // will attempt to resolve name
  11823. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11824. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11825. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11826. if (msg.title[0] == '\0') {
  11827. return; // Message has no length and somehow client verification was skipped.
  11828. }
  11829. if (body_len)
  11830. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11831. else
  11832. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11833. msg.timestamp = time(NULL);
  11834. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11835. mail_deliveryfail(sd, &msg);
  11836. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11837. }
  11838. /// AUCTION SYSTEM
  11839. /// By Zephyrus
  11840. ///
  11841. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11842. /// 025f <type>.L
  11843. /// type:
  11844. /// 0 = open
  11845. /// 1 = close
  11846. void clif_Auction_openwindow(struct map_session_data *sd)
  11847. {
  11848. int fd = sd->fd;
  11849. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11850. return;
  11851. WFIFOHEAD(fd,packet_len(0x25f));
  11852. WFIFOW(fd,0) = 0x25f;
  11853. WFIFOL(fd,2) = 0;
  11854. WFIFOSET(fd,packet_len(0x25f));
  11855. }
  11856. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11857. /// 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 }*
  11858. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11859. {
  11860. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11861. struct auction_data auction;
  11862. struct item_data *item;
  11863. int k;
  11864. WFIFOHEAD(fd,12 + (count * 83));
  11865. WFIFOW(fd,0) = 0x252;
  11866. WFIFOW(fd,2) = 12 + (count * 83);
  11867. WFIFOL(fd,4) = pages;
  11868. WFIFOL(fd,8) = count;
  11869. for( i = 0; i < count; i++ )
  11870. {
  11871. memcpy(&auction, RBUFP(buf,i * len), len);
  11872. k = 12 + (i * 83);
  11873. WFIFOL(fd,k) = auction.auction_id;
  11874. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11875. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11876. WFIFOW(fd,28+k) = item->view_id;
  11877. else
  11878. WFIFOW(fd,28+k) = auction.item.nameid;
  11879. WFIFOL(fd,30+k) = auction.type;
  11880. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11881. WFIFOB(fd,36+k) = auction.item.identify;
  11882. WFIFOB(fd,37+k) = auction.item.attribute;
  11883. WFIFOB(fd,38+k) = auction.item.refine;
  11884. WFIFOW(fd,39+k) = auction.item.card[0];
  11885. WFIFOW(fd,41+k) = auction.item.card[1];
  11886. WFIFOW(fd,43+k) = auction.item.card[2];
  11887. WFIFOW(fd,45+k) = auction.item.card[3];
  11888. WFIFOL(fd,47+k) = auction.price;
  11889. WFIFOL(fd,51+k) = auction.buynow;
  11890. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11891. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11892. }
  11893. WFIFOSET(fd,WFIFOW(fd,2));
  11894. }
  11895. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11896. /// 0256 <index>.W <result>.B
  11897. /// result:
  11898. /// 0 = success
  11899. /// 1 = failure
  11900. static void clif_Auction_setitem(int fd, int index, bool fail)
  11901. {
  11902. WFIFOHEAD(fd,packet_len(0x256));
  11903. WFIFOW(fd,0) = 0x256;
  11904. WFIFOW(fd,2) = index;
  11905. WFIFOB(fd,4) = fail;
  11906. WFIFOSET(fd,packet_len(0x256));
  11907. }
  11908. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11909. /// 024b <type>.W
  11910. /// type:
  11911. /// 0 = create (any other action in auction window)
  11912. /// 1 = cancel (cancel pressed on register tab)
  11913. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11914. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11915. {
  11916. if( sd->auction.amount > 0 )
  11917. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11918. sd->auction.amount = 0;
  11919. }
  11920. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11921. /// 024c <index>.W <count>.L
  11922. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11923. {
  11924. int idx = RFIFOW(fd,2) - 2;
  11925. int amount = RFIFOL(fd,4); // Always 1
  11926. struct item_data *item;
  11927. if( sd->auction.amount > 0 )
  11928. sd->auction.amount = 0;
  11929. if( idx < 0 || idx >= MAX_INVENTORY )
  11930. {
  11931. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11932. return;
  11933. }
  11934. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11935. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11936. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11937. return;
  11938. }
  11939. 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) )
  11940. { // Consumable or pets are not allowed
  11941. clif_Auction_setitem(sd->fd, idx, true);
  11942. return;
  11943. }
  11944. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11945. !sd->status.inventory[idx].identify ||
  11946. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11947. clif_Auction_setitem(sd->fd, idx, true);
  11948. return;
  11949. }
  11950. sd->auction.index = idx;
  11951. sd->auction.amount = amount;
  11952. clif_Auction_setitem(fd, idx + 2, false);
  11953. }
  11954. /// Result from an auction action (ZC_AUCTION_RESULT).
  11955. /// 0250 <result>.B
  11956. /// result:
  11957. /// 0 = You have failed to bid into the auction
  11958. /// 1 = You have successfully bid in the auction
  11959. /// 2 = The auction has been canceled
  11960. /// 3 = An auction with at least one bidder cannot be canceled
  11961. /// 4 = You cannot register more than 5 items in an auction at a time
  11962. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11963. /// 6 = You have won the auction
  11964. /// 7 = You have failed to win the auction
  11965. /// 8 = You do not have enough Zeny
  11966. /// 9 = You cannot place more than 5 bids at a time
  11967. void clif_Auction_message(int fd, unsigned char flag)
  11968. {
  11969. WFIFOHEAD(fd,packet_len(0x250));
  11970. WFIFOW(fd,0) = 0x250;
  11971. WFIFOB(fd,2) = flag;
  11972. WFIFOSET(fd,packet_len(0x250));
  11973. }
  11974. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11975. /// 025e <result>.W
  11976. /// result:
  11977. /// 0 = You have ended the auction
  11978. /// 1 = You cannot end the auction
  11979. /// 2 = Auction ID is incorrect
  11980. void clif_Auction_close(int fd, unsigned char flag)
  11981. {
  11982. WFIFOHEAD(fd,packet_len(0x25e));
  11983. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11984. WFIFOW(fd,2) = flag;
  11985. WFIFOSET(fd,packet_len(0x25e));
  11986. }
  11987. /// Request to add an auction (CZ_AUCTION_ADD).
  11988. /// 024d <now money>.L <max money>.L <delete hour>.W
  11989. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11990. {
  11991. struct auction_data auction;
  11992. struct item_data *item;
  11993. auction.price = RFIFOL(fd,2);
  11994. auction.buynow = RFIFOL(fd,6);
  11995. auction.hours = RFIFOW(fd,10);
  11996. // Invalid Situations...
  11997. if( sd->auction.amount < 1 )
  11998. {
  11999. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12000. return;
  12001. }
  12002. if( auction.price >= auction.buynow )
  12003. {
  12004. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12005. return;
  12006. }
  12007. if( auction.hours < 1 || auction.hours > 48 )
  12008. {
  12009. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12010. return;
  12011. }
  12012. // Auction checks...
  12013. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  12014. {
  12015. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12016. return;
  12017. }
  12018. if( auction.buynow > battle_config.auction_maximumprice )
  12019. { // Zeny Limits
  12020. auction.buynow = battle_config.auction_maximumprice;
  12021. if( auction.price >= auction.buynow )
  12022. auction.price = auction.buynow - 1;
  12023. }
  12024. auction.auction_id = 0;
  12025. auction.seller_id = sd->status.char_id;
  12026. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12027. auction.buyer_id = 0;
  12028. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12029. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12030. {
  12031. clif_Auction_message(fd, 2); // The auction has been canceled
  12032. return;
  12033. }
  12034. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12035. { // Just in case
  12036. clif_Auction_message(fd, 2); // The auction has been canceled
  12037. return;
  12038. }
  12039. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12040. auction.type = item->type;
  12041. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12042. auction.item.amount = 1;
  12043. auction.timestamp = 0;
  12044. if( !intif_Auction_register(&auction) )
  12045. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12046. else
  12047. {
  12048. int zeny = auction.hours*battle_config.auction_feeperhour;
  12049. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12050. sd->auction.amount = 0;
  12051. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12052. }
  12053. }
  12054. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12055. /// 024e <auction id>.L
  12056. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  12057. {
  12058. unsigned int auction_id = RFIFOL(fd,2);
  12059. intif_Auction_cancel(sd->status.char_id, auction_id);
  12060. }
  12061. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12062. /// 025d <auction id>.L
  12063. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  12064. {
  12065. unsigned int auction_id = RFIFOL(fd,2);
  12066. intif_Auction_close(sd->status.char_id, auction_id);
  12067. }
  12068. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12069. /// 024f <auction id>.L <money>.L
  12070. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  12071. {
  12072. unsigned int auction_id = RFIFOL(fd,2);
  12073. int bid = RFIFOL(fd,6);
  12074. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12075. clif_displaymessage(sd->fd, msg_txt(246));
  12076. return;
  12077. }
  12078. if( bid <= 0 )
  12079. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12080. else if( bid > sd->status.zeny )
  12081. clif_Auction_message(fd, 8); // You do not have enough zeny
  12082. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12083. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12084. else {
  12085. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12086. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12087. }
  12088. }
  12089. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12090. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12091. /// search type:
  12092. /// 0 = armor
  12093. /// 1 = weapon
  12094. /// 2 = card
  12095. /// 3 = misc
  12096. /// 4 = name search
  12097. /// 5 = auction id search
  12098. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  12099. {
  12100. char search_text[NAME_LENGTH];
  12101. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  12102. int price = RFIFOL(fd,4); // FIXME: bug #5071
  12103. clif_parse_Auction_cancelreg(fd, sd);
  12104. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  12105. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12106. }
  12107. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12108. /// 025c <type>.W
  12109. /// type:
  12110. /// 0 = sell (own auctions)
  12111. /// 1 = buy (own bids)
  12112. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12113. {
  12114. short type = RFIFOW(fd,2) + 6;
  12115. clif_parse_Auction_cancelreg(fd, sd);
  12116. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12117. }
  12118. /// CASH/POINT SHOP
  12119. ///
  12120. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12121. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12122. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12123. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12124. {
  12125. int fd,i;
  12126. #if PACKETVER < 20070711
  12127. const int offset = 8;
  12128. #else
  12129. const int offset = 12;
  12130. #endif
  12131. nullpo_retv(sd);
  12132. nullpo_retv(nd);
  12133. fd = sd->fd;
  12134. sd->npc_shopid = nd->bl.id;
  12135. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12136. WFIFOW(fd,0) = 0x287;
  12137. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12138. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12139. #if PACKETVER >= 20070711
  12140. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12141. #endif
  12142. for( i = 0; i < nd->u.shop.count; i++ )
  12143. {
  12144. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12145. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12146. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12147. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  12148. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12149. }
  12150. WFIFOSET(fd,WFIFOW(fd,2));
  12151. }
  12152. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12153. /// 0289 <cash point>.L <error>.W
  12154. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12155. /// error:
  12156. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12157. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12158. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12159. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12160. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12161. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12162. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12163. /// 7 = You can purchase up to 10 items.
  12164. /// 8 = Some items could not be purchased.
  12165. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12166. {
  12167. int fd = sd->fd;
  12168. WFIFOHEAD(fd, packet_len(0x289));
  12169. WFIFOW(fd,0) = 0x289;
  12170. WFIFOL(fd,2) = sd->cashPoints;
  12171. #if PACKETVER < 20070711
  12172. WFIFOW(fd,6) = TOW(error);
  12173. #else
  12174. WFIFOL(fd,6) = sd->kafraPoints;
  12175. WFIFOW(fd,10) = TOW(error);
  12176. #endif
  12177. WFIFOSET(fd, packet_len(0x289));
  12178. }
  12179. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12180. /// 0288 <name id>.W <amount>.W
  12181. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12182. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12183. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  12184. {
  12185. int fail = 0;
  12186. nullpo_retv(sd);
  12187. if( sd->state.trading || !sd->npc_shopid )
  12188. fail = 1;
  12189. else
  12190. {
  12191. #if PACKETVER < 20101116
  12192. short nameid = RFIFOW(fd,2);
  12193. short amount = RFIFOW(fd,4);
  12194. int points = RFIFOL(fd,6);
  12195. fail = npc_cashshop_buy(sd, nameid, amount, points);
  12196. #else
  12197. int len = RFIFOW(fd,2);
  12198. int points = RFIFOL(fd,4);
  12199. int count = RFIFOW(fd,8);
  12200. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  12201. if( len < 10 || len != 10 + count * 4)
  12202. {
  12203. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  12204. return;
  12205. }
  12206. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12207. #endif
  12208. }
  12209. clif_cashshop_ack(sd,fail);
  12210. }
  12211. /// Adoption System
  12212. ///
  12213. /// Adoption message (ZC_BABYMSG).
  12214. /// 0216 <msg>.L
  12215. /// msg:
  12216. /// 0 = "You cannot adopt more than 1 child."
  12217. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12218. /// 2 = "You cannot adopt a married person."
  12219. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12220. {
  12221. int fd = sd->fd;
  12222. WFIFOHEAD(fd,6);
  12223. WFIFOW(fd,0) = 0x216;
  12224. WFIFOL(fd,2) = type;
  12225. WFIFOSET(fd,6);
  12226. }
  12227. /// Adoption confirmation (ZC_REQ_BABY).
  12228. /// 01f6 <account id>.L <char id>.L <name>.B
  12229. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12230. {
  12231. int fd = sd->fd;
  12232. WFIFOHEAD(fd,34);
  12233. WFIFOW(fd,0) = 0x1f6;
  12234. WFIFOL(fd,2) = src->status.account_id;
  12235. WFIFOL(fd,6) = p_id;
  12236. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12237. WFIFOSET(fd,34);
  12238. }
  12239. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12240. /// 01f9 <account id>.L
  12241. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12242. {
  12243. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12244. if( pc_can_Adopt(sd, p_sd, tsd) )
  12245. {
  12246. tsd->adopt_invite = sd->status.account_id;
  12247. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12248. }
  12249. }
  12250. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12251. /// 01f7 <account id>.L <char id>.L <answer>.L
  12252. /// answer:
  12253. /// 0 = rejected
  12254. /// 1 = accepted
  12255. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12256. {
  12257. int p1_id = RFIFOL(fd,2);
  12258. int p2_id = RFIFOL(fd,6);
  12259. int result = RFIFOL(fd,10);
  12260. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12261. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12262. int pid = sd->adopt_invite;
  12263. sd->adopt_invite = 0;
  12264. if( p1_sd == NULL || p2_sd == NULL )
  12265. return; // Both players need to be online
  12266. if( pid != p1_sd->status.account_id )
  12267. return; // Incorrect values
  12268. if( result == 0 )
  12269. return; // Rejected
  12270. pc_adoption(p1_sd, p2_sd, sd);
  12271. }
  12272. /// Convex Mirror (ZC_BOSS_INFO).
  12273. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12274. /// infoType:
  12275. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12276. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12277. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12278. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12279. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12280. {
  12281. WFIFOHEAD(fd,70);
  12282. memset(WFIFOP(fd,0),0,70);
  12283. WFIFOW(fd,0) = 0x293;
  12284. if( md != NULL )
  12285. {
  12286. if( md->bl.prev != NULL )
  12287. { // Boss on This Map
  12288. if( flag )
  12289. {
  12290. WFIFOB(fd,2) = 1;
  12291. WFIFOL(fd,3) = md->bl.x;
  12292. WFIFOL(fd,7) = md->bl.y;
  12293. }
  12294. else
  12295. WFIFOB(fd,2) = 2; // First Time
  12296. }
  12297. else if (md->spawn_timer != INVALID_TIMER)
  12298. { // Boss is Dead
  12299. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12300. unsigned int seconds;
  12301. int hours, minutes;
  12302. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12303. hours = seconds / (60 * 60);
  12304. seconds = seconds - (60 * 60 * hours);
  12305. minutes = seconds / 60;
  12306. WFIFOB(fd,2) = 3;
  12307. WFIFOW(fd,11) = hours; // Hours
  12308. WFIFOW(fd,13) = minutes; // Minutes
  12309. }
  12310. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12311. }
  12312. WFIFOSET(fd,70);
  12313. }
  12314. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12315. /// 02d6 <account id>.L
  12316. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12317. {
  12318. int charid = RFIFOL(fd, 2);
  12319. struct map_session_data* tsd = map_id2sd(charid);
  12320. if (!tsd)
  12321. return;
  12322. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12323. clif_viewequip_ack(sd, tsd);
  12324. else
  12325. clif_viewequip_fail(sd);
  12326. }
  12327. /// Request to change equip window tick (CZ_CONFIG).
  12328. /// 02d8 <type>.L <value>.L
  12329. /// type:
  12330. /// 0 = open equip window
  12331. /// value:
  12332. /// 0 = disabled
  12333. /// 1 = enabled
  12334. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12335. {
  12336. bool flag = (bool)RFIFOL(fd,6);
  12337. sd->status.show_equip = flag;
  12338. clif_equiptickack(sd, flag);
  12339. }
  12340. /// Questlog System [Kevin] [Inkfish]
  12341. ///
  12342. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12343. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12344. void clif_quest_send_list(struct map_session_data * sd)
  12345. {
  12346. int fd = sd->fd;
  12347. int i;
  12348. int len = sd->avail_quests*5+8;
  12349. WFIFOHEAD(fd,len);
  12350. WFIFOW(fd, 0) = 0x2b1;
  12351. WFIFOW(fd, 2) = len;
  12352. WFIFOL(fd, 4) = sd->avail_quests;
  12353. for( i = 0; i < sd->avail_quests; i++ )
  12354. {
  12355. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12356. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12357. }
  12358. WFIFOSET(fd, len);
  12359. }
  12360. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12361. /// 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
  12362. void clif_quest_send_mission(struct map_session_data * sd)
  12363. {
  12364. int fd = sd->fd;
  12365. int i, j;
  12366. int len = sd->avail_quests*104+8;
  12367. struct mob_db *mob;
  12368. WFIFOHEAD(fd, len);
  12369. WFIFOW(fd, 0) = 0x2b2;
  12370. WFIFOW(fd, 2) = len;
  12371. WFIFOL(fd, 4) = sd->avail_quests;
  12372. for( i = 0; i < sd->avail_quests; i++ )
  12373. {
  12374. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12375. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12376. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12377. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12378. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  12379. {
  12380. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12381. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12382. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12383. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12384. }
  12385. }
  12386. WFIFOSET(fd, len);
  12387. }
  12388. /// Notification about a new quest (ZC_ADD_QUEST).
  12389. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12390. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12391. {
  12392. int fd = sd->fd;
  12393. int i;
  12394. struct mob_db *mob;
  12395. WFIFOHEAD(fd, packet_len(0x2b3));
  12396. WFIFOW(fd, 0) = 0x2b3;
  12397. WFIFOL(fd, 2) = qd->quest_id;
  12398. WFIFOB(fd, 6) = qd->state;
  12399. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12400. WFIFOL(fd, 11) = qd->time;
  12401. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12402. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12403. {
  12404. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12405. WFIFOW(fd, i*30+21) = qd->count[i];
  12406. mob = mob_db(quest_db[index].mob[i]);
  12407. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12408. }
  12409. WFIFOSET(fd, packet_len(0x2b3));
  12410. }
  12411. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12412. /// 02b4 <quest id>.L
  12413. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12414. {
  12415. int fd = sd->fd;
  12416. WFIFOHEAD(fd, packet_len(0x2b4));
  12417. WFIFOW(fd, 0) = 0x2b4;
  12418. WFIFOL(fd, 2) = quest_id;
  12419. WFIFOSET(fd, packet_len(0x2b4));
  12420. }
  12421. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12422. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12423. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12424. {
  12425. int fd = sd->fd;
  12426. int i;
  12427. int len = quest_db[index].num_objectives*12+6;
  12428. WFIFOHEAD(fd, len);
  12429. WFIFOW(fd, 0) = 0x2b5;
  12430. WFIFOW(fd, 2) = len;
  12431. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12432. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12433. {
  12434. WFIFOL(fd, i*12+6) = qd->quest_id;
  12435. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12436. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12437. WFIFOW(fd, i*12+16) = qd->count[i];
  12438. }
  12439. WFIFOSET(fd, len);
  12440. }
  12441. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12442. /// 02b6 <quest id>.L <active>.B
  12443. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12444. {
  12445. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12446. }
  12447. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12448. /// 02b7 <quest id>.L <active>.B
  12449. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12450. {
  12451. int fd = sd->fd;
  12452. WFIFOHEAD(fd, packet_len(0x2b7));
  12453. WFIFOW(fd, 0) = 0x2b7;
  12454. WFIFOL(fd, 2) = quest_id;
  12455. WFIFOB(fd, 6) = active;
  12456. WFIFOSET(fd, packet_len(0x2b7));
  12457. }
  12458. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12459. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12460. /// effect:
  12461. /// 0 = none
  12462. /// 1 = exclamation mark icon
  12463. /// 2 = question mark icon
  12464. /// type:
  12465. /// 0 = yellow
  12466. /// 1 = orange
  12467. /// 2 = green
  12468. /// 3 = purple
  12469. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12470. {
  12471. #if PACKETVER >= 20090218
  12472. int fd = sd->fd;
  12473. WFIFOHEAD(fd, packet_len(0x446));
  12474. WFIFOW(fd, 0) = 0x446;
  12475. WFIFOL(fd, 2) = bl->id;
  12476. WFIFOW(fd, 6) = bl->x;
  12477. WFIFOW(fd, 8) = bl->y;
  12478. WFIFOW(fd, 10) = state;
  12479. WFIFOW(fd, 12) = color;
  12480. WFIFOSET(fd, packet_len(0x446));
  12481. #endif
  12482. }
  12483. /// Mercenary System
  12484. ///
  12485. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12486. /// 02a2 <var id>.W <value>.L
  12487. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12488. {
  12489. struct mercenary_data *md;
  12490. struct status_data *status;
  12491. int fd;
  12492. if( sd == NULL || (md = sd->md) == NULL )
  12493. return;
  12494. fd = sd->fd;
  12495. status = &md->battle_status;
  12496. WFIFOHEAD(fd,packet_len(0x2a2));
  12497. WFIFOW(fd,0) = 0x2a2;
  12498. WFIFOW(fd,2) = type;
  12499. switch( type )
  12500. {
  12501. case SP_ATK1:
  12502. {
  12503. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12504. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12505. }
  12506. break;
  12507. case SP_MATK1:
  12508. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12509. break;
  12510. case SP_HIT:
  12511. WFIFOL(fd,4) = status->hit;
  12512. break;
  12513. case SP_CRITICAL:
  12514. WFIFOL(fd,4) = status->cri/10;
  12515. break;
  12516. case SP_DEF1:
  12517. WFIFOL(fd,4) = status->def;
  12518. break;
  12519. case SP_MDEF1:
  12520. WFIFOL(fd,4) = status->mdef;
  12521. break;
  12522. case SP_MERCFLEE:
  12523. WFIFOL(fd,4) = status->flee;
  12524. break;
  12525. case SP_ASPD:
  12526. WFIFOL(fd,4) = status->amotion;
  12527. break;
  12528. case SP_HP:
  12529. WFIFOL(fd,4) = status->hp;
  12530. break;
  12531. case SP_MAXHP:
  12532. WFIFOL(fd,4) = status->max_hp;
  12533. break;
  12534. case SP_SP:
  12535. WFIFOL(fd,4) = status->sp;
  12536. break;
  12537. case SP_MAXSP:
  12538. WFIFOL(fd,4) = status->max_sp;
  12539. break;
  12540. case SP_MERCKILLS:
  12541. WFIFOL(fd,4) = md->mercenary.kill_count;
  12542. break;
  12543. case SP_MERCFAITH:
  12544. WFIFOL(fd,4) = mercenary_get_faith(md);
  12545. break;
  12546. }
  12547. WFIFOSET(fd,packet_len(0x2a2));
  12548. }
  12549. /// Mercenary base status data (ZC_MER_INIT).
  12550. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12551. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12552. /// <calls>.L <kills>.L <atk range>.W
  12553. void clif_mercenary_info(struct map_session_data *sd)
  12554. {
  12555. int fd;
  12556. struct mercenary_data *md;
  12557. struct status_data *status;
  12558. int atk;
  12559. if( sd == NULL || (md = sd->md) == NULL )
  12560. return;
  12561. fd = sd->fd;
  12562. status = &md->battle_status;
  12563. WFIFOHEAD(fd,packet_len(0x29b));
  12564. WFIFOW(fd,0) = 0x29b;
  12565. WFIFOL(fd,2) = md->bl.id;
  12566. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12567. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12568. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12569. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12570. WFIFOW(fd,10) = status->hit;
  12571. WFIFOW(fd,12) = status->cri/10;
  12572. WFIFOW(fd,14) = status->def;
  12573. WFIFOW(fd,16) = status->mdef;
  12574. WFIFOW(fd,18) = status->flee;
  12575. WFIFOW(fd,20) = status->amotion;
  12576. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12577. WFIFOW(fd,46) = md->db->lv;
  12578. WFIFOL(fd,48) = status->hp;
  12579. WFIFOL(fd,52) = status->max_hp;
  12580. WFIFOL(fd,56) = status->sp;
  12581. WFIFOL(fd,60) = status->max_sp;
  12582. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12583. WFIFOW(fd,68) = mercenary_get_faith(md);
  12584. WFIFOL(fd,70) = mercenary_get_calls(md);
  12585. WFIFOL(fd,74) = md->mercenary.kill_count;
  12586. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12587. WFIFOSET(fd,packet_len(0x29b));
  12588. }
  12589. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12590. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12591. void clif_mercenary_skillblock(struct map_session_data *sd)
  12592. {
  12593. struct mercenary_data *md;
  12594. int fd, i, len = 4, id, j;
  12595. if( sd == NULL || (md = sd->md) == NULL )
  12596. return;
  12597. fd = sd->fd;
  12598. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12599. WFIFOW(fd,0) = 0x29d;
  12600. for( i = 0; i < MAX_MERCSKILL; i++ )
  12601. {
  12602. if( (id = md->db->skill[i].id) == 0 )
  12603. continue;
  12604. j = id - MC_SKILLBASE;
  12605. WFIFOW(fd,len) = id;
  12606. WFIFOL(fd,len+2) = skill_get_inf(id);
  12607. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12608. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12609. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12610. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12611. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12612. len += 37;
  12613. }
  12614. WFIFOW(fd,2) = len;
  12615. WFIFOSET(fd,len);
  12616. }
  12617. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12618. /// 029f <command>.B
  12619. /// 1 = mercenary information
  12620. /// 2 = delete
  12621. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12622. {
  12623. int option = RFIFOB(fd,2);
  12624. if( sd->md == NULL )
  12625. return;
  12626. if( option == 2 ) merc_delete(sd->md, 2);
  12627. }
  12628. /// Mercenary Message
  12629. /// message:
  12630. /// 0 = Mercenary soldier's duty hour is over.
  12631. /// 1 = Your mercenary soldier has been killed.
  12632. /// 2 = Your mercenary soldier has been fired.
  12633. /// 3 = Your mercenary soldier has ran away.
  12634. void clif_mercenary_message(struct map_session_data* sd, int message)
  12635. {
  12636. clif_msg(sd, 1266 + message);
  12637. }
  12638. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12639. /// 0298 <name id>.W <seconds>.L
  12640. void clif_rental_time(int fd, int nameid, int seconds)
  12641. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12642. WFIFOHEAD(fd,packet_len(0x298));
  12643. WFIFOW(fd,0) = 0x298;
  12644. WFIFOW(fd,2) = nameid;
  12645. WFIFOL(fd,4) = seconds;
  12646. WFIFOSET(fd,packet_len(0x298));
  12647. }
  12648. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12649. /// 0299 <index>.W <name id>.W
  12650. void clif_rental_expired(int fd, int index, int nameid)
  12651. { // '<ItemName>' item has been deleted from the Inventory
  12652. WFIFOHEAD(fd,packet_len(0x299));
  12653. WFIFOW(fd,0) = 0x299;
  12654. WFIFOW(fd,2) = index+2;
  12655. WFIFOW(fd,4) = nameid;
  12656. WFIFOSET(fd,packet_len(0x299));
  12657. }
  12658. /// Book Reading (ZC_READ_BOOK).
  12659. /// 0294 <book id>.L <page>.L
  12660. void clif_readbook(int fd, int book_id, int page)
  12661. {
  12662. WFIFOHEAD(fd,packet_len(0x294));
  12663. WFIFOW(fd,0) = 0x294;
  12664. WFIFOL(fd,2) = book_id;
  12665. WFIFOL(fd,6) = page;
  12666. WFIFOSET(fd,packet_len(0x294));
  12667. }
  12668. /// Battlegrounds
  12669. ///
  12670. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12671. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12672. void clif_bg_hp(struct map_session_data *sd)
  12673. {
  12674. unsigned char buf[34];
  12675. const int cmd = 0x2e0;
  12676. nullpo_retv(sd);
  12677. WBUFW(buf,0) = cmd;
  12678. WBUFL(buf,2) = sd->status.account_id;
  12679. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12680. if( sd->battle_status.max_hp > INT16_MAX )
  12681. { // To correctly display the %hp bar. [Skotlex]
  12682. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12683. WBUFW(buf,32) = 100;
  12684. }
  12685. else
  12686. {
  12687. WBUFW(buf,30) = sd->battle_status.hp;
  12688. WBUFW(buf,32) = sd->battle_status.max_hp;
  12689. }
  12690. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12691. }
  12692. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12693. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12694. void clif_bg_xy(struct map_session_data *sd)
  12695. {
  12696. unsigned char buf[36];
  12697. nullpo_retv(sd);
  12698. WBUFW(buf,0)=0x2df;
  12699. WBUFL(buf,2)=sd->status.account_id;
  12700. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12701. WBUFW(buf,30)=sd->status.class_;
  12702. WBUFW(buf,32)=sd->bl.x;
  12703. WBUFW(buf,34)=sd->bl.y;
  12704. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12705. }
  12706. void clif_bg_xy_remove(struct map_session_data *sd)
  12707. {
  12708. unsigned char buf[36];
  12709. nullpo_retv(sd);
  12710. WBUFW(buf,0)=0x2df;
  12711. WBUFL(buf,2)=sd->status.account_id;
  12712. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12713. WBUFW(buf,30)=0;
  12714. WBUFW(buf,32)=-1;
  12715. WBUFW(buf,34)=-1;
  12716. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12717. }
  12718. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12719. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12720. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12721. {
  12722. struct map_session_data *sd;
  12723. unsigned char *buf;
  12724. if( (sd = bg_getavailablesd(bg)) == NULL )
  12725. return;
  12726. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12727. WBUFW(buf,0) = 0x2dc;
  12728. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12729. WBUFL(buf,4) = src_id;
  12730. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12731. memcpy(WBUFP(buf,32), mes, len);
  12732. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12733. if( buf )
  12734. aFree(buf);
  12735. }
  12736. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12737. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12738. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12739. {
  12740. const char* text = (char*)RFIFOP(fd,4);
  12741. int textlen = RFIFOW(fd,2) - 4;
  12742. char *name, *message;
  12743. int namelen, messagelen;
  12744. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12745. return;
  12746. if( is_atcommand(fd, sd, message, 1) )
  12747. return;
  12748. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12749. return;
  12750. if( battle_config.min_chat_delay )
  12751. {
  12752. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12753. return;
  12754. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12755. }
  12756. bg_send_message(sd, text, textlen);
  12757. }
  12758. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12759. /// 02de <camp A points>.W <camp B points>.W
  12760. void clif_bg_updatescore(int16 m)
  12761. {
  12762. struct block_list bl;
  12763. unsigned char buf[6];
  12764. bl.id = 0;
  12765. bl.type = BL_NUL;
  12766. bl.m = m;
  12767. WBUFW(buf,0) = 0x2de;
  12768. WBUFW(buf,2) = map[m].bgscore_lion;
  12769. WBUFW(buf,4) = map[m].bgscore_eagle;
  12770. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12771. }
  12772. void clif_bg_updatescore_single(struct map_session_data *sd)
  12773. {
  12774. int fd;
  12775. nullpo_retv(sd);
  12776. fd = sd->fd;
  12777. WFIFOHEAD(fd,packet_len(0x2de));
  12778. WFIFOW(fd,0) = 0x2de;
  12779. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12780. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12781. WFIFOSET(fd,packet_len(0x2de));
  12782. }
  12783. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12784. /// 02dd <account id>.L <name>.24B <camp>.W
  12785. void clif_sendbgemblem_area(struct map_session_data *sd)
  12786. {
  12787. unsigned char buf[33];
  12788. nullpo_retv(sd);
  12789. WBUFW(buf, 0) = 0x2dd;
  12790. WBUFL(buf,2) = sd->bl.id;
  12791. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12792. WBUFW(buf,30) = sd->bg_id;
  12793. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12794. }
  12795. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12796. {
  12797. nullpo_retv(sd);
  12798. WFIFOHEAD(fd,32);
  12799. WFIFOW(fd,0) = 0x2dd;
  12800. WFIFOL(fd,2) = sd->bl.id;
  12801. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12802. WFIFOW(fd,30) = sd->bg_id;
  12803. WFIFOSET(fd,packet_len(0x2dd));
  12804. }
  12805. /// Custom Fonts (ZC_NOTIFY_FONT).
  12806. /// 02ef <account_id>.L <font id>.W
  12807. void clif_font(struct map_session_data *sd)
  12808. {
  12809. #if PACKETVER >= 20080102
  12810. unsigned char buf[8];
  12811. nullpo_retv(sd);
  12812. WBUFW(buf,0) = 0x2ef;
  12813. WBUFL(buf,2) = sd->bl.id;
  12814. WBUFW(buf,6) = sd->user_font;
  12815. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12816. #endif
  12817. }
  12818. /*==========================================
  12819. * Instancing Window
  12820. *------------------------------------------*/
  12821. int clif_instance(int instance_id, int type, int flag)
  12822. {
  12823. struct map_session_data *sd;
  12824. struct party_data *p;
  12825. unsigned char buf[255];
  12826. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12827. return 0;
  12828. switch( type )
  12829. {
  12830. case 1:
  12831. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12832. // Required to start the instancing information window on Client
  12833. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12834. WBUFW(buf,0) = 0x02CB;
  12835. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12836. WBUFW(buf,63) = flag;
  12837. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12838. break;
  12839. case 2:
  12840. // S 0x2cc <Standby Position>.W
  12841. // To announce Instancing queue creation if no maps available
  12842. WBUFW(buf,0) = 0x02CC;
  12843. WBUFW(buf,2) = flag;
  12844. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12845. break;
  12846. case 3:
  12847. case 4:
  12848. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12849. WBUFW(buf,0) = 0x02CD;
  12850. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12851. if( type == 3 )
  12852. {
  12853. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12854. WBUFL(buf,67) = 0;
  12855. }
  12856. else
  12857. {
  12858. WBUFL(buf,63) = 0;
  12859. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12860. }
  12861. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12862. break;
  12863. case 5:
  12864. // S 0x2ce <Message ID>.L
  12865. // 0 = Notification (EnterLimitDate update?)
  12866. // 1 = The Memorial Dungeon expired; it has been destroyed
  12867. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12868. // 3 = The Memorial Dungeon has been removed.
  12869. // 4 = Create failure (removes the instance window)
  12870. WBUFW(buf,0) = 0x02CE;
  12871. WBUFL(buf,2) = flag;
  12872. //WBUFL(buf,6) = EnterLimitDate;
  12873. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12874. break;
  12875. }
  12876. return 0;
  12877. }
  12878. void clif_instance_join(int fd, int instance_id)
  12879. {
  12880. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12881. {
  12882. WFIFOHEAD(fd,packet_len(0x02CD));
  12883. WFIFOW(fd,0) = 0x02CD;
  12884. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12885. WFIFOL(fd,63) = 0;
  12886. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12887. WFIFOSET(fd,packet_len(0x02CD));
  12888. }
  12889. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12890. {
  12891. WFIFOHEAD(fd,packet_len(0x02CD));
  12892. WFIFOW(fd,0) = 0x02CD;
  12893. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12894. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12895. WFIFOL(fd,67) = 0;
  12896. WFIFOSET(fd,packet_len(0x02CD));
  12897. }
  12898. else
  12899. {
  12900. WFIFOHEAD(fd,packet_len(0x02CB));
  12901. WFIFOW(fd,0) = 0x02CB;
  12902. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12903. WFIFOW(fd,63) = 0;
  12904. WFIFOSET(fd,packet_len(0x02CB));
  12905. }
  12906. }
  12907. void clif_instance_leave(int fd)
  12908. {
  12909. WFIFOHEAD(fd,packet_len(0x02CE));
  12910. WFIFOW(fd,0) = 0x02ce;
  12911. WFIFOL(fd,2) = 4;
  12912. WFIFOSET(fd,packet_len(0x02CE));
  12913. }
  12914. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12915. /// 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
  12916. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12917. {
  12918. #if PACKETVER >= 20071002
  12919. unsigned char buf[22];
  12920. struct item_data* id = itemdb_search(item_data->nameid);
  12921. WBUFW(buf,0) = 0x2b8;
  12922. WBUFL(buf,2) = sd->status.account_id;
  12923. WBUFW(buf,6) = item_data->nameid;
  12924. WBUFB(buf,8) = item_data->identify;
  12925. WBUFB(buf,9) = item_data->attribute;
  12926. WBUFB(buf,10) = item_data->refine;
  12927. clif_addcards(WBUFP(buf,11), item_data);
  12928. WBUFW(buf,19) = id->equip; // equip location
  12929. WBUFB(buf,21) = itemtype(id->type); // item type
  12930. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12931. #endif
  12932. }
  12933. /// Display gained exp (ZC_NOTIFY_EXP).
  12934. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12935. /// var id:
  12936. /// SP_BASEEXP, SP_JOBEXP
  12937. /// exp type:
  12938. /// 0 = normal exp gain/loss
  12939. /// 1 = quest exp gain/loss
  12940. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12941. {
  12942. int fd;
  12943. nullpo_retv(sd);
  12944. fd = sd->fd;
  12945. WFIFOHEAD(fd, packet_len(0x7f6));
  12946. WFIFOW(fd,0) = 0x7f6;
  12947. WFIFOL(fd,2) = sd->bl.id;
  12948. WFIFOL(fd,6) = exp;
  12949. WFIFOW(fd,10) = type;
  12950. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12951. WFIFOSET(fd,packet_len(0x7f6));
  12952. }
  12953. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12954. /// type:
  12955. /// 0 = Displays 'value' for 5 seconds.
  12956. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12957. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12958. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12959. /// value:
  12960. /// 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).
  12961. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12962. {
  12963. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12964. WFIFOW(sd->fd,0) = 0x1b1;
  12965. WFIFOB(sd->fd,2) = type;
  12966. WFIFOL(sd->fd,3) = value;
  12967. WFIFOSET(sd->fd, packet_len(0x1b1));
  12968. }
  12969. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12970. /// 021d <state>.L
  12971. /// state:
  12972. /// 0 = Full effects
  12973. /// 1 = Reduced effects
  12974. ///
  12975. /// NOTE: The state is used on Aegis for sending skill unit packet
  12976. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12977. /// whenever possible. Due to the way the decision check is
  12978. /// constructed, this state tracking was rendered useless,
  12979. /// as the only skill unit, that is sent with 0x1c9 is
  12980. /// Graffiti.
  12981. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12982. {
  12983. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12984. sd->state.lesseffect = ( isLess != 0 );
  12985. }
  12986. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12987. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12988. int n = (RFIFOW(fd,2)-12) / 4;
  12989. int type = RFIFOL(fd,4);
  12990. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12991. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12992. if( sd->state.trading || sd->npc_shopid )
  12993. return;
  12994. if( flag == 0 || n == 0) {
  12995. clif_menuskill_clear(sd);
  12996. return; // Canceled by player.
  12997. }
  12998. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12999. clif_menuskill_clear(sd);
  13000. return; // Prevent hacking.
  13001. }
  13002. switch( type ) {
  13003. case 0: // Change Material
  13004. skill_changematerial(sd,n,item_list);
  13005. break;
  13006. case 1: // Level 1: Pure to Rough
  13007. case 2: // Level 2: Rough to Pure
  13008. skill_elementalanalysis(sd,n,type,item_list);
  13009. break;
  13010. }
  13011. clif_menuskill_clear(sd);
  13012. return;
  13013. }
  13014. /*==========================================
  13015. * Elemental System
  13016. *==========================================*/
  13017. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13018. struct elemental_data *ed;
  13019. struct status_data *status;
  13020. int fd;
  13021. if( sd == NULL || (ed = sd->ed) == NULL )
  13022. return;
  13023. fd = sd->fd;
  13024. status = &ed->battle_status;
  13025. WFIFOHEAD(fd,8);
  13026. WFIFOW(fd,0) = 0x81e;
  13027. WFIFOW(fd,2) = type;
  13028. switch( type ) {
  13029. case SP_HP:
  13030. WFIFOL(fd,4) = status->hp;
  13031. break;
  13032. case SP_MAXHP:
  13033. WFIFOL(fd,4) = status->max_hp;
  13034. break;
  13035. case SP_SP:
  13036. WFIFOL(fd,4) = status->sp;
  13037. break;
  13038. case SP_MAXSP:
  13039. WFIFOL(fd,4) = status->max_sp;
  13040. break;
  13041. }
  13042. WFIFOSET(fd,8);
  13043. }
  13044. void clif_elemental_info(struct map_session_data *sd) {
  13045. int fd;
  13046. struct elemental_data *ed;
  13047. struct status_data *status;
  13048. if( sd == NULL || (ed = sd->ed) == NULL )
  13049. return;
  13050. fd = sd->fd;
  13051. status = &ed->battle_status;
  13052. WFIFOHEAD(fd,22);
  13053. WFIFOW(fd, 0) = 0x81d;
  13054. WFIFOL(fd, 2) = ed->bl.id;
  13055. WFIFOL(fd, 6) = status->hp;
  13056. WFIFOL(fd,10) = status->max_hp;
  13057. WFIFOL(fd,14) = status->sp;
  13058. WFIFOL(fd,18) = status->max_sp;
  13059. WFIFOSET(fd,22);
  13060. }
  13061. /// Buying Store System
  13062. ///
  13063. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13064. /// 0810 <slots>.B
  13065. void clif_buyingstore_open(struct map_session_data* sd)
  13066. {
  13067. int fd = sd->fd;
  13068. WFIFOHEAD(fd,packet_len(0x810));
  13069. WFIFOW(fd,0) = 0x810;
  13070. WFIFOB(fd,2) = sd->buyingstore.slots;
  13071. WFIFOSET(fd,packet_len(0x810));
  13072. }
  13073. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13074. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13075. /// result:
  13076. /// 0 = cancel
  13077. /// 1 = open
  13078. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13079. {
  13080. const unsigned int blocksize = 8;
  13081. uint8* itemlist;
  13082. char storename[MESSAGE_SIZE];
  13083. unsigned char result;
  13084. int zenylimit;
  13085. unsigned int count, packet_len;
  13086. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13087. packet_len = RFIFOW(fd,info->pos[0]);
  13088. // TODO: Make this check global for all variable length packets.
  13089. if( packet_len < 89 )
  13090. {// minimum packet length
  13091. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13092. return;
  13093. }
  13094. zenylimit = RFIFOL(fd,info->pos[1]);
  13095. result = RFIFOL(fd,info->pos[2]);
  13096. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13097. itemlist = RFIFOP(fd,info->pos[4]);
  13098. // so that buyingstore_create knows, how many elements it has access to
  13099. packet_len-= info->pos[4];
  13100. if( packet_len%blocksize )
  13101. {
  13102. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13103. return;
  13104. }
  13105. count = packet_len/blocksize;
  13106. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13107. }
  13108. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13109. /// 0812 <result>.W <total weight>.L
  13110. /// result:
  13111. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13112. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13113. /// 8 = "No sale (purchase) information available." (0x705)
  13114. /// ? = nothing
  13115. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13116. {
  13117. int fd = sd->fd;
  13118. WFIFOHEAD(fd,packet_len(0x812));
  13119. WFIFOW(fd,0) = 0x812;
  13120. WFIFOW(fd,2) = result;
  13121. WFIFOL(fd,4) = weight;
  13122. WFIFOSET(fd,packet_len(0x812));
  13123. }
  13124. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13125. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13126. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13127. {
  13128. int fd = sd->fd;
  13129. unsigned int i;
  13130. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13131. WFIFOW(fd,0) = 0x813;
  13132. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13133. WFIFOL(fd,4) = sd->bl.id;
  13134. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13135. for( i = 0; i < sd->buyingstore.slots; i++ )
  13136. {
  13137. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13138. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13139. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  13140. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13141. }
  13142. WFIFOSET(fd,WFIFOW(fd,2));
  13143. }
  13144. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13145. /// 0814 <account id>.L <store name>.80B
  13146. void clif_buyingstore_entry(struct map_session_data* sd)
  13147. {
  13148. uint8 buf[86];
  13149. WBUFW(buf,0) = 0x814;
  13150. WBUFL(buf,2) = sd->bl.id;
  13151. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13152. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13153. }
  13154. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13155. {
  13156. int fd = sd->fd;
  13157. WFIFOHEAD(fd,packet_len(0x814));
  13158. WFIFOW(fd,0) = 0x814;
  13159. WFIFOL(fd,2) = pl_sd->bl.id;
  13160. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13161. WFIFOSET(fd,packet_len(0x814));
  13162. }
  13163. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13164. /// 0815
  13165. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13166. {
  13167. buyingstore_close(sd);
  13168. }
  13169. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13170. /// 0816 <account id>.L
  13171. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13172. {
  13173. uint8 buf[6];
  13174. WBUFW(buf,0) = 0x816;
  13175. WBUFL(buf,2) = sd->bl.id;
  13176. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13177. }
  13178. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13179. {
  13180. int fd = sd->fd;
  13181. WFIFOHEAD(fd,packet_len(0x816));
  13182. WFIFOW(fd,0) = 0x816;
  13183. WFIFOL(fd,2) = pl_sd->bl.id;
  13184. WFIFOSET(fd,packet_len(0x816));
  13185. }
  13186. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13187. /// 0817 <account id>.L
  13188. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13189. {
  13190. int account_id;
  13191. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13192. buyingstore_open(sd, account_id);
  13193. }
  13194. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13195. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13196. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13197. {
  13198. int fd = sd->fd;
  13199. unsigned int i;
  13200. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13201. WFIFOW(fd,0) = 0x818;
  13202. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13203. WFIFOL(fd,4) = pl_sd->bl.id;
  13204. WFIFOL(fd,8) = pl_sd->buyer_id;
  13205. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13206. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13207. {
  13208. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13209. 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.
  13210. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13211. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13212. }
  13213. WFIFOSET(fd,WFIFOW(fd,2));
  13214. }
  13215. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13216. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13217. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13218. {
  13219. const unsigned int blocksize = 6;
  13220. uint8* itemlist;
  13221. int account_id;
  13222. unsigned int count, packet_len, buyer_id;
  13223. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13224. packet_len = RFIFOW(fd,info->pos[0]);
  13225. if( packet_len < 12 )
  13226. {// minimum packet length
  13227. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13228. return;
  13229. }
  13230. account_id = RFIFOL(fd,info->pos[1]);
  13231. buyer_id = RFIFOL(fd,info->pos[2]);
  13232. itemlist = RFIFOP(fd,info->pos[3]);
  13233. // so that buyingstore_trade knows, how many elements it has access to
  13234. packet_len-= info->pos[3];
  13235. if( packet_len%blocksize )
  13236. {
  13237. 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);
  13238. return;
  13239. }
  13240. count = packet_len/blocksize;
  13241. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13242. }
  13243. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13244. /// 081a <result>.W
  13245. /// result:
  13246. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13247. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13248. /// ? = nothing
  13249. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13250. {
  13251. int fd = sd->fd;
  13252. WFIFOHEAD(fd,packet_len(0x81a));
  13253. WFIFOW(fd,0) = 0x81a;
  13254. WFIFOW(fd,2) = result;
  13255. WFIFOSET(fd,packet_len(0x81a));
  13256. }
  13257. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13258. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13259. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13260. {
  13261. int fd = sd->fd;
  13262. WFIFOHEAD(fd,packet_len(0x81b));
  13263. WFIFOW(fd,0) = 0x81b;
  13264. WFIFOW(fd,2) = nameid;
  13265. WFIFOW(fd,4) = amount; // amount of nameid received
  13266. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13267. WFIFOSET(fd,packet_len(0x81b));
  13268. }
  13269. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13270. /// 081c <index>.W <amount>.W <price>.L
  13271. /// message:
  13272. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13273. ///
  13274. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13275. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13276. {
  13277. int fd = sd->fd;
  13278. WFIFOHEAD(fd,packet_len(0x81c));
  13279. WFIFOW(fd,0) = 0x81c;
  13280. WFIFOW(fd,2) = index+2;
  13281. WFIFOW(fd,4) = amount;
  13282. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13283. WFIFOSET(fd,packet_len(0x81c));
  13284. }
  13285. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13286. /// 0824 <result>.W <name id>.W
  13287. /// result:
  13288. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13289. /// 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)
  13290. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13291. /// ? = nothing
  13292. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13293. {
  13294. int fd = sd->fd;
  13295. WFIFOHEAD(fd,packet_len(0x824));
  13296. WFIFOW(fd,0) = 0x824;
  13297. WFIFOW(fd,2) = result;
  13298. WFIFOW(fd,4) = nameid;
  13299. WFIFOSET(fd,packet_len(0x824));
  13300. }
  13301. /// Search Store Info System
  13302. ///
  13303. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13304. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13305. /// type:
  13306. /// 0 = Vending
  13307. /// 1 = Buying Store
  13308. ///
  13309. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13310. /// amount of card slots. If the client does not know about the item it
  13311. /// cannot be searched.
  13312. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13313. {
  13314. const unsigned int blocksize = 2;
  13315. const uint8* itemlist;
  13316. const uint8* cardlist;
  13317. unsigned char type;
  13318. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13319. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13320. packet_len = RFIFOW(fd,info->pos[0]);
  13321. if( packet_len < 15 )
  13322. {// minimum packet length
  13323. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13324. return;
  13325. }
  13326. type = RFIFOB(fd,info->pos[1]);
  13327. max_price = RFIFOL(fd,info->pos[2]);
  13328. min_price = RFIFOL(fd,info->pos[3]);
  13329. item_count = RFIFOB(fd,info->pos[4]);
  13330. card_count = RFIFOB(fd,info->pos[5]);
  13331. itemlist = RFIFOP(fd,info->pos[6]);
  13332. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13333. // check, if there is enough data for the claimed count of items
  13334. packet_len-= info->pos[6];
  13335. if( packet_len%blocksize )
  13336. {
  13337. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13338. return;
  13339. }
  13340. count = packet_len/blocksize;
  13341. if( count < item_count+card_count )
  13342. {
  13343. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13344. return;
  13345. }
  13346. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13347. }
  13348. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13349. /// 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 }*
  13350. /// is first page:
  13351. /// 0 = appends to existing results
  13352. /// 1 = clears previous results before displaying this result set
  13353. /// is next page:
  13354. /// 0 = no "next" label
  13355. /// 1 = "next" label to retrieve more results
  13356. void clif_search_store_info_ack(struct map_session_data* sd)
  13357. {
  13358. const unsigned int blocksize = MESSAGE_SIZE+26;
  13359. int fd = sd->fd;
  13360. unsigned int i, start, end;
  13361. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13362. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13363. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13364. WFIFOW(fd,0) = 0x836;
  13365. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13366. WFIFOB(fd,4) = !sd->searchstore.pages;
  13367. WFIFOB(fd,5) = searchstore_querynext(sd);
  13368. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13369. for( i = start; i < end; i++ )
  13370. {
  13371. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13372. struct item it;
  13373. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13374. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13375. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13376. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13377. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13378. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13379. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13380. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13381. // make-up an item for clif_addcards
  13382. memset(&it, 0, sizeof(it));
  13383. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13384. it.nameid = ssitem->nameid;
  13385. it.amount = ssitem->amount;
  13386. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13387. }
  13388. WFIFOSET(fd,WFIFOW(fd,2));
  13389. }
  13390. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13391. /// 0837 <reason>.B
  13392. /// reason:
  13393. /// 0 = "No matching stores were found." (0x70b)
  13394. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13395. /// 2 = "You cannot search anymore." (0x706)
  13396. /// 3 = "You cannot search yet." (0x708)
  13397. /// 4 = "No sale (purchase) information available." (0x705)
  13398. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13399. {
  13400. int fd = sd->fd;
  13401. WFIFOHEAD(fd,packet_len(0x837));
  13402. WFIFOW(fd,0) = 0x837;
  13403. WFIFOB(fd,2) = reason;
  13404. WFIFOSET(fd,packet_len(0x837));
  13405. }
  13406. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13407. /// 0838
  13408. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13409. {
  13410. searchstore_next(sd);
  13411. }
  13412. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13413. /// 083a <type>.W <remaining uses>.B
  13414. /// type:
  13415. /// 0 = Search Stores
  13416. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13417. void clif_open_search_store_info(struct map_session_data* sd)
  13418. {
  13419. int fd = sd->fd;
  13420. WFIFOHEAD(fd,packet_len(0x83a));
  13421. WFIFOW(fd,0) = 0x83a;
  13422. WFIFOW(fd,2) = sd->searchstore.effect;
  13423. #if PACKETVER > 20100701
  13424. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13425. #endif
  13426. WFIFOSET(fd,packet_len(0x83a));
  13427. }
  13428. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13429. /// 083b
  13430. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13431. {
  13432. searchstore_close(sd);
  13433. }
  13434. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13435. /// 083c <account id>.L <store id>.L <nameid>.W
  13436. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13437. {
  13438. unsigned short nameid;
  13439. int account_id, store_id;
  13440. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13441. account_id = RFIFOL(fd,info->pos[0]);
  13442. store_id = RFIFOL(fd,info->pos[1]);
  13443. nameid = RFIFOW(fd,info->pos[2]);
  13444. searchstore_click(sd, account_id, store_id, nameid);
  13445. }
  13446. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13447. /// 083d <xPos>.W <yPos>.W
  13448. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13449. {
  13450. int fd = sd->fd;
  13451. WFIFOHEAD(fd,packet_len(0x83d));
  13452. WFIFOW(fd,0) = 0x83d;
  13453. WFIFOW(fd,2) = x;
  13454. WFIFOW(fd,4) = y;
  13455. WFIFOSET(fd,packet_len(0x83d));
  13456. }
  13457. /// Parse function for packet debugging.
  13458. void clif_parse_debug(int fd,struct map_session_data *sd)
  13459. {
  13460. int cmd, packet_len;
  13461. // clif_parse ensures, that there is at least 2 bytes of data
  13462. cmd = RFIFOW(fd,0);
  13463. if( sd )
  13464. {
  13465. packet_len = packet_db[sd->packet_ver][cmd].len;
  13466. if( packet_len == 0 )
  13467. {// unknown
  13468. packet_len = RFIFOREST(fd);
  13469. }
  13470. else if( packet_len == -1 )
  13471. {// variable length
  13472. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13473. }
  13474. 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);
  13475. }
  13476. else
  13477. {
  13478. packet_len = RFIFOREST(fd);
  13479. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13480. }
  13481. ShowDump(RFIFOP(fd,0), packet_len);
  13482. }
  13483. /*==========================================
  13484. * Server tells client to display a window similar to Magnifier (item) one
  13485. * Server populates the window with avilable elemental converter options according to player's inventory
  13486. *------------------------------------------*/
  13487. int clif_elementalconverter_list(struct map_session_data *sd) {
  13488. int i,c,view,fd;
  13489. nullpo_ret(sd);
  13490. /// Main client packet processing function
  13491. fd=sd->fd;
  13492. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13493. WFIFOW(fd, 0)=0x1ad;
  13494. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13495. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13496. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13497. WFIFOW(fd,c*2+ 4)= view;
  13498. else
  13499. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13500. c++;
  13501. }
  13502. }
  13503. WFIFOW(fd,2) = c*2+4;
  13504. WFIFOSET(fd, WFIFOW(fd,2));
  13505. if (c > 0) {
  13506. sd->menuskill_id = SA_CREATECON;
  13507. sd->menuskill_val = c;
  13508. }
  13509. return 0;
  13510. }
  13511. /**
  13512. * Rune Knight
  13513. **/
  13514. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13515. #if PACKETVER >= 20081217
  13516. unsigned char buf[10];
  13517. WBUFW(buf,0) = 0x440;
  13518. WBUFL(buf,2) = sd->bl.id;
  13519. WBUFW(buf,6) = shields;
  13520. WBUFW(buf,8) = 0;
  13521. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13522. #endif
  13523. }
  13524. /**
  13525. * Warlock
  13526. **/
  13527. /*==========================================
  13528. * Spellbook list [LimitLine/3CeAM]
  13529. *------------------------------------------*/
  13530. int clif_spellbook_list(struct map_session_data *sd)
  13531. {
  13532. int i, c;
  13533. int fd;
  13534. nullpo_ret(sd);
  13535. fd = sd->fd;
  13536. WFIFOHEAD(fd, 8 * 8 + 8);
  13537. WFIFOW(fd,0) = 0x1ad;
  13538. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13539. {
  13540. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13541. {
  13542. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13543. c ++;
  13544. }
  13545. }
  13546. if( c > 0 )
  13547. {
  13548. WFIFOW(fd,2) = c * 2 + 4;
  13549. WFIFOSET(fd, WFIFOW(fd, 2));
  13550. sd->menuskill_id = WL_READING_SB;
  13551. sd->menuskill_val = c;
  13552. }
  13553. else{
  13554. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13555. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  13556. }
  13557. return 1;
  13558. }
  13559. /**
  13560. * Mechanic
  13561. **/
  13562. /*==========================================
  13563. * Magic Decoy Material List
  13564. *------------------------------------------*/
  13565. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  13566. int i, c;
  13567. int fd;
  13568. nullpo_ret(sd);
  13569. fd = sd->fd;
  13570. WFIFOHEAD(fd, 8 * 8 + 8);
  13571. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13572. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13573. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13574. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13575. c ++;
  13576. }
  13577. }
  13578. if( c > 0 ) {
  13579. sd->menuskill_id = NC_MAGICDECOY;
  13580. sd->menuskill_val = skill_lv;
  13581. sd->sc.comet_x = x;
  13582. sd->sc.comet_y = y;
  13583. WFIFOW(fd,2) = c * 2 + 4;
  13584. WFIFOSET(fd, WFIFOW(fd, 2));
  13585. } else {
  13586. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13587. return 0;
  13588. }
  13589. return 1;
  13590. }
  13591. /**
  13592. * Guilotine Cross
  13593. **/
  13594. /*==========================================
  13595. * Guillotine Cross Poisons List
  13596. *------------------------------------------*/
  13597. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  13598. int i, c;
  13599. int fd;
  13600. nullpo_ret(sd);
  13601. fd = sd->fd;
  13602. WFIFOHEAD(fd, 8 * 8 + 8);
  13603. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13604. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13605. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13606. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13607. c ++;
  13608. }
  13609. }
  13610. if( c > 0 ) {
  13611. sd->menuskill_id = GC_POISONINGWEAPON;
  13612. sd->menuskill_val = skill_lv;
  13613. WFIFOW(fd,2) = c * 2 + 4;
  13614. WFIFOSET(fd, WFIFOW(fd, 2));
  13615. } else {
  13616. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13617. return 0;
  13618. }
  13619. return 1;
  13620. }
  13621. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13622. int fd, i, c;
  13623. nullpo_ret(sd);
  13624. fd = sd->fd;
  13625. if( !fd ) return 0;
  13626. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13627. return 0;
  13628. WFIFOHEAD(fd, 2 * 6 + 4);
  13629. WFIFOW(fd,0) = 0x442;
  13630. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13631. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13632. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13633. { // Can't auto cast both Extended class and 3rd class skills.
  13634. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13635. c++;
  13636. }
  13637. if( c > 0 ) {
  13638. WFIFOW(fd,2) = 8 + c * 2;
  13639. WFIFOL(fd,4) = c;
  13640. WFIFOSET(fd,WFIFOW(fd,2));
  13641. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13642. sd->menuskill_val = c;
  13643. } else {
  13644. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13645. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13646. }
  13647. return 1;
  13648. }
  13649. /*===========================================
  13650. * Skill list for Four Elemental Analysis
  13651. * and Change Material skills.
  13652. *------------------------------------------*/
  13653. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  13654. {
  13655. #if PACKETVER >= 20090922
  13656. int fd;
  13657. nullpo_ret(sd);
  13658. sd->menuskill_id = skill_id; // To prevent hacking.
  13659. sd->menuskill_val = skill_lv;
  13660. if( skill_id == GN_CHANGEMATERIAL )
  13661. skill_lv = 0; // Changematerial
  13662. fd = sd->fd;
  13663. WFIFOHEAD(fd,packet_len(0x7e3));
  13664. WFIFOW(fd,0) = 0x7e3;
  13665. WFIFOL(fd,2) = skill_lv;
  13666. WFIFOL(fd,4) = 0;
  13667. WFIFOSET(fd,packet_len(0x7e3));
  13668. #endif
  13669. return 1;
  13670. }
  13671. /**
  13672. * Sends a new status without a tick (currently used by the new mounts)
  13673. **/
  13674. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13675. unsigned char buf[32];
  13676. nullpo_ret(bl);
  13677. WBUFW(buf,0)=0x043f;
  13678. WBUFW(buf,2)=type;
  13679. WBUFL(buf,4)=bl->id;
  13680. WBUFB(buf,8)=flag;
  13681. WBUFL(buf,9) = 0;
  13682. WBUFL(buf,13) = val1;
  13683. WBUFL(buf,17) = val2;
  13684. WBUFL(buf,21) = val3;
  13685. clif_send(buf,packet_len(0x043f),bl,AREA);
  13686. return 0;
  13687. }
  13688. //Notifies FD of ID's type
  13689. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13690. WFIFOHEAD(fd, packet_len(0x043f));
  13691. WFIFOW(fd,0)=0x043f;
  13692. WFIFOW(fd,2)=type;
  13693. WFIFOL(fd,4)=id;
  13694. WFIFOB(fd,8)=flag;
  13695. WFIFOL(fd,9) = 0;
  13696. WFIFOL(fd,13) = val1;
  13697. WFIFOL(fd,17) = val2;
  13698. WFIFOL(fd,21) = val3;
  13699. WFIFOSET(fd, packet_len(0x043f));
  13700. return 0;
  13701. }
  13702. // msgstringtable.txt
  13703. // 0x291 <line>.W
  13704. void clif_msgtable(int fd, int line) {
  13705. WFIFOHEAD(fd, packet_len(0x291));
  13706. WFIFOW(fd, 0) = 0x291;
  13707. WFIFOW(fd, 2) = line;
  13708. WFIFOSET(fd, packet_len(0x291));
  13709. }
  13710. // msgstringtable.txt
  13711. // 0x7e2 <line>.W <value>.L
  13712. void clif_msgtable_num(int fd, int line, int num) {
  13713. #if PACKETVER >= 20090805
  13714. WFIFOHEAD(fd, packet_len(0x7e2));
  13715. WFIFOW(fd, 0) = 0x7e2;
  13716. WFIFOW(fd, 2) = line;
  13717. WFIFOL(fd, 4) = num;
  13718. WFIFOSET(fd, packet_len(0x7e2));
  13719. #endif
  13720. }
  13721. /*==========================================
  13722. * used by SC_AUTOSHADOWSPELL
  13723. * RFIFOL(fd,2) - flag (currently not used)
  13724. *------------------------------------------*/
  13725. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13726. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13727. return;
  13728. if( pc_istrading(sd) ) {
  13729. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  13730. clif_menuskill_clear(sd);
  13731. return;
  13732. }
  13733. skill_select_menu(sd,RFIFOW(fd,6));
  13734. clif_menuskill_clear(sd);
  13735. }
  13736. /*==========================================
  13737. * Kagerou/Oboro amulet spirit
  13738. *------------------------------------------*/
  13739. void clif_talisman(struct map_session_data *sd,short type)
  13740. {
  13741. unsigned char buf[10];
  13742. nullpo_retv(sd);
  13743. WBUFW(buf,0)=0x08cf;
  13744. WBUFL(buf,2)=sd->bl.id;
  13745. WBUFW(buf,6)=type;
  13746. WBUFW(buf,8)=sd->talisman[type];
  13747. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  13748. }
  13749. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  13750. /// 0907 <index>.W
  13751. ///
  13752. /// R 0908 <index>.w <type>.b
  13753. /// type:
  13754. /// 0 = move item to personal tab
  13755. /// 1 = move item to normal tab
  13756. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  13757. #if PACKETVER >= 20111122
  13758. int index;
  13759. /* can't move while dead. */
  13760. if(pc_isdead(sd)) {
  13761. return;
  13762. }
  13763. index = RFIFOW(fd,2)-2;
  13764. if (index < 0 || index >= MAX_INVENTORY)
  13765. return;
  13766. if ( sd->status.inventory[index].favorite && RFIFOB(fd, 4) == 1 )
  13767. sd->status.inventory[index].favorite = 0;
  13768. else if( RFIFOB(fd, 4) == 0 )
  13769. sd->status.inventory[index].favorite = 1;
  13770. else
  13771. return;/* nothing to do. */
  13772. clif_favorite_item(sd, index);
  13773. #endif
  13774. }
  13775. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  13776. /// 0900 <index>.W <favorite>.B
  13777. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  13778. int fd = sd->fd;
  13779. WFIFOHEAD(fd,packet_len(0x908));
  13780. WFIFOW(fd,0) = 0x908;
  13781. WFIFOW(fd,2) = index+2;
  13782. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  13783. WFIFOSET(fd,packet_len(0x908));
  13784. }
  13785. void clif_snap( struct block_list *bl, short x, short y ) {
  13786. unsigned char buf[10];
  13787. WBUFW(buf,0) = 0x8d2;
  13788. WBUFL(buf,2) = bl->id;
  13789. WBUFW(buf,6) = x;
  13790. WBUFW(buf,8) = y;
  13791. clif_send(buf,packet_len(0x8d2),bl,AREA);
  13792. }
  13793. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  13794. #if PACKETVER >= 20120404
  13795. WFIFOHEAD(fd,packet_len(0x977));
  13796. WFIFOW(fd,0) = 0x977;
  13797. WFIFOL(fd,2) = md->bl.id;
  13798. WFIFOL(fd,6) = md->status.hp;
  13799. WFIFOL(fd,10) = md->status.max_hp;
  13800. WFIFOSET(fd,packet_len(0x977));
  13801. #endif
  13802. }
  13803. /*==========================================
  13804. * Main client packet processing function
  13805. *------------------------------------------*/
  13806. static int clif_parse(int fd)
  13807. {
  13808. int cmd, packet_ver, packet_len, err;
  13809. TBL_PC* sd;
  13810. int pnum;
  13811. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13812. // Note: "click masters" can do 80+ clicks in 10 seconds
  13813. 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]
  13814. { // begin main client packet processing loop
  13815. sd = (TBL_PC *)session[fd]->session_data;
  13816. if (session[fd]->flag.eof) {
  13817. if (sd) {
  13818. if (sd->state.autotrade) {
  13819. //Disassociate character from the socket connection.
  13820. session[fd]->session_data = NULL;
  13821. sd->fd = 0;
  13822. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13823. } else
  13824. if (sd->state.active) {
  13825. // Player logout display [Valaris]
  13826. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13827. clif_quitsave(fd, sd);
  13828. } else {
  13829. //Unusual logout (during log on/off/map-changer procedure)
  13830. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13831. map_quit(sd);
  13832. }
  13833. } else {
  13834. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13835. }
  13836. do_close(fd);
  13837. return 0;
  13838. }
  13839. if (RFIFOREST(fd) < 2)
  13840. return 0;
  13841. cmd = RFIFOW(fd,0);
  13842. // identify client's packet version
  13843. if (sd) {
  13844. packet_ver = sd->packet_ver;
  13845. } else {
  13846. // check authentification packet to know packet version
  13847. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13848. if( err ) {// failed to identify packet version
  13849. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  13850. err == 1 ? "" :
  13851. err == 2 ? ", possibly for having an invalid account_id" :
  13852. err == 3 ? ", possibly for having an invalid char_id." :
  13853. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13854. err == 4 ? ", possibly for having an invalid login_id1." :
  13855. err == 5 ? ", possibly for having an invalid client_tick." :
  13856. */
  13857. err == 6 ? ", possibly for having an invalid sex." :
  13858. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  13859. WFIFOHEAD(fd,packet_len(0x6a));
  13860. WFIFOW(fd,0) = 0x6a;
  13861. WFIFOB(fd,2) = 3; // Rejected from Server
  13862. WFIFOSET(fd,packet_len(0x6a));
  13863. #ifdef DUMP_INVALID_PACKET
  13864. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13865. #endif
  13866. RFIFOSKIP(fd, RFIFOREST(fd));
  13867. set_eof(fd);
  13868. return 0;
  13869. }
  13870. }
  13871. // filter out invalid / unsupported packets
  13872. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13873. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13874. #ifdef DUMP_INVALID_PACKET
  13875. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13876. #endif
  13877. set_eof(fd);
  13878. return 0;
  13879. }
  13880. // determine real packet length
  13881. packet_len = packet_db[packet_ver][cmd].len;
  13882. if (packet_len == -1) { // variable-length packet
  13883. if (RFIFOREST(fd) < 4)
  13884. return 0;
  13885. packet_len = RFIFOW(fd,2);
  13886. if (packet_len < 4 || packet_len > 32768) {
  13887. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13888. #ifdef DUMP_INVALID_PACKET
  13889. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13890. #endif
  13891. set_eof(fd);
  13892. return 0;
  13893. }
  13894. }
  13895. if ((int)RFIFOREST(fd) < packet_len)
  13896. return 0; // not enough data received to form the packet
  13897. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13898. packet_db[packet_ver][cmd].func(fd, sd);
  13899. else if( packet_db[packet_ver][cmd].func != NULL ) {
  13900. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13901. ; //Only valid packet when there is no session
  13902. else
  13903. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13904. ; //Only valid packet when player is not on a map
  13905. else
  13906. if( sd && session[sd->fd]->flag.eof )
  13907. ; //No more packets accepted
  13908. else
  13909. packet_db[packet_ver][cmd].func(fd, sd);
  13910. }
  13911. #ifdef DUMP_UNKNOWN_PACKET
  13912. else {
  13913. const char* packet_txt = "save/packet.txt";
  13914. FILE* fp;
  13915. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  13916. if( sd ) {
  13917. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  13918. } else {
  13919. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13920. }
  13921. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13922. fprintf(fp, "\n");
  13923. fclose(fp);
  13924. } else {
  13925. ShowError("Failed to write '%s'.\n", packet_txt);
  13926. // Dump on console instead
  13927. if( sd ) {
  13928. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  13929. } else {
  13930. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13931. }
  13932. ShowDump(RFIFOP(fd,0), packet_len);
  13933. }
  13934. }
  13935. #endif
  13936. RFIFOSKIP(fd, packet_len);
  13937. }; // main loop end
  13938. return 0;
  13939. }
  13940. /*==========================================
  13941. * Reads packet_db.txt and setups its array reference
  13942. *------------------------------------------*/
  13943. static int packetdb_readdb(void)
  13944. {
  13945. FILE *fp;
  13946. char line[1024];
  13947. int ln=0;
  13948. int cmd,i,j,packet_ver;
  13949. int max_cmd=-1;
  13950. int skip_ver = 0;
  13951. int warned = 0;
  13952. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13953. int packet_len_table[MAX_PACKET_DB] = {
  13954. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13958. //#0x0040
  13959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13961. #if PACKETVER <= 20081217
  13962. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13963. #else
  13964. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13965. #endif
  13966. #if PACKETVER < 2
  13967. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13968. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  13969. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13970. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13971. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13972. #else
  13973. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13974. #endif
  13975. //#0x0080
  13976. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13977. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13978. #if PACKETVER <= 20100622
  13979. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13980. #else
  13981. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13982. #endif
  13983. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13984. //#0x00C0
  13985. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13986. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13987. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13988. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13989. //#0x0100
  13990. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13991. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13992. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13993. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13994. //#0x0140
  13995. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13996. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13997. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13998. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13999. //#0x0180
  14000. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14001. #if PACKETVER < 1
  14002. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14003. #else // 196 comodo icon status display for later
  14004. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14005. #endif
  14006. #if PACKETVER < 20081126
  14007. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14008. #else // 0x1a2 changed (35->37)
  14009. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14010. #endif
  14011. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14012. //#0x01C0, Set 0x1d5=-1
  14013. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14014. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14015. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14016. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14017. //#0x0200
  14018. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14019. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14020. #if PACKETVER < 20071106
  14021. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14022. #else // 0x22c changed
  14023. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14024. #endif
  14025. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14026. //#0x0240
  14027. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14028. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14029. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14030. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14031. //#0x0280
  14032. #if PACKETVER < 20070711
  14033. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14034. #else
  14035. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14036. #endif
  14037. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14038. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14039. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14040. //#0x02C0
  14041. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14042. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14043. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14044. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14045. //#0x0300
  14046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14050. //#0x0340
  14051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14055. //#0x0380
  14056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14060. //#0x03C0
  14061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14065. //#0x0400
  14066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14070. //#0x0440
  14071. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14075. //#0x0480
  14076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14080. //#0x04C0
  14081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14085. //#0x0500
  14086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14090. //#0x0540
  14091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14095. //#0x0580
  14096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14100. //#0x05C0
  14101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14105. //#0x0600
  14106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14110. //#0x0640
  14111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14115. //#0x0680
  14116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14120. //#0x06C0
  14121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14125. //#0x0700
  14126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14130. //#0x0740
  14131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14135. //#0x0780
  14136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14140. //#0x07C0
  14141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14142. #if PACKETVER < 20090617
  14143. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  14144. #else // 0x7d9 changed
  14145. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  14146. #endif
  14147. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  14148. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  14149. //#0x0800
  14150. #if PACKETVER < 20091229
  14151. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  14152. #else // for Party booking ( PACKETVER >= 20091229 )
  14153. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  14154. #endif
  14155. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  14156. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14157. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  14158. //#0x0840
  14159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14160. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  14161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14163. //#0x0880
  14164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14168. //#0x08C0
  14169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  14170. 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14173. //#0x0900
  14174. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14178. //#0x0940
  14179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14182. 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0,
  14183. };
  14184. struct {
  14185. void (*func)(int, struct map_session_data *);
  14186. char *name;
  14187. } clif_parse_func[]={
  14188. {clif_parse_WantToConnection,"wanttoconnection"},
  14189. {clif_parse_LoadEndAck,"loadendack"},
  14190. {clif_parse_TickSend,"ticksend"},
  14191. {clif_parse_WalkToXY,"walktoxy"},
  14192. {clif_parse_QuitGame,"quitgame"},
  14193. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14194. {clif_parse_GlobalMessage,"globalmessage"},
  14195. {clif_parse_MapMove,"mapmove"},
  14196. {clif_parse_ChangeDir,"changedir"},
  14197. {clif_parse_Emotion,"emotion"},
  14198. {clif_parse_HowManyConnections,"howmanyconnections"},
  14199. {clif_parse_ActionRequest,"actionrequest"},
  14200. {clif_parse_Restart,"restart"},
  14201. {clif_parse_WisMessage,"wis"},
  14202. {clif_parse_Broadcast,"broadcast"},
  14203. {clif_parse_TakeItem,"takeitem"},
  14204. {clif_parse_DropItem,"dropitem"},
  14205. {clif_parse_UseItem,"useitem"},
  14206. {clif_parse_EquipItem,"equipitem"},
  14207. {clif_parse_UnequipItem,"unequipitem"},
  14208. {clif_parse_NpcClicked,"npcclicked"},
  14209. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14210. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14211. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14212. {clif_parse_CreateChatRoom,"createchatroom"},
  14213. {clif_parse_ChatAddMember,"chataddmember"},
  14214. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14215. {clif_parse_ChangeChatOwner,"changechatowner"},
  14216. {clif_parse_KickFromChat,"kickfromchat"},
  14217. {clif_parse_ChatLeave,"chatleave"},
  14218. {clif_parse_TradeRequest,"traderequest"},
  14219. {clif_parse_TradeAck,"tradeack"},
  14220. {clif_parse_TradeAddItem,"tradeadditem"},
  14221. {clif_parse_TradeOk,"tradeok"},
  14222. {clif_parse_TradeCancel,"tradecancel"},
  14223. {clif_parse_TradeCommit,"tradecommit"},
  14224. {clif_parse_StopAttack,"stopattack"},
  14225. {clif_parse_PutItemToCart,"putitemtocart"},
  14226. {clif_parse_GetItemFromCart,"getitemfromcart"},
  14227. {clif_parse_RemoveOption,"removeoption"},
  14228. {clif_parse_ChangeCart,"changecart"},
  14229. {clif_parse_StatusUp,"statusup"},
  14230. {clif_parse_SkillUp,"skillup"},
  14231. {clif_parse_UseSkillToId,"useskilltoid"},
  14232. {clif_parse_UseSkillToPos,"useskilltopos"},
  14233. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  14234. {clif_parse_UseSkillMap,"useskillmap"},
  14235. {clif_parse_RequestMemo,"requestmemo"},
  14236. {clif_parse_ProduceMix,"producemix"},
  14237. {clif_parse_Cooking,"cooking"},
  14238. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  14239. {clif_parse_NpcNextClicked,"npcnextclicked"},
  14240. {clif_parse_NpcAmountInput,"npcamountinput"},
  14241. {clif_parse_NpcStringInput,"npcstringinput"},
  14242. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  14243. {clif_parse_ItemIdentify,"itemidentify"},
  14244. {clif_parse_SelectArrow,"selectarrow"},
  14245. {clif_parse_AutoSpell,"autospell"},
  14246. {clif_parse_UseCard,"usecard"},
  14247. {clif_parse_InsertCard,"insertcard"},
  14248. {clif_parse_RepairItem,"repairitem"},
  14249. {clif_parse_WeaponRefine,"weaponrefine"},
  14250. {clif_parse_SolveCharName,"solvecharname"},
  14251. {clif_parse_ResetChar,"resetchar"},
  14252. {clif_parse_LocalBroadcast,"localbroadcast"},
  14253. {clif_parse_MoveToKafra,"movetokafra"},
  14254. {clif_parse_MoveFromKafra,"movefromkafra"},
  14255. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  14256. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  14257. {clif_parse_CloseKafra,"closekafra"},
  14258. {clif_parse_CreateParty,"createparty"},
  14259. {clif_parse_CreateParty2,"createparty2"},
  14260. {clif_parse_PartyInvite,"partyinvite"},
  14261. {clif_parse_PartyInvite2,"partyinvite2"},
  14262. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  14263. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  14264. {clif_parse_LeaveParty,"leaveparty"},
  14265. {clif_parse_RemovePartyMember,"removepartymember"},
  14266. {clif_parse_PartyChangeOption,"partychangeoption"},
  14267. {clif_parse_PartyMessage,"partymessage"},
  14268. {clif_parse_PartyChangeLeader,"partychangeleader"},
  14269. {clif_parse_CloseVending,"closevending"},
  14270. {clif_parse_VendingListReq,"vendinglistreq"},
  14271. {clif_parse_PurchaseReq,"purchasereq"},
  14272. {clif_parse_PurchaseReq2,"purchasereq2"},
  14273. {clif_parse_OpenVending,"openvending"},
  14274. {clif_parse_CreateGuild,"createguild"},
  14275. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  14276. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  14277. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  14278. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  14279. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  14280. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  14281. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  14282. {clif_parse_GuildInvite,"guildinvite"},
  14283. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  14284. {clif_parse_GuildLeave,"guildleave"},
  14285. {clif_parse_GuildExpulsion,"guildexpulsion"},
  14286. {clif_parse_GuildMessage,"guildmessage"},
  14287. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  14288. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  14289. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  14290. {clif_parse_GuildOpposition,"guildopposition"},
  14291. {clif_parse_GuildBreak,"guildbreak"},
  14292. {clif_parse_PetMenu,"petmenu"},
  14293. {clif_parse_CatchPet,"catchpet"},
  14294. {clif_parse_SelectEgg,"selectegg"},
  14295. {clif_parse_SendEmotion,"sendemotion"},
  14296. {clif_parse_ChangePetName,"changepetname"},
  14297. {clif_parse_GMKick,"gmkick"},
  14298. {clif_parse_GMHide,"gmhide"},
  14299. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14300. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14301. {clif_parse_GMKickAll,"killall"},
  14302. {clif_parse_GMRecall,"recall"},
  14303. {clif_parse_GMRecall,"summon"},
  14304. {clif_parse_GM_Monster_Item,"itemmonster"},
  14305. {clif_parse_GMShift,"remove"},
  14306. {clif_parse_GMShift,"shift"},
  14307. {clif_parse_GMChangeMapType,"changemaptype"},
  14308. {clif_parse_GMRc,"rc"},
  14309. {clif_parse_GMRecall2,"recall2"},
  14310. {clif_parse_GMRemove2,"remove2"},
  14311. {clif_parse_NoviceDoriDori,"sndoridori"},
  14312. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14313. {clif_parse_PMIgnore,"wisexin"},
  14314. {clif_parse_PMIgnoreList,"wisexlist"},
  14315. {clif_parse_PMIgnoreAll,"wisall"},
  14316. {clif_parse_FriendsListAdd,"friendslistadd"},
  14317. {clif_parse_FriendsListRemove,"friendslistremove"},
  14318. {clif_parse_FriendsListReply,"friendslistreply"},
  14319. {clif_parse_Blacksmith,"blacksmith"},
  14320. {clif_parse_Alchemist,"alchemist"},
  14321. {clif_parse_Taekwon,"taekwon"},
  14322. {clif_parse_RankingPk,"rankingpk"},
  14323. {clif_parse_FeelSaveOk,"feelsaveok"},
  14324. {clif_parse_debug,"debug"},
  14325. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14326. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14327. {clif_parse_HomMoveTo,"hommoveto"},
  14328. {clif_parse_HomAttack,"homattack"},
  14329. {clif_parse_HomMenu,"hommenu"},
  14330. {clif_parse_StoragePassword,"storagepassword"},
  14331. {clif_parse_Hotkey,"hotkey"},
  14332. {clif_parse_AutoRevive,"autorevive"},
  14333. {clif_parse_Check,"check"},
  14334. {clif_parse_Adopt_request,"adoptrequest"},
  14335. {clif_parse_Adopt_reply,"adoptreply"},
  14336. // MAIL SYSTEM
  14337. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14338. {clif_parse_Mail_read,"mailread"},
  14339. {clif_parse_Mail_getattach,"mailgetattach"},
  14340. {clif_parse_Mail_delete,"maildelete"},
  14341. {clif_parse_Mail_return,"mailreturn"},
  14342. {clif_parse_Mail_setattach,"mailsetattach"},
  14343. {clif_parse_Mail_winopen,"mailwinopen"},
  14344. {clif_parse_Mail_send,"mailsend"},
  14345. // AUCTION SYSTEM
  14346. {clif_parse_Auction_search,"auctionsearch"},
  14347. {clif_parse_Auction_buysell,"auctionbuysell"},
  14348. {clif_parse_Auction_setitem,"auctionsetitem"},
  14349. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14350. {clif_parse_Auction_register,"auctionregister"},
  14351. {clif_parse_Auction_cancel,"auctioncancel"},
  14352. {clif_parse_Auction_close,"auctionclose"},
  14353. {clif_parse_Auction_bid,"auctionbid"},
  14354. // Quest Log System
  14355. {clif_parse_questStateAck,"queststate"},
  14356. {clif_parse_cashshop_buy,"cashshopbuy"},
  14357. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14358. {clif_parse_EquipTick,"equiptickbox"},
  14359. {clif_parse_BattleChat,"battlechat"},
  14360. {clif_parse_mercenary_action,"mermenu"},
  14361. {clif_parse_progressbar,"progressbar"},
  14362. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14363. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14364. #if PACKETVER >= 20091229
  14365. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14366. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14367. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14368. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14369. #endif
  14370. {clif_parse_PVPInfo,"pvpinfo"},
  14371. {clif_parse_LessEffect,"lesseffect"},
  14372. // Buying Store
  14373. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14374. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14375. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14376. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14377. // Store Search
  14378. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14379. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14380. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14381. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14382. /* */
  14383. { clif_parse_MoveItem , "moveitem" },
  14384. {NULL,NULL}
  14385. };
  14386. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14387. memset(packet_db,0,sizeof(packet_db));
  14388. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14389. packet_len(i) = packet_len_table[i];
  14390. sprintf(line, "%s/packet_db.txt", db_path);
  14391. if( (fp=fopen(line,"r"))==NULL ){
  14392. ShowFatalError("can't read %s\n", line);
  14393. exit(EXIT_FAILURE);
  14394. }
  14395. clif_config.packet_db_ver = MAX_PACKET_VER;
  14396. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14397. while( fgets(line, sizeof(line), fp) )
  14398. {
  14399. ln++;
  14400. if(line[0]=='/' && line[1]=='/')
  14401. continue;
  14402. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14403. {
  14404. if(strcmpi(w1,"packet_ver")==0) {
  14405. int prev_ver = packet_ver;
  14406. skip_ver = 0;
  14407. packet_ver = atoi(w2);
  14408. if ( packet_ver > MAX_PACKET_VER )
  14409. { //Check to avoid overflowing. [Skotlex]
  14410. if( (warned&1) == 0 )
  14411. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14412. warned &= 1;
  14413. skip_ver = 1;
  14414. }
  14415. else if( packet_ver < 0 )
  14416. {
  14417. if( (warned&2) == 0 )
  14418. ShowWarning("Negative packet versions are not supported.\n");
  14419. warned &= 2;
  14420. skip_ver = 1;
  14421. }
  14422. else if( packet_ver == SERVER )
  14423. {
  14424. if( (warned&4) == 0 )
  14425. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14426. warned &= 4;
  14427. skip_ver = 1;
  14428. }
  14429. if( skip_ver )
  14430. {
  14431. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14432. packet_ver = prev_ver;
  14433. continue;
  14434. }
  14435. // copy from previous version into new version and continue
  14436. // - indicating all following packets should be read into the newer version
  14437. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14438. continue;
  14439. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14440. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14441. clif_config.packet_db_ver = MAX_PACKET_VER;
  14442. else // to manually set the packet DB version
  14443. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14444. continue;
  14445. }
  14446. }
  14447. if( skip_ver != 0 )
  14448. continue; // Skipping current packet version
  14449. memset(str,0,sizeof(str));
  14450. for(j=0,p=line;j<4 && p; ++j)
  14451. {
  14452. str[j]=p;
  14453. p=strchr(p,',');
  14454. if(p) *p++=0;
  14455. }
  14456. if(str[0]==NULL)
  14457. continue;
  14458. cmd=strtol(str[0],(char **)NULL,0);
  14459. if(max_cmd < cmd)
  14460. max_cmd = cmd;
  14461. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14462. continue;
  14463. if(str[1]==NULL){
  14464. ShowError("packet_db: packet len error\n");
  14465. continue;
  14466. }
  14467. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14468. if(str[2]==NULL){
  14469. packet_db[packet_ver][cmd].func = NULL;
  14470. ln++;
  14471. continue;
  14472. }
  14473. // look up processing function by name
  14474. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14475. if( j < ARRAYLENGTH(clif_parse_func) )
  14476. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14477. // set the identifying cmd for the packet_db version
  14478. if (strcmp(str[2],"wanttoconnection")==0)
  14479. clif_config.connect_cmd[packet_ver] = cmd;
  14480. if(str[3]==NULL){
  14481. ShowError("packet_db: packet error\n");
  14482. exit(EXIT_FAILURE);
  14483. }
  14484. for(j=0,p2=str[3];p2;j++){
  14485. short k;
  14486. str2[j]=p2;
  14487. p2=strchr(p2,':');
  14488. if(p2) *p2++=0;
  14489. k = atoi(str2[j]);
  14490. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14491. if( j >= MAX_PACKET_POS )
  14492. {
  14493. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14494. break;
  14495. }
  14496. packet_db[packet_ver][cmd].pos[j] = k;
  14497. }
  14498. }
  14499. fclose(fp);
  14500. if(max_cmd > MAX_PACKET_DB)
  14501. {
  14502. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14503. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14504. }
  14505. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14506. { //Locate the nearest version that we still support. [Skotlex]
  14507. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14508. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14509. }
  14510. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'. Using default packet version: "CL_WHITE"%d"CL_RESET".\n", "packet_db.txt", clif_config.packet_db_ver);
  14511. return 0;
  14512. }
  14513. /*==========================================
  14514. *
  14515. *------------------------------------------*/
  14516. int do_init_clif(void) {
  14517. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14518. int i;
  14519. /**
  14520. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14521. **/
  14522. for(i = 0; i < COLOR_MAX; i++) {
  14523. color_table[i] = strtoul(colors[i],NULL,0);
  14524. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14525. }
  14526. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14527. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14528. memset(packet_db,0,sizeof(packet_db));
  14529. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14530. packetdb_readdb();
  14531. set_defaultparse(clif_parse);
  14532. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14533. ShowFatalError("can't bind game port\n");
  14534. exit(EXIT_FAILURE);
  14535. }
  14536. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14537. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14538. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  14539. return 0;
  14540. }
  14541. void do_final_clif(void) {
  14542. ers_destroy(delay_clearunit_ers);
  14543. }