clif.c 464 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892
  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. if(src_bl->type == BL_PC){
  270. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  271. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  272. return 0;
  273. }
  274. else if(src_bl->type == BL_NPC) {
  275. struct npc_data *nd = (struct npc_data *)src_bl;
  276. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  277. return 0;
  278. }
  279. }
  280. break;
  281. }
  282. if (session[fd] == NULL)
  283. return 0;
  284. WFIFOHEAD(fd, len);
  285. if (WFIFOP(fd,0) == buf) {
  286. ShowError("WARNING: Invalid use of clif_send function\n");
  287. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  288. ShowError(" Please correct your code.\n");
  289. // don't send to not move the pointer of the packet for next sessions in the loop
  290. //WFIFOSET(fd,0);//## TODO is this ok?
  291. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  292. return 0;
  293. }
  294. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  295. memcpy(WFIFOP(fd,0), buf, len);
  296. WFIFOSET(fd,len);
  297. }
  298. return 0;
  299. }
  300. /*==========================================
  301. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  302. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  303. *------------------------------------------*/
  304. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  305. {
  306. int i;
  307. struct map_session_data *sd, *tsd;
  308. struct party_data *p = NULL;
  309. struct guild *g = NULL;
  310. struct battleground_data *bg = NULL;
  311. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  312. struct s_mapiterator* iter;
  313. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  314. nullpo_ret(bl);
  315. sd = BL_CAST(BL_PC, bl);
  316. switch(type) {
  317. case ALL_CLIENT: //All player clients.
  318. iter = mapit_getallusers();
  319. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  320. {
  321. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  322. { // packet must exist for the client version
  323. WFIFOHEAD(tsd->fd, len);
  324. memcpy(WFIFOP(tsd->fd,0), buf, len);
  325. WFIFOSET(tsd->fd,len);
  326. }
  327. }
  328. mapit_free(iter);
  329. break;
  330. case ALL_SAMEMAP: //All players on the same map
  331. iter = mapit_getallusers();
  332. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  333. {
  334. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  335. { // packet must exist for the client version
  336. WFIFOHEAD(tsd->fd, len);
  337. memcpy(WFIFOP(tsd->fd,0), buf, len);
  338. WFIFOSET(tsd->fd,len);
  339. }
  340. }
  341. mapit_free(iter);
  342. break;
  343. case AREA:
  344. case AREA_WOSC:
  345. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  346. clif_send (buf, len, bl, SELF);
  347. case AREA_WOC:
  348. case AREA_WOS:
  349. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  350. BL_PC, buf, len, bl, type);
  351. break;
  352. case AREA_CHAT_WOC:
  353. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  354. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  355. break;
  356. case CHAT:
  357. case CHAT_WOS:
  358. {
  359. struct chat_data *cd;
  360. if (sd) {
  361. cd = (struct chat_data*)map_id2bl(sd->chatID);
  362. } else if (bl->type == BL_CHAT) {
  363. cd = (struct chat_data*)bl;
  364. } else break;
  365. if (cd == NULL)
  366. break;
  367. for(i = 0; i < cd->users; i++) {
  368. if (type == CHAT_WOS && cd->usersd[i] == sd)
  369. continue;
  370. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  371. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  372. {
  373. WFIFOHEAD(fd,len);
  374. memcpy(WFIFOP(fd,0), buf, len);
  375. WFIFOSET(fd,len);
  376. }
  377. }
  378. }
  379. }
  380. break;
  381. case CHAT_MAINCHAT: //[LuzZza]
  382. iter = mapit_getallusers();
  383. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  384. {
  385. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  386. { // packet must exist for the client version
  387. WFIFOHEAD(tsd->fd, len);
  388. memcpy(WFIFOP(tsd->fd,0), buf, len);
  389. WFIFOSET(tsd->fd,len);
  390. }
  391. }
  392. mapit_free(iter);
  393. break;
  394. case PARTY_AREA:
  395. case PARTY_AREA_WOS:
  396. x0 = bl->x - AREA_SIZE;
  397. y0 = bl->y - AREA_SIZE;
  398. x1 = bl->x + AREA_SIZE;
  399. y1 = bl->y + AREA_SIZE;
  400. case PARTY:
  401. case PARTY_WOS:
  402. case PARTY_SAMEMAP:
  403. case PARTY_SAMEMAP_WOS:
  404. if (sd && sd->status.party_id)
  405. p = party_search(sd->status.party_id);
  406. if (p) {
  407. for(i=0;i<MAX_PARTY;i++){
  408. if( (sd = p->data[i].sd) == NULL )
  409. continue;
  410. if( !(fd=sd->fd) )
  411. continue;
  412. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  413. continue;
  414. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  415. continue;
  416. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  417. continue;
  418. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  419. { // packet must exist for the client version
  420. WFIFOHEAD(fd,len);
  421. memcpy(WFIFOP(fd,0), buf, len);
  422. WFIFOSET(fd,len);
  423. }
  424. }
  425. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  426. break;
  427. iter = mapit_getallusers();
  428. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  429. {
  430. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  431. { // packet must exist for the client version
  432. WFIFOHEAD(tsd->fd, len);
  433. memcpy(WFIFOP(tsd->fd,0), buf, len);
  434. WFIFOSET(tsd->fd,len);
  435. }
  436. }
  437. mapit_free(iter);
  438. }
  439. break;
  440. case DUEL:
  441. case DUEL_WOS:
  442. if (!sd || !sd->duel_group) break; //Invalid usage.
  443. iter = mapit_getallusers();
  444. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  445. {
  446. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  447. continue;
  448. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  449. { // packet must exist for the client version
  450. WFIFOHEAD(tsd->fd, len);
  451. memcpy(WFIFOP(tsd->fd,0), buf, len);
  452. WFIFOSET(tsd->fd,len);
  453. }
  454. }
  455. mapit_free(iter);
  456. break;
  457. case SELF:
  458. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  459. WFIFOHEAD(fd,len);
  460. memcpy(WFIFOP(fd,0), buf, len);
  461. WFIFOSET(fd,len);
  462. }
  463. break;
  464. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  465. case GUILD_AREA:
  466. case GUILD_AREA_WOS:
  467. x0 = bl->x - AREA_SIZE;
  468. y0 = bl->y - AREA_SIZE;
  469. x1 = bl->x + AREA_SIZE;
  470. y1 = bl->y + AREA_SIZE;
  471. case GUILD_SAMEMAP:
  472. case GUILD_SAMEMAP_WOS:
  473. case GUILD:
  474. case GUILD_WOS:
  475. case GUILD_NOBG:
  476. if (sd && sd->status.guild_id)
  477. g = guild_search(sd->status.guild_id);
  478. if (g) {
  479. for(i = 0; i < g->max_member; i++) {
  480. if( (sd = g->member[i].sd) != NULL )
  481. {
  482. if( !(fd=sd->fd) )
  483. continue;
  484. if( type == GUILD_NOBG && sd->bg_id )
  485. continue;
  486. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  487. continue;
  488. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  489. continue;
  490. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  491. continue;
  492. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  493. { // packet must exist for the client version
  494. WFIFOHEAD(fd,len);
  495. memcpy(WFIFOP(fd,0), buf, len);
  496. WFIFOSET(fd,len);
  497. }
  498. }
  499. }
  500. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  501. break;
  502. iter = mapit_getallusers();
  503. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  504. {
  505. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  506. { // packet must exist for the client version
  507. WFIFOHEAD(tsd->fd, len);
  508. memcpy(WFIFOP(tsd->fd,0), buf, len);
  509. WFIFOSET(tsd->fd,len);
  510. }
  511. }
  512. mapit_free(iter);
  513. }
  514. break;
  515. case BG_AREA:
  516. case BG_AREA_WOS:
  517. x0 = bl->x - AREA_SIZE;
  518. y0 = bl->y - AREA_SIZE;
  519. x1 = bl->x + AREA_SIZE;
  520. y1 = bl->y + AREA_SIZE;
  521. case BG_SAMEMAP:
  522. case BG_SAMEMAP_WOS:
  523. case BG:
  524. case BG_WOS:
  525. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  526. {
  527. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  528. {
  529. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  530. continue;
  531. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  532. continue;
  533. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  534. continue;
  535. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  536. continue;
  537. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  538. { // packet must exist for the client version
  539. WFIFOHEAD(fd,len);
  540. memcpy(WFIFOP(fd,0), buf, len);
  541. WFIFOSET(fd,len);
  542. }
  543. }
  544. }
  545. break;
  546. default:
  547. ShowError("clif_send: Unrecognized type %d\n",type);
  548. return -1;
  549. }
  550. return 0;
  551. }
  552. /// Notifies the client, that it's connection attempt was accepted.
  553. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  554. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  555. void clif_authok(struct map_session_data *sd)
  556. {
  557. #if PACKETVER < 20080102
  558. const int cmd = 0x73;
  559. #else
  560. const int cmd = 0x2eb;
  561. #endif
  562. int fd = sd->fd;
  563. WFIFOHEAD(fd,packet_len(cmd));
  564. WFIFOW(fd, 0) = cmd;
  565. WFIFOL(fd, 2) = gettick();
  566. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  567. WFIFOB(fd, 9) = 5; // ignored
  568. WFIFOB(fd,10) = 5; // ignored
  569. #if PACKETVER >= 20080102
  570. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  571. #endif
  572. WFIFOSET(fd,packet_len(cmd));
  573. }
  574. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  575. /// 0074 <error code>.B
  576. /// error code:
  577. /// 0 = client type mismatch
  578. /// 1 = ID mismatch
  579. /// 2 = mobile - out of available time
  580. /// 3 = mobile - already logged in
  581. /// 4 = mobile - waiting state
  582. void clif_authrefuse(int fd, uint8 error_code)
  583. {
  584. WFIFOHEAD(fd,packet_len(0x74));
  585. WFIFOW(fd,0) = 0x74;
  586. WFIFOB(fd,2) = error_code;
  587. WFIFOSET(fd,packet_len(0x74));
  588. }
  589. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  590. /// 0081 <error code>.B
  591. /// error code:
  592. /// 0 = BAN_UNFAIR
  593. /// 1 = server closed -> MsgStringTable[4]
  594. /// 2 = ID already logged in -> MsgStringTable[5]
  595. /// 3 = timeout/too much lag -> MsgStringTable[241]
  596. /// 4 = server full -> MsgStringTable[264]
  597. /// 5 = underaged -> MsgStringTable[305]
  598. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  599. /// 9 = too many connections from this ip -> MsgStringTable[529]
  600. /// 10 = out of available time paid for -> MsgStringTable[530]
  601. /// 11 = BAN_PAY_SUSPEND
  602. /// 12 = BAN_PAY_CHANGE
  603. /// 13 = BAN_PAY_WRONGIP
  604. /// 14 = BAN_PAY_PNGAMEROOM
  605. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  606. /// 16 = BAN_JAPAN_REFUSE1
  607. /// 17 = BAN_JAPAN_REFUSE2
  608. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  609. /// 100 = BAN_PC_IP_UNFAIR
  610. /// 101 = BAN_PC_IP_COUNT_ALL
  611. /// 102 = BAN_PC_IP_COUNT
  612. /// 103 = BAN_GRAVITY_MEM_AGREE
  613. /// 104 = BAN_GAME_MEM_AGREE
  614. /// 105 = BAN_HAN_VALID
  615. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  616. /// 107 = BAN_OVER_CHARACTER_LIST
  617. /// 108 = BAN_IP_BLOCK
  618. /// 109 = BAN_INVALID_PWD_CNT
  619. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  620. /// ? = disconnected -> MsgStringTable[3]
  621. void clif_authfail_fd(int fd, int type)
  622. {
  623. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  624. return;
  625. WFIFOHEAD(fd, packet_len(0x81));
  626. WFIFOW(fd,0) = 0x81;
  627. WFIFOB(fd,2) = type;
  628. WFIFOSET(fd,packet_len(0x81));
  629. set_eof(fd);
  630. }
  631. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  632. /// 00b3 <type>.B
  633. /// type:
  634. /// 1 = disconnect, char-select
  635. /// ? = nothing
  636. void clif_charselectok(int id, uint8 ok)
  637. {
  638. struct map_session_data* sd;
  639. int fd;
  640. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  641. return;
  642. fd = sd->fd;
  643. WFIFOHEAD(fd,packet_len(0xb3));
  644. WFIFOW(fd,0) = 0xb3;
  645. WFIFOB(fd,2) = ok;
  646. WFIFOSET(fd,packet_len(0xb3));
  647. }
  648. /// Makes an item appear on the ground.
  649. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  650. /// 084b (ZC_ITEM_FALL_ENTRY4)
  651. void clif_dropflooritem(struct flooritem_data* fitem)
  652. {
  653. uint8 buf[17];
  654. int view;
  655. nullpo_retv(fitem);
  656. if (fitem->item_data.nameid <= 0)
  657. return;
  658. WBUFW(buf, 0) = 0x9e;
  659. WBUFL(buf, 2) = fitem->bl.id;
  660. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  661. WBUFB(buf, 8) = fitem->item_data.identify;
  662. WBUFW(buf, 9) = fitem->bl.x;
  663. WBUFW(buf,11) = fitem->bl.y;
  664. WBUFB(buf,13) = fitem->subx;
  665. WBUFB(buf,14) = fitem->suby;
  666. WBUFW(buf,15) = fitem->item_data.amount;
  667. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  668. }
  669. /// Makes an item disappear from the ground.
  670. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  671. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  672. {
  673. unsigned char buf[16];
  674. nullpo_retv(fitem);
  675. WBUFW(buf,0) = 0xa1;
  676. WBUFL(buf,2) = fitem->bl.id;
  677. if (fd == 0) {
  678. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  679. } else {
  680. WFIFOHEAD(fd,packet_len(0xa1));
  681. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  682. WFIFOSET(fd,packet_len(0xa1));
  683. }
  684. }
  685. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  686. /// 0080 <id>.L <type>.B
  687. /// type:
  688. /// 0 = out of sight
  689. /// 1 = died
  690. /// 2 = logged out
  691. /// 3 = teleport
  692. /// 4 = trickdead
  693. void clif_clearunit_single(int id, clr_type type, int fd)
  694. {
  695. WFIFOHEAD(fd, packet_len(0x80));
  696. WFIFOW(fd,0) = 0x80;
  697. WFIFOL(fd,2) = id;
  698. WFIFOB(fd,6) = type;
  699. WFIFOSET(fd, packet_len(0x80));
  700. }
  701. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  702. /// 0080 <id>.L <type>.B
  703. /// type:
  704. /// 0 = out of sight
  705. /// 1 = died
  706. /// 2 = logged out
  707. /// 3 = teleport
  708. /// 4 = trickdead
  709. void clif_clearunit_area(struct block_list* bl, clr_type type)
  710. {
  711. unsigned char buf[8];
  712. nullpo_retv(bl);
  713. WBUFW(buf,0) = 0x80;
  714. WBUFL(buf,2) = bl->id;
  715. WBUFB(buf,6) = type;
  716. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  717. if(disguised(bl)) {
  718. WBUFL(buf,2) = -bl->id;
  719. clif_send(buf, packet_len(0x80), bl, SELF);
  720. }
  721. }
  722. /// Used to make monsters with player-sprites disappear after dying
  723. /// like normal monsters, because the client does not remove those
  724. /// automatically.
  725. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  726. {
  727. struct block_list *bl = (struct block_list *)data;
  728. clif_clearunit_area(bl, (clr_type) id);
  729. aFree(bl);
  730. return 0;
  731. }
  732. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  733. {
  734. struct block_list *tbl;
  735. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  736. memcpy (tbl, bl, sizeof (struct block_list));
  737. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  738. }
  739. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  740. {
  741. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  742. {
  743. *rhand = *lhand = 0;
  744. return;
  745. }
  746. #if PACKETVER < 4
  747. *rhand = sd->status.weapon;
  748. *lhand = sd->status.shield;
  749. #else
  750. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  751. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  752. {
  753. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  754. if (id->view_id > 0)
  755. *rhand = id->view_id;
  756. else
  757. *rhand = id->nameid;
  758. } else
  759. *rhand = 0;
  760. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  761. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  762. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  763. {
  764. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  765. if (id->view_id > 0)
  766. *lhand = id->view_id;
  767. else
  768. *lhand = id->nameid;
  769. } else
  770. *lhand = 0;
  771. #endif
  772. }
  773. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  774. static int clif_setlevel_sub(int lv)
  775. {
  776. if( lv < battle_config.max_lv )
  777. {
  778. ;
  779. }
  780. else if( lv < battle_config.aura_lv )
  781. {
  782. lv = battle_config.max_lv - 1;
  783. }
  784. else
  785. {
  786. lv = battle_config.max_lv;
  787. }
  788. return lv;
  789. }
  790. static int clif_setlevel(struct block_list* bl)
  791. {
  792. int lv = status_get_lv(bl);
  793. if( battle_config.client_limit_unit_lv&bl->type )
  794. return clif_setlevel_sub(lv);
  795. switch( bl->type )
  796. {
  797. case BL_NPC:
  798. case BL_PET:
  799. // npcs and pets do not have level
  800. return 0;
  801. }
  802. return lv;
  803. }
  804. /*==========================================
  805. * Prepares 'unit standing/spawning' packet
  806. *------------------------------------------*/
  807. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  808. {
  809. struct map_session_data* sd;
  810. struct status_change* sc = status_get_sc(bl);
  811. struct view_data* vd = status_get_viewdata(bl);
  812. unsigned char *buf = WBUFP(buffer,0);
  813. #if PACKETVER < 20091103
  814. bool type = !pcdb_checkid(vd->class_);
  815. #endif
  816. #if PACKETVER >= 7
  817. unsigned short offset = 0;
  818. #endif
  819. #if PACKETVER >= 20091103
  820. const char *name;
  821. #endif
  822. sd = BL_CAST(BL_PC, bl);
  823. #if PACKETVER < 20091103
  824. if(type)
  825. WBUFW(buf,0) = spawn?0x7c:0x78;
  826. else
  827. #endif
  828. #if PACKETVER < 4
  829. WBUFW(buf,0) = spawn?0x79:0x78;
  830. #elif PACKETVER < 7
  831. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  832. #elif PACKETVER < 20080102
  833. WBUFW(buf,0) = spawn?0x22b:0x22a;
  834. #elif PACKETVER < 20091103
  835. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  836. #elif PACKETVER < 20101124
  837. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  838. #else
  839. WBUFW(buf,0) = spawn?0x858:0x857;
  840. #endif
  841. #if PACKETVER >= 20091103
  842. name = status_get_name(bl);
  843. #if PACKETVER < 20110111
  844. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  845. #else
  846. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  847. #endif
  848. WBUFB(buf,4) = clif_bl_type(bl);
  849. offset+=3;
  850. buf = WBUFP(buffer,offset);
  851. #elif PACKETVER >= 20071106
  852. if (type) { //Non-player packets
  853. WBUFB(buf,2) = clif_bl_type(bl);
  854. offset++;
  855. buf = WBUFP(buffer,offset);
  856. }
  857. #endif
  858. WBUFL(buf, 2) = bl->id;
  859. WBUFW(buf, 6) = status_get_speed(bl);
  860. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  861. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  862. #if PACKETVER < 20091103
  863. if (type&&spawn) { //uses an older and different packet structure
  864. WBUFW(buf,12) = (sc)? sc->option : 0;
  865. WBUFW(buf,14) = vd->hair_style;
  866. WBUFW(buf,16) = vd->weapon;
  867. WBUFW(buf,18) = vd->head_bottom;
  868. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  869. WBUFW(buf,22) = vd->shield;
  870. } else {
  871. #endif
  872. #if PACKETVER >= 20091103
  873. WBUFL(buf,12) = (sc)? sc->option : 0;
  874. offset+=2;
  875. buf = WBUFP(buffer,offset);
  876. #elif PACKETVER >= 7
  877. if (!type) {
  878. WBUFL(buf,12) = (sc)? sc->option : 0;
  879. offset+=2;
  880. buf = WBUFP(buffer,offset);
  881. } else
  882. WBUFW(buf,12) = (sc)? sc->option : 0;
  883. #else
  884. WBUFW(buf,12) = (sc)? sc->option : 0;
  885. #endif
  886. WBUFW(buf,14) = vd->class_;
  887. WBUFW(buf,16) = vd->hair_style;
  888. WBUFW(buf,18) = vd->weapon;
  889. #if PACKETVER < 4
  890. WBUFW(buf,20) = vd->head_bottom;
  891. WBUFW(buf,22) = vd->shield;
  892. #else
  893. WBUFW(buf,20) = vd->shield;
  894. WBUFW(buf,22) = vd->head_bottom;
  895. #endif
  896. #if PACKETVER < 20091103
  897. }
  898. #endif
  899. WBUFW(buf,24) = vd->head_top;
  900. WBUFW(buf,26) = vd->head_mid;
  901. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  902. { //The hell, why flags work like this?
  903. WBUFW(buf,22) = status_get_emblem_id(bl);
  904. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  905. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  906. }
  907. WBUFW(buf,28) = vd->hair_color;
  908. WBUFW(buf,30) = vd->cloth_color;
  909. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  910. #if PACKETVER < 20091103
  911. if (type&&spawn) { //End of packet 0x7c
  912. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  913. WBUFB(buf,35) = vd->sex;
  914. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  915. WBUFB(buf,39) = 0;
  916. WBUFB(buf,40) = 0;
  917. return packet_len(0x7c);
  918. }
  919. #endif
  920. #if PACKETVER >= 20110111
  921. WBUFW(buf,34) = vd->robe;
  922. offset+= 2;
  923. buf = WBUFP(buffer,offset);
  924. #endif
  925. WBUFL(buf,34) = status_get_guild_id(bl);
  926. WBUFW(buf,38) = status_get_emblem_id(bl);
  927. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  928. #if PACKETVER >= 20091103
  929. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  930. offset+=2;
  931. buf = WBUFP(buffer,offset);
  932. #elif PACKETVER >= 7
  933. if (!type) {
  934. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  935. offset+=2;
  936. buf = WBUFP(buffer,offset);
  937. } else
  938. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  939. #else
  940. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  941. #endif
  942. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  943. WBUFB(buf,45) = vd->sex;
  944. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  945. WBUFB(buf,49) = (sd)? 5 : 0;
  946. WBUFB(buf,50) = (sd)? 5 : 0;
  947. if (!spawn) {
  948. WBUFB(buf,51) = vd->dead_sit;
  949. offset++;
  950. buf = WBUFP(buffer,offset);
  951. }
  952. WBUFW(buf,51) = clif_setlevel(bl);
  953. #if PACKETVER < 20091103
  954. if (type) //End for non-player packet
  955. return packet_len(WBUFW(buffer,0));
  956. #endif
  957. #if PACKETVER >= 20080102
  958. WBUFW(buf,53) = sd?sd->user_font:0;
  959. #endif
  960. #if PACKETVER >= 20091103
  961. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  962. return WBUFW(buffer,2);
  963. #else
  964. return packet_len(WBUFW(buffer,0));
  965. #endif
  966. }
  967. /*==========================================
  968. * Prepares 'unit walking' packet
  969. *------------------------------------------*/
  970. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  971. {
  972. struct map_session_data* sd;
  973. struct status_change* sc = status_get_sc(bl);
  974. struct view_data* vd = status_get_viewdata(bl);
  975. unsigned char* buf = WBUFP(buffer,0);
  976. #if PACKETVER >= 7
  977. unsigned short offset = 0;
  978. #endif
  979. #if PACKETVER >= 20091103
  980. const char *name;
  981. #endif
  982. sd = BL_CAST(BL_PC, bl);
  983. #if PACKETVER < 4
  984. WBUFW(buf, 0) = 0x7b;
  985. #elif PACKETVER < 7
  986. WBUFW(buf, 0) = 0x1da;
  987. #elif PACKETVER < 20080102
  988. WBUFW(buf, 0) = 0x22c;
  989. #elif PACKETVER < 20091103
  990. WBUFW(buf, 0) = 0x2ec;
  991. #elif PACKETVER < 20101124
  992. WBUFW(buf, 0) = 0x7f7;
  993. #else
  994. WBUFW(buf, 0) = 0x856;
  995. #endif
  996. #if PACKETVER >= 20091103
  997. name = status_get_name(bl);
  998. #if PACKETVER < 20110111
  999. WBUFW(buf, 2) = 69+strlen(name);
  1000. #else
  1001. WBUFW(buf, 2) = 71+strlen(name);
  1002. #endif
  1003. offset+=2;
  1004. buf = WBUFP(buffer,offset);
  1005. #endif
  1006. #if PACKETVER >= 20071106
  1007. WBUFB(buf, 2) = clif_bl_type(bl);
  1008. offset++;
  1009. buf = WBUFP(buffer,offset);
  1010. #endif
  1011. WBUFL(buf, 2) = bl->id;
  1012. WBUFW(buf, 6) = status_get_speed(bl);
  1013. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1014. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1015. #if PACKETVER < 7
  1016. WBUFW(buf,12) = (sc)? sc->option : 0;
  1017. #else
  1018. WBUFL(buf,12) = (sc)? sc->option : 0;
  1019. offset+=2; //Shift the rest of elements by 2 bytes.
  1020. buf = WBUFP(buffer,offset);
  1021. #endif
  1022. WBUFW(buf,14) = vd->class_;
  1023. WBUFW(buf,16) = vd->hair_style;
  1024. WBUFW(buf,18) = vd->weapon;
  1025. #if PACKETVER < 4
  1026. WBUFW(buf,20) = vd->head_bottom;
  1027. WBUFL(buf,22) = gettick();
  1028. WBUFW(buf,26) = vd->shield;
  1029. #else
  1030. WBUFW(buf,20) = vd->shield;
  1031. WBUFW(buf,22) = vd->head_bottom;
  1032. WBUFL(buf,24) = gettick();
  1033. #endif
  1034. WBUFW(buf,28) = vd->head_top;
  1035. WBUFW(buf,30) = vd->head_mid;
  1036. WBUFW(buf,32) = vd->hair_color;
  1037. WBUFW(buf,34) = vd->cloth_color;
  1038. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1039. #if PACKETVER >= 20110111
  1040. WBUFW(buf,38) = vd->robe;
  1041. offset+= 2;
  1042. buf = WBUFP(buffer,offset);
  1043. #endif
  1044. WBUFL(buf,38) = status_get_guild_id(bl);
  1045. WBUFW(buf,42) = status_get_emblem_id(bl);
  1046. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1047. #if PACKETVER < 7
  1048. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1049. #else
  1050. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1051. offset+=2; //Shift the rest of elements by 2 bytes.
  1052. buf = WBUFP(buffer,offset);
  1053. #endif
  1054. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1055. WBUFB(buf,49) = vd->sex;
  1056. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1057. WBUFB(buf,56) = (sd)? 5 : 0;
  1058. WBUFB(buf,57) = (sd)? 5 : 0;
  1059. WBUFW(buf,58) = clif_setlevel(bl);
  1060. #if PACKETVER >= 20080102
  1061. WBUFW(buf,60) = sd?sd->user_font:0;
  1062. #endif
  1063. #if PACKETVER >= 20091103
  1064. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1065. return WBUFW(buffer,2);
  1066. #else
  1067. return packet_len(WBUFW(buffer,0));
  1068. #endif
  1069. }
  1070. //Modifies the buffer for disguise characters and sends it to self.
  1071. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1072. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1073. {
  1074. #if PACKETVER >= 20091103
  1075. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1076. WBUFL(buf,5)=-bl->id;
  1077. #elif PACKETVER >= 20071106
  1078. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1079. WBUFL(buf,3)=-bl->id;
  1080. #else
  1081. WBUFL(buf,2)=-bl->id;
  1082. #endif
  1083. clif_send(buf, len, bl, SELF);
  1084. }
  1085. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1086. /// 01b0 <id>.L <type>.B <value>.L
  1087. /// type:
  1088. /// unused
  1089. void clif_class_change(struct block_list *bl,int class_,int type)
  1090. {
  1091. unsigned char buf[16];
  1092. nullpo_retv(bl);
  1093. if(!pcdb_checkid(class_))
  1094. {// player classes yield missing sprites
  1095. WBUFW(buf,0)=0x1b0;
  1096. WBUFL(buf,2)=bl->id;
  1097. WBUFB(buf,6)=type;
  1098. WBUFL(buf,7)=class_;
  1099. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1100. }
  1101. }
  1102. /// Notifies the client of an object's spirits.
  1103. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1104. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1105. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1106. {
  1107. WFIFOHEAD(fd, packet_len(0x1e1));
  1108. WFIFOW(fd,0)=0x1e1;
  1109. WFIFOL(fd,2)=sd->bl.id;
  1110. WFIFOW(fd,6)=sd->spiritball;
  1111. WFIFOSET(fd, packet_len(0x1e1));
  1112. }
  1113. /*==========================================
  1114. * Run when player changes map / refreshes
  1115. * Tells its client to display all weather settings being used by this map
  1116. *------------------------------------------*/
  1117. static void clif_weather_check(struct map_session_data *sd)
  1118. {
  1119. int m = sd->bl.m, fd = sd->fd;
  1120. if (map[m].flag.snow
  1121. || map[m].flag.clouds
  1122. || map[m].flag.fog
  1123. || map[m].flag.fireworks
  1124. || map[m].flag.sakura
  1125. || map[m].flag.leaves
  1126. /**
  1127. * No longer available, keeping here just in case it's back someday. [Ind]
  1128. **/
  1129. //|| map[m].flag.rain
  1130. || map[m].flag.clouds2)
  1131. {
  1132. if (map[m].flag.snow)
  1133. clif_specialeffect_single(&sd->bl, 162, fd);
  1134. if (map[m].flag.clouds)
  1135. clif_specialeffect_single(&sd->bl, 233, fd);
  1136. if (map[m].flag.clouds2)
  1137. clif_specialeffect_single(&sd->bl, 516, fd);
  1138. if (map[m].flag.fog)
  1139. clif_specialeffect_single(&sd->bl, 515, fd);
  1140. if (map[m].flag.fireworks) {
  1141. clif_specialeffect_single(&sd->bl, 297, fd);
  1142. clif_specialeffect_single(&sd->bl, 299, fd);
  1143. clif_specialeffect_single(&sd->bl, 301, fd);
  1144. }
  1145. if (map[m].flag.sakura)
  1146. clif_specialeffect_single(&sd->bl, 163, fd);
  1147. if (map[m].flag.leaves)
  1148. clif_specialeffect_single(&sd->bl, 333, fd);
  1149. /**
  1150. * No longer available, keeping here just in case it's back someday. [Ind]
  1151. **/
  1152. //if (map[m].flag.rain)
  1153. // clif_specialeffect_single(&sd->bl, 161, fd);
  1154. }
  1155. }
  1156. /**
  1157. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1158. **/
  1159. void clif_weather(int m)
  1160. {
  1161. struct s_mapiterator* iter;
  1162. struct map_session_data *sd=NULL;
  1163. iter = mapit_getallusers();
  1164. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1165. {
  1166. if( sd->bl.m == m )
  1167. clif_weather_check(sd);
  1168. }
  1169. mapit_free(iter);
  1170. }
  1171. /**
  1172. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1173. **/
  1174. int clif_spawn(struct block_list *bl)
  1175. {
  1176. unsigned char buf[128];
  1177. struct view_data *vd;
  1178. int len;
  1179. vd = status_get_viewdata(bl);
  1180. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1181. return 0;
  1182. /**
  1183. * Hide NPC from maya purple card.
  1184. **/
  1185. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1186. return 0;
  1187. len = clif_set_unit_idle(bl, buf,true);
  1188. clif_send(buf, len, bl, AREA_WOS);
  1189. if (disguised(bl))
  1190. clif_setdisguise(bl, buf, len);
  1191. if (vd->cloth_color)
  1192. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1193. switch (bl->type)
  1194. {
  1195. case BL_PC:
  1196. {
  1197. TBL_PC *sd = ((TBL_PC*)bl);
  1198. if (sd->spiritball > 0)
  1199. clif_spiritball(sd);
  1200. if(sd->state.size==2) // tiny/big players [Valaris]
  1201. clif_specialeffect(bl,423,AREA);
  1202. else if(sd->state.size==1)
  1203. clif_specialeffect(bl,421,AREA);
  1204. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1205. clif_sendbgemblem_area(sd);
  1206. if( sd->sc.option&OPTION_MOUNTING ) {
  1207. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1208. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1209. }
  1210. #ifdef NEW_CARTS
  1211. if( sd->sc.data[SC_PUSH_CART] )
  1212. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1213. #endif
  1214. #if PACKETVER <= 20120207
  1215. if (sd->status.robe)
  1216. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1217. #endif
  1218. }
  1219. break;
  1220. case BL_MOB:
  1221. {
  1222. TBL_MOB *md = ((TBL_MOB*)bl);
  1223. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1224. clif_specialeffect(&md->bl,423,AREA);
  1225. else if(md->special_state.size==1)
  1226. clif_specialeffect(&md->bl,421,AREA);
  1227. }
  1228. break;
  1229. case BL_NPC:
  1230. {
  1231. TBL_NPC *nd = ((TBL_NPC*)bl);
  1232. if( nd->size == SZ_BIG )
  1233. clif_specialeffect(&nd->bl,423,AREA);
  1234. else if( nd->size == SZ_MEDIUM )
  1235. clif_specialeffect(&nd->bl,421,AREA);
  1236. }
  1237. break;
  1238. case BL_PET:
  1239. if (vd->head_bottom)
  1240. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1241. break;
  1242. }
  1243. return 0;
  1244. }
  1245. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1246. /// 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
  1247. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1248. {
  1249. struct status_data *status;
  1250. unsigned char buf[128];
  1251. int m_class;
  1252. nullpo_retv(hd);
  1253. status = &hd->battle_status;
  1254. m_class = hom_class2mapid(hd->homunculus.class_);
  1255. memset(buf,0,packet_len(0x22e));
  1256. WBUFW(buf,0)=0x22e;
  1257. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1258. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1259. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1260. WBUFW(buf,27)=hd->homunculus.level;
  1261. WBUFW(buf,29)=hd->homunculus.hunger;
  1262. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1263. WBUFW(buf,33)=0; // equip id
  1264. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1265. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1266. WBUFW(buf,39)=status->hit;
  1267. if (battle_config.hom_setting&0x10)
  1268. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1269. else
  1270. WBUFW(buf,41)=status->cri/10;
  1271. WBUFW(buf,43)=status->def + status->vit ;
  1272. WBUFW(buf,45)=status->mdef;
  1273. WBUFW(buf,47)=status->flee;
  1274. WBUFW(buf,49)=(flag)?0:status->amotion;
  1275. if (status->max_hp > INT16_MAX) {
  1276. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1277. WBUFW(buf,53) = 100;
  1278. } else {
  1279. WBUFW(buf,51)=status->hp;
  1280. WBUFW(buf,53)=status->max_hp;
  1281. }
  1282. if (status->max_sp > INT16_MAX) {
  1283. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1284. WBUFW(buf,57) = 100;
  1285. } else {
  1286. WBUFW(buf,55)=status->sp;
  1287. WBUFW(buf,57)=status->max_sp;
  1288. }
  1289. WBUFL(buf,59)=hd->homunculus.exp;
  1290. if( ((m_class&HOM_REG) && hd->homunculus.level >= battle_config.hom_max_level) || ((m_class&HOM_S) && hd->homunculus.level >= battle_config.hom_S_max_level) )
  1291. WBUFL(buf,63)=0;
  1292. else
  1293. WBUFL(buf,63)=hd->exp_next;
  1294. WBUFW(buf,67)=hd->homunculus.skillpts;
  1295. WBUFW(buf,69)=status_get_range(&hd->bl);
  1296. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1297. }
  1298. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1299. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1300. /// type:
  1301. /// unused
  1302. /// state:
  1303. /// 0 = pre-init
  1304. /// 1 = intimacy
  1305. /// 2 = hunger
  1306. /// 3 = accessory?
  1307. /// ? = ignored
  1308. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1309. { //[orn]
  1310. int fd = sd->fd;
  1311. WFIFOHEAD(fd, packet_len(0x230));
  1312. WFIFOW(fd,0)=0x230;
  1313. WFIFOB(fd,2)=0;
  1314. WFIFOB(fd,3)=state;
  1315. WFIFOL(fd,4)=sd->hd->bl.id;
  1316. WFIFOL(fd,8)=param;
  1317. WFIFOSET(fd,packet_len(0x230));
  1318. }
  1319. int clif_homskillinfoblock(struct map_session_data *sd)
  1320. { //[orn]
  1321. struct homun_data *hd;
  1322. int fd = sd->fd;
  1323. int i,j,len=4,id;
  1324. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1325. hd = sd->hd;
  1326. if ( !hd )
  1327. return 0 ;
  1328. WFIFOW(fd,0)=0x235;
  1329. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1330. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1331. j = id - HM_SKILLBASE;
  1332. WFIFOW(fd,len ) = id;
  1333. WFIFOW(fd,len+2) = skill_get_inf(id);
  1334. WFIFOW(fd,len+4) = 0;
  1335. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1336. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1337. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1338. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1339. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1340. len+=37;
  1341. }
  1342. }
  1343. WFIFOW(fd,2)=len;
  1344. WFIFOSET(fd,len);
  1345. return 0;
  1346. }
  1347. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1348. { //[orn]
  1349. struct homun_data *hd;
  1350. int fd, skillid;
  1351. nullpo_retv(sd);
  1352. skillid = skill_num - HM_SKILLBASE;
  1353. fd=sd->fd;
  1354. hd=sd->hd;
  1355. WFIFOHEAD(fd, packet_len(0x239));
  1356. WFIFOW(fd,0) = 0x239;
  1357. WFIFOW(fd,2) = skill_num;
  1358. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1359. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1360. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1361. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1362. WFIFOSET(fd,packet_len(0x239));
  1363. }
  1364. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1365. {
  1366. int fd=sd->fd;
  1367. WFIFOHEAD(fd,packet_len(0x22f));
  1368. WFIFOW(fd,0)=0x22f;
  1369. WFIFOB(fd,2)=fail;
  1370. WFIFOW(fd,3)=foodid;
  1371. WFIFOSET(fd,packet_len(0x22f));
  1372. return 0;
  1373. }
  1374. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1375. /// 0087 <walk start time>.L <walk data>.6B
  1376. void clif_walkok(struct map_session_data *sd)
  1377. {
  1378. int fd=sd->fd;
  1379. WFIFOHEAD(fd, packet_len(0x87));
  1380. WFIFOW(fd,0)=0x87;
  1381. WFIFOL(fd,2)=gettick();
  1382. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1383. WFIFOSET(fd,packet_len(0x87));
  1384. }
  1385. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1386. {
  1387. uint8 buf[128];
  1388. int len;
  1389. len = clif_set_unit_walking(bl,ud,buf);
  1390. clif_send(buf,len,bl,AREA_WOS);
  1391. if (disguised(bl))
  1392. clif_setdisguise(bl, buf, len);
  1393. if(vd->cloth_color)
  1394. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1395. switch(bl->type)
  1396. {
  1397. case BL_PC:
  1398. {
  1399. TBL_PC *sd = ((TBL_PC*)bl);
  1400. // clif_movepc(sd);
  1401. if(sd->state.size==2) // tiny/big players [Valaris]
  1402. clif_specialeffect(&sd->bl,423,AREA);
  1403. else if(sd->state.size==1)
  1404. clif_specialeffect(&sd->bl,421,AREA);
  1405. }
  1406. break;
  1407. case BL_MOB:
  1408. {
  1409. TBL_MOB *md = ((TBL_MOB*)bl);
  1410. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1411. clif_specialeffect(&md->bl,423,AREA);
  1412. else if(md->special_state.size==1)
  1413. clif_specialeffect(&md->bl,421,AREA);
  1414. }
  1415. break;
  1416. case BL_PET:
  1417. if( vd->head_bottom )
  1418. {// needed to display pet equip properly
  1419. clif_pet_equip_area((TBL_PET*)bl);
  1420. }
  1421. break;
  1422. }
  1423. }
  1424. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1425. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1426. /// Note: unit must not be self
  1427. void clif_move(struct unit_data *ud)
  1428. {
  1429. unsigned char buf[16];
  1430. struct view_data* vd;
  1431. struct block_list* bl = ud->bl;
  1432. vd = status_get_viewdata(bl);
  1433. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1434. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1435. /**
  1436. * Hide NPC from maya purple card.
  1437. **/
  1438. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1439. return;
  1440. if (ud->state.speed_changed) {
  1441. // Since we don't know how to update the speed of other objects,
  1442. // use the old walk packet to update the data.
  1443. ud->state.speed_changed = 0;
  1444. clif_move2(bl, vd, ud);
  1445. return;
  1446. }
  1447. WBUFW(buf,0)=0x86;
  1448. WBUFL(buf,2)=bl->id;
  1449. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1450. WBUFL(buf,12)=gettick();
  1451. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1452. if (disguised(bl))
  1453. {
  1454. WBUFL(buf,2)=-bl->id;
  1455. clif_send(buf, packet_len(0x86), bl, SELF);
  1456. }
  1457. }
  1458. /*==========================================
  1459. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1460. *------------------------------------------*/
  1461. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1462. {
  1463. struct map_session_data *sd = NULL;
  1464. //Remove player from map server
  1465. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1466. map_quit(sd);
  1467. return 0;
  1468. }
  1469. /*==========================================
  1470. *
  1471. *------------------------------------------*/
  1472. void clif_quitsave(int fd,struct map_session_data *sd)
  1473. {
  1474. if (!battle_config.prevent_logout ||
  1475. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1476. map_quit(sd);
  1477. else if (sd->fd)
  1478. { //Disassociate session from player (session is deleted after this function was called)
  1479. //And set a timer to make him quit later.
  1480. session[sd->fd]->session_data = NULL;
  1481. sd->fd = 0;
  1482. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1483. }
  1484. }
  1485. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1486. /// 0091 <map name>.16B <x>.W <y>.W
  1487. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1488. {
  1489. int fd;
  1490. nullpo_retv(sd);
  1491. fd = sd->fd;
  1492. WFIFOHEAD(fd,packet_len(0x91));
  1493. WFIFOW(fd,0) = 0x91;
  1494. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1495. WFIFOW(fd,18) = x;
  1496. WFIFOW(fd,20) = y;
  1497. WFIFOSET(fd,packet_len(0x91));
  1498. }
  1499. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1500. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1501. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1502. {
  1503. int fd;
  1504. nullpo_retv(sd);
  1505. fd = sd->fd;
  1506. WFIFOHEAD(fd,packet_len(0x92));
  1507. WFIFOW(fd,0) = 0x92;
  1508. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1509. WFIFOW(fd,18) = x;
  1510. WFIFOW(fd,20) = y;
  1511. WFIFOL(fd,22) = htonl(ip);
  1512. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1513. WFIFOSET(fd,packet_len(0x92));
  1514. }
  1515. void clif_blown(struct block_list *bl)
  1516. {
  1517. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1518. // clif_fixpos(bl);
  1519. clif_slide(bl, bl->x, bl->y);
  1520. }
  1521. /// Visually moves(slides) a character to x,y. If the target cell
  1522. /// isn't walkable, the char doesn't move at all. If the char is
  1523. /// sitting it will stand up (ZC_STOPMOVE).
  1524. /// 0088 <id>.L <x>.W <y>.W
  1525. void clif_fixpos(struct block_list *bl)
  1526. {
  1527. unsigned char buf[10];
  1528. nullpo_retv(bl);
  1529. WBUFW(buf,0) = 0x88;
  1530. WBUFL(buf,2) = bl->id;
  1531. WBUFW(buf,6) = bl->x;
  1532. WBUFW(buf,8) = bl->y;
  1533. clif_send(buf, packet_len(0x88), bl, AREA);
  1534. if( disguised(bl) )
  1535. {
  1536. WBUFL(buf,2) = -bl->id;
  1537. clif_send(buf, packet_len(0x88), bl, SELF);
  1538. }
  1539. }
  1540. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1541. /// 00c4 <shop id>.L
  1542. void clif_npcbuysell(struct map_session_data* sd, int id)
  1543. {
  1544. int fd;
  1545. nullpo_retv(sd);
  1546. fd=sd->fd;
  1547. WFIFOHEAD(fd, packet_len(0xc4));
  1548. WFIFOW(fd,0)=0xc4;
  1549. WFIFOL(fd,2)=id;
  1550. WFIFOSET(fd,packet_len(0xc4));
  1551. }
  1552. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1553. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1554. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1555. {
  1556. int fd,i,c;
  1557. nullpo_retv(sd);
  1558. nullpo_retv(nd);
  1559. fd = sd->fd;
  1560. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1561. WFIFOW(fd,0) = 0xc6;
  1562. c = 0;
  1563. for( i = 0; i < nd->u.shop.count; i++ )
  1564. {
  1565. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1566. int val = nd->u.shop.shop_item[i].value;
  1567. if( id == NULL )
  1568. continue;
  1569. WFIFOL(fd, 4+c*11) = val;
  1570. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1571. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1572. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1573. c++;
  1574. }
  1575. WFIFOW(fd,2) = 4 + c*11;
  1576. WFIFOSET(fd,WFIFOW(fd,2));
  1577. }
  1578. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1579. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1580. void clif_selllist(struct map_session_data *sd)
  1581. {
  1582. int fd,i,c=0,val;
  1583. nullpo_retv(sd);
  1584. fd=sd->fd;
  1585. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1586. WFIFOW(fd,0)=0xc7;
  1587. for( i = 0; i < MAX_INVENTORY; i++ )
  1588. {
  1589. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1590. {
  1591. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1592. continue;
  1593. if( sd->status.inventory[i].expire_time )
  1594. continue; // Cannot Sell Rental Items
  1595. val=sd->inventory_data[i]->value_sell;
  1596. if( val < 0 )
  1597. continue;
  1598. WFIFOW(fd,4+c*10)=i+2;
  1599. WFIFOL(fd,6+c*10)=val;
  1600. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1601. c++;
  1602. }
  1603. }
  1604. WFIFOW(fd,2)=c*10+4;
  1605. WFIFOSET(fd,WFIFOW(fd,2));
  1606. }
  1607. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1608. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1609. /// Client behavior (dialog window):
  1610. /// - disable mouse targeting
  1611. /// - open the dialog window
  1612. /// - set npcid of dialog window (0 by default)
  1613. /// - if set to clear on next mes, clear contents
  1614. /// - append this text
  1615. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1616. {
  1617. int fd = sd->fd;
  1618. int slen = strlen(mes) + 9;
  1619. WFIFOHEAD(fd, slen);
  1620. WFIFOW(fd,0)=0xb4;
  1621. WFIFOW(fd,2)=slen;
  1622. WFIFOL(fd,4)=npcid;
  1623. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1624. WFIFOSET(fd,WFIFOW(fd,2));
  1625. }
  1626. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1627. /// 00b5 <npc id>.L
  1628. /// Client behavior (dialog window):
  1629. /// - disable mouse targeting
  1630. /// - open the dialog window
  1631. /// - add 'next' button
  1632. /// When 'next' is pressed:
  1633. /// - 00B9 <npcid of dialog window>.L
  1634. /// - set to clear on next mes
  1635. /// - remove 'next' button
  1636. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1637. {
  1638. int fd;
  1639. nullpo_retv(sd);
  1640. fd=sd->fd;
  1641. WFIFOHEAD(fd, packet_len(0xb5));
  1642. WFIFOW(fd,0)=0xb5;
  1643. WFIFOL(fd,2)=npcid;
  1644. WFIFOSET(fd,packet_len(0xb5));
  1645. }
  1646. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1647. /// 00b6 <npc id>.L
  1648. /// Client behavior:
  1649. /// - if dialog window is open:
  1650. /// - remove 'next' button
  1651. /// - add 'close' button
  1652. /// - else:
  1653. /// - enable mouse targeting
  1654. /// - close the dialog window
  1655. /// - close the menu window
  1656. /// When 'close' is pressed:
  1657. /// - enable mouse targeting
  1658. /// - close the dialog window
  1659. /// - close the menu window
  1660. /// - 0146 <npcid of dialog window>.L
  1661. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1662. {
  1663. int fd;
  1664. nullpo_retv(sd);
  1665. fd=sd->fd;
  1666. WFIFOHEAD(fd, packet_len(0xb6));
  1667. WFIFOW(fd,0)=0xb6;
  1668. WFIFOL(fd,2)=npcid;
  1669. WFIFOSET(fd,packet_len(0xb6));
  1670. }
  1671. /*==========================================
  1672. *
  1673. *------------------------------------------*/
  1674. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1675. {
  1676. unsigned char *buf;
  1677. int fd = sd->fd;
  1678. sd->state.using_fake_npc = 1;
  1679. WFIFOHEAD(fd, packet_len(0x78));
  1680. buf = WFIFOP(fd,0);
  1681. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1682. WBUFW(buf,0)=0x78;
  1683. #if PACKETVER >= 20071106
  1684. WBUFB(buf,2) = 0; // object type
  1685. buf = WFIFOP(fd,1);
  1686. #endif
  1687. WBUFL(buf,2)=npcid;
  1688. WBUFW(buf,14)=111;
  1689. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1690. WBUFB(buf,49)=5;
  1691. WBUFB(buf,50)=5;
  1692. WFIFOSET(fd, packet_len(0x78));
  1693. }
  1694. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1695. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1696. /// Client behavior:
  1697. /// - disable mouse targeting
  1698. /// - close the menu window
  1699. /// - open the menu window
  1700. /// - add options to the menu (separated in the text by ":")
  1701. /// - set npcid of menu window
  1702. /// - if dialog window is open:
  1703. /// - remove 'next' button
  1704. /// When 'ok' is pressed:
  1705. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1706. /// - close the menu window
  1707. /// When 'cancel' is pressed:
  1708. /// - 00B8 <npcid of menu window>.L <-1>.B
  1709. /// - enable mouse targeting
  1710. /// - close a bunch of windows...
  1711. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1712. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1713. /// TODO investigate behavior of other windows [FlavioJS]
  1714. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1715. {
  1716. int fd = sd->fd;
  1717. int slen = strlen(mes) + 9;
  1718. struct block_list *bl = NULL;
  1719. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1720. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1721. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1722. clif_sendfakenpc(sd, npcid);
  1723. WFIFOHEAD(fd, slen);
  1724. WFIFOW(fd,0)=0xb7;
  1725. WFIFOW(fd,2)=slen;
  1726. WFIFOL(fd,4)=npcid;
  1727. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1728. WFIFOSET(fd,WFIFOW(fd,2));
  1729. }
  1730. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1731. /// 0142 <npc id>.L
  1732. /// Client behavior (inputnum window):
  1733. /// - if npcid exists in the client:
  1734. /// - open the inputnum window
  1735. /// - set npcid of inputnum window
  1736. /// When 'ok' is pressed:
  1737. /// - if inputnum window has text:
  1738. /// - if npcid exists in the client:
  1739. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1740. /// - close inputnum window
  1741. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1742. {
  1743. int fd;
  1744. struct block_list *bl = NULL;
  1745. nullpo_retv(sd);
  1746. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1747. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1748. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1749. clif_sendfakenpc(sd, npcid);
  1750. fd=sd->fd;
  1751. WFIFOHEAD(fd, packet_len(0x142));
  1752. WFIFOW(fd,0)=0x142;
  1753. WFIFOL(fd,2)=npcid;
  1754. WFIFOSET(fd,packet_len(0x142));
  1755. }
  1756. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1757. /// 01d4 <npc id>.L
  1758. /// Client behavior (inputstr window):
  1759. /// - if npcid is 0 or npcid exists in the client:
  1760. /// - open the inputstr window
  1761. /// - set npcid of inputstr window
  1762. /// When 'ok' is pressed:
  1763. /// - if inputstr window has text and isn't an insult(manner.txt):
  1764. /// - if npcid is 0 or npcid exists in the client:
  1765. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1766. /// - close inputstr window
  1767. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1768. {
  1769. int fd;
  1770. struct block_list *bl = NULL;
  1771. nullpo_retv(sd);
  1772. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1773. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1774. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1775. clif_sendfakenpc(sd, npcid);
  1776. fd=sd->fd;
  1777. WFIFOHEAD(fd, packet_len(0x1d4));
  1778. WFIFOW(fd,0)=0x1d4;
  1779. WFIFOL(fd,2)=npcid;
  1780. WFIFOSET(fd,packet_len(0x1d4));
  1781. }
  1782. /// Marks a position on client's minimap (ZC_COMPASS).
  1783. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1784. /// npc id:
  1785. /// is ignored in the client
  1786. /// type:
  1787. /// 0 = display mark for 15 seconds
  1788. /// 1 = display mark until dead or teleported
  1789. /// 2 = remove mark
  1790. /// color:
  1791. /// 0x00RRGGBB
  1792. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1793. {
  1794. int fd;
  1795. nullpo_retv(sd);
  1796. fd=sd->fd;
  1797. WFIFOHEAD(fd, packet_len(0x144));
  1798. WFIFOW(fd,0)=0x144;
  1799. WFIFOL(fd,2)=npc_id;
  1800. WFIFOL(fd,6)=type;
  1801. WFIFOL(fd,10)=x;
  1802. WFIFOL(fd,14)=y;
  1803. WFIFOB(fd,18)=id;
  1804. WFIFOL(fd,19)=color;
  1805. WFIFOSET(fd,packet_len(0x144));
  1806. }
  1807. /// Displays an illustration image.
  1808. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1809. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1810. /// type:
  1811. /// 0 = bottom left corner
  1812. /// 1 = bottom middle
  1813. /// 2 = bottom right corner
  1814. /// 3 = middle of screen, inside a movable window
  1815. /// 4 = middle of screen, movable with a close button, chrome-less
  1816. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1817. {
  1818. int fd;
  1819. nullpo_retv(sd);
  1820. fd=sd->fd;
  1821. WFIFOHEAD(fd, packet_len(0x1b3));
  1822. WFIFOW(fd,0)=0x1b3;
  1823. strncpy((char*)WFIFOP(fd,2),image,64);
  1824. WFIFOB(fd,66)=type;
  1825. WFIFOSET(fd,packet_len(0x1b3));
  1826. }
  1827. /*==========================================
  1828. * Fills in card data from the given item and into the buffer. [Skotlex]
  1829. *------------------------------------------*/
  1830. static void clif_addcards(unsigned char* buf, struct item* item)
  1831. {
  1832. int i=0,j;
  1833. if( item == NULL ) { //Blank data
  1834. WBUFW(buf,0) = 0;
  1835. WBUFW(buf,2) = 0;
  1836. WBUFW(buf,4) = 0;
  1837. WBUFW(buf,6) = 0;
  1838. return;
  1839. }
  1840. if( item->card[0] == CARD0_PET ) { //pet eggs
  1841. WBUFW(buf,0) = 0;
  1842. WBUFW(buf,2) = 0;
  1843. WBUFW(buf,4) = 0;
  1844. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1845. return;
  1846. }
  1847. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1848. WBUFW(buf,0) = item->card[0];
  1849. WBUFW(buf,2) = item->card[1];
  1850. WBUFW(buf,4) = item->card[2];
  1851. WBUFW(buf,6) = item->card[3];
  1852. return;
  1853. }
  1854. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1855. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1856. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1857. //Normal items.
  1858. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1859. WBUFW(buf,0) = j;
  1860. else
  1861. WBUFW(buf,0) = item->card[i];
  1862. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1863. WBUFW(buf,2) = j;
  1864. else
  1865. WBUFW(buf,2) = item->card[i];
  1866. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1867. WBUFW(buf,4) = j;
  1868. else
  1869. WBUFW(buf,4) = item->card[i];
  1870. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1871. WBUFW(buf,6) = j;
  1872. else
  1873. WBUFW(buf,6) = item->card[i];
  1874. }
  1875. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1876. /// 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)
  1877. /// 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)
  1878. /// 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)
  1879. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1880. {
  1881. int fd;
  1882. #if PACKETVER < 20061218
  1883. const int cmd = 0xa0;
  1884. #elif PACKETVER < 20071002
  1885. const int cmd = 0x29a;
  1886. #else
  1887. const int cmd = 0x2d4;
  1888. #endif
  1889. nullpo_retv(sd);
  1890. fd = sd->fd;
  1891. if( !session_isActive(fd) ) //Sasuke-
  1892. return;
  1893. WFIFOHEAD(fd,packet_len(cmd));
  1894. if( fail )
  1895. {
  1896. WFIFOW(fd,0)=cmd;
  1897. WFIFOW(fd,2)=n+2;
  1898. WFIFOW(fd,4)=amount;
  1899. WFIFOW(fd,6)=0;
  1900. WFIFOB(fd,8)=0;
  1901. WFIFOB(fd,9)=0;
  1902. WFIFOB(fd,10)=0;
  1903. WFIFOW(fd,11)=0;
  1904. WFIFOW(fd,13)=0;
  1905. WFIFOW(fd,15)=0;
  1906. WFIFOW(fd,17)=0;
  1907. WFIFOW(fd,19)=0;
  1908. WFIFOB(fd,21)=0;
  1909. WFIFOB(fd,22)=fail;
  1910. #if PACKETVER >= 20061218
  1911. WFIFOL(fd,23)=0;
  1912. #endif
  1913. #if PACKETVER >= 20071002
  1914. WFIFOW(fd,27)=0; // unknown
  1915. #endif
  1916. }
  1917. else
  1918. {
  1919. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1920. return;
  1921. WFIFOW(fd,0)=cmd;
  1922. WFIFOW(fd,2)=n+2;
  1923. WFIFOW(fd,4)=amount;
  1924. if (sd->inventory_data[n]->view_id > 0)
  1925. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1926. else
  1927. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1928. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1929. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1930. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1931. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1932. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1933. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1934. WFIFOB(fd,22)=fail;
  1935. #if PACKETVER >= 20061218
  1936. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1937. #endif
  1938. #if PACKETVER >= 20071002
  1939. WFIFOW(fd,27)=0; // unknown
  1940. #endif
  1941. }
  1942. WFIFOSET(fd,packet_len(cmd));
  1943. }
  1944. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1945. /// 00af <index>.W <amount>.W
  1946. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1947. {
  1948. int fd;
  1949. nullpo_retv(sd);
  1950. fd=sd->fd;
  1951. WFIFOHEAD(fd, packet_len(0xaf));
  1952. WFIFOW(fd,0)=0xaf;
  1953. WFIFOW(fd,2)=n+2;
  1954. WFIFOW(fd,4)=amount;
  1955. WFIFOSET(fd,packet_len(0xaf));
  1956. }
  1957. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1958. /// 07fa <delete type>.W <index>.W <amount>.W
  1959. /// delete type:
  1960. /// 0 = Normal
  1961. /// 1 = Item used for a skill
  1962. /// 2 = Refine failed
  1963. /// 3 = Material changed
  1964. /// 4 = Moved to storage
  1965. /// 5 = Moved to cart
  1966. /// 6 = Item sold
  1967. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1968. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1969. {
  1970. #if PACKETVER < 20091117
  1971. clif_dropitem(sd,n,amount);
  1972. #else
  1973. int fd;
  1974. nullpo_retv(sd);
  1975. fd=sd->fd;
  1976. WFIFOHEAD(fd, packet_len(0x7fa));
  1977. WFIFOW(fd,0)=0x7fa;
  1978. WFIFOW(fd,2)=reason;
  1979. WFIFOW(fd,4)=n+2;
  1980. WFIFOW(fd,6)=amount;
  1981. WFIFOSET(fd,packet_len(0x7fa));
  1982. #endif
  1983. }
  1984. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1985. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1986. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1987. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1988. {
  1989. if (id->view_id > 0)
  1990. WBUFW(buf,n)=id->view_id;
  1991. else
  1992. WBUFW(buf,n)=i->nameid;
  1993. WBUFB(buf,n+2)=itemtype(id->type);
  1994. WBUFB(buf,n+3)=i->identify;
  1995. if (equip >= 0) { //Equippable item
  1996. WBUFW(buf,n+4)=equip;
  1997. WBUFW(buf,n+6)=i->equip;
  1998. WBUFB(buf,n+8)=i->attribute;
  1999. WBUFB(buf,n+9)=i->refine;
  2000. } else { //Stackable item.
  2001. WBUFW(buf,n+4)=i->amount;
  2002. if (equip == -2 && id->equip == EQP_AMMO)
  2003. WBUFW(buf,n+6)=EQP_AMMO;
  2004. else
  2005. WBUFW(buf,n+6)=0;
  2006. }
  2007. }
  2008. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2009. void clif_inventorylist(struct map_session_data *sd)
  2010. {
  2011. int i,n,ne,arrow=-1;
  2012. unsigned char *buf;
  2013. unsigned char *bufe;
  2014. #if PACKETVER < 5
  2015. const int s = 10; //Entry size.
  2016. #elif PACKETVER < 20080102
  2017. const int s = 18;
  2018. #else
  2019. const int s = 22;
  2020. #endif
  2021. #if PACKETVER < 20071002
  2022. const int se = 20;
  2023. #elif PACKETVER < 20100629
  2024. const int se = 26;
  2025. #else
  2026. const int se = 28;
  2027. #endif
  2028. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2029. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2030. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2031. {
  2032. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2033. continue;
  2034. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2035. { //Non-stackable (Equippable)
  2036. WBUFW(bufe,ne*se+4)=i+2;
  2037. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2038. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  2039. #if PACKETVER >= 20071002
  2040. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  2041. WBUFW(bufe,ne*se+28)=0; //Unknown
  2042. #endif
  2043. #if PACKETVER >= 20100629
  2044. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2045. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  2046. else
  2047. WBUFW(bufe,ne*se+30)=0;
  2048. #endif
  2049. ne++;
  2050. }
  2051. else
  2052. { //Stackable.
  2053. WBUFW(buf,n*s+4)=i+2;
  2054. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2055. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2056. arrow=i;
  2057. #if PACKETVER >= 5
  2058. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2059. #endif
  2060. #if PACKETVER >= 20080102
  2061. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  2062. #endif
  2063. n++;
  2064. }
  2065. }
  2066. if( n )
  2067. {
  2068. #if PACKETVER < 5
  2069. WBUFW(buf,0)=0xa3;
  2070. #elif PACKETVER < 20080102
  2071. WBUFW(buf,0)=0x1ee;
  2072. #else
  2073. WBUFW(buf,0)=0x2e8;
  2074. #endif
  2075. WBUFW(buf,2)=4+n*s;
  2076. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2077. }
  2078. if( arrow >= 0 )
  2079. clif_arrowequip(sd,arrow);
  2080. if( ne )
  2081. {
  2082. #if PACKETVER < 20071002
  2083. WBUFW(bufe,0)=0xa4;
  2084. #else
  2085. WBUFW(bufe,0)=0x2d0;
  2086. #endif
  2087. WBUFW(bufe,2)=4+ne*se;
  2088. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2089. }
  2090. if( buf ) aFree(buf);
  2091. if( bufe ) aFree(bufe);
  2092. }
  2093. //Required when items break/get-repaired. Only sends equippable item list.
  2094. void clif_equiplist(struct map_session_data *sd)
  2095. {
  2096. int i,n,fd = sd->fd;
  2097. unsigned char *buf;
  2098. #if PACKETVER < 20071002
  2099. const int cmd = 20;
  2100. #elif PACKETVER < 20100629
  2101. const int cmd = 26;
  2102. #else
  2103. const int cmd = 28;
  2104. #endif
  2105. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2106. buf = WFIFOP(fd,0);
  2107. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2108. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2109. continue;
  2110. if(itemdb_isstackable2(sd->inventory_data[i]))
  2111. continue;
  2112. //Equippable
  2113. WBUFW(buf,n*cmd+4)=i+2;
  2114. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2115. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  2116. #if PACKETVER >= 20071002
  2117. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  2118. WBUFW(buf,n*cmd+28)=0; //Unknown
  2119. #endif
  2120. #if PACKETVER >= 20100629
  2121. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2122. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  2123. else
  2124. WBUFW(buf,n*cmd+30)=0;
  2125. #endif
  2126. n++;
  2127. }
  2128. if (n) {
  2129. #if PACKETVER < 20071002
  2130. WBUFW(buf,0)=0xa4;
  2131. #else
  2132. WBUFW(buf,0)=0x2d0;
  2133. #endif
  2134. WBUFW(buf,2)=4+n*cmd;
  2135. WFIFOSET(fd,WFIFOW(fd,2));
  2136. }
  2137. }
  2138. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2139. {
  2140. struct item_data *id;
  2141. int i,n,ne;
  2142. unsigned char *buf;
  2143. unsigned char *bufe;
  2144. #if PACKETVER < 5
  2145. const int s = 10; //Entry size.
  2146. #elif PACKETVER < 20080102
  2147. const int s = 18;
  2148. #else
  2149. const int s = 22;
  2150. #endif
  2151. #if PACKETVER < 20071002
  2152. const int cmd = 20;
  2153. #elif PACKETVER < 20100629
  2154. const int cmd = 26;
  2155. #else
  2156. const int cmd = 28;
  2157. #endif
  2158. buf = (unsigned char*)aMalloc(items_length * s + 4);
  2159. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  2160. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2161. {
  2162. if( items[i].nameid <= 0 )
  2163. continue;
  2164. id = itemdb_search(items[i].nameid);
  2165. if( !itemdb_isstackable2(id) )
  2166. { //Equippable
  2167. WBUFW(bufe,ne*cmd+4)=i+1;
  2168. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2169. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2170. #if PACKETVER >= 20071002
  2171. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2172. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2173. #endif
  2174. ne++;
  2175. }
  2176. else
  2177. { //Stackable
  2178. WBUFW(buf,n*s+4)=i+1;
  2179. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2180. #if PACKETVER >= 5
  2181. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2182. #endif
  2183. #if PACKETVER >= 20080102
  2184. WBUFL(buf,n*s+22)=items[i].expire_time;
  2185. #endif
  2186. n++;
  2187. }
  2188. }
  2189. if( n )
  2190. {
  2191. #if PACKETVER < 5
  2192. WBUFW(buf,0)=0xa5;
  2193. #elif PACKETVER < 20080102
  2194. WBUFW(buf,0)=0x1f0;
  2195. #else
  2196. WBUFW(buf,0)=0x2ea;
  2197. #endif
  2198. WBUFW(buf,2)=4+n*s;
  2199. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2200. }
  2201. if( ne )
  2202. {
  2203. #if PACKETVER < 20071002
  2204. WBUFW(bufe,0)=0xa6;
  2205. #else
  2206. WBUFW(bufe,0)=0x2d1;
  2207. #endif
  2208. WBUFW(bufe,2)=4+ne*cmd;
  2209. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2210. }
  2211. if( buf ) aFree(buf);
  2212. if( bufe ) aFree(bufe);
  2213. }
  2214. void clif_cartlist(struct map_session_data *sd)
  2215. {
  2216. struct item_data *id;
  2217. int i,n,ne;
  2218. unsigned char *buf;
  2219. unsigned char *bufe;
  2220. #if PACKETVER < 5
  2221. const int s = 10; //Entry size.
  2222. #elif PACKETVER < 20080102
  2223. const int s = 18;
  2224. #else
  2225. const int s = 22;
  2226. #endif
  2227. #if PACKETVER < 20071002
  2228. const int cmd = 20;
  2229. #elif PACKETVER < 20100629
  2230. const int cmd = 26;
  2231. #else
  2232. const int cmd = 28;
  2233. #endif
  2234. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2235. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2236. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2237. {
  2238. if( sd->status.cart[i].nameid <= 0 )
  2239. continue;
  2240. id = itemdb_search(sd->status.cart[i].nameid);
  2241. if( !itemdb_isstackable2(id) )
  2242. { //Equippable
  2243. WBUFW(bufe,ne*cmd+4)=i+2;
  2244. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2245. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2246. #if PACKETVER >= 20071002
  2247. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2248. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2249. #endif
  2250. ne++;
  2251. }
  2252. else
  2253. { //Stackable
  2254. WBUFW(buf,n*s+4)=i+2;
  2255. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2256. #if PACKETVER >= 5
  2257. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2258. #endif
  2259. #if PACKETVER >= 20080102
  2260. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2261. #endif
  2262. n++;
  2263. }
  2264. }
  2265. if( n )
  2266. {
  2267. #if PACKETVER < 5
  2268. WBUFW(buf,0)=0x123;
  2269. #elif PACKETVER < 20080102
  2270. WBUFW(buf,0)=0x1ef;
  2271. #else
  2272. WBUFW(buf,0)=0x2e9;
  2273. #endif
  2274. WBUFW(buf,2)=4+n*s;
  2275. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2276. }
  2277. if( ne )
  2278. {
  2279. #if PACKETVER < 20071002
  2280. WBUFW(bufe,0)=0x122;
  2281. #else
  2282. WBUFW(bufe,0)=0x2d2;
  2283. #endif
  2284. WBUFW(bufe,2)=4+ne*cmd;
  2285. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2286. }
  2287. if( buf ) aFree(buf);
  2288. if( bufe ) aFree(bufe);
  2289. }
  2290. /// Removes cart (ZC_CARTOFF).
  2291. /// 012b
  2292. /// Client behaviour:
  2293. /// Closes the cart storage and removes all it's items from memory.
  2294. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2295. void clif_clearcart(int fd)
  2296. {
  2297. WFIFOHEAD(fd, packet_len(0x12b));
  2298. WFIFOW(fd,0) = 0x12b;
  2299. WFIFOSET(fd, packet_len(0x12b));
  2300. }
  2301. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2302. /// 01eb <account id>.L <x>.W <y>.W
  2303. void clif_guild_xy(struct map_session_data *sd)
  2304. {
  2305. unsigned char buf[10];
  2306. nullpo_retv(sd);
  2307. WBUFW(buf,0)=0x1eb;
  2308. WBUFL(buf,2)=sd->status.account_id;
  2309. WBUFW(buf,6)=sd->bl.x;
  2310. WBUFW(buf,8)=sd->bl.y;
  2311. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2312. }
  2313. /*==========================================
  2314. * Sends x/y dot to a single fd. [Skotlex]
  2315. *------------------------------------------*/
  2316. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2317. {
  2318. if( sd->bg_id )
  2319. return;
  2320. WFIFOHEAD(fd,packet_len(0x1eb));
  2321. WFIFOW(fd,0)=0x1eb;
  2322. WFIFOL(fd,2)=sd->status.account_id;
  2323. WFIFOW(fd,6)=sd->bl.x;
  2324. WFIFOW(fd,8)=sd->bl.y;
  2325. WFIFOSET(fd,packet_len(0x1eb));
  2326. }
  2327. // Guild XY locators [Valaris]
  2328. void clif_guild_xy_remove(struct map_session_data *sd)
  2329. {
  2330. unsigned char buf[10];
  2331. nullpo_retv(sd);
  2332. WBUFW(buf,0)=0x1eb;
  2333. WBUFL(buf,2)=sd->status.account_id;
  2334. WBUFW(buf,6)=-1;
  2335. WBUFW(buf,8)=-1;
  2336. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2337. }
  2338. /*==========================================
  2339. *
  2340. *------------------------------------------*/
  2341. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2342. {
  2343. struct map_session_data *sd, *tsd;
  2344. #if PACKETVER < 20100126
  2345. const int cmd = 0x106;
  2346. #else
  2347. const int cmd = 0x80e;
  2348. #endif
  2349. sd = va_arg(ap, struct map_session_data *);
  2350. tsd = (TBL_PC *)bl;
  2351. nullpo_ret(sd);
  2352. nullpo_ret(tsd);
  2353. if( !tsd->fd || tsd == sd )
  2354. return 0;
  2355. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2356. return 0;
  2357. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2358. WFIFOW(tsd->fd,0) = cmd;
  2359. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2360. #if PACKETVER < 20100126
  2361. if( sd->battle_status.max_hp > INT16_MAX )
  2362. { //To correctly display the %hp bar. [Skotlex]
  2363. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2364. WFIFOW(tsd->fd,8) = 100;
  2365. } else {
  2366. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2367. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2368. }
  2369. #else
  2370. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2371. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2372. #endif
  2373. WFIFOSET(tsd->fd,packet_len(cmd));
  2374. return 0;
  2375. }
  2376. /*==========================================
  2377. * Server tells all players that are allowed to view HP bars
  2378. * and are nearby 'sd' that 'sd' hp bar was updated.
  2379. *------------------------------------------*/
  2380. static int clif_hpmeter(struct map_session_data *sd)
  2381. {
  2382. nullpo_ret(sd);
  2383. 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);
  2384. return 0;
  2385. }
  2386. /// Notifies client of a character parameter change.
  2387. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2388. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2389. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2390. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2391. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2392. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2393. /// TODO: Extract individual packets.
  2394. /// FIXME: Packet lengths from packet_len(cmd)
  2395. void clif_updatestatus(struct map_session_data *sd,int type)
  2396. {
  2397. int fd,len=8;
  2398. nullpo_retv(sd);
  2399. fd=sd->fd;
  2400. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2401. return;
  2402. WFIFOHEAD(fd, 14);
  2403. WFIFOW(fd,0)=0xb0;
  2404. WFIFOW(fd,2)=type;
  2405. switch(type){
  2406. // 00b0
  2407. case SP_WEIGHT:
  2408. pc_updateweightstatus(sd);
  2409. WFIFOHEAD(fd,14);
  2410. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2411. WFIFOW(fd,2)=type;
  2412. WFIFOL(fd,4)=sd->weight;
  2413. break;
  2414. case SP_MAXWEIGHT:
  2415. WFIFOL(fd,4)=sd->max_weight;
  2416. break;
  2417. case SP_SPEED:
  2418. WFIFOL(fd,4)=sd->battle_status.speed;
  2419. break;
  2420. case SP_BASELEVEL:
  2421. WFIFOL(fd,4)=sd->status.base_level;
  2422. break;
  2423. case SP_JOBLEVEL:
  2424. WFIFOL(fd,4)=sd->status.job_level;
  2425. break;
  2426. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2427. WFIFOL(fd,4)=sd->status.karma;
  2428. break;
  2429. case SP_MANNER:
  2430. WFIFOL(fd,4)=sd->status.manner;
  2431. break;
  2432. case SP_STATUSPOINT:
  2433. WFIFOL(fd,4)=sd->status.status_point;
  2434. break;
  2435. case SP_SKILLPOINT:
  2436. WFIFOL(fd,4)=sd->status.skill_point;
  2437. break;
  2438. case SP_HIT:
  2439. WFIFOL(fd,4)=sd->battle_status.hit;
  2440. break;
  2441. case SP_FLEE1:
  2442. WFIFOL(fd,4)=sd->battle_status.flee;
  2443. break;
  2444. case SP_FLEE2:
  2445. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2446. break;
  2447. case SP_MAXHP:
  2448. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2449. break;
  2450. case SP_MAXSP:
  2451. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2452. break;
  2453. case SP_HP:
  2454. WFIFOL(fd,4)=sd->battle_status.hp;
  2455. // TODO: Won't these overwrite the current packet?
  2456. clif_hpmeter(sd);
  2457. if( !battle_config.party_hp_mode && sd->status.party_id )
  2458. clif_party_hp(sd);
  2459. if( sd->bg_id )
  2460. clif_bg_hp(sd);
  2461. break;
  2462. case SP_SP:
  2463. WFIFOL(fd,4)=sd->battle_status.sp;
  2464. break;
  2465. case SP_ASPD:
  2466. WFIFOL(fd,4)=sd->battle_status.amotion;
  2467. break;
  2468. case SP_ATK1:
  2469. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2470. break;
  2471. case SP_DEF1:
  2472. WFIFOL(fd,4)=pc_leftside_def(sd);
  2473. break;
  2474. case SP_MDEF1:
  2475. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2476. break;
  2477. case SP_ATK2:
  2478. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2479. break;
  2480. case SP_DEF2:
  2481. WFIFOL(fd,4)=pc_rightside_def(sd);
  2482. break;
  2483. case SP_MDEF2: {
  2484. //negative check (in case you have something like Berserk active)
  2485. int mdef2 = pc_rightside_mdef(sd);
  2486. WFIFOL(fd,4)=
  2487. #ifndef RENEWAL
  2488. ( mdef2 < 0 ) ? 0 :
  2489. #endif
  2490. mdef2;
  2491. }
  2492. break;
  2493. case SP_CRITICAL:
  2494. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2495. break;
  2496. case SP_MATK1:
  2497. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2498. break;
  2499. case SP_MATK2:
  2500. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2501. break;
  2502. case SP_ZENY:
  2503. WFIFOW(fd,0)=0xb1;
  2504. WFIFOL(fd,4)=sd->status.zeny;
  2505. break;
  2506. case SP_BASEEXP:
  2507. WFIFOW(fd,0)=0xb1;
  2508. WFIFOL(fd,4)=sd->status.base_exp;
  2509. break;
  2510. case SP_JOBEXP:
  2511. WFIFOW(fd,0)=0xb1;
  2512. WFIFOL(fd,4)=sd->status.job_exp;
  2513. break;
  2514. case SP_NEXTBASEEXP:
  2515. WFIFOW(fd,0)=0xb1;
  2516. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2517. break;
  2518. case SP_NEXTJOBEXP:
  2519. WFIFOW(fd,0)=0xb1;
  2520. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2521. break;
  2522. /**
  2523. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2524. **/
  2525. case SP_USTR:
  2526. case SP_UAGI:
  2527. case SP_UVIT:
  2528. case SP_UINT:
  2529. case SP_UDEX:
  2530. case SP_ULUK:
  2531. WFIFOW(fd,0)=0xbe;
  2532. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2533. len=5;
  2534. break;
  2535. /**
  2536. * Tells the client how far it is allowed to attack (weapon range)
  2537. **/
  2538. case SP_ATTACKRANGE:
  2539. WFIFOW(fd,0)=0x13a;
  2540. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2541. len=4;
  2542. break;
  2543. case SP_STR:
  2544. WFIFOW(fd,0)=0x141;
  2545. WFIFOL(fd,2)=type;
  2546. WFIFOL(fd,6)=sd->status.str;
  2547. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2548. len=14;
  2549. break;
  2550. case SP_AGI:
  2551. WFIFOW(fd,0)=0x141;
  2552. WFIFOL(fd,2)=type;
  2553. WFIFOL(fd,6)=sd->status.agi;
  2554. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2555. len=14;
  2556. break;
  2557. case SP_VIT:
  2558. WFIFOW(fd,0)=0x141;
  2559. WFIFOL(fd,2)=type;
  2560. WFIFOL(fd,6)=sd->status.vit;
  2561. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2562. len=14;
  2563. break;
  2564. case SP_INT:
  2565. WFIFOW(fd,0)=0x141;
  2566. WFIFOL(fd,2)=type;
  2567. WFIFOL(fd,6)=sd->status.int_;
  2568. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2569. len=14;
  2570. break;
  2571. case SP_DEX:
  2572. WFIFOW(fd,0)=0x141;
  2573. WFIFOL(fd,2)=type;
  2574. WFIFOL(fd,6)=sd->status.dex;
  2575. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2576. len=14;
  2577. break;
  2578. case SP_LUK:
  2579. WFIFOW(fd,0)=0x141;
  2580. WFIFOL(fd,2)=type;
  2581. WFIFOL(fd,6)=sd->status.luk;
  2582. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2583. len=14;
  2584. break;
  2585. case SP_CARTINFO:
  2586. WFIFOW(fd,0)=0x121;
  2587. WFIFOW(fd,2)=sd->cart_num;
  2588. WFIFOW(fd,4)=MAX_CART;
  2589. WFIFOL(fd,6)=sd->cart_weight;
  2590. WFIFOL(fd,10)=sd->cart_weight_max;
  2591. len=14;
  2592. break;
  2593. default:
  2594. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2595. return;
  2596. }
  2597. WFIFOSET(fd,len);
  2598. }
  2599. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2600. /// 01ab <account id>.L <var id>.W <value>.L
  2601. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2602. {
  2603. unsigned char buf[12];
  2604. nullpo_retv(sd);
  2605. WBUFW(buf,0)=0x1ab;
  2606. WBUFL(buf,2)=sd->bl.id;
  2607. WBUFW(buf,6)=type;
  2608. switch(type)
  2609. {
  2610. case SP_MANNER:
  2611. WBUFL(buf,8)=val;
  2612. break;
  2613. default:
  2614. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2615. return;
  2616. }
  2617. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2618. }
  2619. /// Updates sprite/style properties of an object.
  2620. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2621. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2622. void clif_changelook(struct block_list *bl,int type,int val)
  2623. {
  2624. unsigned char buf[16];
  2625. struct map_session_data* sd = NULL;
  2626. struct status_change* sc;
  2627. struct view_data* vd;
  2628. enum send_target target = AREA;
  2629. nullpo_retv(bl);
  2630. sd = BL_CAST(BL_PC, bl);
  2631. sc = status_get_sc(bl);
  2632. vd = status_get_viewdata(bl);
  2633. //nullpo_ret(vd);
  2634. if( vd ) //temp hack to let Warp Portal change appearance
  2635. switch(type)
  2636. {
  2637. case LOOK_WEAPON:
  2638. if (sd)
  2639. {
  2640. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2641. val = vd->weapon;
  2642. }
  2643. else vd->weapon = val;
  2644. break;
  2645. case LOOK_SHIELD:
  2646. if (sd)
  2647. {
  2648. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2649. val = vd->shield;
  2650. }
  2651. else vd->shield = val;
  2652. break;
  2653. case LOOK_BASE:
  2654. vd->class_ = val;
  2655. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2656. vd->weapon = vd->shield = 0;
  2657. if (vd->cloth_color && (
  2658. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2659. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2660. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2661. ))
  2662. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2663. break;
  2664. case LOOK_HAIR:
  2665. vd->hair_style = val;
  2666. break;
  2667. case LOOK_HEAD_BOTTOM:
  2668. vd->head_bottom = val;
  2669. break;
  2670. case LOOK_HEAD_TOP:
  2671. vd->head_top = val;
  2672. break;
  2673. case LOOK_HEAD_MID:
  2674. vd->head_mid = val;
  2675. break;
  2676. case LOOK_HAIR_COLOR:
  2677. vd->hair_color = val;
  2678. break;
  2679. case LOOK_CLOTHES_COLOR:
  2680. if (val && (
  2681. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2682. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2683. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2684. ))
  2685. val = 0;
  2686. vd->cloth_color = val;
  2687. break;
  2688. case LOOK_SHOES:
  2689. #if PACKETVER > 3
  2690. if (sd) {
  2691. int n;
  2692. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2693. if(sd->inventory_data[n]->view_id > 0)
  2694. val = sd->inventory_data[n]->view_id;
  2695. else
  2696. val = sd->status.inventory[n].nameid;
  2697. }
  2698. val = 0;
  2699. }
  2700. #endif
  2701. //Shoes? No packet uses this....
  2702. break;
  2703. case LOOK_BODY:
  2704. case LOOK_FLOOR:
  2705. // unknown purpose
  2706. break;
  2707. case LOOK_ROBE:
  2708. #if PACKETVER < 20110111
  2709. return;
  2710. #else
  2711. vd->robe = val;
  2712. #endif
  2713. break;
  2714. }
  2715. // prevent leaking the presence of GM-hidden objects
  2716. if( sc && sc->option&OPTION_INVISIBLE )
  2717. target = SELF;
  2718. #if PACKETVER < 4
  2719. WBUFW(buf,0)=0xc3;
  2720. WBUFL(buf,2)=bl->id;
  2721. WBUFB(buf,6)=type;
  2722. WBUFB(buf,7)=val;
  2723. clif_send(buf,packet_len(0xc3),bl,target);
  2724. #else
  2725. WBUFW(buf,0)=0x1d7;
  2726. WBUFL(buf,2)=bl->id;
  2727. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2728. WBUFB(buf,6)=LOOK_WEAPON;
  2729. WBUFW(buf,7)=vd->weapon;
  2730. WBUFW(buf,9)=vd->shield;
  2731. } else {
  2732. WBUFB(buf,6)=type;
  2733. WBUFL(buf,7)=val;
  2734. }
  2735. clif_send(buf,packet_len(0x1d7),bl,target);
  2736. #endif
  2737. }
  2738. //Sends a change-base-look packet required for traps as they are triggered.
  2739. void clif_changetraplook(struct block_list *bl,int val)
  2740. {
  2741. unsigned char buf[32];
  2742. #if PACKETVER < 4
  2743. WBUFW(buf,0)=0xc3;
  2744. WBUFL(buf,2)=bl->id;
  2745. WBUFB(buf,6)=LOOK_BASE;
  2746. WBUFB(buf,7)=val;
  2747. clif_send(buf,packet_len(0xc3),bl,AREA);
  2748. #else
  2749. WBUFW(buf,0)=0x1d7;
  2750. WBUFL(buf,2)=bl->id;
  2751. WBUFB(buf,6)=LOOK_BASE;
  2752. WBUFW(buf,7)=val;
  2753. WBUFW(buf,9)=0;
  2754. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2755. #endif
  2756. }
  2757. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2758. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2759. {
  2760. unsigned char buf[32];
  2761. #if PACKETVER < 4
  2762. WBUFW(buf,0)=0xc3;
  2763. WBUFL(buf,2)=id;
  2764. WBUFB(buf,6)=type;
  2765. WBUFB(buf,7)=val;
  2766. clif_send(buf,packet_len(0xc3),bl,target);
  2767. #else
  2768. WBUFW(buf,0)=0x1d7;
  2769. WBUFL(buf,2)=id;
  2770. WBUFB(buf,6)=type;
  2771. WBUFW(buf,7)=val;
  2772. WBUFW(buf,9)=0;
  2773. clif_send(buf,packet_len(0x1d7),bl,target);
  2774. #endif
  2775. }
  2776. /// Character status (ZC_STATUS).
  2777. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2778. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2779. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2780. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2781. void clif_initialstatus(struct map_session_data *sd)
  2782. {
  2783. int fd, mdef2;
  2784. unsigned char *buf;
  2785. nullpo_retv(sd);
  2786. fd=sd->fd;
  2787. WFIFOHEAD(fd,packet_len(0xbd));
  2788. buf=WFIFOP(fd,0);
  2789. WBUFW(buf,0)=0xbd;
  2790. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2791. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2792. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2793. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2794. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2795. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2796. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2797. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2798. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2799. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2800. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2801. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2802. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2803. WBUFW(buf,16) = pc_leftside_atk(sd);
  2804. WBUFW(buf,18) = pc_rightside_atk(sd);
  2805. WBUFW(buf,20) = sd->battle_status.matk_max;
  2806. WBUFW(buf,22) = sd->battle_status.matk_min;
  2807. WBUFW(buf,24) = pc_leftside_def(sd);
  2808. WBUFW(buf,26) = pc_rightside_def(sd);
  2809. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2810. mdef2 = pc_rightside_mdef(sd);
  2811. WBUFW(buf,30) =
  2812. #ifndef RENEWAL
  2813. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2814. #endif
  2815. mdef2;
  2816. WBUFW(buf,32) = sd->battle_status.hit;
  2817. WBUFW(buf,34) = sd->battle_status.flee;
  2818. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2819. WBUFW(buf,38) = sd->battle_status.cri/10;
  2820. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2821. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2822. WFIFOSET(fd,packet_len(0xbd));
  2823. clif_updatestatus(sd,SP_STR);
  2824. clif_updatestatus(sd,SP_AGI);
  2825. clif_updatestatus(sd,SP_VIT);
  2826. clif_updatestatus(sd,SP_INT);
  2827. clif_updatestatus(sd,SP_DEX);
  2828. clif_updatestatus(sd,SP_LUK);
  2829. clif_updatestatus(sd,SP_ATTACKRANGE);
  2830. clif_updatestatus(sd,SP_ASPD);
  2831. }
  2832. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2833. /// 013c <index>.W
  2834. void clif_arrowequip(struct map_session_data *sd,int val)
  2835. {
  2836. int fd;
  2837. nullpo_retv(sd);
  2838. pc_stop_attack(sd); // [Valaris]
  2839. fd=sd->fd;
  2840. WFIFOHEAD(fd, packet_len(0x013c));
  2841. WFIFOW(fd,0)=0x013c;
  2842. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2843. WFIFOSET(fd,packet_len(0x013c));
  2844. }
  2845. /// Ammunition action message (ZC_ACTION_FAILURE).
  2846. /// 013b <type>.W
  2847. /// type:
  2848. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2849. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2850. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2851. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2852. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2853. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2854. void clif_arrow_fail(struct map_session_data *sd,int type)
  2855. {
  2856. int fd;
  2857. nullpo_retv(sd);
  2858. fd=sd->fd;
  2859. WFIFOHEAD(fd, packet_len(0x013b));
  2860. WFIFOW(fd,0)=0x013b;
  2861. WFIFOW(fd,2)=type;
  2862. WFIFOSET(fd,packet_len(0x013b));
  2863. }
  2864. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2865. /// 01ad <packet len>.W { <name id>.W }*
  2866. void clif_arrow_create_list(struct map_session_data *sd)
  2867. {
  2868. int i, c, j;
  2869. int fd;
  2870. nullpo_retv(sd);
  2871. fd = sd->fd;
  2872. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2873. WFIFOW(fd,0) = 0x1ad;
  2874. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2875. if (skill_arrow_db[i].nameid > 0 &&
  2876. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2877. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2878. {
  2879. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2880. WFIFOW(fd,c*2+4) = j;
  2881. else
  2882. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2883. c++;
  2884. }
  2885. }
  2886. WFIFOW(fd,2) = c*2+4;
  2887. WFIFOSET(fd, WFIFOW(fd,2));
  2888. if (c > 0) {
  2889. sd->menuskill_id = AC_MAKINGARROW;
  2890. sd->menuskill_val = c;
  2891. }
  2892. }
  2893. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2894. /// 00bc <status id>.W <result>.B <value>.B
  2895. /// status id:
  2896. /// SP_STR ~ SP_LUK
  2897. /// result:
  2898. /// 0 = failure
  2899. /// 1 = success
  2900. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2901. {
  2902. int fd;
  2903. nullpo_retv(sd);
  2904. fd=sd->fd;
  2905. WFIFOHEAD(fd,packet_len(0xbc));
  2906. WFIFOW(fd,0)=0xbc;
  2907. WFIFOW(fd,2)=type;
  2908. WFIFOB(fd,4)=ok;
  2909. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2910. WFIFOSET(fd,packet_len(0xbc));
  2911. }
  2912. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2913. /// 00aa <index>.W <equip location>.W <result>.B
  2914. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2915. /// result:
  2916. /// 0 = failure
  2917. /// 1 = success
  2918. /// 2 = failure due to low level
  2919. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2920. {
  2921. int fd;
  2922. nullpo_retv(sd);
  2923. fd=sd->fd;
  2924. WFIFOHEAD(fd,packet_len(0xaa));
  2925. WFIFOW(fd,0)=0xaa;
  2926. WFIFOW(fd,2)=n+2;
  2927. WFIFOW(fd,4)=pos;
  2928. #if PACKETVER < 20100629
  2929. WFIFOB(fd,6)=ok;
  2930. #else
  2931. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2932. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2933. else
  2934. WFIFOW(fd,6)=0;
  2935. WFIFOB(fd,8)=ok;
  2936. #endif
  2937. WFIFOSET(fd,packet_len(0xaa));
  2938. }
  2939. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2940. /// 00ac <index>.W <equip location>.W <result>.B
  2941. /// result:
  2942. /// 0 = failure
  2943. /// 1 = success
  2944. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2945. {
  2946. int fd;
  2947. nullpo_retv(sd);
  2948. fd=sd->fd;
  2949. WFIFOHEAD(fd,packet_len(0xac));
  2950. WFIFOW(fd,0)=0xac;
  2951. WFIFOW(fd,2)=n+2;
  2952. WFIFOW(fd,4)=pos;
  2953. WFIFOB(fd,6)=ok;
  2954. WFIFOSET(fd,packet_len(0xac));
  2955. }
  2956. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2957. /// 019b <id>.L <effect id>.L
  2958. /// effect id:
  2959. /// 0 = base level up
  2960. /// 1 = job level up
  2961. /// 2 = refine failure
  2962. /// 3 = refine success
  2963. /// 4 = game over
  2964. /// 5 = pharmacy success
  2965. /// 6 = pharmacy failure
  2966. /// 7 = base level up (super novice)
  2967. /// 8 = job level up (super novice)
  2968. /// 9 = base level up (taekwon)
  2969. void clif_misceffect(struct block_list* bl,int type)
  2970. {
  2971. unsigned char buf[32];
  2972. nullpo_retv(bl);
  2973. WBUFW(buf,0) = 0x19b;
  2974. WBUFL(buf,2) = bl->id;
  2975. WBUFL(buf,6) = type;
  2976. clif_send(buf,packet_len(0x19b),bl,AREA);
  2977. }
  2978. /// Notifies clients in the area of a state change.
  2979. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  2980. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  2981. void clif_changeoption(struct block_list* bl)
  2982. {
  2983. unsigned char buf[32];
  2984. struct status_change *sc;
  2985. struct map_session_data* sd;
  2986. nullpo_retv(bl);
  2987. sc = status_get_sc(bl);
  2988. if (!sc) return; //How can an option change if there's no sc?
  2989. sd = BL_CAST(BL_PC, bl);
  2990. #if PACKETVER >= 7
  2991. WBUFW(buf,0) = 0x229;
  2992. WBUFL(buf,2) = bl->id;
  2993. WBUFW(buf,6) = sc->opt1;
  2994. WBUFW(buf,8) = sc->opt2;
  2995. WBUFL(buf,10) = sc->option;
  2996. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2997. if(disguised(bl)) {
  2998. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2999. WBUFL(buf,2) = -bl->id;
  3000. clif_send(buf,packet_len(0x229),bl,SELF);
  3001. WBUFL(buf,2) = bl->id;
  3002. WBUFL(buf,10) = OPTION_INVISIBLE;
  3003. clif_send(buf,packet_len(0x229),bl,SELF);
  3004. } else
  3005. clif_send(buf,packet_len(0x229),bl,AREA);
  3006. #else
  3007. WBUFW(buf,0) = 0x119;
  3008. WBUFL(buf,2) = bl->id;
  3009. WBUFW(buf,6) = sc->opt1;
  3010. WBUFW(buf,8) = sc->opt2;
  3011. WBUFW(buf,10) = sc->option;
  3012. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3013. if(disguised(bl)) {
  3014. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3015. WBUFL(buf,2) = -bl->id;
  3016. clif_send(buf,packet_len(0x119),bl,SELF);
  3017. WBUFL(buf,2) = bl->id;
  3018. WBUFW(buf,10) = OPTION_INVISIBLE;
  3019. clif_send(buf,packet_len(0x119),bl,SELF);
  3020. } else
  3021. clif_send(buf,packet_len(0x119),bl,AREA);
  3022. #endif
  3023. }
  3024. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3025. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3026. void clif_changeoption2(struct block_list* bl)
  3027. {
  3028. unsigned char buf[20];
  3029. struct status_change *sc;
  3030. sc = status_get_sc(bl);
  3031. if (!sc) return; //How can an option change if there's no sc?
  3032. WBUFW(buf,0) = 0x28a;
  3033. WBUFL(buf,2) = bl->id;
  3034. WBUFL(buf,6) = sc->option;
  3035. WBUFL(buf,10) = clif_setlevel(bl);
  3036. WBUFL(buf,14) = sc->opt3;
  3037. if(disguised(bl)) {
  3038. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3039. WBUFL(buf,2) = -bl->id;
  3040. clif_send(buf,packet_len(0x28a),bl,SELF);
  3041. WBUFL(buf,2) = bl->id;
  3042. WBUFL(buf,6) = OPTION_INVISIBLE;
  3043. clif_send(buf,packet_len(0x28a),bl,SELF);
  3044. } else
  3045. clif_send(buf,packet_len(0x28a),bl,AREA);
  3046. }
  3047. /// Notifies the client about the result of an item use request.
  3048. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3049. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3050. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3051. {
  3052. nullpo_retv(sd);
  3053. if(!ok) {
  3054. int fd=sd->fd;
  3055. WFIFOHEAD(fd,packet_len(0xa8));
  3056. WFIFOW(fd,0)=0xa8;
  3057. WFIFOW(fd,2)=index+2;
  3058. WFIFOW(fd,4)=amount;
  3059. WFIFOB(fd,6)=ok;
  3060. WFIFOSET(fd,packet_len(0xa8));
  3061. }
  3062. else {
  3063. #if PACKETVER < 3
  3064. int fd=sd->fd;
  3065. WFIFOHEAD(fd,packet_len(0xa8));
  3066. WFIFOW(fd,0)=0xa8;
  3067. WFIFOW(fd,2)=index+2;
  3068. WFIFOW(fd,4)=amount;
  3069. WFIFOB(fd,6)=ok;
  3070. WFIFOSET(fd,packet_len(0xa8));
  3071. #else
  3072. unsigned char buf[32];
  3073. WBUFW(buf,0)=0x1c8;
  3074. WBUFW(buf,2)=index+2;
  3075. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3076. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3077. else
  3078. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3079. WBUFL(buf,6)=sd->bl.id;
  3080. WBUFW(buf,10)=amount;
  3081. WBUFB(buf,12)=ok;
  3082. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3083. #endif
  3084. }
  3085. }
  3086. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3087. /// 00d6 <flag>.B
  3088. /// flag:
  3089. /// 0 = Room has been successfully created (opens chat room)
  3090. /// 1 = Room limit exceeded
  3091. /// 2 = Same room already exists
  3092. void clif_createchat(struct map_session_data* sd, int flag)
  3093. {
  3094. int fd;
  3095. nullpo_retv(sd);
  3096. fd = sd->fd;
  3097. WFIFOHEAD(fd,packet_len(0xd6));
  3098. WFIFOW(fd,0) = 0xd6;
  3099. WFIFOB(fd,2) = flag;
  3100. WFIFOSET(fd,packet_len(0xd6));
  3101. }
  3102. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3103. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3104. /// type:
  3105. /// 0 = private (password protected)
  3106. /// 1 = public
  3107. /// 2 = arena (npc waiting room)
  3108. /// 3 = PK zone (non-clickable)
  3109. void clif_dispchat(struct chat_data* cd, int fd)
  3110. {
  3111. unsigned char buf[128];
  3112. uint8 type;
  3113. if( cd == NULL || cd->owner == NULL )
  3114. return;
  3115. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3116. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3117. : 1;
  3118. WBUFW(buf, 0) = 0xd7;
  3119. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3120. WBUFL(buf, 4) = cd->owner->id;
  3121. WBUFL(buf, 8) = cd->bl.id;
  3122. WBUFW(buf,12) = cd->limit;
  3123. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3124. WBUFB(buf,16) = type;
  3125. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3126. if( fd ) {
  3127. WFIFOHEAD(fd,WBUFW(buf,2));
  3128. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3129. WFIFOSET(fd,WBUFW(buf,2));
  3130. } else {
  3131. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3132. }
  3133. }
  3134. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3135. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3136. /// type:
  3137. /// 0 = private (password protected)
  3138. /// 1 = public
  3139. /// 2 = arena (npc waiting room)
  3140. /// 3 = PK zone (non-clickable)
  3141. void clif_changechatstatus(struct chat_data* cd)
  3142. {
  3143. unsigned char buf[128];
  3144. uint8 type;
  3145. if( cd == NULL || cd->usersd[0] == NULL )
  3146. return;
  3147. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3148. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3149. : 1;
  3150. WBUFW(buf, 0) = 0xdf;
  3151. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3152. WBUFL(buf, 4) = cd->owner->id;
  3153. WBUFL(buf, 8) = cd->bl.id;
  3154. WBUFW(buf,12) = cd->limit;
  3155. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3156. WBUFB(buf,16) = type;
  3157. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3158. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3159. }
  3160. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3161. /// 00d8 <chat id>.L
  3162. void clif_clearchat(struct chat_data *cd,int fd)
  3163. {
  3164. unsigned char buf[32];
  3165. nullpo_retv(cd);
  3166. WBUFW(buf,0) = 0xd8;
  3167. WBUFL(buf,2) = cd->bl.id;
  3168. if( fd ) {
  3169. WFIFOHEAD(fd,packet_len(0xd8));
  3170. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3171. WFIFOSET(fd,packet_len(0xd8));
  3172. } else {
  3173. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3174. }
  3175. }
  3176. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3177. /// 00da <result>.B
  3178. /// result:
  3179. /// 0 = room full
  3180. /// 1 = wrong password
  3181. /// 2 = kicked
  3182. /// 3 = success (no message)
  3183. /// 4 = no enough zeny
  3184. /// 5 = too low level
  3185. /// 6 = too high level
  3186. /// 7 = unsuitable job class
  3187. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3188. {
  3189. int fd;
  3190. nullpo_retv(sd);
  3191. fd = sd->fd;
  3192. WFIFOHEAD(fd,packet_len(0xda));
  3193. WFIFOW(fd,0) = 0xda;
  3194. WFIFOB(fd,2) = flag;
  3195. WFIFOSET(fd,packet_len(0xda));
  3196. }
  3197. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3198. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3199. /// role:
  3200. /// 0 = owner (menu)
  3201. /// 1 = normal
  3202. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3203. {
  3204. int fd;
  3205. int i,t;
  3206. nullpo_retv(sd);
  3207. nullpo_retv(cd);
  3208. fd = sd->fd;
  3209. if (!session_isActive(fd))
  3210. return;
  3211. t = (int)(cd->owner->type == BL_NPC);
  3212. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3213. WFIFOW(fd, 0) = 0xdb;
  3214. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3215. WFIFOL(fd, 4) = cd->bl.id;
  3216. if(cd->owner->type == BL_NPC){
  3217. WFIFOL(fd, 30) = 1;
  3218. WFIFOL(fd, 8) = 0;
  3219. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3220. for (i = 0; i < cd->users; i++) {
  3221. WFIFOL(fd, 8+(i+1)*28) = 1;
  3222. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3223. }
  3224. } else
  3225. for (i = 0; i < cd->users; i++) {
  3226. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3227. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3228. }
  3229. WFIFOSET(fd, WFIFOW(fd, 2));
  3230. }
  3231. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3232. /// 00dc <users>.W <name>.24B
  3233. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3234. {
  3235. unsigned char buf[32];
  3236. nullpo_retv(sd);
  3237. nullpo_retv(cd);
  3238. WBUFW(buf, 0) = 0xdc;
  3239. WBUFW(buf, 2) = cd->users;
  3240. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3241. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3242. }
  3243. /// Announce the new owner (ZC_ROLE_CHANGE).
  3244. /// 00e1 <role>.L <nick>.24B
  3245. /// role:
  3246. /// 0 = owner (menu)
  3247. /// 1 = normal
  3248. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3249. {
  3250. unsigned char buf[64];
  3251. nullpo_retv(sd);
  3252. nullpo_retv(cd);
  3253. WBUFW(buf, 0) = 0xe1;
  3254. WBUFL(buf, 2) = 1;
  3255. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3256. WBUFW(buf,30) = 0xe1;
  3257. WBUFL(buf,32) = 0;
  3258. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3259. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3260. }
  3261. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3262. /// 00dd <users>.W <nick>.24B <flag>.B
  3263. /// flag:
  3264. /// 0 = left
  3265. /// 1 = kicked
  3266. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3267. {
  3268. unsigned char buf[32];
  3269. nullpo_retv(sd);
  3270. nullpo_retv(cd);
  3271. WBUFW(buf, 0) = 0xdd;
  3272. WBUFW(buf, 2) = cd->users-1;
  3273. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3274. WBUFB(buf,28) = flag;
  3275. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3276. }
  3277. /// Opens a trade request window from char 'name'.
  3278. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3279. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3280. void clif_traderequest(struct map_session_data* sd, const char* name)
  3281. {
  3282. int fd = sd->fd;
  3283. #if PACKETVER < 6
  3284. WFIFOHEAD(fd,packet_len(0xe5));
  3285. WFIFOW(fd,0) = 0xe5;
  3286. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3287. WFIFOSET(fd,packet_len(0xe5));
  3288. #else
  3289. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3290. if( !tsd ) return;
  3291. WFIFOHEAD(fd,packet_len(0x1f4));
  3292. WFIFOW(fd,0) = 0x1f4;
  3293. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3294. WFIFOL(fd,26) = tsd->status.char_id;
  3295. WFIFOW(fd,30) = tsd->status.base_level;
  3296. WFIFOSET(fd,packet_len(0x1f4));
  3297. #endif
  3298. }
  3299. /// Reply to a trade-request.
  3300. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3301. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3302. /// result:
  3303. /// 0 = Char is too far
  3304. /// 1 = Character does not exist
  3305. /// 2 = Trade failed
  3306. /// 3 = Accept
  3307. /// 4 = Cancel
  3308. /// 5 = Busy
  3309. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3310. {
  3311. int fd = sd->fd;
  3312. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3313. if( PACKETVER < 6 || !tsd ) {
  3314. WFIFOHEAD(fd,packet_len(0xe7));
  3315. WFIFOW(fd,0) = 0xe7;
  3316. WFIFOB(fd,2) = type;
  3317. WFIFOSET(fd,packet_len(0xe7));
  3318. } else {
  3319. WFIFOHEAD(fd,packet_len(0x1f5));
  3320. WFIFOW(fd,0) = 0x1f5;
  3321. WFIFOB(fd,2) = type;
  3322. WFIFOL(fd,3) = tsd->status.char_id;
  3323. WFIFOW(fd,7) = tsd->status.base_level;
  3324. WFIFOSET(fd,packet_len(0x1f5));
  3325. }
  3326. }
  3327. /// Notifies the client about an item from other player in current trade.
  3328. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3329. /// 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)
  3330. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3331. {
  3332. int fd;
  3333. unsigned char *buf;
  3334. #if PACKETVER < 20100223
  3335. const int cmd = 0xe9;
  3336. #else
  3337. const int cmd = 0x80f;
  3338. #endif
  3339. nullpo_retv(sd);
  3340. nullpo_retv(tsd);
  3341. fd = tsd->fd;
  3342. buf = WFIFOP(fd,0);
  3343. WFIFOHEAD(fd,packet_len(cmd));
  3344. WBUFW(buf,0) = cmd;
  3345. if( index == 0 )
  3346. {
  3347. #if PACKETVER < 20100223
  3348. WBUFL(buf,2) = amount; //amount
  3349. WBUFW(buf,6) = 0; // type id
  3350. #else
  3351. WBUFW(buf,2) = 0; // type id
  3352. WBUFB(buf,4) = 0; // item type
  3353. WBUFL(buf,5) = amount; // amount
  3354. buf = WBUFP(buf,1); //Advance 1B
  3355. #endif
  3356. WBUFB(buf,8) = 0; //identify flag
  3357. WBUFB(buf,9) = 0; // attribute
  3358. WBUFB(buf,10)= 0; //refine
  3359. WBUFW(buf,11)= 0; //card (4w)
  3360. WBUFW(buf,13)= 0; //card (4w)
  3361. WBUFW(buf,15)= 0; //card (4w)
  3362. WBUFW(buf,17)= 0; //card (4w)
  3363. }
  3364. else
  3365. {
  3366. index -= 2; //index fix
  3367. #if PACKETVER < 20100223
  3368. WBUFL(buf,2) = amount; //amount
  3369. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3370. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3371. else
  3372. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3373. #else
  3374. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3375. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3376. else
  3377. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3378. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3379. WBUFL(buf,5) = amount; // amount
  3380. buf = WBUFP(buf,1); //Advance 1B
  3381. #endif
  3382. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3383. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3384. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3385. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3386. }
  3387. WFIFOSET(fd,packet_len(cmd));
  3388. }
  3389. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3390. /// 00ea <index>.W <result>.B
  3391. /// result:
  3392. /// 0 = success
  3393. /// 1 = overweight
  3394. /// 2 = trade canceled
  3395. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3396. {
  3397. int fd;
  3398. nullpo_retv(sd);
  3399. fd = sd->fd;
  3400. WFIFOHEAD(fd,packet_len(0xea));
  3401. WFIFOW(fd,0) = 0xea;
  3402. WFIFOW(fd,2) = index;
  3403. WFIFOB(fd,4) = fail;
  3404. WFIFOSET(fd,packet_len(0xea));
  3405. }
  3406. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3407. /// 00ec <who>.B
  3408. /// who:
  3409. /// 0 = self
  3410. /// 1 = other player
  3411. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3412. {
  3413. int fd;
  3414. nullpo_retv(sd);
  3415. fd = sd->fd;
  3416. WFIFOHEAD(fd,packet_len(0xec));
  3417. WFIFOW(fd,0) = 0xec;
  3418. WFIFOB(fd,2) = fail;
  3419. WFIFOSET(fd,packet_len(0xec));
  3420. }
  3421. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3422. /// 00ee
  3423. void clif_tradecancelled(struct map_session_data* sd)
  3424. {
  3425. int fd;
  3426. nullpo_retv(sd);
  3427. fd = sd->fd;
  3428. WFIFOHEAD(fd,packet_len(0xee));
  3429. WFIFOW(fd,0) = 0xee;
  3430. WFIFOSET(fd,packet_len(0xee));
  3431. }
  3432. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3433. /// 00f0 <result>.B
  3434. /// result:
  3435. /// 0 = success
  3436. /// 1 = failure
  3437. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3438. {
  3439. int fd;
  3440. nullpo_retv(sd);
  3441. fd = sd->fd;
  3442. WFIFOHEAD(fd,packet_len(0xf0));
  3443. WFIFOW(fd,0) = 0xf0;
  3444. WFIFOB(fd,2) = fail;
  3445. WFIFOSET(fd,packet_len(0xf0));
  3446. }
  3447. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3448. /// 00f1
  3449. /// NOTE: Unknown purpose. Items are not removed until the window is
  3450. /// refreshed (ex. by putting another item in there).
  3451. void clif_tradeundo(struct map_session_data* sd)
  3452. {
  3453. int fd = sd->fd;
  3454. WFIFOHEAD(fd,packet_len(0xf1));
  3455. WFIFOW(fd,0) = 0xf1;
  3456. WFIFOSET(fd,packet_len(0xf1));
  3457. }
  3458. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3459. /// 00f2 <current count>.W <max count>.W
  3460. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3461. {
  3462. int fd;
  3463. nullpo_retv(sd);
  3464. fd=sd->fd;
  3465. WFIFOHEAD(fd,packet_len(0xf2));
  3466. WFIFOW(fd,0) = 0xf2;
  3467. WFIFOW(fd,2) = amount;
  3468. WFIFOW(fd,4) = max_amount;
  3469. WFIFOSET(fd,packet_len(0xf2));
  3470. }
  3471. /// Notifies the client of an item being added to the storage.
  3472. /// 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)
  3473. /// 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)
  3474. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3475. {
  3476. int view,fd;
  3477. nullpo_retv(sd);
  3478. nullpo_retv(i);
  3479. fd=sd->fd;
  3480. view = itemdb_viewid(i->nameid);
  3481. #if PACKETVER < 5
  3482. WFIFOHEAD(fd,packet_len(0xf4));
  3483. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3484. WFIFOW(fd, 2) = index+1; // index
  3485. WFIFOL(fd, 4) = amount; // amount
  3486. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3487. WFIFOB(fd,10) = i->identify; //identify flag
  3488. WFIFOB(fd,11) = i->attribute; // attribute
  3489. WFIFOB(fd,12) = i->refine; //refine
  3490. clif_addcards(WFIFOP(fd,13), i);
  3491. WFIFOSET(fd,packet_len(0xf4));
  3492. #else
  3493. WFIFOHEAD(fd,packet_len(0x1c4));
  3494. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3495. WFIFOW(fd, 2) = index+1; // index
  3496. WFIFOL(fd, 4) = amount; // amount
  3497. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3498. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3499. WFIFOB(fd,11) = i->identify; //identify flag
  3500. WFIFOB(fd,12) = i->attribute; // attribute
  3501. WFIFOB(fd,13) = i->refine; //refine
  3502. clif_addcards(WFIFOP(fd,14), i);
  3503. WFIFOSET(fd,packet_len(0x1c4));
  3504. #endif
  3505. }
  3506. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3507. /// 00f6 <index>.W <amount>.L
  3508. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3509. {
  3510. int fd;
  3511. nullpo_retv(sd);
  3512. fd=sd->fd;
  3513. WFIFOHEAD(fd,packet_len(0xf6));
  3514. WFIFOW(fd,0)=0xf6; // Storage item removed
  3515. WFIFOW(fd,2)=index+1;
  3516. WFIFOL(fd,4)=amount;
  3517. WFIFOSET(fd,packet_len(0xf6));
  3518. }
  3519. /// Closes storage (ZC_CLOSE_STORE).
  3520. /// 00f8
  3521. void clif_storageclose(struct map_session_data* sd)
  3522. {
  3523. int fd;
  3524. nullpo_retv(sd);
  3525. fd=sd->fd;
  3526. WFIFOHEAD(fd,packet_len(0xf8));
  3527. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3528. WFIFOSET(fd,packet_len(0xf8));
  3529. }
  3530. /*==========================================
  3531. * Server tells 'sd' player client the abouts of 'dstsd' player
  3532. *------------------------------------------*/
  3533. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3534. {
  3535. struct block_list *d_bl;
  3536. int i;
  3537. if( dstsd->chatID ) {
  3538. struct chat_data *cd = NULL;
  3539. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3540. clif_dispchat(cd,sd->fd);
  3541. } else if( dstsd->state.vending )
  3542. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3543. else if( dstsd->state.buyingstore )
  3544. clif_buyingstore_entry_single(sd, dstsd);
  3545. if(dstsd->spiritball > 0)
  3546. clif_spiritball_single(sd->fd, dstsd);
  3547. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3548. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3549. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3550. }
  3551. #ifdef NEW_CARTS
  3552. if( dstsd->sc.data[SC_PUSH_CART] )
  3553. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3554. #endif
  3555. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3556. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3557. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3558. )
  3559. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3560. // display link (sd - dstsd) to sd
  3561. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3562. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3563. // display links (dstsd - devotees) to sd
  3564. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3565. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3566. // display link (dstsd - crusader) to sd
  3567. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3568. clif_devotion(d_bl, sd);
  3569. }
  3570. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3571. {
  3572. uint8 buf[128];
  3573. struct unit_data *ud;
  3574. struct view_data *vd;
  3575. int len;
  3576. vd = status_get_viewdata(bl);
  3577. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3578. return;
  3579. /**
  3580. * Hide NPC from maya purple card.
  3581. **/
  3582. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3583. return;
  3584. ud = unit_bl2ud(bl);
  3585. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3586. clif_send(buf,len,&sd->bl,SELF);
  3587. if (vd->cloth_color)
  3588. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3589. switch (bl->type)
  3590. {
  3591. case BL_PC:
  3592. {
  3593. TBL_PC* tsd = (TBL_PC*)bl;
  3594. clif_getareachar_pc(sd, tsd);
  3595. if(tsd->state.size==2) // tiny/big players [Valaris]
  3596. clif_specialeffect_single(bl,423,sd->fd);
  3597. else if(tsd->state.size==1)
  3598. clif_specialeffect_single(bl,421,sd->fd);
  3599. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3600. clif_sendbgemblem_single(sd->fd,tsd);
  3601. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3602. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3603. }
  3604. break;
  3605. case BL_MER: // Devotion Effects
  3606. if( ((TBL_MER*)bl)->devotion_flag )
  3607. clif_devotion(bl, sd);
  3608. break;
  3609. case BL_NPC:
  3610. {
  3611. TBL_NPC* nd = (TBL_NPC*)bl;
  3612. if( nd->chat_id )
  3613. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3614. if( nd->size == SZ_BIG )
  3615. clif_specialeffect_single(bl,423,sd->fd);
  3616. else if( nd->size == SZ_MEDIUM )
  3617. clif_specialeffect_single(bl,421,sd->fd);
  3618. }
  3619. break;
  3620. case BL_MOB:
  3621. {
  3622. TBL_MOB* md = (TBL_MOB*)bl;
  3623. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3624. clif_specialeffect_single(bl,423,sd->fd);
  3625. else if(md->special_state.size==SZ_MEDIUM)
  3626. clif_specialeffect_single(bl,421,sd->fd);
  3627. }
  3628. break;
  3629. case BL_PET:
  3630. if (vd->head_bottom)
  3631. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3632. break;
  3633. }
  3634. }
  3635. //Modifies the type of damage according to status changes [Skotlex]
  3636. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3637. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3638. {
  3639. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3640. }
  3641. /*==========================================
  3642. * Estimates walk delay based on the damage criteria. [Skotlex]
  3643. *------------------------------------------*/
  3644. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3645. {
  3646. if (type == 4 || type == 9 || damage <=0)
  3647. return 0;
  3648. if (bl->type == BL_PC) {
  3649. if (battle_config.pc_walk_delay_rate != 100)
  3650. delay = delay*battle_config.pc_walk_delay_rate/100;
  3651. } else
  3652. if (battle_config.walk_delay_rate != 100)
  3653. delay = delay*battle_config.walk_delay_rate/100;
  3654. if (div_ > 1) //Multi-hit skills mean higher delays.
  3655. delay += battle_config.multihit_delay*(div_-1);
  3656. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3657. }
  3658. /// Sends a 'damage' packet (src performs action on dst)
  3659. /// 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)
  3660. /// 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)
  3661. /// type:
  3662. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3663. /// 1 = pick up item
  3664. /// 2 = sit down
  3665. /// 3 = stand up
  3666. /// 4 = damage (endure)
  3667. /// 5 = (splash?)
  3668. /// 6 = (skill?)
  3669. /// 7 = (repeat damage?)
  3670. /// 8 = multi-hit damage
  3671. /// 9 = multi-hit damage (endure)
  3672. /// 10 = critical hit
  3673. /// 11 = lucky dodge
  3674. /// 12 = (touch skill?)
  3675. 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)
  3676. {
  3677. unsigned char buf[33];
  3678. struct status_change *sc;
  3679. #if PACKETVER < 20071113
  3680. const int cmd = 0x8a;
  3681. #else
  3682. const int cmd = 0x2e1;
  3683. #endif
  3684. nullpo_ret(src);
  3685. nullpo_ret(dst);
  3686. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3687. sc = status_get_sc(dst);
  3688. if(sc && sc->count) {
  3689. if(sc->data[SC_HALLUCINATION]) {
  3690. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3691. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3692. }
  3693. }
  3694. WBUFW(buf,0)=cmd;
  3695. WBUFL(buf,2)=src->id;
  3696. WBUFL(buf,6)=dst->id;
  3697. WBUFL(buf,10)=tick;
  3698. WBUFL(buf,14)=sdelay;
  3699. WBUFL(buf,18)=ddelay;
  3700. #if PACKETVER < 20071113
  3701. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3702. WBUFW(buf,22)=damage?div:0;
  3703. WBUFW(buf,27)=damage2?div:0;
  3704. } else {
  3705. WBUFW(buf,22)=min(damage, INT16_MAX);
  3706. WBUFW(buf,27)=damage2;
  3707. }
  3708. WBUFW(buf,24)=div;
  3709. WBUFB(buf,26)=type;
  3710. #else
  3711. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3712. WBUFL(buf,22)=damage?div:0;
  3713. WBUFL(buf,29)=damage2?div:0;
  3714. } else {
  3715. WBUFL(buf,22)=damage;
  3716. WBUFL(buf,29)=damage2;
  3717. }
  3718. WBUFW(buf,26)=div;
  3719. WBUFB(buf,28)=type;
  3720. #endif
  3721. if(disguised(dst)) {
  3722. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3723. WBUFL(buf,6) = -dst->id;
  3724. clif_send(buf,packet_len(cmd),dst,SELF);
  3725. } else
  3726. clif_send(buf,packet_len(cmd),dst,AREA);
  3727. if(disguised(src)) {
  3728. WBUFL(buf,2) = -src->id;
  3729. if (disguised(dst))
  3730. WBUFL(buf,6) = dst->id;
  3731. #if PACKETVER < 20071113
  3732. if(damage > 0) WBUFW(buf,22) = -1;
  3733. if(damage2 > 0) WBUFW(buf,27) = -1;
  3734. #else
  3735. if(damage > 0) WBUFL(buf,22) = -1;
  3736. if(damage2 > 0) WBUFL(buf,29) = -1;
  3737. #endif
  3738. clif_send(buf,packet_len(cmd),src,SELF);
  3739. }
  3740. if(src == dst) {
  3741. unit_setdir(src,unit_getdir(src));
  3742. }
  3743. //Return adjusted can't walk delay for further processing.
  3744. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3745. }
  3746. /*==========================================
  3747. * src picks up dst
  3748. *------------------------------------------*/
  3749. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3750. {
  3751. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3752. unsigned char buf[32];
  3753. nullpo_retv(src);
  3754. nullpo_retv(dst);
  3755. WBUFW(buf, 0) = 0x8a;
  3756. WBUFL(buf, 2) = src->id;
  3757. WBUFL(buf, 6) = dst->id;
  3758. WBUFB(buf,26) = 1;
  3759. clif_send(buf, packet_len(0x8a), src, AREA);
  3760. }
  3761. /*==========================================
  3762. * inform clients in area that `bl` is sitting
  3763. *------------------------------------------*/
  3764. void clif_sitting(struct block_list* bl)
  3765. {
  3766. unsigned char buf[32];
  3767. nullpo_retv(bl);
  3768. WBUFW(buf, 0) = 0x8a;
  3769. WBUFL(buf, 2) = bl->id;
  3770. WBUFB(buf,26) = 2;
  3771. clif_send(buf, packet_len(0x8a), bl, AREA);
  3772. if(disguised(bl)) {
  3773. WBUFL(buf, 2) = - bl->id;
  3774. clif_send(buf, packet_len(0x8a), bl, SELF);
  3775. }
  3776. }
  3777. /*==========================================
  3778. * inform clients in area that `bl` is standing
  3779. *------------------------------------------*/
  3780. void clif_standing(struct block_list* bl)
  3781. {
  3782. unsigned char buf[32];
  3783. nullpo_retv(bl);
  3784. WBUFW(buf, 0) = 0x8a;
  3785. WBUFL(buf, 2) = bl->id;
  3786. WBUFB(buf,26) = 3;
  3787. clif_send(buf, packet_len(0x8a), bl, AREA);
  3788. if(disguised(bl)) {
  3789. WBUFL(buf, 2) = - bl->id;
  3790. clif_send(buf, packet_len(0x8a), bl, SELF);
  3791. }
  3792. }
  3793. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3794. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3795. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3796. {
  3797. unsigned char buf[32];
  3798. WBUFW(buf,0) = 0x192;
  3799. WBUFW(buf,2) = x;
  3800. WBUFW(buf,4) = y;
  3801. WBUFW(buf,6) = type;
  3802. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3803. if( fd )
  3804. {
  3805. WFIFOHEAD(fd,packet_len(0x192));
  3806. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3807. WFIFOSET(fd,packet_len(0x192));
  3808. }
  3809. else
  3810. {
  3811. struct block_list dummy_bl;
  3812. dummy_bl.type = BL_NUL;
  3813. dummy_bl.x = x;
  3814. dummy_bl.y = y;
  3815. dummy_bl.m = m;
  3816. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3817. }
  3818. }
  3819. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3820. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3821. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3822. {
  3823. int view,fd;
  3824. fd=sd->fd;
  3825. WFIFOHEAD(fd,packet_len(0x9d));
  3826. WFIFOW(fd,0)=0x9d;
  3827. WFIFOL(fd,2)=fitem->bl.id;
  3828. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3829. WFIFOW(fd,6)=view;
  3830. else
  3831. WFIFOW(fd,6)=fitem->item_data.nameid;
  3832. WFIFOB(fd,8)=fitem->item_data.identify;
  3833. WFIFOW(fd,9)=fitem->bl.x;
  3834. WFIFOW(fd,11)=fitem->bl.y;
  3835. WFIFOW(fd,13)=fitem->item_data.amount;
  3836. WFIFOB(fd,15)=fitem->subx;
  3837. WFIFOB(fd,16)=fitem->suby;
  3838. WFIFOSET(fd,packet_len(0x9d));
  3839. }
  3840. /// Notifies the client of a skill unit.
  3841. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3842. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3843. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3844. {
  3845. int fd = sd->fd;
  3846. if( unit->group->state.guildaura )
  3847. return;
  3848. #if PACKETVER >= 3
  3849. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3850. WFIFOHEAD(fd,packet_len(0x1c9));
  3851. WFIFOW(fd, 0)=0x1c9;
  3852. WFIFOL(fd, 2)=unit->bl.id;
  3853. WFIFOL(fd, 6)=unit->group->src_id;
  3854. WFIFOW(fd,10)=unit->bl.x;
  3855. WFIFOW(fd,12)=unit->bl.y;
  3856. WFIFOB(fd,14)=unit->group->unit_id;
  3857. WFIFOB(fd,15)=1;
  3858. WFIFOB(fd,16)=1;
  3859. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3860. WFIFOSET(fd,packet_len(0x1c9));
  3861. return;
  3862. }
  3863. #endif
  3864. WFIFOHEAD(fd,packet_len(0x11f));
  3865. WFIFOW(fd, 0)=0x11f;
  3866. WFIFOL(fd, 2)=unit->bl.id;
  3867. WFIFOL(fd, 6)=unit->group->src_id;
  3868. WFIFOW(fd,10)=unit->bl.x;
  3869. WFIFOW(fd,12)=unit->bl.y;
  3870. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3871. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3872. else
  3873. WFIFOB(fd,14)=unit->group->unit_id;
  3874. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3875. WFIFOSET(fd,packet_len(0x11f));
  3876. if(unit->group->skill_id == WZ_ICEWALL)
  3877. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3878. }
  3879. /*==========================================
  3880. * Server tells client to remove unit of id 'unit->bl.id'
  3881. *------------------------------------------*/
  3882. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3883. {
  3884. nullpo_retv(unit);
  3885. WFIFOHEAD(fd,packet_len(0x120));
  3886. WFIFOW(fd, 0)=0x120;
  3887. WFIFOL(fd, 2)=unit->bl.id;
  3888. WFIFOSET(fd,packet_len(0x120));
  3889. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3890. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3891. }
  3892. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3893. /// 0120 <id>.L
  3894. void clif_skill_delunit(struct skill_unit *unit)
  3895. {
  3896. unsigned char buf[16];
  3897. nullpo_retv(unit);
  3898. WBUFW(buf, 0)=0x120;
  3899. WBUFL(buf, 2)=unit->bl.id;
  3900. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3901. }
  3902. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3903. /// 01ac <id>.L
  3904. /// Only affects units with class [139,153] client-side.
  3905. void clif_skillunit_update(struct block_list* bl)
  3906. {
  3907. unsigned char buf[6];
  3908. nullpo_retv(bl);
  3909. WBUFW(buf,0) = 0x1ac;
  3910. WBUFL(buf,2) = bl->id;
  3911. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3912. }
  3913. /*==========================================
  3914. *
  3915. *------------------------------------------*/
  3916. static int clif_getareachar(struct block_list* bl,va_list ap)
  3917. {
  3918. struct map_session_data *sd;
  3919. nullpo_ret(bl);
  3920. sd=va_arg(ap,struct map_session_data*);
  3921. if (sd == NULL || !sd->fd)
  3922. return 0;
  3923. switch(bl->type){
  3924. case BL_ITEM:
  3925. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3926. break;
  3927. case BL_SKILL:
  3928. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3929. break;
  3930. default:
  3931. if(&sd->bl == bl)
  3932. break;
  3933. clif_getareachar_unit(sd,bl);
  3934. break;
  3935. }
  3936. return 0;
  3937. }
  3938. /*==========================================
  3939. * tbl has gone out of view-size of bl
  3940. *------------------------------------------*/
  3941. int clif_outsight(struct block_list *bl,va_list ap)
  3942. {
  3943. struct block_list *tbl;
  3944. struct view_data *vd;
  3945. TBL_PC *sd, *tsd;
  3946. tbl=va_arg(ap,struct block_list*);
  3947. if(bl == tbl) return 0;
  3948. sd = BL_CAST(BL_PC, bl);
  3949. tsd = BL_CAST(BL_PC, tbl);
  3950. if (tsd && tsd->fd)
  3951. { //tsd has lost sight of the bl object.
  3952. switch(bl->type){
  3953. case BL_PC:
  3954. if (sd->vd.class_ != INVISIBLE_CLASS)
  3955. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3956. if(sd->chatID){
  3957. struct chat_data *cd;
  3958. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3959. if(cd->usersd[0]==sd)
  3960. clif_dispchat(cd,tsd->fd);
  3961. }
  3962. if( sd->state.vending )
  3963. clif_closevendingboard(bl,tsd->fd);
  3964. if( sd->state.buyingstore )
  3965. clif_buyingstore_disappear_entry_single(tsd, sd);
  3966. break;
  3967. case BL_ITEM:
  3968. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3969. break;
  3970. case BL_SKILL:
  3971. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3972. break;
  3973. case BL_NPC:
  3974. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  3975. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3976. break;
  3977. default:
  3978. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3979. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3980. break;
  3981. }
  3982. }
  3983. if (sd && sd->fd)
  3984. { //sd is watching tbl go out of view.
  3985. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  3986. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  3987. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3988. }
  3989. return 0;
  3990. }
  3991. /*==========================================
  3992. * tbl has come into view of bl
  3993. *------------------------------------------*/
  3994. int clif_insight(struct block_list *bl,va_list ap)
  3995. {
  3996. struct block_list *tbl;
  3997. TBL_PC *sd, *tsd;
  3998. tbl=va_arg(ap,struct block_list*);
  3999. if (bl == tbl) return 0;
  4000. sd = BL_CAST(BL_PC, bl);
  4001. tsd = BL_CAST(BL_PC, tbl);
  4002. if (tsd && tsd->fd)
  4003. { //Tell tsd that bl entered into his view
  4004. switch(bl->type){
  4005. case BL_ITEM:
  4006. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4007. break;
  4008. case BL_SKILL:
  4009. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  4010. break;
  4011. default:
  4012. clif_getareachar_unit(tsd,bl);
  4013. break;
  4014. }
  4015. }
  4016. if (sd && sd->fd)
  4017. { //Tell sd that tbl walked into his view
  4018. clif_getareachar_unit(sd,tbl);
  4019. }
  4020. return 0;
  4021. }
  4022. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4023. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4024. void clif_skillinfoblock(struct map_session_data *sd)
  4025. {
  4026. int fd;
  4027. int i,len,id;
  4028. nullpo_retv(sd);
  4029. fd=sd->fd;
  4030. if (!fd) return;
  4031. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4032. WFIFOW(fd,0) = 0x10f;
  4033. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4034. {
  4035. if( (id = sd->status.skill[i].id) != 0 )
  4036. {
  4037. // workaround for bugreport:5348
  4038. if (len + 37 > 8192)
  4039. break;
  4040. WFIFOW(fd,len) = id;
  4041. WFIFOL(fd,len+2) = skill_get_inf(id);
  4042. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4043. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4044. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4045. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4046. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4047. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4048. else
  4049. WFIFOB(fd,len+36) = 0;
  4050. len += 37;
  4051. }
  4052. }
  4053. WFIFOW(fd,2)=len;
  4054. WFIFOSET(fd,len);
  4055. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4056. for ( ; i < MAX_SKILL; i++)
  4057. {
  4058. if( (id = sd->status.skill[i].id) != 0 )
  4059. {
  4060. clif_addskill(sd, id);
  4061. clif_skillinfo(sd, id, 0);
  4062. }
  4063. }
  4064. }
  4065. /**
  4066. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4067. **/
  4068. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4069. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4070. void clif_addskill(struct map_session_data *sd, int id)
  4071. {
  4072. int fd;
  4073. nullpo_retv(sd);
  4074. fd = sd->fd;
  4075. if (!fd) return;
  4076. if( sd->status.skill[id].id <= 0 )
  4077. return;
  4078. WFIFOHEAD(fd, packet_len(0x111));
  4079. WFIFOW(fd,0) = 0x111;
  4080. WFIFOW(fd,2) = id;
  4081. WFIFOL(fd,4) = skill_get_inf(id);
  4082. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4083. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4084. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4085. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4086. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4087. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4088. else
  4089. WFIFOB(fd,38) = 0;
  4090. WFIFOSET(fd,packet_len(0x111));
  4091. }
  4092. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4093. /// 0441 <skill id>.W
  4094. void clif_deleteskill(struct map_session_data *sd, int id)
  4095. {
  4096. #if PACKETVER >= 20081217
  4097. int fd;
  4098. nullpo_retv(sd);
  4099. fd = sd->fd;
  4100. if( !fd ) return;
  4101. WFIFOHEAD(fd,packet_len(0x441));
  4102. WFIFOW(fd,0) = 0x441;
  4103. WFIFOW(fd,2) = id;
  4104. WFIFOSET(fd,packet_len(0x441));
  4105. #else
  4106. clif_skillinfoblock(sd);
  4107. #endif
  4108. }
  4109. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4110. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4111. void clif_skillup(struct map_session_data *sd,int skill_num)
  4112. {
  4113. int fd;
  4114. nullpo_retv(sd);
  4115. fd=sd->fd;
  4116. WFIFOHEAD(fd,packet_len(0x10e));
  4117. WFIFOW(fd,0) = 0x10e;
  4118. WFIFOW(fd,2) = skill_num;
  4119. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  4120. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  4121. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  4122. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  4123. WFIFOSET(fd,packet_len(0x10e));
  4124. }
  4125. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4126. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4127. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4128. {
  4129. const int fd = sd->fd;
  4130. WFIFOHEAD(fd,packet_len(0x7e1));
  4131. WFIFOW(fd,0) = 0x7e1;
  4132. WFIFOW(fd,2) = skill;
  4133. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4134. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4135. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4136. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4137. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4138. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4139. else
  4140. WFIFOB(fd,14) = 0;
  4141. WFIFOSET(fd,packet_len(0x7e1));
  4142. }
  4143. /// Notifies clients in area, that an object is about to use a skill.
  4144. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4145. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4146. /// property:
  4147. /// 0 = Yellow cast aura
  4148. /// 1 = Water elemental cast aura
  4149. /// 2 = Earth elemental cast aura
  4150. /// 3 = Fire elemental cast aura
  4151. /// 4 = Wind elemental cast aura
  4152. /// 5 = Poison elemental cast aura
  4153. /// 6 = Holy elemental cast aura
  4154. /// ? = like 0
  4155. /// is disposable:
  4156. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4157. /// 1 = no text
  4158. 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)
  4159. {
  4160. #if PACKETVER < 20091124
  4161. const int cmd = 0x13e;
  4162. #else
  4163. const int cmd = 0x7fb;
  4164. #endif
  4165. unsigned char buf[32];
  4166. WBUFW(buf,0) = cmd;
  4167. WBUFL(buf,2) = src_id;
  4168. WBUFL(buf,6) = dst_id;
  4169. WBUFW(buf,10) = dst_x;
  4170. WBUFW(buf,12) = dst_y;
  4171. WBUFW(buf,14) = skill_num;
  4172. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4173. WBUFL(buf,20) = casttime;
  4174. #if PACKETVER >= 20091124
  4175. WBUFB(buf,24) = 0; // isDisposable
  4176. #endif
  4177. if (disguised(bl)) {
  4178. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4179. WBUFL(buf,2) = -src_id;
  4180. clif_send(buf,packet_len(cmd), bl, SELF);
  4181. } else
  4182. clif_send(buf,packet_len(cmd), bl, AREA);
  4183. }
  4184. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4185. /// 01b9 <id>.L
  4186. void clif_skillcastcancel(struct block_list* bl)
  4187. {
  4188. unsigned char buf[16];
  4189. nullpo_retv(bl);
  4190. WBUFW(buf,0) = 0x1b9;
  4191. WBUFL(buf,2) = bl->id;
  4192. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4193. }
  4194. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4195. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4196. /// num (only used when skill id = NV_BASIC and cause = 0):
  4197. /// 0 = "skill failed" MsgStringTable[159]
  4198. /// 1 = "no emotions" MsgStringTable[160]
  4199. /// 2 = "no sit" MsgStringTable[161]
  4200. /// 3 = "no chat" MsgStringTable[162]
  4201. /// 4 = "no party" MsgStringTable[163]
  4202. /// 5 = "no shout" MsgStringTable[164]
  4203. /// 6 = "no PKing" MsgStringTable[165]
  4204. /// 7 = "no alligning" MsgStringTable[383]
  4205. /// ? = ignored
  4206. /// cause:
  4207. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4208. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4209. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4210. /// "skill failed" MsgStringTable[204] (otherwise)
  4211. /// ... = @see enum useskill_fail_cause
  4212. /// ? = ignored
  4213. ///
  4214. /// if(result!=0) doesn't display any of the previous messages
  4215. /// Note: when this packet is received an unknown flag is always set to 0,
  4216. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4217. void clif_skill_fail(struct map_session_data *sd,int skill_id,enum useskill_fail_cause cause,int btype)
  4218. {
  4219. int fd;
  4220. if (!sd) { //Since this is the most common nullpo....
  4221. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4222. return;
  4223. }
  4224. fd=sd->fd;
  4225. if (!fd) return;
  4226. if(battle_config.display_skill_fail&1)
  4227. return; //Disable all skill failed messages
  4228. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4229. return; //Disable delay failed messages
  4230. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4231. return;
  4232. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4233. return;
  4234. WFIFOHEAD(fd,packet_len(0x110));
  4235. WFIFOW(fd,0) = 0x110;
  4236. WFIFOW(fd,2) = skill_id;
  4237. WFIFOL(fd,4) = btype;
  4238. WFIFOB(fd,8) = 0;// success
  4239. WFIFOB(fd,9) = cause;
  4240. WFIFOSET(fd,packet_len(0x110));
  4241. }
  4242. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4243. /// 043d <skill ID>.W <tick>.L
  4244. void clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  4245. {
  4246. #if PACKETVER>=20081112
  4247. int fd;
  4248. nullpo_retv(sd);
  4249. fd=sd->fd;
  4250. WFIFOHEAD(fd,packet_len(0x43d));
  4251. WFIFOW(fd,0) = 0x43d;
  4252. WFIFOW(fd,2) = skillid;
  4253. WFIFOL(fd,4) = tick;
  4254. WFIFOSET(fd,packet_len(0x43d));
  4255. #endif
  4256. }
  4257. /// Skill attack effect and damage.
  4258. /// 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)
  4259. /// 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)
  4260. 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)
  4261. {
  4262. unsigned char buf[64];
  4263. struct status_change *sc;
  4264. nullpo_ret(src);
  4265. nullpo_ret(dst);
  4266. type = clif_calc_delay(type,div,damage,ddelay);
  4267. sc = status_get_sc(dst);
  4268. if(sc && sc->count) {
  4269. if(sc->data[SC_HALLUCINATION] && damage)
  4270. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4271. }
  4272. #if PACKETVER < 3
  4273. WBUFW(buf,0)=0x114;
  4274. WBUFW(buf,2)=skill_id;
  4275. WBUFL(buf,4)=src->id;
  4276. WBUFL(buf,8)=dst->id;
  4277. WBUFL(buf,12)=tick;
  4278. WBUFL(buf,16)=sdelay;
  4279. WBUFL(buf,20)=ddelay;
  4280. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4281. WBUFW(buf,24)=damage?div:0;
  4282. } else {
  4283. WBUFW(buf,24)=damage;
  4284. }
  4285. WBUFW(buf,26)=skill_lv;
  4286. WBUFW(buf,28)=div;
  4287. WBUFB(buf,30)=type;
  4288. if (disguised(dst)) {
  4289. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4290. WBUFL(buf,8)=-dst->id;
  4291. clif_send(buf,packet_len(0x114),dst,SELF);
  4292. } else
  4293. clif_send(buf,packet_len(0x114),dst,AREA);
  4294. if(disguised(src)) {
  4295. WBUFL(buf,4)=-src->id;
  4296. if (disguised(dst))
  4297. WBUFL(buf,8)=dst->id;
  4298. if(damage > 0)
  4299. WBUFW(buf,24)=-1;
  4300. clif_send(buf,packet_len(0x114),src,SELF);
  4301. }
  4302. #else
  4303. WBUFW(buf,0)=0x1de;
  4304. WBUFW(buf,2)=skill_id;
  4305. WBUFL(buf,4)=src->id;
  4306. WBUFL(buf,8)=dst->id;
  4307. WBUFL(buf,12)=tick;
  4308. WBUFL(buf,16)=sdelay;
  4309. WBUFL(buf,20)=ddelay;
  4310. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4311. WBUFL(buf,24)=damage?div:0;
  4312. } else {
  4313. WBUFL(buf,24)=damage;
  4314. }
  4315. WBUFW(buf,28)=skill_lv;
  4316. WBUFW(buf,30)=div;
  4317. WBUFB(buf,32)=type;
  4318. if (disguised(dst)) {
  4319. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4320. WBUFL(buf,8)=-dst->id;
  4321. clif_send(buf,packet_len(0x1de),dst,SELF);
  4322. } else
  4323. clif_send(buf,packet_len(0x1de),dst,AREA);
  4324. if(disguised(src)) {
  4325. WBUFL(buf,4)=-src->id;
  4326. if (disguised(dst))
  4327. WBUFL(buf,8)=dst->id;
  4328. if(damage > 0)
  4329. WBUFL(buf,24)=-1;
  4330. clif_send(buf,packet_len(0x1de),src,SELF);
  4331. }
  4332. #endif
  4333. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4334. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4335. }
  4336. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4337. /// 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
  4338. /*
  4339. 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)
  4340. {
  4341. unsigned char buf[64];
  4342. struct status_change *sc;
  4343. nullpo_ret(src);
  4344. nullpo_ret(dst);
  4345. type = (type>0)?type:skill_get_hit(skill_id);
  4346. type = clif_calc_delay(type,div,damage,ddelay);
  4347. sc = status_get_sc(dst);
  4348. if(sc && sc->count) {
  4349. if(sc->data[SC_HALLUCINATION] && damage)
  4350. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4351. }
  4352. WBUFW(buf,0)=0x115;
  4353. WBUFW(buf,2)=skill_id;
  4354. WBUFL(buf,4)=src->id;
  4355. WBUFL(buf,8)=dst->id;
  4356. WBUFL(buf,12)=tick;
  4357. WBUFL(buf,16)=sdelay;
  4358. WBUFL(buf,20)=ddelay;
  4359. WBUFW(buf,24)=dst->x;
  4360. WBUFW(buf,26)=dst->y;
  4361. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4362. WBUFW(buf,28)=damage?div:0;
  4363. } else {
  4364. WBUFW(buf,28)=damage;
  4365. }
  4366. WBUFW(buf,30)=skill_lv;
  4367. WBUFW(buf,32)=div;
  4368. WBUFB(buf,34)=type;
  4369. clif_send(buf,packet_len(0x115),src,AREA);
  4370. if(disguised(src)) {
  4371. WBUFL(buf,4)=-src->id;
  4372. if(damage > 0)
  4373. WBUFW(buf,28)=-1;
  4374. clif_send(buf,packet_len(0x115),src,SELF);
  4375. }
  4376. if (disguised(dst)) {
  4377. WBUFL(buf,8)=-dst->id;
  4378. if (disguised(src))
  4379. WBUFL(buf,4)=src->id;
  4380. else if(damage > 0)
  4381. WBUFW(buf,28)=-1;
  4382. clif_send(buf,packet_len(0x115),dst,SELF);
  4383. }
  4384. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4385. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4386. }
  4387. */
  4388. /// Non-damaging skill effect (ZC_USE_SKILL).
  4389. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4390. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  4391. {
  4392. unsigned char buf[32];
  4393. nullpo_ret(dst);
  4394. WBUFW(buf,0)=0x11a;
  4395. WBUFW(buf,2)=skill_id;
  4396. WBUFW(buf,4)=min(heal, INT16_MAX);
  4397. WBUFL(buf,6)=dst->id;
  4398. WBUFL(buf,10)=src?src->id:0;
  4399. WBUFB(buf,14)=fail;
  4400. if (disguised(dst)) {
  4401. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4402. WBUFL(buf,6)=-dst->id;
  4403. clif_send(buf,packet_len(0x11a),dst,SELF);
  4404. } else
  4405. clif_send(buf,packet_len(0x11a),dst,AREA);
  4406. if(src && disguised(src)) {
  4407. WBUFL(buf,10)=-src->id;
  4408. if (disguised(dst))
  4409. WBUFL(buf,6)=dst->id;
  4410. clif_send(buf,packet_len(0x11a),src,SELF);
  4411. }
  4412. return fail;
  4413. }
  4414. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4415. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4416. void clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4417. {
  4418. unsigned char buf[32];
  4419. nullpo_retv(src);
  4420. WBUFW(buf,0)=0x117;
  4421. WBUFW(buf,2)=skill_id;
  4422. WBUFL(buf,4)=src->id;
  4423. WBUFW(buf,8)=val;
  4424. WBUFW(buf,10)=x;
  4425. WBUFW(buf,12)=y;
  4426. WBUFL(buf,14)=tick;
  4427. if(disguised(src)) {
  4428. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4429. WBUFL(buf,4)=-src->id;
  4430. clif_send(buf,packet_len(0x117),src,SELF);
  4431. } else
  4432. clif_send(buf,packet_len(0x117),src,AREA);
  4433. }
  4434. /*==========================================
  4435. * Tells all client's nearby 'unit' sight range that it spawned
  4436. *------------------------------------------*/
  4437. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4438. void clif_skill_setunit(struct skill_unit *unit)
  4439. {
  4440. unsigned char buf[128];
  4441. nullpo_retv(unit);
  4442. if( unit->group->state.guildaura )
  4443. return;
  4444. #if PACKETVER >= 3
  4445. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4446. WBUFW(buf, 0)=0x1c9;
  4447. WBUFL(buf, 2)=unit->bl.id;
  4448. WBUFL(buf, 6)=unit->group->src_id;
  4449. WBUFW(buf,10)=unit->bl.x;
  4450. WBUFW(buf,12)=unit->bl.y;
  4451. WBUFB(buf,14)=unit->group->unit_id;
  4452. WBUFB(buf,15)=1;
  4453. WBUFB(buf,16)=1;
  4454. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4455. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4456. return;
  4457. }
  4458. #endif
  4459. WBUFW(buf, 0)=0x11f;
  4460. WBUFL(buf, 2)=unit->bl.id;
  4461. WBUFL(buf, 6)=unit->group->src_id;
  4462. WBUFW(buf,10)=unit->bl.x;
  4463. WBUFW(buf,12)=unit->bl.y;
  4464. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4465. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4466. else
  4467. WBUFB(buf,14)=unit->group->unit_id;
  4468. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4469. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4470. }
  4471. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4472. /// 011c <skill id>.W { <map name>.16B }*4
  4473. 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)
  4474. {
  4475. int fd;
  4476. nullpo_retv(sd);
  4477. fd = sd->fd;
  4478. WFIFOHEAD(fd,packet_len(0x11c));
  4479. WFIFOW(fd,0) = 0x11c;
  4480. WFIFOW(fd,2) = skill_num;
  4481. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4482. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4483. else // normal map name
  4484. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4485. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4486. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4487. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4488. WFIFOSET(fd,packet_len(0x11c));
  4489. sd->menuskill_id = skill_num;
  4490. if (skill_num == AL_WARP)
  4491. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4492. else
  4493. sd->menuskill_val = skill_lv;
  4494. }
  4495. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4496. /// 011e <type>.B
  4497. /// type:
  4498. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4499. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4500. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4501. ///
  4502. /// @param sd Who receives the message
  4503. /// @param type What message
  4504. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4505. {
  4506. int fd;
  4507. nullpo_retv(sd);
  4508. fd=sd->fd;
  4509. WFIFOHEAD(fd,packet_len(0x11e));
  4510. WFIFOW(fd,0)=0x11e;
  4511. WFIFOB(fd,2)=type;
  4512. WFIFOSET(fd,packet_len(0x11e));
  4513. }
  4514. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4515. /// 0189 <type>.W
  4516. /// type:
  4517. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4518. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4519. ///
  4520. /// @param sd Who receives the message
  4521. /// @param type What message
  4522. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4523. {
  4524. int fd;
  4525. nullpo_retv(sd);
  4526. fd=sd->fd;
  4527. WFIFOHEAD(fd,packet_len(0x189));
  4528. WFIFOW(fd,0)=0x189;
  4529. WFIFOW(fd,2)=type;
  4530. WFIFOSET(fd,packet_len(0x189));
  4531. }
  4532. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4533. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4534. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4535. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4536. {
  4537. struct status_data *status;
  4538. unsigned char buf[64];
  4539. int i;//, fix;
  4540. nullpo_retv(sd);
  4541. nullpo_retv(dst);
  4542. if( dst->type != BL_MOB )
  4543. return;
  4544. status = status_get_status_data(dst);
  4545. WBUFW(buf, 0)=0x18c;
  4546. WBUFW(buf, 2)=status_get_class(dst);
  4547. WBUFW(buf, 4)=status_get_lv(dst);
  4548. WBUFW(buf, 6)=status->size;
  4549. WBUFL(buf, 8)=status->hp;
  4550. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4551. +(battle_config.estimation_type&2?status->def2:0);
  4552. WBUFW(buf,14)=status->race;
  4553. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4554. +(battle_config.estimation_type&2?status->mdef2:0);
  4555. WBUFW(buf,18)= status->def_ele;
  4556. for(i=0;i<9;i++)
  4557. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4558. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4559. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4560. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4561. }
  4562. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4563. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4564. /// material id:
  4565. /// unused by the client
  4566. void clif_skill_produce_mix_list(struct map_session_data *sd, int skillid , int trigger)
  4567. {
  4568. int i,c,view,fd;
  4569. nullpo_retv(sd);
  4570. if(sd->menuskill_id == skillid)
  4571. return; //Avoid resending the menu twice or more times...
  4572. fd=sd->fd;
  4573. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4574. WFIFOW(fd, 0)=0x18d;
  4575. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4576. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4577. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4578. WFIFOW(fd,c*8+ 4)= view;
  4579. else
  4580. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4581. WFIFOW(fd,c*8+ 6)= 0;
  4582. WFIFOW(fd,c*8+ 8)= 0;
  4583. WFIFOW(fd,c*8+10)= 0;
  4584. c++;
  4585. }
  4586. }
  4587. WFIFOW(fd, 2)=c*8+8;
  4588. WFIFOSET(fd,WFIFOW(fd,2));
  4589. if(c > 0) {
  4590. sd->menuskill_id = skillid;
  4591. sd->menuskill_val = trigger;
  4592. return;
  4593. }
  4594. }
  4595. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4596. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4597. /// mk type:
  4598. /// 1 = cooking
  4599. /// 2 = arrow
  4600. /// 3 = elemental
  4601. /// 4 = GN_MIX_COOKING
  4602. /// 5 = GN_MAKEBOMB
  4603. /// 6 = GN_S_PHARMACY
  4604. void clif_cooking_list(struct map_session_data *sd, int trigger, int skill_id, int qty, int list_type)
  4605. {
  4606. int fd;
  4607. int i, c;
  4608. int view;
  4609. nullpo_retv(sd);
  4610. fd = sd->fd;
  4611. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4612. WFIFOW(fd,0) = 0x25a;
  4613. WFIFOW(fd,4) = list_type; // list type
  4614. c = 0;
  4615. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4616. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4617. continue;
  4618. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4619. WFIFOW(fd, 6 + 2 * c) = view;
  4620. else
  4621. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4622. c++;
  4623. }
  4624. if( skill_id == AM_PHARMACY ) { // Only send it while Cooking else check for c.
  4625. WFIFOW(fd,2) = 6 + 2 * c;
  4626. WFIFOSET(fd,WFIFOW(fd,2));
  4627. }
  4628. if( c > 0 ) {
  4629. sd->menuskill_id = skill_id;
  4630. sd->menuskill_val = trigger;
  4631. if( skill_id != AM_PHARMACY ) {
  4632. sd->menuskill_val2 = qty; // amount.
  4633. WFIFOW(fd,2) = 6 + 2 * c;
  4634. WFIFOSET(fd,WFIFOW(fd,2));
  4635. }
  4636. } else {
  4637. clif_menuskill_clear(sd);
  4638. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4639. // It fails.
  4640. #if PACKETVER >= 20090922
  4641. clif_msg_skill(sd,skill_id,0x625);
  4642. #else
  4643. WFIFOW(fd,2) = 6 + 2 * c;
  4644. WFIFOSET(fd,WFIFOW(fd,2));
  4645. #endif
  4646. }
  4647. }
  4648. }
  4649. /// Notifies clients of a status change.
  4650. /// 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)]
  4651. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4652. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4653. {
  4654. unsigned char buf[32];
  4655. struct map_session_data *sd;
  4656. if (type == SI_BLANK) //It shows nothing on the client...
  4657. return;
  4658. nullpo_retv(bl);
  4659. sd = BL_CAST(BL_PC, bl);
  4660. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4661. return;
  4662. #if PACKETVER >= 20090121
  4663. if(flag && battle_config.display_status_timers && sd)
  4664. WBUFW(buf,0)=0x43f;
  4665. else
  4666. #endif
  4667. WBUFW(buf,0)=0x196;
  4668. WBUFW(buf,2)=type;
  4669. WBUFL(buf,4)=bl->id;
  4670. WBUFB(buf,8)=flag;
  4671. #if PACKETVER >= 20090121
  4672. if(flag && battle_config.display_status_timers && sd)
  4673. {
  4674. if (tick <= 0)
  4675. tick = 9999; // this is indeed what official servers do
  4676. WBUFL(buf,9) = tick;
  4677. WBUFL(buf,13) = val1;
  4678. WBUFL(buf,17) = val2;
  4679. WBUFL(buf,21) = val3;
  4680. }
  4681. #endif
  4682. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4683. }
  4684. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4685. /// 008e <packet len>.W <message>.?B
  4686. void clif_displaymessage(const int fd, const char* mes)
  4687. {
  4688. nullpo_retv(mes);
  4689. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4690. if (fd == 0)
  4691. ;
  4692. else {
  4693. char *message, *line;
  4694. message = aStrdup(mes);
  4695. line = strtok(message, "\n");
  4696. while(line != NULL) {
  4697. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4698. int len = strnlen(line, 255);
  4699. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4700. WFIFOHEAD(fd, 5 + len);
  4701. WFIFOW(fd,0) = 0x8e;
  4702. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4703. safestrncpy(WFIFOP(fd,4), line, len + 1);
  4704. WFIFOSET(fd, 5 + len);
  4705. }
  4706. line = strtok(NULL, "\n");
  4707. }
  4708. aFree(message);
  4709. }
  4710. }
  4711. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4712. /// 009a <packet len>.W <message>.?B
  4713. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4714. {
  4715. int lp = type ? 4 : 0;
  4716. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4717. WBUFW(buf,0) = 0x9a;
  4718. WBUFW(buf,2) = 4 + lp + len;
  4719. if (type == 0x10) // bc_blue
  4720. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4721. else if (type == 0x20) // bc_woe
  4722. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4723. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4724. clif_send(buf, WBUFW(buf,2), bl, target);
  4725. if (buf)
  4726. aFree(buf);
  4727. }
  4728. /*==========================================
  4729. * Displays a message on a 'bl' to all it's nearby clients
  4730. * Used by npc_globalmessage
  4731. *------------------------------------------*/
  4732. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4733. {
  4734. char buf[100];
  4735. int len;
  4736. nullpo_retv(bl);
  4737. if(!message)
  4738. return;
  4739. len = strlen(message)+1;
  4740. if( len > sizeof(buf)-8 )
  4741. {
  4742. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4743. len = sizeof(buf)-8;
  4744. }
  4745. WBUFW(buf,0)=0x8d;
  4746. WBUFW(buf,2)=len+8;
  4747. WBUFL(buf,4)=bl->id;
  4748. safestrncpy((char *) WBUFP(buf,8),message,len);
  4749. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4750. }
  4751. /*==========================================
  4752. * Send main chat message [LuzZza]
  4753. *------------------------------------------*/
  4754. void clif_MainChatMessage(const char* message)
  4755. {
  4756. uint8 buf[200];
  4757. int len;
  4758. if(!message)
  4759. return;
  4760. len = strlen(message)+1;
  4761. if (len+8 > sizeof(buf)) {
  4762. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4763. len = sizeof(buf)-8;
  4764. }
  4765. WBUFW(buf,0)=0x8d;
  4766. WBUFW(buf,2)=len+8;
  4767. WBUFL(buf,4)=0;
  4768. safestrncpy((char *) WBUFP(buf,8),message,len);
  4769. clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4770. }
  4771. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4772. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4773. 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)
  4774. {
  4775. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4776. WBUFW(buf,0) = 0x1c3;
  4777. WBUFW(buf,2) = len + 16;
  4778. WBUFL(buf,4) = fontColor;
  4779. WBUFW(buf,8) = fontType;
  4780. WBUFW(buf,10) = fontSize;
  4781. WBUFW(buf,12) = fontAlign;
  4782. WBUFW(buf,14) = fontY;
  4783. memcpy(WBUFP(buf,16), mes, len);
  4784. clif_send(buf, WBUFW(buf,2), bl, target);
  4785. if (buf)
  4786. aFree(buf);
  4787. }
  4788. /// Displays heal effect (ZC_RECOVERY).
  4789. /// 013d <var id>.W <amount>.W
  4790. /// var id:
  4791. /// 5 = HP (SP_HP)
  4792. /// 7 = SP (SP_SP)
  4793. /// ? = ignored
  4794. void clif_heal(int fd,int type,int val)
  4795. {
  4796. WFIFOHEAD(fd,packet_len(0x13d));
  4797. WFIFOW(fd,0)=0x13d;
  4798. WFIFOW(fd,2)=type;
  4799. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4800. WFIFOSET(fd,packet_len(0x13d));
  4801. }
  4802. /// Displays resurrection effect (ZC_RESURRECTION).
  4803. /// 0148 <id>.L <type>.W
  4804. /// type:
  4805. /// ignored
  4806. void clif_resurrection(struct block_list *bl,int type)
  4807. {
  4808. unsigned char buf[16];
  4809. nullpo_retv(bl);
  4810. WBUFW(buf,0)=0x148;
  4811. WBUFL(buf,2)=bl->id;
  4812. WBUFW(buf,6)=0;
  4813. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4814. if (disguised(bl))
  4815. clif_spawn(bl);
  4816. }
  4817. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4818. /// 0199 <type>.W
  4819. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4820. {
  4821. int fd;
  4822. nullpo_retv(sd);
  4823. fd=sd->fd;
  4824. WFIFOHEAD(fd,packet_len(0x199));
  4825. WFIFOW(fd,0)=0x199;
  4826. WFIFOW(fd,2)=property;
  4827. WFIFOSET(fd,packet_len(0x199));
  4828. }
  4829. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4830. /// 01d6 <type>.W
  4831. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4832. {
  4833. int fd;
  4834. nullpo_retv(sd);
  4835. fd=sd->fd;
  4836. WFIFOHEAD(fd,packet_len(0x1D6));
  4837. WFIFOW(fd,0)=0x1D6;
  4838. WFIFOW(fd,2)=type;
  4839. WFIFOSET(fd,packet_len(0x1D6));
  4840. }
  4841. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4842. /// 019a <id>.L <ranking>.L <total>.L
  4843. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4844. {
  4845. if(type == 2) {
  4846. int fd = sd->fd;
  4847. WFIFOHEAD(fd,packet_len(0x19a));
  4848. WFIFOW(fd,0) = 0x19a;
  4849. WFIFOL(fd,2) = sd->bl.id;
  4850. WFIFOL(fd,6) = pvprank;
  4851. WFIFOL(fd,10) = pvpnum;
  4852. WFIFOSET(fd,packet_len(0x19a));
  4853. } else {
  4854. unsigned char buf[32];
  4855. WBUFW(buf,0) = 0x19a;
  4856. WBUFL(buf,2) = sd->bl.id;
  4857. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4858. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4859. else
  4860. WBUFL(buf,6) = pvprank;
  4861. WBUFL(buf,10) = pvpnum;
  4862. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4863. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4864. else if(!type)
  4865. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4866. else
  4867. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4868. }
  4869. }
  4870. /*==========================================
  4871. *
  4872. *------------------------------------------*/
  4873. void clif_map_property_mapall(int map, enum map_property property)
  4874. {
  4875. struct block_list bl;
  4876. unsigned char buf[16];
  4877. bl.id = 0;
  4878. bl.type = BL_NUL;
  4879. bl.m = map;
  4880. WBUFW(buf,0)=0x199;
  4881. WBUFW(buf,2)=property;
  4882. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4883. }
  4884. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4885. /// 0188 <result>.W <index>.W <refine>.W
  4886. /// result:
  4887. /// 0 = success
  4888. /// 1 = failure
  4889. /// 2 = downgrade
  4890. void clif_refine(int fd, int fail, int index, int val)
  4891. {
  4892. WFIFOHEAD(fd,packet_len(0x188));
  4893. WFIFOW(fd,0)=0x188;
  4894. WFIFOW(fd,2)=fail;
  4895. WFIFOW(fd,4)=index+2;
  4896. WFIFOW(fd,6)=val;
  4897. WFIFOSET(fd,packet_len(0x188));
  4898. }
  4899. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4900. /// 0223 <result>.L <nameid>.W
  4901. /// result:
  4902. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4903. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4904. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4905. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4906. void clif_upgrademessage(int fd, int result, int item_id)
  4907. {
  4908. WFIFOHEAD(fd,packet_len(0x223));
  4909. WFIFOW(fd,0)=0x223;
  4910. WFIFOL(fd,2)=result;
  4911. WFIFOW(fd,6)=item_id;
  4912. WFIFOSET(fd,packet_len(0x223));
  4913. }
  4914. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4915. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4916. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4917. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4918. {
  4919. #if PACKETVER < 20091104
  4920. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4921. WFIFOW(fd,0) = 0x97;
  4922. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4923. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4924. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4925. WFIFOSET(fd,WFIFOW(fd,2));
  4926. #else
  4927. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4928. WFIFOW(fd,0) = 0x97;
  4929. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4930. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4931. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4932. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  4933. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4934. WFIFOSET(fd,WFIFOW(fd,2));
  4935. #endif
  4936. }
  4937. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  4938. /// 0098 <result>.B
  4939. /// result:
  4940. /// 0 = success to send wisper
  4941. /// 1 = target character is not loged in
  4942. /// 2 = ignored by target
  4943. /// 3 = everyone ignored by target
  4944. void clif_wis_end(int fd, int flag)
  4945. {
  4946. WFIFOHEAD(fd,packet_len(0x98));
  4947. WFIFOW(fd,0) = 0x98;
  4948. WFIFOW(fd,2) = flag;
  4949. WFIFOSET(fd,packet_len(0x98));
  4950. }
  4951. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  4952. /// 0194 <char id>.L <name>.24B
  4953. void clif_solved_charname(int fd, int charid, const char* name)
  4954. {
  4955. WFIFOHEAD(fd,packet_len(0x194));
  4956. WFIFOW(fd,0)=0x194;
  4957. WFIFOL(fd,2)=charid;
  4958. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4959. WFIFOSET(fd,packet_len(0x194));
  4960. }
  4961. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  4962. /// 017b <packet len>.W { <name id>.W }*
  4963. void clif_use_card(struct map_session_data *sd,int idx)
  4964. {
  4965. int i,c,ep;
  4966. int fd=sd->fd;
  4967. nullpo_retv(sd);
  4968. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4969. return;
  4970. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4971. return; //Avoid parsing invalid item indexes (no card/no item)
  4972. ep=sd->inventory_data[idx]->equip;
  4973. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4974. WFIFOW(fd,0)=0x17b;
  4975. for(i=c=0;i<MAX_INVENTORY;i++){
  4976. int j;
  4977. if(sd->inventory_data[i] == NULL)
  4978. continue;
  4979. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4980. continue;
  4981. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4982. continue;
  4983. if(sd->status.inventory[i].identify==0 ) //Not identified
  4984. continue;
  4985. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4986. continue;
  4987. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4988. continue;
  4989. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4990. if( j == sd->inventory_data[i]->slot ) // No room
  4991. continue;
  4992. WFIFOW(fd,4+c*2)=i+2;
  4993. c++;
  4994. }
  4995. WFIFOW(fd,2)=4+c*2;
  4996. WFIFOSET(fd,WFIFOW(fd,2));
  4997. }
  4998. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  4999. /// 017d <equip index>.W <card index>.W <result>.B
  5000. /// result:
  5001. /// 0 = success
  5002. /// 1 = failure
  5003. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5004. {
  5005. int fd;
  5006. nullpo_retv(sd);
  5007. fd=sd->fd;
  5008. WFIFOHEAD(fd,packet_len(0x17d));
  5009. WFIFOW(fd,0)=0x17d;
  5010. WFIFOW(fd,2)=idx_equip+2;
  5011. WFIFOW(fd,4)=idx_card+2;
  5012. WFIFOB(fd,6)=flag;
  5013. WFIFOSET(fd,packet_len(0x17d));
  5014. }
  5015. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5016. /// 0177 <packet len>.W { <name id>.W }*
  5017. void clif_item_identify_list(struct map_session_data *sd)
  5018. {
  5019. int i,c;
  5020. int fd;
  5021. nullpo_retv(sd);
  5022. fd=sd->fd;
  5023. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5024. WFIFOW(fd,0)=0x177;
  5025. for(i=c=0;i<MAX_INVENTORY;i++){
  5026. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5027. WFIFOW(fd,c*2+4)=i+2;
  5028. c++;
  5029. }
  5030. }
  5031. if(c > 0) {
  5032. WFIFOW(fd,2)=c*2+4;
  5033. WFIFOSET(fd,WFIFOW(fd,2));
  5034. sd->menuskill_id = MC_IDENTIFY;
  5035. sd->menuskill_val = c;
  5036. }
  5037. }
  5038. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5039. /// 0179 <index>.W <result>.B
  5040. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5041. {
  5042. int fd;
  5043. nullpo_retv(sd);
  5044. fd=sd->fd;
  5045. WFIFOHEAD(fd,packet_len(0x179));
  5046. WFIFOW(fd, 0)=0x179;
  5047. WFIFOW(fd, 2)=idx+2;
  5048. WFIFOB(fd, 4)=flag;
  5049. WFIFOSET(fd,packet_len(0x179));
  5050. }
  5051. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5052. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5053. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  5054. {
  5055. int i,c;
  5056. int fd;
  5057. int nameid;
  5058. nullpo_retv(sd);
  5059. nullpo_retv(dstsd);
  5060. fd=sd->fd;
  5061. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5062. WFIFOW(fd,0)=0x1fc;
  5063. for(i=c=0;i<MAX_INVENTORY;i++){
  5064. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5065. WFIFOW(fd,c*13+4) = i;
  5066. WFIFOW(fd,c*13+6) = nameid;
  5067. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5068. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5069. c++;
  5070. }
  5071. }
  5072. if(c > 0) {
  5073. WFIFOW(fd,2)=c*13+4;
  5074. WFIFOSET(fd,WFIFOW(fd,2));
  5075. sd->menuskill_id = BS_REPAIRWEAPON;
  5076. sd->menuskill_val = dstsd->bl.id;
  5077. }else
  5078. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  5079. }
  5080. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5081. /// 01fe <index>.W <result>.B
  5082. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5083. {
  5084. int fd;
  5085. nullpo_retv(sd);
  5086. fd = sd->fd;
  5087. WFIFOHEAD(fd,packet_len(0x1fe));
  5088. WFIFOW(fd, 0)=0x1fe;
  5089. WFIFOW(fd, 2)=idx+2;
  5090. WFIFOB(fd, 4)=flag;
  5091. WFIFOSET(fd,packet_len(0x1fe));
  5092. }
  5093. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5094. /// 02bb <equip location>.W <account id>.L
  5095. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5096. {
  5097. int fd = sd->fd;
  5098. WFIFOHEAD(fd,packet_len(0x2bb));
  5099. WFIFOW(fd,0) = 0x2bb;
  5100. WFIFOW(fd,2) = position;
  5101. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5102. WFIFOSET(fd,packet_len(0x2bb));
  5103. }
  5104. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5105. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5106. void clif_item_refine_list(struct map_session_data *sd)
  5107. {
  5108. int i,c;
  5109. int fd;
  5110. int skilllv;
  5111. int wlv;
  5112. int refine_item[5];
  5113. nullpo_retv(sd);
  5114. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  5115. fd=sd->fd;
  5116. refine_item[0] = -1;
  5117. refine_item[1] = pc_search_inventory(sd,1010);
  5118. refine_item[2] = pc_search_inventory(sd,1011);
  5119. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5120. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5121. WFIFOW(fd,0)=0x221;
  5122. for(i=c=0;i<MAX_INVENTORY;i++){
  5123. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  5124. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5125. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5126. WFIFOW(fd,c*13+ 4)=i+2;
  5127. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5128. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5129. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5130. c++;
  5131. }
  5132. }
  5133. WFIFOW(fd,2)=c*13+4;
  5134. WFIFOSET(fd,WFIFOW(fd,2));
  5135. if (c > 0) {
  5136. sd->menuskill_id = WS_WEAPONREFINE;
  5137. sd->menuskill_val = skilllv;
  5138. }
  5139. }
  5140. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5141. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5142. void clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  5143. {
  5144. int fd;
  5145. nullpo_retv(sd);
  5146. fd=sd->fd;
  5147. WFIFOHEAD(fd,packet_len(0x147));
  5148. WFIFOW(fd, 0)=0x147;
  5149. WFIFOW(fd, 2)=skillid;
  5150. WFIFOW(fd, 4)=skill_get_inf(skillid);
  5151. WFIFOW(fd, 6)=0;
  5152. WFIFOW(fd, 8)=skilllv;
  5153. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  5154. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  5155. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  5156. WFIFOB(fd,38)=0;
  5157. WFIFOSET(fd,packet_len(0x147));
  5158. }
  5159. /// Adds an item to character's cart.
  5160. /// 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)
  5161. /// 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)
  5162. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5163. {
  5164. int view,fd;
  5165. unsigned char *buf;
  5166. nullpo_retv(sd);
  5167. fd=sd->fd;
  5168. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5169. return;
  5170. #if PACKETVER < 5
  5171. WFIFOHEAD(fd,packet_len(0x124));
  5172. buf=WFIFOP(fd,0);
  5173. WBUFW(buf,0)=0x124;
  5174. WBUFW(buf,2)=n+2;
  5175. WBUFL(buf,4)=amount;
  5176. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5177. WBUFW(buf,8)=view;
  5178. else
  5179. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5180. WBUFB(buf,10)=sd->status.cart[n].identify;
  5181. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5182. WBUFB(buf,12)=sd->status.cart[n].refine;
  5183. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5184. WFIFOSET(fd,packet_len(0x124));
  5185. #else
  5186. WFIFOHEAD(fd,packet_len(0x1c5));
  5187. buf=WFIFOP(fd,0);
  5188. WBUFW(buf,0)=0x1c5;
  5189. WBUFW(buf,2)=n+2;
  5190. WBUFL(buf,4)=amount;
  5191. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5192. WBUFW(buf,8)=view;
  5193. else
  5194. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5195. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5196. WBUFB(buf,11)=sd->status.cart[n].identify;
  5197. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5198. WBUFB(buf,13)=sd->status.cart[n].refine;
  5199. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5200. WFIFOSET(fd,packet_len(0x1c5));
  5201. #endif
  5202. }
  5203. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5204. /// 0125 <index>.W <amount>.L
  5205. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5206. {
  5207. int fd;
  5208. nullpo_retv(sd);
  5209. fd=sd->fd;
  5210. WFIFOHEAD(fd,packet_len(0x125));
  5211. WFIFOW(fd,0)=0x125;
  5212. WFIFOW(fd,2)=n+2;
  5213. WFIFOL(fd,4)=amount;
  5214. WFIFOSET(fd,packet_len(0x125));
  5215. }
  5216. /// Opens the shop creation menu (ZC_OPENSTORE).
  5217. /// 012d <num>.W
  5218. /// num:
  5219. /// number of allowed item slots
  5220. void clif_openvendingreq(struct map_session_data* sd, int num)
  5221. {
  5222. int fd;
  5223. nullpo_retv(sd);
  5224. fd = sd->fd;
  5225. WFIFOHEAD(fd,packet_len(0x12d));
  5226. WFIFOW(fd,0) = 0x12d;
  5227. WFIFOW(fd,2) = num;
  5228. WFIFOSET(fd,packet_len(0x12d));
  5229. }
  5230. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5231. /// 0131 <owner id>.L <message>.80B
  5232. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5233. {
  5234. unsigned char buf[128];
  5235. nullpo_retv(bl);
  5236. WBUFW(buf,0) = 0x131;
  5237. WBUFL(buf,2) = bl->id;
  5238. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5239. if( fd ) {
  5240. WFIFOHEAD(fd,packet_len(0x131));
  5241. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5242. WFIFOSET(fd,packet_len(0x131));
  5243. } else {
  5244. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5245. }
  5246. }
  5247. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5248. /// 0132 <owner id>.L
  5249. void clif_closevendingboard(struct block_list* bl, int fd)
  5250. {
  5251. unsigned char buf[16];
  5252. nullpo_retv(bl);
  5253. WBUFW(buf,0) = 0x132;
  5254. WBUFL(buf,2) = bl->id;
  5255. if( fd ) {
  5256. WFIFOHEAD(fd,packet_len(0x132));
  5257. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5258. WFIFOSET(fd,packet_len(0x132));
  5259. } else {
  5260. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5261. }
  5262. }
  5263. /// Sends a list of items in a shop.
  5264. /// 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)
  5265. /// 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)
  5266. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5267. {
  5268. int i,fd;
  5269. int count;
  5270. struct map_session_data* vsd;
  5271. #if PACKETVER < 20100105
  5272. const int cmd = 0x133;
  5273. const int offset = 8;
  5274. #else
  5275. const int cmd = 0x800;
  5276. const int offset = 12;
  5277. #endif
  5278. nullpo_retv(sd);
  5279. nullpo_retv(vending);
  5280. nullpo_retv(vsd=map_id2sd(id));
  5281. fd = sd->fd;
  5282. count = vsd->vend_num;
  5283. WFIFOHEAD(fd, offset+count*22);
  5284. WFIFOW(fd,0) = cmd;
  5285. WFIFOW(fd,2) = offset+count*22;
  5286. WFIFOL(fd,4) = id;
  5287. #if PACKETVER >= 20100105
  5288. WFIFOL(fd,8) = vsd->vender_id;
  5289. #endif
  5290. for( i = 0; i < count; i++ )
  5291. {
  5292. int index = vending[i].index;
  5293. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5294. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5295. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5296. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5297. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5298. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5299. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5300. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5301. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5302. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5303. }
  5304. WFIFOSET(fd,WFIFOW(fd,2));
  5305. }
  5306. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5307. /// 0135 <index>.W <amount>.W <result>.B
  5308. /// result:
  5309. /// 0 = success
  5310. /// 1 = not enough zeny
  5311. /// 2 = overweight
  5312. /// 4 = out of stock
  5313. /// 5 = "cannot use an npc shop while in a trade"
  5314. /// 6 = Because the store information was incorrect the item was not purchased.
  5315. /// 7 = No sales information.
  5316. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5317. {
  5318. int fd;
  5319. nullpo_retv(sd);
  5320. fd = sd->fd;
  5321. WFIFOHEAD(fd,packet_len(0x135));
  5322. WFIFOW(fd,0) = 0x135;
  5323. WFIFOW(fd,2) = index+2;
  5324. WFIFOW(fd,4) = amount;
  5325. WFIFOB(fd,6) = fail;
  5326. WFIFOSET(fd,packet_len(0x135));
  5327. }
  5328. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5329. /// 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 }*
  5330. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5331. {
  5332. int i,fd;
  5333. int count;
  5334. nullpo_retv(sd);
  5335. fd = sd->fd;
  5336. count = sd->vend_num;
  5337. WFIFOHEAD(fd, 8+count*22);
  5338. WFIFOW(fd,0) = 0x136;
  5339. WFIFOW(fd,2) = 8+count*22;
  5340. WFIFOL(fd,4) = id;
  5341. for( i = 0; i < count; i++ )
  5342. {
  5343. int index = vending[i].index;
  5344. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5345. WFIFOL(fd, 8+i*22) = vending[i].value;
  5346. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5347. WFIFOW(fd,14+i*22) = vending[i].amount;
  5348. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5349. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5350. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5351. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5352. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5353. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5354. }
  5355. WFIFOSET(fd,WFIFOW(fd,2));
  5356. }
  5357. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5358. /// 0137 <index>.W <amount>.W
  5359. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5360. {
  5361. int fd;
  5362. nullpo_retv(sd);
  5363. fd = sd->fd;
  5364. WFIFOHEAD(fd,packet_len(0x137));
  5365. WFIFOW(fd,0) = 0x137;
  5366. WFIFOW(fd,2) = index+2;
  5367. WFIFOW(fd,4) = amount;
  5368. WFIFOSET(fd,packet_len(0x137));
  5369. }
  5370. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5371. /// 00fa <result>.B
  5372. /// result:
  5373. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5374. /// 1 = MsgStringTable[78]="party name already exists"
  5375. /// 2 = MsgStringTable[79]="already in a party"
  5376. /// 3 = cannot organize parties on this map
  5377. /// ? = nothing
  5378. void clif_party_created(struct map_session_data *sd,int result)
  5379. {
  5380. int fd;
  5381. nullpo_retv(sd);
  5382. fd=sd->fd;
  5383. WFIFOHEAD(fd,packet_len(0xfa));
  5384. WFIFOW(fd,0)=0xfa;
  5385. WFIFOB(fd,2)=result;
  5386. WFIFOSET(fd,packet_len(0xfa));
  5387. }
  5388. /// Adds new member to a party.
  5389. /// 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)
  5390. /// 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)
  5391. /// role:
  5392. /// 0 = leader
  5393. /// 1 = normal
  5394. /// state:
  5395. /// 0 = connected
  5396. /// 1 = disconnected
  5397. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5398. {
  5399. unsigned char buf[81];
  5400. int i;
  5401. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5402. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5403. } else {
  5404. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5405. }
  5406. if (i >= MAX_PARTY) return; //Should never happen...
  5407. sd = p->data[i].sd;
  5408. WBUFW(buf, 0) = 0x1e9;
  5409. WBUFL(buf, 2) = sd->status.account_id;
  5410. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5411. WBUFW(buf,10) = sd->bl.x;
  5412. WBUFW(buf,12) = sd->bl.y;
  5413. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5414. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5415. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5416. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5417. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5418. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5419. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5420. }
  5421. /// Sends party information (ZC_GROUP_LIST).
  5422. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5423. /// role:
  5424. /// 0 = leader
  5425. /// 1 = normal
  5426. /// state:
  5427. /// 0 = connected
  5428. /// 1 = disconnected
  5429. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5430. {
  5431. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5432. struct map_session_data* party_sd = NULL;
  5433. int i, c;
  5434. nullpo_retv(p);
  5435. WBUFW(buf,0) = 0xfb;
  5436. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5437. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5438. {
  5439. struct party_member* m = &p->party.member[i];
  5440. if(!m->account_id) continue;
  5441. if(party_sd == NULL) party_sd = p->data[i].sd;
  5442. WBUFL(buf,28+c*46) = m->account_id;
  5443. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5444. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5445. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5446. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5447. c++;
  5448. }
  5449. WBUFW(buf,2) = 28+c*46;
  5450. if(sd) { // send only to self
  5451. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5452. } else if (party_sd) { // send to whole party
  5453. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5454. }
  5455. }
  5456. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5457. /// 02c9 <flag>.B
  5458. /// flag:
  5459. /// 0 = allow party invites
  5460. /// 1 = auto-deny party invites
  5461. void clif_partyinvitationstate(struct map_session_data* sd)
  5462. {
  5463. int fd;
  5464. nullpo_retv(sd);
  5465. fd = sd->fd;
  5466. WFIFOHEAD(fd, packet_len(0x2c9));
  5467. WFIFOW(fd, 0) = 0x2c9;
  5468. WFIFOB(fd, 2) = 0; // not implemented
  5469. WFIFOSET(fd, packet_len(0x2c9));
  5470. }
  5471. /// Party invitation request.
  5472. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5473. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5474. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5475. {
  5476. #if PACKETVER < 20070821
  5477. const int cmd = 0xfe;
  5478. #else
  5479. const int cmd = 0x2c6;
  5480. #endif
  5481. int fd;
  5482. struct party_data *p;
  5483. nullpo_retv(sd);
  5484. nullpo_retv(tsd);
  5485. fd=tsd->fd;
  5486. if( (p=party_search(sd->status.party_id))==NULL )
  5487. return;
  5488. WFIFOHEAD(fd,packet_len(cmd));
  5489. WFIFOW(fd,0)=cmd;
  5490. WFIFOL(fd,2)=sd->status.party_id;
  5491. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5492. WFIFOSET(fd,packet_len(cmd));
  5493. }
  5494. /// Party invite result.
  5495. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5496. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5497. /// result=0 : char is already in a party -> MsgStringTable[80]
  5498. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5499. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5500. /// result=3 : party is full -> MsgStringTable[83]
  5501. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5502. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5503. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5504. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5505. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5506. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5507. {
  5508. int fd;
  5509. nullpo_retv(sd);
  5510. fd=sd->fd;
  5511. #if PACKETVER < 20070904
  5512. if( result == 7 ) {
  5513. clif_displaymessage(fd, msg_txt(3));
  5514. return;
  5515. }
  5516. #endif
  5517. #if PACKETVER < 20070821
  5518. WFIFOHEAD(fd,packet_len(0xfd));
  5519. WFIFOW(fd,0) = 0xfd;
  5520. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5521. WFIFOB(fd,26) = result;
  5522. WFIFOSET(fd,packet_len(0xfd));
  5523. #else
  5524. WFIFOHEAD(fd,packet_len(0x2c5));
  5525. WFIFOW(fd,0) = 0x2c5;
  5526. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5527. WFIFOL(fd,26) = result;
  5528. WFIFOSET(fd,packet_len(0x2c5));
  5529. #endif
  5530. }
  5531. /// Updates party settings.
  5532. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5533. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5534. /// exp option:
  5535. /// 0 = exp sharing disabled
  5536. /// 1 = exp sharing enabled
  5537. /// 2 = cannot change exp sharing
  5538. ///
  5539. /// flag:
  5540. /// 0 = send to party
  5541. /// 1 = send to sd
  5542. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5543. {
  5544. unsigned char buf[16];
  5545. #if PACKETVER < 20090603
  5546. const int cmd = 0x101;
  5547. #else
  5548. const int cmd = 0x7d8;
  5549. #endif
  5550. nullpo_retv(p);
  5551. if(!sd && flag==0){
  5552. int i;
  5553. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5554. if (i < MAX_PARTY)
  5555. sd = p->data[i].sd;
  5556. }
  5557. if(!sd) return;
  5558. WBUFW(buf,0)=cmd;
  5559. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5560. #if PACKETVER >= 20090603
  5561. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5562. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5563. #endif
  5564. if(flag==0)
  5565. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5566. else
  5567. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5568. }
  5569. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5570. /// result:
  5571. /// 0 = leave
  5572. /// 1 = expel
  5573. /// 2 = cannot leave party on this map
  5574. /// 3 = cannot expel from party on this map
  5575. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5576. {
  5577. unsigned char buf[64];
  5578. int i;
  5579. nullpo_retv(p);
  5580. if(!sd && (flag&0xf0)==0)
  5581. {
  5582. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5583. if (i < MAX_PARTY)
  5584. sd = p->data[i].sd;
  5585. }
  5586. if(!sd) return;
  5587. WBUFW(buf,0)=0x105;
  5588. WBUFL(buf,2)=account_id;
  5589. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5590. WBUFB(buf,30)=flag&0x0f;
  5591. if((flag&0xf0)==0)
  5592. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5593. else
  5594. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5595. }
  5596. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5597. /// 0109 <packet len>.W <account id>.L <message>.?B
  5598. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5599. {
  5600. struct map_session_data *sd;
  5601. int i;
  5602. nullpo_retv(p);
  5603. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5604. if(i < MAX_PARTY){
  5605. unsigned char buf[1024];
  5606. if( len > sizeof(buf)-8 )
  5607. {
  5608. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  5609. len = sizeof(buf)-8;
  5610. }
  5611. sd = p->data[i].sd;
  5612. WBUFW(buf,0)=0x109;
  5613. WBUFW(buf,2)=len+8;
  5614. WBUFL(buf,4)=account_id;
  5615. safestrncpy(WBUFP(buf,8), mes, len);
  5616. clif_send(buf,len+8,&sd->bl,PARTY);
  5617. }
  5618. }
  5619. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5620. /// 0107 <account id>.L <x>.W <y>.W
  5621. void clif_party_xy(struct map_session_data *sd)
  5622. {
  5623. unsigned char buf[16];
  5624. nullpo_retv(sd);
  5625. WBUFW(buf,0)=0x107;
  5626. WBUFL(buf,2)=sd->status.account_id;
  5627. WBUFW(buf,6)=sd->bl.x;
  5628. WBUFW(buf,8)=sd->bl.y;
  5629. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5630. }
  5631. /*==========================================
  5632. * Sends x/y dot to a single fd. [Skotlex]
  5633. *------------------------------------------*/
  5634. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5635. {
  5636. WFIFOHEAD(fd,packet_len(0x107));
  5637. WFIFOW(fd,0)=0x107;
  5638. WFIFOL(fd,2)=sd->status.account_id;
  5639. WFIFOW(fd,6)=sd->bl.x;
  5640. WFIFOW(fd,8)=sd->bl.y;
  5641. WFIFOSET(fd,packet_len(0x107));
  5642. }
  5643. /// Updates HP bar of a party member.
  5644. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5645. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5646. void clif_party_hp(struct map_session_data *sd)
  5647. {
  5648. unsigned char buf[16];
  5649. #if PACKETVER < 20100126
  5650. const int cmd = 0x106;
  5651. #else
  5652. const int cmd = 0x80e;
  5653. #endif
  5654. nullpo_retv(sd);
  5655. WBUFW(buf,0)=cmd;
  5656. WBUFL(buf,2)=sd->status.account_id;
  5657. #if PACKETVER < 20100126
  5658. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5659. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5660. WBUFW(buf,8) = 100;
  5661. } else {
  5662. WBUFW(buf,6) = sd->battle_status.hp;
  5663. WBUFW(buf,8) = sd->battle_status.max_hp;
  5664. }
  5665. #else
  5666. WBUFL(buf,6) = sd->battle_status.hp;
  5667. WBUFL(buf,10) = sd->battle_status.max_hp;
  5668. #endif
  5669. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5670. }
  5671. /*==========================================
  5672. * Sends HP bar to a single fd. [Skotlex]
  5673. *------------------------------------------*/
  5674. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5675. {
  5676. #if PACKETVER < 20100126
  5677. const int cmd = 0x106;
  5678. #else
  5679. const int cmd = 0x80e;
  5680. #endif
  5681. WFIFOHEAD(fd,packet_len(cmd));
  5682. WFIFOW(fd,0) = cmd;
  5683. WFIFOL(fd,2) = id;
  5684. #if PACKETVER < 20100126
  5685. if( maxhp > INT16_MAX )
  5686. {// To correctly display the %hp bar. [Skotlex]
  5687. WFIFOW(fd,6) = hp/(maxhp/100);
  5688. WFIFOW(fd,8) = 100;
  5689. } else {
  5690. WFIFOW(fd,6) = hp;
  5691. WFIFOW(fd,8) = maxhp;
  5692. }
  5693. #else
  5694. WFIFOL(fd,6) = hp;
  5695. WFIFOL(fd,10) = maxhp;
  5696. #endif
  5697. WFIFOSET(fd, packet_len(cmd));
  5698. }
  5699. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5700. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5701. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5702. {
  5703. int fd;
  5704. nullpo_retv(sd);
  5705. nullpo_retv(bl);
  5706. fd=sd->fd;
  5707. WFIFOHEAD(fd,packet_len(0x139));
  5708. WFIFOW(fd, 0)=0x139;
  5709. WFIFOL(fd, 2)=bl->id;
  5710. WFIFOW(fd, 6)=bl->x;
  5711. WFIFOW(fd, 8)=bl->y;
  5712. WFIFOW(fd,10)=sd->bl.x;
  5713. WFIFOW(fd,12)=sd->bl.y;
  5714. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5715. WFIFOSET(fd,packet_len(0x139));
  5716. }
  5717. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5718. /// 018f <result>.W <name id>.W
  5719. /// result:
  5720. /// 0 = success
  5721. /// 1 = failure
  5722. /// 2 = success (alchemist)
  5723. /// 3 = failure (alchemist)
  5724. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5725. {
  5726. int view,fd;
  5727. nullpo_retv(sd);
  5728. fd = sd->fd;
  5729. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5730. WFIFOHEAD(fd,packet_len(0x18f));
  5731. WFIFOW(fd, 0)=0x18f;
  5732. WFIFOW(fd, 2)=flag;
  5733. if((view = itemdb_viewid(nameid)) > 0)
  5734. WFIFOW(fd, 4)=view;
  5735. else
  5736. WFIFOW(fd, 4)=nameid;
  5737. WFIFOSET(fd,packet_len(0x18f));
  5738. }
  5739. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5740. /// 019e
  5741. void clif_catch_process(struct map_session_data *sd)
  5742. {
  5743. int fd;
  5744. nullpo_retv(sd);
  5745. fd=sd->fd;
  5746. WFIFOHEAD(fd,packet_len(0x19e));
  5747. WFIFOW(fd,0)=0x19e;
  5748. WFIFOSET(fd,packet_len(0x19e));
  5749. }
  5750. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5751. /// 01a0 <result>.B
  5752. /// 0 = failure
  5753. /// 1 = success
  5754. void clif_pet_roulette(struct map_session_data *sd,int data)
  5755. {
  5756. int fd;
  5757. nullpo_retv(sd);
  5758. fd=sd->fd;
  5759. WFIFOHEAD(fd,packet_len(0x1a0));
  5760. WFIFOW(fd,0)=0x1a0;
  5761. WFIFOB(fd,2)=data;
  5762. WFIFOSET(fd,packet_len(0x1a0));
  5763. }
  5764. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5765. /// 01a6 <packet len>.W { <index>.W }*
  5766. void clif_sendegg(struct map_session_data *sd)
  5767. {
  5768. int i,n=0,fd;
  5769. nullpo_retv(sd);
  5770. fd=sd->fd;
  5771. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5772. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5773. clif_displaymessage(fd, msg_txt(666));
  5774. return;
  5775. }
  5776. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5777. WFIFOW(fd,0)=0x1a6;
  5778. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5779. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5780. sd->inventory_data[i]->type!=IT_PETEGG ||
  5781. sd->status.inventory[i].amount<=0)
  5782. continue;
  5783. WFIFOW(fd,n*2+4)=i+2;
  5784. n++;
  5785. }
  5786. WFIFOW(fd,2)=4+n*2;
  5787. WFIFOSET(fd,WFIFOW(fd,2));
  5788. sd->menuskill_id = SA_TAMINGMONSTER;
  5789. sd->menuskill_val = -1;
  5790. }
  5791. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5792. /// 01a4 <type>.B <id>.L <data>.L
  5793. /// type:
  5794. /// 0 = pre-init (data = 0)
  5795. /// 1 = intimacy (data = 0~4)
  5796. /// 2 = hunger (data = 0~4)
  5797. /// 3 = accessory
  5798. /// 4 = performance (data = 1~3: normal, 4: special)
  5799. /// 5 = hairstyle
  5800. ///
  5801. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5802. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5803. {
  5804. uint8 buf[16];
  5805. nullpo_retv(pd);
  5806. WBUFW(buf,0) = 0x1a4;
  5807. WBUFB(buf,2) = type;
  5808. WBUFL(buf,3) = pd->bl.id;
  5809. WBUFL(buf,7) = param;
  5810. if (sd)
  5811. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5812. else
  5813. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5814. }
  5815. /// Pet's base data (ZC_PROPERTY_PET).
  5816. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5817. void clif_send_petstatus(struct map_session_data *sd)
  5818. {
  5819. int fd;
  5820. struct s_pet *pet;
  5821. nullpo_retv(sd);
  5822. nullpo_retv(sd->pd);
  5823. fd=sd->fd;
  5824. pet = &sd->pd->pet;
  5825. WFIFOHEAD(fd,packet_len(0x1a2));
  5826. WFIFOW(fd,0)=0x1a2;
  5827. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5828. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5829. WFIFOW(fd,27)=pet->level;
  5830. WFIFOW(fd,29)=pet->hungry;
  5831. WFIFOW(fd,31)=pet->intimate;
  5832. WFIFOW(fd,33)=pet->equip;
  5833. #if PACKETVER >= 20081126
  5834. WFIFOW(fd,35)=pet->class_;
  5835. #endif
  5836. WFIFOSET(fd,packet_len(0x1a2));
  5837. }
  5838. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5839. /// 01aa <id>.L <data>.L
  5840. /// data:
  5841. /// @see CZ_PET_ACT.
  5842. void clif_pet_emotion(struct pet_data *pd,int param)
  5843. {
  5844. unsigned char buf[16];
  5845. nullpo_retv(pd);
  5846. memset(buf,0,packet_len(0x1aa));
  5847. WBUFW(buf,0)=0x1aa;
  5848. WBUFL(buf,2)=pd->bl.id;
  5849. if(param >= 100 && pd->petDB->talk_convert_class) {
  5850. if(pd->petDB->talk_convert_class < 0)
  5851. return;
  5852. else if(pd->petDB->talk_convert_class > 0) {
  5853. // replace mob_id component of talk/act data
  5854. param -= (pd->pet.class_ - 100)*100;
  5855. param += (pd->petDB->talk_convert_class - 100)*100;
  5856. }
  5857. }
  5858. WBUFL(buf,6)=param;
  5859. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5860. }
  5861. /// Result of request to feed a pet (ZC_FEED_PET).
  5862. /// 01a3 <result>.B <name id>.W
  5863. /// result:
  5864. /// 0 = failure
  5865. /// 1 = success
  5866. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5867. {
  5868. int fd;
  5869. nullpo_retv(sd);
  5870. fd=sd->fd;
  5871. WFIFOHEAD(fd,packet_len(0x1a3));
  5872. WFIFOW(fd,0)=0x1a3;
  5873. WFIFOB(fd,2)=fail;
  5874. WFIFOW(fd,3)=foodid;
  5875. WFIFOSET(fd,packet_len(0x1a3));
  5876. }
  5877. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5878. /// 01cd { <skill id>.L }*7
  5879. void clif_autospell(struct map_session_data *sd,int skilllv)
  5880. {
  5881. int fd;
  5882. nullpo_retv(sd);
  5883. fd=sd->fd;
  5884. WFIFOHEAD(fd,packet_len(0x1cd));
  5885. WFIFOW(fd, 0)=0x1cd;
  5886. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5887. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5888. else
  5889. WFIFOL(fd,2)= 0x00000000;
  5890. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5891. WFIFOL(fd,6)= MG_COLDBOLT;
  5892. else
  5893. WFIFOL(fd,6)= 0x00000000;
  5894. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5895. WFIFOL(fd,10)= MG_FIREBOLT;
  5896. else
  5897. WFIFOL(fd,10)= 0x00000000;
  5898. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5899. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5900. else
  5901. WFIFOL(fd,14)= 0x00000000;
  5902. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5903. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5904. else
  5905. WFIFOL(fd,18)= 0x00000000;
  5906. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5907. WFIFOL(fd,22)= MG_FIREBALL;
  5908. else
  5909. WFIFOL(fd,22)= 0x00000000;
  5910. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5911. WFIFOL(fd,26)= MG_FROSTDIVER;
  5912. else
  5913. WFIFOL(fd,26)= 0x00000000;
  5914. WFIFOSET(fd,packet_len(0x1cd));
  5915. sd->menuskill_id = SA_AUTOSPELL;
  5916. sd->menuskill_val = skilllv;
  5917. }
  5918. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5919. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5920. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5921. {
  5922. unsigned char buf[56];
  5923. int i;
  5924. nullpo_retv(src);
  5925. memset(buf,0,packet_len(0x1cf));
  5926. WBUFW(buf,0) = 0x1cf;
  5927. WBUFL(buf,2) = src->id;
  5928. if( src->type == BL_MER )
  5929. {
  5930. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5931. if( md && md->master && md->devotion_flag )
  5932. WBUFL(buf,6) = md->master->bl.id;
  5933. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5934. }
  5935. else
  5936. {
  5937. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5938. if( sd == NULL )
  5939. return;
  5940. for( i = 0; i < 5; i++ )
  5941. WBUFL(buf,6+4*i) = sd->devotion[i];
  5942. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5943. }
  5944. if( tsd )
  5945. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5946. else
  5947. clif_send(buf, packet_len(0x1cf), src, AREA);
  5948. }
  5949. /// Notifies clients in an area of an object's spirits.
  5950. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  5951. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  5952. void clif_spiritball(struct map_session_data *sd)
  5953. {
  5954. unsigned char buf[8];
  5955. nullpo_retv(sd);
  5956. WBUFW(buf,0)=0x1d0;
  5957. WBUFL(buf,2)=sd->bl.id;
  5958. WBUFW(buf,6)=sd->spiritball;
  5959. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5960. }
  5961. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  5962. /// 01d2 <account id>.L <delay>.L
  5963. void clif_combo_delay(struct block_list *bl,int wait)
  5964. {
  5965. unsigned char buf[32];
  5966. nullpo_retv(bl);
  5967. WBUFW(buf,0)=0x1d2;
  5968. WBUFL(buf,2)=bl->id;
  5969. WBUFL(buf,6)=wait;
  5970. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5971. }
  5972. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  5973. /// 01d1 <src id>.L <dst id>.L <flag>.L
  5974. /// flag:
  5975. /// 0 = inactive
  5976. /// 1 = active
  5977. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5978. {
  5979. unsigned char buf[32];
  5980. nullpo_retv(src);
  5981. WBUFW(buf,0)=0x1d1;
  5982. WBUFL(buf,2)=src->id;
  5983. WBUFL(buf,6)=dst_id;
  5984. WBUFL(buf,10)=active;
  5985. clif_send(buf,packet_len(0x1d1),src,AREA);
  5986. }
  5987. /// MVP effect (ZC_MVP).
  5988. /// 010c <account id>.L
  5989. void clif_mvp_effect(struct map_session_data *sd)
  5990. {
  5991. unsigned char buf[16];
  5992. nullpo_retv(sd);
  5993. WBUFW(buf,0)=0x10c;
  5994. WBUFL(buf,2)=sd->bl.id;
  5995. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5996. }
  5997. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  5998. /// 010a <name id>.W
  5999. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6000. {
  6001. int view,fd;
  6002. nullpo_retv(sd);
  6003. fd=sd->fd;
  6004. WFIFOHEAD(fd,packet_len(0x10a));
  6005. WFIFOW(fd,0)=0x10a;
  6006. if((view = itemdb_viewid(nameid)) > 0)
  6007. WFIFOW(fd,2)=view;
  6008. else
  6009. WFIFOW(fd,2)=nameid;
  6010. WFIFOSET(fd,packet_len(0x10a));
  6011. }
  6012. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6013. /// 010b <exp>.L
  6014. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6015. {
  6016. int fd;
  6017. nullpo_retv(sd);
  6018. fd=sd->fd;
  6019. WFIFOHEAD(fd,packet_len(0x10b));
  6020. WFIFOW(fd,0)=0x10b;
  6021. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6022. WFIFOSET(fd,packet_len(0x10b));
  6023. }
  6024. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6025. /// 010d
  6026. ///
  6027. /// "You are the MVP, but cannot obtain the reward because
  6028. /// you are overweight."
  6029. void clif_mvp_noitem(struct map_session_data* sd)
  6030. {
  6031. int fd = sd->fd;
  6032. WFIFOHEAD(fd,packet_len(0x10d));
  6033. WFIFOW(fd,0) = 0x10d;
  6034. WFIFOSET(fd,packet_len(0x10d));
  6035. }
  6036. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6037. /// 0167 <result>.B
  6038. /// result:
  6039. /// 0 = "Guild has been created."
  6040. /// 1 = "You are already in a Guild."
  6041. /// 2 = "That Guild Name already exists."
  6042. /// 3 = "You need the neccessary item to create a Guild."
  6043. void clif_guild_created(struct map_session_data *sd,int flag)
  6044. {
  6045. int fd;
  6046. nullpo_retv(sd);
  6047. fd=sd->fd;
  6048. WFIFOHEAD(fd,packet_len(0x167));
  6049. WFIFOW(fd,0)=0x167;
  6050. WFIFOB(fd,2)=flag;
  6051. WFIFOSET(fd,packet_len(0x167));
  6052. }
  6053. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6054. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6055. /// mode:
  6056. /// &0x01 = allow invite
  6057. /// &0x10 = allow expel
  6058. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6059. {
  6060. int ps,fd;
  6061. nullpo_retv(sd);
  6062. nullpo_retv(g);
  6063. fd=sd->fd;
  6064. ps=guild_getposition(g,sd);
  6065. WFIFOHEAD(fd,packet_len(0x16c));
  6066. WFIFOW(fd,0)=0x16c;
  6067. WFIFOL(fd,2)=g->guild_id;
  6068. WFIFOL(fd,6)=g->emblem_id;
  6069. WFIFOL(fd,10)=g->position[ps].mode;
  6070. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6071. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6072. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6073. WFIFOSET(fd,packet_len(0x16c));
  6074. }
  6075. /// Guild member login notice.
  6076. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6077. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6078. /// status:
  6079. /// 0 = offline
  6080. /// 1 = online
  6081. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6082. {
  6083. unsigned char buf[64];
  6084. struct map_session_data* sd;
  6085. nullpo_retv(g);
  6086. WBUFW(buf, 0)=0x1f2;
  6087. WBUFL(buf, 2)=g->member[idx].account_id;
  6088. WBUFL(buf, 6)=g->member[idx].char_id;
  6089. WBUFL(buf,10)=flag;
  6090. if( ( sd = g->member[idx].sd ) != NULL )
  6091. {
  6092. WBUFW(buf,14) = sd->status.sex;
  6093. WBUFW(buf,16) = sd->status.hair;
  6094. WBUFW(buf,18) = sd->status.hair_color;
  6095. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6096. }
  6097. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6098. {
  6099. WBUFW(buf,14) = 0;
  6100. WBUFW(buf,16) = 0;
  6101. WBUFW(buf,18) = 0;
  6102. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6103. }
  6104. }
  6105. // Function `clif_guild_memberlogin_notice` sends info about
  6106. // logins and logouts of a guild member to the rest members.
  6107. // But at the 1st time (after a player login or map changing)
  6108. // the client won't show the message.
  6109. // So I suggest use this function for sending "first-time-info"
  6110. // to some player on entering the game or changing location.
  6111. // At next time the client would always show the message.
  6112. // The function sends all the statuses in the single packet
  6113. // to economize traffic. [LuzZza]
  6114. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6115. {
  6116. struct guild *g;
  6117. unsigned char buf[14*128];
  6118. int i, count=0, p_len;
  6119. nullpo_retv(sd);
  6120. p_len = packet_len(0x16d);
  6121. if(!(g = guild_search(sd->status.guild_id)))
  6122. return;
  6123. for(i=0; i<g->max_member; i++) {
  6124. if(g->member[i].account_id > 0 &&
  6125. g->member[i].account_id != sd->status.account_id) {
  6126. WBUFW(buf,count*p_len) = 0x16d;
  6127. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6128. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6129. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6130. count++;
  6131. }
  6132. }
  6133. clif_send(buf, p_len*count, &sd->bl, SELF);
  6134. }
  6135. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6136. /// 014e <menu flag>.L
  6137. /// menu flag:
  6138. /// 0x00 = Basic Info (always on)
  6139. /// &0x01 = Member manager
  6140. /// &0x02 = Positions
  6141. /// &0x04 = Skills
  6142. /// &0x10 = Expulsion list
  6143. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6144. /// &0x80 = Notice
  6145. void clif_guild_masterormember(struct map_session_data *sd)
  6146. {
  6147. int fd;
  6148. nullpo_retv(sd);
  6149. fd=sd->fd;
  6150. WFIFOHEAD(fd,packet_len(0x14e));
  6151. WFIFOW(fd,0) = 0x14e;
  6152. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6153. WFIFOSET(fd,packet_len(0x14e));
  6154. }
  6155. /// Guild basic information (Territories [Valaris])
  6156. /// 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)
  6157. /// 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)
  6158. void clif_guild_basicinfo(struct map_session_data *sd) {
  6159. int fd;
  6160. struct guild *g;
  6161. nullpo_retv(sd);
  6162. fd = sd->fd;
  6163. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6164. return;
  6165. WFIFOHEAD(fd,packet_len(0x1b6));
  6166. WFIFOW(fd, 0)=0x1b6;//0x150;
  6167. WFIFOL(fd, 2)=g->guild_id;
  6168. WFIFOL(fd, 6)=g->guild_lv;
  6169. WFIFOL(fd,10)=g->connect_member;
  6170. WFIFOL(fd,14)=g->max_member;
  6171. WFIFOL(fd,18)=g->average_lv;
  6172. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6173. WFIFOL(fd,26)=g->next_exp;
  6174. WFIFOL(fd,30)=0; // Tax Points
  6175. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6176. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6177. WFIFOL(fd,42)=g->emblem_id;
  6178. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6179. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6180. safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
  6181. WFIFOL(fd,110) = 0; // zeny
  6182. WFIFOSET(fd,packet_len(0x1b6));
  6183. }
  6184. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6185. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6186. void clif_guild_allianceinfo(struct map_session_data *sd)
  6187. {
  6188. int fd,i,c;
  6189. struct guild *g;
  6190. nullpo_retv(sd);
  6191. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6192. return;
  6193. fd = sd->fd;
  6194. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6195. WFIFOW(fd, 0)=0x14c;
  6196. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6197. struct guild_alliance *a=&g->alliance[i];
  6198. if(a->guild_id>0){
  6199. WFIFOL(fd,c*32+4)=a->opposition;
  6200. WFIFOL(fd,c*32+8)=a->guild_id;
  6201. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6202. c++;
  6203. }
  6204. }
  6205. WFIFOW(fd, 2)=c*32+4;
  6206. WFIFOSET(fd,WFIFOW(fd,2));
  6207. }
  6208. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6209. /// 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 }*
  6210. /// state:
  6211. /// 0 = offline
  6212. /// 1 = online
  6213. /// memo:
  6214. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6215. void clif_guild_memberlist(struct map_session_data *sd)
  6216. {
  6217. int fd;
  6218. int i,c;
  6219. struct guild *g;
  6220. nullpo_retv(sd);
  6221. if( (fd = sd->fd) == 0 )
  6222. return;
  6223. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6224. return;
  6225. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6226. WFIFOW(fd, 0)=0x154;
  6227. for(i=0,c=0;i<g->max_member;i++){
  6228. struct guild_member *m=&g->member[i];
  6229. if(m->account_id==0)
  6230. continue;
  6231. WFIFOL(fd,c*104+ 4)=m->account_id;
  6232. WFIFOL(fd,c*104+ 8)=m->char_id;
  6233. WFIFOW(fd,c*104+12)=m->hair;
  6234. WFIFOW(fd,c*104+14)=m->hair_color;
  6235. WFIFOW(fd,c*104+16)=m->gender;
  6236. WFIFOW(fd,c*104+18)=m->class_;
  6237. WFIFOW(fd,c*104+20)=m->lv;
  6238. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6239. WFIFOL(fd,c*104+26)=m->online;
  6240. WFIFOL(fd,c*104+30)=m->position;
  6241. 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.
  6242. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6243. c++;
  6244. }
  6245. WFIFOW(fd, 2)=c*104+4;
  6246. WFIFOSET(fd,WFIFOW(fd,2));
  6247. }
  6248. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6249. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6250. void clif_guild_positionnamelist(struct map_session_data *sd)
  6251. {
  6252. int i,fd;
  6253. struct guild *g;
  6254. nullpo_retv(sd);
  6255. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6256. return;
  6257. fd = sd->fd;
  6258. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6259. WFIFOW(fd, 0)=0x166;
  6260. for(i=0;i<MAX_GUILDPOSITION;i++){
  6261. WFIFOL(fd,i*28+4)=i;
  6262. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6263. }
  6264. WFIFOW(fd,2)=i*28+4;
  6265. WFIFOSET(fd,WFIFOW(fd,2));
  6266. }
  6267. /// Guild position information (ZC_POSITION_INFO).
  6268. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6269. /// mode:
  6270. /// &0x01 = allow invite
  6271. /// &0x10 = allow expel
  6272. /// ranking:
  6273. /// TODO
  6274. void clif_guild_positioninfolist(struct map_session_data *sd)
  6275. {
  6276. int i,fd;
  6277. struct guild *g;
  6278. nullpo_retv(sd);
  6279. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6280. return;
  6281. fd = sd->fd;
  6282. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6283. WFIFOW(fd, 0)=0x160;
  6284. for(i=0;i<MAX_GUILDPOSITION;i++){
  6285. struct guild_position *p=&g->position[i];
  6286. WFIFOL(fd,i*16+ 4)=i;
  6287. WFIFOL(fd,i*16+ 8)=p->mode;
  6288. WFIFOL(fd,i*16+12)=i;
  6289. WFIFOL(fd,i*16+16)=p->exp_mode;
  6290. }
  6291. WFIFOW(fd, 2)=i*16+4;
  6292. WFIFOSET(fd,WFIFOW(fd,2));
  6293. }
  6294. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6295. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6296. /// mode:
  6297. /// &0x01 = allow invite
  6298. /// &0x10 = allow expel
  6299. /// ranking:
  6300. /// TODO
  6301. void clif_guild_positionchanged(struct guild *g,int idx)
  6302. {
  6303. // FIXME: This packet is intended to update the clients after a
  6304. // commit of position info changes, not sending one packet per
  6305. // position.
  6306. struct map_session_data *sd;
  6307. unsigned char buf[128];
  6308. nullpo_retv(g);
  6309. WBUFW(buf, 0)=0x174;
  6310. WBUFW(buf, 2)=44; // packet len
  6311. // GUILD_REG_POSITION_INFO{
  6312. WBUFL(buf, 4)=idx;
  6313. WBUFL(buf, 8)=g->position[idx].mode;
  6314. WBUFL(buf,12)=idx;
  6315. WBUFL(buf,16)=g->position[idx].exp_mode;
  6316. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6317. // }*
  6318. if( (sd=guild_getavailablesd(g))!=NULL )
  6319. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6320. }
  6321. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6322. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6323. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6324. {
  6325. // FIXME: This packet is intended to update the clients after a
  6326. // commit of member position assignment changes, not sending one
  6327. // packet per position.
  6328. struct map_session_data *sd;
  6329. unsigned char buf[64];
  6330. nullpo_retv(g);
  6331. WBUFW(buf, 0)=0x156;
  6332. WBUFW(buf, 2)=16; // packet len
  6333. // MEMBER_POSITION_INFO{
  6334. WBUFL(buf, 4)=g->member[idx].account_id;
  6335. WBUFL(buf, 8)=g->member[idx].char_id;
  6336. WBUFL(buf,12)=g->member[idx].position;
  6337. // }*
  6338. if( (sd=guild_getavailablesd(g))!=NULL )
  6339. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6340. }
  6341. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6342. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6343. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6344. {
  6345. int fd;
  6346. nullpo_retv(sd);
  6347. nullpo_retv(g);
  6348. fd = sd->fd;
  6349. if( g->emblem_len <= 0 )
  6350. return;
  6351. WFIFOHEAD(fd,g->emblem_len+12);
  6352. WFIFOW(fd,0)=0x152;
  6353. WFIFOW(fd,2)=g->emblem_len+12;
  6354. WFIFOL(fd,4)=g->guild_id;
  6355. WFIFOL(fd,8)=g->emblem_id;
  6356. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6357. WFIFOSET(fd,WFIFOW(fd,2));
  6358. }
  6359. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6360. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6361. void clif_guild_emblem_area(struct block_list* bl)
  6362. {
  6363. uint8 buf[12];
  6364. nullpo_retv(bl);
  6365. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6366. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6367. WBUFW(buf,0) = 0x1b4;
  6368. WBUFL(buf,2) = bl->id;
  6369. WBUFL(buf,6) = status_get_guild_id(bl);
  6370. WBUFW(buf,10) = status_get_emblem_id(bl);
  6371. clif_send(buf, 12, bl, AREA_WOS);
  6372. }
  6373. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6374. /// 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 }*
  6375. void clif_guild_skillinfo(struct map_session_data* sd)
  6376. {
  6377. int fd;
  6378. struct guild* g;
  6379. int i,c;
  6380. nullpo_retv(sd);
  6381. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6382. return;
  6383. fd = sd->fd;
  6384. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6385. WFIFOW(fd,0) = 0x0162;
  6386. WFIFOW(fd,4) = g->skill_point;
  6387. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6388. {
  6389. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6390. {
  6391. int id = g->skill[i].id;
  6392. int p = 6 + c*37;
  6393. WFIFOW(fd,p+0) = id;
  6394. WFIFOL(fd,p+2) = skill_get_inf(id);
  6395. WFIFOW(fd,p+6) = g->skill[i].lv;
  6396. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6397. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6398. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6399. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6400. c++;
  6401. }
  6402. }
  6403. WFIFOW(fd,2) = 6 + c*37;
  6404. WFIFOSET(fd,WFIFOW(fd,2));
  6405. }
  6406. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6407. /// 016f <subject>.60B <notice>.120B
  6408. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6409. {
  6410. int fd;
  6411. nullpo_retv(sd);
  6412. nullpo_retv(g);
  6413. fd = sd->fd;
  6414. if ( !session_isActive(fd) )
  6415. return;
  6416. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6417. return;
  6418. WFIFOHEAD(fd,packet_len(0x16f));
  6419. WFIFOW(fd,0) = 0x16f;
  6420. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6421. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6422. WFIFOSET(fd,packet_len(0x16f));
  6423. }
  6424. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6425. /// 016a <guild id>.L <guild name>.24B
  6426. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6427. {
  6428. int fd;
  6429. nullpo_retv(sd);
  6430. nullpo_retv(g);
  6431. fd=sd->fd;
  6432. WFIFOHEAD(fd,packet_len(0x16a));
  6433. WFIFOW(fd,0)=0x16a;
  6434. WFIFOL(fd,2)=g->guild_id;
  6435. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6436. WFIFOSET(fd,packet_len(0x16a));
  6437. }
  6438. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6439. /// 0169 <answer>.B
  6440. /// answer:
  6441. /// 0 = Already in guild.
  6442. /// 1 = Offer rejected.
  6443. /// 2 = Offer accepted.
  6444. /// 3 = Guild full.
  6445. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6446. {
  6447. int fd;
  6448. nullpo_retv(sd);
  6449. fd=sd->fd;
  6450. WFIFOHEAD(fd,packet_len(0x169));
  6451. WFIFOW(fd,0)=0x169;
  6452. WFIFOB(fd,2)=flag;
  6453. WFIFOSET(fd,packet_len(0x169));
  6454. }
  6455. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6456. /// 015a <char name>.24B <reason>.40B
  6457. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6458. {
  6459. unsigned char buf[128];
  6460. nullpo_retv(sd);
  6461. WBUFW(buf, 0)=0x15a;
  6462. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6463. memcpy(WBUFP(buf,26),mes,40);
  6464. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6465. }
  6466. /// Notifies clients of a guild of an expelled member.
  6467. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6468. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6469. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6470. {
  6471. unsigned char buf[128];
  6472. #if PACKETVER < 20100803
  6473. const unsigned short cmd = 0x15c;
  6474. #else
  6475. const unsigned short cmd = 0x839;
  6476. #endif
  6477. nullpo_retv(sd);
  6478. WBUFW(buf,0) = cmd;
  6479. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6480. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6481. #if PACKETVER < 20100803
  6482. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6483. #endif
  6484. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6485. }
  6486. /// Guild expulsion list (ZC_BAN_LIST).
  6487. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6488. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6489. void clif_guild_expulsionlist(struct map_session_data* sd)
  6490. {
  6491. #if PACKETVER < 20100803
  6492. const int offset = NAME_LENGTH*2+40;
  6493. #else
  6494. const int offset = NAME_LENGTH+40;
  6495. #endif
  6496. int fd, i, c = 0;
  6497. struct guild* g;
  6498. nullpo_retv(sd);
  6499. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6500. return;
  6501. fd = sd->fd;
  6502. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6503. WFIFOW(fd,0) = 0x163;
  6504. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6505. {
  6506. struct guild_expulsion* e = &g->expulsion[i];
  6507. if( e->account_id > 0 )
  6508. {
  6509. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6510. #if PACKETVER < 20100803
  6511. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6512. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6513. #else
  6514. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6515. #endif
  6516. c++;
  6517. }
  6518. }
  6519. WFIFOW(fd,2) = 4 + c*offset;
  6520. WFIFOSET(fd,WFIFOW(fd,2));
  6521. }
  6522. /// Guild chat message (ZC_GUILD_CHAT).
  6523. /// 017f <packet len>.W <message>.?B
  6524. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6525. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6526. struct map_session_data *sd;
  6527. uint8 buf[256];
  6528. if( len == 0 )
  6529. {
  6530. return;
  6531. }
  6532. else if( len > sizeof(buf)-5 )
  6533. {
  6534. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6535. len = sizeof(buf)-5;
  6536. }
  6537. WBUFW(buf, 0) = 0x17f;
  6538. WBUFW(buf, 2) = len + 5;
  6539. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6540. if ((sd = guild_getavailablesd(g)) != NULL)
  6541. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6542. }
  6543. /*==========================================
  6544. * Server tells client 'sd' that his guild skill 'skill_num' gone to level 'lv'
  6545. *------------------------------------------*/
  6546. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6547. {// TODO: Merge with clif_skillup (same packet).
  6548. int fd;
  6549. nullpo_ret(sd);
  6550. fd=sd->fd;
  6551. WFIFOHEAD(fd,11);
  6552. WFIFOW(fd,0) = 0x10e;
  6553. WFIFOW(fd,2) = skill_num;
  6554. WFIFOW(fd,4) = lv;
  6555. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6556. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6557. WFIFOB(fd,10) = 1;
  6558. WFIFOSET(fd,11);
  6559. return 0;
  6560. }
  6561. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6562. /// 0171 <inviter account id>.L <guild name>.24B
  6563. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6564. {
  6565. int fd;
  6566. nullpo_retv(sd);
  6567. fd=sd->fd;
  6568. WFIFOHEAD(fd,packet_len(0x171));
  6569. WFIFOW(fd,0)=0x171;
  6570. WFIFOL(fd,2)=account_id;
  6571. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6572. WFIFOSET(fd,packet_len(0x171));
  6573. }
  6574. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6575. /// 0173 <answer>.B
  6576. /// answer:
  6577. /// 0 = Already allied.
  6578. /// 1 = You rejected the offer.
  6579. /// 2 = You accepted the offer.
  6580. /// 3 = They have too any alliances.
  6581. /// 4 = You have too many alliances.
  6582. /// 5 = Alliances are disabled.
  6583. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6584. {
  6585. int fd;
  6586. nullpo_retv(sd);
  6587. fd=sd->fd;
  6588. WFIFOHEAD(fd,packet_len(0x173));
  6589. WFIFOW(fd,0)=0x173;
  6590. WFIFOL(fd,2)=flag;
  6591. WFIFOSET(fd,packet_len(0x173));
  6592. }
  6593. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6594. /// 0184 <other guild id>.L <relation>.L
  6595. /// relation:
  6596. /// 0 = Ally
  6597. /// 1 = Enemy
  6598. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6599. {
  6600. int fd;
  6601. nullpo_retv(sd);
  6602. fd = sd->fd;
  6603. if (fd <= 0)
  6604. return;
  6605. WFIFOHEAD(fd,packet_len(0x184));
  6606. WFIFOW(fd,0)=0x184;
  6607. WFIFOL(fd,2)=guild_id;
  6608. WFIFOL(fd,6)=flag;
  6609. WFIFOSET(fd,packet_len(0x184));
  6610. }
  6611. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6612. /// 0181 <result>.B
  6613. /// result:
  6614. /// 0 = Antagonist has been set.
  6615. /// 1 = Guild has too many Antagonists.
  6616. /// 2 = Already set as an Antagonist.
  6617. /// 3 = Antagonists are disabled.
  6618. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6619. {
  6620. int fd;
  6621. nullpo_retv(sd);
  6622. fd=sd->fd;
  6623. WFIFOHEAD(fd,packet_len(0x181));
  6624. WFIFOW(fd,0)=0x181;
  6625. WFIFOB(fd,2)=flag;
  6626. WFIFOSET(fd,packet_len(0x181));
  6627. }
  6628. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6629. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6630. /*
  6631. void clif_guild_allianceadded(struct guild *g,int idx)
  6632. {
  6633. unsigned char buf[64];
  6634. WBUFW(buf,0)=0x185;
  6635. WBUFL(buf,2)=g->alliance[idx].opposition;
  6636. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6637. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6638. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6639. }
  6640. */
  6641. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6642. /// 015e <reason>.L
  6643. /// 0 = success
  6644. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6645. /// 2 = there are still members in the guild
  6646. void clif_guild_broken(struct map_session_data *sd,int flag)
  6647. {
  6648. int fd;
  6649. nullpo_retv(sd);
  6650. fd=sd->fd;
  6651. WFIFOHEAD(fd,packet_len(0x15e));
  6652. WFIFOW(fd,0)=0x15e;
  6653. WFIFOL(fd,2)=flag;
  6654. WFIFOSET(fd,packet_len(0x15e));
  6655. }
  6656. /// Displays emotion on an object (ZC_EMOTION).
  6657. /// 00c0 <id>.L <type>.B
  6658. /// type:
  6659. /// enum emotion_type
  6660. void clif_emotion(struct block_list *bl,int type)
  6661. {
  6662. unsigned char buf[8];
  6663. nullpo_retv(bl);
  6664. WBUFW(buf,0)=0xc0;
  6665. WBUFL(buf,2)=bl->id;
  6666. WBUFB(buf,6)=type;
  6667. clif_send(buf,packet_len(0xc0),bl,AREA);
  6668. }
  6669. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6670. /// 0191 <id>.L <contents>.80B
  6671. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6672. {
  6673. unsigned char buf[MESSAGE_SIZE+6];
  6674. nullpo_retv(bl);
  6675. WBUFW(buf,0) = 0x191;
  6676. WBUFL(buf,2) = bl->id;
  6677. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6678. clif_send(buf,packet_len(0x191),bl,AREA);
  6679. }
  6680. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6681. /// 01ea <id>.L
  6682. void clif_wedding_effect(struct block_list *bl)
  6683. {
  6684. unsigned char buf[6];
  6685. nullpo_retv(bl);
  6686. WBUFW(buf,0) = 0x1ea;
  6687. WBUFL(buf,2) = bl->id;
  6688. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6689. }
  6690. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6691. /// 01e6 <partner name>.24B
  6692. void clif_callpartner(struct map_session_data *sd)
  6693. {
  6694. unsigned char buf[26];
  6695. const char *p;
  6696. nullpo_retv(sd);
  6697. WBUFW(buf,0) = 0x1e6;
  6698. if( sd->status.partner_id )
  6699. {
  6700. if( ( p = map_charid2nick(sd->status.partner_id) ) != NULL )
  6701. {
  6702. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  6703. }
  6704. else
  6705. {
  6706. WBUFB(buf,2) = 0;
  6707. }
  6708. }
  6709. else
  6710. {// Send zero-length name if no partner, to initialize the client buffer.
  6711. WBUFB(buf,2) = 0;
  6712. }
  6713. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  6714. }
  6715. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6716. /// 01e4
  6717. /// This packet while still implemented by the client is no longer being officially used.
  6718. /*
  6719. void clif_marriage_process(struct map_session_data *sd)
  6720. {
  6721. int fd;
  6722. nullpo_retv(sd);
  6723. fd=sd->fd;
  6724. WFIFOHEAD(fd,packet_len(0x1e4));
  6725. WFIFOW(fd,0)=0x1e4;
  6726. WFIFOSET(fd,packet_len(0x1e4));
  6727. }
  6728. */
  6729. /// Notice of divorce (ZC_DIVORCE).
  6730. /// 0205 <partner name>.24B
  6731. void clif_divorced(struct map_session_data* sd, const char* name)
  6732. {
  6733. int fd;
  6734. nullpo_retv(sd);
  6735. fd=sd->fd;
  6736. WFIFOHEAD(fd,packet_len(0x205));
  6737. WFIFOW(fd,0)=0x205;
  6738. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6739. WFIFOSET(fd, packet_len(0x205));
  6740. }
  6741. /// Marriage proposal (ZC_REQ_COUPLE).
  6742. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6743. /// This packet while still implemented by the client is no longer being officially used.
  6744. /*
  6745. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6746. {
  6747. nullpo_retv(sd);
  6748. WFIFOHEAD(fd,packet_len(0x1e2));
  6749. WFIFOW(fd,0) = 0x1e2;
  6750. WFIFOL(fd,2) = ssd->status.account_id;
  6751. WFIFOL(fd,6) = ssd->status.char_id;
  6752. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6753. WFIFOSET(fd, packet_len(0x1e2));
  6754. }
  6755. */
  6756. /*==========================================
  6757. *
  6758. *------------------------------------------*/
  6759. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6760. {
  6761. clif_disp_message(&sd->bl, mes, len, SELF);
  6762. }
  6763. /*==========================================
  6764. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6765. *------------------------------------------*/
  6766. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6767. {
  6768. unsigned char buf[256];
  6769. if( len == 0 )
  6770. {
  6771. return;
  6772. }
  6773. else if( len > sizeof(buf)-5 )
  6774. {
  6775. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6776. len = sizeof(buf)-5;
  6777. }
  6778. WBUFW(buf, 0) = 0x17f;
  6779. WBUFW(buf, 2) = len + 5;
  6780. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6781. clif_send(buf, WBUFW(buf,2), src, target);
  6782. }
  6783. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6784. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6785. /// 00cd <result>.B
  6786. /// result:
  6787. /// 0 = failure
  6788. /// 1 = success
  6789. void clif_GM_kickack(struct map_session_data *sd, int id)
  6790. {
  6791. int fd;
  6792. nullpo_retv(sd);
  6793. fd = sd->fd;
  6794. WFIFOHEAD(fd,packet_len(0xcd));
  6795. WFIFOW(fd,0) = 0xcd;
  6796. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6797. WFIFOSET(fd, packet_len(0xcd));
  6798. }
  6799. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6800. {
  6801. int fd = tsd->fd;
  6802. if( fd > 0 )
  6803. clif_authfail_fd(fd, 15);
  6804. else
  6805. map_quit(tsd);
  6806. if( sd )
  6807. clif_GM_kickack(sd,tsd->status.account_id);
  6808. }
  6809. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6810. /// 014a <result>.L
  6811. /// result:
  6812. /// 0 = "A manner point has been successfully aligned."
  6813. /// 1 = MP_FAILURE_EXHAUST
  6814. /// 2 = MP_FAILURE_ALREADY_GIVING
  6815. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6816. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6817. /// 5 = "You got a good point from %s."
  6818. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6819. {
  6820. int fd;
  6821. nullpo_retv(sd);
  6822. fd = sd->fd;
  6823. WFIFOHEAD(fd,packet_len(0x14a));
  6824. WFIFOW(fd,0) = 0x14a;
  6825. WFIFOL(fd,2) = type;
  6826. WFIFOSET(fd, packet_len(0x14a));
  6827. }
  6828. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6829. /// 014b <type>.B <GM name>.24B
  6830. /// type:
  6831. /// 0 = positive (unmute)
  6832. /// 1 = negative (mute)
  6833. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6834. {
  6835. int fd;
  6836. nullpo_retv(sd);
  6837. nullpo_retv(tsd);
  6838. fd = tsd->fd;
  6839. WFIFOHEAD(fd,packet_len(0x14b));
  6840. WFIFOW(fd,0) = 0x14b;
  6841. WFIFOB(fd,2) = type;
  6842. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6843. WFIFOSET(fd, packet_len(0x14b));
  6844. }
  6845. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6846. /// 00d1 <type>.B <result>.B
  6847. /// type:
  6848. /// 0 = /ex (deny)
  6849. /// 1 = /in (allow)
  6850. /// result:
  6851. /// 0 = success
  6852. /// 1 = failure
  6853. /// 2 = too many blocks
  6854. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6855. {
  6856. int fd;
  6857. nullpo_retv(sd);
  6858. fd=sd->fd;
  6859. WFIFOHEAD(fd,packet_len(0xd1));
  6860. WFIFOW(fd,0)=0xd1;
  6861. WFIFOB(fd,2)=type;
  6862. WFIFOB(fd,3)=flag;
  6863. WFIFOSET(fd,packet_len(0xd1));
  6864. }
  6865. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6866. /// 00d2 <type>.B <result>.B
  6867. /// type:
  6868. /// 0 = /exall (deny)
  6869. /// 1 = /inall (allow)
  6870. /// result:
  6871. /// 0 = success
  6872. /// 1 = failure
  6873. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6874. {
  6875. int fd;
  6876. nullpo_retv(sd);
  6877. fd=sd->fd;
  6878. WFIFOHEAD(fd,packet_len(0xd2));
  6879. WFIFOW(fd,0)=0xd2;
  6880. WFIFOB(fd,2)=type;
  6881. WFIFOB(fd,3)=flag;
  6882. WFIFOSET(fd,packet_len(0xd2));
  6883. }
  6884. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6885. /// 07fe <bgm>.24B
  6886. void clif_playBGM(struct map_session_data* sd, const char* name)
  6887. {
  6888. int fd;
  6889. nullpo_retv(sd);
  6890. fd = sd->fd;
  6891. WFIFOHEAD(fd,packet_len(0x7fe));
  6892. WFIFOW(fd,0) = 0x7fe;
  6893. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6894. WFIFOSET(fd,packet_len(0x7fe));
  6895. }
  6896. /// Plays/stops a wave sound (ZC_SOUND).
  6897. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6898. /// file name:
  6899. /// relative to data\wav
  6900. /// act:
  6901. /// 0 = play (once)
  6902. /// 1 = play (repeat, does not work)
  6903. /// 2 = stops all sound instances of file name (does not work)
  6904. /// term:
  6905. /// unknown purpose, only relevant to act = 1
  6906. /// npc id:
  6907. /// The accustic direction of the sound is determined by the
  6908. /// relative position of the NPC to the player (3D sound).
  6909. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6910. {
  6911. int fd;
  6912. nullpo_retv(sd);
  6913. nullpo_retv(bl);
  6914. fd = sd->fd;
  6915. WFIFOHEAD(fd,packet_len(0x1d3));
  6916. WFIFOW(fd,0) = 0x1d3;
  6917. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6918. WFIFOB(fd,26) = type;
  6919. WFIFOL(fd,27) = 0;
  6920. WFIFOL(fd,31) = bl->id;
  6921. WFIFOSET(fd,packet_len(0x1d3));
  6922. }
  6923. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6924. {
  6925. unsigned char buf[40];
  6926. nullpo_retv(bl);
  6927. WBUFW(buf,0) = 0x1d3;
  6928. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6929. WBUFB(buf,26) = type;
  6930. WBUFL(buf,27) = 0;
  6931. WBUFL(buf,31) = bl->id;
  6932. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6933. }
  6934. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6935. /// 01f3 <id>.L <effect id>.L
  6936. /// effect id:
  6937. /// @see doc/effect_list.txt
  6938. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6939. {
  6940. unsigned char buf[24];
  6941. nullpo_retv(bl);
  6942. memset(buf, 0, packet_len(0x1f3));
  6943. WBUFW(buf,0) = 0x1f3;
  6944. WBUFL(buf,2) = bl->id;
  6945. WBUFL(buf,6) = type;
  6946. clif_send(buf, packet_len(0x1f3), bl, target);
  6947. if (disguised(bl)) {
  6948. WBUFL(buf,2) = -bl->id;
  6949. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6950. }
  6951. }
  6952. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6953. {
  6954. WFIFOHEAD(fd,10);
  6955. WFIFOW(fd,0) = 0x1f3;
  6956. WFIFOL(fd,2) = bl->id;
  6957. WFIFOL(fd,6) = type;
  6958. WFIFOSET(fd,10);
  6959. }
  6960. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  6961. /// 0284 <id>.L <effect id>.L <num data>.L
  6962. /// effect id:
  6963. /// @see doc/effect_list.txt
  6964. /// num data:
  6965. /// effect-dependent value
  6966. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  6967. {
  6968. uint8 buf[14];
  6969. WBUFW(buf,0) = 0x284;
  6970. WBUFL(buf,2) = bl->id;
  6971. WBUFL(buf,6) = effect_id;
  6972. WBUFL(buf,10) = num;
  6973. clif_send(buf, packet_len(0x284), bl, target);
  6974. if( disguised(bl) )
  6975. {
  6976. WBUFL(buf,2) = -bl->id;
  6977. clif_send(buf, packet_len(0x284), bl, SELF);
  6978. }
  6979. }
  6980. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  6981. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6982. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  6983. unsigned short msg_len = strlen(msg) + 1;
  6984. WFIFOHEAD(sd->fd,msg_len + 12);
  6985. WFIFOW(sd->fd,0) = 0x2C1;
  6986. WFIFOW(sd->fd,2) = msg_len + 12;
  6987. WFIFOL(sd->fd,4) = 0;
  6988. WFIFOL(sd->fd,8) = color_table[color];
  6989. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  6990. clif_send(WFIFOP(sd->fd,0), WFIFOW(sd->fd,2), &sd->bl, SELF);
  6991. return 0;
  6992. }
  6993. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  6994. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6995. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  6996. unsigned short msg_len = strlen(msg) + 1;
  6997. uint8 buf[256];
  6998. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6999. nullpo_retv(bl);
  7000. if( msg_len > sizeof(buf)-12 )
  7001. {
  7002. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7003. msg_len = sizeof(buf)-12;
  7004. }
  7005. WBUFW(buf,0) = 0x2C1;
  7006. WBUFW(buf,2) = msg_len + 12;
  7007. WBUFL(buf,4) = bl->id;
  7008. WBUFL(buf,8) = color;
  7009. memcpy(WBUFP(buf,12), msg, msg_len);
  7010. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7011. }
  7012. /// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  7013. /// 008d <packet len>.W <id>.L <message>.?B
  7014. void clif_message(struct block_list* bl, const char* msg)
  7015. {
  7016. unsigned short msg_len = strlen(msg) + 1;
  7017. uint8 buf[256];
  7018. // TODO: Merge with other 0x8d functions.
  7019. nullpo_retv(bl);
  7020. if( msg_len > sizeof(buf)-8 )
  7021. {
  7022. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7023. msg_len = sizeof(buf)-8;
  7024. }
  7025. WBUFW(buf,0) = 0x8d;
  7026. WBUFW(buf,2) = msg_len + 8;
  7027. WBUFL(buf,4) = bl->id;
  7028. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  7029. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7030. }
  7031. // refresh the client's screen, getting rid of any effects
  7032. void clif_refresh(struct map_session_data *sd)
  7033. {
  7034. nullpo_retv(sd);
  7035. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7036. clif_inventorylist(sd);
  7037. if(pc_iscarton(sd)) {
  7038. clif_cartlist(sd);
  7039. clif_updatestatus(sd,SP_CARTINFO);
  7040. }
  7041. clif_updatestatus(sd,SP_WEIGHT);
  7042. clif_updatestatus(sd,SP_MAXWEIGHT);
  7043. clif_updatestatus(sd,SP_STR);
  7044. clif_updatestatus(sd,SP_AGI);
  7045. clif_updatestatus(sd,SP_VIT);
  7046. clif_updatestatus(sd,SP_INT);
  7047. clif_updatestatus(sd,SP_DEX);
  7048. clif_updatestatus(sd,SP_LUK);
  7049. if (sd->spiritball)
  7050. clif_spiritball_single(sd->fd, sd);
  7051. if (sd->vd.cloth_color)
  7052. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7053. if(merc_is_hom_active(sd->hd))
  7054. clif_send_homdata(sd,SP_ACK,0);
  7055. if( sd->md ) {
  7056. clif_mercenary_info(sd);
  7057. clif_mercenary_skillblock(sd);
  7058. }
  7059. if( sd->ed )
  7060. clif_elemental_info(sd);
  7061. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7062. clif_weather_check(sd);
  7063. if( sd->chatID )
  7064. chat_leavechat(sd,0);
  7065. if( sd->state.vending )
  7066. clif_openvending(sd, sd->bl.id, sd->vending);
  7067. if( pc_issit(sd) )
  7068. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7069. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7070. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7071. else
  7072. clif_changed_dir(&sd->bl, SELF);
  7073. // unlike vending, resuming buyingstore crashes the client.
  7074. buyingstore_close(sd);
  7075. mail_clear(sd);
  7076. }
  7077. /// Updates the object's (bl) name on client.
  7078. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7079. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7080. void clif_charnameack (int fd, struct block_list *bl)
  7081. {
  7082. unsigned char buf[103];
  7083. int cmd = 0x95, i, ps = -1;
  7084. nullpo_retv(bl);
  7085. WBUFW(buf,0) = cmd;
  7086. WBUFL(buf,2) = bl->id;
  7087. switch( bl->type )
  7088. {
  7089. case BL_PC:
  7090. {
  7091. struct map_session_data *ssd = (struct map_session_data *)bl;
  7092. struct party_data *p = NULL;
  7093. struct guild *g = NULL;
  7094. //Requesting your own "shadow" name. [Skotlex]
  7095. if (ssd->fd == fd && ssd->disguise)
  7096. WBUFL(buf,2) = -bl->id;
  7097. if( ssd->fakename[0] )
  7098. {
  7099. WBUFW(buf, 0) = cmd = 0x195;
  7100. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7101. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7102. break;
  7103. }
  7104. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7105. if( ssd->status.party_id )
  7106. {
  7107. p = party_search(ssd->status.party_id);
  7108. }
  7109. if( ssd->status.guild_id )
  7110. {
  7111. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  7112. {
  7113. 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);
  7114. if( i < g->max_member ) ps = g->member[i].position;
  7115. }
  7116. }
  7117. if( !battle_config.display_party_name && g == NULL )
  7118. {// do not display party unless the player is also in a guild
  7119. p = NULL;
  7120. }
  7121. if (p == NULL && g == NULL)
  7122. break;
  7123. WBUFW(buf, 0) = cmd = 0x195;
  7124. if (p)
  7125. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7126. else
  7127. WBUFB(buf,30) = 0;
  7128. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7129. {
  7130. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7131. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7132. } else { //Assume no guild.
  7133. WBUFB(buf,54) = 0;
  7134. WBUFB(buf,78) = 0;
  7135. }
  7136. }
  7137. break;
  7138. //[blackhole89]
  7139. case BL_HOM:
  7140. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7141. break;
  7142. case BL_MER:
  7143. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7144. break;
  7145. case BL_PET:
  7146. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7147. break;
  7148. case BL_NPC:
  7149. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7150. break;
  7151. case BL_MOB:
  7152. {
  7153. struct mob_data *md = (struct mob_data *)bl;
  7154. nullpo_retv(md);
  7155. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7156. if( md->guardian_data && md->guardian_data->guild_id )
  7157. {
  7158. WBUFW(buf, 0) = cmd = 0x195;
  7159. WBUFB(buf,30) = 0;
  7160. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7161. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7162. }
  7163. else if( battle_config.show_mob_info )
  7164. {
  7165. char mobhp[50], *str_p = mobhp;
  7166. WBUFW(buf, 0) = cmd = 0x195;
  7167. if( battle_config.show_mob_info&4 )
  7168. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7169. if( battle_config.show_mob_info&1 )
  7170. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7171. if( battle_config.show_mob_info&2 )
  7172. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7173. //Even thought mobhp ain't a name, we send it as one so the client
  7174. //can parse it. [Skotlex]
  7175. if( str_p != mobhp )
  7176. {
  7177. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7178. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7179. WBUFB(buf,54) = 0;
  7180. WBUFB(buf,78) = 0;
  7181. }
  7182. }
  7183. }
  7184. break;
  7185. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7186. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7187. // break;
  7188. return;
  7189. case BL_ELEM:
  7190. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7191. break;
  7192. default:
  7193. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7194. return;
  7195. }
  7196. // if no receipient specified just update nearby clients
  7197. if (fd == 0)
  7198. clif_send(buf, packet_len(cmd), bl, AREA);
  7199. else {
  7200. WFIFOHEAD(fd, packet_len(cmd));
  7201. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7202. WFIFOSET(fd, packet_len(cmd));
  7203. }
  7204. }
  7205. //Used to update when a char leaves a party/guild. [Skotlex]
  7206. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7207. void clif_charnameupdate (struct map_session_data *ssd)
  7208. {
  7209. unsigned char buf[103];
  7210. int cmd = 0x195, ps = -1, i;
  7211. struct party_data *p = NULL;
  7212. struct guild *g = NULL;
  7213. nullpo_retv(ssd);
  7214. if( ssd->fakename[0] )
  7215. return; //No need to update as the party/guild was not displayed anyway.
  7216. WBUFW(buf,0) = cmd;
  7217. WBUFL(buf,2) = ssd->bl.id;
  7218. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7219. if (!battle_config.display_party_name) {
  7220. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  7221. p = party_search(ssd->status.party_id);
  7222. }else{
  7223. if (ssd->status.party_id > 0)
  7224. p = party_search(ssd->status.party_id);
  7225. }
  7226. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  7227. {
  7228. 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);
  7229. if( i < g->max_member ) ps = g->member[i].position;
  7230. }
  7231. if( p )
  7232. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7233. else
  7234. WBUFB(buf,30) = 0;
  7235. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7236. {
  7237. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7238. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7239. }
  7240. else
  7241. {
  7242. WBUFB(buf,54) = 0;
  7243. WBUFB(buf,78) = 0;
  7244. }
  7245. // Update nearby clients
  7246. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7247. }
  7248. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7249. /// 01ff <id>.L <x>.W <y>.W
  7250. ///
  7251. /// Visually moves(instant) a character to x,y. The char moves even
  7252. /// when the target cell isn't walkable. If the char is sitting it
  7253. /// stays that way.
  7254. void clif_slide(struct block_list *bl, int x, int y)
  7255. {
  7256. unsigned char buf[10];
  7257. nullpo_retv(bl);
  7258. WBUFW(buf, 0) = 0x01ff;
  7259. WBUFL(buf, 2) = bl->id;
  7260. WBUFW(buf, 6) = x;
  7261. WBUFW(buf, 8) = y;
  7262. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7263. if( disguised(bl) )
  7264. {
  7265. WBUFL(buf,2) = -bl->id;
  7266. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7267. }
  7268. }
  7269. /*------------------------------------------
  7270. * @me command by lordalfa, rewritten implementation by Skotlex
  7271. *------------------------------------------*/
  7272. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  7273. {
  7274. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7275. int len_mes = strlen(mes)+1; //Account for \0
  7276. if (len_mes > sizeof(buf)-8) {
  7277. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7278. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7279. }
  7280. // send message to others
  7281. WBUFW(buf,0) = 0x8d;
  7282. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7283. WBUFL(buf,4) = sd->bl.id;
  7284. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7285. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7286. // send back message to the speaker
  7287. WBUFW(buf,0) = 0x8e;
  7288. WBUFW(buf, 2) = len_mes + 4;
  7289. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7290. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7291. }
  7292. /*==========================
  7293. * Minimap fix [Kevin]
  7294. * Remove dot from minimap
  7295. *--------------------------*/
  7296. void clif_party_xy_remove(struct map_session_data *sd)
  7297. {
  7298. unsigned char buf[16];
  7299. nullpo_retv(sd);
  7300. WBUFW(buf,0)=0x107;
  7301. WBUFL(buf,2)=sd->status.account_id;
  7302. WBUFW(buf,6)=-1;
  7303. WBUFW(buf,8)=-1;
  7304. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7305. }
  7306. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7307. /// 0215 <msg id>.L
  7308. /// msg id:
  7309. /// 0x15 = End all negative status (PA_GOSPEL)
  7310. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7311. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7312. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7313. /// 0x19 = All stats +20 (PA_GOSPEL)
  7314. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7315. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7316. /// 0x1e = DEF +25% (PA_GOSPEL)
  7317. /// 0x1f = ATK +100% (PA_GOSPEL)
  7318. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7319. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7320. /// ? = nothing
  7321. void clif_gospel_info(struct map_session_data *sd, int type)
  7322. {
  7323. int fd=sd->fd;
  7324. WFIFOHEAD(fd,packet_len(0x215));
  7325. WFIFOW(fd,0)=0x215;
  7326. WFIFOL(fd,2)=type;
  7327. WFIFOSET(fd, packet_len(0x215));
  7328. }
  7329. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7330. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7331. /// result:
  7332. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7333. /// star:
  7334. /// 0 = Place of the Sun
  7335. /// 1 = Place of the Moon
  7336. /// 2 = Place of the Stars
  7337. /// 1 = Star Gladiator %s's %s: <mapname>
  7338. /// star:
  7339. /// 0 = Place of the Sun
  7340. /// 1 = Place of the Moon
  7341. /// 2 = Place of the Stars
  7342. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7343. /// star:
  7344. /// 0 = Target of the Sun
  7345. /// 1 = Target of the Moon
  7346. /// 2 = Target of the Stars
  7347. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7348. /// star:
  7349. /// 0 = Monster of the Sun
  7350. /// 1 = Monster of the Moon
  7351. /// 2 = Monster of the Stars
  7352. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7353. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7354. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7355. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7356. /// 40 = Target HP : <monster_id used as HP>
  7357. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7358. {
  7359. int fd = sd->fd;
  7360. WFIFOHEAD(fd,packet_len(0x20e));
  7361. WFIFOW(fd,0) = 0x20e;
  7362. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7363. WFIFOL(fd,26) = monster_id;
  7364. WFIFOB(fd,30) = star;
  7365. WFIFOB(fd,31) = result;
  7366. WFIFOSET(fd,packet_len(0x20e));
  7367. }
  7368. /*==========================================
  7369. * Info about Star Glaldiator save map [Komurka]
  7370. * type: 1: Information, 0: Map registered
  7371. *------------------------------------------*/
  7372. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7373. {
  7374. char mapname[MAP_NAME_LENGTH_EXT];
  7375. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7376. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7377. }
  7378. /*==========================================
  7379. * Info about Star Glaldiator hate mob [Komurka]
  7380. * type: 1: Register mob, 0: Information.
  7381. *------------------------------------------*/
  7382. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7383. {
  7384. if( pcdb_checkid(class_) )
  7385. {
  7386. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7387. }
  7388. else if( mobdb_checkid(class_) )
  7389. {
  7390. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7391. }
  7392. else
  7393. {
  7394. 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);
  7395. }
  7396. }
  7397. /*==========================================
  7398. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7399. *------------------------------------------*/
  7400. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7401. {
  7402. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7403. }
  7404. /*==========================================
  7405. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7406. *------------------------------------------*/
  7407. void clif_feel_hate_reset(struct map_session_data *sd)
  7408. {
  7409. clif_starskill(sd, "", 0, 0, 30);
  7410. }
  7411. /// Equip window (un)tick ack (ZC_CONFIG).
  7412. /// 02d9 <type>.L <value>.L
  7413. /// type:
  7414. /// 0 = open equip window
  7415. /// value:
  7416. /// 0 = disabled
  7417. /// 1 = enabled
  7418. void clif_equiptickack(struct map_session_data* sd, int flag)
  7419. {
  7420. int fd;
  7421. nullpo_retv(sd);
  7422. fd = sd->fd;
  7423. WFIFOHEAD(fd, packet_len(0x2d9));
  7424. WFIFOW(fd, 0) = 0x2d9;
  7425. WFIFOL(fd, 2) = 0;
  7426. WFIFOL(fd, 6) = flag;
  7427. WFIFOSET(fd, packet_len(0x2d9));
  7428. }
  7429. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7430. /// 02da <open equip window>.B
  7431. /// open equip window:
  7432. /// 0 = disabled
  7433. /// 1 = enabled
  7434. void clif_equipcheckbox(struct map_session_data* sd)
  7435. {
  7436. int fd;
  7437. nullpo_retv(sd);
  7438. fd = sd->fd;
  7439. WFIFOHEAD(fd, packet_len(0x2da));
  7440. WFIFOW(fd, 0) = 0x2da;
  7441. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7442. WFIFOSET(fd, packet_len(0x2da));
  7443. }
  7444. /// Sends info about a player's equipped items.
  7445. /// 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)
  7446. /// 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)
  7447. /// 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)
  7448. /// 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)
  7449. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7450. {
  7451. uint8* buf;
  7452. int i, n, fd, offset = 0;
  7453. #if PACKETVER < 20100629
  7454. const int s = 26;
  7455. #else
  7456. const int s = 28;
  7457. #endif
  7458. nullpo_retv(sd);
  7459. nullpo_retv(tsd);
  7460. fd = sd->fd;
  7461. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7462. buf = WFIFOP(fd,0);
  7463. #if PACKETVER < 20101124
  7464. WBUFW(buf, 0) = 0x2d7;
  7465. #else
  7466. WBUFW(buf, 0) = 0x859;
  7467. #endif
  7468. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7469. WBUFW(buf,28) = tsd->status.class_;
  7470. WBUFW(buf,30) = tsd->vd.hair_style;
  7471. WBUFW(buf,32) = tsd->vd.head_bottom;
  7472. WBUFW(buf,34) = tsd->vd.head_mid;
  7473. WBUFW(buf,36) = tsd->vd.head_top;
  7474. #if PACKETVER >= 20110111
  7475. WBUFW(buf,38) = tsd->vd.robe;
  7476. offset+= 2;
  7477. buf = WBUFP(buf,2);
  7478. #endif
  7479. WBUFW(buf,38) = tsd->vd.hair_color;
  7480. WBUFW(buf,40) = tsd->vd.cloth_color;
  7481. WBUFB(buf,42) = tsd->vd.sex;
  7482. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7483. {
  7484. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7485. continue;
  7486. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7487. continue;
  7488. // Inventory position
  7489. WBUFW(buf, n*s+43) = i + 2;
  7490. // Add refine, identify flag, element, etc.
  7491. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7492. // Add cards
  7493. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7494. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7495. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7496. WBUFW(buf, n*s+67) = 0;
  7497. #if PACKETVER >= 20100629
  7498. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7499. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7500. else
  7501. WBUFW(buf, n*s+69) = 0;
  7502. #endif
  7503. n++;
  7504. }
  7505. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7506. WFIFOSET(fd, WFIFOW(fd, 2));
  7507. }
  7508. /// Display msgstringtable.txt string (ZC_MSG).
  7509. /// 0291 <message>.W
  7510. void clif_msg(struct map_session_data* sd, unsigned short id)
  7511. {
  7512. int fd;
  7513. nullpo_retv(sd);
  7514. fd = sd->fd;
  7515. WFIFOHEAD(fd, packet_len(0x291));
  7516. WFIFOW(fd, 0) = 0x291;
  7517. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7518. WFIFOSET(fd, packet_len(0x291));
  7519. }
  7520. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7521. /// 0x7e2 <message>.W <value>.L
  7522. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7523. {
  7524. int fd = sd->fd;
  7525. WFIFOHEAD(fd, packet_len(0x7e2));
  7526. WFIFOW(fd,0) = 0x7e2;
  7527. WFIFOW(fd,2) = id;
  7528. WFIFOL(fd,4) = value;
  7529. WFIFOSET(fd, packet_len(0x7e2));
  7530. }
  7531. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7532. /// 07e6 <skill id>.W <msg id>.L
  7533. ///
  7534. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7535. /// "[SkillName] Message"
  7536. void clif_msg_skill(struct map_session_data* sd, unsigned short skill_id, int msg_id)
  7537. {
  7538. int fd = sd->fd;
  7539. WFIFOHEAD(fd, packet_len(0x7e6));
  7540. WFIFOW(fd,0) = 0x7e6;
  7541. WFIFOW(fd,2) = skill_id;
  7542. WFIFOL(fd,4) = msg_id;
  7543. WFIFOSET(fd, packet_len(0x7e6));
  7544. }
  7545. /// View player equip request denied
  7546. void clif_viewequip_fail(struct map_session_data* sd)
  7547. {
  7548. clif_msg(sd, 0x54d);
  7549. }
  7550. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7551. /// Returns true if the packet was parsed successfully.
  7552. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7553. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7554. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7555. {
  7556. char *text, *name, *message;
  7557. unsigned int packetlen, textlen, namelen, messagelen;
  7558. int fd = sd->fd;
  7559. *name_ = NULL;
  7560. *namelen_ = 0;
  7561. *message_ = NULL;
  7562. *messagelen_ = 0;
  7563. packetlen = RFIFOW(fd,2);
  7564. // basic structure checks
  7565. if( packetlen < 4 + 1 )
  7566. { // 4-byte header and at least an empty string is expected
  7567. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7568. return false;
  7569. }
  7570. text = (char*)RFIFOP(fd,4);
  7571. textlen = packetlen - 4;
  7572. // process <name> part of the packet
  7573. if( format == 0 )
  7574. {// name and message are separated by ' : '
  7575. // validate name
  7576. name = text;
  7577. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7578. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7579. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7580. {
  7581. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7582. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7583. set_eof(fd); // Just kick them out to correct it.
  7584. return false;
  7585. }
  7586. message = name + namelen + 3;
  7587. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7588. }
  7589. else
  7590. {// name has fixed width
  7591. if( textlen < NAME_LENGTH + 1 )
  7592. {
  7593. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7594. return false;
  7595. }
  7596. // validate name
  7597. name = text;
  7598. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7599. if( name[namelen] != '\0' )
  7600. { // only restriction is that the name must be zero-terminated
  7601. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7602. return false;
  7603. }
  7604. message = name + NAME_LENGTH;
  7605. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7606. }
  7607. if( messagelen != strnlen(message, messagelen)+1 )
  7608. { // the declared length must match real length
  7609. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7610. return false;
  7611. }
  7612. // verify <message> part of the packet
  7613. if( message[messagelen-1] != '\0' )
  7614. { // message must be zero-terminated
  7615. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7616. return false;
  7617. }
  7618. if( messagelen > CHAT_SIZE_MAX-1 )
  7619. { // messages mustn't be too long
  7620. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7621. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7622. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7623. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7624. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7625. return false;
  7626. }
  7627. *name_ = name;
  7628. *namelen_ = namelen;
  7629. *message_ = message;
  7630. *messagelen_ = messagelen;
  7631. return true;
  7632. }
  7633. // ---------------------
  7634. // clif_guess_PacketVer
  7635. // ---------------------
  7636. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7637. // error codes:
  7638. // 0 - Success
  7639. // 1 - Unknown packet_ver
  7640. // 2 - Invalid account_id
  7641. // 3 - Invalid char_id
  7642. // 4 - Invalid login_id1 (reserved)
  7643. // 5 - Invalid client_tick (reserved)
  7644. // 6 - Invalid sex
  7645. // Only the first 'invalid' error that appears is used.
  7646. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7647. {
  7648. static int err = 1;
  7649. static int packet_ver = -1;
  7650. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7651. if (get_previous)
  7652. {//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]
  7653. if( error )
  7654. *error = err;
  7655. return packet_ver;
  7656. }
  7657. //By default, start searching on the default one.
  7658. err = 1;
  7659. packet_ver = clif_config.packet_db_ver;
  7660. cmd = RFIFOW(fd,0);
  7661. packet_len = RFIFOREST(fd);
  7662. #define SET_ERROR(n) \
  7663. if( err == 1 )\
  7664. err = n;\
  7665. //define SET_ERROR
  7666. // FIXME: If the packet is not received at once, this will FAIL.
  7667. // Figure out, when it happens, that only part of the packet is
  7668. // received, or fix the function to be able to deal with that
  7669. // case.
  7670. #define CHECK_PACKET_VER() \
  7671. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7672. ;/* not wanttoconnection or wrong length */\
  7673. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7674. { SET_ERROR(2); }/* invalid account_id */\
  7675. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7676. { SET_ERROR(3); }/* invalid char_id */\
  7677. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7678. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7679. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7680. { SET_ERROR(6); }/* invalid sex */\
  7681. else\
  7682. {\
  7683. err = 0;\
  7684. if( error )\
  7685. *error = 0;\
  7686. return packet_ver;\
  7687. }\
  7688. //define CHECK_PACKET_VER
  7689. CHECK_PACKET_VER();//Default packet version found.
  7690. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7691. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7692. CHECK_PACKET_VER();
  7693. }
  7694. if( error )
  7695. *error = err;
  7696. packet_ver = -1;
  7697. return -1;
  7698. #undef SET_ERROR
  7699. #undef CHECK_PACKET_VER
  7700. }
  7701. // ------------
  7702. // clif_parse_*
  7703. // ------------
  7704. // Parses incoming (player) connection
  7705. /// Request to connect to map-server.
  7706. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7707. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7708. /// There are various variants of this packet, some of them have padding between fields.
  7709. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7710. {
  7711. struct block_list* bl;
  7712. struct auth_node* node;
  7713. int cmd, account_id, char_id, login_id1, sex;
  7714. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7715. 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])
  7716. if (sd) {
  7717. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7718. return;
  7719. }
  7720. // Only valid packet version get here
  7721. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7722. cmd = RFIFOW(fd,0);
  7723. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7724. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7725. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7726. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7727. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7728. if( packet_ver < 5 || // reject really old client versions
  7729. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7730. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7731. {// packet version rejected
  7732. 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));
  7733. WFIFOHEAD(fd,packet_len(0x6a));
  7734. WFIFOW(fd,0) = 0x6a;
  7735. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7736. WFIFOSET(fd,packet_len(0x6a));
  7737. set_eof(fd);
  7738. return;
  7739. }
  7740. if( runflag != MAPSERVER_ST_RUNNING )
  7741. {// not allowed
  7742. clif_authfail_fd(fd,1);// server closed
  7743. return;
  7744. }
  7745. //Check for double login.
  7746. bl = map_id2bl(account_id);
  7747. if(bl && bl->type != BL_PC) {
  7748. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7749. WFIFOHEAD(fd,packet_len(0x6a));
  7750. WFIFOW(fd,0) = 0x6a;
  7751. WFIFOB(fd,2) = 3; // Rejected by server
  7752. WFIFOSET(fd,packet_len(0x6a));
  7753. set_eof(fd);
  7754. return;
  7755. }
  7756. if (bl ||
  7757. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7758. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7759. {
  7760. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7761. return;
  7762. }
  7763. CREATE(sd, TBL_PC, 1);
  7764. sd->fd = fd;
  7765. sd->packet_ver = packet_ver;
  7766. session[fd]->session_data = sd;
  7767. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7768. #if PACKETVER < 20070521
  7769. WFIFOHEAD(fd,4);
  7770. WFIFOL(fd,0) = sd->bl.id;
  7771. WFIFOSET(fd,4);
  7772. #else
  7773. WFIFOHEAD(fd,packet_len(0x283));
  7774. WFIFOW(fd,0) = 0x283;
  7775. WFIFOL(fd,2) = sd->bl.id;
  7776. WFIFOSET(fd,packet_len(0x283));
  7777. #endif
  7778. chrif_authreq(sd);
  7779. }
  7780. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7781. /// 007d
  7782. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7783. {
  7784. if(sd->bl.prev != NULL)
  7785. return;
  7786. if (!sd->state.active)
  7787. { //Character loading is not complete yet!
  7788. //Let pc_reg_received reinvoke this when ready.
  7789. sd->state.connect_new = 0;
  7790. return;
  7791. }
  7792. if (sd->state.rewarp)
  7793. { //Rewarp player.
  7794. sd->state.rewarp = 0;
  7795. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7796. return;
  7797. }
  7798. sd->state.warping = 0;
  7799. // look
  7800. #if PACKETVER < 4
  7801. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7802. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7803. #else
  7804. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7805. #endif
  7806. if(sd->vd.cloth_color)
  7807. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7808. // item
  7809. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7810. pc_checkitem(sd);
  7811. // cart
  7812. if(pc_iscarton(sd)) {
  7813. clif_cartlist(sd);
  7814. clif_updatestatus(sd,SP_CARTINFO);
  7815. }
  7816. // weight
  7817. clif_updatestatus(sd,SP_WEIGHT);
  7818. clif_updatestatus(sd,SP_MAXWEIGHT);
  7819. // guild
  7820. // (needs to go before clif_spawn() to show guild emblems correctly)
  7821. if(sd->status.guild_id)
  7822. guild_send_memberinfoshort(sd,1);
  7823. if(battle_config.pc_invincible_time > 0) {
  7824. if(map_flag_gvg(sd->bl.m))
  7825. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7826. else
  7827. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7828. }
  7829. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7830. map_spawnmobs(sd->bl.m);
  7831. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7832. {// increment the number of pvp players on the map
  7833. map[sd->bl.m].users_pvp++;
  7834. }
  7835. if( map[sd->bl.m].instance_id )
  7836. {
  7837. instance[map[sd->bl.m].instance_id].users++;
  7838. instance_check_idle(map[sd->bl.m].instance_id);
  7839. }
  7840. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7841. // reset the callshop flag if the player changes map
  7842. sd->state.callshop = 0;
  7843. map_addblock(&sd->bl);
  7844. clif_spawn(&sd->bl);
  7845. // Party
  7846. // (needs to go after clif_spawn() to show hp bars correctly)
  7847. if(sd->status.party_id) {
  7848. party_send_movemap(sd);
  7849. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7850. }
  7851. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7852. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7853. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7854. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7855. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7856. sd->pvp_rank = 0;
  7857. sd->pvp_lastusers = 0;
  7858. sd->pvp_point = 5;
  7859. sd->pvp_won = 0;
  7860. sd->pvp_lost = 0;
  7861. }
  7862. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7863. } else
  7864. // set flag, if it's a duel [LuzZza]
  7865. if(sd->duel_group)
  7866. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7867. if (map[sd->bl.m].flag.gvg_dungeon)
  7868. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7869. if( map_flag_gvg(sd->bl.m) )
  7870. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7871. // info about nearby objects
  7872. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7873. 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);
  7874. // pet
  7875. if( sd->pd )
  7876. {
  7877. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7878. { //Return the pet to egg. [Skotlex]
  7879. clif_displaymessage(sd->fd, msg_txt(666));
  7880. pet_menu(sd, 3); //Option 3 is return to egg.
  7881. }
  7882. else
  7883. {
  7884. map_addblock(&sd->pd->bl);
  7885. clif_spawn(&sd->pd->bl);
  7886. clif_send_petdata(sd,sd->pd,0,0);
  7887. clif_send_petstatus(sd);
  7888. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7889. }
  7890. }
  7891. //homunculus [blackhole89]
  7892. if( merc_is_hom_active(sd->hd) )
  7893. {
  7894. map_addblock(&sd->hd->bl);
  7895. clif_spawn(&sd->hd->bl);
  7896. clif_send_homdata(sd,SP_ACK,0);
  7897. clif_hominfo(sd,sd->hd,1);
  7898. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7899. clif_homskillinfoblock(sd);
  7900. if( battle_config.hom_setting&0x8 )
  7901. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7902. if( !(battle_config.hom_setting&0x2) )
  7903. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7904. }
  7905. if( sd->md ) {
  7906. map_addblock(&sd->md->bl);
  7907. clif_spawn(&sd->md->bl);
  7908. clif_mercenary_info(sd);
  7909. clif_mercenary_skillblock(sd);
  7910. }
  7911. if( sd->ed ) {
  7912. map_addblock(&sd->ed->bl);
  7913. clif_spawn(&sd->ed->bl);
  7914. clif_elemental_info(sd);
  7915. clif_elemental_updatestatus(sd,SP_HP);
  7916. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.matk_max);
  7917. clif_elemental_updatestatus(sd,SP_SP);
  7918. }
  7919. if(sd->state.connect_new) {
  7920. int lv;
  7921. sd->state.connect_new = 0;
  7922. clif_skillinfoblock(sd);
  7923. clif_hotkeys_send(sd);
  7924. clif_updatestatus(sd,SP_BASEEXP);
  7925. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7926. clif_updatestatus(sd,SP_JOBEXP);
  7927. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7928. clif_updatestatus(sd,SP_SKILLPOINT);
  7929. clif_initialstatus(sd);
  7930. if (sd->sc.option&OPTION_FALCON)
  7931. clif_status_load(&sd->bl, SI_FALCON, 1);
  7932. if (sd->sc.option&OPTION_RIDING)
  7933. clif_status_load(&sd->bl, SI_RIDING, 1);
  7934. if (sd->sc.option&OPTION_WUGRIDER)
  7935. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  7936. if(sd->status.manner < 0)
  7937. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7938. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7939. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7940. if(sd->bl.m == sd->feel_map[0].m
  7941. || sd->bl.m == sd->feel_map[1].m
  7942. || sd->bl.m == sd->feel_map[2].m)
  7943. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7944. }
  7945. if(sd->pd && sd->pd->pet.intimate > 900)
  7946. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7947. if(merc_is_hom_active(sd->hd))
  7948. merc_hom_init_timers(sd->hd);
  7949. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7950. {
  7951. sd->state.night = 1;
  7952. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7953. }
  7954. // Notify everyone that this char logged in [Skotlex].
  7955. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7956. //Login Event
  7957. npc_script_event(sd, NPCE_LOGIN);
  7958. } else {
  7959. //For some reason the client "loses" these on warp/map-change.
  7960. clif_updatestatus(sd,SP_STR);
  7961. clif_updatestatus(sd,SP_AGI);
  7962. clif_updatestatus(sd,SP_VIT);
  7963. clif_updatestatus(sd,SP_INT);
  7964. clif_updatestatus(sd,SP_DEX);
  7965. clif_updatestatus(sd,SP_LUK);
  7966. // abort currently running script
  7967. sd->state.using_fake_npc = 0;
  7968. sd->state.menu_or_input = 0;
  7969. sd->npc_menu = 0;
  7970. if(sd->npc_id)
  7971. npc_event_dequeue(sd);
  7972. }
  7973. if( sd->state.changemap )
  7974. {// restore information that gets lost on map-change
  7975. #if PACKETVER >= 20070918
  7976. clif_partyinvitationstate(sd);
  7977. clif_equipcheckbox(sd);
  7978. #endif
  7979. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7980. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7981. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7982. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7983. { //Display night.
  7984. if( !sd->state.night )
  7985. {
  7986. sd->state.night = 1;
  7987. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7988. }
  7989. }
  7990. else if( sd->state.night )
  7991. { //Clear night display.
  7992. sd->state.night = 0;
  7993. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7994. }
  7995. if( map[sd->bl.m].flag.battleground )
  7996. {
  7997. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7998. if( map[sd->bl.m].flag.battleground == 2 )
  7999. clif_bg_updatescore_single(sd);
  8000. }
  8001. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8002. {
  8003. char output[128];
  8004. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8005. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8006. }
  8007. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8008. sd->state.changemap = false;
  8009. }
  8010. mail_clear(sd);
  8011. /* Guild Aura Init */
  8012. if( sd->state.gmaster_flag ) {
  8013. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8014. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8015. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8016. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8017. }
  8018. if( sd->state.vending ) { /* show we have a vending */
  8019. clif_openvending(sd,sd->bl.id,sd->vending);
  8020. clif_showvendingboard(&sd->bl,sd->message,0);
  8021. }
  8022. if(map[sd->bl.m].flag.loadevent) // Lance
  8023. npc_script_event(sd, NPCE_LOADMAP);
  8024. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8025. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8026. if (sd->sc.opt2) //Client loses these on warp.
  8027. clif_changeoption(&sd->bl);
  8028. clif_weather_check(sd);
  8029. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8030. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8031. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8032. else
  8033. sd->areanpc_id = 0;
  8034. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8035. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8036. pc_setdead(sd);
  8037. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8038. if(pc_isdead(sd))
  8039. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8040. else {
  8041. skill_usave_trigger(sd);
  8042. clif_changed_dir(&sd->bl, SELF);
  8043. }
  8044. // Trigger skill effects if you appear standing on them
  8045. if(!battle_config.pc_invincible_time)
  8046. skill_unit_move(&sd->bl,gettick(),1);
  8047. }
  8048. /// Request for server's tick.
  8049. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8050. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8051. /// There are various variants of this packet, some of them have padding between fields.
  8052. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8053. {
  8054. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8055. WFIFOHEAD(fd, packet_len(0x7f));
  8056. WFIFOW(fd,0)=0x7f;
  8057. WFIFOL(fd,2)=gettick();
  8058. WFIFOSET(fd,packet_len(0x7f));
  8059. // removed until the socket problems are fixed. [FlavioJS]
  8060. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  8061. }
  8062. /// Sends hotkey bar.
  8063. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8064. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8065. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8066. void clif_hotkeys_send(struct map_session_data *sd) {
  8067. #ifdef HOTKEY_SAVING
  8068. const int fd = sd->fd;
  8069. int i;
  8070. #if PACKETVER < 20090603
  8071. const int cmd = 0x2b9;
  8072. #else
  8073. const int cmd = 0x7d9;
  8074. #endif
  8075. if (!fd) return;
  8076. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8077. WFIFOW(fd, 0) = cmd;
  8078. for(i = 0; i < MAX_HOTKEYS; i++) {
  8079. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8080. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8081. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8082. }
  8083. WFIFOSET(fd, packet_len(cmd));
  8084. #endif
  8085. }
  8086. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8087. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8088. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8089. #ifdef HOTKEY_SAVING
  8090. unsigned short idx;
  8091. int cmd;
  8092. cmd = RFIFOW(fd, 0);
  8093. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8094. if (idx >= MAX_HOTKEYS) return;
  8095. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8096. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8097. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8098. #endif
  8099. }
  8100. /// Displays cast-like progress bar (ZC_PROGRESS).
  8101. /// 02f0 <color>.L <time>.L
  8102. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8103. {
  8104. int fd = sd->fd;
  8105. WFIFOHEAD(fd,packet_len(0x2f0));
  8106. WFIFOW(fd,0) = 0x2f0;
  8107. WFIFOL(fd,2) = color;
  8108. WFIFOL(fd,6) = second;
  8109. WFIFOSET(fd,packet_len(0x2f0));
  8110. }
  8111. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8112. /// 02f2
  8113. void clif_progressbar_abort(struct map_session_data * sd)
  8114. {
  8115. int fd = sd->fd;
  8116. WFIFOHEAD(fd,packet_len(0x2f2));
  8117. WFIFOW(fd,0) = 0x2f2;
  8118. WFIFOSET(fd,packet_len(0x2f2));
  8119. }
  8120. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8121. /// 02f1
  8122. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8123. {
  8124. int npc_id = sd->progressbar.npc_id;
  8125. if( gettick() < sd->progressbar.timeout && sd->st )
  8126. sd->st->state = END;
  8127. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8128. npc_scriptcont(sd, npc_id);
  8129. }
  8130. /// Request to walk to a certain position on the current map.
  8131. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8132. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8133. /// There are various variants of this packet, some of them have padding between fields.
  8134. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8135. {
  8136. short x, y;
  8137. if (pc_isdead(sd)) {
  8138. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8139. return;
  8140. }
  8141. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8142. ; //You CAN walk on this OPT1 value.
  8143. else if( sd->progressbar.npc_id )
  8144. clif_progressbar_abort(sd);
  8145. else if (pc_cant_act(sd))
  8146. return;
  8147. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8148. return;
  8149. pc_delinvincibletimer(sd);
  8150. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8151. //Set last idle time... [Skotlex]
  8152. sd->idletime = last_tick;
  8153. unit_walktoxy(&sd->bl, x, y, 4);
  8154. }
  8155. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8156. /// 018a <type>.W
  8157. /// type:
  8158. /// 0 = quit
  8159. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8160. {
  8161. WFIFOHEAD(fd,packet_len(0x18b));
  8162. WFIFOW(fd,0) = 0x18b;
  8163. /* Rovert's prevent logout option fixed [Valaris] */
  8164. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8165. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8166. {
  8167. set_eof(fd);
  8168. WFIFOW(fd,2)=0;
  8169. } else {
  8170. WFIFOW(fd,2)=1;
  8171. }
  8172. WFIFOSET(fd,packet_len(0x18b));
  8173. }
  8174. /// Requesting unit's name.
  8175. /// 0094 <id>.L (CZ_REQNAME)
  8176. /// 0368 <id>.L (CZ_REQNAME2)
  8177. /// There are various variants of this packet, some of them have padding between fields.
  8178. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8179. {
  8180. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8181. struct block_list* bl;
  8182. //struct status_change *sc;
  8183. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8184. id = sd->bl.id;
  8185. bl = map_id2bl(id);
  8186. if( bl == NULL )
  8187. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8188. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8189. return; // Block namerequests past view range
  8190. // 'see people in GM hide' cheat detection
  8191. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8192. sc = status_get_sc(bl);
  8193. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8194. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8195. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8196. ) {
  8197. char gm_msg[256];
  8198. 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);
  8199. ShowWarning(gm_msg);
  8200. // information is sent to all online GMs
  8201. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8202. return;
  8203. }
  8204. */
  8205. clif_charnameack(fd, bl);
  8206. }
  8207. /// Validates and processes global messages
  8208. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8209. /// There are various variants of this packet.
  8210. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8211. {
  8212. const char* text = (char*)RFIFOP(fd,4);
  8213. int textlen = RFIFOW(fd,2) - 4;
  8214. char *name, *message, *fakename = NULL;
  8215. int namelen, messagelen;
  8216. bool is_fake;
  8217. // validate packet and retrieve name and message
  8218. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8219. return;
  8220. if( is_atcommand(fd, sd, message, 1) )
  8221. return;
  8222. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8223. return;
  8224. if( battle_config.min_chat_delay )
  8225. { //[Skotlex]
  8226. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8227. return;
  8228. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8229. }
  8230. /**
  8231. * Fake Name Design by FatalEror (bug report #9)
  8232. **/
  8233. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8234. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8235. strcpy(fakename, sd->fakename);
  8236. strcat(fakename, " : ");
  8237. strcat(fakename, message);
  8238. textlen = strlen(fakename) + 1;
  8239. }
  8240. // send message to others (using the send buffer for temp. storage)
  8241. WFIFOHEAD(fd, 8 + textlen);
  8242. WFIFOW(fd,0) = 0x8d;
  8243. WFIFOW(fd,2) = 8 + textlen;
  8244. WFIFOL(fd,4) = sd->bl.id;
  8245. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8246. //FIXME: chat has range of 9 only
  8247. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8248. // send back message to the speaker
  8249. if( is_fake ) {
  8250. WFIFOW(fd,0) = 0x8e;
  8251. WFIFOW(fd,2) = textlen + 4;
  8252. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8253. aFree(fakename);
  8254. } else {
  8255. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8256. WFIFOW(fd,0) = 0x8e;
  8257. }
  8258. WFIFOSET(fd, WFIFOW(fd,2));
  8259. #ifdef PCRE_SUPPORT
  8260. // trigger listening npcs
  8261. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8262. #endif
  8263. // Chat logging type 'O' / Global Chat
  8264. 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);
  8265. }
  8266. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8267. /// Request to warp to a map on given coordinates.
  8268. /// 0140 <map name>.16B <x>.W <y>.W
  8269. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8270. {
  8271. char command[MAP_NAME_LENGTH_EXT+25];
  8272. char* map_name;
  8273. map_name = (char*)RFIFOP(fd,2);
  8274. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8275. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8276. is_atcommand(fd, sd, command, 1);
  8277. }
  8278. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8279. /// 009c <id>.L <head dir>.W <dir>.B
  8280. /// head dir:
  8281. /// 0 = straight
  8282. /// 1 = turned CW
  8283. /// 2 = turned CCW
  8284. /// dir:
  8285. /// 0 = north
  8286. /// 1 = northwest
  8287. /// 2 = west
  8288. /// 3 = southwest
  8289. /// 4 = south
  8290. /// 5 = southeast
  8291. /// 6 = east
  8292. /// 7 = northeast
  8293. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8294. {
  8295. unsigned char buf[64];
  8296. WBUFW(buf,0) = 0x9c;
  8297. WBUFL(buf,2) = bl->id;
  8298. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8299. WBUFB(buf,8) = unit_getdir(bl);
  8300. clif_send(buf, packet_len(0x9c), bl, target);
  8301. if (disguised(bl)) {
  8302. WBUFL(buf,2) = -bl->id;
  8303. WBUFW(buf,6) = 0;
  8304. clif_send(buf, packet_len(0x9c), bl, SELF);
  8305. }
  8306. }
  8307. /// Request to change own body and head direction.
  8308. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8309. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8310. /// There are various variants of this packet, some of them have padding between fields.
  8311. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8312. {
  8313. unsigned char headdir, dir;
  8314. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8315. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8316. pc_setdir(sd, dir, headdir);
  8317. clif_changed_dir(&sd->bl, AREA_WOS);
  8318. }
  8319. /// Request to show an emotion (CZ_REQ_EMOTION).
  8320. /// 00bf <type>.B
  8321. /// type:
  8322. /// @see enum emotion_type
  8323. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8324. {
  8325. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8326. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8327. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8328. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8329. return;
  8330. }
  8331. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8332. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8333. sd->emotionlasttime = time(NULL);
  8334. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8335. return;
  8336. }
  8337. sd->emotionlasttime = time(NULL);
  8338. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  8339. {// re-roll dice
  8340. emoticon = rnd()%6+E_DICE1;
  8341. }
  8342. clif_emotion(&sd->bl, emoticon);
  8343. } else
  8344. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8345. }
  8346. /// /w /who (CZ_REQ_USER_COUNT).
  8347. /// Request to display amount of currently connected players.
  8348. /// 00c1
  8349. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8350. {
  8351. WFIFOHEAD(fd,packet_len(0xc2));
  8352. WFIFOW(fd,0) = 0xc2;
  8353. WFIFOL(fd,2) = map_getusers();
  8354. WFIFOSET(fd,packet_len(0xc2));
  8355. }
  8356. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8357. {
  8358. if (pc_isdead(sd)) {
  8359. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8360. return;
  8361. }
  8362. if (sd->sc.count &&
  8363. (sd->sc.data[SC_TRICKDEAD] ||
  8364. sd->sc.data[SC_AUTOCOUNTER] ||
  8365. sd->sc.data[SC_BLADESTOP] ||
  8366. sd->sc.data[SC__MANHOLE] ||
  8367. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8368. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8369. return;
  8370. pc_stop_walking(sd, 1);
  8371. pc_stop_attack(sd);
  8372. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8373. target_id = sd->bl.id;
  8374. switch(action_type)
  8375. {
  8376. case 0x00: // once attack
  8377. case 0x07: // continuous attack
  8378. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8379. return;
  8380. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8381. return;
  8382. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8383. return;
  8384. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8385. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8386. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8387. return;
  8388. }
  8389. }
  8390. pc_delinvincibletimer(sd);
  8391. sd->idletime = last_tick;
  8392. unit_attack(&sd->bl, target_id, action_type != 0);
  8393. break;
  8394. case 0x02: // sitdown
  8395. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8396. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8397. break;
  8398. }
  8399. if(pc_issit(sd)) {
  8400. //Bugged client? Just refresh them.
  8401. clif_sitting(&sd->bl);
  8402. return;
  8403. }
  8404. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8405. break;
  8406. if (sd->sc.count && (
  8407. sd->sc.data[SC_DANCING] ||
  8408. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8409. )) //No sitting during these states either.
  8410. break;
  8411. pc_setsit(sd);
  8412. skill_sit(sd,1);
  8413. clif_sitting(&sd->bl);
  8414. break;
  8415. case 0x03: // standup
  8416. if (!pc_issit(sd)) {
  8417. //Bugged client? Just refresh them.
  8418. clif_standing(&sd->bl);
  8419. return;
  8420. }
  8421. pc_setstand(sd);
  8422. skill_sit(sd,0);
  8423. clif_standing(&sd->bl);
  8424. break;
  8425. }
  8426. }
  8427. /// Request for an action.
  8428. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8429. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8430. /// action:
  8431. /// 0 = attack
  8432. /// 1 = pick up item
  8433. /// 2 = sit down
  8434. /// 3 = stand up
  8435. /// 7 = continous attack
  8436. /// 12 = (touch skill?)
  8437. /// There are various variants of this packet, some of them have padding between fields.
  8438. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8439. {
  8440. clif_parse_ActionRequest_sub(sd,
  8441. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8442. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8443. gettick()
  8444. );
  8445. }
  8446. /// Response to the death/system menu (CZ_RESTART).
  8447. /// 00b2 <type>.B
  8448. /// type:
  8449. /// 0 = restart (respawn)
  8450. /// 1 = char-select (disconnect)
  8451. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8452. {
  8453. switch(RFIFOB(fd,2)) {
  8454. case 0x00:
  8455. pc_respawn(sd,CLR_RESPAWN);
  8456. break;
  8457. case 0x01:
  8458. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8459. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8460. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8461. { //Send to char-server for character selection.
  8462. chrif_charselectreq(sd, session[fd]->client_addr);
  8463. } else {
  8464. WFIFOHEAD(fd,packet_len(0x18b));
  8465. WFIFOW(fd,0)=0x18b;
  8466. WFIFOW(fd,2)=1;
  8467. WFIFOSET(fd,packet_len(0x018b));
  8468. }
  8469. break;
  8470. }
  8471. }
  8472. /// Validates and processes whispered messages (CZ_WHISPER).
  8473. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8474. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8475. {
  8476. struct map_session_data* dstsd;
  8477. int i;
  8478. char *target, *message;
  8479. int namelen, messagelen;
  8480. // validate packet and retrieve name and message
  8481. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8482. return;
  8483. if (is_atcommand(fd, sd, message, 1) )
  8484. return;
  8485. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8486. return;
  8487. if (battle_config.min_chat_delay)
  8488. { //[Skotlex]
  8489. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8490. return;
  8491. }
  8492. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8493. }
  8494. // Chat logging type 'W' / Whisper
  8495. 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);
  8496. //-------------------------------------------------------//
  8497. // Lordalfa - Paperboy - To whisper NPC commands //
  8498. //-------------------------------------------------------//
  8499. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8500. {
  8501. char* str = target+4; //Skip the NPC: string part.
  8502. struct npc_data* npc;
  8503. if ((npc = npc_name2id(str)))
  8504. {
  8505. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8506. char *split;
  8507. char output[256];
  8508. str = message;
  8509. // skip codepage indicator, if detected
  8510. if( str[0] == '|' && strlen(str) >= 4 )
  8511. str += 3;
  8512. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8513. {// Splits the message using '#' as separators
  8514. split = strchr(str,'#');
  8515. if( split == NULL )
  8516. { // use the remaining string
  8517. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8518. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8519. split_data[i][0] = '\0';
  8520. break;
  8521. }
  8522. *split = '\0';
  8523. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8524. str = split+1;
  8525. }
  8526. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  8527. {
  8528. sprintf(output, "@whispervar%d$", i);
  8529. set_var(sd,output,(char *) split_data[i]);
  8530. }
  8531. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8532. npc_event(sd,output,0); // Calls the NPC label
  8533. return;
  8534. }
  8535. }
  8536. // Main chat [LuzZza]
  8537. if(strcmpi(target, main_chat_nick) == 0)
  8538. {
  8539. if(!sd->state.mainchat)
  8540. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8541. else {
  8542. // send the main message using inter-server system
  8543. intif_main_message( sd, message );
  8544. }
  8545. return;
  8546. }
  8547. // searching destination character
  8548. dstsd = map_nick2sd(target);
  8549. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8550. {
  8551. // player is not on this map-server
  8552. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8553. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8554. // and if we ask for 'Test', we must not contact 'test' player
  8555. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8556. intif_wis_message(sd, target, message, messagelen);
  8557. return;
  8558. }
  8559. // if player ignores everyone
  8560. if (dstsd->state.ignoreAll)
  8561. {
  8562. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8563. clif_wis_end(fd, 1); // 1: target character is not loged in
  8564. else
  8565. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8566. return;
  8567. }
  8568. // if player ignores the source character
  8569. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8570. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8571. { // source char present in ignore list
  8572. clif_wis_end(fd, 2); // 2: ignored by target
  8573. return;
  8574. }
  8575. // if player is autotrading
  8576. if( dstsd->state.autotrade == 1 )
  8577. {
  8578. char output[256];
  8579. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8580. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8581. return;
  8582. }
  8583. // notify sender of success
  8584. clif_wis_end(fd, 0); // 0: success to send wisper
  8585. // Normal message
  8586. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8587. }
  8588. /// /b /nb (CZ_BROADCAST).
  8589. /// Request to broadcast a message on whole server.
  8590. /// 0099 <packet len>.W <text>.?B 00
  8591. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8592. {
  8593. char command[CHAT_SIZE_MAX+11];
  8594. char* msg = (char*)RFIFOP(fd,4);
  8595. unsigned int len = RFIFOW(fd,2)-4;
  8596. // as the length varies depending on the command used, just block unreasonably long strings
  8597. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  8598. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8599. is_atcommand(fd, sd, command, 1);
  8600. }
  8601. /// Request to pick up an item.
  8602. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8603. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8604. /// There are various variants of this packet, some of them have padding between fields.
  8605. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8606. {
  8607. struct flooritem_data *fitem;
  8608. int map_object_id;
  8609. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8610. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8611. do {
  8612. if (pc_isdead(sd)) {
  8613. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8614. break;
  8615. }
  8616. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8617. break;
  8618. if( sd->sc.cant.pickup )
  8619. break;
  8620. if (pc_cant_act(sd))
  8621. break;
  8622. if (!pc_takeitem(sd, fitem))
  8623. break;
  8624. return;
  8625. } while (0);
  8626. // Client REQUIRES a fail packet or you can no longer pick items.
  8627. clif_additem(sd,0,0,6);
  8628. }
  8629. /// Request to drop an item.
  8630. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8631. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8632. /// There are various variants of this packet, some of them have padding between fields.
  8633. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8634. {
  8635. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8636. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8637. for(;;) {
  8638. if (pc_isdead(sd))
  8639. break;
  8640. if (pc_cant_act(sd))
  8641. break;
  8642. if (sd->sc.count && (
  8643. sd->sc.data[SC_AUTOCOUNTER] ||
  8644. sd->sc.data[SC_BLADESTOP] ||
  8645. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8646. ))
  8647. break;
  8648. if (!pc_dropitem(sd, item_index, item_amount))
  8649. break;
  8650. return;
  8651. }
  8652. //Because the client does not like being ignored.
  8653. clif_dropitem(sd, item_index,0);
  8654. }
  8655. /// Request to use an item.
  8656. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8657. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8658. /// There are various variants of this packet, some of them have padding between fields.
  8659. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8660. {
  8661. int n;
  8662. if (pc_isdead(sd)) {
  8663. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8664. return;
  8665. }
  8666. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  8667. return;
  8668. //This flag enables you to use items while in an NPC. [Skotlex]
  8669. if (sd->npc_id) {
  8670. if (sd->npc_id != sd->npc_item_flag)
  8671. return;
  8672. } else
  8673. if (pc_istrading(sd))
  8674. return;
  8675. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8676. sd->idletime = last_tick;
  8677. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8678. if(n <0 || n >= MAX_INVENTORY)
  8679. return;
  8680. if (!pc_useitem(sd,n))
  8681. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8682. }
  8683. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8684. /// 00a9 <index>.W <position>.W
  8685. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8686. {
  8687. int index;
  8688. if(pc_isdead(sd)) {
  8689. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8690. return;
  8691. }
  8692. index = RFIFOW(fd,2)-2;
  8693. if (index < 0 || index >= MAX_INVENTORY)
  8694. return; //Out of bounds check.
  8695. if(sd->npc_id) {
  8696. if (sd->npc_id != sd->npc_item_flag)
  8697. return;
  8698. } else if (sd->state.storage_flag || sd->sc.opt1)
  8699. ; //You can equip/unequip stuff while storage is open/under status changes
  8700. else if (pc_cant_act(sd))
  8701. return;
  8702. if(!sd->status.inventory[index].identify) {
  8703. clif_equipitemack(sd,index,0,0); // fail
  8704. return;
  8705. }
  8706. if(!sd->inventory_data[index])
  8707. return;
  8708. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8709. pet_equipitem(sd,index);
  8710. return;
  8711. }
  8712. //Client doesn't send the position for ammo.
  8713. if(sd->inventory_data[index]->type == IT_AMMO)
  8714. pc_equipitem(sd,index,EQP_AMMO);
  8715. else
  8716. pc_equipitem(sd,index,RFIFOW(fd,4));
  8717. }
  8718. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8719. /// 00ab <index>.W
  8720. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8721. {
  8722. int index;
  8723. if(pc_isdead(sd)) {
  8724. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8725. return;
  8726. }
  8727. if (sd->state.storage_flag || sd->sc.opt1)
  8728. ; //You can equip/unequip stuff while storage is open/under status changes
  8729. else if (pc_cant_act(sd))
  8730. return;
  8731. index = RFIFOW(fd,2)-2;
  8732. pc_unequipitem(sd,index,1);
  8733. }
  8734. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8735. /// 0090 <id>.L <type>.B
  8736. /// type:
  8737. /// 1 = click
  8738. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8739. {
  8740. struct block_list *bl;
  8741. if(pc_isdead(sd)) {
  8742. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8743. return;
  8744. }
  8745. if (pc_cant_act(sd))
  8746. return;
  8747. bl = map_id2bl(RFIFOL(fd,2));
  8748. if (!bl) return;
  8749. switch (bl->type) {
  8750. case BL_MOB:
  8751. case BL_PC:
  8752. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8753. break;
  8754. case BL_NPC:
  8755. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8756. npc_click(sd,(TBL_NPC*)bl);
  8757. break;
  8758. }
  8759. }
  8760. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8761. /// 00c5 <id>.L <type>.B
  8762. /// type:
  8763. /// 0 = buy
  8764. /// 1 = sell
  8765. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8766. {
  8767. if (sd->state.trading)
  8768. return;
  8769. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8770. }
  8771. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8772. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8773. ///
  8774. /// R 00ca <result>.b
  8775. /// result = 00 -> "The deal has successfully completed."
  8776. /// result = 01 -> "You do not have enough zeny."
  8777. /// result = 02 -> "You are over your Weight Limit."
  8778. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8779. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8780. {
  8781. int n = (RFIFOW(fd,2)-4) /4;
  8782. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8783. int result;
  8784. if( sd->state.trading || !sd->npc_shopid )
  8785. result = 1;
  8786. else
  8787. result = npc_buylist(sd,n,item_list);
  8788. sd->npc_shopid = 0; //Clear shop data.
  8789. WFIFOHEAD(fd,packet_len(0xca));
  8790. WFIFOW(fd,0) = 0xca;
  8791. WFIFOB(fd,2) = result;
  8792. WFIFOSET(fd,packet_len(0xca));
  8793. }
  8794. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8795. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8796. ///
  8797. /// S 00cb <result>.B
  8798. /// result = 00 -> "The deal has successfully completed."
  8799. /// result = 01 -> "The deal has failed."
  8800. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8801. {
  8802. int fail=0,n;
  8803. unsigned short *item_list;
  8804. n = (RFIFOW(fd,2)-4) /4;
  8805. item_list = (unsigned short*)RFIFOP(fd,4);
  8806. if (sd->state.trading || !sd->npc_shopid)
  8807. fail = 1;
  8808. else
  8809. fail = npc_selllist(sd,n,item_list);
  8810. sd->npc_shopid = 0; //Clear shop data.
  8811. WFIFOHEAD(fd,packet_len(0xcb));
  8812. WFIFOW(fd,0)=0xcb;
  8813. WFIFOB(fd,2)=fail;
  8814. WFIFOSET(fd,packet_len(0xcb));
  8815. }
  8816. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8817. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8818. /// type:
  8819. /// 0 = private
  8820. /// 1 = public
  8821. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8822. {
  8823. int len = RFIFOW(fd,2)-15;
  8824. int limit = RFIFOW(fd,4);
  8825. bool pub = (RFIFOB(fd,6) != 0);
  8826. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8827. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8828. char s_password[CHATROOM_PASS_SIZE];
  8829. char s_title[CHATROOM_TITLE_SIZE];
  8830. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8831. return;
  8832. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8833. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8834. return;
  8835. }
  8836. if( len <= 0 )
  8837. return; // invalid input
  8838. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8839. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8840. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8841. }
  8842. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8843. /// 00d9 <chat ID>.L <passwd>.8B
  8844. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8845. {
  8846. int chatid = RFIFOL(fd,2);
  8847. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8848. chat_joinchat(sd,chatid,password);
  8849. }
  8850. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8851. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8852. /// type:
  8853. /// 0 = private
  8854. /// 1 = public
  8855. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8856. {
  8857. int len = RFIFOW(fd,2)-15;
  8858. int limit = RFIFOW(fd,4);
  8859. bool pub = (RFIFOB(fd,6) != 0);
  8860. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8861. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8862. char s_password[CHATROOM_PASS_SIZE];
  8863. char s_title[CHATROOM_TITLE_SIZE];
  8864. if( len <= 0 )
  8865. return; // invalid input
  8866. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8867. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8868. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8869. }
  8870. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8871. /// 00e0 <role>.L <nick>.24B
  8872. /// role:
  8873. /// 0 = owner
  8874. /// 1 = normal
  8875. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8876. {
  8877. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8878. }
  8879. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8880. /// 00e2 <name>.24B
  8881. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8882. {
  8883. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8884. }
  8885. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8886. /// 00e3
  8887. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8888. {
  8889. chat_leavechat(sd,0);
  8890. }
  8891. //Handles notifying asker and rejecter of what has just ocurred.
  8892. //Type is used to determine the correct msg_txt to use:
  8893. //0:
  8894. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8895. {
  8896. const char* msg;
  8897. char output[256];
  8898. // Your request has been rejected by autoreject option.
  8899. msg = msg_txt(392);
  8900. clif_disp_onlyself(src, msg, strlen(msg));
  8901. //Notice that a request was rejected.
  8902. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8903. clif_disp_onlyself(target, output, strlen(output));
  8904. }
  8905. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8906. /// 00e4 <account id>.L
  8907. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8908. {
  8909. struct map_session_data *t_sd;
  8910. t_sd = map_id2sd(RFIFOL(fd,2));
  8911. if(!sd->chatID && pc_cant_act(sd))
  8912. return; //You can trade while in a chatroom.
  8913. // @noask [LuzZza]
  8914. if(t_sd && t_sd->state.noask) {
  8915. clif_noask_sub(sd, t_sd, 0);
  8916. return;
  8917. }
  8918. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8919. {
  8920. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8921. return;
  8922. }
  8923. trade_traderequest(sd,t_sd);
  8924. }
  8925. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8926. /// 00e6 <result>.B
  8927. /// result:
  8928. /// 3 = accepted
  8929. /// 4 = rejected
  8930. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8931. {
  8932. trade_tradeack(sd,RFIFOB(fd,2));
  8933. }
  8934. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  8935. /// 00e8 <index>.W <amount>.L
  8936. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8937. {
  8938. short index = RFIFOW(fd,2);
  8939. int amount = RFIFOL(fd,4);
  8940. if( index == 0 )
  8941. trade_tradeaddzeny(sd, amount);
  8942. else
  8943. trade_tradeadditem(sd, index, (short)amount);
  8944. }
  8945. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  8946. /// 00eb
  8947. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8948. {
  8949. trade_tradeok(sd);
  8950. }
  8951. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  8952. /// 00ed
  8953. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8954. {
  8955. trade_tradecancel(sd);
  8956. }
  8957. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  8958. /// 00ef
  8959. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8960. {
  8961. trade_tradecommit(sd);
  8962. }
  8963. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  8964. /// 0118
  8965. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8966. {
  8967. pc_stop_attack(sd);
  8968. }
  8969. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  8970. /// 0126 <index>.W <amount>.L
  8971. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8972. {
  8973. if (pc_istrading(sd))
  8974. return;
  8975. if (!pc_iscarton(sd))
  8976. return;
  8977. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8978. }
  8979. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  8980. /// 0127 <index>.W <amount>.L
  8981. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8982. {
  8983. if (!pc_iscarton(sd))
  8984. return;
  8985. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8986. }
  8987. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  8988. /// 012a
  8989. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8990. {
  8991. /**
  8992. * Attempts to remove these options when this function is called (will remove all available)
  8993. **/
  8994. #ifdef NEW_CARTS
  8995. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  8996. if( sd->sc.data[SC_PUSH_CART] )
  8997. pc_setcart(sd,0);
  8998. #else
  8999. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9000. #endif
  9001. }
  9002. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9003. /// 01af <num>.W
  9004. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9005. {// TODO: State tracking?
  9006. int type;
  9007. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  9008. return;
  9009. type = (int)RFIFOW(fd,2);
  9010. #ifdef NEW_CARTS
  9011. if( (type == 9 && sd->status.base_level > 131) ||
  9012. (type == 8 && sd->status.base_level > 121) ||
  9013. (type == 7 && sd->status.base_level > 111) ||
  9014. (type == 6 && sd->status.base_level > 101) ||
  9015. (type == 5 && sd->status.base_level > 90) ||
  9016. (type == 4 && sd->status.base_level > 80) ||
  9017. (type == 3 && sd->status.base_level > 65) ||
  9018. (type == 2 && sd->status.base_level > 40) ||
  9019. (type == 1))
  9020. #else
  9021. if( (type == 5 && sd->status.base_level > 90) ||
  9022. (type == 4 && sd->status.base_level > 80) ||
  9023. (type == 3 && sd->status.base_level > 65) ||
  9024. (type == 2 && sd->status.base_level > 40) ||
  9025. (type == 1))
  9026. #endif
  9027. pc_setcart(sd,type);
  9028. }
  9029. /// Request to increase status (CZ_STATUS_CHANGE).
  9030. /// 00bb <status id>.W <amount>.B
  9031. /// status id:
  9032. /// SP_STR ~ SP_LUK
  9033. /// amount:
  9034. /// client sends always 1 for this, even when using /str+ and
  9035. /// the like
  9036. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9037. {
  9038. pc_statusup(sd,RFIFOW(fd,2));
  9039. }
  9040. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9041. /// 0112 <skill id>.W
  9042. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9043. {
  9044. pc_skillup(sd,RFIFOW(fd,2));
  9045. }
  9046. 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)
  9047. {
  9048. int lv;
  9049. if( !hd )
  9050. return;
  9051. if( skillnotok_hom(skillnum, hd) )
  9052. return;
  9053. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  9054. target_id = hd->bl.id;
  9055. if( hd->ud.skilltimer != INVALID_TIMER )
  9056. {
  9057. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  9058. }
  9059. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9060. return;
  9061. lv = merc_hom_checkskill(hd, skillnum);
  9062. if( skilllv > lv )
  9063. skilllv = lv;
  9064. if( skilllv )
  9065. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  9066. }
  9067. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  9068. {
  9069. int lv;
  9070. if( !hd )
  9071. return;
  9072. if( skillnotok_hom(skillnum, hd) )
  9073. return;
  9074. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9075. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  9076. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9077. return;
  9078. if( hd->sc.data[SC_BASILICA] )
  9079. return;
  9080. lv = merc_hom_checkskill(hd, skillnum);
  9081. if( skilllv > lv )
  9082. skilllv = lv;
  9083. if( skilllv )
  9084. unit_skilluse_pos(&hd->bl, x, y, skillnum, skilllv);
  9085. }
  9086. 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)
  9087. {
  9088. int lv;
  9089. if( !md )
  9090. return;
  9091. if( skillnotok_mercenary(skillnum, md) )
  9092. return;
  9093. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  9094. target_id = md->bl.id;
  9095. if( md->ud.skilltimer != INVALID_TIMER )
  9096. {
  9097. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST ) return;
  9098. }
  9099. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9100. return;
  9101. lv = mercenary_checkskill(md, skillnum);
  9102. if( skilllv > lv )
  9103. skilllv = lv;
  9104. if( skilllv )
  9105. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  9106. }
  9107. 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)
  9108. {
  9109. int lv;
  9110. if( !md )
  9111. return;
  9112. if( skillnotok_mercenary(skillnum, md) )
  9113. return;
  9114. if( md->ud.skilltimer != INVALID_TIMER )
  9115. return;
  9116. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9117. {
  9118. clif_skill_fail(md->master, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9119. return;
  9120. }
  9121. if( md->sc.data[SC_BASILICA] )
  9122. return;
  9123. lv = mercenary_checkskill(md, skillnum);
  9124. if( skilllv > lv )
  9125. skilllv = lv;
  9126. if( skilllv )
  9127. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  9128. }
  9129. /// Request to use a targeted skill.
  9130. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9131. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9132. /// There are various variants of this packet, some of them have padding between fields.
  9133. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9134. {
  9135. short skillnum, skilllv;
  9136. int tmp, target_id;
  9137. unsigned int tick = gettick();
  9138. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9139. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9140. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9141. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9142. tmp = skill_get_inf(skillnum);
  9143. if (tmp&INF_GROUND_SKILL || !tmp)
  9144. return; //Using a ground/passive skill on a target? WRONG.
  9145. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  9146. {
  9147. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  9148. return;
  9149. }
  9150. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9151. {
  9152. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  9153. return;
  9154. }
  9155. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9156. sd->idletime = last_tick;
  9157. if( pc_cant_act(sd) && !(skillnum == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9158. return;
  9159. if( pc_issit(sd) )
  9160. return;
  9161. if( skillnotok(skillnum, sd) )
  9162. return;
  9163. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9164. target_id = sd->bl.id; // never trust the client
  9165. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9166. target_id = sd->bl.id;
  9167. if( sd->ud.skilltimer != INVALID_TIMER )
  9168. {
  9169. if( skillnum != SA_CASTCANCEL && skillnum != SO_SPELLFIST )
  9170. return;
  9171. }
  9172. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  9173. {
  9174. if( sd->skillitem != skillnum )
  9175. {
  9176. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9177. return;
  9178. }
  9179. }
  9180. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9181. return;
  9182. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9183. return; // On basilica only caster can use Basilica again to stop it.
  9184. if( sd->menuskill_id ) {
  9185. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9186. clif_menuskill_clear(sd); //Cancel pet capture.
  9187. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9188. return; //Can't use skills while a menu is open.
  9189. }
  9190. if( sd->skillitem == skillnum ) {
  9191. if( skilllv != sd->skillitemlv )
  9192. skilllv = sd->skillitemlv;
  9193. if( !(tmp&INF_SELF_SKILL) )
  9194. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9195. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9196. return;
  9197. }
  9198. sd->skillitem = sd->skillitemlv = 0;
  9199. if( skillnum >= GD_SKILLBASE ) {
  9200. if( sd->state.gmaster_flag )
  9201. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  9202. else
  9203. skilllv = 0;
  9204. } else {
  9205. tmp = pc_checkskill(sd, skillnum);
  9206. if( skilllv > tmp )
  9207. skilllv = tmp;
  9208. }
  9209. pc_delinvincibletimer(sd);
  9210. if( skilllv )
  9211. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  9212. }
  9213. /*==========================================
  9214. * Client tells server he'd like to use AoE skill id 'skillnum' of level 'skilllv' on 'x','y' location
  9215. *------------------------------------------*/
  9216. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  9217. {
  9218. unsigned int tick = gettick();
  9219. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  9220. return; //Using a target skill on the ground? WRONG.
  9221. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9222. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  9223. return;
  9224. }
  9225. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  9226. {
  9227. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  9228. return;
  9229. }
  9230. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9231. sd->idletime = last_tick;
  9232. if( skillnotok(skillnum, sd) )
  9233. return;
  9234. if( skillmoreinfo != -1 )
  9235. {
  9236. if( pc_issit(sd) )
  9237. {
  9238. clif_skill_fail(sd, skillnum, USESKILL_FAIL_LEVEL, 0);
  9239. return;
  9240. }
  9241. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9242. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9243. }
  9244. if( sd->ud.skilltimer != INVALID_TIMER )
  9245. return;
  9246. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9247. if( sd->skillitem != skillnum ) {
  9248. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  9249. return;
  9250. }
  9251. }
  9252. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9253. return;
  9254. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9255. return; // On basilica only caster can use Basilica again to stop it.
  9256. if( sd->menuskill_id ) {
  9257. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9258. clif_menuskill_clear(sd); //Cancel pet capture.
  9259. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9260. return; //Can't use skills while a menu is open.
  9261. }
  9262. pc_delinvincibletimer(sd);
  9263. if( sd->skillitem == skillnum ) {
  9264. if( skilllv != sd->skillitemlv )
  9265. skilllv = sd->skillitemlv;
  9266. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  9267. } else {
  9268. int lv;
  9269. sd->skillitem = sd->skillitemlv = 0;
  9270. if( (lv = pc_checkskill(sd, skillnum)) > 0 ) {
  9271. if( skilllv > lv )
  9272. skilllv = lv;
  9273. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  9274. }
  9275. }
  9276. }
  9277. /// Request to use a ground skill.
  9278. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9279. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9280. /// There are various variants of this packet, some of them have padding between fields.
  9281. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9282. {
  9283. if (pc_cant_act(sd))
  9284. return;
  9285. if (pc_issit(sd))
  9286. return;
  9287. clif_parse_UseSkillToPosSub(fd, sd,
  9288. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9289. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9290. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9291. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9292. -1 //Skill more info.
  9293. );
  9294. }
  9295. /// Request to use a ground skill with text.
  9296. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9297. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9298. /// There are various variants of this packet, some of them have padding between fields.
  9299. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9300. {
  9301. if (pc_cant_act(sd))
  9302. return;
  9303. if (pc_issit(sd))
  9304. return;
  9305. clif_parse_UseSkillToPosSub(fd, sd,
  9306. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9307. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9308. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9309. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9310. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9311. );
  9312. }
  9313. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9314. /// 011b <skill id>.W <map name>.16B
  9315. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9316. {
  9317. short skill_num = RFIFOW(fd,2);
  9318. char map_name[MAP_NAME_LENGTH];
  9319. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9320. if(skill_num != sd->menuskill_id)
  9321. return;
  9322. if( pc_cant_act(sd) ) {
  9323. clif_menuskill_clear(sd);
  9324. return;
  9325. }
  9326. pc_delinvincibletimer(sd);
  9327. skill_castend_map(sd,skill_num,map_name);
  9328. }
  9329. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9330. /// 011d
  9331. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9332. {
  9333. if (!pc_isdead(sd))
  9334. pc_memo(sd,-1);
  9335. }
  9336. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9337. /// 018e <name id>.W { <material id>.W }*3
  9338. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9339. {
  9340. switch( sd->menuskill_id ) {
  9341. case -1:
  9342. case AM_PHARMACY:
  9343. case RK_RUNEMASTERY:
  9344. case GC_CREATENEWPOISON:
  9345. break;
  9346. default:
  9347. return;
  9348. }
  9349. if (pc_istrading(sd)) {
  9350. //Make it fail to avoid shop exploits where you sell something different than you see.
  9351. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9352. clif_menuskill_clear(sd);
  9353. return;
  9354. }
  9355. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9356. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9357. clif_menuskill_clear(sd);
  9358. }
  9359. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9360. /// 025b <mk type>.W <name id>.W
  9361. /// mk type:
  9362. /// 1 = cooking
  9363. /// 2 = arrow
  9364. /// 3 = elemental
  9365. /// 4 = GN_MIX_COOKING
  9366. /// 5 = GN_MAKEBOMB
  9367. /// 6 = GN_S_PHARMACY
  9368. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9369. int type = RFIFOW(fd,2);
  9370. int nameid = RFIFOW(fd,4);
  9371. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9372. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9373. return;
  9374. if (pc_istrading(sd)) {
  9375. //Make it fail to avoid shop exploits where you sell something different than you see.
  9376. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9377. clif_menuskill_clear(sd);
  9378. return;
  9379. }
  9380. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9381. skill_produce_mix(sd,sd->menuskill_id,nameid,0,0,0,amount);
  9382. clif_menuskill_clear(sd);
  9383. }
  9384. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9385. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9386. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9387. {
  9388. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9389. return;
  9390. if (pc_istrading(sd)) {
  9391. //Make it fail to avoid shop exploits where you sell something different than you see.
  9392. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9393. clif_menuskill_clear(sd);
  9394. return;
  9395. }
  9396. skill_repairweapon(sd,RFIFOW(fd,2));
  9397. clif_menuskill_clear(sd);
  9398. }
  9399. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9400. /// 0222 <index>.L
  9401. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9402. {
  9403. int idx;
  9404. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9405. return;
  9406. if (pc_istrading(sd)) {
  9407. //Make it fail to avoid shop exploits where you sell something different than you see.
  9408. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9409. clif_menuskill_clear(sd);
  9410. return;
  9411. }
  9412. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9413. skill_weaponrefine(sd, idx-2);
  9414. clif_menuskill_clear(sd);
  9415. }
  9416. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9417. /// 00b8 <npc id>.L <choice>.B
  9418. /// choice:
  9419. /// 1~254 = menu item
  9420. /// 255 = cancel
  9421. /// NOTE: If there were more than 254 items in the list, choice
  9422. /// overflows to choice%256.
  9423. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9424. {
  9425. int npc_id = RFIFOL(fd,2);
  9426. uint8 select = RFIFOB(fd,6);
  9427. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  9428. {
  9429. TBL_NPC* nd = map_id2nd(npc_id);
  9430. 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);
  9431. clif_GM_kick(NULL,sd);
  9432. return;
  9433. }
  9434. sd->npc_menu = select;
  9435. npc_scriptcont(sd,npc_id);
  9436. }
  9437. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9438. /// 00b9 <npc id>.L
  9439. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9440. {
  9441. npc_scriptcont(sd,RFIFOL(fd,2));
  9442. }
  9443. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9444. /// 0143 <npc id>.L <value>.L
  9445. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9446. {
  9447. int npcid = RFIFOL(fd,2);
  9448. int amount = (int)RFIFOL(fd,6);
  9449. sd->npc_amount = amount;
  9450. npc_scriptcont(sd, npcid);
  9451. }
  9452. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9453. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9454. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9455. {
  9456. int message_len = RFIFOW(fd,2)-8;
  9457. int npcid = RFIFOL(fd,4);
  9458. const char* message = (char*)RFIFOP(fd,8);
  9459. if( message_len <= 0 )
  9460. return; // invalid input
  9461. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9462. npc_scriptcont(sd, npcid);
  9463. }
  9464. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9465. /// 0146 <npc id>.L
  9466. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9467. {
  9468. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9469. return;
  9470. npc_scriptcont(sd,RFIFOL(fd,2));
  9471. }
  9472. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9473. /// 0178 <index>.W
  9474. /// index:
  9475. /// -1 = cancel
  9476. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9477. {
  9478. short idx = RFIFOW(fd,2);
  9479. if (sd->menuskill_id != MC_IDENTIFY)
  9480. return;
  9481. if( idx == -1 ) {// cancel pressed
  9482. clif_menuskill_clear(sd);
  9483. return;
  9484. }
  9485. skill_identify(sd,idx-2);
  9486. clif_menuskill_clear(sd);
  9487. }
  9488. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9489. /// 01ae <name id>.W
  9490. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9491. {
  9492. if (pc_istrading(sd)) {
  9493. //Make it fail to avoid shop exploits where you sell something different than you see.
  9494. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  9495. clif_menuskill_clear(sd);
  9496. return;
  9497. }
  9498. switch( sd->menuskill_id ) {
  9499. case AC_MAKINGARROW:
  9500. skill_arrow_create(sd,RFIFOW(fd,2));
  9501. break;
  9502. case SA_CREATECON:
  9503. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9504. break;
  9505. case WL_READING_SB:
  9506. skill_spellbook(sd,RFIFOW(fd,2));
  9507. break;
  9508. case GC_POISONINGWEAPON:
  9509. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9510. break;
  9511. case NC_MAGICDECOY:
  9512. skill_magicdecoy(sd,RFIFOW(fd,2));
  9513. break;
  9514. }
  9515. clif_menuskill_clear(sd);
  9516. }
  9517. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9518. /// 01ce <skill id>.L
  9519. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9520. {
  9521. if (sd->menuskill_id != SA_AUTOSPELL)
  9522. return;
  9523. skill_autospell(sd,RFIFOL(fd,2));
  9524. clif_menuskill_clear(sd);
  9525. }
  9526. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9527. /// 017a <card index>.W
  9528. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9529. {
  9530. if (sd->state.trading != 0)
  9531. return;
  9532. clif_use_card(sd,RFIFOW(fd,2)-2);
  9533. }
  9534. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9535. /// 017c <card index>.W <equip index>.W
  9536. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9537. {
  9538. if (sd->state.trading != 0)
  9539. return;
  9540. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9541. }
  9542. /// Request of character's name by char ID.
  9543. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9544. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9545. /// There are various variants of this packet, some of them have padding between fields.
  9546. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9547. {
  9548. int charid;
  9549. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9550. map_reqnickdb(sd, charid);
  9551. }
  9552. /// /resetskill /resetstate (CZ_RESET).
  9553. /// Request to reset stats or skills.
  9554. /// 0197 <type>.W
  9555. /// type:
  9556. /// 0 = state
  9557. /// 1 = skill
  9558. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9559. char cmd[15];
  9560. if( RFIFOW(fd,2) )
  9561. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9562. else
  9563. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9564. is_atcommand(fd, sd, cmd, 1);
  9565. }
  9566. /// /lb /nlb (CZ_LOCALBROADCAST).
  9567. /// Request to broadcast a message on current map.
  9568. /// 019c <packet len>.W <text>.?B
  9569. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9570. {
  9571. char command[CHAT_SIZE_MAX+16];
  9572. char* msg = (char*)RFIFOP(fd,4);
  9573. unsigned int len = RFIFOW(fd,2)-4;
  9574. // as the length varies depending on the command used, just block unreasonably long strings
  9575. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  9576. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9577. is_atcommand(fd, sd, command, 1);
  9578. }
  9579. /// Request to move an item from inventory to storage.
  9580. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9581. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9582. /// There are various variants of this packet, some of them have padding between fields.
  9583. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9584. {
  9585. int item_index, item_amount;
  9586. if (pc_istrading(sd))
  9587. return;
  9588. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9589. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9590. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9591. return;
  9592. if (sd->state.storage_flag == 1)
  9593. storage_storageadd(sd, item_index, item_amount);
  9594. else
  9595. if (sd->state.storage_flag == 2)
  9596. storage_guild_storageadd(sd, item_index, item_amount);
  9597. }
  9598. /// Request to move an item from storage to inventory.
  9599. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9600. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9601. /// There are various variants of this packet, some of them have padding between fields.
  9602. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9603. {
  9604. int item_index, item_amount;
  9605. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9606. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9607. if (sd->state.storage_flag == 1)
  9608. storage_storageget(sd, item_index, item_amount);
  9609. else
  9610. if(sd->state.storage_flag == 2)
  9611. storage_guild_storageget(sd, item_index, item_amount);
  9612. }
  9613. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9614. /// 0129 <index>.W <amount>.L
  9615. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9616. {
  9617. if( sd->state.vending )
  9618. return;
  9619. if (!pc_iscarton(sd))
  9620. return;
  9621. if (sd->state.storage_flag == 1)
  9622. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9623. else
  9624. if (sd->state.storage_flag == 2)
  9625. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9626. }
  9627. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9628. /// 0128 <index>.W <amount>.L
  9629. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9630. {
  9631. if( sd->state.vending )
  9632. return;
  9633. if (!pc_iscarton(sd))
  9634. return;
  9635. if (sd->state.storage_flag == 1)
  9636. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9637. else
  9638. if (sd->state.storage_flag == 2)
  9639. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9640. }
  9641. /// Request to close storage (CZ_CLOSE_STORE).
  9642. /// 00f7
  9643. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9644. {
  9645. if( sd->state.storage_flag == 1 )
  9646. storage_storageclose(sd);
  9647. else
  9648. if( sd->state.storage_flag == 2 )
  9649. storage_guild_storageclose(sd);
  9650. }
  9651. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9652. /// 023a <info>.W
  9653. /// info:
  9654. /// 0 = password has not been set yet
  9655. /// 1 = storage is password-protected
  9656. /// 8 = too many wrong passwords
  9657. /// ? = ignored
  9658. /// NOTE: This packet is only available on certain non-kRO clients.
  9659. void clif_storagepassword(struct map_session_data* sd, short info)
  9660. {
  9661. int fd = sd->fd;
  9662. WFIFOHEAD(fd,packet_len(0x23a));
  9663. WFIFOW(fd,0) = 0x23a;
  9664. WFIFOW(fd,2) = info;
  9665. WFIFOSET(fd,packet_len(0x23a));
  9666. }
  9667. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9668. /// 023b <type>.W <password>.16B <new password>.16B
  9669. /// type:
  9670. /// 2 = change password
  9671. /// 3 = check password
  9672. /// NOTE: This packet is only available on certain non-kRO clients.
  9673. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9674. {
  9675. //TODO
  9676. }
  9677. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9678. /// 023c <result>.W <error count>.W
  9679. /// result:
  9680. /// 4 = password change success
  9681. /// 5 = password change failure
  9682. /// 6 = password check success
  9683. /// 7 = password check failure
  9684. /// 8 = too many wrong passwords
  9685. /// ? = ignored
  9686. /// NOTE: This packet is only available on certain non-kRO clients.
  9687. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9688. {
  9689. int fd = sd->fd;
  9690. WFIFOHEAD(fd,packet_len(0x23c));
  9691. WFIFOW(fd,0) = 0x23c;
  9692. WFIFOW(fd,2) = result;
  9693. WFIFOW(fd,4) = error_count;
  9694. WFIFOSET(fd,packet_len(0x23c));
  9695. }
  9696. /// Party creation request
  9697. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9698. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9699. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9700. {
  9701. char* name = (char*)RFIFOP(fd,2);
  9702. name[NAME_LENGTH-1] = '\0';
  9703. if( map[sd->bl.m].flag.partylock )
  9704. {// Party locked.
  9705. clif_displaymessage(fd, msg_txt(227));
  9706. return;
  9707. }
  9708. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9709. {
  9710. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9711. return;
  9712. }
  9713. party_create(sd,name,0,0);
  9714. }
  9715. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9716. {
  9717. char* name = (char*)RFIFOP(fd,2);
  9718. int item1 = RFIFOB(fd,26);
  9719. int item2 = RFIFOB(fd,27);
  9720. name[NAME_LENGTH-1] = '\0';
  9721. if( map[sd->bl.m].flag.partylock )
  9722. {// Party locked.
  9723. clif_displaymessage(fd, msg_txt(227));
  9724. return;
  9725. }
  9726. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9727. {
  9728. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9729. return;
  9730. }
  9731. party_create(sd,name,item1,item2);
  9732. }
  9733. /// Party invitation request
  9734. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9735. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9736. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9737. {
  9738. struct map_session_data *t_sd;
  9739. if(map[sd->bl.m].flag.partylock)
  9740. {// Party locked.
  9741. clif_displaymessage(fd, msg_txt(227));
  9742. return;
  9743. }
  9744. t_sd = map_id2sd(RFIFOL(fd,2));
  9745. if(t_sd && t_sd->state.noask)
  9746. {// @noask [LuzZza]
  9747. clif_noask_sub(sd, t_sd, 1);
  9748. return;
  9749. }
  9750. party_invite(sd, t_sd);
  9751. }
  9752. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9753. {
  9754. struct map_session_data *t_sd;
  9755. char *name = (char*)RFIFOP(fd,2);
  9756. name[NAME_LENGTH-1] = '\0';
  9757. if(map[sd->bl.m].flag.partylock)
  9758. {// Party locked.
  9759. clif_displaymessage(fd, msg_txt(227));
  9760. return;
  9761. }
  9762. t_sd = map_nick2sd(name);
  9763. if(t_sd && t_sd->state.noask)
  9764. {// @noask [LuzZza]
  9765. clif_noask_sub(sd, t_sd, 1);
  9766. return;
  9767. }
  9768. party_invite(sd, t_sd);
  9769. }
  9770. /// Party invitation reply
  9771. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9772. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9773. /// flag:
  9774. /// 0 = reject
  9775. /// 1 = accept
  9776. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9777. {
  9778. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9779. }
  9780. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9781. {
  9782. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9783. }
  9784. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9785. /// 0100
  9786. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9787. {
  9788. if(map[sd->bl.m].flag.partylock)
  9789. { //Guild locked.
  9790. clif_displaymessage(fd, msg_txt(227));
  9791. return;
  9792. }
  9793. party_leave(sd);
  9794. }
  9795. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9796. /// 0103 <account id>.L <char name>.24B
  9797. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9798. {
  9799. if(map[sd->bl.m].flag.partylock)
  9800. { //Guild locked.
  9801. clif_displaymessage(fd, msg_txt(227));
  9802. return;
  9803. }
  9804. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9805. }
  9806. /// Request to change party options.
  9807. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9808. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9809. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9810. {
  9811. struct party_data *p;
  9812. int i;
  9813. if( !sd->status.party_id )
  9814. return;
  9815. p = party_search(sd->status.party_id);
  9816. if( p == NULL )
  9817. return;
  9818. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9819. if( i == MAX_PARTY )
  9820. return; //Shouldn't happen
  9821. if( !p->party.member[i].leader )
  9822. return;
  9823. #if PACKETVER < 20090603
  9824. //Client can't change the item-field
  9825. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9826. #else
  9827. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9828. #endif
  9829. }
  9830. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9831. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9832. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9833. {
  9834. const char* text = (char*)RFIFOP(fd,4);
  9835. int textlen = RFIFOW(fd,2) - 4;
  9836. char *name, *message;
  9837. int namelen, messagelen;
  9838. // validate packet and retrieve name and message
  9839. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9840. return;
  9841. if( is_atcommand(fd, sd, message, 1) )
  9842. return;
  9843. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9844. return;
  9845. if( battle_config.min_chat_delay )
  9846. { //[Skotlex]
  9847. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9848. return;
  9849. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9850. }
  9851. party_send_message(sd, text, textlen);
  9852. }
  9853. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9854. /// 07da <account id>.L
  9855. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9856. {
  9857. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9858. }
  9859. /// Party Booking in KRO [Spiria]
  9860. ///
  9861. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9862. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9863. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9864. {
  9865. short level = RFIFOW(fd,2);
  9866. short mapid = RFIFOW(fd,4);
  9867. short job[PARTY_BOOKING_JOBS];
  9868. int i;
  9869. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9870. job[i] = RFIFOB(fd,6+i*2);
  9871. party_booking_register(sd, level, mapid, job);
  9872. }
  9873. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9874. /// 0803 <result>.W
  9875. /// result:
  9876. /// 0 = success
  9877. /// 1 = failure
  9878. /// 2 = already registered
  9879. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9880. {
  9881. int fd = sd->fd;
  9882. WFIFOHEAD(fd,packet_len(0x803));
  9883. WFIFOW(fd,0) = 0x803;
  9884. WFIFOW(fd,2) = flag;
  9885. WFIFOSET(fd,packet_len(0x803));
  9886. }
  9887. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9888. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9889. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9890. {
  9891. short level = RFIFOW(fd,2);
  9892. short mapid = RFIFOW(fd,4);
  9893. short job = RFIFOW(fd,6);
  9894. unsigned long lastindex = RFIFOL(fd,8);
  9895. short resultcount = RFIFOW(fd,12);
  9896. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9897. }
  9898. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9899. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9900. /// more results:
  9901. /// 0 = no
  9902. /// 1 = yes
  9903. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9904. {
  9905. int i, j;
  9906. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9907. struct party_booking_ad_info *pb_ad;
  9908. WFIFOHEAD(fd,size*count + 5);
  9909. WFIFOW(fd,0) = 0x805;
  9910. WFIFOW(fd,2) = size*count + 5;
  9911. WFIFOB(fd,4) = more_result;
  9912. for(i=0; i<count; i++)
  9913. {
  9914. pb_ad = results[i];
  9915. WFIFOL(fd,i*size+5) = pb_ad->index;
  9916. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9917. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9918. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9919. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9920. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9921. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9922. }
  9923. WFIFOSET(fd,WFIFOW(fd,2));
  9924. }
  9925. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9926. /// 0806
  9927. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9928. {
  9929. if(party_booking_delete(sd))
  9930. clif_PartyBookingDeleteAck(sd, 0);
  9931. }
  9932. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9933. /// 0807 <result>.W
  9934. /// result:
  9935. /// 0 = success
  9936. /// 1 = success (auto-removed expired ad)
  9937. /// 2 = failure
  9938. /// 3 = nothing registered
  9939. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9940. {
  9941. int fd = sd->fd;
  9942. WFIFOHEAD(fd,packet_len(0x807));
  9943. WFIFOW(fd,0) = 0x807;
  9944. WFIFOW(fd,2) = flag;
  9945. WFIFOSET(fd,packet_len(0x807));
  9946. }
  9947. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  9948. /// 0808 { <job>.W }*6
  9949. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9950. {
  9951. short job[PARTY_BOOKING_JOBS];
  9952. int i;
  9953. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9954. job[i] = RFIFOW(fd,2+i*2);
  9955. party_booking_update(sd, job);
  9956. }
  9957. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  9958. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  9959. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9960. {
  9961. int i;
  9962. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9963. if(pb_ad == NULL) return;
  9964. WBUFW(buf,0) = 0x809;
  9965. WBUFL(buf,2) = pb_ad->index;
  9966. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9967. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  9968. WBUFW(buf,34) = pb_ad->p_detail.level;
  9969. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9970. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9971. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9972. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9973. }
  9974. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  9975. /// 080a <index>.L { <job>.W }*6
  9976. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9977. {
  9978. int i;
  9979. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9980. if(pb_ad == NULL) return;
  9981. WBUFW(buf,0) = 0x80a;
  9982. WBUFL(buf,2) = pb_ad->index;
  9983. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9984. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9985. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9986. }
  9987. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  9988. /// 080b <index>.L
  9989. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9990. {
  9991. uint8 buf[6];
  9992. WBUFW(buf,0) = 0x80b;
  9993. WBUFL(buf,2) = index;
  9994. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9995. }
  9996. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  9997. /// 012e
  9998. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9999. {
  10000. vending_closevending(sd);
  10001. }
  10002. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10003. /// 0130 <account id>.L
  10004. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10005. {
  10006. if( sd->npc_id )
  10007. {// using an NPC
  10008. return;
  10009. }
  10010. vending_vendinglistreq(sd,RFIFOL(fd,2));
  10011. }
  10012. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10013. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10014. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  10015. {
  10016. int len = (int)RFIFOW(fd,2) - 8;
  10017. int id = (int)RFIFOL(fd,4);
  10018. const uint8* data = (uint8*)RFIFOP(fd,8);
  10019. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10020. // whether it fails or not, the buy window is closed
  10021. sd->vended_id = 0;
  10022. }
  10023. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10024. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10025. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  10026. {
  10027. int len = (int)RFIFOW(fd,2) - 12;
  10028. int aid = (int)RFIFOL(fd,4);
  10029. int uid = (int)RFIFOL(fd,8);
  10030. const uint8* data = (uint8*)RFIFOP(fd,12);
  10031. vending_purchasereq(sd, aid, uid, data, len/4);
  10032. // whether it fails or not, the buy window is closed
  10033. sd->vended_id = 0;
  10034. }
  10035. /// Confirm or cancel the shop preparation window.
  10036. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10037. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10038. /// result:
  10039. /// 0 = canceled
  10040. /// 1 = open
  10041. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  10042. {
  10043. short len = (short)RFIFOW(fd,2) - 85;
  10044. const char* message = (char*)RFIFOP(fd,4);
  10045. bool flag = (bool)RFIFOB(fd,84);
  10046. const uint8* data = (uint8*)RFIFOP(fd,85);
  10047. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10048. return;
  10049. if( map[sd->bl.m].flag.novending ) {
  10050. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  10051. return;
  10052. }
  10053. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10054. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  10055. return;
  10056. }
  10057. if( vending_checknearnpc(&sd->bl) ) {
  10058. clif_displaymessage(sd->fd, msg_txt(662));
  10059. clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0);
  10060. return;
  10061. }
  10062. if( message[0] == '\0' ) // invalid input
  10063. return;
  10064. vending_openvending(sd, message, flag, data, len/8);
  10065. }
  10066. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10067. /// 0165 <char id>.L <guild name>.24B
  10068. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  10069. {
  10070. char* name = (char*)RFIFOP(fd,6);
  10071. name[NAME_LENGTH-1] = '\0';
  10072. if(map[sd->bl.m].flag.guildlock)
  10073. { //Guild locked.
  10074. clif_displaymessage(fd, msg_txt(228));
  10075. return;
  10076. }
  10077. guild_create(sd, name);
  10078. }
  10079. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10080. /// 014d
  10081. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10082. {
  10083. clif_guild_masterormember(sd);
  10084. }
  10085. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10086. /// 014f <type>.L
  10087. /// type:
  10088. /// 0 = basic info
  10089. /// 1 = member manager
  10090. /// 2 = positions
  10091. /// 3 = skills
  10092. /// 4 = expulsion list
  10093. /// 5 = unknown (GM_ALLGUILDLIST)
  10094. /// 6 = notice
  10095. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10096. {
  10097. if( !sd->status.guild_id && !sd->bg_id )
  10098. return;
  10099. switch( RFIFOL(fd,2) )
  10100. {
  10101. case 0: // ギルド基本情報、同盟敵対情報
  10102. clif_guild_basicinfo(sd);
  10103. clif_guild_allianceinfo(sd);
  10104. break;
  10105. case 1: // メンバーリスト、役職名リスト
  10106. clif_guild_positionnamelist(sd);
  10107. clif_guild_memberlist(sd);
  10108. break;
  10109. case 2: // 役職名リスト、役職情報リスト
  10110. clif_guild_positionnamelist(sd);
  10111. clif_guild_positioninfolist(sd);
  10112. break;
  10113. case 3: // スキルリスト
  10114. clif_guild_skillinfo(sd);
  10115. break;
  10116. case 4: // 追放リスト
  10117. clif_guild_expulsionlist(sd);
  10118. break;
  10119. default:
  10120. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10121. break;
  10122. }
  10123. }
  10124. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10125. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10126. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10127. {
  10128. int i;
  10129. if(!sd->state.gmaster_flag)
  10130. return;
  10131. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  10132. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10133. }
  10134. }
  10135. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10136. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10137. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10138. {
  10139. int i;
  10140. if(!sd->state.gmaster_flag)
  10141. return;
  10142. for(i=4;i<RFIFOW(fd,2);i+=12){
  10143. guild_change_memberposition(sd->status.guild_id,
  10144. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10145. }
  10146. }
  10147. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10148. /// 0151 <guild id>.L
  10149. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10150. {
  10151. struct guild* g;
  10152. int guild_id = RFIFOL(fd,2);
  10153. if( (g = guild_search(guild_id)) != NULL )
  10154. clif_guild_emblem(sd,g);
  10155. }
  10156. /// Validates data of a guild emblem (compressed bitmap)
  10157. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10158. {
  10159. bool success;
  10160. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10161. unsigned long buf_len = sizeof(buf);
  10162. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10163. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10164. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10165. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10166. ;
  10167. return success;
  10168. }
  10169. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10170. /// 0153 <packet len>.W <emblem data>.?B
  10171. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10172. {
  10173. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10174. const uint8* emblem = RFIFOP(fd,4);
  10175. if( !emblem_len || !sd->state.gmaster_flag )
  10176. return;
  10177. if( !clif_validate_emblem(emblem, emblem_len) )
  10178. {
  10179. 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);
  10180. return;
  10181. }
  10182. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10183. }
  10184. /// Guild notice update request (CZ_GUILD_NOTICE).
  10185. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10186. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10187. {
  10188. int guild_id = RFIFOL(fd,2);
  10189. char* msg1 = (char*)RFIFOP(fd,6);
  10190. char* msg2 = (char*)RFIFOP(fd,66);
  10191. if(!sd->state.gmaster_flag)
  10192. return;
  10193. // compensate for some client defects when using multilanguage mode
  10194. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10195. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10196. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10197. guild_change_notice(sd, guild_id, msg1, msg2);
  10198. }
  10199. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10200. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10201. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10202. {
  10203. struct map_session_data *t_sd;
  10204. if(map[sd->bl.m].flag.guildlock)
  10205. { //Guild locked.
  10206. clif_displaymessage(fd, msg_txt(228));
  10207. return;
  10208. }
  10209. t_sd = map_id2sd(RFIFOL(fd,2));
  10210. // @noask [LuzZza]
  10211. if(t_sd && t_sd->state.noask) {
  10212. clif_noask_sub(sd, t_sd, 2);
  10213. return;
  10214. }
  10215. guild_invite(sd,t_sd);
  10216. }
  10217. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10218. /// 016b <guild id>.L <answer>.L
  10219. /// answer:
  10220. /// 0 = refuse
  10221. /// 1 = accept
  10222. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10223. {
  10224. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10225. }
  10226. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10227. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10228. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10229. {
  10230. if(map[sd->bl.m].flag.guildlock)
  10231. { //Guild locked.
  10232. clif_displaymessage(fd, msg_txt(228));
  10233. return;
  10234. }
  10235. if( sd->bg_id )
  10236. {
  10237. clif_displaymessage(fd, "You can't leave battleground guilds.");
  10238. return;
  10239. }
  10240. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10241. }
  10242. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10243. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10244. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10245. {
  10246. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10247. { // Guild locked.
  10248. clif_displaymessage(fd, msg_txt(228));
  10249. return;
  10250. }
  10251. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10252. }
  10253. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10254. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10255. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10256. {
  10257. const char* text = (char*)RFIFOP(fd,4);
  10258. int textlen = RFIFOW(fd,2) - 4;
  10259. char *name, *message;
  10260. int namelen, messagelen;
  10261. // validate packet and retrieve name and message
  10262. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10263. return;
  10264. if( is_atcommand(fd, sd, message, 1) )
  10265. return;
  10266. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10267. return;
  10268. if( battle_config.min_chat_delay )
  10269. { //[Skotlex]
  10270. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10271. return;
  10272. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10273. }
  10274. if( sd->bg_id )
  10275. bg_send_message(sd, text, textlen);
  10276. else
  10277. guild_send_message(sd, text, textlen);
  10278. }
  10279. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10280. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10281. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10282. {
  10283. struct map_session_data *t_sd;
  10284. if(!sd->state.gmaster_flag)
  10285. return;
  10286. if(map[sd->bl.m].flag.guildlock)
  10287. { //Guild locked.
  10288. clif_displaymessage(fd, msg_txt(228));
  10289. return;
  10290. }
  10291. t_sd = map_id2sd(RFIFOL(fd,2));
  10292. // @noask [LuzZza]
  10293. if(t_sd && t_sd->state.noask) {
  10294. clif_noask_sub(sd, t_sd, 3);
  10295. return;
  10296. }
  10297. guild_reqalliance(sd,t_sd);
  10298. }
  10299. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10300. /// 0172 <inviter account id>.L <answer>.L
  10301. /// answer:
  10302. /// 0 = refuse
  10303. /// 1 = accept
  10304. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10305. {
  10306. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10307. }
  10308. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10309. /// 0183 <opponent guild id>.L <relation>.L
  10310. /// relation:
  10311. /// 0 = Ally
  10312. /// 1 = Enemy
  10313. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10314. {
  10315. if(!sd->state.gmaster_flag)
  10316. return;
  10317. if(map[sd->bl.m].flag.guildlock)
  10318. { //Guild locked.
  10319. clif_displaymessage(fd, msg_txt(228));
  10320. return;
  10321. }
  10322. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10323. }
  10324. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10325. /// 0180 <account id>.L
  10326. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10327. {
  10328. struct map_session_data *t_sd;
  10329. if(!sd->state.gmaster_flag)
  10330. return;
  10331. if(map[sd->bl.m].flag.guildlock)
  10332. { //Guild locked.
  10333. clif_displaymessage(fd, msg_txt(228));
  10334. return;
  10335. }
  10336. t_sd = map_id2sd(RFIFOL(fd,2));
  10337. // @noask [LuzZza]
  10338. if(t_sd && t_sd->state.noask) {
  10339. clif_noask_sub(sd, t_sd, 4);
  10340. return;
  10341. }
  10342. guild_opposition(sd,t_sd);
  10343. }
  10344. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10345. /// 015d <key>.40B
  10346. /// key:
  10347. /// now guild name; might have been (intended) email, since the
  10348. /// field name and size is same as the one in CH_DELETE_CHAR.
  10349. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10350. {
  10351. if( map[sd->bl.m].flag.guildlock )
  10352. { //Guild locked.
  10353. clif_displaymessage(fd, msg_txt(228));
  10354. return;
  10355. }
  10356. guild_break(sd,(char*)RFIFOP(fd,2));
  10357. }
  10358. /// Pet
  10359. ///
  10360. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10361. /// 01a1 <type>.B
  10362. /// type:
  10363. /// 0 = pet information
  10364. /// 1 = feed
  10365. /// 2 = performance
  10366. /// 3 = return to egg
  10367. /// 4 = unequip accessory
  10368. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10369. {
  10370. pet_menu(sd,RFIFOB(fd,2));
  10371. }
  10372. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10373. /// 019f <id>.L
  10374. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10375. {
  10376. pet_catch_process2(sd,RFIFOL(fd,2));
  10377. }
  10378. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10379. /// 01a7 <index>.W
  10380. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10381. {
  10382. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10383. {
  10384. //Forged packet, disconnect them [Kevin]
  10385. clif_authfail_fd(fd, 0);
  10386. return;
  10387. }
  10388. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10389. clif_menuskill_clear(sd);
  10390. }
  10391. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10392. /// 01a9 <data>.L
  10393. /// data:
  10394. /// is either emotion (@see enum emotion_type) or a compound value
  10395. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10396. /// entry (given in parentheses) in data\pettalktable.xml
  10397. /// act id:
  10398. /// 0 = feeding
  10399. /// 1 = hunting
  10400. /// 2 = danger
  10401. /// 3 = dead
  10402. /// 4 = normal (stand)
  10403. /// 5 = special performance (perfor_s)
  10404. /// 6 = level up (levelup)
  10405. /// 7 = performance 1 (perfor_1)
  10406. /// 8 = performance 2 (perfor_2)
  10407. /// 9 = performance 3 (perfor_3)
  10408. /// 10 = log-in greeting (connect)
  10409. /// hungry value:
  10410. /// 0 = very hungry (hungry)
  10411. /// 1 = hungry (bit_hungry)
  10412. /// 2 = satisfied (noting)
  10413. /// 3 = stuffed (full)
  10414. /// 4 = full (so_full)
  10415. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10416. {
  10417. if(sd->pd)
  10418. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10419. }
  10420. /// Request to change pet's name (CZ_RENAME_PET).
  10421. /// 01a5 <name>.24B
  10422. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10423. {
  10424. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10425. }
  10426. /// /kill (CZ_DISCONNECT_CHARACTER).
  10427. /// Request to disconnect a character.
  10428. /// 00cc <account id>.L
  10429. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10430. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10431. {
  10432. struct block_list *target;
  10433. int tid;
  10434. tid = RFIFOL(fd,2);
  10435. target = map_id2bl(tid);
  10436. if (!target) {
  10437. clif_GM_kickack(sd, 0);
  10438. return;
  10439. }
  10440. switch (target->type) {
  10441. case BL_PC:
  10442. {
  10443. char command[NAME_LENGTH+6];
  10444. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10445. is_atcommand(fd, sd, command, 1);
  10446. }
  10447. break;
  10448. /**
  10449. * This one does not invoke any atcommand, so we need to check for permissions.
  10450. */
  10451. case BL_MOB:
  10452. {
  10453. char command[100];
  10454. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10455. clif_GM_kickack(sd, 0);
  10456. return;
  10457. }
  10458. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10459. log_atcommand(sd, command);
  10460. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10461. }
  10462. break;
  10463. case BL_NPC:
  10464. {
  10465. char command[NAME_LENGTH+11];
  10466. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10467. is_atcommand(fd, sd, command, 1);
  10468. }
  10469. break;
  10470. default:
  10471. clif_GM_kickack(sd, 0);
  10472. }
  10473. }
  10474. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10475. /// Request to disconnect all characters.
  10476. /// 00ce
  10477. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10478. char cmd[15];
  10479. sprintf(cmd,"%ckickall",atcommand_symbol);
  10480. is_atcommand(fd, sd, cmd, 1);
  10481. }
  10482. /// /remove (CZ_REMOVE_AID).
  10483. /// Request to warp to a character with given login ID.
  10484. /// 01ba <account name>.24B
  10485. /// /shift (CZ_SHIFT).
  10486. /// Request to warp to a character with given name.
  10487. /// 01bb <char name>.24B
  10488. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10489. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10490. char *player_name;
  10491. char command[NAME_LENGTH+8];
  10492. player_name = (char*)RFIFOP(fd,2);
  10493. player_name[NAME_LENGTH-1] = '\0';
  10494. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10495. is_atcommand(fd, sd, command, 1);
  10496. }
  10497. /// /remove (CZ_REMOVE_AID_SSO).
  10498. /// Request to warp to a character with given account ID.
  10499. /// 0843 <account id>.L
  10500. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10501. {
  10502. int account_id;
  10503. struct map_session_data* pl_sd;
  10504. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10505. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10506. {
  10507. char command[NAME_LENGTH+8];
  10508. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10509. is_atcommand(fd, sd, command, 1);
  10510. }
  10511. }
  10512. /// /recall (CZ_RECALL).
  10513. /// Request to summon a player with given login ID to own position.
  10514. /// 01bc <account name>.24B
  10515. /// /summon (CZ_RECALL_GID).
  10516. /// Request to summon a player with given name to own position.
  10517. /// 01bd <char name>.24B
  10518. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10519. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10520. char *player_name;
  10521. char command [NAME_LENGTH+8];
  10522. player_name = (char*)RFIFOP(fd,2);
  10523. player_name[NAME_LENGTH-1] = '\0';
  10524. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10525. is_atcommand(fd, sd, command, 1);
  10526. }
  10527. /// /recall (CZ_RECALL_SSO).
  10528. /// Request to summon a player with given account ID to own position.
  10529. /// 0842 <account id>.L
  10530. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10531. {
  10532. int account_id;
  10533. struct map_session_data* pl_sd;
  10534. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10535. if( (pl_sd = map_id2sd(account_id)) != NULL )
  10536. {
  10537. char command[NAME_LENGTH+8];
  10538. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10539. is_atcommand(fd, sd, command, 1);
  10540. }
  10541. }
  10542. /// /item /monster (CZ_ITEM_CREATE).
  10543. /// Request to make items or spawn monsters.
  10544. /// 013f <item/mob name>.24B
  10545. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10546. {
  10547. char *monster_item_name;
  10548. char command[NAME_LENGTH+10];
  10549. monster_item_name = (char*)RFIFOP(fd,2);
  10550. monster_item_name[NAME_LENGTH-1] = '\0';
  10551. // FIXME: Should look for item first, then for monster.
  10552. // FIXME: /monster takes mob_db Sprite_Name as argument
  10553. if( mobdb_searchname(monster_item_name) ) {
  10554. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10555. is_atcommand(fd, sd, command, 1);
  10556. return;
  10557. }
  10558. // FIXME: Stackables have a quantity of 20.
  10559. // FIXME: Equips are supposed to be unidentified.
  10560. if( itemdb_searchname(monster_item_name) ) {
  10561. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10562. is_atcommand(fd, sd, command, 1);
  10563. return;
  10564. }
  10565. }
  10566. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10567. /// 019d <effect state>.L
  10568. /// effect state:
  10569. /// TODO: Any OPTION_* ?
  10570. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10571. char cmd[6];
  10572. sprintf(cmd,"%chide",atcommand_symbol);
  10573. is_atcommand(fd, sd, cmd, 1);
  10574. }
  10575. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10576. /// 0149 <account id>.L <type>.B <value>.W
  10577. /// type:
  10578. /// 0 = positive points
  10579. /// 1 = negative points
  10580. /// 2 = self mute (+10 minutes)
  10581. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10582. {
  10583. int id, type, value;
  10584. struct map_session_data *dstsd;
  10585. char command[NAME_LENGTH+15];
  10586. id = RFIFOL(fd,2);
  10587. type = RFIFOB(fd,6);
  10588. value = RFIFOW(fd,7);
  10589. if( type == 0 )
  10590. value = -value;
  10591. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10592. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10593. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10594. return;
  10595. dstsd = map_id2sd(id);
  10596. if( dstsd == NULL )
  10597. return;
  10598. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10599. is_atcommand(fd, sd, command, 1);
  10600. }
  10601. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10602. /// GM adjustment of a player's manner value by -60.
  10603. /// 0212 <char name>.24B
  10604. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10605. {
  10606. char command[NAME_LENGTH+15];
  10607. char *name = (char*)RFIFOP(fd,2);
  10608. name[NAME_LENGTH-1] = '\0';
  10609. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10610. is_atcommand(fd, sd, command, 1);
  10611. }
  10612. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10613. /// 01df <account id>.L
  10614. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10615. /// 01e0 <account id>.L <account name>.24B
  10616. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10617. {
  10618. int tid;
  10619. tid = RFIFOL(fd,2);
  10620. //TODO: find out if this works for any player or only for authorized GMs
  10621. WFIFOHEAD(fd,packet_len(0x1e0));
  10622. WFIFOW(fd,0) = 0x1e0;
  10623. WFIFOL(fd,2) = tid;
  10624. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10625. WFIFOSET(fd, packet_len(0x1e0));
  10626. }
  10627. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10628. /// GM single cell type change request.
  10629. /// 0198 <x>.W <y>.W <type>.W
  10630. /// type:
  10631. /// 0 = not walkable
  10632. /// 1 = walkable
  10633. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10634. {
  10635. int x,y,type;
  10636. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10637. return;
  10638. x = RFIFOW(fd,2);
  10639. y = RFIFOW(fd,4);
  10640. type = RFIFOW(fd,6);
  10641. map_setgatcell(sd->bl.m,x,y,type);
  10642. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10643. //FIXME: once players leave the map, the client 'forgets' this information.
  10644. }
  10645. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10646. /// Request to allow/deny whispers from a nick.
  10647. /// 00cf <nick>.24B <type>.B
  10648. /// type:
  10649. /// 0 = (/ex nick) deny speech from nick
  10650. /// 1 = (/in nick) allow speech from nick
  10651. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10652. {
  10653. char* nick;
  10654. uint8 type;
  10655. int i;
  10656. nick = (char*)RFIFOP(fd,2); // speed up
  10657. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10658. type = RFIFOB(fd,26);
  10659. // FIXME: Use clif_wisexin.
  10660. WFIFOHEAD(fd,packet_len(0xd1));
  10661. WFIFOW(fd,0) = 0x0d1;
  10662. WFIFOB(fd,2) = type;
  10663. if( type == 0 )
  10664. { // Add name to ignore list (block)
  10665. if (strcmp(wisp_server_name, nick) == 0) {
  10666. WFIFOB(fd,3) = 1; // fail
  10667. WFIFOSET(fd, packet_len(0x0d1));
  10668. return;
  10669. }
  10670. // try to find a free spot, while checking for duplicates at the same time
  10671. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10672. if( i == MAX_IGNORE_LIST )
  10673. {// no space for new entry
  10674. WFIFOB(fd,3) = 2; // fail
  10675. WFIFOSET(fd, packet_len(0x0d1));
  10676. return;
  10677. }
  10678. if( sd->ignore[i].name[0] != '\0' )
  10679. {// name already exists
  10680. WFIFOB(fd,3) = 0; // Aegis reports success.
  10681. WFIFOSET(fd, packet_len(0x0d1));
  10682. return;
  10683. }
  10684. //Insert in position i
  10685. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10686. WFIFOB(fd,3) = 0; // success
  10687. WFIFOSET(fd, packet_len(0x0d1));
  10688. }
  10689. else
  10690. { // Remove name from ignore list (unblock)
  10691. // find entry
  10692. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10693. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10694. { //Not found
  10695. WFIFOB(fd,3) = 1; // fail
  10696. WFIFOSET(fd, packet_len(0x0d1));
  10697. return;
  10698. }
  10699. // move everything one place down to overwrite removed entry
  10700. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10701. // wipe last entry
  10702. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10703. WFIFOB(fd,3) = 0; // success
  10704. WFIFOSET(fd, packet_len(0x0d1));
  10705. }
  10706. }
  10707. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10708. /// Request to allow/deny all whispers.
  10709. /// 00d0 <type>.B
  10710. /// type:
  10711. /// 0 = (/exall) deny all speech
  10712. /// 1 = (/inall) allow all speech
  10713. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10714. {
  10715. // FIXME: Use clif_wisall.
  10716. WFIFOHEAD(fd,packet_len(0xd2));
  10717. WFIFOW(fd,0) = 0x0d2;
  10718. WFIFOB(fd,2) = RFIFOB(fd,2);
  10719. if( RFIFOB(fd,2) == 0 )
  10720. {// Deny all
  10721. if( sd->state.ignoreAll ) {
  10722. WFIFOB(fd,3) = 1; // fail
  10723. } else {
  10724. sd->state.ignoreAll = 1;
  10725. WFIFOB(fd,3) = 0; // success
  10726. }
  10727. }
  10728. else
  10729. {//Unblock everyone
  10730. if( sd->state.ignoreAll ) {
  10731. sd->state.ignoreAll = 0;
  10732. WFIFOB(fd,3) = 0; // success
  10733. } else {
  10734. if (sd->ignore[0].name[0] != '\0')
  10735. { //Wipe the ignore list.
  10736. memset(sd->ignore, 0, sizeof(sd->ignore));
  10737. WFIFOB(fd,3) = 0; // success
  10738. } else {
  10739. WFIFOB(fd,3) = 1; // fail
  10740. }
  10741. }
  10742. }
  10743. WFIFOSET(fd, packet_len(0x0d2));
  10744. }
  10745. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10746. /// 00d3
  10747. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10748. {
  10749. int i;
  10750. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10751. WFIFOW(fd,0) = 0xd4;
  10752. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10753. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10754. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10755. WFIFOSET(fd, WFIFOW(fd,2));
  10756. }
  10757. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10758. /// 01e7
  10759. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10760. {
  10761. if (sd->state.doridori) return;
  10762. switch (sd->class_&MAPID_UPPERMASK)
  10763. {
  10764. case MAPID_SOUL_LINKER:
  10765. case MAPID_STAR_GLADIATOR:
  10766. case MAPID_TAEKWON:
  10767. if (!sd->state.rest)
  10768. break;
  10769. case MAPID_SUPER_NOVICE:
  10770. sd->state.doridori=1;
  10771. break;
  10772. }
  10773. }
  10774. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10775. /// 01ed
  10776. /// Note: This packet is caused by 7 lines of any text, followed by
  10777. /// the prayer and an another line of any text. The prayer is
  10778. /// defined by lines 790~793 in data\msgstringtable.txt
  10779. /// "Dear angel, can you hear my voice?"
  10780. /// "I am" (space separated player name) "Super Novice~"
  10781. /// "Help me out~ Please~ T_T"
  10782. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10783. {
  10784. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10785. {
  10786. unsigned int next = pc_nextbaseexp(sd);
  10787. if( next == 0 ) next = pc_thisbaseexp(sd);
  10788. if( next )
  10789. {
  10790. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10791. if( percent && ( percent%100 ) == 0 )
  10792. {// 10.0%, 20.0%, ..., 90.0%
  10793. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10794. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10795. }
  10796. }
  10797. }
  10798. }
  10799. /// Friends List
  10800. ///
  10801. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10802. /// 0206 <account id>.L <char id>.L <state>.B
  10803. /// state:
  10804. /// 0 = online
  10805. /// 1 = offline
  10806. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10807. {
  10808. int i, fd = sd->fd;
  10809. //Seek friend.
  10810. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10811. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10812. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10813. return; //Not found
  10814. WFIFOHEAD(fd,packet_len(0x206));
  10815. WFIFOW(fd, 0) = 0x206;
  10816. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10817. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10818. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10819. WFIFOSET(fd, packet_len(0x206));
  10820. }
  10821. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10822. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10823. {
  10824. int account_id, char_id, online;
  10825. account_id = va_arg(ap, int);
  10826. char_id = va_arg(ap, int);
  10827. online = va_arg(ap, int);
  10828. clif_friendslist_toggle(sd, account_id, char_id, online);
  10829. return 0;
  10830. }
  10831. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10832. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10833. void clif_friendslist_send(struct map_session_data *sd)
  10834. {
  10835. int i = 0, n, fd = sd->fd;
  10836. // Send friends list
  10837. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10838. WFIFOW(fd, 0) = 0x201;
  10839. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10840. {
  10841. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10842. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10843. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10844. }
  10845. if (i) {
  10846. WFIFOW(fd,2) = 4 + 32 * i;
  10847. WFIFOSET(fd, WFIFOW(fd,2));
  10848. }
  10849. for (n = 0; n < i; n++)
  10850. { //Sending the online players
  10851. if (map_charid2sd(sd->status.friends[n].char_id))
  10852. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10853. }
  10854. }
  10855. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10856. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10857. /// result:
  10858. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10859. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10860. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10861. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10862. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10863. {
  10864. int fd;
  10865. nullpo_retv(sd);
  10866. fd = sd->fd;
  10867. WFIFOHEAD(fd,packet_len(0x209));
  10868. WFIFOW(fd,0) = 0x209;
  10869. WFIFOW(fd,2) = type;
  10870. if (f_sd)
  10871. {
  10872. WFIFOL(fd,4) = f_sd->status.account_id;
  10873. WFIFOL(fd,8) = f_sd->status.char_id;
  10874. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10875. }
  10876. WFIFOSET(fd, packet_len(0x209));
  10877. }
  10878. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10879. /// 0202 <name>.24B
  10880. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10881. {
  10882. struct map_session_data *f_sd;
  10883. int i, f_fd;
  10884. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10885. // ensure that the request player's friend list is not full
  10886. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10887. if( i == MAX_FRIENDS ) {
  10888. clif_friendslist_reqack(sd, f_sd, 2);
  10889. return;
  10890. }
  10891. // Friend doesn't exist (no player with this name)
  10892. if (f_sd == NULL) {
  10893. clif_displaymessage(fd, msg_txt(3));
  10894. return;
  10895. }
  10896. if( sd->bl.id == f_sd->bl.id )
  10897. {// adding oneself as friend
  10898. return;
  10899. }
  10900. // @noask [LuzZza]
  10901. if(f_sd->state.noask) {
  10902. clif_noask_sub(sd, f_sd, 5);
  10903. return;
  10904. }
  10905. // Friend already exists
  10906. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10907. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10908. clif_displaymessage(fd, "Friend already exists.");
  10909. return;
  10910. }
  10911. }
  10912. f_sd->friend_req = sd->status.char_id;
  10913. sd->friend_req = f_sd->status.char_id;
  10914. f_fd = f_sd->fd;
  10915. WFIFOHEAD(f_fd,packet_len(0x207));
  10916. WFIFOW(f_fd,0) = 0x207;
  10917. WFIFOL(f_fd,2) = sd->status.account_id;
  10918. WFIFOL(f_fd,6) = sd->status.char_id;
  10919. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10920. WFIFOSET(f_fd, packet_len(0x207));
  10921. }
  10922. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10923. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10924. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10925. /// result:
  10926. /// 0 = rejected
  10927. /// 1 = accepted
  10928. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10929. {
  10930. struct map_session_data *f_sd;
  10931. int char_id, account_id;
  10932. char reply;
  10933. account_id = RFIFOL(fd,2);
  10934. char_id = RFIFOL(fd,6);
  10935. #if PACKETVER < 6
  10936. reply = RFIFOB(fd,10);
  10937. #else
  10938. reply = RFIFOL(fd,10);
  10939. #endif
  10940. if( sd->bl.id == account_id )
  10941. {// adding oneself as friend
  10942. return;
  10943. }
  10944. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10945. if (f_sd == NULL)
  10946. return;
  10947. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10948. clif_friendslist_reqack(f_sd, sd, 1);
  10949. else {
  10950. int i;
  10951. // Find an empty slot
  10952. for (i = 0; i < MAX_FRIENDS; i++)
  10953. if (f_sd->status.friends[i].char_id == 0)
  10954. break;
  10955. if (i == MAX_FRIENDS) {
  10956. clif_friendslist_reqack(f_sd, sd, 2);
  10957. return;
  10958. }
  10959. f_sd->status.friends[i].account_id = sd->status.account_id;
  10960. f_sd->status.friends[i].char_id = sd->status.char_id;
  10961. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10962. clif_friendslist_reqack(f_sd, sd, 0);
  10963. if (battle_config.friend_auto_add) {
  10964. // Also add f_sd to sd's friendlist.
  10965. for (i = 0; i < MAX_FRIENDS; i++) {
  10966. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10967. return; //No need to add anything.
  10968. if (sd->status.friends[i].char_id == 0)
  10969. break;
  10970. }
  10971. if (i == MAX_FRIENDS) {
  10972. clif_friendslist_reqack(sd, f_sd, 2);
  10973. return;
  10974. }
  10975. sd->status.friends[i].account_id = f_sd->status.account_id;
  10976. sd->status.friends[i].char_id = f_sd->status.char_id;
  10977. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10978. clif_friendslist_reqack(sd, f_sd, 0);
  10979. }
  10980. }
  10981. }
  10982. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  10983. /// 0203 <account id>.L <char id>.L
  10984. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10985. {
  10986. struct map_session_data *f_sd = NULL;
  10987. int account_id, char_id;
  10988. int i, j;
  10989. account_id = RFIFOL(fd,2);
  10990. char_id = RFIFOL(fd,6);
  10991. // Search friend
  10992. for (i = 0; i < MAX_FRIENDS &&
  10993. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10994. if (i == MAX_FRIENDS) {
  10995. clif_displaymessage(fd, "Name not found in list.");
  10996. return;
  10997. }
  10998. //remove from friend's list first
  10999. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11000. for (i = 0; i < MAX_FRIENDS &&
  11001. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11002. if (i != MAX_FRIENDS) {
  11003. // move all chars up
  11004. for(j = i + 1; j < MAX_FRIENDS; j++)
  11005. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11006. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11007. //should the guy be notified of some message? we should add it here if so
  11008. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11009. WFIFOW(f_sd->fd,0) = 0x20a;
  11010. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11011. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11012. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11013. }
  11014. } else { //friend not online -- ask char server to delete from his friendlist
  11015. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11016. clif_displaymessage(fd, "This action can't be performed at the moment. Please try again later.");
  11017. return;
  11018. }
  11019. }
  11020. // We can now delete from original requester
  11021. for (i = 0; i < MAX_FRIENDS &&
  11022. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11023. // move all chars up
  11024. for(j = i + 1; j < MAX_FRIENDS; j++)
  11025. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11026. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11027. clif_displaymessage(fd, "Friend removed");
  11028. WFIFOHEAD(fd,packet_len(0x20a));
  11029. WFIFOW(fd,0) = 0x20a;
  11030. WFIFOL(fd,2) = account_id;
  11031. WFIFOL(fd,6) = char_id;
  11032. WFIFOSET(fd, packet_len(0x20a));
  11033. }
  11034. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11035. /// 020f <char id>.L <account id>.L
  11036. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11037. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11038. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11039. {
  11040. WFIFOHEAD(fd,packet_len(0x210));
  11041. WFIFOW(fd,0) = 0x210;
  11042. WFIFOL(fd,2) = sd->status.char_id;
  11043. WFIFOL(fd,6) = sd->status.account_id;
  11044. WFIFOL(fd,10) = sd->pvp_won; // times won
  11045. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11046. WFIFOL(fd,18) = sd->pvp_point;
  11047. WFIFOSET(fd, packet_len(0x210));
  11048. }
  11049. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11050. /// 0217
  11051. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11052. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11053. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11054. {
  11055. int i;
  11056. const char* name;
  11057. WFIFOHEAD(fd,packet_len(0x219));
  11058. WFIFOW(fd,0) = 0x219;
  11059. //Packet size limits this list to 10 elements. [Skotlex]
  11060. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11061. if (smith_fame_list[i].id > 0) {
  11062. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11063. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11064. {
  11065. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11066. } else
  11067. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11068. } else
  11069. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11070. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11071. }
  11072. for(;i < 10; i++) { //In case the MAX is less than 10.
  11073. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11074. WFIFOL(fd, 242 + i * 4) = 0;
  11075. }
  11076. WFIFOSET(fd, packet_len(0x219));
  11077. }
  11078. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11079. /// 021b <points>.L <total points>.L
  11080. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11081. {
  11082. int fd = sd->fd;
  11083. WFIFOHEAD(fd,packet_len(0x21b));
  11084. WFIFOW(fd,0) = 0x21b;
  11085. WFIFOL(fd,2) = points;
  11086. WFIFOL(fd,6) = sd->status.fame;
  11087. WFIFOSET(fd, packet_len(0x21b));
  11088. }
  11089. /// /alchemist (CZ_ALCHEMIST_RANK).
  11090. /// 0218
  11091. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11092. /// 021a { <name>.24B }*10 { <point>.L }*10
  11093. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11094. {
  11095. int i;
  11096. const char* name;
  11097. WFIFOHEAD(fd,packet_len(0x21a));
  11098. WFIFOW(fd,0) = 0x21a;
  11099. //Packet size limits this list to 10 elements. [Skotlex]
  11100. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11101. if (chemist_fame_list[i].id > 0) {
  11102. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11103. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11104. {
  11105. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11106. } else
  11107. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11108. } else
  11109. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11110. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11111. }
  11112. for(;i < 10; i++) { //In case the MAX is less than 10.
  11113. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11114. WFIFOL(fd, 242 + i * 4) = 0;
  11115. }
  11116. WFIFOSET(fd, packet_len(0x21a));
  11117. }
  11118. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11119. /// 021c <points>.L <total points>.L
  11120. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11121. {
  11122. int fd = sd->fd;
  11123. WFIFOHEAD(fd,packet_len(0x21c));
  11124. WFIFOW(fd,0) = 0x21c;
  11125. WFIFOL(fd,2) = points;
  11126. WFIFOL(fd,6) = sd->status.fame;
  11127. WFIFOSET(fd, packet_len(0x21c));
  11128. }
  11129. /// /taekwon (CZ_TAEKWON_RANK).
  11130. /// 0225
  11131. /// /taekwon list (ZC_TAEKWON_RANK).
  11132. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11133. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11134. {
  11135. int i;
  11136. const char* name;
  11137. WFIFOHEAD(fd,packet_len(0x226));
  11138. WFIFOW(fd,0) = 0x226;
  11139. //Packet size limits this list to 10 elements. [Skotlex]
  11140. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11141. if (taekwon_fame_list[i].id > 0) {
  11142. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11143. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11144. {
  11145. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11146. } else
  11147. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11148. } else
  11149. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11150. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11151. }
  11152. for(;i < 10; i++) { //In case the MAX is less than 10.
  11153. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11154. WFIFOL(fd, 242 + i * 4) = 0;
  11155. }
  11156. WFIFOSET(fd, packet_len(0x226));
  11157. }
  11158. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11159. /// 0224 <points>.L <total points>.L
  11160. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11161. {
  11162. int fd = sd->fd;
  11163. WFIFOHEAD(fd,packet_len(0x224));
  11164. WFIFOW(fd,0) = 0x224;
  11165. WFIFOL(fd,2) = points;
  11166. WFIFOL(fd,6) = sd->status.fame;
  11167. WFIFOSET(fd, packet_len(0x224));
  11168. }
  11169. /// /pk (CZ_KILLER_RANK).
  11170. /// 0237
  11171. /// /pk list (ZC_KILLER_RANK).
  11172. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11173. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11174. {
  11175. int i;
  11176. WFIFOHEAD(fd,packet_len(0x238));
  11177. WFIFOW(fd,0) = 0x238;
  11178. for(i=0;i<10;i++){
  11179. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11180. WFIFOL(fd,i*4+242) = 0;
  11181. }
  11182. WFIFOSET(fd, packet_len(0x238));
  11183. }
  11184. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11185. /// 0254 <which>.B
  11186. /// which:
  11187. /// 0 = sun
  11188. /// 1 = moon
  11189. /// 2 = star
  11190. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11191. {
  11192. int i;
  11193. if (sd->menuskill_id != SG_FEEL)
  11194. return;
  11195. i = sd->menuskill_val-1;
  11196. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11197. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11198. sd->feel_map[i].m = sd->bl.m;
  11199. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11200. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11201. // clif_misceffect2(&sd->bl, 0x1b0);
  11202. // clif_misceffect2(&sd->bl, 0x21f);
  11203. clif_feel_info(sd, i, 0);
  11204. clif_menuskill_clear(sd);
  11205. }
  11206. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11207. /// 0253 <which>.B
  11208. /// which:
  11209. /// 0 = sun
  11210. /// 1 = moon
  11211. /// 2 = star
  11212. void clif_feel_req(int fd, struct map_session_data *sd, int skilllv)
  11213. {
  11214. WFIFOHEAD(fd,packet_len(0x253));
  11215. WFIFOW(fd,0)=0x253;
  11216. WFIFOB(fd,2)=TOB(skilllv-1);
  11217. WFIFOSET(fd, packet_len(0x253));
  11218. sd->menuskill_id = SG_FEEL;
  11219. sd->menuskill_val = skilllv;
  11220. }
  11221. /// Request to change homunculus' name (CZ_RENAME_MER).
  11222. /// 0231 <name>.24B
  11223. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11224. {
  11225. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11226. }
  11227. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11228. /// 0234 <id>.L
  11229. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11230. {
  11231. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11232. struct block_list *bl = NULL;
  11233. struct unit_data *ud = NULL;
  11234. if( sd->md && sd->md->bl.id == id )
  11235. bl = &sd->md->bl;
  11236. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11237. bl = &sd->hd->bl; // Moving Homunculus
  11238. else
  11239. return;
  11240. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11241. ud = unit_bl2ud(bl);
  11242. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11243. }
  11244. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11245. /// 0232 <id>.L <position data>.3B
  11246. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11247. {
  11248. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11249. struct block_list *bl = NULL;
  11250. short x, y;
  11251. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11252. if( sd->md && sd->md->bl.id == id )
  11253. bl = &sd->md->bl; // Moving Mercenary
  11254. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11255. bl = &sd->hd->bl; // Moving Homunculus
  11256. else
  11257. return;
  11258. unit_walktoxy(bl, x, y, 4);
  11259. }
  11260. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11261. /// 0233 <id>.L <target id>.L <action>.B
  11262. /// action:
  11263. /// always 0
  11264. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11265. {
  11266. struct block_list *bl = NULL;
  11267. int id = RFIFOL(fd,2),
  11268. target_id = RFIFOL(fd,6),
  11269. action_type = RFIFOB(fd,10);
  11270. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11271. bl = &sd->hd->bl;
  11272. else if( sd->md && sd->md->bl.id == id )
  11273. bl = &sd->md->bl;
  11274. else return;
  11275. unit_stop_attack(bl);
  11276. unit_attack(bl, target_id, action_type != 0);
  11277. }
  11278. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11279. /// 022d <type>.W <command>.B
  11280. /// type:
  11281. /// always 0
  11282. /// command:
  11283. /// 0 = homunculus information
  11284. /// 1 = feed
  11285. /// 2 = delete
  11286. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11287. { //[orn]
  11288. int cmd;
  11289. cmd = RFIFOW(fd,0);
  11290. if(!merc_is_hom_active(sd->hd))
  11291. return;
  11292. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11293. }
  11294. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11295. /// 0292
  11296. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11297. {
  11298. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11299. if (item_position < 0)
  11300. return;
  11301. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11302. return;
  11303. if (!status_revive(&sd->bl, 100, 100))
  11304. return;
  11305. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11306. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11307. }
  11308. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11309. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11310. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11311. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11312. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11313. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11314. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11315. void clif_check(int fd, struct map_session_data* pl_sd)
  11316. {
  11317. WFIFOHEAD(fd,packet_len(0x214));
  11318. WFIFOW(fd, 0) = 0x214;
  11319. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11320. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11321. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11322. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11323. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11324. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11325. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11326. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11327. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11328. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11329. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11330. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11331. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11332. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11333. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11334. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11335. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11336. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11337. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11338. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11339. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11340. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11341. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11342. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11343. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11344. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11345. WFIFOSET(fd,packet_len(0x214));
  11346. }
  11347. /// /check (CZ_REQ_STATUS_GM).
  11348. /// Request character's status values.
  11349. /// 0213 <char name>.24B
  11350. void clif_parse_Check(int fd, struct map_session_data *sd)
  11351. {
  11352. char charname[NAME_LENGTH];
  11353. struct map_session_data* pl_sd;
  11354. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11355. return;
  11356. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11357. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11358. {
  11359. return;
  11360. }
  11361. clif_check(fd, pl_sd);
  11362. }
  11363. /// MAIL SYSTEM
  11364. /// By Zephyrus
  11365. ///
  11366. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11367. /// 0255 <index>.W <result>.B
  11368. /// result:
  11369. /// 0 = success
  11370. /// 1 = failure
  11371. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11372. {
  11373. WFIFOHEAD(fd,packet_len(0x255));
  11374. WFIFOW(fd,0) = 0x255;
  11375. WFIFOW(fd,2) = index;
  11376. WFIFOB(fd,4) = flag;
  11377. WFIFOSET(fd,packet_len(0x255));
  11378. }
  11379. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11380. /// 0245 <result>.B
  11381. /// result:
  11382. /// 0 = success
  11383. /// 1 = failure
  11384. /// 2 = too many items
  11385. void clif_Mail_getattachment(int fd, uint8 flag)
  11386. {
  11387. WFIFOHEAD(fd,packet_len(0x245));
  11388. WFIFOW(fd,0) = 0x245;
  11389. WFIFOB(fd,2) = flag;
  11390. WFIFOSET(fd,packet_len(0x245));
  11391. }
  11392. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11393. /// 0249 <result>.B
  11394. /// result:
  11395. /// 0 = success
  11396. /// 1 = recipinent does not exist
  11397. void clif_Mail_send(int fd, bool fail)
  11398. {
  11399. WFIFOHEAD(fd,packet_len(0x249));
  11400. WFIFOW(fd,0) = 0x249;
  11401. WFIFOB(fd,2) = fail;
  11402. WFIFOSET(fd,packet_len(0x249));
  11403. }
  11404. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11405. /// 0257 <mail id>.L <result>.W
  11406. /// result:
  11407. /// 0 = success
  11408. /// 1 = failure
  11409. void clif_Mail_delete(int fd, int mail_id, short fail)
  11410. {
  11411. WFIFOHEAD(fd, packet_len(0x257));
  11412. WFIFOW(fd,0) = 0x257;
  11413. WFIFOL(fd,2) = mail_id;
  11414. WFIFOW(fd,6) = fail;
  11415. WFIFOSET(fd, packet_len(0x257));
  11416. }
  11417. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11418. /// 0274 <mail id>.L <result>.W
  11419. /// result:
  11420. /// 0 = success
  11421. /// 1 = failure
  11422. void clif_Mail_return(int fd, int mail_id, short fail)
  11423. {
  11424. WFIFOHEAD(fd,packet_len(0x274));
  11425. WFIFOW(fd,0) = 0x274;
  11426. WFIFOL(fd,2) = mail_id;
  11427. WFIFOW(fd,6) = fail;
  11428. WFIFOSET(fd,packet_len(0x274));
  11429. }
  11430. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11431. /// 024a <mail id>.L <title>.40B <sender>.24B
  11432. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11433. {
  11434. WFIFOHEAD(fd,packet_len(0x24a));
  11435. WFIFOW(fd,0) = 0x24a;
  11436. WFIFOL(fd,2) = mail_id;
  11437. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11438. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11439. WFIFOSET(fd,packet_len(0x24a));
  11440. }
  11441. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11442. /// 0260 <type>.L
  11443. /// type:
  11444. /// 0 = open
  11445. /// 1 = close
  11446. void clif_Mail_window(int fd, int flag)
  11447. {
  11448. WFIFOHEAD(fd,packet_len(0x260));
  11449. WFIFOW(fd,0) = 0x260;
  11450. WFIFOL(fd,2) = flag;
  11451. WFIFOSET(fd,packet_len(0x260));
  11452. }
  11453. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11454. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11455. /// read:
  11456. /// 0 = unread
  11457. /// 1 = read
  11458. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11459. {
  11460. int fd = sd->fd;
  11461. struct mail_data *md = &sd->mail.inbox;
  11462. struct mail_message *msg;
  11463. int len, i, j;
  11464. len = 8 + (73 * md->amount);
  11465. WFIFOHEAD(fd,len);
  11466. WFIFOW(fd,0) = 0x240;
  11467. WFIFOW(fd,2) = len;
  11468. WFIFOL(fd,4) = md->amount;
  11469. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11470. {
  11471. msg = &md->msg[i];
  11472. if (msg->id < 1)
  11473. continue;
  11474. WFIFOL(fd,8+73*j) = msg->id;
  11475. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11476. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11477. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11478. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11479. j++;
  11480. }
  11481. WFIFOSET(fd,len);
  11482. if( md->full )
  11483. {// TODO: is this official?
  11484. char output[100];
  11485. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11486. clif_disp_onlyself(sd, output, strlen(output));
  11487. }
  11488. }
  11489. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11490. /// 023f
  11491. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11492. {
  11493. struct mail_data* md = &sd->mail.inbox;
  11494. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11495. intif_Mail_requestinbox(sd->status.char_id, 1);
  11496. else
  11497. clif_Mail_refreshinbox(sd);
  11498. mail_removeitem(sd, 0);
  11499. mail_removezeny(sd, 0);
  11500. }
  11501. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11502. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11503. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11504. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11505. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11506. {
  11507. int i, fd = sd->fd;
  11508. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11509. if( i == MAIL_MAX_INBOX )
  11510. {
  11511. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11512. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11513. return;
  11514. }
  11515. else
  11516. {
  11517. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11518. struct item *item = &msg->item;
  11519. struct item_data *data;
  11520. int msg_len = strlen(msg->body), len;
  11521. if( msg_len == 0 ) {
  11522. strcpy(msg->body, "(no message)");
  11523. msg_len = strlen(msg->body);
  11524. }
  11525. len = 101 + msg_len;
  11526. WFIFOHEAD(fd,len);
  11527. WFIFOW(fd,0) = 0x242;
  11528. WFIFOW(fd,2) = len;
  11529. WFIFOL(fd,4) = msg->id;
  11530. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11531. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11532. WFIFOL(fd,72) = 0;
  11533. WFIFOL(fd,76) = msg->zeny;
  11534. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  11535. {
  11536. WFIFOL(fd,80) = item->amount;
  11537. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11538. WFIFOW(fd,86) = data->type;
  11539. WFIFOB(fd,88) = item->identify;
  11540. WFIFOB(fd,89) = item->attribute;
  11541. WFIFOB(fd,90) = item->refine;
  11542. WFIFOW(fd,91) = item->card[0];
  11543. WFIFOW(fd,93) = item->card[1];
  11544. WFIFOW(fd,95) = item->card[2];
  11545. WFIFOW(fd,97) = item->card[3];
  11546. }
  11547. else // no item, set all to zero
  11548. memset(WFIFOP(fd,80), 0x00, 19);
  11549. WFIFOB(fd,99) = (unsigned char)msg_len;
  11550. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11551. WFIFOSET(fd,len);
  11552. if (msg->status == MAIL_UNREAD) {
  11553. msg->status = MAIL_READ;
  11554. intif_Mail_read(mail_id);
  11555. clif_parse_Mail_refreshinbox(fd, sd);
  11556. }
  11557. }
  11558. }
  11559. /// Request to open a mail (CZ_MAIL_OPEN).
  11560. /// 0241 <mail id>.L
  11561. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11562. {
  11563. int mail_id = RFIFOL(fd,2);
  11564. if( mail_id <= 0 )
  11565. return;
  11566. if( mail_invalid_operation(sd) )
  11567. return;
  11568. clif_Mail_read(sd, RFIFOL(fd,2));
  11569. }
  11570. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11571. /// 0244 <mail id>.L
  11572. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11573. {
  11574. int mail_id = RFIFOL(fd,2);
  11575. int i;
  11576. bool fail = false;
  11577. if( mail_id <= 0 )
  11578. return;
  11579. if( mail_invalid_operation(sd) )
  11580. return;
  11581. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11582. if( i == MAIL_MAX_INBOX )
  11583. return;
  11584. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11585. return;
  11586. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY )
  11587. {
  11588. clif_Mail_getattachment(fd, 1);
  11589. return;
  11590. }
  11591. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11592. {
  11593. struct item_data *data;
  11594. unsigned int weight;
  11595. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11596. return;
  11597. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11598. {
  11599. case ADDITEM_NEW:
  11600. fail = ( pc_inventoryblank(sd) == 0 );
  11601. break;
  11602. case ADDITEM_OVERAMOUNT:
  11603. fail = true;
  11604. }
  11605. if( fail )
  11606. {
  11607. clif_Mail_getattachment(fd, 1);
  11608. return;
  11609. }
  11610. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11611. if( sd->weight + weight > sd->max_weight )
  11612. {
  11613. clif_Mail_getattachment(fd, 2);
  11614. return;
  11615. }
  11616. }
  11617. sd->mail.inbox.msg[i].zeny = 0;
  11618. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11619. clif_Mail_read(sd, mail_id);
  11620. intif_Mail_getattach(sd->status.char_id, mail_id);
  11621. }
  11622. /// Request to delete a mail (CZ_MAIL_DELETE).
  11623. /// 0243 <mail id>.L
  11624. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11625. {
  11626. int mail_id = RFIFOL(fd,2);
  11627. int i;
  11628. if( mail_id <= 0 )
  11629. return;
  11630. if( mail_invalid_operation(sd) )
  11631. return;
  11632. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11633. if (i < MAIL_MAX_INBOX)
  11634. {
  11635. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11636. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11637. {// can't delete mail without removing attachment first
  11638. clif_Mail_delete(sd->fd, mail_id, 1);
  11639. return;
  11640. }
  11641. intif_Mail_delete(sd->status.char_id, mail_id);
  11642. }
  11643. }
  11644. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11645. /// 0273 <mail id>.L <receive name>.24B
  11646. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11647. {
  11648. int mail_id = RFIFOL(fd,2);
  11649. int i;
  11650. if( mail_id <= 0 )
  11651. return;
  11652. if( mail_invalid_operation(sd) )
  11653. return;
  11654. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11655. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11656. intif_Mail_return(sd->status.char_id, mail_id);
  11657. else
  11658. clif_Mail_return(sd->fd, mail_id, 1);
  11659. }
  11660. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11661. /// 0247 <index>.W <amount>.L
  11662. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11663. {
  11664. int idx = RFIFOW(fd,2);
  11665. int amount = RFIFOL(fd,4);
  11666. unsigned char flag;
  11667. if (idx < 0 || amount < 0)
  11668. return;
  11669. flag = mail_setitem(sd, idx, amount);
  11670. clif_Mail_setattachment(fd,idx,flag);
  11671. }
  11672. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11673. /// 0246 <type>.W
  11674. /// type:
  11675. /// 0 = reset all
  11676. /// 1 = remove item
  11677. /// 2 = remove zeny
  11678. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11679. {
  11680. int flag = RFIFOW(fd,2);
  11681. if (flag == 0 || flag == 1)
  11682. mail_removeitem(sd, 0);
  11683. if (flag == 0 || flag == 2)
  11684. mail_removezeny(sd, 0);
  11685. }
  11686. /// Request to send mail (CZ_MAIL_SEND).
  11687. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11688. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11689. {
  11690. struct mail_message msg;
  11691. int body_len;
  11692. if( sd->state.trading )
  11693. return;
  11694. if( RFIFOW(fd,2) < 69 ) {
  11695. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11696. return;
  11697. }
  11698. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11699. {
  11700. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11701. clif_Mail_send(fd, true); // fail
  11702. return;
  11703. }
  11704. body_len = RFIFOB(fd,68);
  11705. if (body_len > MAIL_BODY_LENGTH)
  11706. body_len = MAIL_BODY_LENGTH;
  11707. if( !mail_setattachment(sd, &msg) )
  11708. { // Invalid Append condition
  11709. clif_Mail_send(sd->fd, true); // fail
  11710. mail_removeitem(sd,0);
  11711. mail_removezeny(sd,0);
  11712. return;
  11713. }
  11714. msg.id = 0; // id will be assigned by charserver
  11715. msg.send_id = sd->status.char_id;
  11716. msg.dest_id = 0; // will attempt to resolve name
  11717. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11718. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11719. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11720. if (body_len)
  11721. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11722. else
  11723. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11724. msg.timestamp = time(NULL);
  11725. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11726. mail_deliveryfail(sd, &msg);
  11727. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11728. }
  11729. /// AUCTION SYSTEM
  11730. /// By Zephyrus
  11731. ///
  11732. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11733. /// 025f <type>.L
  11734. /// type:
  11735. /// 0 = open
  11736. /// 1 = close
  11737. void clif_Auction_openwindow(struct map_session_data *sd)
  11738. {
  11739. int fd = sd->fd;
  11740. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11741. return;
  11742. WFIFOHEAD(fd,packet_len(0x25f));
  11743. WFIFOW(fd,0) = 0x25f;
  11744. WFIFOL(fd,2) = 0;
  11745. WFIFOSET(fd,packet_len(0x25f));
  11746. }
  11747. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11748. /// 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 }*
  11749. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11750. {
  11751. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11752. struct auction_data auction;
  11753. struct item_data *item;
  11754. int k;
  11755. WFIFOHEAD(fd,12 + (count * 83));
  11756. WFIFOW(fd,0) = 0x252;
  11757. WFIFOW(fd,2) = 12 + (count * 83);
  11758. WFIFOL(fd,4) = pages;
  11759. WFIFOL(fd,8) = count;
  11760. for( i = 0; i < count; i++ )
  11761. {
  11762. memcpy(&auction, RBUFP(buf,i * len), len);
  11763. k = 12 + (i * 83);
  11764. WFIFOL(fd,k) = auction.auction_id;
  11765. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11766. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11767. WFIFOW(fd,28+k) = item->view_id;
  11768. else
  11769. WFIFOW(fd,28+k) = auction.item.nameid;
  11770. WFIFOL(fd,30+k) = auction.type;
  11771. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11772. WFIFOB(fd,36+k) = auction.item.identify;
  11773. WFIFOB(fd,37+k) = auction.item.attribute;
  11774. WFIFOB(fd,38+k) = auction.item.refine;
  11775. WFIFOW(fd,39+k) = auction.item.card[0];
  11776. WFIFOW(fd,41+k) = auction.item.card[1];
  11777. WFIFOW(fd,43+k) = auction.item.card[2];
  11778. WFIFOW(fd,45+k) = auction.item.card[3];
  11779. WFIFOL(fd,47+k) = auction.price;
  11780. WFIFOL(fd,51+k) = auction.buynow;
  11781. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11782. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11783. }
  11784. WFIFOSET(fd,WFIFOW(fd,2));
  11785. }
  11786. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11787. /// 0256 <index>.W <result>.B
  11788. /// result:
  11789. /// 0 = success
  11790. /// 1 = failure
  11791. static void clif_Auction_setitem(int fd, int index, bool fail)
  11792. {
  11793. WFIFOHEAD(fd,packet_len(0x256));
  11794. WFIFOW(fd,0) = 0x256;
  11795. WFIFOW(fd,2) = index;
  11796. WFIFOB(fd,4) = fail;
  11797. WFIFOSET(fd,packet_len(0x256));
  11798. }
  11799. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11800. /// 024b <type>.W
  11801. /// type:
  11802. /// 0 = create (any other action in auction window)
  11803. /// 1 = cancel (cancel pressed on register tab)
  11804. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11805. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11806. {
  11807. if( sd->auction.amount > 0 )
  11808. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11809. sd->auction.amount = 0;
  11810. }
  11811. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11812. /// 024c <index>.W <count>.L
  11813. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11814. {
  11815. int idx = RFIFOW(fd,2) - 2;
  11816. int amount = RFIFOL(fd,4); // Always 1
  11817. struct item_data *item;
  11818. if( sd->auction.amount > 0 )
  11819. sd->auction.amount = 0;
  11820. if( idx < 0 || idx >= MAX_INVENTORY )
  11821. {
  11822. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11823. return;
  11824. }
  11825. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11826. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11827. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11828. return;
  11829. }
  11830. 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) )
  11831. { // Consumable or pets are not allowed
  11832. clif_Auction_setitem(sd->fd, idx, true);
  11833. return;
  11834. }
  11835. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11836. !sd->status.inventory[idx].identify ||
  11837. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11838. clif_Auction_setitem(sd->fd, idx, true);
  11839. return;
  11840. }
  11841. sd->auction.index = idx;
  11842. sd->auction.amount = amount;
  11843. clif_Auction_setitem(fd, idx + 2, false);
  11844. }
  11845. /// Result from an auction action (ZC_AUCTION_RESULT).
  11846. /// 0250 <result>.B
  11847. /// result:
  11848. /// 0 = You have failed to bid into the auction
  11849. /// 1 = You have successfully bid in the auction
  11850. /// 2 = The auction has been canceled
  11851. /// 3 = An auction with at least one bidder cannot be canceled
  11852. /// 4 = You cannot register more than 5 items in an auction at a time
  11853. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11854. /// 6 = You have won the auction
  11855. /// 7 = You have failed to win the auction
  11856. /// 8 = You do not have enough Zeny
  11857. /// 9 = You cannot place more than 5 bids at a time
  11858. void clif_Auction_message(int fd, unsigned char flag)
  11859. {
  11860. WFIFOHEAD(fd,packet_len(0x250));
  11861. WFIFOW(fd,0) = 0x250;
  11862. WFIFOB(fd,2) = flag;
  11863. WFIFOSET(fd,packet_len(0x250));
  11864. }
  11865. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11866. /// 025e <result>.W
  11867. /// result:
  11868. /// 0 = You have ended the auction
  11869. /// 1 = You cannot end the auction
  11870. /// 2 = Auction ID is incorrect
  11871. void clif_Auction_close(int fd, unsigned char flag)
  11872. {
  11873. WFIFOHEAD(fd,packet_len(0x25e));
  11874. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11875. WFIFOW(fd,2) = flag;
  11876. WFIFOSET(fd,packet_len(0x25e));
  11877. }
  11878. /// Request to add an auction (CZ_AUCTION_ADD).
  11879. /// 024d <now money>.L <max money>.L <delete hour>.W
  11880. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11881. {
  11882. struct auction_data auction;
  11883. struct item_data *item;
  11884. auction.price = RFIFOL(fd,2);
  11885. auction.buynow = RFIFOL(fd,6);
  11886. auction.hours = RFIFOW(fd,10);
  11887. // Invalid Situations...
  11888. if( sd->auction.amount < 1 )
  11889. {
  11890. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11891. return;
  11892. }
  11893. if( auction.price >= auction.buynow )
  11894. {
  11895. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11896. return;
  11897. }
  11898. if( auction.hours < 1 || auction.hours > 48 )
  11899. {
  11900. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11901. return;
  11902. }
  11903. // Auction checks...
  11904. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11905. {
  11906. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11907. return;
  11908. }
  11909. if( auction.buynow > battle_config.auction_maximumprice )
  11910. { // Zeny Limits
  11911. auction.buynow = battle_config.auction_maximumprice;
  11912. if( auction.price >= auction.buynow )
  11913. auction.price = auction.buynow - 1;
  11914. }
  11915. auction.auction_id = 0;
  11916. auction.seller_id = sd->status.char_id;
  11917. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11918. auction.buyer_id = 0;
  11919. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11920. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11921. {
  11922. clif_Auction_message(fd, 2); // The auction has been canceled
  11923. return;
  11924. }
  11925. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11926. { // Just in case
  11927. clif_Auction_message(fd, 2); // The auction has been canceled
  11928. return;
  11929. }
  11930. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11931. auction.type = item->type;
  11932. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11933. auction.item.amount = 1;
  11934. auction.timestamp = 0;
  11935. if( !intif_Auction_register(&auction) )
  11936. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11937. else
  11938. {
  11939. int zeny = auction.hours*battle_config.auction_feeperhour;
  11940. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11941. sd->auction.amount = 0;
  11942. log_zeny(sd, LOG_TYPE_AUCTION, sd, -zeny);
  11943. pc_payzeny(sd, zeny);
  11944. }
  11945. }
  11946. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11947. /// 024e <auction id>.L
  11948. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11949. {
  11950. unsigned int auction_id = RFIFOL(fd,2);
  11951. intif_Auction_cancel(sd->status.char_id, auction_id);
  11952. }
  11953. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11954. /// 025d <auction id>.L
  11955. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11956. {
  11957. unsigned int auction_id = RFIFOL(fd,2);
  11958. intif_Auction_close(sd->status.char_id, auction_id);
  11959. }
  11960. /// Places a bid on an auction (CZ_AUCTION_BUY).
  11961. /// 024f <auction id>.L <money>.L
  11962. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11963. {
  11964. unsigned int auction_id = RFIFOL(fd,2);
  11965. int bid = RFIFOL(fd,6);
  11966. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  11967. clif_displaymessage(sd->fd, msg_txt(246));
  11968. return;
  11969. }
  11970. if( bid <= 0 )
  11971. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11972. else if( bid > sd->status.zeny )
  11973. clif_Auction_message(fd, 8); // You do not have enough zeny
  11974. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  11975. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11976. else {
  11977. log_zeny(sd, LOG_TYPE_AUCTION, sd, -bid);
  11978. pc_payzeny(sd, bid);
  11979. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11980. }
  11981. }
  11982. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  11983. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  11984. /// search type:
  11985. /// 0 = armor
  11986. /// 1 = weapon
  11987. /// 2 = card
  11988. /// 3 = misc
  11989. /// 4 = name search
  11990. /// 5 = auction id search
  11991. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11992. {
  11993. char search_text[NAME_LENGTH];
  11994. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11995. int price = RFIFOL(fd,4); // FIXME: bug #5071
  11996. clif_parse_Auction_cancelreg(fd, sd);
  11997. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  11998. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11999. }
  12000. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12001. /// 025c <type>.W
  12002. /// type:
  12003. /// 0 = sell (own auctions)
  12004. /// 1 = buy (own bids)
  12005. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12006. {
  12007. short type = RFIFOW(fd,2) + 6;
  12008. clif_parse_Auction_cancelreg(fd, sd);
  12009. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12010. }
  12011. /// CASH/POINT SHOP
  12012. ///
  12013. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12014. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12015. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12016. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12017. {
  12018. int fd,i;
  12019. #if PACKETVER < 20070711
  12020. const int offset = 8;
  12021. #else
  12022. const int offset = 12;
  12023. #endif
  12024. nullpo_retv(sd);
  12025. nullpo_retv(nd);
  12026. fd = sd->fd;
  12027. sd->npc_shopid = nd->bl.id;
  12028. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12029. WFIFOW(fd,0) = 0x287;
  12030. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12031. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12032. #if PACKETVER >= 20070711
  12033. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12034. #endif
  12035. for( i = 0; i < nd->u.shop.count; i++ )
  12036. {
  12037. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12038. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12039. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12040. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  12041. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12042. }
  12043. WFIFOSET(fd,WFIFOW(fd,2));
  12044. }
  12045. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12046. /// 0289 <cash point>.L <error>.W
  12047. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12048. /// error:
  12049. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12050. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12051. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12052. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12053. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12054. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12055. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12056. /// 7 = You can purchase up to 10 items.
  12057. /// 8 = Some items could not be purchased.
  12058. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12059. {
  12060. int fd = sd->fd;
  12061. WFIFOHEAD(fd, packet_len(0x289));
  12062. WFIFOW(fd,0) = 0x289;
  12063. WFIFOL(fd,2) = sd->cashPoints;
  12064. #if PACKETVER < 20070711
  12065. WFIFOW(fd,6) = TOW(error);
  12066. #else
  12067. WFIFOL(fd,6) = sd->kafraPoints;
  12068. WFIFOW(fd,10) = TOW(error);
  12069. #endif
  12070. WFIFOSET(fd, packet_len(0x289));
  12071. }
  12072. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12073. /// 0288 <name id>.W <amount>.W
  12074. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12075. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12076. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  12077. {
  12078. int fail = 0;
  12079. nullpo_retv(sd);
  12080. if( sd->state.trading || !sd->npc_shopid )
  12081. fail = 1;
  12082. else
  12083. {
  12084. #if PACKETVER < 20101116
  12085. short nameid = RFIFOW(fd,2);
  12086. short amount = RFIFOW(fd,4);
  12087. int points = RFIFOL(fd,6);
  12088. fail = npc_cashshop_buy(sd, nameid, amount, points);
  12089. #else
  12090. int len = RFIFOW(fd,2);
  12091. int points = RFIFOL(fd,4);
  12092. int count = RFIFOW(fd,8);
  12093. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  12094. if( len < 10 || len != 10 + count * 4)
  12095. {
  12096. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  12097. return;
  12098. }
  12099. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12100. #endif
  12101. }
  12102. clif_cashshop_ack(sd,fail);
  12103. }
  12104. /// Adoption System
  12105. ///
  12106. /// Adoption message (ZC_BABYMSG).
  12107. /// 0216 <msg>.L
  12108. /// msg:
  12109. /// 0 = "You cannot adopt more than 1 child."
  12110. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12111. /// 2 = "You cannot adopt a married person."
  12112. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12113. {
  12114. int fd = sd->fd;
  12115. WFIFOHEAD(fd,6);
  12116. WFIFOW(fd,0) = 0x216;
  12117. WFIFOL(fd,2) = type;
  12118. WFIFOSET(fd,6);
  12119. }
  12120. /// Adoption confirmation (ZC_REQ_BABY).
  12121. /// 01f6 <account id>.L <char id>.L <name>.B
  12122. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12123. {
  12124. int fd = sd->fd;
  12125. WFIFOHEAD(fd,34);
  12126. WFIFOW(fd,0) = 0x1f6;
  12127. WFIFOL(fd,2) = src->status.account_id;
  12128. WFIFOL(fd,6) = p_id;
  12129. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12130. WFIFOSET(fd,34);
  12131. }
  12132. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12133. /// 01f9 <account id>.L
  12134. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12135. {
  12136. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12137. if( pc_can_Adopt(sd, p_sd, tsd) )
  12138. {
  12139. tsd->adopt_invite = sd->status.account_id;
  12140. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12141. }
  12142. }
  12143. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12144. /// 01f7 <account id>.L <char id>.L <answer>.L
  12145. /// answer:
  12146. /// 0 = rejected
  12147. /// 1 = accepted
  12148. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12149. {
  12150. int p1_id = RFIFOL(fd,2);
  12151. int p2_id = RFIFOL(fd,6);
  12152. int result = RFIFOL(fd,10);
  12153. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12154. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12155. int pid = sd->adopt_invite;
  12156. sd->adopt_invite = 0;
  12157. if( p1_sd == NULL || p2_sd == NULL )
  12158. return; // Both players need to be online
  12159. if( pid != p1_sd->status.account_id )
  12160. return; // Incorrect values
  12161. if( result == 0 )
  12162. return; // Rejected
  12163. pc_adoption(p1_sd, p2_sd, sd);
  12164. }
  12165. /// Convex Mirror (ZC_BOSS_INFO).
  12166. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12167. /// infoType:
  12168. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12169. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12170. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12171. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12172. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12173. {
  12174. WFIFOHEAD(fd,70);
  12175. memset(WFIFOP(fd,0),0,70);
  12176. WFIFOW(fd,0) = 0x293;
  12177. if( md != NULL )
  12178. {
  12179. if( md->bl.prev != NULL )
  12180. { // Boss on This Map
  12181. if( flag )
  12182. {
  12183. WFIFOB(fd,2) = 1;
  12184. WFIFOL(fd,3) = md->bl.x;
  12185. WFIFOL(fd,7) = md->bl.y;
  12186. }
  12187. else
  12188. WFIFOB(fd,2) = 2; // First Time
  12189. }
  12190. else if (md->spawn_timer != INVALID_TIMER)
  12191. { // Boss is Dead
  12192. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12193. unsigned int seconds;
  12194. int hours, minutes;
  12195. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12196. hours = seconds / (60 * 60);
  12197. seconds = seconds - (60 * 60 * hours);
  12198. minutes = seconds / 60;
  12199. WFIFOB(fd,2) = 3;
  12200. WFIFOW(fd,11) = hours; // Hours
  12201. WFIFOW(fd,13) = minutes; // Minutes
  12202. }
  12203. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12204. }
  12205. WFIFOSET(fd,70);
  12206. }
  12207. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12208. /// 02d6 <account id>.L
  12209. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12210. {
  12211. int charid = RFIFOL(fd, 2);
  12212. struct map_session_data* tsd = map_id2sd(charid);
  12213. if (!tsd)
  12214. return;
  12215. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12216. clif_viewequip_ack(sd, tsd);
  12217. else
  12218. clif_viewequip_fail(sd);
  12219. }
  12220. /// Request to change equip window tick (CZ_CONFIG).
  12221. /// 02d8 <type>.L <value>.L
  12222. /// type:
  12223. /// 0 = open equip window
  12224. /// value:
  12225. /// 0 = disabled
  12226. /// 1 = enabled
  12227. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12228. {
  12229. bool flag = (bool)RFIFOL(fd,6);
  12230. sd->status.show_equip = flag;
  12231. clif_equiptickack(sd, flag);
  12232. }
  12233. /// Questlog System [Kevin] [Inkfish]
  12234. ///
  12235. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12236. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12237. void clif_quest_send_list(struct map_session_data * sd)
  12238. {
  12239. int fd = sd->fd;
  12240. int i;
  12241. int len = sd->avail_quests*5+8;
  12242. WFIFOHEAD(fd,len);
  12243. WFIFOW(fd, 0) = 0x2b1;
  12244. WFIFOW(fd, 2) = len;
  12245. WFIFOL(fd, 4) = sd->avail_quests;
  12246. for( i = 0; i < sd->avail_quests; i++ )
  12247. {
  12248. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12249. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12250. }
  12251. WFIFOSET(fd, len);
  12252. }
  12253. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12254. /// 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
  12255. void clif_quest_send_mission(struct map_session_data * sd)
  12256. {
  12257. int fd = sd->fd;
  12258. int i, j;
  12259. int len = sd->avail_quests*104+8;
  12260. struct mob_db *mob;
  12261. WFIFOHEAD(fd, len);
  12262. WFIFOW(fd, 0) = 0x2b2;
  12263. WFIFOW(fd, 2) = len;
  12264. WFIFOL(fd, 4) = sd->avail_quests;
  12265. for( i = 0; i < sd->avail_quests; i++ )
  12266. {
  12267. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12268. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12269. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12270. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12271. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  12272. {
  12273. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12274. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12275. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12276. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12277. }
  12278. }
  12279. WFIFOSET(fd, len);
  12280. }
  12281. /// Notification about a new quest (ZC_ADD_QUEST).
  12282. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12283. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12284. {
  12285. int fd = sd->fd;
  12286. int i;
  12287. struct mob_db *mob;
  12288. WFIFOHEAD(fd, packet_len(0x2b3));
  12289. WFIFOW(fd, 0) = 0x2b3;
  12290. WFIFOL(fd, 2) = qd->quest_id;
  12291. WFIFOB(fd, 6) = qd->state;
  12292. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12293. WFIFOL(fd, 11) = qd->time;
  12294. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12295. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12296. {
  12297. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12298. WFIFOW(fd, i*30+21) = qd->count[i];
  12299. mob = mob_db(quest_db[index].mob[i]);
  12300. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12301. }
  12302. WFIFOSET(fd, packet_len(0x2b3));
  12303. }
  12304. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12305. /// 02b4 <quest id>.L
  12306. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12307. {
  12308. int fd = sd->fd;
  12309. WFIFOHEAD(fd, packet_len(0x2b4));
  12310. WFIFOW(fd, 0) = 0x2b4;
  12311. WFIFOL(fd, 2) = quest_id;
  12312. WFIFOSET(fd, packet_len(0x2b4));
  12313. }
  12314. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12315. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12316. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12317. {
  12318. int fd = sd->fd;
  12319. int i;
  12320. int len = quest_db[index].num_objectives*12+6;
  12321. WFIFOHEAD(fd, len);
  12322. WFIFOW(fd, 0) = 0x2b5;
  12323. WFIFOW(fd, 2) = len;
  12324. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12325. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12326. {
  12327. WFIFOL(fd, i*12+6) = qd->quest_id;
  12328. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12329. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12330. WFIFOW(fd, i*12+16) = qd->count[i];
  12331. }
  12332. WFIFOSET(fd, len);
  12333. }
  12334. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12335. /// 02b6 <quest id>.L <active>.B
  12336. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12337. {
  12338. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12339. }
  12340. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12341. /// 02b7 <quest id>.L <active>.B
  12342. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12343. {
  12344. int fd = sd->fd;
  12345. WFIFOHEAD(fd, packet_len(0x2b7));
  12346. WFIFOW(fd, 0) = 0x2b7;
  12347. WFIFOL(fd, 2) = quest_id;
  12348. WFIFOB(fd, 6) = active;
  12349. WFIFOSET(fd, packet_len(0x2b7));
  12350. }
  12351. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12352. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12353. /// effect:
  12354. /// 0 = none
  12355. /// 1 = exclamation mark icon
  12356. /// 2 = question mark icon
  12357. /// type:
  12358. /// 0 = yellow
  12359. /// 1 = orange
  12360. /// 2 = green
  12361. /// 3 = purple
  12362. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12363. {
  12364. #if PACKETVER >= 20090218
  12365. int fd = sd->fd;
  12366. WFIFOHEAD(fd, packet_len(0x446));
  12367. WFIFOW(fd, 0) = 0x446;
  12368. WFIFOL(fd, 2) = bl->id;
  12369. WFIFOW(fd, 6) = bl->x;
  12370. WFIFOW(fd, 8) = bl->y;
  12371. WFIFOW(fd, 10) = state;
  12372. WFIFOW(fd, 12) = color;
  12373. WFIFOSET(fd, packet_len(0x446));
  12374. #endif
  12375. }
  12376. /// Mercenary System
  12377. ///
  12378. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12379. /// 02a2 <var id>.W <value>.L
  12380. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12381. {
  12382. struct mercenary_data *md;
  12383. struct status_data *status;
  12384. int fd;
  12385. if( sd == NULL || (md = sd->md) == NULL )
  12386. return;
  12387. fd = sd->fd;
  12388. status = &md->battle_status;
  12389. WFIFOHEAD(fd,packet_len(0x2a2));
  12390. WFIFOW(fd,0) = 0x2a2;
  12391. WFIFOW(fd,2) = type;
  12392. switch( type )
  12393. {
  12394. case SP_ATK1:
  12395. {
  12396. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12397. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12398. }
  12399. break;
  12400. case SP_MATK1:
  12401. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12402. break;
  12403. case SP_HIT:
  12404. WFIFOL(fd,4) = status->hit;
  12405. break;
  12406. case SP_CRITICAL:
  12407. WFIFOL(fd,4) = status->cri/10;
  12408. break;
  12409. case SP_DEF1:
  12410. WFIFOL(fd,4) = status->def;
  12411. break;
  12412. case SP_MDEF1:
  12413. WFIFOL(fd,4) = status->mdef;
  12414. break;
  12415. case SP_MERCFLEE:
  12416. WFIFOL(fd,4) = status->flee;
  12417. break;
  12418. case SP_ASPD:
  12419. WFIFOL(fd,4) = status->amotion;
  12420. break;
  12421. case SP_HP:
  12422. WFIFOL(fd,4) = status->hp;
  12423. break;
  12424. case SP_MAXHP:
  12425. WFIFOL(fd,4) = status->max_hp;
  12426. break;
  12427. case SP_SP:
  12428. WFIFOL(fd,4) = status->sp;
  12429. break;
  12430. case SP_MAXSP:
  12431. WFIFOL(fd,4) = status->max_sp;
  12432. break;
  12433. case SP_MERCKILLS:
  12434. WFIFOL(fd,4) = md->mercenary.kill_count;
  12435. break;
  12436. case SP_MERCFAITH:
  12437. WFIFOL(fd,4) = mercenary_get_faith(md);
  12438. break;
  12439. }
  12440. WFIFOSET(fd,packet_len(0x2a2));
  12441. }
  12442. /// Mercenary base status data (ZC_MER_INIT).
  12443. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12444. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12445. /// <calls>.L <kills>.L <atk range>.W
  12446. void clif_mercenary_info(struct map_session_data *sd)
  12447. {
  12448. int fd;
  12449. struct mercenary_data *md;
  12450. struct status_data *status;
  12451. int atk;
  12452. if( sd == NULL || (md = sd->md) == NULL )
  12453. return;
  12454. fd = sd->fd;
  12455. status = &md->battle_status;
  12456. WFIFOHEAD(fd,packet_len(0x29b));
  12457. WFIFOW(fd,0) = 0x29b;
  12458. WFIFOL(fd,2) = md->bl.id;
  12459. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12460. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12461. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12462. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12463. WFIFOW(fd,10) = status->hit;
  12464. WFIFOW(fd,12) = status->cri/10;
  12465. WFIFOW(fd,14) = status->def;
  12466. WFIFOW(fd,16) = status->mdef;
  12467. WFIFOW(fd,18) = status->flee;
  12468. WFIFOW(fd,20) = status->amotion;
  12469. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12470. WFIFOW(fd,46) = md->db->lv;
  12471. WFIFOL(fd,48) = status->hp;
  12472. WFIFOL(fd,52) = status->max_hp;
  12473. WFIFOL(fd,56) = status->sp;
  12474. WFIFOL(fd,60) = status->max_sp;
  12475. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12476. WFIFOW(fd,68) = mercenary_get_faith(md);
  12477. WFIFOL(fd,70) = mercenary_get_calls(md);
  12478. WFIFOL(fd,74) = md->mercenary.kill_count;
  12479. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12480. WFIFOSET(fd,packet_len(0x29b));
  12481. }
  12482. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12483. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12484. void clif_mercenary_skillblock(struct map_session_data *sd)
  12485. {
  12486. struct mercenary_data *md;
  12487. int fd, i, len = 4, id, j;
  12488. if( sd == NULL || (md = sd->md) == NULL )
  12489. return;
  12490. fd = sd->fd;
  12491. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12492. WFIFOW(fd,0) = 0x29d;
  12493. for( i = 0; i < MAX_MERCSKILL; i++ )
  12494. {
  12495. if( (id = md->db->skill[i].id) == 0 )
  12496. continue;
  12497. j = id - MC_SKILLBASE;
  12498. WFIFOW(fd,len) = id;
  12499. WFIFOL(fd,len+2) = skill_get_inf(id);
  12500. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12501. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12502. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12503. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12504. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12505. len += 37;
  12506. }
  12507. WFIFOW(fd,2) = len;
  12508. WFIFOSET(fd,len);
  12509. }
  12510. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12511. /// 029f <command>.B
  12512. /// 1 = mercenary information
  12513. /// 2 = delete
  12514. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12515. {
  12516. int option = RFIFOB(fd,2);
  12517. if( sd->md == NULL )
  12518. return;
  12519. if( option == 2 ) merc_delete(sd->md, 2);
  12520. }
  12521. /// Mercenary Message
  12522. /// message:
  12523. /// 0 = Mercenary soldier's duty hour is over.
  12524. /// 1 = Your mercenary soldier has been killed.
  12525. /// 2 = Your mercenary soldier has been fired.
  12526. /// 3 = Your mercenary soldier has ran away.
  12527. void clif_mercenary_message(struct map_session_data* sd, int message)
  12528. {
  12529. clif_msg(sd, 1266 + message);
  12530. }
  12531. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12532. /// 0298 <name id>.W <seconds>.L
  12533. void clif_rental_time(int fd, int nameid, int seconds)
  12534. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12535. WFIFOHEAD(fd,packet_len(0x298));
  12536. WFIFOW(fd,0) = 0x298;
  12537. WFIFOW(fd,2) = nameid;
  12538. WFIFOL(fd,4) = seconds;
  12539. WFIFOSET(fd,packet_len(0x298));
  12540. }
  12541. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12542. /// 0299 <index>.W <name id>.W
  12543. void clif_rental_expired(int fd, int index, int nameid)
  12544. { // '<ItemName>' item has been deleted from the Inventory
  12545. WFIFOHEAD(fd,packet_len(0x299));
  12546. WFIFOW(fd,0) = 0x299;
  12547. WFIFOW(fd,2) = index+2;
  12548. WFIFOW(fd,4) = nameid;
  12549. WFIFOSET(fd,packet_len(0x299));
  12550. }
  12551. /// Book Reading (ZC_READ_BOOK).
  12552. /// 0294 <book id>.L <page>.L
  12553. void clif_readbook(int fd, int book_id, int page)
  12554. {
  12555. WFIFOHEAD(fd,packet_len(0x294));
  12556. WFIFOW(fd,0) = 0x294;
  12557. WFIFOL(fd,2) = book_id;
  12558. WFIFOL(fd,6) = page;
  12559. WFIFOSET(fd,packet_len(0x294));
  12560. }
  12561. /// Battlegrounds
  12562. ///
  12563. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12564. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12565. void clif_bg_hp(struct map_session_data *sd)
  12566. {
  12567. unsigned char buf[34];
  12568. const int cmd = 0x2e0;
  12569. nullpo_retv(sd);
  12570. WBUFW(buf,0) = cmd;
  12571. WBUFL(buf,2) = sd->status.account_id;
  12572. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12573. if( sd->battle_status.max_hp > INT16_MAX )
  12574. { // To correctly display the %hp bar. [Skotlex]
  12575. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12576. WBUFW(buf,32) = 100;
  12577. }
  12578. else
  12579. {
  12580. WBUFW(buf,30) = sd->battle_status.hp;
  12581. WBUFW(buf,32) = sd->battle_status.max_hp;
  12582. }
  12583. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12584. }
  12585. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12586. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12587. void clif_bg_xy(struct map_session_data *sd)
  12588. {
  12589. unsigned char buf[36];
  12590. nullpo_retv(sd);
  12591. WBUFW(buf,0)=0x2df;
  12592. WBUFL(buf,2)=sd->status.account_id;
  12593. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12594. WBUFW(buf,30)=sd->status.class_;
  12595. WBUFW(buf,32)=sd->bl.x;
  12596. WBUFW(buf,34)=sd->bl.y;
  12597. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12598. }
  12599. void clif_bg_xy_remove(struct map_session_data *sd)
  12600. {
  12601. unsigned char buf[36];
  12602. nullpo_retv(sd);
  12603. WBUFW(buf,0)=0x2df;
  12604. WBUFL(buf,2)=sd->status.account_id;
  12605. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12606. WBUFW(buf,30)=0;
  12607. WBUFW(buf,32)=-1;
  12608. WBUFW(buf,34)=-1;
  12609. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12610. }
  12611. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12612. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12613. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12614. {
  12615. struct map_session_data *sd;
  12616. unsigned char *buf;
  12617. if( (sd = bg_getavailablesd(bg)) == NULL )
  12618. return;
  12619. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12620. WBUFW(buf,0) = 0x2dc;
  12621. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12622. WBUFL(buf,4) = src_id;
  12623. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12624. memcpy(WBUFP(buf,32), mes, len);
  12625. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12626. if( buf )
  12627. aFree(buf);
  12628. }
  12629. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12630. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12631. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12632. {
  12633. const char* text = (char*)RFIFOP(fd,4);
  12634. int textlen = RFIFOW(fd,2) - 4;
  12635. char *name, *message;
  12636. int namelen, messagelen;
  12637. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12638. return;
  12639. if( is_atcommand(fd, sd, message, 1) )
  12640. return;
  12641. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12642. return;
  12643. if( battle_config.min_chat_delay )
  12644. {
  12645. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12646. return;
  12647. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12648. }
  12649. bg_send_message(sd, text, textlen);
  12650. }
  12651. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12652. /// 02de <camp A points>.W <camp B points>.W
  12653. void clif_bg_updatescore(int m)
  12654. {
  12655. struct block_list bl;
  12656. unsigned char buf[6];
  12657. bl.id = 0;
  12658. bl.type = BL_NUL;
  12659. bl.m = m;
  12660. WBUFW(buf,0) = 0x2de;
  12661. WBUFW(buf,2) = map[m].bgscore_lion;
  12662. WBUFW(buf,4) = map[m].bgscore_eagle;
  12663. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12664. }
  12665. void clif_bg_updatescore_single(struct map_session_data *sd)
  12666. {
  12667. int fd;
  12668. nullpo_retv(sd);
  12669. fd = sd->fd;
  12670. WFIFOHEAD(fd,packet_len(0x2de));
  12671. WFIFOW(fd,0) = 0x2de;
  12672. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12673. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12674. WFIFOSET(fd,packet_len(0x2de));
  12675. }
  12676. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12677. /// 02dd <account id>.L <name>.24B <camp>.W
  12678. void clif_sendbgemblem_area(struct map_session_data *sd)
  12679. {
  12680. unsigned char buf[33];
  12681. nullpo_retv(sd);
  12682. WBUFW(buf, 0) = 0x2dd;
  12683. WBUFL(buf,2) = sd->bl.id;
  12684. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12685. WBUFW(buf,30) = sd->bg_id;
  12686. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12687. }
  12688. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12689. {
  12690. nullpo_retv(sd);
  12691. WFIFOHEAD(fd,32);
  12692. WFIFOW(fd,0) = 0x2dd;
  12693. WFIFOL(fd,2) = sd->bl.id;
  12694. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12695. WFIFOW(fd,30) = sd->bg_id;
  12696. WFIFOSET(fd,packet_len(0x2dd));
  12697. }
  12698. /// Custom Fonts (ZC_NOTIFY_FONT).
  12699. /// 02ef <account_id>.L <font id>.W
  12700. void clif_font(struct map_session_data *sd)
  12701. {
  12702. #if PACKETVER >= 20080102
  12703. unsigned char buf[8];
  12704. nullpo_retv(sd);
  12705. WBUFW(buf,0) = 0x2ef;
  12706. WBUFL(buf,2) = sd->bl.id;
  12707. WBUFW(buf,6) = sd->user_font;
  12708. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12709. #endif
  12710. }
  12711. /*==========================================
  12712. * Instancing Window
  12713. *------------------------------------------*/
  12714. int clif_instance(int instance_id, int type, int flag)
  12715. {
  12716. struct map_session_data *sd;
  12717. struct party_data *p;
  12718. unsigned char buf[255];
  12719. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12720. return 0;
  12721. switch( type )
  12722. {
  12723. case 1:
  12724. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12725. // Required to start the instancing information window on Client
  12726. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12727. WBUFW(buf,0) = 0x02CB;
  12728. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12729. WBUFW(buf,63) = flag;
  12730. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12731. break;
  12732. case 2:
  12733. // S 0x2cc <Standby Position>.W
  12734. // To announce Instancing queue creation if no maps available
  12735. WBUFW(buf,0) = 0x02CC;
  12736. WBUFW(buf,2) = flag;
  12737. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12738. break;
  12739. case 3:
  12740. case 4:
  12741. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12742. WBUFW(buf,0) = 0x02CD;
  12743. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12744. if( type == 3 )
  12745. {
  12746. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12747. WBUFL(buf,67) = 0;
  12748. }
  12749. else
  12750. {
  12751. WBUFL(buf,63) = 0;
  12752. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12753. }
  12754. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12755. break;
  12756. case 5:
  12757. // S 0x2ce <Message ID>.L
  12758. // 0 = Notification (EnterLimitDate update?)
  12759. // 1 = The Memorial Dungeon expired; it has been destroyed
  12760. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12761. // 3 = The Memorial Dungeon has been removed.
  12762. // 4 = Create failure (removes the instance window)
  12763. WBUFW(buf,0) = 0x02CE;
  12764. WBUFL(buf,2) = flag;
  12765. //WBUFL(buf,6) = EnterLimitDate;
  12766. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12767. break;
  12768. }
  12769. return 0;
  12770. }
  12771. void clif_instance_join(int fd, int instance_id)
  12772. {
  12773. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12774. {
  12775. WFIFOHEAD(fd,packet_len(0x02CD));
  12776. WFIFOW(fd,0) = 0x02CD;
  12777. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12778. WFIFOL(fd,63) = 0;
  12779. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12780. WFIFOSET(fd,packet_len(0x02CD));
  12781. }
  12782. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12783. {
  12784. WFIFOHEAD(fd,packet_len(0x02CD));
  12785. WFIFOW(fd,0) = 0x02CD;
  12786. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12787. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12788. WFIFOL(fd,67) = 0;
  12789. WFIFOSET(fd,packet_len(0x02CD));
  12790. }
  12791. else
  12792. {
  12793. WFIFOHEAD(fd,packet_len(0x02CB));
  12794. WFIFOW(fd,0) = 0x02CB;
  12795. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12796. WFIFOW(fd,63) = 0;
  12797. WFIFOSET(fd,packet_len(0x02CB));
  12798. }
  12799. }
  12800. void clif_instance_leave(int fd)
  12801. {
  12802. WFIFOHEAD(fd,packet_len(0x02CE));
  12803. WFIFOW(fd,0) = 0x02ce;
  12804. WFIFOL(fd,2) = 4;
  12805. WFIFOSET(fd,packet_len(0x02CE));
  12806. }
  12807. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12808. /// 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
  12809. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12810. {
  12811. #if PACKETVER >= 20071002
  12812. unsigned char buf[22];
  12813. struct item_data* id = itemdb_search(item_data->nameid);
  12814. WBUFW(buf,0) = 0x2b8;
  12815. WBUFL(buf,2) = sd->status.account_id;
  12816. WBUFW(buf,6) = item_data->nameid;
  12817. WBUFB(buf,8) = item_data->identify;
  12818. WBUFB(buf,9) = item_data->attribute;
  12819. WBUFB(buf,10) = item_data->refine;
  12820. clif_addcards(WBUFP(buf,11), item_data);
  12821. WBUFW(buf,19) = id->equip; // equip location
  12822. WBUFB(buf,21) = itemtype(id->type); // item type
  12823. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12824. #endif
  12825. }
  12826. /// Display gained exp (ZC_NOTIFY_EXP).
  12827. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12828. /// var id:
  12829. /// SP_BASEEXP, SP_JOBEXP
  12830. /// exp type:
  12831. /// 0 = normal exp gain/loss
  12832. /// 1 = quest exp gain/loss
  12833. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12834. {
  12835. int fd;
  12836. nullpo_retv(sd);
  12837. fd = sd->fd;
  12838. WFIFOHEAD(fd, packet_len(0x7f6));
  12839. WFIFOW(fd,0) = 0x7f6;
  12840. WFIFOL(fd,2) = sd->bl.id;
  12841. WFIFOL(fd,6) = exp;
  12842. WFIFOW(fd,10) = type;
  12843. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12844. WFIFOSET(fd,packet_len(0x7f6));
  12845. }
  12846. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12847. /// type:
  12848. /// 0 = Displays 'value' for 5 seconds.
  12849. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12850. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12851. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12852. /// value:
  12853. /// 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).
  12854. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12855. {
  12856. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12857. WFIFOW(sd->fd,0) = 0x1b1;
  12858. WFIFOB(sd->fd,2) = type;
  12859. WFIFOL(sd->fd,3) = value;
  12860. WFIFOSET(sd->fd, packet_len(0x1b1));
  12861. }
  12862. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12863. /// 021d <state>.L
  12864. /// state:
  12865. /// 0 = Full effects
  12866. /// 1 = Reduced effects
  12867. ///
  12868. /// NOTE: The state is used on Aegis for sending skill unit packet
  12869. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12870. /// whenever possible. Due to the way the decision check is
  12871. /// constructed, this state tracking was rendered useless,
  12872. /// as the only skill unit, that is sent with 0x1c9 is
  12873. /// Graffiti.
  12874. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12875. {
  12876. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12877. sd->state.lesseffect = ( isLess != 0 );
  12878. }
  12879. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12880. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12881. int n = (RFIFOW(fd,2)-12) / 4;
  12882. int type = RFIFOL(fd,4);
  12883. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12884. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12885. if( sd->state.trading || sd->npc_shopid )
  12886. return;
  12887. if( flag == 0 || n == 0) {
  12888. clif_menuskill_clear(sd);
  12889. return; // Canceled by player.
  12890. }
  12891. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12892. clif_menuskill_clear(sd);
  12893. return; // Prevent hacking.
  12894. }
  12895. switch( type ) {
  12896. case 0: // Change Material
  12897. skill_changematerial(sd,n,item_list);
  12898. break;
  12899. case 1: // Level 1: Pure to Rough
  12900. case 2: // Level 2: Rough to Pure
  12901. skill_elementalanalysis(sd,n,type,item_list);
  12902. break;
  12903. }
  12904. clif_menuskill_clear(sd);
  12905. return;
  12906. }
  12907. /*==========================================
  12908. * Elemental System
  12909. *==========================================*/
  12910. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  12911. struct elemental_data *ed;
  12912. struct status_data *status;
  12913. int fd;
  12914. if( sd == NULL || (ed = sd->ed) == NULL )
  12915. return;
  12916. fd = sd->fd;
  12917. status = &ed->battle_status;
  12918. WFIFOHEAD(fd,8);
  12919. WFIFOW(fd,0) = 0x81e;
  12920. WFIFOW(fd,2) = type;
  12921. switch( type ) {
  12922. case SP_HP:
  12923. WFIFOL(fd,4) = status->hp;
  12924. break;
  12925. case SP_MAXHP:
  12926. WFIFOL(fd,4) = status->max_hp;
  12927. break;
  12928. case SP_SP:
  12929. WFIFOL(fd,4) = status->sp;
  12930. break;
  12931. case SP_MAXSP:
  12932. WFIFOL(fd,4) = status->max_sp;
  12933. break;
  12934. }
  12935. WFIFOSET(fd,8);
  12936. }
  12937. void clif_elemental_info(struct map_session_data *sd) {
  12938. int fd;
  12939. struct elemental_data *ed;
  12940. struct status_data *status;
  12941. if( sd == NULL || (ed = sd->ed) == NULL )
  12942. return;
  12943. fd = sd->fd;
  12944. status = &ed->battle_status;
  12945. WFIFOHEAD(fd,22);
  12946. WFIFOW(fd, 0) = 0x81d;
  12947. WFIFOL(fd, 2) = ed->bl.id;
  12948. WFIFOL(fd, 6) = status->hp;
  12949. WFIFOL(fd,10) = status->max_hp;
  12950. WFIFOL(fd,14) = status->sp;
  12951. WFIFOL(fd,18) = status->max_sp;
  12952. WFIFOSET(fd,22);
  12953. }
  12954. /// Buying Store System
  12955. ///
  12956. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12957. /// 0810 <slots>.B
  12958. void clif_buyingstore_open(struct map_session_data* sd)
  12959. {
  12960. int fd = sd->fd;
  12961. WFIFOHEAD(fd,packet_len(0x810));
  12962. WFIFOW(fd,0) = 0x810;
  12963. WFIFOB(fd,2) = sd->buyingstore.slots;
  12964. WFIFOSET(fd,packet_len(0x810));
  12965. }
  12966. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12967. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12968. /// result:
  12969. /// 0 = cancel
  12970. /// 1 = open
  12971. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12972. {
  12973. const unsigned int blocksize = 8;
  12974. uint8* itemlist;
  12975. char storename[MESSAGE_SIZE];
  12976. unsigned char result;
  12977. int zenylimit;
  12978. unsigned int count, packet_len;
  12979. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12980. packet_len = RFIFOW(fd,info->pos[0]);
  12981. // TODO: Make this check global for all variable length packets.
  12982. if( packet_len < 89 )
  12983. {// minimum packet length
  12984. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12985. return;
  12986. }
  12987. zenylimit = RFIFOL(fd,info->pos[1]);
  12988. result = RFIFOL(fd,info->pos[2]);
  12989. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12990. itemlist = RFIFOP(fd,info->pos[4]);
  12991. // so that buyingstore_create knows, how many elements it has access to
  12992. packet_len-= info->pos[4];
  12993. if( packet_len%blocksize )
  12994. {
  12995. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12996. return;
  12997. }
  12998. count = packet_len/blocksize;
  12999. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13000. }
  13001. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13002. /// 0812 <result>.W <total weight>.L
  13003. /// result:
  13004. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13005. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13006. /// 8 = "No sale (purchase) information available." (0x705)
  13007. /// ? = nothing
  13008. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13009. {
  13010. int fd = sd->fd;
  13011. WFIFOHEAD(fd,packet_len(0x812));
  13012. WFIFOW(fd,0) = 0x812;
  13013. WFIFOW(fd,2) = result;
  13014. WFIFOL(fd,4) = weight;
  13015. WFIFOSET(fd,packet_len(0x812));
  13016. }
  13017. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13018. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13019. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13020. {
  13021. int fd = sd->fd;
  13022. unsigned int i;
  13023. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13024. WFIFOW(fd,0) = 0x813;
  13025. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13026. WFIFOL(fd,4) = sd->bl.id;
  13027. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13028. for( i = 0; i < sd->buyingstore.slots; i++ )
  13029. {
  13030. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13031. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13032. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  13033. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13034. }
  13035. WFIFOSET(fd,WFIFOW(fd,2));
  13036. }
  13037. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13038. /// 0814 <account id>.L <store name>.80B
  13039. void clif_buyingstore_entry(struct map_session_data* sd)
  13040. {
  13041. uint8 buf[86];
  13042. WBUFW(buf,0) = 0x814;
  13043. WBUFL(buf,2) = sd->bl.id;
  13044. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13045. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13046. }
  13047. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13048. {
  13049. int fd = sd->fd;
  13050. WFIFOHEAD(fd,packet_len(0x814));
  13051. WFIFOW(fd,0) = 0x814;
  13052. WFIFOL(fd,2) = pl_sd->bl.id;
  13053. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13054. WFIFOSET(fd,packet_len(0x814));
  13055. }
  13056. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13057. /// 0815
  13058. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13059. {
  13060. buyingstore_close(sd);
  13061. }
  13062. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13063. /// 0816 <account id>.L
  13064. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13065. {
  13066. uint8 buf[6];
  13067. WBUFW(buf,0) = 0x816;
  13068. WBUFL(buf,2) = sd->bl.id;
  13069. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13070. }
  13071. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13072. {
  13073. int fd = sd->fd;
  13074. WFIFOHEAD(fd,packet_len(0x816));
  13075. WFIFOW(fd,0) = 0x816;
  13076. WFIFOL(fd,2) = pl_sd->bl.id;
  13077. WFIFOSET(fd,packet_len(0x816));
  13078. }
  13079. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13080. /// 0817 <account id>.L
  13081. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13082. {
  13083. int account_id;
  13084. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13085. buyingstore_open(sd, account_id);
  13086. }
  13087. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13088. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13089. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13090. {
  13091. int fd = sd->fd;
  13092. unsigned int i;
  13093. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13094. WFIFOW(fd,0) = 0x818;
  13095. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13096. WFIFOL(fd,4) = pl_sd->bl.id;
  13097. WFIFOL(fd,8) = pl_sd->buyer_id;
  13098. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13099. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13100. {
  13101. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13102. 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.
  13103. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13104. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13105. }
  13106. WFIFOSET(fd,WFIFOW(fd,2));
  13107. }
  13108. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13109. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13110. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13111. {
  13112. const unsigned int blocksize = 6;
  13113. uint8* itemlist;
  13114. int account_id;
  13115. unsigned int count, packet_len, buyer_id;
  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 < 12 )
  13119. {// minimum packet length
  13120. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13121. return;
  13122. }
  13123. account_id = RFIFOL(fd,info->pos[1]);
  13124. buyer_id = RFIFOL(fd,info->pos[2]);
  13125. itemlist = RFIFOP(fd,info->pos[3]);
  13126. // so that buyingstore_trade knows, how many elements it has access to
  13127. packet_len-= info->pos[3];
  13128. if( packet_len%blocksize )
  13129. {
  13130. 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);
  13131. return;
  13132. }
  13133. count = packet_len/blocksize;
  13134. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13135. }
  13136. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13137. /// 081a <result>.W
  13138. /// result:
  13139. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13140. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13141. /// ? = nothing
  13142. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13143. {
  13144. int fd = sd->fd;
  13145. WFIFOHEAD(fd,packet_len(0x81a));
  13146. WFIFOW(fd,0) = 0x81a;
  13147. WFIFOW(fd,2) = result;
  13148. WFIFOSET(fd,packet_len(0x81a));
  13149. }
  13150. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13151. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13152. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13153. {
  13154. int fd = sd->fd;
  13155. WFIFOHEAD(fd,packet_len(0x81b));
  13156. WFIFOW(fd,0) = 0x81b;
  13157. WFIFOW(fd,2) = nameid;
  13158. WFIFOW(fd,4) = amount; // amount of nameid received
  13159. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  13160. WFIFOSET(fd,packet_len(0x81b));
  13161. }
  13162. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13163. /// 081c <index>.W <amount>.W <price>.L
  13164. /// message:
  13165. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13166. ///
  13167. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13168. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13169. {
  13170. int fd = sd->fd;
  13171. WFIFOHEAD(fd,packet_len(0x81c));
  13172. WFIFOW(fd,0) = 0x81c;
  13173. WFIFOW(fd,2) = index+2;
  13174. WFIFOW(fd,4) = amount;
  13175. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13176. WFIFOSET(fd,packet_len(0x81c));
  13177. }
  13178. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13179. /// 0824 <result>.W <name id>.W
  13180. /// result:
  13181. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13182. /// 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)
  13183. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13184. /// ? = nothing
  13185. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13186. {
  13187. int fd = sd->fd;
  13188. WFIFOHEAD(fd,packet_len(0x824));
  13189. WFIFOW(fd,0) = 0x824;
  13190. WFIFOW(fd,2) = result;
  13191. WFIFOW(fd,4) = nameid;
  13192. WFIFOSET(fd,packet_len(0x824));
  13193. }
  13194. /// Search Store Info System
  13195. ///
  13196. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13197. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13198. /// type:
  13199. /// 0 = Vending
  13200. /// 1 = Buying Store
  13201. ///
  13202. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13203. /// amount of card slots. If the client does not know about the item it
  13204. /// cannot be searched.
  13205. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13206. {
  13207. const unsigned int blocksize = 2;
  13208. const uint8* itemlist;
  13209. const uint8* cardlist;
  13210. unsigned char type;
  13211. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13212. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13213. packet_len = RFIFOW(fd,info->pos[0]);
  13214. if( packet_len < 15 )
  13215. {// minimum packet length
  13216. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13217. return;
  13218. }
  13219. type = RFIFOB(fd,info->pos[1]);
  13220. max_price = RFIFOL(fd,info->pos[2]);
  13221. min_price = RFIFOL(fd,info->pos[3]);
  13222. item_count = RFIFOB(fd,info->pos[4]);
  13223. card_count = RFIFOB(fd,info->pos[5]);
  13224. itemlist = RFIFOP(fd,info->pos[6]);
  13225. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13226. // check, if there is enough data for the claimed count of items
  13227. packet_len-= info->pos[6];
  13228. if( packet_len%blocksize )
  13229. {
  13230. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13231. return;
  13232. }
  13233. count = packet_len/blocksize;
  13234. if( count < item_count+card_count )
  13235. {
  13236. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13237. return;
  13238. }
  13239. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13240. }
  13241. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13242. /// 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 }*
  13243. /// is first page:
  13244. /// 0 = appends to existing results
  13245. /// 1 = clears previous results before displaying this result set
  13246. /// is next page:
  13247. /// 0 = no "next" label
  13248. /// 1 = "next" label to retrieve more results
  13249. void clif_search_store_info_ack(struct map_session_data* sd)
  13250. {
  13251. const unsigned int blocksize = MESSAGE_SIZE+26;
  13252. int fd = sd->fd;
  13253. unsigned int i, start, end;
  13254. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13255. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13256. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13257. WFIFOW(fd,0) = 0x836;
  13258. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13259. WFIFOB(fd,4) = !sd->searchstore.pages;
  13260. WFIFOB(fd,5) = searchstore_querynext(sd);
  13261. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13262. for( i = start; i < end; i++ )
  13263. {
  13264. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13265. struct item it;
  13266. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13267. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13268. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13269. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13270. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13271. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13272. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13273. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13274. // make-up an item for clif_addcards
  13275. memset(&it, 0, sizeof(it));
  13276. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13277. it.nameid = ssitem->nameid;
  13278. it.amount = ssitem->amount;
  13279. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13280. }
  13281. WFIFOSET(fd,WFIFOW(fd,2));
  13282. }
  13283. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13284. /// 0837 <reason>.B
  13285. /// reason:
  13286. /// 0 = "No matching stores were found." (0x70b)
  13287. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13288. /// 2 = "You cannot search anymore." (0x706)
  13289. /// 3 = "You cannot search yet." (0x708)
  13290. /// 4 = "No sale (purchase) information available." (0x705)
  13291. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13292. {
  13293. int fd = sd->fd;
  13294. WFIFOHEAD(fd,packet_len(0x837));
  13295. WFIFOW(fd,0) = 0x837;
  13296. WFIFOB(fd,2) = reason;
  13297. WFIFOSET(fd,packet_len(0x837));
  13298. }
  13299. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13300. /// 0838
  13301. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13302. {
  13303. searchstore_next(sd);
  13304. }
  13305. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13306. /// 083a <type>.W <remaining uses>.B
  13307. /// type:
  13308. /// 0 = Search Stores
  13309. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13310. void clif_open_search_store_info(struct map_session_data* sd)
  13311. {
  13312. int fd = sd->fd;
  13313. WFIFOHEAD(fd,packet_len(0x83a));
  13314. WFIFOW(fd,0) = 0x83a;
  13315. WFIFOW(fd,2) = sd->searchstore.effect;
  13316. #if PACKETVER > 20100701
  13317. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13318. #endif
  13319. WFIFOSET(fd,packet_len(0x83a));
  13320. }
  13321. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13322. /// 083b
  13323. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13324. {
  13325. searchstore_close(sd);
  13326. }
  13327. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13328. /// 083c <account id>.L <store id>.L <nameid>.W
  13329. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13330. {
  13331. unsigned short nameid;
  13332. int account_id, store_id;
  13333. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13334. account_id = RFIFOL(fd,info->pos[0]);
  13335. store_id = RFIFOL(fd,info->pos[1]);
  13336. nameid = RFIFOW(fd,info->pos[2]);
  13337. searchstore_click(sd, account_id, store_id, nameid);
  13338. }
  13339. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13340. /// 083d <xPos>.W <yPos>.W
  13341. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13342. {
  13343. int fd = sd->fd;
  13344. WFIFOHEAD(fd,packet_len(0x83d));
  13345. WFIFOW(fd,0) = 0x83d;
  13346. WFIFOW(fd,2) = x;
  13347. WFIFOW(fd,4) = y;
  13348. WFIFOSET(fd,packet_len(0x83d));
  13349. }
  13350. /// Parse function for packet debugging.
  13351. void clif_parse_debug(int fd,struct map_session_data *sd)
  13352. {
  13353. int cmd, packet_len;
  13354. // clif_parse ensures, that there is at least 2 bytes of data
  13355. cmd = RFIFOW(fd,0);
  13356. if( sd )
  13357. {
  13358. packet_len = packet_db[sd->packet_ver][cmd].len;
  13359. if( packet_len == 0 )
  13360. {// unknown
  13361. packet_len = RFIFOREST(fd);
  13362. }
  13363. else if( packet_len == -1 )
  13364. {// variable length
  13365. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13366. }
  13367. 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);
  13368. }
  13369. else
  13370. {
  13371. packet_len = RFIFOREST(fd);
  13372. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13373. }
  13374. ShowDump(RFIFOP(fd,0), packet_len);
  13375. }
  13376. /*==========================================
  13377. * Server tells client to display a window similar to Magnifier (item) one
  13378. * Server populates the window with avilable elemental converter options according to player's inventory
  13379. *------------------------------------------*/
  13380. int clif_elementalconverter_list(struct map_session_data *sd) {
  13381. int i,c,view,fd;
  13382. nullpo_ret(sd);
  13383. /// Main client packet processing function
  13384. fd=sd->fd;
  13385. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13386. WFIFOW(fd, 0)=0x1ad;
  13387. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13388. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13389. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13390. WFIFOW(fd,c*2+ 4)= view;
  13391. else
  13392. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13393. c++;
  13394. }
  13395. }
  13396. WFIFOW(fd,2) = c*2+4;
  13397. WFIFOSET(fd, WFIFOW(fd,2));
  13398. if (c > 0) {
  13399. sd->menuskill_id = SA_CREATECON;
  13400. sd->menuskill_val = c;
  13401. }
  13402. return 0;
  13403. }
  13404. /**
  13405. * Rune Knight
  13406. **/
  13407. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13408. #if PACKETVER >= 20081217
  13409. unsigned char buf[10];
  13410. WBUFW(buf,0) = 0x440;
  13411. WBUFL(buf,2) = sd->bl.id;
  13412. WBUFW(buf,6) = shields;
  13413. WBUFW(buf,8) = 0;
  13414. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13415. #endif
  13416. }
  13417. /**
  13418. * Warlock
  13419. **/
  13420. /*==========================================
  13421. * Spellbook list [LimitLine/3CeAM]
  13422. *------------------------------------------*/
  13423. int clif_spellbook_list(struct map_session_data *sd)
  13424. {
  13425. int i, c;
  13426. int fd;
  13427. nullpo_ret(sd);
  13428. fd = sd->fd;
  13429. WFIFOHEAD(fd, 8 * 8 + 8);
  13430. WFIFOW(fd,0) = 0x1ad;
  13431. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13432. {
  13433. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13434. {
  13435. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13436. c ++;
  13437. }
  13438. }
  13439. if( c > 0 )
  13440. {
  13441. WFIFOW(fd,2) = c * 2 + 4;
  13442. WFIFOSET(fd, WFIFOW(fd, 2));
  13443. sd->menuskill_id = WL_READING_SB;
  13444. sd->menuskill_val = c;
  13445. }
  13446. else{
  13447. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13448. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  13449. }
  13450. return 1;
  13451. }
  13452. /**
  13453. * Mechanic
  13454. **/
  13455. /*==========================================
  13456. * Magic Decoy Material List
  13457. *------------------------------------------*/
  13458. int clif_magicdecoy_list(struct map_session_data *sd, int skill_lv, short x, short y) {
  13459. int i, c;
  13460. int fd;
  13461. nullpo_ret(sd);
  13462. fd = sd->fd;
  13463. WFIFOHEAD(fd, 8 * 8 + 8);
  13464. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13465. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13466. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13467. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13468. c ++;
  13469. }
  13470. }
  13471. if( c > 0 ) {
  13472. sd->menuskill_id = NC_MAGICDECOY;
  13473. sd->menuskill_val = skill_lv;
  13474. sd->sc.comet_x = x;
  13475. sd->sc.comet_y = y;
  13476. WFIFOW(fd,2) = c * 2 + 4;
  13477. WFIFOSET(fd, WFIFOW(fd, 2));
  13478. } else {
  13479. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13480. return 0;
  13481. }
  13482. return 1;
  13483. }
  13484. /**
  13485. * Guilotine Cross
  13486. **/
  13487. /*==========================================
  13488. * Guillotine Cross Poisons List
  13489. *------------------------------------------*/
  13490. int clif_poison_list(struct map_session_data *sd, int skill_lv) {
  13491. int i, c;
  13492. int fd;
  13493. nullpo_ret(sd);
  13494. fd = sd->fd;
  13495. WFIFOHEAD(fd, 8 * 8 + 8);
  13496. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13497. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13498. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13499. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13500. c ++;
  13501. }
  13502. }
  13503. if( c > 0 ) {
  13504. sd->menuskill_id = GC_POISONINGWEAPON;
  13505. sd->menuskill_val = skill_lv;
  13506. WFIFOW(fd,2) = c * 2 + 4;
  13507. WFIFOSET(fd, WFIFOW(fd, 2));
  13508. } else {
  13509. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13510. return 0;
  13511. }
  13512. return 1;
  13513. }
  13514. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13515. int fd, i, c;
  13516. nullpo_ret(sd);
  13517. fd = sd->fd;
  13518. if( !fd ) return 0;
  13519. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13520. return 0;
  13521. WFIFOHEAD(fd, 2 * 6 + 4);
  13522. WFIFOW(fd,0) = 0x442;
  13523. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13524. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13525. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13526. { // Can't auto cast both Extended class and 3rd class skills.
  13527. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13528. c++;
  13529. }
  13530. if( c > 0 ) {
  13531. WFIFOW(fd,2) = 8 + c * 2;
  13532. WFIFOL(fd,4) = c;
  13533. WFIFOSET(fd,WFIFOW(fd,2));
  13534. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13535. sd->menuskill_val = c;
  13536. } else {
  13537. status_change_end(&sd->bl,SC_STOP,-1);
  13538. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13539. }
  13540. return 1;
  13541. }
  13542. /*===========================================
  13543. * Skill list for Four Elemental Analysis
  13544. * and Change Material skills.
  13545. *------------------------------------------*/
  13546. int clif_skill_itemlistwindow( struct map_session_data *sd, int skill_id, int skill_lv )
  13547. {
  13548. #if PACKETVER >= 20090922
  13549. int fd;
  13550. nullpo_ret(sd);
  13551. sd->menuskill_id = skill_id; // To prevent hacking.
  13552. sd->menuskill_val = skill_lv;
  13553. if( skill_id == GN_CHANGEMATERIAL )
  13554. skill_lv = 0; // Changematerial
  13555. fd = sd->fd;
  13556. WFIFOHEAD(fd,packet_len(0x7e3));
  13557. WFIFOW(fd,0) = 0x7e3;
  13558. WFIFOL(fd,2) = skill_lv;
  13559. WFIFOL(fd,4) = 0;
  13560. WFIFOSET(fd,packet_len(0x7e3));
  13561. #endif
  13562. return 1;
  13563. }
  13564. /**
  13565. * Sends a new status without a tick (currently used by the new mounts)
  13566. **/
  13567. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13568. unsigned char buf[32];
  13569. nullpo_ret(bl);
  13570. WBUFW(buf,0)=0x043f;
  13571. WBUFW(buf,2)=type;
  13572. WBUFL(buf,4)=bl->id;
  13573. WBUFB(buf,8)=flag;
  13574. WBUFL(buf,9) = 0;
  13575. WBUFL(buf,13) = val1;
  13576. WBUFL(buf,17) = val2;
  13577. WBUFL(buf,21) = val3;
  13578. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  13579. return 0;
  13580. }
  13581. //Notifies FD of ID's type
  13582. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13583. WFIFOHEAD(fd, packet_len(0x043f));
  13584. WFIFOW(fd,0)=0x043f;
  13585. WFIFOW(fd,2)=type;
  13586. WFIFOL(fd,4)=id;
  13587. WFIFOB(fd,8)=flag;
  13588. WFIFOL(fd,9) = 0;
  13589. WFIFOL(fd,13) = val1;
  13590. WFIFOL(fd,17) = val2;
  13591. WFIFOL(fd,21) = val3;
  13592. WFIFOSET(fd, packet_len(0x043f));
  13593. return 0;
  13594. }
  13595. // msgstringtable.txt
  13596. // 0x291 <line>.W
  13597. void clif_msgtable(int fd, int line) {
  13598. WFIFOHEAD(fd, packet_len(0x291));
  13599. WFIFOW(fd, 0) = 0x291;
  13600. WFIFOW(fd, 2) = line;
  13601. WFIFOSET(fd, packet_len(0x291));
  13602. }
  13603. // msgstringtable.txt
  13604. // 0x7e2 <line>.W <value>.L
  13605. void clif_msgtable_num(int fd, int line, int num) {
  13606. #if PACKETVER >= 20090805
  13607. WFIFOHEAD(fd, packet_len(0x7e2));
  13608. WFIFOW(fd, 0) = 0x7e2;
  13609. WFIFOW(fd, 2) = line;
  13610. WFIFOL(fd, 4) = num;
  13611. WFIFOSET(fd, packet_len(0x7e2));
  13612. #endif
  13613. }
  13614. /*==========================================
  13615. * used by SC_AUTOSHADOWSPELL
  13616. *------------------------------------------*/
  13617. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13618. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13619. return;
  13620. if( pc_istrading(sd) ) {
  13621. clif_skill_fail(sd,sd->ud.skillid,0,0);
  13622. clif_menuskill_clear(sd);
  13623. return;
  13624. }
  13625. skill_select_menu(sd,RFIFOL(fd,2),RFIFOW(fd,6));
  13626. clif_menuskill_clear(sd);
  13627. }
  13628. /*==========================================
  13629. * Main client packet processing function
  13630. *------------------------------------------*/
  13631. static int clif_parse(int fd)
  13632. {
  13633. int cmd, packet_ver, packet_len, err;
  13634. TBL_PC* sd;
  13635. int pnum;
  13636. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13637. // Note: "click masters" can do 80+ clicks in 10 seconds
  13638. 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]
  13639. { // begin main client packet processing loop
  13640. sd = (TBL_PC *)session[fd]->session_data;
  13641. if (session[fd]->flag.eof) {
  13642. if (sd) {
  13643. if (sd->state.autotrade) {
  13644. //Disassociate character from the socket connection.
  13645. session[fd]->session_data = NULL;
  13646. sd->fd = 0;
  13647. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13648. } else
  13649. if (sd->state.active) {
  13650. // Player logout display [Valaris]
  13651. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13652. clif_quitsave(fd, sd);
  13653. } else {
  13654. //Unusual logout (during log on/off/map-changer procedure)
  13655. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13656. map_quit(sd);
  13657. }
  13658. } else {
  13659. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13660. }
  13661. do_close(fd);
  13662. return 0;
  13663. }
  13664. if (RFIFOREST(fd) < 2)
  13665. return 0;
  13666. cmd = RFIFOW(fd,0);
  13667. // identify client's packet version
  13668. if (sd) {
  13669. packet_ver = sd->packet_ver;
  13670. } else {
  13671. // check authentification packet to know packet version
  13672. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13673. if( err ) {// failed to identify packet version
  13674. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  13675. err == 1 ? "" :
  13676. err == 2 ? ", possibly for having an invalid account_id" :
  13677. err == 3 ? ", possibly for having an invalid char_id." :
  13678. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13679. err == 4 ? ", possibly for having an invalid login_id1." :
  13680. err == 5 ? ", possibly for having an invalid client_tick." :
  13681. */
  13682. err == 6 ? ", possibly for having an invalid sex." :
  13683. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  13684. WFIFOHEAD(fd,packet_len(0x6a));
  13685. WFIFOW(fd,0) = 0x6a;
  13686. WFIFOB(fd,2) = 3; // Rejected from Server
  13687. WFIFOSET(fd,packet_len(0x6a));
  13688. #ifdef DUMP_INVALID_PACKET
  13689. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13690. #endif
  13691. RFIFOSKIP(fd, RFIFOREST(fd));
  13692. set_eof(fd);
  13693. return 0;
  13694. }
  13695. }
  13696. // filter out invalid / unsupported packets
  13697. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13698. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13699. #ifdef DUMP_INVALID_PACKET
  13700. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13701. #endif
  13702. set_eof(fd);
  13703. return 0;
  13704. }
  13705. // determine real packet length
  13706. packet_len = packet_db[packet_ver][cmd].len;
  13707. if (packet_len == -1) { // variable-length packet
  13708. if (RFIFOREST(fd) < 4)
  13709. return 0;
  13710. packet_len = RFIFOW(fd,2);
  13711. if (packet_len < 4 || packet_len > 32768) {
  13712. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13713. #ifdef DUMP_INVALID_PACKET
  13714. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13715. #endif
  13716. set_eof(fd);
  13717. return 0;
  13718. }
  13719. }
  13720. if ((int)RFIFOREST(fd) < packet_len)
  13721. return 0; // not enough data received to form the packet
  13722. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13723. packet_db[packet_ver][cmd].func(fd, sd);
  13724. else if( packet_db[packet_ver][cmd].func != NULL ) {
  13725. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13726. ; //Only valid packet when there is no session
  13727. else
  13728. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13729. ; //Only valid packet when player is not on a map
  13730. else
  13731. if( sd && session[sd->fd]->flag.eof )
  13732. ; //No more packets accepted
  13733. else
  13734. packet_db[packet_ver][cmd].func(fd, sd);
  13735. }
  13736. #ifdef DUMP_UNKNOWN_PACKET
  13737. else {
  13738. const char* packet_txt = "save/packet.txt";
  13739. FILE* fp;
  13740. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  13741. if( sd ) {
  13742. 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);
  13743. } else {
  13744. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13745. }
  13746. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13747. fprintf(fp, "\n");
  13748. fclose(fp);
  13749. } else {
  13750. ShowError("Failed to write '%s'.\n", packet_txt);
  13751. // Dump on console instead
  13752. if( sd ) {
  13753. 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);
  13754. } else {
  13755. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13756. }
  13757. ShowDump(RFIFOP(fd,0), packet_len);
  13758. }
  13759. }
  13760. #endif
  13761. RFIFOSKIP(fd, packet_len);
  13762. }; // main loop end
  13763. return 0;
  13764. }
  13765. /*==========================================
  13766. * Reads packet_db.txt and setups its array reference
  13767. *------------------------------------------*/
  13768. static int packetdb_readdb(void)
  13769. {
  13770. FILE *fp;
  13771. char line[1024];
  13772. int ln=0;
  13773. int cmd,i,j,packet_ver;
  13774. int max_cmd=-1;
  13775. int skip_ver = 0;
  13776. int warned = 0;
  13777. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13778. int packet_len_table[MAX_PACKET_DB] = {
  13779. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13783. //#0x0040
  13784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13786. #if PACKETVER <= 20081217
  13787. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13788. #else
  13789. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13790. #endif
  13791. #if PACKETVER < 2
  13792. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13793. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  13794. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13795. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13796. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13797. #else
  13798. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13799. #endif
  13800. //#0x0080
  13801. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13802. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13803. #if PACKETVER <= 20100622
  13804. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13805. #else
  13806. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13807. #endif
  13808. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13809. //#0x00C0
  13810. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13811. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13812. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13813. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13814. //#0x0100
  13815. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13816. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13817. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13818. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13819. //#0x0140
  13820. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13821. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13822. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13823. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13824. //#0x0180
  13825. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13826. #if PACKETVER < 1
  13827. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13828. #else // 196 comodo以降 状態表示アイコン用
  13829. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13830. #endif
  13831. #if PACKETVER < 20081126
  13832. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13833. #else // 0x1a2 changed (35->37)
  13834. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13835. #endif
  13836. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13837. //#0x01C0, Set 0x1d5=-1
  13838. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13839. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13840. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13841. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13842. //#0x0200
  13843. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13844. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13845. #if PACKETVER < 20071106
  13846. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13847. #else // 0x22c changed
  13848. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13849. #endif
  13850. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13851. //#0x0240
  13852. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13853. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13854. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13855. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13856. //#0x0280
  13857. #if PACKETVER < 20070711
  13858. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  13859. #else
  13860. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13861. #endif
  13862. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  13863. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13864. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  13865. //#0x02C0
  13866. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13867. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  13868. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  13869. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13870. //#0x0300
  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. //#0x0340
  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. //#0x0380
  13881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13885. //#0x03C0
  13886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13890. //#0x0400
  13891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  13895. //#0x0440
  13896. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  13897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13900. //#0x0480
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13905. //#0x04C0
  13906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13910. //#0x0500
  13911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13915. //#0x0540
  13916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13920. //#0x0580
  13921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13925. //#0x05C0
  13926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13930. //#0x0600
  13931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13935. //#0x0640
  13936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13940. //#0x0680
  13941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13945. //#0x06C0
  13946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13950. //#0x0700
  13951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13955. //#0x0740
  13956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13960. //#0x0780
  13961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13965. //#0x07C0
  13966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13967. #if PACKETVER < 20090617
  13968. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  13969. #else // 0x7d9 changed
  13970. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  13971. #endif
  13972. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  13973. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  13974. //#0x0800
  13975. #if PACKETVER < 20091229
  13976. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  13977. #else // for Party booking ( PACKETVER >= 20091229 )
  13978. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  13979. #endif
  13980. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  13981. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13982. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  13983. //#0x0840
  13984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13985. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  13986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13988. //#0x0880
  13989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13993. //#0x08C0
  13994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13998. //#0x0900
  13999. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14003. };
  14004. struct {
  14005. void (*func)(int, struct map_session_data *);
  14006. char *name;
  14007. } clif_parse_func[]={
  14008. {clif_parse_WantToConnection,"wanttoconnection"},
  14009. {clif_parse_LoadEndAck,"loadendack"},
  14010. {clif_parse_TickSend,"ticksend"},
  14011. {clif_parse_WalkToXY,"walktoxy"},
  14012. {clif_parse_QuitGame,"quitgame"},
  14013. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14014. {clif_parse_GlobalMessage,"globalmessage"},
  14015. {clif_parse_MapMove,"mapmove"},
  14016. {clif_parse_ChangeDir,"changedir"},
  14017. {clif_parse_Emotion,"emotion"},
  14018. {clif_parse_HowManyConnections,"howmanyconnections"},
  14019. {clif_parse_ActionRequest,"actionrequest"},
  14020. {clif_parse_Restart,"restart"},
  14021. {clif_parse_WisMessage,"wis"},
  14022. {clif_parse_Broadcast,"broadcast"},
  14023. {clif_parse_TakeItem,"takeitem"},
  14024. {clif_parse_DropItem,"dropitem"},
  14025. {clif_parse_UseItem,"useitem"},
  14026. {clif_parse_EquipItem,"equipitem"},
  14027. {clif_parse_UnequipItem,"unequipitem"},
  14028. {clif_parse_NpcClicked,"npcclicked"},
  14029. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14030. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14031. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14032. {clif_parse_CreateChatRoom,"createchatroom"},
  14033. {clif_parse_ChatAddMember,"chataddmember"},
  14034. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14035. {clif_parse_ChangeChatOwner,"changechatowner"},
  14036. {clif_parse_KickFromChat,"kickfromchat"},
  14037. {clif_parse_ChatLeave,"chatleave"},
  14038. {clif_parse_TradeRequest,"traderequest"},
  14039. {clif_parse_TradeAck,"tradeack"},
  14040. {clif_parse_TradeAddItem,"tradeadditem"},
  14041. {clif_parse_TradeOk,"tradeok"},
  14042. {clif_parse_TradeCancel,"tradecancel"},
  14043. {clif_parse_TradeCommit,"tradecommit"},
  14044. {clif_parse_StopAttack,"stopattack"},
  14045. {clif_parse_PutItemToCart,"putitemtocart"},
  14046. {clif_parse_GetItemFromCart,"getitemfromcart"},
  14047. {clif_parse_RemoveOption,"removeoption"},
  14048. {clif_parse_ChangeCart,"changecart"},
  14049. {clif_parse_StatusUp,"statusup"},
  14050. {clif_parse_SkillUp,"skillup"},
  14051. {clif_parse_UseSkillToId,"useskilltoid"},
  14052. {clif_parse_UseSkillToPos,"useskilltopos"},
  14053. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  14054. {clif_parse_UseSkillMap,"useskillmap"},
  14055. {clif_parse_RequestMemo,"requestmemo"},
  14056. {clif_parse_ProduceMix,"producemix"},
  14057. {clif_parse_Cooking,"cooking"},
  14058. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  14059. {clif_parse_NpcNextClicked,"npcnextclicked"},
  14060. {clif_parse_NpcAmountInput,"npcamountinput"},
  14061. {clif_parse_NpcStringInput,"npcstringinput"},
  14062. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  14063. {clif_parse_ItemIdentify,"itemidentify"},
  14064. {clif_parse_SelectArrow,"selectarrow"},
  14065. {clif_parse_AutoSpell,"autospell"},
  14066. {clif_parse_UseCard,"usecard"},
  14067. {clif_parse_InsertCard,"insertcard"},
  14068. {clif_parse_RepairItem,"repairitem"},
  14069. {clif_parse_WeaponRefine,"weaponrefine"},
  14070. {clif_parse_SolveCharName,"solvecharname"},
  14071. {clif_parse_ResetChar,"resetchar"},
  14072. {clif_parse_LocalBroadcast,"localbroadcast"},
  14073. {clif_parse_MoveToKafra,"movetokafra"},
  14074. {clif_parse_MoveFromKafra,"movefromkafra"},
  14075. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  14076. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  14077. {clif_parse_CloseKafra,"closekafra"},
  14078. {clif_parse_CreateParty,"createparty"},
  14079. {clif_parse_CreateParty2,"createparty2"},
  14080. {clif_parse_PartyInvite,"partyinvite"},
  14081. {clif_parse_PartyInvite2,"partyinvite2"},
  14082. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  14083. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  14084. {clif_parse_LeaveParty,"leaveparty"},
  14085. {clif_parse_RemovePartyMember,"removepartymember"},
  14086. {clif_parse_PartyChangeOption,"partychangeoption"},
  14087. {clif_parse_PartyMessage,"partymessage"},
  14088. {clif_parse_PartyChangeLeader,"partychangeleader"},
  14089. {clif_parse_CloseVending,"closevending"},
  14090. {clif_parse_VendingListReq,"vendinglistreq"},
  14091. {clif_parse_PurchaseReq,"purchasereq"},
  14092. {clif_parse_PurchaseReq2,"purchasereq2"},
  14093. {clif_parse_OpenVending,"openvending"},
  14094. {clif_parse_CreateGuild,"createguild"},
  14095. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  14096. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  14097. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  14098. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  14099. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  14100. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  14101. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  14102. {clif_parse_GuildInvite,"guildinvite"},
  14103. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  14104. {clif_parse_GuildLeave,"guildleave"},
  14105. {clif_parse_GuildExpulsion,"guildexpulsion"},
  14106. {clif_parse_GuildMessage,"guildmessage"},
  14107. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  14108. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  14109. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  14110. {clif_parse_GuildOpposition,"guildopposition"},
  14111. {clif_parse_GuildBreak,"guildbreak"},
  14112. {clif_parse_PetMenu,"petmenu"},
  14113. {clif_parse_CatchPet,"catchpet"},
  14114. {clif_parse_SelectEgg,"selectegg"},
  14115. {clif_parse_SendEmotion,"sendemotion"},
  14116. {clif_parse_ChangePetName,"changepetname"},
  14117. {clif_parse_GMKick,"gmkick"},
  14118. {clif_parse_GMHide,"gmhide"},
  14119. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14120. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14121. {clif_parse_GMKickAll,"killall"},
  14122. {clif_parse_GMRecall,"recall"},
  14123. {clif_parse_GMRecall,"summon"},
  14124. {clif_parse_GM_Monster_Item,"itemmonster"},
  14125. {clif_parse_GMShift,"remove"},
  14126. {clif_parse_GMShift,"shift"},
  14127. {clif_parse_GMChangeMapType,"changemaptype"},
  14128. {clif_parse_GMRc,"rc"},
  14129. {clif_parse_GMRecall2,"recall2"},
  14130. {clif_parse_GMRemove2,"remove2"},
  14131. {clif_parse_NoviceDoriDori,"sndoridori"},
  14132. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14133. {clif_parse_PMIgnore,"wisexin"},
  14134. {clif_parse_PMIgnoreList,"wisexlist"},
  14135. {clif_parse_PMIgnoreAll,"wisall"},
  14136. {clif_parse_FriendsListAdd,"friendslistadd"},
  14137. {clif_parse_FriendsListRemove,"friendslistremove"},
  14138. {clif_parse_FriendsListReply,"friendslistreply"},
  14139. {clif_parse_Blacksmith,"blacksmith"},
  14140. {clif_parse_Alchemist,"alchemist"},
  14141. {clif_parse_Taekwon,"taekwon"},
  14142. {clif_parse_RankingPk,"rankingpk"},
  14143. {clif_parse_FeelSaveOk,"feelsaveok"},
  14144. {clif_parse_debug,"debug"},
  14145. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14146. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14147. {clif_parse_HomMoveTo,"hommoveto"},
  14148. {clif_parse_HomAttack,"homattack"},
  14149. {clif_parse_HomMenu,"hommenu"},
  14150. {clif_parse_StoragePassword,"storagepassword"},
  14151. {clif_parse_Hotkey,"hotkey"},
  14152. {clif_parse_AutoRevive,"autorevive"},
  14153. {clif_parse_Check,"check"},
  14154. {clif_parse_Adopt_request,"adoptrequest"},
  14155. {clif_parse_Adopt_reply,"adoptreply"},
  14156. // MAIL SYSTEM
  14157. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14158. {clif_parse_Mail_read,"mailread"},
  14159. {clif_parse_Mail_getattach,"mailgetattach"},
  14160. {clif_parse_Mail_delete,"maildelete"},
  14161. {clif_parse_Mail_return,"mailreturn"},
  14162. {clif_parse_Mail_setattach,"mailsetattach"},
  14163. {clif_parse_Mail_winopen,"mailwinopen"},
  14164. {clif_parse_Mail_send,"mailsend"},
  14165. // AUCTION SYSTEM
  14166. {clif_parse_Auction_search,"auctionsearch"},
  14167. {clif_parse_Auction_buysell,"auctionbuysell"},
  14168. {clif_parse_Auction_setitem,"auctionsetitem"},
  14169. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14170. {clif_parse_Auction_register,"auctionregister"},
  14171. {clif_parse_Auction_cancel,"auctioncancel"},
  14172. {clif_parse_Auction_close,"auctionclose"},
  14173. {clif_parse_Auction_bid,"auctionbid"},
  14174. // Quest Log System
  14175. {clif_parse_questStateAck,"queststate"},
  14176. {clif_parse_cashshop_buy,"cashshopbuy"},
  14177. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14178. {clif_parse_EquipTick,"equiptickbox"},
  14179. {clif_parse_BattleChat,"battlechat"},
  14180. {clif_parse_mercenary_action,"mermenu"},
  14181. {clif_parse_progressbar,"progressbar"},
  14182. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14183. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14184. #if PACKETVER >= 20091229
  14185. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14186. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14187. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14188. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14189. #endif
  14190. {clif_parse_PVPInfo,"pvpinfo"},
  14191. {clif_parse_LessEffect,"lesseffect"},
  14192. // Buying Store
  14193. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14194. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14195. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14196. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14197. // Store Search
  14198. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14199. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14200. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14201. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14202. {NULL,NULL}
  14203. };
  14204. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14205. memset(packet_db,0,sizeof(packet_db));
  14206. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14207. packet_len(i) = packet_len_table[i];
  14208. sprintf(line, "%s/packet_db.txt", db_path);
  14209. if( (fp=fopen(line,"r"))==NULL ){
  14210. ShowFatalError("can't read %s\n", line);
  14211. exit(EXIT_FAILURE);
  14212. }
  14213. clif_config.packet_db_ver = MAX_PACKET_VER;
  14214. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14215. while( fgets(line, sizeof(line), fp) )
  14216. {
  14217. ln++;
  14218. if(line[0]=='/' && line[1]=='/')
  14219. continue;
  14220. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14221. {
  14222. if(strcmpi(w1,"packet_ver")==0) {
  14223. int prev_ver = packet_ver;
  14224. skip_ver = 0;
  14225. packet_ver = atoi(w2);
  14226. if ( packet_ver > MAX_PACKET_VER )
  14227. { //Check to avoid overflowing. [Skotlex]
  14228. if( (warned&1) == 0 )
  14229. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14230. warned &= 1;
  14231. skip_ver = 1;
  14232. }
  14233. else if( packet_ver < 0 )
  14234. {
  14235. if( (warned&2) == 0 )
  14236. ShowWarning("Negative packet versions are not supported.\n");
  14237. warned &= 2;
  14238. skip_ver = 1;
  14239. }
  14240. else if( packet_ver == SERVER )
  14241. {
  14242. if( (warned&4) == 0 )
  14243. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14244. warned &= 4;
  14245. skip_ver = 1;
  14246. }
  14247. if( skip_ver )
  14248. {
  14249. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14250. packet_ver = prev_ver;
  14251. continue;
  14252. }
  14253. // copy from previous version into new version and continue
  14254. // - indicating all following packets should be read into the newer version
  14255. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14256. continue;
  14257. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14258. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14259. clif_config.packet_db_ver = MAX_PACKET_VER;
  14260. else // to manually set the packet DB version
  14261. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14262. continue;
  14263. }
  14264. }
  14265. if( skip_ver != 0 )
  14266. continue; // Skipping current packet version
  14267. memset(str,0,sizeof(str));
  14268. for(j=0,p=line;j<4 && p; ++j)
  14269. {
  14270. str[j]=p;
  14271. p=strchr(p,',');
  14272. if(p) *p++=0;
  14273. }
  14274. if(str[0]==NULL)
  14275. continue;
  14276. cmd=strtol(str[0],(char **)NULL,0);
  14277. if(max_cmd < cmd)
  14278. max_cmd = cmd;
  14279. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14280. continue;
  14281. if(str[1]==NULL){
  14282. ShowError("packet_db: packet len error\n");
  14283. continue;
  14284. }
  14285. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14286. if(str[2]==NULL){
  14287. packet_db[packet_ver][cmd].func = NULL;
  14288. ln++;
  14289. continue;
  14290. }
  14291. // look up processing function by name
  14292. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14293. if( j < ARRAYLENGTH(clif_parse_func) )
  14294. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14295. // set the identifying cmd for the packet_db version
  14296. if (strcmp(str[2],"wanttoconnection")==0)
  14297. clif_config.connect_cmd[packet_ver] = cmd;
  14298. if(str[3]==NULL){
  14299. ShowError("packet_db: packet error\n");
  14300. exit(EXIT_FAILURE);
  14301. }
  14302. for(j=0,p2=str[3];p2;j++){
  14303. short k;
  14304. str2[j]=p2;
  14305. p2=strchr(p2,':');
  14306. if(p2) *p2++=0;
  14307. k = atoi(str2[j]);
  14308. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14309. if( j >= MAX_PACKET_POS )
  14310. {
  14311. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14312. break;
  14313. }
  14314. packet_db[packet_ver][cmd].pos[j] = k;
  14315. }
  14316. }
  14317. fclose(fp);
  14318. if(max_cmd > MAX_PACKET_DB)
  14319. {
  14320. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14321. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14322. }
  14323. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14324. { //Locate the nearest version that we still support. [Skotlex]
  14325. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14326. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14327. }
  14328. 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);
  14329. return 0;
  14330. }
  14331. /*==========================================
  14332. *
  14333. *------------------------------------------*/
  14334. int do_init_clif(void) {
  14335. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14336. int i;
  14337. /**
  14338. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14339. **/
  14340. for(i = 0; i < COLOR_MAX; i++) {
  14341. color_table[i] = strtoul(colors[i],NULL,0);
  14342. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14343. }
  14344. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14345. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14346. memset(packet_db,0,sizeof(packet_db));
  14347. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14348. packetdb_readdb();
  14349. set_defaultparse(clif_parse);
  14350. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14351. ShowFatalError("can't bind game port\n");
  14352. exit(EXIT_FAILURE);
  14353. }
  14354. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14355. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14356. return 0;
  14357. }