clif.c 459 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760
  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 "map.h"
  14. #include "chrif.h"
  15. #include "pc.h"
  16. #include "status.h"
  17. #include "npc.h"
  18. #include "itemdb.h"
  19. #include "chat.h"
  20. #include "trade.h"
  21. #include "storage.h"
  22. #include "script.h"
  23. #include "skill.h"
  24. #include "atcommand.h"
  25. #include "intif.h"
  26. #include "battle.h"
  27. #include "battleground.h"
  28. #include "mob.h"
  29. #include "party.h"
  30. #include "unit.h"
  31. #include "guild.h"
  32. #include "vending.h"
  33. #include "pet.h"
  34. #include "homunculus.h"
  35. #include "instance.h"
  36. #include "mercenary.h"
  37. #include "elemental.h"
  38. #include "log.h"
  39. #include "clif.h"
  40. #include "mail.h"
  41. #include "quest.h"
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <stdarg.h>
  46. #include <time.h>
  47. //#define DUMP_UNKNOWN_PACKET
  48. //#define DUMP_INVALID_PACKET
  49. struct Clif_Config {
  50. int packet_db_ver; //Preferred packet version.
  51. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  52. } clif_config;
  53. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  54. //Converts item type in case of pet eggs.
  55. static inline int itemtype(int type)
  56. {
  57. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  58. }
  59. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
  60. {
  61. p += pos;
  62. p[0] = (uint8)(x>>2);
  63. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  64. p[2] = (uint8)((y<<4) | (dir&0xf));
  65. }
  66. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  67. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  68. {
  69. p += pos;
  70. p[0] = (uint8)(x0>>2);
  71. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  72. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  73. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  74. p[4] = (uint8)y1;
  75. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  76. }
  77. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir)
  78. {
  79. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  80. }
  81. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  82. {
  83. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  84. }
  85. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir)
  86. {
  87. p += pos;
  88. if( x )
  89. {
  90. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  91. }
  92. if( y )
  93. {
  94. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  95. }
  96. if( dir )
  97. {
  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. {
  106. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  107. }
  108. if( y0 )
  109. {
  110. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  111. }
  112. if( x1 )
  113. {
  114. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  115. }
  116. if( y1 )
  117. {
  118. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  119. }
  120. if( sx0 )
  121. {
  122. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  123. }
  124. if( sy0 )
  125. {
  126. sy0[0] = ( p[5] & 0x0f ) >> 0;
  127. }
  128. }
  129. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir)
  130. {
  131. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  132. }
  133. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  134. {
  135. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  136. }
  137. //To idenfity disguised characters.
  138. static inline bool disguised(struct block_list* bl)
  139. {
  140. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  141. }
  142. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  143. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max)
  144. {
  145. if( len > max )
  146. len = max;
  147. mes[len-1] = '\0';
  148. return len;
  149. }
  150. static char map_ip_str[128];
  151. static uint32 map_ip;
  152. static uint32 bind_ip = INADDR_ANY;
  153. static uint16 map_port = 5121;
  154. int map_fd;
  155. static int clif_parse (int fd);
  156. /*==========================================
  157. * map鯖のip設定
  158. *------------------------------------------*/
  159. int clif_setip(const char* ip)
  160. {
  161. char ip_str[16];
  162. map_ip = host2ip(ip);
  163. if (!map_ip) {
  164. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  165. return 0;
  166. }
  167. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  168. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  169. return 1;
  170. }
  171. void clif_setbindip(const char* ip)
  172. {
  173. char ip_str[16];
  174. bind_ip = host2ip(ip);
  175. if (bind_ip) {
  176. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  177. } else {
  178. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  179. }
  180. }
  181. /*==========================================
  182. * Sets map port to 'port'
  183. * is run from map.c upon loading map server configuration
  184. *------------------------------------------*/
  185. void clif_setport(uint16 port)
  186. {
  187. map_port = port;
  188. }
  189. /*==========================================
  190. * Returns map server IP
  191. *------------------------------------------*/
  192. uint32 clif_getip(void)
  193. {
  194. return map_ip;
  195. }
  196. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  197. uint32 clif_refresh_ip(void)
  198. {
  199. uint32 new_ip;
  200. new_ip = host2ip(map_ip_str);
  201. if (new_ip && new_ip != map_ip) {
  202. map_ip = new_ip;
  203. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  204. return map_ip;
  205. }
  206. return 0;
  207. }
  208. /*==========================================
  209. * Returns map port which is set by clif_setport()
  210. *------------------------------------------*/
  211. uint16 clif_getport(void)
  212. {
  213. return map_port;
  214. }
  215. #if PACKETVER >= 20071106
  216. static inline unsigned char clif_bl_type(struct block_list *bl) {
  217. switch (bl->type) {
  218. case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
  219. case BL_ITEM: return 0x2; //ITEM_TYPE
  220. case BL_SKILL: return 0x3; //SKILL_TYPE
  221. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  222. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  223. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  224. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  225. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  226. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  227. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  228. default: return 0x1; //NPC_TYPE
  229. }
  230. }
  231. #endif
  232. /*==========================================
  233. * sub process of clif_send
  234. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  235. * In order to send area-wise packets, such as:
  236. * - AREA : everyone nearby your area
  237. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  238. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  239. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  240. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  241. *------------------------------------------*/
  242. static int clif_send_sub(struct block_list *bl, va_list ap)
  243. {
  244. struct block_list *src_bl;
  245. struct map_session_data *sd;
  246. unsigned char *buf;
  247. int len, type, fd;
  248. nullpo_ret(bl);
  249. nullpo_ret(sd = (struct map_session_data *)bl);
  250. fd = sd->fd;
  251. if (!fd) //Don't send to disconnected clients.
  252. return 0;
  253. buf = va_arg(ap,unsigned char*);
  254. len = va_arg(ap,int);
  255. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  256. type = va_arg(ap,int);
  257. switch(type)
  258. {
  259. case AREA_WOS:
  260. if (bl == src_bl)
  261. return 0;
  262. break;
  263. case AREA_WOC:
  264. if (sd->chatID || bl == src_bl)
  265. return 0;
  266. break;
  267. case AREA_WOSC:
  268. {
  269. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  270. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  271. return 0;
  272. }
  273. break;
  274. }
  275. if (session[fd] == NULL)
  276. return 0;
  277. WFIFOHEAD(fd, len);
  278. if (WFIFOP(fd,0) == buf) {
  279. ShowError("WARNING: Invalid use of clif_send function\n");
  280. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  281. ShowError(" Please correct your code.\n");
  282. // don't send to not move the pointer of the packet for next sessions in the loop
  283. //WFIFOSET(fd,0);//## TODO is this ok?
  284. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  285. return 0;
  286. }
  287. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  288. memcpy(WFIFOP(fd,0), buf, len);
  289. WFIFOSET(fd,len);
  290. }
  291. return 0;
  292. }
  293. /*==========================================
  294. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  295. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  296. *------------------------------------------*/
  297. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  298. {
  299. int i;
  300. struct map_session_data *sd, *tsd;
  301. struct party_data *p = NULL;
  302. struct guild *g = NULL;
  303. struct battleground_data *bg = NULL;
  304. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  305. struct s_mapiterator* iter;
  306. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  307. nullpo_ret(bl);
  308. sd = BL_CAST(BL_PC, bl);
  309. switch(type) {
  310. case ALL_CLIENT: //All player clients.
  311. iter = mapit_getallusers();
  312. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  313. {
  314. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  315. { // packet must exist for the client version
  316. WFIFOHEAD(tsd->fd, len);
  317. memcpy(WFIFOP(tsd->fd,0), buf, len);
  318. WFIFOSET(tsd->fd,len);
  319. }
  320. }
  321. mapit_free(iter);
  322. break;
  323. case ALL_SAMEMAP: //All players on the same map
  324. iter = mapit_getallusers();
  325. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  326. {
  327. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  328. { // packet must exist for the client version
  329. WFIFOHEAD(tsd->fd, len);
  330. memcpy(WFIFOP(tsd->fd,0), buf, len);
  331. WFIFOSET(tsd->fd,len);
  332. }
  333. }
  334. mapit_free(iter);
  335. break;
  336. case AREA:
  337. case AREA_WOSC:
  338. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  339. clif_send (buf, len, bl, SELF);
  340. case AREA_WOC:
  341. case AREA_WOS:
  342. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  343. BL_PC, buf, len, bl, type);
  344. break;
  345. case AREA_CHAT_WOC:
  346. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  347. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  348. break;
  349. case CHAT:
  350. case CHAT_WOS:
  351. {
  352. struct chat_data *cd;
  353. if (sd) {
  354. cd = (struct chat_data*)map_id2bl(sd->chatID);
  355. } else if (bl->type == BL_CHAT) {
  356. cd = (struct chat_data*)bl;
  357. } else break;
  358. if (cd == NULL)
  359. break;
  360. for(i = 0; i < cd->users; i++) {
  361. if (type == CHAT_WOS && cd->usersd[i] == sd)
  362. continue;
  363. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  364. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  365. {
  366. WFIFOHEAD(fd,len);
  367. memcpy(WFIFOP(fd,0), buf, len);
  368. WFIFOSET(fd,len);
  369. }
  370. }
  371. }
  372. }
  373. break;
  374. case CHAT_MAINCHAT: //[LuzZza]
  375. iter = mapit_getallusers();
  376. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  377. {
  378. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  379. { // packet must exist for the client version
  380. WFIFOHEAD(tsd->fd, len);
  381. memcpy(WFIFOP(tsd->fd,0), buf, len);
  382. WFIFOSET(tsd->fd,len);
  383. }
  384. }
  385. mapit_free(iter);
  386. break;
  387. case PARTY_AREA:
  388. case PARTY_AREA_WOS:
  389. x0 = bl->x - AREA_SIZE;
  390. y0 = bl->y - AREA_SIZE;
  391. x1 = bl->x + AREA_SIZE;
  392. y1 = bl->y + AREA_SIZE;
  393. case PARTY:
  394. case PARTY_WOS:
  395. case PARTY_SAMEMAP:
  396. case PARTY_SAMEMAP_WOS:
  397. if (sd && sd->status.party_id)
  398. p = party_search(sd->status.party_id);
  399. if (p) {
  400. for(i=0;i<MAX_PARTY;i++){
  401. if( (sd = p->data[i].sd) == NULL )
  402. continue;
  403. if( !(fd=sd->fd) )
  404. continue;
  405. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  406. continue;
  407. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  408. continue;
  409. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  410. continue;
  411. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  412. { // packet must exist for the client version
  413. WFIFOHEAD(fd,len);
  414. memcpy(WFIFOP(fd,0), buf, len);
  415. WFIFOSET(fd,len);
  416. }
  417. }
  418. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  419. break;
  420. iter = mapit_getallusers();
  421. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  422. {
  423. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  424. { // packet must exist for the client version
  425. WFIFOHEAD(tsd->fd, len);
  426. memcpy(WFIFOP(tsd->fd,0), buf, len);
  427. WFIFOSET(tsd->fd,len);
  428. }
  429. }
  430. mapit_free(iter);
  431. }
  432. break;
  433. case DUEL:
  434. case DUEL_WOS:
  435. if (!sd || !sd->duel_group) break; //Invalid usage.
  436. iter = mapit_getallusers();
  437. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  438. {
  439. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  440. continue;
  441. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  442. { // packet must exist for the client version
  443. WFIFOHEAD(tsd->fd, len);
  444. memcpy(WFIFOP(tsd->fd,0), buf, len);
  445. WFIFOSET(tsd->fd,len);
  446. }
  447. }
  448. mapit_free(iter);
  449. break;
  450. case SELF:
  451. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  452. WFIFOHEAD(fd,len);
  453. memcpy(WFIFOP(fd,0), buf, len);
  454. WFIFOSET(fd,len);
  455. }
  456. break;
  457. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  458. case GUILD_AREA:
  459. case GUILD_AREA_WOS:
  460. x0 = bl->x - AREA_SIZE;
  461. y0 = bl->y - AREA_SIZE;
  462. x1 = bl->x + AREA_SIZE;
  463. y1 = bl->y + AREA_SIZE;
  464. case GUILD_SAMEMAP:
  465. case GUILD_SAMEMAP_WOS:
  466. case GUILD:
  467. case GUILD_WOS:
  468. case GUILD_NOBG:
  469. if (sd && sd->status.guild_id)
  470. g = guild_search(sd->status.guild_id);
  471. if (g) {
  472. for(i = 0; i < g->max_member; i++) {
  473. if( (sd = g->member[i].sd) != NULL )
  474. {
  475. if( !(fd=sd->fd) )
  476. continue;
  477. if( type == GUILD_NOBG && sd->bg_id )
  478. continue;
  479. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  480. continue;
  481. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  482. continue;
  483. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  484. continue;
  485. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  486. { // packet must exist for the client version
  487. WFIFOHEAD(fd,len);
  488. memcpy(WFIFOP(fd,0), buf, len);
  489. WFIFOSET(fd,len);
  490. }
  491. }
  492. }
  493. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  494. break;
  495. iter = mapit_getallusers();
  496. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  497. {
  498. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  499. { // packet must exist for the client version
  500. WFIFOHEAD(tsd->fd, len);
  501. memcpy(WFIFOP(tsd->fd,0), buf, len);
  502. WFIFOSET(tsd->fd,len);
  503. }
  504. }
  505. mapit_free(iter);
  506. }
  507. break;
  508. case BG_AREA:
  509. case BG_AREA_WOS:
  510. x0 = bl->x - AREA_SIZE;
  511. y0 = bl->y - AREA_SIZE;
  512. x1 = bl->x + AREA_SIZE;
  513. y1 = bl->y + AREA_SIZE;
  514. case BG_SAMEMAP:
  515. case BG_SAMEMAP_WOS:
  516. case BG:
  517. case BG_WOS:
  518. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  519. {
  520. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  521. {
  522. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  523. continue;
  524. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  525. continue;
  526. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  527. continue;
  528. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  529. continue;
  530. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  531. { // packet must exist for the client version
  532. WFIFOHEAD(fd,len);
  533. memcpy(WFIFOP(fd,0), buf, len);
  534. WFIFOSET(fd,len);
  535. }
  536. }
  537. }
  538. break;
  539. default:
  540. ShowError("clif_send: Unrecognized type %d\n",type);
  541. return -1;
  542. }
  543. return 0;
  544. }
  545. /// Notifies the client, that it's connection attempt was accepted.
  546. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  547. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  548. void clif_authok(struct map_session_data *sd)
  549. {
  550. #if PACKETVER < 20080102
  551. const int cmd = 0x73;
  552. #else
  553. const int cmd = 0x2eb;
  554. #endif
  555. int fd = sd->fd;
  556. WFIFOHEAD(fd,packet_len(cmd));
  557. WFIFOW(fd, 0) = cmd;
  558. WFIFOL(fd, 2) = gettick();
  559. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  560. WFIFOB(fd, 9) = 5; // ignored
  561. WFIFOB(fd,10) = 5; // ignored
  562. #if PACKETVER >= 20080102
  563. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  564. #endif
  565. WFIFOSET(fd,packet_len(cmd));
  566. }
  567. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  568. /// 0074 <error code>.B
  569. /// error code:
  570. /// 0 = client type mismatch
  571. /// 1 = ID mismatch
  572. /// 2 = mobile - out of available time
  573. /// 3 = mobile - already logged in
  574. /// 4 = mobile - waiting state
  575. void clif_authrefuse(int fd, uint8 error_code)
  576. {
  577. WFIFOHEAD(fd,packet_len(0x74));
  578. WFIFOW(fd,0) = 0x74;
  579. WFIFOB(fd,2) = error_code;
  580. WFIFOSET(fd,packet_len(0x74));
  581. }
  582. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  583. /// 0081 <error code>.B
  584. /// error code:
  585. /// 0 = BAN_UNFAIR
  586. /// 1 = server closed -> MsgStringTable[4]
  587. /// 2 = ID already logged in -> MsgStringTable[5]
  588. /// 3 = timeout/too much lag -> MsgStringTable[241]
  589. /// 4 = server full -> MsgStringTable[264]
  590. /// 5 = underaged -> MsgStringTable[305]
  591. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  592. /// 9 = too many connections from this ip -> MsgStringTable[529]
  593. /// 10 = out of available time paid for -> MsgStringTable[530]
  594. /// 11 = BAN_PAY_SUSPEND
  595. /// 12 = BAN_PAY_CHANGE
  596. /// 13 = BAN_PAY_WRONGIP
  597. /// 14 = BAN_PAY_PNGAMEROOM
  598. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  599. /// 16 = BAN_JAPAN_REFUSE1
  600. /// 17 = BAN_JAPAN_REFUSE2
  601. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  602. /// 100 = BAN_PC_IP_UNFAIR
  603. /// 101 = BAN_PC_IP_COUNT_ALL
  604. /// 102 = BAN_PC_IP_COUNT
  605. /// 103 = BAN_GRAVITY_MEM_AGREE
  606. /// 104 = BAN_GAME_MEM_AGREE
  607. /// 105 = BAN_HAN_VALID
  608. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  609. /// 107 = BAN_OVER_CHARACTER_LIST
  610. /// 108 = BAN_IP_BLOCK
  611. /// 109 = BAN_INVALID_PWD_CNT
  612. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  613. /// ? = disconnected -> MsgStringTable[3]
  614. void clif_authfail_fd(int fd, int type)
  615. {
  616. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  617. return;
  618. WFIFOHEAD(fd, packet_len(0x81));
  619. WFIFOW(fd,0) = 0x81;
  620. WFIFOB(fd,2) = type;
  621. WFIFOSET(fd,packet_len(0x81));
  622. set_eof(fd);
  623. }
  624. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  625. /// 00b3 <type>.B
  626. /// type:
  627. /// 1 = disconnect, char-select
  628. /// ? = nothing
  629. void clif_charselectok(int id, uint8 ok)
  630. {
  631. struct map_session_data* sd;
  632. int fd;
  633. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  634. return;
  635. fd = sd->fd;
  636. WFIFOHEAD(fd,packet_len(0xb3));
  637. WFIFOW(fd,0) = 0xb3;
  638. WFIFOB(fd,2) = ok;
  639. WFIFOSET(fd,packet_len(0xb3));
  640. }
  641. /// Makes an item appear on the ground.
  642. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  643. /// 084b (ZC_ITEM_FALL_ENTRY4)
  644. void clif_dropflooritem(struct flooritem_data* fitem)
  645. {
  646. uint8 buf[17];
  647. int view;
  648. nullpo_retv(fitem);
  649. if (fitem->item_data.nameid <= 0)
  650. return;
  651. WBUFW(buf, 0) = 0x9e;
  652. WBUFL(buf, 2) = fitem->bl.id;
  653. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  654. WBUFB(buf, 8) = fitem->item_data.identify;
  655. WBUFW(buf, 9) = fitem->bl.x;
  656. WBUFW(buf,11) = fitem->bl.y;
  657. WBUFB(buf,13) = fitem->subx;
  658. WBUFB(buf,14) = fitem->suby;
  659. WBUFW(buf,15) = fitem->item_data.amount;
  660. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  661. }
  662. /// Makes an item disappear from the ground.
  663. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  664. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  665. {
  666. unsigned char buf[16];
  667. nullpo_retv(fitem);
  668. WBUFW(buf,0) = 0xa1;
  669. WBUFL(buf,2) = fitem->bl.id;
  670. if (fd == 0) {
  671. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  672. } else {
  673. WFIFOHEAD(fd,packet_len(0xa1));
  674. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  675. WFIFOSET(fd,packet_len(0xa1));
  676. }
  677. }
  678. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  679. /// 0080 <id>.L <type>.B
  680. /// type:
  681. /// 0 = out of sight
  682. /// 1 = died
  683. /// 2 = logged out
  684. /// 3 = teleport
  685. /// 4 = trickdead
  686. void clif_clearunit_single(int id, clr_type type, int fd)
  687. {
  688. WFIFOHEAD(fd, packet_len(0x80));
  689. WFIFOW(fd,0) = 0x80;
  690. WFIFOL(fd,2) = id;
  691. WFIFOB(fd,6) = type;
  692. WFIFOSET(fd, packet_len(0x80));
  693. }
  694. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  695. /// 0080 <id>.L <type>.B
  696. /// type:
  697. /// 0 = out of sight
  698. /// 1 = died
  699. /// 2 = logged out
  700. /// 3 = teleport
  701. /// 4 = trickdead
  702. void clif_clearunit_area(struct block_list* bl, clr_type type)
  703. {
  704. unsigned char buf[8];
  705. nullpo_retv(bl);
  706. WBUFW(buf,0) = 0x80;
  707. WBUFL(buf,2) = bl->id;
  708. WBUFB(buf,6) = type;
  709. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  710. if(disguised(bl)) {
  711. WBUFL(buf,2) = -bl->id;
  712. clif_send(buf, packet_len(0x80), bl, SELF);
  713. }
  714. }
  715. /// Used to make monsters with player-sprites disappear after dying
  716. /// like normal monsters, because the client does not remove those
  717. /// automatically.
  718. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  719. {
  720. struct block_list *bl = (struct block_list *)data;
  721. clif_clearunit_area(bl, (clr_type) id);
  722. aFree(bl);
  723. return 0;
  724. }
  725. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  726. {
  727. struct block_list *tbl;
  728. tbl = (struct block_list*)aMalloc(sizeof (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. #if PACKETVER >= 7
  810. unsigned short offset = 0;
  811. #endif
  812. #if PACKETVER >= 20091103
  813. const char *name;
  814. #endif
  815. sd = BL_CAST(BL_PC, bl);
  816. #if PACKETVER < 20091103
  817. if(type)
  818. WBUFW(buf,0) = spawn?0x7c:0x78;
  819. else
  820. #endif
  821. #if PACKETVER < 4
  822. WBUFW(buf,0) = spawn?0x79:0x78;
  823. #elif PACKETVER < 7
  824. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  825. #elif PACKETVER < 20080102
  826. WBUFW(buf,0) = spawn?0x22b:0x22a;
  827. #elif PACKETVER < 20091103
  828. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  829. #elif PACKETVER < 20101124
  830. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  831. #else
  832. WBUFW(buf,0) = spawn?0x858:0x857;
  833. #endif
  834. #if PACKETVER >= 20091103
  835. name = status_get_name(bl);
  836. #if PACKETVER < 20110111
  837. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  838. #else
  839. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  840. #endif
  841. WBUFB(buf,4) = clif_bl_type(bl);
  842. offset+=3;
  843. buf = WBUFP(buffer,offset);
  844. #elif PACKETVER >= 20071106
  845. if (type) { //Non-player packets
  846. WBUFB(buf,2) = clif_bl_type(bl);
  847. offset++;
  848. buf = WBUFP(buffer,offset);
  849. }
  850. #endif
  851. WBUFL(buf, 2) = bl->id;
  852. WBUFW(buf, 6) = status_get_speed(bl);
  853. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  854. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  855. #if PACKETVER < 20091103
  856. if (type&&spawn) { //uses an older and different packet structure
  857. WBUFW(buf,12) = (sc)? sc->option : 0;
  858. WBUFW(buf,14) = vd->hair_style;
  859. WBUFW(buf,16) = vd->weapon;
  860. WBUFW(buf,18) = vd->head_bottom;
  861. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  862. WBUFW(buf,22) = vd->shield;
  863. } else {
  864. #endif
  865. #if PACKETVER >= 20091103
  866. WBUFL(buf,12) = (sc)? sc->option : 0;
  867. offset+=2;
  868. buf = WBUFP(buffer,offset);
  869. #elif PACKETVER >= 7
  870. if (!type) {
  871. WBUFL(buf,12) = (sc)? sc->option : 0;
  872. offset+=2;
  873. buf = WBUFP(buffer,offset);
  874. } else
  875. WBUFW(buf,12) = (sc)? sc->option : 0;
  876. #else
  877. WBUFW(buf,12) = (sc)? sc->option : 0;
  878. #endif
  879. WBUFW(buf,14) = vd->class_;
  880. WBUFW(buf,16) = vd->hair_style;
  881. WBUFW(buf,18) = vd->weapon;
  882. #if PACKETVER < 4
  883. WBUFW(buf,20) = vd->head_bottom;
  884. WBUFW(buf,22) = vd->shield;
  885. #else
  886. WBUFW(buf,20) = vd->shield;
  887. WBUFW(buf,22) = vd->head_bottom;
  888. #endif
  889. #if PACKETVER < 20091103
  890. }
  891. #endif
  892. WBUFW(buf,24) = vd->head_top;
  893. WBUFW(buf,26) = vd->head_mid;
  894. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  895. { //The hell, why flags work like this?
  896. WBUFW(buf,22) = status_get_emblem_id(bl);
  897. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  898. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  899. }
  900. WBUFW(buf,28) = vd->hair_color;
  901. WBUFW(buf,30) = vd->cloth_color;
  902. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  903. #if PACKETVER < 20091103
  904. if (type&&spawn) { //End of packet 0x7c
  905. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  906. WBUFB(buf,35) = vd->sex;
  907. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  908. WBUFB(buf,39) = 0;
  909. WBUFB(buf,40) = 0;
  910. return packet_len(0x7c);
  911. }
  912. #endif
  913. #if PACKETVER >= 20110111
  914. WBUFW(buf,34) = vd->robe;
  915. offset+= 2;
  916. buf = WBUFP(buffer,offset);
  917. #endif
  918. WBUFL(buf,34) = status_get_guild_id(bl);
  919. WBUFW(buf,38) = status_get_emblem_id(bl);
  920. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  921. #if PACKETVER >= 20091103
  922. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  923. offset+=2;
  924. buf = WBUFP(buffer,offset);
  925. #elif PACKETVER >= 7
  926. if (!type) {
  927. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  928. offset+=2;
  929. buf = WBUFP(buffer,offset);
  930. } else
  931. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  932. #else
  933. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  934. #endif
  935. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  936. WBUFB(buf,45) = vd->sex;
  937. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  938. WBUFB(buf,49) = (sd)? 5 : 0;
  939. WBUFB(buf,50) = (sd)? 5 : 0;
  940. if (!spawn) {
  941. WBUFB(buf,51) = vd->dead_sit;
  942. offset++;
  943. buf = WBUFP(buffer,offset);
  944. }
  945. WBUFW(buf,51) = clif_setlevel(bl);
  946. #if PACKETVER < 20091103
  947. if (type) //End for non-player packet
  948. return packet_len(WBUFW(buffer,0));
  949. #endif
  950. #if PACKETVER >= 20080102
  951. WBUFW(buf,53) = sd?sd->user_font:0;
  952. #endif
  953. #if PACKETVER >= 20091103
  954. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  955. return WBUFW(buffer,2);
  956. #else
  957. return packet_len(WBUFW(buffer,0));
  958. #endif
  959. }
  960. /*==========================================
  961. * Prepares 'unit walking' packet
  962. *------------------------------------------*/
  963. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  964. {
  965. struct map_session_data* sd;
  966. struct status_change* sc = status_get_sc(bl);
  967. struct view_data* vd = status_get_viewdata(bl);
  968. unsigned char* buf = WBUFP(buffer,0);
  969. #if PACKETVER >= 7
  970. unsigned short offset = 0;
  971. #endif
  972. #if PACKETVER >= 20091103
  973. const char *name;
  974. #endif
  975. sd = BL_CAST(BL_PC, bl);
  976. #if PACKETVER < 4
  977. WBUFW(buf, 0) = 0x7b;
  978. #elif PACKETVER < 7
  979. WBUFW(buf, 0) = 0x1da;
  980. #elif PACKETVER < 20080102
  981. WBUFW(buf, 0) = 0x22c;
  982. #elif PACKETVER < 20091103
  983. WBUFW(buf, 0) = 0x2ec;
  984. #elif PACKETVER < 20101124
  985. WBUFW(buf, 0) = 0x7f7;
  986. #else
  987. WBUFW(buf, 0) = 0x856;
  988. #endif
  989. #if PACKETVER >= 20091103
  990. name = status_get_name(bl);
  991. #if PACKETVER < 20110111
  992. WBUFW(buf, 2) = 69+strlen(name);
  993. #else
  994. WBUFW(buf, 2) = 71+strlen(name);
  995. #endif
  996. offset+=2;
  997. buf = WBUFP(buffer,offset);
  998. #endif
  999. #if PACKETVER >= 20071106
  1000. WBUFB(buf, 2) = clif_bl_type(bl);
  1001. offset++;
  1002. buf = WBUFP(buffer,offset);
  1003. #endif
  1004. WBUFL(buf, 2) = bl->id;
  1005. WBUFW(buf, 6) = status_get_speed(bl);
  1006. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1007. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1008. #if PACKETVER < 7
  1009. WBUFW(buf,12) = (sc)? sc->option : 0;
  1010. #else
  1011. WBUFL(buf,12) = (sc)? sc->option : 0;
  1012. offset+=2; //Shift the rest of elements by 2 bytes.
  1013. buf = WBUFP(buffer,offset);
  1014. #endif
  1015. WBUFW(buf,14) = vd->class_;
  1016. WBUFW(buf,16) = vd->hair_style;
  1017. WBUFW(buf,18) = vd->weapon;
  1018. #if PACKETVER < 4
  1019. WBUFW(buf,20) = vd->head_bottom;
  1020. WBUFL(buf,22) = gettick();
  1021. WBUFW(buf,26) = vd->shield;
  1022. #else
  1023. WBUFW(buf,20) = vd->shield;
  1024. WBUFW(buf,22) = vd->head_bottom;
  1025. WBUFL(buf,24) = gettick();
  1026. #endif
  1027. WBUFW(buf,28) = vd->head_top;
  1028. WBUFW(buf,30) = vd->head_mid;
  1029. WBUFW(buf,32) = vd->hair_color;
  1030. WBUFW(buf,34) = vd->cloth_color;
  1031. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1032. #if PACKETVER >= 20110111
  1033. WBUFW(buf,38) = vd->robe;
  1034. offset+= 2;
  1035. buf = WBUFP(buffer,offset);
  1036. #endif
  1037. WBUFL(buf,38) = status_get_guild_id(bl);
  1038. WBUFW(buf,42) = status_get_emblem_id(bl);
  1039. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1040. #if PACKETVER < 7
  1041. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1042. #else
  1043. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1044. offset+=2; //Shift the rest of elements by 2 bytes.
  1045. buf = WBUFP(buffer,offset);
  1046. #endif
  1047. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1048. WBUFB(buf,49) = vd->sex;
  1049. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1050. WBUFB(buf,56) = (sd)? 5 : 0;
  1051. WBUFB(buf,57) = (sd)? 5 : 0;
  1052. WBUFW(buf,58) = clif_setlevel(bl);
  1053. #if PACKETVER >= 20080102
  1054. WBUFW(buf,60) = sd?sd->user_font:0;
  1055. #endif
  1056. #if PACKETVER >= 20091103
  1057. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1058. return WBUFW(buffer,2);
  1059. #else
  1060. return packet_len(WBUFW(buffer,0));
  1061. #endif
  1062. }
  1063. //Modifies the buffer for disguise characters and sends it to self.
  1064. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1065. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1066. {
  1067. #if PACKETVER >= 20091103
  1068. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1069. WBUFL(buf,5)=-bl->id;
  1070. #elif PACKETVER >= 20071106
  1071. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1072. WBUFL(buf,3)=-bl->id;
  1073. #else
  1074. WBUFL(buf,2)=-bl->id;
  1075. #endif
  1076. clif_send(buf, len, bl, SELF);
  1077. }
  1078. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1079. /// 01b0 <id>.L <type>.B <value>.L
  1080. /// type:
  1081. /// unused
  1082. void clif_class_change(struct block_list *bl,int class_,int type)
  1083. {
  1084. unsigned char buf[16];
  1085. nullpo_retv(bl);
  1086. if(!pcdb_checkid(class_))
  1087. {// player classes yield missing sprites
  1088. WBUFW(buf,0)=0x1b0;
  1089. WBUFL(buf,2)=bl->id;
  1090. WBUFB(buf,6)=type;
  1091. WBUFL(buf,7)=class_;
  1092. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1093. }
  1094. }
  1095. /// Notifies the client of an object's spirits.
  1096. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1097. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1098. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1099. {
  1100. WFIFOHEAD(fd, packet_len(0x1e1));
  1101. WFIFOW(fd,0)=0x1e1;
  1102. WFIFOL(fd,2)=sd->bl.id;
  1103. WFIFOW(fd,6)=sd->spiritball;
  1104. WFIFOSET(fd, packet_len(0x1e1));
  1105. }
  1106. /*==========================================
  1107. * Run when player changes map / refreshes
  1108. * Tells its client to display all weather settings being used by this map
  1109. *------------------------------------------*/
  1110. static void clif_weather_check(struct map_session_data *sd)
  1111. {
  1112. int m = sd->bl.m, fd = sd->fd;
  1113. if (map[m].flag.snow
  1114. || map[m].flag.clouds
  1115. || map[m].flag.fog
  1116. || map[m].flag.fireworks
  1117. || map[m].flag.sakura
  1118. || map[m].flag.leaves
  1119. /**
  1120. * No longer available, keeping here just in case it's back someday. [Ind]
  1121. **/
  1122. //|| map[m].flag.rain
  1123. || map[m].flag.clouds2)
  1124. {
  1125. if (map[m].flag.snow)
  1126. clif_specialeffect_single(&sd->bl, 162, fd);
  1127. if (map[m].flag.clouds)
  1128. clif_specialeffect_single(&sd->bl, 233, fd);
  1129. if (map[m].flag.clouds2)
  1130. clif_specialeffect_single(&sd->bl, 516, fd);
  1131. if (map[m].flag.fog)
  1132. clif_specialeffect_single(&sd->bl, 515, fd);
  1133. if (map[m].flag.fireworks) {
  1134. clif_specialeffect_single(&sd->bl, 297, fd);
  1135. clif_specialeffect_single(&sd->bl, 299, fd);
  1136. clif_specialeffect_single(&sd->bl, 301, fd);
  1137. }
  1138. if (map[m].flag.sakura)
  1139. clif_specialeffect_single(&sd->bl, 163, fd);
  1140. if (map[m].flag.leaves)
  1141. clif_specialeffect_single(&sd->bl, 333, fd);
  1142. /**
  1143. * No longer available, keeping here just in case it's back someday. [Ind]
  1144. **/
  1145. //if (map[m].flag.rain)
  1146. // clif_specialeffect_single(&sd->bl, 161, fd);
  1147. }
  1148. }
  1149. /**
  1150. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1151. **/
  1152. void clif_weather(int m)
  1153. {
  1154. struct s_mapiterator* iter;
  1155. struct map_session_data *sd=NULL;
  1156. iter = mapit_getallusers();
  1157. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1158. {
  1159. if( sd->bl.m == m )
  1160. clif_weather_check(sd);
  1161. }
  1162. mapit_free(iter);
  1163. }
  1164. /**
  1165. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1166. **/
  1167. int clif_spawn(struct block_list *bl)
  1168. {
  1169. unsigned char buf[128];
  1170. struct view_data *vd;
  1171. int len;
  1172. vd = status_get_viewdata(bl);
  1173. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1174. return 0;
  1175. /**
  1176. * Hide NPC from maya purple card.
  1177. **/
  1178. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1179. return 0;
  1180. len = clif_set_unit_idle(bl, buf,true);
  1181. clif_send(buf, len, bl, AREA_WOS);
  1182. if (disguised(bl))
  1183. clif_setdisguise(bl, buf, len);
  1184. if (vd->cloth_color)
  1185. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1186. switch (bl->type)
  1187. {
  1188. case BL_PC:
  1189. {
  1190. TBL_PC *sd = ((TBL_PC*)bl);
  1191. if (sd->spiritball > 0)
  1192. clif_spiritball(sd);
  1193. if(sd->state.size==2) // tiny/big players [Valaris]
  1194. clif_specialeffect(bl,423,AREA);
  1195. else if(sd->state.size==1)
  1196. clif_specialeffect(bl,421,AREA);
  1197. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1198. clif_sendbgemblem_area(sd);
  1199. if( sd->sc.option&OPTION_MOUNTING ) {
  1200. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1201. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1202. }
  1203. }
  1204. break;
  1205. case BL_MOB:
  1206. {
  1207. TBL_MOB *md = ((TBL_MOB*)bl);
  1208. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1209. clif_specialeffect(&md->bl,423,AREA);
  1210. else if(md->special_state.size==1)
  1211. clif_specialeffect(&md->bl,421,AREA);
  1212. }
  1213. break;
  1214. case BL_NPC:
  1215. {
  1216. TBL_NPC *nd = ((TBL_NPC*)bl);
  1217. if( nd->size == SZ_BIG )
  1218. clif_specialeffect(&nd->bl,423,AREA);
  1219. else if( nd->size == SZ_MEDIUM )
  1220. clif_specialeffect(&nd->bl,421,AREA);
  1221. }
  1222. break;
  1223. case BL_PET:
  1224. if (vd->head_bottom)
  1225. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1226. break;
  1227. }
  1228. return 0;
  1229. }
  1230. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1231. /// 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
  1232. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1233. {
  1234. struct status_data *status;
  1235. unsigned char buf[128];
  1236. nullpo_retv(hd);
  1237. status = &hd->battle_status;
  1238. memset(buf,0,packet_len(0x22e));
  1239. WBUFW(buf,0)=0x22e;
  1240. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1241. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1242. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1243. WBUFW(buf,27)=hd->homunculus.level;
  1244. WBUFW(buf,29)=hd->homunculus.hunger;
  1245. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1246. WBUFW(buf,33)=0; // equip id
  1247. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1248. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1249. WBUFW(buf,39)=status->hit;
  1250. if (battle_config.hom_setting&0x10)
  1251. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1252. else
  1253. WBUFW(buf,41)=status->cri/10;
  1254. WBUFW(buf,43)=status->def + status->vit ;
  1255. WBUFW(buf,45)=status->mdef;
  1256. WBUFW(buf,47)=status->flee;
  1257. WBUFW(buf,49)=(flag)?0:status->amotion;
  1258. if (status->max_hp > INT16_MAX) {
  1259. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1260. WBUFW(buf,53) = 100;
  1261. } else {
  1262. WBUFW(buf,51)=status->hp;
  1263. WBUFW(buf,53)=status->max_hp;
  1264. }
  1265. if (status->max_sp > INT16_MAX) {
  1266. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1267. WBUFW(buf,57) = 100;
  1268. } else {
  1269. WBUFW(buf,55)=status->sp;
  1270. WBUFW(buf,57)=status->max_sp;
  1271. }
  1272. WBUFL(buf,59)=hd->homunculus.exp;
  1273. WBUFL(buf,63)=hd->exp_next;
  1274. WBUFW(buf,67)=hd->homunculus.skillpts;
  1275. WBUFW(buf,69)=status_get_range(&hd->bl);
  1276. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1277. }
  1278. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1279. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1280. /// type:
  1281. /// unused
  1282. /// state:
  1283. /// 0 = pre-init
  1284. /// 1 = intimacy
  1285. /// 2 = hunger
  1286. /// 3 = accessory?
  1287. /// ? = ignored
  1288. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1289. { //[orn]
  1290. int fd = sd->fd;
  1291. WFIFOHEAD(fd, packet_len(0x230));
  1292. WFIFOW(fd,0)=0x230;
  1293. WFIFOB(fd,2)=0;
  1294. WFIFOB(fd,3)=state;
  1295. WFIFOL(fd,4)=sd->hd->bl.id;
  1296. WFIFOL(fd,8)=param;
  1297. WFIFOSET(fd,packet_len(0x230));
  1298. }
  1299. int clif_homskillinfoblock(struct map_session_data *sd)
  1300. { //[orn]
  1301. struct homun_data *hd;
  1302. int fd = sd->fd;
  1303. int i,j,len=4,id;
  1304. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1305. hd = sd->hd;
  1306. if ( !hd )
  1307. return 0 ;
  1308. WFIFOW(fd,0)=0x235;
  1309. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1310. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1311. j = id - HM_SKILLBASE;
  1312. WFIFOW(fd,len ) = id;
  1313. WFIFOW(fd,len+2) = skill_get_inf(id);
  1314. WFIFOW(fd,len+4) = 0;
  1315. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1316. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1317. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1318. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1319. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1320. len+=37;
  1321. }
  1322. }
  1323. WFIFOW(fd,2)=len;
  1324. WFIFOSET(fd,len);
  1325. return 0;
  1326. }
  1327. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1328. { //[orn]
  1329. struct homun_data *hd;
  1330. int fd, skillid;
  1331. nullpo_retv(sd);
  1332. skillid = skill_num - HM_SKILLBASE;
  1333. fd=sd->fd;
  1334. hd=sd->hd;
  1335. WFIFOHEAD(fd, packet_len(0x239));
  1336. WFIFOW(fd,0) = 0x239;
  1337. WFIFOW(fd,2) = skill_num;
  1338. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1339. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1340. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1341. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1342. WFIFOSET(fd,packet_len(0x239));
  1343. }
  1344. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1345. {
  1346. int fd=sd->fd;
  1347. WFIFOHEAD(fd,packet_len(0x22f));
  1348. WFIFOW(fd,0)=0x22f;
  1349. WFIFOB(fd,2)=fail;
  1350. WFIFOW(fd,3)=foodid;
  1351. WFIFOSET(fd,packet_len(0x22f));
  1352. return 0;
  1353. }
  1354. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1355. /// 0087 <walk start time>.L <walk data>.6B
  1356. void clif_walkok(struct map_session_data *sd)
  1357. {
  1358. int fd=sd->fd;
  1359. WFIFOHEAD(fd, packet_len(0x87));
  1360. WFIFOW(fd,0)=0x87;
  1361. WFIFOL(fd,2)=gettick();
  1362. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1363. WFIFOSET(fd,packet_len(0x87));
  1364. }
  1365. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1366. {
  1367. uint8 buf[128];
  1368. int len;
  1369. len = clif_set_unit_walking(bl,ud,buf);
  1370. clif_send(buf,len,bl,AREA_WOS);
  1371. if (disguised(bl))
  1372. clif_setdisguise(bl, buf, len);
  1373. if(vd->cloth_color)
  1374. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1375. switch(bl->type)
  1376. {
  1377. case BL_PC:
  1378. {
  1379. TBL_PC *sd = ((TBL_PC*)bl);
  1380. // clif_movepc(sd);
  1381. if(sd->state.size==2) // tiny/big players [Valaris]
  1382. clif_specialeffect(&sd->bl,423,AREA);
  1383. else if(sd->state.size==1)
  1384. clif_specialeffect(&sd->bl,421,AREA);
  1385. }
  1386. break;
  1387. case BL_MOB:
  1388. {
  1389. TBL_MOB *md = ((TBL_MOB*)bl);
  1390. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1391. clif_specialeffect(&md->bl,423,AREA);
  1392. else if(md->special_state.size==1)
  1393. clif_specialeffect(&md->bl,421,AREA);
  1394. }
  1395. break;
  1396. case BL_PET:
  1397. if( vd->head_bottom )
  1398. {// needed to display pet equip properly
  1399. clif_pet_equip_area((TBL_PET*)bl);
  1400. }
  1401. break;
  1402. }
  1403. }
  1404. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1405. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1406. /// Note: unit must not be self
  1407. void clif_move(struct unit_data *ud)
  1408. {
  1409. unsigned char buf[16];
  1410. struct view_data* vd;
  1411. struct block_list* bl = ud->bl;
  1412. vd = status_get_viewdata(bl);
  1413. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1414. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1415. /**
  1416. * Hide NPC from maya purple card.
  1417. **/
  1418. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1419. return;
  1420. if (ud->state.speed_changed) {
  1421. // Since we don't know how to update the speed of other objects,
  1422. // use the old walk packet to update the data.
  1423. ud->state.speed_changed = 0;
  1424. clif_move2(bl, vd, ud);
  1425. return;
  1426. }
  1427. WBUFW(buf,0)=0x86;
  1428. WBUFL(buf,2)=bl->id;
  1429. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1430. WBUFL(buf,12)=gettick();
  1431. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1432. if (disguised(bl))
  1433. {
  1434. WBUFL(buf,2)=-bl->id;
  1435. clif_send(buf, packet_len(0x86), bl, SELF);
  1436. }
  1437. }
  1438. /*==========================================
  1439. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1440. *------------------------------------------*/
  1441. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1442. {
  1443. struct map_session_data *sd = NULL;
  1444. //Remove player from map server
  1445. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1446. map_quit(sd);
  1447. return 0;
  1448. }
  1449. /*==========================================
  1450. *
  1451. *------------------------------------------*/
  1452. void clif_quitsave(int fd,struct map_session_data *sd)
  1453. {
  1454. if (!battle_config.prevent_logout ||
  1455. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1456. map_quit(sd);
  1457. else if (sd->fd)
  1458. { //Disassociate session from player (session is deleted after this function was called)
  1459. //And set a timer to make him quit later.
  1460. session[sd->fd]->session_data = NULL;
  1461. sd->fd = 0;
  1462. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1463. }
  1464. }
  1465. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1466. /// 0091 <map name>.16B <x>.W <y>.W
  1467. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1468. {
  1469. int fd;
  1470. nullpo_retv(sd);
  1471. fd = sd->fd;
  1472. WFIFOHEAD(fd,packet_len(0x91));
  1473. WFIFOW(fd,0) = 0x91;
  1474. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1475. WFIFOW(fd,18) = x;
  1476. WFIFOW(fd,20) = y;
  1477. WFIFOSET(fd,packet_len(0x91));
  1478. }
  1479. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1480. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1481. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1482. {
  1483. int fd;
  1484. nullpo_retv(sd);
  1485. fd = sd->fd;
  1486. WFIFOHEAD(fd,packet_len(0x92));
  1487. WFIFOW(fd,0) = 0x92;
  1488. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1489. WFIFOW(fd,18) = x;
  1490. WFIFOW(fd,20) = y;
  1491. WFIFOL(fd,22) = htonl(ip);
  1492. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1493. WFIFOSET(fd,packet_len(0x92));
  1494. }
  1495. void clif_blown(struct block_list *bl)
  1496. {
  1497. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1498. // clif_fixpos(bl);
  1499. clif_slide(bl, bl->x, bl->y);
  1500. }
  1501. /// Visually moves(slides) a character to x,y. If the target cell
  1502. /// isn't walkable, the char doesn't move at all. If the char is
  1503. /// sitting it will stand up (ZC_STOPMOVE).
  1504. /// 0088 <id>.L <x>.W <y>.W
  1505. void clif_fixpos(struct block_list *bl)
  1506. {
  1507. unsigned char buf[10];
  1508. nullpo_retv(bl);
  1509. WBUFW(buf,0) = 0x88;
  1510. WBUFL(buf,2) = bl->id;
  1511. WBUFW(buf,6) = bl->x;
  1512. WBUFW(buf,8) = bl->y;
  1513. clif_send(buf, packet_len(0x88), bl, AREA);
  1514. if( disguised(bl) )
  1515. {
  1516. WBUFL(buf,2) = -bl->id;
  1517. clif_send(buf, packet_len(0x88), bl, SELF);
  1518. }
  1519. }
  1520. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1521. /// 00c4 <shop id>.L
  1522. void clif_npcbuysell(struct map_session_data* sd, int id)
  1523. {
  1524. int fd;
  1525. nullpo_retv(sd);
  1526. fd=sd->fd;
  1527. WFIFOHEAD(fd, packet_len(0xc4));
  1528. WFIFOW(fd,0)=0xc4;
  1529. WFIFOL(fd,2)=id;
  1530. WFIFOSET(fd,packet_len(0xc4));
  1531. }
  1532. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1533. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1534. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1535. {
  1536. int fd,i,c;
  1537. nullpo_retv(sd);
  1538. nullpo_retv(nd);
  1539. fd = sd->fd;
  1540. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1541. WFIFOW(fd,0) = 0xc6;
  1542. c = 0;
  1543. for( i = 0; i < nd->u.shop.count; i++ )
  1544. {
  1545. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1546. int val = nd->u.shop.shop_item[i].value;
  1547. if( id == NULL )
  1548. continue;
  1549. WFIFOL(fd, 4+c*11) = val;
  1550. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1551. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1552. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1553. c++;
  1554. }
  1555. WFIFOW(fd,2) = 4 + c*11;
  1556. WFIFOSET(fd,WFIFOW(fd,2));
  1557. }
  1558. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1559. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1560. void clif_selllist(struct map_session_data *sd)
  1561. {
  1562. int fd,i,c=0,val;
  1563. nullpo_retv(sd);
  1564. fd=sd->fd;
  1565. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1566. WFIFOW(fd,0)=0xc7;
  1567. for( i = 0; i < MAX_INVENTORY; i++ )
  1568. {
  1569. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1570. {
  1571. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1572. continue;
  1573. if( sd->status.inventory[i].expire_time )
  1574. continue; // Cannot Sell Rental Items
  1575. val=sd->inventory_data[i]->value_sell;
  1576. if( val < 0 )
  1577. continue;
  1578. WFIFOW(fd,4+c*10)=i+2;
  1579. WFIFOL(fd,6+c*10)=val;
  1580. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1581. c++;
  1582. }
  1583. }
  1584. WFIFOW(fd,2)=c*10+4;
  1585. WFIFOSET(fd,WFIFOW(fd,2));
  1586. }
  1587. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1588. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1589. /// Client behavior (dialog window):
  1590. /// - disable mouse targeting
  1591. /// - open the dialog window
  1592. /// - set npcid of dialog window (0 by default)
  1593. /// - if set to clear on next mes, clear contents
  1594. /// - append this text
  1595. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1596. {
  1597. int fd = sd->fd;
  1598. int slen = strlen(mes) + 9;
  1599. WFIFOHEAD(fd, slen);
  1600. WFIFOW(fd,0)=0xb4;
  1601. WFIFOW(fd,2)=slen;
  1602. WFIFOL(fd,4)=npcid;
  1603. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1604. WFIFOSET(fd,WFIFOW(fd,2));
  1605. }
  1606. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1607. /// 00b5 <npc id>.L
  1608. /// Client behavior (dialog window):
  1609. /// - disable mouse targeting
  1610. /// - open the dialog window
  1611. /// - add 'next' button
  1612. /// When 'next' is pressed:
  1613. /// - 00B9 <npcid of dialog window>.L
  1614. /// - set to clear on next mes
  1615. /// - remove 'next' button
  1616. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1617. {
  1618. int fd;
  1619. nullpo_retv(sd);
  1620. fd=sd->fd;
  1621. WFIFOHEAD(fd, packet_len(0xb5));
  1622. WFIFOW(fd,0)=0xb5;
  1623. WFIFOL(fd,2)=npcid;
  1624. WFIFOSET(fd,packet_len(0xb5));
  1625. }
  1626. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1627. /// 00b6 <npc id>.L
  1628. /// Client behavior:
  1629. /// - if dialog window is open:
  1630. /// - remove 'next' button
  1631. /// - add 'close' button
  1632. /// - else:
  1633. /// - enable mouse targeting
  1634. /// - close the dialog window
  1635. /// - close the menu window
  1636. /// When 'close' is pressed:
  1637. /// - enable mouse targeting
  1638. /// - close the dialog window
  1639. /// - close the menu window
  1640. /// - 0146 <npcid of dialog window>.L
  1641. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1642. {
  1643. int fd;
  1644. nullpo_retv(sd);
  1645. fd=sd->fd;
  1646. WFIFOHEAD(fd, packet_len(0xb6));
  1647. WFIFOW(fd,0)=0xb6;
  1648. WFIFOL(fd,2)=npcid;
  1649. WFIFOSET(fd,packet_len(0xb6));
  1650. }
  1651. /*==========================================
  1652. *
  1653. *------------------------------------------*/
  1654. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1655. {
  1656. unsigned char *buf;
  1657. int fd = sd->fd;
  1658. sd->state.using_fake_npc = 1;
  1659. WFIFOHEAD(fd, packet_len(0x78));
  1660. buf = WFIFOP(fd,0);
  1661. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1662. WBUFW(buf,0)=0x78;
  1663. #if PACKETVER >= 20071106
  1664. WBUFB(buf,2) = 0; // object type
  1665. buf = WFIFOP(fd,1);
  1666. #endif
  1667. WBUFL(buf,2)=npcid;
  1668. WBUFW(buf,14)=111;
  1669. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1670. WBUFB(buf,49)=5;
  1671. WBUFB(buf,50)=5;
  1672. WFIFOSET(fd, packet_len(0x78));
  1673. }
  1674. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1675. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1676. /// Client behavior:
  1677. /// - disable mouse targeting
  1678. /// - close the menu window
  1679. /// - open the menu window
  1680. /// - add options to the menu (separated in the text by ":")
  1681. /// - set npcid of menu window
  1682. /// - if dialog window is open:
  1683. /// - remove 'next' button
  1684. /// When 'ok' is pressed:
  1685. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1686. /// - close the menu window
  1687. /// When 'cancel' is pressed:
  1688. /// - 00B8 <npcid of menu window>.L <-1>.B
  1689. /// - enable mouse targeting
  1690. /// - close a bunch of windows...
  1691. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1692. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1693. /// TODO investigate behavior of other windows [FlavioJS]
  1694. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1695. {
  1696. int fd = sd->fd;
  1697. int slen = strlen(mes) + 9;
  1698. struct block_list *bl = NULL;
  1699. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1700. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1701. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1702. clif_sendfakenpc(sd, npcid);
  1703. WFIFOHEAD(fd, slen);
  1704. WFIFOW(fd,0)=0xb7;
  1705. WFIFOW(fd,2)=slen;
  1706. WFIFOL(fd,4)=npcid;
  1707. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1708. WFIFOSET(fd,WFIFOW(fd,2));
  1709. }
  1710. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1711. /// 0142 <npc id>.L
  1712. /// Client behavior (inputnum window):
  1713. /// - if npcid exists in the client:
  1714. /// - open the inputnum window
  1715. /// - set npcid of inputnum window
  1716. /// When 'ok' is pressed:
  1717. /// - if inputnum window has text:
  1718. /// - if npcid exists in the client:
  1719. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1720. /// - close inputnum window
  1721. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1722. {
  1723. int fd;
  1724. struct block_list *bl = NULL;
  1725. nullpo_retv(sd);
  1726. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1727. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1728. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1729. clif_sendfakenpc(sd, npcid);
  1730. fd=sd->fd;
  1731. WFIFOHEAD(fd, packet_len(0x142));
  1732. WFIFOW(fd,0)=0x142;
  1733. WFIFOL(fd,2)=npcid;
  1734. WFIFOSET(fd,packet_len(0x142));
  1735. }
  1736. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1737. /// 01d4 <npc id>.L
  1738. /// Client behavior (inputstr window):
  1739. /// - if npcid is 0 or npcid exists in the client:
  1740. /// - open the inputstr window
  1741. /// - set npcid of inputstr window
  1742. /// When 'ok' is pressed:
  1743. /// - if inputstr window has text and isn't an insult(manner.txt):
  1744. /// - if npcid is 0 or npcid exists in the client:
  1745. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1746. /// - close inputstr window
  1747. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1748. {
  1749. int fd;
  1750. struct block_list *bl = NULL;
  1751. nullpo_retv(sd);
  1752. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1753. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1754. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1755. clif_sendfakenpc(sd, npcid);
  1756. fd=sd->fd;
  1757. WFIFOHEAD(fd, packet_len(0x1d4));
  1758. WFIFOW(fd,0)=0x1d4;
  1759. WFIFOL(fd,2)=npcid;
  1760. WFIFOSET(fd,packet_len(0x1d4));
  1761. }
  1762. /// Marks a position on client's minimap (ZC_COMPASS).
  1763. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1764. /// npc id:
  1765. /// is ignored in the client
  1766. /// type:
  1767. /// 0 = display mark for 15 seconds
  1768. /// 1 = display mark until dead or teleported
  1769. /// 2 = remove mark
  1770. /// color:
  1771. /// 0x00RRGGBB
  1772. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1773. {
  1774. int fd;
  1775. nullpo_retv(sd);
  1776. fd=sd->fd;
  1777. WFIFOHEAD(fd, packet_len(0x144));
  1778. WFIFOW(fd,0)=0x144;
  1779. WFIFOL(fd,2)=npc_id;
  1780. WFIFOL(fd,6)=type;
  1781. WFIFOL(fd,10)=x;
  1782. WFIFOL(fd,14)=y;
  1783. WFIFOB(fd,18)=id;
  1784. WFIFOL(fd,19)=color;
  1785. WFIFOSET(fd,packet_len(0x144));
  1786. }
  1787. /// Displays an illustration image.
  1788. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1789. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1790. /// type:
  1791. /// 0 = bottom left corner
  1792. /// 1 = bottom middle
  1793. /// 2 = bottom right corner
  1794. /// 3 = middle of screen, inside a movable window
  1795. /// 4 = middle of screen, movable with a close button, chrome-less
  1796. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1797. {
  1798. int fd;
  1799. nullpo_retv(sd);
  1800. fd=sd->fd;
  1801. WFIFOHEAD(fd, packet_len(0x1b3));
  1802. WFIFOW(fd,0)=0x1b3;
  1803. strncpy((char*)WFIFOP(fd,2),image,64);
  1804. WFIFOB(fd,66)=type;
  1805. WFIFOSET(fd,packet_len(0x1b3));
  1806. }
  1807. /*==========================================
  1808. * Fills in card data from the given item and into the buffer. [Skotlex]
  1809. *------------------------------------------*/
  1810. static void clif_addcards(unsigned char* buf, struct item* item)
  1811. {
  1812. int i=0,j;
  1813. if( item == NULL ) { //Blank data
  1814. WBUFW(buf,0) = 0;
  1815. WBUFW(buf,2) = 0;
  1816. WBUFW(buf,4) = 0;
  1817. WBUFW(buf,6) = 0;
  1818. return;
  1819. }
  1820. if( item->card[0] == CARD0_PET ) { //pet eggs
  1821. WBUFW(buf,0) = 0;
  1822. WBUFW(buf,2) = 0;
  1823. WBUFW(buf,4) = 0;
  1824. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1825. return;
  1826. }
  1827. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1828. WBUFW(buf,0) = item->card[0];
  1829. WBUFW(buf,2) = item->card[1];
  1830. WBUFW(buf,4) = item->card[2];
  1831. WBUFW(buf,6) = item->card[3];
  1832. return;
  1833. }
  1834. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1835. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1836. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1837. //Normal items.
  1838. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1839. WBUFW(buf,0) = j;
  1840. else
  1841. WBUFW(buf,0) = item->card[i];
  1842. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1843. WBUFW(buf,2) = j;
  1844. else
  1845. WBUFW(buf,2) = item->card[i];
  1846. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1847. WBUFW(buf,4) = j;
  1848. else
  1849. WBUFW(buf,4) = item->card[i];
  1850. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1851. WBUFW(buf,6) = j;
  1852. else
  1853. WBUFW(buf,6) = item->card[i];
  1854. }
  1855. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1856. /// 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)
  1857. /// 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)
  1858. /// 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)
  1859. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1860. {
  1861. int fd;
  1862. #if PACKETVER < 20061218
  1863. const int cmd = 0xa0;
  1864. #elif PACKETVER < 20071002
  1865. const int cmd = 0x29a;
  1866. #else
  1867. const int cmd = 0x2d4;
  1868. #endif
  1869. nullpo_retv(sd);
  1870. fd = sd->fd;
  1871. if( !session_isActive(fd) ) //Sasuke-
  1872. return;
  1873. WFIFOHEAD(fd,packet_len(cmd));
  1874. if( fail )
  1875. {
  1876. WFIFOW(fd,0)=cmd;
  1877. WFIFOW(fd,2)=n+2;
  1878. WFIFOW(fd,4)=amount;
  1879. WFIFOW(fd,6)=0;
  1880. WFIFOB(fd,8)=0;
  1881. WFIFOB(fd,9)=0;
  1882. WFIFOB(fd,10)=0;
  1883. WFIFOW(fd,11)=0;
  1884. WFIFOW(fd,13)=0;
  1885. WFIFOW(fd,15)=0;
  1886. WFIFOW(fd,17)=0;
  1887. WFIFOW(fd,19)=0;
  1888. WFIFOB(fd,21)=0;
  1889. WFIFOB(fd,22)=fail;
  1890. #if PACKETVER >= 20061218
  1891. WFIFOL(fd,23)=0;
  1892. #endif
  1893. #if PACKETVER >= 20071002
  1894. WFIFOW(fd,27)=0; // unknown
  1895. #endif
  1896. }
  1897. else
  1898. {
  1899. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1900. return;
  1901. WFIFOW(fd,0)=cmd;
  1902. WFIFOW(fd,2)=n+2;
  1903. WFIFOW(fd,4)=amount;
  1904. if (sd->inventory_data[n]->view_id > 0)
  1905. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1906. else
  1907. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1908. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1909. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1910. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1911. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1912. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1913. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1914. WFIFOB(fd,22)=fail;
  1915. #if PACKETVER >= 20061218
  1916. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1917. #endif
  1918. #if PACKETVER >= 20071002
  1919. WFIFOW(fd,27)=0; // unknown
  1920. #endif
  1921. }
  1922. WFIFOSET(fd,packet_len(cmd));
  1923. }
  1924. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1925. /// 00af <index>.W <amount>.W
  1926. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1927. {
  1928. int fd;
  1929. nullpo_retv(sd);
  1930. fd=sd->fd;
  1931. WFIFOHEAD(fd, packet_len(0xaf));
  1932. WFIFOW(fd,0)=0xaf;
  1933. WFIFOW(fd,2)=n+2;
  1934. WFIFOW(fd,4)=amount;
  1935. WFIFOSET(fd,packet_len(0xaf));
  1936. }
  1937. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1938. /// 07fa <delete type>.W <index>.W <amount>.W
  1939. /// delete type:
  1940. /// 0 = Normal
  1941. /// 1 = Item used for a skill
  1942. /// 2 = Refine failed
  1943. /// 3 = Material changed
  1944. /// 4 = Moved to storage
  1945. /// 5 = Moved to cart
  1946. /// 6 = Item sold
  1947. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1948. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1949. {
  1950. #if PACKETVER < 20091117
  1951. clif_dropitem(sd,n,amount);
  1952. #else
  1953. int fd;
  1954. nullpo_retv(sd);
  1955. fd=sd->fd;
  1956. WFIFOHEAD(fd, packet_len(0x7fa));
  1957. WFIFOW(fd,0)=0x7fa;
  1958. WFIFOW(fd,2)=reason;
  1959. WFIFOW(fd,4)=n+2;
  1960. WFIFOW(fd,6)=amount;
  1961. WFIFOSET(fd,packet_len(0x7fa));
  1962. #endif
  1963. }
  1964. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1965. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1966. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1967. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1968. {
  1969. if (id->view_id > 0)
  1970. WBUFW(buf,n)=id->view_id;
  1971. else
  1972. WBUFW(buf,n)=i->nameid;
  1973. WBUFB(buf,n+2)=itemtype(id->type);
  1974. WBUFB(buf,n+3)=i->identify;
  1975. if (equip >= 0) { //Equippable item
  1976. WBUFW(buf,n+4)=equip;
  1977. WBUFW(buf,n+6)=i->equip;
  1978. WBUFB(buf,n+8)=i->attribute;
  1979. WBUFB(buf,n+9)=i->refine;
  1980. } else { //Stackable item.
  1981. WBUFW(buf,n+4)=i->amount;
  1982. if (equip == -2 && id->equip == EQP_AMMO)
  1983. WBUFW(buf,n+6)=EQP_AMMO;
  1984. else
  1985. WBUFW(buf,n+6)=0;
  1986. }
  1987. }
  1988. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1989. void clif_inventorylist(struct map_session_data *sd)
  1990. {
  1991. int i,n,ne,arrow=-1;
  1992. unsigned char *buf;
  1993. unsigned char *bufe;
  1994. #if PACKETVER < 5
  1995. const int s = 10; //Entry size.
  1996. #elif PACKETVER < 20080102
  1997. const int s = 18;
  1998. #else
  1999. const int s = 22;
  2000. #endif
  2001. #if PACKETVER < 20071002
  2002. const int se = 20;
  2003. #elif PACKETVER < 20100629
  2004. const int se = 26;
  2005. #else
  2006. const int se = 28;
  2007. #endif
  2008. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2009. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2010. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2011. {
  2012. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2013. continue;
  2014. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2015. { //Non-stackable (Equippable)
  2016. WBUFW(bufe,ne*se+4)=i+2;
  2017. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2018. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  2019. #if PACKETVER >= 20071002
  2020. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  2021. WBUFW(bufe,ne*se+28)=0; //Unknown
  2022. #endif
  2023. #if PACKETVER >= 20100629
  2024. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2025. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  2026. else
  2027. WBUFW(bufe,ne*se+30)=0;
  2028. #endif
  2029. ne++;
  2030. }
  2031. else
  2032. { //Stackable.
  2033. WBUFW(buf,n*s+4)=i+2;
  2034. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2035. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2036. arrow=i;
  2037. #if PACKETVER >= 5
  2038. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2039. #endif
  2040. #if PACKETVER >= 20080102
  2041. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  2042. #endif
  2043. n++;
  2044. }
  2045. }
  2046. if( n )
  2047. {
  2048. #if PACKETVER < 5
  2049. WBUFW(buf,0)=0xa3;
  2050. #elif PACKETVER < 20080102
  2051. WBUFW(buf,0)=0x1ee;
  2052. #else
  2053. WBUFW(buf,0)=0x2e8;
  2054. #endif
  2055. WBUFW(buf,2)=4+n*s;
  2056. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2057. }
  2058. if( arrow >= 0 )
  2059. clif_arrowequip(sd,arrow);
  2060. if( ne )
  2061. {
  2062. #if PACKETVER < 20071002
  2063. WBUFW(bufe,0)=0xa4;
  2064. #else
  2065. WBUFW(bufe,0)=0x2d0;
  2066. #endif
  2067. WBUFW(bufe,2)=4+ne*se;
  2068. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2069. }
  2070. if( buf ) aFree(buf);
  2071. if( bufe ) aFree(bufe);
  2072. }
  2073. //Required when items break/get-repaired. Only sends equippable item list.
  2074. void clif_equiplist(struct map_session_data *sd)
  2075. {
  2076. int i,n,fd = sd->fd;
  2077. unsigned char *buf;
  2078. #if PACKETVER < 20071002
  2079. const int cmd = 20;
  2080. #elif PACKETVER < 20100629
  2081. const int cmd = 26;
  2082. #else
  2083. const int cmd = 28;
  2084. #endif
  2085. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2086. buf = WFIFOP(fd,0);
  2087. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2088. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2089. continue;
  2090. if(itemdb_isstackable2(sd->inventory_data[i]))
  2091. continue;
  2092. //Equippable
  2093. WBUFW(buf,n*cmd+4)=i+2;
  2094. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2095. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  2096. #if PACKETVER >= 20071002
  2097. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  2098. WBUFW(buf,n*cmd+28)=0; //Unknown
  2099. #endif
  2100. #if PACKETVER >= 20100629
  2101. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2102. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  2103. else
  2104. WBUFW(buf,n*cmd+30)=0;
  2105. #endif
  2106. n++;
  2107. }
  2108. if (n) {
  2109. #if PACKETVER < 20071002
  2110. WBUFW(buf,0)=0xa4;
  2111. #else
  2112. WBUFW(buf,0)=0x2d0;
  2113. #endif
  2114. WBUFW(buf,2)=4+n*cmd;
  2115. WFIFOSET(fd,WFIFOW(fd,2));
  2116. }
  2117. }
  2118. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2119. {
  2120. struct item_data *id;
  2121. int i,n,ne;
  2122. unsigned char *buf;
  2123. unsigned char *bufe;
  2124. #if PACKETVER < 5
  2125. const int s = 10; //Entry size.
  2126. #elif PACKETVER < 20080102
  2127. const int s = 18;
  2128. #else
  2129. const int s = 22;
  2130. #endif
  2131. #if PACKETVER < 20071002
  2132. const int cmd = 20;
  2133. #elif PACKETVER < 20100629
  2134. const int cmd = 26;
  2135. #else
  2136. const int cmd = 28;
  2137. #endif
  2138. buf = (unsigned char*)aMalloc(items_length * s + 4);
  2139. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  2140. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2141. {
  2142. if( items[i].nameid <= 0 )
  2143. continue;
  2144. id = itemdb_search(items[i].nameid);
  2145. if( !itemdb_isstackable2(id) )
  2146. { //Equippable
  2147. WBUFW(bufe,ne*cmd+4)=i+1;
  2148. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2149. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2150. #if PACKETVER >= 20071002
  2151. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2152. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2153. #endif
  2154. ne++;
  2155. }
  2156. else
  2157. { //Stackable
  2158. WBUFW(buf,n*s+4)=i+1;
  2159. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2160. #if PACKETVER >= 5
  2161. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2162. #endif
  2163. #if PACKETVER >= 20080102
  2164. WBUFL(buf,n*s+22)=items[i].expire_time;
  2165. #endif
  2166. n++;
  2167. }
  2168. }
  2169. if( n )
  2170. {
  2171. #if PACKETVER < 5
  2172. WBUFW(buf,0)=0xa5;
  2173. #elif PACKETVER < 20080102
  2174. WBUFW(buf,0)=0x1f0;
  2175. #else
  2176. WBUFW(buf,0)=0x2ea;
  2177. #endif
  2178. WBUFW(buf,2)=4+n*s;
  2179. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2180. }
  2181. if( ne )
  2182. {
  2183. #if PACKETVER < 20071002
  2184. WBUFW(bufe,0)=0xa6;
  2185. #else
  2186. WBUFW(bufe,0)=0x2d1;
  2187. #endif
  2188. WBUFW(bufe,2)=4+ne*cmd;
  2189. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2190. }
  2191. if( buf ) aFree(buf);
  2192. if( bufe ) aFree(bufe);
  2193. }
  2194. void clif_cartlist(struct map_session_data *sd)
  2195. {
  2196. struct item_data *id;
  2197. int i,n,ne;
  2198. unsigned char *buf;
  2199. unsigned char *bufe;
  2200. #if PACKETVER < 5
  2201. const int s = 10; //Entry size.
  2202. #elif PACKETVER < 20080102
  2203. const int s = 18;
  2204. #else
  2205. const int s = 22;
  2206. #endif
  2207. #if PACKETVER < 20071002
  2208. const int cmd = 20;
  2209. #elif PACKETVER < 20100629
  2210. const int cmd = 26;
  2211. #else
  2212. const int cmd = 28;
  2213. #endif
  2214. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2215. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2216. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2217. {
  2218. if( sd->status.cart[i].nameid <= 0 )
  2219. continue;
  2220. id = itemdb_search(sd->status.cart[i].nameid);
  2221. if( !itemdb_isstackable2(id) )
  2222. { //Equippable
  2223. WBUFW(bufe,ne*cmd+4)=i+2;
  2224. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2225. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2226. #if PACKETVER >= 20071002
  2227. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2228. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2229. #endif
  2230. ne++;
  2231. }
  2232. else
  2233. { //Stackable
  2234. WBUFW(buf,n*s+4)=i+2;
  2235. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2236. #if PACKETVER >= 5
  2237. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2238. #endif
  2239. #if PACKETVER >= 20080102
  2240. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2241. #endif
  2242. n++;
  2243. }
  2244. }
  2245. if( n )
  2246. {
  2247. #if PACKETVER < 5
  2248. WBUFW(buf,0)=0x123;
  2249. #elif PACKETVER < 20080102
  2250. WBUFW(buf,0)=0x1ef;
  2251. #else
  2252. WBUFW(buf,0)=0x2e9;
  2253. #endif
  2254. WBUFW(buf,2)=4+n*s;
  2255. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2256. }
  2257. if( ne )
  2258. {
  2259. #if PACKETVER < 20071002
  2260. WBUFW(bufe,0)=0x122;
  2261. #else
  2262. WBUFW(bufe,0)=0x2d2;
  2263. #endif
  2264. WBUFW(bufe,2)=4+ne*cmd;
  2265. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2266. }
  2267. if( buf ) aFree(buf);
  2268. if( bufe ) aFree(bufe);
  2269. }
  2270. /// Removes cart (ZC_CARTOFF).
  2271. /// 012b
  2272. /// Client behaviour:
  2273. /// Closes the cart storage and removes all it's items from memory.
  2274. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2275. void clif_clearcart(int fd)
  2276. {
  2277. WFIFOHEAD(fd, packet_len(0x12b));
  2278. WFIFOW(fd,0) = 0x12b;
  2279. WFIFOSET(fd, packet_len(0x12b));
  2280. }
  2281. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2282. /// 01eb <account id>.L <x>.W <y>.W
  2283. void clif_guild_xy(struct map_session_data *sd)
  2284. {
  2285. unsigned char buf[10];
  2286. nullpo_retv(sd);
  2287. WBUFW(buf,0)=0x1eb;
  2288. WBUFL(buf,2)=sd->status.account_id;
  2289. WBUFW(buf,6)=sd->bl.x;
  2290. WBUFW(buf,8)=sd->bl.y;
  2291. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2292. }
  2293. /*==========================================
  2294. * Sends x/y dot to a single fd. [Skotlex]
  2295. *------------------------------------------*/
  2296. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2297. {
  2298. if( sd->bg_id )
  2299. return;
  2300. WFIFOHEAD(fd,packet_len(0x1eb));
  2301. WFIFOW(fd,0)=0x1eb;
  2302. WFIFOL(fd,2)=sd->status.account_id;
  2303. WFIFOW(fd,6)=sd->bl.x;
  2304. WFIFOW(fd,8)=sd->bl.y;
  2305. WFIFOSET(fd,packet_len(0x1eb));
  2306. }
  2307. // Guild XY locators [Valaris]
  2308. void clif_guild_xy_remove(struct map_session_data *sd)
  2309. {
  2310. unsigned char buf[10];
  2311. nullpo_retv(sd);
  2312. WBUFW(buf,0)=0x1eb;
  2313. WBUFL(buf,2)=sd->status.account_id;
  2314. WBUFW(buf,6)=-1;
  2315. WBUFW(buf,8)=-1;
  2316. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2317. }
  2318. /*==========================================
  2319. *
  2320. *------------------------------------------*/
  2321. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2322. {
  2323. struct map_session_data *sd, *tsd;
  2324. #if PACKETVER < 20100126
  2325. const int cmd = 0x106;
  2326. #else
  2327. const int cmd = 0x80e;
  2328. #endif
  2329. sd = va_arg(ap, struct map_session_data *);
  2330. tsd = (TBL_PC *)bl;
  2331. nullpo_ret(sd);
  2332. nullpo_ret(tsd);
  2333. if( !tsd->fd || tsd == sd )
  2334. return 0;
  2335. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2336. return 0;
  2337. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2338. WFIFOW(tsd->fd,0) = cmd;
  2339. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2340. #if PACKETVER < 20100126
  2341. if( sd->battle_status.max_hp > INT16_MAX )
  2342. { //To correctly display the %hp bar. [Skotlex]
  2343. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2344. WFIFOW(tsd->fd,8) = 100;
  2345. } else {
  2346. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2347. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2348. }
  2349. #else
  2350. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2351. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2352. #endif
  2353. WFIFOSET(tsd->fd,packet_len(cmd));
  2354. return 0;
  2355. }
  2356. /*==========================================
  2357. * Server tells all players that are allowed to view HP bars
  2358. * and are nearby 'sd' that 'sd' hp bar was updated.
  2359. *------------------------------------------*/
  2360. static int clif_hpmeter(struct map_session_data *sd)
  2361. {
  2362. nullpo_ret(sd);
  2363. 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);
  2364. return 0;
  2365. }
  2366. /// Notifies client of a character parameter change.
  2367. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2368. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2369. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2370. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2371. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2372. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2373. /// TODO: Extract individual packets.
  2374. /// FIXME: Packet lengths from packet_len(cmd)
  2375. void clif_updatestatus(struct map_session_data *sd,int type)
  2376. {
  2377. int fd,len=8;
  2378. nullpo_retv(sd);
  2379. fd=sd->fd;
  2380. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2381. return;
  2382. WFIFOHEAD(fd, 14);
  2383. WFIFOW(fd,0)=0xb0;
  2384. WFIFOW(fd,2)=type;
  2385. switch(type){
  2386. // 00b0
  2387. case SP_WEIGHT:
  2388. pc_updateweightstatus(sd);
  2389. WFIFOHEAD(fd,14);
  2390. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2391. WFIFOW(fd,2)=type;
  2392. WFIFOL(fd,4)=sd->weight;
  2393. break;
  2394. case SP_MAXWEIGHT:
  2395. WFIFOL(fd,4)=sd->max_weight;
  2396. break;
  2397. case SP_SPEED:
  2398. WFIFOL(fd,4)=sd->battle_status.speed;
  2399. break;
  2400. case SP_BASELEVEL:
  2401. WFIFOL(fd,4)=sd->status.base_level;
  2402. break;
  2403. case SP_JOBLEVEL:
  2404. WFIFOL(fd,4)=sd->status.job_level;
  2405. break;
  2406. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2407. WFIFOL(fd,4)=sd->status.karma;
  2408. break;
  2409. case SP_MANNER:
  2410. WFIFOL(fd,4)=sd->status.manner;
  2411. break;
  2412. case SP_STATUSPOINT:
  2413. WFIFOL(fd,4)=sd->status.status_point;
  2414. break;
  2415. case SP_SKILLPOINT:
  2416. WFIFOL(fd,4)=sd->status.skill_point;
  2417. break;
  2418. case SP_HIT:
  2419. WFIFOL(fd,4)=sd->battle_status.hit;
  2420. break;
  2421. case SP_FLEE1:
  2422. WFIFOL(fd,4)=sd->battle_status.flee;
  2423. break;
  2424. case SP_FLEE2:
  2425. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2426. break;
  2427. case SP_MAXHP:
  2428. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2429. break;
  2430. case SP_MAXSP:
  2431. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2432. break;
  2433. case SP_HP:
  2434. WFIFOL(fd,4)=sd->battle_status.hp;
  2435. // TODO: Won't these overwrite the current packet?
  2436. clif_hpmeter(sd);
  2437. if( !battle_config.party_hp_mode && sd->status.party_id )
  2438. clif_party_hp(sd);
  2439. if( sd->bg_id )
  2440. clif_bg_hp(sd);
  2441. break;
  2442. case SP_SP:
  2443. WFIFOL(fd,4)=sd->battle_status.sp;
  2444. break;
  2445. case SP_ASPD:
  2446. WFIFOL(fd,4)=sd->battle_status.amotion;
  2447. break;
  2448. case SP_ATK1:
  2449. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2450. break;
  2451. case SP_DEF1:
  2452. WFIFOL(fd,4)=pc_leftside_def(sd);
  2453. break;
  2454. case SP_MDEF1:
  2455. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2456. break;
  2457. case SP_ATK2:
  2458. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2459. break;
  2460. case SP_DEF2:
  2461. WFIFOL(fd,4)=pc_rightside_def(sd);
  2462. break;
  2463. case SP_MDEF2: {
  2464. //negative check (in case you have something like Berserk active)
  2465. int mdef2 = pc_rightside_mdef(sd);
  2466. WFIFOL(fd,4)=
  2467. #ifndef RENEWAL
  2468. ( mdef2 < 0 ) ? 0 :
  2469. #endif
  2470. mdef2;
  2471. }
  2472. break;
  2473. case SP_CRITICAL:
  2474. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2475. break;
  2476. case SP_MATK1:
  2477. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2478. break;
  2479. case SP_MATK2:
  2480. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2481. break;
  2482. case SP_ZENY:
  2483. WFIFOW(fd,0)=0xb1;
  2484. WFIFOL(fd,4)=sd->status.zeny;
  2485. break;
  2486. case SP_BASEEXP:
  2487. WFIFOW(fd,0)=0xb1;
  2488. WFIFOL(fd,4)=sd->status.base_exp;
  2489. break;
  2490. case SP_JOBEXP:
  2491. WFIFOW(fd,0)=0xb1;
  2492. WFIFOL(fd,4)=sd->status.job_exp;
  2493. break;
  2494. case SP_NEXTBASEEXP:
  2495. WFIFOW(fd,0)=0xb1;
  2496. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2497. break;
  2498. case SP_NEXTJOBEXP:
  2499. WFIFOW(fd,0)=0xb1;
  2500. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2501. break;
  2502. /**
  2503. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2504. **/
  2505. case SP_USTR:
  2506. case SP_UAGI:
  2507. case SP_UVIT:
  2508. case SP_UINT:
  2509. case SP_UDEX:
  2510. case SP_ULUK:
  2511. WFIFOW(fd,0)=0xbe;
  2512. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2513. len=5;
  2514. break;
  2515. /**
  2516. * Tells the client how far it is allowed to attack (weapon range)
  2517. **/
  2518. case SP_ATTACKRANGE:
  2519. WFIFOW(fd,0)=0x13a;
  2520. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2521. len=4;
  2522. break;
  2523. case SP_STR:
  2524. WFIFOW(fd,0)=0x141;
  2525. WFIFOL(fd,2)=type;
  2526. WFIFOL(fd,6)=sd->status.str;
  2527. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2528. len=14;
  2529. break;
  2530. case SP_AGI:
  2531. WFIFOW(fd,0)=0x141;
  2532. WFIFOL(fd,2)=type;
  2533. WFIFOL(fd,6)=sd->status.agi;
  2534. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2535. len=14;
  2536. break;
  2537. case SP_VIT:
  2538. WFIFOW(fd,0)=0x141;
  2539. WFIFOL(fd,2)=type;
  2540. WFIFOL(fd,6)=sd->status.vit;
  2541. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2542. len=14;
  2543. break;
  2544. case SP_INT:
  2545. WFIFOW(fd,0)=0x141;
  2546. WFIFOL(fd,2)=type;
  2547. WFIFOL(fd,6)=sd->status.int_;
  2548. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2549. len=14;
  2550. break;
  2551. case SP_DEX:
  2552. WFIFOW(fd,0)=0x141;
  2553. WFIFOL(fd,2)=type;
  2554. WFIFOL(fd,6)=sd->status.dex;
  2555. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2556. len=14;
  2557. break;
  2558. case SP_LUK:
  2559. WFIFOW(fd,0)=0x141;
  2560. WFIFOL(fd,2)=type;
  2561. WFIFOL(fd,6)=sd->status.luk;
  2562. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2563. len=14;
  2564. break;
  2565. case SP_CARTINFO:
  2566. WFIFOW(fd,0)=0x121;
  2567. WFIFOW(fd,2)=sd->cart_num;
  2568. WFIFOW(fd,4)=MAX_CART;
  2569. WFIFOL(fd,6)=sd->cart_weight;
  2570. WFIFOL(fd,10)=sd->cart_weight_max;
  2571. len=14;
  2572. break;
  2573. default:
  2574. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2575. return;
  2576. }
  2577. WFIFOSET(fd,len);
  2578. }
  2579. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2580. /// 01ab <account id>.L <var id>.W <value>.L
  2581. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2582. {
  2583. unsigned char buf[12];
  2584. nullpo_retv(sd);
  2585. WBUFW(buf,0)=0x1ab;
  2586. WBUFL(buf,2)=sd->bl.id;
  2587. WBUFW(buf,6)=type;
  2588. switch(type)
  2589. {
  2590. case SP_MANNER:
  2591. WBUFL(buf,8)=val;
  2592. break;
  2593. default:
  2594. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2595. return;
  2596. }
  2597. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2598. }
  2599. /// Updates sprite/style properties of an object.
  2600. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2601. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2602. void clif_changelook(struct block_list *bl,int type,int val)
  2603. {
  2604. unsigned char buf[16];
  2605. struct map_session_data* sd = NULL;
  2606. struct status_change* sc;
  2607. struct view_data* vd;
  2608. enum send_target target = AREA;
  2609. nullpo_retv(bl);
  2610. sd = BL_CAST(BL_PC, bl);
  2611. sc = status_get_sc(bl);
  2612. vd = status_get_viewdata(bl);
  2613. //nullpo_ret(vd);
  2614. if( vd ) //temp hack to let Warp Portal change appearance
  2615. switch(type)
  2616. {
  2617. case LOOK_WEAPON:
  2618. if (sd)
  2619. {
  2620. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2621. val = vd->weapon;
  2622. }
  2623. else vd->weapon = val;
  2624. break;
  2625. case LOOK_SHIELD:
  2626. if (sd)
  2627. {
  2628. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2629. val = vd->shield;
  2630. }
  2631. else vd->shield = val;
  2632. break;
  2633. case LOOK_BASE:
  2634. vd->class_ = val;
  2635. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2636. vd->weapon = vd->shield = 0;
  2637. if (vd->cloth_color && (
  2638. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2639. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2640. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2641. ))
  2642. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2643. break;
  2644. case LOOK_HAIR:
  2645. vd->hair_style = val;
  2646. break;
  2647. case LOOK_HEAD_BOTTOM:
  2648. vd->head_bottom = val;
  2649. break;
  2650. case LOOK_HEAD_TOP:
  2651. vd->head_top = val;
  2652. break;
  2653. case LOOK_HEAD_MID:
  2654. vd->head_mid = val;
  2655. break;
  2656. case LOOK_HAIR_COLOR:
  2657. vd->hair_color = val;
  2658. break;
  2659. case LOOK_CLOTHES_COLOR:
  2660. if (val && (
  2661. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2662. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2663. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2664. ))
  2665. val = 0;
  2666. vd->cloth_color = val;
  2667. break;
  2668. case LOOK_SHOES:
  2669. #if PACKETVER > 3
  2670. if (sd) {
  2671. int n;
  2672. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2673. if(sd->inventory_data[n]->view_id > 0)
  2674. val = sd->inventory_data[n]->view_id;
  2675. else
  2676. val = sd->status.inventory[n].nameid;
  2677. }
  2678. val = 0;
  2679. }
  2680. #endif
  2681. //Shoes? No packet uses this....
  2682. break;
  2683. case LOOK_BODY:
  2684. case LOOK_FLOOR:
  2685. // unknown purpose
  2686. break;
  2687. case LOOK_ROBE:
  2688. #if PACKETVER < 20110111
  2689. return;
  2690. #else
  2691. vd->robe = val;
  2692. #endif
  2693. break;
  2694. }
  2695. // prevent leaking the presence of GM-hidden objects
  2696. if( sc && sc->option&OPTION_INVISIBLE )
  2697. target = SELF;
  2698. #if PACKETVER < 4
  2699. WBUFW(buf,0)=0xc3;
  2700. WBUFL(buf,2)=bl->id;
  2701. WBUFB(buf,6)=type;
  2702. WBUFB(buf,7)=val;
  2703. clif_send(buf,packet_len(0xc3),bl,target);
  2704. #else
  2705. WBUFW(buf,0)=0x1d7;
  2706. WBUFL(buf,2)=bl->id;
  2707. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2708. WBUFB(buf,6)=LOOK_WEAPON;
  2709. WBUFW(buf,7)=vd->weapon;
  2710. WBUFW(buf,9)=vd->shield;
  2711. } else {
  2712. WBUFB(buf,6)=type;
  2713. WBUFL(buf,7)=val;
  2714. }
  2715. clif_send(buf,packet_len(0x1d7),bl,target);
  2716. #endif
  2717. }
  2718. //Sends a change-base-look packet required for traps as they are triggered.
  2719. void clif_changetraplook(struct block_list *bl,int val)
  2720. {
  2721. unsigned char buf[32];
  2722. #if PACKETVER < 4
  2723. WBUFW(buf,0)=0xc3;
  2724. WBUFL(buf,2)=bl->id;
  2725. WBUFB(buf,6)=LOOK_BASE;
  2726. WBUFB(buf,7)=val;
  2727. clif_send(buf,packet_len(0xc3),bl,AREA);
  2728. #else
  2729. WBUFW(buf,0)=0x1d7;
  2730. WBUFL(buf,2)=bl->id;
  2731. WBUFB(buf,6)=LOOK_BASE;
  2732. WBUFW(buf,7)=val;
  2733. WBUFW(buf,9)=0;
  2734. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2735. #endif
  2736. }
  2737. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2738. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2739. {
  2740. unsigned char buf[32];
  2741. #if PACKETVER < 4
  2742. WBUFW(buf,0)=0xc3;
  2743. WBUFL(buf,2)=id;
  2744. WBUFB(buf,6)=type;
  2745. WBUFB(buf,7)=val;
  2746. clif_send(buf,packet_len(0xc3),bl,target);
  2747. #else
  2748. WBUFW(buf,0)=0x1d7;
  2749. WBUFL(buf,2)=id;
  2750. WBUFB(buf,6)=type;
  2751. WBUFW(buf,7)=val;
  2752. WBUFW(buf,9)=0;
  2753. clif_send(buf,packet_len(0x1d7),bl,target);
  2754. #endif
  2755. }
  2756. /// Character status (ZC_STATUS).
  2757. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2758. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2759. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2760. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2761. void clif_initialstatus(struct map_session_data *sd)
  2762. {
  2763. int fd, mdef2;
  2764. unsigned char *buf;
  2765. nullpo_retv(sd);
  2766. fd=sd->fd;
  2767. WFIFOHEAD(fd,packet_len(0xbd));
  2768. buf=WFIFOP(fd,0);
  2769. WBUFW(buf,0)=0xbd;
  2770. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2771. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2772. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2773. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2774. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2775. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2776. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2777. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2778. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2779. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2780. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2781. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2782. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2783. WBUFW(buf,16) = pc_leftside_atk(sd);
  2784. WBUFW(buf,18) = pc_rightside_atk(sd);
  2785. WBUFW(buf,20) = sd->battle_status.matk_max;
  2786. WBUFW(buf,22) = sd->battle_status.matk_min;
  2787. WBUFW(buf,24) = pc_leftside_def(sd);
  2788. WBUFW(buf,26) = pc_rightside_def(sd);
  2789. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2790. mdef2 = pc_rightside_mdef(sd);
  2791. WBUFW(buf,30) =
  2792. #ifndef RENEWAL
  2793. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2794. #endif
  2795. mdef2;
  2796. WBUFW(buf,32) = sd->battle_status.hit;
  2797. WBUFW(buf,34) = sd->battle_status.flee;
  2798. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2799. WBUFW(buf,38) = sd->battle_status.cri/10;
  2800. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2801. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2802. WFIFOSET(fd,packet_len(0xbd));
  2803. clif_updatestatus(sd,SP_STR);
  2804. clif_updatestatus(sd,SP_AGI);
  2805. clif_updatestatus(sd,SP_VIT);
  2806. clif_updatestatus(sd,SP_INT);
  2807. clif_updatestatus(sd,SP_DEX);
  2808. clif_updatestatus(sd,SP_LUK);
  2809. clif_updatestatus(sd,SP_ATTACKRANGE);
  2810. clif_updatestatus(sd,SP_ASPD);
  2811. }
  2812. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2813. /// 013c <index>.W
  2814. void clif_arrowequip(struct map_session_data *sd,int val)
  2815. {
  2816. int fd;
  2817. nullpo_retv(sd);
  2818. pc_stop_attack(sd); // [Valaris]
  2819. fd=sd->fd;
  2820. WFIFOHEAD(fd, packet_len(0x013c));
  2821. WFIFOW(fd,0)=0x013c;
  2822. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2823. WFIFOSET(fd,packet_len(0x013c));
  2824. }
  2825. /// Ammunition action message (ZC_ACTION_FAILURE).
  2826. /// 013b <type>.W
  2827. /// type:
  2828. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2829. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2830. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2831. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2832. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2833. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2834. void clif_arrow_fail(struct map_session_data *sd,int type)
  2835. {
  2836. int fd;
  2837. nullpo_retv(sd);
  2838. fd=sd->fd;
  2839. WFIFOHEAD(fd, packet_len(0x013b));
  2840. WFIFOW(fd,0)=0x013b;
  2841. WFIFOW(fd,2)=type;
  2842. WFIFOSET(fd,packet_len(0x013b));
  2843. }
  2844. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2845. /// 01ad <packet len>.W { <name id>.W }*
  2846. void clif_arrow_create_list(struct map_session_data *sd)
  2847. {
  2848. int i, c, j;
  2849. int fd;
  2850. nullpo_retv(sd);
  2851. fd = sd->fd;
  2852. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2853. WFIFOW(fd,0) = 0x1ad;
  2854. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2855. if (skill_arrow_db[i].nameid > 0 &&
  2856. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2857. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2858. {
  2859. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2860. WFIFOW(fd,c*2+4) = j;
  2861. else
  2862. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2863. c++;
  2864. }
  2865. }
  2866. WFIFOW(fd,2) = c*2+4;
  2867. WFIFOSET(fd, WFIFOW(fd,2));
  2868. if (c > 0) {
  2869. sd->menuskill_id = AC_MAKINGARROW;
  2870. sd->menuskill_val = c;
  2871. }
  2872. }
  2873. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2874. /// 00bc <status id>.W <result>.B <value>.B
  2875. /// status id:
  2876. /// SP_STR ~ SP_LUK
  2877. /// result:
  2878. /// 0 = failure
  2879. /// 1 = success
  2880. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2881. {
  2882. int fd;
  2883. nullpo_retv(sd);
  2884. fd=sd->fd;
  2885. WFIFOHEAD(fd,packet_len(0xbc));
  2886. WFIFOW(fd,0)=0xbc;
  2887. WFIFOW(fd,2)=type;
  2888. WFIFOB(fd,4)=ok;
  2889. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2890. WFIFOSET(fd,packet_len(0xbc));
  2891. }
  2892. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2893. /// 00aa <index>.W <equip location>.W <result>.B
  2894. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2895. /// result:
  2896. /// 0 = failure
  2897. /// 1 = success
  2898. /// 2 = failure due to low level
  2899. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2900. {
  2901. int fd;
  2902. nullpo_retv(sd);
  2903. fd=sd->fd;
  2904. WFIFOHEAD(fd,packet_len(0xaa));
  2905. WFIFOW(fd,0)=0xaa;
  2906. WFIFOW(fd,2)=n+2;
  2907. WFIFOW(fd,4)=pos;
  2908. #if PACKETVER < 20100629
  2909. WFIFOB(fd,6)=ok;
  2910. #else
  2911. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2912. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2913. else
  2914. WFIFOW(fd,6)=0;
  2915. WFIFOB(fd,8)=ok;
  2916. #endif
  2917. WFIFOSET(fd,packet_len(0xaa));
  2918. }
  2919. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2920. /// 00ac <index>.W <equip location>.W <result>.B
  2921. /// result:
  2922. /// 0 = failure
  2923. /// 1 = success
  2924. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2925. {
  2926. int fd;
  2927. nullpo_retv(sd);
  2928. fd=sd->fd;
  2929. WFIFOHEAD(fd,packet_len(0xac));
  2930. WFIFOW(fd,0)=0xac;
  2931. WFIFOW(fd,2)=n+2;
  2932. WFIFOW(fd,4)=pos;
  2933. WFIFOB(fd,6)=ok;
  2934. WFIFOSET(fd,packet_len(0xac));
  2935. }
  2936. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2937. /// 019b <id>.L <effect id>.L
  2938. /// effect id:
  2939. /// 0 = base level up
  2940. /// 1 = job level up
  2941. /// 2 = refine failure
  2942. /// 3 = refine success
  2943. /// 4 = game over
  2944. /// 5 = pharmacy success
  2945. /// 6 = pharmacy failure
  2946. /// 7 = base level up (super novice)
  2947. /// 8 = job level up (super novice)
  2948. /// 9 = base level up (taekwon)
  2949. void clif_misceffect(struct block_list* bl,int type)
  2950. {
  2951. unsigned char buf[32];
  2952. nullpo_retv(bl);
  2953. WBUFW(buf,0) = 0x19b;
  2954. WBUFL(buf,2) = bl->id;
  2955. WBUFL(buf,6) = type;
  2956. clif_send(buf,packet_len(0x19b),bl,AREA);
  2957. }
  2958. /// Notifies clients in the area of a state change.
  2959. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  2960. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  2961. void clif_changeoption(struct block_list* bl)
  2962. {
  2963. unsigned char buf[32];
  2964. struct status_change *sc;
  2965. struct map_session_data* sd;
  2966. nullpo_retv(bl);
  2967. sc = status_get_sc(bl);
  2968. if (!sc) return; //How can an option change if there's no sc?
  2969. sd = BL_CAST(BL_PC, bl);
  2970. #if PACKETVER >= 7
  2971. WBUFW(buf,0) = 0x229;
  2972. WBUFL(buf,2) = bl->id;
  2973. WBUFW(buf,6) = sc->opt1;
  2974. WBUFW(buf,8) = sc->opt2;
  2975. WBUFL(buf,10) = sc->option;
  2976. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2977. if(disguised(bl)) {
  2978. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2979. WBUFL(buf,2) = -bl->id;
  2980. clif_send(buf,packet_len(0x229),bl,SELF);
  2981. WBUFL(buf,2) = bl->id;
  2982. WBUFL(buf,10) = OPTION_INVISIBLE;
  2983. clif_send(buf,packet_len(0x229),bl,SELF);
  2984. } else
  2985. clif_send(buf,packet_len(0x229),bl,AREA);
  2986. #else
  2987. WBUFW(buf,0) = 0x119;
  2988. WBUFL(buf,2) = bl->id;
  2989. WBUFW(buf,6) = sc->opt1;
  2990. WBUFW(buf,8) = sc->opt2;
  2991. WBUFW(buf,10) = sc->option;
  2992. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  2993. if(disguised(bl)) {
  2994. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2995. WBUFL(buf,2) = -bl->id;
  2996. clif_send(buf,packet_len(0x119),bl,SELF);
  2997. WBUFL(buf,2) = bl->id;
  2998. WBUFW(buf,10) = OPTION_INVISIBLE;
  2999. clif_send(buf,packet_len(0x119),bl,SELF);
  3000. } else
  3001. clif_send(buf,packet_len(0x119),bl,AREA);
  3002. #endif
  3003. }
  3004. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3005. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3006. void clif_changeoption2(struct block_list* bl)
  3007. {
  3008. unsigned char buf[20];
  3009. struct status_change *sc;
  3010. sc = status_get_sc(bl);
  3011. if (!sc) return; //How can an option change if there's no sc?
  3012. WBUFW(buf,0) = 0x28a;
  3013. WBUFL(buf,2) = bl->id;
  3014. WBUFL(buf,6) = sc->option;
  3015. WBUFL(buf,10) = clif_setlevel(bl);
  3016. WBUFL(buf,14) = sc->opt3;
  3017. if(disguised(bl)) {
  3018. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3019. WBUFL(buf,2) = -bl->id;
  3020. clif_send(buf,packet_len(0x28a),bl,SELF);
  3021. WBUFL(buf,2) = bl->id;
  3022. WBUFL(buf,6) = OPTION_INVISIBLE;
  3023. clif_send(buf,packet_len(0x28a),bl,SELF);
  3024. } else
  3025. clif_send(buf,packet_len(0x28a),bl,AREA);
  3026. }
  3027. /// Notifies the client about the result of an item use request.
  3028. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3029. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3030. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3031. {
  3032. nullpo_retv(sd);
  3033. if(!ok) {
  3034. int fd=sd->fd;
  3035. WFIFOHEAD(fd,packet_len(0xa8));
  3036. WFIFOW(fd,0)=0xa8;
  3037. WFIFOW(fd,2)=index+2;
  3038. WFIFOW(fd,4)=amount;
  3039. WFIFOB(fd,6)=ok;
  3040. WFIFOSET(fd,packet_len(0xa8));
  3041. }
  3042. else {
  3043. #if PACKETVER < 3
  3044. int fd=sd->fd;
  3045. WFIFOHEAD(fd,packet_len(0xa8));
  3046. WFIFOW(fd,0)=0xa8;
  3047. WFIFOW(fd,2)=index+2;
  3048. WFIFOW(fd,4)=amount;
  3049. WFIFOB(fd,6)=ok;
  3050. WFIFOSET(fd,packet_len(0xa8));
  3051. #else
  3052. unsigned char buf[32];
  3053. WBUFW(buf,0)=0x1c8;
  3054. WBUFW(buf,2)=index+2;
  3055. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3056. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3057. else
  3058. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3059. WBUFL(buf,6)=sd->bl.id;
  3060. WBUFW(buf,10)=amount;
  3061. WBUFB(buf,12)=ok;
  3062. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3063. #endif
  3064. }
  3065. }
  3066. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3067. /// 00d6 <flag>.B
  3068. /// flag:
  3069. /// 0 = Room has been successfully created (opens chat room)
  3070. /// 1 = Room limit exceeded
  3071. /// 2 = Same room already exists
  3072. void clif_createchat(struct map_session_data* sd, int flag)
  3073. {
  3074. int fd;
  3075. nullpo_retv(sd);
  3076. fd = sd->fd;
  3077. WFIFOHEAD(fd,packet_len(0xd6));
  3078. WFIFOW(fd,0) = 0xd6;
  3079. WFIFOB(fd,2) = flag;
  3080. WFIFOSET(fd,packet_len(0xd6));
  3081. }
  3082. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3083. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3084. /// type:
  3085. /// 0 = private (password protected)
  3086. /// 1 = public
  3087. /// 2 = arena (npc waiting room)
  3088. /// 3 = PK zone (non-clickable)
  3089. void clif_dispchat(struct chat_data* cd, int fd)
  3090. {
  3091. unsigned char buf[128];
  3092. uint8 type;
  3093. if( cd == NULL || cd->owner == NULL )
  3094. return;
  3095. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3096. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3097. : 1;
  3098. WBUFW(buf, 0) = 0xd7;
  3099. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3100. WBUFL(buf, 4) = cd->owner->id;
  3101. WBUFL(buf, 8) = cd->bl.id;
  3102. WBUFW(buf,12) = cd->limit;
  3103. WBUFW(buf,14) = cd->users;
  3104. WBUFB(buf,16) = type;
  3105. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3106. if( fd ) {
  3107. WFIFOHEAD(fd,WBUFW(buf,2));
  3108. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3109. WFIFOSET(fd,WBUFW(buf,2));
  3110. } else {
  3111. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3112. }
  3113. }
  3114. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3115. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3116. /// type:
  3117. /// 0 = private (password protected)
  3118. /// 1 = public
  3119. /// 2 = arena (npc waiting room)
  3120. /// 3 = PK zone (non-clickable)
  3121. void clif_changechatstatus(struct chat_data* cd)
  3122. {
  3123. unsigned char buf[128];
  3124. uint8 type;
  3125. if( cd == NULL || cd->usersd[0] == NULL )
  3126. return;
  3127. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3128. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3129. : 1;
  3130. WBUFW(buf, 0) = 0xdf;
  3131. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3132. WBUFL(buf, 4) = cd->owner->id;
  3133. WBUFL(buf, 8) = cd->bl.id;
  3134. WBUFW(buf,12) = cd->limit;
  3135. WBUFW(buf,14) = cd->users;
  3136. WBUFB(buf,16) = type;
  3137. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3138. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3139. }
  3140. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3141. /// 00d8 <chat id>.L
  3142. void clif_clearchat(struct chat_data *cd,int fd)
  3143. {
  3144. unsigned char buf[32];
  3145. nullpo_retv(cd);
  3146. WBUFW(buf,0) = 0xd8;
  3147. WBUFL(buf,2) = cd->bl.id;
  3148. if( fd ) {
  3149. WFIFOHEAD(fd,packet_len(0xd8));
  3150. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3151. WFIFOSET(fd,packet_len(0xd8));
  3152. } else {
  3153. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3154. }
  3155. }
  3156. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3157. /// 00da <result>.B
  3158. /// result:
  3159. /// 0 = room full
  3160. /// 1 = wrong password
  3161. /// 2 = kicked
  3162. /// 3 = success (no message)
  3163. /// 4 = no enough zeny
  3164. /// 5 = too low level
  3165. /// 6 = too high level
  3166. /// 7 = unsuitable job class
  3167. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3168. {
  3169. int fd;
  3170. nullpo_retv(sd);
  3171. fd = sd->fd;
  3172. WFIFOHEAD(fd,packet_len(0xda));
  3173. WFIFOW(fd,0) = 0xda;
  3174. WFIFOB(fd,2) = flag;
  3175. WFIFOSET(fd,packet_len(0xda));
  3176. }
  3177. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3178. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3179. /// role:
  3180. /// 0 = owner (menu)
  3181. /// 1 = normal
  3182. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3183. {
  3184. int fd;
  3185. int i;
  3186. nullpo_retv(sd);
  3187. nullpo_retv(cd);
  3188. fd = sd->fd;
  3189. if (!session_isActive(fd))
  3190. return;
  3191. WFIFOHEAD(fd, 8 + (28*cd->users));
  3192. WFIFOW(fd, 0) = 0xdb;
  3193. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3194. WFIFOL(fd, 4) = cd->bl.id;
  3195. for (i = 0; i < cd->users; i++) {
  3196. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3197. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3198. }
  3199. WFIFOSET(fd, WFIFOW(fd, 2));
  3200. }
  3201. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3202. /// 00dc <users>.W <name>.24B
  3203. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3204. {
  3205. unsigned char buf[32];
  3206. nullpo_retv(sd);
  3207. nullpo_retv(cd);
  3208. WBUFW(buf, 0) = 0xdc;
  3209. WBUFW(buf, 2) = cd->users;
  3210. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3211. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3212. }
  3213. /// Announce the new owner (ZC_ROLE_CHANGE).
  3214. /// 00e1 <role>.L <nick>.24B
  3215. /// role:
  3216. /// 0 = owner (menu)
  3217. /// 1 = normal
  3218. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3219. {
  3220. unsigned char buf[64];
  3221. nullpo_retv(sd);
  3222. nullpo_retv(cd);
  3223. WBUFW(buf, 0) = 0xe1;
  3224. WBUFL(buf, 2) = 1;
  3225. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3226. WBUFW(buf,30) = 0xe1;
  3227. WBUFL(buf,32) = 0;
  3228. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3229. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3230. }
  3231. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3232. /// 00dd <users>.W <nick>.24B <flag>.B
  3233. /// flag:
  3234. /// 0 = left
  3235. /// 1 = kicked
  3236. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3237. {
  3238. unsigned char buf[32];
  3239. nullpo_retv(sd);
  3240. nullpo_retv(cd);
  3241. WBUFW(buf, 0) = 0xdd;
  3242. WBUFW(buf, 2) = cd->users-1;
  3243. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3244. WBUFB(buf,28) = flag;
  3245. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3246. }
  3247. /// Opens a trade request window from char 'name'.
  3248. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3249. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3250. void clif_traderequest(struct map_session_data* sd, const char* name)
  3251. {
  3252. int fd = sd->fd;
  3253. #if PACKETVER < 6
  3254. WFIFOHEAD(fd,packet_len(0xe5));
  3255. WFIFOW(fd,0) = 0xe5;
  3256. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3257. WFIFOSET(fd,packet_len(0xe5));
  3258. #else
  3259. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3260. if( !tsd ) return;
  3261. WFIFOHEAD(fd,packet_len(0x1f4));
  3262. WFIFOW(fd,0) = 0x1f4;
  3263. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3264. WFIFOL(fd,26) = tsd->status.char_id;
  3265. WFIFOW(fd,30) = tsd->status.base_level;
  3266. WFIFOSET(fd,packet_len(0x1f4));
  3267. #endif
  3268. }
  3269. /// Reply to a trade-request.
  3270. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3271. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3272. /// result:
  3273. /// 0 = Char is too far
  3274. /// 1 = Character does not exist
  3275. /// 2 = Trade failed
  3276. /// 3 = Accept
  3277. /// 4 = Cancel
  3278. /// 5 = Busy
  3279. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3280. {
  3281. int fd = sd->fd;
  3282. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3283. if( PACKETVER < 6 || !tsd ) {
  3284. WFIFOHEAD(fd,packet_len(0xe7));
  3285. WFIFOW(fd,0) = 0xe7;
  3286. WFIFOB(fd,2) = type;
  3287. WFIFOSET(fd,packet_len(0xe7));
  3288. } else {
  3289. WFIFOHEAD(fd,packet_len(0x1f5));
  3290. WFIFOW(fd,0) = 0x1f5;
  3291. WFIFOB(fd,2) = type;
  3292. WFIFOL(fd,3) = tsd->status.char_id;
  3293. WFIFOW(fd,7) = tsd->status.base_level;
  3294. WFIFOSET(fd,packet_len(0x1f5));
  3295. }
  3296. }
  3297. /// Notifies the client about an item from other player in current trade.
  3298. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3299. /// 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)
  3300. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3301. {
  3302. int fd;
  3303. unsigned char *buf;
  3304. #if PACKETVER < 20100223
  3305. const int cmd = 0xe9;
  3306. #else
  3307. const int cmd = 0x80f;
  3308. #endif
  3309. nullpo_retv(sd);
  3310. nullpo_retv(tsd);
  3311. fd = tsd->fd;
  3312. buf = WFIFOP(fd,0);
  3313. WFIFOHEAD(fd,packet_len(cmd));
  3314. WBUFW(buf,0) = cmd;
  3315. if( index == 0 )
  3316. {
  3317. #if PACKETVER < 20100223
  3318. WBUFL(buf,2) = amount; //amount
  3319. WBUFW(buf,6) = 0; // type id
  3320. #else
  3321. WBUFW(buf,2) = 0; // type id
  3322. WBUFB(buf,4) = 0; // item type
  3323. WBUFL(buf,5) = amount; // amount
  3324. buf = WBUFP(buf,1); //Advance 1B
  3325. #endif
  3326. WBUFB(buf,8) = 0; //identify flag
  3327. WBUFB(buf,9) = 0; // attribute
  3328. WBUFB(buf,10)= 0; //refine
  3329. WBUFW(buf,11)= 0; //card (4w)
  3330. WBUFW(buf,13)= 0; //card (4w)
  3331. WBUFW(buf,15)= 0; //card (4w)
  3332. WBUFW(buf,17)= 0; //card (4w)
  3333. }
  3334. else
  3335. {
  3336. index -= 2; //index fix
  3337. #if PACKETVER < 20100223
  3338. WBUFL(buf,2) = amount; //amount
  3339. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3340. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3341. else
  3342. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3343. #else
  3344. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3345. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3346. else
  3347. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3348. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3349. WBUFL(buf,5) = amount; // amount
  3350. buf = WBUFP(buf,1); //Advance 1B
  3351. #endif
  3352. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3353. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3354. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3355. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3356. }
  3357. WFIFOSET(fd,packet_len(cmd));
  3358. }
  3359. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3360. /// 00ea <index>.W <result>.B
  3361. /// result:
  3362. /// 0 = success
  3363. /// 1 = overweight
  3364. /// 2 = trade canceled
  3365. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3366. {
  3367. int fd;
  3368. nullpo_retv(sd);
  3369. fd = sd->fd;
  3370. WFIFOHEAD(fd,packet_len(0xea));
  3371. WFIFOW(fd,0) = 0xea;
  3372. WFIFOW(fd,2) = index;
  3373. WFIFOB(fd,4) = fail;
  3374. WFIFOSET(fd,packet_len(0xea));
  3375. }
  3376. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3377. /// 00ec <who>.B
  3378. /// who:
  3379. /// 0 = self
  3380. /// 1 = other player
  3381. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3382. {
  3383. int fd;
  3384. nullpo_retv(sd);
  3385. fd = sd->fd;
  3386. WFIFOHEAD(fd,packet_len(0xec));
  3387. WFIFOW(fd,0) = 0xec;
  3388. WFIFOB(fd,2) = fail;
  3389. WFIFOSET(fd,packet_len(0xec));
  3390. }
  3391. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3392. /// 00ee
  3393. void clif_tradecancelled(struct map_session_data* sd)
  3394. {
  3395. int fd;
  3396. nullpo_retv(sd);
  3397. fd = sd->fd;
  3398. WFIFOHEAD(fd,packet_len(0xee));
  3399. WFIFOW(fd,0) = 0xee;
  3400. WFIFOSET(fd,packet_len(0xee));
  3401. }
  3402. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3403. /// 00f0 <result>.B
  3404. /// result:
  3405. /// 0 = success
  3406. /// 1 = failure
  3407. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3408. {
  3409. int fd;
  3410. nullpo_retv(sd);
  3411. fd = sd->fd;
  3412. WFIFOHEAD(fd,packet_len(0xf0));
  3413. WFIFOW(fd,0) = 0xf0;
  3414. WFIFOB(fd,2) = fail;
  3415. WFIFOSET(fd,packet_len(0xf0));
  3416. }
  3417. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3418. /// 00f1
  3419. /// NOTE: Unknown purpose. Items are not removed until the window is
  3420. /// refreshed (ex. by putting another item in there).
  3421. void clif_tradeundo(struct map_session_data* sd)
  3422. {
  3423. int fd = sd->fd;
  3424. WFIFOHEAD(fd,packet_len(0xf1));
  3425. WFIFOW(fd,0) = 0xf1;
  3426. WFIFOSET(fd,packet_len(0xf1));
  3427. }
  3428. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3429. /// 00f2 <current count>.W <max count>.W
  3430. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3431. {
  3432. int fd;
  3433. nullpo_retv(sd);
  3434. fd=sd->fd;
  3435. WFIFOHEAD(fd,packet_len(0xf2));
  3436. WFIFOW(fd,0) = 0xf2;
  3437. WFIFOW(fd,2) = amount;
  3438. WFIFOW(fd,4) = max_amount;
  3439. WFIFOSET(fd,packet_len(0xf2));
  3440. }
  3441. /// Notifies the client of an item being added to the storage.
  3442. /// 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)
  3443. /// 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)
  3444. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3445. {
  3446. int view,fd;
  3447. nullpo_retv(sd);
  3448. nullpo_retv(i);
  3449. fd=sd->fd;
  3450. view = itemdb_viewid(i->nameid);
  3451. #if PACKETVER < 5
  3452. WFIFOHEAD(fd,packet_len(0xf4));
  3453. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3454. WFIFOW(fd, 2) = index+1; // index
  3455. WFIFOL(fd, 4) = amount; // amount
  3456. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3457. WFIFOB(fd,10) = i->identify; //identify flag
  3458. WFIFOB(fd,11) = i->attribute; // attribute
  3459. WFIFOB(fd,12) = i->refine; //refine
  3460. clif_addcards(WFIFOP(fd,13), i);
  3461. WFIFOSET(fd,packet_len(0xf4));
  3462. #else
  3463. WFIFOHEAD(fd,packet_len(0x1c4));
  3464. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3465. WFIFOW(fd, 2) = index+1; // index
  3466. WFIFOL(fd, 4) = amount; // amount
  3467. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3468. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3469. WFIFOB(fd,11) = i->identify; //identify flag
  3470. WFIFOB(fd,12) = i->attribute; // attribute
  3471. WFIFOB(fd,13) = i->refine; //refine
  3472. clif_addcards(WFIFOP(fd,14), i);
  3473. WFIFOSET(fd,packet_len(0x1c4));
  3474. #endif
  3475. }
  3476. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3477. /// 00f6 <index>.W <amount>.L
  3478. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3479. {
  3480. int fd;
  3481. nullpo_retv(sd);
  3482. fd=sd->fd;
  3483. WFIFOHEAD(fd,packet_len(0xf6));
  3484. WFIFOW(fd,0)=0xf6; // Storage item removed
  3485. WFIFOW(fd,2)=index+1;
  3486. WFIFOL(fd,4)=amount;
  3487. WFIFOSET(fd,packet_len(0xf6));
  3488. }
  3489. /// Closes storage (ZC_CLOSE_STORE).
  3490. /// 00f8
  3491. void clif_storageclose(struct map_session_data* sd)
  3492. {
  3493. int fd;
  3494. nullpo_retv(sd);
  3495. fd=sd->fd;
  3496. WFIFOHEAD(fd,packet_len(0xf8));
  3497. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3498. WFIFOSET(fd,packet_len(0xf8));
  3499. }
  3500. /*==========================================
  3501. * Server tells 'sd' player client the abouts of 'dstsd' player
  3502. *------------------------------------------*/
  3503. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3504. {
  3505. struct block_list *d_bl;
  3506. int i;
  3507. if( dstsd->chatID ) {
  3508. struct chat_data *cd = NULL;
  3509. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3510. clif_dispchat(cd,sd->fd);
  3511. } else if( dstsd->state.vending )
  3512. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3513. else if( dstsd->state.buyingstore )
  3514. clif_buyingstore_entry_single(sd, dstsd);
  3515. if(dstsd->spiritball > 0)
  3516. clif_spiritball_single(sd->fd, dstsd);
  3517. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3518. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3519. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3520. }
  3521. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3522. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3523. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3524. )
  3525. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3526. // display link (sd - dstsd) to sd
  3527. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3528. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3529. // display links (dstsd - devotees) to sd
  3530. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3531. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3532. // display link (dstsd - crusader) to sd
  3533. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3534. clif_devotion(d_bl, sd);
  3535. }
  3536. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3537. {
  3538. uint8 buf[128];
  3539. struct unit_data *ud;
  3540. struct view_data *vd;
  3541. int len;
  3542. vd = status_get_viewdata(bl);
  3543. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3544. return;
  3545. /**
  3546. * Hide NPC from maya purple card.
  3547. **/
  3548. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3549. return;
  3550. ud = unit_bl2ud(bl);
  3551. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3552. clif_send(buf,len,&sd->bl,SELF);
  3553. if (vd->cloth_color)
  3554. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3555. switch (bl->type)
  3556. {
  3557. case BL_PC:
  3558. {
  3559. TBL_PC* tsd = (TBL_PC*)bl;
  3560. clif_getareachar_pc(sd, tsd);
  3561. if(tsd->state.size==2) // tiny/big players [Valaris]
  3562. clif_specialeffect_single(bl,423,sd->fd);
  3563. else if(tsd->state.size==1)
  3564. clif_specialeffect_single(bl,421,sd->fd);
  3565. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3566. clif_sendbgemblem_single(sd->fd,tsd);
  3567. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3568. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3569. }
  3570. break;
  3571. case BL_MER: // Devotion Effects
  3572. if( ((TBL_MER*)bl)->devotion_flag )
  3573. clif_devotion(bl, sd);
  3574. break;
  3575. case BL_NPC:
  3576. {
  3577. TBL_NPC* nd = (TBL_NPC*)bl;
  3578. if( nd->chat_id )
  3579. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3580. if( nd->size == SZ_BIG )
  3581. clif_specialeffect_single(bl,423,sd->fd);
  3582. else if( nd->size == SZ_MEDIUM )
  3583. clif_specialeffect_single(bl,421,sd->fd);
  3584. }
  3585. break;
  3586. case BL_MOB:
  3587. {
  3588. TBL_MOB* md = (TBL_MOB*)bl;
  3589. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3590. clif_specialeffect_single(bl,423,sd->fd);
  3591. else if(md->special_state.size==SZ_MEDIUM)
  3592. clif_specialeffect_single(bl,421,sd->fd);
  3593. }
  3594. break;
  3595. case BL_PET:
  3596. if (vd->head_bottom)
  3597. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3598. break;
  3599. }
  3600. }
  3601. //Modifies the type of damage according to status changes [Skotlex]
  3602. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3603. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3604. {
  3605. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3606. }
  3607. /*==========================================
  3608. * Estimates walk delay based on the damage criteria. [Skotlex]
  3609. *------------------------------------------*/
  3610. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3611. {
  3612. if (type == 4 || type == 9 || damage <=0)
  3613. return 0;
  3614. if (bl->type == BL_PC) {
  3615. if (battle_config.pc_walk_delay_rate != 100)
  3616. delay = delay*battle_config.pc_walk_delay_rate/100;
  3617. } else
  3618. if (battle_config.walk_delay_rate != 100)
  3619. delay = delay*battle_config.walk_delay_rate/100;
  3620. if (div_ > 1) //Multi-hit skills mean higher delays.
  3621. delay += battle_config.multihit_delay*(div_-1);
  3622. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3623. }
  3624. /// Sends a 'damage' packet (src performs action on dst)
  3625. /// 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)
  3626. /// 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)
  3627. /// type:
  3628. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3629. /// 1 = pick up item
  3630. /// 2 = sit down
  3631. /// 3 = stand up
  3632. /// 4 = damage (endure)
  3633. /// 5 = (splash?)
  3634. /// 6 = (skill?)
  3635. /// 7 = (repeat damage?)
  3636. /// 8 = multi-hit damage
  3637. /// 9 = multi-hit damage (endure)
  3638. /// 10 = critical hit
  3639. /// 11 = lucky dodge
  3640. /// 12 = (touch skill?)
  3641. 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)
  3642. {
  3643. unsigned char buf[33];
  3644. struct status_change *sc;
  3645. #if PACKETVER < 20071113
  3646. const int cmd = 0x8a;
  3647. #else
  3648. const int cmd = 0x2e1;
  3649. #endif
  3650. nullpo_ret(src);
  3651. nullpo_ret(dst);
  3652. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3653. sc = status_get_sc(dst);
  3654. if(sc && sc->count) {
  3655. if(sc->data[SC_HALLUCINATION]) {
  3656. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3657. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3658. }
  3659. }
  3660. WBUFW(buf,0)=cmd;
  3661. WBUFL(buf,2)=src->id;
  3662. WBUFL(buf,6)=dst->id;
  3663. WBUFL(buf,10)=tick;
  3664. WBUFL(buf,14)=sdelay;
  3665. WBUFL(buf,18)=ddelay;
  3666. #if PACKETVER < 20071113
  3667. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3668. WBUFW(buf,22)=damage?div:0;
  3669. WBUFW(buf,27)=damage2?div:0;
  3670. } else {
  3671. WBUFW(buf,22)=min(damage, INT16_MAX);
  3672. WBUFW(buf,27)=damage2;
  3673. }
  3674. WBUFW(buf,24)=div;
  3675. WBUFB(buf,26)=type;
  3676. #else
  3677. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3678. WBUFL(buf,22)=damage?div:0;
  3679. WBUFL(buf,29)=damage2?div:0;
  3680. } else {
  3681. WBUFL(buf,22)=damage;
  3682. WBUFL(buf,29)=damage2;
  3683. }
  3684. WBUFW(buf,26)=div;
  3685. WBUFB(buf,28)=type;
  3686. #endif
  3687. if(disguised(dst)) {
  3688. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3689. WBUFL(buf,6) = -dst->id;
  3690. clif_send(buf,packet_len(cmd),dst,SELF);
  3691. } else
  3692. clif_send(buf,packet_len(cmd),dst,AREA);
  3693. if(disguised(src)) {
  3694. WBUFL(buf,2) = -src->id;
  3695. if (disguised(dst))
  3696. WBUFL(buf,6) = dst->id;
  3697. #if PACKETVER < 20071113
  3698. if(damage > 0) WBUFW(buf,22) = -1;
  3699. if(damage2 > 0) WBUFW(buf,27) = -1;
  3700. #else
  3701. if(damage > 0) WBUFL(buf,22) = -1;
  3702. if(damage2 > 0) WBUFL(buf,29) = -1;
  3703. #endif
  3704. clif_send(buf,packet_len(cmd),src,SELF);
  3705. }
  3706. if(src == dst) {
  3707. unit_setdir(src,unit_getdir(src));
  3708. }
  3709. //Return adjusted can't walk delay for further processing.
  3710. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3711. }
  3712. /*==========================================
  3713. * src picks up dst
  3714. *------------------------------------------*/
  3715. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3716. {
  3717. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3718. unsigned char buf[32];
  3719. nullpo_retv(src);
  3720. nullpo_retv(dst);
  3721. WBUFW(buf, 0) = 0x8a;
  3722. WBUFL(buf, 2) = src->id;
  3723. WBUFL(buf, 6) = dst->id;
  3724. WBUFB(buf,26) = 1;
  3725. clif_send(buf, packet_len(0x8a), src, AREA);
  3726. }
  3727. /*==========================================
  3728. * inform clients in area that `bl` is sitting
  3729. *------------------------------------------*/
  3730. void clif_sitting(struct block_list* bl)
  3731. {
  3732. unsigned char buf[32];
  3733. nullpo_retv(bl);
  3734. WBUFW(buf, 0) = 0x8a;
  3735. WBUFL(buf, 2) = bl->id;
  3736. WBUFB(buf,26) = 2;
  3737. clif_send(buf, packet_len(0x8a), bl, AREA);
  3738. if(disguised(bl)) {
  3739. WBUFL(buf, 2) = - bl->id;
  3740. clif_send(buf, packet_len(0x8a), bl, SELF);
  3741. }
  3742. }
  3743. /*==========================================
  3744. * inform clients in area that `bl` is standing
  3745. *------------------------------------------*/
  3746. void clif_standing(struct block_list* bl)
  3747. {
  3748. unsigned char buf[32];
  3749. nullpo_retv(bl);
  3750. WBUFW(buf, 0) = 0x8a;
  3751. WBUFL(buf, 2) = bl->id;
  3752. WBUFB(buf,26) = 3;
  3753. clif_send(buf, packet_len(0x8a), bl, AREA);
  3754. if(disguised(bl)) {
  3755. WBUFL(buf, 2) = - bl->id;
  3756. clif_send(buf, packet_len(0x8a), bl, SELF);
  3757. }
  3758. }
  3759. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3760. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3761. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3762. {
  3763. unsigned char buf[32];
  3764. WBUFW(buf,0) = 0x192;
  3765. WBUFW(buf,2) = x;
  3766. WBUFW(buf,4) = y;
  3767. WBUFW(buf,6) = type;
  3768. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3769. if( fd )
  3770. {
  3771. WFIFOHEAD(fd,packet_len(0x192));
  3772. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3773. WFIFOSET(fd,packet_len(0x192));
  3774. }
  3775. else
  3776. {
  3777. struct block_list dummy_bl;
  3778. dummy_bl.type = BL_NUL;
  3779. dummy_bl.x = x;
  3780. dummy_bl.y = y;
  3781. dummy_bl.m = m;
  3782. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3783. }
  3784. }
  3785. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3786. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3787. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3788. {
  3789. int view,fd;
  3790. fd=sd->fd;
  3791. WFIFOHEAD(fd,packet_len(0x9d));
  3792. WFIFOW(fd,0)=0x9d;
  3793. WFIFOL(fd,2)=fitem->bl.id;
  3794. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3795. WFIFOW(fd,6)=view;
  3796. else
  3797. WFIFOW(fd,6)=fitem->item_data.nameid;
  3798. WFIFOB(fd,8)=fitem->item_data.identify;
  3799. WFIFOW(fd,9)=fitem->bl.x;
  3800. WFIFOW(fd,11)=fitem->bl.y;
  3801. WFIFOW(fd,13)=fitem->item_data.amount;
  3802. WFIFOB(fd,15)=fitem->subx;
  3803. WFIFOB(fd,16)=fitem->suby;
  3804. WFIFOSET(fd,packet_len(0x9d));
  3805. }
  3806. /// Notifies the client of a skill unit.
  3807. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3808. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3809. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3810. {
  3811. int fd = sd->fd;
  3812. if( unit->group->state.guildaura )
  3813. return;
  3814. #if PACKETVER >= 3
  3815. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3816. WFIFOHEAD(fd,packet_len(0x1c9));
  3817. WFIFOW(fd, 0)=0x1c9;
  3818. WFIFOL(fd, 2)=unit->bl.id;
  3819. WFIFOL(fd, 6)=unit->group->src_id;
  3820. WFIFOW(fd,10)=unit->bl.x;
  3821. WFIFOW(fd,12)=unit->bl.y;
  3822. WFIFOB(fd,14)=unit->group->unit_id;
  3823. WFIFOB(fd,15)=1;
  3824. WFIFOB(fd,16)=1;
  3825. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3826. WFIFOSET(fd,packet_len(0x1c9));
  3827. return;
  3828. }
  3829. #endif
  3830. WFIFOHEAD(fd,packet_len(0x11f));
  3831. WFIFOW(fd, 0)=0x11f;
  3832. WFIFOL(fd, 2)=unit->bl.id;
  3833. WFIFOL(fd, 6)=unit->group->src_id;
  3834. WFIFOW(fd,10)=unit->bl.x;
  3835. WFIFOW(fd,12)=unit->bl.y;
  3836. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3837. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3838. else
  3839. WFIFOB(fd,14)=unit->group->unit_id;
  3840. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3841. WFIFOSET(fd,packet_len(0x11f));
  3842. if(unit->group->skill_id == WZ_ICEWALL)
  3843. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3844. }
  3845. /*==========================================
  3846. * Server tells client to remove unit of id 'unit->bl.id'
  3847. *------------------------------------------*/
  3848. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3849. {
  3850. nullpo_retv(unit);
  3851. WFIFOHEAD(fd,packet_len(0x120));
  3852. WFIFOW(fd, 0)=0x120;
  3853. WFIFOL(fd, 2)=unit->bl.id;
  3854. WFIFOSET(fd,packet_len(0x120));
  3855. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3856. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3857. }
  3858. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3859. /// 0120 <id>.L
  3860. void clif_skill_delunit(struct skill_unit *unit)
  3861. {
  3862. unsigned char buf[16];
  3863. nullpo_retv(unit);
  3864. WBUFW(buf, 0)=0x120;
  3865. WBUFL(buf, 2)=unit->bl.id;
  3866. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3867. }
  3868. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3869. /// 01ac <id>.L
  3870. /// Only affects units with class [139,153] client-side.
  3871. void clif_skillunit_update(struct block_list* bl)
  3872. {
  3873. unsigned char buf[6];
  3874. nullpo_retv(bl);
  3875. WBUFW(buf,0) = 0x1ac;
  3876. WBUFL(buf,2) = bl->id;
  3877. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3878. }
  3879. /*==========================================
  3880. *
  3881. *------------------------------------------*/
  3882. static int clif_getareachar(struct block_list* bl,va_list ap)
  3883. {
  3884. struct map_session_data *sd;
  3885. nullpo_ret(bl);
  3886. sd=va_arg(ap,struct map_session_data*);
  3887. if (sd == NULL || !sd->fd)
  3888. return 0;
  3889. switch(bl->type){
  3890. case BL_ITEM:
  3891. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3892. break;
  3893. case BL_SKILL:
  3894. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3895. break;
  3896. default:
  3897. if(&sd->bl == bl)
  3898. break;
  3899. clif_getareachar_unit(sd,bl);
  3900. break;
  3901. }
  3902. return 0;
  3903. }
  3904. /*==========================================
  3905. * tbl has gone out of view-size of bl
  3906. *------------------------------------------*/
  3907. int clif_outsight(struct block_list *bl,va_list ap)
  3908. {
  3909. struct block_list *tbl;
  3910. struct view_data *vd;
  3911. TBL_PC *sd, *tsd;
  3912. tbl=va_arg(ap,struct block_list*);
  3913. if(bl == tbl) return 0;
  3914. sd = BL_CAST(BL_PC, bl);
  3915. tsd = BL_CAST(BL_PC, tbl);
  3916. if (tsd && tsd->fd)
  3917. { //tsd has lost sight of the bl object.
  3918. switch(bl->type){
  3919. case BL_PC:
  3920. if (sd->vd.class_ != INVISIBLE_CLASS)
  3921. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3922. if(sd->chatID){
  3923. struct chat_data *cd;
  3924. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3925. if(cd->usersd[0]==sd)
  3926. clif_dispchat(cd,tsd->fd);
  3927. }
  3928. if( sd->state.vending )
  3929. clif_closevendingboard(bl,tsd->fd);
  3930. if( sd->state.buyingstore )
  3931. clif_buyingstore_disappear_entry_single(tsd, sd);
  3932. break;
  3933. case BL_ITEM:
  3934. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3935. break;
  3936. case BL_SKILL:
  3937. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3938. break;
  3939. case BL_NPC:
  3940. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  3941. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3942. break;
  3943. default:
  3944. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3945. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3946. break;
  3947. }
  3948. }
  3949. if (sd && sd->fd)
  3950. { //sd is watching tbl go out of view.
  3951. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  3952. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  3953. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3954. }
  3955. return 0;
  3956. }
  3957. /*==========================================
  3958. * tbl has come into view of bl
  3959. *------------------------------------------*/
  3960. int clif_insight(struct block_list *bl,va_list ap)
  3961. {
  3962. struct block_list *tbl;
  3963. TBL_PC *sd, *tsd;
  3964. tbl=va_arg(ap,struct block_list*);
  3965. if (bl == tbl) return 0;
  3966. sd = BL_CAST(BL_PC, bl);
  3967. tsd = BL_CAST(BL_PC, tbl);
  3968. if (tsd && tsd->fd)
  3969. { //Tell tsd that bl entered into his view
  3970. switch(bl->type){
  3971. case BL_ITEM:
  3972. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3973. break;
  3974. case BL_SKILL:
  3975. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3976. break;
  3977. default:
  3978. clif_getareachar_unit(tsd,bl);
  3979. break;
  3980. }
  3981. }
  3982. if (sd && sd->fd)
  3983. { //Tell sd that tbl walked into his view
  3984. clif_getareachar_unit(sd,tbl);
  3985. }
  3986. return 0;
  3987. }
  3988. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  3989. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  3990. void clif_skillinfoblock(struct map_session_data *sd)
  3991. {
  3992. int fd;
  3993. int i,len,id;
  3994. nullpo_retv(sd);
  3995. fd=sd->fd;
  3996. if (!fd) return;
  3997. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3998. WFIFOW(fd,0) = 0x10f;
  3999. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4000. {
  4001. if( (id = sd->status.skill[i].id) != 0 )
  4002. {
  4003. // workaround for bugreport:5348
  4004. if (len + 37 > 8192)
  4005. break;
  4006. WFIFOW(fd,len) = id;
  4007. WFIFOL(fd,len+2) = skill_get_inf(id);
  4008. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4009. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4010. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4011. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4012. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4013. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4014. else
  4015. WFIFOB(fd,len+36) = 0;
  4016. len += 37;
  4017. }
  4018. }
  4019. WFIFOW(fd,2)=len;
  4020. WFIFOSET(fd,len);
  4021. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4022. for ( ; i < MAX_SKILL; i++)
  4023. {
  4024. if( (id = sd->status.skill[i].id) != 0 )
  4025. {
  4026. clif_addskill(sd, id);
  4027. clif_skillinfo(sd, id, 0);
  4028. }
  4029. }
  4030. }
  4031. /**
  4032. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4033. **/
  4034. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4035. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4036. void clif_addskill(struct map_session_data *sd, int id)
  4037. {
  4038. int fd;
  4039. nullpo_retv(sd);
  4040. fd = sd->fd;
  4041. if (!fd) return;
  4042. if( sd->status.skill[id].id <= 0 )
  4043. return;
  4044. WFIFOHEAD(fd, packet_len(0x111));
  4045. WFIFOW(fd,0) = 0x111;
  4046. WFIFOW(fd,2) = id;
  4047. WFIFOL(fd,4) = skill_get_inf(id);
  4048. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4049. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4050. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4051. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4052. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4053. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4054. else
  4055. WFIFOB(fd,38) = 0;
  4056. WFIFOSET(fd,packet_len(0x111));
  4057. }
  4058. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4059. /// 0441 <skill id>.W
  4060. void clif_deleteskill(struct map_session_data *sd, int id)
  4061. {
  4062. #if PACKETVER >= 20081217
  4063. int fd;
  4064. nullpo_retv(sd);
  4065. fd = sd->fd;
  4066. if( !fd ) return;
  4067. WFIFOHEAD(fd,packet_len(0x441));
  4068. WFIFOW(fd,0) = 0x441;
  4069. WFIFOW(fd,2) = id;
  4070. WFIFOSET(fd,packet_len(0x441));
  4071. #else
  4072. clif_skillinfoblock(sd);
  4073. #endif
  4074. }
  4075. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4076. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4077. void clif_skillup(struct map_session_data *sd,int skill_num)
  4078. {
  4079. int fd;
  4080. nullpo_retv(sd);
  4081. fd=sd->fd;
  4082. WFIFOHEAD(fd,packet_len(0x10e));
  4083. WFIFOW(fd,0) = 0x10e;
  4084. WFIFOW(fd,2) = skill_num;
  4085. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  4086. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  4087. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  4088. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  4089. WFIFOSET(fd,packet_len(0x10e));
  4090. }
  4091. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4092. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4093. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4094. {
  4095. const int fd = sd->fd;
  4096. WFIFOHEAD(fd,packet_len(0x7e1));
  4097. WFIFOW(fd,0) = 0x7e1;
  4098. WFIFOW(fd,2) = skill;
  4099. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4100. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4101. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4102. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4103. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4104. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4105. else
  4106. WFIFOB(fd,14) = 0;
  4107. WFIFOSET(fd,packet_len(0x7e1));
  4108. }
  4109. /// Notifies clients in area, that an object is about to use a skill.
  4110. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4111. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4112. /// property:
  4113. /// 0 = Yellow cast aura
  4114. /// 1 = Water elemental cast aura
  4115. /// 2 = Earth elemental cast aura
  4116. /// 3 = Fire elemental cast aura
  4117. /// 4 = Wind elemental cast aura
  4118. /// 5 = Poison elemental cast aura
  4119. /// 6 = Holy elemental cast aura
  4120. /// ? = like 0
  4121. /// is disposable:
  4122. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4123. /// 1 = no text
  4124. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, int skill_num, int property, int casttime)
  4125. {
  4126. #if PACKETVER < 20091124
  4127. const int cmd = 0x13e;
  4128. #else
  4129. const int cmd = 0x7fb;
  4130. #endif
  4131. unsigned char buf[32];
  4132. WBUFW(buf,0) = cmd;
  4133. WBUFL(buf,2) = src_id;
  4134. WBUFL(buf,6) = dst_id;
  4135. WBUFW(buf,10) = dst_x;
  4136. WBUFW(buf,12) = dst_y;
  4137. WBUFW(buf,14) = skill_num;
  4138. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4139. WBUFL(buf,20) = casttime;
  4140. #if PACKETVER >= 20091124
  4141. WBUFB(buf,24) = 0; // isDisposable
  4142. #endif
  4143. if (disguised(bl)) {
  4144. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4145. WBUFL(buf,2) = -src_id;
  4146. clif_send(buf,packet_len(cmd), bl, SELF);
  4147. } else
  4148. clif_send(buf,packet_len(cmd), bl, AREA);
  4149. }
  4150. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4151. /// 01b9 <id>.L
  4152. void clif_skillcastcancel(struct block_list* bl)
  4153. {
  4154. unsigned char buf[16];
  4155. nullpo_retv(bl);
  4156. WBUFW(buf,0) = 0x1b9;
  4157. WBUFL(buf,2) = bl->id;
  4158. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4159. }
  4160. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4161. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4162. /// num (only used when skill id = NV_BASIC and cause = 0):
  4163. /// 0 = "skill failed" MsgStringTable[159]
  4164. /// 1 = "no emotions" MsgStringTable[160]
  4165. /// 2 = "no sit" MsgStringTable[161]
  4166. /// 3 = "no chat" MsgStringTable[162]
  4167. /// 4 = "no party" MsgStringTable[163]
  4168. /// 5 = "no shout" MsgStringTable[164]
  4169. /// 6 = "no PKing" MsgStringTable[165]
  4170. /// 7 = "no alligning" MsgStringTable[383]
  4171. /// ? = ignored
  4172. /// cause:
  4173. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4174. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4175. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4176. /// "skill failed" MsgStringTable[204] (otherwise)
  4177. /// ... = @see enum useskill_fail_cause
  4178. /// ? = ignored
  4179. ///
  4180. /// if(result!=0) doesn't display any of the previous messages
  4181. /// Note: when this packet is received an unknown flag is always set to 0,
  4182. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4183. void clif_skill_fail(struct map_session_data *sd,int skill_id,enum useskill_fail_cause cause,int btype)
  4184. {
  4185. int fd;
  4186. if (!sd) { //Since this is the most common nullpo....
  4187. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4188. return;
  4189. }
  4190. fd=sd->fd;
  4191. if (!fd) return;
  4192. if(battle_config.display_skill_fail&1)
  4193. return; //Disable all skill failed messages
  4194. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4195. return; //Disable delay failed messages
  4196. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4197. return;
  4198. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4199. return;
  4200. WFIFOHEAD(fd,packet_len(0x110));
  4201. WFIFOW(fd,0) = 0x110;
  4202. WFIFOW(fd,2) = skill_id;
  4203. WFIFOL(fd,4) = btype;
  4204. WFIFOB(fd,8) = 0;// success
  4205. WFIFOB(fd,9) = cause;
  4206. WFIFOSET(fd,packet_len(0x110));
  4207. }
  4208. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4209. /// 043d <skill ID>.W <tick>.L
  4210. void clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  4211. {
  4212. #if PACKETVER>=20081112
  4213. int fd;
  4214. nullpo_retv(sd);
  4215. fd=sd->fd;
  4216. WFIFOHEAD(fd,packet_len(0x43d));
  4217. WFIFOW(fd,0) = 0x43d;
  4218. WFIFOW(fd,2) = skillid;
  4219. WFIFOL(fd,4) = tick;
  4220. WFIFOSET(fd,packet_len(0x43d));
  4221. #endif
  4222. }
  4223. /// Skill attack effect and damage.
  4224. /// 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)
  4225. /// 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)
  4226. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4227. {
  4228. unsigned char buf[64];
  4229. struct status_change *sc;
  4230. nullpo_ret(src);
  4231. nullpo_ret(dst);
  4232. type = clif_calc_delay(type,div,damage,ddelay);
  4233. sc = status_get_sc(dst);
  4234. if(sc && sc->count) {
  4235. if(sc->data[SC_HALLUCINATION] && damage)
  4236. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4237. }
  4238. #if PACKETVER < 3
  4239. WBUFW(buf,0)=0x114;
  4240. WBUFW(buf,2)=skill_id;
  4241. WBUFL(buf,4)=src->id;
  4242. WBUFL(buf,8)=dst->id;
  4243. WBUFL(buf,12)=tick;
  4244. WBUFL(buf,16)=sdelay;
  4245. WBUFL(buf,20)=ddelay;
  4246. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4247. WBUFW(buf,24)=damage?div:0;
  4248. } else {
  4249. WBUFW(buf,24)=damage;
  4250. }
  4251. WBUFW(buf,26)=skill_lv;
  4252. WBUFW(buf,28)=div;
  4253. WBUFB(buf,30)=type;
  4254. if (disguised(dst)) {
  4255. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4256. WBUFL(buf,8)=-dst->id;
  4257. clif_send(buf,packet_len(0x114),dst,SELF);
  4258. } else
  4259. clif_send(buf,packet_len(0x114),dst,AREA);
  4260. if(disguised(src)) {
  4261. WBUFL(buf,4)=-src->id;
  4262. if (disguised(dst))
  4263. WBUFL(buf,8)=dst->id;
  4264. if(damage > 0)
  4265. WBUFW(buf,24)=-1;
  4266. clif_send(buf,packet_len(0x114),src,SELF);
  4267. }
  4268. #else
  4269. WBUFW(buf,0)=0x1de;
  4270. WBUFW(buf,2)=skill_id;
  4271. WBUFL(buf,4)=src->id;
  4272. WBUFL(buf,8)=dst->id;
  4273. WBUFL(buf,12)=tick;
  4274. WBUFL(buf,16)=sdelay;
  4275. WBUFL(buf,20)=ddelay;
  4276. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4277. WBUFL(buf,24)=damage?div:0;
  4278. } else {
  4279. WBUFL(buf,24)=damage;
  4280. }
  4281. WBUFW(buf,28)=skill_lv;
  4282. WBUFW(buf,30)=div;
  4283. WBUFB(buf,32)=type;
  4284. if (disguised(dst)) {
  4285. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4286. WBUFL(buf,8)=-dst->id;
  4287. clif_send(buf,packet_len(0x1de),dst,SELF);
  4288. } else
  4289. clif_send(buf,packet_len(0x1de),dst,AREA);
  4290. if(disguised(src)) {
  4291. WBUFL(buf,4)=-src->id;
  4292. if (disguised(dst))
  4293. WBUFL(buf,8)=dst->id;
  4294. if(damage > 0)
  4295. WBUFL(buf,24)=-1;
  4296. clif_send(buf,packet_len(0x1de),src,SELF);
  4297. }
  4298. #endif
  4299. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4300. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4301. }
  4302. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4303. /// 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
  4304. /*
  4305. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4306. {
  4307. unsigned char buf[64];
  4308. struct status_change *sc;
  4309. nullpo_ret(src);
  4310. nullpo_ret(dst);
  4311. type = (type>0)?type:skill_get_hit(skill_id);
  4312. type = clif_calc_delay(type,div,damage,ddelay);
  4313. sc = status_get_sc(dst);
  4314. if(sc && sc->count) {
  4315. if(sc->data[SC_HALLUCINATION] && damage)
  4316. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4317. }
  4318. WBUFW(buf,0)=0x115;
  4319. WBUFW(buf,2)=skill_id;
  4320. WBUFL(buf,4)=src->id;
  4321. WBUFL(buf,8)=dst->id;
  4322. WBUFL(buf,12)=tick;
  4323. WBUFL(buf,16)=sdelay;
  4324. WBUFL(buf,20)=ddelay;
  4325. WBUFW(buf,24)=dst->x;
  4326. WBUFW(buf,26)=dst->y;
  4327. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4328. WBUFW(buf,28)=damage?div:0;
  4329. } else {
  4330. WBUFW(buf,28)=damage;
  4331. }
  4332. WBUFW(buf,30)=skill_lv;
  4333. WBUFW(buf,32)=div;
  4334. WBUFB(buf,34)=type;
  4335. clif_send(buf,packet_len(0x115),src,AREA);
  4336. if(disguised(src)) {
  4337. WBUFL(buf,4)=-src->id;
  4338. if(damage > 0)
  4339. WBUFW(buf,28)=-1;
  4340. clif_send(buf,packet_len(0x115),src,SELF);
  4341. }
  4342. if (disguised(dst)) {
  4343. WBUFL(buf,8)=-dst->id;
  4344. if (disguised(src))
  4345. WBUFL(buf,4)=src->id;
  4346. else if(damage > 0)
  4347. WBUFW(buf,28)=-1;
  4348. clif_send(buf,packet_len(0x115),dst,SELF);
  4349. }
  4350. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4351. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4352. }
  4353. */
  4354. /// Non-damaging skill effect (ZC_USE_SKILL).
  4355. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4356. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  4357. {
  4358. unsigned char buf[32];
  4359. nullpo_ret(dst);
  4360. WBUFW(buf,0)=0x11a;
  4361. WBUFW(buf,2)=skill_id;
  4362. WBUFW(buf,4)=min(heal, INT16_MAX);
  4363. WBUFL(buf,6)=dst->id;
  4364. WBUFL(buf,10)=src?src->id:0;
  4365. WBUFB(buf,14)=fail;
  4366. if (disguised(dst)) {
  4367. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4368. WBUFL(buf,6)=-dst->id;
  4369. clif_send(buf,packet_len(0x11a),dst,SELF);
  4370. } else
  4371. clif_send(buf,packet_len(0x11a),dst,AREA);
  4372. if(src && disguised(src)) {
  4373. WBUFL(buf,10)=-src->id;
  4374. if (disguised(dst))
  4375. WBUFL(buf,6)=dst->id;
  4376. clif_send(buf,packet_len(0x11a),src,SELF);
  4377. }
  4378. return fail;
  4379. }
  4380. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4381. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4382. void clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4383. {
  4384. unsigned char buf[32];
  4385. nullpo_retv(src);
  4386. WBUFW(buf,0)=0x117;
  4387. WBUFW(buf,2)=skill_id;
  4388. WBUFL(buf,4)=src->id;
  4389. WBUFW(buf,8)=val;
  4390. WBUFW(buf,10)=x;
  4391. WBUFW(buf,12)=y;
  4392. WBUFL(buf,14)=tick;
  4393. if(disguised(src)) {
  4394. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4395. WBUFL(buf,4)=-src->id;
  4396. clif_send(buf,packet_len(0x117),src,SELF);
  4397. } else
  4398. clif_send(buf,packet_len(0x117),src,AREA);
  4399. }
  4400. /*==========================================
  4401. * Tells all client's nearby 'unit' sight range that it spawned
  4402. *------------------------------------------*/
  4403. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4404. void clif_skill_setunit(struct skill_unit *unit)
  4405. {
  4406. unsigned char buf[128];
  4407. nullpo_retv(unit);
  4408. if( unit->group->state.guildaura )
  4409. return;
  4410. #if PACKETVER >= 3
  4411. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4412. WBUFW(buf, 0)=0x1c9;
  4413. WBUFL(buf, 2)=unit->bl.id;
  4414. WBUFL(buf, 6)=unit->group->src_id;
  4415. WBUFW(buf,10)=unit->bl.x;
  4416. WBUFW(buf,12)=unit->bl.y;
  4417. WBUFB(buf,14)=unit->group->unit_id;
  4418. WBUFB(buf,15)=1;
  4419. WBUFB(buf,16)=1;
  4420. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4421. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4422. return;
  4423. }
  4424. #endif
  4425. WBUFW(buf, 0)=0x11f;
  4426. WBUFL(buf, 2)=unit->bl.id;
  4427. WBUFL(buf, 6)=unit->group->src_id;
  4428. WBUFW(buf,10)=unit->bl.x;
  4429. WBUFW(buf,12)=unit->bl.y;
  4430. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4431. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4432. else
  4433. WBUFB(buf,14)=unit->group->unit_id;
  4434. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4435. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4436. }
  4437. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4438. /// 011c <skill id>.W { <map name>.16B }*4
  4439. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4440. {
  4441. int fd;
  4442. nullpo_retv(sd);
  4443. fd = sd->fd;
  4444. WFIFOHEAD(fd,packet_len(0x11c));
  4445. WFIFOW(fd,0) = 0x11c;
  4446. WFIFOW(fd,2) = skill_num;
  4447. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4448. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4449. else // normal map name
  4450. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4451. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4452. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4453. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4454. WFIFOSET(fd,packet_len(0x11c));
  4455. sd->menuskill_id = skill_num;
  4456. if (skill_num == AL_WARP)
  4457. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4458. else
  4459. sd->menuskill_val = skill_lv;
  4460. }
  4461. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4462. /// 011e <type>.B
  4463. /// type:
  4464. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4465. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4466. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4467. ///
  4468. /// @param sd Who receives the message
  4469. /// @param type What message
  4470. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4471. {
  4472. int fd;
  4473. nullpo_retv(sd);
  4474. fd=sd->fd;
  4475. WFIFOHEAD(fd,packet_len(0x11e));
  4476. WFIFOW(fd,0)=0x11e;
  4477. WFIFOB(fd,2)=type;
  4478. WFIFOSET(fd,packet_len(0x11e));
  4479. }
  4480. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4481. /// 0189 <type>.W
  4482. /// type:
  4483. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4484. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4485. ///
  4486. /// @param sd Who receives the message
  4487. /// @param type What message
  4488. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4489. {
  4490. int fd;
  4491. nullpo_retv(sd);
  4492. fd=sd->fd;
  4493. WFIFOHEAD(fd,packet_len(0x189));
  4494. WFIFOW(fd,0)=0x189;
  4495. WFIFOW(fd,2)=type;
  4496. WFIFOSET(fd,packet_len(0x189));
  4497. }
  4498. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4499. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4500. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4501. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4502. {
  4503. struct status_data *status;
  4504. unsigned char buf[64];
  4505. int i;//, fix;
  4506. nullpo_retv(sd);
  4507. nullpo_retv(dst);
  4508. if( dst->type != BL_MOB )
  4509. return;
  4510. status = status_get_status_data(dst);
  4511. WBUFW(buf, 0)=0x18c;
  4512. WBUFW(buf, 2)=status_get_class(dst);
  4513. WBUFW(buf, 4)=status_get_lv(dst);
  4514. WBUFW(buf, 6)=status->size;
  4515. WBUFL(buf, 8)=status->hp;
  4516. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4517. +(battle_config.estimation_type&2?status->def2:0);
  4518. WBUFW(buf,14)=status->race;
  4519. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4520. +(battle_config.estimation_type&2?status->mdef2:0);
  4521. WBUFW(buf,18)= status->def_ele;
  4522. for(i=0;i<9;i++)
  4523. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4524. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4525. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4526. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4527. }
  4528. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4529. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4530. /// material id:
  4531. /// unused by the client
  4532. void clif_skill_produce_mix_list(struct map_session_data *sd, int skillid , int trigger)
  4533. {
  4534. int i,c,view,fd;
  4535. nullpo_retv(sd);
  4536. if(sd->menuskill_id == skillid)
  4537. return; //Avoid resending the menu twice or more times...
  4538. fd=sd->fd;
  4539. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4540. WFIFOW(fd, 0)=0x18d;
  4541. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4542. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4543. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4544. WFIFOW(fd,c*8+ 4)= view;
  4545. else
  4546. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4547. WFIFOW(fd,c*8+ 6)= 0;
  4548. WFIFOW(fd,c*8+ 8)= 0;
  4549. WFIFOW(fd,c*8+10)= 0;
  4550. c++;
  4551. }
  4552. }
  4553. WFIFOW(fd, 2)=c*8+8;
  4554. WFIFOSET(fd,WFIFOW(fd,2));
  4555. if(c > 0) {
  4556. sd->menuskill_id = skillid;
  4557. sd->menuskill_val = trigger;
  4558. return;
  4559. }
  4560. }
  4561. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4562. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4563. /// mk type:
  4564. /// 1 = cooking
  4565. /// 2 = arrow
  4566. /// 3 = elemental
  4567. /// 4 = GN_MIX_COOKING
  4568. /// 5 = GN_MAKEBOMB
  4569. /// 6 = GN_S_PHARMACY
  4570. void clif_cooking_list(struct map_session_data *sd, int trigger, int skill_id, int qty, int list_type)
  4571. {
  4572. int fd;
  4573. int i, c;
  4574. int view;
  4575. nullpo_retv(sd);
  4576. fd = sd->fd;
  4577. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4578. WFIFOW(fd,0) = 0x25a;
  4579. WFIFOW(fd,4) = list_type; // list type
  4580. c = 0;
  4581. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4582. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4583. continue;
  4584. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4585. WFIFOW(fd, 6 + 2 * c) = view;
  4586. else
  4587. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4588. c++;
  4589. }
  4590. if( skill_id == AM_PHARMACY ) { // Only send it while Cooking else check for c.
  4591. WFIFOW(fd,2) = 6 + 2 * c;
  4592. WFIFOSET(fd,WFIFOW(fd,2));
  4593. }
  4594. if( c > 0 ) {
  4595. sd->menuskill_id = skill_id;
  4596. sd->menuskill_val = trigger;
  4597. if( skill_id != AM_PHARMACY ) {
  4598. sd->menuskill_val2 = qty; // amount.
  4599. WFIFOW(fd,2) = 6 + 2 * c;
  4600. WFIFOSET(fd,WFIFOW(fd,2));
  4601. }
  4602. } else {
  4603. clif_menuskill_clear(sd);
  4604. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4605. // It fails.
  4606. #if PACKETVER >= 20090922
  4607. clif_msg_skill(sd,skill_id,0x625);
  4608. #else
  4609. WFIFOW(fd,2) = 6 + 2 * c;
  4610. WFIFOSET(fd,WFIFOW(fd,2));
  4611. #endif
  4612. }
  4613. }
  4614. }
  4615. /// Notifies clients of a status change.
  4616. /// 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)]
  4617. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4618. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4619. {
  4620. unsigned char buf[32];
  4621. struct map_session_data *sd;
  4622. if (type == SI_BLANK) //It shows nothing on the client...
  4623. return;
  4624. nullpo_retv(bl);
  4625. sd = BL_CAST(BL_PC, bl);
  4626. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4627. return;
  4628. if(flag && battle_config.display_status_timers && sd)
  4629. WBUFW(buf,0)=0x43f;
  4630. else
  4631. WBUFW(buf,0)=0x196;
  4632. WBUFW(buf,2)=type;
  4633. WBUFL(buf,4)=bl->id;
  4634. WBUFB(buf,8)=flag;
  4635. if(flag && battle_config.display_status_timers && sd)
  4636. {
  4637. if (tick <= 0)
  4638. tick = 9999; // this is indeed what official servers do
  4639. WBUFL(buf,9) = tick;
  4640. WBUFL(buf,13) = val1;
  4641. WBUFL(buf,17) = val2;
  4642. WBUFL(buf,21) = val3;
  4643. }
  4644. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4645. }
  4646. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4647. /// 008e <packet len>.W <message>.?B
  4648. void clif_displaymessage(const int fd, const char* mes)
  4649. {
  4650. nullpo_retv(mes);
  4651. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4652. if (fd == 0)
  4653. ;
  4654. else {
  4655. char *message, *line;
  4656. message = aStrdup(mes);
  4657. line = strtok(message, "\n");
  4658. while(line != NULL) {
  4659. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4660. int len = strnlen(line, 255);
  4661. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4662. WFIFOHEAD(fd, 5 + len);
  4663. WFIFOW(fd,0) = 0x8e;
  4664. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4665. safestrncpy(WFIFOP(fd,4), line, len + 1);
  4666. WFIFOSET(fd, 5 + len);
  4667. }
  4668. line = strtok(NULL, "\n");
  4669. }
  4670. aFree(message);
  4671. }
  4672. }
  4673. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4674. /// 009a <packet len>.W <message>.?B
  4675. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4676. {
  4677. int lp = type ? 4 : 0;
  4678. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4679. WBUFW(buf,0) = 0x9a;
  4680. WBUFW(buf,2) = 4 + lp + len;
  4681. if (type == 0x10) // bc_blue
  4682. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4683. else if (type == 0x20) // bc_woe
  4684. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4685. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4686. clif_send(buf, WBUFW(buf,2), bl, target);
  4687. if (buf)
  4688. aFree(buf);
  4689. }
  4690. /*==========================================
  4691. * Displays a message on a 'bl' to all it's nearby clients
  4692. * Used by npc_globalmessage
  4693. *------------------------------------------*/
  4694. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4695. {
  4696. char buf[100];
  4697. int len;
  4698. nullpo_retv(bl);
  4699. if(!message)
  4700. return;
  4701. len = strlen(message)+1;
  4702. if( len > sizeof(buf)-8 )
  4703. {
  4704. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4705. len = sizeof(buf)-8;
  4706. }
  4707. WBUFW(buf,0)=0x8d;
  4708. WBUFW(buf,2)=len+8;
  4709. WBUFL(buf,4)=bl->id;
  4710. safestrncpy((char *) WBUFP(buf,8),message,len);
  4711. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4712. }
  4713. /*==========================================
  4714. * Send main chat message [LuzZza]
  4715. *------------------------------------------*/
  4716. void clif_MainChatMessage(const char* message)
  4717. {
  4718. uint8 buf[200];
  4719. int len;
  4720. if(!message)
  4721. return;
  4722. len = strlen(message)+1;
  4723. if (len+8 > sizeof(buf)) {
  4724. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4725. len = sizeof(buf)-8;
  4726. }
  4727. WBUFW(buf,0)=0x8d;
  4728. WBUFW(buf,2)=len+8;
  4729. WBUFL(buf,4)=0;
  4730. safestrncpy((char *) WBUFP(buf,8),message,len);
  4731. clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4732. }
  4733. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4734. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4735. 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)
  4736. {
  4737. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4738. WBUFW(buf,0) = 0x1c3;
  4739. WBUFW(buf,2) = len + 16;
  4740. WBUFL(buf,4) = fontColor;
  4741. WBUFW(buf,8) = fontType;
  4742. WBUFW(buf,10) = fontSize;
  4743. WBUFW(buf,12) = fontAlign;
  4744. WBUFW(buf,14) = fontY;
  4745. memcpy(WBUFP(buf,16), mes, len);
  4746. clif_send(buf, WBUFW(buf,2), bl, target);
  4747. if (buf)
  4748. aFree(buf);
  4749. }
  4750. /// Displays heal effect (ZC_RECOVERY).
  4751. /// 013d <var id>.W <amount>.W
  4752. /// var id:
  4753. /// 5 = HP (SP_HP)
  4754. /// 7 = SP (SP_SP)
  4755. /// ? = ignored
  4756. void clif_heal(int fd,int type,int val)
  4757. {
  4758. WFIFOHEAD(fd,packet_len(0x13d));
  4759. WFIFOW(fd,0)=0x13d;
  4760. WFIFOW(fd,2)=type;
  4761. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4762. WFIFOSET(fd,packet_len(0x13d));
  4763. }
  4764. /// Displays resurrection effect (ZC_RESURRECTION).
  4765. /// 0148 <id>.L <type>.W
  4766. /// type:
  4767. /// ignored
  4768. void clif_resurrection(struct block_list *bl,int type)
  4769. {
  4770. unsigned char buf[16];
  4771. nullpo_retv(bl);
  4772. WBUFW(buf,0)=0x148;
  4773. WBUFL(buf,2)=bl->id;
  4774. WBUFW(buf,6)=0;
  4775. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4776. if (disguised(bl))
  4777. clif_spawn(bl);
  4778. }
  4779. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4780. /// 0199 <type>.W
  4781. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4782. {
  4783. int fd;
  4784. nullpo_retv(sd);
  4785. fd=sd->fd;
  4786. WFIFOHEAD(fd,packet_len(0x199));
  4787. WFIFOW(fd,0)=0x199;
  4788. WFIFOW(fd,2)=property;
  4789. WFIFOSET(fd,packet_len(0x199));
  4790. }
  4791. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4792. /// 01d6 <type>.W
  4793. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4794. {
  4795. int fd;
  4796. nullpo_retv(sd);
  4797. fd=sd->fd;
  4798. WFIFOHEAD(fd,packet_len(0x1D6));
  4799. WFIFOW(fd,0)=0x1D6;
  4800. WFIFOW(fd,2)=type;
  4801. WFIFOSET(fd,packet_len(0x1D6));
  4802. }
  4803. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4804. /// 019a <id>.L <ranking>.L <total>.L
  4805. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4806. {
  4807. if(type == 2) {
  4808. int fd = sd->fd;
  4809. WFIFOHEAD(fd,packet_len(0x19a));
  4810. WFIFOW(fd,0) = 0x19a;
  4811. WFIFOL(fd,2) = sd->bl.id;
  4812. WFIFOL(fd,6) = pvprank;
  4813. WFIFOL(fd,10) = pvpnum;
  4814. WFIFOSET(fd,packet_len(0x19a));
  4815. } else {
  4816. unsigned char buf[32];
  4817. WBUFW(buf,0) = 0x19a;
  4818. WBUFL(buf,2) = sd->bl.id;
  4819. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4820. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4821. else
  4822. WBUFL(buf,6) = pvprank;
  4823. WBUFL(buf,10) = pvpnum;
  4824. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4825. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4826. else if(!type)
  4827. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4828. else
  4829. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4830. }
  4831. }
  4832. /*==========================================
  4833. *
  4834. *------------------------------------------*/
  4835. void clif_map_property_mapall(int map, enum map_property property)
  4836. {
  4837. struct block_list bl;
  4838. unsigned char buf[16];
  4839. bl.id = 0;
  4840. bl.type = BL_NUL;
  4841. bl.m = map;
  4842. WBUFW(buf,0)=0x199;
  4843. WBUFW(buf,2)=property;
  4844. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4845. }
  4846. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4847. /// 0188 <result>.W <index>.W <refine>.W
  4848. /// result:
  4849. /// 0 = success
  4850. /// 1 = failure
  4851. /// 2 = downgrade
  4852. void clif_refine(int fd, int fail, int index, int val)
  4853. {
  4854. WFIFOHEAD(fd,packet_len(0x188));
  4855. WFIFOW(fd,0)=0x188;
  4856. WFIFOW(fd,2)=fail;
  4857. WFIFOW(fd,4)=index+2;
  4858. WFIFOW(fd,6)=val;
  4859. WFIFOSET(fd,packet_len(0x188));
  4860. }
  4861. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4862. /// 0223 <result>.L <nameid>.W
  4863. /// result:
  4864. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4865. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4866. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4867. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4868. void clif_upgrademessage(int fd, int result, int item_id)
  4869. {
  4870. WFIFOHEAD(fd,packet_len(0x223));
  4871. WFIFOW(fd,0)=0x223;
  4872. WFIFOL(fd,2)=result;
  4873. WFIFOW(fd,6)=item_id;
  4874. WFIFOSET(fd,packet_len(0x223));
  4875. }
  4876. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4877. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4878. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4879. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4880. {
  4881. #if PACKETVER < 20091104
  4882. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4883. WFIFOW(fd,0) = 0x97;
  4884. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4885. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4886. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4887. WFIFOSET(fd,WFIFOW(fd,2));
  4888. #else
  4889. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4890. WFIFOW(fd,0) = 0x97;
  4891. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4892. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4893. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4894. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  4895. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4896. WFIFOSET(fd,WFIFOW(fd,2));
  4897. #endif
  4898. }
  4899. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  4900. /// 0098 <result>.B
  4901. /// result:
  4902. /// 0 = success to send wisper
  4903. /// 1 = target character is not loged in
  4904. /// 2 = ignored by target
  4905. /// 3 = everyone ignored by target
  4906. void clif_wis_end(int fd, int flag)
  4907. {
  4908. WFIFOHEAD(fd,packet_len(0x98));
  4909. WFIFOW(fd,0) = 0x98;
  4910. WFIFOW(fd,2) = flag;
  4911. WFIFOSET(fd,packet_len(0x98));
  4912. }
  4913. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  4914. /// 0194 <char id>.L <name>.24B
  4915. void clif_solved_charname(int fd, int charid, const char* name)
  4916. {
  4917. WFIFOHEAD(fd,packet_len(0x194));
  4918. WFIFOW(fd,0)=0x194;
  4919. WFIFOL(fd,2)=charid;
  4920. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4921. WFIFOSET(fd,packet_len(0x194));
  4922. }
  4923. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  4924. /// 017b <packet len>.W { <name id>.W }*
  4925. void clif_use_card(struct map_session_data *sd,int idx)
  4926. {
  4927. int i,c,ep;
  4928. int fd=sd->fd;
  4929. nullpo_retv(sd);
  4930. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4931. return;
  4932. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4933. return; //Avoid parsing invalid item indexes (no card/no item)
  4934. ep=sd->inventory_data[idx]->equip;
  4935. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4936. WFIFOW(fd,0)=0x17b;
  4937. for(i=c=0;i<MAX_INVENTORY;i++){
  4938. int j;
  4939. if(sd->inventory_data[i] == NULL)
  4940. continue;
  4941. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4942. continue;
  4943. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4944. continue;
  4945. if(sd->status.inventory[i].identify==0 ) //Not identified
  4946. continue;
  4947. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4948. continue;
  4949. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4950. continue;
  4951. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4952. if( j == sd->inventory_data[i]->slot ) // No room
  4953. continue;
  4954. WFIFOW(fd,4+c*2)=i+2;
  4955. c++;
  4956. }
  4957. WFIFOW(fd,2)=4+c*2;
  4958. WFIFOSET(fd,WFIFOW(fd,2));
  4959. }
  4960. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  4961. /// 017d <equip index>.W <card index>.W <result>.B
  4962. /// result:
  4963. /// 0 = success
  4964. /// 1 = failure
  4965. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4966. {
  4967. int fd;
  4968. nullpo_retv(sd);
  4969. fd=sd->fd;
  4970. WFIFOHEAD(fd,packet_len(0x17d));
  4971. WFIFOW(fd,0)=0x17d;
  4972. WFIFOW(fd,2)=idx_equip+2;
  4973. WFIFOW(fd,4)=idx_card+2;
  4974. WFIFOB(fd,6)=flag;
  4975. WFIFOSET(fd,packet_len(0x17d));
  4976. }
  4977. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  4978. /// 0177 <packet len>.W { <name id>.W }*
  4979. void clif_item_identify_list(struct map_session_data *sd)
  4980. {
  4981. int i,c;
  4982. int fd;
  4983. nullpo_retv(sd);
  4984. fd=sd->fd;
  4985. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4986. WFIFOW(fd,0)=0x177;
  4987. for(i=c=0;i<MAX_INVENTORY;i++){
  4988. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4989. WFIFOW(fd,c*2+4)=i+2;
  4990. c++;
  4991. }
  4992. }
  4993. if(c > 0) {
  4994. WFIFOW(fd,2)=c*2+4;
  4995. WFIFOSET(fd,WFIFOW(fd,2));
  4996. sd->menuskill_id = MC_IDENTIFY;
  4997. sd->menuskill_val = c;
  4998. }
  4999. }
  5000. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5001. /// 0179 <index>.W <result>.B
  5002. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5003. {
  5004. int fd;
  5005. nullpo_retv(sd);
  5006. fd=sd->fd;
  5007. WFIFOHEAD(fd,packet_len(0x179));
  5008. WFIFOW(fd, 0)=0x179;
  5009. WFIFOW(fd, 2)=idx+2;
  5010. WFIFOB(fd, 4)=flag;
  5011. WFIFOSET(fd,packet_len(0x179));
  5012. }
  5013. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5014. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5015. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  5016. {
  5017. int i,c;
  5018. int fd;
  5019. int nameid;
  5020. nullpo_retv(sd);
  5021. nullpo_retv(dstsd);
  5022. fd=sd->fd;
  5023. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5024. WFIFOW(fd,0)=0x1fc;
  5025. for(i=c=0;i<MAX_INVENTORY;i++){
  5026. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5027. WFIFOW(fd,c*13+4) = i;
  5028. WFIFOW(fd,c*13+6) = nameid;
  5029. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5030. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5031. c++;
  5032. }
  5033. }
  5034. if(c > 0) {
  5035. WFIFOW(fd,2)=c*13+4;
  5036. WFIFOSET(fd,WFIFOW(fd,2));
  5037. sd->menuskill_id = BS_REPAIRWEAPON;
  5038. sd->menuskill_val = dstsd->bl.id;
  5039. }else
  5040. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  5041. }
  5042. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5043. /// 01fe <index>.W <result>.B
  5044. void clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  5045. {
  5046. int view,fd;
  5047. nullpo_retv(sd);
  5048. fd=sd->fd;
  5049. WFIFOHEAD(fd,packet_len(0x1fe));
  5050. WFIFOW(fd, 0)=0x1fe;
  5051. // FIXME: this is inventory index
  5052. if((view = itemdb_viewid(nameid)) > 0)
  5053. WFIFOW(fd, 2)=view;
  5054. else
  5055. WFIFOW(fd, 2)=nameid;
  5056. WFIFOB(fd, 4)=flag;
  5057. WFIFOSET(fd,packet_len(0x1fe));
  5058. }
  5059. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5060. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5061. void clif_item_refine_list(struct map_session_data *sd)
  5062. {
  5063. int i,c;
  5064. int fd;
  5065. int skilllv;
  5066. int wlv;
  5067. int refine_item[5];
  5068. nullpo_retv(sd);
  5069. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  5070. fd=sd->fd;
  5071. refine_item[0] = -1;
  5072. refine_item[1] = pc_search_inventory(sd,1010);
  5073. refine_item[2] = pc_search_inventory(sd,1011);
  5074. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5075. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5076. WFIFOW(fd,0)=0x221;
  5077. for(i=c=0;i<MAX_INVENTORY;i++){
  5078. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  5079. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5080. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5081. WFIFOW(fd,c*13+ 4)=i+2;
  5082. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5083. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5084. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5085. c++;
  5086. }
  5087. }
  5088. WFIFOW(fd,2)=c*13+4;
  5089. WFIFOSET(fd,WFIFOW(fd,2));
  5090. if (c > 0) {
  5091. sd->menuskill_id = WS_WEAPONREFINE;
  5092. sd->menuskill_val = skilllv;
  5093. }
  5094. }
  5095. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5096. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5097. void clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  5098. {
  5099. int fd;
  5100. nullpo_retv(sd);
  5101. fd=sd->fd;
  5102. WFIFOHEAD(fd,packet_len(0x147));
  5103. WFIFOW(fd, 0)=0x147;
  5104. WFIFOW(fd, 2)=skillid;
  5105. WFIFOW(fd, 4)=skill_get_inf(skillid);
  5106. WFIFOW(fd, 6)=0;
  5107. WFIFOW(fd, 8)=skilllv;
  5108. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  5109. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  5110. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  5111. WFIFOB(fd,38)=0;
  5112. WFIFOSET(fd,packet_len(0x147));
  5113. }
  5114. /// Adds an item to character's cart.
  5115. /// 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)
  5116. /// 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)
  5117. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5118. {
  5119. int view,fd;
  5120. unsigned char *buf;
  5121. nullpo_retv(sd);
  5122. fd=sd->fd;
  5123. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5124. return;
  5125. #if PACKETVER < 5
  5126. WFIFOHEAD(fd,packet_len(0x124));
  5127. buf=WFIFOP(fd,0);
  5128. WBUFW(buf,0)=0x124;
  5129. WBUFW(buf,2)=n+2;
  5130. WBUFL(buf,4)=amount;
  5131. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5132. WBUFW(buf,8)=view;
  5133. else
  5134. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5135. WBUFB(buf,10)=sd->status.cart[n].identify;
  5136. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5137. WBUFB(buf,12)=sd->status.cart[n].refine;
  5138. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5139. WFIFOSET(fd,packet_len(0x124));
  5140. #else
  5141. WFIFOHEAD(fd,packet_len(0x1c5));
  5142. buf=WFIFOP(fd,0);
  5143. WBUFW(buf,0)=0x1c5;
  5144. WBUFW(buf,2)=n+2;
  5145. WBUFL(buf,4)=amount;
  5146. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5147. WBUFW(buf,8)=view;
  5148. else
  5149. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5150. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5151. WBUFB(buf,11)=sd->status.cart[n].identify;
  5152. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5153. WBUFB(buf,13)=sd->status.cart[n].refine;
  5154. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5155. WFIFOSET(fd,packet_len(0x1c5));
  5156. #endif
  5157. }
  5158. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5159. /// 0125 <index>.W <amount>.L
  5160. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5161. {
  5162. int fd;
  5163. nullpo_retv(sd);
  5164. fd=sd->fd;
  5165. WFIFOHEAD(fd,packet_len(0x125));
  5166. WFIFOW(fd,0)=0x125;
  5167. WFIFOW(fd,2)=n+2;
  5168. WFIFOL(fd,4)=amount;
  5169. WFIFOSET(fd,packet_len(0x125));
  5170. }
  5171. /// Opens the shop creation menu (ZC_OPENSTORE).
  5172. /// 012d <num>.W
  5173. /// num:
  5174. /// number of allowed item slots
  5175. void clif_openvendingreq(struct map_session_data* sd, int num)
  5176. {
  5177. int fd;
  5178. nullpo_retv(sd);
  5179. fd = sd->fd;
  5180. WFIFOHEAD(fd,packet_len(0x12d));
  5181. WFIFOW(fd,0) = 0x12d;
  5182. WFIFOW(fd,2) = num;
  5183. WFIFOSET(fd,packet_len(0x12d));
  5184. }
  5185. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5186. /// 0131 <owner id>.L <message>.80B
  5187. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5188. {
  5189. unsigned char buf[128];
  5190. nullpo_retv(bl);
  5191. WBUFW(buf,0) = 0x131;
  5192. WBUFL(buf,2) = bl->id;
  5193. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5194. if( fd ) {
  5195. WFIFOHEAD(fd,packet_len(0x131));
  5196. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5197. WFIFOSET(fd,packet_len(0x131));
  5198. } else {
  5199. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5200. }
  5201. }
  5202. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5203. /// 0132 <owner id>.L
  5204. void clif_closevendingboard(struct block_list* bl, int fd)
  5205. {
  5206. unsigned char buf[16];
  5207. nullpo_retv(bl);
  5208. WBUFW(buf,0) = 0x132;
  5209. WBUFL(buf,2) = bl->id;
  5210. if( fd ) {
  5211. WFIFOHEAD(fd,packet_len(0x132));
  5212. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5213. WFIFOSET(fd,packet_len(0x132));
  5214. } else {
  5215. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5216. }
  5217. }
  5218. /// Sends a list of items in a shop.
  5219. /// 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)
  5220. /// 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)
  5221. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5222. {
  5223. int i,fd;
  5224. int count;
  5225. struct map_session_data* vsd;
  5226. #if PACKETVER < 20100105
  5227. const int cmd = 0x133;
  5228. const int offset = 8;
  5229. #else
  5230. const int cmd = 0x800;
  5231. const int offset = 12;
  5232. #endif
  5233. nullpo_retv(sd);
  5234. nullpo_retv(vending);
  5235. nullpo_retv(vsd=map_id2sd(id));
  5236. fd = sd->fd;
  5237. count = vsd->vend_num;
  5238. WFIFOHEAD(fd, offset+count*22);
  5239. WFIFOW(fd,0) = cmd;
  5240. WFIFOW(fd,2) = offset+count*22;
  5241. WFIFOL(fd,4) = id;
  5242. #if PACKETVER >= 20100105
  5243. WFIFOL(fd,8) = vsd->vender_id;
  5244. #endif
  5245. for( i = 0; i < count; i++ )
  5246. {
  5247. int index = vending[i].index;
  5248. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5249. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5250. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5251. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5252. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5253. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5254. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5255. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5256. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5257. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5258. }
  5259. WFIFOSET(fd,WFIFOW(fd,2));
  5260. }
  5261. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5262. /// 0135 <index>.W <amount>.W <result>.B
  5263. /// result:
  5264. /// 0 = success
  5265. /// 1 = not enough zeny
  5266. /// 2 = overweight
  5267. /// 4 = out of stock
  5268. /// 5 = "cannot use an npc shop while in a trade"
  5269. /// 6 = Because the store information was incorrect the item was not purchased.
  5270. /// 7 = No sales information.
  5271. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5272. {
  5273. int fd;
  5274. nullpo_retv(sd);
  5275. fd = sd->fd;
  5276. WFIFOHEAD(fd,packet_len(0x135));
  5277. WFIFOW(fd,0) = 0x135;
  5278. WFIFOW(fd,2) = index+2;
  5279. WFIFOW(fd,4) = amount;
  5280. WFIFOB(fd,6) = fail;
  5281. WFIFOSET(fd,packet_len(0x135));
  5282. }
  5283. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5284. /// 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 }*
  5285. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5286. {
  5287. int i,fd;
  5288. int count;
  5289. nullpo_retv(sd);
  5290. fd = sd->fd;
  5291. count = sd->vend_num;
  5292. WFIFOHEAD(fd, 8+count*22);
  5293. WFIFOW(fd,0) = 0x136;
  5294. WFIFOW(fd,2) = 8+count*22;
  5295. WFIFOL(fd,4) = id;
  5296. for( i = 0; i < count; i++ )
  5297. {
  5298. int index = vending[i].index;
  5299. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5300. WFIFOL(fd, 8+i*22) = vending[i].value;
  5301. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5302. WFIFOW(fd,14+i*22) = vending[i].amount;
  5303. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5304. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5305. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5306. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5307. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5308. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5309. }
  5310. WFIFOSET(fd,WFIFOW(fd,2));
  5311. }
  5312. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5313. /// 0137 <index>.W <amount>.W
  5314. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5315. {
  5316. int fd;
  5317. nullpo_retv(sd);
  5318. fd = sd->fd;
  5319. WFIFOHEAD(fd,packet_len(0x137));
  5320. WFIFOW(fd,0) = 0x137;
  5321. WFIFOW(fd,2) = index+2;
  5322. WFIFOW(fd,4) = amount;
  5323. WFIFOSET(fd,packet_len(0x137));
  5324. }
  5325. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5326. /// 00fa <result>.B
  5327. /// result:
  5328. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5329. /// 1 = MsgStringTable[78]="party name already exists"
  5330. /// 2 = MsgStringTable[79]="already in a party"
  5331. /// 3 = cannot organize parties on this map
  5332. /// ? = nothing
  5333. void clif_party_created(struct map_session_data *sd,int result)
  5334. {
  5335. int fd;
  5336. nullpo_retv(sd);
  5337. fd=sd->fd;
  5338. WFIFOHEAD(fd,packet_len(0xfa));
  5339. WFIFOW(fd,0)=0xfa;
  5340. WFIFOB(fd,2)=result;
  5341. WFIFOSET(fd,packet_len(0xfa));
  5342. }
  5343. /// Adds new member to a party.
  5344. /// 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)
  5345. /// 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)
  5346. /// role:
  5347. /// 0 = leader
  5348. /// 1 = normal
  5349. /// state:
  5350. /// 0 = connected
  5351. /// 1 = disconnected
  5352. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5353. {
  5354. unsigned char buf[81];
  5355. int i;
  5356. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5357. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5358. } else {
  5359. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5360. }
  5361. if (i >= MAX_PARTY) return; //Should never happen...
  5362. sd = p->data[i].sd;
  5363. WBUFW(buf, 0) = 0x1e9;
  5364. WBUFL(buf, 2) = sd->status.account_id;
  5365. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5366. WBUFW(buf,10) = sd->bl.x;
  5367. WBUFW(buf,12) = sd->bl.y;
  5368. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5369. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5370. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5371. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5372. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5373. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5374. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5375. }
  5376. /// Sends party information (ZC_GROUP_LIST).
  5377. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5378. /// role:
  5379. /// 0 = leader
  5380. /// 1 = normal
  5381. /// state:
  5382. /// 0 = connected
  5383. /// 1 = disconnected
  5384. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5385. {
  5386. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5387. struct map_session_data* party_sd = NULL;
  5388. int i, c;
  5389. nullpo_retv(p);
  5390. WBUFW(buf,0) = 0xfb;
  5391. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5392. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5393. {
  5394. struct party_member* m = &p->party.member[i];
  5395. if(!m->account_id) continue;
  5396. if(party_sd == NULL) party_sd = p->data[i].sd;
  5397. WBUFL(buf,28+c*46) = m->account_id;
  5398. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5399. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5400. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5401. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5402. c++;
  5403. }
  5404. WBUFW(buf,2) = 28+c*46;
  5405. if(sd) { // send only to self
  5406. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5407. } else if (party_sd) { // send to whole party
  5408. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5409. }
  5410. }
  5411. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5412. /// 02c9 <flag>.B
  5413. /// flag:
  5414. /// 0 = allow party invites
  5415. /// 1 = auto-deny party invites
  5416. void clif_partyinvitationstate(struct map_session_data* sd)
  5417. {
  5418. int fd;
  5419. nullpo_retv(sd);
  5420. fd = sd->fd;
  5421. WFIFOHEAD(fd, packet_len(0x2c9));
  5422. WFIFOW(fd, 0) = 0x2c9;
  5423. WFIFOB(fd, 2) = 0; // not implemented
  5424. WFIFOSET(fd, packet_len(0x2c9));
  5425. }
  5426. /// Party invitation request.
  5427. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5428. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5429. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5430. {
  5431. #if PACKETVER < 20070821
  5432. const int cmd = 0xfe;
  5433. #else
  5434. const int cmd = 0x2c6;
  5435. #endif
  5436. int fd;
  5437. struct party_data *p;
  5438. nullpo_retv(sd);
  5439. nullpo_retv(tsd);
  5440. fd=tsd->fd;
  5441. if( (p=party_search(sd->status.party_id))==NULL )
  5442. return;
  5443. WFIFOHEAD(fd,packet_len(cmd));
  5444. WFIFOW(fd,0)=cmd;
  5445. WFIFOL(fd,2)=sd->status.party_id;
  5446. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5447. WFIFOSET(fd,packet_len(cmd));
  5448. }
  5449. /// Party invite result.
  5450. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5451. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5452. /// result=0 : char is already in a party -> MsgStringTable[80]
  5453. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5454. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5455. /// result=3 : party is full -> MsgStringTable[83]
  5456. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5457. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5458. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5459. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5460. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5461. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5462. {
  5463. int fd;
  5464. nullpo_retv(sd);
  5465. fd=sd->fd;
  5466. #if PACKETVER < 20070904
  5467. if( result == 7 ) {
  5468. clif_displaymessage(fd, msg_txt(3));
  5469. return;
  5470. }
  5471. #endif
  5472. #if PACKETVER < 20070821
  5473. WFIFOHEAD(fd,packet_len(0xfd));
  5474. WFIFOW(fd,0) = 0xfd;
  5475. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5476. WFIFOB(fd,26) = result;
  5477. WFIFOSET(fd,packet_len(0xfd));
  5478. #else
  5479. WFIFOHEAD(fd,packet_len(0x2c5));
  5480. WFIFOW(fd,0) = 0x2c5;
  5481. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5482. WFIFOL(fd,26) = result;
  5483. WFIFOSET(fd,packet_len(0x2c5));
  5484. #endif
  5485. }
  5486. /// Updates party settings.
  5487. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5488. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5489. /// exp option:
  5490. /// 0 = exp sharing disabled
  5491. /// 1 = exp sharing enabled
  5492. /// 2 = cannot change exp sharing
  5493. ///
  5494. /// flag:
  5495. /// 0 = send to party
  5496. /// 1 = send to sd
  5497. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5498. {
  5499. unsigned char buf[16];
  5500. #if PACKETVER < 20090603
  5501. const int cmd = 0x101;
  5502. #else
  5503. const int cmd = 0x7d8;
  5504. #endif
  5505. nullpo_retv(p);
  5506. if(!sd && flag==0){
  5507. int i;
  5508. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5509. if (i < MAX_PARTY)
  5510. sd = p->data[i].sd;
  5511. }
  5512. if(!sd) return;
  5513. WBUFW(buf,0)=cmd;
  5514. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5515. #if PACKETVER >= 20090603
  5516. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5517. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5518. #endif
  5519. if(flag==0)
  5520. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5521. else
  5522. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5523. }
  5524. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5525. /// result:
  5526. /// 0 = leave
  5527. /// 1 = expel
  5528. /// 2 = cannot leave party on this map
  5529. /// 3 = cannot expel from party on this map
  5530. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5531. {
  5532. unsigned char buf[64];
  5533. int i;
  5534. nullpo_retv(p);
  5535. if(!sd && (flag&0xf0)==0)
  5536. {
  5537. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5538. if (i < MAX_PARTY)
  5539. sd = p->data[i].sd;
  5540. }
  5541. if(!sd) return;
  5542. WBUFW(buf,0)=0x105;
  5543. WBUFL(buf,2)=account_id;
  5544. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5545. WBUFB(buf,30)=flag&0x0f;
  5546. if((flag&0xf0)==0)
  5547. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5548. else
  5549. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5550. }
  5551. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5552. /// 0109 <packet len>.W <account id>.L <message>.?B
  5553. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5554. {
  5555. struct map_session_data *sd;
  5556. int i;
  5557. nullpo_retv(p);
  5558. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5559. if(i < MAX_PARTY){
  5560. unsigned char buf[1024];
  5561. sd = p->data[i].sd;
  5562. WBUFW(buf,0)=0x109;
  5563. WBUFW(buf,2)=len+8;
  5564. WBUFL(buf,4)=account_id;
  5565. memcpy(WBUFP(buf,8),mes,len); // FIXME: buffer size check
  5566. clif_send(buf,len+8,&sd->bl,PARTY);
  5567. }
  5568. }
  5569. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5570. /// 0107 <account id>.L <x>.W <y>.W
  5571. void clif_party_xy(struct map_session_data *sd)
  5572. {
  5573. unsigned char buf[16];
  5574. nullpo_retv(sd);
  5575. WBUFW(buf,0)=0x107;
  5576. WBUFL(buf,2)=sd->status.account_id;
  5577. WBUFW(buf,6)=sd->bl.x;
  5578. WBUFW(buf,8)=sd->bl.y;
  5579. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5580. }
  5581. /*==========================================
  5582. * Sends x/y dot to a single fd. [Skotlex]
  5583. *------------------------------------------*/
  5584. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5585. {
  5586. WFIFOHEAD(fd,packet_len(0x107));
  5587. WFIFOW(fd,0)=0x107;
  5588. WFIFOL(fd,2)=sd->status.account_id;
  5589. WFIFOW(fd,6)=sd->bl.x;
  5590. WFIFOW(fd,8)=sd->bl.y;
  5591. WFIFOSET(fd,packet_len(0x107));
  5592. }
  5593. /// Updates HP bar of a party member.
  5594. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5595. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5596. void clif_party_hp(struct map_session_data *sd)
  5597. {
  5598. unsigned char buf[16];
  5599. #if PACKETVER < 20100126
  5600. const int cmd = 0x106;
  5601. #else
  5602. const int cmd = 0x80e;
  5603. #endif
  5604. nullpo_retv(sd);
  5605. WBUFW(buf,0)=cmd;
  5606. WBUFL(buf,2)=sd->status.account_id;
  5607. #if PACKETVER < 20100126
  5608. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5609. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5610. WBUFW(buf,8) = 100;
  5611. } else {
  5612. WBUFW(buf,6) = sd->battle_status.hp;
  5613. WBUFW(buf,8) = sd->battle_status.max_hp;
  5614. }
  5615. #else
  5616. WBUFL(buf,6) = sd->battle_status.hp;
  5617. WBUFL(buf,10) = sd->battle_status.max_hp;
  5618. #endif
  5619. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5620. }
  5621. /*==========================================
  5622. * Sends HP bar to a single fd. [Skotlex]
  5623. *------------------------------------------*/
  5624. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5625. {
  5626. #if PACKETVER < 20100126
  5627. const int cmd = 0x106;
  5628. #else
  5629. const int cmd = 0x80e;
  5630. #endif
  5631. WFIFOHEAD(fd,packet_len(cmd));
  5632. WFIFOW(fd,0) = cmd;
  5633. WFIFOL(fd,2) = id;
  5634. #if PACKETVER < 20100126
  5635. if( maxhp > INT16_MAX )
  5636. {// To correctly display the %hp bar. [Skotlex]
  5637. WFIFOW(fd,6) = hp/(maxhp/100);
  5638. WFIFOW(fd,8) = 100;
  5639. } else {
  5640. WFIFOW(fd,6) = hp;
  5641. WFIFOW(fd,8) = maxhp;
  5642. }
  5643. #else
  5644. WFIFOL(fd,6) = hp;
  5645. WFIFOL(fd,10) = maxhp;
  5646. #endif
  5647. WFIFOSET(fd, packet_len(cmd));
  5648. }
  5649. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5650. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5651. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5652. {
  5653. int fd;
  5654. nullpo_retv(sd);
  5655. nullpo_retv(bl);
  5656. fd=sd->fd;
  5657. WFIFOHEAD(fd,packet_len(0x139));
  5658. WFIFOW(fd, 0)=0x139;
  5659. WFIFOL(fd, 2)=bl->id;
  5660. WFIFOW(fd, 6)=bl->x;
  5661. WFIFOW(fd, 8)=bl->y;
  5662. WFIFOW(fd,10)=sd->bl.x;
  5663. WFIFOW(fd,12)=sd->bl.y;
  5664. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5665. WFIFOSET(fd,packet_len(0x139));
  5666. }
  5667. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5668. /// 018f <result>.W <name id>.W
  5669. /// result:
  5670. /// 0 = success
  5671. /// 1 = failure
  5672. /// 2 = success (alchemist)
  5673. /// 3 = failure (alchemist)
  5674. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5675. {
  5676. int view,fd;
  5677. nullpo_retv(sd);
  5678. fd = sd->fd;
  5679. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5680. WFIFOHEAD(fd,packet_len(0x18f));
  5681. WFIFOW(fd, 0)=0x18f;
  5682. WFIFOW(fd, 2)=flag;
  5683. if((view = itemdb_viewid(nameid)) > 0)
  5684. WFIFOW(fd, 4)=view;
  5685. else
  5686. WFIFOW(fd, 4)=nameid;
  5687. WFIFOSET(fd,packet_len(0x18f));
  5688. }
  5689. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5690. /// 019e
  5691. void clif_catch_process(struct map_session_data *sd)
  5692. {
  5693. int fd;
  5694. nullpo_retv(sd);
  5695. fd=sd->fd;
  5696. WFIFOHEAD(fd,packet_len(0x19e));
  5697. WFIFOW(fd,0)=0x19e;
  5698. WFIFOSET(fd,packet_len(0x19e));
  5699. }
  5700. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5701. /// 01a0 <result>.B
  5702. /// 0 = failure
  5703. /// 1 = success
  5704. void clif_pet_roulette(struct map_session_data *sd,int data)
  5705. {
  5706. int fd;
  5707. nullpo_retv(sd);
  5708. fd=sd->fd;
  5709. WFIFOHEAD(fd,packet_len(0x1a0));
  5710. WFIFOW(fd,0)=0x1a0;
  5711. WFIFOB(fd,2)=data;
  5712. WFIFOSET(fd,packet_len(0x1a0));
  5713. }
  5714. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5715. /// 01a6 <packet len>.W { <index>.W }*
  5716. void clif_sendegg(struct map_session_data *sd)
  5717. {
  5718. int i,n=0,fd;
  5719. nullpo_retv(sd);
  5720. fd=sd->fd;
  5721. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5722. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5723. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5724. return;
  5725. }
  5726. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5727. WFIFOW(fd,0)=0x1a6;
  5728. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5729. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5730. sd->inventory_data[i]->type!=IT_PETEGG ||
  5731. sd->status.inventory[i].amount<=0)
  5732. continue;
  5733. WFIFOW(fd,n*2+4)=i+2;
  5734. n++;
  5735. }
  5736. WFIFOW(fd,2)=4+n*2;
  5737. WFIFOSET(fd,WFIFOW(fd,2));
  5738. sd->menuskill_id = SA_TAMINGMONSTER;
  5739. sd->menuskill_val = -1;
  5740. }
  5741. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5742. /// 01a4 <type>.B <id>.L <data>.L
  5743. /// type:
  5744. /// 0 = pre-init (data = 0)
  5745. /// 1 = intimacy (data = 0~4)
  5746. /// 2 = hunger (data = 0~4)
  5747. /// 3 = accessory
  5748. /// 4 = performance (data = 1~3: normal, 4: special)
  5749. /// 5 = hairstyle
  5750. ///
  5751. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5752. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5753. {
  5754. uint8 buf[16];
  5755. nullpo_retv(pd);
  5756. WBUFW(buf,0) = 0x1a4;
  5757. WBUFB(buf,2) = type;
  5758. WBUFL(buf,3) = pd->bl.id;
  5759. WBUFL(buf,7) = param;
  5760. if (sd)
  5761. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5762. else
  5763. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5764. }
  5765. /// Pet's base data (ZC_PROPERTY_PET).
  5766. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5767. void clif_send_petstatus(struct map_session_data *sd)
  5768. {
  5769. int fd;
  5770. struct s_pet *pet;
  5771. nullpo_retv(sd);
  5772. nullpo_retv(sd->pd);
  5773. fd=sd->fd;
  5774. pet = &sd->pd->pet;
  5775. WFIFOHEAD(fd,packet_len(0x1a2));
  5776. WFIFOW(fd,0)=0x1a2;
  5777. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5778. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5779. WFIFOW(fd,27)=pet->level;
  5780. WFIFOW(fd,29)=pet->hungry;
  5781. WFIFOW(fd,31)=pet->intimate;
  5782. WFIFOW(fd,33)=pet->equip;
  5783. #if PACKETVER >= 20081126
  5784. WFIFOW(fd,35)=pet->class_;
  5785. #endif
  5786. WFIFOSET(fd,packet_len(0x1a2));
  5787. }
  5788. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5789. /// 01aa <id>.L <data>.L
  5790. /// data:
  5791. /// @see CZ_PET_ACT.
  5792. void clif_pet_emotion(struct pet_data *pd,int param)
  5793. {
  5794. unsigned char buf[16];
  5795. nullpo_retv(pd);
  5796. memset(buf,0,packet_len(0x1aa));
  5797. WBUFW(buf,0)=0x1aa;
  5798. WBUFL(buf,2)=pd->bl.id;
  5799. if(param >= 100 && pd->petDB->talk_convert_class) {
  5800. if(pd->petDB->talk_convert_class < 0)
  5801. return;
  5802. else if(pd->petDB->talk_convert_class > 0) {
  5803. // replace mob_id component of talk/act data
  5804. param -= (pd->pet.class_ - 100)*100;
  5805. param += (pd->petDB->talk_convert_class - 100)*100;
  5806. }
  5807. }
  5808. WBUFL(buf,6)=param;
  5809. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5810. }
  5811. /// Result of request to feed a pet (ZC_FEED_PET).
  5812. /// 01a3 <result>.B <name id>.W
  5813. /// result:
  5814. /// 0 = failure
  5815. /// 1 = success
  5816. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5817. {
  5818. int fd;
  5819. nullpo_retv(sd);
  5820. fd=sd->fd;
  5821. WFIFOHEAD(fd,packet_len(0x1a3));
  5822. WFIFOW(fd,0)=0x1a3;
  5823. WFIFOB(fd,2)=fail;
  5824. WFIFOW(fd,3)=foodid;
  5825. WFIFOSET(fd,packet_len(0x1a3));
  5826. }
  5827. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5828. /// 01cd { <skill id>.L }*7
  5829. void clif_autospell(struct map_session_data *sd,int skilllv)
  5830. {
  5831. int fd;
  5832. nullpo_retv(sd);
  5833. fd=sd->fd;
  5834. WFIFOHEAD(fd,packet_len(0x1cd));
  5835. WFIFOW(fd, 0)=0x1cd;
  5836. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5837. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5838. else
  5839. WFIFOL(fd,2)= 0x00000000;
  5840. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5841. WFIFOL(fd,6)= MG_COLDBOLT;
  5842. else
  5843. WFIFOL(fd,6)= 0x00000000;
  5844. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5845. WFIFOL(fd,10)= MG_FIREBOLT;
  5846. else
  5847. WFIFOL(fd,10)= 0x00000000;
  5848. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5849. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5850. else
  5851. WFIFOL(fd,14)= 0x00000000;
  5852. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5853. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5854. else
  5855. WFIFOL(fd,18)= 0x00000000;
  5856. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5857. WFIFOL(fd,22)= MG_FIREBALL;
  5858. else
  5859. WFIFOL(fd,22)= 0x00000000;
  5860. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5861. WFIFOL(fd,26)= MG_FROSTDIVER;
  5862. else
  5863. WFIFOL(fd,26)= 0x00000000;
  5864. WFIFOSET(fd,packet_len(0x1cd));
  5865. sd->menuskill_id = SA_AUTOSPELL;
  5866. sd->menuskill_val = skilllv;
  5867. }
  5868. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5869. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5870. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5871. {
  5872. unsigned char buf[56];
  5873. int i;
  5874. nullpo_retv(src);
  5875. memset(buf,0,packet_len(0x1cf));
  5876. WBUFW(buf,0) = 0x1cf;
  5877. WBUFL(buf,2) = src->id;
  5878. if( src->type == BL_MER )
  5879. {
  5880. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5881. if( md && md->master && md->devotion_flag )
  5882. WBUFL(buf,6) = md->master->bl.id;
  5883. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5884. }
  5885. else
  5886. {
  5887. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5888. if( sd == NULL )
  5889. return;
  5890. for( i = 0; i < 5; i++ )
  5891. WBUFL(buf,6+4*i) = sd->devotion[i];
  5892. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5893. }
  5894. if( tsd )
  5895. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5896. else
  5897. clif_send(buf, packet_len(0x1cf), src, AREA);
  5898. }
  5899. /// Notifies clients in an area of an object's spirits.
  5900. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  5901. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  5902. void clif_spiritball(struct map_session_data *sd)
  5903. {
  5904. unsigned char buf[8];
  5905. nullpo_retv(sd);
  5906. WBUFW(buf,0)=0x1d0;
  5907. WBUFL(buf,2)=sd->bl.id;
  5908. WBUFW(buf,6)=sd->spiritball;
  5909. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5910. }
  5911. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  5912. /// 01d2 <account id>.L <delay>.L
  5913. void clif_combo_delay(struct block_list *bl,int wait)
  5914. {
  5915. unsigned char buf[32];
  5916. nullpo_retv(bl);
  5917. WBUFW(buf,0)=0x1d2;
  5918. WBUFL(buf,2)=bl->id;
  5919. WBUFL(buf,6)=wait;
  5920. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5921. }
  5922. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  5923. /// 01d1 <src id>.L <dst id>.L <flag>.L
  5924. /// flag:
  5925. /// 0 = inactive
  5926. /// 1 = active
  5927. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5928. {
  5929. unsigned char buf[32];
  5930. nullpo_retv(src);
  5931. WBUFW(buf,0)=0x1d1;
  5932. WBUFL(buf,2)=src->id;
  5933. WBUFL(buf,6)=dst_id;
  5934. WBUFL(buf,10)=active;
  5935. clif_send(buf,packet_len(0x1d1),src,AREA);
  5936. }
  5937. /// MVP effect (ZC_MVP).
  5938. /// 010c <account id>.L
  5939. void clif_mvp_effect(struct map_session_data *sd)
  5940. {
  5941. unsigned char buf[16];
  5942. nullpo_retv(sd);
  5943. WBUFW(buf,0)=0x10c;
  5944. WBUFL(buf,2)=sd->bl.id;
  5945. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5946. }
  5947. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  5948. /// 010a <name id>.W
  5949. void clif_mvp_item(struct map_session_data *sd,int nameid)
  5950. {
  5951. int view,fd;
  5952. nullpo_retv(sd);
  5953. fd=sd->fd;
  5954. WFIFOHEAD(fd,packet_len(0x10a));
  5955. WFIFOW(fd,0)=0x10a;
  5956. if((view = itemdb_viewid(nameid)) > 0)
  5957. WFIFOW(fd,2)=view;
  5958. else
  5959. WFIFOW(fd,2)=nameid;
  5960. WFIFOSET(fd,packet_len(0x10a));
  5961. }
  5962. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  5963. /// 010b <exp>.L
  5964. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5965. {
  5966. int fd;
  5967. nullpo_retv(sd);
  5968. fd=sd->fd;
  5969. WFIFOHEAD(fd,packet_len(0x10b));
  5970. WFIFOW(fd,0)=0x10b;
  5971. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  5972. WFIFOSET(fd,packet_len(0x10b));
  5973. }
  5974. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  5975. /// 010d
  5976. ///
  5977. /// "You are the MVP, but cannot obtain the reward because
  5978. /// you are overweight."
  5979. void clif_mvp_noitem(struct map_session_data* sd)
  5980. {
  5981. int fd = sd->fd;
  5982. WFIFOHEAD(fd,packet_len(0x10d));
  5983. WFIFOW(fd,0) = 0x10d;
  5984. WFIFOSET(fd,packet_len(0x10d));
  5985. }
  5986. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  5987. /// 0167 <result>.B
  5988. /// result:
  5989. /// 0 = "Guild has been created."
  5990. /// 1 = "You are already in a Guild."
  5991. /// 2 = "That Guild Name already exists."
  5992. /// 3 = "You need the neccessary item to create a Guild."
  5993. void clif_guild_created(struct map_session_data *sd,int flag)
  5994. {
  5995. int fd;
  5996. nullpo_retv(sd);
  5997. fd=sd->fd;
  5998. WFIFOHEAD(fd,packet_len(0x167));
  5999. WFIFOW(fd,0)=0x167;
  6000. WFIFOB(fd,2)=flag;
  6001. WFIFOSET(fd,packet_len(0x167));
  6002. }
  6003. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6004. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6005. /// mode:
  6006. /// &0x01 = allow invite
  6007. /// &0x10 = allow expel
  6008. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6009. {
  6010. int ps,fd;
  6011. nullpo_retv(sd);
  6012. nullpo_retv(g);
  6013. fd=sd->fd;
  6014. ps=guild_getposition(g,sd);
  6015. WFIFOHEAD(fd,packet_len(0x16c));
  6016. WFIFOW(fd,0)=0x16c;
  6017. WFIFOL(fd,2)=g->guild_id;
  6018. WFIFOL(fd,6)=g->emblem_id;
  6019. WFIFOL(fd,10)=g->position[ps].mode;
  6020. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6021. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6022. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6023. WFIFOSET(fd,packet_len(0x16c));
  6024. }
  6025. /// Guild member login notice.
  6026. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6027. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6028. /// status:
  6029. /// 0 = offline
  6030. /// 1 = online
  6031. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6032. {
  6033. unsigned char buf[64];
  6034. struct map_session_data* sd;
  6035. nullpo_retv(g);
  6036. WBUFW(buf, 0)=0x1f2;
  6037. WBUFL(buf, 2)=g->member[idx].account_id;
  6038. WBUFL(buf, 6)=g->member[idx].char_id;
  6039. WBUFL(buf,10)=flag;
  6040. if( ( sd = g->member[idx].sd ) != NULL )
  6041. {
  6042. WBUFW(buf,14) = sd->status.sex;
  6043. WBUFW(buf,16) = sd->status.hair;
  6044. WBUFW(buf,18) = sd->status.hair_color;
  6045. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6046. }
  6047. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6048. {
  6049. WBUFW(buf,14) = 0;
  6050. WBUFW(buf,16) = 0;
  6051. WBUFW(buf,18) = 0;
  6052. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6053. }
  6054. }
  6055. // Function `clif_guild_memberlogin_notice` sends info about
  6056. // logins and logouts of a guild member to the rest members.
  6057. // But at the 1st time (after a player login or map changing)
  6058. // the client won't show the message.
  6059. // So I suggest use this function for sending "first-time-info"
  6060. // to some player on entering the game or changing location.
  6061. // At next time the client would always show the message.
  6062. // The function sends all the statuses in the single packet
  6063. // to economize traffic. [LuzZza]
  6064. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6065. {
  6066. struct guild *g;
  6067. unsigned char buf[14*128];
  6068. int i, count=0, p_len;
  6069. nullpo_retv(sd);
  6070. p_len = packet_len(0x16d);
  6071. if(!(g = guild_search(sd->status.guild_id)))
  6072. return;
  6073. for(i=0; i<g->max_member; i++) {
  6074. if(g->member[i].account_id > 0 &&
  6075. g->member[i].account_id != sd->status.account_id) {
  6076. WBUFW(buf,count*p_len) = 0x16d;
  6077. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6078. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6079. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6080. count++;
  6081. }
  6082. }
  6083. clif_send(buf, p_len*count, &sd->bl, SELF);
  6084. }
  6085. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6086. /// 014e <menu flag>.L
  6087. /// menu flag:
  6088. /// 0x00 = Basic Info (always on)
  6089. /// &0x01 = Member manager
  6090. /// &0x02 = Positions
  6091. /// &0x04 = Skills
  6092. /// &0x10 = Expulsion list
  6093. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6094. /// &0x80 = Notice
  6095. void clif_guild_masterormember(struct map_session_data *sd)
  6096. {
  6097. int fd;
  6098. nullpo_retv(sd);
  6099. fd=sd->fd;
  6100. WFIFOHEAD(fd,packet_len(0x14e));
  6101. WFIFOW(fd,0) = 0x14e;
  6102. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6103. WFIFOSET(fd,packet_len(0x14e));
  6104. }
  6105. /// Guild basic information (Territories [Valaris])
  6106. /// 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)
  6107. /// 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)
  6108. void clif_guild_basicinfo(struct map_session_data *sd) {
  6109. int fd;
  6110. struct guild *g;
  6111. nullpo_retv(sd);
  6112. fd = sd->fd;
  6113. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6114. return;
  6115. WFIFOHEAD(fd,packet_len(0x1b6));
  6116. WFIFOW(fd, 0)=0x1b6;//0x150;
  6117. WFIFOL(fd, 2)=g->guild_id;
  6118. WFIFOL(fd, 6)=g->guild_lv;
  6119. WFIFOL(fd,10)=g->connect_member;
  6120. WFIFOL(fd,14)=g->max_member;
  6121. WFIFOL(fd,18)=g->average_lv;
  6122. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6123. WFIFOL(fd,26)=g->next_exp;
  6124. WFIFOL(fd,30)=0; // Tax Points
  6125. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6126. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6127. WFIFOL(fd,42)=g->emblem_id;
  6128. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6129. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6130. safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
  6131. WFIFOL(fd,110) = 0; // zeny
  6132. WFIFOSET(fd,packet_len(0x1b6));
  6133. }
  6134. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6135. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6136. void clif_guild_allianceinfo(struct map_session_data *sd)
  6137. {
  6138. int fd,i,c;
  6139. struct guild *g;
  6140. nullpo_retv(sd);
  6141. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6142. return;
  6143. fd = sd->fd;
  6144. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6145. WFIFOW(fd, 0)=0x14c;
  6146. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6147. struct guild_alliance *a=&g->alliance[i];
  6148. if(a->guild_id>0){
  6149. WFIFOL(fd,c*32+4)=a->opposition;
  6150. WFIFOL(fd,c*32+8)=a->guild_id;
  6151. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6152. c++;
  6153. }
  6154. }
  6155. WFIFOW(fd, 2)=c*32+4;
  6156. WFIFOSET(fd,WFIFOW(fd,2));
  6157. }
  6158. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6159. /// 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 }*
  6160. /// state:
  6161. /// 0 = offline
  6162. /// 1 = online
  6163. /// memo:
  6164. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6165. void clif_guild_memberlist(struct map_session_data *sd)
  6166. {
  6167. int fd;
  6168. int i,c;
  6169. struct guild *g;
  6170. nullpo_retv(sd);
  6171. if( (fd = sd->fd) == 0 )
  6172. return;
  6173. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6174. return;
  6175. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6176. WFIFOW(fd, 0)=0x154;
  6177. for(i=0,c=0;i<g->max_member;i++){
  6178. struct guild_member *m=&g->member[i];
  6179. if(m->account_id==0)
  6180. continue;
  6181. WFIFOL(fd,c*104+ 4)=m->account_id;
  6182. WFIFOL(fd,c*104+ 8)=m->char_id;
  6183. WFIFOW(fd,c*104+12)=m->hair;
  6184. WFIFOW(fd,c*104+14)=m->hair_color;
  6185. WFIFOW(fd,c*104+16)=m->gender;
  6186. WFIFOW(fd,c*104+18)=m->class_;
  6187. WFIFOW(fd,c*104+20)=m->lv;
  6188. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6189. WFIFOL(fd,c*104+26)=m->online;
  6190. WFIFOL(fd,c*104+30)=m->position;
  6191. 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.
  6192. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6193. c++;
  6194. }
  6195. WFIFOW(fd, 2)=c*104+4;
  6196. WFIFOSET(fd,WFIFOW(fd,2));
  6197. }
  6198. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6199. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6200. void clif_guild_positionnamelist(struct map_session_data *sd)
  6201. {
  6202. int i,fd;
  6203. struct guild *g;
  6204. nullpo_retv(sd);
  6205. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6206. return;
  6207. fd = sd->fd;
  6208. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6209. WFIFOW(fd, 0)=0x166;
  6210. for(i=0;i<MAX_GUILDPOSITION;i++){
  6211. WFIFOL(fd,i*28+4)=i;
  6212. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6213. }
  6214. WFIFOW(fd,2)=i*28+4;
  6215. WFIFOSET(fd,WFIFOW(fd,2));
  6216. }
  6217. /// Guild position information (ZC_POSITION_INFO).
  6218. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6219. /// mode:
  6220. /// &0x01 = allow invite
  6221. /// &0x10 = allow expel
  6222. /// ranking:
  6223. /// TODO
  6224. void clif_guild_positioninfolist(struct map_session_data *sd)
  6225. {
  6226. int i,fd;
  6227. struct guild *g;
  6228. nullpo_retv(sd);
  6229. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6230. return;
  6231. fd = sd->fd;
  6232. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6233. WFIFOW(fd, 0)=0x160;
  6234. for(i=0;i<MAX_GUILDPOSITION;i++){
  6235. struct guild_position *p=&g->position[i];
  6236. WFIFOL(fd,i*16+ 4)=i;
  6237. WFIFOL(fd,i*16+ 8)=p->mode;
  6238. WFIFOL(fd,i*16+12)=i;
  6239. WFIFOL(fd,i*16+16)=p->exp_mode;
  6240. }
  6241. WFIFOW(fd, 2)=i*16+4;
  6242. WFIFOSET(fd,WFIFOW(fd,2));
  6243. }
  6244. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6245. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6246. /// mode:
  6247. /// &0x01 = allow invite
  6248. /// &0x10 = allow expel
  6249. /// ranking:
  6250. /// TODO
  6251. void clif_guild_positionchanged(struct guild *g,int idx)
  6252. {
  6253. // FIXME: This packet is intended to update the clients after a
  6254. // commit of position info changes, not sending one packet per
  6255. // position.
  6256. struct map_session_data *sd;
  6257. unsigned char buf[128];
  6258. nullpo_retv(g);
  6259. WBUFW(buf, 0)=0x174;
  6260. WBUFW(buf, 2)=44; // packet len
  6261. // GUILD_REG_POSITION_INFO{
  6262. WBUFL(buf, 4)=idx;
  6263. WBUFL(buf, 8)=g->position[idx].mode;
  6264. WBUFL(buf,12)=idx;
  6265. WBUFL(buf,16)=g->position[idx].exp_mode;
  6266. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6267. // }*
  6268. if( (sd=guild_getavailablesd(g))!=NULL )
  6269. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6270. }
  6271. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6272. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6273. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6274. {
  6275. // FIXME: This packet is intended to update the clients after a
  6276. // commit of member position assignment changes, not sending one
  6277. // packet per position.
  6278. struct map_session_data *sd;
  6279. unsigned char buf[64];
  6280. nullpo_retv(g);
  6281. WBUFW(buf, 0)=0x156;
  6282. WBUFW(buf, 2)=16; // packet len
  6283. // MEMBER_POSITION_INFO{
  6284. WBUFL(buf, 4)=g->member[idx].account_id;
  6285. WBUFL(buf, 8)=g->member[idx].char_id;
  6286. WBUFL(buf,12)=g->member[idx].position;
  6287. // }*
  6288. if( (sd=guild_getavailablesd(g))!=NULL )
  6289. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6290. }
  6291. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6292. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6293. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6294. {
  6295. int fd;
  6296. nullpo_retv(sd);
  6297. nullpo_retv(g);
  6298. fd = sd->fd;
  6299. if( g->emblem_len <= 0 )
  6300. return;
  6301. WFIFOHEAD(fd,g->emblem_len+12);
  6302. WFIFOW(fd,0)=0x152;
  6303. WFIFOW(fd,2)=g->emblem_len+12;
  6304. WFIFOL(fd,4)=g->guild_id;
  6305. WFIFOL(fd,8)=g->emblem_id;
  6306. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6307. WFIFOSET(fd,WFIFOW(fd,2));
  6308. }
  6309. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6310. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6311. void clif_guild_emblem_area(struct block_list* bl)
  6312. {
  6313. uint8 buf[12];
  6314. nullpo_retv(bl);
  6315. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6316. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6317. WBUFW(buf,0) = 0x1b4;
  6318. WBUFL(buf,2) = bl->id;
  6319. WBUFL(buf,6) = status_get_guild_id(bl);
  6320. WBUFW(buf,10) = status_get_emblem_id(bl);
  6321. clif_send(buf, 12, bl, AREA_WOS);
  6322. }
  6323. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6324. /// 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 }*
  6325. void clif_guild_skillinfo(struct map_session_data* sd)
  6326. {
  6327. int fd;
  6328. struct guild* g;
  6329. int i,c;
  6330. nullpo_retv(sd);
  6331. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6332. return;
  6333. fd = sd->fd;
  6334. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6335. WFIFOW(fd,0) = 0x0162;
  6336. WFIFOW(fd,4) = g->skill_point;
  6337. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6338. {
  6339. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6340. {
  6341. int id = g->skill[i].id;
  6342. int p = 6 + c*37;
  6343. WFIFOW(fd,p+0) = id;
  6344. WFIFOL(fd,p+2) = skill_get_inf(id);
  6345. WFIFOW(fd,p+6) = g->skill[i].lv;
  6346. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6347. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6348. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6349. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6350. c++;
  6351. }
  6352. }
  6353. WFIFOW(fd,2) = 6 + c*37;
  6354. WFIFOSET(fd,WFIFOW(fd,2));
  6355. }
  6356. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6357. /// 016f <subject>.60B <notice>.120B
  6358. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6359. {
  6360. int fd;
  6361. nullpo_retv(sd);
  6362. nullpo_retv(g);
  6363. fd = sd->fd;
  6364. if ( !session_isActive(fd) )
  6365. return;
  6366. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6367. return;
  6368. WFIFOHEAD(fd,packet_len(0x16f));
  6369. WFIFOW(fd,0) = 0x16f;
  6370. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6371. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6372. WFIFOSET(fd,packet_len(0x16f));
  6373. }
  6374. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6375. /// 016a <guild id>.L <guild name>.24B
  6376. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6377. {
  6378. int fd;
  6379. nullpo_retv(sd);
  6380. nullpo_retv(g);
  6381. fd=sd->fd;
  6382. WFIFOHEAD(fd,packet_len(0x16a));
  6383. WFIFOW(fd,0)=0x16a;
  6384. WFIFOL(fd,2)=g->guild_id;
  6385. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6386. WFIFOSET(fd,packet_len(0x16a));
  6387. }
  6388. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6389. /// 0169 <answer>.B
  6390. /// answer:
  6391. /// 0 = Already in guild.
  6392. /// 1 = Offer rejected.
  6393. /// 2 = Offer accepted.
  6394. /// 3 = Guild full.
  6395. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6396. {
  6397. int fd;
  6398. nullpo_retv(sd);
  6399. fd=sd->fd;
  6400. WFIFOHEAD(fd,packet_len(0x169));
  6401. WFIFOW(fd,0)=0x169;
  6402. WFIFOB(fd,2)=flag;
  6403. WFIFOSET(fd,packet_len(0x169));
  6404. }
  6405. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6406. /// 015a <char name>.24B <reason>.40B
  6407. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6408. {
  6409. unsigned char buf[128];
  6410. nullpo_retv(sd);
  6411. WBUFW(buf, 0)=0x15a;
  6412. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6413. memcpy(WBUFP(buf,26),mes,40);
  6414. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6415. }
  6416. /// Notifies clients of a guild of an expelled member.
  6417. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6418. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6419. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6420. {
  6421. unsigned char buf[128];
  6422. #if PACKETVER < 20100803
  6423. const unsigned short cmd = 0x15c;
  6424. #else
  6425. const unsigned short cmd = 0x839;
  6426. #endif
  6427. nullpo_retv(sd);
  6428. WBUFW(buf,0) = cmd;
  6429. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6430. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6431. #if PACKETVER < 20100803
  6432. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6433. #endif
  6434. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6435. }
  6436. /// Guild expulsion list (ZC_BAN_LIST).
  6437. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6438. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6439. void clif_guild_expulsionlist(struct map_session_data* sd)
  6440. {
  6441. #if PACKETVER < 20100803
  6442. const int offset = NAME_LENGTH*2+40;
  6443. #else
  6444. const int offset = NAME_LENGTH+40;
  6445. #endif
  6446. int fd, i, c = 0;
  6447. struct guild* g;
  6448. nullpo_retv(sd);
  6449. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6450. return;
  6451. fd = sd->fd;
  6452. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6453. WFIFOW(fd,0) = 0x163;
  6454. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6455. {
  6456. struct guild_expulsion* e = &g->expulsion[i];
  6457. if( e->account_id > 0 )
  6458. {
  6459. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6460. #if PACKETVER < 20100803
  6461. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6462. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6463. #else
  6464. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6465. #endif
  6466. c++;
  6467. }
  6468. }
  6469. WFIFOW(fd,2) = 4 + c*offset;
  6470. WFIFOSET(fd,WFIFOW(fd,2));
  6471. }
  6472. /// Guild chat message (ZC_GUILD_CHAT).
  6473. /// 017f <packet len>.W <message>.?B
  6474. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6475. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6476. struct map_session_data *sd;
  6477. uint8 buf[256];
  6478. if( len == 0 )
  6479. {
  6480. return;
  6481. }
  6482. else if( len > sizeof(buf)-5 )
  6483. {
  6484. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6485. len = sizeof(buf)-5;
  6486. }
  6487. WBUFW(buf, 0) = 0x17f;
  6488. WBUFW(buf, 2) = len + 5;
  6489. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6490. if ((sd = guild_getavailablesd(g)) != NULL)
  6491. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6492. }
  6493. /*==========================================
  6494. * Server tells client 'sd' that his guild skill 'skill_num' gone to level 'lv'
  6495. *------------------------------------------*/
  6496. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6497. {// TODO: Merge with clif_skillup (same packet).
  6498. int fd;
  6499. nullpo_ret(sd);
  6500. fd=sd->fd;
  6501. WFIFOHEAD(fd,11);
  6502. WFIFOW(fd,0) = 0x10e;
  6503. WFIFOW(fd,2) = skill_num;
  6504. WFIFOW(fd,4) = lv;
  6505. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6506. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6507. WFIFOB(fd,10) = 1;
  6508. WFIFOSET(fd,11);
  6509. return 0;
  6510. }
  6511. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6512. /// 0171 <inviter account id>.L <guild name>.24B
  6513. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6514. {
  6515. int fd;
  6516. nullpo_retv(sd);
  6517. fd=sd->fd;
  6518. WFIFOHEAD(fd,packet_len(0x171));
  6519. WFIFOW(fd,0)=0x171;
  6520. WFIFOL(fd,2)=account_id;
  6521. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6522. WFIFOSET(fd,packet_len(0x171));
  6523. }
  6524. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6525. /// 0173 <answer>.B
  6526. /// answer:
  6527. /// 0 = Already allied.
  6528. /// 1 = You rejected the offer.
  6529. /// 2 = You accepted the offer.
  6530. /// 3 = They have too any alliances.
  6531. /// 4 = You have too many alliances.
  6532. /// 5 = Alliances are disabled.
  6533. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6534. {
  6535. int fd;
  6536. nullpo_retv(sd);
  6537. fd=sd->fd;
  6538. WFIFOHEAD(fd,packet_len(0x173));
  6539. WFIFOW(fd,0)=0x173;
  6540. WFIFOL(fd,2)=flag;
  6541. WFIFOSET(fd,packet_len(0x173));
  6542. }
  6543. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6544. /// 0184 <other guild id>.L <relation>.L
  6545. /// relation:
  6546. /// 0 = Ally
  6547. /// 1 = Enemy
  6548. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6549. {
  6550. int fd;
  6551. nullpo_retv(sd);
  6552. fd = sd->fd;
  6553. if (fd <= 0)
  6554. return;
  6555. WFIFOHEAD(fd,packet_len(0x184));
  6556. WFIFOW(fd,0)=0x184;
  6557. WFIFOL(fd,2)=guild_id;
  6558. WFIFOL(fd,6)=flag;
  6559. WFIFOSET(fd,packet_len(0x184));
  6560. }
  6561. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6562. /// 0181 <result>.B
  6563. /// result:
  6564. /// 0 = Antagonist has been set.
  6565. /// 1 = Guild has too many Antagonists.
  6566. /// 2 = Already set as an Antagonist.
  6567. /// 3 = Antagonists are disabled.
  6568. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6569. {
  6570. int fd;
  6571. nullpo_retv(sd);
  6572. fd=sd->fd;
  6573. WFIFOHEAD(fd,packet_len(0x181));
  6574. WFIFOW(fd,0)=0x181;
  6575. WFIFOB(fd,2)=flag;
  6576. WFIFOSET(fd,packet_len(0x181));
  6577. }
  6578. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6579. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6580. /*
  6581. void clif_guild_allianceadded(struct guild *g,int idx)
  6582. {
  6583. unsigned char buf[64];
  6584. WBUFW(buf,0)=0x185;
  6585. WBUFL(buf,2)=g->alliance[idx].opposition;
  6586. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6587. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6588. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6589. }
  6590. */
  6591. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6592. /// 015e <reason>.L
  6593. /// 0 = success
  6594. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6595. /// 2 = there are still members in the guild
  6596. void clif_guild_broken(struct map_session_data *sd,int flag)
  6597. {
  6598. int fd;
  6599. nullpo_retv(sd);
  6600. fd=sd->fd;
  6601. WFIFOHEAD(fd,packet_len(0x15e));
  6602. WFIFOW(fd,0)=0x15e;
  6603. WFIFOL(fd,2)=flag;
  6604. WFIFOSET(fd,packet_len(0x15e));
  6605. }
  6606. /// Displays emotion on an object (ZC_EMOTION).
  6607. /// 00c0 <id>.L <type>.B
  6608. /// type:
  6609. /// enum emotion_type
  6610. void clif_emotion(struct block_list *bl,int type)
  6611. {
  6612. unsigned char buf[8];
  6613. nullpo_retv(bl);
  6614. WBUFW(buf,0)=0xc0;
  6615. WBUFL(buf,2)=bl->id;
  6616. WBUFB(buf,6)=type;
  6617. clif_send(buf,packet_len(0xc0),bl,AREA);
  6618. }
  6619. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6620. /// 0191 <id>.L <contents>.80B
  6621. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6622. {
  6623. unsigned char buf[MESSAGE_SIZE+6];
  6624. nullpo_retv(bl);
  6625. WBUFW(buf,0) = 0x191;
  6626. WBUFL(buf,2) = bl->id;
  6627. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6628. clif_send(buf,packet_len(0x191),bl,AREA);
  6629. }
  6630. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6631. /// 01ea <id>.L
  6632. void clif_wedding_effect(struct block_list *bl)
  6633. {
  6634. unsigned char buf[6];
  6635. nullpo_retv(bl);
  6636. WBUFW(buf,0) = 0x1ea;
  6637. WBUFL(buf,2) = bl->id;
  6638. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6639. }
  6640. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6641. /// 01e6 <partner name>.24B
  6642. void clif_callpartner(struct map_session_data *sd)
  6643. {
  6644. unsigned char buf[26];
  6645. const char *p;
  6646. nullpo_retv(sd);
  6647. // TODO: Send zero-length name if no partner (to initialize the client buffer).
  6648. if(sd->status.partner_id){
  6649. WBUFW(buf,0)=0x1e6;
  6650. p = map_charid2nick(sd->status.partner_id);
  6651. if(p){
  6652. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6653. }else{
  6654. WBUFB(buf,2) = 0;
  6655. }
  6656. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6657. }
  6658. }
  6659. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6660. /// 01e4
  6661. /// This packet while still implemented by the client is no longer being officially used.
  6662. /*
  6663. void clif_marriage_process(struct map_session_data *sd)
  6664. {
  6665. int fd;
  6666. nullpo_retv(sd);
  6667. fd=sd->fd;
  6668. WFIFOHEAD(fd,packet_len(0x1e4));
  6669. WFIFOW(fd,0)=0x1e4;
  6670. WFIFOSET(fd,packet_len(0x1e4));
  6671. }
  6672. */
  6673. /// Notice of divorce (ZC_DIVORCE).
  6674. /// 0205 <partner name>.24B
  6675. void clif_divorced(struct map_session_data* sd, const char* name)
  6676. {
  6677. int fd;
  6678. nullpo_retv(sd);
  6679. fd=sd->fd;
  6680. WFIFOHEAD(fd,packet_len(0x205));
  6681. WFIFOW(fd,0)=0x205;
  6682. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6683. WFIFOSET(fd, packet_len(0x205));
  6684. }
  6685. /// Marriage proposal (ZC_REQ_COUPLE).
  6686. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6687. /// This packet while still implemented by the client is no longer being officially used.
  6688. /*
  6689. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6690. {
  6691. nullpo_retv(sd);
  6692. WFIFOHEAD(fd,packet_len(0x1e2));
  6693. WFIFOW(fd,0) = 0x1e2;
  6694. WFIFOL(fd,2) = ssd->status.account_id;
  6695. WFIFOL(fd,6) = ssd->status.char_id;
  6696. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6697. WFIFOSET(fd, packet_len(0x1e2));
  6698. }
  6699. */
  6700. /*==========================================
  6701. *
  6702. *------------------------------------------*/
  6703. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6704. {
  6705. clif_disp_message(&sd->bl, mes, len, SELF);
  6706. }
  6707. /*==========================================
  6708. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6709. *------------------------------------------*/
  6710. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6711. {
  6712. unsigned char buf[256];
  6713. if( len == 0 )
  6714. {
  6715. return;
  6716. }
  6717. else if( len > sizeof(buf)-5 )
  6718. {
  6719. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6720. len = sizeof(buf)-5;
  6721. }
  6722. WBUFW(buf, 0) = 0x17f;
  6723. WBUFW(buf, 2) = len + 5;
  6724. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6725. clif_send(buf, WBUFW(buf,2), src, target);
  6726. }
  6727. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6728. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6729. /// 00cd <result>.B
  6730. /// result:
  6731. /// 0 = failure
  6732. /// 1 = success
  6733. void clif_GM_kickack(struct map_session_data *sd, int id)
  6734. {
  6735. int fd;
  6736. nullpo_retv(sd);
  6737. fd = sd->fd;
  6738. WFIFOHEAD(fd,packet_len(0xcd));
  6739. WFIFOW(fd,0) = 0xcd;
  6740. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6741. WFIFOSET(fd, packet_len(0xcd));
  6742. }
  6743. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6744. {
  6745. int fd = tsd->fd;
  6746. if( fd > 0 )
  6747. clif_authfail_fd(fd, 15);
  6748. else
  6749. map_quit(tsd);
  6750. if( sd )
  6751. clif_GM_kickack(sd,tsd->status.account_id);
  6752. }
  6753. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6754. /// 014a <result>.L
  6755. /// result:
  6756. /// 0 = "A manner point has been successfully aligned."
  6757. /// 1 = MP_FAILURE_EXHAUST
  6758. /// 2 = MP_FAILURE_ALREADY_GIVING
  6759. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6760. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6761. /// 5 = "You got a good point from %s."
  6762. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6763. {
  6764. int fd;
  6765. nullpo_retv(sd);
  6766. fd = sd->fd;
  6767. WFIFOHEAD(fd,packet_len(0x14a));
  6768. WFIFOW(fd,0) = 0x14a;
  6769. WFIFOL(fd,2) = type;
  6770. WFIFOSET(fd, packet_len(0x14a));
  6771. }
  6772. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6773. /// 014b <type>.B <GM name>.24B
  6774. /// type:
  6775. /// 0 = positive (unmute)
  6776. /// 1 = negative (mute)
  6777. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6778. {
  6779. int fd;
  6780. nullpo_retv(sd);
  6781. nullpo_retv(tsd);
  6782. fd = tsd->fd;
  6783. WFIFOHEAD(fd,packet_len(0x14b));
  6784. WFIFOW(fd,0) = 0x14b;
  6785. WFIFOB(fd,2) = type;
  6786. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6787. WFIFOSET(fd, packet_len(0x14b));
  6788. }
  6789. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6790. /// 00d1 <type>.B <result>.B
  6791. /// type:
  6792. /// 0 = /ex (deny)
  6793. /// 1 = /in (allow)
  6794. /// result:
  6795. /// 0 = success
  6796. /// 1 = failure
  6797. /// 2 = too many blocks
  6798. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6799. {
  6800. int fd;
  6801. nullpo_retv(sd);
  6802. fd=sd->fd;
  6803. WFIFOHEAD(fd,packet_len(0xd1));
  6804. WFIFOW(fd,0)=0xd1;
  6805. WFIFOB(fd,2)=type;
  6806. WFIFOB(fd,3)=flag;
  6807. WFIFOSET(fd,packet_len(0xd1));
  6808. }
  6809. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6810. /// 00d2 <type>.B <result>.B
  6811. /// type:
  6812. /// 0 = /exall (deny)
  6813. /// 1 = /inall (allow)
  6814. /// result:
  6815. /// 0 = success
  6816. /// 1 = failure
  6817. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6818. {
  6819. int fd;
  6820. nullpo_retv(sd);
  6821. fd=sd->fd;
  6822. WFIFOHEAD(fd,packet_len(0xd2));
  6823. WFIFOW(fd,0)=0xd2;
  6824. WFIFOB(fd,2)=type;
  6825. WFIFOB(fd,3)=flag;
  6826. WFIFOSET(fd,packet_len(0xd2));
  6827. }
  6828. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6829. /// 07fe <bgm>.24B
  6830. void clif_playBGM(struct map_session_data* sd, const char* name)
  6831. {
  6832. int fd;
  6833. nullpo_retv(sd);
  6834. fd = sd->fd;
  6835. WFIFOHEAD(fd,packet_len(0x7fe));
  6836. WFIFOW(fd,0) = 0x7fe;
  6837. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6838. WFIFOSET(fd,packet_len(0x7fe));
  6839. }
  6840. /// Plays/stops a wave sound (ZC_SOUND).
  6841. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6842. /// file name:
  6843. /// relative to data\wav
  6844. /// act:
  6845. /// 0 = play (once)
  6846. /// 1 = play (repeat, does not work)
  6847. /// 2 = stops all sound instances of file name (does not work)
  6848. /// term:
  6849. /// unknown purpose, only relevant to act = 1
  6850. /// npc id:
  6851. /// The accustic direction of the sound is determined by the
  6852. /// relative position of the NPC to the player (3D sound).
  6853. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6854. {
  6855. int fd;
  6856. nullpo_retv(sd);
  6857. nullpo_retv(bl);
  6858. fd = sd->fd;
  6859. WFIFOHEAD(fd,packet_len(0x1d3));
  6860. WFIFOW(fd,0) = 0x1d3;
  6861. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6862. WFIFOB(fd,26) = type;
  6863. WFIFOL(fd,27) = 0;
  6864. WFIFOL(fd,31) = bl->id;
  6865. WFIFOSET(fd,packet_len(0x1d3));
  6866. }
  6867. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6868. {
  6869. unsigned char buf[40];
  6870. nullpo_retv(bl);
  6871. WBUFW(buf,0) = 0x1d3;
  6872. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6873. WBUFB(buf,26) = type;
  6874. WBUFL(buf,27) = 0;
  6875. WBUFL(buf,31) = bl->id;
  6876. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6877. }
  6878. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6879. /// 01f3 <id>.L <effect id>.L
  6880. /// effect id:
  6881. /// @see doc/effect_list.txt
  6882. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6883. {
  6884. unsigned char buf[24];
  6885. nullpo_retv(bl);
  6886. memset(buf, 0, packet_len(0x1f3));
  6887. WBUFW(buf,0) = 0x1f3;
  6888. WBUFL(buf,2) = bl->id;
  6889. WBUFL(buf,6) = type;
  6890. clif_send(buf, packet_len(0x1f3), bl, target);
  6891. if (disguised(bl)) {
  6892. WBUFL(buf,2) = -bl->id;
  6893. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6894. }
  6895. }
  6896. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6897. {
  6898. WFIFOHEAD(fd,10);
  6899. WFIFOW(fd,0) = 0x1f3;
  6900. WFIFOL(fd,2) = bl->id;
  6901. WFIFOL(fd,6) = type;
  6902. WFIFOSET(fd,10);
  6903. }
  6904. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  6905. /// 0284 <id>.L <effect id>.L <num data>.L
  6906. /// effect id:
  6907. /// @see doc/effect_list.txt
  6908. /// num data:
  6909. /// effect-dependent value
  6910. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  6911. {
  6912. uint8 buf[14];
  6913. WBUFW(buf,0) = 0x284;
  6914. WBUFL(buf,2) = bl->id;
  6915. WBUFL(buf,6) = effect_id;
  6916. WBUFL(buf,10) = num;
  6917. clif_send(buf, packet_len(0x284), bl, target);
  6918. if( disguised(bl) )
  6919. {
  6920. WBUFL(buf,2) = -bl->id;
  6921. clif_send(buf, packet_len(0x284), bl, SELF);
  6922. }
  6923. }
  6924. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  6925. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6926. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  6927. unsigned short msg_len = strlen(msg) + 1;
  6928. WFIFOHEAD(sd->fd,msg_len + 12);
  6929. WFIFOW(sd->fd,0) = 0x2C1;
  6930. WFIFOW(sd->fd,2) = msg_len + 12;
  6931. WFIFOL(sd->fd,4) = 0;
  6932. WFIFOL(sd->fd,8) = color_table[color];
  6933. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  6934. clif_send(WFIFOP(sd->fd,0), WFIFOW(sd->fd,2), &sd->bl, SELF);
  6935. return 0;
  6936. }
  6937. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  6938. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6939. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  6940. unsigned short msg_len = strlen(msg) + 1;
  6941. uint8 buf[256];
  6942. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6943. nullpo_retv(bl);
  6944. if( msg_len > sizeof(buf)-12 )
  6945. {
  6946. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6947. msg_len = sizeof(buf)-12;
  6948. }
  6949. WBUFW(buf,0) = 0x2C1;
  6950. WBUFW(buf,2) = msg_len + 12;
  6951. WBUFL(buf,4) = bl->id;
  6952. WBUFL(buf,8) = color;
  6953. memcpy(WBUFP(buf,12), msg, msg_len);
  6954. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6955. }
  6956. /// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  6957. /// 008d <packet len>.W <id>.L <message>.?B
  6958. void clif_message(struct block_list* bl, const char* msg)
  6959. {
  6960. unsigned short msg_len = strlen(msg) + 1;
  6961. uint8 buf[256];
  6962. // TODO: Merge with other 0x8d functions.
  6963. nullpo_retv(bl);
  6964. if( msg_len > sizeof(buf)-8 )
  6965. {
  6966. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6967. msg_len = sizeof(buf)-8;
  6968. }
  6969. WBUFW(buf,0) = 0x8d;
  6970. WBUFW(buf,2) = msg_len + 8;
  6971. WBUFL(buf,4) = bl->id;
  6972. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  6973. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6974. }
  6975. // refresh the client's screen, getting rid of any effects
  6976. void clif_refresh(struct map_session_data *sd)
  6977. {
  6978. nullpo_retv(sd);
  6979. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6980. clif_inventorylist(sd);
  6981. if(pc_iscarton(sd)) {
  6982. clif_cartlist(sd);
  6983. clif_updatestatus(sd,SP_CARTINFO);
  6984. }
  6985. clif_updatestatus(sd,SP_WEIGHT);
  6986. clif_updatestatus(sd,SP_MAXWEIGHT);
  6987. clif_updatestatus(sd,SP_STR);
  6988. clif_updatestatus(sd,SP_AGI);
  6989. clif_updatestatus(sd,SP_VIT);
  6990. clif_updatestatus(sd,SP_INT);
  6991. clif_updatestatus(sd,SP_DEX);
  6992. clif_updatestatus(sd,SP_LUK);
  6993. if (sd->spiritball)
  6994. clif_spiritball_single(sd->fd, sd);
  6995. if (sd->vd.cloth_color)
  6996. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6997. if(merc_is_hom_active(sd->hd))
  6998. clif_send_homdata(sd,SP_ACK,0);
  6999. if( sd->md ) {
  7000. clif_mercenary_info(sd);
  7001. clif_mercenary_skillblock(sd);
  7002. }
  7003. if( sd->ed )
  7004. clif_elemental_info(sd);
  7005. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7006. clif_weather_check(sd);
  7007. if( sd->chatID )
  7008. chat_leavechat(sd,0);
  7009. if( sd->state.vending )
  7010. clif_openvending(sd, sd->bl.id, sd->vending);
  7011. if( pc_issit(sd) )
  7012. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7013. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7014. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7015. else
  7016. clif_changed_dir(&sd->bl, SELF);
  7017. // unlike vending, resuming buyingstore crashes the client.
  7018. buyingstore_close(sd);
  7019. mail_clear(sd);
  7020. }
  7021. /// Updates the object's (bl) name on client.
  7022. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7023. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7024. void clif_charnameack (int fd, struct block_list *bl)
  7025. {
  7026. unsigned char buf[103];
  7027. int cmd = 0x95, i, ps = -1;
  7028. nullpo_retv(bl);
  7029. WBUFW(buf,0) = cmd;
  7030. WBUFL(buf,2) = bl->id;
  7031. switch( bl->type )
  7032. {
  7033. case BL_PC:
  7034. {
  7035. struct map_session_data *ssd = (struct map_session_data *)bl;
  7036. struct party_data *p = NULL;
  7037. struct guild *g = NULL;
  7038. //Requesting your own "shadow" name. [Skotlex]
  7039. if (ssd->fd == fd && ssd->disguise)
  7040. WBUFL(buf,2) = -bl->id;
  7041. if( ssd->fakename[0] )
  7042. {
  7043. WBUFW(buf, 0) = cmd = 0x195;
  7044. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7045. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7046. break;
  7047. }
  7048. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7049. if( ssd->status.party_id )
  7050. {
  7051. p = party_search(ssd->status.party_id);
  7052. }
  7053. if( ssd->status.guild_id )
  7054. {
  7055. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  7056. {
  7057. 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);
  7058. if( i < g->max_member ) ps = g->member[i].position;
  7059. }
  7060. }
  7061. if( !battle_config.display_party_name && g == NULL )
  7062. {// do not display party unless the player is also in a guild
  7063. p = NULL;
  7064. }
  7065. if (p == NULL && g == NULL)
  7066. break;
  7067. WBUFW(buf, 0) = cmd = 0x195;
  7068. if (p)
  7069. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7070. else
  7071. WBUFB(buf,30) = 0;
  7072. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7073. {
  7074. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7075. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7076. } else { //Assume no guild.
  7077. WBUFB(buf,54) = 0;
  7078. WBUFB(buf,78) = 0;
  7079. }
  7080. }
  7081. break;
  7082. //[blackhole89]
  7083. case BL_HOM:
  7084. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7085. break;
  7086. case BL_MER:
  7087. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7088. break;
  7089. case BL_PET:
  7090. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7091. break;
  7092. case BL_NPC:
  7093. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7094. break;
  7095. case BL_MOB:
  7096. {
  7097. struct mob_data *md = (struct mob_data *)bl;
  7098. nullpo_retv(md);
  7099. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7100. if( md->guardian_data && md->guardian_data->guild_id )
  7101. {
  7102. WBUFW(buf, 0) = cmd = 0x195;
  7103. WBUFB(buf,30) = 0;
  7104. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7105. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7106. }
  7107. else if( battle_config.show_mob_info )
  7108. {
  7109. char mobhp[50], *str_p = mobhp;
  7110. WBUFW(buf, 0) = cmd = 0x195;
  7111. if( battle_config.show_mob_info&4 )
  7112. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7113. if( battle_config.show_mob_info&1 )
  7114. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7115. if( battle_config.show_mob_info&2 )
  7116. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7117. //Even thought mobhp ain't a name, we send it as one so the client
  7118. //can parse it. [Skotlex]
  7119. if( str_p != mobhp )
  7120. {
  7121. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7122. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7123. WBUFB(buf,54) = 0;
  7124. WBUFB(buf,78) = 0;
  7125. }
  7126. }
  7127. }
  7128. break;
  7129. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7130. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7131. // break;
  7132. return;
  7133. case BL_ELEM:
  7134. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7135. break;
  7136. default:
  7137. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7138. return;
  7139. }
  7140. // if no receipient specified just update nearby clients
  7141. if (fd == 0)
  7142. clif_send(buf, packet_len(cmd), bl, AREA);
  7143. else {
  7144. WFIFOHEAD(fd, packet_len(cmd));
  7145. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7146. WFIFOSET(fd, packet_len(cmd));
  7147. }
  7148. }
  7149. //Used to update when a char leaves a party/guild. [Skotlex]
  7150. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7151. void clif_charnameupdate (struct map_session_data *ssd)
  7152. {
  7153. unsigned char buf[103];
  7154. int cmd = 0x195, ps = -1, i;
  7155. struct party_data *p = NULL;
  7156. struct guild *g = NULL;
  7157. nullpo_retv(ssd);
  7158. if( ssd->fakename[0] )
  7159. return; //No need to update as the party/guild was not displayed anyway.
  7160. WBUFW(buf,0) = cmd;
  7161. WBUFL(buf,2) = ssd->bl.id;
  7162. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7163. if (!battle_config.display_party_name) {
  7164. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  7165. p = party_search(ssd->status.party_id);
  7166. }else{
  7167. if (ssd->status.party_id > 0)
  7168. p = party_search(ssd->status.party_id);
  7169. }
  7170. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  7171. {
  7172. 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);
  7173. if( i < g->max_member ) ps = g->member[i].position;
  7174. }
  7175. if( p )
  7176. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7177. else
  7178. WBUFB(buf,30) = 0;
  7179. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7180. {
  7181. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7182. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7183. }
  7184. else
  7185. {
  7186. WBUFB(buf,54) = 0;
  7187. WBUFB(buf,78) = 0;
  7188. }
  7189. // Update nearby clients
  7190. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7191. }
  7192. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7193. /// 01ff <id>.L <x>.W <y>.W
  7194. ///
  7195. /// Visually moves(instant) a character to x,y. The char moves even
  7196. /// when the target cell isn't walkable. If the char is sitting it
  7197. /// stays that way.
  7198. void clif_slide(struct block_list *bl, int x, int y)
  7199. {
  7200. unsigned char buf[10];
  7201. nullpo_retv(bl);
  7202. WBUFW(buf, 0) = 0x01ff;
  7203. WBUFL(buf, 2) = bl->id;
  7204. WBUFW(buf, 6) = x;
  7205. WBUFW(buf, 8) = y;
  7206. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7207. if( disguised(bl) )
  7208. {
  7209. WBUFL(buf,2) = -bl->id;
  7210. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7211. }
  7212. }
  7213. /*------------------------------------------
  7214. * @me command by lordalfa, rewritten implementation by Skotlex
  7215. *------------------------------------------*/
  7216. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  7217. {
  7218. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7219. int len_mes = strlen(mes)+1; //Account for \0
  7220. if (len_mes > sizeof(buf)-8) {
  7221. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7222. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7223. }
  7224. // send message to others
  7225. WBUFW(buf,0) = 0x8d;
  7226. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7227. WBUFL(buf,4) = sd->bl.id;
  7228. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7229. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7230. // send back message to the speaker
  7231. WBUFW(buf,0) = 0x8e;
  7232. WBUFW(buf, 2) = len_mes + 4;
  7233. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7234. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7235. }
  7236. /*==========================
  7237. * Minimap fix [Kevin]
  7238. * Remove dot from minimap
  7239. *--------------------------*/
  7240. void clif_party_xy_remove(struct map_session_data *sd)
  7241. {
  7242. unsigned char buf[16];
  7243. nullpo_retv(sd);
  7244. WBUFW(buf,0)=0x107;
  7245. WBUFL(buf,2)=sd->status.account_id;
  7246. WBUFW(buf,6)=-1;
  7247. WBUFW(buf,8)=-1;
  7248. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7249. }
  7250. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7251. /// 0215 <msg id>.L
  7252. /// msg id:
  7253. /// 0x15 = End all negative status (PA_GOSPEL)
  7254. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7255. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7256. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7257. /// 0x19 = All stats +20 (PA_GOSPEL)
  7258. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7259. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7260. /// 0x1e = DEF +25% (PA_GOSPEL)
  7261. /// 0x1f = ATK +100% (PA_GOSPEL)
  7262. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7263. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7264. /// ? = nothing
  7265. void clif_gospel_info(struct map_session_data *sd, int type)
  7266. {
  7267. int fd=sd->fd;
  7268. WFIFOHEAD(fd,packet_len(0x215));
  7269. WFIFOW(fd,0)=0x215;
  7270. WFIFOL(fd,2)=type;
  7271. WFIFOSET(fd, packet_len(0x215));
  7272. }
  7273. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7274. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7275. /// result:
  7276. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7277. /// star:
  7278. /// 0 = Place of the Sun
  7279. /// 1 = Place of the Moon
  7280. /// 2 = Place of the Stars
  7281. /// 1 = Star Gladiator %s's %s: <mapname>
  7282. /// star:
  7283. /// 0 = Place of the Sun
  7284. /// 1 = Place of the Moon
  7285. /// 2 = Place of the Stars
  7286. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7287. /// star:
  7288. /// 0 = Target of the Sun
  7289. /// 1 = Target of the Moon
  7290. /// 2 = Target of the Stars
  7291. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7292. /// star:
  7293. /// 0 = Monster of the Sun
  7294. /// 1 = Monster of the Moon
  7295. /// 2 = Monster of the Stars
  7296. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7297. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7298. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7299. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7300. /// 40 = Target HP : <monster_id used as HP>
  7301. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7302. {
  7303. int fd = sd->fd;
  7304. WFIFOHEAD(fd,packet_len(0x20e));
  7305. WFIFOW(fd,0) = 0x20e;
  7306. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7307. WFIFOL(fd,26) = monster_id;
  7308. WFIFOB(fd,30) = star;
  7309. WFIFOB(fd,31) = result;
  7310. WFIFOSET(fd,packet_len(0x20e));
  7311. }
  7312. /*==========================================
  7313. * Info about Star Glaldiator save map [Komurka]
  7314. * type: 1: Information, 0: Map registered
  7315. *------------------------------------------*/
  7316. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7317. {
  7318. char mapname[MAP_NAME_LENGTH_EXT];
  7319. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7320. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7321. }
  7322. /*==========================================
  7323. * Info about Star Glaldiator hate mob [Komurka]
  7324. * type: 1: Register mob, 0: Information.
  7325. *------------------------------------------*/
  7326. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7327. {
  7328. if( pcdb_checkid(class_) )
  7329. {
  7330. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7331. }
  7332. else if( mobdb_checkid(class_) )
  7333. {
  7334. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7335. }
  7336. else
  7337. {
  7338. 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);
  7339. }
  7340. }
  7341. /*==========================================
  7342. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7343. *------------------------------------------*/
  7344. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7345. {
  7346. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7347. }
  7348. /*==========================================
  7349. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7350. *------------------------------------------*/
  7351. void clif_feel_hate_reset(struct map_session_data *sd)
  7352. {
  7353. clif_starskill(sd, "", 0, 0, 30);
  7354. }
  7355. /// Equip window (un)tick ack (ZC_CONFIG).
  7356. /// 02d9 <type>.L <value>.L
  7357. /// type:
  7358. /// 0 = open equip window
  7359. /// value:
  7360. /// 0 = disabled
  7361. /// 1 = enabled
  7362. void clif_equiptickack(struct map_session_data* sd, int flag)
  7363. {
  7364. int fd;
  7365. nullpo_retv(sd);
  7366. fd = sd->fd;
  7367. WFIFOHEAD(fd, packet_len(0x2d9));
  7368. WFIFOW(fd, 0) = 0x2d9;
  7369. WFIFOL(fd, 2) = 0;
  7370. WFIFOL(fd, 6) = flag;
  7371. WFIFOSET(fd, packet_len(0x2d9));
  7372. }
  7373. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7374. /// 02da <open equip window>.B
  7375. /// open equip window:
  7376. /// 0 = disabled
  7377. /// 1 = enabled
  7378. void clif_equipcheckbox(struct map_session_data* sd)
  7379. {
  7380. int fd;
  7381. nullpo_retv(sd);
  7382. fd = sd->fd;
  7383. WFIFOHEAD(fd, packet_len(0x2da));
  7384. WFIFOW(fd, 0) = 0x2da;
  7385. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7386. WFIFOSET(fd, packet_len(0x2da));
  7387. }
  7388. /// Sends info about a player's equipped items.
  7389. /// 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)
  7390. /// 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)
  7391. /// 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)
  7392. /// 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)
  7393. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7394. {
  7395. uint8* buf;
  7396. int i, n, fd, offset = 0;
  7397. #if PACKETVER < 20100629
  7398. const int s = 26;
  7399. #else
  7400. const int s = 28;
  7401. #endif
  7402. nullpo_retv(sd);
  7403. nullpo_retv(tsd);
  7404. fd = sd->fd;
  7405. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7406. buf = WFIFOP(fd,0);
  7407. #if PACKETVER < 20101124
  7408. WBUFW(buf, 0) = 0x2d7;
  7409. #else
  7410. WBUFW(buf, 0) = 0x859;
  7411. #endif
  7412. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7413. WBUFW(buf,28) = tsd->status.class_;
  7414. WBUFW(buf,30) = tsd->vd.hair_style;
  7415. WBUFW(buf,32) = tsd->vd.head_bottom;
  7416. WBUFW(buf,34) = tsd->vd.head_mid;
  7417. WBUFW(buf,36) = tsd->vd.head_top;
  7418. #if PACKETVER >= 20110111
  7419. WBUFW(buf,38) = tsd->vd.robe;
  7420. offset+= 2;
  7421. buf = WBUFP(buf,2);
  7422. #endif
  7423. WBUFW(buf,38) = tsd->vd.hair_color;
  7424. WBUFW(buf,40) = tsd->vd.cloth_color;
  7425. WBUFB(buf,42) = tsd->vd.sex;
  7426. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7427. {
  7428. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7429. continue;
  7430. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7431. continue;
  7432. // Inventory position
  7433. WBUFW(buf, n*s+43) = i + 2;
  7434. // Add refine, identify flag, element, etc.
  7435. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7436. // Add cards
  7437. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7438. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7439. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7440. WBUFW(buf, n*s+67) = 0;
  7441. #if PACKETVER >= 20100629
  7442. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7443. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7444. else
  7445. WBUFW(buf, n*s+69) = 0;
  7446. #endif
  7447. n++;
  7448. }
  7449. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7450. WFIFOSET(fd, WFIFOW(fd, 2));
  7451. }
  7452. /// Display msgstringtable.txt string (ZC_MSG).
  7453. /// 0291 <message>.W
  7454. void clif_msg(struct map_session_data* sd, unsigned short id)
  7455. {
  7456. int fd;
  7457. nullpo_retv(sd);
  7458. fd = sd->fd;
  7459. WFIFOHEAD(fd, packet_len(0x291));
  7460. WFIFOW(fd, 0) = 0x291;
  7461. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7462. WFIFOSET(fd, packet_len(0x291));
  7463. }
  7464. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7465. /// 0x7e2 <message>.W <value>.L
  7466. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7467. {
  7468. int fd = sd->fd;
  7469. WFIFOHEAD(fd, packet_len(0x7e2));
  7470. WFIFOW(fd,0) = 0x7e2;
  7471. WFIFOW(fd,2) = id;
  7472. WFIFOL(fd,4) = value;
  7473. WFIFOSET(fd, packet_len(0x7e2));
  7474. }
  7475. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7476. /// 07e6 <skill id>.W <msg id>.L
  7477. ///
  7478. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7479. /// "[SkillName] Message"
  7480. void clif_msg_skill(struct map_session_data* sd, unsigned short skill_id, int msg_id)
  7481. {
  7482. int fd = sd->fd;
  7483. WFIFOHEAD(fd, packet_len(0x7e6));
  7484. WFIFOW(fd,0) = 0x7e6;
  7485. WFIFOW(fd,2) = skill_id;
  7486. WFIFOL(fd,4) = msg_id;
  7487. WFIFOSET(fd, packet_len(0x7e6));
  7488. }
  7489. /// View player equip request denied
  7490. void clif_viewequip_fail(struct map_session_data* sd)
  7491. {
  7492. clif_msg(sd, 0x54d);
  7493. }
  7494. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7495. /// Returns true if the packet was parsed successfully.
  7496. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7497. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7498. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7499. {
  7500. char *text, *name, *message;
  7501. unsigned int packetlen, textlen, namelen, messagelen;
  7502. int fd = sd->fd;
  7503. *name_ = NULL;
  7504. *namelen_ = 0;
  7505. *message_ = NULL;
  7506. *messagelen_ = 0;
  7507. packetlen = RFIFOW(fd,2);
  7508. // basic structure checks
  7509. if( packetlen < 4 + 1 )
  7510. { // 4-byte header and at least an empty string is expected
  7511. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7512. return false;
  7513. }
  7514. text = (char*)RFIFOP(fd,4);
  7515. textlen = packetlen - 4;
  7516. // process <name> part of the packet
  7517. if( format == 0 )
  7518. {// name and message are separated by ' : '
  7519. // validate name
  7520. name = text;
  7521. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7522. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7523. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7524. {
  7525. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7526. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7527. set_eof(fd); // Just kick them out to correct it.
  7528. return false;
  7529. }
  7530. message = name + namelen + 3;
  7531. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7532. }
  7533. else
  7534. {// name has fixed width
  7535. if( textlen < NAME_LENGTH + 1 )
  7536. {
  7537. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7538. return false;
  7539. }
  7540. // validate name
  7541. name = text;
  7542. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7543. if( name[namelen] != '\0' )
  7544. { // only restriction is that the name must be zero-terminated
  7545. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7546. return false;
  7547. }
  7548. message = name + NAME_LENGTH;
  7549. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7550. }
  7551. if( messagelen != strnlen(message, messagelen)+1 )
  7552. { // the declared length must match real length
  7553. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7554. return false;
  7555. }
  7556. // verify <message> part of the packet
  7557. if( message[messagelen-1] != '\0' )
  7558. { // message must be zero-terminated
  7559. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7560. return false;
  7561. }
  7562. if( messagelen > CHAT_SIZE_MAX-1 )
  7563. { // messages mustn't be too long
  7564. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7565. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7566. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7567. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7568. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7569. return false;
  7570. }
  7571. *name_ = name;
  7572. *namelen_ = namelen;
  7573. *message_ = message;
  7574. *messagelen_ = messagelen;
  7575. return true;
  7576. }
  7577. // ---------------------
  7578. // clif_guess_PacketVer
  7579. // ---------------------
  7580. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7581. // error codes:
  7582. // 0 - Success
  7583. // 1 - Unknown packet_ver
  7584. // 2 - Invalid account_id
  7585. // 3 - Invalid char_id
  7586. // 4 - Invalid login_id1 (reserved)
  7587. // 5 - Invalid client_tick (reserved)
  7588. // 6 - Invalid sex
  7589. // Only the first 'invalid' error that appears is used.
  7590. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7591. {
  7592. static int err = 1;
  7593. static int packet_ver = -1;
  7594. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7595. if (get_previous)
  7596. {//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]
  7597. if( error )
  7598. *error = err;
  7599. return packet_ver;
  7600. }
  7601. //By default, start searching on the default one.
  7602. err = 1;
  7603. packet_ver = clif_config.packet_db_ver;
  7604. cmd = RFIFOW(fd,0);
  7605. packet_len = RFIFOREST(fd);
  7606. #define SET_ERROR(n) \
  7607. if( err == 1 )\
  7608. err = n;\
  7609. //define SET_ERROR
  7610. // FIXME: If the packet is not received at once, this will FAIL.
  7611. // Figure out, when it happens, that only part of the packet is
  7612. // received, or fix the function to be able to deal with that
  7613. // case.
  7614. #define CHECK_PACKET_VER() \
  7615. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7616. ;/* not wanttoconnection or wrong length */\
  7617. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7618. { SET_ERROR(2); }/* invalid account_id */\
  7619. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7620. { SET_ERROR(3); }/* invalid char_id */\
  7621. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7622. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7623. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7624. { SET_ERROR(6); }/* invalid sex */\
  7625. else\
  7626. {\
  7627. err = 0;\
  7628. if( error )\
  7629. *error = 0;\
  7630. return packet_ver;\
  7631. }\
  7632. //define CHECK_PACKET_VER
  7633. CHECK_PACKET_VER();//Default packet version found.
  7634. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7635. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7636. CHECK_PACKET_VER();
  7637. }
  7638. if( error )
  7639. *error = err;
  7640. packet_ver = -1;
  7641. return -1;
  7642. #undef SET_ERROR
  7643. #undef CHECK_PACKET_VER
  7644. }
  7645. // ------------
  7646. // clif_parse_*
  7647. // ------------
  7648. // Parses incoming (player) connection
  7649. /// Request to connect to map-server.
  7650. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7651. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7652. /// There are various variants of this packet, some of them have padding between fields.
  7653. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7654. {
  7655. struct block_list* bl;
  7656. struct auth_node* node;
  7657. int cmd, account_id, char_id, login_id1, sex;
  7658. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7659. 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])
  7660. if (sd) {
  7661. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7662. return;
  7663. }
  7664. // Only valid packet version get here
  7665. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7666. cmd = RFIFOW(fd,0);
  7667. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7668. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7669. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7670. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7671. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7672. if( packet_ver < 5 || // reject really old client versions
  7673. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7674. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7675. {// packet version rejected
  7676. 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));
  7677. WFIFOHEAD(fd,packet_len(0x6a));
  7678. WFIFOW(fd,0) = 0x6a;
  7679. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7680. WFIFOSET(fd,packet_len(0x6a));
  7681. set_eof(fd);
  7682. return;
  7683. }
  7684. if( runflag != MAPSERVER_ST_RUNNING )
  7685. {// not allowed
  7686. clif_authfail_fd(fd,1);// server closed
  7687. return;
  7688. }
  7689. //Check for double login.
  7690. bl = map_id2bl(account_id);
  7691. if(bl && bl->type != BL_PC) {
  7692. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7693. WFIFOHEAD(fd,packet_len(0x6a));
  7694. WFIFOW(fd,0) = 0x6a;
  7695. WFIFOB(fd,2) = 3; // Rejected by server
  7696. WFIFOSET(fd,packet_len(0x6a));
  7697. set_eof(fd);
  7698. return;
  7699. }
  7700. if (bl ||
  7701. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7702. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7703. {
  7704. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7705. return;
  7706. }
  7707. CREATE(sd, TBL_PC, 1);
  7708. sd->fd = fd;
  7709. sd->packet_ver = packet_ver;
  7710. session[fd]->session_data = sd;
  7711. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7712. #if PACKETVER < 20070521
  7713. WFIFOHEAD(fd,4);
  7714. WFIFOL(fd,0) = sd->bl.id;
  7715. WFIFOSET(fd,4);
  7716. #else
  7717. WFIFOHEAD(fd,packet_len(0x283));
  7718. WFIFOW(fd,0) = 0x283;
  7719. WFIFOL(fd,2) = sd->bl.id;
  7720. WFIFOSET(fd,packet_len(0x283));
  7721. #endif
  7722. chrif_authreq(sd);
  7723. }
  7724. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7725. /// 007d
  7726. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7727. {
  7728. if(sd->bl.prev != NULL)
  7729. return;
  7730. if (!sd->state.active)
  7731. { //Character loading is not complete yet!
  7732. //Let pc_reg_received reinvoke this when ready.
  7733. sd->state.connect_new = 0;
  7734. return;
  7735. }
  7736. if (sd->state.rewarp)
  7737. { //Rewarp player.
  7738. sd->state.rewarp = 0;
  7739. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7740. return;
  7741. }
  7742. sd->state.warping = 0;
  7743. // look
  7744. #if PACKETVER < 4
  7745. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7746. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7747. #else
  7748. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7749. #endif
  7750. if(sd->vd.cloth_color)
  7751. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7752. // item
  7753. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7754. pc_checkitem(sd);
  7755. // cart
  7756. if(pc_iscarton(sd)) {
  7757. clif_cartlist(sd);
  7758. clif_updatestatus(sd,SP_CARTINFO);
  7759. }
  7760. // weight
  7761. clif_updatestatus(sd,SP_WEIGHT);
  7762. clif_updatestatus(sd,SP_MAXWEIGHT);
  7763. // guild
  7764. // (needs to go before clif_spawn() to show guild emblems correctly)
  7765. if(sd->status.guild_id)
  7766. guild_send_memberinfoshort(sd,1);
  7767. if(battle_config.pc_invincible_time > 0) {
  7768. if(map_flag_gvg(sd->bl.m))
  7769. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7770. else
  7771. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7772. }
  7773. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7774. map_spawnmobs(sd->bl.m);
  7775. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7776. {// increment the number of pvp players on the map
  7777. map[sd->bl.m].users_pvp++;
  7778. }
  7779. if( map[sd->bl.m].instance_id )
  7780. {
  7781. instance[map[sd->bl.m].instance_id].users++;
  7782. instance_check_idle(map[sd->bl.m].instance_id);
  7783. }
  7784. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7785. // reset the callshop flag if the player changes map
  7786. sd->state.callshop = 0;
  7787. map_addblock(&sd->bl);
  7788. clif_spawn(&sd->bl);
  7789. // Party
  7790. // (needs to go after clif_spawn() to show hp bars correctly)
  7791. if(sd->status.party_id) {
  7792. party_send_movemap(sd);
  7793. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7794. }
  7795. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7796. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7797. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7798. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7799. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7800. sd->pvp_rank = 0;
  7801. sd->pvp_lastusers = 0;
  7802. sd->pvp_point = 5;
  7803. sd->pvp_won = 0;
  7804. sd->pvp_lost = 0;
  7805. }
  7806. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7807. } else
  7808. // set flag, if it's a duel [LuzZza]
  7809. if(sd->duel_group)
  7810. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7811. if (map[sd->bl.m].flag.gvg_dungeon)
  7812. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7813. if( map_flag_gvg(sd->bl.m) )
  7814. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7815. // info about nearby objects
  7816. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7817. 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);
  7818. // pet
  7819. if( sd->pd )
  7820. {
  7821. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7822. { //Return the pet to egg. [Skotlex]
  7823. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7824. pet_menu(sd, 3); //Option 3 is return to egg.
  7825. }
  7826. else
  7827. {
  7828. map_addblock(&sd->pd->bl);
  7829. clif_spawn(&sd->pd->bl);
  7830. clif_send_petdata(sd,sd->pd,0,0);
  7831. clif_send_petstatus(sd);
  7832. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7833. }
  7834. }
  7835. //homunculus [blackhole89]
  7836. if( merc_is_hom_active(sd->hd) )
  7837. {
  7838. map_addblock(&sd->hd->bl);
  7839. clif_spawn(&sd->hd->bl);
  7840. clif_send_homdata(sd,SP_ACK,0);
  7841. clif_hominfo(sd,sd->hd,1);
  7842. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7843. clif_homskillinfoblock(sd);
  7844. if( battle_config.hom_setting&0x8 )
  7845. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7846. if( !(battle_config.hom_setting&0x2) )
  7847. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7848. }
  7849. if( sd->md ) {
  7850. map_addblock(&sd->md->bl);
  7851. clif_spawn(&sd->md->bl);
  7852. clif_mercenary_info(sd);
  7853. clif_mercenary_skillblock(sd);
  7854. }
  7855. if( sd->ed ) {
  7856. map_addblock(&sd->ed->bl);
  7857. clif_spawn(&sd->ed->bl);
  7858. clif_elemental_info(sd);
  7859. clif_elemental_updatestatus(sd,SP_HP);
  7860. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.matk_max);
  7861. clif_elemental_updatestatus(sd,SP_SP);
  7862. }
  7863. if(sd->state.connect_new) {
  7864. int lv;
  7865. sd->state.connect_new = 0;
  7866. clif_skillinfoblock(sd);
  7867. clif_hotkeys_send(sd);
  7868. clif_updatestatus(sd,SP_BASEEXP);
  7869. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7870. clif_updatestatus(sd,SP_JOBEXP);
  7871. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7872. clif_updatestatus(sd,SP_SKILLPOINT);
  7873. clif_initialstatus(sd);
  7874. if (sd->sc.option&OPTION_FALCON)
  7875. clif_status_load(&sd->bl, SI_FALCON, 1);
  7876. if (sd->sc.option&OPTION_RIDING)
  7877. clif_status_load(&sd->bl, SI_RIDING, 1);
  7878. if(sd->status.manner < 0)
  7879. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7880. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7881. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7882. if(sd->bl.m == sd->feel_map[0].m
  7883. || sd->bl.m == sd->feel_map[1].m
  7884. || sd->bl.m == sd->feel_map[2].m)
  7885. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7886. }
  7887. if(sd->pd && sd->pd->pet.intimate > 900)
  7888. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7889. if(merc_is_hom_active(sd->hd))
  7890. merc_hom_init_timers(sd->hd);
  7891. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7892. {
  7893. sd->state.night = 1;
  7894. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7895. }
  7896. // Notify everyone that this char logged in [Skotlex].
  7897. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7898. //Login Event
  7899. npc_script_event(sd, NPCE_LOGIN);
  7900. } else {
  7901. //For some reason the client "loses" these on warp/map-change.
  7902. clif_updatestatus(sd,SP_STR);
  7903. clif_updatestatus(sd,SP_AGI);
  7904. clif_updatestatus(sd,SP_VIT);
  7905. clif_updatestatus(sd,SP_INT);
  7906. clif_updatestatus(sd,SP_DEX);
  7907. clif_updatestatus(sd,SP_LUK);
  7908. // abort currently running script
  7909. sd->state.using_fake_npc = 0;
  7910. sd->state.menu_or_input = 0;
  7911. sd->npc_menu = 0;
  7912. if(sd->npc_id)
  7913. npc_event_dequeue(sd);
  7914. }
  7915. if( sd->state.changemap )
  7916. {// restore information that gets lost on map-change
  7917. #if PACKETVER >= 20070918
  7918. clif_partyinvitationstate(sd);
  7919. clif_equipcheckbox(sd);
  7920. #endif
  7921. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7922. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7923. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7924. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7925. { //Display night.
  7926. if( !sd->state.night )
  7927. {
  7928. sd->state.night = 1;
  7929. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7930. }
  7931. }
  7932. else if( sd->state.night )
  7933. { //Clear night display.
  7934. sd->state.night = 0;
  7935. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7936. }
  7937. if( map[sd->bl.m].flag.battleground )
  7938. {
  7939. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7940. if( map[sd->bl.m].flag.battleground == 2 )
  7941. clif_bg_updatescore_single(sd);
  7942. }
  7943. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7944. {
  7945. char output[128];
  7946. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7947. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7948. }
  7949. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7950. sd->state.changemap = false;
  7951. }
  7952. mail_clear(sd);
  7953. /* Guild Aura Init */
  7954. if( sd->state.gmaster_flag ) {
  7955. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  7956. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  7957. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  7958. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  7959. }
  7960. if(map[sd->bl.m].flag.loadevent) // Lance
  7961. npc_script_event(sd, NPCE_LOADMAP);
  7962. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7963. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7964. if (sd->sc.opt2) //Client loses these on warp.
  7965. clif_changeoption(&sd->bl);
  7966. clif_weather_check(sd);
  7967. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7968. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7969. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7970. else
  7971. sd->areanpc_id = 0;
  7972. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7973. if(pc_isdead(sd))
  7974. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7975. else {
  7976. skill_usave_trigger(sd);
  7977. clif_changed_dir(&sd->bl, SELF);
  7978. }
  7979. // Trigger skill effects if you appear standing on them
  7980. if(!battle_config.pc_invincible_time)
  7981. skill_unit_move(&sd->bl,gettick(),1);
  7982. }
  7983. /// Request for server's tick.
  7984. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  7985. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  7986. /// There are various variants of this packet, some of them have padding between fields.
  7987. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7988. {
  7989. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7990. WFIFOHEAD(fd, packet_len(0x7f));
  7991. WFIFOW(fd,0)=0x7f;
  7992. WFIFOL(fd,2)=gettick();
  7993. WFIFOSET(fd,packet_len(0x7f));
  7994. // removed until the socket problems are fixed. [FlavioJS]
  7995. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7996. }
  7997. /// Sends hotkey bar.
  7998. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  7999. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8000. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8001. void clif_hotkeys_send(struct map_session_data *sd) {
  8002. #ifdef HOTKEY_SAVING
  8003. const int fd = sd->fd;
  8004. int i;
  8005. #if PACKETVER < 20090603
  8006. const int cmd = 0x2b9;
  8007. #else
  8008. const int cmd = 0x7d9;
  8009. #endif
  8010. if (!fd) return;
  8011. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8012. WFIFOW(fd, 0) = cmd;
  8013. for(i = 0; i < MAX_HOTKEYS; i++) {
  8014. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8015. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8016. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8017. }
  8018. WFIFOSET(fd, packet_len(cmd));
  8019. #endif
  8020. }
  8021. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8022. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8023. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8024. #ifdef HOTKEY_SAVING
  8025. unsigned short idx;
  8026. int cmd;
  8027. cmd = RFIFOW(fd, 0);
  8028. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8029. if (idx >= MAX_HOTKEYS) return;
  8030. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8031. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8032. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8033. #endif
  8034. }
  8035. /// Displays cast-like progress bar (ZC_PROGRESS).
  8036. /// 02f0 <color>.L <time>.L
  8037. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8038. {
  8039. int fd = sd->fd;
  8040. WFIFOHEAD(fd,packet_len(0x2f0));
  8041. WFIFOW(fd,0) = 0x2f0;
  8042. WFIFOL(fd,2) = color;
  8043. WFIFOL(fd,6) = second;
  8044. WFIFOSET(fd,packet_len(0x2f0));
  8045. }
  8046. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8047. /// 02f2
  8048. void clif_progressbar_abort(struct map_session_data * sd)
  8049. {
  8050. int fd = sd->fd;
  8051. WFIFOHEAD(fd,packet_len(0x2f2));
  8052. WFIFOW(fd,0) = 0x2f2;
  8053. WFIFOSET(fd,packet_len(0x2f2));
  8054. }
  8055. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8056. /// 02f1
  8057. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8058. {
  8059. int npc_id = sd->progressbar.npc_id;
  8060. if( gettick() < sd->progressbar.timeout && sd->st )
  8061. sd->st->state = END;
  8062. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8063. npc_scriptcont(sd, npc_id);
  8064. }
  8065. /// Request to walk to a certain position on the current map.
  8066. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8067. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8068. /// There are various variants of this packet, some of them have padding between fields.
  8069. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8070. {
  8071. short x, y;
  8072. if (pc_isdead(sd)) {
  8073. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8074. return;
  8075. }
  8076. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8077. ; //You CAN walk on this OPT1 value.
  8078. else if( sd->progressbar.npc_id )
  8079. clif_progressbar_abort(sd);
  8080. else if (pc_cant_act(sd))
  8081. return;
  8082. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8083. return;
  8084. pc_delinvincibletimer(sd);
  8085. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8086. //Set last idle time... [Skotlex]
  8087. sd->idletime = last_tick;
  8088. unit_walktoxy(&sd->bl, x, y, 4);
  8089. }
  8090. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8091. /// 018a <type>.W
  8092. /// type:
  8093. /// 0 = quit
  8094. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8095. {
  8096. WFIFOHEAD(fd,packet_len(0x18b));
  8097. WFIFOW(fd,0) = 0x18b;
  8098. /* Rovert's prevent logout option fixed [Valaris] */
  8099. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8100. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8101. {
  8102. set_eof(fd);
  8103. WFIFOW(fd,2)=0;
  8104. } else {
  8105. WFIFOW(fd,2)=1;
  8106. }
  8107. WFIFOSET(fd,packet_len(0x18b));
  8108. }
  8109. /// Requesting unit's name.
  8110. /// 0094 <id>.L (CZ_REQNAME)
  8111. /// 0368 <id>.L (CZ_REQNAME2)
  8112. /// There are various variants of this packet, some of them have padding between fields.
  8113. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8114. {
  8115. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8116. struct block_list* bl;
  8117. //struct status_change *sc;
  8118. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8119. id = sd->bl.id;
  8120. bl = map_id2bl(id);
  8121. if( bl == NULL )
  8122. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8123. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8124. return; // Block namerequests past view range
  8125. // 'see people in GM hide' cheat detection
  8126. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8127. sc = status_get_sc(bl);
  8128. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8129. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8130. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8131. ) {
  8132. char gm_msg[256];
  8133. 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);
  8134. ShowWarning(gm_msg);
  8135. // information is sent to all online GMs
  8136. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8137. return;
  8138. }
  8139. */
  8140. clif_charnameack(fd, bl);
  8141. }
  8142. /// Validates and processes global messages
  8143. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8144. /// There are various variants of this packet.
  8145. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8146. {
  8147. const char* text = (char*)RFIFOP(fd,4);
  8148. int textlen = RFIFOW(fd,2) - 4;
  8149. char *name, *message, *fakename = NULL;
  8150. int namelen, messagelen;
  8151. bool is_fake;
  8152. // validate packet and retrieve name and message
  8153. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8154. return;
  8155. if( is_atcommand(fd, sd, message, 1) )
  8156. return;
  8157. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8158. return;
  8159. if( battle_config.min_chat_delay )
  8160. { //[Skotlex]
  8161. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8162. return;
  8163. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8164. }
  8165. /**
  8166. * Fake Name Design by FatalEror (bug report #9)
  8167. **/
  8168. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8169. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8170. strcpy(fakename, sd->fakename);
  8171. strcat(fakename, " : ");
  8172. strcat(fakename, message);
  8173. textlen = strlen(fakename) + 1;
  8174. }
  8175. // send message to others (using the send buffer for temp. storage)
  8176. WFIFOHEAD(fd, 8 + textlen);
  8177. WFIFOW(fd,0) = 0x8d;
  8178. WFIFOW(fd,2) = 8 + textlen;
  8179. WFIFOL(fd,4) = sd->bl.id;
  8180. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8181. //FIXME: chat has range of 9 only
  8182. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8183. // send back message to the speaker
  8184. if( is_fake ) {
  8185. WFIFOW(fd,0) = 0x8e;
  8186. WFIFOW(fd,2) = textlen + 4;
  8187. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8188. aFree(fakename);
  8189. } else {
  8190. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8191. WFIFOW(fd,0) = 0x8e;
  8192. }
  8193. WFIFOSET(fd, WFIFOW(fd,2));
  8194. #ifdef PCRE_SUPPORT
  8195. // trigger listening npcs
  8196. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8197. #endif
  8198. // Chat logging type 'O' / Global Chat
  8199. 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);
  8200. }
  8201. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8202. /// Request to warp to a map on given coordinates.
  8203. /// 0140 <map name>.16B <x>.W <y>.W
  8204. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8205. {
  8206. char command[MAP_NAME_LENGTH_EXT+25];
  8207. char* map_name;
  8208. map_name = (char*)RFIFOP(fd,2);
  8209. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8210. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8211. is_atcommand(fd, sd, command, 1);
  8212. }
  8213. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8214. /// 009c <id>.L <head dir>.W <dir>.B
  8215. /// head dir:
  8216. /// 0 = straight
  8217. /// 1 = turned CW
  8218. /// 2 = turned CCW
  8219. /// dir:
  8220. /// 0 = north
  8221. /// 1 = northwest
  8222. /// 2 = west
  8223. /// 3 = southwest
  8224. /// 4 = south
  8225. /// 5 = southeast
  8226. /// 6 = east
  8227. /// 7 = northeast
  8228. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8229. {
  8230. unsigned char buf[64];
  8231. WBUFW(buf,0) = 0x9c;
  8232. WBUFL(buf,2) = bl->id;
  8233. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8234. WBUFB(buf,8) = unit_getdir(bl);
  8235. clif_send(buf, packet_len(0x9c), bl, target);
  8236. if (disguised(bl)) {
  8237. WBUFL(buf,2) = -bl->id;
  8238. WBUFW(buf,6) = 0;
  8239. clif_send(buf, packet_len(0x9c), bl, SELF);
  8240. }
  8241. }
  8242. /// Request to change own body and head direction.
  8243. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8244. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8245. /// There are various variants of this packet, some of them have padding between fields.
  8246. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8247. {
  8248. unsigned char headdir, dir;
  8249. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8250. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8251. pc_setdir(sd, dir, headdir);
  8252. clif_changed_dir(&sd->bl, AREA_WOS);
  8253. }
  8254. /// Request to show an emotion (CZ_REQ_EMOTION).
  8255. /// 00bf <type>.B
  8256. /// type:
  8257. /// @see enum emotion_type
  8258. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8259. {
  8260. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8261. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8262. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8263. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8264. return;
  8265. }
  8266. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8267. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8268. sd->emotionlasttime = time(NULL);
  8269. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8270. return;
  8271. }
  8272. sd->emotionlasttime = time(NULL);
  8273. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  8274. {// re-roll dice
  8275. emoticon = rnd()%6+E_DICE1;
  8276. }
  8277. clif_emotion(&sd->bl, emoticon);
  8278. } else
  8279. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8280. }
  8281. /// /w /who (CZ_REQ_USER_COUNT).
  8282. /// Request to display amount of currently connected players.
  8283. /// 00c1
  8284. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8285. {
  8286. WFIFOHEAD(fd,packet_len(0xc2));
  8287. WFIFOW(fd,0) = 0xc2;
  8288. WFIFOL(fd,2) = map_getusers();
  8289. WFIFOSET(fd,packet_len(0xc2));
  8290. }
  8291. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8292. {
  8293. if (pc_isdead(sd)) {
  8294. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8295. return;
  8296. }
  8297. if (sd->sc.count &&
  8298. (sd->sc.data[SC_TRICKDEAD] ||
  8299. sd->sc.data[SC_AUTOCOUNTER] ||
  8300. sd->sc.data[SC_BLADESTOP] ||
  8301. sd->sc.data[SC__MANHOLE] ||
  8302. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8303. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8304. return;
  8305. pc_stop_walking(sd, 1);
  8306. pc_stop_attack(sd);
  8307. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8308. target_id = sd->bl.id;
  8309. switch(action_type)
  8310. {
  8311. case 0x00: // once attack
  8312. case 0x07: // continuous attack
  8313. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8314. return;
  8315. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8316. return;
  8317. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8318. return;
  8319. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8320. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8321. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8322. return;
  8323. }
  8324. }
  8325. pc_delinvincibletimer(sd);
  8326. sd->idletime = last_tick;
  8327. unit_attack(&sd->bl, target_id, action_type != 0);
  8328. break;
  8329. case 0x02: // sitdown
  8330. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8331. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8332. break;
  8333. }
  8334. if(pc_issit(sd)) {
  8335. //Bugged client? Just refresh them.
  8336. clif_sitting(&sd->bl);
  8337. return;
  8338. }
  8339. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8340. break;
  8341. if (sd->sc.count && (
  8342. sd->sc.data[SC_DANCING] ||
  8343. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8344. )) //No sitting during these states either.
  8345. break;
  8346. pc_setsit(sd);
  8347. skill_sit(sd,1);
  8348. clif_sitting(&sd->bl);
  8349. break;
  8350. case 0x03: // standup
  8351. if (!pc_issit(sd)) {
  8352. //Bugged client? Just refresh them.
  8353. clif_standing(&sd->bl);
  8354. return;
  8355. }
  8356. pc_setstand(sd);
  8357. skill_sit(sd,0);
  8358. clif_standing(&sd->bl);
  8359. break;
  8360. }
  8361. }
  8362. /// Request for an action.
  8363. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8364. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8365. /// action:
  8366. /// 0 = attack
  8367. /// 1 = pick up item
  8368. /// 2 = sit down
  8369. /// 3 = stand up
  8370. /// 7 = continous attack
  8371. /// 12 = (touch skill?)
  8372. /// There are various variants of this packet, some of them have padding between fields.
  8373. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8374. {
  8375. clif_parse_ActionRequest_sub(sd,
  8376. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8377. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8378. gettick()
  8379. );
  8380. }
  8381. /// Response to the death/system menu (CZ_RESTART).
  8382. /// 00b2 <type>.B
  8383. /// type:
  8384. /// 0 = restart (respawn)
  8385. /// 1 = char-select (disconnect)
  8386. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8387. {
  8388. switch(RFIFOB(fd,2)) {
  8389. case 0x00:
  8390. pc_respawn(sd,CLR_RESPAWN);
  8391. break;
  8392. case 0x01:
  8393. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8394. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8395. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8396. { //Send to char-server for character selection.
  8397. chrif_charselectreq(sd, session[fd]->client_addr);
  8398. } else {
  8399. WFIFOHEAD(fd,packet_len(0x18b));
  8400. WFIFOW(fd,0)=0x18b;
  8401. WFIFOW(fd,2)=1;
  8402. WFIFOSET(fd,packet_len(0x018b));
  8403. }
  8404. break;
  8405. }
  8406. }
  8407. /// Validates and processes whispered messages (CZ_WHISPER).
  8408. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8409. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8410. {
  8411. struct map_session_data* dstsd;
  8412. int i;
  8413. char *target, *message;
  8414. int namelen, messagelen;
  8415. // validate packet and retrieve name and message
  8416. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8417. return;
  8418. if (is_atcommand(fd, sd, message, 1) )
  8419. return;
  8420. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8421. return;
  8422. if (battle_config.min_chat_delay)
  8423. { //[Skotlex]
  8424. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8425. return;
  8426. }
  8427. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8428. }
  8429. // Chat logging type 'W' / Whisper
  8430. 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);
  8431. //-------------------------------------------------------//
  8432. // Lordalfa - Paperboy - To whisper NPC commands //
  8433. //-------------------------------------------------------//
  8434. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8435. {
  8436. char* str = target+4; //Skip the NPC: string part.
  8437. struct npc_data* npc;
  8438. if ((npc = npc_name2id(str)))
  8439. {
  8440. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8441. char *split;
  8442. char output[256];
  8443. str = message;
  8444. // skip codepage indicator, if detected
  8445. if( str[0] == '|' && strlen(str) >= 4 )
  8446. str += 3;
  8447. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8448. {// Splits the message using '#' as separators
  8449. split = strchr(str,'#');
  8450. if( split == NULL )
  8451. { // use the remaining string
  8452. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8453. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8454. split_data[i][0] = '\0';
  8455. break;
  8456. }
  8457. *split = '\0';
  8458. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8459. str = split+1;
  8460. }
  8461. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8462. {
  8463. sprintf(output, "@whispervar%d$", i);
  8464. set_var(sd,output,(char *) split_data[i]);
  8465. }
  8466. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8467. npc_event(sd,output,0); // Calls the NPC label
  8468. return;
  8469. }
  8470. }
  8471. // Main chat [LuzZza]
  8472. if(strcmpi(target, main_chat_nick) == 0)
  8473. {
  8474. if(!sd->state.mainchat)
  8475. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8476. else {
  8477. // send the main message using inter-server system
  8478. intif_main_message( sd, message );
  8479. }
  8480. return;
  8481. }
  8482. // searching destination character
  8483. dstsd = map_nick2sd(target);
  8484. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8485. {
  8486. // player is not on this map-server
  8487. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8488. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8489. // and if we ask for 'Test', we must not contact 'test' player
  8490. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8491. intif_wis_message(sd, target, message, messagelen);
  8492. return;
  8493. }
  8494. // if player ignores everyone
  8495. if (dstsd->state.ignoreAll)
  8496. {
  8497. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8498. clif_wis_end(fd, 1); // 1: target character is not loged in
  8499. else
  8500. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8501. return;
  8502. }
  8503. // if player ignores the source character
  8504. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8505. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8506. { // source char present in ignore list
  8507. clif_wis_end(fd, 2); // 2: ignored by target
  8508. return;
  8509. }
  8510. // if player is autotrading
  8511. if( dstsd->state.autotrade == 1 )
  8512. {
  8513. char output[256];
  8514. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8515. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8516. return;
  8517. }
  8518. // notify sender of success
  8519. clif_wis_end(fd, 0); // 0: success to send wisper
  8520. // Normal message
  8521. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8522. }
  8523. /// /b /nb (CZ_BROADCAST).
  8524. /// Request to broadcast a message on whole server.
  8525. /// 0099 <packet len>.W <text>.?B 00
  8526. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8527. {
  8528. char command[CHAT_SIZE_MAX+11];
  8529. char* msg = (char*)RFIFOP(fd,4);
  8530. unsigned int len = RFIFOW(fd,2)-4;
  8531. // as the length varies depending on the command used, just block unreasonably long strings
  8532. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  8533. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8534. is_atcommand(fd, sd, command, 1);
  8535. }
  8536. /// Request to pick up an item.
  8537. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8538. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8539. /// There are various variants of this packet, some of them have padding between fields.
  8540. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8541. {
  8542. struct flooritem_data *fitem;
  8543. int map_object_id;
  8544. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8545. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8546. do {
  8547. if (pc_isdead(sd)) {
  8548. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8549. break;
  8550. }
  8551. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8552. break;
  8553. if (pc_cant_act(sd))
  8554. break;
  8555. if(sd->sc.count && (
  8556. sd->sc.data[SC_HIDING] ||
  8557. sd->sc.data[SC_CLOAKING] ||
  8558. sd->sc.data[SC_TRICKDEAD] ||
  8559. sd->sc.data[SC_BLADESTOP] ||
  8560. sd->sc.data[SC_CLOAKINGEXCEED] ||
  8561. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8562. )
  8563. break;
  8564. if (!pc_takeitem(sd, fitem))
  8565. break;
  8566. return;
  8567. } while (0);
  8568. // Client REQUIRES a fail packet or you can no longer pick items.
  8569. clif_additem(sd,0,0,6);
  8570. }
  8571. /// Request to drop an item.
  8572. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8573. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8574. /// There are various variants of this packet, some of them have padding between fields.
  8575. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8576. {
  8577. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8578. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8579. for(;;) {
  8580. if (pc_isdead(sd))
  8581. break;
  8582. if (pc_cant_act(sd))
  8583. break;
  8584. if (sd->sc.count && (
  8585. sd->sc.data[SC_AUTOCOUNTER] ||
  8586. sd->sc.data[SC_BLADESTOP] ||
  8587. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8588. ))
  8589. break;
  8590. if (!pc_dropitem(sd, item_index, item_amount))
  8591. break;
  8592. return;
  8593. }
  8594. //Because the client does not like being ignored.
  8595. clif_dropitem(sd, item_index,0);
  8596. }
  8597. /// Request to use an item.
  8598. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8599. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8600. /// There are various variants of this packet, some of them have padding between fields.
  8601. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8602. {
  8603. int n;
  8604. if (pc_isdead(sd)) {
  8605. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8606. return;
  8607. }
  8608. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  8609. return;
  8610. //This flag enables you to use items while in an NPC. [Skotlex]
  8611. if (sd->npc_id) {
  8612. if (sd->npc_id != sd->npc_item_flag)
  8613. return;
  8614. } else
  8615. if (pc_istrading(sd))
  8616. return;
  8617. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8618. sd->idletime = last_tick;
  8619. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8620. if(n <0 || n >= MAX_INVENTORY)
  8621. return;
  8622. if (!pc_useitem(sd,n))
  8623. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8624. }
  8625. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8626. /// 00a9 <index>.W <position>.W
  8627. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8628. {
  8629. int index;
  8630. if(pc_isdead(sd)) {
  8631. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8632. return;
  8633. }
  8634. index = RFIFOW(fd,2)-2;
  8635. if (index < 0 || index >= MAX_INVENTORY)
  8636. return; //Out of bounds check.
  8637. if(sd->npc_id) {
  8638. if (sd->npc_id != sd->npc_item_flag)
  8639. return;
  8640. } else if (sd->state.storage_flag || sd->sc.opt1)
  8641. ; //You can equip/unequip stuff while storage is open/under status changes
  8642. else if (pc_cant_act(sd))
  8643. return;
  8644. if(!sd->status.inventory[index].identify) {
  8645. clif_equipitemack(sd,index,0,0); // fail
  8646. return;
  8647. }
  8648. if(!sd->inventory_data[index])
  8649. return;
  8650. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8651. pet_equipitem(sd,index);
  8652. return;
  8653. }
  8654. //Client doesn't send the position for ammo.
  8655. if(sd->inventory_data[index]->type == IT_AMMO)
  8656. pc_equipitem(sd,index,EQP_AMMO);
  8657. else
  8658. pc_equipitem(sd,index,RFIFOW(fd,4));
  8659. }
  8660. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8661. /// 00ab <index>.W
  8662. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8663. {
  8664. int index;
  8665. if(pc_isdead(sd)) {
  8666. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8667. return;
  8668. }
  8669. if (sd->state.storage_flag || sd->sc.opt1)
  8670. ; //You can equip/unequip stuff while storage is open/under status changes
  8671. else if (pc_cant_act(sd))
  8672. return;
  8673. index = RFIFOW(fd,2)-2;
  8674. pc_unequipitem(sd,index,1);
  8675. }
  8676. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8677. /// 0090 <id>.L <type>.B
  8678. /// type:
  8679. /// 1 = click
  8680. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8681. {
  8682. struct block_list *bl;
  8683. if(pc_isdead(sd)) {
  8684. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8685. return;
  8686. }
  8687. if (pc_cant_act(sd))
  8688. return;
  8689. bl = map_id2bl(RFIFOL(fd,2));
  8690. if (!bl) return;
  8691. switch (bl->type) {
  8692. case BL_MOB:
  8693. case BL_PC:
  8694. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8695. break;
  8696. case BL_NPC:
  8697. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8698. npc_click(sd,(TBL_NPC*)bl);
  8699. break;
  8700. }
  8701. }
  8702. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8703. /// 00c5 <id>.L <type>.B
  8704. /// type:
  8705. /// 0 = buy
  8706. /// 1 = sell
  8707. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8708. {
  8709. if (sd->state.trading)
  8710. return;
  8711. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8712. }
  8713. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8714. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8715. ///
  8716. /// R 00ca <result>.b
  8717. /// result = 00 -> "The deal has successfully completed."
  8718. /// result = 01 -> "You do not have enough zeny."
  8719. /// result = 02 -> "You are over your Weight Limit."
  8720. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8721. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8722. {
  8723. int n = (RFIFOW(fd,2)-4) /4;
  8724. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8725. int result;
  8726. if( sd->state.trading || !sd->npc_shopid )
  8727. result = 1;
  8728. else
  8729. result = npc_buylist(sd,n,item_list);
  8730. sd->npc_shopid = 0; //Clear shop data.
  8731. WFIFOHEAD(fd,packet_len(0xca));
  8732. WFIFOW(fd,0) = 0xca;
  8733. WFIFOB(fd,2) = result;
  8734. WFIFOSET(fd,packet_len(0xca));
  8735. }
  8736. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8737. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8738. ///
  8739. /// S 00cb <result>.B
  8740. /// result = 00 -> "The deal has successfully completed."
  8741. /// result = 01 -> "The deal has failed."
  8742. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8743. {
  8744. int fail=0,n;
  8745. unsigned short *item_list;
  8746. n = (RFIFOW(fd,2)-4) /4;
  8747. item_list = (unsigned short*)RFIFOP(fd,4);
  8748. if (sd->state.trading || !sd->npc_shopid)
  8749. fail = 1;
  8750. else
  8751. fail = npc_selllist(sd,n,item_list);
  8752. sd->npc_shopid = 0; //Clear shop data.
  8753. WFIFOHEAD(fd,packet_len(0xcb));
  8754. WFIFOW(fd,0)=0xcb;
  8755. WFIFOB(fd,2)=fail;
  8756. WFIFOSET(fd,packet_len(0xcb));
  8757. }
  8758. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8759. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8760. /// type:
  8761. /// 0 = private
  8762. /// 1 = public
  8763. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8764. {
  8765. int len = RFIFOW(fd,2)-15;
  8766. int limit = RFIFOW(fd,4);
  8767. bool pub = (RFIFOB(fd,6) != 0);
  8768. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8769. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8770. char s_password[CHATROOM_PASS_SIZE];
  8771. char s_title[CHATROOM_TITLE_SIZE];
  8772. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8773. return;
  8774. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8775. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8776. return;
  8777. }
  8778. if( len <= 0 )
  8779. return; // invalid input
  8780. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8781. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8782. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8783. }
  8784. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8785. /// 00d9 <chat ID>.L <passwd>.8B
  8786. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8787. {
  8788. int chatid = RFIFOL(fd,2);
  8789. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8790. chat_joinchat(sd,chatid,password);
  8791. }
  8792. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8793. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8794. /// type:
  8795. /// 0 = private
  8796. /// 1 = public
  8797. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8798. {
  8799. int len = RFIFOW(fd,2)-15;
  8800. int limit = RFIFOW(fd,4);
  8801. bool pub = (RFIFOB(fd,6) != 0);
  8802. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8803. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8804. char s_password[CHATROOM_PASS_SIZE];
  8805. char s_title[CHATROOM_TITLE_SIZE];
  8806. if( len <= 0 )
  8807. return; // invalid input
  8808. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8809. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8810. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8811. }
  8812. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8813. /// 00e0 <role>.L <nick>.24B
  8814. /// role:
  8815. /// 0 = owner
  8816. /// 1 = normal
  8817. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8818. {
  8819. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8820. }
  8821. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8822. /// 00e2 <name>.24B
  8823. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8824. {
  8825. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8826. }
  8827. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8828. /// 00e3
  8829. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8830. {
  8831. chat_leavechat(sd,0);
  8832. }
  8833. //Handles notifying asker and rejecter of what has just ocurred.
  8834. //Type is used to determine the correct msg_txt to use:
  8835. //0:
  8836. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8837. {
  8838. const char* msg;
  8839. char output[256];
  8840. // Your request has been rejected by autoreject option.
  8841. msg = msg_txt(392);
  8842. clif_disp_onlyself(src, msg, strlen(msg));
  8843. //Notice that a request was rejected.
  8844. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8845. clif_disp_onlyself(target, output, strlen(output));
  8846. }
  8847. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8848. /// 00e4 <account id>.L
  8849. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8850. {
  8851. struct map_session_data *t_sd;
  8852. t_sd = map_id2sd(RFIFOL(fd,2));
  8853. if(!sd->chatID && pc_cant_act(sd))
  8854. return; //You can trade while in a chatroom.
  8855. // @noask [LuzZza]
  8856. if(t_sd && t_sd->state.noask) {
  8857. clif_noask_sub(sd, t_sd, 0);
  8858. return;
  8859. }
  8860. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8861. {
  8862. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8863. return;
  8864. }
  8865. trade_traderequest(sd,t_sd);
  8866. }
  8867. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8868. /// 00e6 <result>.B
  8869. /// result:
  8870. /// 3 = accepted
  8871. /// 4 = rejected
  8872. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8873. {
  8874. trade_tradeack(sd,RFIFOB(fd,2));
  8875. }
  8876. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  8877. /// 00e8 <index>.W <amount>.L
  8878. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8879. {
  8880. short index = RFIFOW(fd,2);
  8881. int amount = RFIFOL(fd,4);
  8882. if( index == 0 )
  8883. trade_tradeaddzeny(sd, amount);
  8884. else
  8885. trade_tradeadditem(sd, index, (short)amount);
  8886. }
  8887. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  8888. /// 00eb
  8889. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8890. {
  8891. trade_tradeok(sd);
  8892. }
  8893. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  8894. /// 00ed
  8895. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8896. {
  8897. trade_tradecancel(sd);
  8898. }
  8899. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  8900. /// 00ef
  8901. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8902. {
  8903. trade_tradecommit(sd);
  8904. }
  8905. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  8906. /// 0118
  8907. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8908. {
  8909. pc_stop_attack(sd);
  8910. }
  8911. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  8912. /// 0126 <index>.W <amount>.L
  8913. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8914. {
  8915. if (pc_istrading(sd))
  8916. return;
  8917. if (!pc_iscarton(sd))
  8918. return;
  8919. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8920. }
  8921. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  8922. /// 0127 <index>.W <amount>.L
  8923. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8924. {
  8925. if (!pc_iscarton(sd))
  8926. return;
  8927. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8928. }
  8929. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  8930. /// 012a
  8931. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8932. {
  8933. /**
  8934. * Attempts to remove these options when this function is called (will remove all available)
  8935. **/
  8936. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  8937. }
  8938. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  8939. /// 01af <num>.W
  8940. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8941. {
  8942. int type;
  8943. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8944. return;
  8945. type = (int)RFIFOW(fd,2);
  8946. if( (type == 5 && sd->status.base_level > 90) ||
  8947. (type == 4 && sd->status.base_level > 80) ||
  8948. (type == 3 && sd->status.base_level > 65) ||
  8949. (type == 2 && sd->status.base_level > 40) ||
  8950. (type == 1))
  8951. pc_setcart(sd,type);
  8952. }
  8953. /// Request to increase status (CZ_STATUS_CHANGE).
  8954. /// 00bb <status id>.W <amount>.B
  8955. /// status id:
  8956. /// SP_STR ~ SP_LUK
  8957. /// amount:
  8958. /// client sends always 1 for this, even when using /str+ and
  8959. /// the like
  8960. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8961. {
  8962. pc_statusup(sd,RFIFOW(fd,2));
  8963. }
  8964. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  8965. /// 0112 <skill id>.W
  8966. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8967. {
  8968. pc_skillup(sd,RFIFOW(fd,2));
  8969. }
  8970. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8971. {
  8972. int lv;
  8973. if( !hd )
  8974. return;
  8975. if( skillnotok_hom(skillnum, hd) )
  8976. return;
  8977. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8978. target_id = hd->bl.id;
  8979. if( hd->ud.skilltimer != INVALID_TIMER )
  8980. {
  8981. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  8982. }
  8983. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8984. return;
  8985. lv = merc_hom_checkskill(hd, skillnum);
  8986. if( skilllv > lv )
  8987. skilllv = lv;
  8988. if( skilllv )
  8989. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8990. }
  8991. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8992. {
  8993. int lv;
  8994. if( !md )
  8995. return;
  8996. if( skillnotok_mercenary(skillnum, md) )
  8997. return;
  8998. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8999. target_id = md->bl.id;
  9000. if( md->ud.skilltimer != INVALID_TIMER )
  9001. {
  9002. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  9003. }
  9004. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9005. return;
  9006. lv = mercenary_checkskill(md, skillnum);
  9007. if( skilllv > lv )
  9008. skilllv = lv;
  9009. if( skilllv )
  9010. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  9011. }
  9012. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  9013. {
  9014. int lv;
  9015. if( !md )
  9016. return;
  9017. if( skillnotok_mercenary(skillnum, md) )
  9018. return;
  9019. if( md->ud.skilltimer != INVALID_TIMER )
  9020. return;
  9021. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9022. {
  9023. clif_skill_fail(md->master, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9024. return;
  9025. }
  9026. if( md->sc.data[SC_BASILICA] )
  9027. return;
  9028. lv = mercenary_checkskill(md, skillnum);
  9029. if( skilllv > lv )
  9030. skilllv = lv;
  9031. if( skilllv )
  9032. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  9033. }
  9034. /// Request to use a targeted skill.
  9035. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9036. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9037. /// There are various variants of this packet, some of them have padding between fields.
  9038. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9039. {
  9040. short skillnum, skilllv;
  9041. int tmp, target_id;
  9042. unsigned int tick = gettick();
  9043. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9044. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9045. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9046. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9047. tmp = skill_get_inf(skillnum);
  9048. if (tmp&INF_GROUND_SKILL || !tmp)
  9049. return; //Using a ground/passive skill on a target? WRONG.
  9050. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  9051. {
  9052. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  9053. return;
  9054. }
  9055. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9056. {
  9057. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  9058. return;
  9059. }
  9060. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9061. sd->idletime = last_tick;
  9062. if( pc_cant_act(sd) && !(skillnum == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9063. return;
  9064. if( pc_issit(sd) )
  9065. return;
  9066. if( skillnotok(skillnum, sd) )
  9067. return;
  9068. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9069. target_id = sd->bl.id; // never trust the client
  9070. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9071. target_id = sd->bl.id;
  9072. if( sd->ud.skilltimer != INVALID_TIMER )
  9073. {
  9074. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST )
  9075. return;
  9076. }
  9077. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  9078. {
  9079. if( sd->skillitem != skillnum )
  9080. {
  9081. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9082. return;
  9083. }
  9084. }
  9085. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9086. return;
  9087. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9088. return; // On basilica only caster can use Basilica again to stop it.
  9089. if( sd->menuskill_id ) {
  9090. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9091. clif_menuskill_clear(sd); //Cancel pet capture.
  9092. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9093. return; //Can't use skills while a menu is open.
  9094. }
  9095. if( sd->skillitem == skillnum ) {
  9096. if( skilllv != sd->skillitemlv )
  9097. skilllv = sd->skillitemlv;
  9098. if( !(tmp&INF_SELF_SKILL) )
  9099. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9100. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9101. return;
  9102. }
  9103. sd->skillitem = sd->skillitemlv = 0;
  9104. if( skillnum >= GD_SKILLBASE ) {
  9105. if( sd->state.gmaster_flag )
  9106. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  9107. else
  9108. skilllv = 0;
  9109. } else {
  9110. tmp = pc_checkskill(sd, skillnum);
  9111. if( skilllv > tmp )
  9112. skilllv = tmp;
  9113. }
  9114. pc_delinvincibletimer(sd);
  9115. if( skilllv )
  9116. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9117. }
  9118. /*==========================================
  9119. * Client tells server he'd like to use AoE skill id 'skillnum' of level 'skilllv' on 'x','y' location
  9120. *------------------------------------------*/
  9121. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  9122. {
  9123. unsigned int tick = gettick();
  9124. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  9125. return; //Using a target skill on the ground? WRONG.
  9126. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9127. {
  9128. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  9129. return;
  9130. }
  9131. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9132. sd->idletime = last_tick;
  9133. if( skillnotok(skillnum, sd) )
  9134. return;
  9135. if( skillmoreinfo != -1 )
  9136. {
  9137. if( pc_issit(sd) )
  9138. {
  9139. clif_skill_fail(sd, skillnum, USESKILL_FAIL_LEVEL, 0);
  9140. return;
  9141. }
  9142. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9143. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9144. }
  9145. if( sd->ud.skilltimer != INVALID_TIMER )
  9146. return;
  9147. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9148. if( sd->skillitem != skillnum ) {
  9149. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9150. return;
  9151. }
  9152. }
  9153. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9154. return;
  9155. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9156. return; // On basilica only caster can use Basilica again to stop it.
  9157. if( sd->menuskill_id ) {
  9158. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9159. clif_menuskill_clear(sd); //Cancel pet capture.
  9160. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9161. return; //Can't use skills while a menu is open.
  9162. }
  9163. pc_delinvincibletimer(sd);
  9164. if( sd->skillitem == skillnum ) {
  9165. if( skilllv != sd->skillitemlv )
  9166. skilllv = sd->skillitemlv;
  9167. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  9168. } else {
  9169. int lv;
  9170. sd->skillitem = sd->skillitemlv = 0;
  9171. if( (lv = pc_checkskill(sd, skillnum)) > 0 ) {
  9172. if( skilllv > lv )
  9173. skilllv = lv;
  9174. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  9175. }
  9176. }
  9177. }
  9178. /// Request to use a ground skill.
  9179. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9180. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9181. /// There are various variants of this packet, some of them have padding between fields.
  9182. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9183. {
  9184. if (pc_cant_act(sd))
  9185. return;
  9186. if (pc_issit(sd))
  9187. return;
  9188. clif_parse_UseSkillToPosSub(fd, sd,
  9189. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9190. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9191. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9192. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9193. -1 //Skill more info.
  9194. );
  9195. }
  9196. /// Request to use a ground skill with text.
  9197. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9198. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9199. /// There are various variants of this packet, some of them have padding between fields.
  9200. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9201. {
  9202. if (pc_cant_act(sd))
  9203. return;
  9204. if (pc_issit(sd))
  9205. return;
  9206. clif_parse_UseSkillToPosSub(fd, sd,
  9207. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9208. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9209. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9210. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9211. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9212. );
  9213. }
  9214. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9215. /// 011b <skill id>.W <map name>.16B
  9216. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9217. {
  9218. short skill_num = RFIFOW(fd,2);
  9219. char map_name[MAP_NAME_LENGTH];
  9220. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9221. if(skill_num != sd->menuskill_id)
  9222. return;
  9223. if( pc_cant_act(sd) ) {
  9224. clif_menuskill_clear(sd);
  9225. return;
  9226. }
  9227. pc_delinvincibletimer(sd);
  9228. skill_castend_map(sd,skill_num,map_name);
  9229. }
  9230. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9231. /// 011d
  9232. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9233. {
  9234. if (!pc_isdead(sd))
  9235. pc_memo(sd,-1);
  9236. }
  9237. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9238. /// 018e <name id>.W { <material id>.W }*3
  9239. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9240. {
  9241. switch( sd->menuskill_id ) {
  9242. case -1:
  9243. case AM_PHARMACY:
  9244. case RK_RUNEMASTERY:
  9245. case GC_CREATENEWPOISON:
  9246. break;
  9247. default:
  9248. return;
  9249. }
  9250. if (pc_istrading(sd)) {
  9251. //Make it fail to avoid shop exploits where you sell something different than you see.
  9252. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9253. clif_menuskill_clear(sd);
  9254. return;
  9255. }
  9256. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9257. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9258. clif_menuskill_clear(sd);
  9259. }
  9260. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9261. /// 025b <mk type>.W <name id>.W
  9262. /// mk type:
  9263. /// 1 = cooking
  9264. /// 2 = arrow
  9265. /// 3 = elemental
  9266. /// 4 = GN_MIX_COOKING
  9267. /// 5 = GN_MAKEBOMB
  9268. /// 6 = GN_S_PHARMACY
  9269. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9270. int type = RFIFOW(fd,2);
  9271. int nameid = RFIFOW(fd,4);
  9272. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9273. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9274. return;
  9275. if (pc_istrading(sd)) {
  9276. //Make it fail to avoid shop exploits where you sell something different than you see.
  9277. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9278. clif_menuskill_clear(sd);
  9279. return;
  9280. }
  9281. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9282. skill_produce_mix(sd,sd->menuskill_id,nameid,0,0,0,amount);
  9283. clif_menuskill_clear(sd);
  9284. }
  9285. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9286. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9287. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9288. {
  9289. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9290. return;
  9291. if (pc_istrading(sd)) {
  9292. //Make it fail to avoid shop exploits where you sell something different than you see.
  9293. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9294. clif_menuskill_clear(sd);
  9295. return;
  9296. }
  9297. skill_repairweapon(sd,RFIFOW(fd,2));
  9298. clif_menuskill_clear(sd);
  9299. }
  9300. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9301. /// 0222 <index>.L
  9302. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9303. {
  9304. int idx;
  9305. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9306. return;
  9307. if (pc_istrading(sd)) {
  9308. //Make it fail to avoid shop exploits where you sell something different than you see.
  9309. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9310. clif_menuskill_clear(sd);
  9311. return;
  9312. }
  9313. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9314. skill_weaponrefine(sd, idx-2);
  9315. clif_menuskill_clear(sd);
  9316. }
  9317. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9318. /// 00b8 <npc id>.L <choice>.B
  9319. /// choice:
  9320. /// 1~254 = menu item
  9321. /// 255 = cancel
  9322. /// NOTE: If there were more than 254 items in the list, choice
  9323. /// overflows to choice%256.
  9324. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9325. {
  9326. int npc_id = RFIFOL(fd,2);
  9327. uint8 select = RFIFOB(fd,6);
  9328. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  9329. {
  9330. TBL_NPC* nd = map_id2nd(npc_id);
  9331. 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);
  9332. clif_GM_kick(NULL,sd);
  9333. return;
  9334. }
  9335. sd->npc_menu = select;
  9336. npc_scriptcont(sd,npc_id);
  9337. }
  9338. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9339. /// 00b9 <npc id>.L
  9340. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9341. {
  9342. npc_scriptcont(sd,RFIFOL(fd,2));
  9343. }
  9344. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9345. /// 0143 <npc id>.L <value>.L
  9346. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9347. {
  9348. int npcid = RFIFOL(fd,2);
  9349. int amount = (int)RFIFOL(fd,6);
  9350. sd->npc_amount = amount;
  9351. npc_scriptcont(sd, npcid);
  9352. }
  9353. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9354. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9355. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9356. {
  9357. int message_len = RFIFOW(fd,2)-8;
  9358. int npcid = RFIFOL(fd,4);
  9359. const char* message = (char*)RFIFOP(fd,8);
  9360. if( message_len <= 0 )
  9361. return; // invalid input
  9362. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9363. npc_scriptcont(sd, npcid);
  9364. }
  9365. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9366. /// 0146 <npc id>.L
  9367. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9368. {
  9369. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9370. return;
  9371. npc_scriptcont(sd,RFIFOL(fd,2));
  9372. }
  9373. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9374. /// 0178 <index>.W
  9375. /// index:
  9376. /// -1 = cancel
  9377. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9378. {
  9379. short idx = RFIFOW(fd,2);
  9380. if (sd->menuskill_id != MC_IDENTIFY)
  9381. return;
  9382. if( idx == -1 ) {// cancel pressed
  9383. clif_menuskill_clear(sd);
  9384. return;
  9385. }
  9386. skill_identify(sd,idx-2);
  9387. clif_menuskill_clear(sd);
  9388. }
  9389. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9390. /// 01ae <name id>.W
  9391. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9392. {
  9393. if (pc_istrading(sd)) {
  9394. //Make it fail to avoid shop exploits where you sell something different than you see.
  9395. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9396. clif_menuskill_clear(sd);
  9397. return;
  9398. }
  9399. switch( sd->menuskill_id ) {
  9400. case AC_MAKINGARROW:
  9401. skill_arrow_create(sd,RFIFOW(fd,2));
  9402. break;
  9403. case SA_CREATECON:
  9404. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9405. break;
  9406. case WL_READING_SB:
  9407. skill_spellbook(sd,RFIFOW(fd,2));
  9408. break;
  9409. case GC_POISONINGWEAPON:
  9410. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9411. break;
  9412. case NC_MAGICDECOY:
  9413. skill_magicdecoy(sd,RFIFOW(fd,2));
  9414. break;
  9415. }
  9416. clif_menuskill_clear(sd);
  9417. }
  9418. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9419. /// 01ce <skill id>.L
  9420. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9421. {
  9422. if (sd->menuskill_id != SA_AUTOSPELL)
  9423. return;
  9424. skill_autospell(sd,RFIFOL(fd,2));
  9425. clif_menuskill_clear(sd);
  9426. }
  9427. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9428. /// 017a <card index>.W
  9429. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9430. {
  9431. if (sd->state.trading != 0)
  9432. return;
  9433. clif_use_card(sd,RFIFOW(fd,2)-2);
  9434. }
  9435. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9436. /// 017c <card index>.W <equip index>.W
  9437. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9438. {
  9439. if (sd->state.trading != 0)
  9440. return;
  9441. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9442. }
  9443. /// Request of character's name by char ID.
  9444. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9445. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9446. /// There are various variants of this packet, some of them have padding between fields.
  9447. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9448. {
  9449. int charid;
  9450. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9451. map_reqnickdb(sd, charid);
  9452. }
  9453. /// /resetskill /resetstate (CZ_RESET).
  9454. /// Request to reset stats or skills.
  9455. /// 0197 <type>.W
  9456. /// type:
  9457. /// 0 = state
  9458. /// 1 = skill
  9459. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9460. char cmd[15];
  9461. if( RFIFOW(fd,2) )
  9462. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9463. else
  9464. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9465. is_atcommand(fd, sd, cmd, 1);
  9466. }
  9467. /// /lb /nlb (CZ_LOCALBROADCAST).
  9468. /// Request to broadcast a message on current map.
  9469. /// 019c <packet len>.W <text>.?B
  9470. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9471. {
  9472. char command[CHAT_SIZE_MAX+16];
  9473. char* msg = (char*)RFIFOP(fd,4);
  9474. unsigned int len = RFIFOW(fd,2)-4;
  9475. // as the length varies depending on the command used, just block unreasonably long strings
  9476. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  9477. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9478. is_atcommand(fd, sd, command, 1);
  9479. }
  9480. /// Request to move an item from inventory to storage.
  9481. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9482. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9483. /// There are various variants of this packet, some of them have padding between fields.
  9484. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9485. {
  9486. int item_index, item_amount;
  9487. if (pc_istrading(sd))
  9488. return;
  9489. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9490. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9491. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9492. return;
  9493. if (sd->state.storage_flag == 1)
  9494. storage_storageadd(sd, item_index, item_amount);
  9495. else
  9496. if (sd->state.storage_flag == 2)
  9497. storage_guild_storageadd(sd, item_index, item_amount);
  9498. }
  9499. /// Request to move an item from storage to inventory.
  9500. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9501. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9502. /// There are various variants of this packet, some of them have padding between fields.
  9503. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9504. {
  9505. int item_index, item_amount;
  9506. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9507. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9508. if (sd->state.storage_flag == 1)
  9509. storage_storageget(sd, item_index, item_amount);
  9510. else
  9511. if(sd->state.storage_flag == 2)
  9512. storage_guild_storageget(sd, item_index, item_amount);
  9513. }
  9514. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9515. /// 0129 <index>.W <amount>.L
  9516. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9517. {
  9518. if( sd->state.vending )
  9519. return;
  9520. if (!pc_iscarton(sd))
  9521. return;
  9522. if (sd->state.storage_flag == 1)
  9523. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9524. else
  9525. if (sd->state.storage_flag == 2)
  9526. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9527. }
  9528. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9529. /// 0128 <index>.W <amount>.L
  9530. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9531. {
  9532. if( sd->state.vending )
  9533. return;
  9534. if (!pc_iscarton(sd))
  9535. return;
  9536. if (sd->state.storage_flag == 1)
  9537. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9538. else
  9539. if (sd->state.storage_flag == 2)
  9540. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9541. }
  9542. /// Request to close storage (CZ_CLOSE_STORE).
  9543. /// 00f7
  9544. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9545. {
  9546. if( sd->state.storage_flag == 1 )
  9547. storage_storageclose(sd);
  9548. else
  9549. if( sd->state.storage_flag == 2 )
  9550. storage_guild_storageclose(sd);
  9551. }
  9552. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9553. /// 023a <info>.W
  9554. /// info:
  9555. /// 0 = password has not been set yet
  9556. /// 1 = storage is password-protected
  9557. /// 8 = too many wrong passwords
  9558. /// ? = ignored
  9559. /// NOTE: This packet is only available on certain non-kRO clients.
  9560. void clif_storagepassword(struct map_session_data* sd, short info)
  9561. {
  9562. int fd = sd->fd;
  9563. WFIFOHEAD(fd,packet_len(0x23a));
  9564. WFIFOW(fd,0) = 0x23a;
  9565. WFIFOW(fd,2) = info;
  9566. WFIFOSET(fd,packet_len(0x23a));
  9567. }
  9568. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9569. /// 023b <type>.W <password>.16B <new password>.16B
  9570. /// type:
  9571. /// 2 = change password
  9572. /// 3 = check password
  9573. /// NOTE: This packet is only available on certain non-kRO clients.
  9574. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9575. {
  9576. //TODO
  9577. }
  9578. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9579. /// 023c <result>.W <error count>.W
  9580. /// result:
  9581. /// 4 = password change success
  9582. /// 5 = password change failure
  9583. /// 6 = password check success
  9584. /// 7 = password check failure
  9585. /// 8 = too many wrong passwords
  9586. /// ? = ignored
  9587. /// NOTE: This packet is only available on certain non-kRO clients.
  9588. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9589. {
  9590. int fd = sd->fd;
  9591. WFIFOHEAD(fd,packet_len(0x23c));
  9592. WFIFOW(fd,0) = 0x23c;
  9593. WFIFOW(fd,2) = result;
  9594. WFIFOW(fd,4) = error_count;
  9595. WFIFOSET(fd,packet_len(0x23c));
  9596. }
  9597. /// Party creation request
  9598. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9599. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9600. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9601. {
  9602. char* name = (char*)RFIFOP(fd,2);
  9603. name[NAME_LENGTH-1] = '\0';
  9604. if( map[sd->bl.m].flag.partylock )
  9605. {// Party locked.
  9606. clif_displaymessage(fd, msg_txt(227));
  9607. return;
  9608. }
  9609. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9610. {
  9611. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9612. return;
  9613. }
  9614. party_create(sd,name,0,0);
  9615. }
  9616. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9617. {
  9618. char* name = (char*)RFIFOP(fd,2);
  9619. int item1 = RFIFOB(fd,26);
  9620. int item2 = RFIFOB(fd,27);
  9621. name[NAME_LENGTH-1] = '\0';
  9622. if( map[sd->bl.m].flag.partylock )
  9623. {// Party locked.
  9624. clif_displaymessage(fd, msg_txt(227));
  9625. return;
  9626. }
  9627. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9628. {
  9629. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9630. return;
  9631. }
  9632. party_create(sd,name,item1,item2);
  9633. }
  9634. /// Party invitation request
  9635. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9636. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9637. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9638. {
  9639. struct map_session_data *t_sd;
  9640. if(map[sd->bl.m].flag.partylock)
  9641. {// Party locked.
  9642. clif_displaymessage(fd, msg_txt(227));
  9643. return;
  9644. }
  9645. t_sd = map_id2sd(RFIFOL(fd,2));
  9646. if(t_sd && t_sd->state.noask)
  9647. {// @noask [LuzZza]
  9648. clif_noask_sub(sd, t_sd, 1);
  9649. return;
  9650. }
  9651. party_invite(sd, t_sd);
  9652. }
  9653. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9654. {
  9655. struct map_session_data *t_sd;
  9656. char *name = (char*)RFIFOP(fd,2);
  9657. name[NAME_LENGTH-1] = '\0';
  9658. if(map[sd->bl.m].flag.partylock)
  9659. {// Party locked.
  9660. clif_displaymessage(fd, msg_txt(227));
  9661. return;
  9662. }
  9663. t_sd = map_nick2sd(name);
  9664. if(t_sd && t_sd->state.noask)
  9665. {// @noask [LuzZza]
  9666. clif_noask_sub(sd, t_sd, 1);
  9667. return;
  9668. }
  9669. party_invite(sd, t_sd);
  9670. }
  9671. /// Party invitation reply
  9672. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9673. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9674. /// flag:
  9675. /// 0 = reject
  9676. /// 1 = accept
  9677. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9678. {
  9679. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9680. }
  9681. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9682. {
  9683. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9684. }
  9685. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9686. /// 0100
  9687. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9688. {
  9689. if(map[sd->bl.m].flag.partylock)
  9690. { //Guild locked.
  9691. clif_displaymessage(fd, msg_txt(227));
  9692. return;
  9693. }
  9694. party_leave(sd);
  9695. }
  9696. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9697. /// 0103 <account id>.L <char name>.24B
  9698. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9699. {
  9700. if(map[sd->bl.m].flag.partylock)
  9701. { //Guild locked.
  9702. clif_displaymessage(fd, msg_txt(227));
  9703. return;
  9704. }
  9705. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9706. }
  9707. /// Request to change party options.
  9708. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9709. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9710. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9711. {
  9712. struct party_data *p;
  9713. int i;
  9714. if( !sd->status.party_id )
  9715. return;
  9716. p = party_search(sd->status.party_id);
  9717. if( p == NULL )
  9718. return;
  9719. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9720. if( i == MAX_PARTY )
  9721. return; //Shouldn't happen
  9722. if( !p->party.member[i].leader )
  9723. return;
  9724. #if PACKETVER < 20090603
  9725. //Client can't change the item-field
  9726. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9727. #else
  9728. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9729. #endif
  9730. }
  9731. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9732. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9733. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9734. {
  9735. const char* text = (char*)RFIFOP(fd,4);
  9736. int textlen = RFIFOW(fd,2) - 4;
  9737. char *name, *message;
  9738. int namelen, messagelen;
  9739. // validate packet and retrieve name and message
  9740. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9741. return;
  9742. if( is_atcommand(fd, sd, message, 1) )
  9743. return;
  9744. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9745. return;
  9746. if( battle_config.min_chat_delay )
  9747. { //[Skotlex]
  9748. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9749. return;
  9750. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9751. }
  9752. party_send_message(sd, text, textlen);
  9753. }
  9754. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9755. /// 07da <account id>.L
  9756. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9757. {
  9758. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9759. }
  9760. /// Party Booking in KRO [Spiria]
  9761. ///
  9762. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9763. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9764. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9765. {
  9766. short level = RFIFOW(fd,2);
  9767. short mapid = RFIFOW(fd,4);
  9768. short job[PARTY_BOOKING_JOBS];
  9769. int i;
  9770. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9771. job[i] = RFIFOB(fd,6+i*2);
  9772. party_booking_register(sd, level, mapid, job);
  9773. }
  9774. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9775. /// 0803 <result>.W
  9776. /// result:
  9777. /// 0 = success
  9778. /// 1 = failure
  9779. /// 2 = already registered
  9780. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9781. {
  9782. int fd = sd->fd;
  9783. WFIFOHEAD(fd,packet_len(0x803));
  9784. WFIFOW(fd,0) = 0x803;
  9785. WFIFOW(fd,2) = flag;
  9786. WFIFOSET(fd,packet_len(0x803));
  9787. }
  9788. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9789. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9790. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9791. {
  9792. short level = RFIFOW(fd,2);
  9793. short mapid = RFIFOW(fd,4);
  9794. short job = RFIFOW(fd,6);
  9795. unsigned long lastindex = RFIFOL(fd,8);
  9796. short resultcount = RFIFOW(fd,12);
  9797. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9798. }
  9799. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9800. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9801. /// more results:
  9802. /// 0 = no
  9803. /// 1 = yes
  9804. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9805. {
  9806. int i, j;
  9807. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9808. struct party_booking_ad_info *pb_ad;
  9809. WFIFOHEAD(fd,size*count + 5);
  9810. WFIFOW(fd,0) = 0x805;
  9811. WFIFOW(fd,2) = size*count + 5;
  9812. WFIFOB(fd,4) = more_result;
  9813. for(i=0; i<count; i++)
  9814. {
  9815. pb_ad = results[i];
  9816. WFIFOL(fd,i*size+5) = pb_ad->index;
  9817. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9818. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9819. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9820. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9821. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9822. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9823. }
  9824. WFIFOSET(fd,WFIFOW(fd,2));
  9825. }
  9826. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9827. /// 0806
  9828. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9829. {
  9830. if(party_booking_delete(sd))
  9831. clif_PartyBookingDeleteAck(sd, 0);
  9832. }
  9833. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9834. /// 0807 <result>.W
  9835. /// result:
  9836. /// 0 = success
  9837. /// 1 = success (auto-removed expired ad)
  9838. /// 2 = failure
  9839. /// 3 = nothing registered
  9840. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9841. {
  9842. int fd = sd->fd;
  9843. WFIFOHEAD(fd,packet_len(0x807));
  9844. WFIFOW(fd,0) = 0x807;
  9845. WFIFOW(fd,2) = flag;
  9846. WFIFOSET(fd,packet_len(0x807));
  9847. }
  9848. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  9849. /// 0808 { <job>.W }*6
  9850. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9851. {
  9852. short job[PARTY_BOOKING_JOBS];
  9853. int i;
  9854. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9855. job[i] = RFIFOW(fd,2+i*2);
  9856. party_booking_update(sd, job);
  9857. }
  9858. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  9859. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  9860. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9861. {
  9862. int i;
  9863. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9864. if(pb_ad == NULL) return;
  9865. WBUFW(buf,0) = 0x809;
  9866. WBUFL(buf,2) = pb_ad->index;
  9867. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9868. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  9869. WBUFW(buf,34) = pb_ad->p_detail.level;
  9870. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9871. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9872. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9873. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9874. }
  9875. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  9876. /// 080a <index>.L { <job>.W }*6
  9877. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9878. {
  9879. int i;
  9880. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9881. if(pb_ad == NULL) return;
  9882. WBUFW(buf,0) = 0x80a;
  9883. WBUFL(buf,2) = pb_ad->index;
  9884. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9885. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9886. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9887. }
  9888. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  9889. /// 080b <index>.L
  9890. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9891. {
  9892. uint8 buf[6];
  9893. WBUFW(buf,0) = 0x80b;
  9894. WBUFL(buf,2) = index;
  9895. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9896. }
  9897. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  9898. /// 012e
  9899. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9900. {
  9901. vending_closevending(sd);
  9902. }
  9903. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  9904. /// 0130 <account id>.L
  9905. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9906. {
  9907. if( sd->npc_id )
  9908. {// using an NPC
  9909. return;
  9910. }
  9911. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9912. }
  9913. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  9914. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  9915. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9916. {
  9917. int len = (int)RFIFOW(fd,2) - 8;
  9918. int id = (int)RFIFOL(fd,4);
  9919. const uint8* data = (uint8*)RFIFOP(fd,8);
  9920. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  9921. // whether it fails or not, the buy window is closed
  9922. sd->vended_id = 0;
  9923. }
  9924. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  9925. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  9926. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9927. {
  9928. int len = (int)RFIFOW(fd,2) - 12;
  9929. int aid = (int)RFIFOL(fd,4);
  9930. int uid = (int)RFIFOL(fd,8);
  9931. const uint8* data = (uint8*)RFIFOP(fd,12);
  9932. vending_purchasereq(sd, aid, uid, data, len/4);
  9933. // whether it fails or not, the buy window is closed
  9934. sd->vended_id = 0;
  9935. }
  9936. /// Confirm or cancel the shop preparation window.
  9937. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  9938. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  9939. /// result:
  9940. /// 0 = canceled
  9941. /// 1 = open
  9942. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9943. {
  9944. short len = (short)RFIFOW(fd,2) - 85;
  9945. const char* message = (char*)RFIFOP(fd,4);
  9946. bool flag = (bool)RFIFOB(fd,84);
  9947. const uint8* data = (uint8*)RFIFOP(fd,85);
  9948. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9949. return;
  9950. if( map[sd->bl.m].flag.novending ) {
  9951. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9952. return;
  9953. }
  9954. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9955. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  9956. return;
  9957. }
  9958. if( message[0] == '\0' ) // invalid input
  9959. return;
  9960. vending_openvending(sd, message, flag, data, len/8);
  9961. }
  9962. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  9963. /// 0165 <char id>.L <guild name>.24B
  9964. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9965. {
  9966. char* name = (char*)RFIFOP(fd,6);
  9967. name[NAME_LENGTH-1] = '\0';
  9968. if(map[sd->bl.m].flag.guildlock)
  9969. { //Guild locked.
  9970. clif_displaymessage(fd, msg_txt(228));
  9971. return;
  9972. }
  9973. guild_create(sd, name);
  9974. }
  9975. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  9976. /// 014d
  9977. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9978. {
  9979. clif_guild_masterormember(sd);
  9980. }
  9981. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  9982. /// 014f <type>.L
  9983. /// type:
  9984. /// 0 = basic info
  9985. /// 1 = member manager
  9986. /// 2 = positions
  9987. /// 3 = skills
  9988. /// 4 = expulsion list
  9989. /// 5 = unknown (GM_ALLGUILDLIST)
  9990. /// 6 = notice
  9991. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  9992. {
  9993. if( !sd->status.guild_id && !sd->bg_id )
  9994. return;
  9995. switch( RFIFOL(fd,2) )
  9996. {
  9997. case 0: // ギルド基本情報、同盟敵対情報
  9998. clif_guild_basicinfo(sd);
  9999. clif_guild_allianceinfo(sd);
  10000. break;
  10001. case 1: // メンバーリスト、役職名リスト
  10002. clif_guild_positionnamelist(sd);
  10003. clif_guild_memberlist(sd);
  10004. break;
  10005. case 2: // 役職名リスト、役職情報リスト
  10006. clif_guild_positionnamelist(sd);
  10007. clif_guild_positioninfolist(sd);
  10008. break;
  10009. case 3: // スキルリスト
  10010. clif_guild_skillinfo(sd);
  10011. break;
  10012. case 4: // 追放リスト
  10013. clif_guild_expulsionlist(sd);
  10014. break;
  10015. default:
  10016. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10017. break;
  10018. }
  10019. }
  10020. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10021. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10022. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10023. {
  10024. int i;
  10025. if(!sd->state.gmaster_flag)
  10026. return;
  10027. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  10028. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10029. }
  10030. }
  10031. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10032. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10033. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10034. {
  10035. int i;
  10036. if(!sd->state.gmaster_flag)
  10037. return;
  10038. for(i=4;i<RFIFOW(fd,2);i+=12){
  10039. guild_change_memberposition(sd->status.guild_id,
  10040. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10041. }
  10042. }
  10043. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10044. /// 0151 <guild id>.L
  10045. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10046. {
  10047. struct guild* g;
  10048. int guild_id = RFIFOL(fd,2);
  10049. if( (g = guild_search(guild_id)) != NULL )
  10050. clif_guild_emblem(sd,g);
  10051. }
  10052. /// Validates data of a guild emblem (compressed bitmap)
  10053. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10054. {
  10055. bool success;
  10056. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10057. unsigned long buf_len = sizeof(buf);
  10058. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10059. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10060. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10061. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10062. ;
  10063. return success;
  10064. }
  10065. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10066. /// 0153 <packet len>.W <emblem data>.?B
  10067. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10068. {
  10069. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10070. const uint8* emblem = RFIFOP(fd,4);
  10071. if( !emblem_len || !sd->state.gmaster_flag )
  10072. return;
  10073. if( !clif_validate_emblem(emblem, emblem_len) )
  10074. {
  10075. 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);
  10076. return;
  10077. }
  10078. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10079. }
  10080. /// Guild notice update request (CZ_GUILD_NOTICE).
  10081. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10082. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10083. {
  10084. int guild_id = RFIFOL(fd,2);
  10085. char* msg1 = (char*)RFIFOP(fd,6);
  10086. char* msg2 = (char*)RFIFOP(fd,66);
  10087. if(!sd->state.gmaster_flag)
  10088. return;
  10089. // compensate for some client defects when using multilanguage mode
  10090. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10091. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10092. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10093. guild_change_notice(sd, guild_id, msg1, msg2);
  10094. }
  10095. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10096. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10097. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10098. {
  10099. struct map_session_data *t_sd;
  10100. if(map[sd->bl.m].flag.guildlock)
  10101. { //Guild locked.
  10102. clif_displaymessage(fd, msg_txt(228));
  10103. return;
  10104. }
  10105. t_sd = map_id2sd(RFIFOL(fd,2));
  10106. // @noask [LuzZza]
  10107. if(t_sd && t_sd->state.noask) {
  10108. clif_noask_sub(sd, t_sd, 2);
  10109. return;
  10110. }
  10111. guild_invite(sd,t_sd);
  10112. }
  10113. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10114. /// 016b <guild id>.L <answer>.L
  10115. /// answer:
  10116. /// 0 = refuse
  10117. /// 1 = accept
  10118. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10119. {
  10120. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10121. }
  10122. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10123. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10124. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10125. {
  10126. if(map[sd->bl.m].flag.guildlock)
  10127. { //Guild locked.
  10128. clif_displaymessage(fd, msg_txt(228));
  10129. return;
  10130. }
  10131. if( sd->bg_id )
  10132. {
  10133. clif_displaymessage(fd, "You can't leave battleground guilds.");
  10134. return;
  10135. }
  10136. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10137. }
  10138. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10139. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10140. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10141. {
  10142. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10143. { // Guild locked.
  10144. clif_displaymessage(fd, msg_txt(228));
  10145. return;
  10146. }
  10147. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10148. }
  10149. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10150. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10151. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10152. {
  10153. const char* text = (char*)RFIFOP(fd,4);
  10154. int textlen = RFIFOW(fd,2) - 4;
  10155. char *name, *message;
  10156. int namelen, messagelen;
  10157. // validate packet and retrieve name and message
  10158. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10159. return;
  10160. if( is_atcommand(fd, sd, message, 1) )
  10161. return;
  10162. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10163. return;
  10164. if( battle_config.min_chat_delay )
  10165. { //[Skotlex]
  10166. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10167. return;
  10168. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10169. }
  10170. if( sd->bg_id )
  10171. bg_send_message(sd, text, textlen);
  10172. else
  10173. guild_send_message(sd, text, textlen);
  10174. }
  10175. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10176. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10177. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10178. {
  10179. struct map_session_data *t_sd;
  10180. if(!sd->state.gmaster_flag)
  10181. return;
  10182. if(map[sd->bl.m].flag.guildlock)
  10183. { //Guild locked.
  10184. clif_displaymessage(fd, msg_txt(228));
  10185. return;
  10186. }
  10187. t_sd = map_id2sd(RFIFOL(fd,2));
  10188. // @noask [LuzZza]
  10189. if(t_sd && t_sd->state.noask) {
  10190. clif_noask_sub(sd, t_sd, 3);
  10191. return;
  10192. }
  10193. guild_reqalliance(sd,t_sd);
  10194. }
  10195. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10196. /// 0172 <inviter account id>.L <answer>.L
  10197. /// answer:
  10198. /// 0 = refuse
  10199. /// 1 = accept
  10200. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10201. {
  10202. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10203. }
  10204. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10205. /// 0183 <opponent guild id>.L <relation>.L
  10206. /// relation:
  10207. /// 0 = Ally
  10208. /// 1 = Enemy
  10209. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10210. {
  10211. if(!sd->state.gmaster_flag)
  10212. return;
  10213. if(map[sd->bl.m].flag.guildlock)
  10214. { //Guild locked.
  10215. clif_displaymessage(fd, msg_txt(228));
  10216. return;
  10217. }
  10218. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10219. }
  10220. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10221. /// 0180 <account id>.L
  10222. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10223. {
  10224. struct map_session_data *t_sd;
  10225. if(!sd->state.gmaster_flag)
  10226. return;
  10227. if(map[sd->bl.m].flag.guildlock)
  10228. { //Guild locked.
  10229. clif_displaymessage(fd, msg_txt(228));
  10230. return;
  10231. }
  10232. t_sd = map_id2sd(RFIFOL(fd,2));
  10233. // @noask [LuzZza]
  10234. if(t_sd && t_sd->state.noask) {
  10235. clif_noask_sub(sd, t_sd, 4);
  10236. return;
  10237. }
  10238. guild_opposition(sd,t_sd);
  10239. }
  10240. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10241. /// 015d <key>.40B
  10242. /// key:
  10243. /// now guild name; might have been (intended) email, since the
  10244. /// field name and size is same as the one in CH_DELETE_CHAR.
  10245. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10246. {
  10247. if( map[sd->bl.m].flag.guildlock )
  10248. { //Guild locked.
  10249. clif_displaymessage(fd, msg_txt(228));
  10250. return;
  10251. }
  10252. guild_break(sd,(char*)RFIFOP(fd,2));
  10253. }
  10254. /// Pet
  10255. ///
  10256. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10257. /// 01a1 <type>.B
  10258. /// type:
  10259. /// 0 = pet information
  10260. /// 1 = feed
  10261. /// 2 = performance
  10262. /// 3 = return to egg
  10263. /// 4 = unequip accessory
  10264. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10265. {
  10266. pet_menu(sd,RFIFOB(fd,2));
  10267. }
  10268. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10269. /// 019f <id>.L
  10270. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10271. {
  10272. pet_catch_process2(sd,RFIFOL(fd,2));
  10273. }
  10274. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10275. /// 01a7 <index>.W
  10276. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10277. {
  10278. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10279. {
  10280. //Forged packet, disconnect them [Kevin]
  10281. clif_authfail_fd(fd, 0);
  10282. return;
  10283. }
  10284. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10285. clif_menuskill_clear(sd);
  10286. }
  10287. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10288. /// 01a9 <data>.L
  10289. /// data:
  10290. /// is either emotion (@see enum emotion_type) or a compound value
  10291. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10292. /// entry (given in parentheses) in data\pettalktable.xml
  10293. /// act id:
  10294. /// 0 = feeding
  10295. /// 1 = hunting
  10296. /// 2 = danger
  10297. /// 3 = dead
  10298. /// 4 = normal (stand)
  10299. /// 5 = special performance (perfor_s)
  10300. /// 6 = level up (levelup)
  10301. /// 7 = performance 1 (perfor_1)
  10302. /// 8 = performance 2 (perfor_2)
  10303. /// 9 = performance 3 (perfor_3)
  10304. /// 10 = log-in greeting (connect)
  10305. /// hungry value:
  10306. /// 0 = very hungry (hungry)
  10307. /// 1 = hungry (bit_hungry)
  10308. /// 2 = satisfied (noting)
  10309. /// 3 = stuffed (full)
  10310. /// 4 = full (so_full)
  10311. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10312. {
  10313. if(sd->pd)
  10314. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10315. }
  10316. /// Request to change pet's name (CZ_RENAME_PET).
  10317. /// 01a5 <name>.24B
  10318. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10319. {
  10320. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10321. }
  10322. /// /kill (CZ_DISCONNECT_CHARACTER).
  10323. /// Request to disconnect a character.
  10324. /// 00cc <account id>.L
  10325. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10326. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10327. {
  10328. struct block_list *target;
  10329. int tid;
  10330. tid = RFIFOL(fd,2);
  10331. target = map_id2bl(tid);
  10332. if (!target) {
  10333. clif_GM_kickack(sd, 0);
  10334. return;
  10335. }
  10336. switch (target->type) {
  10337. case BL_PC:
  10338. {
  10339. char command[NAME_LENGTH+6];
  10340. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10341. is_atcommand(fd, sd, command, 1);
  10342. }
  10343. break;
  10344. /**
  10345. * This one does not invoke any atcommand, so we need to check for permissions.
  10346. */
  10347. case BL_MOB:
  10348. {
  10349. char command[100];
  10350. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10351. clif_GM_kickack(sd, 0);
  10352. return;
  10353. }
  10354. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10355. log_atcommand(sd, command);
  10356. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10357. }
  10358. break;
  10359. case BL_NPC:
  10360. {
  10361. char command[NAME_LENGTH+11];
  10362. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10363. is_atcommand(fd, sd, command, 1);
  10364. }
  10365. break;
  10366. default:
  10367. clif_GM_kickack(sd, 0);
  10368. }
  10369. }
  10370. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10371. /// Request to disconnect all characters.
  10372. /// 00ce
  10373. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10374. char cmd[15];
  10375. sprintf(cmd,"%ckickall",atcommand_symbol);
  10376. is_atcommand(fd, sd, cmd, 1);
  10377. }
  10378. /// /remove (CZ_REMOVE_AID).
  10379. /// Request to warp to a character with given login ID.
  10380. /// 01ba <account name>.24B
  10381. /// /shift (CZ_SHIFT).
  10382. /// Request to warp to a character with given name.
  10383. /// 01bb <char name>.24B
  10384. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10385. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10386. char *player_name;
  10387. char command[NAME_LENGTH+8];
  10388. player_name = (char*)RFIFOP(fd,2);
  10389. player_name[NAME_LENGTH-1] = '\0';
  10390. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10391. is_atcommand(fd, sd, command, 1);
  10392. }
  10393. /// /remove (CZ_REMOVE_AID_SSO).
  10394. /// Request to warp to a character with given account ID.
  10395. /// 0843 <account id>.L
  10396. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10397. {
  10398. int account_id;
  10399. struct map_session_data* pl_sd;
  10400. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10401. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10402. {
  10403. char command[NAME_LENGTH+8];
  10404. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10405. is_atcommand(fd, sd, command, 1);
  10406. }
  10407. }
  10408. /// /recall (CZ_RECALL).
  10409. /// Request to summon a player with given login ID to own position.
  10410. /// 01bc <account name>.24B
  10411. /// /summon (CZ_RECALL_GID).
  10412. /// Request to summon a player with given name to own position.
  10413. /// 01bd <char name>.24B
  10414. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10415. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10416. char *player_name;
  10417. char command [NAME_LENGTH+8];
  10418. player_name = (char*)RFIFOP(fd,2);
  10419. player_name[NAME_LENGTH-1] = '\0';
  10420. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10421. is_atcommand(fd, sd, command, 1);
  10422. }
  10423. /// /recall (CZ_RECALL_SSO).
  10424. /// Request to summon a player with given account ID to own position.
  10425. /// 0842 <account id>.L
  10426. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10427. {
  10428. int account_id;
  10429. struct map_session_data* pl_sd;
  10430. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10431. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10432. {
  10433. char command[NAME_LENGTH+8];
  10434. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10435. is_atcommand(fd, sd, command, 1);
  10436. }
  10437. }
  10438. /// /item /monster (CZ_ITEM_CREATE).
  10439. /// Request to make items or spawn monsters.
  10440. /// 013f <item/mob name>.24B
  10441. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10442. {
  10443. char *monster_item_name;
  10444. char command[NAME_LENGTH+10];
  10445. monster_item_name = (char*)RFIFOP(fd,2);
  10446. monster_item_name[NAME_LENGTH-1] = '\0';
  10447. if( mobdb_searchname(monster_item_name) ) {
  10448. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10449. is_atcommand(fd, sd, command, 1);
  10450. return;
  10451. }
  10452. if( itemdb_searchname(monster_item_name) ) {
  10453. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10454. is_atcommand(fd, sd, command, 1);
  10455. return;
  10456. }
  10457. }
  10458. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10459. /// 019d <effect state>.L
  10460. /// effect state:
  10461. /// TODO: Any OPTION_* ?
  10462. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10463. char cmd[6];
  10464. sprintf(cmd,"%chide",atcommand_symbol);
  10465. is_atcommand(fd, sd, cmd, 1);
  10466. }
  10467. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10468. /// 0149 <account id>.L <type>.B <value>.W
  10469. /// type:
  10470. /// 0 = positive points
  10471. /// 1 = negative points
  10472. /// 2 = self mute (+10 minutes)
  10473. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10474. {
  10475. int id, type, value;
  10476. struct map_session_data *dstsd;
  10477. char command[NAME_LENGTH+15];
  10478. id = RFIFOL(fd,2);
  10479. type = RFIFOB(fd,6);
  10480. value = RFIFOW(fd,7);
  10481. if( type == 0 )
  10482. value = -value;
  10483. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10484. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10485. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10486. return;
  10487. dstsd = map_id2sd(id);
  10488. if( dstsd == NULL )
  10489. return;
  10490. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10491. is_atcommand(fd, sd, command, 1);
  10492. }
  10493. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10494. /// GM adjustment of a player's manner value by -60.
  10495. /// 0212 <char name>.24B
  10496. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10497. {
  10498. char command[NAME_LENGTH+15];
  10499. char *name = (char*)RFIFOP(fd,2);
  10500. name[NAME_LENGTH-1] = '\0';
  10501. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10502. is_atcommand(fd, sd, command, 1);
  10503. }
  10504. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10505. /// 01df <account id>.L
  10506. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10507. /// 01e0 <account id>.L <account name>.24B
  10508. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10509. {
  10510. int tid;
  10511. tid = RFIFOL(fd,2);
  10512. //TODO: find out if this works for any player or only for authorized GMs
  10513. WFIFOHEAD(fd,packet_len(0x1e0));
  10514. WFIFOW(fd,0) = 0x1e0;
  10515. WFIFOL(fd,2) = tid;
  10516. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10517. WFIFOSET(fd, packet_len(0x1e0));
  10518. }
  10519. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10520. /// GM single cell type change request.
  10521. /// 0198 <x>.W <y>.W <type>.W
  10522. /// type:
  10523. /// 0 = not walkable
  10524. /// 1 = walkable
  10525. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10526. {
  10527. int x,y,type;
  10528. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10529. return;
  10530. x = RFIFOW(fd,2);
  10531. y = RFIFOW(fd,4);
  10532. type = RFIFOW(fd,6);
  10533. map_setgatcell(sd->bl.m,x,y,type);
  10534. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10535. //FIXME: once players leave the map, the client 'forgets' this information.
  10536. }
  10537. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10538. /// Request to allow/deny whispers from a nick.
  10539. /// 00cf <nick>.24B <type>.B
  10540. /// type:
  10541. /// 0 = (/ex nick) deny speech from nick
  10542. /// 1 = (/in nick) allow speech from nick
  10543. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10544. {
  10545. char* nick;
  10546. uint8 type;
  10547. int i;
  10548. nick = (char*)RFIFOP(fd,2); // speed up
  10549. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10550. type = RFIFOB(fd,26);
  10551. // FIXME: Use clif_wisexin.
  10552. WFIFOHEAD(fd,packet_len(0xd1));
  10553. WFIFOW(fd,0) = 0x0d1;
  10554. WFIFOB(fd,2) = type;
  10555. if( type == 0 )
  10556. { // Add name to ignore list (block)
  10557. if (strcmp(wisp_server_name, nick) == 0) {
  10558. WFIFOB(fd,3) = 1; // fail
  10559. WFIFOSET(fd, packet_len(0x0d1));
  10560. return;
  10561. }
  10562. // try to find a free spot, while checking for duplicates at the same time
  10563. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10564. if( i == MAX_IGNORE_LIST )
  10565. {// no space for new entry
  10566. WFIFOB(fd,3) = 2; // fail
  10567. WFIFOSET(fd, packet_len(0x0d1));
  10568. return;
  10569. }
  10570. if( sd->ignore[i].name[0] != '\0' )
  10571. {// name already exists
  10572. WFIFOB(fd,3) = 0; // Aegis reports success.
  10573. WFIFOSET(fd, packet_len(0x0d1));
  10574. return;
  10575. }
  10576. //Insert in position i
  10577. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10578. WFIFOB(fd,3) = 0; // success
  10579. WFIFOSET(fd, packet_len(0x0d1));
  10580. }
  10581. else
  10582. { // Remove name from ignore list (unblock)
  10583. // find entry
  10584. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10585. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10586. { //Not found
  10587. WFIFOB(fd,3) = 1; // fail
  10588. WFIFOSET(fd, packet_len(0x0d1));
  10589. return;
  10590. }
  10591. // move everything one place down to overwrite removed entry
  10592. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10593. // wipe last entry
  10594. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10595. WFIFOB(fd,3) = 0; // success
  10596. WFIFOSET(fd, packet_len(0x0d1));
  10597. }
  10598. }
  10599. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10600. /// Request to allow/deny all whispers.
  10601. /// 00d0 <type>.B
  10602. /// type:
  10603. /// 0 = (/exall) deny all speech
  10604. /// 1 = (/inall) allow all speech
  10605. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10606. {
  10607. // FIXME: Use clif_wisall.
  10608. WFIFOHEAD(fd,packet_len(0xd2));
  10609. WFIFOW(fd,0) = 0x0d2;
  10610. WFIFOB(fd,2) = RFIFOB(fd,2);
  10611. if( RFIFOB(fd,2) == 0 )
  10612. {// Deny all
  10613. if( sd->state.ignoreAll ) {
  10614. WFIFOB(fd,3) = 1; // fail
  10615. } else {
  10616. sd->state.ignoreAll = 1;
  10617. WFIFOB(fd,3) = 0; // success
  10618. }
  10619. }
  10620. else
  10621. {//Unblock everyone
  10622. if( sd->state.ignoreAll ) {
  10623. sd->state.ignoreAll = 0;
  10624. WFIFOB(fd,3) = 0; // success
  10625. } else {
  10626. if (sd->ignore[0].name[0] != '\0')
  10627. { //Wipe the ignore list.
  10628. memset(sd->ignore, 0, sizeof(sd->ignore));
  10629. WFIFOB(fd,3) = 0; // success
  10630. } else {
  10631. WFIFOB(fd,3) = 1; // fail
  10632. }
  10633. }
  10634. }
  10635. WFIFOSET(fd, packet_len(0x0d2));
  10636. }
  10637. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10638. /// 00d3
  10639. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10640. {
  10641. int i;
  10642. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10643. WFIFOW(fd,0) = 0xd4;
  10644. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10645. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10646. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10647. WFIFOSET(fd, WFIFOW(fd,2));
  10648. }
  10649. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10650. /// 01e7
  10651. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10652. {
  10653. if (sd->state.doridori) return;
  10654. switch (sd->class_&MAPID_UPPERMASK)
  10655. {
  10656. case MAPID_SOUL_LINKER:
  10657. case MAPID_STAR_GLADIATOR:
  10658. case MAPID_TAEKWON:
  10659. if (!sd->state.rest)
  10660. break;
  10661. case MAPID_SUPER_NOVICE:
  10662. sd->state.doridori=1;
  10663. break;
  10664. }
  10665. }
  10666. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10667. /// 01ed
  10668. /// Note: This packet is caused by 7 lines of any text, followed by
  10669. /// the prayer and an another line of any text. The prayer is
  10670. /// defined by lines 790~793 in data\msgstringtable.txt
  10671. /// "Dear angel, can you hear my voice?"
  10672. /// "I am" (space separated player name) "Super Novice~"
  10673. /// "Help me out~ Please~ T_T"
  10674. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10675. {
  10676. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10677. {
  10678. unsigned int next = pc_nextbaseexp(sd);
  10679. if( next == 0 ) next = pc_thisbaseexp(sd);
  10680. if( next )
  10681. {
  10682. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10683. if( percent && ( percent%100 ) == 0 )
  10684. {// 10.0%, 20.0%, ..., 90.0%
  10685. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10686. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10687. }
  10688. }
  10689. }
  10690. }
  10691. /// Friends List
  10692. ///
  10693. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10694. /// 0206 <account id>.L <char id>.L <state>.B
  10695. /// state:
  10696. /// 0 = online
  10697. /// 1 = offline
  10698. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10699. {
  10700. int i, fd = sd->fd;
  10701. //Seek friend.
  10702. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10703. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10704. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10705. return; //Not found
  10706. WFIFOHEAD(fd,packet_len(0x206));
  10707. WFIFOW(fd, 0) = 0x206;
  10708. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10709. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10710. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10711. WFIFOSET(fd, packet_len(0x206));
  10712. }
  10713. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10714. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10715. {
  10716. int account_id, char_id, online;
  10717. account_id = va_arg(ap, int);
  10718. char_id = va_arg(ap, int);
  10719. online = va_arg(ap, int);
  10720. clif_friendslist_toggle(sd, account_id, char_id, online);
  10721. return 0;
  10722. }
  10723. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10724. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10725. void clif_friendslist_send(struct map_session_data *sd)
  10726. {
  10727. int i = 0, n, fd = sd->fd;
  10728. // Send friends list
  10729. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10730. WFIFOW(fd, 0) = 0x201;
  10731. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10732. {
  10733. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10734. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10735. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10736. }
  10737. if (i) {
  10738. WFIFOW(fd,2) = 4 + 32 * i;
  10739. WFIFOSET(fd, WFIFOW(fd,2));
  10740. }
  10741. for (n = 0; n < i; n++)
  10742. { //Sending the online players
  10743. if (map_charid2sd(sd->status.friends[n].char_id))
  10744. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10745. }
  10746. }
  10747. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10748. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10749. /// result:
  10750. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10751. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10752. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10753. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10754. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10755. {
  10756. int fd;
  10757. nullpo_retv(sd);
  10758. fd = sd->fd;
  10759. WFIFOHEAD(fd,packet_len(0x209));
  10760. WFIFOW(fd,0) = 0x209;
  10761. WFIFOW(fd,2) = type;
  10762. if (f_sd)
  10763. {
  10764. WFIFOL(fd,4) = f_sd->status.account_id;
  10765. WFIFOL(fd,8) = f_sd->status.char_id;
  10766. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10767. }
  10768. WFIFOSET(fd, packet_len(0x209));
  10769. }
  10770. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10771. /// 0202 <name>.24B
  10772. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10773. {
  10774. struct map_session_data *f_sd;
  10775. int i, f_fd;
  10776. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10777. // ensure that the request player's friend list is not full
  10778. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10779. if( i == MAX_FRIENDS ) {
  10780. clif_friendslist_reqack(sd, f_sd, 2);
  10781. return;
  10782. }
  10783. // Friend doesn't exist (no player with this name)
  10784. if (f_sd == NULL) {
  10785. clif_displaymessage(fd, msg_txt(3));
  10786. return;
  10787. }
  10788. if( sd->bl.id == f_sd->bl.id )
  10789. {// adding oneself as friend
  10790. return;
  10791. }
  10792. // @noask [LuzZza]
  10793. if(f_sd->state.noask) {
  10794. clif_noask_sub(sd, f_sd, 5);
  10795. return;
  10796. }
  10797. // Friend already exists
  10798. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10799. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10800. clif_displaymessage(fd, "Friend already exists.");
  10801. return;
  10802. }
  10803. }
  10804. f_sd->friend_req = sd->status.char_id;
  10805. sd->friend_req = f_sd->status.char_id;
  10806. f_fd = f_sd->fd;
  10807. WFIFOHEAD(f_fd,packet_len(0x207));
  10808. WFIFOW(f_fd,0) = 0x207;
  10809. WFIFOL(f_fd,2) = sd->status.account_id;
  10810. WFIFOL(f_fd,6) = sd->status.char_id;
  10811. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10812. WFIFOSET(f_fd, packet_len(0x207));
  10813. }
  10814. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10815. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10816. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10817. /// result:
  10818. /// 0 = rejected
  10819. /// 1 = accepted
  10820. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10821. {
  10822. struct map_session_data *f_sd;
  10823. int char_id, account_id;
  10824. char reply;
  10825. account_id = RFIFOL(fd,2);
  10826. char_id = RFIFOL(fd,6);
  10827. #if PACKETVER < 6
  10828. reply = RFIFOB(fd,10);
  10829. #else
  10830. reply = RFIFOL(fd,10);
  10831. #endif
  10832. if( sd->bl.id == account_id )
  10833. {// adding oneself as friend
  10834. return;
  10835. }
  10836. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10837. if (f_sd == NULL)
  10838. return;
  10839. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10840. clif_friendslist_reqack(f_sd, sd, 1);
  10841. else {
  10842. int i;
  10843. // Find an empty slot
  10844. for (i = 0; i < MAX_FRIENDS; i++)
  10845. if (f_sd->status.friends[i].char_id == 0)
  10846. break;
  10847. if (i == MAX_FRIENDS) {
  10848. clif_friendslist_reqack(f_sd, sd, 2);
  10849. return;
  10850. }
  10851. f_sd->status.friends[i].account_id = sd->status.account_id;
  10852. f_sd->status.friends[i].char_id = sd->status.char_id;
  10853. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10854. clif_friendslist_reqack(f_sd, sd, 0);
  10855. if (battle_config.friend_auto_add) {
  10856. // Also add f_sd to sd's friendlist.
  10857. for (i = 0; i < MAX_FRIENDS; i++) {
  10858. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10859. return; //No need to add anything.
  10860. if (sd->status.friends[i].char_id == 0)
  10861. break;
  10862. }
  10863. if (i == MAX_FRIENDS) {
  10864. clif_friendslist_reqack(sd, f_sd, 2);
  10865. return;
  10866. }
  10867. sd->status.friends[i].account_id = f_sd->status.account_id;
  10868. sd->status.friends[i].char_id = f_sd->status.char_id;
  10869. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10870. clif_friendslist_reqack(sd, f_sd, 0);
  10871. }
  10872. }
  10873. }
  10874. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  10875. /// 0203 <account id>.L <char id>.L
  10876. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10877. {
  10878. struct map_session_data *f_sd = NULL;
  10879. int account_id, char_id;
  10880. int i, j;
  10881. account_id = RFIFOL(fd,2);
  10882. char_id = RFIFOL(fd,6);
  10883. // Search friend
  10884. for (i = 0; i < MAX_FRIENDS &&
  10885. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10886. if (i == MAX_FRIENDS) {
  10887. clif_displaymessage(fd, "Name not found in list.");
  10888. return;
  10889. }
  10890. //remove from friend's list first
  10891. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  10892. for (i = 0; i < MAX_FRIENDS &&
  10893. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  10894. if (i != MAX_FRIENDS) {
  10895. // move all chars up
  10896. for(j = i + 1; j < MAX_FRIENDS; j++)
  10897. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  10898. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  10899. //should the guy be notified of some message? we should add it here if so
  10900. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  10901. WFIFOW(f_sd->fd,0) = 0x20a;
  10902. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  10903. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  10904. WFIFOSET(f_sd->fd, packet_len(0x20a));
  10905. }
  10906. } else { //friend not online -- ask char server to delete from his friendlist
  10907. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  10908. clif_displaymessage(fd, "This action can't be performed at the moment. Please try again later.");
  10909. return;
  10910. }
  10911. }
  10912. // We can now delete from original requester
  10913. for (i = 0; i < MAX_FRIENDS &&
  10914. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10915. // move all chars up
  10916. for(j = i + 1; j < MAX_FRIENDS; j++)
  10917. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10918. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10919. clif_displaymessage(fd, "Friend removed");
  10920. WFIFOHEAD(fd,packet_len(0x20a));
  10921. WFIFOW(fd,0) = 0x20a;
  10922. WFIFOL(fd,2) = account_id;
  10923. WFIFOL(fd,6) = char_id;
  10924. WFIFOSET(fd, packet_len(0x20a));
  10925. // clif_friendslist_send(sd); //This is not needed anymore.
  10926. }
  10927. /// /pvpinfo (CZ_REQ_PVPPOINT).
  10928. /// 020f <char id>.L <account id>.L
  10929. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  10930. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  10931. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10932. {
  10933. WFIFOHEAD(fd,packet_len(0x210));
  10934. WFIFOW(fd,0) = 0x210;
  10935. WFIFOL(fd,2) = sd->status.char_id;
  10936. WFIFOL(fd,6) = sd->status.account_id;
  10937. WFIFOL(fd,10) = sd->pvp_won; // times won
  10938. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10939. WFIFOL(fd,18) = sd->pvp_point;
  10940. WFIFOSET(fd, packet_len(0x210));
  10941. }
  10942. /// /blacksmith (CZ_BLACKSMITH_RANK).
  10943. /// 0217
  10944. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  10945. /// 0219 { <name>.24B }*10 { <point>.L }*10
  10946. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10947. {
  10948. int i;
  10949. const char* name;
  10950. WFIFOHEAD(fd,packet_len(0x219));
  10951. WFIFOW(fd,0) = 0x219;
  10952. //Packet size limits this list to 10 elements. [Skotlex]
  10953. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10954. if (smith_fame_list[i].id > 0) {
  10955. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10956. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10957. {
  10958. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10959. } else
  10960. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10961. } else
  10962. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10963. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10964. }
  10965. for(;i < 10; i++) { //In case the MAX is less than 10.
  10966. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10967. WFIFOL(fd, 242 + i * 4) = 0;
  10968. }
  10969. WFIFOSET(fd, packet_len(0x219));
  10970. }
  10971. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  10972. /// 021b <points>.L <total points>.L
  10973. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  10974. {
  10975. int fd = sd->fd;
  10976. WFIFOHEAD(fd,packet_len(0x21b));
  10977. WFIFOW(fd,0) = 0x21b;
  10978. WFIFOL(fd,2) = points;
  10979. WFIFOL(fd,6) = sd->status.fame;
  10980. WFIFOSET(fd, packet_len(0x21b));
  10981. }
  10982. /// /alchemist (CZ_ALCHEMIST_RANK).
  10983. /// 0218
  10984. /// /alchemist list (ZC_ALCHEMIST_RANK).
  10985. /// 021a { <name>.24B }*10 { <point>.L }*10
  10986. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10987. {
  10988. int i;
  10989. const char* name;
  10990. WFIFOHEAD(fd,packet_len(0x21a));
  10991. WFIFOW(fd,0) = 0x21a;
  10992. //Packet size limits this list to 10 elements. [Skotlex]
  10993. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10994. if (chemist_fame_list[i].id > 0) {
  10995. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10996. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10997. {
  10998. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10999. } else
  11000. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11001. } else
  11002. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11003. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11004. }
  11005. for(;i < 10; i++) { //In case the MAX is less than 10.
  11006. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11007. WFIFOL(fd, 242 + i * 4) = 0;
  11008. }
  11009. WFIFOSET(fd, packet_len(0x21a));
  11010. }
  11011. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11012. /// 021c <points>.L <total points>.L
  11013. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11014. {
  11015. int fd = sd->fd;
  11016. WFIFOHEAD(fd,packet_len(0x21c));
  11017. WFIFOW(fd,0) = 0x21c;
  11018. WFIFOL(fd,2) = points;
  11019. WFIFOL(fd,6) = sd->status.fame;
  11020. WFIFOSET(fd, packet_len(0x21c));
  11021. }
  11022. /// /taekwon (CZ_TAEKWON_RANK).
  11023. /// 0225
  11024. /// /taekwon list (ZC_TAEKWON_RANK).
  11025. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11026. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11027. {
  11028. int i;
  11029. const char* name;
  11030. WFIFOHEAD(fd,packet_len(0x226));
  11031. WFIFOW(fd,0) = 0x226;
  11032. //Packet size limits this list to 10 elements. [Skotlex]
  11033. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11034. if (taekwon_fame_list[i].id > 0) {
  11035. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11036. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11037. {
  11038. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11039. } else
  11040. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11041. } else
  11042. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11043. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11044. }
  11045. for(;i < 10; i++) { //In case the MAX is less than 10.
  11046. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11047. WFIFOL(fd, 242 + i * 4) = 0;
  11048. }
  11049. WFIFOSET(fd, packet_len(0x226));
  11050. }
  11051. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11052. /// 0224 <points>.L <total points>.L
  11053. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11054. {
  11055. int fd = sd->fd;
  11056. WFIFOHEAD(fd,packet_len(0x224));
  11057. WFIFOW(fd,0) = 0x224;
  11058. WFIFOL(fd,2) = points;
  11059. WFIFOL(fd,6) = sd->status.fame;
  11060. WFIFOSET(fd, packet_len(0x224));
  11061. }
  11062. /// /pk (CZ_KILLER_RANK).
  11063. /// 0237
  11064. /// /pk list (ZC_KILLER_RANK).
  11065. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11066. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11067. {
  11068. int i;
  11069. WFIFOHEAD(fd,packet_len(0x238));
  11070. WFIFOW(fd,0) = 0x238;
  11071. for(i=0;i<10;i++){
  11072. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11073. WFIFOL(fd,i*4+242) = 0;
  11074. }
  11075. WFIFOSET(fd, packet_len(0x238));
  11076. }
  11077. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11078. /// 0254 <which>.B
  11079. /// which:
  11080. /// 0 = sun
  11081. /// 1 = moon
  11082. /// 2 = star
  11083. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11084. {
  11085. int i;
  11086. if (sd->menuskill_id != SG_FEEL)
  11087. return;
  11088. i = sd->menuskill_val-1;
  11089. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11090. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11091. sd->feel_map[i].m = sd->bl.m;
  11092. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11093. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11094. // clif_misceffect2(&sd->bl, 0x1b0);
  11095. // clif_misceffect2(&sd->bl, 0x21f);
  11096. clif_feel_info(sd, i, 0);
  11097. clif_menuskill_clear(sd);
  11098. }
  11099. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11100. /// 0253 <which>.B
  11101. /// which:
  11102. /// 0 = sun
  11103. /// 1 = moon
  11104. /// 2 = star
  11105. void clif_feel_req(int fd, struct map_session_data *sd, int skilllv)
  11106. {
  11107. WFIFOHEAD(fd,packet_len(0x253));
  11108. WFIFOW(fd,0)=0x253;
  11109. WFIFOB(fd,2)=TOB(skilllv-1);
  11110. WFIFOSET(fd, packet_len(0x253));
  11111. sd->menuskill_id = SG_FEEL;
  11112. sd->menuskill_val = skilllv;
  11113. }
  11114. /// Request to change homunculus' name (CZ_RENAME_MER).
  11115. /// 0231 <name>.24B
  11116. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11117. {
  11118. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11119. }
  11120. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11121. /// 0234 <id>.L
  11122. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11123. {
  11124. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11125. struct block_list *bl = NULL;
  11126. struct unit_data *ud = NULL;
  11127. if( sd->md && sd->md->bl.id == id )
  11128. bl = &sd->md->bl;
  11129. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11130. bl = &sd->hd->bl; // Moving Homunculus
  11131. else
  11132. return;
  11133. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11134. ud = unit_bl2ud(bl);
  11135. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11136. }
  11137. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11138. /// 0232 <id>.L <position data>.3B
  11139. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11140. {
  11141. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11142. struct block_list *bl = NULL;
  11143. short x, y;
  11144. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11145. if( sd->md && sd->md->bl.id == id )
  11146. bl = &sd->md->bl; // Moving Mercenary
  11147. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11148. bl = &sd->hd->bl; // Moving Homunculus
  11149. else
  11150. return;
  11151. unit_walktoxy(bl, x, y, 4);
  11152. }
  11153. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11154. /// 0233 <id>.L <target id>.L <action>.B
  11155. /// action:
  11156. /// always 0
  11157. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11158. {
  11159. struct block_list *bl = NULL;
  11160. int id = RFIFOL(fd,2),
  11161. target_id = RFIFOL(fd,6),
  11162. action_type = RFIFOB(fd,10);
  11163. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11164. bl = &sd->hd->bl;
  11165. else if( sd->md && sd->md->bl.id == id )
  11166. bl = &sd->md->bl;
  11167. else return;
  11168. unit_stop_attack(bl);
  11169. unit_attack(bl, target_id, action_type != 0);
  11170. }
  11171. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11172. /// 022d <type>.W <command>.B
  11173. /// type:
  11174. /// always 0
  11175. /// command:
  11176. /// 0 = homunculus information
  11177. /// 1 = feed
  11178. /// 2 = delete
  11179. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11180. { //[orn]
  11181. int cmd;
  11182. cmd = RFIFOW(fd,0);
  11183. if(!merc_is_hom_active(sd->hd))
  11184. return;
  11185. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11186. }
  11187. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11188. /// 0292
  11189. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11190. {
  11191. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11192. if (item_position < 0)
  11193. return;
  11194. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11195. return;
  11196. if (!status_revive(&sd->bl, 100, 100))
  11197. return;
  11198. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11199. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11200. }
  11201. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11202. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11203. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11204. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11205. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11206. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11207. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11208. void clif_check(int fd, struct map_session_data* pl_sd)
  11209. {
  11210. WFIFOHEAD(fd,packet_len(0x214));
  11211. WFIFOW(fd, 0) = 0x214;
  11212. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11213. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11214. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11215. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11216. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11217. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11218. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11219. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11220. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11221. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11222. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11223. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11224. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11225. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11226. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11227. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11228. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11229. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11230. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11231. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11232. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11233. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11234. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11235. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11236. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11237. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be?
  11238. WFIFOSET(fd,packet_len(0x214));
  11239. }
  11240. /// /check (CZ_REQ_STATUS_GM).
  11241. /// Request character's status values.
  11242. /// 0213 <char name>.24B
  11243. void clif_parse_Check(int fd, struct map_session_data *sd)
  11244. {
  11245. char charname[NAME_LENGTH];
  11246. struct map_session_data* pl_sd;
  11247. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11248. return;
  11249. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11250. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11251. {
  11252. return;
  11253. }
  11254. clif_check(fd, pl_sd);
  11255. }
  11256. /// MAIL SYSTEM
  11257. /// By Zephyrus
  11258. ///
  11259. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11260. /// 0255 <index>.W <result>.B
  11261. /// result:
  11262. /// 0 = success
  11263. /// 1 = failure
  11264. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11265. {
  11266. WFIFOHEAD(fd,packet_len(0x255));
  11267. WFIFOW(fd,0) = 0x255;
  11268. WFIFOW(fd,2) = index;
  11269. WFIFOB(fd,4) = flag;
  11270. WFIFOSET(fd,packet_len(0x255));
  11271. }
  11272. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11273. /// 0245 <result>.B
  11274. /// result:
  11275. /// 0 = success
  11276. /// 1 = failure
  11277. /// 2 = too many items
  11278. void clif_Mail_getattachment(int fd, uint8 flag)
  11279. {
  11280. WFIFOHEAD(fd,packet_len(0x245));
  11281. WFIFOW(fd,0) = 0x245;
  11282. WFIFOB(fd,2) = flag;
  11283. WFIFOSET(fd,packet_len(0x245));
  11284. }
  11285. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11286. /// 0249 <result>.B
  11287. /// result:
  11288. /// 0 = success
  11289. /// 1 = recipinent does not exist
  11290. void clif_Mail_send(int fd, bool fail)
  11291. {
  11292. WFIFOHEAD(fd,packet_len(0x249));
  11293. WFIFOW(fd,0) = 0x249;
  11294. WFIFOB(fd,2) = fail;
  11295. WFIFOSET(fd,packet_len(0x249));
  11296. }
  11297. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11298. /// 0257 <mail id>.L <result>.W
  11299. /// result:
  11300. /// 0 = success
  11301. /// 1 = failure
  11302. void clif_Mail_delete(int fd, int mail_id, short fail)
  11303. {
  11304. WFIFOHEAD(fd, packet_len(0x257));
  11305. WFIFOW(fd,0) = 0x257;
  11306. WFIFOL(fd,2) = mail_id;
  11307. WFIFOW(fd,6) = fail;
  11308. WFIFOSET(fd, packet_len(0x257));
  11309. }
  11310. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11311. /// 0274 <mail id>.L <result>.W
  11312. /// result:
  11313. /// 0 = success
  11314. /// 1 = failure
  11315. void clif_Mail_return(int fd, int mail_id, short fail)
  11316. {
  11317. WFIFOHEAD(fd,packet_len(0x274));
  11318. WFIFOW(fd,0) = 0x274;
  11319. WFIFOL(fd,2) = mail_id;
  11320. WFIFOW(fd,6) = fail;
  11321. WFIFOSET(fd,packet_len(0x274));
  11322. }
  11323. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11324. /// 024a <mail id>.L <title>.40B <sender>.24B
  11325. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11326. {
  11327. WFIFOHEAD(fd,packet_len(0x24a));
  11328. WFIFOW(fd,0) = 0x24a;
  11329. WFIFOL(fd,2) = mail_id;
  11330. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11331. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11332. WFIFOSET(fd,packet_len(0x24a));
  11333. }
  11334. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11335. /// 0260 <type>.L
  11336. /// type:
  11337. /// 0 = open
  11338. /// 1 = close
  11339. void clif_Mail_window(int fd, int flag)
  11340. {
  11341. WFIFOHEAD(fd,packet_len(0x260));
  11342. WFIFOW(fd,0) = 0x260;
  11343. WFIFOL(fd,2) = flag;
  11344. WFIFOSET(fd,packet_len(0x260));
  11345. }
  11346. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11347. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11348. /// read:
  11349. /// 0 = unread
  11350. /// 1 = read
  11351. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11352. {
  11353. int fd = sd->fd;
  11354. struct mail_data *md = &sd->mail.inbox;
  11355. struct mail_message *msg;
  11356. int len, i, j;
  11357. len = 8 + (73 * md->amount);
  11358. WFIFOHEAD(fd,len);
  11359. WFIFOW(fd,0) = 0x240;
  11360. WFIFOW(fd,2) = len;
  11361. WFIFOL(fd,4) = md->amount;
  11362. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11363. {
  11364. msg = &md->msg[i];
  11365. if (msg->id < 1)
  11366. continue;
  11367. WFIFOL(fd,8+73*j) = msg->id;
  11368. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11369. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11370. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11371. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11372. j++;
  11373. }
  11374. WFIFOSET(fd,len);
  11375. if( md->full )
  11376. {// TODO: is this official?
  11377. char output[100];
  11378. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11379. clif_disp_onlyself(sd, output, strlen(output));
  11380. }
  11381. }
  11382. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11383. /// 023f
  11384. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11385. {
  11386. struct mail_data* md = &sd->mail.inbox;
  11387. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11388. intif_Mail_requestinbox(sd->status.char_id, 1);
  11389. else
  11390. clif_Mail_refreshinbox(sd);
  11391. mail_removeitem(sd, 0);
  11392. mail_removezeny(sd, 0);
  11393. }
  11394. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11395. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11396. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11397. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11398. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11399. {
  11400. int i, fd = sd->fd;
  11401. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11402. if( i == MAIL_MAX_INBOX )
  11403. {
  11404. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11405. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11406. return;
  11407. }
  11408. else
  11409. {
  11410. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11411. struct item *item = &msg->item;
  11412. struct item_data *data;
  11413. int msg_len = strlen(msg->body), len;
  11414. if( msg_len == 0 ) {
  11415. strcpy(msg->body, "(no message)");
  11416. msg_len = strlen(msg->body);
  11417. }
  11418. len = 101 + msg_len;
  11419. WFIFOHEAD(fd,len);
  11420. WFIFOW(fd,0) = 0x242;
  11421. WFIFOW(fd,2) = len;
  11422. WFIFOL(fd,4) = msg->id;
  11423. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11424. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11425. WFIFOL(fd,72) = 0;
  11426. WFIFOL(fd,76) = msg->zeny;
  11427. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  11428. {
  11429. WFIFOL(fd,80) = item->amount;
  11430. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11431. WFIFOW(fd,86) = data->type;
  11432. WFIFOB(fd,88) = item->identify;
  11433. WFIFOB(fd,89) = item->attribute;
  11434. WFIFOB(fd,90) = item->refine;
  11435. WFIFOW(fd,91) = item->card[0];
  11436. WFIFOW(fd,93) = item->card[1];
  11437. WFIFOW(fd,95) = item->card[2];
  11438. WFIFOW(fd,97) = item->card[3];
  11439. }
  11440. else // no item, set all to zero
  11441. memset(WFIFOP(fd,80), 0x00, 19);
  11442. WFIFOB(fd,99) = (unsigned char)msg_len;
  11443. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11444. WFIFOSET(fd,len);
  11445. if (msg->status == MAIL_UNREAD) {
  11446. msg->status = MAIL_READ;
  11447. intif_Mail_read(mail_id);
  11448. clif_parse_Mail_refreshinbox(fd, sd);
  11449. }
  11450. }
  11451. }
  11452. /// Request to open a mail (CZ_MAIL_OPEN).
  11453. /// 0241 <mail id>.L
  11454. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11455. {
  11456. int mail_id = RFIFOL(fd,2);
  11457. if( mail_id <= 0 )
  11458. return;
  11459. if( mail_invalid_operation(sd) )
  11460. return;
  11461. clif_Mail_read(sd, RFIFOL(fd,2));
  11462. }
  11463. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11464. /// 0244 <mail id>.L
  11465. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11466. {
  11467. int mail_id = RFIFOL(fd,2);
  11468. int i;
  11469. bool fail = false;
  11470. if( mail_id <= 0 )
  11471. return;
  11472. if( mail_invalid_operation(sd) )
  11473. return;
  11474. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11475. if( i == MAIL_MAX_INBOX )
  11476. return;
  11477. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11478. return;
  11479. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY )
  11480. {
  11481. clif_Mail_getattachment(fd, 1);
  11482. return;
  11483. }
  11484. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11485. {
  11486. struct item_data *data;
  11487. unsigned int weight;
  11488. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11489. return;
  11490. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11491. {
  11492. case ADDITEM_NEW:
  11493. fail = ( pc_inventoryblank(sd) == 0 );
  11494. break;
  11495. case ADDITEM_OVERAMOUNT:
  11496. fail = true;
  11497. }
  11498. if( fail )
  11499. {
  11500. clif_Mail_getattachment(fd, 1);
  11501. return;
  11502. }
  11503. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11504. if( sd->weight + weight > sd->max_weight )
  11505. {
  11506. clif_Mail_getattachment(fd, 2);
  11507. return;
  11508. }
  11509. }
  11510. sd->mail.inbox.msg[i].zeny = 0;
  11511. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11512. clif_Mail_read(sd, mail_id);
  11513. intif_Mail_getattach(sd->status.char_id, mail_id);
  11514. }
  11515. /// Request to delete a mail (CZ_MAIL_DELETE).
  11516. /// 0243 <mail id>.L
  11517. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11518. {
  11519. int mail_id = RFIFOL(fd,2);
  11520. int i;
  11521. if( mail_id <= 0 )
  11522. return;
  11523. if( mail_invalid_operation(sd) )
  11524. return;
  11525. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11526. if (i < MAIL_MAX_INBOX)
  11527. {
  11528. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11529. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11530. {// can't delete mail without removing attachment first
  11531. clif_Mail_delete(sd->fd, mail_id, 1);
  11532. return;
  11533. }
  11534. intif_Mail_delete(sd->status.char_id, mail_id);
  11535. }
  11536. }
  11537. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11538. /// 0273 <mail id>.L <receive name>.24B
  11539. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11540. {
  11541. int mail_id = RFIFOL(fd,2);
  11542. int i;
  11543. if( mail_id <= 0 )
  11544. return;
  11545. if( mail_invalid_operation(sd) )
  11546. return;
  11547. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11548. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11549. intif_Mail_return(sd->status.char_id, mail_id);
  11550. else
  11551. clif_Mail_return(sd->fd, mail_id, 1);
  11552. }
  11553. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11554. /// 0247 <index>.W <amount>.L
  11555. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11556. {
  11557. int idx = RFIFOW(fd,2);
  11558. int amount = RFIFOL(fd,4);
  11559. unsigned char flag;
  11560. if (idx < 0 || amount < 0)
  11561. return;
  11562. flag = mail_setitem(sd, idx, amount);
  11563. clif_Mail_setattachment(fd,idx,flag);
  11564. }
  11565. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11566. /// 0246 <type>.W
  11567. /// type:
  11568. /// 0 = reset all
  11569. /// 1 = remove item
  11570. /// 2 = remove zeny
  11571. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11572. {
  11573. int flag = RFIFOW(fd,2);
  11574. if (flag == 0 || flag == 1)
  11575. mail_removeitem(sd, 0);
  11576. if (flag == 0 || flag == 2)
  11577. mail_removezeny(sd, 0);
  11578. }
  11579. /// Request to send mail (CZ_MAIL_SEND).
  11580. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11581. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11582. {
  11583. struct mail_message msg;
  11584. int body_len;
  11585. if( sd->state.trading )
  11586. return;
  11587. if( RFIFOW(fd,2) < 69 ) {
  11588. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11589. return;
  11590. }
  11591. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11592. {
  11593. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11594. clif_Mail_send(fd, true); // fail
  11595. return;
  11596. }
  11597. body_len = RFIFOB(fd,68);
  11598. if (body_len > MAIL_BODY_LENGTH)
  11599. body_len = MAIL_BODY_LENGTH;
  11600. if( !mail_setattachment(sd, &msg) )
  11601. { // Invalid Append condition
  11602. clif_Mail_send(sd->fd, true); // fail
  11603. mail_removeitem(sd,0);
  11604. mail_removezeny(sd,0);
  11605. return;
  11606. }
  11607. msg.id = 0; // id will be assigned by charserver
  11608. msg.send_id = sd->status.char_id;
  11609. msg.dest_id = 0; // will attempt to resolve name
  11610. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11611. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11612. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11613. if (body_len)
  11614. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11615. else
  11616. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11617. msg.timestamp = time(NULL);
  11618. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11619. mail_deliveryfail(sd, &msg);
  11620. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11621. }
  11622. /// AUCTION SYSTEM
  11623. /// By Zephyrus
  11624. ///
  11625. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11626. /// 025f <type>.L
  11627. /// type:
  11628. /// 0 = open
  11629. /// 1 = close
  11630. void clif_Auction_openwindow(struct map_session_data *sd)
  11631. {
  11632. int fd = sd->fd;
  11633. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11634. return;
  11635. WFIFOHEAD(fd,packet_len(0x25f));
  11636. WFIFOW(fd,0) = 0x25f;
  11637. WFIFOL(fd,2) = 0;
  11638. WFIFOSET(fd,packet_len(0x25f));
  11639. }
  11640. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11641. /// 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 }*
  11642. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11643. {
  11644. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11645. struct auction_data auction;
  11646. struct item_data *item;
  11647. int k;
  11648. WFIFOHEAD(fd,12 + (count * 83));
  11649. WFIFOW(fd,0) = 0x252;
  11650. WFIFOW(fd,2) = 12 + (count * 83);
  11651. WFIFOL(fd,4) = pages;
  11652. WFIFOL(fd,8) = count;
  11653. for( i = 0; i < count; i++ )
  11654. {
  11655. memcpy(&auction, RBUFP(buf,i * len), len);
  11656. k = 12 + (i * 83);
  11657. WFIFOL(fd,k) = auction.auction_id;
  11658. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11659. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11660. WFIFOW(fd,28+k) = item->view_id;
  11661. else
  11662. WFIFOW(fd,28+k) = auction.item.nameid;
  11663. WFIFOL(fd,30+k) = auction.type;
  11664. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11665. WFIFOB(fd,36+k) = auction.item.identify;
  11666. WFIFOB(fd,37+k) = auction.item.attribute;
  11667. WFIFOB(fd,38+k) = auction.item.refine;
  11668. WFIFOW(fd,39+k) = auction.item.card[0];
  11669. WFIFOW(fd,41+k) = auction.item.card[1];
  11670. WFIFOW(fd,43+k) = auction.item.card[2];
  11671. WFIFOW(fd,45+k) = auction.item.card[3];
  11672. WFIFOL(fd,47+k) = auction.price;
  11673. WFIFOL(fd,51+k) = auction.buynow;
  11674. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11675. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11676. }
  11677. WFIFOSET(fd,WFIFOW(fd,2));
  11678. }
  11679. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11680. /// 0256 <index>.W <result>.B
  11681. /// result:
  11682. /// 0 = success
  11683. /// 1 = failure
  11684. static void clif_Auction_setitem(int fd, int index, bool fail)
  11685. {
  11686. WFIFOHEAD(fd,packet_len(0x256));
  11687. WFIFOW(fd,0) = 0x256;
  11688. WFIFOW(fd,2) = index;
  11689. WFIFOB(fd,4) = fail;
  11690. WFIFOSET(fd,packet_len(0x256));
  11691. }
  11692. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11693. /// 024b <type>.W
  11694. /// type:
  11695. /// 0 = create (any other action in auction window)
  11696. /// 1 = cancel (cancel pressed on register tab)
  11697. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11698. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11699. {
  11700. if( sd->auction.amount > 0 )
  11701. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11702. sd->auction.amount = 0;
  11703. }
  11704. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11705. /// 024c <index>.W <count>.L
  11706. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11707. {
  11708. int idx = RFIFOW(fd,2) - 2;
  11709. int amount = RFIFOL(fd,4); // Always 1
  11710. struct item_data *item;
  11711. if( sd->auction.amount > 0 )
  11712. sd->auction.amount = 0;
  11713. if( idx < 0 || idx >= MAX_INVENTORY )
  11714. {
  11715. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11716. return;
  11717. }
  11718. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11719. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11720. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11721. return;
  11722. }
  11723. 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) )
  11724. { // Consumable or pets are not allowed
  11725. clif_Auction_setitem(sd->fd, idx, true);
  11726. return;
  11727. }
  11728. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11729. !sd->status.inventory[idx].identify ||
  11730. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11731. clif_Auction_setitem(sd->fd, idx, true);
  11732. return;
  11733. }
  11734. sd->auction.index = idx;
  11735. sd->auction.amount = amount;
  11736. clif_Auction_setitem(fd, idx + 2, false);
  11737. }
  11738. /// Result from an auction action (ZC_AUCTION_RESULT).
  11739. /// 0250 <result>.B
  11740. /// result:
  11741. /// 0 = You have failed to bid into the auction
  11742. /// 1 = You have successfully bid in the auction
  11743. /// 2 = The auction has been canceled
  11744. /// 3 = An auction with at least one bidder cannot be canceled
  11745. /// 4 = You cannot register more than 5 items in an auction at a time
  11746. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11747. /// 6 = You have won the auction
  11748. /// 7 = You have failed to win the auction
  11749. /// 8 = You do not have enough Zeny
  11750. /// 9 = You cannot place more than 5 bids at a time
  11751. void clif_Auction_message(int fd, unsigned char flag)
  11752. {
  11753. WFIFOHEAD(fd,packet_len(0x250));
  11754. WFIFOW(fd,0) = 0x250;
  11755. WFIFOB(fd,2) = flag;
  11756. WFIFOSET(fd,packet_len(0x250));
  11757. }
  11758. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11759. /// 025e <result>.W
  11760. /// result:
  11761. /// 0 = You have ended the auction
  11762. /// 1 = You cannot end the auction
  11763. /// 2 = Auction ID is incorrect
  11764. void clif_Auction_close(int fd, unsigned char flag)
  11765. {
  11766. WFIFOHEAD(fd,packet_len(0x25e));
  11767. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11768. WFIFOW(fd,2) = flag;
  11769. WFIFOSET(fd,packet_len(0x25e));
  11770. }
  11771. /// Request to add an auction (CZ_AUCTION_ADD).
  11772. /// 024d <now money>.L <max money>.L <delete hour>.W
  11773. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11774. {
  11775. struct auction_data auction;
  11776. struct item_data *item;
  11777. auction.price = RFIFOL(fd,2);
  11778. auction.buynow = RFIFOL(fd,6);
  11779. auction.hours = RFIFOW(fd,10);
  11780. // Invalid Situations...
  11781. if( sd->auction.amount < 1 )
  11782. {
  11783. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11784. return;
  11785. }
  11786. if( auction.price >= auction.buynow )
  11787. {
  11788. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11789. return;
  11790. }
  11791. if( auction.hours < 1 || auction.hours > 48 )
  11792. {
  11793. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11794. return;
  11795. }
  11796. // Auction checks...
  11797. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11798. {
  11799. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11800. return;
  11801. }
  11802. if( auction.buynow > battle_config.auction_maximumprice )
  11803. { // Zeny Limits
  11804. auction.buynow = battle_config.auction_maximumprice;
  11805. if( auction.price >= auction.buynow )
  11806. auction.price = auction.buynow - 1;
  11807. }
  11808. auction.auction_id = 0;
  11809. auction.seller_id = sd->status.char_id;
  11810. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11811. auction.buyer_id = 0;
  11812. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11813. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11814. {
  11815. clif_Auction_message(fd, 2); // The auction has been canceled
  11816. return;
  11817. }
  11818. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11819. { // Just in case
  11820. clif_Auction_message(fd, 2); // The auction has been canceled
  11821. return;
  11822. }
  11823. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11824. auction.type = item->type;
  11825. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11826. auction.item.amount = 1;
  11827. auction.timestamp = 0;
  11828. if( !intif_Auction_register(&auction) )
  11829. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11830. else
  11831. {
  11832. int zeny = auction.hours*battle_config.auction_feeperhour;
  11833. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11834. sd->auction.amount = 0;
  11835. log_zeny(sd, LOG_TYPE_AUCTION, sd, -zeny);
  11836. pc_payzeny(sd, zeny);
  11837. }
  11838. }
  11839. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11840. /// 024e <auction id>.L
  11841. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11842. {
  11843. unsigned int auction_id = RFIFOL(fd,2);
  11844. intif_Auction_cancel(sd->status.char_id, auction_id);
  11845. }
  11846. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11847. /// 025d <auction id>.L
  11848. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11849. {
  11850. unsigned int auction_id = RFIFOL(fd,2);
  11851. intif_Auction_close(sd->status.char_id, auction_id);
  11852. }
  11853. /// Places a bid on an auction (CZ_AUCTION_BUY).
  11854. /// 024f <auction id>.L <money>.L
  11855. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11856. {
  11857. unsigned int auction_id = RFIFOL(fd,2);
  11858. int bid = RFIFOL(fd,6);
  11859. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  11860. clif_displaymessage(sd->fd, msg_txt(246));
  11861. return;
  11862. }
  11863. if( bid <= 0 )
  11864. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11865. else if( bid > sd->status.zeny )
  11866. clif_Auction_message(fd, 8); // You do not have enough zeny
  11867. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  11868. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11869. else {
  11870. log_zeny(sd, LOG_TYPE_AUCTION, sd, -bid);
  11871. pc_payzeny(sd, bid);
  11872. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11873. }
  11874. }
  11875. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  11876. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  11877. /// search type:
  11878. /// 0 = armor
  11879. /// 1 = weapon
  11880. /// 2 = card
  11881. /// 3 = misc
  11882. /// 4 = name search
  11883. /// 5 = auction id search
  11884. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11885. {
  11886. char search_text[NAME_LENGTH];
  11887. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11888. int price = RFIFOL(fd,4); // FIXME: bug #5071
  11889. clif_parse_Auction_cancelreg(fd, sd);
  11890. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  11891. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11892. }
  11893. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  11894. /// 025c <type>.W
  11895. /// type:
  11896. /// 0 = sell (own auctions)
  11897. /// 1 = buy (own bids)
  11898. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11899. {
  11900. short type = RFIFOW(fd,2) + 6;
  11901. clif_parse_Auction_cancelreg(fd, sd);
  11902. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11903. }
  11904. /// CASH/POINT SHOP
  11905. ///
  11906. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  11907. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  11908. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  11909. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11910. {
  11911. int fd,i;
  11912. #if PACKETVER < 20070711
  11913. const int offset = 8;
  11914. #else
  11915. const int offset = 12;
  11916. #endif
  11917. nullpo_retv(sd);
  11918. nullpo_retv(nd);
  11919. fd = sd->fd;
  11920. sd->npc_shopid = nd->bl.id;
  11921. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  11922. WFIFOW(fd,0) = 0x287;
  11923. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  11924. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11925. #if PACKETVER >= 20070711
  11926. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11927. #endif
  11928. for( i = 0; i < nd->u.shop.count; i++ )
  11929. {
  11930. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11931. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  11932. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  11933. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  11934. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11935. }
  11936. WFIFOSET(fd,WFIFOW(fd,2));
  11937. }
  11938. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  11939. /// 0289 <cash point>.L <error>.W
  11940. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  11941. /// error:
  11942. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  11943. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11944. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11945. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11946. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11947. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11948. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11949. /// 7 = You can purchase up to 10 items.
  11950. /// 8 = Some items could not be purchased.
  11951. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11952. {
  11953. int fd = sd->fd;
  11954. WFIFOHEAD(fd, packet_len(0x289));
  11955. WFIFOW(fd,0) = 0x289;
  11956. WFIFOL(fd,2) = sd->cashPoints;
  11957. #if PACKETVER < 20070711
  11958. WFIFOW(fd,6) = TOW(error);
  11959. #else
  11960. WFIFOL(fd,6) = sd->kafraPoints;
  11961. WFIFOW(fd,10) = TOW(error);
  11962. #endif
  11963. WFIFOSET(fd, packet_len(0x289));
  11964. }
  11965. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  11966. /// 0288 <name id>.W <amount>.W
  11967. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  11968. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  11969. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11970. {
  11971. int fail = 0;
  11972. nullpo_retv(sd);
  11973. if( sd->state.trading || !sd->npc_shopid )
  11974. fail = 1;
  11975. else
  11976. {
  11977. #if PACKETVER < 20101116
  11978. short nameid = RFIFOW(fd,2);
  11979. short amount = RFIFOW(fd,4);
  11980. int points = RFIFOL(fd,6);
  11981. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11982. #else
  11983. int len = RFIFOW(fd,2);
  11984. int points = RFIFOL(fd,4);
  11985. int count = RFIFOW(fd,8);
  11986. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  11987. if( len < 10 || len != 10 + count * 4)
  11988. {
  11989. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  11990. return;
  11991. }
  11992. fail = npc_cashshop_buylist(sd,points,count,item_list);
  11993. #endif
  11994. }
  11995. clif_cashshop_ack(sd,fail);
  11996. }
  11997. /// Adoption System
  11998. ///
  11999. /// Adoption message (ZC_BABYMSG).
  12000. /// 0216 <msg>.L
  12001. /// msg:
  12002. /// 0 = "You cannot adopt more than 1 child."
  12003. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12004. /// 2 = "You cannot adopt a married person."
  12005. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12006. {
  12007. int fd = sd->fd;
  12008. WFIFOHEAD(fd,6);
  12009. WFIFOW(fd,0) = 0x216;
  12010. WFIFOL(fd,2) = type;
  12011. WFIFOSET(fd,6);
  12012. }
  12013. /// Adoption confirmation (ZC_REQ_BABY).
  12014. /// 01f6 <account id>.L <char id>.L <name>.B
  12015. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12016. {
  12017. int fd = sd->fd;
  12018. WFIFOHEAD(fd,34);
  12019. WFIFOW(fd,0) = 0x1f6;
  12020. WFIFOL(fd,2) = src->status.account_id;
  12021. WFIFOL(fd,6) = p_id;
  12022. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12023. WFIFOSET(fd,34);
  12024. }
  12025. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12026. /// 01f9 <account id>.L
  12027. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12028. {
  12029. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12030. if( pc_can_Adopt(sd, p_sd, tsd) )
  12031. {
  12032. tsd->adopt_invite = sd->status.account_id;
  12033. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12034. }
  12035. }
  12036. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12037. /// 01f7 <account id>.L <char id>.L <answer>.L
  12038. /// answer:
  12039. /// 0 = rejected
  12040. /// 1 = accepted
  12041. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12042. {
  12043. int p1_id = RFIFOL(fd,2);
  12044. int p2_id = RFIFOL(fd,6);
  12045. int result = RFIFOL(fd,10);
  12046. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12047. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12048. int pid = sd->adopt_invite;
  12049. sd->adopt_invite = 0;
  12050. if( p1_sd == NULL || p2_sd == NULL )
  12051. return; // Both players need to be online
  12052. if( pid != p1_sd->status.account_id )
  12053. return; // Incorrect values
  12054. if( result == 0 )
  12055. return; // Rejected
  12056. pc_adoption(p1_sd, p2_sd, sd);
  12057. }
  12058. /// Convex Mirror (ZC_BOSS_INFO).
  12059. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12060. /// infoType:
  12061. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12062. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12063. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12064. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12065. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12066. {
  12067. WFIFOHEAD(fd,70);
  12068. memset(WFIFOP(fd,0),0,70);
  12069. WFIFOW(fd,0) = 0x293;
  12070. if( md != NULL )
  12071. {
  12072. if( md->bl.prev != NULL )
  12073. { // Boss on This Map
  12074. if( flag )
  12075. {
  12076. WFIFOB(fd,2) = 1;
  12077. WFIFOL(fd,3) = md->bl.x;
  12078. WFIFOL(fd,7) = md->bl.y;
  12079. }
  12080. else
  12081. WFIFOB(fd,2) = 2; // First Time
  12082. }
  12083. else if (md->spawn_timer != INVALID_TIMER)
  12084. { // Boss is Dead
  12085. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12086. unsigned int seconds;
  12087. int hours, minutes;
  12088. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12089. hours = seconds / (60 * 60);
  12090. seconds = seconds - (60 * 60 * hours);
  12091. minutes = seconds / 60;
  12092. WFIFOB(fd,2) = 3;
  12093. WFIFOW(fd,11) = hours; // Hours
  12094. WFIFOW(fd,13) = minutes; // Minutes
  12095. }
  12096. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12097. }
  12098. WFIFOSET(fd,70);
  12099. }
  12100. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12101. /// 02d6 <account id>.L
  12102. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12103. {
  12104. int charid = RFIFOL(fd, 2);
  12105. struct map_session_data* tsd = map_id2sd(charid);
  12106. if (!tsd)
  12107. return;
  12108. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12109. clif_viewequip_ack(sd, tsd);
  12110. else
  12111. clif_viewequip_fail(sd);
  12112. }
  12113. /// Request to change equip window tick (CZ_CONFIG).
  12114. /// 02d8 <type>.L <value>.L
  12115. /// type:
  12116. /// 0 = open equip window
  12117. /// value:
  12118. /// 0 = disabled
  12119. /// 1 = enabled
  12120. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12121. {
  12122. bool flag = (bool)RFIFOL(fd,6);
  12123. sd->status.show_equip = flag;
  12124. clif_equiptickack(sd, flag);
  12125. }
  12126. /// Questlog System [Kevin] [Inkfish]
  12127. ///
  12128. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12129. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12130. void clif_quest_send_list(struct map_session_data * sd)
  12131. {
  12132. int fd = sd->fd;
  12133. int i;
  12134. int len = sd->avail_quests*5+8;
  12135. WFIFOHEAD(fd,len);
  12136. WFIFOW(fd, 0) = 0x2b1;
  12137. WFIFOW(fd, 2) = len;
  12138. WFIFOL(fd, 4) = sd->avail_quests;
  12139. for( i = 0; i < sd->avail_quests; i++ )
  12140. {
  12141. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12142. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12143. }
  12144. WFIFOSET(fd, len);
  12145. }
  12146. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12147. /// 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
  12148. void clif_quest_send_mission(struct map_session_data * sd)
  12149. {
  12150. int fd = sd->fd;
  12151. int i, j;
  12152. int len = sd->avail_quests*104+8;
  12153. struct mob_db *mob;
  12154. WFIFOHEAD(fd, len);
  12155. WFIFOW(fd, 0) = 0x2b2;
  12156. WFIFOW(fd, 2) = len;
  12157. WFIFOL(fd, 4) = sd->avail_quests;
  12158. for( i = 0; i < sd->avail_quests; i++ )
  12159. {
  12160. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12161. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12162. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12163. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12164. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  12165. {
  12166. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12167. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12168. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12169. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12170. }
  12171. }
  12172. WFIFOSET(fd, len);
  12173. }
  12174. /// Notification about a new quest (ZC_ADD_QUEST).
  12175. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12176. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12177. {
  12178. int fd = sd->fd;
  12179. int i;
  12180. struct mob_db *mob;
  12181. WFIFOHEAD(fd, packet_len(0x2b3));
  12182. WFIFOW(fd, 0) = 0x2b3;
  12183. WFIFOL(fd, 2) = qd->quest_id;
  12184. WFIFOB(fd, 6) = qd->state;
  12185. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12186. WFIFOL(fd, 11) = qd->time;
  12187. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12188. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12189. {
  12190. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12191. WFIFOW(fd, i*30+21) = qd->count[i];
  12192. mob = mob_db(quest_db[index].mob[i]);
  12193. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12194. }
  12195. WFIFOSET(fd, packet_len(0x2b3));
  12196. }
  12197. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12198. /// 02b4 <quest id>.L
  12199. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12200. {
  12201. int fd = sd->fd;
  12202. WFIFOHEAD(fd, packet_len(0x2b4));
  12203. WFIFOW(fd, 0) = 0x2b4;
  12204. WFIFOL(fd, 2) = quest_id;
  12205. WFIFOSET(fd, packet_len(0x2b4));
  12206. }
  12207. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12208. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12209. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12210. {
  12211. int fd = sd->fd;
  12212. int i;
  12213. int len = quest_db[index].num_objectives*12+6;
  12214. WFIFOHEAD(fd, len);
  12215. WFIFOW(fd, 0) = 0x2b5;
  12216. WFIFOW(fd, 2) = len;
  12217. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12218. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12219. {
  12220. WFIFOL(fd, i*12+6) = qd->quest_id;
  12221. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12222. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12223. WFIFOW(fd, i*12+16) = qd->count[i];
  12224. }
  12225. WFIFOSET(fd, len);
  12226. }
  12227. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12228. /// 02b6 <quest id>.L <active>.B
  12229. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12230. {
  12231. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12232. }
  12233. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12234. /// 02b7 <quest id>.L <active>.B
  12235. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12236. {
  12237. int fd = sd->fd;
  12238. WFIFOHEAD(fd, packet_len(0x2b7));
  12239. WFIFOW(fd, 0) = 0x2b7;
  12240. WFIFOL(fd, 2) = quest_id;
  12241. WFIFOB(fd, 6) = active;
  12242. WFIFOSET(fd, packet_len(0x2b7));
  12243. }
  12244. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12245. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12246. /// effect:
  12247. /// 0 = none
  12248. /// 1 = exclamation mark icon
  12249. /// 2 = question mark icon
  12250. /// type:
  12251. /// 0 = yellow
  12252. /// 1 = orange
  12253. /// 2 = green
  12254. /// 3 = purple
  12255. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12256. {
  12257. #if PACKETVER >= 20090218
  12258. int fd = sd->fd;
  12259. WFIFOHEAD(fd, packet_len(0x446));
  12260. WFIFOW(fd, 0) = 0x446;
  12261. WFIFOL(fd, 2) = bl->id;
  12262. WFIFOW(fd, 6) = bl->x;
  12263. WFIFOW(fd, 8) = bl->y;
  12264. WFIFOW(fd, 10) = state;
  12265. WFIFOW(fd, 12) = color;
  12266. WFIFOSET(fd, packet_len(0x446));
  12267. #endif
  12268. }
  12269. /// Mercenary System
  12270. ///
  12271. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12272. /// 02a2 <var id>.W <value>.L
  12273. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12274. {
  12275. struct mercenary_data *md;
  12276. struct status_data *status;
  12277. int fd;
  12278. if( sd == NULL || (md = sd->md) == NULL )
  12279. return;
  12280. fd = sd->fd;
  12281. status = &md->battle_status;
  12282. WFIFOHEAD(fd,packet_len(0x2a2));
  12283. WFIFOW(fd,0) = 0x2a2;
  12284. WFIFOW(fd,2) = type;
  12285. switch( type )
  12286. {
  12287. case SP_ATK1:
  12288. {
  12289. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12290. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12291. }
  12292. break;
  12293. case SP_MATK1:
  12294. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12295. break;
  12296. case SP_HIT:
  12297. WFIFOL(fd,4) = status->hit;
  12298. break;
  12299. case SP_CRITICAL:
  12300. WFIFOL(fd,4) = status->cri/10;
  12301. break;
  12302. case SP_DEF1:
  12303. WFIFOL(fd,4) = status->def;
  12304. break;
  12305. case SP_MDEF1:
  12306. WFIFOL(fd,4) = status->mdef;
  12307. break;
  12308. case SP_MERCFLEE:
  12309. WFIFOL(fd,4) = status->flee;
  12310. break;
  12311. case SP_ASPD:
  12312. WFIFOL(fd,4) = status->amotion;
  12313. break;
  12314. case SP_HP:
  12315. WFIFOL(fd,4) = status->hp;
  12316. break;
  12317. case SP_MAXHP:
  12318. WFIFOL(fd,4) = status->max_hp;
  12319. break;
  12320. case SP_SP:
  12321. WFIFOL(fd,4) = status->sp;
  12322. break;
  12323. case SP_MAXSP:
  12324. WFIFOL(fd,4) = status->max_sp;
  12325. break;
  12326. case SP_MERCKILLS:
  12327. WFIFOL(fd,4) = md->mercenary.kill_count;
  12328. break;
  12329. case SP_MERCFAITH:
  12330. WFIFOL(fd,4) = mercenary_get_faith(md);
  12331. break;
  12332. }
  12333. WFIFOSET(fd,packet_len(0x2a2));
  12334. }
  12335. /// Mercenary base status data (ZC_MER_INIT).
  12336. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12337. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12338. /// <calls>.L <kills>.L <atk range>.W
  12339. void clif_mercenary_info(struct map_session_data *sd)
  12340. {
  12341. int fd;
  12342. struct mercenary_data *md;
  12343. struct status_data *status;
  12344. int atk;
  12345. if( sd == NULL || (md = sd->md) == NULL )
  12346. return;
  12347. fd = sd->fd;
  12348. status = &md->battle_status;
  12349. WFIFOHEAD(fd,packet_len(0x29b));
  12350. WFIFOW(fd,0) = 0x29b;
  12351. WFIFOL(fd,2) = md->bl.id;
  12352. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12353. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12354. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12355. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12356. WFIFOW(fd,10) = status->hit;
  12357. WFIFOW(fd,12) = status->cri/10;
  12358. WFIFOW(fd,14) = status->def;
  12359. WFIFOW(fd,16) = status->mdef;
  12360. WFIFOW(fd,18) = status->flee;
  12361. WFIFOW(fd,20) = status->amotion;
  12362. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12363. WFIFOW(fd,46) = md->db->lv;
  12364. WFIFOL(fd,48) = status->hp;
  12365. WFIFOL(fd,52) = status->max_hp;
  12366. WFIFOL(fd,56) = status->sp;
  12367. WFIFOL(fd,60) = status->max_sp;
  12368. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12369. WFIFOW(fd,68) = mercenary_get_faith(md);
  12370. WFIFOL(fd,70) = mercenary_get_calls(md);
  12371. WFIFOL(fd,74) = md->mercenary.kill_count;
  12372. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12373. WFIFOSET(fd,packet_len(0x29b));
  12374. }
  12375. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12376. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12377. void clif_mercenary_skillblock(struct map_session_data *sd)
  12378. {
  12379. struct mercenary_data *md;
  12380. int fd, i, len = 4, id, j;
  12381. if( sd == NULL || (md = sd->md) == NULL )
  12382. return;
  12383. fd = sd->fd;
  12384. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12385. WFIFOW(fd,0) = 0x29d;
  12386. for( i = 0; i < MAX_MERCSKILL; i++ )
  12387. {
  12388. if( (id = md->db->skill[i].id) == 0 )
  12389. continue;
  12390. j = id - MC_SKILLBASE;
  12391. WFIFOW(fd,len) = id;
  12392. WFIFOL(fd,len+2) = skill_get_inf(id);
  12393. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12394. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12395. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12396. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12397. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12398. len += 37;
  12399. }
  12400. WFIFOW(fd,2) = len;
  12401. WFIFOSET(fd,len);
  12402. }
  12403. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12404. /// 029f <command>.B
  12405. /// 1 = mercenary information
  12406. /// 2 = delete
  12407. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12408. {
  12409. int option = RFIFOB(fd,2);
  12410. if( sd->md == NULL )
  12411. return;
  12412. if( option == 2 ) merc_delete(sd->md, 2);
  12413. }
  12414. /// Mercenary Message
  12415. /// message:
  12416. /// 0 = Mercenary soldier's duty hour is over.
  12417. /// 1 = Your mercenary soldier has been killed.
  12418. /// 2 = Your mercenary soldier has been fired.
  12419. /// 3 = Your mercenary soldier has ran away.
  12420. void clif_mercenary_message(struct map_session_data* sd, int message)
  12421. {
  12422. clif_msg(sd, 1266 + message);
  12423. }
  12424. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12425. /// 0298 <name id>.W <seconds>.L
  12426. void clif_rental_time(int fd, int nameid, int seconds)
  12427. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12428. WFIFOHEAD(fd,packet_len(0x298));
  12429. WFIFOW(fd,0) = 0x298;
  12430. WFIFOW(fd,2) = nameid;
  12431. WFIFOL(fd,4) = seconds;
  12432. WFIFOSET(fd,packet_len(0x298));
  12433. }
  12434. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12435. /// 0299 <index>.W <name id>.W
  12436. void clif_rental_expired(int fd, int index, int nameid)
  12437. { // '<ItemName>' item has been deleted from the Inventory
  12438. WFIFOHEAD(fd,packet_len(0x299));
  12439. WFIFOW(fd,0) = 0x299;
  12440. WFIFOW(fd,2) = index+2;
  12441. WFIFOW(fd,4) = nameid;
  12442. WFIFOSET(fd,packet_len(0x299));
  12443. }
  12444. /// Book Reading (ZC_READ_BOOK).
  12445. /// 0294 <book id>.L <page>.L
  12446. void clif_readbook(int fd, int book_id, int page)
  12447. {
  12448. WFIFOHEAD(fd,packet_len(0x294));
  12449. WFIFOW(fd,0) = 0x294;
  12450. WFIFOL(fd,2) = book_id;
  12451. WFIFOL(fd,6) = page;
  12452. WFIFOSET(fd,packet_len(0x294));
  12453. }
  12454. /// Battlegrounds
  12455. ///
  12456. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12457. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12458. void clif_bg_hp(struct map_session_data *sd)
  12459. {
  12460. unsigned char buf[34];
  12461. const int cmd = 0x2e0;
  12462. nullpo_retv(sd);
  12463. WBUFW(buf,0) = cmd;
  12464. WBUFL(buf,2) = sd->status.account_id;
  12465. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12466. if( sd->battle_status.max_hp > INT16_MAX )
  12467. { // To correctly display the %hp bar. [Skotlex]
  12468. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12469. WBUFW(buf,32) = 100;
  12470. }
  12471. else
  12472. {
  12473. WBUFW(buf,30) = sd->battle_status.hp;
  12474. WBUFW(buf,32) = sd->battle_status.max_hp;
  12475. }
  12476. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12477. }
  12478. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12479. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12480. void clif_bg_xy(struct map_session_data *sd)
  12481. {
  12482. unsigned char buf[36];
  12483. nullpo_retv(sd);
  12484. WBUFW(buf,0)=0x2df;
  12485. WBUFL(buf,2)=sd->status.account_id;
  12486. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12487. WBUFW(buf,30)=sd->status.class_;
  12488. WBUFW(buf,32)=sd->bl.x;
  12489. WBUFW(buf,34)=sd->bl.y;
  12490. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12491. }
  12492. void clif_bg_xy_remove(struct map_session_data *sd)
  12493. {
  12494. unsigned char buf[36];
  12495. nullpo_retv(sd);
  12496. WBUFW(buf,0)=0x2df;
  12497. WBUFL(buf,2)=sd->status.account_id;
  12498. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12499. WBUFW(buf,30)=0;
  12500. WBUFW(buf,32)=-1;
  12501. WBUFW(buf,34)=-1;
  12502. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12503. }
  12504. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12505. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12506. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12507. {
  12508. struct map_session_data *sd;
  12509. unsigned char *buf;
  12510. if( (sd = bg_getavailablesd(bg)) == NULL )
  12511. return;
  12512. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12513. WBUFW(buf,0) = 0x2dc;
  12514. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12515. WBUFL(buf,4) = src_id;
  12516. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12517. memcpy(WBUFP(buf,32), mes, len);
  12518. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12519. if( buf )
  12520. aFree(buf);
  12521. }
  12522. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12523. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12524. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12525. {
  12526. const char* text = (char*)RFIFOP(fd,4);
  12527. int textlen = RFIFOW(fd,2) - 4;
  12528. char *name, *message;
  12529. int namelen, messagelen;
  12530. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12531. return;
  12532. if( is_atcommand(fd, sd, message, 1) )
  12533. return;
  12534. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12535. return;
  12536. if( battle_config.min_chat_delay )
  12537. {
  12538. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12539. return;
  12540. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12541. }
  12542. bg_send_message(sd, text, textlen);
  12543. }
  12544. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12545. /// 02de <camp A points>.W <camp B points>.W
  12546. void clif_bg_updatescore(int m)
  12547. {
  12548. struct block_list bl;
  12549. unsigned char buf[6];
  12550. bl.id = 0;
  12551. bl.type = BL_NUL;
  12552. bl.m = m;
  12553. WBUFW(buf,0) = 0x2de;
  12554. WBUFW(buf,2) = map[m].bgscore_lion;
  12555. WBUFW(buf,4) = map[m].bgscore_eagle;
  12556. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12557. }
  12558. void clif_bg_updatescore_single(struct map_session_data *sd)
  12559. {
  12560. int fd;
  12561. nullpo_retv(sd);
  12562. fd = sd->fd;
  12563. WFIFOHEAD(fd,packet_len(0x2de));
  12564. WFIFOW(fd,0) = 0x2de;
  12565. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12566. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12567. WFIFOSET(fd,packet_len(0x2de));
  12568. }
  12569. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12570. /// 02dd <account id>.L <name>.24B <camp>.W
  12571. void clif_sendbgemblem_area(struct map_session_data *sd)
  12572. {
  12573. unsigned char buf[33];
  12574. nullpo_retv(sd);
  12575. WBUFW(buf, 0) = 0x2dd;
  12576. WBUFL(buf,2) = sd->bl.id;
  12577. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12578. WBUFW(buf,30) = sd->bg_id;
  12579. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12580. }
  12581. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12582. {
  12583. nullpo_retv(sd);
  12584. WFIFOHEAD(fd,32);
  12585. WFIFOW(fd,0) = 0x2dd;
  12586. WFIFOL(fd,2) = sd->bl.id;
  12587. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12588. WFIFOW(fd,30) = sd->bg_id;
  12589. WFIFOSET(fd,packet_len(0x2dd));
  12590. }
  12591. /// Custom Fonts (ZC_NOTIFY_FONT).
  12592. /// 02ef <account_id>.L <font id>.W
  12593. void clif_font(struct map_session_data *sd)
  12594. {
  12595. #if PACKETVER >= 20080102
  12596. unsigned char buf[8];
  12597. nullpo_retv(sd);
  12598. WBUFW(buf,0) = 0x2ef;
  12599. WBUFL(buf,2) = sd->bl.id;
  12600. WBUFW(buf,6) = sd->user_font;
  12601. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12602. #endif
  12603. }
  12604. /*==========================================
  12605. * Instancing Window
  12606. *------------------------------------------*/
  12607. int clif_instance(int instance_id, int type, int flag)
  12608. {
  12609. struct map_session_data *sd;
  12610. struct party_data *p;
  12611. unsigned char buf[255];
  12612. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12613. return 0;
  12614. switch( type )
  12615. {
  12616. case 1:
  12617. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12618. // Required to start the instancing information window on Client
  12619. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12620. WBUFW(buf,0) = 0x02CB;
  12621. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12622. WBUFW(buf,63) = flag;
  12623. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12624. break;
  12625. case 2:
  12626. // S 0x2cc <Standby Position>.W
  12627. // To announce Instancing queue creation if no maps available
  12628. WBUFW(buf,0) = 0x02CC;
  12629. WBUFW(buf,2) = flag;
  12630. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12631. break;
  12632. case 3:
  12633. case 4:
  12634. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12635. WBUFW(buf,0) = 0x02CD;
  12636. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12637. if( type == 3 )
  12638. {
  12639. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12640. WBUFL(buf,67) = 0;
  12641. }
  12642. else
  12643. {
  12644. WBUFL(buf,63) = 0;
  12645. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12646. }
  12647. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12648. break;
  12649. case 5:
  12650. // S 0x2ce <Message ID>.L
  12651. // 0 = Notification (EnterLimitDate update?)
  12652. // 1 = The Memorial Dungeon expired; it has been destroyed
  12653. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12654. // 3 = The Memorial Dungeon has been removed.
  12655. // 4 = Create failure (removes the instance window)
  12656. WBUFW(buf,0) = 0x02CE;
  12657. WBUFL(buf,2) = flag;
  12658. //WBUFL(buf,6) = EnterLimitDate;
  12659. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12660. break;
  12661. }
  12662. return 0;
  12663. }
  12664. void clif_instance_join(int fd, int instance_id)
  12665. {
  12666. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12667. {
  12668. WFIFOHEAD(fd,packet_len(0x02CD));
  12669. WFIFOW(fd,0) = 0x02CD;
  12670. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12671. WFIFOL(fd,63) = 0;
  12672. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12673. WFIFOSET(fd,packet_len(0x02CD));
  12674. }
  12675. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12676. {
  12677. WFIFOHEAD(fd,packet_len(0x02CD));
  12678. WFIFOW(fd,0) = 0x02CD;
  12679. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12680. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12681. WFIFOL(fd,67) = 0;
  12682. WFIFOSET(fd,packet_len(0x02CD));
  12683. }
  12684. else
  12685. {
  12686. WFIFOHEAD(fd,packet_len(0x02CB));
  12687. WFIFOW(fd,0) = 0x02CB;
  12688. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12689. WFIFOW(fd,63) = 0;
  12690. WFIFOSET(fd,packet_len(0x02CB));
  12691. }
  12692. }
  12693. void clif_instance_leave(int fd)
  12694. {
  12695. WFIFOHEAD(fd,packet_len(0x02CE));
  12696. WFIFOW(fd,0) = 0x02ce;
  12697. WFIFOL(fd,2) = 4;
  12698. WFIFOSET(fd,packet_len(0x02CE));
  12699. }
  12700. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12701. /// 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
  12702. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12703. {
  12704. #if PACKETVER >= 20071002
  12705. unsigned char buf[22];
  12706. struct item_data* id = itemdb_search(item_data->nameid);
  12707. WBUFW(buf,0) = 0x2b8;
  12708. WBUFL(buf,2) = sd->status.account_id;
  12709. WBUFW(buf,6) = item_data->nameid;
  12710. WBUFB(buf,8) = item_data->identify;
  12711. WBUFB(buf,9) = item_data->attribute;
  12712. WBUFB(buf,10) = item_data->refine;
  12713. clif_addcards(WBUFP(buf,11), item_data);
  12714. WBUFW(buf,19) = id->equip; // equip location
  12715. WBUFB(buf,21) = itemtype(id->type); // item type
  12716. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12717. #endif
  12718. }
  12719. /// Display gained exp (ZC_NOTIFY_EXP).
  12720. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12721. /// var id:
  12722. /// SP_BASEEXP, SP_JOBEXP
  12723. /// exp type:
  12724. /// 0 = normal exp gain/loss
  12725. /// 1 = quest exp gain/loss
  12726. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12727. {
  12728. int fd;
  12729. nullpo_retv(sd);
  12730. fd = sd->fd;
  12731. WFIFOHEAD(fd, packet_len(0x7f6));
  12732. WFIFOW(fd,0) = 0x7f6;
  12733. WFIFOL(fd,2) = sd->bl.id;
  12734. WFIFOL(fd,6) = exp;
  12735. WFIFOW(fd,10) = type;
  12736. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12737. WFIFOSET(fd,packet_len(0x7f6));
  12738. }
  12739. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12740. /// type:
  12741. /// 0 = Displays 'value' for 5 seconds.
  12742. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12743. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12744. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12745. /// value:
  12746. /// 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).
  12747. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12748. {
  12749. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12750. WFIFOW(sd->fd,0) = 0x1b1;
  12751. WFIFOB(sd->fd,2) = type;
  12752. WFIFOL(sd->fd,3) = value;
  12753. WFIFOSET(sd->fd, packet_len(0x1b1));
  12754. }
  12755. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12756. /// 021d <state>.L
  12757. /// state:
  12758. /// 0 = Full effects
  12759. /// 1 = Reduced effects
  12760. ///
  12761. /// NOTE: The state is used on Aegis for sending skill unit packet
  12762. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12763. /// whenever possible. Due to the way the decision check is
  12764. /// constructed, this state tracking was rendered useless,
  12765. /// as the only skill unit, that is sent with 0x1c9 is
  12766. /// Graffiti.
  12767. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12768. {
  12769. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12770. sd->state.lesseffect = ( isLess != 0 );
  12771. }
  12772. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12773. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12774. int n = (RFIFOW(fd,2)-12) / 4;
  12775. int type = RFIFOL(fd,4);
  12776. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12777. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12778. if( sd->state.trading || sd->npc_shopid )
  12779. return;
  12780. if( flag == 0 || n == 0) {
  12781. clif_menuskill_clear(sd);
  12782. return; // Canceled by player.
  12783. }
  12784. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12785. clif_menuskill_clear(sd);
  12786. return; // Prevent hacking.
  12787. }
  12788. switch( type ) {
  12789. case 0: // Change Material
  12790. skill_changematerial(sd,n,item_list);
  12791. break;
  12792. case 1: // Level 1: Pure to Rough
  12793. case 2: // Level 2: Rough to Pure
  12794. skill_elementalanalysis(sd,n,type,item_list);
  12795. break;
  12796. }
  12797. clif_menuskill_clear(sd);
  12798. return;
  12799. }
  12800. /*==========================================
  12801. * Elemental System
  12802. *==========================================*/
  12803. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  12804. struct elemental_data *ed;
  12805. struct status_data *status;
  12806. int fd;
  12807. if( sd == NULL || (ed = sd->ed) == NULL )
  12808. return;
  12809. fd = sd->fd;
  12810. status = &ed->battle_status;
  12811. WFIFOHEAD(fd,8);
  12812. WFIFOW(fd,0) = 0x81e;
  12813. WFIFOW(fd,2) = type;
  12814. switch( type ) {
  12815. case SP_HP:
  12816. WFIFOL(fd,4) = status->hp;
  12817. break;
  12818. case SP_MAXHP:
  12819. WFIFOL(fd,4) = status->max_hp;
  12820. break;
  12821. case SP_SP:
  12822. WFIFOL(fd,4) = status->sp;
  12823. break;
  12824. case SP_MAXSP:
  12825. WFIFOL(fd,4) = status->max_sp;
  12826. break;
  12827. }
  12828. WFIFOSET(fd,8);
  12829. }
  12830. void clif_elemental_info(struct map_session_data *sd) {
  12831. int fd;
  12832. struct elemental_data *ed;
  12833. struct status_data *status;
  12834. if( sd == NULL || (ed = sd->ed) == NULL )
  12835. return;
  12836. fd = sd->fd;
  12837. status = &ed->battle_status;
  12838. WFIFOHEAD(fd,22);
  12839. WFIFOW(fd, 0) = 0x81d;
  12840. WFIFOL(fd, 2) = ed->bl.id;
  12841. WFIFOL(fd, 6) = status->hp;
  12842. WFIFOL(fd,10) = status->max_hp;
  12843. WFIFOL(fd,14) = status->sp;
  12844. WFIFOL(fd,18) = status->max_sp;
  12845. WFIFOSET(fd,22);
  12846. }
  12847. /// Buying Store System
  12848. ///
  12849. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12850. /// 0810 <slots>.B
  12851. void clif_buyingstore_open(struct map_session_data* sd)
  12852. {
  12853. int fd = sd->fd;
  12854. WFIFOHEAD(fd,packet_len(0x810));
  12855. WFIFOW(fd,0) = 0x810;
  12856. WFIFOB(fd,2) = sd->buyingstore.slots;
  12857. WFIFOSET(fd,packet_len(0x810));
  12858. }
  12859. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12860. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12861. /// result:
  12862. /// 0 = cancel
  12863. /// 1 = open
  12864. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12865. {
  12866. const unsigned int blocksize = 8;
  12867. uint8* itemlist;
  12868. char storename[MESSAGE_SIZE];
  12869. unsigned char result;
  12870. int zenylimit;
  12871. unsigned int count, packet_len;
  12872. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12873. packet_len = RFIFOW(fd,info->pos[0]);
  12874. // TODO: Make this check global for all variable length packets.
  12875. if( packet_len < 89 )
  12876. {// minimum packet length
  12877. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12878. return;
  12879. }
  12880. zenylimit = RFIFOL(fd,info->pos[1]);
  12881. result = RFIFOL(fd,info->pos[2]);
  12882. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12883. itemlist = RFIFOP(fd,info->pos[4]);
  12884. // so that buyingstore_create knows, how many elements it has access to
  12885. packet_len-= info->pos[4];
  12886. if( packet_len%blocksize )
  12887. {
  12888. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12889. return;
  12890. }
  12891. count = packet_len/blocksize;
  12892. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  12893. }
  12894. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  12895. /// 0812 <result>.W <total weight>.L
  12896. /// result:
  12897. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  12898. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  12899. /// 8 = "No sale (purchase) information available." (0x705)
  12900. /// ? = nothing
  12901. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  12902. {
  12903. int fd = sd->fd;
  12904. WFIFOHEAD(fd,packet_len(0x812));
  12905. WFIFOW(fd,0) = 0x812;
  12906. WFIFOW(fd,2) = result;
  12907. WFIFOL(fd,4) = weight;
  12908. WFIFOSET(fd,packet_len(0x812));
  12909. }
  12910. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  12911. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  12912. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  12913. {
  12914. int fd = sd->fd;
  12915. unsigned int i;
  12916. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  12917. WFIFOW(fd,0) = 0x813;
  12918. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  12919. WFIFOL(fd,4) = sd->bl.id;
  12920. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  12921. for( i = 0; i < sd->buyingstore.slots; i++ )
  12922. {
  12923. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  12924. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  12925. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  12926. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  12927. }
  12928. WFIFOSET(fd,WFIFOW(fd,2));
  12929. }
  12930. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  12931. /// 0814 <account id>.L <store name>.80B
  12932. void clif_buyingstore_entry(struct map_session_data* sd)
  12933. {
  12934. uint8 buf[86];
  12935. WBUFW(buf,0) = 0x814;
  12936. WBUFL(buf,2) = sd->bl.id;
  12937. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  12938. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  12939. }
  12940. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12941. {
  12942. int fd = sd->fd;
  12943. WFIFOHEAD(fd,packet_len(0x814));
  12944. WFIFOW(fd,0) = 0x814;
  12945. WFIFOL(fd,2) = pl_sd->bl.id;
  12946. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  12947. WFIFOSET(fd,packet_len(0x814));
  12948. }
  12949. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  12950. /// 0815
  12951. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  12952. {
  12953. buyingstore_close(sd);
  12954. }
  12955. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  12956. /// 0816 <account id>.L
  12957. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  12958. {
  12959. uint8 buf[6];
  12960. WBUFW(buf,0) = 0x816;
  12961. WBUFL(buf,2) = sd->bl.id;
  12962. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  12963. }
  12964. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12965. {
  12966. int fd = sd->fd;
  12967. WFIFOHEAD(fd,packet_len(0x816));
  12968. WFIFOW(fd,0) = 0x816;
  12969. WFIFOL(fd,2) = pl_sd->bl.id;
  12970. WFIFOSET(fd,packet_len(0x816));
  12971. }
  12972. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  12973. /// 0817 <account id>.L
  12974. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  12975. {
  12976. int account_id;
  12977. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12978. buyingstore_open(sd, account_id);
  12979. }
  12980. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  12981. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  12982. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  12983. {
  12984. int fd = sd->fd;
  12985. unsigned int i;
  12986. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  12987. WFIFOW(fd,0) = 0x818;
  12988. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  12989. WFIFOL(fd,4) = pl_sd->bl.id;
  12990. WFIFOL(fd,8) = pl_sd->buyer_id;
  12991. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  12992. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  12993. {
  12994. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  12995. 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.
  12996. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  12997. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  12998. }
  12999. WFIFOSET(fd,WFIFOW(fd,2));
  13000. }
  13001. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13002. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13003. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13004. {
  13005. const unsigned int blocksize = 6;
  13006. uint8* itemlist;
  13007. int account_id;
  13008. unsigned int count, packet_len, buyer_id;
  13009. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13010. packet_len = RFIFOW(fd,info->pos[0]);
  13011. if( packet_len < 12 )
  13012. {// minimum packet length
  13013. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13014. return;
  13015. }
  13016. account_id = RFIFOL(fd,info->pos[1]);
  13017. buyer_id = RFIFOL(fd,info->pos[2]);
  13018. itemlist = RFIFOP(fd,info->pos[3]);
  13019. // so that buyingstore_trade knows, how many elements it has access to
  13020. packet_len-= info->pos[3];
  13021. if( packet_len%blocksize )
  13022. {
  13023. 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);
  13024. return;
  13025. }
  13026. count = packet_len/blocksize;
  13027. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13028. }
  13029. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13030. /// 081a <result>.W
  13031. /// result:
  13032. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13033. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13034. /// ? = nothing
  13035. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13036. {
  13037. int fd = sd->fd;
  13038. WFIFOHEAD(fd,packet_len(0x81a));
  13039. WFIFOW(fd,0) = 0x81a;
  13040. WFIFOW(fd,2) = result;
  13041. WFIFOSET(fd,packet_len(0x81a));
  13042. }
  13043. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13044. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13045. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13046. {
  13047. int fd = sd->fd;
  13048. WFIFOHEAD(fd,packet_len(0x81b));
  13049. WFIFOW(fd,0) = 0x81b;
  13050. WFIFOW(fd,2) = nameid;
  13051. WFIFOW(fd,4) = amount; // amount of nameid received
  13052. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  13053. WFIFOSET(fd,packet_len(0x81b));
  13054. }
  13055. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13056. /// 081c <index>.W <amount>.W <price>.L
  13057. /// message:
  13058. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13059. ///
  13060. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13061. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13062. {
  13063. int fd = sd->fd;
  13064. WFIFOHEAD(fd,packet_len(0x81c));
  13065. WFIFOW(fd,0) = 0x81c;
  13066. WFIFOW(fd,2) = index+2;
  13067. WFIFOW(fd,4) = amount;
  13068. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13069. WFIFOSET(fd,packet_len(0x81c));
  13070. }
  13071. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13072. /// 0824 <result>.W <name id>.W
  13073. /// result:
  13074. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13075. /// 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)
  13076. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13077. /// ? = nothing
  13078. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13079. {
  13080. int fd = sd->fd;
  13081. WFIFOHEAD(fd,packet_len(0x824));
  13082. WFIFOW(fd,0) = 0x824;
  13083. WFIFOW(fd,2) = result;
  13084. WFIFOW(fd,4) = nameid;
  13085. WFIFOSET(fd,packet_len(0x824));
  13086. }
  13087. /// Search Store Info System
  13088. ///
  13089. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13090. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13091. /// type:
  13092. /// 0 = Vending
  13093. /// 1 = Buying Store
  13094. ///
  13095. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13096. /// amount of card slots. If the client does not know about the item it
  13097. /// cannot be searched.
  13098. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13099. {
  13100. const unsigned int blocksize = 2;
  13101. const uint8* itemlist;
  13102. const uint8* cardlist;
  13103. unsigned char type;
  13104. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13105. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13106. packet_len = RFIFOW(fd,info->pos[0]);
  13107. if( packet_len < 15 )
  13108. {// minimum packet length
  13109. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13110. return;
  13111. }
  13112. type = RFIFOB(fd,info->pos[1]);
  13113. max_price = RFIFOL(fd,info->pos[2]);
  13114. min_price = RFIFOL(fd,info->pos[3]);
  13115. item_count = RFIFOB(fd,info->pos[4]);
  13116. card_count = RFIFOB(fd,info->pos[5]);
  13117. itemlist = RFIFOP(fd,info->pos[6]);
  13118. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13119. // check, if there is enough data for the claimed count of items
  13120. packet_len-= info->pos[6];
  13121. if( packet_len%blocksize )
  13122. {
  13123. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13124. return;
  13125. }
  13126. count = packet_len/blocksize;
  13127. if( count < item_count+card_count )
  13128. {
  13129. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13130. return;
  13131. }
  13132. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13133. }
  13134. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13135. /// 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 }*
  13136. /// is first page:
  13137. /// 0 = appends to existing results
  13138. /// 1 = clears previous results before displaying this result set
  13139. /// is next page:
  13140. /// 0 = no "next" label
  13141. /// 1 = "next" label to retrieve more results
  13142. void clif_search_store_info_ack(struct map_session_data* sd)
  13143. {
  13144. const unsigned int blocksize = MESSAGE_SIZE+26;
  13145. int fd = sd->fd;
  13146. unsigned int i, start, end;
  13147. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13148. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13149. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13150. WFIFOW(fd,0) = 0x836;
  13151. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13152. WFIFOB(fd,4) = !sd->searchstore.pages;
  13153. WFIFOB(fd,5) = searchstore_querynext(sd);
  13154. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13155. for( i = start; i < end; i++ )
  13156. {
  13157. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13158. struct item it;
  13159. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13160. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13161. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13162. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13163. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13164. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13165. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13166. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13167. // make-up an item for clif_addcards
  13168. memset(&it, 0, sizeof(it));
  13169. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13170. it.nameid = ssitem->nameid;
  13171. it.amount = ssitem->amount;
  13172. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13173. }
  13174. WFIFOSET(fd,WFIFOW(fd,2));
  13175. }
  13176. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13177. /// 0837 <reason>.B
  13178. /// reason:
  13179. /// 0 = "No matching stores were found." (0x70b)
  13180. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13181. /// 2 = "You cannot search anymore." (0x706)
  13182. /// 3 = "You cannot search yet." (0x708)
  13183. /// 4 = "No sale (purchase) information available." (0x705)
  13184. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13185. {
  13186. int fd = sd->fd;
  13187. WFIFOHEAD(fd,packet_len(0x837));
  13188. WFIFOW(fd,0) = 0x837;
  13189. WFIFOB(fd,2) = reason;
  13190. WFIFOSET(fd,packet_len(0x837));
  13191. }
  13192. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13193. /// 0838
  13194. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13195. {
  13196. searchstore_next(sd);
  13197. }
  13198. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13199. /// 083a <type>.W <remaining uses>.B
  13200. /// type:
  13201. /// 0 = Search Stores
  13202. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13203. void clif_open_search_store_info(struct map_session_data* sd)
  13204. {
  13205. int fd = sd->fd;
  13206. WFIFOHEAD(fd,packet_len(0x83a));
  13207. WFIFOW(fd,0) = 0x83a;
  13208. WFIFOW(fd,2) = sd->searchstore.effect;
  13209. #if PACKETVER > 20100701
  13210. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13211. #endif
  13212. WFIFOSET(fd,packet_len(0x83a));
  13213. }
  13214. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13215. /// 083b
  13216. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13217. {
  13218. searchstore_close(sd);
  13219. }
  13220. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13221. /// 083c <account id>.L <store id>.L <nameid>.W
  13222. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13223. {
  13224. unsigned short nameid;
  13225. int account_id, store_id;
  13226. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13227. account_id = RFIFOL(fd,info->pos[0]);
  13228. store_id = RFIFOL(fd,info->pos[1]);
  13229. nameid = RFIFOW(fd,info->pos[2]);
  13230. searchstore_click(sd, account_id, store_id, nameid);
  13231. }
  13232. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13233. /// 083d <xPos>.W <yPos>.W
  13234. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13235. {
  13236. int fd = sd->fd;
  13237. WFIFOHEAD(fd,packet_len(0x83d));
  13238. WFIFOW(fd,0) = 0x83d;
  13239. WFIFOW(fd,2) = x;
  13240. WFIFOW(fd,4) = y;
  13241. WFIFOSET(fd,packet_len(0x83d));
  13242. }
  13243. /// Parse function for packet debugging.
  13244. void clif_parse_debug(int fd,struct map_session_data *sd)
  13245. {
  13246. int cmd, packet_len;
  13247. // clif_parse ensures, that there is at least 2 bytes of data
  13248. cmd = RFIFOW(fd,0);
  13249. if( sd )
  13250. {
  13251. packet_len = packet_db[sd->packet_ver][cmd].len;
  13252. if( packet_len == 0 )
  13253. {// unknown
  13254. packet_len = RFIFOREST(fd);
  13255. }
  13256. else if( packet_len == -1 )
  13257. {// variable length
  13258. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13259. }
  13260. 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);
  13261. }
  13262. else
  13263. {
  13264. packet_len = RFIFOREST(fd);
  13265. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13266. }
  13267. ShowDump(RFIFOP(fd,0), packet_len);
  13268. }
  13269. /*==========================================
  13270. * Server tells client to display a window similar to Magnifier (item) one
  13271. * Server populates the window with avilable elemental converter options according to player's inventory
  13272. *------------------------------------------*/
  13273. int clif_elementalconverter_list(struct map_session_data *sd) {
  13274. int i,c,view,fd;
  13275. nullpo_ret(sd);
  13276. /// Main client packet processing function
  13277. fd=sd->fd;
  13278. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13279. WFIFOW(fd, 0)=0x1ad;
  13280. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13281. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13282. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13283. WFIFOW(fd,c*2+ 4)= view;
  13284. else
  13285. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13286. c++;
  13287. }
  13288. }
  13289. WFIFOW(fd,2) = c*2+4;
  13290. WFIFOSET(fd, WFIFOW(fd,2));
  13291. if (c > 0) {
  13292. sd->menuskill_id = SA_CREATECON;
  13293. sd->menuskill_val = c;
  13294. }
  13295. return 0;
  13296. }
  13297. /**
  13298. * Rune Knight
  13299. **/
  13300. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13301. #if PACKETVER >= 20081217
  13302. unsigned char buf[10];
  13303. WBUFW(buf,0) = 0x440;
  13304. WBUFL(buf,2) = sd->bl.id;
  13305. WBUFW(buf,6) = shields;
  13306. WBUFW(buf,8) = 0;
  13307. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13308. #endif
  13309. }
  13310. /**
  13311. * Warlock
  13312. **/
  13313. /*==========================================
  13314. * Spellbook list [LimitLine/3CeAM]
  13315. *------------------------------------------*/
  13316. int clif_spellbook_list(struct map_session_data *sd)
  13317. {
  13318. int i, c;
  13319. int fd;
  13320. nullpo_ret(sd);
  13321. fd = sd->fd;
  13322. WFIFOHEAD(fd, 8 * 8 + 8);
  13323. WFIFOW(fd,0) = 0x1ad;
  13324. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13325. {
  13326. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13327. {
  13328. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13329. c ++;
  13330. }
  13331. }
  13332. if( c > 0 )
  13333. {
  13334. WFIFOW(fd,2) = c * 2 + 4;
  13335. WFIFOSET(fd, WFIFOW(fd, 2));
  13336. sd->menuskill_id = WL_READING_SB;
  13337. sd->menuskill_val = c;
  13338. }
  13339. else
  13340. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13341. return 1;
  13342. }
  13343. /**
  13344. * Mechanic
  13345. **/
  13346. /*==========================================
  13347. * Magic Decoy Material List
  13348. *------------------------------------------*/
  13349. int clif_magicdecoy_list(struct map_session_data *sd, int skill_lv, short x, short y) {
  13350. int i, c;
  13351. int fd;
  13352. nullpo_ret(sd);
  13353. fd = sd->fd;
  13354. WFIFOHEAD(fd, 8 * 8 + 8);
  13355. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13356. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13357. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13358. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13359. c ++;
  13360. }
  13361. }
  13362. if( c > 0 ) {
  13363. sd->menuskill_id = NC_MAGICDECOY;
  13364. sd->menuskill_val = skill_lv;
  13365. sd->sc.comet_x = x;
  13366. sd->sc.comet_y = y;
  13367. WFIFOW(fd,2) = c * 2 + 4;
  13368. WFIFOSET(fd, WFIFOW(fd, 2));
  13369. } else {
  13370. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13371. return 0;
  13372. }
  13373. return 1;
  13374. }
  13375. /**
  13376. * Guilotine Cross
  13377. **/
  13378. /*==========================================
  13379. * Guillotine Cross Poisons List
  13380. *------------------------------------------*/
  13381. int clif_poison_list(struct map_session_data *sd, int skill_lv) {
  13382. int i, c;
  13383. int fd;
  13384. nullpo_ret(sd);
  13385. fd = sd->fd;
  13386. WFIFOHEAD(fd, 8 * 8 + 8);
  13387. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13388. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13389. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13390. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13391. c ++;
  13392. }
  13393. }
  13394. if( c > 0 ) {
  13395. sd->menuskill_id = GC_POISONINGWEAPON;
  13396. sd->menuskill_val = skill_lv;
  13397. WFIFOW(fd,2) = c * 2 + 4;
  13398. WFIFOSET(fd, WFIFOW(fd, 2));
  13399. } else {
  13400. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13401. return 0;
  13402. }
  13403. return 1;
  13404. }
  13405. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13406. int fd, i, c;
  13407. nullpo_ret(sd);
  13408. fd = sd->fd;
  13409. if( !fd ) return 0;
  13410. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13411. return 0;
  13412. WFIFOHEAD(fd, 2 * 6 + 4);
  13413. WFIFOW(fd,0) = 0x442;
  13414. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13415. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13416. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13417. { // Can't auto cast both Extended class and 3rd class skills.
  13418. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13419. c++;
  13420. }
  13421. if( c > 0 ) {
  13422. WFIFOW(fd,2) = 8 + c * 2;
  13423. WFIFOL(fd,4) = c;
  13424. WFIFOSET(fd,WFIFOW(fd,2));
  13425. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13426. sd->menuskill_val = c;
  13427. } else {
  13428. status_change_end(&sd->bl,SC_STOP,-1);
  13429. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13430. }
  13431. return 1;
  13432. }
  13433. /*===========================================
  13434. * Skill list for Four Elemental Analysis
  13435. * and Change Material skills.
  13436. *------------------------------------------*/
  13437. int clif_skill_itemlistwindow( struct map_session_data *sd, int skill_id, int skill_lv )
  13438. {
  13439. #if PACKETVER >= 20090922
  13440. int fd;
  13441. nullpo_ret(sd);
  13442. sd->menuskill_id = skill_id; // To prevent hacking.
  13443. sd->menuskill_val = skill_lv;
  13444. if( skill_id == GN_CHANGEMATERIAL )
  13445. skill_lv = 0; // Changematerial
  13446. fd = sd->fd;
  13447. WFIFOHEAD(fd,packet_len(0x7e3));
  13448. WFIFOW(fd,0) = 0x7e3;
  13449. WFIFOL(fd,2) = skill_lv;
  13450. WFIFOL(fd,4) = 0;
  13451. WFIFOSET(fd,packet_len(0x7e3));
  13452. #endif
  13453. return 1;
  13454. }
  13455. /**
  13456. * Sends a new status without a tick (currently used by the new mounts)
  13457. **/
  13458. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13459. unsigned char buf[32];
  13460. nullpo_ret(bl);
  13461. WBUFW(buf,0)=0x043f;
  13462. WBUFW(buf,2)=type;
  13463. WBUFL(buf,4)=bl->id;
  13464. WBUFB(buf,8)=flag;
  13465. WBUFL(buf,9) = 0;
  13466. WBUFL(buf,13) = val1;
  13467. WBUFL(buf,17) = val2;
  13468. WBUFL(buf,21) = val3;
  13469. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  13470. return 0;
  13471. }
  13472. //Notifies FD of ID's type
  13473. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13474. WFIFOHEAD(fd, packet_len(0x043f));
  13475. WFIFOW(fd,0)=0x043f;
  13476. WFIFOW(fd,2)=type;
  13477. WFIFOL(fd,4)=id;
  13478. WFIFOB(fd,8)=flag;
  13479. WFIFOL(fd,9) = 0;
  13480. WFIFOL(fd,13) = val1;
  13481. WFIFOL(fd,17) = val2;
  13482. WFIFOL(fd,21) = val3;
  13483. WFIFOSET(fd, packet_len(0x043f));
  13484. return 0;
  13485. }
  13486. // msgstringtable.txt
  13487. // 0x291 <line>.W
  13488. void clif_msgtable(int fd, int line) {
  13489. WFIFOHEAD(fd, packet_len(0x291));
  13490. WFIFOW(fd, 0) = 0x291;
  13491. WFIFOW(fd, 2) = line;
  13492. WFIFOSET(fd, packet_len(0x291));
  13493. }
  13494. // msgstringtable.txt
  13495. // 0x7e2 <line>.W <value>.L
  13496. void clif_msgtable_num(int fd, int line, int num) {
  13497. #if PACKETVER >= 20090805
  13498. WFIFOHEAD(fd, packet_len(0x7e2));
  13499. WFIFOW(fd, 0) = 0x7e2;
  13500. WFIFOW(fd, 2) = line;
  13501. WFIFOL(fd, 4) = num;
  13502. WFIFOSET(fd, packet_len(0x7e2));
  13503. #endif
  13504. }
  13505. /*==========================================
  13506. * used by SC_AUTOSHADOWSPELL
  13507. *------------------------------------------*/
  13508. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13509. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13510. return;
  13511. if( pc_istrading(sd) ) {
  13512. clif_skill_fail(sd,sd->ud.skillid,0,0);
  13513. clif_menuskill_clear(sd);
  13514. return;
  13515. }
  13516. skill_select_menu(sd,RFIFOL(fd,2),RFIFOW(fd,6));
  13517. clif_menuskill_clear(sd);
  13518. }
  13519. /*==========================================
  13520. * Main client packet processing function
  13521. *------------------------------------------*/
  13522. static int clif_parse(int fd)
  13523. {
  13524. int cmd, packet_ver, packet_len, err;
  13525. TBL_PC* sd;
  13526. int pnum;
  13527. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13528. // Note: "click masters" can do 80+ clicks in 10 seconds
  13529. 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]
  13530. { // begin main client packet processing loop
  13531. sd = (TBL_PC *)session[fd]->session_data;
  13532. if (session[fd]->flag.eof) {
  13533. if (sd) {
  13534. if (sd->state.autotrade) {
  13535. //Disassociate character from the socket connection.
  13536. session[fd]->session_data = NULL;
  13537. sd->fd = 0;
  13538. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13539. } else
  13540. if (sd->state.active) {
  13541. // Player logout display [Valaris]
  13542. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13543. clif_quitsave(fd, sd);
  13544. } else {
  13545. //Unusual logout (during log on/off/map-changer procedure)
  13546. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13547. map_quit(sd);
  13548. }
  13549. } else {
  13550. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13551. }
  13552. do_close(fd);
  13553. return 0;
  13554. }
  13555. if (RFIFOREST(fd) < 2)
  13556. return 0;
  13557. cmd = RFIFOW(fd,0);
  13558. // identify client's packet version
  13559. if (sd) {
  13560. packet_ver = sd->packet_ver;
  13561. } else {
  13562. // check authentification packet to know packet version
  13563. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13564. if( err )
  13565. {// failed to identify packet version
  13566. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  13567. err == 1 ? "" :
  13568. err == 2 ? ", possibly for having an invalid account_id" :
  13569. err == 3 ? ", possibly for having an invalid char_id." :
  13570. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13571. err == 4 ? ", possibly for having an invalid login_id1." :
  13572. err == 5 ? ", possibly for having an invalid client_tick." :
  13573. */
  13574. err == 6 ? ", possibly for having an invalid sex." :
  13575. ". ERROR invalid error code"));
  13576. WFIFOHEAD(fd,packet_len(0x6a));
  13577. WFIFOW(fd,0) = 0x6a;
  13578. WFIFOB(fd,2) = 3; // Rejected from Server
  13579. WFIFOSET(fd,packet_len(0x6a));
  13580. #ifdef DUMP_INVALID_PACKET
  13581. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13582. #endif
  13583. RFIFOSKIP(fd, RFIFOREST(fd));
  13584. set_eof(fd);
  13585. return 0;
  13586. }
  13587. }
  13588. // filter out invalid / unsupported packets
  13589. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13590. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13591. #ifdef DUMP_INVALID_PACKET
  13592. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13593. #endif
  13594. set_eof(fd);
  13595. return 0;
  13596. }
  13597. // determine real packet length
  13598. packet_len = packet_db[packet_ver][cmd].len;
  13599. if (packet_len == -1) { // variable-length packet
  13600. if (RFIFOREST(fd) < 4)
  13601. return 0;
  13602. packet_len = RFIFOW(fd,2);
  13603. if (packet_len < 4 || packet_len > 32768) {
  13604. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13605. #ifdef DUMP_INVALID_PACKET
  13606. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13607. #endif
  13608. set_eof(fd);
  13609. return 0;
  13610. }
  13611. }
  13612. if ((int)RFIFOREST(fd) < packet_len)
  13613. return 0; // not enough data received to form the packet
  13614. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13615. packet_db[packet_ver][cmd].func(fd, sd);
  13616. else
  13617. if( packet_db[packet_ver][cmd].func != NULL )
  13618. {
  13619. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13620. ; //Only valid packet when there is no session
  13621. else
  13622. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13623. ; //Only valid packet when player is not on a map
  13624. else
  13625. if( sd && session[sd->fd]->flag.eof )
  13626. ; //No more packets accepted
  13627. else
  13628. packet_db[packet_ver][cmd].func(fd, sd);
  13629. }
  13630. #ifdef DUMP_UNKNOWN_PACKET
  13631. else
  13632. {
  13633. const char* packet_txt = "save/packet.txt";
  13634. FILE* fp;
  13635. if((fp = fopen(packet_txt, "a"))!=NULL)
  13636. {
  13637. if( sd )
  13638. {
  13639. 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);
  13640. }
  13641. else
  13642. {
  13643. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13644. }
  13645. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13646. fprintf(fp, "\n");
  13647. fclose(fp);
  13648. }
  13649. else
  13650. {
  13651. ShowError("Failed to write '%s'.\n", packet_txt);
  13652. // Dump on console instead
  13653. if( sd )
  13654. {
  13655. 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);
  13656. }
  13657. else
  13658. {
  13659. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13660. }
  13661. ShowDump(RFIFOP(fd,0), packet_len);
  13662. }
  13663. }
  13664. #endif
  13665. RFIFOSKIP(fd, packet_len);
  13666. }; // main loop end
  13667. return 0;
  13668. }
  13669. /*==========================================
  13670. * Reads packet_db.txt and setups its array reference
  13671. *------------------------------------------*/
  13672. static int packetdb_readdb(void)
  13673. {
  13674. FILE *fp;
  13675. char line[1024];
  13676. int ln=0;
  13677. int cmd,i,j,packet_ver;
  13678. int max_cmd=-1;
  13679. int skip_ver = 0;
  13680. int warned = 0;
  13681. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13682. int packet_len_table[MAX_PACKET_DB] = {
  13683. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13687. //#0x0040
  13688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13690. #if PACKETVER <= 20081217
  13691. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13692. #else
  13693. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13694. #endif
  13695. #if PACKETVER < 2
  13696. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13697. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  13698. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13699. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13700. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13701. #else
  13702. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13703. #endif
  13704. //#0x0080
  13705. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13706. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13707. #if PACKETVER <= 20100622
  13708. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13709. #else
  13710. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13711. #endif
  13712. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13713. //#0x00C0
  13714. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13715. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13716. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13717. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13718. //#0x0100
  13719. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13720. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13721. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13722. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13723. //#0x0140
  13724. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13725. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13726. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13727. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13728. //#0x0180
  13729. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13730. #if PACKETVER < 1
  13731. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13732. #else // 196 comodo以降 状態表示アイコン用
  13733. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13734. #endif
  13735. #if PACKETVER < 20081126
  13736. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13737. #else // 0x1a2 changed (35->37)
  13738. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13739. #endif
  13740. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13741. //#0x01C0, Set 0x1d5=-1
  13742. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13743. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13744. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13745. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13746. //#0x0200
  13747. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13748. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13749. #if PACKETVER < 20071106
  13750. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13751. #else // 0x22c changed
  13752. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13753. #endif
  13754. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13755. //#0x0240
  13756. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13757. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13758. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13759. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13760. //#0x0280
  13761. #if PACKETVER < 20070711
  13762. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  13763. #else
  13764. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13765. #endif
  13766. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  13767. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13768. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
  13769. //#0x02C0
  13770. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13771. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  13772. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  13773. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13774. //#0x0300
  13775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13779. //#0x0340
  13780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13784. //#0x0380
  13785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13789. //#0x03C0
  13790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13794. //#0x0400
  13795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  13799. //#0x0440
  13800. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  13801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13804. //#0x0480
  13805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13809. //#0x04C0
  13810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13814. //#0x0500
  13815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13819. //#0x0540
  13820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13824. //#0x0580
  13825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13829. //#0x05C0
  13830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13834. //#0x0600
  13835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13839. //#0x0640
  13840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13844. //#0x0680
  13845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13849. //#0x06C0
  13850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13854. //#0x0700
  13855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13859. //#0x0740
  13860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13864. //#0x0780
  13865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13869. //#0x07C0
  13870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13871. #if PACKETVER < 20090617
  13872. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  13873. #else // 0x7d9 changed
  13874. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  13875. #endif
  13876. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  13877. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  13878. //#0x0800
  13879. #if PACKETVER < 20091229
  13880. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  13881. #else // for Party booking ( PACKETVER >= 20091229 )
  13882. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  13883. #endif
  13884. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  13885. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13886. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  13887. //#0x0840
  13888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13889. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  13890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13892. };
  13893. struct {
  13894. void (*func)(int, struct map_session_data *);
  13895. char *name;
  13896. } clif_parse_func[]={
  13897. {clif_parse_WantToConnection,"wanttoconnection"},
  13898. {clif_parse_LoadEndAck,"loadendack"},
  13899. {clif_parse_TickSend,"ticksend"},
  13900. {clif_parse_WalkToXY,"walktoxy"},
  13901. {clif_parse_QuitGame,"quitgame"},
  13902. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  13903. {clif_parse_GlobalMessage,"globalmessage"},
  13904. {clif_parse_MapMove,"mapmove"},
  13905. {clif_parse_ChangeDir,"changedir"},
  13906. {clif_parse_Emotion,"emotion"},
  13907. {clif_parse_HowManyConnections,"howmanyconnections"},
  13908. {clif_parse_ActionRequest,"actionrequest"},
  13909. {clif_parse_Restart,"restart"},
  13910. {clif_parse_WisMessage,"wis"},
  13911. {clif_parse_Broadcast,"broadcast"},
  13912. {clif_parse_TakeItem,"takeitem"},
  13913. {clif_parse_DropItem,"dropitem"},
  13914. {clif_parse_UseItem,"useitem"},
  13915. {clif_parse_EquipItem,"equipitem"},
  13916. {clif_parse_UnequipItem,"unequipitem"},
  13917. {clif_parse_NpcClicked,"npcclicked"},
  13918. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  13919. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  13920. {clif_parse_NpcSellListSend,"npcselllistsend"},
  13921. {clif_parse_CreateChatRoom,"createchatroom"},
  13922. {clif_parse_ChatAddMember,"chataddmember"},
  13923. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  13924. {clif_parse_ChangeChatOwner,"changechatowner"},
  13925. {clif_parse_KickFromChat,"kickfromchat"},
  13926. {clif_parse_ChatLeave,"chatleave"},
  13927. {clif_parse_TradeRequest,"traderequest"},
  13928. {clif_parse_TradeAck,"tradeack"},
  13929. {clif_parse_TradeAddItem,"tradeadditem"},
  13930. {clif_parse_TradeOk,"tradeok"},
  13931. {clif_parse_TradeCancel,"tradecancel"},
  13932. {clif_parse_TradeCommit,"tradecommit"},
  13933. {clif_parse_StopAttack,"stopattack"},
  13934. {clif_parse_PutItemToCart,"putitemtocart"},
  13935. {clif_parse_GetItemFromCart,"getitemfromcart"},
  13936. {clif_parse_RemoveOption,"removeoption"},
  13937. {clif_parse_ChangeCart,"changecart"},
  13938. {clif_parse_StatusUp,"statusup"},
  13939. {clif_parse_SkillUp,"skillup"},
  13940. {clif_parse_UseSkillToId,"useskilltoid"},
  13941. {clif_parse_UseSkillToPos,"useskilltopos"},
  13942. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  13943. {clif_parse_UseSkillMap,"useskillmap"},
  13944. {clif_parse_RequestMemo,"requestmemo"},
  13945. {clif_parse_ProduceMix,"producemix"},
  13946. {clif_parse_Cooking,"cooking"},
  13947. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  13948. {clif_parse_NpcNextClicked,"npcnextclicked"},
  13949. {clif_parse_NpcAmountInput,"npcamountinput"},
  13950. {clif_parse_NpcStringInput,"npcstringinput"},
  13951. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  13952. {clif_parse_ItemIdentify,"itemidentify"},
  13953. {clif_parse_SelectArrow,"selectarrow"},
  13954. {clif_parse_AutoSpell,"autospell"},
  13955. {clif_parse_UseCard,"usecard"},
  13956. {clif_parse_InsertCard,"insertcard"},
  13957. {clif_parse_RepairItem,"repairitem"},
  13958. {clif_parse_WeaponRefine,"weaponrefine"},
  13959. {clif_parse_SolveCharName,"solvecharname"},
  13960. {clif_parse_ResetChar,"resetchar"},
  13961. {clif_parse_LocalBroadcast,"localbroadcast"},
  13962. {clif_parse_MoveToKafra,"movetokafra"},
  13963. {clif_parse_MoveFromKafra,"movefromkafra"},
  13964. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  13965. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  13966. {clif_parse_CloseKafra,"closekafra"},
  13967. {clif_parse_CreateParty,"createparty"},
  13968. {clif_parse_CreateParty2,"createparty2"},
  13969. {clif_parse_PartyInvite,"partyinvite"},
  13970. {clif_parse_PartyInvite2,"partyinvite2"},
  13971. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  13972. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  13973. {clif_parse_LeaveParty,"leaveparty"},
  13974. {clif_parse_RemovePartyMember,"removepartymember"},
  13975. {clif_parse_PartyChangeOption,"partychangeoption"},
  13976. {clif_parse_PartyMessage,"partymessage"},
  13977. {clif_parse_PartyChangeLeader,"partychangeleader"},
  13978. {clif_parse_CloseVending,"closevending"},
  13979. {clif_parse_VendingListReq,"vendinglistreq"},
  13980. {clif_parse_PurchaseReq,"purchasereq"},
  13981. {clif_parse_PurchaseReq2,"purchasereq2"},
  13982. {clif_parse_OpenVending,"openvending"},
  13983. {clif_parse_CreateGuild,"createguild"},
  13984. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  13985. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  13986. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  13987. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  13988. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  13989. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  13990. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  13991. {clif_parse_GuildInvite,"guildinvite"},
  13992. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  13993. {clif_parse_GuildLeave,"guildleave"},
  13994. {clif_parse_GuildExpulsion,"guildexpulsion"},
  13995. {clif_parse_GuildMessage,"guildmessage"},
  13996. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  13997. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  13998. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  13999. {clif_parse_GuildOpposition,"guildopposition"},
  14000. {clif_parse_GuildBreak,"guildbreak"},
  14001. {clif_parse_PetMenu,"petmenu"},
  14002. {clif_parse_CatchPet,"catchpet"},
  14003. {clif_parse_SelectEgg,"selectegg"},
  14004. {clif_parse_SendEmotion,"sendemotion"},
  14005. {clif_parse_ChangePetName,"changepetname"},
  14006. {clif_parse_GMKick,"gmkick"},
  14007. {clif_parse_GMHide,"gmhide"},
  14008. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14009. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14010. {clif_parse_GMKickAll,"killall"},
  14011. {clif_parse_GMRecall,"recall"},
  14012. {clif_parse_GMRecall,"summon"},
  14013. {clif_parse_GM_Monster_Item,"itemmonster"},
  14014. {clif_parse_GMShift,"remove"},
  14015. {clif_parse_GMShift,"shift"},
  14016. {clif_parse_GMChangeMapType,"changemaptype"},
  14017. {clif_parse_GMRc,"rc"},
  14018. {clif_parse_GMRecall2,"recall2"},
  14019. {clif_parse_GMRemove2,"remove2"},
  14020. {clif_parse_NoviceDoriDori,"sndoridori"},
  14021. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14022. {clif_parse_PMIgnore,"wisexin"},
  14023. {clif_parse_PMIgnoreList,"wisexlist"},
  14024. {clif_parse_PMIgnoreAll,"wisall"},
  14025. {clif_parse_FriendsListAdd,"friendslistadd"},
  14026. {clif_parse_FriendsListRemove,"friendslistremove"},
  14027. {clif_parse_FriendsListReply,"friendslistreply"},
  14028. {clif_parse_Blacksmith,"blacksmith"},
  14029. {clif_parse_Alchemist,"alchemist"},
  14030. {clif_parse_Taekwon,"taekwon"},
  14031. {clif_parse_RankingPk,"rankingpk"},
  14032. {clif_parse_FeelSaveOk,"feelsaveok"},
  14033. {clif_parse_debug,"debug"},
  14034. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14035. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14036. {clif_parse_HomMoveTo,"hommoveto"},
  14037. {clif_parse_HomAttack,"homattack"},
  14038. {clif_parse_HomMenu,"hommenu"},
  14039. {clif_parse_StoragePassword,"storagepassword"},
  14040. {clif_parse_Hotkey,"hotkey"},
  14041. {clif_parse_AutoRevive,"autorevive"},
  14042. {clif_parse_Check,"check"},
  14043. {clif_parse_Adopt_request,"adoptrequest"},
  14044. {clif_parse_Adopt_reply,"adoptreply"},
  14045. // MAIL SYSTEM
  14046. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14047. {clif_parse_Mail_read,"mailread"},
  14048. {clif_parse_Mail_getattach,"mailgetattach"},
  14049. {clif_parse_Mail_delete,"maildelete"},
  14050. {clif_parse_Mail_return,"mailreturn"},
  14051. {clif_parse_Mail_setattach,"mailsetattach"},
  14052. {clif_parse_Mail_winopen,"mailwinopen"},
  14053. {clif_parse_Mail_send,"mailsend"},
  14054. // AUCTION SYSTEM
  14055. {clif_parse_Auction_search,"auctionsearch"},
  14056. {clif_parse_Auction_buysell,"auctionbuysell"},
  14057. {clif_parse_Auction_setitem,"auctionsetitem"},
  14058. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14059. {clif_parse_Auction_register,"auctionregister"},
  14060. {clif_parse_Auction_cancel,"auctioncancel"},
  14061. {clif_parse_Auction_close,"auctionclose"},
  14062. {clif_parse_Auction_bid,"auctionbid"},
  14063. // Quest Log System
  14064. {clif_parse_questStateAck,"queststate"},
  14065. {clif_parse_cashshop_buy,"cashshopbuy"},
  14066. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14067. {clif_parse_EquipTick,"equiptickbox"},
  14068. {clif_parse_BattleChat,"battlechat"},
  14069. {clif_parse_mercenary_action,"mermenu"},
  14070. {clif_parse_progressbar,"progressbar"},
  14071. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14072. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14073. #if PACKETVER >= 20091229
  14074. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14075. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14076. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14077. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14078. #endif
  14079. {clif_parse_PVPInfo,"pvpinfo"},
  14080. {clif_parse_LessEffect,"lesseffect"},
  14081. // Buying Store
  14082. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14083. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14084. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14085. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14086. // Store Search
  14087. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14088. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14089. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14090. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14091. {NULL,NULL}
  14092. };
  14093. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14094. memset(packet_db,0,sizeof(packet_db));
  14095. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14096. packet_len(i) = packet_len_table[i];
  14097. sprintf(line, "%s/packet_db.txt", db_path);
  14098. if( (fp=fopen(line,"r"))==NULL ){
  14099. ShowFatalError("can't read %s\n", line);
  14100. exit(EXIT_FAILURE);
  14101. }
  14102. clif_config.packet_db_ver = MAX_PACKET_VER;
  14103. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14104. while( fgets(line, sizeof(line), fp) )
  14105. {
  14106. ln++;
  14107. if(line[0]=='/' && line[1]=='/')
  14108. continue;
  14109. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14110. {
  14111. if(strcmpi(w1,"packet_ver")==0) {
  14112. int prev_ver = packet_ver;
  14113. skip_ver = 0;
  14114. packet_ver = atoi(w2);
  14115. if ( packet_ver > MAX_PACKET_VER )
  14116. { //Check to avoid overflowing. [Skotlex]
  14117. if( (warned&1) == 0 )
  14118. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14119. warned &= 1;
  14120. skip_ver = 1;
  14121. }
  14122. else if( packet_ver < 0 )
  14123. {
  14124. if( (warned&2) == 0 )
  14125. ShowWarning("Negative packet versions are not supported.\n");
  14126. warned &= 2;
  14127. skip_ver = 1;
  14128. }
  14129. else if( packet_ver == SERVER )
  14130. {
  14131. if( (warned&4) == 0 )
  14132. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14133. warned &= 4;
  14134. skip_ver = 1;
  14135. }
  14136. if( skip_ver )
  14137. {
  14138. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14139. packet_ver = prev_ver;
  14140. continue;
  14141. }
  14142. // copy from previous version into new version and continue
  14143. // - indicating all following packets should be read into the newer version
  14144. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14145. continue;
  14146. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14147. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14148. clif_config.packet_db_ver = MAX_PACKET_VER;
  14149. else // to manually set the packet DB version
  14150. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14151. continue;
  14152. }
  14153. }
  14154. if( skip_ver != 0 )
  14155. continue; // Skipping current packet version
  14156. memset(str,0,sizeof(str));
  14157. for(j=0,p=line;j<4 && p; ++j)
  14158. {
  14159. str[j]=p;
  14160. p=strchr(p,',');
  14161. if(p) *p++=0;
  14162. }
  14163. if(str[0]==NULL)
  14164. continue;
  14165. cmd=strtol(str[0],(char **)NULL,0);
  14166. if(max_cmd < cmd)
  14167. max_cmd = cmd;
  14168. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14169. continue;
  14170. if(str[1]==NULL){
  14171. ShowError("packet_db: packet len error\n");
  14172. continue;
  14173. }
  14174. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14175. if(str[2]==NULL){
  14176. packet_db[packet_ver][cmd].func = NULL;
  14177. ln++;
  14178. continue;
  14179. }
  14180. // look up processing function by name
  14181. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14182. if( j < ARRAYLENGTH(clif_parse_func) )
  14183. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14184. // set the identifying cmd for the packet_db version
  14185. if (strcmp(str[2],"wanttoconnection")==0)
  14186. clif_config.connect_cmd[packet_ver] = cmd;
  14187. if(str[3]==NULL){
  14188. ShowError("packet_db: packet error\n");
  14189. exit(EXIT_FAILURE);
  14190. }
  14191. for(j=0,p2=str[3];p2;j++){
  14192. short k;
  14193. str2[j]=p2;
  14194. p2=strchr(p2,':');
  14195. if(p2) *p2++=0;
  14196. k = atoi(str2[j]);
  14197. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14198. if( j >= MAX_PACKET_POS )
  14199. {
  14200. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14201. break;
  14202. }
  14203. packet_db[packet_ver][cmd].pos[j] = k;
  14204. }
  14205. }
  14206. fclose(fp);
  14207. if(max_cmd > MAX_PACKET_DB)
  14208. {
  14209. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14210. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14211. }
  14212. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14213. { //Locate the nearest version that we still support. [Skotlex]
  14214. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14215. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14216. }
  14217. 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);
  14218. return 0;
  14219. }
  14220. /*==========================================
  14221. *
  14222. *------------------------------------------*/
  14223. int do_init_clif(void) {
  14224. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14225. int i;
  14226. /**
  14227. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14228. **/
  14229. for(i = 0; i < COLOR_MAX; i++) {
  14230. color_table[i] = strtoul(colors[i],NULL,0);
  14231. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14232. }
  14233. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14234. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14235. memset(packet_db,0,sizeof(packet_db));
  14236. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14237. packetdb_readdb();
  14238. set_defaultparse(clif_parse);
  14239. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14240. ShowFatalError("can't bind game port\n");
  14241. exit(EXIT_FAILURE);
  14242. }
  14243. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14244. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14245. return 0;
  14246. }