clif.c 460 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774
  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. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5060. /// 02bb <equip location>.W <account id>.L
  5061. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5062. {
  5063. int fd = sd->fd;
  5064. WFIFOHEAD(fd,packet_len(0x2bb));
  5065. WFIFOW(fd,0) = 0x2bb;
  5066. WFIFOW(fd,2) = position;
  5067. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5068. WFIFOSET(fd,packet_len(0x2bb));
  5069. }
  5070. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5071. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5072. void clif_item_refine_list(struct map_session_data *sd)
  5073. {
  5074. int i,c;
  5075. int fd;
  5076. int skilllv;
  5077. int wlv;
  5078. int refine_item[5];
  5079. nullpo_retv(sd);
  5080. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  5081. fd=sd->fd;
  5082. refine_item[0] = -1;
  5083. refine_item[1] = pc_search_inventory(sd,1010);
  5084. refine_item[2] = pc_search_inventory(sd,1011);
  5085. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5086. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5087. WFIFOW(fd,0)=0x221;
  5088. for(i=c=0;i<MAX_INVENTORY;i++){
  5089. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  5090. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5091. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5092. WFIFOW(fd,c*13+ 4)=i+2;
  5093. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5094. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5095. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5096. c++;
  5097. }
  5098. }
  5099. WFIFOW(fd,2)=c*13+4;
  5100. WFIFOSET(fd,WFIFOW(fd,2));
  5101. if (c > 0) {
  5102. sd->menuskill_id = WS_WEAPONREFINE;
  5103. sd->menuskill_val = skilllv;
  5104. }
  5105. }
  5106. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5107. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5108. void clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  5109. {
  5110. int fd;
  5111. nullpo_retv(sd);
  5112. fd=sd->fd;
  5113. WFIFOHEAD(fd,packet_len(0x147));
  5114. WFIFOW(fd, 0)=0x147;
  5115. WFIFOW(fd, 2)=skillid;
  5116. WFIFOW(fd, 4)=skill_get_inf(skillid);
  5117. WFIFOW(fd, 6)=0;
  5118. WFIFOW(fd, 8)=skilllv;
  5119. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  5120. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  5121. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  5122. WFIFOB(fd,38)=0;
  5123. WFIFOSET(fd,packet_len(0x147));
  5124. }
  5125. /// Adds an item to character's cart.
  5126. /// 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)
  5127. /// 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)
  5128. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5129. {
  5130. int view,fd;
  5131. unsigned char *buf;
  5132. nullpo_retv(sd);
  5133. fd=sd->fd;
  5134. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5135. return;
  5136. #if PACKETVER < 5
  5137. WFIFOHEAD(fd,packet_len(0x124));
  5138. buf=WFIFOP(fd,0);
  5139. WBUFW(buf,0)=0x124;
  5140. WBUFW(buf,2)=n+2;
  5141. WBUFL(buf,4)=amount;
  5142. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5143. WBUFW(buf,8)=view;
  5144. else
  5145. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5146. WBUFB(buf,10)=sd->status.cart[n].identify;
  5147. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5148. WBUFB(buf,12)=sd->status.cart[n].refine;
  5149. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5150. WFIFOSET(fd,packet_len(0x124));
  5151. #else
  5152. WFIFOHEAD(fd,packet_len(0x1c5));
  5153. buf=WFIFOP(fd,0);
  5154. WBUFW(buf,0)=0x1c5;
  5155. WBUFW(buf,2)=n+2;
  5156. WBUFL(buf,4)=amount;
  5157. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5158. WBUFW(buf,8)=view;
  5159. else
  5160. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5161. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5162. WBUFB(buf,11)=sd->status.cart[n].identify;
  5163. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5164. WBUFB(buf,13)=sd->status.cart[n].refine;
  5165. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5166. WFIFOSET(fd,packet_len(0x1c5));
  5167. #endif
  5168. }
  5169. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5170. /// 0125 <index>.W <amount>.L
  5171. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5172. {
  5173. int fd;
  5174. nullpo_retv(sd);
  5175. fd=sd->fd;
  5176. WFIFOHEAD(fd,packet_len(0x125));
  5177. WFIFOW(fd,0)=0x125;
  5178. WFIFOW(fd,2)=n+2;
  5179. WFIFOL(fd,4)=amount;
  5180. WFIFOSET(fd,packet_len(0x125));
  5181. }
  5182. /// Opens the shop creation menu (ZC_OPENSTORE).
  5183. /// 012d <num>.W
  5184. /// num:
  5185. /// number of allowed item slots
  5186. void clif_openvendingreq(struct map_session_data* sd, int num)
  5187. {
  5188. int fd;
  5189. nullpo_retv(sd);
  5190. fd = sd->fd;
  5191. WFIFOHEAD(fd,packet_len(0x12d));
  5192. WFIFOW(fd,0) = 0x12d;
  5193. WFIFOW(fd,2) = num;
  5194. WFIFOSET(fd,packet_len(0x12d));
  5195. }
  5196. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5197. /// 0131 <owner id>.L <message>.80B
  5198. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5199. {
  5200. unsigned char buf[128];
  5201. nullpo_retv(bl);
  5202. WBUFW(buf,0) = 0x131;
  5203. WBUFL(buf,2) = bl->id;
  5204. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5205. if( fd ) {
  5206. WFIFOHEAD(fd,packet_len(0x131));
  5207. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5208. WFIFOSET(fd,packet_len(0x131));
  5209. } else {
  5210. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5211. }
  5212. }
  5213. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5214. /// 0132 <owner id>.L
  5215. void clif_closevendingboard(struct block_list* bl, int fd)
  5216. {
  5217. unsigned char buf[16];
  5218. nullpo_retv(bl);
  5219. WBUFW(buf,0) = 0x132;
  5220. WBUFL(buf,2) = bl->id;
  5221. if( fd ) {
  5222. WFIFOHEAD(fd,packet_len(0x132));
  5223. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5224. WFIFOSET(fd,packet_len(0x132));
  5225. } else {
  5226. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5227. }
  5228. }
  5229. /// Sends a list of items in a shop.
  5230. /// 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)
  5231. /// 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)
  5232. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5233. {
  5234. int i,fd;
  5235. int count;
  5236. struct map_session_data* vsd;
  5237. #if PACKETVER < 20100105
  5238. const int cmd = 0x133;
  5239. const int offset = 8;
  5240. #else
  5241. const int cmd = 0x800;
  5242. const int offset = 12;
  5243. #endif
  5244. nullpo_retv(sd);
  5245. nullpo_retv(vending);
  5246. nullpo_retv(vsd=map_id2sd(id));
  5247. fd = sd->fd;
  5248. count = vsd->vend_num;
  5249. WFIFOHEAD(fd, offset+count*22);
  5250. WFIFOW(fd,0) = cmd;
  5251. WFIFOW(fd,2) = offset+count*22;
  5252. WFIFOL(fd,4) = id;
  5253. #if PACKETVER >= 20100105
  5254. WFIFOL(fd,8) = vsd->vender_id;
  5255. #endif
  5256. for( i = 0; i < count; i++ )
  5257. {
  5258. int index = vending[i].index;
  5259. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5260. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5261. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5262. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5263. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5264. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5265. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5266. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5267. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5268. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5269. }
  5270. WFIFOSET(fd,WFIFOW(fd,2));
  5271. }
  5272. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5273. /// 0135 <index>.W <amount>.W <result>.B
  5274. /// result:
  5275. /// 0 = success
  5276. /// 1 = not enough zeny
  5277. /// 2 = overweight
  5278. /// 4 = out of stock
  5279. /// 5 = "cannot use an npc shop while in a trade"
  5280. /// 6 = Because the store information was incorrect the item was not purchased.
  5281. /// 7 = No sales information.
  5282. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5283. {
  5284. int fd;
  5285. nullpo_retv(sd);
  5286. fd = sd->fd;
  5287. WFIFOHEAD(fd,packet_len(0x135));
  5288. WFIFOW(fd,0) = 0x135;
  5289. WFIFOW(fd,2) = index+2;
  5290. WFIFOW(fd,4) = amount;
  5291. WFIFOB(fd,6) = fail;
  5292. WFIFOSET(fd,packet_len(0x135));
  5293. }
  5294. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5295. /// 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 }*
  5296. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5297. {
  5298. int i,fd;
  5299. int count;
  5300. nullpo_retv(sd);
  5301. fd = sd->fd;
  5302. count = sd->vend_num;
  5303. WFIFOHEAD(fd, 8+count*22);
  5304. WFIFOW(fd,0) = 0x136;
  5305. WFIFOW(fd,2) = 8+count*22;
  5306. WFIFOL(fd,4) = id;
  5307. for( i = 0; i < count; i++ )
  5308. {
  5309. int index = vending[i].index;
  5310. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5311. WFIFOL(fd, 8+i*22) = vending[i].value;
  5312. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5313. WFIFOW(fd,14+i*22) = vending[i].amount;
  5314. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5315. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5316. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5317. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5318. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5319. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5320. }
  5321. WFIFOSET(fd,WFIFOW(fd,2));
  5322. }
  5323. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5324. /// 0137 <index>.W <amount>.W
  5325. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5326. {
  5327. int fd;
  5328. nullpo_retv(sd);
  5329. fd = sd->fd;
  5330. WFIFOHEAD(fd,packet_len(0x137));
  5331. WFIFOW(fd,0) = 0x137;
  5332. WFIFOW(fd,2) = index+2;
  5333. WFIFOW(fd,4) = amount;
  5334. WFIFOSET(fd,packet_len(0x137));
  5335. }
  5336. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5337. /// 00fa <result>.B
  5338. /// result:
  5339. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5340. /// 1 = MsgStringTable[78]="party name already exists"
  5341. /// 2 = MsgStringTable[79]="already in a party"
  5342. /// 3 = cannot organize parties on this map
  5343. /// ? = nothing
  5344. void clif_party_created(struct map_session_data *sd,int result)
  5345. {
  5346. int fd;
  5347. nullpo_retv(sd);
  5348. fd=sd->fd;
  5349. WFIFOHEAD(fd,packet_len(0xfa));
  5350. WFIFOW(fd,0)=0xfa;
  5351. WFIFOB(fd,2)=result;
  5352. WFIFOSET(fd,packet_len(0xfa));
  5353. }
  5354. /// Adds new member to a party.
  5355. /// 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)
  5356. /// 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)
  5357. /// role:
  5358. /// 0 = leader
  5359. /// 1 = normal
  5360. /// state:
  5361. /// 0 = connected
  5362. /// 1 = disconnected
  5363. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5364. {
  5365. unsigned char buf[81];
  5366. int i;
  5367. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5368. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5369. } else {
  5370. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5371. }
  5372. if (i >= MAX_PARTY) return; //Should never happen...
  5373. sd = p->data[i].sd;
  5374. WBUFW(buf, 0) = 0x1e9;
  5375. WBUFL(buf, 2) = sd->status.account_id;
  5376. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5377. WBUFW(buf,10) = sd->bl.x;
  5378. WBUFW(buf,12) = sd->bl.y;
  5379. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5380. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5381. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5382. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5383. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5384. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5385. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5386. }
  5387. /// Sends party information (ZC_GROUP_LIST).
  5388. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5389. /// role:
  5390. /// 0 = leader
  5391. /// 1 = normal
  5392. /// state:
  5393. /// 0 = connected
  5394. /// 1 = disconnected
  5395. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5396. {
  5397. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5398. struct map_session_data* party_sd = NULL;
  5399. int i, c;
  5400. nullpo_retv(p);
  5401. WBUFW(buf,0) = 0xfb;
  5402. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5403. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5404. {
  5405. struct party_member* m = &p->party.member[i];
  5406. if(!m->account_id) continue;
  5407. if(party_sd == NULL) party_sd = p->data[i].sd;
  5408. WBUFL(buf,28+c*46) = m->account_id;
  5409. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5410. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5411. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5412. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5413. c++;
  5414. }
  5415. WBUFW(buf,2) = 28+c*46;
  5416. if(sd) { // send only to self
  5417. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5418. } else if (party_sd) { // send to whole party
  5419. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5420. }
  5421. }
  5422. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5423. /// 02c9 <flag>.B
  5424. /// flag:
  5425. /// 0 = allow party invites
  5426. /// 1 = auto-deny party invites
  5427. void clif_partyinvitationstate(struct map_session_data* sd)
  5428. {
  5429. int fd;
  5430. nullpo_retv(sd);
  5431. fd = sd->fd;
  5432. WFIFOHEAD(fd, packet_len(0x2c9));
  5433. WFIFOW(fd, 0) = 0x2c9;
  5434. WFIFOB(fd, 2) = 0; // not implemented
  5435. WFIFOSET(fd, packet_len(0x2c9));
  5436. }
  5437. /// Party invitation request.
  5438. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5439. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5440. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5441. {
  5442. #if PACKETVER < 20070821
  5443. const int cmd = 0xfe;
  5444. #else
  5445. const int cmd = 0x2c6;
  5446. #endif
  5447. int fd;
  5448. struct party_data *p;
  5449. nullpo_retv(sd);
  5450. nullpo_retv(tsd);
  5451. fd=tsd->fd;
  5452. if( (p=party_search(sd->status.party_id))==NULL )
  5453. return;
  5454. WFIFOHEAD(fd,packet_len(cmd));
  5455. WFIFOW(fd,0)=cmd;
  5456. WFIFOL(fd,2)=sd->status.party_id;
  5457. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5458. WFIFOSET(fd,packet_len(cmd));
  5459. }
  5460. /// Party invite result.
  5461. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5462. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5463. /// result=0 : char is already in a party -> MsgStringTable[80]
  5464. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5465. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5466. /// result=3 : party is full -> MsgStringTable[83]
  5467. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5468. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5469. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5470. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5471. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5472. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5473. {
  5474. int fd;
  5475. nullpo_retv(sd);
  5476. fd=sd->fd;
  5477. #if PACKETVER < 20070904
  5478. if( result == 7 ) {
  5479. clif_displaymessage(fd, msg_txt(3));
  5480. return;
  5481. }
  5482. #endif
  5483. #if PACKETVER < 20070821
  5484. WFIFOHEAD(fd,packet_len(0xfd));
  5485. WFIFOW(fd,0) = 0xfd;
  5486. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5487. WFIFOB(fd,26) = result;
  5488. WFIFOSET(fd,packet_len(0xfd));
  5489. #else
  5490. WFIFOHEAD(fd,packet_len(0x2c5));
  5491. WFIFOW(fd,0) = 0x2c5;
  5492. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5493. WFIFOL(fd,26) = result;
  5494. WFIFOSET(fd,packet_len(0x2c5));
  5495. #endif
  5496. }
  5497. /// Updates party settings.
  5498. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5499. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5500. /// exp option:
  5501. /// 0 = exp sharing disabled
  5502. /// 1 = exp sharing enabled
  5503. /// 2 = cannot change exp sharing
  5504. ///
  5505. /// flag:
  5506. /// 0 = send to party
  5507. /// 1 = send to sd
  5508. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5509. {
  5510. unsigned char buf[16];
  5511. #if PACKETVER < 20090603
  5512. const int cmd = 0x101;
  5513. #else
  5514. const int cmd = 0x7d8;
  5515. #endif
  5516. nullpo_retv(p);
  5517. if(!sd && flag==0){
  5518. int i;
  5519. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5520. if (i < MAX_PARTY)
  5521. sd = p->data[i].sd;
  5522. }
  5523. if(!sd) return;
  5524. WBUFW(buf,0)=cmd;
  5525. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5526. #if PACKETVER >= 20090603
  5527. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5528. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5529. #endif
  5530. if(flag==0)
  5531. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5532. else
  5533. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5534. }
  5535. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5536. /// result:
  5537. /// 0 = leave
  5538. /// 1 = expel
  5539. /// 2 = cannot leave party on this map
  5540. /// 3 = cannot expel from party on this map
  5541. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5542. {
  5543. unsigned char buf[64];
  5544. int i;
  5545. nullpo_retv(p);
  5546. if(!sd && (flag&0xf0)==0)
  5547. {
  5548. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5549. if (i < MAX_PARTY)
  5550. sd = p->data[i].sd;
  5551. }
  5552. if(!sd) return;
  5553. WBUFW(buf,0)=0x105;
  5554. WBUFL(buf,2)=account_id;
  5555. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5556. WBUFB(buf,30)=flag&0x0f;
  5557. if((flag&0xf0)==0)
  5558. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5559. else
  5560. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5561. }
  5562. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5563. /// 0109 <packet len>.W <account id>.L <message>.?B
  5564. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5565. {
  5566. struct map_session_data *sd;
  5567. int i;
  5568. nullpo_retv(p);
  5569. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5570. if(i < MAX_PARTY){
  5571. unsigned char buf[1024];
  5572. sd = p->data[i].sd;
  5573. WBUFW(buf,0)=0x109;
  5574. WBUFW(buf,2)=len+8;
  5575. WBUFL(buf,4)=account_id;
  5576. memcpy(WBUFP(buf,8),mes,len); // FIXME: buffer size check
  5577. clif_send(buf,len+8,&sd->bl,PARTY);
  5578. }
  5579. }
  5580. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5581. /// 0107 <account id>.L <x>.W <y>.W
  5582. void clif_party_xy(struct map_session_data *sd)
  5583. {
  5584. unsigned char buf[16];
  5585. nullpo_retv(sd);
  5586. WBUFW(buf,0)=0x107;
  5587. WBUFL(buf,2)=sd->status.account_id;
  5588. WBUFW(buf,6)=sd->bl.x;
  5589. WBUFW(buf,8)=sd->bl.y;
  5590. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5591. }
  5592. /*==========================================
  5593. * Sends x/y dot to a single fd. [Skotlex]
  5594. *------------------------------------------*/
  5595. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5596. {
  5597. WFIFOHEAD(fd,packet_len(0x107));
  5598. WFIFOW(fd,0)=0x107;
  5599. WFIFOL(fd,2)=sd->status.account_id;
  5600. WFIFOW(fd,6)=sd->bl.x;
  5601. WFIFOW(fd,8)=sd->bl.y;
  5602. WFIFOSET(fd,packet_len(0x107));
  5603. }
  5604. /// Updates HP bar of a party member.
  5605. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5606. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5607. void clif_party_hp(struct map_session_data *sd)
  5608. {
  5609. unsigned char buf[16];
  5610. #if PACKETVER < 20100126
  5611. const int cmd = 0x106;
  5612. #else
  5613. const int cmd = 0x80e;
  5614. #endif
  5615. nullpo_retv(sd);
  5616. WBUFW(buf,0)=cmd;
  5617. WBUFL(buf,2)=sd->status.account_id;
  5618. #if PACKETVER < 20100126
  5619. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5620. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5621. WBUFW(buf,8) = 100;
  5622. } else {
  5623. WBUFW(buf,6) = sd->battle_status.hp;
  5624. WBUFW(buf,8) = sd->battle_status.max_hp;
  5625. }
  5626. #else
  5627. WBUFL(buf,6) = sd->battle_status.hp;
  5628. WBUFL(buf,10) = sd->battle_status.max_hp;
  5629. #endif
  5630. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5631. }
  5632. /*==========================================
  5633. * Sends HP bar to a single fd. [Skotlex]
  5634. *------------------------------------------*/
  5635. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5636. {
  5637. #if PACKETVER < 20100126
  5638. const int cmd = 0x106;
  5639. #else
  5640. const int cmd = 0x80e;
  5641. #endif
  5642. WFIFOHEAD(fd,packet_len(cmd));
  5643. WFIFOW(fd,0) = cmd;
  5644. WFIFOL(fd,2) = id;
  5645. #if PACKETVER < 20100126
  5646. if( maxhp > INT16_MAX )
  5647. {// To correctly display the %hp bar. [Skotlex]
  5648. WFIFOW(fd,6) = hp/(maxhp/100);
  5649. WFIFOW(fd,8) = 100;
  5650. } else {
  5651. WFIFOW(fd,6) = hp;
  5652. WFIFOW(fd,8) = maxhp;
  5653. }
  5654. #else
  5655. WFIFOL(fd,6) = hp;
  5656. WFIFOL(fd,10) = maxhp;
  5657. #endif
  5658. WFIFOSET(fd, packet_len(cmd));
  5659. }
  5660. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5661. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5662. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5663. {
  5664. int fd;
  5665. nullpo_retv(sd);
  5666. nullpo_retv(bl);
  5667. fd=sd->fd;
  5668. WFIFOHEAD(fd,packet_len(0x139));
  5669. WFIFOW(fd, 0)=0x139;
  5670. WFIFOL(fd, 2)=bl->id;
  5671. WFIFOW(fd, 6)=bl->x;
  5672. WFIFOW(fd, 8)=bl->y;
  5673. WFIFOW(fd,10)=sd->bl.x;
  5674. WFIFOW(fd,12)=sd->bl.y;
  5675. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5676. WFIFOSET(fd,packet_len(0x139));
  5677. }
  5678. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5679. /// 018f <result>.W <name id>.W
  5680. /// result:
  5681. /// 0 = success
  5682. /// 1 = failure
  5683. /// 2 = success (alchemist)
  5684. /// 3 = failure (alchemist)
  5685. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5686. {
  5687. int view,fd;
  5688. nullpo_retv(sd);
  5689. fd = sd->fd;
  5690. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5691. WFIFOHEAD(fd,packet_len(0x18f));
  5692. WFIFOW(fd, 0)=0x18f;
  5693. WFIFOW(fd, 2)=flag;
  5694. if((view = itemdb_viewid(nameid)) > 0)
  5695. WFIFOW(fd, 4)=view;
  5696. else
  5697. WFIFOW(fd, 4)=nameid;
  5698. WFIFOSET(fd,packet_len(0x18f));
  5699. }
  5700. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5701. /// 019e
  5702. void clif_catch_process(struct map_session_data *sd)
  5703. {
  5704. int fd;
  5705. nullpo_retv(sd);
  5706. fd=sd->fd;
  5707. WFIFOHEAD(fd,packet_len(0x19e));
  5708. WFIFOW(fd,0)=0x19e;
  5709. WFIFOSET(fd,packet_len(0x19e));
  5710. }
  5711. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5712. /// 01a0 <result>.B
  5713. /// 0 = failure
  5714. /// 1 = success
  5715. void clif_pet_roulette(struct map_session_data *sd,int data)
  5716. {
  5717. int fd;
  5718. nullpo_retv(sd);
  5719. fd=sd->fd;
  5720. WFIFOHEAD(fd,packet_len(0x1a0));
  5721. WFIFOW(fd,0)=0x1a0;
  5722. WFIFOB(fd,2)=data;
  5723. WFIFOSET(fd,packet_len(0x1a0));
  5724. }
  5725. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5726. /// 01a6 <packet len>.W { <index>.W }*
  5727. void clif_sendegg(struct map_session_data *sd)
  5728. {
  5729. int i,n=0,fd;
  5730. nullpo_retv(sd);
  5731. fd=sd->fd;
  5732. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5733. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5734. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5735. return;
  5736. }
  5737. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5738. WFIFOW(fd,0)=0x1a6;
  5739. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5740. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5741. sd->inventory_data[i]->type!=IT_PETEGG ||
  5742. sd->status.inventory[i].amount<=0)
  5743. continue;
  5744. WFIFOW(fd,n*2+4)=i+2;
  5745. n++;
  5746. }
  5747. WFIFOW(fd,2)=4+n*2;
  5748. WFIFOSET(fd,WFIFOW(fd,2));
  5749. sd->menuskill_id = SA_TAMINGMONSTER;
  5750. sd->menuskill_val = -1;
  5751. }
  5752. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5753. /// 01a4 <type>.B <id>.L <data>.L
  5754. /// type:
  5755. /// 0 = pre-init (data = 0)
  5756. /// 1 = intimacy (data = 0~4)
  5757. /// 2 = hunger (data = 0~4)
  5758. /// 3 = accessory
  5759. /// 4 = performance (data = 1~3: normal, 4: special)
  5760. /// 5 = hairstyle
  5761. ///
  5762. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5763. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5764. {
  5765. uint8 buf[16];
  5766. nullpo_retv(pd);
  5767. WBUFW(buf,0) = 0x1a4;
  5768. WBUFB(buf,2) = type;
  5769. WBUFL(buf,3) = pd->bl.id;
  5770. WBUFL(buf,7) = param;
  5771. if (sd)
  5772. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5773. else
  5774. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5775. }
  5776. /// Pet's base data (ZC_PROPERTY_PET).
  5777. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5778. void clif_send_petstatus(struct map_session_data *sd)
  5779. {
  5780. int fd;
  5781. struct s_pet *pet;
  5782. nullpo_retv(sd);
  5783. nullpo_retv(sd->pd);
  5784. fd=sd->fd;
  5785. pet = &sd->pd->pet;
  5786. WFIFOHEAD(fd,packet_len(0x1a2));
  5787. WFIFOW(fd,0)=0x1a2;
  5788. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5789. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5790. WFIFOW(fd,27)=pet->level;
  5791. WFIFOW(fd,29)=pet->hungry;
  5792. WFIFOW(fd,31)=pet->intimate;
  5793. WFIFOW(fd,33)=pet->equip;
  5794. #if PACKETVER >= 20081126
  5795. WFIFOW(fd,35)=pet->class_;
  5796. #endif
  5797. WFIFOSET(fd,packet_len(0x1a2));
  5798. }
  5799. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5800. /// 01aa <id>.L <data>.L
  5801. /// data:
  5802. /// @see CZ_PET_ACT.
  5803. void clif_pet_emotion(struct pet_data *pd,int param)
  5804. {
  5805. unsigned char buf[16];
  5806. nullpo_retv(pd);
  5807. memset(buf,0,packet_len(0x1aa));
  5808. WBUFW(buf,0)=0x1aa;
  5809. WBUFL(buf,2)=pd->bl.id;
  5810. if(param >= 100 && pd->petDB->talk_convert_class) {
  5811. if(pd->petDB->talk_convert_class < 0)
  5812. return;
  5813. else if(pd->petDB->talk_convert_class > 0) {
  5814. // replace mob_id component of talk/act data
  5815. param -= (pd->pet.class_ - 100)*100;
  5816. param += (pd->petDB->talk_convert_class - 100)*100;
  5817. }
  5818. }
  5819. WBUFL(buf,6)=param;
  5820. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5821. }
  5822. /// Result of request to feed a pet (ZC_FEED_PET).
  5823. /// 01a3 <result>.B <name id>.W
  5824. /// result:
  5825. /// 0 = failure
  5826. /// 1 = success
  5827. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5828. {
  5829. int fd;
  5830. nullpo_retv(sd);
  5831. fd=sd->fd;
  5832. WFIFOHEAD(fd,packet_len(0x1a3));
  5833. WFIFOW(fd,0)=0x1a3;
  5834. WFIFOB(fd,2)=fail;
  5835. WFIFOW(fd,3)=foodid;
  5836. WFIFOSET(fd,packet_len(0x1a3));
  5837. }
  5838. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5839. /// 01cd { <skill id>.L }*7
  5840. void clif_autospell(struct map_session_data *sd,int skilllv)
  5841. {
  5842. int fd;
  5843. nullpo_retv(sd);
  5844. fd=sd->fd;
  5845. WFIFOHEAD(fd,packet_len(0x1cd));
  5846. WFIFOW(fd, 0)=0x1cd;
  5847. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5848. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5849. else
  5850. WFIFOL(fd,2)= 0x00000000;
  5851. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5852. WFIFOL(fd,6)= MG_COLDBOLT;
  5853. else
  5854. WFIFOL(fd,6)= 0x00000000;
  5855. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5856. WFIFOL(fd,10)= MG_FIREBOLT;
  5857. else
  5858. WFIFOL(fd,10)= 0x00000000;
  5859. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5860. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5861. else
  5862. WFIFOL(fd,14)= 0x00000000;
  5863. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5864. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5865. else
  5866. WFIFOL(fd,18)= 0x00000000;
  5867. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5868. WFIFOL(fd,22)= MG_FIREBALL;
  5869. else
  5870. WFIFOL(fd,22)= 0x00000000;
  5871. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5872. WFIFOL(fd,26)= MG_FROSTDIVER;
  5873. else
  5874. WFIFOL(fd,26)= 0x00000000;
  5875. WFIFOSET(fd,packet_len(0x1cd));
  5876. sd->menuskill_id = SA_AUTOSPELL;
  5877. sd->menuskill_val = skilllv;
  5878. }
  5879. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5880. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5881. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5882. {
  5883. unsigned char buf[56];
  5884. int i;
  5885. nullpo_retv(src);
  5886. memset(buf,0,packet_len(0x1cf));
  5887. WBUFW(buf,0) = 0x1cf;
  5888. WBUFL(buf,2) = src->id;
  5889. if( src->type == BL_MER )
  5890. {
  5891. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5892. if( md && md->master && md->devotion_flag )
  5893. WBUFL(buf,6) = md->master->bl.id;
  5894. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5895. }
  5896. else
  5897. {
  5898. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5899. if( sd == NULL )
  5900. return;
  5901. for( i = 0; i < 5; i++ )
  5902. WBUFL(buf,6+4*i) = sd->devotion[i];
  5903. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5904. }
  5905. if( tsd )
  5906. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5907. else
  5908. clif_send(buf, packet_len(0x1cf), src, AREA);
  5909. }
  5910. /// Notifies clients in an area of an object's spirits.
  5911. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  5912. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  5913. void clif_spiritball(struct map_session_data *sd)
  5914. {
  5915. unsigned char buf[8];
  5916. nullpo_retv(sd);
  5917. WBUFW(buf,0)=0x1d0;
  5918. WBUFL(buf,2)=sd->bl.id;
  5919. WBUFW(buf,6)=sd->spiritball;
  5920. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5921. }
  5922. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  5923. /// 01d2 <account id>.L <delay>.L
  5924. void clif_combo_delay(struct block_list *bl,int wait)
  5925. {
  5926. unsigned char buf[32];
  5927. nullpo_retv(bl);
  5928. WBUFW(buf,0)=0x1d2;
  5929. WBUFL(buf,2)=bl->id;
  5930. WBUFL(buf,6)=wait;
  5931. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5932. }
  5933. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  5934. /// 01d1 <src id>.L <dst id>.L <flag>.L
  5935. /// flag:
  5936. /// 0 = inactive
  5937. /// 1 = active
  5938. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5939. {
  5940. unsigned char buf[32];
  5941. nullpo_retv(src);
  5942. WBUFW(buf,0)=0x1d1;
  5943. WBUFL(buf,2)=src->id;
  5944. WBUFL(buf,6)=dst_id;
  5945. WBUFL(buf,10)=active;
  5946. clif_send(buf,packet_len(0x1d1),src,AREA);
  5947. }
  5948. /// MVP effect (ZC_MVP).
  5949. /// 010c <account id>.L
  5950. void clif_mvp_effect(struct map_session_data *sd)
  5951. {
  5952. unsigned char buf[16];
  5953. nullpo_retv(sd);
  5954. WBUFW(buf,0)=0x10c;
  5955. WBUFL(buf,2)=sd->bl.id;
  5956. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5957. }
  5958. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  5959. /// 010a <name id>.W
  5960. void clif_mvp_item(struct map_session_data *sd,int nameid)
  5961. {
  5962. int view,fd;
  5963. nullpo_retv(sd);
  5964. fd=sd->fd;
  5965. WFIFOHEAD(fd,packet_len(0x10a));
  5966. WFIFOW(fd,0)=0x10a;
  5967. if((view = itemdb_viewid(nameid)) > 0)
  5968. WFIFOW(fd,2)=view;
  5969. else
  5970. WFIFOW(fd,2)=nameid;
  5971. WFIFOSET(fd,packet_len(0x10a));
  5972. }
  5973. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  5974. /// 010b <exp>.L
  5975. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5976. {
  5977. int fd;
  5978. nullpo_retv(sd);
  5979. fd=sd->fd;
  5980. WFIFOHEAD(fd,packet_len(0x10b));
  5981. WFIFOW(fd,0)=0x10b;
  5982. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  5983. WFIFOSET(fd,packet_len(0x10b));
  5984. }
  5985. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  5986. /// 010d
  5987. ///
  5988. /// "You are the MVP, but cannot obtain the reward because
  5989. /// you are overweight."
  5990. void clif_mvp_noitem(struct map_session_data* sd)
  5991. {
  5992. int fd = sd->fd;
  5993. WFIFOHEAD(fd,packet_len(0x10d));
  5994. WFIFOW(fd,0) = 0x10d;
  5995. WFIFOSET(fd,packet_len(0x10d));
  5996. }
  5997. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  5998. /// 0167 <result>.B
  5999. /// result:
  6000. /// 0 = "Guild has been created."
  6001. /// 1 = "You are already in a Guild."
  6002. /// 2 = "That Guild Name already exists."
  6003. /// 3 = "You need the neccessary item to create a Guild."
  6004. void clif_guild_created(struct map_session_data *sd,int flag)
  6005. {
  6006. int fd;
  6007. nullpo_retv(sd);
  6008. fd=sd->fd;
  6009. WFIFOHEAD(fd,packet_len(0x167));
  6010. WFIFOW(fd,0)=0x167;
  6011. WFIFOB(fd,2)=flag;
  6012. WFIFOSET(fd,packet_len(0x167));
  6013. }
  6014. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6015. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6016. /// mode:
  6017. /// &0x01 = allow invite
  6018. /// &0x10 = allow expel
  6019. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6020. {
  6021. int ps,fd;
  6022. nullpo_retv(sd);
  6023. nullpo_retv(g);
  6024. fd=sd->fd;
  6025. ps=guild_getposition(g,sd);
  6026. WFIFOHEAD(fd,packet_len(0x16c));
  6027. WFIFOW(fd,0)=0x16c;
  6028. WFIFOL(fd,2)=g->guild_id;
  6029. WFIFOL(fd,6)=g->emblem_id;
  6030. WFIFOL(fd,10)=g->position[ps].mode;
  6031. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6032. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6033. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6034. WFIFOSET(fd,packet_len(0x16c));
  6035. }
  6036. /// Guild member login notice.
  6037. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6038. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6039. /// status:
  6040. /// 0 = offline
  6041. /// 1 = online
  6042. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6043. {
  6044. unsigned char buf[64];
  6045. struct map_session_data* sd;
  6046. nullpo_retv(g);
  6047. WBUFW(buf, 0)=0x1f2;
  6048. WBUFL(buf, 2)=g->member[idx].account_id;
  6049. WBUFL(buf, 6)=g->member[idx].char_id;
  6050. WBUFL(buf,10)=flag;
  6051. if( ( sd = g->member[idx].sd ) != NULL )
  6052. {
  6053. WBUFW(buf,14) = sd->status.sex;
  6054. WBUFW(buf,16) = sd->status.hair;
  6055. WBUFW(buf,18) = sd->status.hair_color;
  6056. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6057. }
  6058. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6059. {
  6060. WBUFW(buf,14) = 0;
  6061. WBUFW(buf,16) = 0;
  6062. WBUFW(buf,18) = 0;
  6063. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6064. }
  6065. }
  6066. // Function `clif_guild_memberlogin_notice` sends info about
  6067. // logins and logouts of a guild member to the rest members.
  6068. // But at the 1st time (after a player login or map changing)
  6069. // the client won't show the message.
  6070. // So I suggest use this function for sending "first-time-info"
  6071. // to some player on entering the game or changing location.
  6072. // At next time the client would always show the message.
  6073. // The function sends all the statuses in the single packet
  6074. // to economize traffic. [LuzZza]
  6075. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6076. {
  6077. struct guild *g;
  6078. unsigned char buf[14*128];
  6079. int i, count=0, p_len;
  6080. nullpo_retv(sd);
  6081. p_len = packet_len(0x16d);
  6082. if(!(g = guild_search(sd->status.guild_id)))
  6083. return;
  6084. for(i=0; i<g->max_member; i++) {
  6085. if(g->member[i].account_id > 0 &&
  6086. g->member[i].account_id != sd->status.account_id) {
  6087. WBUFW(buf,count*p_len) = 0x16d;
  6088. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6089. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6090. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6091. count++;
  6092. }
  6093. }
  6094. clif_send(buf, p_len*count, &sd->bl, SELF);
  6095. }
  6096. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6097. /// 014e <menu flag>.L
  6098. /// menu flag:
  6099. /// 0x00 = Basic Info (always on)
  6100. /// &0x01 = Member manager
  6101. /// &0x02 = Positions
  6102. /// &0x04 = Skills
  6103. /// &0x10 = Expulsion list
  6104. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6105. /// &0x80 = Notice
  6106. void clif_guild_masterormember(struct map_session_data *sd)
  6107. {
  6108. int fd;
  6109. nullpo_retv(sd);
  6110. fd=sd->fd;
  6111. WFIFOHEAD(fd,packet_len(0x14e));
  6112. WFIFOW(fd,0) = 0x14e;
  6113. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6114. WFIFOSET(fd,packet_len(0x14e));
  6115. }
  6116. /// Guild basic information (Territories [Valaris])
  6117. /// 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)
  6118. /// 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)
  6119. void clif_guild_basicinfo(struct map_session_data *sd) {
  6120. int fd;
  6121. struct guild *g;
  6122. nullpo_retv(sd);
  6123. fd = sd->fd;
  6124. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6125. return;
  6126. WFIFOHEAD(fd,packet_len(0x1b6));
  6127. WFIFOW(fd, 0)=0x1b6;//0x150;
  6128. WFIFOL(fd, 2)=g->guild_id;
  6129. WFIFOL(fd, 6)=g->guild_lv;
  6130. WFIFOL(fd,10)=g->connect_member;
  6131. WFIFOL(fd,14)=g->max_member;
  6132. WFIFOL(fd,18)=g->average_lv;
  6133. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6134. WFIFOL(fd,26)=g->next_exp;
  6135. WFIFOL(fd,30)=0; // Tax Points
  6136. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6137. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6138. WFIFOL(fd,42)=g->emblem_id;
  6139. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6140. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6141. safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
  6142. WFIFOL(fd,110) = 0; // zeny
  6143. WFIFOSET(fd,packet_len(0x1b6));
  6144. }
  6145. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6146. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6147. void clif_guild_allianceinfo(struct map_session_data *sd)
  6148. {
  6149. int fd,i,c;
  6150. struct guild *g;
  6151. nullpo_retv(sd);
  6152. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6153. return;
  6154. fd = sd->fd;
  6155. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6156. WFIFOW(fd, 0)=0x14c;
  6157. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6158. struct guild_alliance *a=&g->alliance[i];
  6159. if(a->guild_id>0){
  6160. WFIFOL(fd,c*32+4)=a->opposition;
  6161. WFIFOL(fd,c*32+8)=a->guild_id;
  6162. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6163. c++;
  6164. }
  6165. }
  6166. WFIFOW(fd, 2)=c*32+4;
  6167. WFIFOSET(fd,WFIFOW(fd,2));
  6168. }
  6169. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6170. /// 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 }*
  6171. /// state:
  6172. /// 0 = offline
  6173. /// 1 = online
  6174. /// memo:
  6175. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6176. void clif_guild_memberlist(struct map_session_data *sd)
  6177. {
  6178. int fd;
  6179. int i,c;
  6180. struct guild *g;
  6181. nullpo_retv(sd);
  6182. if( (fd = sd->fd) == 0 )
  6183. return;
  6184. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6185. return;
  6186. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6187. WFIFOW(fd, 0)=0x154;
  6188. for(i=0,c=0;i<g->max_member;i++){
  6189. struct guild_member *m=&g->member[i];
  6190. if(m->account_id==0)
  6191. continue;
  6192. WFIFOL(fd,c*104+ 4)=m->account_id;
  6193. WFIFOL(fd,c*104+ 8)=m->char_id;
  6194. WFIFOW(fd,c*104+12)=m->hair;
  6195. WFIFOW(fd,c*104+14)=m->hair_color;
  6196. WFIFOW(fd,c*104+16)=m->gender;
  6197. WFIFOW(fd,c*104+18)=m->class_;
  6198. WFIFOW(fd,c*104+20)=m->lv;
  6199. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6200. WFIFOL(fd,c*104+26)=m->online;
  6201. WFIFOL(fd,c*104+30)=m->position;
  6202. 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.
  6203. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6204. c++;
  6205. }
  6206. WFIFOW(fd, 2)=c*104+4;
  6207. WFIFOSET(fd,WFIFOW(fd,2));
  6208. }
  6209. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6210. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6211. void clif_guild_positionnamelist(struct map_session_data *sd)
  6212. {
  6213. int i,fd;
  6214. struct guild *g;
  6215. nullpo_retv(sd);
  6216. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6217. return;
  6218. fd = sd->fd;
  6219. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6220. WFIFOW(fd, 0)=0x166;
  6221. for(i=0;i<MAX_GUILDPOSITION;i++){
  6222. WFIFOL(fd,i*28+4)=i;
  6223. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6224. }
  6225. WFIFOW(fd,2)=i*28+4;
  6226. WFIFOSET(fd,WFIFOW(fd,2));
  6227. }
  6228. /// Guild position information (ZC_POSITION_INFO).
  6229. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6230. /// mode:
  6231. /// &0x01 = allow invite
  6232. /// &0x10 = allow expel
  6233. /// ranking:
  6234. /// TODO
  6235. void clif_guild_positioninfolist(struct map_session_data *sd)
  6236. {
  6237. int i,fd;
  6238. struct guild *g;
  6239. nullpo_retv(sd);
  6240. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6241. return;
  6242. fd = sd->fd;
  6243. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6244. WFIFOW(fd, 0)=0x160;
  6245. for(i=0;i<MAX_GUILDPOSITION;i++){
  6246. struct guild_position *p=&g->position[i];
  6247. WFIFOL(fd,i*16+ 4)=i;
  6248. WFIFOL(fd,i*16+ 8)=p->mode;
  6249. WFIFOL(fd,i*16+12)=i;
  6250. WFIFOL(fd,i*16+16)=p->exp_mode;
  6251. }
  6252. WFIFOW(fd, 2)=i*16+4;
  6253. WFIFOSET(fd,WFIFOW(fd,2));
  6254. }
  6255. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6256. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6257. /// mode:
  6258. /// &0x01 = allow invite
  6259. /// &0x10 = allow expel
  6260. /// ranking:
  6261. /// TODO
  6262. void clif_guild_positionchanged(struct guild *g,int idx)
  6263. {
  6264. // FIXME: This packet is intended to update the clients after a
  6265. // commit of position info changes, not sending one packet per
  6266. // position.
  6267. struct map_session_data *sd;
  6268. unsigned char buf[128];
  6269. nullpo_retv(g);
  6270. WBUFW(buf, 0)=0x174;
  6271. WBUFW(buf, 2)=44; // packet len
  6272. // GUILD_REG_POSITION_INFO{
  6273. WBUFL(buf, 4)=idx;
  6274. WBUFL(buf, 8)=g->position[idx].mode;
  6275. WBUFL(buf,12)=idx;
  6276. WBUFL(buf,16)=g->position[idx].exp_mode;
  6277. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6278. // }*
  6279. if( (sd=guild_getavailablesd(g))!=NULL )
  6280. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6281. }
  6282. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6283. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6284. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6285. {
  6286. // FIXME: This packet is intended to update the clients after a
  6287. // commit of member position assignment changes, not sending one
  6288. // packet per position.
  6289. struct map_session_data *sd;
  6290. unsigned char buf[64];
  6291. nullpo_retv(g);
  6292. WBUFW(buf, 0)=0x156;
  6293. WBUFW(buf, 2)=16; // packet len
  6294. // MEMBER_POSITION_INFO{
  6295. WBUFL(buf, 4)=g->member[idx].account_id;
  6296. WBUFL(buf, 8)=g->member[idx].char_id;
  6297. WBUFL(buf,12)=g->member[idx].position;
  6298. // }*
  6299. if( (sd=guild_getavailablesd(g))!=NULL )
  6300. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6301. }
  6302. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6303. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6304. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6305. {
  6306. int fd;
  6307. nullpo_retv(sd);
  6308. nullpo_retv(g);
  6309. fd = sd->fd;
  6310. if( g->emblem_len <= 0 )
  6311. return;
  6312. WFIFOHEAD(fd,g->emblem_len+12);
  6313. WFIFOW(fd,0)=0x152;
  6314. WFIFOW(fd,2)=g->emblem_len+12;
  6315. WFIFOL(fd,4)=g->guild_id;
  6316. WFIFOL(fd,8)=g->emblem_id;
  6317. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6318. WFIFOSET(fd,WFIFOW(fd,2));
  6319. }
  6320. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6321. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6322. void clif_guild_emblem_area(struct block_list* bl)
  6323. {
  6324. uint8 buf[12];
  6325. nullpo_retv(bl);
  6326. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6327. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6328. WBUFW(buf,0) = 0x1b4;
  6329. WBUFL(buf,2) = bl->id;
  6330. WBUFL(buf,6) = status_get_guild_id(bl);
  6331. WBUFW(buf,10) = status_get_emblem_id(bl);
  6332. clif_send(buf, 12, bl, AREA_WOS);
  6333. }
  6334. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6335. /// 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 }*
  6336. void clif_guild_skillinfo(struct map_session_data* sd)
  6337. {
  6338. int fd;
  6339. struct guild* g;
  6340. int i,c;
  6341. nullpo_retv(sd);
  6342. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6343. return;
  6344. fd = sd->fd;
  6345. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6346. WFIFOW(fd,0) = 0x0162;
  6347. WFIFOW(fd,4) = g->skill_point;
  6348. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6349. {
  6350. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6351. {
  6352. int id = g->skill[i].id;
  6353. int p = 6 + c*37;
  6354. WFIFOW(fd,p+0) = id;
  6355. WFIFOL(fd,p+2) = skill_get_inf(id);
  6356. WFIFOW(fd,p+6) = g->skill[i].lv;
  6357. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6358. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6359. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6360. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6361. c++;
  6362. }
  6363. }
  6364. WFIFOW(fd,2) = 6 + c*37;
  6365. WFIFOSET(fd,WFIFOW(fd,2));
  6366. }
  6367. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6368. /// 016f <subject>.60B <notice>.120B
  6369. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6370. {
  6371. int fd;
  6372. nullpo_retv(sd);
  6373. nullpo_retv(g);
  6374. fd = sd->fd;
  6375. if ( !session_isActive(fd) )
  6376. return;
  6377. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6378. return;
  6379. WFIFOHEAD(fd,packet_len(0x16f));
  6380. WFIFOW(fd,0) = 0x16f;
  6381. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6382. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6383. WFIFOSET(fd,packet_len(0x16f));
  6384. }
  6385. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6386. /// 016a <guild id>.L <guild name>.24B
  6387. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6388. {
  6389. int fd;
  6390. nullpo_retv(sd);
  6391. nullpo_retv(g);
  6392. fd=sd->fd;
  6393. WFIFOHEAD(fd,packet_len(0x16a));
  6394. WFIFOW(fd,0)=0x16a;
  6395. WFIFOL(fd,2)=g->guild_id;
  6396. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6397. WFIFOSET(fd,packet_len(0x16a));
  6398. }
  6399. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6400. /// 0169 <answer>.B
  6401. /// answer:
  6402. /// 0 = Already in guild.
  6403. /// 1 = Offer rejected.
  6404. /// 2 = Offer accepted.
  6405. /// 3 = Guild full.
  6406. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6407. {
  6408. int fd;
  6409. nullpo_retv(sd);
  6410. fd=sd->fd;
  6411. WFIFOHEAD(fd,packet_len(0x169));
  6412. WFIFOW(fd,0)=0x169;
  6413. WFIFOB(fd,2)=flag;
  6414. WFIFOSET(fd,packet_len(0x169));
  6415. }
  6416. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6417. /// 015a <char name>.24B <reason>.40B
  6418. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6419. {
  6420. unsigned char buf[128];
  6421. nullpo_retv(sd);
  6422. WBUFW(buf, 0)=0x15a;
  6423. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6424. memcpy(WBUFP(buf,26),mes,40);
  6425. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6426. }
  6427. /// Notifies clients of a guild of an expelled member.
  6428. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6429. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6430. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6431. {
  6432. unsigned char buf[128];
  6433. #if PACKETVER < 20100803
  6434. const unsigned short cmd = 0x15c;
  6435. #else
  6436. const unsigned short cmd = 0x839;
  6437. #endif
  6438. nullpo_retv(sd);
  6439. WBUFW(buf,0) = cmd;
  6440. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6441. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6442. #if PACKETVER < 20100803
  6443. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6444. #endif
  6445. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6446. }
  6447. /// Guild expulsion list (ZC_BAN_LIST).
  6448. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6449. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6450. void clif_guild_expulsionlist(struct map_session_data* sd)
  6451. {
  6452. #if PACKETVER < 20100803
  6453. const int offset = NAME_LENGTH*2+40;
  6454. #else
  6455. const int offset = NAME_LENGTH+40;
  6456. #endif
  6457. int fd, i, c = 0;
  6458. struct guild* g;
  6459. nullpo_retv(sd);
  6460. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6461. return;
  6462. fd = sd->fd;
  6463. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6464. WFIFOW(fd,0) = 0x163;
  6465. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6466. {
  6467. struct guild_expulsion* e = &g->expulsion[i];
  6468. if( e->account_id > 0 )
  6469. {
  6470. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6471. #if PACKETVER < 20100803
  6472. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6473. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6474. #else
  6475. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6476. #endif
  6477. c++;
  6478. }
  6479. }
  6480. WFIFOW(fd,2) = 4 + c*offset;
  6481. WFIFOSET(fd,WFIFOW(fd,2));
  6482. }
  6483. /// Guild chat message (ZC_GUILD_CHAT).
  6484. /// 017f <packet len>.W <message>.?B
  6485. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6486. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6487. struct map_session_data *sd;
  6488. uint8 buf[256];
  6489. if( len == 0 )
  6490. {
  6491. return;
  6492. }
  6493. else if( len > sizeof(buf)-5 )
  6494. {
  6495. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6496. len = sizeof(buf)-5;
  6497. }
  6498. WBUFW(buf, 0) = 0x17f;
  6499. WBUFW(buf, 2) = len + 5;
  6500. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6501. if ((sd = guild_getavailablesd(g)) != NULL)
  6502. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6503. }
  6504. /*==========================================
  6505. * Server tells client 'sd' that his guild skill 'skill_num' gone to level 'lv'
  6506. *------------------------------------------*/
  6507. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6508. {// TODO: Merge with clif_skillup (same packet).
  6509. int fd;
  6510. nullpo_ret(sd);
  6511. fd=sd->fd;
  6512. WFIFOHEAD(fd,11);
  6513. WFIFOW(fd,0) = 0x10e;
  6514. WFIFOW(fd,2) = skill_num;
  6515. WFIFOW(fd,4) = lv;
  6516. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6517. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6518. WFIFOB(fd,10) = 1;
  6519. WFIFOSET(fd,11);
  6520. return 0;
  6521. }
  6522. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6523. /// 0171 <inviter account id>.L <guild name>.24B
  6524. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6525. {
  6526. int fd;
  6527. nullpo_retv(sd);
  6528. fd=sd->fd;
  6529. WFIFOHEAD(fd,packet_len(0x171));
  6530. WFIFOW(fd,0)=0x171;
  6531. WFIFOL(fd,2)=account_id;
  6532. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6533. WFIFOSET(fd,packet_len(0x171));
  6534. }
  6535. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6536. /// 0173 <answer>.B
  6537. /// answer:
  6538. /// 0 = Already allied.
  6539. /// 1 = You rejected the offer.
  6540. /// 2 = You accepted the offer.
  6541. /// 3 = They have too any alliances.
  6542. /// 4 = You have too many alliances.
  6543. /// 5 = Alliances are disabled.
  6544. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6545. {
  6546. int fd;
  6547. nullpo_retv(sd);
  6548. fd=sd->fd;
  6549. WFIFOHEAD(fd,packet_len(0x173));
  6550. WFIFOW(fd,0)=0x173;
  6551. WFIFOL(fd,2)=flag;
  6552. WFIFOSET(fd,packet_len(0x173));
  6553. }
  6554. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6555. /// 0184 <other guild id>.L <relation>.L
  6556. /// relation:
  6557. /// 0 = Ally
  6558. /// 1 = Enemy
  6559. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6560. {
  6561. int fd;
  6562. nullpo_retv(sd);
  6563. fd = sd->fd;
  6564. if (fd <= 0)
  6565. return;
  6566. WFIFOHEAD(fd,packet_len(0x184));
  6567. WFIFOW(fd,0)=0x184;
  6568. WFIFOL(fd,2)=guild_id;
  6569. WFIFOL(fd,6)=flag;
  6570. WFIFOSET(fd,packet_len(0x184));
  6571. }
  6572. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6573. /// 0181 <result>.B
  6574. /// result:
  6575. /// 0 = Antagonist has been set.
  6576. /// 1 = Guild has too many Antagonists.
  6577. /// 2 = Already set as an Antagonist.
  6578. /// 3 = Antagonists are disabled.
  6579. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6580. {
  6581. int fd;
  6582. nullpo_retv(sd);
  6583. fd=sd->fd;
  6584. WFIFOHEAD(fd,packet_len(0x181));
  6585. WFIFOW(fd,0)=0x181;
  6586. WFIFOB(fd,2)=flag;
  6587. WFIFOSET(fd,packet_len(0x181));
  6588. }
  6589. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6590. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6591. /*
  6592. void clif_guild_allianceadded(struct guild *g,int idx)
  6593. {
  6594. unsigned char buf[64];
  6595. WBUFW(buf,0)=0x185;
  6596. WBUFL(buf,2)=g->alliance[idx].opposition;
  6597. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6598. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6599. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6600. }
  6601. */
  6602. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6603. /// 015e <reason>.L
  6604. /// 0 = success
  6605. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6606. /// 2 = there are still members in the guild
  6607. void clif_guild_broken(struct map_session_data *sd,int flag)
  6608. {
  6609. int fd;
  6610. nullpo_retv(sd);
  6611. fd=sd->fd;
  6612. WFIFOHEAD(fd,packet_len(0x15e));
  6613. WFIFOW(fd,0)=0x15e;
  6614. WFIFOL(fd,2)=flag;
  6615. WFIFOSET(fd,packet_len(0x15e));
  6616. }
  6617. /// Displays emotion on an object (ZC_EMOTION).
  6618. /// 00c0 <id>.L <type>.B
  6619. /// type:
  6620. /// enum emotion_type
  6621. void clif_emotion(struct block_list *bl,int type)
  6622. {
  6623. unsigned char buf[8];
  6624. nullpo_retv(bl);
  6625. WBUFW(buf,0)=0xc0;
  6626. WBUFL(buf,2)=bl->id;
  6627. WBUFB(buf,6)=type;
  6628. clif_send(buf,packet_len(0xc0),bl,AREA);
  6629. }
  6630. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6631. /// 0191 <id>.L <contents>.80B
  6632. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6633. {
  6634. unsigned char buf[MESSAGE_SIZE+6];
  6635. nullpo_retv(bl);
  6636. WBUFW(buf,0) = 0x191;
  6637. WBUFL(buf,2) = bl->id;
  6638. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6639. clif_send(buf,packet_len(0x191),bl,AREA);
  6640. }
  6641. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6642. /// 01ea <id>.L
  6643. void clif_wedding_effect(struct block_list *bl)
  6644. {
  6645. unsigned char buf[6];
  6646. nullpo_retv(bl);
  6647. WBUFW(buf,0) = 0x1ea;
  6648. WBUFL(buf,2) = bl->id;
  6649. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6650. }
  6651. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6652. /// 01e6 <partner name>.24B
  6653. void clif_callpartner(struct map_session_data *sd)
  6654. {
  6655. unsigned char buf[26];
  6656. const char *p;
  6657. nullpo_retv(sd);
  6658. // TODO: Send zero-length name if no partner (to initialize the client buffer).
  6659. if(sd->status.partner_id){
  6660. WBUFW(buf,0)=0x1e6;
  6661. p = map_charid2nick(sd->status.partner_id);
  6662. if(p){
  6663. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6664. }else{
  6665. WBUFB(buf,2) = 0;
  6666. }
  6667. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6668. }
  6669. }
  6670. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6671. /// 01e4
  6672. /// This packet while still implemented by the client is no longer being officially used.
  6673. /*
  6674. void clif_marriage_process(struct map_session_data *sd)
  6675. {
  6676. int fd;
  6677. nullpo_retv(sd);
  6678. fd=sd->fd;
  6679. WFIFOHEAD(fd,packet_len(0x1e4));
  6680. WFIFOW(fd,0)=0x1e4;
  6681. WFIFOSET(fd,packet_len(0x1e4));
  6682. }
  6683. */
  6684. /// Notice of divorce (ZC_DIVORCE).
  6685. /// 0205 <partner name>.24B
  6686. void clif_divorced(struct map_session_data* sd, const char* name)
  6687. {
  6688. int fd;
  6689. nullpo_retv(sd);
  6690. fd=sd->fd;
  6691. WFIFOHEAD(fd,packet_len(0x205));
  6692. WFIFOW(fd,0)=0x205;
  6693. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6694. WFIFOSET(fd, packet_len(0x205));
  6695. }
  6696. /// Marriage proposal (ZC_REQ_COUPLE).
  6697. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6698. /// This packet while still implemented by the client is no longer being officially used.
  6699. /*
  6700. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6701. {
  6702. nullpo_retv(sd);
  6703. WFIFOHEAD(fd,packet_len(0x1e2));
  6704. WFIFOW(fd,0) = 0x1e2;
  6705. WFIFOL(fd,2) = ssd->status.account_id;
  6706. WFIFOL(fd,6) = ssd->status.char_id;
  6707. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6708. WFIFOSET(fd, packet_len(0x1e2));
  6709. }
  6710. */
  6711. /*==========================================
  6712. *
  6713. *------------------------------------------*/
  6714. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6715. {
  6716. clif_disp_message(&sd->bl, mes, len, SELF);
  6717. }
  6718. /*==========================================
  6719. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6720. *------------------------------------------*/
  6721. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6722. {
  6723. unsigned char buf[256];
  6724. if( len == 0 )
  6725. {
  6726. return;
  6727. }
  6728. else if( len > sizeof(buf)-5 )
  6729. {
  6730. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6731. len = sizeof(buf)-5;
  6732. }
  6733. WBUFW(buf, 0) = 0x17f;
  6734. WBUFW(buf, 2) = len + 5;
  6735. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6736. clif_send(buf, WBUFW(buf,2), src, target);
  6737. }
  6738. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6739. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6740. /// 00cd <result>.B
  6741. /// result:
  6742. /// 0 = failure
  6743. /// 1 = success
  6744. void clif_GM_kickack(struct map_session_data *sd, int id)
  6745. {
  6746. int fd;
  6747. nullpo_retv(sd);
  6748. fd = sd->fd;
  6749. WFIFOHEAD(fd,packet_len(0xcd));
  6750. WFIFOW(fd,0) = 0xcd;
  6751. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6752. WFIFOSET(fd, packet_len(0xcd));
  6753. }
  6754. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6755. {
  6756. int fd = tsd->fd;
  6757. if( fd > 0 )
  6758. clif_authfail_fd(fd, 15);
  6759. else
  6760. map_quit(tsd);
  6761. if( sd )
  6762. clif_GM_kickack(sd,tsd->status.account_id);
  6763. }
  6764. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6765. /// 014a <result>.L
  6766. /// result:
  6767. /// 0 = "A manner point has been successfully aligned."
  6768. /// 1 = MP_FAILURE_EXHAUST
  6769. /// 2 = MP_FAILURE_ALREADY_GIVING
  6770. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6771. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6772. /// 5 = "You got a good point from %s."
  6773. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6774. {
  6775. int fd;
  6776. nullpo_retv(sd);
  6777. fd = sd->fd;
  6778. WFIFOHEAD(fd,packet_len(0x14a));
  6779. WFIFOW(fd,0) = 0x14a;
  6780. WFIFOL(fd,2) = type;
  6781. WFIFOSET(fd, packet_len(0x14a));
  6782. }
  6783. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6784. /// 014b <type>.B <GM name>.24B
  6785. /// type:
  6786. /// 0 = positive (unmute)
  6787. /// 1 = negative (mute)
  6788. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6789. {
  6790. int fd;
  6791. nullpo_retv(sd);
  6792. nullpo_retv(tsd);
  6793. fd = tsd->fd;
  6794. WFIFOHEAD(fd,packet_len(0x14b));
  6795. WFIFOW(fd,0) = 0x14b;
  6796. WFIFOB(fd,2) = type;
  6797. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6798. WFIFOSET(fd, packet_len(0x14b));
  6799. }
  6800. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6801. /// 00d1 <type>.B <result>.B
  6802. /// type:
  6803. /// 0 = /ex (deny)
  6804. /// 1 = /in (allow)
  6805. /// result:
  6806. /// 0 = success
  6807. /// 1 = failure
  6808. /// 2 = too many blocks
  6809. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6810. {
  6811. int fd;
  6812. nullpo_retv(sd);
  6813. fd=sd->fd;
  6814. WFIFOHEAD(fd,packet_len(0xd1));
  6815. WFIFOW(fd,0)=0xd1;
  6816. WFIFOB(fd,2)=type;
  6817. WFIFOB(fd,3)=flag;
  6818. WFIFOSET(fd,packet_len(0xd1));
  6819. }
  6820. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6821. /// 00d2 <type>.B <result>.B
  6822. /// type:
  6823. /// 0 = /exall (deny)
  6824. /// 1 = /inall (allow)
  6825. /// result:
  6826. /// 0 = success
  6827. /// 1 = failure
  6828. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6829. {
  6830. int fd;
  6831. nullpo_retv(sd);
  6832. fd=sd->fd;
  6833. WFIFOHEAD(fd,packet_len(0xd2));
  6834. WFIFOW(fd,0)=0xd2;
  6835. WFIFOB(fd,2)=type;
  6836. WFIFOB(fd,3)=flag;
  6837. WFIFOSET(fd,packet_len(0xd2));
  6838. }
  6839. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6840. /// 07fe <bgm>.24B
  6841. void clif_playBGM(struct map_session_data* sd, const char* name)
  6842. {
  6843. int fd;
  6844. nullpo_retv(sd);
  6845. fd = sd->fd;
  6846. WFIFOHEAD(fd,packet_len(0x7fe));
  6847. WFIFOW(fd,0) = 0x7fe;
  6848. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6849. WFIFOSET(fd,packet_len(0x7fe));
  6850. }
  6851. /// Plays/stops a wave sound (ZC_SOUND).
  6852. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6853. /// file name:
  6854. /// relative to data\wav
  6855. /// act:
  6856. /// 0 = play (once)
  6857. /// 1 = play (repeat, does not work)
  6858. /// 2 = stops all sound instances of file name (does not work)
  6859. /// term:
  6860. /// unknown purpose, only relevant to act = 1
  6861. /// npc id:
  6862. /// The accustic direction of the sound is determined by the
  6863. /// relative position of the NPC to the player (3D sound).
  6864. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6865. {
  6866. int fd;
  6867. nullpo_retv(sd);
  6868. nullpo_retv(bl);
  6869. fd = sd->fd;
  6870. WFIFOHEAD(fd,packet_len(0x1d3));
  6871. WFIFOW(fd,0) = 0x1d3;
  6872. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6873. WFIFOB(fd,26) = type;
  6874. WFIFOL(fd,27) = 0;
  6875. WFIFOL(fd,31) = bl->id;
  6876. WFIFOSET(fd,packet_len(0x1d3));
  6877. }
  6878. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6879. {
  6880. unsigned char buf[40];
  6881. nullpo_retv(bl);
  6882. WBUFW(buf,0) = 0x1d3;
  6883. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6884. WBUFB(buf,26) = type;
  6885. WBUFL(buf,27) = 0;
  6886. WBUFL(buf,31) = bl->id;
  6887. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6888. }
  6889. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6890. /// 01f3 <id>.L <effect id>.L
  6891. /// effect id:
  6892. /// @see doc/effect_list.txt
  6893. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6894. {
  6895. unsigned char buf[24];
  6896. nullpo_retv(bl);
  6897. memset(buf, 0, packet_len(0x1f3));
  6898. WBUFW(buf,0) = 0x1f3;
  6899. WBUFL(buf,2) = bl->id;
  6900. WBUFL(buf,6) = type;
  6901. clif_send(buf, packet_len(0x1f3), bl, target);
  6902. if (disguised(bl)) {
  6903. WBUFL(buf,2) = -bl->id;
  6904. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6905. }
  6906. }
  6907. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6908. {
  6909. WFIFOHEAD(fd,10);
  6910. WFIFOW(fd,0) = 0x1f3;
  6911. WFIFOL(fd,2) = bl->id;
  6912. WFIFOL(fd,6) = type;
  6913. WFIFOSET(fd,10);
  6914. }
  6915. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  6916. /// 0284 <id>.L <effect id>.L <num data>.L
  6917. /// effect id:
  6918. /// @see doc/effect_list.txt
  6919. /// num data:
  6920. /// effect-dependent value
  6921. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  6922. {
  6923. uint8 buf[14];
  6924. WBUFW(buf,0) = 0x284;
  6925. WBUFL(buf,2) = bl->id;
  6926. WBUFL(buf,6) = effect_id;
  6927. WBUFL(buf,10) = num;
  6928. clif_send(buf, packet_len(0x284), bl, target);
  6929. if( disguised(bl) )
  6930. {
  6931. WBUFL(buf,2) = -bl->id;
  6932. clif_send(buf, packet_len(0x284), bl, SELF);
  6933. }
  6934. }
  6935. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  6936. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6937. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  6938. unsigned short msg_len = strlen(msg) + 1;
  6939. WFIFOHEAD(sd->fd,msg_len + 12);
  6940. WFIFOW(sd->fd,0) = 0x2C1;
  6941. WFIFOW(sd->fd,2) = msg_len + 12;
  6942. WFIFOL(sd->fd,4) = 0;
  6943. WFIFOL(sd->fd,8) = color_table[color];
  6944. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  6945. clif_send(WFIFOP(sd->fd,0), WFIFOW(sd->fd,2), &sd->bl, SELF);
  6946. return 0;
  6947. }
  6948. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  6949. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6950. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  6951. unsigned short msg_len = strlen(msg) + 1;
  6952. uint8 buf[256];
  6953. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6954. nullpo_retv(bl);
  6955. if( msg_len > sizeof(buf)-12 )
  6956. {
  6957. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6958. msg_len = sizeof(buf)-12;
  6959. }
  6960. WBUFW(buf,0) = 0x2C1;
  6961. WBUFW(buf,2) = msg_len + 12;
  6962. WBUFL(buf,4) = bl->id;
  6963. WBUFL(buf,8) = color;
  6964. memcpy(WBUFP(buf,12), msg, msg_len);
  6965. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6966. }
  6967. /// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  6968. /// 008d <packet len>.W <id>.L <message>.?B
  6969. void clif_message(struct block_list* bl, const char* msg)
  6970. {
  6971. unsigned short msg_len = strlen(msg) + 1;
  6972. uint8 buf[256];
  6973. // TODO: Merge with other 0x8d functions.
  6974. nullpo_retv(bl);
  6975. if( msg_len > sizeof(buf)-8 )
  6976. {
  6977. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6978. msg_len = sizeof(buf)-8;
  6979. }
  6980. WBUFW(buf,0) = 0x8d;
  6981. WBUFW(buf,2) = msg_len + 8;
  6982. WBUFL(buf,4) = bl->id;
  6983. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  6984. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6985. }
  6986. // refresh the client's screen, getting rid of any effects
  6987. void clif_refresh(struct map_session_data *sd)
  6988. {
  6989. nullpo_retv(sd);
  6990. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6991. clif_inventorylist(sd);
  6992. if(pc_iscarton(sd)) {
  6993. clif_cartlist(sd);
  6994. clif_updatestatus(sd,SP_CARTINFO);
  6995. }
  6996. clif_updatestatus(sd,SP_WEIGHT);
  6997. clif_updatestatus(sd,SP_MAXWEIGHT);
  6998. clif_updatestatus(sd,SP_STR);
  6999. clif_updatestatus(sd,SP_AGI);
  7000. clif_updatestatus(sd,SP_VIT);
  7001. clif_updatestatus(sd,SP_INT);
  7002. clif_updatestatus(sd,SP_DEX);
  7003. clif_updatestatus(sd,SP_LUK);
  7004. if (sd->spiritball)
  7005. clif_spiritball_single(sd->fd, sd);
  7006. if (sd->vd.cloth_color)
  7007. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7008. if(merc_is_hom_active(sd->hd))
  7009. clif_send_homdata(sd,SP_ACK,0);
  7010. if( sd->md ) {
  7011. clif_mercenary_info(sd);
  7012. clif_mercenary_skillblock(sd);
  7013. }
  7014. if( sd->ed )
  7015. clif_elemental_info(sd);
  7016. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7017. clif_weather_check(sd);
  7018. if( sd->chatID )
  7019. chat_leavechat(sd,0);
  7020. if( sd->state.vending )
  7021. clif_openvending(sd, sd->bl.id, sd->vending);
  7022. if( pc_issit(sd) )
  7023. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7024. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7025. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7026. else
  7027. clif_changed_dir(&sd->bl, SELF);
  7028. // unlike vending, resuming buyingstore crashes the client.
  7029. buyingstore_close(sd);
  7030. mail_clear(sd);
  7031. }
  7032. /// Updates the object's (bl) name on client.
  7033. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7034. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7035. void clif_charnameack (int fd, struct block_list *bl)
  7036. {
  7037. unsigned char buf[103];
  7038. int cmd = 0x95, i, ps = -1;
  7039. nullpo_retv(bl);
  7040. WBUFW(buf,0) = cmd;
  7041. WBUFL(buf,2) = bl->id;
  7042. switch( bl->type )
  7043. {
  7044. case BL_PC:
  7045. {
  7046. struct map_session_data *ssd = (struct map_session_data *)bl;
  7047. struct party_data *p = NULL;
  7048. struct guild *g = NULL;
  7049. //Requesting your own "shadow" name. [Skotlex]
  7050. if (ssd->fd == fd && ssd->disguise)
  7051. WBUFL(buf,2) = -bl->id;
  7052. if( ssd->fakename[0] )
  7053. {
  7054. WBUFW(buf, 0) = cmd = 0x195;
  7055. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7056. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7057. break;
  7058. }
  7059. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7060. if( ssd->status.party_id )
  7061. {
  7062. p = party_search(ssd->status.party_id);
  7063. }
  7064. if( ssd->status.guild_id )
  7065. {
  7066. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  7067. {
  7068. 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);
  7069. if( i < g->max_member ) ps = g->member[i].position;
  7070. }
  7071. }
  7072. if( !battle_config.display_party_name && g == NULL )
  7073. {// do not display party unless the player is also in a guild
  7074. p = NULL;
  7075. }
  7076. if (p == NULL && g == NULL)
  7077. break;
  7078. WBUFW(buf, 0) = cmd = 0x195;
  7079. if (p)
  7080. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7081. else
  7082. WBUFB(buf,30) = 0;
  7083. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7084. {
  7085. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7086. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7087. } else { //Assume no guild.
  7088. WBUFB(buf,54) = 0;
  7089. WBUFB(buf,78) = 0;
  7090. }
  7091. }
  7092. break;
  7093. //[blackhole89]
  7094. case BL_HOM:
  7095. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7096. break;
  7097. case BL_MER:
  7098. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7099. break;
  7100. case BL_PET:
  7101. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7102. break;
  7103. case BL_NPC:
  7104. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7105. break;
  7106. case BL_MOB:
  7107. {
  7108. struct mob_data *md = (struct mob_data *)bl;
  7109. nullpo_retv(md);
  7110. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7111. if( md->guardian_data && md->guardian_data->guild_id )
  7112. {
  7113. WBUFW(buf, 0) = cmd = 0x195;
  7114. WBUFB(buf,30) = 0;
  7115. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7116. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7117. }
  7118. else if( battle_config.show_mob_info )
  7119. {
  7120. char mobhp[50], *str_p = mobhp;
  7121. WBUFW(buf, 0) = cmd = 0x195;
  7122. if( battle_config.show_mob_info&4 )
  7123. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7124. if( battle_config.show_mob_info&1 )
  7125. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7126. if( battle_config.show_mob_info&2 )
  7127. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7128. //Even thought mobhp ain't a name, we send it as one so the client
  7129. //can parse it. [Skotlex]
  7130. if( str_p != mobhp )
  7131. {
  7132. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7133. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7134. WBUFB(buf,54) = 0;
  7135. WBUFB(buf,78) = 0;
  7136. }
  7137. }
  7138. }
  7139. break;
  7140. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7141. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7142. // break;
  7143. return;
  7144. case BL_ELEM:
  7145. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7146. break;
  7147. default:
  7148. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7149. return;
  7150. }
  7151. // if no receipient specified just update nearby clients
  7152. if (fd == 0)
  7153. clif_send(buf, packet_len(cmd), bl, AREA);
  7154. else {
  7155. WFIFOHEAD(fd, packet_len(cmd));
  7156. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7157. WFIFOSET(fd, packet_len(cmd));
  7158. }
  7159. }
  7160. //Used to update when a char leaves a party/guild. [Skotlex]
  7161. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7162. void clif_charnameupdate (struct map_session_data *ssd)
  7163. {
  7164. unsigned char buf[103];
  7165. int cmd = 0x195, ps = -1, i;
  7166. struct party_data *p = NULL;
  7167. struct guild *g = NULL;
  7168. nullpo_retv(ssd);
  7169. if( ssd->fakename[0] )
  7170. return; //No need to update as the party/guild was not displayed anyway.
  7171. WBUFW(buf,0) = cmd;
  7172. WBUFL(buf,2) = ssd->bl.id;
  7173. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7174. if (!battle_config.display_party_name) {
  7175. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  7176. p = party_search(ssd->status.party_id);
  7177. }else{
  7178. if (ssd->status.party_id > 0)
  7179. p = party_search(ssd->status.party_id);
  7180. }
  7181. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  7182. {
  7183. 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);
  7184. if( i < g->max_member ) ps = g->member[i].position;
  7185. }
  7186. if( p )
  7187. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7188. else
  7189. WBUFB(buf,30) = 0;
  7190. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7191. {
  7192. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7193. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7194. }
  7195. else
  7196. {
  7197. WBUFB(buf,54) = 0;
  7198. WBUFB(buf,78) = 0;
  7199. }
  7200. // Update nearby clients
  7201. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7202. }
  7203. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7204. /// 01ff <id>.L <x>.W <y>.W
  7205. ///
  7206. /// Visually moves(instant) a character to x,y. The char moves even
  7207. /// when the target cell isn't walkable. If the char is sitting it
  7208. /// stays that way.
  7209. void clif_slide(struct block_list *bl, int x, int y)
  7210. {
  7211. unsigned char buf[10];
  7212. nullpo_retv(bl);
  7213. WBUFW(buf, 0) = 0x01ff;
  7214. WBUFL(buf, 2) = bl->id;
  7215. WBUFW(buf, 6) = x;
  7216. WBUFW(buf, 8) = y;
  7217. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7218. if( disguised(bl) )
  7219. {
  7220. WBUFL(buf,2) = -bl->id;
  7221. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7222. }
  7223. }
  7224. /*------------------------------------------
  7225. * @me command by lordalfa, rewritten implementation by Skotlex
  7226. *------------------------------------------*/
  7227. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  7228. {
  7229. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7230. int len_mes = strlen(mes)+1; //Account for \0
  7231. if (len_mes > sizeof(buf)-8) {
  7232. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7233. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7234. }
  7235. // send message to others
  7236. WBUFW(buf,0) = 0x8d;
  7237. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7238. WBUFL(buf,4) = sd->bl.id;
  7239. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7240. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7241. // send back message to the speaker
  7242. WBUFW(buf,0) = 0x8e;
  7243. WBUFW(buf, 2) = len_mes + 4;
  7244. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7245. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7246. }
  7247. /*==========================
  7248. * Minimap fix [Kevin]
  7249. * Remove dot from minimap
  7250. *--------------------------*/
  7251. void clif_party_xy_remove(struct map_session_data *sd)
  7252. {
  7253. unsigned char buf[16];
  7254. nullpo_retv(sd);
  7255. WBUFW(buf,0)=0x107;
  7256. WBUFL(buf,2)=sd->status.account_id;
  7257. WBUFW(buf,6)=-1;
  7258. WBUFW(buf,8)=-1;
  7259. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7260. }
  7261. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7262. /// 0215 <msg id>.L
  7263. /// msg id:
  7264. /// 0x15 = End all negative status (PA_GOSPEL)
  7265. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7266. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7267. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7268. /// 0x19 = All stats +20 (PA_GOSPEL)
  7269. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7270. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7271. /// 0x1e = DEF +25% (PA_GOSPEL)
  7272. /// 0x1f = ATK +100% (PA_GOSPEL)
  7273. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7274. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7275. /// ? = nothing
  7276. void clif_gospel_info(struct map_session_data *sd, int type)
  7277. {
  7278. int fd=sd->fd;
  7279. WFIFOHEAD(fd,packet_len(0x215));
  7280. WFIFOW(fd,0)=0x215;
  7281. WFIFOL(fd,2)=type;
  7282. WFIFOSET(fd, packet_len(0x215));
  7283. }
  7284. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7285. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7286. /// result:
  7287. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7288. /// star:
  7289. /// 0 = Place of the Sun
  7290. /// 1 = Place of the Moon
  7291. /// 2 = Place of the Stars
  7292. /// 1 = Star Gladiator %s's %s: <mapname>
  7293. /// star:
  7294. /// 0 = Place of the Sun
  7295. /// 1 = Place of the Moon
  7296. /// 2 = Place of the Stars
  7297. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7298. /// star:
  7299. /// 0 = Target of the Sun
  7300. /// 1 = Target of the Moon
  7301. /// 2 = Target of the Stars
  7302. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7303. /// star:
  7304. /// 0 = Monster of the Sun
  7305. /// 1 = Monster of the Moon
  7306. /// 2 = Monster of the Stars
  7307. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7308. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7309. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7310. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7311. /// 40 = Target HP : <monster_id used as HP>
  7312. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7313. {
  7314. int fd = sd->fd;
  7315. WFIFOHEAD(fd,packet_len(0x20e));
  7316. WFIFOW(fd,0) = 0x20e;
  7317. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7318. WFIFOL(fd,26) = monster_id;
  7319. WFIFOB(fd,30) = star;
  7320. WFIFOB(fd,31) = result;
  7321. WFIFOSET(fd,packet_len(0x20e));
  7322. }
  7323. /*==========================================
  7324. * Info about Star Glaldiator save map [Komurka]
  7325. * type: 1: Information, 0: Map registered
  7326. *------------------------------------------*/
  7327. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7328. {
  7329. char mapname[MAP_NAME_LENGTH_EXT];
  7330. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7331. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7332. }
  7333. /*==========================================
  7334. * Info about Star Glaldiator hate mob [Komurka]
  7335. * type: 1: Register mob, 0: Information.
  7336. *------------------------------------------*/
  7337. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7338. {
  7339. if( pcdb_checkid(class_) )
  7340. {
  7341. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7342. }
  7343. else if( mobdb_checkid(class_) )
  7344. {
  7345. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7346. }
  7347. else
  7348. {
  7349. 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);
  7350. }
  7351. }
  7352. /*==========================================
  7353. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7354. *------------------------------------------*/
  7355. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7356. {
  7357. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7358. }
  7359. /*==========================================
  7360. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7361. *------------------------------------------*/
  7362. void clif_feel_hate_reset(struct map_session_data *sd)
  7363. {
  7364. clif_starskill(sd, "", 0, 0, 30);
  7365. }
  7366. /// Equip window (un)tick ack (ZC_CONFIG).
  7367. /// 02d9 <type>.L <value>.L
  7368. /// type:
  7369. /// 0 = open equip window
  7370. /// value:
  7371. /// 0 = disabled
  7372. /// 1 = enabled
  7373. void clif_equiptickack(struct map_session_data* sd, int flag)
  7374. {
  7375. int fd;
  7376. nullpo_retv(sd);
  7377. fd = sd->fd;
  7378. WFIFOHEAD(fd, packet_len(0x2d9));
  7379. WFIFOW(fd, 0) = 0x2d9;
  7380. WFIFOL(fd, 2) = 0;
  7381. WFIFOL(fd, 6) = flag;
  7382. WFIFOSET(fd, packet_len(0x2d9));
  7383. }
  7384. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7385. /// 02da <open equip window>.B
  7386. /// open equip window:
  7387. /// 0 = disabled
  7388. /// 1 = enabled
  7389. void clif_equipcheckbox(struct map_session_data* sd)
  7390. {
  7391. int fd;
  7392. nullpo_retv(sd);
  7393. fd = sd->fd;
  7394. WFIFOHEAD(fd, packet_len(0x2da));
  7395. WFIFOW(fd, 0) = 0x2da;
  7396. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7397. WFIFOSET(fd, packet_len(0x2da));
  7398. }
  7399. /// Sends info about a player's equipped items.
  7400. /// 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)
  7401. /// 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)
  7402. /// 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)
  7403. /// 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)
  7404. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7405. {
  7406. uint8* buf;
  7407. int i, n, fd, offset = 0;
  7408. #if PACKETVER < 20100629
  7409. const int s = 26;
  7410. #else
  7411. const int s = 28;
  7412. #endif
  7413. nullpo_retv(sd);
  7414. nullpo_retv(tsd);
  7415. fd = sd->fd;
  7416. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7417. buf = WFIFOP(fd,0);
  7418. #if PACKETVER < 20101124
  7419. WBUFW(buf, 0) = 0x2d7;
  7420. #else
  7421. WBUFW(buf, 0) = 0x859;
  7422. #endif
  7423. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7424. WBUFW(buf,28) = tsd->status.class_;
  7425. WBUFW(buf,30) = tsd->vd.hair_style;
  7426. WBUFW(buf,32) = tsd->vd.head_bottom;
  7427. WBUFW(buf,34) = tsd->vd.head_mid;
  7428. WBUFW(buf,36) = tsd->vd.head_top;
  7429. #if PACKETVER >= 20110111
  7430. WBUFW(buf,38) = tsd->vd.robe;
  7431. offset+= 2;
  7432. buf = WBUFP(buf,2);
  7433. #endif
  7434. WBUFW(buf,38) = tsd->vd.hair_color;
  7435. WBUFW(buf,40) = tsd->vd.cloth_color;
  7436. WBUFB(buf,42) = tsd->vd.sex;
  7437. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7438. {
  7439. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7440. continue;
  7441. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7442. continue;
  7443. // Inventory position
  7444. WBUFW(buf, n*s+43) = i + 2;
  7445. // Add refine, identify flag, element, etc.
  7446. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7447. // Add cards
  7448. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7449. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7450. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7451. WBUFW(buf, n*s+67) = 0;
  7452. #if PACKETVER >= 20100629
  7453. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7454. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7455. else
  7456. WBUFW(buf, n*s+69) = 0;
  7457. #endif
  7458. n++;
  7459. }
  7460. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7461. WFIFOSET(fd, WFIFOW(fd, 2));
  7462. }
  7463. /// Display msgstringtable.txt string (ZC_MSG).
  7464. /// 0291 <message>.W
  7465. void clif_msg(struct map_session_data* sd, unsigned short id)
  7466. {
  7467. int fd;
  7468. nullpo_retv(sd);
  7469. fd = sd->fd;
  7470. WFIFOHEAD(fd, packet_len(0x291));
  7471. WFIFOW(fd, 0) = 0x291;
  7472. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7473. WFIFOSET(fd, packet_len(0x291));
  7474. }
  7475. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7476. /// 0x7e2 <message>.W <value>.L
  7477. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7478. {
  7479. int fd = sd->fd;
  7480. WFIFOHEAD(fd, packet_len(0x7e2));
  7481. WFIFOW(fd,0) = 0x7e2;
  7482. WFIFOW(fd,2) = id;
  7483. WFIFOL(fd,4) = value;
  7484. WFIFOSET(fd, packet_len(0x7e2));
  7485. }
  7486. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7487. /// 07e6 <skill id>.W <msg id>.L
  7488. ///
  7489. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7490. /// "[SkillName] Message"
  7491. void clif_msg_skill(struct map_session_data* sd, unsigned short skill_id, int msg_id)
  7492. {
  7493. int fd = sd->fd;
  7494. WFIFOHEAD(fd, packet_len(0x7e6));
  7495. WFIFOW(fd,0) = 0x7e6;
  7496. WFIFOW(fd,2) = skill_id;
  7497. WFIFOL(fd,4) = msg_id;
  7498. WFIFOSET(fd, packet_len(0x7e6));
  7499. }
  7500. /// View player equip request denied
  7501. void clif_viewequip_fail(struct map_session_data* sd)
  7502. {
  7503. clif_msg(sd, 0x54d);
  7504. }
  7505. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7506. /// Returns true if the packet was parsed successfully.
  7507. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7508. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7509. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7510. {
  7511. char *text, *name, *message;
  7512. unsigned int packetlen, textlen, namelen, messagelen;
  7513. int fd = sd->fd;
  7514. *name_ = NULL;
  7515. *namelen_ = 0;
  7516. *message_ = NULL;
  7517. *messagelen_ = 0;
  7518. packetlen = RFIFOW(fd,2);
  7519. // basic structure checks
  7520. if( packetlen < 4 + 1 )
  7521. { // 4-byte header and at least an empty string is expected
  7522. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7523. return false;
  7524. }
  7525. text = (char*)RFIFOP(fd,4);
  7526. textlen = packetlen - 4;
  7527. // process <name> part of the packet
  7528. if( format == 0 )
  7529. {// name and message are separated by ' : '
  7530. // validate name
  7531. name = text;
  7532. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7533. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7534. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7535. {
  7536. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7537. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7538. set_eof(fd); // Just kick them out to correct it.
  7539. return false;
  7540. }
  7541. message = name + namelen + 3;
  7542. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7543. }
  7544. else
  7545. {// name has fixed width
  7546. if( textlen < NAME_LENGTH + 1 )
  7547. {
  7548. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7549. return false;
  7550. }
  7551. // validate name
  7552. name = text;
  7553. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7554. if( name[namelen] != '\0' )
  7555. { // only restriction is that the name must be zero-terminated
  7556. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7557. return false;
  7558. }
  7559. message = name + NAME_LENGTH;
  7560. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7561. }
  7562. if( messagelen != strnlen(message, messagelen)+1 )
  7563. { // the declared length must match real length
  7564. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7565. return false;
  7566. }
  7567. // verify <message> part of the packet
  7568. if( message[messagelen-1] != '\0' )
  7569. { // message must be zero-terminated
  7570. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7571. return false;
  7572. }
  7573. if( messagelen > CHAT_SIZE_MAX-1 )
  7574. { // messages mustn't be too long
  7575. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7576. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7577. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7578. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7579. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7580. return false;
  7581. }
  7582. *name_ = name;
  7583. *namelen_ = namelen;
  7584. *message_ = message;
  7585. *messagelen_ = messagelen;
  7586. return true;
  7587. }
  7588. // ---------------------
  7589. // clif_guess_PacketVer
  7590. // ---------------------
  7591. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7592. // error codes:
  7593. // 0 - Success
  7594. // 1 - Unknown packet_ver
  7595. // 2 - Invalid account_id
  7596. // 3 - Invalid char_id
  7597. // 4 - Invalid login_id1 (reserved)
  7598. // 5 - Invalid client_tick (reserved)
  7599. // 6 - Invalid sex
  7600. // Only the first 'invalid' error that appears is used.
  7601. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7602. {
  7603. static int err = 1;
  7604. static int packet_ver = -1;
  7605. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7606. if (get_previous)
  7607. {//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]
  7608. if( error )
  7609. *error = err;
  7610. return packet_ver;
  7611. }
  7612. //By default, start searching on the default one.
  7613. err = 1;
  7614. packet_ver = clif_config.packet_db_ver;
  7615. cmd = RFIFOW(fd,0);
  7616. packet_len = RFIFOREST(fd);
  7617. #define SET_ERROR(n) \
  7618. if( err == 1 )\
  7619. err = n;\
  7620. //define SET_ERROR
  7621. // FIXME: If the packet is not received at once, this will FAIL.
  7622. // Figure out, when it happens, that only part of the packet is
  7623. // received, or fix the function to be able to deal with that
  7624. // case.
  7625. #define CHECK_PACKET_VER() \
  7626. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7627. ;/* not wanttoconnection or wrong length */\
  7628. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7629. { SET_ERROR(2); }/* invalid account_id */\
  7630. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7631. { SET_ERROR(3); }/* invalid char_id */\
  7632. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7633. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7634. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7635. { SET_ERROR(6); }/* invalid sex */\
  7636. else\
  7637. {\
  7638. err = 0;\
  7639. if( error )\
  7640. *error = 0;\
  7641. return packet_ver;\
  7642. }\
  7643. //define CHECK_PACKET_VER
  7644. CHECK_PACKET_VER();//Default packet version found.
  7645. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7646. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7647. CHECK_PACKET_VER();
  7648. }
  7649. if( error )
  7650. *error = err;
  7651. packet_ver = -1;
  7652. return -1;
  7653. #undef SET_ERROR
  7654. #undef CHECK_PACKET_VER
  7655. }
  7656. // ------------
  7657. // clif_parse_*
  7658. // ------------
  7659. // Parses incoming (player) connection
  7660. /// Request to connect to map-server.
  7661. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7662. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7663. /// There are various variants of this packet, some of them have padding between fields.
  7664. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7665. {
  7666. struct block_list* bl;
  7667. struct auth_node* node;
  7668. int cmd, account_id, char_id, login_id1, sex;
  7669. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7670. 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])
  7671. if (sd) {
  7672. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7673. return;
  7674. }
  7675. // Only valid packet version get here
  7676. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7677. cmd = RFIFOW(fd,0);
  7678. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7679. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7680. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7681. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7682. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7683. if( packet_ver < 5 || // reject really old client versions
  7684. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7685. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7686. {// packet version rejected
  7687. 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));
  7688. WFIFOHEAD(fd,packet_len(0x6a));
  7689. WFIFOW(fd,0) = 0x6a;
  7690. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7691. WFIFOSET(fd,packet_len(0x6a));
  7692. set_eof(fd);
  7693. return;
  7694. }
  7695. if( runflag != MAPSERVER_ST_RUNNING )
  7696. {// not allowed
  7697. clif_authfail_fd(fd,1);// server closed
  7698. return;
  7699. }
  7700. //Check for double login.
  7701. bl = map_id2bl(account_id);
  7702. if(bl && bl->type != BL_PC) {
  7703. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7704. WFIFOHEAD(fd,packet_len(0x6a));
  7705. WFIFOW(fd,0) = 0x6a;
  7706. WFIFOB(fd,2) = 3; // Rejected by server
  7707. WFIFOSET(fd,packet_len(0x6a));
  7708. set_eof(fd);
  7709. return;
  7710. }
  7711. if (bl ||
  7712. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7713. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7714. {
  7715. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7716. return;
  7717. }
  7718. CREATE(sd, TBL_PC, 1);
  7719. sd->fd = fd;
  7720. sd->packet_ver = packet_ver;
  7721. session[fd]->session_data = sd;
  7722. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7723. #if PACKETVER < 20070521
  7724. WFIFOHEAD(fd,4);
  7725. WFIFOL(fd,0) = sd->bl.id;
  7726. WFIFOSET(fd,4);
  7727. #else
  7728. WFIFOHEAD(fd,packet_len(0x283));
  7729. WFIFOW(fd,0) = 0x283;
  7730. WFIFOL(fd,2) = sd->bl.id;
  7731. WFIFOSET(fd,packet_len(0x283));
  7732. #endif
  7733. chrif_authreq(sd);
  7734. }
  7735. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7736. /// 007d
  7737. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7738. {
  7739. if(sd->bl.prev != NULL)
  7740. return;
  7741. if (!sd->state.active)
  7742. { //Character loading is not complete yet!
  7743. //Let pc_reg_received reinvoke this when ready.
  7744. sd->state.connect_new = 0;
  7745. return;
  7746. }
  7747. if (sd->state.rewarp)
  7748. { //Rewarp player.
  7749. sd->state.rewarp = 0;
  7750. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7751. return;
  7752. }
  7753. sd->state.warping = 0;
  7754. // look
  7755. #if PACKETVER < 4
  7756. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7757. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7758. #else
  7759. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7760. #endif
  7761. if(sd->vd.cloth_color)
  7762. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7763. // item
  7764. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7765. pc_checkitem(sd);
  7766. // cart
  7767. if(pc_iscarton(sd)) {
  7768. clif_cartlist(sd);
  7769. clif_updatestatus(sd,SP_CARTINFO);
  7770. }
  7771. // weight
  7772. clif_updatestatus(sd,SP_WEIGHT);
  7773. clif_updatestatus(sd,SP_MAXWEIGHT);
  7774. // guild
  7775. // (needs to go before clif_spawn() to show guild emblems correctly)
  7776. if(sd->status.guild_id)
  7777. guild_send_memberinfoshort(sd,1);
  7778. if(battle_config.pc_invincible_time > 0) {
  7779. if(map_flag_gvg(sd->bl.m))
  7780. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7781. else
  7782. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7783. }
  7784. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7785. map_spawnmobs(sd->bl.m);
  7786. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7787. {// increment the number of pvp players on the map
  7788. map[sd->bl.m].users_pvp++;
  7789. }
  7790. if( map[sd->bl.m].instance_id )
  7791. {
  7792. instance[map[sd->bl.m].instance_id].users++;
  7793. instance_check_idle(map[sd->bl.m].instance_id);
  7794. }
  7795. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7796. // reset the callshop flag if the player changes map
  7797. sd->state.callshop = 0;
  7798. map_addblock(&sd->bl);
  7799. clif_spawn(&sd->bl);
  7800. // Party
  7801. // (needs to go after clif_spawn() to show hp bars correctly)
  7802. if(sd->status.party_id) {
  7803. party_send_movemap(sd);
  7804. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7805. }
  7806. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7807. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7808. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7809. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7810. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7811. sd->pvp_rank = 0;
  7812. sd->pvp_lastusers = 0;
  7813. sd->pvp_point = 5;
  7814. sd->pvp_won = 0;
  7815. sd->pvp_lost = 0;
  7816. }
  7817. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7818. } else
  7819. // set flag, if it's a duel [LuzZza]
  7820. if(sd->duel_group)
  7821. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7822. if (map[sd->bl.m].flag.gvg_dungeon)
  7823. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7824. if( map_flag_gvg(sd->bl.m) )
  7825. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7826. // info about nearby objects
  7827. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7828. 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);
  7829. // pet
  7830. if( sd->pd )
  7831. {
  7832. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7833. { //Return the pet to egg. [Skotlex]
  7834. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7835. pet_menu(sd, 3); //Option 3 is return to egg.
  7836. }
  7837. else
  7838. {
  7839. map_addblock(&sd->pd->bl);
  7840. clif_spawn(&sd->pd->bl);
  7841. clif_send_petdata(sd,sd->pd,0,0);
  7842. clif_send_petstatus(sd);
  7843. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7844. }
  7845. }
  7846. //homunculus [blackhole89]
  7847. if( merc_is_hom_active(sd->hd) )
  7848. {
  7849. map_addblock(&sd->hd->bl);
  7850. clif_spawn(&sd->hd->bl);
  7851. clif_send_homdata(sd,SP_ACK,0);
  7852. clif_hominfo(sd,sd->hd,1);
  7853. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7854. clif_homskillinfoblock(sd);
  7855. if( battle_config.hom_setting&0x8 )
  7856. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7857. if( !(battle_config.hom_setting&0x2) )
  7858. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7859. }
  7860. if( sd->md ) {
  7861. map_addblock(&sd->md->bl);
  7862. clif_spawn(&sd->md->bl);
  7863. clif_mercenary_info(sd);
  7864. clif_mercenary_skillblock(sd);
  7865. }
  7866. if( sd->ed ) {
  7867. map_addblock(&sd->ed->bl);
  7868. clif_spawn(&sd->ed->bl);
  7869. clif_elemental_info(sd);
  7870. clif_elemental_updatestatus(sd,SP_HP);
  7871. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.matk_max);
  7872. clif_elemental_updatestatus(sd,SP_SP);
  7873. }
  7874. if(sd->state.connect_new) {
  7875. int lv;
  7876. sd->state.connect_new = 0;
  7877. clif_skillinfoblock(sd);
  7878. clif_hotkeys_send(sd);
  7879. clif_updatestatus(sd,SP_BASEEXP);
  7880. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7881. clif_updatestatus(sd,SP_JOBEXP);
  7882. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7883. clif_updatestatus(sd,SP_SKILLPOINT);
  7884. clif_initialstatus(sd);
  7885. if (sd->sc.option&OPTION_FALCON)
  7886. clif_status_load(&sd->bl, SI_FALCON, 1);
  7887. if (sd->sc.option&OPTION_RIDING)
  7888. clif_status_load(&sd->bl, SI_RIDING, 1);
  7889. if(sd->status.manner < 0)
  7890. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7891. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7892. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7893. if(sd->bl.m == sd->feel_map[0].m
  7894. || sd->bl.m == sd->feel_map[1].m
  7895. || sd->bl.m == sd->feel_map[2].m)
  7896. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7897. }
  7898. if(sd->pd && sd->pd->pet.intimate > 900)
  7899. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7900. if(merc_is_hom_active(sd->hd))
  7901. merc_hom_init_timers(sd->hd);
  7902. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7903. {
  7904. sd->state.night = 1;
  7905. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7906. }
  7907. // Notify everyone that this char logged in [Skotlex].
  7908. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7909. //Login Event
  7910. npc_script_event(sd, NPCE_LOGIN);
  7911. } else {
  7912. //For some reason the client "loses" these on warp/map-change.
  7913. clif_updatestatus(sd,SP_STR);
  7914. clif_updatestatus(sd,SP_AGI);
  7915. clif_updatestatus(sd,SP_VIT);
  7916. clif_updatestatus(sd,SP_INT);
  7917. clif_updatestatus(sd,SP_DEX);
  7918. clif_updatestatus(sd,SP_LUK);
  7919. // abort currently running script
  7920. sd->state.using_fake_npc = 0;
  7921. sd->state.menu_or_input = 0;
  7922. sd->npc_menu = 0;
  7923. if(sd->npc_id)
  7924. npc_event_dequeue(sd);
  7925. }
  7926. if( sd->state.changemap )
  7927. {// restore information that gets lost on map-change
  7928. #if PACKETVER >= 20070918
  7929. clif_partyinvitationstate(sd);
  7930. clif_equipcheckbox(sd);
  7931. #endif
  7932. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7933. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7934. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7935. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7936. { //Display night.
  7937. if( !sd->state.night )
  7938. {
  7939. sd->state.night = 1;
  7940. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7941. }
  7942. }
  7943. else if( sd->state.night )
  7944. { //Clear night display.
  7945. sd->state.night = 0;
  7946. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7947. }
  7948. if( map[sd->bl.m].flag.battleground )
  7949. {
  7950. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7951. if( map[sd->bl.m].flag.battleground == 2 )
  7952. clif_bg_updatescore_single(sd);
  7953. }
  7954. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7955. {
  7956. char output[128];
  7957. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7958. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7959. }
  7960. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7961. sd->state.changemap = false;
  7962. }
  7963. mail_clear(sd);
  7964. /* Guild Aura Init */
  7965. if( sd->state.gmaster_flag ) {
  7966. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  7967. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  7968. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  7969. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  7970. }
  7971. if(map[sd->bl.m].flag.loadevent) // Lance
  7972. npc_script_event(sd, NPCE_LOADMAP);
  7973. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7974. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7975. if (sd->sc.opt2) //Client loses these on warp.
  7976. clif_changeoption(&sd->bl);
  7977. clif_weather_check(sd);
  7978. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7979. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7980. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7981. else
  7982. sd->areanpc_id = 0;
  7983. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7984. if(pc_isdead(sd))
  7985. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7986. else {
  7987. skill_usave_trigger(sd);
  7988. clif_changed_dir(&sd->bl, SELF);
  7989. }
  7990. // Trigger skill effects if you appear standing on them
  7991. if(!battle_config.pc_invincible_time)
  7992. skill_unit_move(&sd->bl,gettick(),1);
  7993. }
  7994. /// Request for server's tick.
  7995. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  7996. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  7997. /// There are various variants of this packet, some of them have padding between fields.
  7998. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7999. {
  8000. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8001. WFIFOHEAD(fd, packet_len(0x7f));
  8002. WFIFOW(fd,0)=0x7f;
  8003. WFIFOL(fd,2)=gettick();
  8004. WFIFOSET(fd,packet_len(0x7f));
  8005. // removed until the socket problems are fixed. [FlavioJS]
  8006. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  8007. }
  8008. /// Sends hotkey bar.
  8009. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8010. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8011. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8012. void clif_hotkeys_send(struct map_session_data *sd) {
  8013. #ifdef HOTKEY_SAVING
  8014. const int fd = sd->fd;
  8015. int i;
  8016. #if PACKETVER < 20090603
  8017. const int cmd = 0x2b9;
  8018. #else
  8019. const int cmd = 0x7d9;
  8020. #endif
  8021. if (!fd) return;
  8022. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8023. WFIFOW(fd, 0) = cmd;
  8024. for(i = 0; i < MAX_HOTKEYS; i++) {
  8025. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8026. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8027. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8028. }
  8029. WFIFOSET(fd, packet_len(cmd));
  8030. #endif
  8031. }
  8032. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8033. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8034. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8035. #ifdef HOTKEY_SAVING
  8036. unsigned short idx;
  8037. int cmd;
  8038. cmd = RFIFOW(fd, 0);
  8039. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8040. if (idx >= MAX_HOTKEYS) return;
  8041. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8042. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8043. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8044. #endif
  8045. }
  8046. /// Displays cast-like progress bar (ZC_PROGRESS).
  8047. /// 02f0 <color>.L <time>.L
  8048. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8049. {
  8050. int fd = sd->fd;
  8051. WFIFOHEAD(fd,packet_len(0x2f0));
  8052. WFIFOW(fd,0) = 0x2f0;
  8053. WFIFOL(fd,2) = color;
  8054. WFIFOL(fd,6) = second;
  8055. WFIFOSET(fd,packet_len(0x2f0));
  8056. }
  8057. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8058. /// 02f2
  8059. void clif_progressbar_abort(struct map_session_data * sd)
  8060. {
  8061. int fd = sd->fd;
  8062. WFIFOHEAD(fd,packet_len(0x2f2));
  8063. WFIFOW(fd,0) = 0x2f2;
  8064. WFIFOSET(fd,packet_len(0x2f2));
  8065. }
  8066. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8067. /// 02f1
  8068. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8069. {
  8070. int npc_id = sd->progressbar.npc_id;
  8071. if( gettick() < sd->progressbar.timeout && sd->st )
  8072. sd->st->state = END;
  8073. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8074. npc_scriptcont(sd, npc_id);
  8075. }
  8076. /// Request to walk to a certain position on the current map.
  8077. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8078. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8079. /// There are various variants of this packet, some of them have padding between fields.
  8080. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8081. {
  8082. short x, y;
  8083. if (pc_isdead(sd)) {
  8084. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8085. return;
  8086. }
  8087. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8088. ; //You CAN walk on this OPT1 value.
  8089. else if( sd->progressbar.npc_id )
  8090. clif_progressbar_abort(sd);
  8091. else if (pc_cant_act(sd))
  8092. return;
  8093. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8094. return;
  8095. pc_delinvincibletimer(sd);
  8096. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8097. //Set last idle time... [Skotlex]
  8098. sd->idletime = last_tick;
  8099. unit_walktoxy(&sd->bl, x, y, 4);
  8100. }
  8101. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8102. /// 018a <type>.W
  8103. /// type:
  8104. /// 0 = quit
  8105. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8106. {
  8107. WFIFOHEAD(fd,packet_len(0x18b));
  8108. WFIFOW(fd,0) = 0x18b;
  8109. /* Rovert's prevent logout option fixed [Valaris] */
  8110. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8111. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8112. {
  8113. set_eof(fd);
  8114. WFIFOW(fd,2)=0;
  8115. } else {
  8116. WFIFOW(fd,2)=1;
  8117. }
  8118. WFIFOSET(fd,packet_len(0x18b));
  8119. }
  8120. /// Requesting unit's name.
  8121. /// 0094 <id>.L (CZ_REQNAME)
  8122. /// 0368 <id>.L (CZ_REQNAME2)
  8123. /// There are various variants of this packet, some of them have padding between fields.
  8124. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8125. {
  8126. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8127. struct block_list* bl;
  8128. //struct status_change *sc;
  8129. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8130. id = sd->bl.id;
  8131. bl = map_id2bl(id);
  8132. if( bl == NULL )
  8133. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8134. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8135. return; // Block namerequests past view range
  8136. // 'see people in GM hide' cheat detection
  8137. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8138. sc = status_get_sc(bl);
  8139. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8140. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8141. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8142. ) {
  8143. char gm_msg[256];
  8144. 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);
  8145. ShowWarning(gm_msg);
  8146. // information is sent to all online GMs
  8147. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8148. return;
  8149. }
  8150. */
  8151. clif_charnameack(fd, bl);
  8152. }
  8153. /// Validates and processes global messages
  8154. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8155. /// There are various variants of this packet.
  8156. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8157. {
  8158. const char* text = (char*)RFIFOP(fd,4);
  8159. int textlen = RFIFOW(fd,2) - 4;
  8160. char *name, *message, *fakename = NULL;
  8161. int namelen, messagelen;
  8162. bool is_fake;
  8163. // validate packet and retrieve name and message
  8164. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8165. return;
  8166. if( is_atcommand(fd, sd, message, 1) )
  8167. return;
  8168. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8169. return;
  8170. if( battle_config.min_chat_delay )
  8171. { //[Skotlex]
  8172. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8173. return;
  8174. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8175. }
  8176. /**
  8177. * Fake Name Design by FatalEror (bug report #9)
  8178. **/
  8179. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8180. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8181. strcpy(fakename, sd->fakename);
  8182. strcat(fakename, " : ");
  8183. strcat(fakename, message);
  8184. textlen = strlen(fakename) + 1;
  8185. }
  8186. // send message to others (using the send buffer for temp. storage)
  8187. WFIFOHEAD(fd, 8 + textlen);
  8188. WFIFOW(fd,0) = 0x8d;
  8189. WFIFOW(fd,2) = 8 + textlen;
  8190. WFIFOL(fd,4) = sd->bl.id;
  8191. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8192. //FIXME: chat has range of 9 only
  8193. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8194. // send back message to the speaker
  8195. if( is_fake ) {
  8196. WFIFOW(fd,0) = 0x8e;
  8197. WFIFOW(fd,2) = textlen + 4;
  8198. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8199. aFree(fakename);
  8200. } else {
  8201. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8202. WFIFOW(fd,0) = 0x8e;
  8203. }
  8204. WFIFOSET(fd, WFIFOW(fd,2));
  8205. #ifdef PCRE_SUPPORT
  8206. // trigger listening npcs
  8207. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8208. #endif
  8209. // Chat logging type 'O' / Global Chat
  8210. 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);
  8211. }
  8212. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8213. /// Request to warp to a map on given coordinates.
  8214. /// 0140 <map name>.16B <x>.W <y>.W
  8215. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8216. {
  8217. char command[MAP_NAME_LENGTH_EXT+25];
  8218. char* map_name;
  8219. map_name = (char*)RFIFOP(fd,2);
  8220. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8221. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8222. is_atcommand(fd, sd, command, 1);
  8223. }
  8224. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8225. /// 009c <id>.L <head dir>.W <dir>.B
  8226. /// head dir:
  8227. /// 0 = straight
  8228. /// 1 = turned CW
  8229. /// 2 = turned CCW
  8230. /// dir:
  8231. /// 0 = north
  8232. /// 1 = northwest
  8233. /// 2 = west
  8234. /// 3 = southwest
  8235. /// 4 = south
  8236. /// 5 = southeast
  8237. /// 6 = east
  8238. /// 7 = northeast
  8239. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8240. {
  8241. unsigned char buf[64];
  8242. WBUFW(buf,0) = 0x9c;
  8243. WBUFL(buf,2) = bl->id;
  8244. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8245. WBUFB(buf,8) = unit_getdir(bl);
  8246. clif_send(buf, packet_len(0x9c), bl, target);
  8247. if (disguised(bl)) {
  8248. WBUFL(buf,2) = -bl->id;
  8249. WBUFW(buf,6) = 0;
  8250. clif_send(buf, packet_len(0x9c), bl, SELF);
  8251. }
  8252. }
  8253. /// Request to change own body and head direction.
  8254. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8255. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8256. /// There are various variants of this packet, some of them have padding between fields.
  8257. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8258. {
  8259. unsigned char headdir, dir;
  8260. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8261. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8262. pc_setdir(sd, dir, headdir);
  8263. clif_changed_dir(&sd->bl, AREA_WOS);
  8264. }
  8265. /// Request to show an emotion (CZ_REQ_EMOTION).
  8266. /// 00bf <type>.B
  8267. /// type:
  8268. /// @see enum emotion_type
  8269. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8270. {
  8271. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8272. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8273. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8274. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8275. return;
  8276. }
  8277. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8278. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8279. sd->emotionlasttime = time(NULL);
  8280. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8281. return;
  8282. }
  8283. sd->emotionlasttime = time(NULL);
  8284. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  8285. {// re-roll dice
  8286. emoticon = rnd()%6+E_DICE1;
  8287. }
  8288. clif_emotion(&sd->bl, emoticon);
  8289. } else
  8290. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8291. }
  8292. /// /w /who (CZ_REQ_USER_COUNT).
  8293. /// Request to display amount of currently connected players.
  8294. /// 00c1
  8295. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8296. {
  8297. WFIFOHEAD(fd,packet_len(0xc2));
  8298. WFIFOW(fd,0) = 0xc2;
  8299. WFIFOL(fd,2) = map_getusers();
  8300. WFIFOSET(fd,packet_len(0xc2));
  8301. }
  8302. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8303. {
  8304. if (pc_isdead(sd)) {
  8305. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8306. return;
  8307. }
  8308. if (sd->sc.count &&
  8309. (sd->sc.data[SC_TRICKDEAD] ||
  8310. sd->sc.data[SC_AUTOCOUNTER] ||
  8311. sd->sc.data[SC_BLADESTOP] ||
  8312. sd->sc.data[SC__MANHOLE] ||
  8313. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8314. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8315. return;
  8316. pc_stop_walking(sd, 1);
  8317. pc_stop_attack(sd);
  8318. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8319. target_id = sd->bl.id;
  8320. switch(action_type)
  8321. {
  8322. case 0x00: // once attack
  8323. case 0x07: // continuous attack
  8324. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8325. return;
  8326. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8327. return;
  8328. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8329. return;
  8330. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8331. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8332. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8333. return;
  8334. }
  8335. }
  8336. pc_delinvincibletimer(sd);
  8337. sd->idletime = last_tick;
  8338. unit_attack(&sd->bl, target_id, action_type != 0);
  8339. break;
  8340. case 0x02: // sitdown
  8341. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8342. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8343. break;
  8344. }
  8345. if(pc_issit(sd)) {
  8346. //Bugged client? Just refresh them.
  8347. clif_sitting(&sd->bl);
  8348. return;
  8349. }
  8350. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8351. break;
  8352. if (sd->sc.count && (
  8353. sd->sc.data[SC_DANCING] ||
  8354. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8355. )) //No sitting during these states either.
  8356. break;
  8357. pc_setsit(sd);
  8358. skill_sit(sd,1);
  8359. clif_sitting(&sd->bl);
  8360. break;
  8361. case 0x03: // standup
  8362. if (!pc_issit(sd)) {
  8363. //Bugged client? Just refresh them.
  8364. clif_standing(&sd->bl);
  8365. return;
  8366. }
  8367. pc_setstand(sd);
  8368. skill_sit(sd,0);
  8369. clif_standing(&sd->bl);
  8370. break;
  8371. }
  8372. }
  8373. /// Request for an action.
  8374. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8375. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8376. /// action:
  8377. /// 0 = attack
  8378. /// 1 = pick up item
  8379. /// 2 = sit down
  8380. /// 3 = stand up
  8381. /// 7 = continous attack
  8382. /// 12 = (touch skill?)
  8383. /// There are various variants of this packet, some of them have padding between fields.
  8384. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8385. {
  8386. clif_parse_ActionRequest_sub(sd,
  8387. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8388. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8389. gettick()
  8390. );
  8391. }
  8392. /// Response to the death/system menu (CZ_RESTART).
  8393. /// 00b2 <type>.B
  8394. /// type:
  8395. /// 0 = restart (respawn)
  8396. /// 1 = char-select (disconnect)
  8397. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8398. {
  8399. switch(RFIFOB(fd,2)) {
  8400. case 0x00:
  8401. pc_respawn(sd,CLR_RESPAWN);
  8402. break;
  8403. case 0x01:
  8404. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8405. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8406. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8407. { //Send to char-server for character selection.
  8408. chrif_charselectreq(sd, session[fd]->client_addr);
  8409. } else {
  8410. WFIFOHEAD(fd,packet_len(0x18b));
  8411. WFIFOW(fd,0)=0x18b;
  8412. WFIFOW(fd,2)=1;
  8413. WFIFOSET(fd,packet_len(0x018b));
  8414. }
  8415. break;
  8416. }
  8417. }
  8418. /// Validates and processes whispered messages (CZ_WHISPER).
  8419. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8420. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8421. {
  8422. struct map_session_data* dstsd;
  8423. int i;
  8424. char *target, *message;
  8425. int namelen, messagelen;
  8426. // validate packet and retrieve name and message
  8427. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8428. return;
  8429. if (is_atcommand(fd, sd, message, 1) )
  8430. return;
  8431. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8432. return;
  8433. if (battle_config.min_chat_delay)
  8434. { //[Skotlex]
  8435. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8436. return;
  8437. }
  8438. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8439. }
  8440. // Chat logging type 'W' / Whisper
  8441. 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);
  8442. //-------------------------------------------------------//
  8443. // Lordalfa - Paperboy - To whisper NPC commands //
  8444. //-------------------------------------------------------//
  8445. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8446. {
  8447. char* str = target+4; //Skip the NPC: string part.
  8448. struct npc_data* npc;
  8449. if ((npc = npc_name2id(str)))
  8450. {
  8451. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8452. char *split;
  8453. char output[256];
  8454. str = message;
  8455. // skip codepage indicator, if detected
  8456. if( str[0] == '|' && strlen(str) >= 4 )
  8457. str += 3;
  8458. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8459. {// Splits the message using '#' as separators
  8460. split = strchr(str,'#');
  8461. if( split == NULL )
  8462. { // use the remaining string
  8463. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8464. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8465. split_data[i][0] = '\0';
  8466. break;
  8467. }
  8468. *split = '\0';
  8469. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8470. str = split+1;
  8471. }
  8472. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8473. {
  8474. sprintf(output, "@whispervar%d$", i);
  8475. set_var(sd,output,(char *) split_data[i]);
  8476. }
  8477. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8478. npc_event(sd,output,0); // Calls the NPC label
  8479. return;
  8480. }
  8481. }
  8482. // Main chat [LuzZza]
  8483. if(strcmpi(target, main_chat_nick) == 0)
  8484. {
  8485. if(!sd->state.mainchat)
  8486. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8487. else {
  8488. // send the main message using inter-server system
  8489. intif_main_message( sd, message );
  8490. }
  8491. return;
  8492. }
  8493. // searching destination character
  8494. dstsd = map_nick2sd(target);
  8495. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8496. {
  8497. // player is not on this map-server
  8498. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8499. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8500. // and if we ask for 'Test', we must not contact 'test' player
  8501. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8502. intif_wis_message(sd, target, message, messagelen);
  8503. return;
  8504. }
  8505. // if player ignores everyone
  8506. if (dstsd->state.ignoreAll)
  8507. {
  8508. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8509. clif_wis_end(fd, 1); // 1: target character is not loged in
  8510. else
  8511. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8512. return;
  8513. }
  8514. // if player ignores the source character
  8515. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8516. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8517. { // source char present in ignore list
  8518. clif_wis_end(fd, 2); // 2: ignored by target
  8519. return;
  8520. }
  8521. // if player is autotrading
  8522. if( dstsd->state.autotrade == 1 )
  8523. {
  8524. char output[256];
  8525. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8526. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8527. return;
  8528. }
  8529. // notify sender of success
  8530. clif_wis_end(fd, 0); // 0: success to send wisper
  8531. // Normal message
  8532. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8533. }
  8534. /// /b /nb (CZ_BROADCAST).
  8535. /// Request to broadcast a message on whole server.
  8536. /// 0099 <packet len>.W <text>.?B 00
  8537. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8538. {
  8539. char command[CHAT_SIZE_MAX+11];
  8540. char* msg = (char*)RFIFOP(fd,4);
  8541. unsigned int len = RFIFOW(fd,2)-4;
  8542. // as the length varies depending on the command used, just block unreasonably long strings
  8543. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  8544. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8545. is_atcommand(fd, sd, command, 1);
  8546. }
  8547. /// Request to pick up an item.
  8548. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8549. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8550. /// There are various variants of this packet, some of them have padding between fields.
  8551. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8552. {
  8553. struct flooritem_data *fitem;
  8554. int map_object_id;
  8555. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8556. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8557. do {
  8558. if (pc_isdead(sd)) {
  8559. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8560. break;
  8561. }
  8562. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8563. break;
  8564. if (pc_cant_act(sd))
  8565. break;
  8566. if(sd->sc.count && (
  8567. sd->sc.data[SC_HIDING] ||
  8568. sd->sc.data[SC_CLOAKING] ||
  8569. sd->sc.data[SC_TRICKDEAD] ||
  8570. sd->sc.data[SC_BLADESTOP] ||
  8571. sd->sc.data[SC_CLOAKINGEXCEED] ||
  8572. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8573. )
  8574. break;
  8575. if (!pc_takeitem(sd, fitem))
  8576. break;
  8577. return;
  8578. } while (0);
  8579. // Client REQUIRES a fail packet or you can no longer pick items.
  8580. clif_additem(sd,0,0,6);
  8581. }
  8582. /// Request to drop an item.
  8583. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8584. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8585. /// There are various variants of this packet, some of them have padding between fields.
  8586. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8587. {
  8588. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8589. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8590. for(;;) {
  8591. if (pc_isdead(sd))
  8592. break;
  8593. if (pc_cant_act(sd))
  8594. break;
  8595. if (sd->sc.count && (
  8596. sd->sc.data[SC_AUTOCOUNTER] ||
  8597. sd->sc.data[SC_BLADESTOP] ||
  8598. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8599. ))
  8600. break;
  8601. if (!pc_dropitem(sd, item_index, item_amount))
  8602. break;
  8603. return;
  8604. }
  8605. //Because the client does not like being ignored.
  8606. clif_dropitem(sd, item_index,0);
  8607. }
  8608. /// Request to use an item.
  8609. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8610. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8611. /// There are various variants of this packet, some of them have padding between fields.
  8612. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8613. {
  8614. int n;
  8615. if (pc_isdead(sd)) {
  8616. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8617. return;
  8618. }
  8619. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  8620. return;
  8621. //This flag enables you to use items while in an NPC. [Skotlex]
  8622. if (sd->npc_id) {
  8623. if (sd->npc_id != sd->npc_item_flag)
  8624. return;
  8625. } else
  8626. if (pc_istrading(sd))
  8627. return;
  8628. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8629. sd->idletime = last_tick;
  8630. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8631. if(n <0 || n >= MAX_INVENTORY)
  8632. return;
  8633. if (!pc_useitem(sd,n))
  8634. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8635. }
  8636. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8637. /// 00a9 <index>.W <position>.W
  8638. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8639. {
  8640. int index;
  8641. if(pc_isdead(sd)) {
  8642. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8643. return;
  8644. }
  8645. index = RFIFOW(fd,2)-2;
  8646. if (index < 0 || index >= MAX_INVENTORY)
  8647. return; //Out of bounds check.
  8648. if(sd->npc_id) {
  8649. if (sd->npc_id != sd->npc_item_flag)
  8650. return;
  8651. } else if (sd->state.storage_flag || sd->sc.opt1)
  8652. ; //You can equip/unequip stuff while storage is open/under status changes
  8653. else if (pc_cant_act(sd))
  8654. return;
  8655. if(!sd->status.inventory[index].identify) {
  8656. clif_equipitemack(sd,index,0,0); // fail
  8657. return;
  8658. }
  8659. if(!sd->inventory_data[index])
  8660. return;
  8661. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8662. pet_equipitem(sd,index);
  8663. return;
  8664. }
  8665. //Client doesn't send the position for ammo.
  8666. if(sd->inventory_data[index]->type == IT_AMMO)
  8667. pc_equipitem(sd,index,EQP_AMMO);
  8668. else
  8669. pc_equipitem(sd,index,RFIFOW(fd,4));
  8670. }
  8671. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8672. /// 00ab <index>.W
  8673. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8674. {
  8675. int index;
  8676. if(pc_isdead(sd)) {
  8677. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8678. return;
  8679. }
  8680. if (sd->state.storage_flag || sd->sc.opt1)
  8681. ; //You can equip/unequip stuff while storage is open/under status changes
  8682. else if (pc_cant_act(sd))
  8683. return;
  8684. index = RFIFOW(fd,2)-2;
  8685. pc_unequipitem(sd,index,1);
  8686. }
  8687. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8688. /// 0090 <id>.L <type>.B
  8689. /// type:
  8690. /// 1 = click
  8691. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8692. {
  8693. struct block_list *bl;
  8694. if(pc_isdead(sd)) {
  8695. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8696. return;
  8697. }
  8698. if (pc_cant_act(sd))
  8699. return;
  8700. bl = map_id2bl(RFIFOL(fd,2));
  8701. if (!bl) return;
  8702. switch (bl->type) {
  8703. case BL_MOB:
  8704. case BL_PC:
  8705. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8706. break;
  8707. case BL_NPC:
  8708. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8709. npc_click(sd,(TBL_NPC*)bl);
  8710. break;
  8711. }
  8712. }
  8713. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8714. /// 00c5 <id>.L <type>.B
  8715. /// type:
  8716. /// 0 = buy
  8717. /// 1 = sell
  8718. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8719. {
  8720. if (sd->state.trading)
  8721. return;
  8722. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8723. }
  8724. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8725. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8726. ///
  8727. /// R 00ca <result>.b
  8728. /// result = 00 -> "The deal has successfully completed."
  8729. /// result = 01 -> "You do not have enough zeny."
  8730. /// result = 02 -> "You are over your Weight Limit."
  8731. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8732. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8733. {
  8734. int n = (RFIFOW(fd,2)-4) /4;
  8735. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8736. int result;
  8737. if( sd->state.trading || !sd->npc_shopid )
  8738. result = 1;
  8739. else
  8740. result = npc_buylist(sd,n,item_list);
  8741. sd->npc_shopid = 0; //Clear shop data.
  8742. WFIFOHEAD(fd,packet_len(0xca));
  8743. WFIFOW(fd,0) = 0xca;
  8744. WFIFOB(fd,2) = result;
  8745. WFIFOSET(fd,packet_len(0xca));
  8746. }
  8747. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8748. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8749. ///
  8750. /// S 00cb <result>.B
  8751. /// result = 00 -> "The deal has successfully completed."
  8752. /// result = 01 -> "The deal has failed."
  8753. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8754. {
  8755. int fail=0,n;
  8756. unsigned short *item_list;
  8757. n = (RFIFOW(fd,2)-4) /4;
  8758. item_list = (unsigned short*)RFIFOP(fd,4);
  8759. if (sd->state.trading || !sd->npc_shopid)
  8760. fail = 1;
  8761. else
  8762. fail = npc_selllist(sd,n,item_list);
  8763. sd->npc_shopid = 0; //Clear shop data.
  8764. WFIFOHEAD(fd,packet_len(0xcb));
  8765. WFIFOW(fd,0)=0xcb;
  8766. WFIFOB(fd,2)=fail;
  8767. WFIFOSET(fd,packet_len(0xcb));
  8768. }
  8769. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8770. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8771. /// type:
  8772. /// 0 = private
  8773. /// 1 = public
  8774. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8775. {
  8776. int len = RFIFOW(fd,2)-15;
  8777. int limit = RFIFOW(fd,4);
  8778. bool pub = (RFIFOB(fd,6) != 0);
  8779. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8780. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8781. char s_password[CHATROOM_PASS_SIZE];
  8782. char s_title[CHATROOM_TITLE_SIZE];
  8783. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8784. return;
  8785. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8786. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8787. return;
  8788. }
  8789. if( len <= 0 )
  8790. return; // invalid input
  8791. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8792. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8793. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8794. }
  8795. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8796. /// 00d9 <chat ID>.L <passwd>.8B
  8797. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8798. {
  8799. int chatid = RFIFOL(fd,2);
  8800. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8801. chat_joinchat(sd,chatid,password);
  8802. }
  8803. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8804. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8805. /// type:
  8806. /// 0 = private
  8807. /// 1 = public
  8808. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8809. {
  8810. int len = RFIFOW(fd,2)-15;
  8811. int limit = RFIFOW(fd,4);
  8812. bool pub = (RFIFOB(fd,6) != 0);
  8813. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8814. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8815. char s_password[CHATROOM_PASS_SIZE];
  8816. char s_title[CHATROOM_TITLE_SIZE];
  8817. if( len <= 0 )
  8818. return; // invalid input
  8819. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8820. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8821. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8822. }
  8823. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8824. /// 00e0 <role>.L <nick>.24B
  8825. /// role:
  8826. /// 0 = owner
  8827. /// 1 = normal
  8828. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8829. {
  8830. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8831. }
  8832. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8833. /// 00e2 <name>.24B
  8834. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8835. {
  8836. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8837. }
  8838. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8839. /// 00e3
  8840. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8841. {
  8842. chat_leavechat(sd,0);
  8843. }
  8844. //Handles notifying asker and rejecter of what has just ocurred.
  8845. //Type is used to determine the correct msg_txt to use:
  8846. //0:
  8847. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8848. {
  8849. const char* msg;
  8850. char output[256];
  8851. // Your request has been rejected by autoreject option.
  8852. msg = msg_txt(392);
  8853. clif_disp_onlyself(src, msg, strlen(msg));
  8854. //Notice that a request was rejected.
  8855. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8856. clif_disp_onlyself(target, output, strlen(output));
  8857. }
  8858. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8859. /// 00e4 <account id>.L
  8860. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8861. {
  8862. struct map_session_data *t_sd;
  8863. t_sd = map_id2sd(RFIFOL(fd,2));
  8864. if(!sd->chatID && pc_cant_act(sd))
  8865. return; //You can trade while in a chatroom.
  8866. // @noask [LuzZza]
  8867. if(t_sd && t_sd->state.noask) {
  8868. clif_noask_sub(sd, t_sd, 0);
  8869. return;
  8870. }
  8871. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8872. {
  8873. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8874. return;
  8875. }
  8876. trade_traderequest(sd,t_sd);
  8877. }
  8878. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8879. /// 00e6 <result>.B
  8880. /// result:
  8881. /// 3 = accepted
  8882. /// 4 = rejected
  8883. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8884. {
  8885. trade_tradeack(sd,RFIFOB(fd,2));
  8886. }
  8887. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  8888. /// 00e8 <index>.W <amount>.L
  8889. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8890. {
  8891. short index = RFIFOW(fd,2);
  8892. int amount = RFIFOL(fd,4);
  8893. if( index == 0 )
  8894. trade_tradeaddzeny(sd, amount);
  8895. else
  8896. trade_tradeadditem(sd, index, (short)amount);
  8897. }
  8898. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  8899. /// 00eb
  8900. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8901. {
  8902. trade_tradeok(sd);
  8903. }
  8904. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  8905. /// 00ed
  8906. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8907. {
  8908. trade_tradecancel(sd);
  8909. }
  8910. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  8911. /// 00ef
  8912. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8913. {
  8914. trade_tradecommit(sd);
  8915. }
  8916. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  8917. /// 0118
  8918. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8919. {
  8920. pc_stop_attack(sd);
  8921. }
  8922. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  8923. /// 0126 <index>.W <amount>.L
  8924. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8925. {
  8926. if (pc_istrading(sd))
  8927. return;
  8928. if (!pc_iscarton(sd))
  8929. return;
  8930. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8931. }
  8932. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  8933. /// 0127 <index>.W <amount>.L
  8934. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8935. {
  8936. if (!pc_iscarton(sd))
  8937. return;
  8938. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8939. }
  8940. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  8941. /// 012a
  8942. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8943. {
  8944. /**
  8945. * Attempts to remove these options when this function is called (will remove all available)
  8946. **/
  8947. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  8948. }
  8949. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  8950. /// 01af <num>.W
  8951. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8952. {
  8953. int type;
  8954. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8955. return;
  8956. type = (int)RFIFOW(fd,2);
  8957. if( (type == 5 && sd->status.base_level > 90) ||
  8958. (type == 4 && sd->status.base_level > 80) ||
  8959. (type == 3 && sd->status.base_level > 65) ||
  8960. (type == 2 && sd->status.base_level > 40) ||
  8961. (type == 1))
  8962. pc_setcart(sd,type);
  8963. }
  8964. /// Request to increase status (CZ_STATUS_CHANGE).
  8965. /// 00bb <status id>.W <amount>.B
  8966. /// status id:
  8967. /// SP_STR ~ SP_LUK
  8968. /// amount:
  8969. /// client sends always 1 for this, even when using /str+ and
  8970. /// the like
  8971. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8972. {
  8973. pc_statusup(sd,RFIFOW(fd,2));
  8974. }
  8975. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  8976. /// 0112 <skill id>.W
  8977. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8978. {
  8979. pc_skillup(sd,RFIFOW(fd,2));
  8980. }
  8981. 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)
  8982. {
  8983. int lv;
  8984. if( !hd )
  8985. return;
  8986. if( skillnotok_hom(skillnum, hd) )
  8987. return;
  8988. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8989. target_id = hd->bl.id;
  8990. if( hd->ud.skilltimer != INVALID_TIMER )
  8991. {
  8992. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  8993. }
  8994. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8995. return;
  8996. lv = merc_hom_checkskill(hd, skillnum);
  8997. if( skilllv > lv )
  8998. skilllv = lv;
  8999. if( skilllv )
  9000. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  9001. }
  9002. 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)
  9003. {
  9004. int lv;
  9005. if( !md )
  9006. return;
  9007. if( skillnotok_mercenary(skillnum, md) )
  9008. return;
  9009. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  9010. target_id = md->bl.id;
  9011. if( md->ud.skilltimer != INVALID_TIMER )
  9012. {
  9013. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  9014. }
  9015. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9016. return;
  9017. lv = mercenary_checkskill(md, skillnum);
  9018. if( skilllv > lv )
  9019. skilllv = lv;
  9020. if( skilllv )
  9021. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  9022. }
  9023. 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)
  9024. {
  9025. int lv;
  9026. if( !md )
  9027. return;
  9028. if( skillnotok_mercenary(skillnum, md) )
  9029. return;
  9030. if( md->ud.skilltimer != INVALID_TIMER )
  9031. return;
  9032. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9033. {
  9034. clif_skill_fail(md->master, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9035. return;
  9036. }
  9037. if( md->sc.data[SC_BASILICA] )
  9038. return;
  9039. lv = mercenary_checkskill(md, skillnum);
  9040. if( skilllv > lv )
  9041. skilllv = lv;
  9042. if( skilllv )
  9043. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  9044. }
  9045. /// Request to use a targeted skill.
  9046. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9047. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9048. /// There are various variants of this packet, some of them have padding between fields.
  9049. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9050. {
  9051. short skillnum, skilllv;
  9052. int tmp, target_id;
  9053. unsigned int tick = gettick();
  9054. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9055. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9056. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9057. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9058. tmp = skill_get_inf(skillnum);
  9059. if (tmp&INF_GROUND_SKILL || !tmp)
  9060. return; //Using a ground/passive skill on a target? WRONG.
  9061. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  9062. {
  9063. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  9064. return;
  9065. }
  9066. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9067. {
  9068. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  9069. return;
  9070. }
  9071. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9072. sd->idletime = last_tick;
  9073. if( pc_cant_act(sd) && !(skillnum == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9074. return;
  9075. if( pc_issit(sd) )
  9076. return;
  9077. if( skillnotok(skillnum, sd) )
  9078. return;
  9079. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9080. target_id = sd->bl.id; // never trust the client
  9081. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9082. target_id = sd->bl.id;
  9083. if( sd->ud.skilltimer != INVALID_TIMER )
  9084. {
  9085. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST )
  9086. return;
  9087. }
  9088. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  9089. {
  9090. if( sd->skillitem != skillnum )
  9091. {
  9092. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9093. return;
  9094. }
  9095. }
  9096. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9097. return;
  9098. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9099. return; // On basilica only caster can use Basilica again to stop it.
  9100. if( sd->menuskill_id ) {
  9101. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9102. clif_menuskill_clear(sd); //Cancel pet capture.
  9103. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9104. return; //Can't use skills while a menu is open.
  9105. }
  9106. if( sd->skillitem == skillnum ) {
  9107. if( skilllv != sd->skillitemlv )
  9108. skilllv = sd->skillitemlv;
  9109. if( !(tmp&INF_SELF_SKILL) )
  9110. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9111. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9112. return;
  9113. }
  9114. sd->skillitem = sd->skillitemlv = 0;
  9115. if( skillnum >= GD_SKILLBASE ) {
  9116. if( sd->state.gmaster_flag )
  9117. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  9118. else
  9119. skilllv = 0;
  9120. } else {
  9121. tmp = pc_checkskill(sd, skillnum);
  9122. if( skilllv > tmp )
  9123. skilllv = tmp;
  9124. }
  9125. pc_delinvincibletimer(sd);
  9126. if( skilllv )
  9127. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9128. }
  9129. /*==========================================
  9130. * Client tells server he'd like to use AoE skill id 'skillnum' of level 'skilllv' on 'x','y' location
  9131. *------------------------------------------*/
  9132. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  9133. {
  9134. unsigned int tick = gettick();
  9135. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  9136. return; //Using a target skill on the ground? WRONG.
  9137. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9138. {
  9139. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  9140. return;
  9141. }
  9142. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9143. sd->idletime = last_tick;
  9144. if( skillnotok(skillnum, sd) )
  9145. return;
  9146. if( skillmoreinfo != -1 )
  9147. {
  9148. if( pc_issit(sd) )
  9149. {
  9150. clif_skill_fail(sd, skillnum, USESKILL_FAIL_LEVEL, 0);
  9151. return;
  9152. }
  9153. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9154. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9155. }
  9156. if( sd->ud.skilltimer != INVALID_TIMER )
  9157. return;
  9158. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9159. if( sd->skillitem != skillnum ) {
  9160. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9161. return;
  9162. }
  9163. }
  9164. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9165. return;
  9166. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9167. return; // On basilica only caster can use Basilica again to stop it.
  9168. if( sd->menuskill_id ) {
  9169. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9170. clif_menuskill_clear(sd); //Cancel pet capture.
  9171. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9172. return; //Can't use skills while a menu is open.
  9173. }
  9174. pc_delinvincibletimer(sd);
  9175. if( sd->skillitem == skillnum ) {
  9176. if( skilllv != sd->skillitemlv )
  9177. skilllv = sd->skillitemlv;
  9178. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  9179. } else {
  9180. int lv;
  9181. sd->skillitem = sd->skillitemlv = 0;
  9182. if( (lv = pc_checkskill(sd, skillnum)) > 0 ) {
  9183. if( skilllv > lv )
  9184. skilllv = lv;
  9185. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  9186. }
  9187. }
  9188. }
  9189. /// Request to use a ground skill.
  9190. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9191. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9192. /// There are various variants of this packet, some of them have padding between fields.
  9193. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9194. {
  9195. if (pc_cant_act(sd))
  9196. return;
  9197. if (pc_issit(sd))
  9198. return;
  9199. clif_parse_UseSkillToPosSub(fd, sd,
  9200. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9201. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9202. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9203. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9204. -1 //Skill more info.
  9205. );
  9206. }
  9207. /// Request to use a ground skill with text.
  9208. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9209. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9210. /// There are various variants of this packet, some of them have padding between fields.
  9211. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9212. {
  9213. if (pc_cant_act(sd))
  9214. return;
  9215. if (pc_issit(sd))
  9216. return;
  9217. clif_parse_UseSkillToPosSub(fd, sd,
  9218. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9219. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9220. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9221. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9222. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9223. );
  9224. }
  9225. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9226. /// 011b <skill id>.W <map name>.16B
  9227. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9228. {
  9229. short skill_num = RFIFOW(fd,2);
  9230. char map_name[MAP_NAME_LENGTH];
  9231. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9232. if(skill_num != sd->menuskill_id)
  9233. return;
  9234. if( pc_cant_act(sd) ) {
  9235. clif_menuskill_clear(sd);
  9236. return;
  9237. }
  9238. pc_delinvincibletimer(sd);
  9239. skill_castend_map(sd,skill_num,map_name);
  9240. }
  9241. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9242. /// 011d
  9243. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9244. {
  9245. if (!pc_isdead(sd))
  9246. pc_memo(sd,-1);
  9247. }
  9248. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9249. /// 018e <name id>.W { <material id>.W }*3
  9250. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9251. {
  9252. switch( sd->menuskill_id ) {
  9253. case -1:
  9254. case AM_PHARMACY:
  9255. case RK_RUNEMASTERY:
  9256. case GC_CREATENEWPOISON:
  9257. break;
  9258. default:
  9259. return;
  9260. }
  9261. if (pc_istrading(sd)) {
  9262. //Make it fail to avoid shop exploits where you sell something different than you see.
  9263. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9264. clif_menuskill_clear(sd);
  9265. return;
  9266. }
  9267. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9268. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9269. clif_menuskill_clear(sd);
  9270. }
  9271. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9272. /// 025b <mk type>.W <name id>.W
  9273. /// mk type:
  9274. /// 1 = cooking
  9275. /// 2 = arrow
  9276. /// 3 = elemental
  9277. /// 4 = GN_MIX_COOKING
  9278. /// 5 = GN_MAKEBOMB
  9279. /// 6 = GN_S_PHARMACY
  9280. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9281. int type = RFIFOW(fd,2);
  9282. int nameid = RFIFOW(fd,4);
  9283. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9284. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9285. return;
  9286. if (pc_istrading(sd)) {
  9287. //Make it fail to avoid shop exploits where you sell something different than you see.
  9288. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9289. clif_menuskill_clear(sd);
  9290. return;
  9291. }
  9292. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9293. skill_produce_mix(sd,sd->menuskill_id,nameid,0,0,0,amount);
  9294. clif_menuskill_clear(sd);
  9295. }
  9296. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9297. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9298. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9299. {
  9300. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9301. return;
  9302. if (pc_istrading(sd)) {
  9303. //Make it fail to avoid shop exploits where you sell something different than you see.
  9304. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9305. clif_menuskill_clear(sd);
  9306. return;
  9307. }
  9308. skill_repairweapon(sd,RFIFOW(fd,2));
  9309. clif_menuskill_clear(sd);
  9310. }
  9311. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9312. /// 0222 <index>.L
  9313. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9314. {
  9315. int idx;
  9316. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9317. return;
  9318. if (pc_istrading(sd)) {
  9319. //Make it fail to avoid shop exploits where you sell something different than you see.
  9320. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9321. clif_menuskill_clear(sd);
  9322. return;
  9323. }
  9324. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9325. skill_weaponrefine(sd, idx-2);
  9326. clif_menuskill_clear(sd);
  9327. }
  9328. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9329. /// 00b8 <npc id>.L <choice>.B
  9330. /// choice:
  9331. /// 1~254 = menu item
  9332. /// 255 = cancel
  9333. /// NOTE: If there were more than 254 items in the list, choice
  9334. /// overflows to choice%256.
  9335. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9336. {
  9337. int npc_id = RFIFOL(fd,2);
  9338. uint8 select = RFIFOB(fd,6);
  9339. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  9340. {
  9341. TBL_NPC* nd = map_id2nd(npc_id);
  9342. 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);
  9343. clif_GM_kick(NULL,sd);
  9344. return;
  9345. }
  9346. sd->npc_menu = select;
  9347. npc_scriptcont(sd,npc_id);
  9348. }
  9349. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9350. /// 00b9 <npc id>.L
  9351. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9352. {
  9353. npc_scriptcont(sd,RFIFOL(fd,2));
  9354. }
  9355. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9356. /// 0143 <npc id>.L <value>.L
  9357. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9358. {
  9359. int npcid = RFIFOL(fd,2);
  9360. int amount = (int)RFIFOL(fd,6);
  9361. sd->npc_amount = amount;
  9362. npc_scriptcont(sd, npcid);
  9363. }
  9364. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9365. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9366. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9367. {
  9368. int message_len = RFIFOW(fd,2)-8;
  9369. int npcid = RFIFOL(fd,4);
  9370. const char* message = (char*)RFIFOP(fd,8);
  9371. if( message_len <= 0 )
  9372. return; // invalid input
  9373. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9374. npc_scriptcont(sd, npcid);
  9375. }
  9376. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9377. /// 0146 <npc id>.L
  9378. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9379. {
  9380. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9381. return;
  9382. npc_scriptcont(sd,RFIFOL(fd,2));
  9383. }
  9384. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9385. /// 0178 <index>.W
  9386. /// index:
  9387. /// -1 = cancel
  9388. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9389. {
  9390. short idx = RFIFOW(fd,2);
  9391. if (sd->menuskill_id != MC_IDENTIFY)
  9392. return;
  9393. if( idx == -1 ) {// cancel pressed
  9394. clif_menuskill_clear(sd);
  9395. return;
  9396. }
  9397. skill_identify(sd,idx-2);
  9398. clif_menuskill_clear(sd);
  9399. }
  9400. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9401. /// 01ae <name id>.W
  9402. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9403. {
  9404. if (pc_istrading(sd)) {
  9405. //Make it fail to avoid shop exploits where you sell something different than you see.
  9406. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9407. clif_menuskill_clear(sd);
  9408. return;
  9409. }
  9410. switch( sd->menuskill_id ) {
  9411. case AC_MAKINGARROW:
  9412. skill_arrow_create(sd,RFIFOW(fd,2));
  9413. break;
  9414. case SA_CREATECON:
  9415. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9416. break;
  9417. case WL_READING_SB:
  9418. skill_spellbook(sd,RFIFOW(fd,2));
  9419. break;
  9420. case GC_POISONINGWEAPON:
  9421. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9422. break;
  9423. case NC_MAGICDECOY:
  9424. skill_magicdecoy(sd,RFIFOW(fd,2));
  9425. break;
  9426. }
  9427. clif_menuskill_clear(sd);
  9428. }
  9429. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9430. /// 01ce <skill id>.L
  9431. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9432. {
  9433. if (sd->menuskill_id != SA_AUTOSPELL)
  9434. return;
  9435. skill_autospell(sd,RFIFOL(fd,2));
  9436. clif_menuskill_clear(sd);
  9437. }
  9438. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9439. /// 017a <card index>.W
  9440. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9441. {
  9442. if (sd->state.trading != 0)
  9443. return;
  9444. clif_use_card(sd,RFIFOW(fd,2)-2);
  9445. }
  9446. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9447. /// 017c <card index>.W <equip index>.W
  9448. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9449. {
  9450. if (sd->state.trading != 0)
  9451. return;
  9452. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9453. }
  9454. /// Request of character's name by char ID.
  9455. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9456. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9457. /// There are various variants of this packet, some of them have padding between fields.
  9458. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9459. {
  9460. int charid;
  9461. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9462. map_reqnickdb(sd, charid);
  9463. }
  9464. /// /resetskill /resetstate (CZ_RESET).
  9465. /// Request to reset stats or skills.
  9466. /// 0197 <type>.W
  9467. /// type:
  9468. /// 0 = state
  9469. /// 1 = skill
  9470. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9471. char cmd[15];
  9472. if( RFIFOW(fd,2) )
  9473. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9474. else
  9475. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9476. is_atcommand(fd, sd, cmd, 1);
  9477. }
  9478. /// /lb /nlb (CZ_LOCALBROADCAST).
  9479. /// Request to broadcast a message on current map.
  9480. /// 019c <packet len>.W <text>.?B
  9481. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9482. {
  9483. char command[CHAT_SIZE_MAX+16];
  9484. char* msg = (char*)RFIFOP(fd,4);
  9485. unsigned int len = RFIFOW(fd,2)-4;
  9486. // as the length varies depending on the command used, just block unreasonably long strings
  9487. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  9488. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9489. is_atcommand(fd, sd, command, 1);
  9490. }
  9491. /// Request to move an item from inventory to storage.
  9492. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9493. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9494. /// There are various variants of this packet, some of them have padding between fields.
  9495. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9496. {
  9497. int item_index, item_amount;
  9498. if (pc_istrading(sd))
  9499. return;
  9500. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9501. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9502. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9503. return;
  9504. if (sd->state.storage_flag == 1)
  9505. storage_storageadd(sd, item_index, item_amount);
  9506. else
  9507. if (sd->state.storage_flag == 2)
  9508. storage_guild_storageadd(sd, item_index, item_amount);
  9509. }
  9510. /// Request to move an item from storage to inventory.
  9511. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9512. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9513. /// There are various variants of this packet, some of them have padding between fields.
  9514. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9515. {
  9516. int item_index, item_amount;
  9517. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9518. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9519. if (sd->state.storage_flag == 1)
  9520. storage_storageget(sd, item_index, item_amount);
  9521. else
  9522. if(sd->state.storage_flag == 2)
  9523. storage_guild_storageget(sd, item_index, item_amount);
  9524. }
  9525. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9526. /// 0129 <index>.W <amount>.L
  9527. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9528. {
  9529. if( sd->state.vending )
  9530. return;
  9531. if (!pc_iscarton(sd))
  9532. return;
  9533. if (sd->state.storage_flag == 1)
  9534. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9535. else
  9536. if (sd->state.storage_flag == 2)
  9537. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9538. }
  9539. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9540. /// 0128 <index>.W <amount>.L
  9541. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9542. {
  9543. if( sd->state.vending )
  9544. return;
  9545. if (!pc_iscarton(sd))
  9546. return;
  9547. if (sd->state.storage_flag == 1)
  9548. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9549. else
  9550. if (sd->state.storage_flag == 2)
  9551. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9552. }
  9553. /// Request to close storage (CZ_CLOSE_STORE).
  9554. /// 00f7
  9555. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9556. {
  9557. if( sd->state.storage_flag == 1 )
  9558. storage_storageclose(sd);
  9559. else
  9560. if( sd->state.storage_flag == 2 )
  9561. storage_guild_storageclose(sd);
  9562. }
  9563. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9564. /// 023a <info>.W
  9565. /// info:
  9566. /// 0 = password has not been set yet
  9567. /// 1 = storage is password-protected
  9568. /// 8 = too many wrong passwords
  9569. /// ? = ignored
  9570. /// NOTE: This packet is only available on certain non-kRO clients.
  9571. void clif_storagepassword(struct map_session_data* sd, short info)
  9572. {
  9573. int fd = sd->fd;
  9574. WFIFOHEAD(fd,packet_len(0x23a));
  9575. WFIFOW(fd,0) = 0x23a;
  9576. WFIFOW(fd,2) = info;
  9577. WFIFOSET(fd,packet_len(0x23a));
  9578. }
  9579. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9580. /// 023b <type>.W <password>.16B <new password>.16B
  9581. /// type:
  9582. /// 2 = change password
  9583. /// 3 = check password
  9584. /// NOTE: This packet is only available on certain non-kRO clients.
  9585. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9586. {
  9587. //TODO
  9588. }
  9589. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9590. /// 023c <result>.W <error count>.W
  9591. /// result:
  9592. /// 4 = password change success
  9593. /// 5 = password change failure
  9594. /// 6 = password check success
  9595. /// 7 = password check failure
  9596. /// 8 = too many wrong passwords
  9597. /// ? = ignored
  9598. /// NOTE: This packet is only available on certain non-kRO clients.
  9599. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9600. {
  9601. int fd = sd->fd;
  9602. WFIFOHEAD(fd,packet_len(0x23c));
  9603. WFIFOW(fd,0) = 0x23c;
  9604. WFIFOW(fd,2) = result;
  9605. WFIFOW(fd,4) = error_count;
  9606. WFIFOSET(fd,packet_len(0x23c));
  9607. }
  9608. /// Party creation request
  9609. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9610. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9611. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9612. {
  9613. char* name = (char*)RFIFOP(fd,2);
  9614. name[NAME_LENGTH-1] = '\0';
  9615. if( map[sd->bl.m].flag.partylock )
  9616. {// Party locked.
  9617. clif_displaymessage(fd, msg_txt(227));
  9618. return;
  9619. }
  9620. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9621. {
  9622. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9623. return;
  9624. }
  9625. party_create(sd,name,0,0);
  9626. }
  9627. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9628. {
  9629. char* name = (char*)RFIFOP(fd,2);
  9630. int item1 = RFIFOB(fd,26);
  9631. int item2 = RFIFOB(fd,27);
  9632. name[NAME_LENGTH-1] = '\0';
  9633. if( map[sd->bl.m].flag.partylock )
  9634. {// Party locked.
  9635. clif_displaymessage(fd, msg_txt(227));
  9636. return;
  9637. }
  9638. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9639. {
  9640. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9641. return;
  9642. }
  9643. party_create(sd,name,item1,item2);
  9644. }
  9645. /// Party invitation request
  9646. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9647. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9648. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9649. {
  9650. struct map_session_data *t_sd;
  9651. if(map[sd->bl.m].flag.partylock)
  9652. {// Party locked.
  9653. clif_displaymessage(fd, msg_txt(227));
  9654. return;
  9655. }
  9656. t_sd = map_id2sd(RFIFOL(fd,2));
  9657. if(t_sd && t_sd->state.noask)
  9658. {// @noask [LuzZza]
  9659. clif_noask_sub(sd, t_sd, 1);
  9660. return;
  9661. }
  9662. party_invite(sd, t_sd);
  9663. }
  9664. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9665. {
  9666. struct map_session_data *t_sd;
  9667. char *name = (char*)RFIFOP(fd,2);
  9668. name[NAME_LENGTH-1] = '\0';
  9669. if(map[sd->bl.m].flag.partylock)
  9670. {// Party locked.
  9671. clif_displaymessage(fd, msg_txt(227));
  9672. return;
  9673. }
  9674. t_sd = map_nick2sd(name);
  9675. if(t_sd && t_sd->state.noask)
  9676. {// @noask [LuzZza]
  9677. clif_noask_sub(sd, t_sd, 1);
  9678. return;
  9679. }
  9680. party_invite(sd, t_sd);
  9681. }
  9682. /// Party invitation reply
  9683. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9684. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9685. /// flag:
  9686. /// 0 = reject
  9687. /// 1 = accept
  9688. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9689. {
  9690. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9691. }
  9692. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9693. {
  9694. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9695. }
  9696. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9697. /// 0100
  9698. void clif_parse_LeaveParty(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_leave(sd);
  9706. }
  9707. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9708. /// 0103 <account id>.L <char name>.24B
  9709. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9710. {
  9711. if(map[sd->bl.m].flag.partylock)
  9712. { //Guild locked.
  9713. clif_displaymessage(fd, msg_txt(227));
  9714. return;
  9715. }
  9716. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9717. }
  9718. /// Request to change party options.
  9719. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9720. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9721. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9722. {
  9723. struct party_data *p;
  9724. int i;
  9725. if( !sd->status.party_id )
  9726. return;
  9727. p = party_search(sd->status.party_id);
  9728. if( p == NULL )
  9729. return;
  9730. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9731. if( i == MAX_PARTY )
  9732. return; //Shouldn't happen
  9733. if( !p->party.member[i].leader )
  9734. return;
  9735. #if PACKETVER < 20090603
  9736. //Client can't change the item-field
  9737. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9738. #else
  9739. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9740. #endif
  9741. }
  9742. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9743. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9744. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9745. {
  9746. const char* text = (char*)RFIFOP(fd,4);
  9747. int textlen = RFIFOW(fd,2) - 4;
  9748. char *name, *message;
  9749. int namelen, messagelen;
  9750. // validate packet and retrieve name and message
  9751. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9752. return;
  9753. if( is_atcommand(fd, sd, message, 1) )
  9754. return;
  9755. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9756. return;
  9757. if( battle_config.min_chat_delay )
  9758. { //[Skotlex]
  9759. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9760. return;
  9761. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9762. }
  9763. party_send_message(sd, text, textlen);
  9764. }
  9765. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9766. /// 07da <account id>.L
  9767. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9768. {
  9769. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9770. }
  9771. /// Party Booking in KRO [Spiria]
  9772. ///
  9773. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9774. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9775. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9776. {
  9777. short level = RFIFOW(fd,2);
  9778. short mapid = RFIFOW(fd,4);
  9779. short job[PARTY_BOOKING_JOBS];
  9780. int i;
  9781. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9782. job[i] = RFIFOB(fd,6+i*2);
  9783. party_booking_register(sd, level, mapid, job);
  9784. }
  9785. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9786. /// 0803 <result>.W
  9787. /// result:
  9788. /// 0 = success
  9789. /// 1 = failure
  9790. /// 2 = already registered
  9791. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9792. {
  9793. int fd = sd->fd;
  9794. WFIFOHEAD(fd,packet_len(0x803));
  9795. WFIFOW(fd,0) = 0x803;
  9796. WFIFOW(fd,2) = flag;
  9797. WFIFOSET(fd,packet_len(0x803));
  9798. }
  9799. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9800. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9801. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9802. {
  9803. short level = RFIFOW(fd,2);
  9804. short mapid = RFIFOW(fd,4);
  9805. short job = RFIFOW(fd,6);
  9806. unsigned long lastindex = RFIFOL(fd,8);
  9807. short resultcount = RFIFOW(fd,12);
  9808. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9809. }
  9810. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9811. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9812. /// more results:
  9813. /// 0 = no
  9814. /// 1 = yes
  9815. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9816. {
  9817. int i, j;
  9818. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9819. struct party_booking_ad_info *pb_ad;
  9820. WFIFOHEAD(fd,size*count + 5);
  9821. WFIFOW(fd,0) = 0x805;
  9822. WFIFOW(fd,2) = size*count + 5;
  9823. WFIFOB(fd,4) = more_result;
  9824. for(i=0; i<count; i++)
  9825. {
  9826. pb_ad = results[i];
  9827. WFIFOL(fd,i*size+5) = pb_ad->index;
  9828. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9829. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9830. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9831. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9832. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9833. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9834. }
  9835. WFIFOSET(fd,WFIFOW(fd,2));
  9836. }
  9837. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9838. /// 0806
  9839. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9840. {
  9841. if(party_booking_delete(sd))
  9842. clif_PartyBookingDeleteAck(sd, 0);
  9843. }
  9844. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9845. /// 0807 <result>.W
  9846. /// result:
  9847. /// 0 = success
  9848. /// 1 = success (auto-removed expired ad)
  9849. /// 2 = failure
  9850. /// 3 = nothing registered
  9851. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9852. {
  9853. int fd = sd->fd;
  9854. WFIFOHEAD(fd,packet_len(0x807));
  9855. WFIFOW(fd,0) = 0x807;
  9856. WFIFOW(fd,2) = flag;
  9857. WFIFOSET(fd,packet_len(0x807));
  9858. }
  9859. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  9860. /// 0808 { <job>.W }*6
  9861. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9862. {
  9863. short job[PARTY_BOOKING_JOBS];
  9864. int i;
  9865. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9866. job[i] = RFIFOW(fd,2+i*2);
  9867. party_booking_update(sd, job);
  9868. }
  9869. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  9870. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  9871. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9872. {
  9873. int i;
  9874. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9875. if(pb_ad == NULL) return;
  9876. WBUFW(buf,0) = 0x809;
  9877. WBUFL(buf,2) = pb_ad->index;
  9878. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9879. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  9880. WBUFW(buf,34) = pb_ad->p_detail.level;
  9881. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9882. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9883. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9884. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9885. }
  9886. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  9887. /// 080a <index>.L { <job>.W }*6
  9888. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9889. {
  9890. int i;
  9891. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9892. if(pb_ad == NULL) return;
  9893. WBUFW(buf,0) = 0x80a;
  9894. WBUFL(buf,2) = pb_ad->index;
  9895. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9896. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9897. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9898. }
  9899. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  9900. /// 080b <index>.L
  9901. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9902. {
  9903. uint8 buf[6];
  9904. WBUFW(buf,0) = 0x80b;
  9905. WBUFL(buf,2) = index;
  9906. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9907. }
  9908. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  9909. /// 012e
  9910. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9911. {
  9912. vending_closevending(sd);
  9913. }
  9914. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  9915. /// 0130 <account id>.L
  9916. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9917. {
  9918. if( sd->npc_id )
  9919. {// using an NPC
  9920. return;
  9921. }
  9922. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9923. }
  9924. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  9925. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  9926. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9927. {
  9928. int len = (int)RFIFOW(fd,2) - 8;
  9929. int id = (int)RFIFOL(fd,4);
  9930. const uint8* data = (uint8*)RFIFOP(fd,8);
  9931. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  9932. // whether it fails or not, the buy window is closed
  9933. sd->vended_id = 0;
  9934. }
  9935. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  9936. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  9937. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9938. {
  9939. int len = (int)RFIFOW(fd,2) - 12;
  9940. int aid = (int)RFIFOL(fd,4);
  9941. int uid = (int)RFIFOL(fd,8);
  9942. const uint8* data = (uint8*)RFIFOP(fd,12);
  9943. vending_purchasereq(sd, aid, uid, data, len/4);
  9944. // whether it fails or not, the buy window is closed
  9945. sd->vended_id = 0;
  9946. }
  9947. /// Confirm or cancel the shop preparation window.
  9948. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  9949. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  9950. /// result:
  9951. /// 0 = canceled
  9952. /// 1 = open
  9953. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9954. {
  9955. short len = (short)RFIFOW(fd,2) - 85;
  9956. const char* message = (char*)RFIFOP(fd,4);
  9957. bool flag = (bool)RFIFOB(fd,84);
  9958. const uint8* data = (uint8*)RFIFOP(fd,85);
  9959. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9960. return;
  9961. if( map[sd->bl.m].flag.novending ) {
  9962. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9963. return;
  9964. }
  9965. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9966. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  9967. return;
  9968. }
  9969. if( message[0] == '\0' ) // invalid input
  9970. return;
  9971. vending_openvending(sd, message, flag, data, len/8);
  9972. }
  9973. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  9974. /// 0165 <char id>.L <guild name>.24B
  9975. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9976. {
  9977. char* name = (char*)RFIFOP(fd,6);
  9978. name[NAME_LENGTH-1] = '\0';
  9979. if(map[sd->bl.m].flag.guildlock)
  9980. { //Guild locked.
  9981. clif_displaymessage(fd, msg_txt(228));
  9982. return;
  9983. }
  9984. guild_create(sd, name);
  9985. }
  9986. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  9987. /// 014d
  9988. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9989. {
  9990. clif_guild_masterormember(sd);
  9991. }
  9992. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  9993. /// 014f <type>.L
  9994. /// type:
  9995. /// 0 = basic info
  9996. /// 1 = member manager
  9997. /// 2 = positions
  9998. /// 3 = skills
  9999. /// 4 = expulsion list
  10000. /// 5 = unknown (GM_ALLGUILDLIST)
  10001. /// 6 = notice
  10002. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10003. {
  10004. if( !sd->status.guild_id && !sd->bg_id )
  10005. return;
  10006. switch( RFIFOL(fd,2) )
  10007. {
  10008. case 0: // ギルド基本情報、同盟敵対情報
  10009. clif_guild_basicinfo(sd);
  10010. clif_guild_allianceinfo(sd);
  10011. break;
  10012. case 1: // メンバーリスト、役職名リスト
  10013. clif_guild_positionnamelist(sd);
  10014. clif_guild_memberlist(sd);
  10015. break;
  10016. case 2: // 役職名リスト、役職情報リスト
  10017. clif_guild_positionnamelist(sd);
  10018. clif_guild_positioninfolist(sd);
  10019. break;
  10020. case 3: // スキルリスト
  10021. clif_guild_skillinfo(sd);
  10022. break;
  10023. case 4: // 追放リスト
  10024. clif_guild_expulsionlist(sd);
  10025. break;
  10026. default:
  10027. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10028. break;
  10029. }
  10030. }
  10031. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10032. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10033. void clif_parse_GuildChangePositionInfo(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 += 40 ){
  10039. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10040. }
  10041. }
  10042. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10043. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10044. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10045. {
  10046. int i;
  10047. if(!sd->state.gmaster_flag)
  10048. return;
  10049. for(i=4;i<RFIFOW(fd,2);i+=12){
  10050. guild_change_memberposition(sd->status.guild_id,
  10051. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10052. }
  10053. }
  10054. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10055. /// 0151 <guild id>.L
  10056. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10057. {
  10058. struct guild* g;
  10059. int guild_id = RFIFOL(fd,2);
  10060. if( (g = guild_search(guild_id)) != NULL )
  10061. clif_guild_emblem(sd,g);
  10062. }
  10063. /// Validates data of a guild emblem (compressed bitmap)
  10064. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10065. {
  10066. bool success;
  10067. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10068. unsigned long buf_len = sizeof(buf);
  10069. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10070. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10071. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10072. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10073. ;
  10074. return success;
  10075. }
  10076. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10077. /// 0153 <packet len>.W <emblem data>.?B
  10078. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10079. {
  10080. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10081. const uint8* emblem = RFIFOP(fd,4);
  10082. if( !emblem_len || !sd->state.gmaster_flag )
  10083. return;
  10084. if( !clif_validate_emblem(emblem, emblem_len) )
  10085. {
  10086. 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);
  10087. return;
  10088. }
  10089. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10090. }
  10091. /// Guild notice update request (CZ_GUILD_NOTICE).
  10092. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10093. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10094. {
  10095. int guild_id = RFIFOL(fd,2);
  10096. char* msg1 = (char*)RFIFOP(fd,6);
  10097. char* msg2 = (char*)RFIFOP(fd,66);
  10098. if(!sd->state.gmaster_flag)
  10099. return;
  10100. // compensate for some client defects when using multilanguage mode
  10101. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10102. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10103. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10104. guild_change_notice(sd, guild_id, msg1, msg2);
  10105. }
  10106. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10107. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10108. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10109. {
  10110. struct map_session_data *t_sd;
  10111. if(map[sd->bl.m].flag.guildlock)
  10112. { //Guild locked.
  10113. clif_displaymessage(fd, msg_txt(228));
  10114. return;
  10115. }
  10116. t_sd = map_id2sd(RFIFOL(fd,2));
  10117. // @noask [LuzZza]
  10118. if(t_sd && t_sd->state.noask) {
  10119. clif_noask_sub(sd, t_sd, 2);
  10120. return;
  10121. }
  10122. guild_invite(sd,t_sd);
  10123. }
  10124. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10125. /// 016b <guild id>.L <answer>.L
  10126. /// answer:
  10127. /// 0 = refuse
  10128. /// 1 = accept
  10129. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10130. {
  10131. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10132. }
  10133. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10134. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10135. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10136. {
  10137. if(map[sd->bl.m].flag.guildlock)
  10138. { //Guild locked.
  10139. clif_displaymessage(fd, msg_txt(228));
  10140. return;
  10141. }
  10142. if( sd->bg_id )
  10143. {
  10144. clif_displaymessage(fd, "You can't leave battleground guilds.");
  10145. return;
  10146. }
  10147. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10148. }
  10149. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10150. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10151. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10152. {
  10153. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10154. { // Guild locked.
  10155. clif_displaymessage(fd, msg_txt(228));
  10156. return;
  10157. }
  10158. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10159. }
  10160. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10161. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10162. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10163. {
  10164. const char* text = (char*)RFIFOP(fd,4);
  10165. int textlen = RFIFOW(fd,2) - 4;
  10166. char *name, *message;
  10167. int namelen, messagelen;
  10168. // validate packet and retrieve name and message
  10169. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10170. return;
  10171. if( is_atcommand(fd, sd, message, 1) )
  10172. return;
  10173. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10174. return;
  10175. if( battle_config.min_chat_delay )
  10176. { //[Skotlex]
  10177. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10178. return;
  10179. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10180. }
  10181. if( sd->bg_id )
  10182. bg_send_message(sd, text, textlen);
  10183. else
  10184. guild_send_message(sd, text, textlen);
  10185. }
  10186. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10187. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10188. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10189. {
  10190. struct map_session_data *t_sd;
  10191. if(!sd->state.gmaster_flag)
  10192. return;
  10193. if(map[sd->bl.m].flag.guildlock)
  10194. { //Guild locked.
  10195. clif_displaymessage(fd, msg_txt(228));
  10196. return;
  10197. }
  10198. t_sd = map_id2sd(RFIFOL(fd,2));
  10199. // @noask [LuzZza]
  10200. if(t_sd && t_sd->state.noask) {
  10201. clif_noask_sub(sd, t_sd, 3);
  10202. return;
  10203. }
  10204. guild_reqalliance(sd,t_sd);
  10205. }
  10206. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10207. /// 0172 <inviter account id>.L <answer>.L
  10208. /// answer:
  10209. /// 0 = refuse
  10210. /// 1 = accept
  10211. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10212. {
  10213. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10214. }
  10215. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10216. /// 0183 <opponent guild id>.L <relation>.L
  10217. /// relation:
  10218. /// 0 = Ally
  10219. /// 1 = Enemy
  10220. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10221. {
  10222. if(!sd->state.gmaster_flag)
  10223. return;
  10224. if(map[sd->bl.m].flag.guildlock)
  10225. { //Guild locked.
  10226. clif_displaymessage(fd, msg_txt(228));
  10227. return;
  10228. }
  10229. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10230. }
  10231. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10232. /// 0180 <account id>.L
  10233. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10234. {
  10235. struct map_session_data *t_sd;
  10236. if(!sd->state.gmaster_flag)
  10237. return;
  10238. if(map[sd->bl.m].flag.guildlock)
  10239. { //Guild locked.
  10240. clif_displaymessage(fd, msg_txt(228));
  10241. return;
  10242. }
  10243. t_sd = map_id2sd(RFIFOL(fd,2));
  10244. // @noask [LuzZza]
  10245. if(t_sd && t_sd->state.noask) {
  10246. clif_noask_sub(sd, t_sd, 4);
  10247. return;
  10248. }
  10249. guild_opposition(sd,t_sd);
  10250. }
  10251. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10252. /// 015d <key>.40B
  10253. /// key:
  10254. /// now guild name; might have been (intended) email, since the
  10255. /// field name and size is same as the one in CH_DELETE_CHAR.
  10256. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10257. {
  10258. if( map[sd->bl.m].flag.guildlock )
  10259. { //Guild locked.
  10260. clif_displaymessage(fd, msg_txt(228));
  10261. return;
  10262. }
  10263. guild_break(sd,(char*)RFIFOP(fd,2));
  10264. }
  10265. /// Pet
  10266. ///
  10267. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10268. /// 01a1 <type>.B
  10269. /// type:
  10270. /// 0 = pet information
  10271. /// 1 = feed
  10272. /// 2 = performance
  10273. /// 3 = return to egg
  10274. /// 4 = unequip accessory
  10275. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10276. {
  10277. pet_menu(sd,RFIFOB(fd,2));
  10278. }
  10279. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10280. /// 019f <id>.L
  10281. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10282. {
  10283. pet_catch_process2(sd,RFIFOL(fd,2));
  10284. }
  10285. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10286. /// 01a7 <index>.W
  10287. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10288. {
  10289. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10290. {
  10291. //Forged packet, disconnect them [Kevin]
  10292. clif_authfail_fd(fd, 0);
  10293. return;
  10294. }
  10295. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10296. clif_menuskill_clear(sd);
  10297. }
  10298. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10299. /// 01a9 <data>.L
  10300. /// data:
  10301. /// is either emotion (@see enum emotion_type) or a compound value
  10302. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10303. /// entry (given in parentheses) in data\pettalktable.xml
  10304. /// act id:
  10305. /// 0 = feeding
  10306. /// 1 = hunting
  10307. /// 2 = danger
  10308. /// 3 = dead
  10309. /// 4 = normal (stand)
  10310. /// 5 = special performance (perfor_s)
  10311. /// 6 = level up (levelup)
  10312. /// 7 = performance 1 (perfor_1)
  10313. /// 8 = performance 2 (perfor_2)
  10314. /// 9 = performance 3 (perfor_3)
  10315. /// 10 = log-in greeting (connect)
  10316. /// hungry value:
  10317. /// 0 = very hungry (hungry)
  10318. /// 1 = hungry (bit_hungry)
  10319. /// 2 = satisfied (noting)
  10320. /// 3 = stuffed (full)
  10321. /// 4 = full (so_full)
  10322. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10323. {
  10324. if(sd->pd)
  10325. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10326. }
  10327. /// Request to change pet's name (CZ_RENAME_PET).
  10328. /// 01a5 <name>.24B
  10329. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10330. {
  10331. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10332. }
  10333. /// /kill (CZ_DISCONNECT_CHARACTER).
  10334. /// Request to disconnect a character.
  10335. /// 00cc <account id>.L
  10336. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10337. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10338. {
  10339. struct block_list *target;
  10340. int tid;
  10341. tid = RFIFOL(fd,2);
  10342. target = map_id2bl(tid);
  10343. if (!target) {
  10344. clif_GM_kickack(sd, 0);
  10345. return;
  10346. }
  10347. switch (target->type) {
  10348. case BL_PC:
  10349. {
  10350. char command[NAME_LENGTH+6];
  10351. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10352. is_atcommand(fd, sd, command, 1);
  10353. }
  10354. break;
  10355. /**
  10356. * This one does not invoke any atcommand, so we need to check for permissions.
  10357. */
  10358. case BL_MOB:
  10359. {
  10360. char command[100];
  10361. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10362. clif_GM_kickack(sd, 0);
  10363. return;
  10364. }
  10365. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10366. log_atcommand(sd, command);
  10367. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10368. }
  10369. break;
  10370. case BL_NPC:
  10371. {
  10372. char command[NAME_LENGTH+11];
  10373. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10374. is_atcommand(fd, sd, command, 1);
  10375. }
  10376. break;
  10377. default:
  10378. clif_GM_kickack(sd, 0);
  10379. }
  10380. }
  10381. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10382. /// Request to disconnect all characters.
  10383. /// 00ce
  10384. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10385. char cmd[15];
  10386. sprintf(cmd,"%ckickall",atcommand_symbol);
  10387. is_atcommand(fd, sd, cmd, 1);
  10388. }
  10389. /// /remove (CZ_REMOVE_AID).
  10390. /// Request to warp to a character with given login ID.
  10391. /// 01ba <account name>.24B
  10392. /// /shift (CZ_SHIFT).
  10393. /// Request to warp to a character with given name.
  10394. /// 01bb <char name>.24B
  10395. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10396. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10397. char *player_name;
  10398. char command[NAME_LENGTH+8];
  10399. player_name = (char*)RFIFOP(fd,2);
  10400. player_name[NAME_LENGTH-1] = '\0';
  10401. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10402. is_atcommand(fd, sd, command, 1);
  10403. }
  10404. /// /remove (CZ_REMOVE_AID_SSO).
  10405. /// Request to warp to a character with given account ID.
  10406. /// 0843 <account id>.L
  10407. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10408. {
  10409. int account_id;
  10410. struct map_session_data* pl_sd;
  10411. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10412. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10413. {
  10414. char command[NAME_LENGTH+8];
  10415. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10416. is_atcommand(fd, sd, command, 1);
  10417. }
  10418. }
  10419. /// /recall (CZ_RECALL).
  10420. /// Request to summon a player with given login ID to own position.
  10421. /// 01bc <account name>.24B
  10422. /// /summon (CZ_RECALL_GID).
  10423. /// Request to summon a player with given name to own position.
  10424. /// 01bd <char name>.24B
  10425. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10426. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10427. char *player_name;
  10428. char command [NAME_LENGTH+8];
  10429. player_name = (char*)RFIFOP(fd,2);
  10430. player_name[NAME_LENGTH-1] = '\0';
  10431. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10432. is_atcommand(fd, sd, command, 1);
  10433. }
  10434. /// /recall (CZ_RECALL_SSO).
  10435. /// Request to summon a player with given account ID to own position.
  10436. /// 0842 <account id>.L
  10437. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10438. {
  10439. int account_id;
  10440. struct map_session_data* pl_sd;
  10441. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10442. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10443. {
  10444. char command[NAME_LENGTH+8];
  10445. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10446. is_atcommand(fd, sd, command, 1);
  10447. }
  10448. }
  10449. /// /item /monster (CZ_ITEM_CREATE).
  10450. /// Request to make items or spawn monsters.
  10451. /// 013f <item/mob name>.24B
  10452. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10453. {
  10454. char *monster_item_name;
  10455. char command[NAME_LENGTH+10];
  10456. monster_item_name = (char*)RFIFOP(fd,2);
  10457. monster_item_name[NAME_LENGTH-1] = '\0';
  10458. if( mobdb_searchname(monster_item_name) ) {
  10459. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10460. is_atcommand(fd, sd, command, 1);
  10461. return;
  10462. }
  10463. if( itemdb_searchname(monster_item_name) ) {
  10464. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10465. is_atcommand(fd, sd, command, 1);
  10466. return;
  10467. }
  10468. }
  10469. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10470. /// 019d <effect state>.L
  10471. /// effect state:
  10472. /// TODO: Any OPTION_* ?
  10473. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10474. char cmd[6];
  10475. sprintf(cmd,"%chide",atcommand_symbol);
  10476. is_atcommand(fd, sd, cmd, 1);
  10477. }
  10478. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10479. /// 0149 <account id>.L <type>.B <value>.W
  10480. /// type:
  10481. /// 0 = positive points
  10482. /// 1 = negative points
  10483. /// 2 = self mute (+10 minutes)
  10484. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10485. {
  10486. int id, type, value;
  10487. struct map_session_data *dstsd;
  10488. char command[NAME_LENGTH+15];
  10489. id = RFIFOL(fd,2);
  10490. type = RFIFOB(fd,6);
  10491. value = RFIFOW(fd,7);
  10492. if( type == 0 )
  10493. value = -value;
  10494. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10495. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10496. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10497. return;
  10498. dstsd = map_id2sd(id);
  10499. if( dstsd == NULL )
  10500. return;
  10501. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10502. is_atcommand(fd, sd, command, 1);
  10503. }
  10504. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10505. /// GM adjustment of a player's manner value by -60.
  10506. /// 0212 <char name>.24B
  10507. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10508. {
  10509. char command[NAME_LENGTH+15];
  10510. char *name = (char*)RFIFOP(fd,2);
  10511. name[NAME_LENGTH-1] = '\0';
  10512. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10513. is_atcommand(fd, sd, command, 1);
  10514. }
  10515. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10516. /// 01df <account id>.L
  10517. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10518. /// 01e0 <account id>.L <account name>.24B
  10519. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10520. {
  10521. int tid;
  10522. tid = RFIFOL(fd,2);
  10523. //TODO: find out if this works for any player or only for authorized GMs
  10524. WFIFOHEAD(fd,packet_len(0x1e0));
  10525. WFIFOW(fd,0) = 0x1e0;
  10526. WFIFOL(fd,2) = tid;
  10527. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10528. WFIFOSET(fd, packet_len(0x1e0));
  10529. }
  10530. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10531. /// GM single cell type change request.
  10532. /// 0198 <x>.W <y>.W <type>.W
  10533. /// type:
  10534. /// 0 = not walkable
  10535. /// 1 = walkable
  10536. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10537. {
  10538. int x,y,type;
  10539. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10540. return;
  10541. x = RFIFOW(fd,2);
  10542. y = RFIFOW(fd,4);
  10543. type = RFIFOW(fd,6);
  10544. map_setgatcell(sd->bl.m,x,y,type);
  10545. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10546. //FIXME: once players leave the map, the client 'forgets' this information.
  10547. }
  10548. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10549. /// Request to allow/deny whispers from a nick.
  10550. /// 00cf <nick>.24B <type>.B
  10551. /// type:
  10552. /// 0 = (/ex nick) deny speech from nick
  10553. /// 1 = (/in nick) allow speech from nick
  10554. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10555. {
  10556. char* nick;
  10557. uint8 type;
  10558. int i;
  10559. nick = (char*)RFIFOP(fd,2); // speed up
  10560. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10561. type = RFIFOB(fd,26);
  10562. // FIXME: Use clif_wisexin.
  10563. WFIFOHEAD(fd,packet_len(0xd1));
  10564. WFIFOW(fd,0) = 0x0d1;
  10565. WFIFOB(fd,2) = type;
  10566. if( type == 0 )
  10567. { // Add name to ignore list (block)
  10568. if (strcmp(wisp_server_name, nick) == 0) {
  10569. WFIFOB(fd,3) = 1; // fail
  10570. WFIFOSET(fd, packet_len(0x0d1));
  10571. return;
  10572. }
  10573. // try to find a free spot, while checking for duplicates at the same time
  10574. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10575. if( i == MAX_IGNORE_LIST )
  10576. {// no space for new entry
  10577. WFIFOB(fd,3) = 2; // fail
  10578. WFIFOSET(fd, packet_len(0x0d1));
  10579. return;
  10580. }
  10581. if( sd->ignore[i].name[0] != '\0' )
  10582. {// name already exists
  10583. WFIFOB(fd,3) = 0; // Aegis reports success.
  10584. WFIFOSET(fd, packet_len(0x0d1));
  10585. return;
  10586. }
  10587. //Insert in position i
  10588. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10589. WFIFOB(fd,3) = 0; // success
  10590. WFIFOSET(fd, packet_len(0x0d1));
  10591. }
  10592. else
  10593. { // Remove name from ignore list (unblock)
  10594. // find entry
  10595. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10596. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10597. { //Not found
  10598. WFIFOB(fd,3) = 1; // fail
  10599. WFIFOSET(fd, packet_len(0x0d1));
  10600. return;
  10601. }
  10602. // move everything one place down to overwrite removed entry
  10603. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10604. // wipe last entry
  10605. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10606. WFIFOB(fd,3) = 0; // success
  10607. WFIFOSET(fd, packet_len(0x0d1));
  10608. }
  10609. }
  10610. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10611. /// Request to allow/deny all whispers.
  10612. /// 00d0 <type>.B
  10613. /// type:
  10614. /// 0 = (/exall) deny all speech
  10615. /// 1 = (/inall) allow all speech
  10616. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10617. {
  10618. // FIXME: Use clif_wisall.
  10619. WFIFOHEAD(fd,packet_len(0xd2));
  10620. WFIFOW(fd,0) = 0x0d2;
  10621. WFIFOB(fd,2) = RFIFOB(fd,2);
  10622. if( RFIFOB(fd,2) == 0 )
  10623. {// Deny all
  10624. if( sd->state.ignoreAll ) {
  10625. WFIFOB(fd,3) = 1; // fail
  10626. } else {
  10627. sd->state.ignoreAll = 1;
  10628. WFIFOB(fd,3) = 0; // success
  10629. }
  10630. }
  10631. else
  10632. {//Unblock everyone
  10633. if( sd->state.ignoreAll ) {
  10634. sd->state.ignoreAll = 0;
  10635. WFIFOB(fd,3) = 0; // success
  10636. } else {
  10637. if (sd->ignore[0].name[0] != '\0')
  10638. { //Wipe the ignore list.
  10639. memset(sd->ignore, 0, sizeof(sd->ignore));
  10640. WFIFOB(fd,3) = 0; // success
  10641. } else {
  10642. WFIFOB(fd,3) = 1; // fail
  10643. }
  10644. }
  10645. }
  10646. WFIFOSET(fd, packet_len(0x0d2));
  10647. }
  10648. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10649. /// 00d3
  10650. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10651. {
  10652. int i;
  10653. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10654. WFIFOW(fd,0) = 0xd4;
  10655. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10656. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10657. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10658. WFIFOSET(fd, WFIFOW(fd,2));
  10659. }
  10660. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10661. /// 01e7
  10662. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10663. {
  10664. if (sd->state.doridori) return;
  10665. switch (sd->class_&MAPID_UPPERMASK)
  10666. {
  10667. case MAPID_SOUL_LINKER:
  10668. case MAPID_STAR_GLADIATOR:
  10669. case MAPID_TAEKWON:
  10670. if (!sd->state.rest)
  10671. break;
  10672. case MAPID_SUPER_NOVICE:
  10673. sd->state.doridori=1;
  10674. break;
  10675. }
  10676. }
  10677. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10678. /// 01ed
  10679. /// Note: This packet is caused by 7 lines of any text, followed by
  10680. /// the prayer and an another line of any text. The prayer is
  10681. /// defined by lines 790~793 in data\msgstringtable.txt
  10682. /// "Dear angel, can you hear my voice?"
  10683. /// "I am" (space separated player name) "Super Novice~"
  10684. /// "Help me out~ Please~ T_T"
  10685. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10686. {
  10687. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10688. {
  10689. unsigned int next = pc_nextbaseexp(sd);
  10690. if( next == 0 ) next = pc_thisbaseexp(sd);
  10691. if( next )
  10692. {
  10693. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10694. if( percent && ( percent%100 ) == 0 )
  10695. {// 10.0%, 20.0%, ..., 90.0%
  10696. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10697. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10698. }
  10699. }
  10700. }
  10701. }
  10702. /// Friends List
  10703. ///
  10704. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10705. /// 0206 <account id>.L <char id>.L <state>.B
  10706. /// state:
  10707. /// 0 = online
  10708. /// 1 = offline
  10709. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10710. {
  10711. int i, fd = sd->fd;
  10712. //Seek friend.
  10713. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10714. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10715. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10716. return; //Not found
  10717. WFIFOHEAD(fd,packet_len(0x206));
  10718. WFIFOW(fd, 0) = 0x206;
  10719. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10720. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10721. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10722. WFIFOSET(fd, packet_len(0x206));
  10723. }
  10724. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10725. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10726. {
  10727. int account_id, char_id, online;
  10728. account_id = va_arg(ap, int);
  10729. char_id = va_arg(ap, int);
  10730. online = va_arg(ap, int);
  10731. clif_friendslist_toggle(sd, account_id, char_id, online);
  10732. return 0;
  10733. }
  10734. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10735. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10736. void clif_friendslist_send(struct map_session_data *sd)
  10737. {
  10738. int i = 0, n, fd = sd->fd;
  10739. // Send friends list
  10740. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10741. WFIFOW(fd, 0) = 0x201;
  10742. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10743. {
  10744. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10745. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10746. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10747. }
  10748. if (i) {
  10749. WFIFOW(fd,2) = 4 + 32 * i;
  10750. WFIFOSET(fd, WFIFOW(fd,2));
  10751. }
  10752. for (n = 0; n < i; n++)
  10753. { //Sending the online players
  10754. if (map_charid2sd(sd->status.friends[n].char_id))
  10755. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10756. }
  10757. }
  10758. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10759. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10760. /// result:
  10761. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10762. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10763. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10764. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10765. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10766. {
  10767. int fd;
  10768. nullpo_retv(sd);
  10769. fd = sd->fd;
  10770. WFIFOHEAD(fd,packet_len(0x209));
  10771. WFIFOW(fd,0) = 0x209;
  10772. WFIFOW(fd,2) = type;
  10773. if (f_sd)
  10774. {
  10775. WFIFOL(fd,4) = f_sd->status.account_id;
  10776. WFIFOL(fd,8) = f_sd->status.char_id;
  10777. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10778. }
  10779. WFIFOSET(fd, packet_len(0x209));
  10780. }
  10781. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10782. /// 0202 <name>.24B
  10783. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10784. {
  10785. struct map_session_data *f_sd;
  10786. int i, f_fd;
  10787. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10788. // ensure that the request player's friend list is not full
  10789. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10790. if( i == MAX_FRIENDS ) {
  10791. clif_friendslist_reqack(sd, f_sd, 2);
  10792. return;
  10793. }
  10794. // Friend doesn't exist (no player with this name)
  10795. if (f_sd == NULL) {
  10796. clif_displaymessage(fd, msg_txt(3));
  10797. return;
  10798. }
  10799. if( sd->bl.id == f_sd->bl.id )
  10800. {// adding oneself as friend
  10801. return;
  10802. }
  10803. // @noask [LuzZza]
  10804. if(f_sd->state.noask) {
  10805. clif_noask_sub(sd, f_sd, 5);
  10806. return;
  10807. }
  10808. // Friend already exists
  10809. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10810. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10811. clif_displaymessage(fd, "Friend already exists.");
  10812. return;
  10813. }
  10814. }
  10815. f_sd->friend_req = sd->status.char_id;
  10816. sd->friend_req = f_sd->status.char_id;
  10817. f_fd = f_sd->fd;
  10818. WFIFOHEAD(f_fd,packet_len(0x207));
  10819. WFIFOW(f_fd,0) = 0x207;
  10820. WFIFOL(f_fd,2) = sd->status.account_id;
  10821. WFIFOL(f_fd,6) = sd->status.char_id;
  10822. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10823. WFIFOSET(f_fd, packet_len(0x207));
  10824. }
  10825. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10826. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10827. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10828. /// result:
  10829. /// 0 = rejected
  10830. /// 1 = accepted
  10831. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10832. {
  10833. struct map_session_data *f_sd;
  10834. int char_id, account_id;
  10835. char reply;
  10836. account_id = RFIFOL(fd,2);
  10837. char_id = RFIFOL(fd,6);
  10838. #if PACKETVER < 6
  10839. reply = RFIFOB(fd,10);
  10840. #else
  10841. reply = RFIFOL(fd,10);
  10842. #endif
  10843. if( sd->bl.id == account_id )
  10844. {// adding oneself as friend
  10845. return;
  10846. }
  10847. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10848. if (f_sd == NULL)
  10849. return;
  10850. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10851. clif_friendslist_reqack(f_sd, sd, 1);
  10852. else {
  10853. int i;
  10854. // Find an empty slot
  10855. for (i = 0; i < MAX_FRIENDS; i++)
  10856. if (f_sd->status.friends[i].char_id == 0)
  10857. break;
  10858. if (i == MAX_FRIENDS) {
  10859. clif_friendslist_reqack(f_sd, sd, 2);
  10860. return;
  10861. }
  10862. f_sd->status.friends[i].account_id = sd->status.account_id;
  10863. f_sd->status.friends[i].char_id = sd->status.char_id;
  10864. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10865. clif_friendslist_reqack(f_sd, sd, 0);
  10866. if (battle_config.friend_auto_add) {
  10867. // Also add f_sd to sd's friendlist.
  10868. for (i = 0; i < MAX_FRIENDS; i++) {
  10869. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10870. return; //No need to add anything.
  10871. if (sd->status.friends[i].char_id == 0)
  10872. break;
  10873. }
  10874. if (i == MAX_FRIENDS) {
  10875. clif_friendslist_reqack(sd, f_sd, 2);
  10876. return;
  10877. }
  10878. sd->status.friends[i].account_id = f_sd->status.account_id;
  10879. sd->status.friends[i].char_id = f_sd->status.char_id;
  10880. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10881. clif_friendslist_reqack(sd, f_sd, 0);
  10882. }
  10883. }
  10884. }
  10885. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  10886. /// 0203 <account id>.L <char id>.L
  10887. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10888. {
  10889. struct map_session_data *f_sd = NULL;
  10890. int account_id, char_id;
  10891. int i, j;
  10892. account_id = RFIFOL(fd,2);
  10893. char_id = RFIFOL(fd,6);
  10894. // Search friend
  10895. for (i = 0; i < MAX_FRIENDS &&
  10896. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10897. if (i == MAX_FRIENDS) {
  10898. clif_displaymessage(fd, "Name not found in list.");
  10899. return;
  10900. }
  10901. //remove from friend's list first
  10902. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  10903. for (i = 0; i < MAX_FRIENDS &&
  10904. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  10905. if (i != MAX_FRIENDS) {
  10906. // move all chars up
  10907. for(j = i + 1; j < MAX_FRIENDS; j++)
  10908. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  10909. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  10910. //should the guy be notified of some message? we should add it here if so
  10911. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  10912. WFIFOW(f_sd->fd,0) = 0x20a;
  10913. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  10914. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  10915. WFIFOSET(f_sd->fd, packet_len(0x20a));
  10916. }
  10917. } else { //friend not online -- ask char server to delete from his friendlist
  10918. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  10919. clif_displaymessage(fd, "This action can't be performed at the moment. Please try again later.");
  10920. return;
  10921. }
  10922. }
  10923. // We can now delete from original requester
  10924. for (i = 0; i < MAX_FRIENDS &&
  10925. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10926. // move all chars up
  10927. for(j = i + 1; j < MAX_FRIENDS; j++)
  10928. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10929. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10930. clif_displaymessage(fd, "Friend removed");
  10931. WFIFOHEAD(fd,packet_len(0x20a));
  10932. WFIFOW(fd,0) = 0x20a;
  10933. WFIFOL(fd,2) = account_id;
  10934. WFIFOL(fd,6) = char_id;
  10935. WFIFOSET(fd, packet_len(0x20a));
  10936. // clif_friendslist_send(sd); //This is not needed anymore.
  10937. }
  10938. /// /pvpinfo (CZ_REQ_PVPPOINT).
  10939. /// 020f <char id>.L <account id>.L
  10940. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  10941. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  10942. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10943. {
  10944. WFIFOHEAD(fd,packet_len(0x210));
  10945. WFIFOW(fd,0) = 0x210;
  10946. WFIFOL(fd,2) = sd->status.char_id;
  10947. WFIFOL(fd,6) = sd->status.account_id;
  10948. WFIFOL(fd,10) = sd->pvp_won; // times won
  10949. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10950. WFIFOL(fd,18) = sd->pvp_point;
  10951. WFIFOSET(fd, packet_len(0x210));
  10952. }
  10953. /// /blacksmith (CZ_BLACKSMITH_RANK).
  10954. /// 0217
  10955. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  10956. /// 0219 { <name>.24B }*10 { <point>.L }*10
  10957. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10958. {
  10959. int i;
  10960. const char* name;
  10961. WFIFOHEAD(fd,packet_len(0x219));
  10962. WFIFOW(fd,0) = 0x219;
  10963. //Packet size limits this list to 10 elements. [Skotlex]
  10964. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10965. if (smith_fame_list[i].id > 0) {
  10966. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10967. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10968. {
  10969. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10970. } else
  10971. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10972. } else
  10973. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10974. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10975. }
  10976. for(;i < 10; i++) { //In case the MAX is less than 10.
  10977. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10978. WFIFOL(fd, 242 + i * 4) = 0;
  10979. }
  10980. WFIFOSET(fd, packet_len(0x219));
  10981. }
  10982. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  10983. /// 021b <points>.L <total points>.L
  10984. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  10985. {
  10986. int fd = sd->fd;
  10987. WFIFOHEAD(fd,packet_len(0x21b));
  10988. WFIFOW(fd,0) = 0x21b;
  10989. WFIFOL(fd,2) = points;
  10990. WFIFOL(fd,6) = sd->status.fame;
  10991. WFIFOSET(fd, packet_len(0x21b));
  10992. }
  10993. /// /alchemist (CZ_ALCHEMIST_RANK).
  10994. /// 0218
  10995. /// /alchemist list (ZC_ALCHEMIST_RANK).
  10996. /// 021a { <name>.24B }*10 { <point>.L }*10
  10997. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10998. {
  10999. int i;
  11000. const char* name;
  11001. WFIFOHEAD(fd,packet_len(0x21a));
  11002. WFIFOW(fd,0) = 0x21a;
  11003. //Packet size limits this list to 10 elements. [Skotlex]
  11004. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11005. if (chemist_fame_list[i].id > 0) {
  11006. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11007. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11008. {
  11009. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11010. } else
  11011. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11012. } else
  11013. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11014. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11015. }
  11016. for(;i < 10; i++) { //In case the MAX is less than 10.
  11017. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11018. WFIFOL(fd, 242 + i * 4) = 0;
  11019. }
  11020. WFIFOSET(fd, packet_len(0x21a));
  11021. }
  11022. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11023. /// 021c <points>.L <total points>.L
  11024. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11025. {
  11026. int fd = sd->fd;
  11027. WFIFOHEAD(fd,packet_len(0x21c));
  11028. WFIFOW(fd,0) = 0x21c;
  11029. WFIFOL(fd,2) = points;
  11030. WFIFOL(fd,6) = sd->status.fame;
  11031. WFIFOSET(fd, packet_len(0x21c));
  11032. }
  11033. /// /taekwon (CZ_TAEKWON_RANK).
  11034. /// 0225
  11035. /// /taekwon list (ZC_TAEKWON_RANK).
  11036. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11037. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11038. {
  11039. int i;
  11040. const char* name;
  11041. WFIFOHEAD(fd,packet_len(0x226));
  11042. WFIFOW(fd,0) = 0x226;
  11043. //Packet size limits this list to 10 elements. [Skotlex]
  11044. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11045. if (taekwon_fame_list[i].id > 0) {
  11046. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11047. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11048. {
  11049. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11050. } else
  11051. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11052. } else
  11053. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11054. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11055. }
  11056. for(;i < 10; i++) { //In case the MAX is less than 10.
  11057. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11058. WFIFOL(fd, 242 + i * 4) = 0;
  11059. }
  11060. WFIFOSET(fd, packet_len(0x226));
  11061. }
  11062. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11063. /// 0224 <points>.L <total points>.L
  11064. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11065. {
  11066. int fd = sd->fd;
  11067. WFIFOHEAD(fd,packet_len(0x224));
  11068. WFIFOW(fd,0) = 0x224;
  11069. WFIFOL(fd,2) = points;
  11070. WFIFOL(fd,6) = sd->status.fame;
  11071. WFIFOSET(fd, packet_len(0x224));
  11072. }
  11073. /// /pk (CZ_KILLER_RANK).
  11074. /// 0237
  11075. /// /pk list (ZC_KILLER_RANK).
  11076. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11077. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11078. {
  11079. int i;
  11080. WFIFOHEAD(fd,packet_len(0x238));
  11081. WFIFOW(fd,0) = 0x238;
  11082. for(i=0;i<10;i++){
  11083. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11084. WFIFOL(fd,i*4+242) = 0;
  11085. }
  11086. WFIFOSET(fd, packet_len(0x238));
  11087. }
  11088. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11089. /// 0254 <which>.B
  11090. /// which:
  11091. /// 0 = sun
  11092. /// 1 = moon
  11093. /// 2 = star
  11094. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11095. {
  11096. int i;
  11097. if (sd->menuskill_id != SG_FEEL)
  11098. return;
  11099. i = sd->menuskill_val-1;
  11100. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11101. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11102. sd->feel_map[i].m = sd->bl.m;
  11103. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11104. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11105. // clif_misceffect2(&sd->bl, 0x1b0);
  11106. // clif_misceffect2(&sd->bl, 0x21f);
  11107. clif_feel_info(sd, i, 0);
  11108. clif_menuskill_clear(sd);
  11109. }
  11110. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11111. /// 0253 <which>.B
  11112. /// which:
  11113. /// 0 = sun
  11114. /// 1 = moon
  11115. /// 2 = star
  11116. void clif_feel_req(int fd, struct map_session_data *sd, int skilllv)
  11117. {
  11118. WFIFOHEAD(fd,packet_len(0x253));
  11119. WFIFOW(fd,0)=0x253;
  11120. WFIFOB(fd,2)=TOB(skilllv-1);
  11121. WFIFOSET(fd, packet_len(0x253));
  11122. sd->menuskill_id = SG_FEEL;
  11123. sd->menuskill_val = skilllv;
  11124. }
  11125. /// Request to change homunculus' name (CZ_RENAME_MER).
  11126. /// 0231 <name>.24B
  11127. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11128. {
  11129. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11130. }
  11131. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11132. /// 0234 <id>.L
  11133. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11134. {
  11135. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11136. struct block_list *bl = NULL;
  11137. struct unit_data *ud = NULL;
  11138. if( sd->md && sd->md->bl.id == id )
  11139. bl = &sd->md->bl;
  11140. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11141. bl = &sd->hd->bl; // Moving Homunculus
  11142. else
  11143. return;
  11144. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11145. ud = unit_bl2ud(bl);
  11146. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11147. }
  11148. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11149. /// 0232 <id>.L <position data>.3B
  11150. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11151. {
  11152. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11153. struct block_list *bl = NULL;
  11154. short x, y;
  11155. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11156. if( sd->md && sd->md->bl.id == id )
  11157. bl = &sd->md->bl; // Moving Mercenary
  11158. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11159. bl = &sd->hd->bl; // Moving Homunculus
  11160. else
  11161. return;
  11162. unit_walktoxy(bl, x, y, 4);
  11163. }
  11164. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11165. /// 0233 <id>.L <target id>.L <action>.B
  11166. /// action:
  11167. /// always 0
  11168. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11169. {
  11170. struct block_list *bl = NULL;
  11171. int id = RFIFOL(fd,2),
  11172. target_id = RFIFOL(fd,6),
  11173. action_type = RFIFOB(fd,10);
  11174. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11175. bl = &sd->hd->bl;
  11176. else if( sd->md && sd->md->bl.id == id )
  11177. bl = &sd->md->bl;
  11178. else return;
  11179. unit_stop_attack(bl);
  11180. unit_attack(bl, target_id, action_type != 0);
  11181. }
  11182. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11183. /// 022d <type>.W <command>.B
  11184. /// type:
  11185. /// always 0
  11186. /// command:
  11187. /// 0 = homunculus information
  11188. /// 1 = feed
  11189. /// 2 = delete
  11190. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11191. { //[orn]
  11192. int cmd;
  11193. cmd = RFIFOW(fd,0);
  11194. if(!merc_is_hom_active(sd->hd))
  11195. return;
  11196. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11197. }
  11198. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11199. /// 0292
  11200. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11201. {
  11202. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11203. if (item_position < 0)
  11204. return;
  11205. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11206. return;
  11207. if (!status_revive(&sd->bl, 100, 100))
  11208. return;
  11209. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11210. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11211. }
  11212. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11213. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11214. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11215. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11216. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11217. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11218. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11219. void clif_check(int fd, struct map_session_data* pl_sd)
  11220. {
  11221. WFIFOHEAD(fd,packet_len(0x214));
  11222. WFIFOW(fd, 0) = 0x214;
  11223. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11224. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11225. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11226. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11227. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11228. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11229. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11230. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11231. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11232. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11233. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11234. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11235. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11236. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11237. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11238. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11239. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11240. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11241. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11242. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11243. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11244. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11245. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11246. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11247. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11248. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be?
  11249. WFIFOSET(fd,packet_len(0x214));
  11250. }
  11251. /// /check (CZ_REQ_STATUS_GM).
  11252. /// Request character's status values.
  11253. /// 0213 <char name>.24B
  11254. void clif_parse_Check(int fd, struct map_session_data *sd)
  11255. {
  11256. char charname[NAME_LENGTH];
  11257. struct map_session_data* pl_sd;
  11258. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11259. return;
  11260. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11261. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11262. {
  11263. return;
  11264. }
  11265. clif_check(fd, pl_sd);
  11266. }
  11267. /// MAIL SYSTEM
  11268. /// By Zephyrus
  11269. ///
  11270. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11271. /// 0255 <index>.W <result>.B
  11272. /// result:
  11273. /// 0 = success
  11274. /// 1 = failure
  11275. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11276. {
  11277. WFIFOHEAD(fd,packet_len(0x255));
  11278. WFIFOW(fd,0) = 0x255;
  11279. WFIFOW(fd,2) = index;
  11280. WFIFOB(fd,4) = flag;
  11281. WFIFOSET(fd,packet_len(0x255));
  11282. }
  11283. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11284. /// 0245 <result>.B
  11285. /// result:
  11286. /// 0 = success
  11287. /// 1 = failure
  11288. /// 2 = too many items
  11289. void clif_Mail_getattachment(int fd, uint8 flag)
  11290. {
  11291. WFIFOHEAD(fd,packet_len(0x245));
  11292. WFIFOW(fd,0) = 0x245;
  11293. WFIFOB(fd,2) = flag;
  11294. WFIFOSET(fd,packet_len(0x245));
  11295. }
  11296. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11297. /// 0249 <result>.B
  11298. /// result:
  11299. /// 0 = success
  11300. /// 1 = recipinent does not exist
  11301. void clif_Mail_send(int fd, bool fail)
  11302. {
  11303. WFIFOHEAD(fd,packet_len(0x249));
  11304. WFIFOW(fd,0) = 0x249;
  11305. WFIFOB(fd,2) = fail;
  11306. WFIFOSET(fd,packet_len(0x249));
  11307. }
  11308. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11309. /// 0257 <mail id>.L <result>.W
  11310. /// result:
  11311. /// 0 = success
  11312. /// 1 = failure
  11313. void clif_Mail_delete(int fd, int mail_id, short fail)
  11314. {
  11315. WFIFOHEAD(fd, packet_len(0x257));
  11316. WFIFOW(fd,0) = 0x257;
  11317. WFIFOL(fd,2) = mail_id;
  11318. WFIFOW(fd,6) = fail;
  11319. WFIFOSET(fd, packet_len(0x257));
  11320. }
  11321. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11322. /// 0274 <mail id>.L <result>.W
  11323. /// result:
  11324. /// 0 = success
  11325. /// 1 = failure
  11326. void clif_Mail_return(int fd, int mail_id, short fail)
  11327. {
  11328. WFIFOHEAD(fd,packet_len(0x274));
  11329. WFIFOW(fd,0) = 0x274;
  11330. WFIFOL(fd,2) = mail_id;
  11331. WFIFOW(fd,6) = fail;
  11332. WFIFOSET(fd,packet_len(0x274));
  11333. }
  11334. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11335. /// 024a <mail id>.L <title>.40B <sender>.24B
  11336. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11337. {
  11338. WFIFOHEAD(fd,packet_len(0x24a));
  11339. WFIFOW(fd,0) = 0x24a;
  11340. WFIFOL(fd,2) = mail_id;
  11341. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11342. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11343. WFIFOSET(fd,packet_len(0x24a));
  11344. }
  11345. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11346. /// 0260 <type>.L
  11347. /// type:
  11348. /// 0 = open
  11349. /// 1 = close
  11350. void clif_Mail_window(int fd, int flag)
  11351. {
  11352. WFIFOHEAD(fd,packet_len(0x260));
  11353. WFIFOW(fd,0) = 0x260;
  11354. WFIFOL(fd,2) = flag;
  11355. WFIFOSET(fd,packet_len(0x260));
  11356. }
  11357. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11358. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11359. /// read:
  11360. /// 0 = unread
  11361. /// 1 = read
  11362. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11363. {
  11364. int fd = sd->fd;
  11365. struct mail_data *md = &sd->mail.inbox;
  11366. struct mail_message *msg;
  11367. int len, i, j;
  11368. len = 8 + (73 * md->amount);
  11369. WFIFOHEAD(fd,len);
  11370. WFIFOW(fd,0) = 0x240;
  11371. WFIFOW(fd,2) = len;
  11372. WFIFOL(fd,4) = md->amount;
  11373. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11374. {
  11375. msg = &md->msg[i];
  11376. if (msg->id < 1)
  11377. continue;
  11378. WFIFOL(fd,8+73*j) = msg->id;
  11379. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11380. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11381. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11382. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11383. j++;
  11384. }
  11385. WFIFOSET(fd,len);
  11386. if( md->full )
  11387. {// TODO: is this official?
  11388. char output[100];
  11389. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11390. clif_disp_onlyself(sd, output, strlen(output));
  11391. }
  11392. }
  11393. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11394. /// 023f
  11395. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11396. {
  11397. struct mail_data* md = &sd->mail.inbox;
  11398. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11399. intif_Mail_requestinbox(sd->status.char_id, 1);
  11400. else
  11401. clif_Mail_refreshinbox(sd);
  11402. mail_removeitem(sd, 0);
  11403. mail_removezeny(sd, 0);
  11404. }
  11405. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11406. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11407. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11408. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11409. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11410. {
  11411. int i, fd = sd->fd;
  11412. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11413. if( i == MAIL_MAX_INBOX )
  11414. {
  11415. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11416. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11417. return;
  11418. }
  11419. else
  11420. {
  11421. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11422. struct item *item = &msg->item;
  11423. struct item_data *data;
  11424. int msg_len = strlen(msg->body), len;
  11425. if( msg_len == 0 ) {
  11426. strcpy(msg->body, "(no message)");
  11427. msg_len = strlen(msg->body);
  11428. }
  11429. len = 101 + msg_len;
  11430. WFIFOHEAD(fd,len);
  11431. WFIFOW(fd,0) = 0x242;
  11432. WFIFOW(fd,2) = len;
  11433. WFIFOL(fd,4) = msg->id;
  11434. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11435. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11436. WFIFOL(fd,72) = 0;
  11437. WFIFOL(fd,76) = msg->zeny;
  11438. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  11439. {
  11440. WFIFOL(fd,80) = item->amount;
  11441. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11442. WFIFOW(fd,86) = data->type;
  11443. WFIFOB(fd,88) = item->identify;
  11444. WFIFOB(fd,89) = item->attribute;
  11445. WFIFOB(fd,90) = item->refine;
  11446. WFIFOW(fd,91) = item->card[0];
  11447. WFIFOW(fd,93) = item->card[1];
  11448. WFIFOW(fd,95) = item->card[2];
  11449. WFIFOW(fd,97) = item->card[3];
  11450. }
  11451. else // no item, set all to zero
  11452. memset(WFIFOP(fd,80), 0x00, 19);
  11453. WFIFOB(fd,99) = (unsigned char)msg_len;
  11454. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11455. WFIFOSET(fd,len);
  11456. if (msg->status == MAIL_UNREAD) {
  11457. msg->status = MAIL_READ;
  11458. intif_Mail_read(mail_id);
  11459. clif_parse_Mail_refreshinbox(fd, sd);
  11460. }
  11461. }
  11462. }
  11463. /// Request to open a mail (CZ_MAIL_OPEN).
  11464. /// 0241 <mail id>.L
  11465. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11466. {
  11467. int mail_id = RFIFOL(fd,2);
  11468. if( mail_id <= 0 )
  11469. return;
  11470. if( mail_invalid_operation(sd) )
  11471. return;
  11472. clif_Mail_read(sd, RFIFOL(fd,2));
  11473. }
  11474. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11475. /// 0244 <mail id>.L
  11476. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11477. {
  11478. int mail_id = RFIFOL(fd,2);
  11479. int i;
  11480. bool fail = false;
  11481. if( mail_id <= 0 )
  11482. return;
  11483. if( mail_invalid_operation(sd) )
  11484. return;
  11485. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11486. if( i == MAIL_MAX_INBOX )
  11487. return;
  11488. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11489. return;
  11490. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY )
  11491. {
  11492. clif_Mail_getattachment(fd, 1);
  11493. return;
  11494. }
  11495. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11496. {
  11497. struct item_data *data;
  11498. unsigned int weight;
  11499. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11500. return;
  11501. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11502. {
  11503. case ADDITEM_NEW:
  11504. fail = ( pc_inventoryblank(sd) == 0 );
  11505. break;
  11506. case ADDITEM_OVERAMOUNT:
  11507. fail = true;
  11508. }
  11509. if( fail )
  11510. {
  11511. clif_Mail_getattachment(fd, 1);
  11512. return;
  11513. }
  11514. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11515. if( sd->weight + weight > sd->max_weight )
  11516. {
  11517. clif_Mail_getattachment(fd, 2);
  11518. return;
  11519. }
  11520. }
  11521. sd->mail.inbox.msg[i].zeny = 0;
  11522. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11523. clif_Mail_read(sd, mail_id);
  11524. intif_Mail_getattach(sd->status.char_id, mail_id);
  11525. }
  11526. /// Request to delete a mail (CZ_MAIL_DELETE).
  11527. /// 0243 <mail id>.L
  11528. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11529. {
  11530. int mail_id = RFIFOL(fd,2);
  11531. int i;
  11532. if( mail_id <= 0 )
  11533. return;
  11534. if( mail_invalid_operation(sd) )
  11535. return;
  11536. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11537. if (i < MAIL_MAX_INBOX)
  11538. {
  11539. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11540. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11541. {// can't delete mail without removing attachment first
  11542. clif_Mail_delete(sd->fd, mail_id, 1);
  11543. return;
  11544. }
  11545. intif_Mail_delete(sd->status.char_id, mail_id);
  11546. }
  11547. }
  11548. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11549. /// 0273 <mail id>.L <receive name>.24B
  11550. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11551. {
  11552. int mail_id = RFIFOL(fd,2);
  11553. int i;
  11554. if( mail_id <= 0 )
  11555. return;
  11556. if( mail_invalid_operation(sd) )
  11557. return;
  11558. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11559. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11560. intif_Mail_return(sd->status.char_id, mail_id);
  11561. else
  11562. clif_Mail_return(sd->fd, mail_id, 1);
  11563. }
  11564. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11565. /// 0247 <index>.W <amount>.L
  11566. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11567. {
  11568. int idx = RFIFOW(fd,2);
  11569. int amount = RFIFOL(fd,4);
  11570. unsigned char flag;
  11571. if (idx < 0 || amount < 0)
  11572. return;
  11573. flag = mail_setitem(sd, idx, amount);
  11574. clif_Mail_setattachment(fd,idx,flag);
  11575. }
  11576. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11577. /// 0246 <type>.W
  11578. /// type:
  11579. /// 0 = reset all
  11580. /// 1 = remove item
  11581. /// 2 = remove zeny
  11582. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11583. {
  11584. int flag = RFIFOW(fd,2);
  11585. if (flag == 0 || flag == 1)
  11586. mail_removeitem(sd, 0);
  11587. if (flag == 0 || flag == 2)
  11588. mail_removezeny(sd, 0);
  11589. }
  11590. /// Request to send mail (CZ_MAIL_SEND).
  11591. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11592. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11593. {
  11594. struct mail_message msg;
  11595. int body_len;
  11596. if( sd->state.trading )
  11597. return;
  11598. if( RFIFOW(fd,2) < 69 ) {
  11599. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11600. return;
  11601. }
  11602. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11603. {
  11604. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11605. clif_Mail_send(fd, true); // fail
  11606. return;
  11607. }
  11608. body_len = RFIFOB(fd,68);
  11609. if (body_len > MAIL_BODY_LENGTH)
  11610. body_len = MAIL_BODY_LENGTH;
  11611. if( !mail_setattachment(sd, &msg) )
  11612. { // Invalid Append condition
  11613. clif_Mail_send(sd->fd, true); // fail
  11614. mail_removeitem(sd,0);
  11615. mail_removezeny(sd,0);
  11616. return;
  11617. }
  11618. msg.id = 0; // id will be assigned by charserver
  11619. msg.send_id = sd->status.char_id;
  11620. msg.dest_id = 0; // will attempt to resolve name
  11621. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11622. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11623. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11624. if (body_len)
  11625. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11626. else
  11627. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11628. msg.timestamp = time(NULL);
  11629. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11630. mail_deliveryfail(sd, &msg);
  11631. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11632. }
  11633. /// AUCTION SYSTEM
  11634. /// By Zephyrus
  11635. ///
  11636. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11637. /// 025f <type>.L
  11638. /// type:
  11639. /// 0 = open
  11640. /// 1 = close
  11641. void clif_Auction_openwindow(struct map_session_data *sd)
  11642. {
  11643. int fd = sd->fd;
  11644. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11645. return;
  11646. WFIFOHEAD(fd,packet_len(0x25f));
  11647. WFIFOW(fd,0) = 0x25f;
  11648. WFIFOL(fd,2) = 0;
  11649. WFIFOSET(fd,packet_len(0x25f));
  11650. }
  11651. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11652. /// 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 }*
  11653. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11654. {
  11655. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11656. struct auction_data auction;
  11657. struct item_data *item;
  11658. int k;
  11659. WFIFOHEAD(fd,12 + (count * 83));
  11660. WFIFOW(fd,0) = 0x252;
  11661. WFIFOW(fd,2) = 12 + (count * 83);
  11662. WFIFOL(fd,4) = pages;
  11663. WFIFOL(fd,8) = count;
  11664. for( i = 0; i < count; i++ )
  11665. {
  11666. memcpy(&auction, RBUFP(buf,i * len), len);
  11667. k = 12 + (i * 83);
  11668. WFIFOL(fd,k) = auction.auction_id;
  11669. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11670. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11671. WFIFOW(fd,28+k) = item->view_id;
  11672. else
  11673. WFIFOW(fd,28+k) = auction.item.nameid;
  11674. WFIFOL(fd,30+k) = auction.type;
  11675. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11676. WFIFOB(fd,36+k) = auction.item.identify;
  11677. WFIFOB(fd,37+k) = auction.item.attribute;
  11678. WFIFOB(fd,38+k) = auction.item.refine;
  11679. WFIFOW(fd,39+k) = auction.item.card[0];
  11680. WFIFOW(fd,41+k) = auction.item.card[1];
  11681. WFIFOW(fd,43+k) = auction.item.card[2];
  11682. WFIFOW(fd,45+k) = auction.item.card[3];
  11683. WFIFOL(fd,47+k) = auction.price;
  11684. WFIFOL(fd,51+k) = auction.buynow;
  11685. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11686. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11687. }
  11688. WFIFOSET(fd,WFIFOW(fd,2));
  11689. }
  11690. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11691. /// 0256 <index>.W <result>.B
  11692. /// result:
  11693. /// 0 = success
  11694. /// 1 = failure
  11695. static void clif_Auction_setitem(int fd, int index, bool fail)
  11696. {
  11697. WFIFOHEAD(fd,packet_len(0x256));
  11698. WFIFOW(fd,0) = 0x256;
  11699. WFIFOW(fd,2) = index;
  11700. WFIFOB(fd,4) = fail;
  11701. WFIFOSET(fd,packet_len(0x256));
  11702. }
  11703. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11704. /// 024b <type>.W
  11705. /// type:
  11706. /// 0 = create (any other action in auction window)
  11707. /// 1 = cancel (cancel pressed on register tab)
  11708. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11709. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11710. {
  11711. if( sd->auction.amount > 0 )
  11712. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11713. sd->auction.amount = 0;
  11714. }
  11715. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11716. /// 024c <index>.W <count>.L
  11717. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11718. {
  11719. int idx = RFIFOW(fd,2) - 2;
  11720. int amount = RFIFOL(fd,4); // Always 1
  11721. struct item_data *item;
  11722. if( sd->auction.amount > 0 )
  11723. sd->auction.amount = 0;
  11724. if( idx < 0 || idx >= MAX_INVENTORY )
  11725. {
  11726. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11727. return;
  11728. }
  11729. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11730. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11731. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11732. return;
  11733. }
  11734. 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) )
  11735. { // Consumable or pets are not allowed
  11736. clif_Auction_setitem(sd->fd, idx, true);
  11737. return;
  11738. }
  11739. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11740. !sd->status.inventory[idx].identify ||
  11741. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11742. clif_Auction_setitem(sd->fd, idx, true);
  11743. return;
  11744. }
  11745. sd->auction.index = idx;
  11746. sd->auction.amount = amount;
  11747. clif_Auction_setitem(fd, idx + 2, false);
  11748. }
  11749. /// Result from an auction action (ZC_AUCTION_RESULT).
  11750. /// 0250 <result>.B
  11751. /// result:
  11752. /// 0 = You have failed to bid into the auction
  11753. /// 1 = You have successfully bid in the auction
  11754. /// 2 = The auction has been canceled
  11755. /// 3 = An auction with at least one bidder cannot be canceled
  11756. /// 4 = You cannot register more than 5 items in an auction at a time
  11757. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11758. /// 6 = You have won the auction
  11759. /// 7 = You have failed to win the auction
  11760. /// 8 = You do not have enough Zeny
  11761. /// 9 = You cannot place more than 5 bids at a time
  11762. void clif_Auction_message(int fd, unsigned char flag)
  11763. {
  11764. WFIFOHEAD(fd,packet_len(0x250));
  11765. WFIFOW(fd,0) = 0x250;
  11766. WFIFOB(fd,2) = flag;
  11767. WFIFOSET(fd,packet_len(0x250));
  11768. }
  11769. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11770. /// 025e <result>.W
  11771. /// result:
  11772. /// 0 = You have ended the auction
  11773. /// 1 = You cannot end the auction
  11774. /// 2 = Auction ID is incorrect
  11775. void clif_Auction_close(int fd, unsigned char flag)
  11776. {
  11777. WFIFOHEAD(fd,packet_len(0x25e));
  11778. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11779. WFIFOW(fd,2) = flag;
  11780. WFIFOSET(fd,packet_len(0x25e));
  11781. }
  11782. /// Request to add an auction (CZ_AUCTION_ADD).
  11783. /// 024d <now money>.L <max money>.L <delete hour>.W
  11784. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11785. {
  11786. struct auction_data auction;
  11787. struct item_data *item;
  11788. auction.price = RFIFOL(fd,2);
  11789. auction.buynow = RFIFOL(fd,6);
  11790. auction.hours = RFIFOW(fd,10);
  11791. // Invalid Situations...
  11792. if( sd->auction.amount < 1 )
  11793. {
  11794. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11795. return;
  11796. }
  11797. if( auction.price >= auction.buynow )
  11798. {
  11799. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11800. return;
  11801. }
  11802. if( auction.hours < 1 || auction.hours > 48 )
  11803. {
  11804. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11805. return;
  11806. }
  11807. // Auction checks...
  11808. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11809. {
  11810. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11811. return;
  11812. }
  11813. if( auction.buynow > battle_config.auction_maximumprice )
  11814. { // Zeny Limits
  11815. auction.buynow = battle_config.auction_maximumprice;
  11816. if( auction.price >= auction.buynow )
  11817. auction.price = auction.buynow - 1;
  11818. }
  11819. auction.auction_id = 0;
  11820. auction.seller_id = sd->status.char_id;
  11821. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11822. auction.buyer_id = 0;
  11823. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11824. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11825. {
  11826. clif_Auction_message(fd, 2); // The auction has been canceled
  11827. return;
  11828. }
  11829. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11830. { // Just in case
  11831. clif_Auction_message(fd, 2); // The auction has been canceled
  11832. return;
  11833. }
  11834. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11835. auction.type = item->type;
  11836. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11837. auction.item.amount = 1;
  11838. auction.timestamp = 0;
  11839. if( !intif_Auction_register(&auction) )
  11840. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11841. else
  11842. {
  11843. int zeny = auction.hours*battle_config.auction_feeperhour;
  11844. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11845. sd->auction.amount = 0;
  11846. log_zeny(sd, LOG_TYPE_AUCTION, sd, -zeny);
  11847. pc_payzeny(sd, zeny);
  11848. }
  11849. }
  11850. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11851. /// 024e <auction id>.L
  11852. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11853. {
  11854. unsigned int auction_id = RFIFOL(fd,2);
  11855. intif_Auction_cancel(sd->status.char_id, auction_id);
  11856. }
  11857. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11858. /// 025d <auction id>.L
  11859. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11860. {
  11861. unsigned int auction_id = RFIFOL(fd,2);
  11862. intif_Auction_close(sd->status.char_id, auction_id);
  11863. }
  11864. /// Places a bid on an auction (CZ_AUCTION_BUY).
  11865. /// 024f <auction id>.L <money>.L
  11866. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11867. {
  11868. unsigned int auction_id = RFIFOL(fd,2);
  11869. int bid = RFIFOL(fd,6);
  11870. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  11871. clif_displaymessage(sd->fd, msg_txt(246));
  11872. return;
  11873. }
  11874. if( bid <= 0 )
  11875. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11876. else if( bid > sd->status.zeny )
  11877. clif_Auction_message(fd, 8); // You do not have enough zeny
  11878. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  11879. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11880. else {
  11881. log_zeny(sd, LOG_TYPE_AUCTION, sd, -bid);
  11882. pc_payzeny(sd, bid);
  11883. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11884. }
  11885. }
  11886. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  11887. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  11888. /// search type:
  11889. /// 0 = armor
  11890. /// 1 = weapon
  11891. /// 2 = card
  11892. /// 3 = misc
  11893. /// 4 = name search
  11894. /// 5 = auction id search
  11895. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11896. {
  11897. char search_text[NAME_LENGTH];
  11898. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11899. int price = RFIFOL(fd,4); // FIXME: bug #5071
  11900. clif_parse_Auction_cancelreg(fd, sd);
  11901. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  11902. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11903. }
  11904. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  11905. /// 025c <type>.W
  11906. /// type:
  11907. /// 0 = sell (own auctions)
  11908. /// 1 = buy (own bids)
  11909. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11910. {
  11911. short type = RFIFOW(fd,2) + 6;
  11912. clif_parse_Auction_cancelreg(fd, sd);
  11913. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11914. }
  11915. /// CASH/POINT SHOP
  11916. ///
  11917. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  11918. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  11919. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  11920. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11921. {
  11922. int fd,i;
  11923. #if PACKETVER < 20070711
  11924. const int offset = 8;
  11925. #else
  11926. const int offset = 12;
  11927. #endif
  11928. nullpo_retv(sd);
  11929. nullpo_retv(nd);
  11930. fd = sd->fd;
  11931. sd->npc_shopid = nd->bl.id;
  11932. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  11933. WFIFOW(fd,0) = 0x287;
  11934. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  11935. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11936. #if PACKETVER >= 20070711
  11937. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11938. #endif
  11939. for( i = 0; i < nd->u.shop.count; i++ )
  11940. {
  11941. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11942. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  11943. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  11944. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  11945. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11946. }
  11947. WFIFOSET(fd,WFIFOW(fd,2));
  11948. }
  11949. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  11950. /// 0289 <cash point>.L <error>.W
  11951. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  11952. /// error:
  11953. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  11954. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11955. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11956. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11957. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11958. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11959. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11960. /// 7 = You can purchase up to 10 items.
  11961. /// 8 = Some items could not be purchased.
  11962. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11963. {
  11964. int fd = sd->fd;
  11965. WFIFOHEAD(fd, packet_len(0x289));
  11966. WFIFOW(fd,0) = 0x289;
  11967. WFIFOL(fd,2) = sd->cashPoints;
  11968. #if PACKETVER < 20070711
  11969. WFIFOW(fd,6) = TOW(error);
  11970. #else
  11971. WFIFOL(fd,6) = sd->kafraPoints;
  11972. WFIFOW(fd,10) = TOW(error);
  11973. #endif
  11974. WFIFOSET(fd, packet_len(0x289));
  11975. }
  11976. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  11977. /// 0288 <name id>.W <amount>.W
  11978. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  11979. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  11980. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11981. {
  11982. int fail = 0;
  11983. nullpo_retv(sd);
  11984. if( sd->state.trading || !sd->npc_shopid )
  11985. fail = 1;
  11986. else
  11987. {
  11988. #if PACKETVER < 20101116
  11989. short nameid = RFIFOW(fd,2);
  11990. short amount = RFIFOW(fd,4);
  11991. int points = RFIFOL(fd,6);
  11992. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11993. #else
  11994. int len = RFIFOW(fd,2);
  11995. int points = RFIFOL(fd,4);
  11996. int count = RFIFOW(fd,8);
  11997. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  11998. if( len < 10 || len != 10 + count * 4)
  11999. {
  12000. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  12001. return;
  12002. }
  12003. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12004. #endif
  12005. }
  12006. clif_cashshop_ack(sd,fail);
  12007. }
  12008. /// Adoption System
  12009. ///
  12010. /// Adoption message (ZC_BABYMSG).
  12011. /// 0216 <msg>.L
  12012. /// msg:
  12013. /// 0 = "You cannot adopt more than 1 child."
  12014. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12015. /// 2 = "You cannot adopt a married person."
  12016. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12017. {
  12018. int fd = sd->fd;
  12019. WFIFOHEAD(fd,6);
  12020. WFIFOW(fd,0) = 0x216;
  12021. WFIFOL(fd,2) = type;
  12022. WFIFOSET(fd,6);
  12023. }
  12024. /// Adoption confirmation (ZC_REQ_BABY).
  12025. /// 01f6 <account id>.L <char id>.L <name>.B
  12026. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12027. {
  12028. int fd = sd->fd;
  12029. WFIFOHEAD(fd,34);
  12030. WFIFOW(fd,0) = 0x1f6;
  12031. WFIFOL(fd,2) = src->status.account_id;
  12032. WFIFOL(fd,6) = p_id;
  12033. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12034. WFIFOSET(fd,34);
  12035. }
  12036. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12037. /// 01f9 <account id>.L
  12038. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12039. {
  12040. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12041. if( pc_can_Adopt(sd, p_sd, tsd) )
  12042. {
  12043. tsd->adopt_invite = sd->status.account_id;
  12044. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12045. }
  12046. }
  12047. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12048. /// 01f7 <account id>.L <char id>.L <answer>.L
  12049. /// answer:
  12050. /// 0 = rejected
  12051. /// 1 = accepted
  12052. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12053. {
  12054. int p1_id = RFIFOL(fd,2);
  12055. int p2_id = RFIFOL(fd,6);
  12056. int result = RFIFOL(fd,10);
  12057. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12058. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12059. int pid = sd->adopt_invite;
  12060. sd->adopt_invite = 0;
  12061. if( p1_sd == NULL || p2_sd == NULL )
  12062. return; // Both players need to be online
  12063. if( pid != p1_sd->status.account_id )
  12064. return; // Incorrect values
  12065. if( result == 0 )
  12066. return; // Rejected
  12067. pc_adoption(p1_sd, p2_sd, sd);
  12068. }
  12069. /// Convex Mirror (ZC_BOSS_INFO).
  12070. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12071. /// infoType:
  12072. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12073. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12074. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12075. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12076. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12077. {
  12078. WFIFOHEAD(fd,70);
  12079. memset(WFIFOP(fd,0),0,70);
  12080. WFIFOW(fd,0) = 0x293;
  12081. if( md != NULL )
  12082. {
  12083. if( md->bl.prev != NULL )
  12084. { // Boss on This Map
  12085. if( flag )
  12086. {
  12087. WFIFOB(fd,2) = 1;
  12088. WFIFOL(fd,3) = md->bl.x;
  12089. WFIFOL(fd,7) = md->bl.y;
  12090. }
  12091. else
  12092. WFIFOB(fd,2) = 2; // First Time
  12093. }
  12094. else if (md->spawn_timer != INVALID_TIMER)
  12095. { // Boss is Dead
  12096. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12097. unsigned int seconds;
  12098. int hours, minutes;
  12099. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12100. hours = seconds / (60 * 60);
  12101. seconds = seconds - (60 * 60 * hours);
  12102. minutes = seconds / 60;
  12103. WFIFOB(fd,2) = 3;
  12104. WFIFOW(fd,11) = hours; // Hours
  12105. WFIFOW(fd,13) = minutes; // Minutes
  12106. }
  12107. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12108. }
  12109. WFIFOSET(fd,70);
  12110. }
  12111. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12112. /// 02d6 <account id>.L
  12113. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12114. {
  12115. int charid = RFIFOL(fd, 2);
  12116. struct map_session_data* tsd = map_id2sd(charid);
  12117. if (!tsd)
  12118. return;
  12119. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12120. clif_viewequip_ack(sd, tsd);
  12121. else
  12122. clif_viewequip_fail(sd);
  12123. }
  12124. /// Request to change equip window tick (CZ_CONFIG).
  12125. /// 02d8 <type>.L <value>.L
  12126. /// type:
  12127. /// 0 = open equip window
  12128. /// value:
  12129. /// 0 = disabled
  12130. /// 1 = enabled
  12131. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12132. {
  12133. bool flag = (bool)RFIFOL(fd,6);
  12134. sd->status.show_equip = flag;
  12135. clif_equiptickack(sd, flag);
  12136. }
  12137. /// Questlog System [Kevin] [Inkfish]
  12138. ///
  12139. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12140. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12141. void clif_quest_send_list(struct map_session_data * sd)
  12142. {
  12143. int fd = sd->fd;
  12144. int i;
  12145. int len = sd->avail_quests*5+8;
  12146. WFIFOHEAD(fd,len);
  12147. WFIFOW(fd, 0) = 0x2b1;
  12148. WFIFOW(fd, 2) = len;
  12149. WFIFOL(fd, 4) = sd->avail_quests;
  12150. for( i = 0; i < sd->avail_quests; i++ )
  12151. {
  12152. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12153. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12154. }
  12155. WFIFOSET(fd, len);
  12156. }
  12157. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12158. /// 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
  12159. void clif_quest_send_mission(struct map_session_data * sd)
  12160. {
  12161. int fd = sd->fd;
  12162. int i, j;
  12163. int len = sd->avail_quests*104+8;
  12164. struct mob_db *mob;
  12165. WFIFOHEAD(fd, len);
  12166. WFIFOW(fd, 0) = 0x2b2;
  12167. WFIFOW(fd, 2) = len;
  12168. WFIFOL(fd, 4) = sd->avail_quests;
  12169. for( i = 0; i < sd->avail_quests; i++ )
  12170. {
  12171. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12172. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12173. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12174. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12175. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  12176. {
  12177. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12178. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12179. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12180. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12181. }
  12182. }
  12183. WFIFOSET(fd, len);
  12184. }
  12185. /// Notification about a new quest (ZC_ADD_QUEST).
  12186. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12187. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12188. {
  12189. int fd = sd->fd;
  12190. int i;
  12191. struct mob_db *mob;
  12192. WFIFOHEAD(fd, packet_len(0x2b3));
  12193. WFIFOW(fd, 0) = 0x2b3;
  12194. WFIFOL(fd, 2) = qd->quest_id;
  12195. WFIFOB(fd, 6) = qd->state;
  12196. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12197. WFIFOL(fd, 11) = qd->time;
  12198. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12199. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12200. {
  12201. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12202. WFIFOW(fd, i*30+21) = qd->count[i];
  12203. mob = mob_db(quest_db[index].mob[i]);
  12204. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12205. }
  12206. WFIFOSET(fd, packet_len(0x2b3));
  12207. }
  12208. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12209. /// 02b4 <quest id>.L
  12210. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12211. {
  12212. int fd = sd->fd;
  12213. WFIFOHEAD(fd, packet_len(0x2b4));
  12214. WFIFOW(fd, 0) = 0x2b4;
  12215. WFIFOL(fd, 2) = quest_id;
  12216. WFIFOSET(fd, packet_len(0x2b4));
  12217. }
  12218. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12219. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12220. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12221. {
  12222. int fd = sd->fd;
  12223. int i;
  12224. int len = quest_db[index].num_objectives*12+6;
  12225. WFIFOHEAD(fd, len);
  12226. WFIFOW(fd, 0) = 0x2b5;
  12227. WFIFOW(fd, 2) = len;
  12228. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12229. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12230. {
  12231. WFIFOL(fd, i*12+6) = qd->quest_id;
  12232. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12233. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12234. WFIFOW(fd, i*12+16) = qd->count[i];
  12235. }
  12236. WFIFOSET(fd, len);
  12237. }
  12238. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12239. /// 02b6 <quest id>.L <active>.B
  12240. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12241. {
  12242. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12243. }
  12244. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12245. /// 02b7 <quest id>.L <active>.B
  12246. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12247. {
  12248. int fd = sd->fd;
  12249. WFIFOHEAD(fd, packet_len(0x2b7));
  12250. WFIFOW(fd, 0) = 0x2b7;
  12251. WFIFOL(fd, 2) = quest_id;
  12252. WFIFOB(fd, 6) = active;
  12253. WFIFOSET(fd, packet_len(0x2b7));
  12254. }
  12255. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12256. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12257. /// effect:
  12258. /// 0 = none
  12259. /// 1 = exclamation mark icon
  12260. /// 2 = question mark icon
  12261. /// type:
  12262. /// 0 = yellow
  12263. /// 1 = orange
  12264. /// 2 = green
  12265. /// 3 = purple
  12266. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12267. {
  12268. #if PACKETVER >= 20090218
  12269. int fd = sd->fd;
  12270. WFIFOHEAD(fd, packet_len(0x446));
  12271. WFIFOW(fd, 0) = 0x446;
  12272. WFIFOL(fd, 2) = bl->id;
  12273. WFIFOW(fd, 6) = bl->x;
  12274. WFIFOW(fd, 8) = bl->y;
  12275. WFIFOW(fd, 10) = state;
  12276. WFIFOW(fd, 12) = color;
  12277. WFIFOSET(fd, packet_len(0x446));
  12278. #endif
  12279. }
  12280. /// Mercenary System
  12281. ///
  12282. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12283. /// 02a2 <var id>.W <value>.L
  12284. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12285. {
  12286. struct mercenary_data *md;
  12287. struct status_data *status;
  12288. int fd;
  12289. if( sd == NULL || (md = sd->md) == NULL )
  12290. return;
  12291. fd = sd->fd;
  12292. status = &md->battle_status;
  12293. WFIFOHEAD(fd,packet_len(0x2a2));
  12294. WFIFOW(fd,0) = 0x2a2;
  12295. WFIFOW(fd,2) = type;
  12296. switch( type )
  12297. {
  12298. case SP_ATK1:
  12299. {
  12300. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12301. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12302. }
  12303. break;
  12304. case SP_MATK1:
  12305. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12306. break;
  12307. case SP_HIT:
  12308. WFIFOL(fd,4) = status->hit;
  12309. break;
  12310. case SP_CRITICAL:
  12311. WFIFOL(fd,4) = status->cri/10;
  12312. break;
  12313. case SP_DEF1:
  12314. WFIFOL(fd,4) = status->def;
  12315. break;
  12316. case SP_MDEF1:
  12317. WFIFOL(fd,4) = status->mdef;
  12318. break;
  12319. case SP_MERCFLEE:
  12320. WFIFOL(fd,4) = status->flee;
  12321. break;
  12322. case SP_ASPD:
  12323. WFIFOL(fd,4) = status->amotion;
  12324. break;
  12325. case SP_HP:
  12326. WFIFOL(fd,4) = status->hp;
  12327. break;
  12328. case SP_MAXHP:
  12329. WFIFOL(fd,4) = status->max_hp;
  12330. break;
  12331. case SP_SP:
  12332. WFIFOL(fd,4) = status->sp;
  12333. break;
  12334. case SP_MAXSP:
  12335. WFIFOL(fd,4) = status->max_sp;
  12336. break;
  12337. case SP_MERCKILLS:
  12338. WFIFOL(fd,4) = md->mercenary.kill_count;
  12339. break;
  12340. case SP_MERCFAITH:
  12341. WFIFOL(fd,4) = mercenary_get_faith(md);
  12342. break;
  12343. }
  12344. WFIFOSET(fd,packet_len(0x2a2));
  12345. }
  12346. /// Mercenary base status data (ZC_MER_INIT).
  12347. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12348. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12349. /// <calls>.L <kills>.L <atk range>.W
  12350. void clif_mercenary_info(struct map_session_data *sd)
  12351. {
  12352. int fd;
  12353. struct mercenary_data *md;
  12354. struct status_data *status;
  12355. int atk;
  12356. if( sd == NULL || (md = sd->md) == NULL )
  12357. return;
  12358. fd = sd->fd;
  12359. status = &md->battle_status;
  12360. WFIFOHEAD(fd,packet_len(0x29b));
  12361. WFIFOW(fd,0) = 0x29b;
  12362. WFIFOL(fd,2) = md->bl.id;
  12363. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12364. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12365. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12366. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12367. WFIFOW(fd,10) = status->hit;
  12368. WFIFOW(fd,12) = status->cri/10;
  12369. WFIFOW(fd,14) = status->def;
  12370. WFIFOW(fd,16) = status->mdef;
  12371. WFIFOW(fd,18) = status->flee;
  12372. WFIFOW(fd,20) = status->amotion;
  12373. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12374. WFIFOW(fd,46) = md->db->lv;
  12375. WFIFOL(fd,48) = status->hp;
  12376. WFIFOL(fd,52) = status->max_hp;
  12377. WFIFOL(fd,56) = status->sp;
  12378. WFIFOL(fd,60) = status->max_sp;
  12379. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12380. WFIFOW(fd,68) = mercenary_get_faith(md);
  12381. WFIFOL(fd,70) = mercenary_get_calls(md);
  12382. WFIFOL(fd,74) = md->mercenary.kill_count;
  12383. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12384. WFIFOSET(fd,packet_len(0x29b));
  12385. }
  12386. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12387. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12388. void clif_mercenary_skillblock(struct map_session_data *sd)
  12389. {
  12390. struct mercenary_data *md;
  12391. int fd, i, len = 4, id, j;
  12392. if( sd == NULL || (md = sd->md) == NULL )
  12393. return;
  12394. fd = sd->fd;
  12395. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12396. WFIFOW(fd,0) = 0x29d;
  12397. for( i = 0; i < MAX_MERCSKILL; i++ )
  12398. {
  12399. if( (id = md->db->skill[i].id) == 0 )
  12400. continue;
  12401. j = id - MC_SKILLBASE;
  12402. WFIFOW(fd,len) = id;
  12403. WFIFOL(fd,len+2) = skill_get_inf(id);
  12404. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12405. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12406. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12407. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12408. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12409. len += 37;
  12410. }
  12411. WFIFOW(fd,2) = len;
  12412. WFIFOSET(fd,len);
  12413. }
  12414. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12415. /// 029f <command>.B
  12416. /// 1 = mercenary information
  12417. /// 2 = delete
  12418. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12419. {
  12420. int option = RFIFOB(fd,2);
  12421. if( sd->md == NULL )
  12422. return;
  12423. if( option == 2 ) merc_delete(sd->md, 2);
  12424. }
  12425. /// Mercenary Message
  12426. /// message:
  12427. /// 0 = Mercenary soldier's duty hour is over.
  12428. /// 1 = Your mercenary soldier has been killed.
  12429. /// 2 = Your mercenary soldier has been fired.
  12430. /// 3 = Your mercenary soldier has ran away.
  12431. void clif_mercenary_message(struct map_session_data* sd, int message)
  12432. {
  12433. clif_msg(sd, 1266 + message);
  12434. }
  12435. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12436. /// 0298 <name id>.W <seconds>.L
  12437. void clif_rental_time(int fd, int nameid, int seconds)
  12438. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12439. WFIFOHEAD(fd,packet_len(0x298));
  12440. WFIFOW(fd,0) = 0x298;
  12441. WFIFOW(fd,2) = nameid;
  12442. WFIFOL(fd,4) = seconds;
  12443. WFIFOSET(fd,packet_len(0x298));
  12444. }
  12445. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12446. /// 0299 <index>.W <name id>.W
  12447. void clif_rental_expired(int fd, int index, int nameid)
  12448. { // '<ItemName>' item has been deleted from the Inventory
  12449. WFIFOHEAD(fd,packet_len(0x299));
  12450. WFIFOW(fd,0) = 0x299;
  12451. WFIFOW(fd,2) = index+2;
  12452. WFIFOW(fd,4) = nameid;
  12453. WFIFOSET(fd,packet_len(0x299));
  12454. }
  12455. /// Book Reading (ZC_READ_BOOK).
  12456. /// 0294 <book id>.L <page>.L
  12457. void clif_readbook(int fd, int book_id, int page)
  12458. {
  12459. WFIFOHEAD(fd,packet_len(0x294));
  12460. WFIFOW(fd,0) = 0x294;
  12461. WFIFOL(fd,2) = book_id;
  12462. WFIFOL(fd,6) = page;
  12463. WFIFOSET(fd,packet_len(0x294));
  12464. }
  12465. /// Battlegrounds
  12466. ///
  12467. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12468. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12469. void clif_bg_hp(struct map_session_data *sd)
  12470. {
  12471. unsigned char buf[34];
  12472. const int cmd = 0x2e0;
  12473. nullpo_retv(sd);
  12474. WBUFW(buf,0) = cmd;
  12475. WBUFL(buf,2) = sd->status.account_id;
  12476. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12477. if( sd->battle_status.max_hp > INT16_MAX )
  12478. { // To correctly display the %hp bar. [Skotlex]
  12479. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12480. WBUFW(buf,32) = 100;
  12481. }
  12482. else
  12483. {
  12484. WBUFW(buf,30) = sd->battle_status.hp;
  12485. WBUFW(buf,32) = sd->battle_status.max_hp;
  12486. }
  12487. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12488. }
  12489. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12490. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12491. void clif_bg_xy(struct map_session_data *sd)
  12492. {
  12493. unsigned char buf[36];
  12494. nullpo_retv(sd);
  12495. WBUFW(buf,0)=0x2df;
  12496. WBUFL(buf,2)=sd->status.account_id;
  12497. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12498. WBUFW(buf,30)=sd->status.class_;
  12499. WBUFW(buf,32)=sd->bl.x;
  12500. WBUFW(buf,34)=sd->bl.y;
  12501. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12502. }
  12503. void clif_bg_xy_remove(struct map_session_data *sd)
  12504. {
  12505. unsigned char buf[36];
  12506. nullpo_retv(sd);
  12507. WBUFW(buf,0)=0x2df;
  12508. WBUFL(buf,2)=sd->status.account_id;
  12509. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12510. WBUFW(buf,30)=0;
  12511. WBUFW(buf,32)=-1;
  12512. WBUFW(buf,34)=-1;
  12513. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12514. }
  12515. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12516. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12517. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12518. {
  12519. struct map_session_data *sd;
  12520. unsigned char *buf;
  12521. if( (sd = bg_getavailablesd(bg)) == NULL )
  12522. return;
  12523. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12524. WBUFW(buf,0) = 0x2dc;
  12525. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12526. WBUFL(buf,4) = src_id;
  12527. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12528. memcpy(WBUFP(buf,32), mes, len);
  12529. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12530. if( buf )
  12531. aFree(buf);
  12532. }
  12533. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12534. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12535. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12536. {
  12537. const char* text = (char*)RFIFOP(fd,4);
  12538. int textlen = RFIFOW(fd,2) - 4;
  12539. char *name, *message;
  12540. int namelen, messagelen;
  12541. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12542. return;
  12543. if( is_atcommand(fd, sd, message, 1) )
  12544. return;
  12545. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12546. return;
  12547. if( battle_config.min_chat_delay )
  12548. {
  12549. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12550. return;
  12551. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12552. }
  12553. bg_send_message(sd, text, textlen);
  12554. }
  12555. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12556. /// 02de <camp A points>.W <camp B points>.W
  12557. void clif_bg_updatescore(int m)
  12558. {
  12559. struct block_list bl;
  12560. unsigned char buf[6];
  12561. bl.id = 0;
  12562. bl.type = BL_NUL;
  12563. bl.m = m;
  12564. WBUFW(buf,0) = 0x2de;
  12565. WBUFW(buf,2) = map[m].bgscore_lion;
  12566. WBUFW(buf,4) = map[m].bgscore_eagle;
  12567. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12568. }
  12569. void clif_bg_updatescore_single(struct map_session_data *sd)
  12570. {
  12571. int fd;
  12572. nullpo_retv(sd);
  12573. fd = sd->fd;
  12574. WFIFOHEAD(fd,packet_len(0x2de));
  12575. WFIFOW(fd,0) = 0x2de;
  12576. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12577. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12578. WFIFOSET(fd,packet_len(0x2de));
  12579. }
  12580. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12581. /// 02dd <account id>.L <name>.24B <camp>.W
  12582. void clif_sendbgemblem_area(struct map_session_data *sd)
  12583. {
  12584. unsigned char buf[33];
  12585. nullpo_retv(sd);
  12586. WBUFW(buf, 0) = 0x2dd;
  12587. WBUFL(buf,2) = sd->bl.id;
  12588. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12589. WBUFW(buf,30) = sd->bg_id;
  12590. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12591. }
  12592. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12593. {
  12594. nullpo_retv(sd);
  12595. WFIFOHEAD(fd,32);
  12596. WFIFOW(fd,0) = 0x2dd;
  12597. WFIFOL(fd,2) = sd->bl.id;
  12598. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12599. WFIFOW(fd,30) = sd->bg_id;
  12600. WFIFOSET(fd,packet_len(0x2dd));
  12601. }
  12602. /// Custom Fonts (ZC_NOTIFY_FONT).
  12603. /// 02ef <account_id>.L <font id>.W
  12604. void clif_font(struct map_session_data *sd)
  12605. {
  12606. #if PACKETVER >= 20080102
  12607. unsigned char buf[8];
  12608. nullpo_retv(sd);
  12609. WBUFW(buf,0) = 0x2ef;
  12610. WBUFL(buf,2) = sd->bl.id;
  12611. WBUFW(buf,6) = sd->user_font;
  12612. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12613. #endif
  12614. }
  12615. /*==========================================
  12616. * Instancing Window
  12617. *------------------------------------------*/
  12618. int clif_instance(int instance_id, int type, int flag)
  12619. {
  12620. struct map_session_data *sd;
  12621. struct party_data *p;
  12622. unsigned char buf[255];
  12623. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12624. return 0;
  12625. switch( type )
  12626. {
  12627. case 1:
  12628. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12629. // Required to start the instancing information window on Client
  12630. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12631. WBUFW(buf,0) = 0x02CB;
  12632. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12633. WBUFW(buf,63) = flag;
  12634. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12635. break;
  12636. case 2:
  12637. // S 0x2cc <Standby Position>.W
  12638. // To announce Instancing queue creation if no maps available
  12639. WBUFW(buf,0) = 0x02CC;
  12640. WBUFW(buf,2) = flag;
  12641. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12642. break;
  12643. case 3:
  12644. case 4:
  12645. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12646. WBUFW(buf,0) = 0x02CD;
  12647. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12648. if( type == 3 )
  12649. {
  12650. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12651. WBUFL(buf,67) = 0;
  12652. }
  12653. else
  12654. {
  12655. WBUFL(buf,63) = 0;
  12656. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12657. }
  12658. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12659. break;
  12660. case 5:
  12661. // S 0x2ce <Message ID>.L
  12662. // 0 = Notification (EnterLimitDate update?)
  12663. // 1 = The Memorial Dungeon expired; it has been destroyed
  12664. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12665. // 3 = The Memorial Dungeon has been removed.
  12666. // 4 = Create failure (removes the instance window)
  12667. WBUFW(buf,0) = 0x02CE;
  12668. WBUFL(buf,2) = flag;
  12669. //WBUFL(buf,6) = EnterLimitDate;
  12670. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12671. break;
  12672. }
  12673. return 0;
  12674. }
  12675. void clif_instance_join(int fd, int instance_id)
  12676. {
  12677. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12678. {
  12679. WFIFOHEAD(fd,packet_len(0x02CD));
  12680. WFIFOW(fd,0) = 0x02CD;
  12681. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12682. WFIFOL(fd,63) = 0;
  12683. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12684. WFIFOSET(fd,packet_len(0x02CD));
  12685. }
  12686. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12687. {
  12688. WFIFOHEAD(fd,packet_len(0x02CD));
  12689. WFIFOW(fd,0) = 0x02CD;
  12690. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12691. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12692. WFIFOL(fd,67) = 0;
  12693. WFIFOSET(fd,packet_len(0x02CD));
  12694. }
  12695. else
  12696. {
  12697. WFIFOHEAD(fd,packet_len(0x02CB));
  12698. WFIFOW(fd,0) = 0x02CB;
  12699. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12700. WFIFOW(fd,63) = 0;
  12701. WFIFOSET(fd,packet_len(0x02CB));
  12702. }
  12703. }
  12704. void clif_instance_leave(int fd)
  12705. {
  12706. WFIFOHEAD(fd,packet_len(0x02CE));
  12707. WFIFOW(fd,0) = 0x02ce;
  12708. WFIFOL(fd,2) = 4;
  12709. WFIFOSET(fd,packet_len(0x02CE));
  12710. }
  12711. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12712. /// 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
  12713. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12714. {
  12715. #if PACKETVER >= 20071002
  12716. unsigned char buf[22];
  12717. struct item_data* id = itemdb_search(item_data->nameid);
  12718. WBUFW(buf,0) = 0x2b8;
  12719. WBUFL(buf,2) = sd->status.account_id;
  12720. WBUFW(buf,6) = item_data->nameid;
  12721. WBUFB(buf,8) = item_data->identify;
  12722. WBUFB(buf,9) = item_data->attribute;
  12723. WBUFB(buf,10) = item_data->refine;
  12724. clif_addcards(WBUFP(buf,11), item_data);
  12725. WBUFW(buf,19) = id->equip; // equip location
  12726. WBUFB(buf,21) = itemtype(id->type); // item type
  12727. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12728. #endif
  12729. }
  12730. /// Display gained exp (ZC_NOTIFY_EXP).
  12731. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12732. /// var id:
  12733. /// SP_BASEEXP, SP_JOBEXP
  12734. /// exp type:
  12735. /// 0 = normal exp gain/loss
  12736. /// 1 = quest exp gain/loss
  12737. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12738. {
  12739. int fd;
  12740. nullpo_retv(sd);
  12741. fd = sd->fd;
  12742. WFIFOHEAD(fd, packet_len(0x7f6));
  12743. WFIFOW(fd,0) = 0x7f6;
  12744. WFIFOL(fd,2) = sd->bl.id;
  12745. WFIFOL(fd,6) = exp;
  12746. WFIFOW(fd,10) = type;
  12747. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12748. WFIFOSET(fd,packet_len(0x7f6));
  12749. }
  12750. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12751. /// type:
  12752. /// 0 = Displays 'value' for 5 seconds.
  12753. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12754. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12755. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12756. /// value:
  12757. /// 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).
  12758. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12759. {
  12760. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12761. WFIFOW(sd->fd,0) = 0x1b1;
  12762. WFIFOB(sd->fd,2) = type;
  12763. WFIFOL(sd->fd,3) = value;
  12764. WFIFOSET(sd->fd, packet_len(0x1b1));
  12765. }
  12766. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12767. /// 021d <state>.L
  12768. /// state:
  12769. /// 0 = Full effects
  12770. /// 1 = Reduced effects
  12771. ///
  12772. /// NOTE: The state is used on Aegis for sending skill unit packet
  12773. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12774. /// whenever possible. Due to the way the decision check is
  12775. /// constructed, this state tracking was rendered useless,
  12776. /// as the only skill unit, that is sent with 0x1c9 is
  12777. /// Graffiti.
  12778. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12779. {
  12780. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12781. sd->state.lesseffect = ( isLess != 0 );
  12782. }
  12783. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12784. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12785. int n = (RFIFOW(fd,2)-12) / 4;
  12786. int type = RFIFOL(fd,4);
  12787. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12788. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12789. if( sd->state.trading || sd->npc_shopid )
  12790. return;
  12791. if( flag == 0 || n == 0) {
  12792. clif_menuskill_clear(sd);
  12793. return; // Canceled by player.
  12794. }
  12795. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12796. clif_menuskill_clear(sd);
  12797. return; // Prevent hacking.
  12798. }
  12799. switch( type ) {
  12800. case 0: // Change Material
  12801. skill_changematerial(sd,n,item_list);
  12802. break;
  12803. case 1: // Level 1: Pure to Rough
  12804. case 2: // Level 2: Rough to Pure
  12805. skill_elementalanalysis(sd,n,type,item_list);
  12806. break;
  12807. }
  12808. clif_menuskill_clear(sd);
  12809. return;
  12810. }
  12811. /*==========================================
  12812. * Elemental System
  12813. *==========================================*/
  12814. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  12815. struct elemental_data *ed;
  12816. struct status_data *status;
  12817. int fd;
  12818. if( sd == NULL || (ed = sd->ed) == NULL )
  12819. return;
  12820. fd = sd->fd;
  12821. status = &ed->battle_status;
  12822. WFIFOHEAD(fd,8);
  12823. WFIFOW(fd,0) = 0x81e;
  12824. WFIFOW(fd,2) = type;
  12825. switch( type ) {
  12826. case SP_HP:
  12827. WFIFOL(fd,4) = status->hp;
  12828. break;
  12829. case SP_MAXHP:
  12830. WFIFOL(fd,4) = status->max_hp;
  12831. break;
  12832. case SP_SP:
  12833. WFIFOL(fd,4) = status->sp;
  12834. break;
  12835. case SP_MAXSP:
  12836. WFIFOL(fd,4) = status->max_sp;
  12837. break;
  12838. }
  12839. WFIFOSET(fd,8);
  12840. }
  12841. void clif_elemental_info(struct map_session_data *sd) {
  12842. int fd;
  12843. struct elemental_data *ed;
  12844. struct status_data *status;
  12845. if( sd == NULL || (ed = sd->ed) == NULL )
  12846. return;
  12847. fd = sd->fd;
  12848. status = &ed->battle_status;
  12849. WFIFOHEAD(fd,22);
  12850. WFIFOW(fd, 0) = 0x81d;
  12851. WFIFOL(fd, 2) = ed->bl.id;
  12852. WFIFOL(fd, 6) = status->hp;
  12853. WFIFOL(fd,10) = status->max_hp;
  12854. WFIFOL(fd,14) = status->sp;
  12855. WFIFOL(fd,18) = status->max_sp;
  12856. WFIFOSET(fd,22);
  12857. }
  12858. /// Buying Store System
  12859. ///
  12860. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12861. /// 0810 <slots>.B
  12862. void clif_buyingstore_open(struct map_session_data* sd)
  12863. {
  12864. int fd = sd->fd;
  12865. WFIFOHEAD(fd,packet_len(0x810));
  12866. WFIFOW(fd,0) = 0x810;
  12867. WFIFOB(fd,2) = sd->buyingstore.slots;
  12868. WFIFOSET(fd,packet_len(0x810));
  12869. }
  12870. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12871. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12872. /// result:
  12873. /// 0 = cancel
  12874. /// 1 = open
  12875. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12876. {
  12877. const unsigned int blocksize = 8;
  12878. uint8* itemlist;
  12879. char storename[MESSAGE_SIZE];
  12880. unsigned char result;
  12881. int zenylimit;
  12882. unsigned int count, packet_len;
  12883. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12884. packet_len = RFIFOW(fd,info->pos[0]);
  12885. // TODO: Make this check global for all variable length packets.
  12886. if( packet_len < 89 )
  12887. {// minimum packet length
  12888. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12889. return;
  12890. }
  12891. zenylimit = RFIFOL(fd,info->pos[1]);
  12892. result = RFIFOL(fd,info->pos[2]);
  12893. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12894. itemlist = RFIFOP(fd,info->pos[4]);
  12895. // so that buyingstore_create knows, how many elements it has access to
  12896. packet_len-= info->pos[4];
  12897. if( packet_len%blocksize )
  12898. {
  12899. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12900. return;
  12901. }
  12902. count = packet_len/blocksize;
  12903. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  12904. }
  12905. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  12906. /// 0812 <result>.W <total weight>.L
  12907. /// result:
  12908. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  12909. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  12910. /// 8 = "No sale (purchase) information available." (0x705)
  12911. /// ? = nothing
  12912. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  12913. {
  12914. int fd = sd->fd;
  12915. WFIFOHEAD(fd,packet_len(0x812));
  12916. WFIFOW(fd,0) = 0x812;
  12917. WFIFOW(fd,2) = result;
  12918. WFIFOL(fd,4) = weight;
  12919. WFIFOSET(fd,packet_len(0x812));
  12920. }
  12921. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  12922. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  12923. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  12924. {
  12925. int fd = sd->fd;
  12926. unsigned int i;
  12927. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  12928. WFIFOW(fd,0) = 0x813;
  12929. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  12930. WFIFOL(fd,4) = sd->bl.id;
  12931. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  12932. for( i = 0; i < sd->buyingstore.slots; i++ )
  12933. {
  12934. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  12935. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  12936. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  12937. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  12938. }
  12939. WFIFOSET(fd,WFIFOW(fd,2));
  12940. }
  12941. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  12942. /// 0814 <account id>.L <store name>.80B
  12943. void clif_buyingstore_entry(struct map_session_data* sd)
  12944. {
  12945. uint8 buf[86];
  12946. WBUFW(buf,0) = 0x814;
  12947. WBUFL(buf,2) = sd->bl.id;
  12948. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  12949. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  12950. }
  12951. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12952. {
  12953. int fd = sd->fd;
  12954. WFIFOHEAD(fd,packet_len(0x814));
  12955. WFIFOW(fd,0) = 0x814;
  12956. WFIFOL(fd,2) = pl_sd->bl.id;
  12957. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  12958. WFIFOSET(fd,packet_len(0x814));
  12959. }
  12960. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  12961. /// 0815
  12962. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  12963. {
  12964. buyingstore_close(sd);
  12965. }
  12966. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  12967. /// 0816 <account id>.L
  12968. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  12969. {
  12970. uint8 buf[6];
  12971. WBUFW(buf,0) = 0x816;
  12972. WBUFL(buf,2) = sd->bl.id;
  12973. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  12974. }
  12975. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12976. {
  12977. int fd = sd->fd;
  12978. WFIFOHEAD(fd,packet_len(0x816));
  12979. WFIFOW(fd,0) = 0x816;
  12980. WFIFOL(fd,2) = pl_sd->bl.id;
  12981. WFIFOSET(fd,packet_len(0x816));
  12982. }
  12983. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  12984. /// 0817 <account id>.L
  12985. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  12986. {
  12987. int account_id;
  12988. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12989. buyingstore_open(sd, account_id);
  12990. }
  12991. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  12992. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  12993. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  12994. {
  12995. int fd = sd->fd;
  12996. unsigned int i;
  12997. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  12998. WFIFOW(fd,0) = 0x818;
  12999. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13000. WFIFOL(fd,4) = pl_sd->bl.id;
  13001. WFIFOL(fd,8) = pl_sd->buyer_id;
  13002. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13003. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13004. {
  13005. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13006. 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.
  13007. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13008. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13009. }
  13010. WFIFOSET(fd,WFIFOW(fd,2));
  13011. }
  13012. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13013. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13014. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13015. {
  13016. const unsigned int blocksize = 6;
  13017. uint8* itemlist;
  13018. int account_id;
  13019. unsigned int count, packet_len, buyer_id;
  13020. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13021. packet_len = RFIFOW(fd,info->pos[0]);
  13022. if( packet_len < 12 )
  13023. {// minimum packet length
  13024. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13025. return;
  13026. }
  13027. account_id = RFIFOL(fd,info->pos[1]);
  13028. buyer_id = RFIFOL(fd,info->pos[2]);
  13029. itemlist = RFIFOP(fd,info->pos[3]);
  13030. // so that buyingstore_trade knows, how many elements it has access to
  13031. packet_len-= info->pos[3];
  13032. if( packet_len%blocksize )
  13033. {
  13034. 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);
  13035. return;
  13036. }
  13037. count = packet_len/blocksize;
  13038. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13039. }
  13040. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13041. /// 081a <result>.W
  13042. /// result:
  13043. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13044. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13045. /// ? = nothing
  13046. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13047. {
  13048. int fd = sd->fd;
  13049. WFIFOHEAD(fd,packet_len(0x81a));
  13050. WFIFOW(fd,0) = 0x81a;
  13051. WFIFOW(fd,2) = result;
  13052. WFIFOSET(fd,packet_len(0x81a));
  13053. }
  13054. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13055. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13056. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13057. {
  13058. int fd = sd->fd;
  13059. WFIFOHEAD(fd,packet_len(0x81b));
  13060. WFIFOW(fd,0) = 0x81b;
  13061. WFIFOW(fd,2) = nameid;
  13062. WFIFOW(fd,4) = amount; // amount of nameid received
  13063. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  13064. WFIFOSET(fd,packet_len(0x81b));
  13065. }
  13066. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13067. /// 081c <index>.W <amount>.W <price>.L
  13068. /// message:
  13069. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13070. ///
  13071. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13072. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13073. {
  13074. int fd = sd->fd;
  13075. WFIFOHEAD(fd,packet_len(0x81c));
  13076. WFIFOW(fd,0) = 0x81c;
  13077. WFIFOW(fd,2) = index+2;
  13078. WFIFOW(fd,4) = amount;
  13079. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13080. WFIFOSET(fd,packet_len(0x81c));
  13081. }
  13082. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13083. /// 0824 <result>.W <name id>.W
  13084. /// result:
  13085. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13086. /// 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)
  13087. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13088. /// ? = nothing
  13089. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13090. {
  13091. int fd = sd->fd;
  13092. WFIFOHEAD(fd,packet_len(0x824));
  13093. WFIFOW(fd,0) = 0x824;
  13094. WFIFOW(fd,2) = result;
  13095. WFIFOW(fd,4) = nameid;
  13096. WFIFOSET(fd,packet_len(0x824));
  13097. }
  13098. /// Search Store Info System
  13099. ///
  13100. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13101. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13102. /// type:
  13103. /// 0 = Vending
  13104. /// 1 = Buying Store
  13105. ///
  13106. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13107. /// amount of card slots. If the client does not know about the item it
  13108. /// cannot be searched.
  13109. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13110. {
  13111. const unsigned int blocksize = 2;
  13112. const uint8* itemlist;
  13113. const uint8* cardlist;
  13114. unsigned char type;
  13115. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13116. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13117. packet_len = RFIFOW(fd,info->pos[0]);
  13118. if( packet_len < 15 )
  13119. {// minimum packet length
  13120. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13121. return;
  13122. }
  13123. type = RFIFOB(fd,info->pos[1]);
  13124. max_price = RFIFOL(fd,info->pos[2]);
  13125. min_price = RFIFOL(fd,info->pos[3]);
  13126. item_count = RFIFOB(fd,info->pos[4]);
  13127. card_count = RFIFOB(fd,info->pos[5]);
  13128. itemlist = RFIFOP(fd,info->pos[6]);
  13129. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13130. // check, if there is enough data for the claimed count of items
  13131. packet_len-= info->pos[6];
  13132. if( packet_len%blocksize )
  13133. {
  13134. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13135. return;
  13136. }
  13137. count = packet_len/blocksize;
  13138. if( count < item_count+card_count )
  13139. {
  13140. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13141. return;
  13142. }
  13143. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13144. }
  13145. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13146. /// 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 }*
  13147. /// is first page:
  13148. /// 0 = appends to existing results
  13149. /// 1 = clears previous results before displaying this result set
  13150. /// is next page:
  13151. /// 0 = no "next" label
  13152. /// 1 = "next" label to retrieve more results
  13153. void clif_search_store_info_ack(struct map_session_data* sd)
  13154. {
  13155. const unsigned int blocksize = MESSAGE_SIZE+26;
  13156. int fd = sd->fd;
  13157. unsigned int i, start, end;
  13158. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13159. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13160. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13161. WFIFOW(fd,0) = 0x836;
  13162. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13163. WFIFOB(fd,4) = !sd->searchstore.pages;
  13164. WFIFOB(fd,5) = searchstore_querynext(sd);
  13165. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13166. for( i = start; i < end; i++ )
  13167. {
  13168. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13169. struct item it;
  13170. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13171. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13172. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13173. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13174. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13175. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13176. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13177. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13178. // make-up an item for clif_addcards
  13179. memset(&it, 0, sizeof(it));
  13180. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13181. it.nameid = ssitem->nameid;
  13182. it.amount = ssitem->amount;
  13183. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13184. }
  13185. WFIFOSET(fd,WFIFOW(fd,2));
  13186. }
  13187. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13188. /// 0837 <reason>.B
  13189. /// reason:
  13190. /// 0 = "No matching stores were found." (0x70b)
  13191. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13192. /// 2 = "You cannot search anymore." (0x706)
  13193. /// 3 = "You cannot search yet." (0x708)
  13194. /// 4 = "No sale (purchase) information available." (0x705)
  13195. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13196. {
  13197. int fd = sd->fd;
  13198. WFIFOHEAD(fd,packet_len(0x837));
  13199. WFIFOW(fd,0) = 0x837;
  13200. WFIFOB(fd,2) = reason;
  13201. WFIFOSET(fd,packet_len(0x837));
  13202. }
  13203. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13204. /// 0838
  13205. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13206. {
  13207. searchstore_next(sd);
  13208. }
  13209. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13210. /// 083a <type>.W <remaining uses>.B
  13211. /// type:
  13212. /// 0 = Search Stores
  13213. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13214. void clif_open_search_store_info(struct map_session_data* sd)
  13215. {
  13216. int fd = sd->fd;
  13217. WFIFOHEAD(fd,packet_len(0x83a));
  13218. WFIFOW(fd,0) = 0x83a;
  13219. WFIFOW(fd,2) = sd->searchstore.effect;
  13220. #if PACKETVER > 20100701
  13221. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13222. #endif
  13223. WFIFOSET(fd,packet_len(0x83a));
  13224. }
  13225. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13226. /// 083b
  13227. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13228. {
  13229. searchstore_close(sd);
  13230. }
  13231. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13232. /// 083c <account id>.L <store id>.L <nameid>.W
  13233. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13234. {
  13235. unsigned short nameid;
  13236. int account_id, store_id;
  13237. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13238. account_id = RFIFOL(fd,info->pos[0]);
  13239. store_id = RFIFOL(fd,info->pos[1]);
  13240. nameid = RFIFOW(fd,info->pos[2]);
  13241. searchstore_click(sd, account_id, store_id, nameid);
  13242. }
  13243. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13244. /// 083d <xPos>.W <yPos>.W
  13245. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13246. {
  13247. int fd = sd->fd;
  13248. WFIFOHEAD(fd,packet_len(0x83d));
  13249. WFIFOW(fd,0) = 0x83d;
  13250. WFIFOW(fd,2) = x;
  13251. WFIFOW(fd,4) = y;
  13252. WFIFOSET(fd,packet_len(0x83d));
  13253. }
  13254. /// Parse function for packet debugging.
  13255. void clif_parse_debug(int fd,struct map_session_data *sd)
  13256. {
  13257. int cmd, packet_len;
  13258. // clif_parse ensures, that there is at least 2 bytes of data
  13259. cmd = RFIFOW(fd,0);
  13260. if( sd )
  13261. {
  13262. packet_len = packet_db[sd->packet_ver][cmd].len;
  13263. if( packet_len == 0 )
  13264. {// unknown
  13265. packet_len = RFIFOREST(fd);
  13266. }
  13267. else if( packet_len == -1 )
  13268. {// variable length
  13269. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13270. }
  13271. 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);
  13272. }
  13273. else
  13274. {
  13275. packet_len = RFIFOREST(fd);
  13276. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13277. }
  13278. ShowDump(RFIFOP(fd,0), packet_len);
  13279. }
  13280. /*==========================================
  13281. * Server tells client to display a window similar to Magnifier (item) one
  13282. * Server populates the window with avilable elemental converter options according to player's inventory
  13283. *------------------------------------------*/
  13284. int clif_elementalconverter_list(struct map_session_data *sd) {
  13285. int i,c,view,fd;
  13286. nullpo_ret(sd);
  13287. /// Main client packet processing function
  13288. fd=sd->fd;
  13289. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13290. WFIFOW(fd, 0)=0x1ad;
  13291. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13292. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13293. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13294. WFIFOW(fd,c*2+ 4)= view;
  13295. else
  13296. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13297. c++;
  13298. }
  13299. }
  13300. WFIFOW(fd,2) = c*2+4;
  13301. WFIFOSET(fd, WFIFOW(fd,2));
  13302. if (c > 0) {
  13303. sd->menuskill_id = SA_CREATECON;
  13304. sd->menuskill_val = c;
  13305. }
  13306. return 0;
  13307. }
  13308. /**
  13309. * Rune Knight
  13310. **/
  13311. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13312. #if PACKETVER >= 20081217
  13313. unsigned char buf[10];
  13314. WBUFW(buf,0) = 0x440;
  13315. WBUFL(buf,2) = sd->bl.id;
  13316. WBUFW(buf,6) = shields;
  13317. WBUFW(buf,8) = 0;
  13318. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13319. #endif
  13320. }
  13321. /**
  13322. * Warlock
  13323. **/
  13324. /*==========================================
  13325. * Spellbook list [LimitLine/3CeAM]
  13326. *------------------------------------------*/
  13327. int clif_spellbook_list(struct map_session_data *sd)
  13328. {
  13329. int i, c;
  13330. int fd;
  13331. nullpo_ret(sd);
  13332. fd = sd->fd;
  13333. WFIFOHEAD(fd, 8 * 8 + 8);
  13334. WFIFOW(fd,0) = 0x1ad;
  13335. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13336. {
  13337. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13338. {
  13339. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13340. c ++;
  13341. }
  13342. }
  13343. if( c > 0 )
  13344. {
  13345. WFIFOW(fd,2) = c * 2 + 4;
  13346. WFIFOSET(fd, WFIFOW(fd, 2));
  13347. sd->menuskill_id = WL_READING_SB;
  13348. sd->menuskill_val = c;
  13349. }
  13350. else
  13351. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13352. return 1;
  13353. }
  13354. /**
  13355. * Mechanic
  13356. **/
  13357. /*==========================================
  13358. * Magic Decoy Material List
  13359. *------------------------------------------*/
  13360. int clif_magicdecoy_list(struct map_session_data *sd, int skill_lv, short x, short y) {
  13361. int i, c;
  13362. int fd;
  13363. nullpo_ret(sd);
  13364. fd = sd->fd;
  13365. WFIFOHEAD(fd, 8 * 8 + 8);
  13366. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13367. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13368. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13369. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13370. c ++;
  13371. }
  13372. }
  13373. if( c > 0 ) {
  13374. sd->menuskill_id = NC_MAGICDECOY;
  13375. sd->menuskill_val = skill_lv;
  13376. sd->sc.comet_x = x;
  13377. sd->sc.comet_y = y;
  13378. WFIFOW(fd,2) = c * 2 + 4;
  13379. WFIFOSET(fd, WFIFOW(fd, 2));
  13380. } else {
  13381. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13382. return 0;
  13383. }
  13384. return 1;
  13385. }
  13386. /**
  13387. * Guilotine Cross
  13388. **/
  13389. /*==========================================
  13390. * Guillotine Cross Poisons List
  13391. *------------------------------------------*/
  13392. int clif_poison_list(struct map_session_data *sd, int skill_lv) {
  13393. int i, c;
  13394. int fd;
  13395. nullpo_ret(sd);
  13396. fd = sd->fd;
  13397. WFIFOHEAD(fd, 8 * 8 + 8);
  13398. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13399. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13400. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13401. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13402. c ++;
  13403. }
  13404. }
  13405. if( c > 0 ) {
  13406. sd->menuskill_id = GC_POISONINGWEAPON;
  13407. sd->menuskill_val = skill_lv;
  13408. WFIFOW(fd,2) = c * 2 + 4;
  13409. WFIFOSET(fd, WFIFOW(fd, 2));
  13410. } else {
  13411. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13412. return 0;
  13413. }
  13414. return 1;
  13415. }
  13416. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13417. int fd, i, c;
  13418. nullpo_ret(sd);
  13419. fd = sd->fd;
  13420. if( !fd ) return 0;
  13421. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13422. return 0;
  13423. WFIFOHEAD(fd, 2 * 6 + 4);
  13424. WFIFOW(fd,0) = 0x442;
  13425. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13426. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13427. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13428. { // Can't auto cast both Extended class and 3rd class skills.
  13429. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13430. c++;
  13431. }
  13432. if( c > 0 ) {
  13433. WFIFOW(fd,2) = 8 + c * 2;
  13434. WFIFOL(fd,4) = c;
  13435. WFIFOSET(fd,WFIFOW(fd,2));
  13436. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13437. sd->menuskill_val = c;
  13438. } else {
  13439. status_change_end(&sd->bl,SC_STOP,-1);
  13440. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13441. }
  13442. return 1;
  13443. }
  13444. /*===========================================
  13445. * Skill list for Four Elemental Analysis
  13446. * and Change Material skills.
  13447. *------------------------------------------*/
  13448. int clif_skill_itemlistwindow( struct map_session_data *sd, int skill_id, int skill_lv )
  13449. {
  13450. #if PACKETVER >= 20090922
  13451. int fd;
  13452. nullpo_ret(sd);
  13453. sd->menuskill_id = skill_id; // To prevent hacking.
  13454. sd->menuskill_val = skill_lv;
  13455. if( skill_id == GN_CHANGEMATERIAL )
  13456. skill_lv = 0; // Changematerial
  13457. fd = sd->fd;
  13458. WFIFOHEAD(fd,packet_len(0x7e3));
  13459. WFIFOW(fd,0) = 0x7e3;
  13460. WFIFOL(fd,2) = skill_lv;
  13461. WFIFOL(fd,4) = 0;
  13462. WFIFOSET(fd,packet_len(0x7e3));
  13463. #endif
  13464. return 1;
  13465. }
  13466. /**
  13467. * Sends a new status without a tick (currently used by the new mounts)
  13468. **/
  13469. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13470. unsigned char buf[32];
  13471. nullpo_ret(bl);
  13472. WBUFW(buf,0)=0x043f;
  13473. WBUFW(buf,2)=type;
  13474. WBUFL(buf,4)=bl->id;
  13475. WBUFB(buf,8)=flag;
  13476. WBUFL(buf,9) = 0;
  13477. WBUFL(buf,13) = val1;
  13478. WBUFL(buf,17) = val2;
  13479. WBUFL(buf,21) = val3;
  13480. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  13481. return 0;
  13482. }
  13483. //Notifies FD of ID's type
  13484. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13485. WFIFOHEAD(fd, packet_len(0x043f));
  13486. WFIFOW(fd,0)=0x043f;
  13487. WFIFOW(fd,2)=type;
  13488. WFIFOL(fd,4)=id;
  13489. WFIFOB(fd,8)=flag;
  13490. WFIFOL(fd,9) = 0;
  13491. WFIFOL(fd,13) = val1;
  13492. WFIFOL(fd,17) = val2;
  13493. WFIFOL(fd,21) = val3;
  13494. WFIFOSET(fd, packet_len(0x043f));
  13495. return 0;
  13496. }
  13497. // msgstringtable.txt
  13498. // 0x291 <line>.W
  13499. void clif_msgtable(int fd, int line) {
  13500. WFIFOHEAD(fd, packet_len(0x291));
  13501. WFIFOW(fd, 0) = 0x291;
  13502. WFIFOW(fd, 2) = line;
  13503. WFIFOSET(fd, packet_len(0x291));
  13504. }
  13505. // msgstringtable.txt
  13506. // 0x7e2 <line>.W <value>.L
  13507. void clif_msgtable_num(int fd, int line, int num) {
  13508. #if PACKETVER >= 20090805
  13509. WFIFOHEAD(fd, packet_len(0x7e2));
  13510. WFIFOW(fd, 0) = 0x7e2;
  13511. WFIFOW(fd, 2) = line;
  13512. WFIFOL(fd, 4) = num;
  13513. WFIFOSET(fd, packet_len(0x7e2));
  13514. #endif
  13515. }
  13516. /*==========================================
  13517. * used by SC_AUTOSHADOWSPELL
  13518. *------------------------------------------*/
  13519. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13520. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13521. return;
  13522. if( pc_istrading(sd) ) {
  13523. clif_skill_fail(sd,sd->ud.skillid,0,0);
  13524. clif_menuskill_clear(sd);
  13525. return;
  13526. }
  13527. skill_select_menu(sd,RFIFOL(fd,2),RFIFOW(fd,6));
  13528. clif_menuskill_clear(sd);
  13529. }
  13530. /*==========================================
  13531. * Main client packet processing function
  13532. *------------------------------------------*/
  13533. static int clif_parse(int fd)
  13534. {
  13535. int cmd, packet_ver, packet_len, err;
  13536. TBL_PC* sd;
  13537. int pnum;
  13538. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13539. // Note: "click masters" can do 80+ clicks in 10 seconds
  13540. 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]
  13541. { // begin main client packet processing loop
  13542. sd = (TBL_PC *)session[fd]->session_data;
  13543. if (session[fd]->flag.eof) {
  13544. if (sd) {
  13545. if (sd->state.autotrade) {
  13546. //Disassociate character from the socket connection.
  13547. session[fd]->session_data = NULL;
  13548. sd->fd = 0;
  13549. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13550. } else
  13551. if (sd->state.active) {
  13552. // Player logout display [Valaris]
  13553. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13554. clif_quitsave(fd, sd);
  13555. } else {
  13556. //Unusual logout (during log on/off/map-changer procedure)
  13557. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13558. map_quit(sd);
  13559. }
  13560. } else {
  13561. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13562. }
  13563. do_close(fd);
  13564. return 0;
  13565. }
  13566. if (RFIFOREST(fd) < 2)
  13567. return 0;
  13568. cmd = RFIFOW(fd,0);
  13569. // identify client's packet version
  13570. if (sd) {
  13571. packet_ver = sd->packet_ver;
  13572. } else {
  13573. // check authentification packet to know packet version
  13574. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13575. if( err )
  13576. {// failed to identify packet version
  13577. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  13578. err == 1 ? "" :
  13579. err == 2 ? ", possibly for having an invalid account_id" :
  13580. err == 3 ? ", possibly for having an invalid char_id." :
  13581. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13582. err == 4 ? ", possibly for having an invalid login_id1." :
  13583. err == 5 ? ", possibly for having an invalid client_tick." :
  13584. */
  13585. err == 6 ? ", possibly for having an invalid sex." :
  13586. ". ERROR invalid error code"));
  13587. WFIFOHEAD(fd,packet_len(0x6a));
  13588. WFIFOW(fd,0) = 0x6a;
  13589. WFIFOB(fd,2) = 3; // Rejected from Server
  13590. WFIFOSET(fd,packet_len(0x6a));
  13591. #ifdef DUMP_INVALID_PACKET
  13592. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13593. #endif
  13594. RFIFOSKIP(fd, RFIFOREST(fd));
  13595. set_eof(fd);
  13596. return 0;
  13597. }
  13598. }
  13599. // filter out invalid / unsupported packets
  13600. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13601. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13602. #ifdef DUMP_INVALID_PACKET
  13603. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13604. #endif
  13605. set_eof(fd);
  13606. return 0;
  13607. }
  13608. // determine real packet length
  13609. packet_len = packet_db[packet_ver][cmd].len;
  13610. if (packet_len == -1) { // variable-length packet
  13611. if (RFIFOREST(fd) < 4)
  13612. return 0;
  13613. packet_len = RFIFOW(fd,2);
  13614. if (packet_len < 4 || packet_len > 32768) {
  13615. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13616. #ifdef DUMP_INVALID_PACKET
  13617. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13618. #endif
  13619. set_eof(fd);
  13620. return 0;
  13621. }
  13622. }
  13623. if ((int)RFIFOREST(fd) < packet_len)
  13624. return 0; // not enough data received to form the packet
  13625. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13626. packet_db[packet_ver][cmd].func(fd, sd);
  13627. else
  13628. if( packet_db[packet_ver][cmd].func != NULL )
  13629. {
  13630. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13631. ; //Only valid packet when there is no session
  13632. else
  13633. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13634. ; //Only valid packet when player is not on a map
  13635. else
  13636. if( sd && session[sd->fd]->flag.eof )
  13637. ; //No more packets accepted
  13638. else
  13639. packet_db[packet_ver][cmd].func(fd, sd);
  13640. }
  13641. #ifdef DUMP_UNKNOWN_PACKET
  13642. else
  13643. {
  13644. const char* packet_txt = "save/packet.txt";
  13645. FILE* fp;
  13646. if((fp = fopen(packet_txt, "a"))!=NULL)
  13647. {
  13648. if( sd )
  13649. {
  13650. 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);
  13651. }
  13652. else
  13653. {
  13654. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13655. }
  13656. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13657. fprintf(fp, "\n");
  13658. fclose(fp);
  13659. }
  13660. else
  13661. {
  13662. ShowError("Failed to write '%s'.\n", packet_txt);
  13663. // Dump on console instead
  13664. if( sd )
  13665. {
  13666. 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);
  13667. }
  13668. else
  13669. {
  13670. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13671. }
  13672. ShowDump(RFIFOP(fd,0), packet_len);
  13673. }
  13674. }
  13675. #endif
  13676. RFIFOSKIP(fd, packet_len);
  13677. }; // main loop end
  13678. return 0;
  13679. }
  13680. /*==========================================
  13681. * Reads packet_db.txt and setups its array reference
  13682. *------------------------------------------*/
  13683. static int packetdb_readdb(void)
  13684. {
  13685. FILE *fp;
  13686. char line[1024];
  13687. int ln=0;
  13688. int cmd,i,j,packet_ver;
  13689. int max_cmd=-1;
  13690. int skip_ver = 0;
  13691. int warned = 0;
  13692. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13693. int packet_len_table[MAX_PACKET_DB] = {
  13694. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13698. //#0x0040
  13699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13701. #if PACKETVER <= 20081217
  13702. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13703. #else
  13704. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13705. #endif
  13706. #if PACKETVER < 2
  13707. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13708. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  13709. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13710. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13711. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13712. #else
  13713. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13714. #endif
  13715. //#0x0080
  13716. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13717. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13718. #if PACKETVER <= 20100622
  13719. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13720. #else
  13721. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13722. #endif
  13723. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13724. //#0x00C0
  13725. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13726. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13727. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13728. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13729. //#0x0100
  13730. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13731. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13732. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13733. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13734. //#0x0140
  13735. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13736. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13737. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13738. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13739. //#0x0180
  13740. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13741. #if PACKETVER < 1
  13742. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13743. #else // 196 comodo以降 状態表示アイコン用
  13744. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13745. #endif
  13746. #if PACKETVER < 20081126
  13747. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13748. #else // 0x1a2 changed (35->37)
  13749. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13750. #endif
  13751. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13752. //#0x01C0, Set 0x1d5=-1
  13753. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13754. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13755. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13756. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13757. //#0x0200
  13758. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13759. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13760. #if PACKETVER < 20071106
  13761. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13762. #else // 0x22c changed
  13763. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13764. #endif
  13765. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13766. //#0x0240
  13767. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13768. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13769. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13770. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13771. //#0x0280
  13772. #if PACKETVER < 20070711
  13773. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  13774. #else
  13775. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13776. #endif
  13777. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  13778. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13779. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  13780. //#0x02C0
  13781. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13782. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  13783. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  13784. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13785. //#0x0300
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13790. //#0x0340
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13795. //#0x0380
  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, 0, 0, 0,
  13799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13800. //#0x03C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13805. //#0x0400
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  13810. //#0x0440
  13811. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13815. //#0x0480
  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, 0,
  13819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13820. //#0x04C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13825. //#0x0500
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13830. //#0x0540
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13835. //#0x0580
  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, 0,
  13839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13840. //#0x05C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13845. //#0x0600
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13850. //#0x0640
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13855. //#0x0680
  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, 0,
  13859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13860. //#0x06C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13865. //#0x0700
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13870. //#0x0740
  13871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13875. //#0x0780
  13876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13880. //#0x07C0
  13881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13882. #if PACKETVER < 20090617
  13883. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  13884. #else // 0x7d9 changed
  13885. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  13886. #endif
  13887. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  13888. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  13889. //#0x0800
  13890. #if PACKETVER < 20091229
  13891. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  13892. #else // for Party booking ( PACKETVER >= 20091229 )
  13893. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  13894. #endif
  13895. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  13896. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13897. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  13898. //#0x0840
  13899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13900. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  13901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13903. };
  13904. struct {
  13905. void (*func)(int, struct map_session_data *);
  13906. char *name;
  13907. } clif_parse_func[]={
  13908. {clif_parse_WantToConnection,"wanttoconnection"},
  13909. {clif_parse_LoadEndAck,"loadendack"},
  13910. {clif_parse_TickSend,"ticksend"},
  13911. {clif_parse_WalkToXY,"walktoxy"},
  13912. {clif_parse_QuitGame,"quitgame"},
  13913. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  13914. {clif_parse_GlobalMessage,"globalmessage"},
  13915. {clif_parse_MapMove,"mapmove"},
  13916. {clif_parse_ChangeDir,"changedir"},
  13917. {clif_parse_Emotion,"emotion"},
  13918. {clif_parse_HowManyConnections,"howmanyconnections"},
  13919. {clif_parse_ActionRequest,"actionrequest"},
  13920. {clif_parse_Restart,"restart"},
  13921. {clif_parse_WisMessage,"wis"},
  13922. {clif_parse_Broadcast,"broadcast"},
  13923. {clif_parse_TakeItem,"takeitem"},
  13924. {clif_parse_DropItem,"dropitem"},
  13925. {clif_parse_UseItem,"useitem"},
  13926. {clif_parse_EquipItem,"equipitem"},
  13927. {clif_parse_UnequipItem,"unequipitem"},
  13928. {clif_parse_NpcClicked,"npcclicked"},
  13929. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  13930. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  13931. {clif_parse_NpcSellListSend,"npcselllistsend"},
  13932. {clif_parse_CreateChatRoom,"createchatroom"},
  13933. {clif_parse_ChatAddMember,"chataddmember"},
  13934. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  13935. {clif_parse_ChangeChatOwner,"changechatowner"},
  13936. {clif_parse_KickFromChat,"kickfromchat"},
  13937. {clif_parse_ChatLeave,"chatleave"},
  13938. {clif_parse_TradeRequest,"traderequest"},
  13939. {clif_parse_TradeAck,"tradeack"},
  13940. {clif_parse_TradeAddItem,"tradeadditem"},
  13941. {clif_parse_TradeOk,"tradeok"},
  13942. {clif_parse_TradeCancel,"tradecancel"},
  13943. {clif_parse_TradeCommit,"tradecommit"},
  13944. {clif_parse_StopAttack,"stopattack"},
  13945. {clif_parse_PutItemToCart,"putitemtocart"},
  13946. {clif_parse_GetItemFromCart,"getitemfromcart"},
  13947. {clif_parse_RemoveOption,"removeoption"},
  13948. {clif_parse_ChangeCart,"changecart"},
  13949. {clif_parse_StatusUp,"statusup"},
  13950. {clif_parse_SkillUp,"skillup"},
  13951. {clif_parse_UseSkillToId,"useskilltoid"},
  13952. {clif_parse_UseSkillToPos,"useskilltopos"},
  13953. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  13954. {clif_parse_UseSkillMap,"useskillmap"},
  13955. {clif_parse_RequestMemo,"requestmemo"},
  13956. {clif_parse_ProduceMix,"producemix"},
  13957. {clif_parse_Cooking,"cooking"},
  13958. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  13959. {clif_parse_NpcNextClicked,"npcnextclicked"},
  13960. {clif_parse_NpcAmountInput,"npcamountinput"},
  13961. {clif_parse_NpcStringInput,"npcstringinput"},
  13962. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  13963. {clif_parse_ItemIdentify,"itemidentify"},
  13964. {clif_parse_SelectArrow,"selectarrow"},
  13965. {clif_parse_AutoSpell,"autospell"},
  13966. {clif_parse_UseCard,"usecard"},
  13967. {clif_parse_InsertCard,"insertcard"},
  13968. {clif_parse_RepairItem,"repairitem"},
  13969. {clif_parse_WeaponRefine,"weaponrefine"},
  13970. {clif_parse_SolveCharName,"solvecharname"},
  13971. {clif_parse_ResetChar,"resetchar"},
  13972. {clif_parse_LocalBroadcast,"localbroadcast"},
  13973. {clif_parse_MoveToKafra,"movetokafra"},
  13974. {clif_parse_MoveFromKafra,"movefromkafra"},
  13975. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  13976. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  13977. {clif_parse_CloseKafra,"closekafra"},
  13978. {clif_parse_CreateParty,"createparty"},
  13979. {clif_parse_CreateParty2,"createparty2"},
  13980. {clif_parse_PartyInvite,"partyinvite"},
  13981. {clif_parse_PartyInvite2,"partyinvite2"},
  13982. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  13983. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  13984. {clif_parse_LeaveParty,"leaveparty"},
  13985. {clif_parse_RemovePartyMember,"removepartymember"},
  13986. {clif_parse_PartyChangeOption,"partychangeoption"},
  13987. {clif_parse_PartyMessage,"partymessage"},
  13988. {clif_parse_PartyChangeLeader,"partychangeleader"},
  13989. {clif_parse_CloseVending,"closevending"},
  13990. {clif_parse_VendingListReq,"vendinglistreq"},
  13991. {clif_parse_PurchaseReq,"purchasereq"},
  13992. {clif_parse_PurchaseReq2,"purchasereq2"},
  13993. {clif_parse_OpenVending,"openvending"},
  13994. {clif_parse_CreateGuild,"createguild"},
  13995. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  13996. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  13997. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  13998. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  13999. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  14000. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  14001. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  14002. {clif_parse_GuildInvite,"guildinvite"},
  14003. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  14004. {clif_parse_GuildLeave,"guildleave"},
  14005. {clif_parse_GuildExpulsion,"guildexpulsion"},
  14006. {clif_parse_GuildMessage,"guildmessage"},
  14007. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  14008. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  14009. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  14010. {clif_parse_GuildOpposition,"guildopposition"},
  14011. {clif_parse_GuildBreak,"guildbreak"},
  14012. {clif_parse_PetMenu,"petmenu"},
  14013. {clif_parse_CatchPet,"catchpet"},
  14014. {clif_parse_SelectEgg,"selectegg"},
  14015. {clif_parse_SendEmotion,"sendemotion"},
  14016. {clif_parse_ChangePetName,"changepetname"},
  14017. {clif_parse_GMKick,"gmkick"},
  14018. {clif_parse_GMHide,"gmhide"},
  14019. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14020. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14021. {clif_parse_GMKickAll,"killall"},
  14022. {clif_parse_GMRecall,"recall"},
  14023. {clif_parse_GMRecall,"summon"},
  14024. {clif_parse_GM_Monster_Item,"itemmonster"},
  14025. {clif_parse_GMShift,"remove"},
  14026. {clif_parse_GMShift,"shift"},
  14027. {clif_parse_GMChangeMapType,"changemaptype"},
  14028. {clif_parse_GMRc,"rc"},
  14029. {clif_parse_GMRecall2,"recall2"},
  14030. {clif_parse_GMRemove2,"remove2"},
  14031. {clif_parse_NoviceDoriDori,"sndoridori"},
  14032. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14033. {clif_parse_PMIgnore,"wisexin"},
  14034. {clif_parse_PMIgnoreList,"wisexlist"},
  14035. {clif_parse_PMIgnoreAll,"wisall"},
  14036. {clif_parse_FriendsListAdd,"friendslistadd"},
  14037. {clif_parse_FriendsListRemove,"friendslistremove"},
  14038. {clif_parse_FriendsListReply,"friendslistreply"},
  14039. {clif_parse_Blacksmith,"blacksmith"},
  14040. {clif_parse_Alchemist,"alchemist"},
  14041. {clif_parse_Taekwon,"taekwon"},
  14042. {clif_parse_RankingPk,"rankingpk"},
  14043. {clif_parse_FeelSaveOk,"feelsaveok"},
  14044. {clif_parse_debug,"debug"},
  14045. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14046. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14047. {clif_parse_HomMoveTo,"hommoveto"},
  14048. {clif_parse_HomAttack,"homattack"},
  14049. {clif_parse_HomMenu,"hommenu"},
  14050. {clif_parse_StoragePassword,"storagepassword"},
  14051. {clif_parse_Hotkey,"hotkey"},
  14052. {clif_parse_AutoRevive,"autorevive"},
  14053. {clif_parse_Check,"check"},
  14054. {clif_parse_Adopt_request,"adoptrequest"},
  14055. {clif_parse_Adopt_reply,"adoptreply"},
  14056. // MAIL SYSTEM
  14057. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14058. {clif_parse_Mail_read,"mailread"},
  14059. {clif_parse_Mail_getattach,"mailgetattach"},
  14060. {clif_parse_Mail_delete,"maildelete"},
  14061. {clif_parse_Mail_return,"mailreturn"},
  14062. {clif_parse_Mail_setattach,"mailsetattach"},
  14063. {clif_parse_Mail_winopen,"mailwinopen"},
  14064. {clif_parse_Mail_send,"mailsend"},
  14065. // AUCTION SYSTEM
  14066. {clif_parse_Auction_search,"auctionsearch"},
  14067. {clif_parse_Auction_buysell,"auctionbuysell"},
  14068. {clif_parse_Auction_setitem,"auctionsetitem"},
  14069. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14070. {clif_parse_Auction_register,"auctionregister"},
  14071. {clif_parse_Auction_cancel,"auctioncancel"},
  14072. {clif_parse_Auction_close,"auctionclose"},
  14073. {clif_parse_Auction_bid,"auctionbid"},
  14074. // Quest Log System
  14075. {clif_parse_questStateAck,"queststate"},
  14076. {clif_parse_cashshop_buy,"cashshopbuy"},
  14077. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14078. {clif_parse_EquipTick,"equiptickbox"},
  14079. {clif_parse_BattleChat,"battlechat"},
  14080. {clif_parse_mercenary_action,"mermenu"},
  14081. {clif_parse_progressbar,"progressbar"},
  14082. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14083. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14084. #if PACKETVER >= 20091229
  14085. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14086. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14087. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14088. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14089. #endif
  14090. {clif_parse_PVPInfo,"pvpinfo"},
  14091. {clif_parse_LessEffect,"lesseffect"},
  14092. // Buying Store
  14093. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14094. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14095. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14096. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14097. // Store Search
  14098. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14099. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14100. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14101. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14102. {NULL,NULL}
  14103. };
  14104. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14105. memset(packet_db,0,sizeof(packet_db));
  14106. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14107. packet_len(i) = packet_len_table[i];
  14108. sprintf(line, "%s/packet_db.txt", db_path);
  14109. if( (fp=fopen(line,"r"))==NULL ){
  14110. ShowFatalError("can't read %s\n", line);
  14111. exit(EXIT_FAILURE);
  14112. }
  14113. clif_config.packet_db_ver = MAX_PACKET_VER;
  14114. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14115. while( fgets(line, sizeof(line), fp) )
  14116. {
  14117. ln++;
  14118. if(line[0]=='/' && line[1]=='/')
  14119. continue;
  14120. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14121. {
  14122. if(strcmpi(w1,"packet_ver")==0) {
  14123. int prev_ver = packet_ver;
  14124. skip_ver = 0;
  14125. packet_ver = atoi(w2);
  14126. if ( packet_ver > MAX_PACKET_VER )
  14127. { //Check to avoid overflowing. [Skotlex]
  14128. if( (warned&1) == 0 )
  14129. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14130. warned &= 1;
  14131. skip_ver = 1;
  14132. }
  14133. else if( packet_ver < 0 )
  14134. {
  14135. if( (warned&2) == 0 )
  14136. ShowWarning("Negative packet versions are not supported.\n");
  14137. warned &= 2;
  14138. skip_ver = 1;
  14139. }
  14140. else if( packet_ver == SERVER )
  14141. {
  14142. if( (warned&4) == 0 )
  14143. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14144. warned &= 4;
  14145. skip_ver = 1;
  14146. }
  14147. if( skip_ver )
  14148. {
  14149. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14150. packet_ver = prev_ver;
  14151. continue;
  14152. }
  14153. // copy from previous version into new version and continue
  14154. // - indicating all following packets should be read into the newer version
  14155. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14156. continue;
  14157. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14158. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14159. clif_config.packet_db_ver = MAX_PACKET_VER;
  14160. else // to manually set the packet DB version
  14161. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14162. continue;
  14163. }
  14164. }
  14165. if( skip_ver != 0 )
  14166. continue; // Skipping current packet version
  14167. memset(str,0,sizeof(str));
  14168. for(j=0,p=line;j<4 && p; ++j)
  14169. {
  14170. str[j]=p;
  14171. p=strchr(p,',');
  14172. if(p) *p++=0;
  14173. }
  14174. if(str[0]==NULL)
  14175. continue;
  14176. cmd=strtol(str[0],(char **)NULL,0);
  14177. if(max_cmd < cmd)
  14178. max_cmd = cmd;
  14179. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14180. continue;
  14181. if(str[1]==NULL){
  14182. ShowError("packet_db: packet len error\n");
  14183. continue;
  14184. }
  14185. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14186. if(str[2]==NULL){
  14187. packet_db[packet_ver][cmd].func = NULL;
  14188. ln++;
  14189. continue;
  14190. }
  14191. // look up processing function by name
  14192. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14193. if( j < ARRAYLENGTH(clif_parse_func) )
  14194. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14195. // set the identifying cmd for the packet_db version
  14196. if (strcmp(str[2],"wanttoconnection")==0)
  14197. clif_config.connect_cmd[packet_ver] = cmd;
  14198. if(str[3]==NULL){
  14199. ShowError("packet_db: packet error\n");
  14200. exit(EXIT_FAILURE);
  14201. }
  14202. for(j=0,p2=str[3];p2;j++){
  14203. short k;
  14204. str2[j]=p2;
  14205. p2=strchr(p2,':');
  14206. if(p2) *p2++=0;
  14207. k = atoi(str2[j]);
  14208. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14209. if( j >= MAX_PACKET_POS )
  14210. {
  14211. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14212. break;
  14213. }
  14214. packet_db[packet_ver][cmd].pos[j] = k;
  14215. }
  14216. }
  14217. fclose(fp);
  14218. if(max_cmd > MAX_PACKET_DB)
  14219. {
  14220. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14221. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14222. }
  14223. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14224. { //Locate the nearest version that we still support. [Skotlex]
  14225. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14226. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14227. }
  14228. 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);
  14229. return 0;
  14230. }
  14231. /*==========================================
  14232. *
  14233. *------------------------------------------*/
  14234. int do_init_clif(void) {
  14235. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14236. int i;
  14237. /**
  14238. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14239. **/
  14240. for(i = 0; i < COLOR_MAX; i++) {
  14241. color_table[i] = strtoul(colors[i],NULL,0);
  14242. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14243. }
  14244. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14245. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14246. memset(packet_db,0,sizeof(packet_db));
  14247. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14248. packetdb_readdb();
  14249. set_defaultparse(clif_parse);
  14250. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14251. ShowFatalError("can't bind game port\n");
  14252. exit(EXIT_FAILURE);
  14253. }
  14254. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14255. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14256. return 0;
  14257. }