clif.c 525 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/grfio.h"
  7. #include "../common/malloc.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/random.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "../common/ers.h"
  14. #include "../common/conf.h"
  15. #include "map.h"
  16. #include "chrif.h"
  17. #include "pc.h"
  18. #include "status.h"
  19. #include "npc.h"
  20. #include "itemdb.h"
  21. #include "chat.h"
  22. #include "trade.h"
  23. #include "storage.h"
  24. #include "script.h"
  25. #include "skill.h"
  26. #include "atcommand.h"
  27. #include "intif.h"
  28. #include "battle.h"
  29. #include "battleground.h"
  30. #include "mob.h"
  31. #include "party.h"
  32. #include "unit.h"
  33. #include "guild.h"
  34. #include "vending.h"
  35. #include "pet.h"
  36. #include "homunculus.h"
  37. #include "instance.h"
  38. #include "mercenary.h"
  39. #include "elemental.h"
  40. #include "log.h"
  41. #include "clif.h"
  42. #include "mail.h"
  43. #include "quest.h"
  44. #include "cashshop.h"
  45. #include "channel.h"
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stdarg.h>
  50. #include <time.h>
  51. /* for clif_clearunit_delayed */
  52. static struct eri *delay_clearunit_ers;
  53. //#define DUMP_UNKNOWN_PACKET
  54. //#define DUMP_INVALID_PACKET
  55. struct Clif_Config {
  56. int packet_db_ver; //Preferred packet version.
  57. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  58. } clif_config;
  59. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  60. int packet_db_ack[MAX_PACKET_VER + 1][MAX_ACK_FUNC + 1];
  61. /** Converts item type to display it on client if necessary.
  62. * @param nameid: Item ID
  63. * @return item type. For IT_PETEGG will be displayed as IT_WEAPON. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  64. */
  65. static inline int itemtype(unsigned short nameid) {
  66. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  67. int type = id->type;
  68. if( type == IT_SHADOWGEAR ) {
  69. if( id->equip&EQP_SHADOW_WEAPON )
  70. return IT_WEAPON;
  71. else
  72. return IT_ARMOR;
  73. }
  74. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  75. }
  76. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  77. p += pos;
  78. p[0] = (uint8)(x>>2);
  79. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  80. p[2] = (uint8)((y<<4) | (dir&0xf));
  81. }
  82. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  83. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  84. p += pos;
  85. p[0] = (uint8)(x0>>2);
  86. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  87. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  88. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  89. p[4] = (uint8)y1;
  90. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  91. }
  92. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  93. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  94. }
  95. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  96. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  97. }
  98. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  99. p += pos;
  100. if( x ) {
  101. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  102. }
  103. if( y ) {
  104. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  105. }
  106. if( dir ) {
  107. dir[0] = ( p[2] & 0x0f );
  108. }
  109. }
  110. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  111. p += pos;
  112. if( x0 ) {
  113. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  114. }
  115. if( y0 ) {
  116. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  117. }
  118. if( x1 ) {
  119. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  120. }
  121. if( y1 ) {
  122. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  123. }
  124. if( sx0 ) {
  125. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  126. }
  127. if( sy0 ) {
  128. sy0[0] = ( p[5] & 0x0f ) >> 0;
  129. }
  130. }
  131. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  132. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  133. }
  134. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  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. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  140. }
  141. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  142. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  143. if( len > max )
  144. len = max;
  145. mes[len-1] = '\0';
  146. return len;
  147. }
  148. static char map_ip_str[128];
  149. static uint32 map_ip;
  150. static uint32 bind_ip = INADDR_ANY;
  151. static uint16 map_port = 5121;
  152. static bool clif_ally_only = false;
  153. int map_fd;
  154. static int clif_parse (int fd);
  155. /*==========================================
  156. * Ip setting of map-server
  157. *------------------------------------------*/
  158. int clif_setip(const char* ip) {
  159. char ip_str[16];
  160. map_ip = host2ip(ip);
  161. if (!map_ip) {
  162. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  163. return 0;
  164. }
  165. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  166. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  167. return 1;
  168. }
  169. void clif_setbindip(const char* ip)
  170. {
  171. bind_ip = host2ip(ip);
  172. if (bind_ip) {
  173. char ip_str[16];
  174. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  175. } else {
  176. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  177. }
  178. }
  179. /*==========================================
  180. * Sets map port to 'port'
  181. * is run from map.c upon loading map server configuration
  182. *------------------------------------------*/
  183. void clif_setport(uint16 port)
  184. {
  185. map_port = port;
  186. }
  187. /*==========================================
  188. * Returns map server IP
  189. *------------------------------------------*/
  190. uint32 clif_getip(void)
  191. {
  192. return map_ip;
  193. }
  194. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  195. uint32 clif_refresh_ip(void)
  196. {
  197. uint32 new_ip;
  198. new_ip = host2ip(map_ip_str);
  199. if (new_ip && new_ip != map_ip) {
  200. map_ip = new_ip;
  201. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  202. return map_ip;
  203. }
  204. return 0;
  205. }
  206. /*==========================================
  207. * Returns map port which is set by clif_setport()
  208. *------------------------------------------*/
  209. uint16 clif_getport(void)
  210. {
  211. return map_port;
  212. }
  213. #if PACKETVER >= 20071106
  214. static inline unsigned char clif_bl_type(struct block_list *bl) {
  215. switch (bl->type) {
  216. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  217. case BL_ITEM: return 0x2; //ITEM_TYPE
  218. case BL_SKILL: return 0x3; //SKILL_TYPE
  219. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  220. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  221. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  222. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  223. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  224. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  225. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  226. default: return 0x1; //NPC_TYPE
  227. }
  228. }
  229. #endif
  230. /*==========================================
  231. * sub process of clif_send
  232. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  233. * In order to send area-wise packets, such as:
  234. * - AREA : everyone nearby your area
  235. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  236. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  237. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  238. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  239. *------------------------------------------*/
  240. static int clif_send_sub(struct block_list *bl, va_list ap)
  241. {
  242. struct block_list *src_bl;
  243. struct map_session_data *sd;
  244. unsigned char *buf;
  245. int len, type, fd;
  246. nullpo_ret(bl);
  247. nullpo_ret(sd = (struct map_session_data *)bl);
  248. fd = sd->fd;
  249. if (!fd) //Don't send to disconnected clients.
  250. return 0;
  251. buf = va_arg(ap,unsigned char*);
  252. len = va_arg(ap,int);
  253. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  254. type = va_arg(ap,int);
  255. switch(type) {
  256. case AREA_WOS:
  257. if (bl == src_bl)
  258. return 0;
  259. break;
  260. case AREA_WOC:
  261. if (sd->chatID || bl == src_bl)
  262. return 0;
  263. break;
  264. case AREA_WOSC:
  265. {
  266. if(src_bl->type == BL_PC) {
  267. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  268. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  269. return 0;
  270. }
  271. else if(src_bl->type == BL_NPC) {
  272. struct npc_data *nd = (struct npc_data *)src_bl;
  273. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  274. return 0;
  275. }
  276. }
  277. break;
  278. }
  279. if (session[fd] == NULL)
  280. return 0;
  281. /* unless visible, hold it here */
  282. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  283. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  284. return 0;
  285. WFIFOHEAD(fd, len);
  286. if (WFIFOP(fd,0) == buf) {
  287. ShowError("WARNING: Invalid use of clif_send function\n");
  288. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  289. ShowError(" Please correct your code.\n");
  290. // don't send to not move the pointer of the packet for next sessions in the loop
  291. //WFIFOSET(fd,0);//## TODO is this ok?
  292. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  293. return 0;
  294. }
  295. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  296. memcpy(WFIFOP(fd,0), buf, len);
  297. WFIFOSET(fd,len);
  298. }
  299. return 0;
  300. }
  301. /*==========================================
  302. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  303. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  304. *------------------------------------------*/
  305. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  306. {
  307. int i;
  308. struct map_session_data *sd, *tsd;
  309. struct party_data *p = NULL;
  310. struct guild *g = NULL;
  311. struct battleground_data *bg = NULL;
  312. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  313. struct s_mapiterator* iter;
  314. if( type != ALL_CLIENT )
  315. nullpo_ret(bl);
  316. sd = BL_CAST(BL_PC, bl);
  317. switch(type) {
  318. case ALL_CLIENT: //All player clients.
  319. iter = mapit_getallusers();
  320. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  321. {
  322. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  323. { // packet must exist for the client version
  324. WFIFOHEAD(tsd->fd, len);
  325. memcpy(WFIFOP(tsd->fd,0), buf, len);
  326. WFIFOSET(tsd->fd,len);
  327. }
  328. }
  329. mapit_free(iter);
  330. break;
  331. case ALL_SAMEMAP: //All players on the same map
  332. iter = mapit_getallusers();
  333. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  334. {
  335. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  336. { // packet must exist for the client version
  337. WFIFOHEAD(tsd->fd, len);
  338. memcpy(WFIFOP(tsd->fd,0), buf, len);
  339. WFIFOSET(tsd->fd,len);
  340. }
  341. }
  342. mapit_free(iter);
  343. break;
  344. case AREA:
  345. case AREA_WOSC:
  346. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  347. clif_send (buf, len, bl, SELF);
  348. case AREA_WOC:
  349. case AREA_WOS:
  350. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  351. BL_PC, buf, len, bl, type);
  352. break;
  353. case AREA_CHAT_WOC:
  354. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  355. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  356. break;
  357. case CHAT:
  358. case CHAT_WOS:
  359. {
  360. struct chat_data *cd;
  361. if (sd) {
  362. cd = (struct chat_data*)map_id2bl(sd->chatID);
  363. } else if (bl->type == BL_CHAT) {
  364. cd = (struct chat_data*)bl;
  365. } else break;
  366. if (cd == NULL)
  367. break;
  368. for(i = 0; i < cd->users; i++) {
  369. if (type == CHAT_WOS && cd->usersd[i] == sd)
  370. continue;
  371. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  372. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  373. {
  374. WFIFOHEAD(fd,len);
  375. memcpy(WFIFOP(fd,0), buf, len);
  376. WFIFOSET(fd,len);
  377. }
  378. }
  379. }
  380. }
  381. break;
  382. case PARTY_AREA:
  383. case PARTY_AREA_WOS:
  384. x0 = bl->x - AREA_SIZE;
  385. y0 = bl->y - AREA_SIZE;
  386. x1 = bl->x + AREA_SIZE;
  387. y1 = bl->y + AREA_SIZE;
  388. case PARTY:
  389. case PARTY_WOS:
  390. case PARTY_SAMEMAP:
  391. case PARTY_SAMEMAP_WOS:
  392. if (sd && sd->status.party_id)
  393. p = party_search(sd->status.party_id);
  394. if (p) {
  395. for(i=0;i<MAX_PARTY;i++){
  396. if( (sd = p->data[i].sd) == NULL )
  397. continue;
  398. if( !(fd=sd->fd) )
  399. continue;
  400. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  401. continue;
  402. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  403. continue;
  404. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  405. continue;
  406. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  407. { // packet must exist for the client version
  408. WFIFOHEAD(fd,len);
  409. memcpy(WFIFOP(fd,0), buf, len);
  410. WFIFOSET(fd,len);
  411. }
  412. }
  413. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  414. break;
  415. iter = mapit_getallusers();
  416. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  417. {
  418. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  419. { // packet must exist for the client version
  420. WFIFOHEAD(tsd->fd, len);
  421. memcpy(WFIFOP(tsd->fd,0), buf, len);
  422. WFIFOSET(tsd->fd,len);
  423. }
  424. }
  425. mapit_free(iter);
  426. }
  427. break;
  428. case DUEL:
  429. case DUEL_WOS:
  430. if (!sd || !sd->duel_group) break; //Invalid usage.
  431. iter = mapit_getallusers();
  432. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  433. {
  434. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  435. continue;
  436. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  437. { // packet must exist for the client version
  438. WFIFOHEAD(tsd->fd, len);
  439. memcpy(WFIFOP(tsd->fd,0), buf, len);
  440. WFIFOSET(tsd->fd,len);
  441. }
  442. }
  443. mapit_free(iter);
  444. break;
  445. case SELF:
  446. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  447. WFIFOHEAD(fd,len);
  448. memcpy(WFIFOP(fd,0), buf, len);
  449. WFIFOSET(fd,len);
  450. }
  451. break;
  452. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  453. case GUILD_AREA:
  454. case GUILD_AREA_WOS:
  455. x0 = bl->x - AREA_SIZE;
  456. y0 = bl->y - AREA_SIZE;
  457. x1 = bl->x + AREA_SIZE;
  458. y1 = bl->y + AREA_SIZE;
  459. case GUILD_SAMEMAP:
  460. case GUILD_SAMEMAP_WOS:
  461. case GUILD:
  462. case GUILD_WOS:
  463. case GUILD_NOBG:
  464. if (sd && sd->status.guild_id)
  465. g = sd->guild;
  466. if (g) {
  467. for(i = 0; i < g->max_member; i++) {
  468. if( (sd = g->member[i].sd) != NULL )
  469. {
  470. if( !(fd=sd->fd) )
  471. continue;
  472. if( type == GUILD_NOBG && sd->bg_id )
  473. continue;
  474. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  475. continue;
  476. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  477. continue;
  478. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  479. continue;
  480. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  481. { // packet must exist for the client version
  482. WFIFOHEAD(fd,len);
  483. memcpy(WFIFOP(fd,0), buf, len);
  484. WFIFOSET(fd,len);
  485. }
  486. }
  487. }
  488. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  489. break;
  490. iter = mapit_getallusers();
  491. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  492. {
  493. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  494. { // packet must exist for the client version
  495. WFIFOHEAD(tsd->fd, len);
  496. memcpy(WFIFOP(tsd->fd,0), buf, len);
  497. WFIFOSET(tsd->fd,len);
  498. }
  499. }
  500. mapit_free(iter);
  501. }
  502. break;
  503. case BG_AREA:
  504. case BG_AREA_WOS:
  505. x0 = bl->x - AREA_SIZE;
  506. y0 = bl->y - AREA_SIZE;
  507. x1 = bl->x + AREA_SIZE;
  508. y1 = bl->y + AREA_SIZE;
  509. case BG_SAMEMAP:
  510. case BG_SAMEMAP_WOS:
  511. case BG:
  512. case BG_WOS:
  513. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  514. {
  515. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  516. {
  517. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  518. continue;
  519. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  520. continue;
  521. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  522. continue;
  523. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  524. continue;
  525. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  526. { // packet must exist for the client version
  527. WFIFOHEAD(fd,len);
  528. memcpy(WFIFOP(fd,0), buf, len);
  529. WFIFOSET(fd,len);
  530. }
  531. }
  532. }
  533. break;
  534. default:
  535. ShowError("clif_send: Unrecognized type %d\n",type);
  536. return -1;
  537. }
  538. return 0;
  539. }
  540. /// Notifies the client, that it's connection attempt was accepted.
  541. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  542. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  543. void clif_authok(struct map_session_data *sd)
  544. {
  545. #if PACKETVER < 20080102
  546. const int cmd = 0x73;
  547. #else
  548. const int cmd = 0x2eb;
  549. #endif
  550. int fd = sd->fd;
  551. WFIFOHEAD(fd,packet_len(cmd));
  552. WFIFOW(fd, 0) = cmd;
  553. WFIFOL(fd, 2) = gettick();
  554. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  555. WFIFOB(fd, 9) = 5; // ignored
  556. WFIFOB(fd,10) = 5; // ignored
  557. #if PACKETVER >= 20080102
  558. WFIFOW(fd,11) = sd->status.font;
  559. #endif
  560. WFIFOSET(fd,packet_len(cmd));
  561. }
  562. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  563. /// 0074 <error code>.B
  564. /// error code:
  565. /// 0 = client type mismatch
  566. /// 1 = ID mismatch
  567. /// 2 = mobile - out of available time
  568. /// 3 = mobile - already logged in
  569. /// 4 = mobile - waiting state
  570. void clif_authrefuse(int fd, uint8 error_code)
  571. {
  572. WFIFOHEAD(fd,packet_len(0x74));
  573. WFIFOW(fd,0) = 0x74;
  574. WFIFOB(fd,2) = error_code;
  575. WFIFOSET(fd,packet_len(0x74));
  576. }
  577. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  578. /// 0081 <error code>.B
  579. /// error code:
  580. /// 0 = BAN_UNFAIR
  581. /// 1 = server closed -> MsgStringTable[4]
  582. /// 2 = ID already logged in -> MsgStringTable[5]
  583. /// 3 = timeout/too much lag -> MsgStringTable[241]
  584. /// 4 = server full -> MsgStringTable[264]
  585. /// 5 = underaged -> MsgStringTable[305]
  586. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  587. /// 9 = too many connections from this ip -> MsgStringTable[529]
  588. /// 10 = out of available time paid for -> MsgStringTable[530]
  589. /// 11 = BAN_PAY_SUSPEND
  590. /// 12 = BAN_PAY_CHANGE
  591. /// 13 = BAN_PAY_WRONGIP
  592. /// 14 = BAN_PAY_PNGAMEROOM
  593. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  594. /// 16 = BAN_JAPAN_REFUSE1
  595. /// 17 = BAN_JAPAN_REFUSE2
  596. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  597. /// 100 = BAN_PC_IP_UNFAIR
  598. /// 101 = BAN_PC_IP_COUNT_ALL
  599. /// 102 = BAN_PC_IP_COUNT
  600. /// 103 = BAN_GRAVITY_MEM_AGREE
  601. /// 104 = BAN_GAME_MEM_AGREE
  602. /// 105 = BAN_HAN_VALID
  603. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  604. /// 107 = BAN_OVER_CHARACTER_LIST
  605. /// 108 = BAN_IP_BLOCK
  606. /// 109 = BAN_INVALID_PWD_CNT
  607. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  608. /// ? = disconnected -> MsgStringTable[3]
  609. void clif_authfail_fd(int fd, int type)
  610. {
  611. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  612. return;
  613. WFIFOHEAD(fd, packet_len(0x81));
  614. WFIFOW(fd,0) = 0x81;
  615. WFIFOB(fd,2) = type;
  616. WFIFOSET(fd,packet_len(0x81));
  617. set_eof(fd);
  618. }
  619. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  620. /// 00b3 <type>.B
  621. /// type:
  622. /// 1 = disconnect, char-select
  623. /// ? = nothing
  624. void clif_charselectok(int id, uint8 ok)
  625. {
  626. struct map_session_data* sd;
  627. int fd;
  628. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  629. return;
  630. fd = sd->fd;
  631. WFIFOHEAD(fd,packet_len(0xb3));
  632. WFIFOW(fd,0) = 0xb3;
  633. WFIFOB(fd,2) = ok;
  634. WFIFOSET(fd,packet_len(0xb3));
  635. }
  636. /// Makes an item appear on the ground.
  637. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  638. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  639. void clif_dropflooritem(struct flooritem_data* fitem)
  640. {
  641. #if PACKETVER >= 20130000
  642. uint8 buf[19];
  643. uint32 header=0x84b;
  644. #else
  645. uint8 buf[17];
  646. uint32 header=0x09e;
  647. #endif
  648. int view, offset=0;
  649. nullpo_retv(fitem);
  650. if (fitem->item.nameid == 0)
  651. return;
  652. WBUFW(buf, offset+0) = header;
  653. WBUFL(buf, offset+2) = fitem->bl.id;
  654. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  655. #if PACKETVER >= 20130000
  656. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  657. offset +=2;
  658. #endif
  659. WBUFB(buf, offset+8) = fitem->item.identify;
  660. WBUFW(buf, offset+9) = fitem->bl.x;
  661. WBUFW(buf, offset+11) = fitem->bl.y;
  662. WBUFB(buf, offset+13) = fitem->subx;
  663. WBUFB(buf, offset+14) = fitem->suby;
  664. WBUFW(buf, offset+15) = fitem->item.amount;
  665. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  666. }
  667. /// Makes an item disappear from the ground.
  668. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  669. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  670. {
  671. unsigned char buf[16];
  672. nullpo_retv(fitem);
  673. WBUFW(buf,0) = 0xa1;
  674. WBUFL(buf,2) = fitem->bl.id;
  675. if (fd == 0) {
  676. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  677. } else {
  678. WFIFOHEAD(fd,packet_len(0xa1));
  679. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  680. WFIFOSET(fd,packet_len(0xa1));
  681. }
  682. }
  683. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  684. /// 0080 <id>.L <type>.B
  685. /// type:
  686. /// 0 = out of sight
  687. /// 1 = died
  688. /// 2 = logged out
  689. /// 3 = teleport
  690. /// 4 = trickdead
  691. void clif_clearunit_single(int id, clr_type type, int fd)
  692. {
  693. WFIFOHEAD(fd, packet_len(0x80));
  694. WFIFOW(fd,0) = 0x80;
  695. WFIFOL(fd,2) = id;
  696. WFIFOB(fd,6) = type;
  697. WFIFOSET(fd, packet_len(0x80));
  698. }
  699. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  700. /// 0080 <id>.L <type>.B
  701. /// type:
  702. /// 0 = out of sight
  703. /// 1 = died
  704. /// 2 = logged out
  705. /// 3 = teleport
  706. /// 4 = trickdead
  707. void clif_clearunit_area(struct block_list* bl, clr_type type)
  708. {
  709. unsigned char buf[8];
  710. nullpo_retv(bl);
  711. WBUFW(buf,0) = 0x80;
  712. WBUFL(buf,2) = bl->id;
  713. WBUFB(buf,6) = type;
  714. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  715. if(disguised(bl)) {
  716. WBUFL(buf,2) = -bl->id;
  717. clif_send(buf, packet_len(0x80), bl, SELF);
  718. }
  719. }
  720. /// Used to make monsters with player-sprites disappear after dying
  721. /// like normal monsters, because the client does not remove those
  722. /// automatically.
  723. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  724. {
  725. struct block_list *bl = (struct block_list *)data;
  726. clif_clearunit_area(bl, (clr_type) id);
  727. ers_free(delay_clearunit_ers,bl);
  728. return 0;
  729. }
  730. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  731. {
  732. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  733. memcpy (tbl, bl, sizeof (struct block_list));
  734. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  735. }
  736. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  737. {
  738. if(sd->sc.option&OPTION_COSTUME)
  739. {
  740. *rhand = *lhand = 0;
  741. return;
  742. }
  743. #if PACKETVER < 4
  744. *rhand = sd->status.weapon;
  745. *lhand = sd->status.shield;
  746. #else
  747. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  748. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  749. {
  750. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  751. if (id->view_id > 0)
  752. *rhand = id->view_id;
  753. else
  754. *rhand = id->nameid;
  755. } else
  756. *rhand = 0;
  757. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  758. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  759. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  760. {
  761. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  762. if (id->view_id > 0)
  763. *lhand = id->view_id;
  764. else
  765. *lhand = id->nameid;
  766. } else
  767. *lhand = 0;
  768. #endif
  769. }
  770. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  771. static int clif_setlevel_sub(int lv) {
  772. if( lv < battle_config.max_lv ) {
  773. ;
  774. } else if( lv < battle_config.aura_lv ) {
  775. lv = battle_config.max_lv - 1;
  776. } else {
  777. lv = battle_config.max_lv;
  778. }
  779. return lv;
  780. }
  781. static int clif_setlevel(struct block_list* bl) {
  782. int lv = status_get_lv(bl);
  783. if( battle_config.client_limit_unit_lv&bl->type )
  784. return clif_setlevel_sub(lv);
  785. switch( bl->type ) {
  786. case BL_NPC:
  787. case BL_PET:
  788. // npcs and pets do not have level
  789. return 0;
  790. }
  791. return lv;
  792. }
  793. /*==========================================
  794. * Prepares 'unit standing/spawning' packet
  795. *------------------------------------------*/
  796. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  797. {
  798. struct map_session_data* sd;
  799. struct status_change* sc = status_get_sc(bl);
  800. struct view_data* vd = status_get_viewdata(bl);
  801. unsigned char *buf = WBUFP(buffer,0);
  802. #if PACKETVER < 20091103
  803. bool type = !pcdb_checkid(vd->class_);
  804. #endif
  805. unsigned short offset = 0;
  806. #if PACKETVER >= 20091103
  807. const char *name;
  808. #endif
  809. sd = BL_CAST(BL_PC, bl);
  810. #if PACKETVER < 20091103
  811. if(type)
  812. WBUFW(buf,0) = spawn?0x7c:0x78;
  813. else
  814. #endif
  815. #if PACKETVER < 4
  816. WBUFW(buf,0) = spawn?0x79:0x78;
  817. #elif PACKETVER < 7
  818. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  819. #elif PACKETVER < 20080102
  820. WBUFW(buf,0) = spawn?0x22b:0x22a;
  821. #elif PACKETVER < 20091103
  822. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  823. #elif PACKETVER < 20101124
  824. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  825. #else
  826. WBUFW(buf,0) = spawn?0x858:0x857;
  827. #endif
  828. #if PACKETVER >= 20091103
  829. name = status_get_name(bl);
  830. #if PACKETVER < 20110111
  831. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  832. #else
  833. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  834. #endif
  835. WBUFB(buf,4) = clif_bl_type(bl);
  836. offset+=3;
  837. buf = WBUFP(buffer,offset);
  838. #elif PACKETVER >= 20071106
  839. if (type) { //Non-player packets
  840. WBUFB(buf,2) = clif_bl_type(bl);
  841. offset++;
  842. buf = WBUFP(buffer,offset);
  843. }
  844. #endif
  845. WBUFL(buf, 2) = bl->id;
  846. WBUFW(buf, 6) = status_get_speed(bl);
  847. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  848. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  849. #if PACKETVER < 20091103
  850. if (type&&spawn) { //uses an older and different packet structure
  851. WBUFW(buf,12) = (sc)? sc->option : 0;
  852. WBUFW(buf,14) = vd->hair_style;
  853. WBUFW(buf,16) = vd->weapon;
  854. WBUFW(buf,18) = vd->head_bottom;
  855. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  856. WBUFW(buf,22) = vd->shield;
  857. } else {
  858. #endif
  859. #if PACKETVER >= 20091103
  860. WBUFL(buf,12) = (sc)? sc->option : 0;
  861. offset+=2;
  862. buf = WBUFP(buffer,offset);
  863. #elif PACKETVER >= 7
  864. if (!type) {
  865. WBUFL(buf,12) = (sc)? sc->option : 0;
  866. offset+=2;
  867. buf = WBUFP(buffer,offset);
  868. } else
  869. WBUFW(buf,12) = (sc)? sc->option : 0;
  870. #else
  871. WBUFW(buf,12) = (sc)? sc->option : 0;
  872. #endif
  873. WBUFW(buf,14) = vd->class_;
  874. WBUFW(buf,16) = vd->hair_style;
  875. WBUFW(buf,18) = vd->weapon;
  876. #if PACKETVER < 4
  877. WBUFW(buf,20) = vd->head_bottom;
  878. WBUFW(buf,22) = vd->shield;
  879. #else
  880. WBUFW(buf,20) = vd->shield;
  881. WBUFW(buf,22) = vd->head_bottom;
  882. #endif
  883. #if PACKETVER < 20091103
  884. }
  885. #endif
  886. WBUFW(buf,24) = vd->head_top;
  887. WBUFW(buf,26) = vd->head_mid;
  888. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  889. { //The hell, why flags work like this?
  890. WBUFW(buf,22) = status_get_emblem_id(bl);
  891. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  892. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  893. }
  894. WBUFW(buf,28) = vd->hair_color;
  895. WBUFW(buf,30) = vd->cloth_color;
  896. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  897. #if PACKETVER < 20091103
  898. if (type&&spawn) { //End of packet 0x7c
  899. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  900. WBUFB(buf,35) = vd->sex;
  901. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  902. WBUFB(buf,39) = 0;
  903. WBUFB(buf,40) = 0;
  904. return packet_len(0x7c);
  905. }
  906. #endif
  907. #if PACKETVER >= 20110111
  908. WBUFW(buf,34) = vd->robe;
  909. offset+= 2;
  910. buf = WBUFP(buffer,offset);
  911. #endif
  912. WBUFL(buf,34) = status_get_guild_id(bl);
  913. WBUFW(buf,38) = status_get_emblem_id(bl);
  914. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  915. #if PACKETVER >= 20091103
  916. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  917. offset+=2;
  918. buf = WBUFP(buffer,offset);
  919. #elif PACKETVER >= 7
  920. if (!type) {
  921. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  922. offset+=2;
  923. buf = WBUFP(buffer,offset);
  924. } else
  925. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  926. #else
  927. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  928. #endif
  929. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  930. WBUFB(buf,45) = vd->sex;
  931. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  932. WBUFB(buf,49) = (sd)? 5 : 0;
  933. WBUFB(buf,50) = (sd)? 5 : 0;
  934. if (!spawn) {
  935. WBUFB(buf,51) = vd->dead_sit;
  936. offset++;
  937. buf = WBUFP(buffer,offset);
  938. }
  939. WBUFW(buf,51) = clif_setlevel(bl);
  940. #if PACKETVER < 20091103
  941. if (type) //End for non-player packet
  942. return packet_len(WBUFW(buffer,0));
  943. #endif
  944. #if PACKETVER >= 20080102
  945. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  946. #endif
  947. #if PACKETVER >= 20091103
  948. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  949. return WBUFW(buffer,2);
  950. #else
  951. return packet_len(WBUFW(buffer,0));
  952. #endif
  953. }
  954. /*==========================================
  955. * Prepares 'unit walking' packet
  956. *------------------------------------------*/
  957. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  958. {
  959. struct map_session_data* sd;
  960. struct status_change* sc = status_get_sc(bl);
  961. struct view_data* vd = status_get_viewdata(bl);
  962. unsigned char* buf = WBUFP(buffer,0);
  963. #if PACKETVER >= 7
  964. unsigned short offset = 0;
  965. #endif
  966. #if PACKETVER >= 20091103
  967. const char *name;
  968. #endif
  969. sd = BL_CAST(BL_PC, bl);
  970. #if PACKETVER < 4
  971. WBUFW(buf, 0) = 0x7b;
  972. #elif PACKETVER < 7
  973. WBUFW(buf, 0) = 0x1da;
  974. #elif PACKETVER < 20080102
  975. WBUFW(buf, 0) = 0x22c;
  976. #elif PACKETVER < 20091103
  977. WBUFW(buf, 0) = 0x2ec;
  978. #elif PACKETVER < 20101124
  979. WBUFW(buf, 0) = 0x7f7;
  980. #else
  981. WBUFW(buf, 0) = 0x856;
  982. #endif
  983. #if PACKETVER >= 20091103
  984. name = status_get_name(bl);
  985. #if PACKETVER < 20110111
  986. WBUFW(buf, 2) = 69+strlen(name);
  987. #else
  988. WBUFW(buf, 2) = 71+strlen(name);
  989. #endif
  990. offset+=2;
  991. buf = WBUFP(buffer,offset);
  992. #endif
  993. #if PACKETVER >= 20071106
  994. WBUFB(buf, 2) = clif_bl_type(bl);
  995. offset++;
  996. buf = WBUFP(buffer,offset);
  997. #endif
  998. WBUFL(buf, 2) = bl->id;
  999. WBUFW(buf, 6) = status_get_speed(bl);
  1000. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1001. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1002. #if PACKETVER < 7
  1003. WBUFW(buf,12) = (sc)? sc->option : 0;
  1004. #else
  1005. WBUFL(buf,12) = (sc)? sc->option : 0;
  1006. offset+=2; //Shift the rest of elements by 2 bytes.
  1007. buf = WBUFP(buffer,offset);
  1008. #endif
  1009. WBUFW(buf,14) = vd->class_;
  1010. WBUFW(buf,16) = vd->hair_style;
  1011. WBUFW(buf,18) = vd->weapon;
  1012. #if PACKETVER < 4
  1013. WBUFW(buf,20) = vd->head_bottom;
  1014. WBUFL(buf,22) = gettick();
  1015. WBUFW(buf,26) = vd->shield;
  1016. #else
  1017. WBUFW(buf,20) = vd->shield;
  1018. WBUFW(buf,22) = vd->head_bottom;
  1019. WBUFL(buf,24) = gettick();
  1020. #endif
  1021. WBUFW(buf,28) = vd->head_top;
  1022. WBUFW(buf,30) = vd->head_mid;
  1023. WBUFW(buf,32) = vd->hair_color;
  1024. WBUFW(buf,34) = vd->cloth_color;
  1025. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1026. #if PACKETVER >= 20110111
  1027. WBUFW(buf,38) = vd->robe;
  1028. offset+= 2;
  1029. buf = WBUFP(buffer,offset);
  1030. #endif
  1031. WBUFL(buf,38) = status_get_guild_id(bl);
  1032. WBUFW(buf,42) = status_get_emblem_id(bl);
  1033. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1034. #if PACKETVER < 7
  1035. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1036. #else
  1037. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1038. offset+=2; //Shift the rest of elements by 2 bytes.
  1039. buf = WBUFP(buffer,offset);
  1040. #endif
  1041. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1042. WBUFB(buf,49) = vd->sex;
  1043. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1044. WBUFB(buf,56) = (sd)? 5 : 0;
  1045. WBUFB(buf,57) = (sd)? 5 : 0;
  1046. WBUFW(buf,58) = clif_setlevel(bl);
  1047. #if PACKETVER >= 20080102
  1048. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1049. #endif
  1050. #if PACKETVER >= 20091103
  1051. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1052. return WBUFW(buffer,2);
  1053. #else
  1054. return packet_len(WBUFW(buffer,0));
  1055. #endif
  1056. }
  1057. //Modifies the buffer for disguise characters and sends it to self.
  1058. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1059. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1060. {
  1061. #if PACKETVER >= 20091103
  1062. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1063. WBUFL(buf,5)=-bl->id;
  1064. #elif PACKETVER >= 20071106
  1065. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. WBUFL(buf,3)=-bl->id;
  1067. #else
  1068. WBUFL(buf,2)=-bl->id;
  1069. #endif
  1070. clif_send(buf, len, bl, SELF);
  1071. }
  1072. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1073. /// 01b0 <id>.L <type>.B <value>.L
  1074. /// type:
  1075. /// unused
  1076. void clif_class_change(struct block_list *bl,int class_,int type)
  1077. {
  1078. nullpo_retv(bl);
  1079. if(!pcdb_checkid(class_))
  1080. {// player classes yield missing sprites
  1081. unsigned char buf[16];
  1082. WBUFW(buf,0)=0x1b0;
  1083. WBUFL(buf,2)=bl->id;
  1084. WBUFB(buf,6)=type;
  1085. WBUFL(buf,7)=class_;
  1086. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1087. }
  1088. }
  1089. /// Notifies the client of an object's spirits.
  1090. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1091. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1092. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1093. {
  1094. WFIFOHEAD(fd, packet_len(0x1e1));
  1095. WFIFOW(fd,0)=0x1e1;
  1096. WFIFOL(fd,2)=sd->bl.id;
  1097. WFIFOW(fd,6)=sd->spiritball;
  1098. WFIFOSET(fd, packet_len(0x1e1));
  1099. }
  1100. /*==========================================
  1101. * Kagerou/Oboro amulet spirit
  1102. *------------------------------------------*/
  1103. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1104. {
  1105. WFIFOHEAD(fd, packet_len(0x08cf));
  1106. WFIFOW(fd,0)=0x08cf;
  1107. WFIFOL(fd,2)=sd->bl.id;
  1108. WFIFOW(fd,6)=type;
  1109. WFIFOW(fd,8)=sd->talisman[type];
  1110. WFIFOSET(fd, packet_len(0x08cf));
  1111. }
  1112. /*==========================================
  1113. * Run when player changes map / refreshes
  1114. * Tells its client to display all weather settings being used by this map
  1115. *------------------------------------------*/
  1116. static void clif_weather_check(struct map_session_data *sd)
  1117. {
  1118. int16 m = sd->bl.m;
  1119. int 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. || map[m].flag.clouds2)
  1127. {
  1128. if (map[m].flag.snow)
  1129. clif_specialeffect_single(&sd->bl, 162, fd);
  1130. if (map[m].flag.clouds)
  1131. clif_specialeffect_single(&sd->bl, 233, fd);
  1132. if (map[m].flag.clouds2)
  1133. clif_specialeffect_single(&sd->bl, 516, fd);
  1134. if (map[m].flag.fog)
  1135. clif_specialeffect_single(&sd->bl, 515, fd);
  1136. if (map[m].flag.fireworks) {
  1137. clif_specialeffect_single(&sd->bl, 297, fd);
  1138. clif_specialeffect_single(&sd->bl, 299, fd);
  1139. clif_specialeffect_single(&sd->bl, 301, fd);
  1140. }
  1141. if (map[m].flag.sakura)
  1142. clif_specialeffect_single(&sd->bl, 163, fd);
  1143. if (map[m].flag.leaves)
  1144. clif_specialeffect_single(&sd->bl, 333, fd);
  1145. }
  1146. }
  1147. /**
  1148. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1149. **/
  1150. void clif_weather(int16 m)
  1151. {
  1152. struct s_mapiterator* iter;
  1153. struct map_session_data *sd=NULL;
  1154. iter = mapit_getallusers();
  1155. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1156. {
  1157. if( sd->bl.m == m )
  1158. clif_weather_check(sd);
  1159. }
  1160. mapit_free(iter);
  1161. }
  1162. /**
  1163. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1164. **/
  1165. int clif_spawn(struct block_list *bl)
  1166. {
  1167. unsigned char buf[128];
  1168. struct view_data *vd;
  1169. struct status_change *sc = status_get_sc(bl);
  1170. int len;
  1171. vd = status_get_viewdata(bl);
  1172. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1173. return 0;
  1174. /**
  1175. * Hide NPC from maya purple card.
  1176. **/
  1177. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1178. return 0;
  1179. len = clif_set_unit_idle(bl, buf,true);
  1180. clif_send(buf, len, bl, AREA_WOS);
  1181. if (disguised(bl))
  1182. clif_setdisguise(bl, buf, len);
  1183. if (vd->cloth_color)
  1184. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1185. switch (bl->type)
  1186. {
  1187. case BL_PC:
  1188. {
  1189. TBL_PC *sd = ((TBL_PC*)bl);
  1190. int i;
  1191. if (sd->spiritball > 0)
  1192. clif_spiritball(&sd->bl);
  1193. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1194. clif_specialeffect(bl,423,AREA);
  1195. else if(sd->state.size==SZ_MEDIUM)
  1196. clif_specialeffect(bl,421,AREA);
  1197. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1198. clif_sendbgemblem_area(sd);
  1199. for(i = 1; i < 5; i++){
  1200. if( sd->talisman[i] > 0 )
  1201. clif_talisman(sd, i);
  1202. }
  1203. for (i = 0; i < sd->sc_display_count; i++) {
  1204. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1205. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1206. else
  1207. clif_status_change2(&sd->bl,sd->bl.id,AREA,StatusIconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3);
  1208. }
  1209. if (sd->status.robe)
  1210. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1211. }
  1212. break;
  1213. case BL_MOB:
  1214. {
  1215. TBL_MOB *md = ((TBL_MOB*)bl);
  1216. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1217. clif_specialeffect(&md->bl,423,AREA);
  1218. else if(md->special_state.size==SZ_MEDIUM)
  1219. clif_specialeffect(&md->bl,421,AREA);
  1220. }
  1221. break;
  1222. case BL_NPC:
  1223. {
  1224. TBL_NPC *nd = ((TBL_NPC*)bl);
  1225. if( nd->size == SZ_BIG )
  1226. clif_specialeffect(&nd->bl,423,AREA);
  1227. else if( nd->size == SZ_MEDIUM )
  1228. clif_specialeffect(&nd->bl,421,AREA);
  1229. }
  1230. break;
  1231. case BL_PET:
  1232. if (vd->head_bottom)
  1233. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1234. break;
  1235. }
  1236. return 0;
  1237. }
  1238. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1239. /// 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
  1240. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1241. {
  1242. struct status_data *status;
  1243. unsigned char buf[128];
  1244. int htype;
  1245. nullpo_retv(hd);
  1246. status = &hd->battle_status;
  1247. htype = hom_class2type(hd->homunculus.class_);
  1248. memset(buf,0,packet_len(0x22e));
  1249. WBUFW(buf,0)=0x22e;
  1250. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1251. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1252. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1253. WBUFW(buf,27)=hd->homunculus.level;
  1254. WBUFW(buf,29)=hd->homunculus.hunger;
  1255. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1256. WBUFW(buf,33)=0; // equip id
  1257. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1258. WBUFW(buf,37)=min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1259. WBUFW(buf,39)=status->hit;
  1260. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1261. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1262. else
  1263. WBUFW(buf,41)=status->cri/10;
  1264. WBUFW(buf,43)=status->def + status->vit ;
  1265. WBUFW(buf,45)=status->mdef;
  1266. WBUFW(buf,47)=status->flee;
  1267. WBUFW(buf,49)=(flag)?0:status->amotion;
  1268. if (status->max_hp > INT16_MAX) {
  1269. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1270. WBUFW(buf,53) = 100;
  1271. } else {
  1272. WBUFW(buf,51)=status->hp;
  1273. WBUFW(buf,53)=status->max_hp;
  1274. }
  1275. if (status->max_sp > INT16_MAX) {
  1276. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1277. WBUFW(buf,57) = 100;
  1278. } else {
  1279. WBUFW(buf,55)=status->sp;
  1280. WBUFW(buf,57)=status->max_sp;
  1281. }
  1282. WBUFL(buf,59)=hd->homunculus.exp;
  1283. WBUFL(buf,63)=hd->exp_next;
  1284. switch( htype ) {
  1285. case HT_REG:
  1286. case HT_EVO:
  1287. if( hd->homunculus.level >= battle_config.hom_max_level )
  1288. WBUFL(buf,63)=0;
  1289. break;
  1290. case HT_S:
  1291. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1292. WBUFL(buf,63)=0;
  1293. break;
  1294. }
  1295. WBUFW(buf,67)=hd->homunculus.skillpts;
  1296. WBUFW(buf,69)=status_get_range(&hd->bl);
  1297. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1298. }
  1299. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1300. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1301. /// type:
  1302. /// unused
  1303. /// state:
  1304. /// 0 = pre-init
  1305. /// 1 = intimacy
  1306. /// 2 = hunger
  1307. /// 3 = accessory?
  1308. /// ? = ignored
  1309. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1310. { //[orn]
  1311. int fd = sd->fd;
  1312. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1313. hom_calc_skilltree(sd->hd, 0);
  1314. WFIFOHEAD(fd, packet_len(0x230));
  1315. WFIFOW(fd,0)=0x230;
  1316. WFIFOB(fd,2)=0;
  1317. WFIFOB(fd,3)=state;
  1318. WFIFOL(fd,4)=sd->hd->bl.id;
  1319. WFIFOL(fd,8)=param;
  1320. WFIFOSET(fd,packet_len(0x230));
  1321. }
  1322. int clif_homskillinfoblock(struct map_session_data *sd)
  1323. { //[orn]
  1324. struct homun_data *hd;
  1325. int fd = sd->fd;
  1326. int i,j,len=4;
  1327. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1328. hd = sd->hd;
  1329. if ( !hd )
  1330. return 0 ;
  1331. WFIFOW(fd,0)=0x235;
  1332. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1333. int id = hd->homunculus.hskill[i].id;
  1334. if( id != 0 ){
  1335. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1336. j = id - HM_SKILLBASE;
  1337. WFIFOW(fd,len ) = id;
  1338. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1339. WFIFOW(fd,len+4) = 0;
  1340. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1341. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1342. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1343. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1344. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < hom_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1345. len+=37;
  1346. }
  1347. }
  1348. WFIFOW(fd,2)=len;
  1349. WFIFOSET(fd,len);
  1350. return 0;
  1351. }
  1352. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1353. { //[orn]
  1354. struct homun_data *hd;
  1355. int fd, idx;
  1356. nullpo_retv(sd);
  1357. idx = skill_id - HM_SKILLBASE;
  1358. fd=sd->fd;
  1359. hd=sd->hd;
  1360. WFIFOHEAD(fd, packet_len(0x239));
  1361. WFIFOW(fd,0) = 0x239;
  1362. WFIFOW(fd,2) = skill_id;
  1363. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1364. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1365. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1366. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1367. WFIFOSET(fd,packet_len(0x239));
  1368. }
  1369. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1370. {
  1371. int fd=sd->fd;
  1372. WFIFOHEAD(fd,packet_len(0x22f));
  1373. WFIFOW(fd,0)=0x22f;
  1374. WFIFOB(fd,2)=fail;
  1375. WFIFOW(fd,3)=foodid;
  1376. WFIFOSET(fd,packet_len(0x22f));
  1377. return 0;
  1378. }
  1379. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1380. /// 0087 <walk start time>.L <walk data>.6B
  1381. void clif_walkok(struct map_session_data *sd)
  1382. {
  1383. int fd=sd->fd;
  1384. WFIFOHEAD(fd, packet_len(0x87));
  1385. WFIFOW(fd,0)=0x87;
  1386. WFIFOL(fd,2)=gettick();
  1387. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1388. WFIFOSET(fd,packet_len(0x87));
  1389. }
  1390. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1391. {
  1392. uint8 buf[128];
  1393. int len;
  1394. struct status_change *sc = NULL;
  1395. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1396. clif_ally_only = true;
  1397. len = clif_set_unit_walking(bl,ud,buf);
  1398. clif_send(buf,len,bl,AREA_WOS);
  1399. if (disguised(bl))
  1400. clif_setdisguise(bl, buf, len);
  1401. if(vd->cloth_color)
  1402. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1403. switch(bl->type) {
  1404. case BL_PC:
  1405. {
  1406. TBL_PC *sd = ((TBL_PC*)bl);
  1407. // clif_movepc(sd);
  1408. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1409. clif_specialeffect(&sd->bl,423,AREA);
  1410. else if(sd->state.size==SZ_MEDIUM)
  1411. clif_specialeffect(&sd->bl,421,AREA);
  1412. }
  1413. break;
  1414. case BL_MOB:
  1415. {
  1416. TBL_MOB *md = ((TBL_MOB*)bl);
  1417. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1418. clif_specialeffect(&md->bl,423,AREA);
  1419. else if(md->special_state.size==SZ_MEDIUM)
  1420. clif_specialeffect(&md->bl,421,AREA);
  1421. }
  1422. break;
  1423. case BL_PET:
  1424. if(vd->head_bottom) // needed to display pet equip properly
  1425. clif_pet_equip_area((TBL_PET*)bl);
  1426. break;
  1427. }
  1428. clif_ally_only = false;
  1429. }
  1430. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1431. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1432. /// Note: unit must not be self
  1433. void clif_move(struct unit_data *ud)
  1434. {
  1435. unsigned char buf[16];
  1436. struct view_data* vd;
  1437. struct block_list* bl = ud->bl;
  1438. struct status_change *sc = NULL;
  1439. vd = status_get_viewdata(bl);
  1440. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1441. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1442. /**
  1443. * Hide NPC from maya purple card.
  1444. **/
  1445. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1446. return;
  1447. if (ud->state.speed_changed) {
  1448. // Since we don't know how to update the speed of other objects,
  1449. // use the old walk packet to update the data.
  1450. ud->state.speed_changed = 0;
  1451. clif_move2(bl, vd, ud);
  1452. return;
  1453. }
  1454. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1455. clif_ally_only = true;
  1456. WBUFW(buf,0)=0x86;
  1457. WBUFL(buf,2)=bl->id;
  1458. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1459. WBUFL(buf,12)=gettick();
  1460. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1461. if (disguised(bl)) {
  1462. WBUFL(buf,2)=-bl->id;
  1463. clif_send(buf, packet_len(0x86), bl, SELF);
  1464. }
  1465. clif_ally_only = false;
  1466. }
  1467. /*==========================================
  1468. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1469. *------------------------------------------*/
  1470. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1471. {
  1472. struct map_session_data *sd = NULL;
  1473. //Remove player from map server
  1474. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1475. map_quit(sd);
  1476. return 0;
  1477. }
  1478. /*==========================================
  1479. *
  1480. *------------------------------------------*/
  1481. void clif_quitsave(int fd,struct map_session_data *sd) {
  1482. if (!battle_config.prevent_logout ||
  1483. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1484. map_quit(sd);
  1485. else if (sd->fd) {
  1486. //Disassociate session from player (session is deleted after this function was called)
  1487. //And set a timer to make him quit later.
  1488. session[sd->fd]->session_data = NULL;
  1489. sd->fd = 0;
  1490. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1491. }
  1492. }
  1493. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1494. /// 0091 <map name>.16B <x>.W <y>.W
  1495. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1496. {
  1497. int fd;
  1498. nullpo_retv(sd);
  1499. fd = sd->fd;
  1500. WFIFOHEAD(fd,packet_len(0x91));
  1501. WFIFOW(fd,0) = 0x91;
  1502. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1503. WFIFOW(fd,18) = x;
  1504. WFIFOW(fd,20) = y;
  1505. WFIFOSET(fd,packet_len(0x91));
  1506. }
  1507. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1508. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1509. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1510. {
  1511. int fd;
  1512. nullpo_retv(sd);
  1513. fd = sd->fd;
  1514. WFIFOHEAD(fd,packet_len(0x92));
  1515. WFIFOW(fd,0) = 0x92;
  1516. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1517. WFIFOW(fd,18) = x;
  1518. WFIFOW(fd,20) = y;
  1519. WFIFOL(fd,22) = htonl(ip);
  1520. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1521. WFIFOSET(fd,packet_len(0x92));
  1522. }
  1523. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1524. /// This function combines both calls and allows to simplify the calling code
  1525. void clif_blown(struct block_list *bl)
  1526. {
  1527. clif_slide(bl, bl->x, bl->y);
  1528. clif_fixpos(bl);
  1529. }
  1530. /// Visually moves(slides) a character to x,y. If the target cell
  1531. /// isn't walkable, the char doesn't move at all. If the char is
  1532. /// sitting it will stand up (ZC_STOPMOVE).
  1533. /// 0088 <id>.L <x>.W <y>.W
  1534. void clif_fixpos(struct block_list *bl)
  1535. {
  1536. unsigned char buf[10];
  1537. nullpo_retv(bl);
  1538. WBUFW(buf,0) = 0x88;
  1539. WBUFL(buf,2) = bl->id;
  1540. WBUFW(buf,6) = bl->x;
  1541. WBUFW(buf,8) = bl->y;
  1542. clif_send(buf, packet_len(0x88), bl, AREA);
  1543. if( disguised(bl) ) {
  1544. WBUFL(buf,2) = -bl->id;
  1545. clif_send(buf, packet_len(0x88), bl, SELF);
  1546. }
  1547. }
  1548. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1549. /// 00c4 <shop id>.L
  1550. void clif_npcbuysell(struct map_session_data* sd, int id)
  1551. {
  1552. int fd;
  1553. nullpo_retv(sd);
  1554. fd=sd->fd;
  1555. WFIFOHEAD(fd, packet_len(0xc4));
  1556. WFIFOW(fd,0)=0xc4;
  1557. WFIFOL(fd,2)=id;
  1558. WFIFOSET(fd,packet_len(0xc4));
  1559. }
  1560. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1561. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1562. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1563. {
  1564. int fd,i,c;
  1565. bool discount;
  1566. nullpo_retv(sd);
  1567. nullpo_retv(nd);
  1568. fd = sd->fd;
  1569. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1570. WFIFOW(fd,0) = 0xc6;
  1571. c = 0;
  1572. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1573. for( i = 0; i < nd->u.shop.count; i++ )
  1574. {
  1575. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1576. int val = nd->u.shop.shop_item[i].value;
  1577. if( id == NULL )
  1578. continue;
  1579. WFIFOL(fd, 4+c*11) = val;
  1580. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1581. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1582. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1583. c++;
  1584. }
  1585. WFIFOW(fd,2) = 4 + c*11;
  1586. WFIFOSET(fd,WFIFOW(fd,2));
  1587. }
  1588. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1589. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1590. void clif_selllist(struct map_session_data *sd)
  1591. {
  1592. int fd,i,c=0,val;
  1593. nullpo_retv(sd);
  1594. fd=sd->fd;
  1595. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1596. WFIFOW(fd,0)=0xc7;
  1597. for( i = 0; i < MAX_INVENTORY; i++ )
  1598. {
  1599. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1600. {
  1601. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1602. continue;
  1603. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1604. continue; // Cannot Sell Rental Items or Account Bounded Items
  1605. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1606. continue; // Don't allow sale of bound items
  1607. val=sd->inventory_data[i]->value_sell;
  1608. if( val < 0 )
  1609. continue;
  1610. WFIFOW(fd,4+c*10)=i+2;
  1611. WFIFOL(fd,6+c*10)=val;
  1612. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1613. c++;
  1614. }
  1615. }
  1616. WFIFOW(fd,2)=c*10+4;
  1617. WFIFOSET(fd,WFIFOW(fd,2));
  1618. }
  1619. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1620. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1621. /// Client behavior (dialog window):
  1622. /// - disable mouse targeting
  1623. /// - open the dialog window
  1624. /// - set npcid of dialog window (0 by default)
  1625. /// - if set to clear on next mes, clear contents
  1626. /// - append this text
  1627. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1628. {
  1629. int fd = sd->fd;
  1630. int slen = strlen(mes) + 9;
  1631. WFIFOHEAD(fd, slen);
  1632. WFIFOW(fd,0)=0xb4;
  1633. WFIFOW(fd,2)=slen;
  1634. WFIFOL(fd,4)=npcid;
  1635. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1636. WFIFOSET(fd,WFIFOW(fd,2));
  1637. }
  1638. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1639. /// 00b5 <npc id>.L
  1640. /// Client behavior (dialog window):
  1641. /// - disable mouse targeting
  1642. /// - open the dialog window
  1643. /// - add 'next' button
  1644. /// When 'next' is pressed:
  1645. /// - 00B9 <npcid of dialog window>.L
  1646. /// - set to clear on next mes
  1647. /// - remove 'next' button
  1648. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1649. {
  1650. int fd;
  1651. nullpo_retv(sd);
  1652. fd=sd->fd;
  1653. WFIFOHEAD(fd, packet_len(0xb5));
  1654. WFIFOW(fd,0)=0xb5;
  1655. WFIFOL(fd,2)=npcid;
  1656. WFIFOSET(fd,packet_len(0xb5));
  1657. }
  1658. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1659. /// 00b6 <npc id>.L
  1660. /// Client behavior:
  1661. /// - if dialog window is open:
  1662. /// - remove 'next' button
  1663. /// - add 'close' button
  1664. /// - else:
  1665. /// - enable mouse targeting
  1666. /// - close the dialog window
  1667. /// - close the menu window
  1668. /// When 'close' is pressed:
  1669. /// - enable mouse targeting
  1670. /// - close the dialog window
  1671. /// - close the menu window
  1672. /// - 0146 <npcid of dialog window>.L
  1673. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1674. {
  1675. int fd;
  1676. nullpo_retv(sd);
  1677. fd=sd->fd;
  1678. WFIFOHEAD(fd, packet_len(0xb6));
  1679. WFIFOW(fd,0)=0xb6;
  1680. WFIFOL(fd,2)=npcid;
  1681. WFIFOSET(fd,packet_len(0xb6));
  1682. }
  1683. /**
  1684. * Close script when player is idle
  1685. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1686. * @author [Ind/Hercules]
  1687. * @param sd : player pointer
  1688. * @param npcid : npc gid to close
  1689. */
  1690. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1691. {
  1692. struct s_packet_db* info;
  1693. int16 len;
  1694. int cmd = 0;
  1695. int fd;
  1696. nullpo_retv(sd);
  1697. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1698. if(!cmd) cmd = 0x8d6; //default
  1699. info = &packet_db[sd->packet_ver][cmd];
  1700. len = info->len;
  1701. fd = sd->fd;
  1702. WFIFOHEAD(fd, len);
  1703. WFIFOW(fd,0)=0x8d6;
  1704. WFIFOL(fd,info->pos[0])=npcid;
  1705. WFIFOSET(fd,len);
  1706. }
  1707. /*==========================================
  1708. *
  1709. *------------------------------------------*/
  1710. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1711. unsigned char *buf;
  1712. int fd = sd->fd;
  1713. sd->state.using_fake_npc = 1;
  1714. WFIFOHEAD(fd, packet_len(0x78));
  1715. buf = WFIFOP(fd,0);
  1716. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1717. WBUFW(buf,0)=0x78;
  1718. #if PACKETVER >= 20071106
  1719. WBUFB(buf,2) = 0; // object type
  1720. buf = WFIFOP(fd,1);
  1721. #endif
  1722. WBUFL(buf,2)=npcid;
  1723. WBUFW(buf,14)=111;
  1724. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1725. WBUFB(buf,49)=5;
  1726. WBUFB(buf,50)=5;
  1727. WFIFOSET(fd, packet_len(0x78));
  1728. }
  1729. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1730. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1731. /// Client behavior:
  1732. /// - disable mouse targeting
  1733. /// - close the menu window
  1734. /// - open the menu window
  1735. /// - add options to the menu (separated in the text by ":")
  1736. /// - set npcid of menu window
  1737. /// - if dialog window is open:
  1738. /// - remove 'next' button
  1739. /// When 'ok' is pressed:
  1740. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1741. /// - close the menu window
  1742. /// When 'cancel' is pressed:
  1743. /// - 00B8 <npcid of menu window>.L <-1>.B
  1744. /// - enable mouse targeting
  1745. /// - close a bunch of windows...
  1746. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1747. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1748. /// TODO investigate behavior of other windows [FlavioJS]
  1749. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1750. {
  1751. int fd = sd->fd;
  1752. int slen = strlen(mes) + 9;
  1753. struct block_list *bl = NULL;
  1754. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1755. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1756. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1757. clif_sendfakenpc(sd, npcid);
  1758. WFIFOHEAD(fd, slen);
  1759. WFIFOW(fd,0)=0xb7;
  1760. WFIFOW(fd,2)=slen;
  1761. WFIFOL(fd,4)=npcid;
  1762. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1763. WFIFOSET(fd,WFIFOW(fd,2));
  1764. }
  1765. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1766. /// 0142 <npc id>.L
  1767. /// Client behavior (inputnum window):
  1768. /// - if npcid exists in the client:
  1769. /// - open the inputnum window
  1770. /// - set npcid of inputnum window
  1771. /// When 'ok' is pressed:
  1772. /// - if inputnum window has text:
  1773. /// - if npcid exists in the client:
  1774. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1775. /// - close inputnum window
  1776. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1777. {
  1778. int fd;
  1779. struct block_list *bl = NULL;
  1780. nullpo_retv(sd);
  1781. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1782. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1783. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1784. clif_sendfakenpc(sd, npcid);
  1785. fd=sd->fd;
  1786. WFIFOHEAD(fd, packet_len(0x142));
  1787. WFIFOW(fd,0)=0x142;
  1788. WFIFOL(fd,2)=npcid;
  1789. WFIFOSET(fd,packet_len(0x142));
  1790. }
  1791. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1792. /// 01d4 <npc id>.L
  1793. /// Client behavior (inputstr window):
  1794. /// - if npcid is 0 or npcid exists in the client:
  1795. /// - open the inputstr window
  1796. /// - set npcid of inputstr window
  1797. /// When 'ok' is pressed:
  1798. /// - if inputstr window has text and isn't an insult(manner.txt):
  1799. /// - if npcid is 0 or npcid exists in the client:
  1800. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1801. /// - close inputstr window
  1802. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1803. {
  1804. int fd;
  1805. struct block_list *bl = NULL;
  1806. nullpo_retv(sd);
  1807. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1808. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1809. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1810. clif_sendfakenpc(sd, npcid);
  1811. fd=sd->fd;
  1812. WFIFOHEAD(fd, packet_len(0x1d4));
  1813. WFIFOW(fd,0)=0x1d4;
  1814. WFIFOL(fd,2)=npcid;
  1815. WFIFOSET(fd,packet_len(0x1d4));
  1816. }
  1817. /// Marks a position on client's minimap (ZC_COMPASS).
  1818. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1819. /// npc id:
  1820. /// is ignored in the client
  1821. /// type:
  1822. /// 0 = display mark for 15 seconds
  1823. /// 1 = display mark until dead or teleported
  1824. /// 2 = remove mark
  1825. /// color:
  1826. /// 0x00RRGGBB
  1827. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1828. {
  1829. int fd;
  1830. nullpo_retv(sd);
  1831. fd=sd->fd;
  1832. WFIFOHEAD(fd, packet_len(0x144));
  1833. WFIFOW(fd,0)=0x144;
  1834. WFIFOL(fd,2)=npc_id;
  1835. WFIFOL(fd,6)=type;
  1836. WFIFOL(fd,10)=x;
  1837. WFIFOL(fd,14)=y;
  1838. WFIFOB(fd,18)=id;
  1839. WFIFOL(fd,19)=color;
  1840. WFIFOSET(fd,packet_len(0x144));
  1841. }
  1842. /// Displays an illustration image.
  1843. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1844. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1845. /// type:
  1846. /// 0 = bottom left corner
  1847. /// 1 = bottom middle
  1848. /// 2 = bottom right corner
  1849. /// 3 = middle of screen, inside a movable window
  1850. /// 4 = middle of screen, movable with a close button, chrome-less
  1851. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1852. {
  1853. int fd;
  1854. nullpo_retv(sd);
  1855. fd=sd->fd;
  1856. WFIFOHEAD(fd, packet_len(0x1b3));
  1857. WFIFOW(fd,0)=0x1b3;
  1858. strncpy((char*)WFIFOP(fd,2),image,64);
  1859. WFIFOB(fd,66)=type;
  1860. WFIFOSET(fd,packet_len(0x1b3));
  1861. }
  1862. /*==========================================
  1863. * Fills in card data from the given item and into the buffer. [Skotlex]
  1864. *------------------------------------------*/
  1865. static void clif_addcards(unsigned char* buf, struct item* item)
  1866. {
  1867. int i=0,j;
  1868. if( item == NULL ) { //Blank data
  1869. WBUFW(buf,0) = 0;
  1870. WBUFW(buf,2) = 0;
  1871. WBUFW(buf,4) = 0;
  1872. WBUFW(buf,6) = 0;
  1873. return;
  1874. }
  1875. if( item->card[0] == CARD0_PET ) { //pet eggs
  1876. WBUFW(buf,0) = 0;
  1877. WBUFW(buf,2) = 0;
  1878. WBUFW(buf,4) = 0;
  1879. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1880. return;
  1881. }
  1882. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1883. WBUFW(buf,0) = item->card[0];
  1884. WBUFW(buf,2) = item->card[1];
  1885. WBUFW(buf,4) = item->card[2];
  1886. WBUFW(buf,6) = item->card[3];
  1887. return;
  1888. }
  1889. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1890. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1891. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1892. //Normal items.
  1893. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1894. WBUFW(buf,0) = j;
  1895. else
  1896. WBUFW(buf,0) = item->card[i];
  1897. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1898. WBUFW(buf,2) = j;
  1899. else
  1900. WBUFW(buf,2) = item->card[i];
  1901. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1902. WBUFW(buf,4) = j;
  1903. else
  1904. WBUFW(buf,4) = item->card[i];
  1905. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1906. WBUFW(buf,6) = j;
  1907. else
  1908. WBUFW(buf,6) = item->card[i];
  1909. }
  1910. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1911. /// 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)
  1912. /// 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)
  1913. /// 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)
  1914. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  1915. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  1916. {
  1917. int fd, header, offs=0;
  1918. #if PACKETVER < 20061218
  1919. header = 0xa0;
  1920. #elif PACKETVER < 20071002
  1921. header = 0x29a;
  1922. #elif PACKETVER < 20120925
  1923. header = 0x2d4;
  1924. #else
  1925. header = 0x990;
  1926. #endif
  1927. nullpo_retv(sd);
  1928. fd = sd->fd;
  1929. if( !session_isActive(fd) ) //Sasuke-
  1930. return;
  1931. WFIFOHEAD(fd,packet_len(header));
  1932. if( fail )
  1933. {
  1934. WFIFOW(fd,offs+0) = header;
  1935. WFIFOW(fd,offs+2) = n+2;
  1936. WFIFOW(fd,offs+4) = amount;
  1937. WFIFOW(fd,offs+6) = 0;
  1938. WFIFOB(fd,offs+8) = 0;
  1939. WFIFOB(fd,offs+9) = 0;
  1940. WFIFOB(fd,offs+10) = 0;
  1941. WFIFOW(fd,offs+11) = 0;
  1942. WFIFOW(fd,offs+13) = 0;
  1943. WFIFOW(fd,offs+15) = 0;
  1944. WFIFOW(fd,offs+17) = 0;
  1945. #if PACKETVER < 20120925
  1946. WFIFOW(fd,offs+19) = 0;
  1947. #else
  1948. WFIFOL(fd,offs+19) = 0;
  1949. offs += 2;
  1950. #endif
  1951. WFIFOB(fd,offs+21) = 0;
  1952. WFIFOB(fd,offs+22) = fail;
  1953. #if PACKETVER >= 20061218
  1954. WFIFOL(fd,offs+23) = 0;
  1955. #endif
  1956. #if PACKETVER >= 20071002
  1957. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  1958. #endif
  1959. }
  1960. else
  1961. {
  1962. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1963. return;
  1964. WFIFOW(fd,offs+0) = header;
  1965. WFIFOW(fd,offs+2) = n+2;
  1966. WFIFOW(fd,offs+4) = amount;
  1967. if (sd->inventory_data[n]->view_id > 0)
  1968. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  1969. else
  1970. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  1971. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  1972. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  1973. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  1974. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  1975. #if PACKETVER < 20120925
  1976. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  1977. #else
  1978. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  1979. offs += 2;
  1980. #endif
  1981. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  1982. WFIFOB(fd,offs+22) = fail;
  1983. #if PACKETVER >= 20061218
  1984. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  1985. #endif
  1986. #if PACKETVER >= 20071002
  1987. /* Yellow color only for non-stackable item */
  1988. WFIFOW(fd,offs+27) = (sd->status.inventory[n].bound && !itemdb_isstackable(sd->status.inventory[n].nameid)) ? BOUND_DISPYELLOW : sd->inventory_data[n]->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  1989. #endif
  1990. }
  1991. WFIFOSET(fd,packet_len(header));
  1992. }
  1993. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1994. /// 00af <index>.W <amount>.W
  1995. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1996. {
  1997. int fd;
  1998. nullpo_retv(sd);
  1999. fd=sd->fd;
  2000. WFIFOHEAD(fd, packet_len(0xaf));
  2001. WFIFOW(fd,0)=0xaf;
  2002. WFIFOW(fd,2)=n+2;
  2003. WFIFOW(fd,4)=amount;
  2004. WFIFOSET(fd,packet_len(0xaf));
  2005. }
  2006. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2007. /// 07fa <delete type>.W <index>.W <amount>.W
  2008. /// delete type:
  2009. /// 0 = Normal
  2010. /// 1 = Item used for a skill
  2011. /// 2 = Refine failed
  2012. /// 3 = Material changed
  2013. /// 4 = Moved to storage
  2014. /// 5 = Moved to cart
  2015. /// 6 = Item sold
  2016. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2017. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2018. {
  2019. #if PACKETVER < 20091117
  2020. clif_dropitem(sd,n,amount);
  2021. #else
  2022. int fd;
  2023. nullpo_retv(sd);
  2024. fd=sd->fd;
  2025. WFIFOHEAD(fd, packet_len(0x7fa));
  2026. WFIFOW(fd,0)=0x7fa;
  2027. WFIFOW(fd,2)=reason;
  2028. WFIFOW(fd,4)=n+2;
  2029. WFIFOW(fd,6)=amount;
  2030. WFIFOSET(fd,packet_len(0x7fa));
  2031. #endif
  2032. }
  2033. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2034. char normal = (equip < 0);
  2035. WBUFW(buf,n) = idx; //index
  2036. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2037. WBUFB(buf,n+4) = itemtype(id->nameid);
  2038. if (!normal){ //equip 31B
  2039. WBUFL(buf,n+5) = equip; //location
  2040. WBUFL(buf,n+9) = it->equip; //wear state
  2041. WBUFB(buf,n+13) = it->refine; //refine lvl
  2042. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2043. WBUFL(buf,n+22) = it->expire_time;
  2044. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2045. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2046. //V5_ITEM_flag
  2047. WBUFB(buf,n+30) = it->identify; //0x1 IsIdentified
  2048. WBUFB(buf,n+30) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2049. WBUFB(buf,n+30) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2050. }
  2051. else { //normal 24B
  2052. WBUFW(buf,n+5) = it->amount;
  2053. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2054. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2055. WBUFL(buf,n+19) = it->expire_time;
  2056. //V5_ITEM_flag
  2057. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2058. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2059. }
  2060. }
  2061. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2062. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2063. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2064. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2065. #if PACKETVER >= 20120925
  2066. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2067. #else
  2068. WBUFW(buf,n) = idx; //index
  2069. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2070. WBUFB(buf,n+4) = itemtype(id->nameid);
  2071. WBUFB(buf,n+5) = it->identify;
  2072. if (equip >= 0) { //Equippable item 28.B
  2073. WBUFW(buf,n+6) = equip;
  2074. WBUFW(buf,n+8) = it->equip;
  2075. WBUFB(buf,n+10) = it->attribute;
  2076. WBUFB(buf,n+11) = it->refine;
  2077. clif_addcards(WBUFP(buf, n+12), it); //8B
  2078. #if PACKETVER >= 20071002
  2079. WBUFL(buf,n+20) = it->expire_time;
  2080. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2081. #endif
  2082. #if PACKETVER >= 20100629
  2083. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2084. #endif
  2085. } else { //Stackable item. 22.B
  2086. WBUFW(buf,n+6) = it->amount;
  2087. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2088. clif_addcards(WBUFP(buf, n+10), it); //8B
  2089. #if PACKETVER >= 20071002
  2090. WBUFL(buf,n+18) = it->expire_time;
  2091. #endif
  2092. }
  2093. #endif
  2094. }
  2095. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2096. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2097. void clif_inventorylist(struct map_session_data *sd) {
  2098. int i,n,ne,arrow=-1;
  2099. unsigned char *buf;
  2100. unsigned char *bufe;
  2101. #if PACKETVER < 5
  2102. const int s = 10; //Entry size
  2103. #elif PACKETVER < 20080102
  2104. const int s = 18;
  2105. #elif PACKETVER < 20120925
  2106. const int s = 22;
  2107. #else
  2108. const int s = 24;
  2109. #endif
  2110. #if PACKETVER < 20071002
  2111. const int se = 20;
  2112. #elif PACKETVER < 20100629
  2113. const int se = 26;
  2114. #elif PACKETVER < 20120925
  2115. const int se = 28;
  2116. #else
  2117. const int se = 31;
  2118. #endif
  2119. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2120. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2121. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2122. {
  2123. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2124. continue;
  2125. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2126. { //Non-stackable (Equippable)
  2127. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2128. ne++;
  2129. }
  2130. else { //Stackable.
  2131. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2132. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2133. arrow=i;
  2134. n++;
  2135. }
  2136. }
  2137. if( n )
  2138. {
  2139. #if PACKETVER < 5
  2140. WBUFW(buf,0)=0xa3;
  2141. #elif PACKETVER < 20080102
  2142. WBUFW(buf,0)=0x1ee;
  2143. #elif PACKETVER < 20120925
  2144. WBUFW(buf,0)=0x2e8;
  2145. #else
  2146. WBUFW(buf,0)=0x991;
  2147. #endif
  2148. WBUFW(buf,2)=4+n*s;
  2149. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2150. }
  2151. if( arrow >= 0 )
  2152. clif_arrowequip(sd,arrow);
  2153. if( ne ) {
  2154. #if PACKETVER < 20071002
  2155. WBUFW(bufe,0)=0xa4;
  2156. #elif PACKETVER < 20120925
  2157. WBUFW(bufe,0)=0x2d0;
  2158. #else
  2159. WBUFW(bufe,0)=0x992;
  2160. #endif
  2161. WBUFW(bufe,2)=4+ne*se;
  2162. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2163. }
  2164. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2165. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2166. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2167. continue;
  2168. if ( sd->status.inventory[i].favorite )
  2169. clif_favorite_item(sd, i);
  2170. }
  2171. #endif
  2172. if( buf ) aFree(buf);
  2173. if( bufe ) aFree(bufe);
  2174. }
  2175. //Required when items break/get-repaired. Only sends equippable item list.
  2176. void clif_equiplist(struct map_session_data *sd)
  2177. {
  2178. int i,n,fd = sd->fd;
  2179. unsigned char *buf;
  2180. #if PACKETVER < 20071002
  2181. const int cmd = 20;
  2182. #elif PACKETVER < 20100629
  2183. const int cmd = 26;
  2184. #elif PACKETVER < 20120925
  2185. const int cmd = 28;
  2186. #else
  2187. const int cmd = 31;
  2188. #endif
  2189. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2190. buf = WFIFOP(fd,0);
  2191. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2192. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2193. continue;
  2194. if(itemdb_isstackable2(sd->inventory_data[i]))
  2195. continue;
  2196. //Equippable
  2197. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2198. n++;
  2199. }
  2200. if (n) {
  2201. #if PACKETVER < 20071002
  2202. WBUFW(buf,0)=0xa4;
  2203. #elif PACKETVER < 20120925
  2204. WBUFW(buf,0)=0x2d0;
  2205. #else
  2206. WBUFW(buf,0)=0x992;
  2207. #endif
  2208. WBUFW(buf,2)=4+n*cmd;
  2209. WFIFOSET(fd,WFIFOW(fd,2));
  2210. }
  2211. }
  2212. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2213. {
  2214. static const int client_buf = 0x5000; // Max buffer to send
  2215. struct item_data *id;
  2216. int i,n,ne,nn;
  2217. unsigned char *buf;
  2218. unsigned char *bufe;
  2219. #if PACKETVER < 5
  2220. const int s = 10; //Entry size.normal item
  2221. const int sidx=4; //start itemlist idx
  2222. const int cmd = 0xa5;
  2223. #elif PACKETVER < 20080102
  2224. const int s = 18;
  2225. const int sidx=4;
  2226. const int cmd = 0x1f0;
  2227. #elif PACKETVER < 20120925
  2228. const int s = 22;
  2229. const int sidx=4;
  2230. const int cmd = 0x2ea;
  2231. #else
  2232. const int s = 24;
  2233. const int sidx = 4+24;
  2234. const int cmd = 0x995;
  2235. #endif
  2236. #if PACKETVER < 20071002
  2237. const int se = 20; //entry size equip
  2238. const int sidxe = 4; //start itemlist idx
  2239. const int cmde = 0xa6;
  2240. #elif PACKETVER < 20100629
  2241. const int se = 26;
  2242. const int sidxe = 4;
  2243. const int cmde = 0x2d1;
  2244. #elif PACKETVER < 20120925
  2245. const int se = 28;
  2246. const int sidxe = 4;
  2247. const int cmde = 0x2d1;
  2248. #else
  2249. const int se = 31;
  2250. const int sidxe = 4+24;
  2251. const int cmde = 0x996;
  2252. #endif
  2253. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2254. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2255. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2256. {
  2257. if( items[i].nameid <= 0 )
  2258. continue;
  2259. id = itemdb_search(items[i].nameid);
  2260. if( !itemdb_isstackable2(id) ) { //Equippable
  2261. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2262. ne++;
  2263. }
  2264. else { //Stackable
  2265. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2266. n++;
  2267. }
  2268. }
  2269. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2270. {
  2271. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2272. WFIFOHEAD(sd->fd,sidx+nn*s);
  2273. WFIFOW(sd->fd,0)=cmd;
  2274. WFIFOW(sd->fd,2)=sidx+nn*s;
  2275. #if PACKETVER >= 20120925
  2276. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2277. #endif
  2278. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2279. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2280. }
  2281. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2282. {
  2283. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2284. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2285. WFIFOW(sd->fd,0)=cmde;
  2286. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2287. #if PACKETVER >= 20120925
  2288. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2289. #endif
  2290. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2291. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2292. }
  2293. if( buf ) aFree(buf);
  2294. if( bufe ) aFree(bufe);
  2295. }
  2296. void clif_cartlist(struct map_session_data *sd)
  2297. {
  2298. struct item_data *id;
  2299. int i,n,ne;
  2300. unsigned char *buf;
  2301. unsigned char *bufe;
  2302. #if PACKETVER < 5
  2303. const int s = 10; //Entry size.
  2304. #elif PACKETVER < 20080102
  2305. const int s = 18;
  2306. #elif PACKETVER < 20120925
  2307. const int s = 22;
  2308. #else
  2309. const int s = 24;
  2310. #endif
  2311. #if PACKETVER < 20071002
  2312. const int cmd = 20;
  2313. #elif PACKETVER < 20100629
  2314. const int cmd = 26;
  2315. #elif PACKETVER < 20120925
  2316. const int cmd = 28;
  2317. #else
  2318. const int cmd = 31;
  2319. #endif
  2320. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2321. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2322. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2323. {
  2324. if( sd->status.cart[i].nameid <= 0 )
  2325. continue;
  2326. id = itemdb_search(sd->status.cart[i].nameid);
  2327. if( !itemdb_isstackable2(id) ) { //Equippable
  2328. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2329. ne++;
  2330. }
  2331. else { //Stackable
  2332. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2333. n++;
  2334. }
  2335. }
  2336. if( n )
  2337. {
  2338. #if PACKETVER < 5
  2339. WBUFW(buf,0)=0x123;
  2340. #elif PACKETVER < 20080102
  2341. WBUFW(buf,0)=0x1ef;
  2342. #elif PACKETVER < 20120925
  2343. WBUFW(buf,0)=0x2e9;
  2344. #else
  2345. WBUFW(buf,0)=0x993;
  2346. #endif
  2347. WBUFW(buf,2)=4+n*s;
  2348. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2349. }
  2350. if( ne )
  2351. {
  2352. #if PACKETVER < 20071002
  2353. WBUFW(bufe,0)=0x122;
  2354. #elif PACKETVER < 20120925
  2355. WBUFW(bufe,0)=0x2d2;
  2356. #else
  2357. WBUFW(bufe,0)=0x994;
  2358. #endif
  2359. WBUFW(bufe,2)=4+ne*cmd;
  2360. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2361. }
  2362. if( buf ) aFree(buf);
  2363. if( bufe ) aFree(bufe);
  2364. }
  2365. /// Removes cart (ZC_CARTOFF).
  2366. /// 012b
  2367. /// Client behaviour:
  2368. /// Closes the cart storage and removes all it's items from memory.
  2369. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2370. void clif_clearcart(int fd)
  2371. {
  2372. WFIFOHEAD(fd, packet_len(0x12b));
  2373. WFIFOW(fd,0) = 0x12b;
  2374. WFIFOSET(fd, packet_len(0x12b));
  2375. }
  2376. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2377. /// 01eb <account id>.L <x>.W <y>.W
  2378. void clif_guild_xy(struct map_session_data *sd)
  2379. {
  2380. unsigned char buf[10];
  2381. nullpo_retv(sd);
  2382. WBUFW(buf,0)=0x1eb;
  2383. WBUFL(buf,2)=sd->status.account_id;
  2384. WBUFW(buf,6)=sd->bl.x;
  2385. WBUFW(buf,8)=sd->bl.y;
  2386. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2387. }
  2388. /*==========================================
  2389. * Sends x/y dot to a single fd. [Skotlex]
  2390. *------------------------------------------*/
  2391. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2392. {
  2393. if( sd->bg_id )
  2394. return;
  2395. WFIFOHEAD(fd,packet_len(0x1eb));
  2396. WFIFOW(fd,0)=0x1eb;
  2397. WFIFOL(fd,2)=sd->status.account_id;
  2398. WFIFOW(fd,6)=sd->bl.x;
  2399. WFIFOW(fd,8)=sd->bl.y;
  2400. WFIFOSET(fd,packet_len(0x1eb));
  2401. }
  2402. // Guild XY locators [Valaris]
  2403. void clif_guild_xy_remove(struct map_session_data *sd)
  2404. {
  2405. unsigned char buf[10];
  2406. nullpo_retv(sd);
  2407. WBUFW(buf,0)=0x1eb;
  2408. WBUFL(buf,2)=sd->status.account_id;
  2409. WBUFW(buf,6)=-1;
  2410. WBUFW(buf,8)=-1;
  2411. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2412. }
  2413. /*==========================================
  2414. *
  2415. *------------------------------------------*/
  2416. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2417. {
  2418. struct map_session_data *sd, *tsd;
  2419. #if PACKETVER < 20100126
  2420. const int cmd = 0x106;
  2421. #else
  2422. const int cmd = 0x80e;
  2423. #endif
  2424. sd = va_arg(ap, struct map_session_data *);
  2425. tsd = (TBL_PC *)bl;
  2426. nullpo_ret(sd);
  2427. nullpo_ret(tsd);
  2428. if( !tsd->fd || tsd == sd )
  2429. return 0;
  2430. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2431. return 0;
  2432. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2433. WFIFOW(tsd->fd,0) = cmd;
  2434. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2435. #if PACKETVER < 20100126
  2436. if( sd->battle_status.max_hp > INT16_MAX )
  2437. { //To correctly display the %hp bar. [Skotlex]
  2438. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2439. WFIFOW(tsd->fd,8) = 100;
  2440. } else {
  2441. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2442. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2443. }
  2444. #else
  2445. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2446. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2447. #endif
  2448. WFIFOSET(tsd->fd,packet_len(cmd));
  2449. return 0;
  2450. }
  2451. /*==========================================
  2452. * Server tells all players that are allowed to view HP bars
  2453. * and are nearby 'sd' that 'sd' hp bar was updated.
  2454. *------------------------------------------*/
  2455. static int clif_hpmeter(struct map_session_data *sd)
  2456. {
  2457. nullpo_ret(sd);
  2458. 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);
  2459. return 0;
  2460. }
  2461. /// Notifies client of a character parameter change.
  2462. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2463. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2464. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2465. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2466. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2467. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2468. /// TODO: Extract individual packets.
  2469. /// FIXME: Packet lengths from packet_len(cmd)
  2470. void clif_updatestatus(struct map_session_data *sd,int type)
  2471. {
  2472. int fd,len=8;
  2473. nullpo_retv(sd);
  2474. fd=sd->fd;
  2475. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2476. return;
  2477. WFIFOHEAD(fd, 14);
  2478. WFIFOW(fd,0)=0xb0;
  2479. WFIFOW(fd,2)=type;
  2480. switch(type){
  2481. // 00b0
  2482. case SP_WEIGHT:
  2483. pc_updateweightstatus(sd);
  2484. WFIFOHEAD(fd,14);
  2485. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2486. WFIFOW(fd,2)=type;
  2487. WFIFOL(fd,4)=sd->weight;
  2488. break;
  2489. case SP_MAXWEIGHT:
  2490. WFIFOL(fd,4)=sd->max_weight;
  2491. break;
  2492. case SP_SPEED:
  2493. WFIFOL(fd,4)=sd->battle_status.speed;
  2494. break;
  2495. case SP_BASELEVEL:
  2496. WFIFOL(fd,4)=sd->status.base_level;
  2497. break;
  2498. case SP_JOBLEVEL:
  2499. WFIFOL(fd,4)=sd->status.job_level;
  2500. break;
  2501. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2502. WFIFOL(fd,4)=sd->status.karma;
  2503. break;
  2504. case SP_MANNER:
  2505. WFIFOL(fd,4)=sd->status.manner;
  2506. break;
  2507. case SP_STATUSPOINT:
  2508. WFIFOL(fd,4)=sd->status.status_point;
  2509. break;
  2510. case SP_SKILLPOINT:
  2511. WFIFOL(fd,4)=sd->status.skill_point;
  2512. break;
  2513. case SP_HIT:
  2514. WFIFOL(fd,4)=sd->battle_status.hit;
  2515. break;
  2516. case SP_FLEE1:
  2517. WFIFOL(fd,4)=sd->battle_status.flee;
  2518. break;
  2519. case SP_FLEE2:
  2520. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2521. break;
  2522. case SP_MAXHP:
  2523. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2524. break;
  2525. case SP_MAXSP:
  2526. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2527. break;
  2528. case SP_HP:
  2529. WFIFOL(fd,4)=sd->battle_status.hp;
  2530. // TODO: Won't these overwrite the current packet?
  2531. if( map[sd->bl.m].hpmeter_visible )
  2532. clif_hpmeter(sd);
  2533. if( !battle_config.party_hp_mode && sd->status.party_id )
  2534. clif_party_hp(sd);
  2535. if( sd->bg_id )
  2536. clif_bg_hp(sd);
  2537. break;
  2538. case SP_SP:
  2539. WFIFOL(fd,4)=sd->battle_status.sp;
  2540. break;
  2541. case SP_ASPD:
  2542. WFIFOL(fd,4)=sd->battle_status.amotion;
  2543. break;
  2544. case SP_ATK1:
  2545. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2546. break;
  2547. case SP_DEF1:
  2548. WFIFOL(fd,4)=pc_leftside_def(sd);
  2549. break;
  2550. case SP_MDEF1:
  2551. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2552. break;
  2553. case SP_ATK2:
  2554. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2555. break;
  2556. case SP_DEF2:
  2557. WFIFOL(fd,4)=pc_rightside_def(sd);
  2558. break;
  2559. case SP_MDEF2: {
  2560. //negative check (in case you have something like Berserk active)
  2561. int mdef2 = pc_rightside_mdef(sd);
  2562. WFIFOL(fd,4)=
  2563. #ifndef RENEWAL
  2564. ( mdef2 < 0 ) ? 0 :
  2565. #endif
  2566. mdef2;
  2567. }
  2568. break;
  2569. case SP_CRITICAL:
  2570. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2571. break;
  2572. case SP_MATK1:
  2573. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2574. break;
  2575. case SP_MATK2:
  2576. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2577. break;
  2578. case SP_ZENY:
  2579. WFIFOW(fd,0)=0xb1;
  2580. WFIFOL(fd,4)=sd->status.zeny;
  2581. break;
  2582. case SP_BASEEXP:
  2583. WFIFOW(fd,0)=0xb1;
  2584. WFIFOL(fd,4)=sd->status.base_exp;
  2585. break;
  2586. case SP_JOBEXP:
  2587. WFIFOW(fd,0)=0xb1;
  2588. WFIFOL(fd,4)=sd->status.job_exp;
  2589. break;
  2590. case SP_NEXTBASEEXP:
  2591. WFIFOW(fd,0)=0xb1;
  2592. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2593. break;
  2594. case SP_NEXTJOBEXP:
  2595. WFIFOW(fd,0)=0xb1;
  2596. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2597. break;
  2598. /**
  2599. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2600. **/
  2601. case SP_USTR:
  2602. case SP_UAGI:
  2603. case SP_UVIT:
  2604. case SP_UINT:
  2605. case SP_UDEX:
  2606. case SP_ULUK:
  2607. WFIFOW(fd,0)=0xbe;
  2608. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2609. len=5;
  2610. break;
  2611. /**
  2612. * Tells the client how far it is allowed to attack (weapon range)
  2613. **/
  2614. case SP_ATTACKRANGE:
  2615. WFIFOW(fd,0)=0x13a;
  2616. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2617. len=4;
  2618. break;
  2619. case SP_STR:
  2620. WFIFOW(fd,0)=0x141;
  2621. WFIFOL(fd,2)=type;
  2622. WFIFOL(fd,6)=sd->status.str;
  2623. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2624. len=14;
  2625. break;
  2626. case SP_AGI:
  2627. WFIFOW(fd,0)=0x141;
  2628. WFIFOL(fd,2)=type;
  2629. WFIFOL(fd,6)=sd->status.agi;
  2630. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2631. len=14;
  2632. break;
  2633. case SP_VIT:
  2634. WFIFOW(fd,0)=0x141;
  2635. WFIFOL(fd,2)=type;
  2636. WFIFOL(fd,6)=sd->status.vit;
  2637. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2638. len=14;
  2639. break;
  2640. case SP_INT:
  2641. WFIFOW(fd,0)=0x141;
  2642. WFIFOL(fd,2)=type;
  2643. WFIFOL(fd,6)=sd->status.int_;
  2644. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2645. len=14;
  2646. break;
  2647. case SP_DEX:
  2648. WFIFOW(fd,0)=0x141;
  2649. WFIFOL(fd,2)=type;
  2650. WFIFOL(fd,6)=sd->status.dex;
  2651. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2652. len=14;
  2653. break;
  2654. case SP_LUK:
  2655. WFIFOW(fd,0)=0x141;
  2656. WFIFOL(fd,2)=type;
  2657. WFIFOL(fd,6)=sd->status.luk;
  2658. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2659. len=14;
  2660. break;
  2661. case SP_CARTINFO:
  2662. WFIFOW(fd,0)=0x121;
  2663. WFIFOW(fd,2)=sd->cart_num;
  2664. WFIFOW(fd,4)=MAX_CART;
  2665. WFIFOL(fd,6)=sd->cart_weight;
  2666. WFIFOL(fd,10)=sd->cart_weight_max;
  2667. len=14;
  2668. break;
  2669. default:
  2670. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2671. return;
  2672. }
  2673. WFIFOSET(fd,len);
  2674. }
  2675. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2676. /// 01ab <account id>.L <var id>.W <value>.L
  2677. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2678. {
  2679. unsigned char buf[12];
  2680. nullpo_retv(sd);
  2681. WBUFW(buf,0)=0x1ab;
  2682. WBUFL(buf,2)=sd->bl.id;
  2683. WBUFW(buf,6)=type;
  2684. switch(type)
  2685. {
  2686. case SP_MANNER:
  2687. WBUFL(buf,8)=val;
  2688. break;
  2689. default:
  2690. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2691. return;
  2692. }
  2693. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2694. }
  2695. /// Updates sprite/style properties of an object.
  2696. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2697. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2698. void clif_changelook(struct block_list *bl,int type,int val)
  2699. {
  2700. unsigned char buf[16];
  2701. struct map_session_data* sd;
  2702. struct status_change* sc;
  2703. struct view_data* vd;
  2704. enum send_target target = AREA;
  2705. nullpo_retv(bl);
  2706. sd = BL_CAST(BL_PC, bl);
  2707. sc = status_get_sc(bl);
  2708. vd = status_get_viewdata(bl);
  2709. //nullpo_ret(vd);
  2710. if( vd ) //temp hack to let Warp Portal change appearance
  2711. switch(type)
  2712. {
  2713. case LOOK_WEAPON:
  2714. if (sd)
  2715. {
  2716. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2717. val = vd->weapon;
  2718. }
  2719. else vd->weapon = val;
  2720. break;
  2721. case LOOK_SHIELD:
  2722. if (sd)
  2723. {
  2724. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2725. val = vd->shield;
  2726. }
  2727. else vd->shield = val;
  2728. break;
  2729. case LOOK_BASE:
  2730. if (!sd) break;
  2731. if (sd->sc.option&OPTION_COSTUME)
  2732. vd->weapon = vd->shield = 0;
  2733. if (!vd->cloth_color)
  2734. break;
  2735. if (sd) {
  2736. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2737. vd->cloth_color = 0;
  2738. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2739. vd->cloth_color = 0;
  2740. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2741. vd->cloth_color = 0;
  2742. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2743. vd->cloth_color = 0;
  2744. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2745. vd->cloth_color = 0;
  2746. }
  2747. break;
  2748. case LOOK_HAIR:
  2749. vd->hair_style = val;
  2750. break;
  2751. case LOOK_HEAD_BOTTOM:
  2752. vd->head_bottom = val;
  2753. break;
  2754. case LOOK_HEAD_TOP:
  2755. vd->head_top = val;
  2756. break;
  2757. case LOOK_HEAD_MID:
  2758. vd->head_mid = val;
  2759. break;
  2760. case LOOK_HAIR_COLOR:
  2761. vd->hair_color = val;
  2762. break;
  2763. case LOOK_CLOTHES_COLOR:
  2764. if (val && sd) {
  2765. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2766. val = 0;
  2767. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2768. val = 0;
  2769. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2770. val = 0;
  2771. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2772. val = 0;
  2773. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2774. val = 0;
  2775. }
  2776. vd->cloth_color = val;
  2777. break;
  2778. case LOOK_SHOES:
  2779. #if PACKETVER > 3
  2780. if (sd) {
  2781. int n;
  2782. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2783. if(sd->inventory_data[n]->view_id > 0)
  2784. val = sd->inventory_data[n]->view_id;
  2785. else
  2786. val = sd->status.inventory[n].nameid;
  2787. } else
  2788. val = 0;
  2789. }
  2790. #endif
  2791. //Shoes? No packet uses this....
  2792. break;
  2793. case LOOK_BODY:
  2794. // unknown purpose
  2795. break;
  2796. case LOOK_ROBE:
  2797. #if PACKETVER < 20110111
  2798. return;
  2799. #else
  2800. vd->robe = val;
  2801. #endif
  2802. break;
  2803. }
  2804. // prevent leaking the presence of GM-hidden objects
  2805. if( sc && sc->option&OPTION_INVISIBLE )
  2806. target = SELF;
  2807. #if PACKETVER < 4
  2808. WBUFW(buf,0)=0xc3;
  2809. WBUFL(buf,2)=bl->id;
  2810. WBUFB(buf,6)=type;
  2811. WBUFB(buf,7)=val;
  2812. clif_send(buf,packet_len(0xc3),bl,target);
  2813. #else
  2814. WBUFW(buf,0)=0x1d7;
  2815. WBUFL(buf,2)=bl->id;
  2816. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2817. WBUFB(buf,6)=LOOK_WEAPON;
  2818. WBUFW(buf,7)=vd->weapon;
  2819. WBUFW(buf,9)=vd->shield;
  2820. } else {
  2821. WBUFB(buf,6)=type;
  2822. WBUFL(buf,7)=val;
  2823. }
  2824. clif_send(buf,packet_len(0x1d7),bl,target);
  2825. #endif
  2826. }
  2827. //Sends a change-base-look packet required for traps as they are triggered.
  2828. void clif_changetraplook(struct block_list *bl,int val)
  2829. {
  2830. unsigned char buf[32];
  2831. #if PACKETVER < 4
  2832. WBUFW(buf,0)=0xc3;
  2833. WBUFL(buf,2)=bl->id;
  2834. WBUFB(buf,6)=LOOK_BASE;
  2835. WBUFB(buf,7)=val;
  2836. clif_send(buf,packet_len(0xc3),bl,AREA);
  2837. #else
  2838. WBUFW(buf,0)=0x1d7;
  2839. WBUFL(buf,2)=bl->id;
  2840. WBUFB(buf,6)=LOOK_BASE;
  2841. WBUFW(buf,7)=val;
  2842. WBUFW(buf,9)=0;
  2843. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2844. #endif
  2845. }
  2846. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2847. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2848. {
  2849. unsigned char buf[32];
  2850. #if PACKETVER < 4
  2851. WBUFW(buf,0)=0xc3;
  2852. WBUFL(buf,2)=id;
  2853. WBUFB(buf,6)=type;
  2854. WBUFB(buf,7)=val;
  2855. clif_send(buf,packet_len(0xc3),bl,target);
  2856. #else
  2857. WBUFW(buf,0)=0x1d7;
  2858. WBUFL(buf,2)=id;
  2859. WBUFB(buf,6)=type;
  2860. WBUFW(buf,7)=val;
  2861. WBUFW(buf,9)=0;
  2862. clif_send(buf,packet_len(0x1d7),bl,target);
  2863. #endif
  2864. }
  2865. /// Character status (ZC_STATUS).
  2866. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2867. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2868. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2869. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2870. void clif_initialstatus(struct map_session_data *sd) {
  2871. int fd, mdef2;
  2872. unsigned char *buf;
  2873. nullpo_retv(sd);
  2874. fd=sd->fd;
  2875. WFIFOHEAD(fd,packet_len(0xbd));
  2876. buf=WFIFOP(fd,0);
  2877. WBUFW(buf,0)=0xbd;
  2878. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2879. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2880. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2881. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2882. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2883. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2884. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2885. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2886. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2887. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2888. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2889. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2890. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2891. WBUFW(buf,16) = pc_leftside_atk(sd);
  2892. WBUFW(buf,18) = pc_rightside_atk(sd);
  2893. WBUFW(buf,20) = pc_rightside_matk(sd);
  2894. WBUFW(buf,22) = pc_leftside_matk(sd);
  2895. WBUFW(buf,24) = pc_leftside_def(sd);
  2896. WBUFW(buf,26) = pc_rightside_def(sd);
  2897. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2898. mdef2 = pc_rightside_mdef(sd);
  2899. WBUFW(buf,30) =
  2900. #ifndef RENEWAL
  2901. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2902. #endif
  2903. mdef2;
  2904. WBUFW(buf,32) = sd->battle_status.hit;
  2905. WBUFW(buf,34) = sd->battle_status.flee;
  2906. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2907. WBUFW(buf,38) = sd->battle_status.cri/10;
  2908. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2909. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2910. WFIFOSET(fd,packet_len(0xbd));
  2911. clif_updatestatus(sd,SP_STR);
  2912. clif_updatestatus(sd,SP_AGI);
  2913. clif_updatestatus(sd,SP_VIT);
  2914. clif_updatestatus(sd,SP_INT);
  2915. clif_updatestatus(sd,SP_DEX);
  2916. clif_updatestatus(sd,SP_LUK);
  2917. clif_updatestatus(sd,SP_ATTACKRANGE);
  2918. clif_updatestatus(sd,SP_ASPD);
  2919. }
  2920. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2921. /// 013c <index>.W
  2922. void clif_arrowequip(struct map_session_data *sd,int val)
  2923. {
  2924. int fd;
  2925. nullpo_retv(sd);
  2926. #if PACKETVER >= 20121128
  2927. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2928. #endif
  2929. fd=sd->fd;
  2930. WFIFOHEAD(fd, packet_len(0x013c));
  2931. WFIFOW(fd,0)=0x013c;
  2932. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2933. WFIFOSET(fd,packet_len(0x013c));
  2934. }
  2935. /// Ammunition action message (ZC_ACTION_FAILURE).
  2936. /// 013b <type>.W
  2937. /// type:
  2938. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2939. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2940. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2941. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2942. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2943. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2944. void clif_arrow_fail(struct map_session_data *sd,int type)
  2945. {
  2946. int fd;
  2947. nullpo_retv(sd);
  2948. fd=sd->fd;
  2949. WFIFOHEAD(fd, packet_len(0x013b));
  2950. WFIFOW(fd,0)=0x013b;
  2951. WFIFOW(fd,2)=type;
  2952. WFIFOSET(fd,packet_len(0x013b));
  2953. }
  2954. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2955. /// 01ad <packet len>.W { <name id>.W }*
  2956. void clif_arrow_create_list(struct map_session_data *sd)
  2957. {
  2958. int i, c;
  2959. int fd;
  2960. nullpo_retv(sd);
  2961. fd = sd->fd;
  2962. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2963. WFIFOW(fd,0) = 0x1ad;
  2964. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2965. short j, nameid = skill_arrow_db[i].nameid;
  2966. if (nameid > 0 && itemdb_exists(nameid) &&
  2967. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  2968. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2969. {
  2970. if ((j = itemdb_viewid(nameid)) > 0)
  2971. WFIFOW(fd,c*2+4) = j;
  2972. else
  2973. WFIFOW(fd,c*2+4) = nameid;
  2974. c++;
  2975. }
  2976. }
  2977. WFIFOW(fd,2) = c*2+4;
  2978. WFIFOSET(fd, WFIFOW(fd,2));
  2979. if (c > 0) {
  2980. sd->menuskill_id = AC_MAKINGARROW;
  2981. sd->menuskill_val = c;
  2982. }
  2983. }
  2984. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2985. /// 00bc <status id>.W <result>.B <value>.B
  2986. /// status id:
  2987. /// SP_STR ~ SP_LUK
  2988. /// result:
  2989. /// 0 = failure
  2990. /// 1 = success
  2991. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2992. {
  2993. int fd;
  2994. nullpo_retv(sd);
  2995. fd=sd->fd;
  2996. WFIFOHEAD(fd,packet_len(0xbc));
  2997. WFIFOW(fd,0)=0xbc;
  2998. WFIFOW(fd,2)=type;
  2999. WFIFOB(fd,4)=ok;
  3000. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3001. WFIFOSET(fd,packet_len(0xbc));
  3002. }
  3003. /// Notifies the client about the result of a request to equip an item.
  3004. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3005. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3006. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3007. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3008. /// @ok: //inversed forv2 v5
  3009. /// 0 = failure
  3010. /// 1 = success
  3011. /// 2 = failure due to low level
  3012. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3013. {
  3014. int fd = 0, cmd = 0, look = 0;
  3015. struct s_packet_db *info = NULL;
  3016. nullpo_retv(sd);
  3017. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3018. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3019. return;
  3020. fd = sd->fd;
  3021. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3022. look = sd->inventory_data[n]->look;
  3023. WFIFOHEAD(fd, info->len);
  3024. WFIFOW(fd, 0) = cmd;
  3025. WFIFOW(fd, info->pos[0]) = n+2;
  3026. switch (cmd) {
  3027. case 0xaa:
  3028. WFIFOW(fd, info->pos[1]) = pos;
  3029. if (sd->packet_ver < date2version(20100629))
  3030. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3031. else {
  3032. WFIFOL(fd, info->pos[2]) = look;
  3033. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3034. }
  3035. break;
  3036. case 0x8d0:
  3037. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3038. flag = 1;
  3039. case 0x999:
  3040. if (cmd == 0x999)
  3041. WFIFOL(fd, info->pos[1]) = pos;
  3042. else
  3043. WFIFOW(fd, info->pos[1]) = pos;
  3044. WFIFOL(fd, info->pos[2]) = look;
  3045. WFIFOW(fd, info->pos[3]) = flag;
  3046. break;
  3047. }
  3048. WFIFOSET(fd, info->len);
  3049. }
  3050. /// Notifies the client about the result of a request to take off an item.
  3051. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3052. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3053. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3054. /// @ok : //inversed for v2 v5
  3055. /// 0 = failure
  3056. /// 1 = success
  3057. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3058. {
  3059. int fd,header,offs=0;
  3060. #if PACKETVER >= 20130000
  3061. header = 0x99a;
  3062. ok = ok ? 0:1;
  3063. #elif PACKETVER >= 20110824
  3064. header = 0x8d1;
  3065. ok = ok ? 0:1;
  3066. #else
  3067. header = 0xac;
  3068. #endif
  3069. nullpo_retv(sd);
  3070. fd=sd->fd;
  3071. WFIFOHEAD(fd,packet_len(header));
  3072. WFIFOW(fd,offs+0)=header;
  3073. WFIFOW(fd,offs+2)=n+2;
  3074. #if PACKETVER >= 20130000
  3075. WFIFOL(fd,offs+4)=pos;
  3076. offs +=2;
  3077. #else
  3078. WFIFOW(fd,offs+4)=pos;
  3079. #endif
  3080. WFIFOB(fd,offs+6)=ok;
  3081. WFIFOSET(fd,packet_len(header));
  3082. }
  3083. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3084. /// 019b <id>.L <effect id>.L
  3085. /// effect id:
  3086. /// 0 = base level up
  3087. /// 1 = job level up
  3088. /// 2 = refine failure
  3089. /// 3 = refine success
  3090. /// 4 = game over
  3091. /// 5 = pharmacy success
  3092. /// 6 = pharmacy failure
  3093. /// 7 = base level up (super novice)
  3094. /// 8 = job level up (super novice)
  3095. /// 9 = base level up (taekwon)
  3096. void clif_misceffect(struct block_list* bl,int type)
  3097. {
  3098. unsigned char buf[32];
  3099. nullpo_retv(bl);
  3100. WBUFW(buf,0) = 0x19b;
  3101. WBUFL(buf,2) = bl->id;
  3102. WBUFL(buf,6) = type;
  3103. clif_send(buf,packet_len(0x19b),bl,AREA);
  3104. }
  3105. /// Notifies clients in the area of a state change.
  3106. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3107. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3108. void clif_changeoption(struct block_list* bl)
  3109. {
  3110. unsigned char buf[32];
  3111. struct status_change *sc;
  3112. struct map_session_data* sd;
  3113. nullpo_retv(bl);
  3114. sc = status_get_sc(bl);
  3115. if (!sc) return; //How can an option change if there's no sc?
  3116. sd = BL_CAST(BL_PC, bl);
  3117. #if PACKETVER >= 7
  3118. WBUFW(buf,0) = 0x229;
  3119. WBUFL(buf,2) = bl->id;
  3120. WBUFW(buf,6) = sc->opt1;
  3121. WBUFW(buf,8) = sc->opt2;
  3122. WBUFL(buf,10) = sc->option;
  3123. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3124. if(disguised(bl)) {
  3125. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3126. WBUFL(buf,2) = -bl->id;
  3127. clif_send(buf,packet_len(0x229),bl,SELF);
  3128. WBUFL(buf,2) = bl->id;
  3129. WBUFL(buf,10) = OPTION_INVISIBLE;
  3130. clif_send(buf,packet_len(0x229),bl,SELF);
  3131. } else
  3132. clif_send(buf,packet_len(0x229),bl,AREA);
  3133. #else
  3134. WBUFW(buf,0) = 0x119;
  3135. WBUFL(buf,2) = bl->id;
  3136. WBUFW(buf,6) = sc->opt1;
  3137. WBUFW(buf,8) = sc->opt2;
  3138. WBUFW(buf,10) = sc->option;
  3139. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3140. if(disguised(bl)) {
  3141. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3142. WBUFL(buf,2) = -bl->id;
  3143. clif_send(buf,packet_len(0x119),bl,SELF);
  3144. WBUFL(buf,2) = bl->id;
  3145. WBUFW(buf,10) = OPTION_INVISIBLE;
  3146. clif_send(buf,packet_len(0x119),bl,SELF);
  3147. } else
  3148. clif_send(buf,packet_len(0x119),bl,AREA);
  3149. #endif
  3150. }
  3151. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3152. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3153. void clif_changeoption2(struct block_list* bl)
  3154. {
  3155. unsigned char buf[20];
  3156. struct status_change *sc;
  3157. sc = status_get_sc(bl);
  3158. if (!sc) return; //How can an option change if there's no sc?
  3159. WBUFW(buf,0) = 0x28a;
  3160. WBUFL(buf,2) = bl->id;
  3161. WBUFL(buf,6) = sc->option;
  3162. WBUFL(buf,10) = clif_setlevel(bl);
  3163. WBUFL(buf,14) = sc->opt3;
  3164. if(disguised(bl)) {
  3165. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3166. WBUFL(buf,2) = -bl->id;
  3167. clif_send(buf,packet_len(0x28a),bl,SELF);
  3168. WBUFL(buf,2) = bl->id;
  3169. WBUFL(buf,6) = OPTION_INVISIBLE;
  3170. clif_send(buf,packet_len(0x28a),bl,SELF);
  3171. } else
  3172. clif_send(buf,packet_len(0x28a),bl,AREA);
  3173. }
  3174. /// Notifies the client about the result of an item use request.
  3175. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3176. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3177. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3178. {
  3179. nullpo_retv(sd);
  3180. if(!ok) {
  3181. int fd=sd->fd;
  3182. WFIFOHEAD(fd,packet_len(0xa8));
  3183. WFIFOW(fd,0)=0xa8;
  3184. WFIFOW(fd,2)=index+2;
  3185. WFIFOW(fd,4)=amount;
  3186. WFIFOB(fd,6)=ok;
  3187. WFIFOSET(fd,packet_len(0xa8));
  3188. }
  3189. else {
  3190. #if PACKETVER < 3
  3191. int fd=sd->fd;
  3192. WFIFOHEAD(fd,packet_len(0xa8));
  3193. WFIFOW(fd,0)=0xa8;
  3194. WFIFOW(fd,2)=index+2;
  3195. WFIFOW(fd,4)=amount;
  3196. WFIFOB(fd,6)=ok;
  3197. WFIFOSET(fd,packet_len(0xa8));
  3198. #else
  3199. unsigned char buf[32];
  3200. WBUFW(buf,0)=0x1c8;
  3201. WBUFW(buf,2)=index+2;
  3202. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3203. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3204. else
  3205. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3206. WBUFL(buf,6)=sd->bl.id;
  3207. WBUFW(buf,10)=amount;
  3208. WBUFB(buf,12)=ok;
  3209. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3210. #endif
  3211. }
  3212. }
  3213. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3214. /// 00d6 <flag>.B
  3215. /// flag:
  3216. /// 0 = Room has been successfully created (opens chat room)
  3217. /// 1 = Room limit exceeded
  3218. /// 2 = Same room already exists
  3219. void clif_createchat(struct map_session_data* sd, int flag)
  3220. {
  3221. int fd;
  3222. nullpo_retv(sd);
  3223. fd = sd->fd;
  3224. WFIFOHEAD(fd,packet_len(0xd6));
  3225. WFIFOW(fd,0) = 0xd6;
  3226. WFIFOB(fd,2) = flag;
  3227. WFIFOSET(fd,packet_len(0xd6));
  3228. }
  3229. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3230. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3231. /// type:
  3232. /// 0 = private (password protected)
  3233. /// 1 = public
  3234. /// 2 = arena (npc waiting room)
  3235. /// 3 = PK zone (non-clickable)
  3236. void clif_dispchat(struct chat_data* cd, int fd)
  3237. {
  3238. unsigned char buf[128];
  3239. uint8 type;
  3240. if( cd == NULL || cd->owner == NULL )
  3241. return;
  3242. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3243. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3244. : 1;
  3245. WBUFW(buf, 0) = 0xd7;
  3246. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3247. WBUFL(buf, 4) = cd->owner->id;
  3248. WBUFL(buf, 8) = cd->bl.id;
  3249. WBUFW(buf,12) = cd->limit;
  3250. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3251. WBUFB(buf,16) = type;
  3252. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3253. if( fd ) {
  3254. WFIFOHEAD(fd,WBUFW(buf,2));
  3255. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3256. WFIFOSET(fd,WBUFW(buf,2));
  3257. } else {
  3258. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3259. }
  3260. }
  3261. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3262. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3263. /// type:
  3264. /// 0 = private (password protected)
  3265. /// 1 = public
  3266. /// 2 = arena (npc waiting room)
  3267. /// 3 = PK zone (non-clickable)
  3268. void clif_changechatstatus(struct chat_data* cd)
  3269. {
  3270. unsigned char buf[128];
  3271. uint8 type;
  3272. if( cd == NULL || cd->usersd[0] == NULL )
  3273. return;
  3274. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3275. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3276. : 1;
  3277. WBUFW(buf, 0) = 0xdf;
  3278. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3279. WBUFL(buf, 4) = cd->owner->id;
  3280. WBUFL(buf, 8) = cd->bl.id;
  3281. WBUFW(buf,12) = cd->limit;
  3282. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3283. WBUFB(buf,16) = type;
  3284. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3285. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3286. }
  3287. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3288. /// 00d8 <chat id>.L
  3289. void clif_clearchat(struct chat_data *cd,int fd)
  3290. {
  3291. unsigned char buf[32];
  3292. nullpo_retv(cd);
  3293. WBUFW(buf,0) = 0xd8;
  3294. WBUFL(buf,2) = cd->bl.id;
  3295. if( fd ) {
  3296. WFIFOHEAD(fd,packet_len(0xd8));
  3297. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3298. WFIFOSET(fd,packet_len(0xd8));
  3299. } else {
  3300. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3301. }
  3302. }
  3303. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3304. /// 00da <result>.B
  3305. /// result:
  3306. /// 0 = room full
  3307. /// 1 = wrong password
  3308. /// 2 = kicked
  3309. /// 3 = success (no message)
  3310. /// 4 = no enough zeny
  3311. /// 5 = too low level
  3312. /// 6 = too high level
  3313. /// 7 = unsuitable job class
  3314. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3315. {
  3316. int fd;
  3317. nullpo_retv(sd);
  3318. fd = sd->fd;
  3319. WFIFOHEAD(fd,packet_len(0xda));
  3320. WFIFOW(fd,0) = 0xda;
  3321. WFIFOB(fd,2) = flag;
  3322. WFIFOSET(fd,packet_len(0xda));
  3323. }
  3324. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3325. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3326. /// role:
  3327. /// 0 = owner (menu)
  3328. /// 1 = normal
  3329. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3330. {
  3331. int fd;
  3332. int i,t;
  3333. nullpo_retv(sd);
  3334. nullpo_retv(cd);
  3335. fd = sd->fd;
  3336. if (!session_isActive(fd))
  3337. return;
  3338. t = (int)(cd->owner->type == BL_NPC);
  3339. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3340. WFIFOW(fd, 0) = 0xdb;
  3341. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3342. WFIFOL(fd, 4) = cd->bl.id;
  3343. if(cd->owner->type == BL_NPC){
  3344. WFIFOL(fd, 30) = 1;
  3345. WFIFOL(fd, 8) = 0;
  3346. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3347. for (i = 0; i < cd->users; i++) {
  3348. WFIFOL(fd, 8+(i+1)*28) = 1;
  3349. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3350. }
  3351. } else
  3352. for (i = 0; i < cd->users; i++) {
  3353. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3354. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3355. }
  3356. WFIFOSET(fd, WFIFOW(fd, 2));
  3357. }
  3358. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3359. /// 00dc <users>.W <name>.24B
  3360. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3361. {
  3362. unsigned char buf[29];
  3363. nullpo_retv(sd);
  3364. nullpo_retv(cd);
  3365. WBUFW(buf, 0) = 0xdc;
  3366. WBUFW(buf, 2) = cd->users;
  3367. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3368. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3369. }
  3370. /// Announce the new owner (ZC_ROLE_CHANGE).
  3371. /// 00e1 <role>.L <nick>.24B
  3372. /// role:
  3373. /// 0 = owner (menu)
  3374. /// 1 = normal
  3375. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3376. {
  3377. unsigned char buf[64];
  3378. nullpo_retv(sd);
  3379. nullpo_retv(cd);
  3380. WBUFW(buf, 0) = 0xe1;
  3381. WBUFL(buf, 2) = 1;
  3382. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3383. WBUFW(buf,30) = 0xe1;
  3384. WBUFL(buf,32) = 0;
  3385. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3386. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3387. }
  3388. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3389. /// 00dd <users>.W <nick>.24B <flag>.B
  3390. /// flag:
  3391. /// 0 = left
  3392. /// 1 = kicked
  3393. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3394. {
  3395. unsigned char buf[32];
  3396. nullpo_retv(sd);
  3397. nullpo_retv(cd);
  3398. WBUFW(buf, 0) = 0xdd;
  3399. WBUFW(buf, 2) = cd->users-1;
  3400. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3401. WBUFB(buf,28) = flag;
  3402. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3403. }
  3404. /// Opens a trade request window from char 'name'.
  3405. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3406. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3407. void clif_traderequest(struct map_session_data* sd, const char* name)
  3408. {
  3409. int fd = sd->fd;
  3410. #if PACKETVER < 6
  3411. WFIFOHEAD(fd,packet_len(0xe5));
  3412. WFIFOW(fd,0) = 0xe5;
  3413. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3414. WFIFOSET(fd,packet_len(0xe5));
  3415. #else
  3416. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3417. if( !tsd ) return;
  3418. WFIFOHEAD(fd,packet_len(0x1f4));
  3419. WFIFOW(fd,0) = 0x1f4;
  3420. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3421. WFIFOL(fd,26) = tsd->status.char_id;
  3422. WFIFOW(fd,30) = tsd->status.base_level;
  3423. WFIFOSET(fd,packet_len(0x1f4));
  3424. #endif
  3425. }
  3426. /// Reply to a trade-request.
  3427. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3428. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3429. /// result:
  3430. /// 0 = Char is too far
  3431. /// 1 = Character does not exist
  3432. /// 2 = Trade failed
  3433. /// 3 = Accept
  3434. /// 4 = Cancel
  3435. /// 5 = Busy
  3436. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3437. {
  3438. int fd = sd->fd;
  3439. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3440. if( PACKETVER < 6 || !tsd ) {
  3441. WFIFOHEAD(fd,packet_len(0xe7));
  3442. WFIFOW(fd,0) = 0xe7;
  3443. WFIFOB(fd,2) = type;
  3444. WFIFOSET(fd,packet_len(0xe7));
  3445. } else {
  3446. WFIFOHEAD(fd,packet_len(0x1f5));
  3447. WFIFOW(fd,0) = 0x1f5;
  3448. WFIFOB(fd,2) = type;
  3449. WFIFOL(fd,3) = tsd->status.char_id;
  3450. WFIFOW(fd,7) = tsd->status.base_level;
  3451. WFIFOSET(fd,packet_len(0x1f5));
  3452. }
  3453. }
  3454. /// Notifies the client about an item from other player in current trade.
  3455. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3456. /// 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)
  3457. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3458. {
  3459. int fd;
  3460. unsigned char *buf;
  3461. #if PACKETVER < 20100223
  3462. const int cmd = 0xe9;
  3463. #else
  3464. const int cmd = 0x80f;
  3465. #endif
  3466. nullpo_retv(sd);
  3467. nullpo_retv(tsd);
  3468. fd = tsd->fd;
  3469. buf = WFIFOP(fd,0);
  3470. WFIFOHEAD(fd,packet_len(cmd));
  3471. WBUFW(buf,0) = cmd;
  3472. if( index == 0 )
  3473. {
  3474. #if PACKETVER < 20100223
  3475. WBUFL(buf,2) = amount; //amount
  3476. WBUFW(buf,6) = 0; // type id
  3477. #else
  3478. WBUFW(buf,2) = 0; // type id
  3479. WBUFB(buf,4) = 0; // item type
  3480. WBUFL(buf,5) = amount; // amount
  3481. buf = WBUFP(buf,1); //Advance 1B
  3482. #endif
  3483. WBUFB(buf,8) = 0; //identify flag
  3484. WBUFB(buf,9) = 0; // attribute
  3485. WBUFB(buf,10)= 0; //refine
  3486. WBUFW(buf,11)= 0; //card (4w)
  3487. WBUFW(buf,13)= 0; //card (4w)
  3488. WBUFW(buf,15)= 0; //card (4w)
  3489. WBUFW(buf,17)= 0; //card (4w)
  3490. }
  3491. else
  3492. {
  3493. index -= 2; //index fix
  3494. #if PACKETVER < 20100223
  3495. WBUFL(buf,2) = amount; //amount
  3496. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3497. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3498. else
  3499. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3500. #else
  3501. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3502. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3503. else
  3504. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3505. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3506. WBUFL(buf,5) = amount; // amount
  3507. buf = WBUFP(buf,1); //Advance 1B
  3508. #endif
  3509. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3510. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3511. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3512. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3513. }
  3514. WFIFOSET(fd,packet_len(cmd));
  3515. }
  3516. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3517. /// 00ea <index>.W <result>.B
  3518. /// result:
  3519. /// 0 = success
  3520. /// 1 = overweight
  3521. /// 2 = trade canceled
  3522. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3523. {
  3524. int fd;
  3525. nullpo_retv(sd);
  3526. fd = sd->fd;
  3527. WFIFOHEAD(fd,packet_len(0xea));
  3528. WFIFOW(fd,0) = 0xea;
  3529. WFIFOW(fd,2) = index;
  3530. WFIFOB(fd,4) = fail;
  3531. WFIFOSET(fd,packet_len(0xea));
  3532. }
  3533. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3534. /// 00ec <who>.B
  3535. /// who:
  3536. /// 0 = self
  3537. /// 1 = other player
  3538. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3539. {
  3540. int fd;
  3541. nullpo_retv(sd);
  3542. fd = sd->fd;
  3543. WFIFOHEAD(fd,packet_len(0xec));
  3544. WFIFOW(fd,0) = 0xec;
  3545. WFIFOB(fd,2) = fail;
  3546. WFIFOSET(fd,packet_len(0xec));
  3547. }
  3548. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3549. /// 00ee
  3550. void clif_tradecancelled(struct map_session_data* sd)
  3551. {
  3552. int fd;
  3553. nullpo_retv(sd);
  3554. fd = sd->fd;
  3555. WFIFOHEAD(fd,packet_len(0xee));
  3556. WFIFOW(fd,0) = 0xee;
  3557. WFIFOSET(fd,packet_len(0xee));
  3558. }
  3559. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3560. /// 00f0 <result>.B
  3561. /// result:
  3562. /// 0 = success
  3563. /// 1 = failure
  3564. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3565. {
  3566. int fd;
  3567. nullpo_retv(sd);
  3568. fd = sd->fd;
  3569. WFIFOHEAD(fd,packet_len(0xf0));
  3570. WFIFOW(fd,0) = 0xf0;
  3571. WFIFOB(fd,2) = fail;
  3572. WFIFOSET(fd,packet_len(0xf0));
  3573. }
  3574. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3575. /// 00f1
  3576. /// NOTE: Unknown purpose. Items are not removed until the window is
  3577. /// refreshed (ex. by putting another item in there).
  3578. void clif_tradeundo(struct map_session_data* sd)
  3579. {
  3580. int fd = sd->fd;
  3581. WFIFOHEAD(fd,packet_len(0xf1));
  3582. WFIFOW(fd,0) = 0xf1;
  3583. WFIFOSET(fd,packet_len(0xf1));
  3584. }
  3585. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3586. /// 00f2 <current count>.W <max count>.W
  3587. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3588. {
  3589. int fd;
  3590. nullpo_retv(sd);
  3591. fd=sd->fd;
  3592. WFIFOHEAD(fd,packet_len(0xf2));
  3593. WFIFOW(fd,0) = 0xf2;
  3594. WFIFOW(fd,2) = amount;
  3595. WFIFOW(fd,4) = max_amount;
  3596. WFIFOSET(fd,packet_len(0xf2));
  3597. }
  3598. /// Notifies the client of an item being added to the storage.
  3599. /// 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)
  3600. /// 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)
  3601. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3602. {
  3603. int view,fd;
  3604. nullpo_retv(sd);
  3605. nullpo_retv(i);
  3606. fd=sd->fd;
  3607. view = itemdb_viewid(i->nameid);
  3608. #if PACKETVER < 5
  3609. WFIFOHEAD(fd,packet_len(0xf4));
  3610. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3611. WFIFOW(fd, 2) = index+1; // index
  3612. WFIFOL(fd, 4) = amount; // amount
  3613. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3614. WFIFOB(fd,10) = i->identify; //identify flag
  3615. WFIFOB(fd,11) = i->attribute; // attribute
  3616. WFIFOB(fd,12) = i->refine; //refine
  3617. clif_addcards(WFIFOP(fd,13), i);
  3618. WFIFOSET(fd,packet_len(0xf4));
  3619. #else
  3620. WFIFOHEAD(fd,packet_len(0x1c4));
  3621. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3622. WFIFOW(fd, 2) = index+1; // index
  3623. WFIFOL(fd, 4) = amount; // amount
  3624. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3625. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3626. WFIFOB(fd,11) = i->identify; //identify flag
  3627. WFIFOB(fd,12) = i->attribute; // attribute
  3628. WFIFOB(fd,13) = i->refine; //refine
  3629. clif_addcards(WFIFOP(fd,14), i);
  3630. WFIFOSET(fd,packet_len(0x1c4));
  3631. #endif
  3632. }
  3633. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3634. /// 00f6 <index>.W <amount>.L
  3635. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3636. {
  3637. int fd;
  3638. nullpo_retv(sd);
  3639. fd=sd->fd;
  3640. WFIFOHEAD(fd,packet_len(0xf6));
  3641. WFIFOW(fd,0)=0xf6; // Storage item removed
  3642. WFIFOW(fd,2)=index+1;
  3643. WFIFOL(fd,4)=amount;
  3644. WFIFOSET(fd,packet_len(0xf6));
  3645. }
  3646. /// Closes storage (ZC_CLOSE_STORE).
  3647. /// 00f8
  3648. void clif_storageclose(struct map_session_data* sd)
  3649. {
  3650. int fd;
  3651. nullpo_retv(sd);
  3652. fd=sd->fd;
  3653. WFIFOHEAD(fd,packet_len(0xf8));
  3654. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3655. WFIFOSET(fd,packet_len(0xf8));
  3656. }
  3657. /*==========================================
  3658. * Server tells 'sd' player client the abouts of 'dstsd' player
  3659. *------------------------------------------*/
  3660. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3661. {
  3662. struct block_list *d_bl;
  3663. int i;
  3664. if( dstsd->chatID ) {
  3665. struct chat_data *cd = NULL;
  3666. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3667. clif_dispchat(cd,sd->fd);
  3668. } else if( dstsd->state.vending )
  3669. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3670. else if( dstsd->state.buyingstore )
  3671. clif_buyingstore_entry_single(sd, dstsd);
  3672. if(dstsd->spiritball > 0)
  3673. clif_spiritball_single(sd->fd, dstsd);
  3674. for(i = 1; i < 5; i++){
  3675. if( dstsd->talisman[i] > 0 )
  3676. clif_talisman_single(sd->fd, dstsd, i);
  3677. }
  3678. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3679. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3680. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3681. else
  3682. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, StatusIconChangeTable[dstsd->sc_display[i]->type], dstsd->sc_display[i]->val1, dstsd->sc_display[i]->val2, dstsd->sc_display[i]->val3);
  3683. }
  3684. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3685. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3686. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3687. )
  3688. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3689. // display link (sd - dstsd) to sd
  3690. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3691. if( i < MAX_DEVOTION )
  3692. clif_devotion(&sd->bl, sd);
  3693. // display links (dstsd - devotees) to sd
  3694. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3695. if( i < MAX_DEVOTION )
  3696. clif_devotion(&dstsd->bl, sd);
  3697. // display link (dstsd - crusader) to sd
  3698. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3699. clif_devotion(d_bl, sd);
  3700. }
  3701. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3702. {
  3703. uint8 buf[128];
  3704. struct unit_data *ud;
  3705. struct view_data *vd;
  3706. int len;
  3707. vd = status_get_viewdata(bl);
  3708. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3709. return;
  3710. /**
  3711. * Hide NPC from maya purple card.
  3712. **/
  3713. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3714. return;
  3715. ud = unit_bl2ud(bl);
  3716. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3717. clif_send(buf,len,&sd->bl,SELF);
  3718. if (vd->cloth_color)
  3719. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3720. switch (bl->type)
  3721. {
  3722. case BL_PC:
  3723. {
  3724. TBL_PC* tsd = (TBL_PC*)bl;
  3725. clif_getareachar_pc(sd, tsd);
  3726. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3727. clif_specialeffect_single(bl,423,sd->fd);
  3728. else if(tsd->state.size==SZ_MEDIUM)
  3729. clif_specialeffect_single(bl,421,sd->fd);
  3730. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3731. clif_sendbgemblem_single(sd->fd,tsd);
  3732. if ( tsd->status.robe )
  3733. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3734. if (!&tsd->sc)
  3735. break;
  3736. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3737. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3738. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3739. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3740. if( tsd->sc.data[SC_MOONSTAR] )
  3741. clif_status_load(bl,SI_MOONSTAR,1);
  3742. if( tsd->sc.data[SC_SUPER_STAR] )
  3743. clif_status_load(bl,SI_SUPER_STAR,1);
  3744. if( tsd->sc.data[SC_ALL_RIDING] )
  3745. clif_status_load(bl,SI_ALL_RIDING,1);
  3746. }
  3747. break;
  3748. case BL_MER: // Devotion Effects
  3749. if( ((TBL_MER*)bl)->devotion_flag )
  3750. clif_devotion(bl, sd);
  3751. break;
  3752. case BL_NPC:
  3753. {
  3754. TBL_NPC* nd = (TBL_NPC*)bl;
  3755. if( nd->chat_id )
  3756. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3757. if( nd->size == SZ_BIG )
  3758. clif_specialeffect_single(bl,423,sd->fd);
  3759. else if( nd->size == SZ_MEDIUM )
  3760. clif_specialeffect_single(bl,421,sd->fd);
  3761. }
  3762. break;
  3763. case BL_MOB:
  3764. {
  3765. TBL_MOB* md = (TBL_MOB*)bl;
  3766. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3767. clif_specialeffect_single(bl,423,sd->fd);
  3768. else if(md->special_state.size==SZ_MEDIUM)
  3769. clif_specialeffect_single(bl,421,sd->fd);
  3770. #if PACKETVER >= 20120404
  3771. if( !(md->status.mode&MD_BOSS) ){
  3772. int i;
  3773. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3774. if( md->dmglog[i].id == sd->status.char_id )
  3775. clif_monster_hp_bar(md, sd->fd);
  3776. }
  3777. #endif
  3778. }
  3779. break;
  3780. case BL_PET:
  3781. if (vd->head_bottom)
  3782. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3783. break;
  3784. }
  3785. }
  3786. //Modifies the type of damage according to status changes [Skotlex]
  3787. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3788. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  3789. {
  3790. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  3791. }
  3792. /*==========================================
  3793. * Estimates walk delay based on the damage criteria. [Skotlex]
  3794. *------------------------------------------*/
  3795. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  3796. {
  3797. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  3798. return 0;
  3799. if (bl->type == BL_PC) {
  3800. if (battle_config.pc_walk_delay_rate != 100)
  3801. delay = delay*battle_config.pc_walk_delay_rate/100;
  3802. } else
  3803. if (battle_config.walk_delay_rate != 100)
  3804. delay = delay*battle_config.walk_delay_rate/100;
  3805. if (div_ > 1) //Multi-hit skills mean higher delays.
  3806. delay += battle_config.multihit_delay*(div_-1);
  3807. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3808. }
  3809. /// Sends a 'damage' packet (src performs action on dst)
  3810. /// 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)
  3811. /// 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)
  3812. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3) //! TODO
  3813. /// type:
  3814. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3815. /// 1 = pick up item
  3816. /// 2 = sit down
  3817. /// 3 = stand up
  3818. /// 4 = damage (endure)
  3819. /// 5 = (splash?)
  3820. /// 6 = (skill?)
  3821. /// 7 = (repeat damage?)
  3822. /// 8 = multi-hit damage
  3823. /// 9 = multi-hit damage (endure)
  3824. /// 10 = critical hit
  3825. /// 11 = lucky dodge
  3826. /// 12 = (touch skill?)
  3827. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2)
  3828. {
  3829. unsigned char buf[33];
  3830. struct status_change *sc;
  3831. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3832. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3833. #if PACKETVER < 20071113
  3834. const int cmd = 0x8a;
  3835. #else
  3836. const int cmd = 0x2e1;
  3837. #endif
  3838. nullpo_ret(src);
  3839. nullpo_ret(dst);
  3840. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3841. sc = status_get_sc(dst);
  3842. if(sc && sc->count) {
  3843. if(sc->data[SC_HALLUCINATION]) {
  3844. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3845. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3846. }
  3847. }
  3848. WBUFW(buf,0)=cmd;
  3849. WBUFL(buf,2)=src->id;
  3850. WBUFL(buf,6)=dst->id;
  3851. WBUFL(buf,10)=tick;
  3852. WBUFL(buf,14)=sdelay;
  3853. WBUFL(buf,18)=ddelay;
  3854. #if PACKETVER < 20071113
  3855. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3856. WBUFW(buf,22)=damage?div:0;
  3857. WBUFW(buf,27)=damage2?div:0;
  3858. } else {
  3859. WBUFW(buf,22)=min(damage, INT16_MAX);
  3860. WBUFW(buf,27)=damage2;
  3861. }
  3862. WBUFW(buf,24)=div;
  3863. WBUFB(buf,26)=type;
  3864. #else
  3865. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3866. WBUFL(buf,22)=damage?div:0;
  3867. WBUFL(buf,29)=damage2?div:0;
  3868. } else {
  3869. WBUFL(buf,22)=damage;
  3870. WBUFL(buf,29)=damage2;
  3871. }
  3872. WBUFW(buf,26)=div;
  3873. WBUFB(buf,28)=type;
  3874. #endif
  3875. if(disguised(dst)) {
  3876. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3877. WBUFL(buf,6) = -dst->id;
  3878. clif_send(buf,packet_len(cmd),dst,SELF);
  3879. } else
  3880. clif_send(buf,packet_len(cmd),dst,AREA);
  3881. if(disguised(src)) {
  3882. WBUFL(buf,2) = -src->id;
  3883. if (disguised(dst))
  3884. WBUFL(buf,6) = dst->id;
  3885. #if PACKETVER < 20071113
  3886. if(damage > 0) WBUFW(buf,22) = -1;
  3887. if(damage2 > 0) WBUFW(buf,27) = -1;
  3888. #else
  3889. if(damage > 0) WBUFL(buf,22) = -1;
  3890. if(damage2 > 0) WBUFL(buf,29) = -1;
  3891. #endif
  3892. clif_send(buf,packet_len(cmd),src,SELF);
  3893. }
  3894. if(src == dst) {
  3895. unit_setdir(src,unit_getdir(src));
  3896. }
  3897. //Return adjusted can't walk delay for further processing.
  3898. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3899. }
  3900. /*==========================================
  3901. * src picks up dst
  3902. *------------------------------------------*/
  3903. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3904. {
  3905. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  3906. unsigned char buf[32];
  3907. nullpo_retv(src);
  3908. nullpo_retv(dst);
  3909. WBUFW(buf, 0) = 0x8a;
  3910. WBUFL(buf, 2) = src->id;
  3911. WBUFL(buf, 6) = dst->id;
  3912. WBUFB(buf,26) = 1;
  3913. clif_send(buf, packet_len(0x8a), src, AREA);
  3914. }
  3915. /*==========================================
  3916. * inform clients in area that `bl` is sitting
  3917. *------------------------------------------*/
  3918. void clif_sitting(struct block_list* bl)
  3919. {
  3920. unsigned char buf[32];
  3921. nullpo_retv(bl);
  3922. WBUFW(buf, 0) = 0x8a;
  3923. WBUFL(buf, 2) = bl->id;
  3924. WBUFB(buf,26) = 2;
  3925. clif_send(buf, packet_len(0x8a), bl, AREA);
  3926. if(disguised(bl)) {
  3927. WBUFL(buf, 2) = - bl->id;
  3928. clif_send(buf, packet_len(0x8a), bl, SELF);
  3929. }
  3930. }
  3931. /*==========================================
  3932. * inform clients in area that `bl` is standing
  3933. *------------------------------------------*/
  3934. void clif_standing(struct block_list* bl)
  3935. {
  3936. unsigned char buf[32];
  3937. nullpo_retv(bl);
  3938. WBUFW(buf, 0) = 0x8a;
  3939. WBUFL(buf, 2) = bl->id;
  3940. WBUFB(buf,26) = 3;
  3941. clif_send(buf, packet_len(0x8a), bl, AREA);
  3942. if(disguised(bl)) {
  3943. WBUFL(buf, 2) = - bl->id;
  3944. clif_send(buf, packet_len(0x8a), bl, SELF);
  3945. }
  3946. }
  3947. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3948. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3949. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3950. {
  3951. unsigned char buf[32];
  3952. WBUFW(buf,0) = 0x192;
  3953. WBUFW(buf,2) = x;
  3954. WBUFW(buf,4) = y;
  3955. WBUFW(buf,6) = type;
  3956. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  3957. if( fd )
  3958. {
  3959. WFIFOHEAD(fd,packet_len(0x192));
  3960. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3961. WFIFOSET(fd,packet_len(0x192));
  3962. }
  3963. else
  3964. {
  3965. struct block_list dummy_bl;
  3966. dummy_bl.type = BL_NUL;
  3967. dummy_bl.x = x;
  3968. dummy_bl.y = y;
  3969. dummy_bl.m = m;
  3970. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3971. }
  3972. }
  3973. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3974. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3975. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3976. {
  3977. int view,fd;
  3978. fd=sd->fd;
  3979. WFIFOHEAD(fd,packet_len(0x9d));
  3980. WFIFOW(fd,0)=0x9d;
  3981. WFIFOL(fd,2)=fitem->bl.id;
  3982. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  3983. WFIFOW(fd,6)=view;
  3984. else
  3985. WFIFOW(fd,6)=fitem->item.nameid;
  3986. WFIFOB(fd,8)=fitem->item.identify;
  3987. WFIFOW(fd,9)=fitem->bl.x;
  3988. WFIFOW(fd,11)=fitem->bl.y;
  3989. WFIFOW(fd,13)=fitem->item.amount;
  3990. WFIFOB(fd,15)=fitem->subx;
  3991. WFIFOB(fd,16)=fitem->suby;
  3992. WFIFOSET(fd,packet_len(0x9d));
  3993. }
  3994. /// Notifes client about Graffiti
  3995. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3996. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  3997. unsigned char buf[128];
  3998. nullpo_retv(bl);
  3999. nullpo_retv(unit);
  4000. WBUFW(buf, 0) = 0x1c9;
  4001. WBUFL(buf, 2) = unit->bl.id;
  4002. WBUFL(buf, 6) = unit->group->src_id;
  4003. WBUFW(buf,10) = unit->bl.x;
  4004. WBUFW(buf,12) = unit->bl.y;
  4005. WBUFB(buf,14) = unit->group->unit_id;
  4006. WBUFB(buf,15) = 1;
  4007. WBUFB(buf,16) = 1;
  4008. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4009. clif_send(buf,packet_len(0x1c9),bl,target);
  4010. }
  4011. /// Notifies the client of a skill unit.
  4012. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4013. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4014. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4015. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4016. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4017. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4018. unsigned char buf[128];
  4019. nullpo_retv(bl);
  4020. nullpo_retv(unit);
  4021. if (bl->type == BL_PC)
  4022. fd = ((TBL_PC*)bl)->fd;
  4023. if (unit->group->state.guildaura)
  4024. return;
  4025. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  4026. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for traps.
  4027. else if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4028. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4029. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4030. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  4031. else
  4032. unit_id = unit->group->unit_id;
  4033. #if PACKETVER >= 3
  4034. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4035. clif_graffiti(bl, unit, target);
  4036. return;
  4037. }
  4038. #endif
  4039. #if PACKETVER <= 20120702
  4040. header = 0x011f;
  4041. //#if PACKETVER < 20110718
  4042. // header = 0x011f;
  4043. //#elif PACKETVER < 20121212
  4044. // header = 0x08c7;
  4045. #elif PACKETVER < 20130731
  4046. header = 0x099f;
  4047. #else
  4048. header = 0x09ca;
  4049. #endif
  4050. len = packet_len(header);
  4051. WBUFW(buf,pos) = header;
  4052. if (header != 0x011f) {
  4053. WBUFW(buf, pos+2) = len;
  4054. pos += 2;
  4055. }
  4056. WBUFL(buf,pos+2) = unit->bl.id;
  4057. WBUFL(buf,pos+6) = unit->group->src_id;
  4058. WBUFW(buf,pos+10) = unit->bl.x;
  4059. WBUFW(buf,pos+12) = unit->bl.y;
  4060. switch (header) {
  4061. case 0x011f:
  4062. WBUFB(buf,pos+14) = unit_id;
  4063. WBUFB(buf,pos+15) = 1;
  4064. break;
  4065. case 0x08c7:
  4066. WBUFB(buf,pos+14) = unit_id;
  4067. WBUFW(buf,pos+15) = unit->range;
  4068. WBUFB(buf,pos+17) = 1;
  4069. break;
  4070. case 0x099f:
  4071. WBUFL(buf,pos+14) = unit_id;
  4072. WBUFW(buf,pos+18) = unit->range;
  4073. WBUFB(buf,pos+20) = 1;
  4074. break;
  4075. case 0x09ca:
  4076. WBUFL(buf,pos+14) = unit_id;
  4077. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4078. WBUFB(buf,pos+19) = 1;
  4079. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4080. break;
  4081. }
  4082. clif_send(buf, len, bl, target);
  4083. if (unit->group->skill_id == WZ_ICEWALL)
  4084. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4085. }
  4086. /*==========================================
  4087. * Server tells client to remove unit of id 'unit->bl.id'
  4088. *------------------------------------------*/
  4089. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4090. {
  4091. nullpo_retv(unit);
  4092. WFIFOHEAD(fd,packet_len(0x120));
  4093. WFIFOW(fd, 0)=0x120;
  4094. WFIFOL(fd, 2)=unit->bl.id;
  4095. WFIFOSET(fd,packet_len(0x120));
  4096. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4097. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4098. }
  4099. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4100. /// 0120 <id>.L
  4101. void clif_skill_delunit(struct skill_unit *unit)
  4102. {
  4103. unsigned char buf[16];
  4104. nullpo_retv(unit);
  4105. WBUFW(buf, 0)=0x120;
  4106. WBUFL(buf, 2)=unit->bl.id;
  4107. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4108. }
  4109. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4110. /// 01ac <id>.L
  4111. /// Only affects units with class [139,153] client-side.
  4112. void clif_skillunit_update(struct block_list* bl)
  4113. {
  4114. unsigned char buf[6];
  4115. nullpo_retv(bl);
  4116. WBUFW(buf,0) = 0x1ac;
  4117. WBUFL(buf,2) = bl->id;
  4118. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4119. }
  4120. /*==========================================
  4121. *
  4122. *------------------------------------------*/
  4123. static int clif_getareachar(struct block_list* bl,va_list ap)
  4124. {
  4125. struct map_session_data *sd;
  4126. nullpo_ret(bl);
  4127. sd=va_arg(ap,struct map_session_data*);
  4128. if (sd == NULL || !sd->fd)
  4129. return 0;
  4130. switch(bl->type){
  4131. case BL_ITEM:
  4132. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4133. break;
  4134. case BL_SKILL:
  4135. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF);
  4136. break;
  4137. default:
  4138. if(&sd->bl == bl)
  4139. break;
  4140. clif_getareachar_unit(sd,bl);
  4141. break;
  4142. }
  4143. return 0;
  4144. }
  4145. /*==========================================
  4146. * tbl has gone out of view-size of bl
  4147. *------------------------------------------*/
  4148. int clif_outsight(struct block_list *bl,va_list ap)
  4149. {
  4150. struct block_list *tbl;
  4151. struct view_data *vd;
  4152. TBL_PC *sd, *tsd;
  4153. tbl=va_arg(ap,struct block_list*);
  4154. if(bl == tbl) return 0;
  4155. sd = BL_CAST(BL_PC, bl);
  4156. tsd = BL_CAST(BL_PC, tbl);
  4157. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4158. nullpo_ret(bl);
  4159. switch(bl->type){
  4160. case BL_PC:
  4161. if(sd->vd.class_ != INVISIBLE_CLASS)
  4162. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4163. if(sd->chatID){
  4164. struct chat_data *cd;
  4165. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4166. if(cd->usersd[0]==sd)
  4167. clif_dispchat(cd,tsd->fd);
  4168. }
  4169. if(sd->state.vending)
  4170. clif_closevendingboard(bl,tsd->fd);
  4171. if(sd->state.buyingstore)
  4172. clif_buyingstore_disappear_entry_single(tsd, sd);
  4173. break;
  4174. case BL_ITEM:
  4175. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4176. break;
  4177. case BL_SKILL:
  4178. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4179. break;
  4180. case BL_NPC:
  4181. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4182. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4183. break;
  4184. default:
  4185. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4186. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4187. break;
  4188. }
  4189. }
  4190. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4191. nullpo_ret(tbl);
  4192. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4193. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4194. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4195. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4196. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4197. }
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. * tbl has come into view of bl
  4202. *------------------------------------------*/
  4203. int clif_insight(struct block_list *bl,va_list ap)
  4204. {
  4205. struct block_list *tbl;
  4206. TBL_PC *sd, *tsd;
  4207. tbl=va_arg(ap,struct block_list*);
  4208. if (bl == tbl) return 0;
  4209. sd = BL_CAST(BL_PC, bl);
  4210. tsd = BL_CAST(BL_PC, tbl);
  4211. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4212. switch(bl->type){
  4213. case BL_ITEM:
  4214. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4215. break;
  4216. case BL_SKILL:
  4217. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF);
  4218. break;
  4219. default:
  4220. clif_getareachar_unit(tsd,bl);
  4221. break;
  4222. }
  4223. }
  4224. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4225. clif_getareachar_unit(sd,tbl);
  4226. }
  4227. return 0;
  4228. }
  4229. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4230. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4231. void clif_skillinfoblock(struct map_session_data *sd)
  4232. {
  4233. int fd;
  4234. int i,len,id;
  4235. nullpo_retv(sd);
  4236. fd=sd->fd;
  4237. if (!fd) return;
  4238. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4239. WFIFOW(fd,0) = 0x10f;
  4240. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4241. {
  4242. if( (id = sd->status.skill[i].id) != 0 )
  4243. {
  4244. // workaround for bugreport:5348
  4245. if (len + 37 > 8192)
  4246. break;
  4247. WFIFOW(fd,len) = id;
  4248. WFIFOL(fd,len+2) = skill_get_inf(id);
  4249. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4250. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4251. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4252. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4253. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4254. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4255. else
  4256. WFIFOB(fd,len+36) = 0;
  4257. len += 37;
  4258. }
  4259. }
  4260. WFIFOW(fd,2)=len;
  4261. WFIFOSET(fd,len);
  4262. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4263. for ( ; i < MAX_SKILL; i++)
  4264. {
  4265. if( (id = sd->status.skill[i].id) != 0 )
  4266. {
  4267. clif_addskill(sd, id);
  4268. clif_skillinfo(sd, id, 0);
  4269. }
  4270. }
  4271. }
  4272. /**
  4273. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4274. **/
  4275. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4276. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4277. void clif_addskill(struct map_session_data *sd, int id)
  4278. {
  4279. int fd;
  4280. nullpo_retv(sd);
  4281. fd = sd->fd;
  4282. if (!fd) return;
  4283. if( sd->status.skill[id].id <= 0 )
  4284. return;
  4285. WFIFOHEAD(fd, packet_len(0x111));
  4286. WFIFOW(fd,0) = 0x111;
  4287. WFIFOW(fd,2) = id;
  4288. WFIFOL(fd,4) = skill_get_inf(id);
  4289. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4290. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4291. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4292. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4293. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4294. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4295. else
  4296. WFIFOB(fd,38) = 0;
  4297. WFIFOSET(fd,packet_len(0x111));
  4298. }
  4299. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4300. /// 0441 <skill id>.W
  4301. void clif_deleteskill(struct map_session_data *sd, int id)
  4302. {
  4303. #if PACKETVER >= 20081217
  4304. int fd;
  4305. nullpo_retv(sd);
  4306. fd = sd->fd;
  4307. if( !fd ) return;
  4308. WFIFOHEAD(fd,packet_len(0x441));
  4309. WFIFOW(fd,0) = 0x441;
  4310. WFIFOW(fd,2) = id;
  4311. WFIFOSET(fd,packet_len(0x441));
  4312. #endif
  4313. clif_skillinfoblock(sd);
  4314. }
  4315. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4316. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4317. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4318. int fd;
  4319. nullpo_retv(sd);
  4320. fd = sd->fd;
  4321. WFIFOHEAD(fd, packet_len(0x10e));
  4322. WFIFOW(fd, 0) = 0x10e;
  4323. WFIFOW(fd, 2) = skill_id;
  4324. WFIFOW(fd, 4) = lv;
  4325. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4326. WFIFOW(fd, 8) = range;
  4327. WFIFOB(fd, 10) = upgradable;
  4328. WFIFOSET(fd, packet_len(0x10e));
  4329. }
  4330. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4331. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4332. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4333. {
  4334. const int fd = sd->fd;
  4335. WFIFOHEAD(fd,packet_len(0x7e1));
  4336. WFIFOW(fd,0) = 0x7e1;
  4337. WFIFOW(fd,2) = skill;
  4338. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4339. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4340. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4341. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4342. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4343. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4344. else
  4345. WFIFOB(fd,14) = 0;
  4346. WFIFOSET(fd,packet_len(0x7e1));
  4347. }
  4348. /// Notifies clients in area, that an object is about to use a skill.
  4349. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4350. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4351. /// property:
  4352. /// 0 = Yellow cast aura
  4353. /// 1 = Water elemental cast aura
  4354. /// 2 = Earth elemental cast aura
  4355. /// 3 = Fire elemental cast aura
  4356. /// 4 = Wind elemental cast aura
  4357. /// 5 = Poison elemental cast aura
  4358. /// 6 = Holy elemental cast aura
  4359. /// ? = like 0
  4360. /// is disposable:
  4361. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4362. /// 1 = no text
  4363. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, int property, int casttime)
  4364. {
  4365. #if PACKETVER < 20091124
  4366. const int cmd = 0x13e;
  4367. #else
  4368. const int cmd = 0x7fb;
  4369. #endif
  4370. unsigned char buf[32];
  4371. WBUFW(buf,0) = cmd;
  4372. WBUFL(buf,2) = src_id;
  4373. WBUFL(buf,6) = dst_id;
  4374. WBUFW(buf,10) = dst_x;
  4375. WBUFW(buf,12) = dst_y;
  4376. WBUFW(buf,14) = skill_id;
  4377. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4378. WBUFL(buf,20) = casttime;
  4379. #if PACKETVER >= 20091124
  4380. WBUFB(buf,24) = 0; // isDisposable
  4381. #endif
  4382. if (disguised(bl)) {
  4383. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4384. WBUFL(buf,2) = -src_id;
  4385. clif_send(buf,packet_len(cmd), bl, SELF);
  4386. } else
  4387. clif_send(buf,packet_len(cmd), bl, AREA);
  4388. }
  4389. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4390. /// 01b9 <id>.L
  4391. void clif_skillcastcancel(struct block_list* bl)
  4392. {
  4393. unsigned char buf[16];
  4394. nullpo_retv(bl);
  4395. WBUFW(buf,0) = 0x1b9;
  4396. WBUFL(buf,2) = bl->id;
  4397. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4398. }
  4399. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4400. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4401. /// num (only used when skill id = NV_BASIC and cause = 0):
  4402. /// 0 = "skill failed" MsgStringTable[159]
  4403. /// 1 = "no emotions" MsgStringTable[160]
  4404. /// 2 = "no sit" MsgStringTable[161]
  4405. /// 3 = "no chat" MsgStringTable[162]
  4406. /// 4 = "no party" MsgStringTable[163]
  4407. /// 5 = "no shout" MsgStringTable[164]
  4408. /// 6 = "no PKing" MsgStringTable[165]
  4409. /// 7 = "no alligning" MsgStringTable[383]
  4410. /// ? = ignored
  4411. /// cause:
  4412. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4413. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4414. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4415. /// "skill failed" MsgStringTable[204] (otherwise)
  4416. /// ... = @see enum useskill_fail_cause
  4417. /// ? = ignored
  4418. ///
  4419. /// if(result!=0) doesn't display any of the previous messages
  4420. /// Note: when this packet is received an unknown flag is always set to 0,
  4421. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4422. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4423. {
  4424. int fd;
  4425. if (!sd) { //Since this is the most common nullpo....
  4426. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4427. return;
  4428. }
  4429. fd=sd->fd;
  4430. if (!fd) return;
  4431. if(battle_config.display_skill_fail&1)
  4432. return; //Disable all skill failed messages
  4433. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4434. return; //Disable delay failed messages
  4435. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4436. return;
  4437. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4438. return;
  4439. WFIFOHEAD(fd,packet_len(0x110));
  4440. WFIFOW(fd,0) = 0x110;
  4441. WFIFOW(fd,2) = skill_id;
  4442. WFIFOL(fd,4) = btype;
  4443. WFIFOB(fd,8) = 0;// success
  4444. WFIFOB(fd,9) = cause;
  4445. WFIFOSET(fd,packet_len(0x110));
  4446. }
  4447. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4448. /// 043d <skill ID>.W <tick>.L
  4449. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4450. {
  4451. #if PACKETVER>=20081112
  4452. int fd;
  4453. nullpo_retv(sd);
  4454. fd=sd->fd;
  4455. WFIFOHEAD(fd,packet_len(0x43d));
  4456. WFIFOW(fd,0) = 0x43d;
  4457. WFIFOW(fd,2) = skill_id;
  4458. WFIFOL(fd,4) = tick;
  4459. WFIFOSET(fd,packet_len(0x43d));
  4460. #endif
  4461. }
  4462. /// Skill attack effect and damage.
  4463. /// 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)
  4464. /// 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)
  4465. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4466. {
  4467. unsigned char buf[64];
  4468. struct status_change *sc;
  4469. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4470. nullpo_ret(src);
  4471. nullpo_ret(dst);
  4472. type = clif_calc_delay(type,div,damage,ddelay);
  4473. #if PACKETVER >= 20131223
  4474. if ( type == DMG_SKILL )
  4475. type = DMG_MULTI_HIT; /* Temporary Fix */
  4476. #endif
  4477. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4478. if(sc->data[SC_HALLUCINATION] && damage)
  4479. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4480. }
  4481. #if PACKETVER < 3
  4482. WBUFW(buf,0)=0x114;
  4483. WBUFW(buf,2)=skill_id;
  4484. WBUFL(buf,4)=src->id;
  4485. WBUFL(buf,8)=dst->id;
  4486. WBUFL(buf,12)=tick;
  4487. WBUFL(buf,16)=sdelay;
  4488. WBUFL(buf,20)=ddelay;
  4489. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4490. WBUFW(buf,24)=damage?div:0;
  4491. } else {
  4492. WBUFW(buf,24)=damage;
  4493. }
  4494. WBUFW(buf,26)=skill_lv;
  4495. WBUFW(buf,28)=div;
  4496. WBUFB(buf,30)=type;
  4497. if (disguised(dst)) {
  4498. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4499. WBUFL(buf,8)=-dst->id;
  4500. clif_send(buf,packet_len(0x114),dst,SELF);
  4501. } else
  4502. clif_send(buf,packet_len(0x114),dst,AREA);
  4503. if(disguised(src)) {
  4504. WBUFL(buf,4)=-src->id;
  4505. if (disguised(dst))
  4506. WBUFL(buf,8)=dst->id;
  4507. if(damage > 0)
  4508. WBUFW(buf,24)=-1;
  4509. clif_send(buf,packet_len(0x114),src,SELF);
  4510. }
  4511. #else
  4512. WBUFW(buf,0)=0x1de;
  4513. WBUFW(buf,2)=skill_id;
  4514. WBUFL(buf,4)=src->id;
  4515. WBUFL(buf,8)=dst->id;
  4516. WBUFL(buf,12)=tick;
  4517. WBUFL(buf,16)=sdelay;
  4518. WBUFL(buf,20)=ddelay;
  4519. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4520. WBUFL(buf,24)=damage?div:0;
  4521. } else {
  4522. WBUFL(buf,24)=damage;
  4523. }
  4524. WBUFW(buf,28)=skill_lv;
  4525. WBUFW(buf,30)=div;
  4526. WBUFB(buf,32)=type;
  4527. if (disguised(dst)) {
  4528. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4529. WBUFL(buf,8)=-dst->id;
  4530. clif_send(buf,packet_len(0x1de),dst,SELF);
  4531. } else
  4532. clif_send(buf,packet_len(0x1de),dst,AREA);
  4533. if(disguised(src)) {
  4534. WBUFL(buf,4)=-src->id;
  4535. if (disguised(dst))
  4536. WBUFL(buf,8)=dst->id;
  4537. if(damage > 0)
  4538. WBUFL(buf,24)=-1;
  4539. clif_send(buf,packet_len(0x1de),src,SELF);
  4540. }
  4541. #endif
  4542. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4543. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4544. }
  4545. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4546. /// 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
  4547. /*
  4548. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4549. {
  4550. unsigned char buf[64];
  4551. struct status_change *sc;
  4552. nullpo_ret(src);
  4553. nullpo_ret(dst);
  4554. type = (type>0)?type:skill_get_hit(skill_id);
  4555. type = clif_calc_delay(type,div,damage,ddelay);
  4556. sc = status_get_sc(dst);
  4557. if(sc && sc->count) {
  4558. if(sc->data[SC_HALLUCINATION] && damage)
  4559. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4560. }
  4561. WBUFW(buf,0)=0x115;
  4562. WBUFW(buf,2)=skill_id;
  4563. WBUFL(buf,4)=src->id;
  4564. WBUFL(buf,8)=dst->id;
  4565. WBUFL(buf,12)=tick;
  4566. WBUFL(buf,16)=sdelay;
  4567. WBUFL(buf,20)=ddelay;
  4568. WBUFW(buf,24)=dst->x;
  4569. WBUFW(buf,26)=dst->y;
  4570. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4571. WBUFW(buf,28)=damage?div:0;
  4572. } else {
  4573. WBUFW(buf,28)=damage;
  4574. }
  4575. WBUFW(buf,30)=skill_lv;
  4576. WBUFW(buf,32)=div;
  4577. WBUFB(buf,34)=type;
  4578. clif_send(buf,packet_len(0x115),src,AREA);
  4579. if(disguised(src)) {
  4580. WBUFL(buf,4)=-src->id;
  4581. if(damage > 0)
  4582. WBUFW(buf,28)=-1;
  4583. clif_send(buf,packet_len(0x115),src,SELF);
  4584. }
  4585. if (disguised(dst)) {
  4586. WBUFL(buf,8)=-dst->id;
  4587. if (disguised(src))
  4588. WBUFL(buf,4)=src->id;
  4589. else if(damage > 0)
  4590. WBUFW(buf,28)=-1;
  4591. clif_send(buf,packet_len(0x115),dst,SELF);
  4592. }
  4593. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4594. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4595. }
  4596. */
  4597. /// Non-damaging skill effect (ZC_USE_SKILL).
  4598. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4599. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4600. {
  4601. unsigned char buf[32];
  4602. nullpo_ret(dst);
  4603. WBUFW(buf,0)=0x11a;
  4604. WBUFW(buf,2)=skill_id;
  4605. WBUFW(buf,4)=min(heal, INT16_MAX);
  4606. WBUFL(buf,6)=dst->id;
  4607. WBUFL(buf,10)=src?src->id:0;
  4608. WBUFB(buf,14)=fail;
  4609. if (disguised(dst)) {
  4610. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4611. WBUFL(buf,6)=-dst->id;
  4612. clif_send(buf,packet_len(0x11a),dst,SELF);
  4613. } else
  4614. clif_send(buf,packet_len(0x11a),dst,AREA);
  4615. if(src && disguised(src)) {
  4616. WBUFL(buf,10)=-src->id;
  4617. if (disguised(dst))
  4618. WBUFL(buf,6)=dst->id;
  4619. clif_send(buf,packet_len(0x11a),src,SELF);
  4620. }
  4621. return fail;
  4622. }
  4623. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4624. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4625. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4626. {
  4627. unsigned char buf[32];
  4628. nullpo_retv(src);
  4629. WBUFW(buf,0)=0x117;
  4630. WBUFW(buf,2)=skill_id;
  4631. WBUFL(buf,4)=src->id;
  4632. WBUFW(buf,8)=val;
  4633. WBUFW(buf,10)=x;
  4634. WBUFW(buf,12)=y;
  4635. WBUFL(buf,14)=tick;
  4636. if(disguised(src)) {
  4637. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4638. WBUFL(buf,4)=-src->id;
  4639. clif_send(buf,packet_len(0x117),src,SELF);
  4640. } else
  4641. clif_send(buf,packet_len(0x117),src,AREA);
  4642. }
  4643. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4644. /// 011c <skill id>.W { <map name>.16B }*4
  4645. void clif_skill_warppoint(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4646. {
  4647. int fd;
  4648. nullpo_retv(sd);
  4649. fd = sd->fd;
  4650. WFIFOHEAD(fd,packet_len(0x11c));
  4651. WFIFOW(fd,0) = 0x11c;
  4652. WFIFOW(fd,2) = skill_id;
  4653. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4654. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4655. else // normal map name
  4656. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4657. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4658. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4659. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4660. WFIFOSET(fd,packet_len(0x11c));
  4661. sd->menuskill_id = skill_id;
  4662. if (skill_id == AL_WARP)
  4663. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4664. else
  4665. sd->menuskill_val = skill_lv;
  4666. }
  4667. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4668. /// 011e <type>.B
  4669. /// type:
  4670. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4671. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4672. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4673. ///
  4674. /// @param sd Who receives the message
  4675. /// @param type What message
  4676. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4677. {
  4678. int fd;
  4679. nullpo_retv(sd);
  4680. fd=sd->fd;
  4681. WFIFOHEAD(fd,packet_len(0x11e));
  4682. WFIFOW(fd,0)=0x11e;
  4683. WFIFOB(fd,2)=type;
  4684. WFIFOSET(fd,packet_len(0x11e));
  4685. }
  4686. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4687. /// 0189 <type>.W
  4688. /// type:
  4689. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4690. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4691. ///
  4692. /// @param sd Who receives the message
  4693. /// @param type What message
  4694. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4695. {
  4696. int fd;
  4697. nullpo_retv(sd);
  4698. fd=sd->fd;
  4699. WFIFOHEAD(fd,packet_len(0x189));
  4700. WFIFOW(fd,0)=0x189;
  4701. WFIFOW(fd,2)=type;
  4702. WFIFOSET(fd,packet_len(0x189));
  4703. }
  4704. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4705. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4706. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4707. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4708. {
  4709. struct status_data *status;
  4710. unsigned char buf[64];
  4711. int i;//, fix;
  4712. nullpo_retv(sd);
  4713. nullpo_retv(dst);
  4714. if( dst->type != BL_MOB )
  4715. return;
  4716. status = status_get_status_data(dst);
  4717. WBUFW(buf, 0)=0x18c;
  4718. WBUFW(buf, 2)=status_get_class(dst);
  4719. WBUFW(buf, 4)=status_get_lv(dst);
  4720. WBUFW(buf, 6)=status->size;
  4721. WBUFL(buf, 8)=status->hp;
  4722. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4723. +(battle_config.estimation_type&2?status->def2:0);
  4724. WBUFW(buf,14)=status->race;
  4725. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4726. +(battle_config.estimation_type&2?status->mdef2:0);
  4727. WBUFW(buf,18)= status->def_ele;
  4728. for(i=0;i<9;i++)
  4729. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4730. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4731. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4732. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4733. }
  4734. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4735. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4736. /// material id:
  4737. /// unused by the client
  4738. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4739. {
  4740. int i,c,view,fd;
  4741. nullpo_retv(sd);
  4742. if (sd->menuskill_id == skill_id)
  4743. return; //Avoid resending the menu twice or more times...
  4744. if (skill_id == GC_CREATENEWPOISON)
  4745. skill_id = GC_RESEARCHNEWPOISON;
  4746. fd = sd->fd;
  4747. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4748. WFIFOW(fd, 0) = 0x18d;
  4749. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  4750. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4751. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  4752. )
  4753. {
  4754. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4755. WFIFOW(fd,c*8+ 4) = view;
  4756. else
  4757. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  4758. WFIFOW(fd,c*8+ 6) = 0;
  4759. WFIFOW(fd,c*8+ 8) = 0;
  4760. WFIFOW(fd,c*8+10) = 0;
  4761. c++;
  4762. }
  4763. }
  4764. WFIFOW(fd, 2) = c*8+8;
  4765. WFIFOSET(fd,WFIFOW(fd,2));
  4766. if (c > 0) {
  4767. sd->menuskill_id = skill_id;
  4768. sd->menuskill_val = trigger;
  4769. return;
  4770. }
  4771. }
  4772. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4773. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4774. /// mk type:
  4775. /// 1 = cooking
  4776. /// 2 = arrow
  4777. /// 3 = elemental
  4778. /// 4 = GN_MIX_COOKING
  4779. /// 5 = GN_MAKEBOMB
  4780. /// 6 = GN_S_PHARMACY
  4781. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4782. {
  4783. int fd;
  4784. int i, c;
  4785. int view;
  4786. nullpo_retv(sd);
  4787. fd = sd->fd;
  4788. if(sd->menuskill_id == skill_id)
  4789. return; //Avoid resending the menu twice or more times...
  4790. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4791. WFIFOW(fd,0) = 0x25a;
  4792. WFIFOW(fd,4) = list_type; // list type
  4793. c = 0;
  4794. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4795. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4796. continue;
  4797. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4798. WFIFOW(fd, 6 + 2 * c) = view;
  4799. else
  4800. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4801. c++;
  4802. }
  4803. if( c > 0 || skill_id == AM_PHARMACY) {
  4804. sd->menuskill_id = skill_id;
  4805. sd->menuskill_val = trigger;
  4806. sd->menuskill_val2 = qty; // amount.
  4807. WFIFOW(fd,2) = 6 + 2 * c;
  4808. WFIFOSET(fd,WFIFOW(fd,2));
  4809. } else {
  4810. clif_menuskill_clear(sd);
  4811. #if PACKETVER >= 20090922
  4812. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  4813. #else
  4814. WFIFOW(fd,2) = 6 + 2 * c;
  4815. WFIFOSET(fd,WFIFOW(fd,2));
  4816. #endif
  4817. }
  4818. }
  4819. /// Notifies clients of a status change.
  4820. /// 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)]
  4821. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4822. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  4823. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4824. {
  4825. unsigned char buf[32];
  4826. struct map_session_data *sd;
  4827. if (type == SI_BLANK) //It shows nothing on the client...
  4828. return;
  4829. nullpo_retv(bl);
  4830. sd = BL_CAST(BL_PC, bl);
  4831. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4832. return;
  4833. #if PACKETVER >= 20120618
  4834. if(flag && battle_config.display_status_timers && sd)
  4835. WBUFW(buf,0)=0x983;
  4836. else
  4837. #elif PACKETVER >= 20090121
  4838. if(flag && battle_config.display_status_timers && sd)
  4839. WBUFW(buf,0)=0x43f;
  4840. else
  4841. #endif
  4842. WBUFW(buf,0)=0x196;
  4843. WBUFW(buf,2)=type;
  4844. WBUFL(buf,4)=bl->id;
  4845. WBUFB(buf,8)=flag;
  4846. #if PACKETVER >= 20120618
  4847. if(flag && battle_config.display_status_timers && sd) {
  4848. if (tick <= 0)
  4849. tick = 9999; // this is indeed what official servers do
  4850. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4851. WBUFL(buf,13)=tick;
  4852. WBUFL(buf,17) = val1;
  4853. WBUFL(buf,21) = val2;
  4854. WBUFL(buf,25) = val3;
  4855. }
  4856. #elif PACKETVER >= 20090121
  4857. if(flag && battle_config.display_status_timers && sd) {
  4858. if (tick <= 0)
  4859. tick = 9999; // this is indeed what official servers do
  4860. WBUFL(buf,9) = tick;
  4861. WBUFL(buf,13) = val1;
  4862. WBUFL(buf,17) = val2;
  4863. WBUFL(buf,21) = val3;
  4864. }
  4865. #endif
  4866. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4867. }
  4868. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  4869. unsigned char buf[32];
  4870. if (type == SI_BLANK) //It shows nothing on the client
  4871. return;
  4872. nullpo_retv(bl);
  4873. WBUFW(buf,0) = 0x43f;
  4874. WBUFW(buf,2) = type;
  4875. WBUFL(buf,4) = tid;
  4876. WBUFB(buf,8) = 1;
  4877. WBUFL(buf,9) = 9999;
  4878. WBUFL(buf,13) = val1;
  4879. WBUFL(buf,17) = val2;
  4880. WBUFL(buf,21) = val3;
  4881. clif_send(buf,packet_len(0x43f),bl,target);
  4882. }
  4883. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  4884. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  4885. //! TODO
  4886. //void clif_efst_enter();
  4887. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4888. /// 008e <packet len>.W <message>.?B
  4889. void clif_displaymessage(const int fd, const char* mes)
  4890. {
  4891. nullpo_retv(mes);
  4892. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4893. if (fd == 0)
  4894. ;
  4895. else {
  4896. char *message, *line;
  4897. message = aStrdup(mes);
  4898. line = strtok(message, "\n");
  4899. while(line != NULL) {
  4900. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4901. int len = strnlen(line, 255);
  4902. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4903. WFIFOHEAD(fd, 5 + len);
  4904. WFIFOW(fd,0) = 0x8e;
  4905. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4906. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4907. WFIFOSET(fd, 5 + len);
  4908. }
  4909. line = strtok(NULL, "\n");
  4910. }
  4911. aFree(message);
  4912. }
  4913. }
  4914. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4915. /// 009a <packet len>.W <message>.?B
  4916. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4917. {
  4918. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  4919. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4920. WBUFW(buf,0) = 0x9a;
  4921. WBUFW(buf,2) = 4 + lp + len;
  4922. if (type&BC_BLUE)
  4923. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4924. else if (type&BC_WOE)
  4925. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4926. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4927. clif_send(buf, WBUFW(buf,2), bl, target);
  4928. if (buf)
  4929. aFree(buf);
  4930. }
  4931. /*==========================================
  4932. * Displays a message on a 'bl' to all it's nearby clients
  4933. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4934. *------------------------------------------*/
  4935. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4936. char buf[100];
  4937. int len;
  4938. nullpo_retv(bl);
  4939. if(!message)
  4940. return;
  4941. len = strlen(message)+1;
  4942. if( len > sizeof(buf)-8 ) {
  4943. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4944. len = sizeof(buf)-8;
  4945. }
  4946. WBUFW(buf,0)=0x8d;
  4947. WBUFW(buf,2)=len+8;
  4948. WBUFL(buf,4)=bl->id;
  4949. safestrncpy((char *) WBUFP(buf,8),message,len);
  4950. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4951. }
  4952. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4953. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4954. 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)
  4955. {
  4956. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4957. WBUFW(buf,0) = 0x1c3;
  4958. WBUFW(buf,2) = len + 16;
  4959. WBUFL(buf,4) = fontColor;
  4960. WBUFW(buf,8) = fontType;
  4961. WBUFW(buf,10) = fontSize;
  4962. WBUFW(buf,12) = fontAlign;
  4963. WBUFW(buf,14) = fontY;
  4964. memcpy(WBUFP(buf,16), mes, len);
  4965. clif_send(buf, WBUFW(buf,2), bl, target);
  4966. if (buf)
  4967. aFree(buf);
  4968. }
  4969. /*
  4970. * Display *msg from *sd to all *users in channel
  4971. */
  4972. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4973. DBIterator *iter;
  4974. struct map_session_data *user;
  4975. unsigned short msg_len = strlen(msg) + 1;
  4976. WFIFOHEAD(sd->fd,msg_len + 12);
  4977. WFIFOW(sd->fd,0) = 0x2C1;
  4978. WFIFOW(sd->fd,2) = msg_len + 12;
  4979. WFIFOL(sd->fd,4) = 0;
  4980. WFIFOL(sd->fd,8) = channel_config.colors[color];
  4981. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4982. iter = db_iterator(channel->users);
  4983. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4984. if( user->fd == sd->fd )
  4985. continue;
  4986. WFIFOHEAD(user->fd,msg_len + 12);
  4987. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4988. WFIFOSET(user->fd, msg_len + 12);
  4989. }
  4990. dbi_destroy(iter);
  4991. WFIFOSET(sd->fd, msg_len + 12);
  4992. }
  4993. /// Displays heal effect (ZC_RECOVERY).
  4994. /// 013d <var id>.W <amount>.W
  4995. /// var id:
  4996. /// 5 = HP (SP_HP)
  4997. /// 7 = SP (SP_SP)
  4998. /// ? = ignored
  4999. void clif_heal(int fd,int type,int val)
  5000. {
  5001. WFIFOHEAD(fd,packet_len(0x13d));
  5002. WFIFOW(fd,0)=0x13d;
  5003. WFIFOW(fd,2)=type;
  5004. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  5005. WFIFOSET(fd,packet_len(0x13d));
  5006. }
  5007. /// Displays resurrection effect (ZC_RESURRECTION).
  5008. /// 0148 <id>.L <type>.W
  5009. /// type:
  5010. /// ignored
  5011. void clif_resurrection(struct block_list *bl,int type)
  5012. {
  5013. unsigned char buf[16];
  5014. nullpo_retv(bl);
  5015. WBUFW(buf,0)=0x148;
  5016. WBUFL(buf,2)=bl->id;
  5017. WBUFW(buf,6)=0;
  5018. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5019. if (disguised(bl))
  5020. clif_spawn(bl);
  5021. }
  5022. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5023. /// 0199 <type>.W
  5024. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5025. {
  5026. int fd;
  5027. nullpo_retv(sd);
  5028. fd=sd->fd;
  5029. WFIFOHEAD(fd,packet_len(0x199));
  5030. WFIFOW(fd,0)=0x199;
  5031. WFIFOW(fd,2)=property;
  5032. WFIFOSET(fd,packet_len(0x199));
  5033. }
  5034. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5035. #if PACKETVER >= 20121010
  5036. unsigned char buf[8];
  5037. unsigned int NotifyProperty =
  5038. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5039. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5040. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5041. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5042. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5043. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5044. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5045. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5046. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5047. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5048. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5049. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5050. WBUFW(buf,0)=0x99b;
  5051. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5052. WBUFL(buf,4)=NotifyProperty;
  5053. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5054. clif_send(buf,packet_len(0x99b),bl,t);
  5055. #endif
  5056. }
  5057. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5058. /// 01d6 <type>.W
  5059. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5060. {
  5061. int fd;
  5062. nullpo_retv(sd);
  5063. fd=sd->fd;
  5064. WFIFOHEAD(fd,packet_len(0x1D6));
  5065. WFIFOW(fd,0)=0x1D6;
  5066. WFIFOW(fd,2)=type;
  5067. WFIFOSET(fd,packet_len(0x1D6));
  5068. }
  5069. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5070. /// 019a <id>.L <ranking>.L <total>.L
  5071. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5072. {
  5073. if(type == 2) {
  5074. int fd = sd->fd;
  5075. WFIFOHEAD(fd,packet_len(0x19a));
  5076. WFIFOW(fd,0) = 0x19a;
  5077. WFIFOL(fd,2) = sd->bl.id;
  5078. WFIFOL(fd,6) = pvprank;
  5079. WFIFOL(fd,10) = pvpnum;
  5080. WFIFOSET(fd,packet_len(0x19a));
  5081. } else {
  5082. unsigned char buf[32];
  5083. WBUFW(buf,0) = 0x19a;
  5084. WBUFL(buf,2) = sd->bl.id;
  5085. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5086. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5087. else
  5088. WBUFL(buf,6) = pvprank;
  5089. WBUFL(buf,10) = pvpnum;
  5090. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5091. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5092. else if(!type)
  5093. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5094. else
  5095. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5096. }
  5097. }
  5098. /*==========================================
  5099. *
  5100. *------------------------------------------*/
  5101. void clif_map_property_mapall(int map_idx, enum map_property property)
  5102. {
  5103. struct block_list bl;
  5104. unsigned char buf[16];
  5105. bl.id = 0;
  5106. bl.type = BL_NUL;
  5107. bl.m = map_idx;
  5108. WBUFW(buf,0)=0x199;
  5109. WBUFW(buf,2)=property;
  5110. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5111. }
  5112. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5113. /// 0188 <result>.W <index>.W <refine>.W
  5114. /// result:
  5115. /// 0 = success
  5116. /// 1 = failure
  5117. /// 2 = downgrade
  5118. void clif_refine(int fd, int fail, int index, int val)
  5119. {
  5120. WFIFOHEAD(fd,packet_len(0x188));
  5121. WFIFOW(fd,0)=0x188;
  5122. WFIFOW(fd,2)=fail;
  5123. WFIFOW(fd,4)=index+2;
  5124. WFIFOW(fd,6)=val;
  5125. WFIFOSET(fd,packet_len(0x188));
  5126. }
  5127. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5128. /// 0223 <result>.L <nameid>.W
  5129. /// result:
  5130. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5131. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5132. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5133. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5134. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5135. {
  5136. WFIFOHEAD(fd,packet_len(0x223));
  5137. WFIFOW(fd,0)=0x223;
  5138. WFIFOL(fd,2)=result;
  5139. WFIFOW(fd,6)=item_id;
  5140. WFIFOSET(fd,packet_len(0x223));
  5141. }
  5142. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5143. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5144. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5145. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5146. {
  5147. #if PACKETVER < 20091104
  5148. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5149. WFIFOW(fd,0) = 0x97;
  5150. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5151. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5152. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5153. WFIFOSET(fd,WFIFOW(fd,2));
  5154. #else
  5155. struct map_session_data *ssd = map_nick2sd(nick);
  5156. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5157. WFIFOW(fd,0) = 0x97;
  5158. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5159. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5160. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5161. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5162. WFIFOSET(fd,WFIFOW(fd,2));
  5163. #endif
  5164. }
  5165. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5166. /// 0098 <result>.B
  5167. /// result:
  5168. /// 0 = success to send wisper
  5169. /// 1 = target character is not loged in
  5170. /// 2 = ignored by target
  5171. /// 3 = everyone ignored by target
  5172. void clif_wis_end(int fd, int result)
  5173. {
  5174. struct map_session_data *sd = (session_isValid(fd) ? session[fd]->session_data : NULL);
  5175. if (!sd)
  5176. return;
  5177. #if PACKETVER >= 20131223
  5178. WFIFOHEAD(fd,packet_len(0x9df));
  5179. WFIFOW(fd,0) = 0x9df;
  5180. WFIFOB(fd,2) = (char)result;
  5181. WFIFOL(fd,3) = 0;
  5182. WFIFOSET(fd,packet_len(0x9df));
  5183. #else
  5184. WFIFOHEAD(fd,packet_len(0x98));
  5185. WFIFOW(fd,0) = 0x98;
  5186. WFIFOB(fd,2) = (char)result;
  5187. WFIFOSET(fd,packet_len(0x98));
  5188. #endif
  5189. }
  5190. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5191. /// 0194 <char id>.L <name>.24B
  5192. void clif_solved_charname(int fd, int charid, const char* name)
  5193. {
  5194. WFIFOHEAD(fd,packet_len(0x194));
  5195. WFIFOW(fd,0)=0x194;
  5196. WFIFOL(fd,2)=charid;
  5197. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5198. WFIFOSET(fd,packet_len(0x194));
  5199. }
  5200. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5201. /// 017b <packet len>.W { <name id>.W }*
  5202. void clif_use_card(struct map_session_data *sd,int idx)
  5203. {
  5204. int i,c,ep;
  5205. int fd=sd->fd;
  5206. nullpo_retv(sd);
  5207. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5208. return;
  5209. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5210. return; //Avoid parsing invalid item indexes (no card/no item)
  5211. ep=sd->inventory_data[idx]->equip;
  5212. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5213. WFIFOW(fd,0)=0x17b;
  5214. for(i=c=0;i<MAX_INVENTORY;i++){
  5215. int j;
  5216. if(sd->inventory_data[i] == NULL)
  5217. continue;
  5218. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5219. continue;
  5220. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5221. continue;
  5222. if(sd->status.inventory[i].identify==0 ) //Not identified
  5223. continue;
  5224. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5225. continue;
  5226. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5227. continue;
  5228. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5229. if( j == sd->inventory_data[i]->slot ) // No room
  5230. continue;
  5231. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5232. continue;
  5233. WFIFOW(fd,4+c*2)=i+2;
  5234. c++;
  5235. }
  5236. if( !c ) return; // no item is available for card insertion
  5237. WFIFOW(fd,2)=4+c*2;
  5238. WFIFOSET(fd,WFIFOW(fd,2));
  5239. }
  5240. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5241. /// 017d <equip index>.W <card index>.W <result>.B
  5242. /// result:
  5243. /// 0 = success
  5244. /// 1 = failure
  5245. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5246. {
  5247. int fd;
  5248. nullpo_retv(sd);
  5249. fd=sd->fd;
  5250. WFIFOHEAD(fd,packet_len(0x17d));
  5251. WFIFOW(fd,0)=0x17d;
  5252. WFIFOW(fd,2)=idx_equip+2;
  5253. WFIFOW(fd,4)=idx_card+2;
  5254. WFIFOB(fd,6)=flag;
  5255. WFIFOSET(fd,packet_len(0x17d));
  5256. }
  5257. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5258. /// 0177 <packet len>.W { <name id>.W }*
  5259. void clif_item_identify_list(struct map_session_data *sd)
  5260. {
  5261. int i,c;
  5262. int fd;
  5263. nullpo_retv(sd);
  5264. fd=sd->fd;
  5265. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5266. WFIFOW(fd,0)=0x177;
  5267. for(i=c=0;i<MAX_INVENTORY;i++){
  5268. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5269. WFIFOW(fd,c*2+4)=i+2;
  5270. c++;
  5271. }
  5272. }
  5273. if(c > 0) {
  5274. WFIFOW(fd,2)=c*2+4;
  5275. WFIFOSET(fd,WFIFOW(fd,2));
  5276. sd->menuskill_id = MC_IDENTIFY;
  5277. sd->menuskill_val = c;
  5278. }
  5279. }
  5280. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5281. /// 0179 <index>.W <result>.B
  5282. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5283. {
  5284. int fd;
  5285. nullpo_retv(sd);
  5286. fd=sd->fd;
  5287. WFIFOHEAD(fd,packet_len(0x179));
  5288. WFIFOW(fd, 0)=0x179;
  5289. WFIFOW(fd, 2)=idx+2;
  5290. WFIFOB(fd, 4)=flag;
  5291. WFIFOSET(fd,packet_len(0x179));
  5292. }
  5293. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5294. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5295. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5296. {
  5297. int i,c;
  5298. int fd;
  5299. nullpo_retv(sd);
  5300. nullpo_retv(dstsd);
  5301. fd=sd->fd;
  5302. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5303. WFIFOW(fd,0)=0x1fc;
  5304. for(i=c=0;i<MAX_INVENTORY;i++){
  5305. unsigned short nameid;
  5306. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5307. WFIFOW(fd,c*13+4) = i;
  5308. WFIFOW(fd,c*13+6) = nameid;
  5309. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5310. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5311. c++;
  5312. }
  5313. }
  5314. if(c > 0) {
  5315. WFIFOW(fd,2)=c*13+4;
  5316. WFIFOSET(fd,WFIFOW(fd,2));
  5317. sd->menuskill_id = BS_REPAIRWEAPON;
  5318. sd->menuskill_val = dstsd->bl.id;
  5319. sd->menuskill_val2 = lv;
  5320. }else
  5321. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5322. }
  5323. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5324. /// 01fe <index>.W <result>.B
  5325. /// index:
  5326. /// ignored (inventory index)
  5327. /// result:
  5328. /// 0 = Item repair success.
  5329. /// 1 = Item repair failure.
  5330. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5331. {
  5332. int fd;
  5333. nullpo_retv(sd);
  5334. fd = sd->fd;
  5335. WFIFOHEAD(fd,packet_len(0x1fe));
  5336. WFIFOW(fd, 0)=0x1fe;
  5337. WFIFOW(fd, 2)=idx+2;
  5338. WFIFOB(fd, 4)=flag;
  5339. WFIFOSET(fd,packet_len(0x1fe));
  5340. }
  5341. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5342. /// 02bb <equip location>.W <account id>.L
  5343. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5344. {
  5345. int fd = sd->fd;
  5346. WFIFOHEAD(fd,packet_len(0x2bb));
  5347. WFIFOW(fd,0) = 0x2bb;
  5348. WFIFOW(fd,2) = position;
  5349. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5350. WFIFOSET(fd,packet_len(0x2bb));
  5351. }
  5352. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5353. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5354. void clif_item_refine_list(struct map_session_data *sd)
  5355. {
  5356. int i,c;
  5357. int fd;
  5358. uint16 skill_lv;
  5359. int refine_item[5];
  5360. nullpo_retv(sd);
  5361. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5362. fd=sd->fd;
  5363. refine_item[0] = -1;
  5364. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5365. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5366. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5367. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5368. WFIFOW(fd,0)=0x221;
  5369. for(i=c=0;i<MAX_INVENTORY;i++){
  5370. unsigned char wlv;
  5371. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5372. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5373. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5374. WFIFOW(fd,c*13+ 4)=i+2;
  5375. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5376. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5377. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5378. c++;
  5379. }
  5380. }
  5381. WFIFOW(fd,2)=c*13+4;
  5382. WFIFOSET(fd,WFIFOW(fd,2));
  5383. if (c > 0) {
  5384. sd->menuskill_id = WS_WEAPONREFINE;
  5385. sd->menuskill_val = skill_lv;
  5386. }
  5387. }
  5388. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5389. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5390. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5391. {
  5392. int fd;
  5393. nullpo_retv(sd);
  5394. fd=sd->fd;
  5395. WFIFOHEAD(fd,packet_len(0x147));
  5396. WFIFOW(fd, 0)=0x147;
  5397. WFIFOW(fd, 2)=skill_id;
  5398. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5399. WFIFOW(fd, 6)=0;
  5400. WFIFOW(fd, 8)=skill_lv;
  5401. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5402. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5403. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5404. WFIFOB(fd,38)=0;
  5405. WFIFOSET(fd,packet_len(0x147));
  5406. }
  5407. /// Adds an item to character's cart.
  5408. /// 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)
  5409. /// 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)
  5410. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5411. {
  5412. int view,fd;
  5413. unsigned char *buf;
  5414. nullpo_retv(sd);
  5415. fd=sd->fd;
  5416. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5417. return;
  5418. #if PACKETVER < 5
  5419. WFIFOHEAD(fd,packet_len(0x124));
  5420. buf=WFIFOP(fd,0);
  5421. WBUFW(buf,0)=0x124;
  5422. WBUFW(buf,2)=n+2;
  5423. WBUFL(buf,4)=amount;
  5424. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5425. WBUFW(buf,8)=view;
  5426. else
  5427. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5428. WBUFB(buf,10)=sd->status.cart[n].identify;
  5429. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5430. WBUFB(buf,12)=sd->status.cart[n].refine;
  5431. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5432. WFIFOSET(fd,packet_len(0x124));
  5433. #else
  5434. WFIFOHEAD(fd,packet_len(0x1c5));
  5435. buf=WFIFOP(fd,0);
  5436. WBUFW(buf,0)=0x1c5;
  5437. WBUFW(buf,2)=n+2;
  5438. WBUFL(buf,4)=amount;
  5439. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5440. WBUFW(buf,8)=view;
  5441. else
  5442. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5443. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5444. WBUFB(buf,11)=sd->status.cart[n].identify;
  5445. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5446. WBUFB(buf,13)=sd->status.cart[n].refine;
  5447. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5448. WFIFOSET(fd,packet_len(0x1c5));
  5449. #endif
  5450. }
  5451. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5452. /* Acknowledge an item have been added to cart
  5453. * 012c <result>B
  5454. * result :
  5455. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5456. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5457. */
  5458. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5459. {
  5460. int fd;
  5461. unsigned char *buf;
  5462. nullpo_retv(sd);
  5463. fd = sd->fd;
  5464. buf = WFIFOP(fd,0);
  5465. WBUFW(buf,0) = 0x12c;
  5466. WBUFB(buf,2) = flag;
  5467. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5468. }
  5469. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5470. void clif_bank_open(struct map_session_data *sd){
  5471. int fd;
  5472. nullpo_retv(sd);
  5473. fd = sd->fd;
  5474. WFIFOHEAD(fd,4);
  5475. WFIFOW(fd,0) = 0x09b7;
  5476. WFIFOW(fd,2) = 0;
  5477. WFIFOSET(fd,4);
  5478. }
  5479. /*
  5480. * Request to Open the banking system
  5481. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5482. */
  5483. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5484. //TODO check if preventing trade or stuff like that
  5485. //also mark something in case char ain't available for saving, should we check now ?
  5486. nullpo_retv(sd);
  5487. if( !battle_config.feature_banking ) {
  5488. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5489. return;
  5490. }
  5491. else {
  5492. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5493. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5494. if(sd->status.account_id == aid){
  5495. sd->state.banking = 1;
  5496. //request save ?
  5497. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5498. //on succes open bank ?
  5499. clif_bank_open(sd);
  5500. }
  5501. }
  5502. }
  5503. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5504. void clif_bank_close(struct map_session_data *sd){
  5505. int fd;
  5506. nullpo_retv(sd);
  5507. fd = sd->fd;
  5508. WFIFOHEAD(fd,4);
  5509. WFIFOW(fd,0) = 0x09B9;
  5510. WFIFOW(fd,2) = 0;
  5511. WFIFOSET(fd,4);
  5512. }
  5513. /*
  5514. * Request to close the banking system
  5515. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5516. */
  5517. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5518. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5519. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5520. nullpo_retv(sd);
  5521. if( !battle_config.feature_banking ) {
  5522. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5523. //still allow to go trough to not stuck player if we have disable it while they was in
  5524. }
  5525. if(sd->status.account_id == aid){
  5526. sd->state.banking = 0;
  5527. clif_bank_close(sd);
  5528. }
  5529. }
  5530. /*
  5531. * Display how much we got in bank (I suppose)
  5532. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5533. */
  5534. void clif_Bank_Check(struct map_session_data* sd) {
  5535. unsigned char buf[13];
  5536. struct s_packet_db* info;
  5537. int16 len;
  5538. int cmd = 0;
  5539. nullpo_retv(sd);
  5540. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5541. if(!cmd) cmd = 0x09A6; //default
  5542. info = &packet_db[sd->packet_ver][cmd];
  5543. len = info->len;
  5544. if(!len) return; //version as packet disable
  5545. // sd->state.banking = 1; //mark opening and closing
  5546. WBUFW(buf,0) = cmd;
  5547. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5548. WBUFW(buf,info->pos[1]) = 0; //reason
  5549. clif_send(buf,len,&sd->bl,SELF);
  5550. }
  5551. /*
  5552. * Requesting the data in bank
  5553. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5554. */
  5555. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5556. nullpo_retv(sd);
  5557. if( !battle_config.feature_banking ) {
  5558. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5559. return;
  5560. }
  5561. else {
  5562. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5563. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5564. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5565. clif_Bank_Check(sd);
  5566. }
  5567. }
  5568. /*
  5569. * Acknowledge of deposit some money in bank
  5570. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5571. */
  5572. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5573. unsigned char buf[17];
  5574. struct s_packet_db* info;
  5575. int16 len;
  5576. int cmd =0;
  5577. nullpo_retv(sd);
  5578. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5579. if(!cmd) cmd = 0x09A8;
  5580. info = &packet_db[sd->packet_ver][cmd];
  5581. len = info->len;
  5582. if(!len) return; //version as packet disable
  5583. WBUFW(buf,0) = cmd;
  5584. WBUFW(buf,info->pos[0]) = (short)reason;
  5585. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5586. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5587. clif_send(buf,len,&sd->bl,SELF);
  5588. }
  5589. /*
  5590. * Request saving some money in bank
  5591. * @author : original [Yommy/Hercules]
  5592. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5593. */
  5594. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5595. nullpo_retv(sd);
  5596. if( !battle_config.feature_banking ) {
  5597. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5598. return;
  5599. }
  5600. else {
  5601. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5602. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5603. int money = RFIFOL(fd,info->pos[1]);
  5604. if(sd->status.account_id == aid){
  5605. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5606. clif_bank_deposit(sd,reason);
  5607. }
  5608. }
  5609. }
  5610. /*
  5611. * Acknowledge of withdrawing some money from bank
  5612. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5613. */
  5614. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5615. unsigned char buf[17];
  5616. struct s_packet_db* info;
  5617. int16 len;
  5618. int cmd;
  5619. nullpo_retv(sd);
  5620. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5621. if(!cmd) cmd = 0x09AA;
  5622. info = &packet_db[sd->packet_ver][cmd];
  5623. len = info->len;
  5624. if(!len) return; //version as packet disable
  5625. WBUFW(buf,0) = cmd;
  5626. WBUFW(buf,info->pos[0]) = (short)reason;
  5627. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5628. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5629. clif_send(buf,len,&sd->bl,SELF);
  5630. }
  5631. /*
  5632. * Request Withdrawing some money from bank
  5633. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5634. */
  5635. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5636. nullpo_retv(sd);
  5637. if( !battle_config.feature_banking ) {
  5638. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5639. return;
  5640. }
  5641. else {
  5642. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5643. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5644. int money = RFIFOL(fd,info->pos[1]);
  5645. if(sd->status.account_id == aid){
  5646. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5647. clif_bank_withdraw(sd,reason);
  5648. }
  5649. }
  5650. }
  5651. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5652. /// 0125 <index>.W <amount>.L
  5653. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5654. {
  5655. int fd;
  5656. nullpo_retv(sd);
  5657. fd=sd->fd;
  5658. WFIFOHEAD(fd,packet_len(0x125));
  5659. WFIFOW(fd,0)=0x125;
  5660. WFIFOW(fd,2)=n+2;
  5661. WFIFOL(fd,4)=amount;
  5662. WFIFOSET(fd,packet_len(0x125));
  5663. }
  5664. /// Opens the shop creation menu (ZC_OPENSTORE).
  5665. /// 012d <num>.W
  5666. /// num:
  5667. /// number of allowed item slots
  5668. void clif_openvendingreq(struct map_session_data* sd, int num)
  5669. {
  5670. int fd;
  5671. nullpo_retv(sd);
  5672. fd = sd->fd;
  5673. WFIFOHEAD(fd,packet_len(0x12d));
  5674. WFIFOW(fd,0) = 0x12d;
  5675. WFIFOW(fd,2) = num;
  5676. WFIFOSET(fd,packet_len(0x12d));
  5677. }
  5678. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5679. /// 0131 <owner id>.L <message>.80B
  5680. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5681. {
  5682. unsigned char buf[128];
  5683. nullpo_retv(bl);
  5684. WBUFW(buf,0) = 0x131;
  5685. WBUFL(buf,2) = bl->id;
  5686. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5687. if( fd ) {
  5688. WFIFOHEAD(fd,packet_len(0x131));
  5689. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5690. WFIFOSET(fd,packet_len(0x131));
  5691. } else {
  5692. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5693. }
  5694. }
  5695. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5696. /// 0132 <owner id>.L
  5697. void clif_closevendingboard(struct block_list* bl, int fd)
  5698. {
  5699. unsigned char buf[16];
  5700. nullpo_retv(bl);
  5701. WBUFW(buf,0) = 0x132;
  5702. WBUFL(buf,2) = bl->id;
  5703. if( fd ) {
  5704. WFIFOHEAD(fd,packet_len(0x132));
  5705. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5706. WFIFOSET(fd,packet_len(0x132));
  5707. } else {
  5708. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5709. }
  5710. }
  5711. /// Sends a list of items in a shop.
  5712. /// 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)
  5713. /// 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)
  5714. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5715. {
  5716. int i,fd;
  5717. int count;
  5718. struct map_session_data* vsd;
  5719. #if PACKETVER < 20100105
  5720. const int cmd = 0x133;
  5721. const int offset = 8;
  5722. #else
  5723. const int cmd = 0x800;
  5724. const int offset = 12;
  5725. #endif
  5726. nullpo_retv(sd);
  5727. nullpo_retv(vending);
  5728. nullpo_retv(vsd=map_id2sd(id));
  5729. fd = sd->fd;
  5730. count = vsd->vend_num;
  5731. WFIFOHEAD(fd, offset+count*22);
  5732. WFIFOW(fd,0) = cmd;
  5733. WFIFOW(fd,2) = offset+count*22;
  5734. WFIFOL(fd,4) = id;
  5735. #if PACKETVER >= 20100105
  5736. WFIFOL(fd,8) = vsd->vender_id;
  5737. #endif
  5738. for( i = 0; i < count; i++ )
  5739. {
  5740. int index = vending[i].index;
  5741. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5742. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5743. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5744. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5745. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5746. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5747. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5748. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5749. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5750. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5751. }
  5752. WFIFOSET(fd,WFIFOW(fd,2));
  5753. }
  5754. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5755. /// 0135 <index>.W <amount>.W <result>.B
  5756. /// result:
  5757. /// 0 = success
  5758. /// 1 = not enough zeny
  5759. /// 2 = overweight
  5760. /// 4 = out of stock
  5761. /// 5 = "cannot use an npc shop while in a trade"
  5762. /// 6 = Because the store information was incorrect the item was not purchased.
  5763. /// 7 = No sales information.
  5764. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5765. {
  5766. int fd;
  5767. nullpo_retv(sd);
  5768. fd = sd->fd;
  5769. WFIFOHEAD(fd,packet_len(0x135));
  5770. WFIFOW(fd,0) = 0x135;
  5771. WFIFOW(fd,2) = index+2;
  5772. WFIFOW(fd,4) = amount;
  5773. WFIFOB(fd,6) = fail;
  5774. WFIFOSET(fd,packet_len(0x135));
  5775. }
  5776. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5777. /// 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 }*
  5778. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5779. {
  5780. int i,fd;
  5781. int count;
  5782. nullpo_retv(sd);
  5783. fd = sd->fd;
  5784. count = sd->vend_num;
  5785. WFIFOHEAD(fd, 8+count*22);
  5786. WFIFOW(fd,0) = 0x136;
  5787. WFIFOW(fd,2) = 8+count*22;
  5788. WFIFOL(fd,4) = id;
  5789. for( i = 0; i < count; i++ ) {
  5790. int index = vending[i].index;
  5791. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5792. WFIFOL(fd, 8+i*22) = vending[i].value;
  5793. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5794. WFIFOW(fd,14+i*22) = vending[i].amount;
  5795. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5796. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5797. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5798. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5799. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5800. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5801. }
  5802. WFIFOSET(fd,WFIFOW(fd,2));
  5803. }
  5804. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5805. /// 0137 <index>.W <amount>.W
  5806. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5807. {
  5808. int fd;
  5809. nullpo_retv(sd);
  5810. fd = sd->fd;
  5811. WFIFOHEAD(fd,packet_len(0x137));
  5812. WFIFOW(fd,0) = 0x137;
  5813. WFIFOW(fd,2) = index+2;
  5814. WFIFOW(fd,4) = amount;
  5815. WFIFOSET(fd,packet_len(0x137));
  5816. }
  5817. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5818. /// 00fa <result>.B
  5819. /// result:
  5820. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5821. /// 1 = MsgStringTable[78]="party name already exists"
  5822. /// 2 = MsgStringTable[79]="already in a party"
  5823. /// 3 = cannot organize parties on this map
  5824. /// ? = nothing
  5825. void clif_party_created(struct map_session_data *sd,int result)
  5826. {
  5827. int fd;
  5828. nullpo_retv(sd);
  5829. fd=sd->fd;
  5830. WFIFOHEAD(fd,packet_len(0xfa));
  5831. WFIFOW(fd,0)=0xfa;
  5832. WFIFOB(fd,2)=result;
  5833. WFIFOSET(fd,packet_len(0xfa));
  5834. }
  5835. /// Adds new member to a party.
  5836. /// 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)
  5837. /// 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)
  5838. /// role:
  5839. /// 0 = leader
  5840. /// 1 = normal
  5841. /// state:
  5842. /// 0 = connected
  5843. /// 1 = disconnected
  5844. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5845. {
  5846. unsigned char buf[81];
  5847. int i;
  5848. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5849. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5850. } else {
  5851. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5852. }
  5853. if (i >= MAX_PARTY) return; //Should never happen...
  5854. sd = p->data[i].sd;
  5855. WBUFW(buf, 0) = 0x1e9;
  5856. WBUFL(buf, 2) = sd->status.account_id;
  5857. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5858. WBUFW(buf,10) = sd->bl.x;
  5859. WBUFW(buf,12) = sd->bl.y;
  5860. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5861. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5862. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5863. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  5864. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5865. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5866. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5867. }
  5868. /// Sends party information (ZC_GROUP_LIST).
  5869. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5870. /// role:
  5871. /// 0 = leader
  5872. /// 1 = normal
  5873. /// state:
  5874. /// 0 = connected
  5875. /// 1 = disconnected
  5876. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5877. {
  5878. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5879. struct map_session_data* party_sd = NULL;
  5880. int i, c;
  5881. nullpo_retv(p);
  5882. WBUFW(buf,0) = 0xfb;
  5883. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5884. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5885. {
  5886. struct party_member* m = &p->party.member[i];
  5887. if(!m->account_id) continue;
  5888. if(party_sd == NULL) party_sd = p->data[i].sd;
  5889. WBUFL(buf,28+c*46) = m->account_id;
  5890. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5891. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5892. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5893. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5894. c++;
  5895. }
  5896. WBUFW(buf,2) = 28+c*46;
  5897. if(sd) { // send only to self
  5898. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5899. } else if (party_sd) { // send to whole party
  5900. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5901. }
  5902. }
  5903. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5904. /// 02c9 <flag>.B
  5905. /// flag:
  5906. /// 0 = allow party invites
  5907. /// 1 = auto-deny party invites
  5908. void clif_partyinvitationstate(struct map_session_data* sd)
  5909. {
  5910. int fd;
  5911. nullpo_retv(sd);
  5912. fd = sd->fd;
  5913. WFIFOHEAD(fd, packet_len(0x2c9));
  5914. WFIFOW(fd, 0) = 0x2c9;
  5915. WFIFOB(fd, 2) = 0; // not implemented
  5916. WFIFOSET(fd, packet_len(0x2c9));
  5917. }
  5918. /// Party invitation request.
  5919. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5920. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5921. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5922. {
  5923. #if PACKETVER < 20070821
  5924. const int cmd = 0xfe;
  5925. #else
  5926. const int cmd = 0x2c6;
  5927. #endif
  5928. int fd;
  5929. struct party_data *p;
  5930. nullpo_retv(sd);
  5931. nullpo_retv(tsd);
  5932. fd=tsd->fd;
  5933. if( (p=party_search(sd->status.party_id))==NULL )
  5934. return;
  5935. WFIFOHEAD(fd,packet_len(cmd));
  5936. WFIFOW(fd,0)=cmd;
  5937. WFIFOL(fd,2)=sd->status.party_id;
  5938. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5939. WFIFOSET(fd,packet_len(cmd));
  5940. }
  5941. /// Party invite result.
  5942. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5943. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5944. /// result=0 : char is already in a party -> MsgStringTable[80]
  5945. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5946. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5947. /// result=3 : party is full -> MsgStringTable[83]
  5948. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5949. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5950. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5951. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5952. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5953. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5954. {
  5955. int fd;
  5956. nullpo_retv(sd);
  5957. fd=sd->fd;
  5958. #if PACKETVER < 20070904
  5959. if( result == 7 ) {
  5960. clif_displaymessage(fd, msg_txt(sd,3));
  5961. return;
  5962. }
  5963. #endif
  5964. #if PACKETVER < 20070821
  5965. WFIFOHEAD(fd,packet_len(0xfd));
  5966. WFIFOW(fd,0) = 0xfd;
  5967. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5968. WFIFOB(fd,26) = result;
  5969. WFIFOSET(fd,packet_len(0xfd));
  5970. #else
  5971. WFIFOHEAD(fd,packet_len(0x2c5));
  5972. WFIFOW(fd,0) = 0x2c5;
  5973. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5974. WFIFOL(fd,26) = result;
  5975. WFIFOSET(fd,packet_len(0x2c5));
  5976. #endif
  5977. }
  5978. /// Updates party settings.
  5979. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5980. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5981. /// exp option:
  5982. /// 0 = exp sharing disabled
  5983. /// 1 = exp sharing enabled
  5984. /// 2 = cannot change exp sharing
  5985. ///
  5986. /// flag:
  5987. /// 0 = send to party
  5988. /// 1 = send to sd
  5989. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5990. {
  5991. unsigned char buf[16];
  5992. #if PACKETVER < 20090603
  5993. const int cmd = 0x101;
  5994. #else
  5995. const int cmd = 0x7d8;
  5996. #endif
  5997. nullpo_retv(p);
  5998. if(!sd && flag==0){
  5999. int i;
  6000. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6001. if (i < MAX_PARTY)
  6002. sd = p->data[i].sd;
  6003. }
  6004. if(!sd) return;
  6005. WBUFW(buf,0)=cmd;
  6006. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6007. #if PACKETVER >= 20090603
  6008. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6009. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6010. #endif
  6011. if(flag==0)
  6012. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6013. else
  6014. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6015. }
  6016. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6017. /// result:
  6018. /// 0 = leave
  6019. /// 1 = expel
  6020. /// 2 = cannot leave party on this map
  6021. /// 3 = cannot expel from party on this map
  6022. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6023. {
  6024. unsigned char buf[64];
  6025. nullpo_retv(p);
  6026. if(!sd && (flag&0xf0)==0)
  6027. {
  6028. int i;
  6029. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6030. if (i < MAX_PARTY)
  6031. sd = p->data[i].sd;
  6032. }
  6033. if(!sd) return;
  6034. WBUFW(buf,0)=0x105;
  6035. WBUFL(buf,2)=account_id;
  6036. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6037. WBUFB(buf,30)=flag&0x0f;
  6038. if((flag&0xf0)==0)
  6039. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6040. else
  6041. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6042. }
  6043. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6044. /// 0109 <packet len>.W <account id>.L <message>.?B
  6045. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6046. {
  6047. struct map_session_data *sd;
  6048. int i;
  6049. nullpo_retv(p);
  6050. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6051. if(i < MAX_PARTY){
  6052. unsigned char buf[1024];
  6053. if( len > sizeof(buf)-8 )
  6054. {
  6055. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6056. len = sizeof(buf)-8;
  6057. }
  6058. sd = p->data[i].sd;
  6059. WBUFW(buf,0)=0x109;
  6060. WBUFW(buf,2)=len+8;
  6061. WBUFL(buf,4)=account_id;
  6062. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6063. clif_send(buf,len+8,&sd->bl,PARTY);
  6064. }
  6065. }
  6066. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6067. /// 0107 <account id>.L <x>.W <y>.W
  6068. void clif_party_xy(struct map_session_data *sd)
  6069. {
  6070. unsigned char buf[16];
  6071. nullpo_retv(sd);
  6072. WBUFW(buf,0)=0x107;
  6073. WBUFL(buf,2)=sd->status.account_id;
  6074. WBUFW(buf,6)=sd->bl.x;
  6075. WBUFW(buf,8)=sd->bl.y;
  6076. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6077. }
  6078. /*==========================================
  6079. * Sends x/y dot to a single fd. [Skotlex]
  6080. *------------------------------------------*/
  6081. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6082. {
  6083. WFIFOHEAD(fd,packet_len(0x107));
  6084. WFIFOW(fd,0)=0x107;
  6085. WFIFOL(fd,2)=sd->status.account_id;
  6086. WFIFOW(fd,6)=sd->bl.x;
  6087. WFIFOW(fd,8)=sd->bl.y;
  6088. WFIFOSET(fd,packet_len(0x107));
  6089. }
  6090. /// Updates HP bar of a party member.
  6091. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6092. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6093. void clif_party_hp(struct map_session_data *sd)
  6094. {
  6095. unsigned char buf[16];
  6096. #if PACKETVER < 20100126
  6097. const int cmd = 0x106;
  6098. #else
  6099. const int cmd = 0x80e;
  6100. #endif
  6101. nullpo_retv(sd);
  6102. WBUFW(buf,0)=cmd;
  6103. WBUFL(buf,2)=sd->status.account_id;
  6104. #if PACKETVER < 20100126
  6105. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6106. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6107. WBUFW(buf,8) = 100;
  6108. } else {
  6109. WBUFW(buf,6) = sd->battle_status.hp;
  6110. WBUFW(buf,8) = sd->battle_status.max_hp;
  6111. }
  6112. #else
  6113. WBUFL(buf,6) = sd->battle_status.hp;
  6114. WBUFL(buf,10) = sd->battle_status.max_hp;
  6115. #endif
  6116. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6117. }
  6118. /*==========================================
  6119. * Sends HP bar to a single fd. [Skotlex]
  6120. *------------------------------------------*/
  6121. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6122. {
  6123. #if PACKETVER < 20100126
  6124. const int cmd = 0x106;
  6125. #else
  6126. const int cmd = 0x80e;
  6127. #endif
  6128. WFIFOHEAD(fd,packet_len(cmd));
  6129. WFIFOW(fd,0) = cmd;
  6130. WFIFOL(fd,2) = id;
  6131. #if PACKETVER < 20100126
  6132. if( maxhp > INT16_MAX )
  6133. {// To correctly display the %hp bar. [Skotlex]
  6134. WFIFOW(fd,6) = hp/(maxhp/100);
  6135. WFIFOW(fd,8) = 100;
  6136. } else {
  6137. WFIFOW(fd,6) = hp;
  6138. WFIFOW(fd,8) = maxhp;
  6139. }
  6140. #else
  6141. WFIFOL(fd,6) = hp;
  6142. WFIFOL(fd,10) = maxhp;
  6143. #endif
  6144. WFIFOSET(fd, packet_len(cmd));
  6145. }
  6146. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6147. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6148. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6149. {
  6150. int fd;
  6151. nullpo_retv(sd);
  6152. nullpo_retv(bl);
  6153. fd=sd->fd;
  6154. WFIFOHEAD(fd,packet_len(0x139));
  6155. WFIFOW(fd, 0)=0x139;
  6156. WFIFOL(fd, 2)=bl->id;
  6157. WFIFOW(fd, 6)=bl->x;
  6158. WFIFOW(fd, 8)=bl->y;
  6159. WFIFOW(fd,10)=sd->bl.x;
  6160. WFIFOW(fd,12)=sd->bl.y;
  6161. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6162. WFIFOSET(fd,packet_len(0x139));
  6163. }
  6164. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6165. /// 018f <result>.W <name id>.W
  6166. /// result:
  6167. /// 0 = success
  6168. /// 1 = failure
  6169. /// 2 = success (alchemist)
  6170. /// 3 = failure (alchemist)
  6171. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6172. {
  6173. int view,fd;
  6174. nullpo_retv(sd);
  6175. fd = sd->fd;
  6176. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6177. WFIFOHEAD(fd,packet_len(0x18f));
  6178. WFIFOW(fd, 0)=0x18f;
  6179. WFIFOW(fd, 2)=flag;
  6180. if((view = itemdb_viewid(nameid)) > 0)
  6181. WFIFOW(fd, 4)=view;
  6182. else
  6183. WFIFOW(fd, 4)=nameid;
  6184. WFIFOSET(fd,packet_len(0x18f));
  6185. }
  6186. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6187. /// 019e
  6188. void clif_catch_process(struct map_session_data *sd)
  6189. {
  6190. int fd;
  6191. nullpo_retv(sd);
  6192. fd=sd->fd;
  6193. WFIFOHEAD(fd,packet_len(0x19e));
  6194. WFIFOW(fd,0)=0x19e;
  6195. WFIFOSET(fd,packet_len(0x19e));
  6196. }
  6197. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6198. /// 01a0 <result>.B
  6199. /// 0 = failure
  6200. /// 1 = success
  6201. void clif_pet_roulette(struct map_session_data *sd,int data)
  6202. {
  6203. int fd;
  6204. nullpo_retv(sd);
  6205. fd=sd->fd;
  6206. WFIFOHEAD(fd,packet_len(0x1a0));
  6207. WFIFOW(fd,0)=0x1a0;
  6208. WFIFOB(fd,2)=data;
  6209. WFIFOSET(fd,packet_len(0x1a0));
  6210. }
  6211. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6212. /// 01a6 <packet len>.W { <index>.W }*
  6213. void clif_sendegg(struct map_session_data *sd)
  6214. {
  6215. int i,n=0,fd;
  6216. nullpo_retv(sd);
  6217. fd=sd->fd;
  6218. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6219. clif_displaymessage(fd, msg_txt(sd,666));
  6220. return;
  6221. }
  6222. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6223. WFIFOW(fd,0)=0x1a6;
  6224. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6225. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6226. sd->inventory_data[i]->type!=IT_PETEGG ||
  6227. sd->status.inventory[i].amount<=0)
  6228. continue;
  6229. WFIFOW(fd,n*2+4)=i+2;
  6230. n++;
  6231. }
  6232. WFIFOW(fd,2)=4+n*2;
  6233. WFIFOSET(fd,WFIFOW(fd,2));
  6234. sd->menuskill_id = SA_TAMINGMONSTER;
  6235. sd->menuskill_val = -1;
  6236. }
  6237. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6238. /// 01a4 <type>.B <id>.L <data>.L
  6239. /// type:
  6240. /// 0 = pre-init (data = 0)
  6241. /// 1 = intimacy (data = 0~4)
  6242. /// 2 = hunger (data = 0~4)
  6243. /// 3 = accessory
  6244. /// 4 = performance (data = 1~3: normal, 4: special)
  6245. /// 5 = hairstyle
  6246. ///
  6247. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6248. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6249. {
  6250. uint8 buf[16];
  6251. nullpo_retv(pd);
  6252. WBUFW(buf,0) = 0x1a4;
  6253. WBUFB(buf,2) = type;
  6254. WBUFL(buf,3) = pd->bl.id;
  6255. WBUFL(buf,7) = param;
  6256. if (sd)
  6257. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6258. else
  6259. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6260. }
  6261. /// Pet's base data (ZC_PROPERTY_PET).
  6262. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6263. void clif_send_petstatus(struct map_session_data *sd)
  6264. {
  6265. int fd;
  6266. struct s_pet *pet;
  6267. nullpo_retv(sd);
  6268. nullpo_retv(sd->pd);
  6269. fd=sd->fd;
  6270. pet = &sd->pd->pet;
  6271. WFIFOHEAD(fd,packet_len(0x1a2));
  6272. WFIFOW(fd,0)=0x1a2;
  6273. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6274. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6275. WFIFOW(fd,27)=pet->level;
  6276. WFIFOW(fd,29)=pet->hungry;
  6277. WFIFOW(fd,31)=pet->intimate;
  6278. WFIFOW(fd,33)=pet->equip;
  6279. #if PACKETVER >= 20081126
  6280. WFIFOW(fd,35)=pet->class_;
  6281. #endif
  6282. WFIFOSET(fd,packet_len(0x1a2));
  6283. }
  6284. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6285. /// 01aa <id>.L <data>.L
  6286. /// data:
  6287. /// @see CZ_PET_ACT.
  6288. void clif_pet_emotion(struct pet_data *pd,int param)
  6289. {
  6290. unsigned char buf[16];
  6291. nullpo_retv(pd);
  6292. memset(buf,0,packet_len(0x1aa));
  6293. WBUFW(buf,0)=0x1aa;
  6294. WBUFL(buf,2)=pd->bl.id;
  6295. if(param >= 100 && pd->petDB->talk_convert_class) {
  6296. if(pd->petDB->talk_convert_class < 0)
  6297. return;
  6298. else if(pd->petDB->talk_convert_class > 0) {
  6299. // replace mob_id component of talk/act data
  6300. param -= (pd->pet.class_ - 100)*100;
  6301. param += (pd->petDB->talk_convert_class - 100)*100;
  6302. }
  6303. }
  6304. WBUFL(buf,6)=param;
  6305. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6306. }
  6307. /// Result of request to feed a pet (ZC_FEED_PET).
  6308. /// 01a3 <result>.B <name id>.W
  6309. /// result:
  6310. /// 0 = failure
  6311. /// 1 = success
  6312. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6313. {
  6314. int fd;
  6315. nullpo_retv(sd);
  6316. fd=sd->fd;
  6317. WFIFOHEAD(fd,packet_len(0x1a3));
  6318. WFIFOW(fd,0)=0x1a3;
  6319. WFIFOB(fd,2)=fail;
  6320. WFIFOW(fd,3)=foodid;
  6321. WFIFOSET(fd,packet_len(0x1a3));
  6322. }
  6323. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6324. /// 01cd { <skill id>.L }*7
  6325. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6326. {
  6327. int fd;
  6328. nullpo_retv(sd);
  6329. fd=sd->fd;
  6330. WFIFOHEAD(fd,packet_len(0x1cd));
  6331. WFIFOW(fd, 0)=0x1cd;
  6332. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6333. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6334. else
  6335. WFIFOL(fd,2)= 0x00000000;
  6336. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6337. WFIFOL(fd,6)= MG_COLDBOLT;
  6338. else
  6339. WFIFOL(fd,6)= 0x00000000;
  6340. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6341. WFIFOL(fd,10)= MG_FIREBOLT;
  6342. else
  6343. WFIFOL(fd,10)= 0x00000000;
  6344. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6345. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6346. else
  6347. WFIFOL(fd,14)= 0x00000000;
  6348. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6349. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6350. else
  6351. WFIFOL(fd,18)= 0x00000000;
  6352. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6353. WFIFOL(fd,22)= MG_FIREBALL;
  6354. else
  6355. WFIFOL(fd,22)= 0x00000000;
  6356. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6357. WFIFOL(fd,26)= MG_FROSTDIVER;
  6358. else
  6359. WFIFOL(fd,26)= 0x00000000;
  6360. WFIFOSET(fd,packet_len(0x1cd));
  6361. sd->menuskill_id = SA_AUTOSPELL;
  6362. sd->menuskill_val = skill_lv;
  6363. }
  6364. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6365. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6366. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6367. {
  6368. unsigned char buf[56];
  6369. nullpo_retv(src);
  6370. memset(buf,0,packet_len(0x1cf));
  6371. WBUFW(buf,0) = 0x1cf;
  6372. WBUFL(buf,2) = src->id;
  6373. if( src->type == BL_MER )
  6374. {
  6375. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6376. if( md && md->master && md->devotion_flag )
  6377. WBUFL(buf,6) = md->master->bl.id;
  6378. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6379. }
  6380. else
  6381. {
  6382. int i;
  6383. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6384. if( sd == NULL )
  6385. return;
  6386. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6387. WBUFL(buf,6+4*i) = sd->devotion[i];
  6388. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6389. }
  6390. if( tsd )
  6391. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6392. else
  6393. clif_send(buf, packet_len(0x1cf), src, AREA);
  6394. }
  6395. /*==========================================
  6396. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6397. * Notifies clients in an area of an object's spirits.
  6398. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6399. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6400. *------------------------------------------*/
  6401. void clif_spiritball(struct block_list *bl) {
  6402. unsigned char buf[16];
  6403. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6404. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6405. nullpo_retv(bl);
  6406. WBUFW(buf, 0) = 0x1d0;
  6407. WBUFL(buf, 2) = bl->id;
  6408. WBUFW(buf, 6) = 0; //init to 0
  6409. switch(bl->type){
  6410. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6411. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6412. }
  6413. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6414. }
  6415. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6416. /// 01d2 <account id>.L <delay>.L
  6417. void clif_combo_delay(struct block_list *bl,int wait)
  6418. {
  6419. unsigned char buf[32];
  6420. nullpo_retv(bl);
  6421. WBUFW(buf,0)=0x1d2;
  6422. WBUFL(buf,2)=bl->id;
  6423. WBUFL(buf,6)=wait;
  6424. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6425. }
  6426. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6427. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6428. /// flag:
  6429. /// 0 = inactive
  6430. /// 1 = active
  6431. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6432. {
  6433. unsigned char buf[32];
  6434. nullpo_retv(src);
  6435. WBUFW(buf,0)=0x1d1;
  6436. WBUFL(buf,2)=src->id;
  6437. WBUFL(buf,6)=dst_id;
  6438. WBUFL(buf,10)=active;
  6439. clif_send(buf,packet_len(0x1d1),src,AREA);
  6440. }
  6441. /// MVP effect (ZC_MVP).
  6442. /// 010c <account id>.L
  6443. void clif_mvp_effect(struct map_session_data *sd)
  6444. {
  6445. unsigned char buf[16];
  6446. nullpo_retv(sd);
  6447. WBUFW(buf,0)=0x10c;
  6448. WBUFL(buf,2)=sd->bl.id;
  6449. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6450. }
  6451. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6452. /// 010a <name id>.W
  6453. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6454. {
  6455. int view,fd;
  6456. nullpo_retv(sd);
  6457. fd=sd->fd;
  6458. WFIFOHEAD(fd,packet_len(0x10a));
  6459. WFIFOW(fd,0)=0x10a;
  6460. if((view = itemdb_viewid(nameid)) > 0)
  6461. WFIFOW(fd,2)=view;
  6462. else
  6463. WFIFOW(fd,2)=nameid;
  6464. WFIFOSET(fd,packet_len(0x10a));
  6465. }
  6466. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6467. /// 010b <exp>.L
  6468. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6469. {
  6470. int fd;
  6471. nullpo_retv(sd);
  6472. fd=sd->fd;
  6473. WFIFOHEAD(fd,packet_len(0x10b));
  6474. WFIFOW(fd,0)=0x10b;
  6475. WFIFOL(fd,2)=min(exp,UINT32_MAX);
  6476. WFIFOSET(fd,packet_len(0x10b));
  6477. }
  6478. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6479. /// 010d
  6480. ///
  6481. /// "You are the MVP, but cannot obtain the reward because
  6482. /// you are overweight."
  6483. void clif_mvp_noitem(struct map_session_data* sd)
  6484. {
  6485. int fd = sd->fd;
  6486. WFIFOHEAD(fd,packet_len(0x10d));
  6487. WFIFOW(fd,0) = 0x10d;
  6488. WFIFOSET(fd,packet_len(0x10d));
  6489. }
  6490. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6491. /// 0167 <result>.B
  6492. /// result:
  6493. /// 0 = "Guild has been created."
  6494. /// 1 = "You are already in a Guild."
  6495. /// 2 = "That Guild Name already exists."
  6496. /// 3 = "You need the neccessary item to create a Guild."
  6497. void clif_guild_created(struct map_session_data *sd,int flag)
  6498. {
  6499. int fd;
  6500. nullpo_retv(sd);
  6501. fd=sd->fd;
  6502. WFIFOHEAD(fd,packet_len(0x167));
  6503. WFIFOW(fd,0)=0x167;
  6504. WFIFOB(fd,2)=flag;
  6505. WFIFOSET(fd,packet_len(0x167));
  6506. }
  6507. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6508. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6509. /// mode:
  6510. /// &0x01 = allow invite
  6511. /// &0x10 = allow expel
  6512. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6513. {
  6514. int ps,fd;
  6515. nullpo_retv(sd);
  6516. nullpo_retv(g);
  6517. fd=sd->fd;
  6518. ps=guild_getposition(g,sd);
  6519. WFIFOHEAD(fd,packet_len(0x16c));
  6520. WFIFOW(fd,0)=0x16c;
  6521. WFIFOL(fd,2)=g->guild_id;
  6522. WFIFOL(fd,6)=g->emblem_id;
  6523. WFIFOL(fd,10)=g->position[ps].mode;
  6524. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6525. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6526. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6527. WFIFOSET(fd,packet_len(0x16c));
  6528. }
  6529. /// Guild member login notice.
  6530. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6531. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6532. /// status:
  6533. /// 0 = offline
  6534. /// 1 = online
  6535. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6536. {
  6537. unsigned char buf[64];
  6538. struct map_session_data* sd;
  6539. nullpo_retv(g);
  6540. WBUFW(buf, 0)=0x1f2;
  6541. WBUFL(buf, 2)=g->member[idx].account_id;
  6542. WBUFL(buf, 6)=g->member[idx].char_id;
  6543. WBUFL(buf,10)=flag;
  6544. if( ( sd = g->member[idx].sd ) != NULL )
  6545. {
  6546. WBUFW(buf,14) = sd->status.sex;
  6547. WBUFW(buf,16) = sd->status.hair;
  6548. WBUFW(buf,18) = sd->status.hair_color;
  6549. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6550. }
  6551. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6552. {
  6553. WBUFW(buf,14) = 0;
  6554. WBUFW(buf,16) = 0;
  6555. WBUFW(buf,18) = 0;
  6556. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6557. }
  6558. }
  6559. // Function `clif_guild_memberlogin_notice` sends info about
  6560. // logins and logouts of a guild member to the rest members.
  6561. // But at the 1st time (after a player login or map changing)
  6562. // the client won't show the message.
  6563. // So I suggest use this function for sending "first-time-info"
  6564. // to some player on entering the game or changing location.
  6565. // At next time the client would always show the message.
  6566. // The function sends all the statuses in the single packet
  6567. // to economize traffic. [LuzZza]
  6568. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6569. {
  6570. struct guild *g;
  6571. unsigned char buf[14*128];
  6572. int i, count=0, p_len;
  6573. nullpo_retv(sd);
  6574. p_len = packet_len(0x16d);
  6575. if(!(g = sd->guild))
  6576. return;
  6577. for(i=0; i<g->max_member; i++) {
  6578. if(g->member[i].account_id > 0 &&
  6579. g->member[i].account_id != sd->status.account_id) {
  6580. WBUFW(buf,count*p_len) = 0x16d;
  6581. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6582. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6583. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6584. count++;
  6585. }
  6586. }
  6587. clif_send(buf, p_len*count, &sd->bl, SELF);
  6588. }
  6589. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6590. /// 014e <menu flag>.L
  6591. /// menu flag:
  6592. /// 0x00 = Basic Info (always on)
  6593. /// &0x01 = Member manager
  6594. /// &0x02 = Positions
  6595. /// &0x04 = Skills
  6596. /// &0x10 = Expulsion list
  6597. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6598. /// &0x80 = Notice
  6599. void clif_guild_masterormember(struct map_session_data *sd)
  6600. {
  6601. int fd;
  6602. nullpo_retv(sd);
  6603. fd=sd->fd;
  6604. WFIFOHEAD(fd,packet_len(0x14e));
  6605. WFIFOW(fd,0) = 0x14e;
  6606. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6607. WFIFOSET(fd,packet_len(0x14e));
  6608. }
  6609. /// Guild basic information (Territories [Valaris])
  6610. /// 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)
  6611. /// 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)
  6612. void clif_guild_basicinfo(struct map_session_data *sd) {
  6613. int fd;
  6614. struct guild *g;
  6615. nullpo_retv(sd);
  6616. fd = sd->fd;
  6617. if( (g = sd->guild) == NULL )
  6618. return;
  6619. WFIFOHEAD(fd,packet_len(0x1b6));
  6620. WFIFOW(fd, 0)=0x1b6;//0x150;
  6621. WFIFOL(fd, 2)=g->guild_id;
  6622. WFIFOL(fd, 6)=g->guild_lv;
  6623. WFIFOL(fd,10)=g->connect_member;
  6624. WFIFOL(fd,14)=g->max_member;
  6625. WFIFOL(fd,18)=g->average_lv;
  6626. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6627. WFIFOL(fd,26)=g->next_exp;
  6628. WFIFOL(fd,30)=0; // Tax Points
  6629. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6630. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6631. WFIFOL(fd,42)=g->emblem_id;
  6632. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6633. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6634. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6635. WFIFOL(fd,110) = 0; // zeny
  6636. WFIFOSET(fd,packet_len(0x1b6));
  6637. }
  6638. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6639. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6640. void clif_guild_allianceinfo(struct map_session_data *sd)
  6641. {
  6642. int fd,i,c;
  6643. struct guild *g;
  6644. nullpo_retv(sd);
  6645. if( (g = sd->guild) == NULL )
  6646. return;
  6647. fd = sd->fd;
  6648. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6649. WFIFOW(fd, 0)=0x14c;
  6650. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6651. struct guild_alliance *a=&g->alliance[i];
  6652. if(a->guild_id>0){
  6653. WFIFOL(fd,c*32+4)=a->opposition;
  6654. WFIFOL(fd,c*32+8)=a->guild_id;
  6655. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6656. c++;
  6657. }
  6658. }
  6659. WFIFOW(fd, 2)=c*32+4;
  6660. WFIFOSET(fd,WFIFOW(fd,2));
  6661. }
  6662. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6663. /// 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 }*
  6664. /// state:
  6665. /// 0 = offline
  6666. /// 1 = online
  6667. /// memo:
  6668. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6669. void clif_guild_memberlist(struct map_session_data *sd)
  6670. {
  6671. int fd;
  6672. int i,c;
  6673. struct guild *g;
  6674. nullpo_retv(sd);
  6675. if( (fd = sd->fd) == 0 )
  6676. return;
  6677. if( (g = sd->guild) == NULL )
  6678. return;
  6679. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6680. WFIFOW(fd, 0)=0x154;
  6681. for(i=0,c=0;i<g->max_member;i++){
  6682. struct guild_member *m=&g->member[i];
  6683. if(m->account_id==0)
  6684. continue;
  6685. WFIFOL(fd,c*104+ 4)=m->account_id;
  6686. WFIFOL(fd,c*104+ 8)=m->char_id;
  6687. WFIFOW(fd,c*104+12)=m->hair;
  6688. WFIFOW(fd,c*104+14)=m->hair_color;
  6689. WFIFOW(fd,c*104+16)=m->gender;
  6690. WFIFOW(fd,c*104+18)=m->class_;
  6691. WFIFOW(fd,c*104+20)=m->lv;
  6692. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6693. WFIFOL(fd,c*104+26)=m->online;
  6694. WFIFOL(fd,c*104+30)=m->position;
  6695. 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.
  6696. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6697. c++;
  6698. }
  6699. WFIFOW(fd, 2)=c*104+4;
  6700. WFIFOSET(fd,WFIFOW(fd,2));
  6701. }
  6702. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6703. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6704. void clif_guild_positionnamelist(struct map_session_data *sd)
  6705. {
  6706. int i,fd;
  6707. struct guild *g;
  6708. nullpo_retv(sd);
  6709. if( (g = sd->guild) == NULL )
  6710. return;
  6711. fd = sd->fd;
  6712. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6713. WFIFOW(fd, 0)=0x166;
  6714. for(i=0;i<MAX_GUILDPOSITION;i++){
  6715. WFIFOL(fd,i*28+4)=i;
  6716. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6717. }
  6718. WFIFOW(fd,2)=i*28+4;
  6719. WFIFOSET(fd,WFIFOW(fd,2));
  6720. }
  6721. /// Guild position information (ZC_POSITION_INFO).
  6722. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6723. /// mode:
  6724. /// &0x01 = allow invite
  6725. /// &0x10 = allow expel
  6726. /// ranking:
  6727. /// TODO
  6728. void clif_guild_positioninfolist(struct map_session_data *sd)
  6729. {
  6730. int i,fd;
  6731. struct guild *g;
  6732. nullpo_retv(sd);
  6733. if( (g = sd->guild) == NULL )
  6734. return;
  6735. fd = sd->fd;
  6736. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6737. WFIFOW(fd, 0)=0x160;
  6738. for(i=0;i<MAX_GUILDPOSITION;i++){
  6739. struct guild_position *p=&g->position[i];
  6740. WFIFOL(fd,i*16+ 4)=i;
  6741. WFIFOL(fd,i*16+ 8)=p->mode;
  6742. WFIFOL(fd,i*16+12)=i;
  6743. WFIFOL(fd,i*16+16)=p->exp_mode;
  6744. }
  6745. WFIFOW(fd, 2)=i*16+4;
  6746. WFIFOSET(fd,WFIFOW(fd,2));
  6747. }
  6748. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6749. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6750. /// mode:
  6751. /// &0x01 = allow invite
  6752. /// &0x10 = allow expel
  6753. /// ranking:
  6754. /// TODO
  6755. void clif_guild_positionchanged(struct guild *g,int idx)
  6756. {
  6757. // FIXME: This packet is intended to update the clients after a
  6758. // commit of position info changes, not sending one packet per
  6759. // position.
  6760. struct map_session_data *sd;
  6761. unsigned char buf[128];
  6762. nullpo_retv(g);
  6763. WBUFW(buf, 0)=0x174;
  6764. WBUFW(buf, 2)=44; // packet len
  6765. // GUILD_REG_POSITION_INFO{
  6766. WBUFL(buf, 4)=idx;
  6767. WBUFL(buf, 8)=g->position[idx].mode;
  6768. WBUFL(buf,12)=idx;
  6769. WBUFL(buf,16)=g->position[idx].exp_mode;
  6770. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6771. // }*
  6772. if( (sd=guild_getavailablesd(g))!=NULL )
  6773. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6774. }
  6775. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6776. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6777. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6778. {
  6779. // FIXME: This packet is intended to update the clients after a
  6780. // commit of member position assignment changes, not sending one
  6781. // packet per position.
  6782. struct map_session_data *sd;
  6783. unsigned char buf[64];
  6784. nullpo_retv(g);
  6785. WBUFW(buf, 0)=0x156;
  6786. WBUFW(buf, 2)=16; // packet len
  6787. // MEMBER_POSITION_INFO{
  6788. WBUFL(buf, 4)=g->member[idx].account_id;
  6789. WBUFL(buf, 8)=g->member[idx].char_id;
  6790. WBUFL(buf,12)=g->member[idx].position;
  6791. // }*
  6792. if( (sd=guild_getavailablesd(g))!=NULL )
  6793. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6794. }
  6795. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6796. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6797. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6798. {
  6799. int fd;
  6800. nullpo_retv(sd);
  6801. nullpo_retv(g);
  6802. fd = sd->fd;
  6803. if( g->emblem_len <= 0 )
  6804. return;
  6805. WFIFOHEAD(fd,g->emblem_len+12);
  6806. WFIFOW(fd,0)=0x152;
  6807. WFIFOW(fd,2)=g->emblem_len+12;
  6808. WFIFOL(fd,4)=g->guild_id;
  6809. WFIFOL(fd,8)=g->emblem_id;
  6810. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6811. WFIFOSET(fd,WFIFOW(fd,2));
  6812. }
  6813. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6814. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6815. void clif_guild_emblem_area(struct block_list* bl)
  6816. {
  6817. uint8 buf[12];
  6818. nullpo_retv(bl);
  6819. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6820. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6821. WBUFW(buf,0) = 0x1b4;
  6822. WBUFL(buf,2) = bl->id;
  6823. WBUFL(buf,6) = status_get_guild_id(bl);
  6824. WBUFW(buf,10) = status_get_emblem_id(bl);
  6825. clif_send(buf, 12, bl, AREA_WOS);
  6826. }
  6827. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6828. /// 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 }*
  6829. void clif_guild_skillinfo(struct map_session_data* sd)
  6830. {
  6831. int fd;
  6832. struct guild* g;
  6833. int i,c;
  6834. nullpo_retv(sd);
  6835. if( (g = sd->guild) == NULL )
  6836. return;
  6837. fd = sd->fd;
  6838. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6839. WFIFOW(fd,0) = 0x0162;
  6840. WFIFOW(fd,4) = g->skill_point;
  6841. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6842. {
  6843. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6844. {
  6845. int id = g->skill[i].id;
  6846. int p = 6 + c*37;
  6847. WFIFOW(fd,p+0) = id;
  6848. WFIFOL(fd,p+2) = skill_get_inf(id);
  6849. WFIFOW(fd,p+6) = g->skill[i].lv;
  6850. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6851. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6852. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6853. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6854. c++;
  6855. }
  6856. }
  6857. WFIFOW(fd,2) = 6 + c*37;
  6858. WFIFOSET(fd,WFIFOW(fd,2));
  6859. }
  6860. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6861. /// 016f <subject>.60B <notice>.120B
  6862. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6863. {
  6864. int fd;
  6865. nullpo_retv(sd);
  6866. nullpo_retv(g);
  6867. fd = sd->fd;
  6868. if ( !session_isActive(fd) )
  6869. return;
  6870. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6871. return;
  6872. WFIFOHEAD(fd,packet_len(0x16f));
  6873. WFIFOW(fd,0) = 0x16f;
  6874. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6875. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6876. WFIFOSET(fd,packet_len(0x16f));
  6877. }
  6878. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6879. /// 016a <guild id>.L <guild name>.24B
  6880. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6881. {
  6882. int fd;
  6883. nullpo_retv(sd);
  6884. nullpo_retv(g);
  6885. fd=sd->fd;
  6886. WFIFOHEAD(fd,packet_len(0x16a));
  6887. WFIFOW(fd,0)=0x16a;
  6888. WFIFOL(fd,2)=g->guild_id;
  6889. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6890. WFIFOSET(fd,packet_len(0x16a));
  6891. }
  6892. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6893. /// 0169 <answer>.B
  6894. /// answer:
  6895. /// 0 = Already in guild.
  6896. /// 1 = Offer rejected.
  6897. /// 2 = Offer accepted.
  6898. /// 3 = Guild full.
  6899. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6900. {
  6901. int fd;
  6902. nullpo_retv(sd);
  6903. fd=sd->fd;
  6904. WFIFOHEAD(fd,packet_len(0x169));
  6905. WFIFOW(fd,0)=0x169;
  6906. WFIFOB(fd,2)=flag;
  6907. WFIFOSET(fd,packet_len(0x169));
  6908. }
  6909. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6910. /// 015a <char name>.24B <reason>.40B
  6911. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6912. {
  6913. unsigned char buf[128];
  6914. nullpo_retv(sd);
  6915. WBUFW(buf, 0)=0x15a;
  6916. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6917. memcpy(WBUFP(buf,26),mes,40);
  6918. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6919. }
  6920. /// Notifies clients of a guild of an expelled member.
  6921. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6922. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6923. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  6924. {
  6925. unsigned char buf[128];
  6926. #if PACKETVER < 20100803
  6927. const unsigned short cmd = 0x15c;
  6928. #else
  6929. const unsigned short cmd = 0x839;
  6930. #endif
  6931. nullpo_retv(sd);
  6932. WBUFW(buf,0) = cmd;
  6933. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6934. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6935. #if PACKETVER < 20100803
  6936. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6937. #endif
  6938. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6939. }
  6940. /// Guild expulsion list (ZC_BAN_LIST).
  6941. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6942. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6943. void clif_guild_expulsionlist(struct map_session_data* sd)
  6944. {
  6945. #if PACKETVER < 20100803
  6946. const int offset = NAME_LENGTH*2+40;
  6947. #else
  6948. const int offset = NAME_LENGTH+40;
  6949. #endif
  6950. int fd, i, c = 0;
  6951. struct guild* g;
  6952. nullpo_retv(sd);
  6953. if( (g = sd->guild) == NULL )
  6954. return;
  6955. fd = sd->fd;
  6956. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6957. WFIFOW(fd,0) = 0x163;
  6958. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6959. {
  6960. struct guild_expulsion* e = &g->expulsion[i];
  6961. if( e->account_id > 0 )
  6962. {
  6963. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6964. #if PACKETVER < 20100803
  6965. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6966. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6967. #else
  6968. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6969. #endif
  6970. c++;
  6971. }
  6972. }
  6973. WFIFOW(fd,2) = 4 + c*offset;
  6974. WFIFOSET(fd,WFIFOW(fd,2));
  6975. }
  6976. /// Guild chat message (ZC_GUILD_CHAT).
  6977. /// 017f <packet len>.W <message>.?B
  6978. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  6979. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6980. struct map_session_data *sd;
  6981. uint8 buf[256];
  6982. if( len == 0 )
  6983. {
  6984. return;
  6985. }
  6986. else if( len > sizeof(buf)-5 )
  6987. {
  6988. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6989. len = sizeof(buf)-5;
  6990. }
  6991. WBUFW(buf, 0) = 0x17f;
  6992. WBUFW(buf, 2) = len + 5;
  6993. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6994. if ((sd = guild_getavailablesd(g)) != NULL)
  6995. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6996. }
  6997. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6998. /// 0171 <inviter account id>.L <guild name>.24B
  6999. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7000. {
  7001. int fd;
  7002. nullpo_retv(sd);
  7003. fd=sd->fd;
  7004. WFIFOHEAD(fd,packet_len(0x171));
  7005. WFIFOW(fd,0)=0x171;
  7006. WFIFOL(fd,2)=account_id;
  7007. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7008. WFIFOSET(fd,packet_len(0x171));
  7009. }
  7010. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7011. /// 0173 <answer>.B
  7012. /// answer:
  7013. /// 0 = Already allied.
  7014. /// 1 = You rejected the offer.
  7015. /// 2 = You accepted the offer.
  7016. /// 3 = They have too any alliances.
  7017. /// 4 = You have too many alliances.
  7018. /// 5 = Alliances are disabled.
  7019. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7020. {
  7021. int fd;
  7022. nullpo_retv(sd);
  7023. fd=sd->fd;
  7024. WFIFOHEAD(fd,packet_len(0x173));
  7025. WFIFOW(fd,0)=0x173;
  7026. WFIFOL(fd,2)=flag;
  7027. WFIFOSET(fd,packet_len(0x173));
  7028. }
  7029. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7030. /// 0184 <other guild id>.L <relation>.L
  7031. /// relation:
  7032. /// 0 = Ally
  7033. /// 1 = Enemy
  7034. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7035. {
  7036. int fd;
  7037. nullpo_retv(sd);
  7038. fd = sd->fd;
  7039. if (fd <= 0)
  7040. return;
  7041. WFIFOHEAD(fd,packet_len(0x184));
  7042. WFIFOW(fd,0)=0x184;
  7043. WFIFOL(fd,2)=guild_id;
  7044. WFIFOL(fd,6)=flag;
  7045. WFIFOSET(fd,packet_len(0x184));
  7046. }
  7047. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7048. /// 0181 <result>.B
  7049. /// result:
  7050. /// 0 = Antagonist has been set.
  7051. /// 1 = Guild has too many Antagonists.
  7052. /// 2 = Already set as an Antagonist.
  7053. /// 3 = Antagonists are disabled.
  7054. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7055. {
  7056. int fd;
  7057. nullpo_retv(sd);
  7058. fd=sd->fd;
  7059. WFIFOHEAD(fd,packet_len(0x181));
  7060. WFIFOW(fd,0)=0x181;
  7061. WFIFOB(fd,2)=flag;
  7062. WFIFOSET(fd,packet_len(0x181));
  7063. }
  7064. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7065. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7066. /*
  7067. void clif_guild_allianceadded(struct guild *g,int idx)
  7068. {
  7069. unsigned char buf[64];
  7070. WBUFW(buf,0)=0x185;
  7071. WBUFL(buf,2)=g->alliance[idx].opposition;
  7072. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7073. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7074. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7075. }
  7076. */
  7077. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7078. /// 015e <reason>.L
  7079. /// 0 = success
  7080. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7081. /// 2 = there are still members in the guild
  7082. void clif_guild_broken(struct map_session_data *sd,int flag)
  7083. {
  7084. int fd;
  7085. nullpo_retv(sd);
  7086. fd=sd->fd;
  7087. WFIFOHEAD(fd,packet_len(0x15e));
  7088. WFIFOW(fd,0)=0x15e;
  7089. WFIFOL(fd,2)=flag;
  7090. WFIFOSET(fd,packet_len(0x15e));
  7091. }
  7092. /// Displays emotion on an object (ZC_EMOTION).
  7093. /// 00c0 <id>.L <type>.B
  7094. /// type:
  7095. /// enum emotion_type
  7096. void clif_emotion(struct block_list *bl,int type)
  7097. {
  7098. unsigned char buf[8];
  7099. nullpo_retv(bl);
  7100. WBUFW(buf,0)=0xc0;
  7101. WBUFL(buf,2)=bl->id;
  7102. WBUFB(buf,6)=type;
  7103. clif_send(buf,packet_len(0xc0),bl,AREA);
  7104. }
  7105. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7106. /// 0191 <id>.L <contents>.80B
  7107. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7108. {
  7109. unsigned char buf[MESSAGE_SIZE+6];
  7110. nullpo_retv(bl);
  7111. WBUFW(buf,0) = 0x191;
  7112. WBUFL(buf,2) = bl->id;
  7113. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7114. clif_send(buf,packet_len(0x191),bl,AREA);
  7115. }
  7116. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7117. /// 01ea <id>.L
  7118. void clif_wedding_effect(struct block_list *bl)
  7119. {
  7120. unsigned char buf[6];
  7121. nullpo_retv(bl);
  7122. WBUFW(buf,0) = 0x1ea;
  7123. WBUFL(buf,2) = bl->id;
  7124. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7125. }
  7126. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7127. /// 01e6 <partner name>.24B
  7128. void clif_callpartner(struct map_session_data *sd)
  7129. {
  7130. unsigned char buf[26];
  7131. nullpo_retv(sd);
  7132. WBUFW(buf,0) = 0x1e6;
  7133. if( sd->status.partner_id ) {
  7134. const char *p = map_charid2nick(sd->status.partner_id);
  7135. struct map_session_data *p_sd = pc_get_partner(sd);
  7136. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7137. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7138. else
  7139. WBUFB(buf,2) = 0;
  7140. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7141. WBUFB(buf,2) = 0;
  7142. }
  7143. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7144. }
  7145. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7146. /// 01e4
  7147. /// This packet while still implemented by the client is no longer being officially used.
  7148. /*
  7149. void clif_marriage_process(struct map_session_data *sd)
  7150. {
  7151. int fd;
  7152. nullpo_retv(sd);
  7153. fd=sd->fd;
  7154. WFIFOHEAD(fd,packet_len(0x1e4));
  7155. WFIFOW(fd,0)=0x1e4;
  7156. WFIFOSET(fd,packet_len(0x1e4));
  7157. }
  7158. */
  7159. /// Notice of divorce (ZC_DIVORCE).
  7160. /// 0205 <partner name>.24B
  7161. void clif_divorced(struct map_session_data* sd, const char* name)
  7162. {
  7163. int fd;
  7164. nullpo_retv(sd);
  7165. fd=sd->fd;
  7166. WFIFOHEAD(fd,packet_len(0x205));
  7167. WFIFOW(fd,0)=0x205;
  7168. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7169. WFIFOSET(fd, packet_len(0x205));
  7170. }
  7171. /// Marriage proposal (ZC_REQ_COUPLE).
  7172. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7173. /// This packet while still implemented by the client is no longer being officially used.
  7174. /*
  7175. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7176. {
  7177. nullpo_retv(sd);
  7178. WFIFOHEAD(fd,packet_len(0x1e2));
  7179. WFIFOW(fd,0) = 0x1e2;
  7180. WFIFOL(fd,2) = ssd->status.account_id;
  7181. WFIFOL(fd,6) = ssd->status.char_id;
  7182. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7183. WFIFOSET(fd, packet_len(0x1e2));
  7184. }
  7185. */
  7186. /*==========================================
  7187. *
  7188. *------------------------------------------*/
  7189. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7190. {
  7191. clif_disp_message(&sd->bl, mes, len, SELF);
  7192. }
  7193. /*==========================================
  7194. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7195. *------------------------------------------*/
  7196. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7197. {
  7198. unsigned char buf[256];
  7199. if( len == 0 ) {
  7200. return;
  7201. } else if( len > sizeof(buf)-5 ) {
  7202. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7203. len = sizeof(buf)-5;
  7204. }
  7205. WBUFW(buf, 0) = 0x17f;
  7206. WBUFW(buf, 2) = len + 5;
  7207. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7208. clif_send(buf, WBUFW(buf,2), src, target);
  7209. }
  7210. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7211. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7212. /// 00cd <result>.B
  7213. /// result:
  7214. /// 0 = failure
  7215. /// 1 = success
  7216. void clif_GM_kickack(struct map_session_data *sd, int id)
  7217. {
  7218. int fd;
  7219. nullpo_retv(sd);
  7220. fd = sd->fd;
  7221. WFIFOHEAD(fd,packet_len(0xcd));
  7222. WFIFOW(fd,0) = 0xcd;
  7223. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7224. WFIFOSET(fd, packet_len(0xcd));
  7225. }
  7226. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7227. {
  7228. int fd = tsd->fd;
  7229. if( fd > 0 )
  7230. clif_authfail_fd(fd, 15);
  7231. else {
  7232. // Close vending/buyingstore
  7233. if (sd) {
  7234. if (tsd->state.vending)
  7235. vending_closevending(tsd);
  7236. else if (tsd->state.buyingstore)
  7237. buyingstore_close(tsd);
  7238. }
  7239. map_quit(tsd);
  7240. }
  7241. if( sd )
  7242. clif_GM_kickack(sd,tsd->status.account_id);
  7243. }
  7244. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7245. /// 014a <result>.L
  7246. /// result:
  7247. /// 0 = "A manner point has been successfully aligned."
  7248. /// 1 = MP_FAILURE_EXHAUST
  7249. /// 2 = MP_FAILURE_ALREADY_GIVING
  7250. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7251. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7252. /// 5 = "You got a good point from %s."
  7253. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7254. {
  7255. int fd;
  7256. nullpo_retv(sd);
  7257. fd = sd->fd;
  7258. WFIFOHEAD(fd,packet_len(0x14a));
  7259. WFIFOW(fd,0) = 0x14a;
  7260. WFIFOL(fd,2) = type;
  7261. WFIFOSET(fd, packet_len(0x14a));
  7262. }
  7263. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7264. /// 014b <type>.B <GM name>.24B
  7265. /// type:
  7266. /// 0 = positive (unmute)
  7267. /// 1 = negative (mute)
  7268. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7269. {
  7270. int fd;
  7271. nullpo_retv(sd);
  7272. nullpo_retv(tsd);
  7273. fd = tsd->fd;
  7274. WFIFOHEAD(fd,packet_len(0x14b));
  7275. WFIFOW(fd,0) = 0x14b;
  7276. WFIFOB(fd,2) = type;
  7277. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7278. WFIFOSET(fd, packet_len(0x14b));
  7279. }
  7280. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7281. /// 00d1 <type>.B <result>.B
  7282. /// type:
  7283. /// 0 = /ex (deny)
  7284. /// 1 = /in (allow)
  7285. /// result:
  7286. /// 0 = success
  7287. /// 1 = failure
  7288. /// 2 = too many blocks
  7289. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7290. {
  7291. int fd;
  7292. nullpo_retv(sd);
  7293. fd=sd->fd;
  7294. WFIFOHEAD(fd,packet_len(0xd1));
  7295. WFIFOW(fd,0)=0xd1;
  7296. WFIFOB(fd,2)=type;
  7297. WFIFOB(fd,3)=flag;
  7298. WFIFOSET(fd,packet_len(0xd1));
  7299. }
  7300. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7301. /// 00d2 <type>.B <result>.B
  7302. /// type:
  7303. /// 0 = /exall (deny)
  7304. /// 1 = /inall (allow)
  7305. /// result:
  7306. /// 0 = success
  7307. /// 1 = failure
  7308. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7309. {
  7310. int fd;
  7311. nullpo_retv(sd);
  7312. fd=sd->fd;
  7313. WFIFOHEAD(fd,packet_len(0xd2));
  7314. WFIFOW(fd,0)=0xd2;
  7315. WFIFOB(fd,2)=type;
  7316. WFIFOB(fd,3)=flag;
  7317. WFIFOSET(fd,packet_len(0xd2));
  7318. }
  7319. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7320. /// 07fe <bgm>.24B
  7321. void clif_playBGM(struct map_session_data* sd, const char* name)
  7322. {
  7323. int fd;
  7324. nullpo_retv(sd);
  7325. fd = sd->fd;
  7326. WFIFOHEAD(fd,packet_len(0x7fe));
  7327. WFIFOW(fd,0) = 0x7fe;
  7328. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7329. WFIFOSET(fd,packet_len(0x7fe));
  7330. }
  7331. /// Plays/stops a wave sound (ZC_SOUND).
  7332. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7333. /// file name:
  7334. /// relative to data\wav
  7335. /// act:
  7336. /// 0 = play (once)
  7337. /// 1 = play (repeat, does not work)
  7338. /// 2 = stops all sound instances of file name (does not work)
  7339. /// term:
  7340. /// unknown purpose, only relevant to act = 1
  7341. /// npc id:
  7342. /// The accustic direction of the sound is determined by the
  7343. /// relative position of the NPC to the player (3D sound).
  7344. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7345. {
  7346. int fd;
  7347. nullpo_retv(sd);
  7348. nullpo_retv(bl);
  7349. fd = sd->fd;
  7350. WFIFOHEAD(fd,packet_len(0x1d3));
  7351. WFIFOW(fd,0) = 0x1d3;
  7352. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7353. WFIFOB(fd,26) = type;
  7354. WFIFOL(fd,27) = 0;
  7355. WFIFOL(fd,31) = bl->id;
  7356. WFIFOSET(fd,packet_len(0x1d3));
  7357. }
  7358. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7359. {
  7360. unsigned char buf[40];
  7361. nullpo_retv(bl);
  7362. WBUFW(buf,0) = 0x1d3;
  7363. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7364. WBUFB(buf,26) = type;
  7365. WBUFL(buf,27) = 0;
  7366. WBUFL(buf,31) = bl->id;
  7367. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7368. }
  7369. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7370. /// 01f3 <id>.L <effect id>.L
  7371. /// effect id:
  7372. /// @see doc/effect_list.txt
  7373. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7374. {
  7375. unsigned char buf[24];
  7376. nullpo_retv(bl);
  7377. memset(buf, 0, packet_len(0x1f3));
  7378. WBUFW(buf,0) = 0x1f3;
  7379. WBUFL(buf,2) = bl->id;
  7380. WBUFL(buf,6) = type;
  7381. clif_send(buf, packet_len(0x1f3), bl, target);
  7382. if (disguised(bl)) {
  7383. WBUFL(buf,2) = -bl->id;
  7384. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7385. }
  7386. }
  7387. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7388. {
  7389. WFIFOHEAD(fd,10);
  7390. WFIFOW(fd,0) = 0x1f3;
  7391. WFIFOL(fd,2) = bl->id;
  7392. WFIFOL(fd,6) = type;
  7393. WFIFOSET(fd,10);
  7394. }
  7395. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7396. /// 0284 <id>.L <effect id>.L <num data>.L
  7397. /// effect id:
  7398. /// @see doc/effect_list.txt
  7399. /// num data:
  7400. /// effect-dependent value
  7401. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7402. {
  7403. uint8 buf[14];
  7404. WBUFW(buf,0) = 0x284;
  7405. WBUFL(buf,2) = bl->id;
  7406. WBUFL(buf,6) = effect_id;
  7407. WBUFL(buf,10) = num;
  7408. clif_send(buf, packet_len(0x284), bl, target);
  7409. if( disguised(bl) )
  7410. {
  7411. WBUFL(buf,2) = -bl->id;
  7412. clif_send(buf, packet_len(0x284), bl, SELF);
  7413. }
  7414. }
  7415. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7416. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7417. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7418. unsigned short msg_len = strlen(msg) + 1;
  7419. WFIFOHEAD(sd->fd,msg_len + 12);
  7420. WFIFOW(sd->fd,0) = 0x2C1;
  7421. WFIFOW(sd->fd,2) = msg_len + 12;
  7422. WFIFOL(sd->fd,4) = 0;
  7423. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7424. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7425. WFIFOSET(sd->fd, msg_len + 12);
  7426. return 0;
  7427. }
  7428. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7429. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7430. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7431. unsigned short msg_len = strlen(msg) + 1;
  7432. uint8 buf[256];
  7433. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7434. nullpo_retv(bl);
  7435. if( msg_len > sizeof(buf)-12 ) {
  7436. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7437. msg_len = sizeof(buf)-12;
  7438. }
  7439. WBUFW(buf,0) = 0x2C1;
  7440. WBUFW(buf,2) = msg_len + 12;
  7441. WBUFL(buf,4) = bl->id;
  7442. WBUFL(buf,8) = color;
  7443. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7444. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7445. }
  7446. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7447. {
  7448. int fd;
  7449. unsigned short msg_len = strlen(msg) + 1;
  7450. nullpo_retv(sd);
  7451. if(msg_len > 0) {
  7452. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7453. fd = sd->fd;
  7454. WFIFOHEAD(fd, msg_len+12);
  7455. WFIFOW(fd,0) = 0x2C1;
  7456. WFIFOW(fd,2) = msg_len+12;
  7457. WFIFOL(fd,4) = 0;
  7458. WFIFOL(fd,8) = color;
  7459. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7460. WFIFOSET(fd, WFIFOW(fd,2));
  7461. }
  7462. }
  7463. /**
  7464. * Notifies the client that the storage window is still open
  7465. *
  7466. * Should only be used in cases where the client closed the
  7467. * storage window without server's consent
  7468. */
  7469. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7470. // Notify the client that the storage is open
  7471. if( sd->state.storage_flag == 1 ) {
  7472. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7473. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7474. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7475. }
  7476. // Notify the client that the gstorage is open otherwise it will
  7477. // remain locked forever and nobody will be able to access it
  7478. if( sd->state.storage_flag == 2 ) {
  7479. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7480. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7481. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7482. else {
  7483. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7484. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7485. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7486. }
  7487. }
  7488. }
  7489. // refresh the client's screen, getting rid of any effects
  7490. void clif_refresh(struct map_session_data *sd)
  7491. {
  7492. int i;
  7493. nullpo_retv(sd);
  7494. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7495. clif_inventorylist(sd);
  7496. if(pc_iscarton(sd)) {
  7497. clif_cartlist(sd);
  7498. clif_updatestatus(sd,SP_CARTINFO);
  7499. }
  7500. clif_updatestatus(sd,SP_WEIGHT);
  7501. clif_updatestatus(sd,SP_MAXWEIGHT);
  7502. clif_updatestatus(sd,SP_STR);
  7503. clif_updatestatus(sd,SP_AGI);
  7504. clif_updatestatus(sd,SP_VIT);
  7505. clif_updatestatus(sd,SP_INT);
  7506. clif_updatestatus(sd,SP_DEX);
  7507. clif_updatestatus(sd,SP_LUK);
  7508. if (sd->spiritball)
  7509. clif_spiritball_single(sd->fd, sd);
  7510. for(i = 1; i < 5; i++){
  7511. if( sd->talisman[i] > 0 )
  7512. clif_talisman_single(sd->fd, sd, i);
  7513. }
  7514. if (sd->vd.cloth_color)
  7515. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7516. if(hom_is_active(sd->hd))
  7517. clif_send_homdata(sd,SP_ACK,0);
  7518. if( sd->md ) {
  7519. clif_mercenary_info(sd);
  7520. clif_mercenary_skillblock(sd);
  7521. }
  7522. if( sd->ed )
  7523. clif_elemental_info(sd);
  7524. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7525. clif_weather_check(sd);
  7526. if( sd->chatID )
  7527. chat_leavechat(sd,0);
  7528. if( sd->state.vending )
  7529. clif_openvending(sd, sd->bl.id, sd->vending);
  7530. if( pc_issit(sd) )
  7531. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7532. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7533. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7534. else
  7535. clif_changed_dir(&sd->bl, SELF);
  7536. // unlike vending, resuming buyingstore crashes the client.
  7537. buyingstore_close(sd);
  7538. mail_clear(sd);
  7539. if( disguised(&sd->bl) ) {/* refresh-da */
  7540. short disguise = sd->disguise;
  7541. pc_disguise(sd, 0);
  7542. pc_disguise(sd, disguise);
  7543. }
  7544. clif_refresh_storagewindow(sd);
  7545. }
  7546. /// Updates the object's (bl) name on client.
  7547. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7548. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7549. void clif_charnameack (int fd, struct block_list *bl)
  7550. {
  7551. unsigned char buf[103];
  7552. int cmd = 0x95;
  7553. nullpo_retv(bl);
  7554. WBUFW(buf,0) = cmd;
  7555. WBUFL(buf,2) = bl->id;
  7556. switch( bl->type )
  7557. {
  7558. case BL_PC:
  7559. {
  7560. struct map_session_data *ssd = (struct map_session_data *)bl;
  7561. struct party_data *p = NULL;
  7562. struct guild *g = NULL;
  7563. int ps = -1;
  7564. //Requesting your own "shadow" name. [Skotlex]
  7565. if (ssd->fd == fd && ssd->disguise)
  7566. WBUFL(buf,2) = -bl->id;
  7567. if( ssd->fakename[0] ) {
  7568. WBUFW(buf, 0) = cmd = 0x195;
  7569. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7570. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7571. break;
  7572. }
  7573. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7574. if( ssd->status.party_id ) {
  7575. p = party_search(ssd->status.party_id);
  7576. }
  7577. if( ssd->status.guild_id ) {
  7578. if( ( g = ssd->guild ) != NULL ) {
  7579. int i;
  7580. 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);
  7581. if( i < g->max_member ) ps = g->member[i].position;
  7582. }
  7583. }
  7584. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7585. p = NULL;
  7586. }
  7587. if (p == NULL && g == NULL)
  7588. break;
  7589. WBUFW(buf, 0) = cmd = 0x195;
  7590. if (p)
  7591. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7592. else
  7593. WBUFB(buf,30) = 0;
  7594. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7595. {
  7596. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7597. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7598. } else { //Assume no guild.
  7599. WBUFB(buf,54) = 0;
  7600. WBUFB(buf,78) = 0;
  7601. }
  7602. }
  7603. break;
  7604. //[blackhole89]
  7605. case BL_HOM:
  7606. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7607. break;
  7608. case BL_MER:
  7609. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7610. break;
  7611. case BL_PET:
  7612. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7613. break;
  7614. case BL_NPC:
  7615. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7616. break;
  7617. case BL_MOB:
  7618. {
  7619. struct mob_data *md = (struct mob_data *)bl;
  7620. nullpo_retv(md);
  7621. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7622. if( md->guardian_data && md->guardian_data->guild_id )
  7623. {
  7624. WBUFW(buf, 0) = cmd = 0x195;
  7625. WBUFB(buf,30) = 0;
  7626. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7627. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7628. }
  7629. else if( battle_config.show_mob_info )
  7630. {
  7631. char mobhp[50], *str_p = mobhp;
  7632. WBUFW(buf, 0) = cmd = 0x195;
  7633. if( battle_config.show_mob_info&4 )
  7634. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7635. if( battle_config.show_mob_info&1 )
  7636. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7637. if( battle_config.show_mob_info&2 )
  7638. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7639. //Even thought mobhp ain't a name, we send it as one so the client
  7640. //can parse it. [Skotlex]
  7641. if( str_p != mobhp )
  7642. {
  7643. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7644. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7645. WBUFB(buf,54) = 0;
  7646. WBUFB(buf,78) = 0;
  7647. }
  7648. }
  7649. }
  7650. break;
  7651. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7652. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7653. // break;
  7654. return;
  7655. case BL_ELEM:
  7656. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7657. break;
  7658. default:
  7659. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7660. return;
  7661. }
  7662. // if no receipient specified just update nearby clients
  7663. if (fd == 0)
  7664. clif_send(buf, packet_len(cmd), bl, AREA);
  7665. else {
  7666. WFIFOHEAD(fd, packet_len(cmd));
  7667. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7668. WFIFOSET(fd, packet_len(cmd));
  7669. }
  7670. }
  7671. //Used to update when a char leaves a party/guild. [Skotlex]
  7672. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7673. void clif_charnameupdate (struct map_session_data *ssd)
  7674. {
  7675. unsigned char buf[103];
  7676. int cmd = 0x195, ps = -1;
  7677. struct party_data *p = NULL;
  7678. struct guild *g = NULL;
  7679. nullpo_retv(ssd);
  7680. if( ssd->fakename[0] )
  7681. return; //No need to update as the party/guild was not displayed anyway.
  7682. WBUFW(buf,0) = cmd;
  7683. WBUFL(buf,2) = ssd->bl.id;
  7684. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7685. if (!battle_config.display_party_name) {
  7686. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7687. p = party_search(ssd->status.party_id);
  7688. }else{
  7689. if (ssd->status.party_id > 0)
  7690. p = party_search(ssd->status.party_id);
  7691. }
  7692. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7693. {
  7694. int i;
  7695. 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);
  7696. if( i < g->max_member ) ps = g->member[i].position;
  7697. }
  7698. if( p )
  7699. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7700. else
  7701. WBUFB(buf,30) = 0;
  7702. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7703. {
  7704. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7705. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7706. }
  7707. else
  7708. {
  7709. WBUFB(buf,54) = 0;
  7710. WBUFB(buf,78) = 0;
  7711. }
  7712. // Update nearby clients
  7713. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7714. }
  7715. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7716. /// 01ff <id>.L <x>.W <y>.W
  7717. ///
  7718. /// Visually moves(instant) a character to x,y. The char moves even
  7719. /// when the target cell isn't walkable. If the char is sitting it
  7720. /// stays that way.
  7721. void clif_slide(struct block_list *bl, int x, int y)
  7722. {
  7723. unsigned char buf[10];
  7724. nullpo_retv(bl);
  7725. WBUFW(buf, 0) = 0x01ff;
  7726. WBUFL(buf, 2) = bl->id;
  7727. WBUFW(buf, 6) = x;
  7728. WBUFW(buf, 8) = y;
  7729. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7730. if( disguised(bl) )
  7731. {
  7732. WBUFL(buf,2) = -bl->id;
  7733. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7734. }
  7735. }
  7736. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7737. /// 008d <packet len>.W <id>.L <message>.?B
  7738. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7739. {
  7740. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7741. int len_mes = strlen(mes)+1; //Account for \0
  7742. if (len_mes > sizeof(buf)-8) {
  7743. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7744. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7745. }
  7746. // send message to others
  7747. WBUFW(buf,0) = 0x8d;
  7748. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7749. WBUFL(buf,4) = bl->id;
  7750. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7751. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7752. // send back message to the speaker
  7753. if( bl->type == BL_PC ) {
  7754. WBUFW(buf,0) = 0x8e;
  7755. WBUFW(buf, 2) = len_mes + 4;
  7756. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7757. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7758. }
  7759. }
  7760. /*==========================
  7761. * Minimap fix [Kevin]
  7762. * Remove dot from minimap
  7763. *--------------------------*/
  7764. void clif_party_xy_remove(struct map_session_data *sd)
  7765. {
  7766. unsigned char buf[16];
  7767. nullpo_retv(sd);
  7768. WBUFW(buf,0)=0x107;
  7769. WBUFL(buf,2)=sd->status.account_id;
  7770. WBUFW(buf,6)=-1;
  7771. WBUFW(buf,8)=-1;
  7772. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7773. }
  7774. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7775. /// 0215 <msg id>.L
  7776. /// msg id:
  7777. /// 0x15 = End all negative status (PA_GOSPEL)
  7778. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7779. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7780. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7781. /// 0x19 = All stats +20 (PA_GOSPEL)
  7782. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7783. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7784. /// 0x1e = DEF +25% (PA_GOSPEL)
  7785. /// 0x1f = ATK +100% (PA_GOSPEL)
  7786. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7787. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7788. /// ? = nothing
  7789. void clif_gospel_info(struct map_session_data *sd, int type)
  7790. {
  7791. int fd=sd->fd;
  7792. WFIFOHEAD(fd,packet_len(0x215));
  7793. WFIFOW(fd,0)=0x215;
  7794. WFIFOL(fd,2)=type;
  7795. WFIFOSET(fd, packet_len(0x215));
  7796. }
  7797. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7798. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7799. /// result:
  7800. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7801. /// star:
  7802. /// 0 = Place of the Sun
  7803. /// 1 = Place of the Moon
  7804. /// 2 = Place of the Stars
  7805. /// 1 = Star Gladiator %s's %s: <mapname>
  7806. /// star:
  7807. /// 0 = Place of the Sun
  7808. /// 1 = Place of the Moon
  7809. /// 2 = Place of the Stars
  7810. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7811. /// star:
  7812. /// 0 = Target of the Sun
  7813. /// 1 = Target of the Moon
  7814. /// 2 = Target of the Stars
  7815. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7816. /// star:
  7817. /// 0 = Monster of the Sun
  7818. /// 1 = Monster of the Moon
  7819. /// 2 = Monster of the Stars
  7820. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7821. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7822. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7823. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7824. /// 40 = Target HP : <monster_id used as HP>
  7825. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7826. {
  7827. int fd = sd->fd;
  7828. WFIFOHEAD(fd,packet_len(0x20e));
  7829. WFIFOW(fd,0) = 0x20e;
  7830. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7831. WFIFOL(fd,26) = monster_id;
  7832. WFIFOB(fd,30) = star;
  7833. WFIFOB(fd,31) = result;
  7834. WFIFOSET(fd,packet_len(0x20e));
  7835. }
  7836. /*==========================================
  7837. * Info about Star Glaldiator save map [Komurka]
  7838. * type: 1: Information, 0: Map registered
  7839. *------------------------------------------*/
  7840. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7841. {
  7842. char mapname[MAP_NAME_LENGTH_EXT];
  7843. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7844. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7845. }
  7846. /*==========================================
  7847. * Info about Star Glaldiator hate mob [Komurka]
  7848. * type: 1: Register mob, 0: Information.
  7849. *------------------------------------------*/
  7850. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7851. {
  7852. if( pcdb_checkid(class_) ) {
  7853. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7854. } else if( mobdb_checkid(class_) ) {
  7855. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7856. } else {
  7857. 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);
  7858. }
  7859. }
  7860. /*==========================================
  7861. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7862. *------------------------------------------*/
  7863. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7864. {
  7865. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7866. }
  7867. /*==========================================
  7868. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7869. *------------------------------------------*/
  7870. void clif_feel_hate_reset(struct map_session_data *sd)
  7871. {
  7872. clif_starskill(sd, "", 0, 0, 30);
  7873. }
  7874. /// Equip window (un)tick ack (ZC_CONFIG).
  7875. /// 02d9 <type>.L <value>.L
  7876. /// type:
  7877. /// 0 = open equip window
  7878. /// value:
  7879. /// 0 = disabled
  7880. /// 1 = enabled
  7881. void clif_equiptickack(struct map_session_data* sd, int flag)
  7882. {
  7883. int fd;
  7884. nullpo_retv(sd);
  7885. fd = sd->fd;
  7886. WFIFOHEAD(fd, packet_len(0x2d9));
  7887. WFIFOW(fd, 0) = 0x2d9;
  7888. WFIFOL(fd, 2) = 0;
  7889. WFIFOL(fd, 6) = flag;
  7890. WFIFOSET(fd, packet_len(0x2d9));
  7891. }
  7892. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7893. /// 02da <open equip window>.B
  7894. /// open equip window:
  7895. /// 0 = disabled
  7896. /// 1 = enabled
  7897. void clif_equipcheckbox(struct map_session_data* sd)
  7898. {
  7899. int fd;
  7900. nullpo_retv(sd);
  7901. fd = sd->fd;
  7902. WFIFOHEAD(fd, packet_len(0x2da));
  7903. WFIFOW(fd, 0) = 0x2da;
  7904. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7905. WFIFOSET(fd, packet_len(0x2da));
  7906. }
  7907. /// Sends info about a player's equipped items.
  7908. /// 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)
  7909. /// 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)
  7910. /// 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)
  7911. /// 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)
  7912. /// 0997 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.31B* (ZC_EQUIPWIN_MICROSCOPE_V5, PACKETVER >= 20120925)
  7913. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7914. {
  7915. uint8* buf;
  7916. int i, n, fd, offset = 0;
  7917. #if PACKETVER < 20100629
  7918. const int s = 26;
  7919. #elif PACKETVER < 20120925
  7920. const int s = 28;
  7921. #else
  7922. const int s = 31;
  7923. #endif
  7924. nullpo_retv(sd);
  7925. nullpo_retv(tsd);
  7926. fd = sd->fd;
  7927. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7928. buf = WFIFOP(fd,0);
  7929. #if PACKETVER < 20101124
  7930. WBUFW(buf, 0) = 0x2d7;
  7931. #elif PACKETVER < 20120925
  7932. WBUFW(buf, 0) = 0x859;
  7933. #else
  7934. WBUFW(buf, 0) = 0x997;
  7935. #endif
  7936. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7937. WBUFW(buf,28) = tsd->status.class_;
  7938. WBUFW(buf,30) = tsd->vd.hair_style;
  7939. WBUFW(buf,32) = tsd->vd.head_bottom;
  7940. WBUFW(buf,34) = tsd->vd.head_mid;
  7941. WBUFW(buf,36) = tsd->vd.head_top;
  7942. #if PACKETVER >= 20110111
  7943. WBUFW(buf,38) = tsd->vd.robe;
  7944. offset+= 2;
  7945. buf = WBUFP(buf,2);
  7946. #endif
  7947. WBUFW(buf,38) = tsd->vd.hair_color;
  7948. WBUFW(buf,40) = tsd->vd.cloth_color;
  7949. WBUFB(buf,42) = tsd->vd.sex;
  7950. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7951. {
  7952. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7953. continue;
  7954. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7955. continue;
  7956. // Add item info : refine, identify flag, element, etc.
  7957. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7958. n++;
  7959. }
  7960. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7961. WFIFOSET(fd, WFIFOW(fd, 2));
  7962. }
  7963. /// Display msgstringtable.txt string (ZC_MSG).
  7964. /// 0291 <message>.W
  7965. void clif_msg(struct map_session_data* sd, unsigned short id)
  7966. {
  7967. int fd;
  7968. nullpo_retv(sd);
  7969. fd = sd->fd;
  7970. WFIFOHEAD(fd, packet_len(0x291));
  7971. WFIFOW(fd, 0) = 0x291;
  7972. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7973. WFIFOSET(fd, packet_len(0x291));
  7974. }
  7975. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7976. /// 0x7e2 <message>.W <value>.L
  7977. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7978. {
  7979. int fd = sd->fd;
  7980. WFIFOHEAD(fd, packet_len(0x7e2));
  7981. WFIFOW(fd,0) = 0x7e2;
  7982. WFIFOW(fd,2) = id;
  7983. WFIFOL(fd,4) = value;
  7984. WFIFOSET(fd, packet_len(0x7e2));
  7985. }
  7986. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7987. /// 07e6 <skill id>.W <msg id>.L
  7988. ///
  7989. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7990. /// "[SkillName] Message"
  7991. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7992. {
  7993. int fd = sd->fd;
  7994. WFIFOHEAD(fd, packet_len(0x7e6));
  7995. WFIFOW(fd,0) = 0x7e6;
  7996. WFIFOW(fd,2) = skill_id;
  7997. WFIFOL(fd,4) = msg_id;
  7998. WFIFOSET(fd, packet_len(0x7e6));
  7999. }
  8000. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8001. /// Returns true if the packet was parsed successfully.
  8002. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8003. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8004. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  8005. {
  8006. char *text, *name, *message;
  8007. unsigned int packetlen, textlen, namelen, messagelen;
  8008. int fd = sd->fd;
  8009. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8010. *name_ = NULL;
  8011. *namelen_ = 0;
  8012. *message_ = NULL;
  8013. *messagelen_ = 0;
  8014. packetlen = RFIFOW(fd,info->pos[0]);
  8015. // basic structure checks
  8016. if( packetlen < 4 + 1 )
  8017. { // 4-byte header and at least an empty string is expected
  8018. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8019. return false;
  8020. }
  8021. text = (char*)RFIFOP(fd,info->pos[1]);
  8022. textlen = packetlen - 4;
  8023. // process <name> part of the packet
  8024. if( format == 0 )
  8025. {// name and message are separated by ' : '
  8026. // validate name
  8027. name = text;
  8028. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8029. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8030. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8031. {
  8032. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8033. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8034. set_eof(fd); // Just kick them out to correct it.
  8035. return false;
  8036. }
  8037. message = name + namelen + 3;
  8038. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8039. }
  8040. else
  8041. {// name has fixed width
  8042. if( textlen < NAME_LENGTH + 1 )
  8043. {
  8044. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8045. return false;
  8046. }
  8047. // validate name
  8048. name = text;
  8049. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8050. if( name[namelen] != '\0' )
  8051. { // only restriction is that the name must be zero-terminated
  8052. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8053. return false;
  8054. }
  8055. message = name + NAME_LENGTH;
  8056. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8057. }
  8058. if( messagelen != strnlen(message, messagelen)+1 )
  8059. { // the declared length must match real length
  8060. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8061. return false;
  8062. }
  8063. // verify <message> part of the packet
  8064. if( message[messagelen-1] != '\0' )
  8065. { // message must be zero-terminated
  8066. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8067. return false;
  8068. }
  8069. if( messagelen > CHAT_SIZE_MAX-1 )
  8070. { // messages mustn't be too long
  8071. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8072. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8073. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8074. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8075. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8076. return false;
  8077. }
  8078. *name_ = name;
  8079. *namelen_ = namelen;
  8080. *message_ = message;
  8081. *messagelen_ = messagelen;
  8082. return true;
  8083. }
  8084. // ---------------------
  8085. // clif_guess_PacketVer
  8086. // ---------------------
  8087. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8088. // error codes:
  8089. // 0 - Success
  8090. // 1 - Unknown packet_ver
  8091. // 2 - Invalid account_id
  8092. // 3 - Invalid char_id
  8093. // 4 - Invalid login_id1 (reserved)
  8094. // 5 - Invalid client_tick (reserved)
  8095. // 6 - Invalid sex
  8096. // Only the first 'invalid' error that appears is used.
  8097. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8098. {
  8099. static int err = 1;
  8100. static int packet_ver = -1;
  8101. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  8102. if (get_previous)
  8103. {//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]
  8104. if( error )
  8105. *error = err;
  8106. return packet_ver;
  8107. }
  8108. //By default, start searching on the default one.
  8109. err = 1;
  8110. packet_ver = clif_config.packet_db_ver;
  8111. cmd = RFIFOW(fd,0);
  8112. packet_len = RFIFOREST(fd);
  8113. #define SET_ERROR(n) \
  8114. if( err == 1 )\
  8115. err = n;\
  8116. //define SET_ERROR
  8117. // FIXME: If the packet is not received at once, this will FAIL.
  8118. // Figure out, when it happens, that only part of the packet is
  8119. // received, or fix the function to be able to deal with that
  8120. // case.
  8121. #define CHECK_PACKET_VER() \
  8122. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8123. ;/* not wanttoconnection or wrong length */\
  8124. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8125. { SET_ERROR(2); }/* invalid account_id */\
  8126. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8127. { SET_ERROR(3); }/* invalid char_id */\
  8128. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8129. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8130. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8131. { SET_ERROR(6); }/* invalid sex */\
  8132. else\
  8133. {\
  8134. err = 0;\
  8135. if( error )\
  8136. *error = 0;\
  8137. return packet_ver;\
  8138. }\
  8139. //define CHECK_PACKET_VER
  8140. CHECK_PACKET_VER();//Default packet version found.
  8141. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8142. CHECK_PACKET_VER();
  8143. }
  8144. if( error )
  8145. *error = err;
  8146. packet_ver = -1;
  8147. return -1;
  8148. #undef SET_ERROR
  8149. #undef CHECK_PACKET_VER
  8150. }
  8151. // ------------
  8152. // clif_parse_*
  8153. // ------------
  8154. // Parses incoming (player) connection
  8155. /// Request to connect to map-server.
  8156. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8157. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8158. /// There are various variants of this packet, some of them have padding between fields.
  8159. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8160. {
  8161. struct block_list* bl;
  8162. struct auth_node* node;
  8163. int cmd, account_id, char_id, login_id1, sex;
  8164. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8165. 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])
  8166. if (sd) {
  8167. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8168. return;
  8169. }
  8170. // Only valid packet version get here
  8171. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8172. cmd = RFIFOW(fd,0);
  8173. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8174. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8175. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8176. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8177. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8178. if( packet_ver < 5 || // reject really old client versions
  8179. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8180. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8181. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8182. {// packet version rejected
  8183. 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));
  8184. WFIFOHEAD(fd,packet_len(0x6a));
  8185. WFIFOW(fd,0) = 0x6a;
  8186. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8187. WFIFOSET(fd,packet_len(0x6a));
  8188. set_eof(fd);
  8189. return;
  8190. }
  8191. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8192. clif_authfail_fd(fd,1);// server closed
  8193. return;
  8194. }
  8195. //Check for double login.
  8196. bl = map_id2bl(account_id);
  8197. if(bl && bl->type != BL_PC) {
  8198. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8199. WFIFOHEAD(fd,packet_len(0x6a));
  8200. WFIFOW(fd,0) = 0x6a;
  8201. WFIFOB(fd,2) = 3; // Rejected by server
  8202. WFIFOSET(fd,packet_len(0x6a));
  8203. set_eof(fd);
  8204. return;
  8205. }
  8206. if (bl ||
  8207. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8208. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8209. {
  8210. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8211. return;
  8212. }
  8213. CREATE(sd, TBL_PC, 1);
  8214. sd->fd = fd;
  8215. sd->packet_ver = packet_ver;
  8216. session[fd]->session_data = sd;
  8217. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8218. #if PACKETVER < 20070521
  8219. WFIFOHEAD(fd,4);
  8220. WFIFOL(fd,0) = sd->bl.id;
  8221. WFIFOSET(fd,4);
  8222. #else
  8223. WFIFOHEAD(fd,packet_len(0x283));
  8224. WFIFOW(fd,0) = 0x283;
  8225. WFIFOL(fd,2) = sd->bl.id;
  8226. WFIFOSET(fd,packet_len(0x283));
  8227. #endif
  8228. chrif_authreq(sd,false);
  8229. }
  8230. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8231. /// 007d
  8232. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8233. {
  8234. int i;
  8235. bool guild_notice = false;
  8236. if(sd->bl.prev != NULL)
  8237. return;
  8238. if (!sd->state.active) { //Character loading is not complete yet!
  8239. //Let pc_reg_received reinvoke this when ready.
  8240. sd->state.connect_new = 0;
  8241. return;
  8242. }
  8243. if (sd->state.rewarp) { //Rewarp player.
  8244. sd->state.rewarp = 0;
  8245. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8246. return;
  8247. }
  8248. sd->state.warping = 0;
  8249. // look
  8250. #if PACKETVER < 4
  8251. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8252. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8253. #else
  8254. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8255. #endif
  8256. if(sd->vd.cloth_color)
  8257. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8258. // item
  8259. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8260. pc_checkitem(sd);
  8261. // cart
  8262. if(pc_iscarton(sd)) {
  8263. clif_cartlist(sd);
  8264. clif_updatestatus(sd,SP_CARTINFO);
  8265. }
  8266. // weight
  8267. clif_updatestatus(sd,SP_WEIGHT);
  8268. clif_updatestatus(sd,SP_MAXWEIGHT);
  8269. // guild
  8270. // (needs to go before clif_spawn() to show guild emblems correctly)
  8271. if(sd->status.guild_id)
  8272. guild_send_memberinfoshort(sd,1);
  8273. if(battle_config.pc_invincible_time > 0) {
  8274. if(map_flag_gvg(sd->bl.m))
  8275. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8276. else
  8277. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8278. }
  8279. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8280. map_spawnmobs(sd->bl.m);
  8281. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8282. map[sd->bl.m].users_pvp++;
  8283. }
  8284. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8285. // reset the callshop flag if the player changes map
  8286. sd->state.callshop = 0;
  8287. if(map_addblock(&sd->bl))
  8288. return;
  8289. clif_spawn(&sd->bl);
  8290. // Party
  8291. // (needs to go after clif_spawn() to show hp bars correctly)
  8292. if(sd->status.party_id) {
  8293. party_send_movemap(sd);
  8294. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8295. }
  8296. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8297. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8298. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8299. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8300. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8301. sd->pvp_rank = 0;
  8302. sd->pvp_lastusers = 0;
  8303. sd->pvp_point = 5;
  8304. sd->pvp_won = 0;
  8305. sd->pvp_lost = 0;
  8306. }
  8307. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8308. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8309. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8310. if (map[sd->bl.m].flag.gvg_dungeon)
  8311. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8312. if( map_flag_gvg(sd->bl.m) )
  8313. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8314. // info about nearby objects
  8315. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8316. 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);
  8317. // pet
  8318. if( sd->pd ) {
  8319. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8320. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8321. pet_menu(sd, 3); //Option 3 is return to egg.
  8322. } else {
  8323. if(map_addblock(&sd->pd->bl))
  8324. return;
  8325. clif_spawn(&sd->pd->bl);
  8326. clif_send_petdata(sd,sd->pd,0,0);
  8327. clif_send_petstatus(sd);
  8328. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8329. }
  8330. }
  8331. //homunculus [blackhole89]
  8332. if( hom_is_active(sd->hd) ) {
  8333. if(map_addblock(&sd->hd->bl))
  8334. return;
  8335. clif_spawn(&sd->hd->bl);
  8336. clif_send_homdata(sd,SP_ACK,0);
  8337. clif_hominfo(sd,sd->hd,1);
  8338. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8339. clif_homskillinfoblock(sd);
  8340. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8341. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8342. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8343. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8344. }
  8345. if( sd->md ) {
  8346. if(map_addblock(&sd->md->bl))
  8347. return;
  8348. clif_spawn(&sd->md->bl);
  8349. clif_mercenary_info(sd);
  8350. clif_mercenary_skillblock(sd);
  8351. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8352. }
  8353. if( sd->ed ) {
  8354. map_addblock(&sd->ed->bl);
  8355. clif_spawn(&sd->ed->bl);
  8356. clif_elemental_info(sd);
  8357. clif_elemental_updatestatus(sd,SP_HP);
  8358. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8359. clif_elemental_updatestatus(sd,SP_SP);
  8360. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8361. }
  8362. if(sd->state.connect_new) {
  8363. int lv;
  8364. guild_notice = true;
  8365. sd->state.connect_new = 0;
  8366. clif_skillinfoblock(sd);
  8367. clif_hotkeys_send(sd);
  8368. clif_updatestatus(sd,SP_BASEEXP);
  8369. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8370. clif_updatestatus(sd,SP_JOBEXP);
  8371. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8372. clif_updatestatus(sd,SP_SKILLPOINT);
  8373. clif_initialstatus(sd);
  8374. if (sd->sc.option&OPTION_FALCON)
  8375. clif_status_load(&sd->bl, SI_FALCON, 1);
  8376. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8377. clif_status_load(&sd->bl, SI_RIDING, 1);
  8378. else if (sd->sc.option&OPTION_WUGRIDER)
  8379. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8380. else if (sd->sc.data[SC_ALL_RIDING])
  8381. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8382. if(sd->status.manner < 0)
  8383. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8384. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8385. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8386. if(sd->bl.m == sd->feel_map[0].m
  8387. || sd->bl.m == sd->feel_map[1].m
  8388. || sd->bl.m == sd->feel_map[2].m)
  8389. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8390. }
  8391. if(sd->pd && sd->pd->pet.intimate > 900)
  8392. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8393. if(hom_is_active(sd->hd))
  8394. hom_init_timers(sd->hd);
  8395. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8396. sd->state.night = 1;
  8397. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8398. }
  8399. // Notify everyone that this char logged in [Skotlex].
  8400. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8401. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8402. //Login Event
  8403. npc_script_event(sd, NPCE_LOGIN);
  8404. }
  8405. } else {
  8406. //For some reason the client "loses" these on warp/map-change.
  8407. clif_updatestatus(sd,SP_STR);
  8408. clif_updatestatus(sd,SP_AGI);
  8409. clif_updatestatus(sd,SP_VIT);
  8410. clif_updatestatus(sd,SP_INT);
  8411. clif_updatestatus(sd,SP_DEX);
  8412. clif_updatestatus(sd,SP_LUK);
  8413. // abort currently running script
  8414. sd->state.using_fake_npc = 0;
  8415. sd->state.menu_or_input = 0;
  8416. sd->npc_menu = 0;
  8417. if(sd->npc_id)
  8418. npc_event_dequeue(sd);
  8419. }
  8420. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8421. #if PACKETVER >= 20070918
  8422. clif_partyinvitationstate(sd);
  8423. clif_equipcheckbox(sd);
  8424. #endif
  8425. #ifdef VIP_ENABLE
  8426. if (!sd->disableshowrate) {
  8427. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8428. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8429. }
  8430. #endif
  8431. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8432. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8433. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8434. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8435. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8436. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8437. { //Display night.
  8438. if( !sd->state.night )
  8439. {
  8440. sd->state.night = 1;
  8441. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8442. }
  8443. }
  8444. else if( sd->state.night )
  8445. { //Clear night display.
  8446. sd->state.night = 0;
  8447. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8448. }
  8449. if( map[sd->bl.m].flag.battleground )
  8450. {
  8451. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8452. if( map[sd->bl.m].flag.battleground == 2 )
  8453. clif_bg_updatescore_single(sd);
  8454. }
  8455. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8456. {
  8457. char output[128];
  8458. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8459. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8460. }
  8461. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8462. map[sd->bl.m].hpmeter_visible++;
  8463. sd->state.hpmeter_visible = 1;
  8464. }
  8465. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8466. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8467. sd->state.changemap = false;
  8468. // Instances do not need their own channels
  8469. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8470. channel_mjoin(sd); //join new map
  8471. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8472. clif_guild_notice(sd, sd->guild); // Displays at end
  8473. mail_clear(sd);
  8474. clif_maptypeproperty2(&sd->bl,SELF);
  8475. /* Guild Aura Init */
  8476. if( sd->state.gmaster_flag ) {
  8477. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8478. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8479. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8480. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8481. }
  8482. if( sd->state.vending ) { /* show we have a vending */
  8483. clif_openvending(sd,sd->bl.id,sd->vending);
  8484. clif_showvendingboard(&sd->bl,sd->message,0);
  8485. }
  8486. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8487. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8488. npc_script_event(sd, NPCE_LOADMAP);
  8489. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8490. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8491. if (sd->sc.opt2) //Client loses these on warp.
  8492. clif_changeoption(&sd->bl);
  8493. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8494. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8495. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8496. }
  8497. clif_weather_check(sd);
  8498. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8499. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8500. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8501. else
  8502. sd->areanpc_id = 0;
  8503. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8504. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8505. pc_setdead(sd);
  8506. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8507. if(pc_isdead(sd))
  8508. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8509. else {
  8510. skill_usave_trigger(sd);
  8511. if (battle_config.spawn_direction)
  8512. clif_changed_dir(&sd->bl, SELF);
  8513. }
  8514. // Trigger skill effects if you appear standing on them
  8515. if(!battle_config.pc_invincible_time)
  8516. skill_unit_move(&sd->bl,gettick(),1);
  8517. // NPC Quest / Event Icon Check [Kisuka]
  8518. #if PACKETVER >= 20090218
  8519. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8520. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8521. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8522. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8523. if( sd->class_ == qi->job )
  8524. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8525. } else {
  8526. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8527. }
  8528. }
  8529. }
  8530. #endif
  8531. }
  8532. /// Server's tick (ZC_NOTIFY_TIME).
  8533. /// 007f <time>.L
  8534. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8535. {
  8536. int fd = sd->fd;
  8537. WFIFOHEAD(fd,packet_len(0x7f));
  8538. WFIFOW(fd,0) = 0x7f;
  8539. WFIFOL(fd,2) = time;
  8540. WFIFOSET(fd,packet_len(0x7f));
  8541. }
  8542. /// Request for server's tick.
  8543. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8544. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8545. /// There are various variants of this packet, some of them have padding between fields.
  8546. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8547. {
  8548. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8549. clif_notify_time(sd, gettick());
  8550. }
  8551. /// Sends hotkey bar.
  8552. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8553. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8554. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8555. void clif_hotkeys_send(struct map_session_data *sd) {
  8556. #ifdef HOTKEY_SAVING
  8557. const int fd = sd->fd;
  8558. int i;
  8559. #if PACKETVER < 20090603
  8560. const int cmd = 0x2b9;
  8561. #else
  8562. const int cmd = 0x7d9;
  8563. #endif
  8564. if (!fd) return;
  8565. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8566. WFIFOW(fd, 0) = cmd;
  8567. for(i = 0; i < MAX_HOTKEYS; i++) {
  8568. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8569. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8570. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8571. }
  8572. WFIFOSET(fd, packet_len(cmd));
  8573. #endif
  8574. }
  8575. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8576. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8577. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8578. #ifdef HOTKEY_SAVING
  8579. unsigned short idx;
  8580. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8581. idx = RFIFOW(fd, info->pos[0]);
  8582. if (idx >= MAX_HOTKEYS) return;
  8583. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8584. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8585. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8586. #endif
  8587. }
  8588. /// Displays cast-like progress bar (ZC_PROGRESS).
  8589. /// 02f0 <color>.L <time>.L
  8590. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8591. {
  8592. int fd = sd->fd;
  8593. WFIFOHEAD(fd,packet_len(0x2f0));
  8594. WFIFOW(fd,0) = 0x2f0;
  8595. WFIFOL(fd,2) = color;
  8596. WFIFOL(fd,6) = second;
  8597. WFIFOSET(fd,packet_len(0x2f0));
  8598. }
  8599. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8600. /// 02f2
  8601. void clif_progressbar_abort(struct map_session_data * sd)
  8602. {
  8603. int fd = sd->fd;
  8604. WFIFOHEAD(fd,packet_len(0x2f2));
  8605. WFIFOW(fd,0) = 0x2f2;
  8606. WFIFOSET(fd,packet_len(0x2f2));
  8607. }
  8608. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8609. /// 02f1
  8610. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8611. {
  8612. int npc_id = sd->progressbar.npc_id;
  8613. if( gettick() < sd->progressbar.timeout && sd->st )
  8614. sd->st->state = END;
  8615. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8616. npc_scriptcont(sd, npc_id, false);
  8617. }
  8618. /// Request to walk to a certain position on the current map.
  8619. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8620. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8621. /// There are various variants of this packet, some of them have padding between fields.
  8622. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8623. {
  8624. short x, y;
  8625. if (pc_isdead(sd)) {
  8626. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8627. return;
  8628. }
  8629. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8630. ; //You CAN walk on this OPT1 value.
  8631. else if( sd->progressbar.npc_id )
  8632. clif_progressbar_abort(sd);
  8633. else if (pc_cant_act(sd))
  8634. return;
  8635. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8636. return;
  8637. // Cloaking wall check is actually updated when you click to process next movement
  8638. // not when you move each cell. This is official behaviour.
  8639. if (sd->sc.data[SC_CLOAKING])
  8640. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8641. pc_delinvincibletimer(sd);
  8642. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8643. //Set last idle time... [Skotlex]
  8644. if (battle_config.idletime_option&IDLE_WALK)
  8645. sd->idletime = last_tick;
  8646. unit_walktoxy(&sd->bl, x, y, 4);
  8647. }
  8648. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8649. /// 018b <result>.W
  8650. /// result:
  8651. /// 0 = disconnect (quit)
  8652. /// 1 = cannot disconnect (wait 10 seconds)
  8653. /// ? = ignored
  8654. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8655. {
  8656. int fd = sd->fd;
  8657. WFIFOHEAD(fd,packet_len(0x18b));
  8658. WFIFOW(fd,0) = 0x18b;
  8659. WFIFOW(fd,2) = result;
  8660. WFIFOSET(fd,packet_len(0x18b));
  8661. }
  8662. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8663. /// 018a <type>.W
  8664. /// type:
  8665. /// 0 = quit
  8666. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8667. {
  8668. /* Rovert's prevent logout option fixed [Valaris] */
  8669. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8670. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8671. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8672. {
  8673. set_eof(fd);
  8674. pc_damage_log_clear(sd,0);
  8675. clif_disconnect_ack(sd, 0);
  8676. } else {
  8677. clif_disconnect_ack(sd, 1);
  8678. }
  8679. }
  8680. /// Requesting unit's name.
  8681. /// 0094 <id>.L (CZ_REQNAME)
  8682. /// 0368 <id>.L (CZ_REQNAME2)
  8683. /// There are various variants of this packet, some of them have padding between fields.
  8684. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8685. {
  8686. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8687. struct block_list* bl;
  8688. //struct status_change *sc;
  8689. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8690. id = sd->bl.id;
  8691. bl = map_id2bl(id);
  8692. if( bl == NULL )
  8693. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8694. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8695. return; // Block namerequests past view range
  8696. // 'see people in GM hide' cheat detection
  8697. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8698. sc = status_get_sc(bl);
  8699. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8700. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8701. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8702. ) {
  8703. char gm_msg[256];
  8704. 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);
  8705. ShowWarning(gm_msg);
  8706. // information is sent to all online GMs
  8707. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8708. return;
  8709. }
  8710. */
  8711. clif_charnameack(fd, bl);
  8712. }
  8713. /// Validates and processes global messages
  8714. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8715. /// There are various variants of this packet.
  8716. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8717. {
  8718. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8719. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8720. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8721. char *name, *message, *fakename = NULL;
  8722. int namelen, messagelen;
  8723. bool is_fake;
  8724. // validate packet and retrieve name and message
  8725. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8726. return;
  8727. if( is_atcommand(fd, sd, message, 1) )
  8728. return;
  8729. if (sd->sc.cant.chat)
  8730. return; //no "chatting" while muted.
  8731. if( battle_config.min_chat_delay ) { //[Skotlex]
  8732. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8733. return;
  8734. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8735. }
  8736. if (battle_config.idletime_option&IDLE_CHAT)
  8737. sd->idletime = last_tick;
  8738. if( sd->gcbind ) {
  8739. channel_send(sd->gcbind,sd,message);
  8740. return;
  8741. }
  8742. /**
  8743. * Fake Name Design by FatalEror (bug report #9)
  8744. **/
  8745. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8746. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8747. strcpy(fakename, sd->fakename);
  8748. strcat(fakename, " : ");
  8749. strcat(fakename, message);
  8750. textlen = strlen(fakename) + 1;
  8751. }
  8752. // send message to others (using the send buffer for temp. storage)
  8753. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8754. // send back message to the speaker
  8755. if( is_fake ) {
  8756. WFIFOW(fd,0) = 0x8e;
  8757. WFIFOW(fd,2) = textlen + 4;
  8758. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8759. aFree(fakename);
  8760. } else {
  8761. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8762. WFIFOW(fd,0) = 0x8e;
  8763. }
  8764. WFIFOSET(fd, WFIFOW(fd,2));
  8765. #ifdef PCRE_SUPPORT
  8766. // trigger listening npcs
  8767. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8768. #endif
  8769. // Chat logging type 'O' / Global Chat
  8770. 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);
  8771. }
  8772. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8773. /// Request to warp to a map on given coordinates.
  8774. /// 0140 <map name>.16B <x>.W <y>.W
  8775. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8776. {
  8777. char command[MAP_NAME_LENGTH_EXT+25];
  8778. char* map_name;
  8779. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8780. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8781. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8782. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8783. RFIFOW(fd,info->pos[1]), //x
  8784. RFIFOW(fd,info->pos[2])); //y
  8785. is_atcommand(fd, sd, command, 1);
  8786. }
  8787. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8788. /// 009c <id>.L <head dir>.W <dir>.B
  8789. /// head dir:
  8790. /// 0 = straight
  8791. /// 1 = turned CW
  8792. /// 2 = turned CCW
  8793. /// dir:
  8794. /// 0 = north
  8795. /// 1 = northwest
  8796. /// 2 = west
  8797. /// 3 = southwest
  8798. /// 4 = south
  8799. /// 5 = southeast
  8800. /// 6 = east
  8801. /// 7 = northeast
  8802. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8803. {
  8804. unsigned char buf[64];
  8805. WBUFW(buf,0) = 0x9c;
  8806. WBUFL(buf,2) = bl->id;
  8807. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8808. WBUFB(buf,8) = unit_getdir(bl);
  8809. clif_send(buf, packet_len(0x9c), bl, target);
  8810. if (disguised(bl)) {
  8811. WBUFL(buf,2) = -bl->id;
  8812. WBUFW(buf,6) = 0;
  8813. clif_send(buf, packet_len(0x9c), bl, SELF);
  8814. }
  8815. }
  8816. /// Request to change own body and head direction.
  8817. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8818. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8819. /// There are various variants of this packet, some of them have padding between fields.
  8820. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8821. {
  8822. unsigned char headdir, dir;
  8823. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8824. headdir = RFIFOB(fd,info->pos[0]);
  8825. dir = RFIFOB(fd,info->pos[1]);
  8826. pc_setdir(sd, dir, headdir);
  8827. clif_changed_dir(&sd->bl, AREA_WOS);
  8828. }
  8829. /// Request to show an emotion (CZ_REQ_EMOTION).
  8830. /// 00bf <type>.B
  8831. /// type:
  8832. /// @see enum emotion_type
  8833. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8834. {
  8835. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8836. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8837. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8838. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8839. return;
  8840. }
  8841. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8842. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8843. sd->emotionlasttime = time(NULL);
  8844. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8845. return;
  8846. }
  8847. sd->emotionlasttime = time(NULL);
  8848. if (battle_config.idletime_option&IDLE_EMOTION)
  8849. sd->idletime = last_tick;
  8850. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8851. emoticon = rnd()%6+E_DICE1;
  8852. }
  8853. clif_emotion(&sd->bl, emoticon);
  8854. } else
  8855. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8856. }
  8857. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8858. /// 00c2 <count>.L
  8859. void clif_user_count(struct map_session_data* sd, int count)
  8860. {
  8861. int fd = sd->fd;
  8862. WFIFOHEAD(fd,packet_len(0xc2));
  8863. WFIFOW(fd,0) = 0xc2;
  8864. WFIFOL(fd,2) = count;
  8865. WFIFOSET(fd,packet_len(0xc2));
  8866. }
  8867. /// /w /who (CZ_REQ_USER_COUNT).
  8868. /// Request to display amount of currently connected players.
  8869. /// 00c1
  8870. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8871. {
  8872. clif_user_count(sd, map_getusers());
  8873. }
  8874. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8875. {
  8876. if (pc_isdead(sd)) {
  8877. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8878. return;
  8879. }
  8880. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  8881. // (not all are included in pc_can_attack)
  8882. if (sd->sc.count &&
  8883. (sd->sc.data[SC_TRICKDEAD] ||
  8884. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  8885. sd->sc.data[SC_BLADESTOP] ||
  8886. sd->sc.data[SC__MANHOLE] ))
  8887. return;
  8888. if(action_type != 0x00 && action_type != 0x07)
  8889. pc_stop_walking(sd, 1);
  8890. pc_stop_attack(sd);
  8891. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8892. target_id = sd->bl.id;
  8893. switch(action_type)
  8894. {
  8895. case 0x00: // once attack
  8896. case 0x07: // continuous attack
  8897. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8898. return;
  8899. if( sd->sc.option&OPTION_COSTUME )
  8900. return;
  8901. if( sd->sc.option&OPTION_COSTUME )
  8902. return;
  8903. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8904. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8905. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8906. return;
  8907. }
  8908. }
  8909. pc_delinvincibletimer(sd);
  8910. if (battle_config.idletime_option&IDLE_ATTACK)
  8911. sd->idletime = last_tick;
  8912. unit_attack(&sd->bl, target_id, action_type != 0);
  8913. break;
  8914. case 0x02: // sitdown
  8915. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8916. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8917. break;
  8918. }
  8919. if(pc_issit(sd)) {
  8920. //Bugged client? Just refresh them.
  8921. clif_sitting(&sd->bl);
  8922. return;
  8923. }
  8924. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8925. break;
  8926. if (sd->sc.count && (
  8927. sd->sc.data[SC_DANCING] ||
  8928. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8929. )) //No sitting during these states either.
  8930. break;
  8931. if (battle_config.idletime_option&IDLE_SIT)
  8932. sd->idletime = last_tick;
  8933. pc_setsit(sd);
  8934. skill_sit(sd, 1);
  8935. clif_sitting(&sd->bl);
  8936. break;
  8937. case 0x03: // standup
  8938. if (!pc_issit(sd)) {
  8939. //Bugged client? Just refresh them.
  8940. clif_standing(&sd->bl);
  8941. return;
  8942. }
  8943. if (pc_setstand(sd, false)) {
  8944. if (battle_config.idletime_option&IDLE_SIT)
  8945. sd->idletime = last_tick;
  8946. skill_sit(sd, 0);
  8947. clif_standing(&sd->bl);
  8948. }
  8949. break;
  8950. }
  8951. }
  8952. /// Request for an action.
  8953. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8954. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8955. /// action:
  8956. /// 0 = attack
  8957. /// 1 = pick up item
  8958. /// 2 = sit down
  8959. /// 3 = stand up
  8960. /// 7 = continous attack
  8961. /// 12 = (touch skill?)
  8962. /// There are various variants of this packet, some of them have padding between fields.
  8963. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8964. {
  8965. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8966. clif_parse_ActionRequest_sub(sd,
  8967. RFIFOB(fd,info->pos[1]),
  8968. RFIFOL(fd,info->pos[0]),
  8969. gettick()
  8970. );
  8971. }
  8972. /// Response to the death/system menu (CZ_RESTART).
  8973. /// 00b2 <type>.B
  8974. /// type:
  8975. /// 0 = restart (respawn)
  8976. /// 1 = char-select (disconnect)
  8977. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8978. {
  8979. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8980. case 0x00:
  8981. pc_respawn(sd,CLR_OUTSIGHT);
  8982. break;
  8983. case 0x01:
  8984. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8985. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8986. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8987. { //Send to char-server for character selection.
  8988. pc_damage_log_clear(sd,0);
  8989. chrif_charselectreq(sd, session[fd]->client_addr);
  8990. } else {
  8991. clif_disconnect_ack(sd, 1);
  8992. }
  8993. break;
  8994. }
  8995. }
  8996. /// Validates and processes whispered messages (CZ_WHISPER).
  8997. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8998. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8999. {
  9000. struct map_session_data* dstsd;
  9001. int i;
  9002. char *target, *message;
  9003. int namelen, messagelen;
  9004. // validate packet and retrieve name and message
  9005. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9006. return;
  9007. if ( is_atcommand(fd, sd, message, 1) )
  9008. return;
  9009. if (sd->sc.cant.chat)
  9010. return; //no "chatting" while muted.
  9011. if (battle_config.min_chat_delay) { //[Skotlex]
  9012. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9013. return;
  9014. }
  9015. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9016. }
  9017. if (battle_config.idletime_option&IDLE_CHAT)
  9018. sd->idletime = last_tick;
  9019. // Chat logging type 'W' / Whisper
  9020. 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);
  9021. //-------------------------------------------------------//
  9022. // Lordalfa - Paperboy - To whisper NPC commands //
  9023. //-------------------------------------------------------//
  9024. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9025. {
  9026. char* str = target+4; //Skip the NPC: string part.
  9027. struct npc_data* npc;
  9028. if ((npc = npc_name2id(str))) {
  9029. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9030. char *split;
  9031. char output[256];
  9032. str = message;
  9033. // skip codepage indicator, if detected
  9034. if( str[0] == '|' && strlen(str) >= 4 )
  9035. str += 3;
  9036. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9037. split = strchr(str,'#');
  9038. if( split == NULL ) { // use the remaining string
  9039. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9040. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9041. split_data[i][0] = '\0';
  9042. break;
  9043. }
  9044. *split = '\0';
  9045. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9046. str = split+1;
  9047. }
  9048. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9049. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9050. set_var(sd,output,(char *) split_data[i]);
  9051. }
  9052. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9053. npc_event(sd,output,0); // Calls the NPC label
  9054. return;
  9055. }
  9056. } else if( target[0] == '#' ) {
  9057. struct Channel *channel = NULL;
  9058. char* chname = target;
  9059. channel = channel_name2channel(chname,sd,3);
  9060. if(channel){
  9061. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9062. channel_send(channel,sd,message);
  9063. }
  9064. else if( channel->pass[0] == '\0') { //no pass needed
  9065. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9066. }
  9067. else {
  9068. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9069. }
  9070. return;
  9071. }
  9072. }
  9073. // searching destination character
  9074. dstsd = map_nick2sd(target);
  9075. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9076. // player is not on this map-server
  9077. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9078. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9079. // and if we ask for 'Test', we must not contact 'test' player
  9080. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9081. intif_wis_message(sd, target, message, messagelen);
  9082. return;
  9083. }
  9084. // if player ignores everyone
  9085. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9086. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9087. clif_wis_end(fd, 1); // 1: target character is not logged in
  9088. else
  9089. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9090. return;
  9091. }
  9092. // if player is autotrading
  9093. if (dstsd->state.autotrade == 1) {
  9094. char output[256];
  9095. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9096. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9097. return;
  9098. }
  9099. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9100. // if player ignores the source character
  9101. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9102. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9103. clif_wis_end(fd, 2); // 2: ignored by target
  9104. return;
  9105. }
  9106. }
  9107. // notify sender of success
  9108. clif_wis_end(fd, 0); // 0: success to send wisper
  9109. // Normal message
  9110. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9111. }
  9112. /// /b /nb (CZ_BROADCAST).
  9113. /// Request to broadcast a message on whole server.
  9114. /// 0099 <packet len>.W <text>.?B 00
  9115. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9116. char command[CHAT_SIZE_MAX+11];
  9117. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9118. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9119. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9120. // as the length varies depending on the command used, just block unreasonably long strings
  9121. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9122. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9123. is_atcommand(fd, sd, command, 1);
  9124. }
  9125. /// Request to pick up an item.
  9126. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9127. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9128. /// There are various variants of this packet, some of them have padding between fields.
  9129. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9130. {
  9131. struct flooritem_data *fitem;
  9132. int map_object_id;
  9133. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9134. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9135. do {
  9136. if (pc_isdead(sd)) {
  9137. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9138. break;
  9139. }
  9140. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9141. break;
  9142. if (pc_cant_act(sd))
  9143. break;
  9144. if (!pc_takeitem(sd, fitem))
  9145. break;
  9146. return;
  9147. } while (0);
  9148. // Client REQUIRES a fail packet or you can no longer pick items.
  9149. clif_additem(sd,0,0,6);
  9150. }
  9151. /// Request to drop an item.
  9152. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9153. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9154. /// There are various variants of this packet, some of them have padding between fields.
  9155. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9156. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9157. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9158. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9159. for(;;) {
  9160. if (pc_isdead(sd))
  9161. break;
  9162. if (pc_cant_act2(sd) || sd->npc_id)
  9163. break;
  9164. if (sd->sc.count && (
  9165. sd->sc.data[SC_AUTOCOUNTER] ||
  9166. sd->sc.data[SC_BLADESTOP] ||
  9167. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9168. ))
  9169. break;
  9170. if (!pc_dropitem(sd, item_index, item_amount))
  9171. break;
  9172. if (battle_config.idletime_option&IDLE_DROPITEM)
  9173. sd->idletime = last_tick;
  9174. return;
  9175. }
  9176. //Because the client does not like being ignored.
  9177. clif_dropitem(sd, item_index,0);
  9178. }
  9179. /// Request to use an item.
  9180. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9181. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9182. /// There are various variants of this packet, some of them have padding between fields.
  9183. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9184. {
  9185. int n;
  9186. if (pc_isdead(sd)) {
  9187. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9188. return;
  9189. }
  9190. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9191. return;
  9192. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9193. if (battle_config.idletime_option&IDLE_USEITEM)
  9194. sd->idletime = last_tick;
  9195. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9196. if(n <0 || n >= MAX_INVENTORY)
  9197. return;
  9198. if (!pc_useitem(sd,n))
  9199. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9200. }
  9201. /// Request to equip an item
  9202. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9203. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9204. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9205. {
  9206. int index;
  9207. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9208. if(pc_isdead(sd)) {
  9209. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9210. return;
  9211. }
  9212. index = RFIFOW(fd,info->pos[0])-2;
  9213. if (index < 0 || index >= MAX_INVENTORY)
  9214. return; //Out of bounds check.
  9215. if(sd->npc_id && !sd->npc_item_flag) {
  9216. return;
  9217. } else if (sd->state.storage_flag || sd->sc.opt1)
  9218. ; //You can equip/unequip stuff while storage is open/under status changes
  9219. else if (pc_cant_act2(sd))
  9220. return;
  9221. if(!sd->status.inventory[index].identify) {
  9222. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9223. return;
  9224. }
  9225. if(!sd->inventory_data[index])
  9226. return;
  9227. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9228. pet_equipitem(sd,index);
  9229. return;
  9230. }
  9231. if (battle_config.idletime_option&IDLE_USEITEM)
  9232. sd->idletime = last_tick;
  9233. //Client doesn't send the position for ammo.
  9234. if(sd->inventory_data[index]->type == IT_AMMO)
  9235. pc_equipitem(sd,index,EQP_AMMO);
  9236. else {
  9237. int req_pos;
  9238. #if PACKETVER >= 20120925
  9239. req_pos = RFIFOL(fd,info->pos[1]);
  9240. #else
  9241. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9242. #endif
  9243. pc_equipitem(sd,index,req_pos);
  9244. }
  9245. }
  9246. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9247. /// 00ab <index>.W
  9248. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9249. {
  9250. int index;
  9251. if(pc_isdead(sd)) {
  9252. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9253. return;
  9254. }
  9255. if (sd->npc_id && !sd->npc_item_flag) {
  9256. return;
  9257. } else if (sd->state.storage_flag || sd->sc.opt1)
  9258. ; //You can equip/unequip stuff while storage is open/under status changes
  9259. else if (pc_cant_act2(sd))
  9260. return;
  9261. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9262. if (battle_config.idletime_option&IDLE_USEITEM)
  9263. sd->idletime = last_tick;
  9264. pc_unequipitem(sd,index,1);
  9265. }
  9266. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9267. /// 0090 <id>.L <type>.B
  9268. /// type:
  9269. /// 1 = click
  9270. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9271. {
  9272. struct block_list *bl;
  9273. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9274. if(pc_isdead(sd)) {
  9275. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9276. return;
  9277. }
  9278. if (pc_cant_act2(sd) || sd->npc_id)
  9279. return;
  9280. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9281. //type = RFIFOB(fd,info->pos[1]);
  9282. if (!bl) return;
  9283. switch (bl->type) {
  9284. case BL_MOB:
  9285. case BL_PC:
  9286. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9287. break;
  9288. case BL_NPC:
  9289. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9290. npc_click(sd,(TBL_NPC*)bl);
  9291. break;
  9292. }
  9293. }
  9294. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9295. /// 00c5 <id>.L <type>.B
  9296. /// type:
  9297. /// 0 = buy
  9298. /// 1 = sell
  9299. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9300. {
  9301. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9302. if (sd->state.trading)
  9303. return;
  9304. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9305. }
  9306. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9307. /// 00ca <result>.B
  9308. /// result:
  9309. /// 0 = "The deal has successfully completed."
  9310. /// 1 = "You do not have enough zeny."
  9311. /// 2 = "You are over your Weight Limit."
  9312. /// 3 = "Out of the maximum capacity, you have too many items."
  9313. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9314. {
  9315. int fd = sd->fd;
  9316. WFIFOHEAD(fd,packet_len(0xca));
  9317. WFIFOW(fd,0) = 0xca;
  9318. WFIFOB(fd,2) = result;
  9319. WFIFOSET(fd,packet_len(0xca));
  9320. }
  9321. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9322. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9323. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9324. {
  9325. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9326. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9327. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9328. int result;
  9329. if( sd->state.trading || !sd->npc_shopid )
  9330. result = 1;
  9331. else
  9332. result = npc_buylist(sd,n,item_list);
  9333. sd->npc_shopid = 0; //Clear shop data.
  9334. clif_npc_buy_result(sd, result);
  9335. }
  9336. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9337. /// 00cb <result>.B
  9338. /// result:
  9339. /// 0 = "The deal has successfully completed."
  9340. /// 1 = "The deal has failed."
  9341. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9342. {
  9343. int fd = sd->fd;
  9344. WFIFOHEAD(fd,packet_len(0xcb));
  9345. WFIFOW(fd,0) = 0xcb;
  9346. WFIFOB(fd,2) = result;
  9347. WFIFOSET(fd,packet_len(0xcb));
  9348. }
  9349. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9350. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9351. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9352. {
  9353. int fail=0,n;
  9354. unsigned short *item_list;
  9355. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9356. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9357. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9358. if (sd->state.trading || !sd->npc_shopid)
  9359. fail = 1;
  9360. else
  9361. fail = npc_selllist(sd,n,item_list);
  9362. sd->npc_shopid = 0; //Clear shop data.
  9363. clif_npc_sell_result(sd, fail);
  9364. }
  9365. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9366. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9367. /// type:
  9368. /// 0 = private
  9369. /// 1 = public
  9370. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9371. {
  9372. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9373. int len = RFIFOW(fd,info->pos[0])-15;
  9374. int limit = RFIFOW(fd,info->pos[1]);
  9375. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9376. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9377. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9378. char s_password[CHATROOM_PASS_SIZE];
  9379. char s_title[CHATROOM_TITLE_SIZE];
  9380. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9381. return;
  9382. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9383. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9384. return;
  9385. }
  9386. if( npc_isnear(&sd->bl) ) {
  9387. // uncomment to send msg_txt.
  9388. //char output[150];
  9389. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9390. //clif_displaymessage(sd->fd, output);
  9391. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9392. return;
  9393. }
  9394. if( len <= 0 )
  9395. return; // invalid input
  9396. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9397. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9398. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9399. }
  9400. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9401. /// 00d9 <chat ID>.L <passwd>.8B
  9402. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9403. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9404. int chatid = RFIFOL(fd,info->pos[0]);
  9405. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9406. chat_joinchat(sd,chatid,password);
  9407. }
  9408. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9409. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9410. /// type:
  9411. /// 0 = private
  9412. /// 1 = public
  9413. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9414. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9415. int len = RFIFOW(fd,info->pos[0])-15;
  9416. int limit = RFIFOW(fd,info->pos[1]);
  9417. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9418. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9419. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9420. char s_password[CHATROOM_PASS_SIZE];
  9421. char s_title[CHATROOM_TITLE_SIZE];
  9422. if( len <= 0 )
  9423. return; // invalid input
  9424. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9425. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9426. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9427. }
  9428. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9429. /// 00e0 <role>.L <nick>.24B
  9430. /// role:
  9431. /// 0 = owner
  9432. /// 1 = normal
  9433. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9434. {
  9435. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9436. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9437. }
  9438. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9439. /// 00e2 <name>.24B
  9440. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9441. {
  9442. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9443. }
  9444. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9445. /// 00e3
  9446. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9447. {
  9448. chat_leavechat(sd,0);
  9449. }
  9450. //Handles notifying asker and rejecter of what has just ocurred.
  9451. //Type is used to determine the correct msg_txt to use:
  9452. //0:
  9453. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9454. {
  9455. const char* msg;
  9456. char output[256];
  9457. // Your request has been rejected by autoreject option.
  9458. msg = msg_txt(sd,392);
  9459. clif_disp_onlyself(sd, msg, strlen(msg));
  9460. //Notice that a request was rejected.
  9461. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9462. clif_disp_onlyself(tsd, output, strlen(output));
  9463. }
  9464. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9465. /// 00e4 <account id>.L
  9466. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9467. {
  9468. struct map_session_data *t_sd;
  9469. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9470. if(!sd->chatID && pc_cant_act(sd))
  9471. return; //You can trade while in a chatroom.
  9472. // @noask [LuzZza]
  9473. if(t_sd && t_sd->state.noask) {
  9474. clif_noask_sub(sd, t_sd, 0);
  9475. return;
  9476. }
  9477. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9478. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9479. return;
  9480. }
  9481. trade_traderequest(sd,t_sd);
  9482. }
  9483. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9484. /// 00e6 <result>.B
  9485. /// result:
  9486. /// 3 = accepted
  9487. /// 4 = rejected
  9488. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9489. {
  9490. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9491. }
  9492. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9493. /// 00e8 <index>.W <amount>.L
  9494. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9495. {
  9496. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9497. short index = RFIFOW(fd,info->pos[0]);
  9498. int amount = RFIFOL(fd,info->pos[1]);
  9499. if( index == 0 )
  9500. trade_tradeaddzeny(sd, amount);
  9501. else
  9502. trade_tradeadditem(sd, index, (short)amount);
  9503. }
  9504. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9505. /// 00eb
  9506. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9507. {
  9508. trade_tradeok(sd);
  9509. }
  9510. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9511. /// 00ed
  9512. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9513. {
  9514. trade_tradecancel(sd);
  9515. }
  9516. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9517. /// 00ef
  9518. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9519. {
  9520. trade_tradecommit(sd);
  9521. }
  9522. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9523. /// 0118
  9524. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9525. {
  9526. pc_stop_attack(sd);
  9527. }
  9528. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9529. /// 0126 <index>.W <amount>.L
  9530. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9531. {
  9532. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9533. if (pc_istrading(sd))
  9534. return;
  9535. if (!pc_iscarton(sd))
  9536. return;
  9537. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9538. }
  9539. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9540. /// 0127 <index>.W <amount>.L
  9541. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9542. {
  9543. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9544. if (!pc_iscarton(sd))
  9545. return;
  9546. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9547. }
  9548. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9549. /// 012a
  9550. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9551. {
  9552. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9553. #ifdef NEW_CARTS
  9554. && sd->sc.data[SC_PUSH_CART] )
  9555. pc_setcart(sd,0);
  9556. #else
  9557. )
  9558. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9559. #endif
  9560. else // priority to remove this option before we can clear cart
  9561. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9562. }
  9563. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9564. /// 01af <num>.W
  9565. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9566. {// TODO: State tracking?
  9567. int type;
  9568. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9569. return;
  9570. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9571. #ifdef NEW_CARTS
  9572. if( (type == 9 && sd->status.base_level > 131) ||
  9573. (type == 8 && sd->status.base_level > 121) ||
  9574. (type == 7 && sd->status.base_level > 111) ||
  9575. (type == 6 && sd->status.base_level > 101) ||
  9576. (type == 5 && sd->status.base_level > 90) ||
  9577. (type == 4 && sd->status.base_level > 80) ||
  9578. (type == 3 && sd->status.base_level > 65) ||
  9579. (type == 2 && sd->status.base_level > 40) ||
  9580. (type == 1))
  9581. #else
  9582. if( (type == 5 && sd->status.base_level > 90) ||
  9583. (type == 4 && sd->status.base_level > 80) ||
  9584. (type == 3 && sd->status.base_level > 65) ||
  9585. (type == 2 && sd->status.base_level > 40) ||
  9586. (type == 1))
  9587. #endif
  9588. pc_setcart(sd,type);
  9589. }
  9590. /// Request to increase status (CZ_STATUS_CHANGE).
  9591. /// 00bb <status id>.W <amount>.B
  9592. /// status id:
  9593. /// SP_STR ~ SP_LUK
  9594. /// amount:
  9595. /// Old clients always send 1 for this, even when using /str+ and the like.
  9596. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9597. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9598. {
  9599. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9600. if( increase_amount < 0 ) {
  9601. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9602. fd, increase_amount);
  9603. }
  9604. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9605. }
  9606. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9607. /// 0112 <skill id>.W
  9608. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9609. {
  9610. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9611. }
  9612. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  9613. {
  9614. int lv;
  9615. if( !hd )
  9616. return;
  9617. if( skill_isNotOk_hom(skill_id, hd) )
  9618. return;
  9619. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9620. target_id = hd->bl.id;
  9621. if( hd->ud.skilltimer != INVALID_TIMER )
  9622. {
  9623. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9624. }
  9625. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9626. return;
  9627. lv = hom_checkskill(hd, skill_id);
  9628. if( skill_lv > lv )
  9629. skill_lv = lv;
  9630. if( skill_lv )
  9631. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9632. }
  9633. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  9634. {
  9635. int lv;
  9636. if( !hd )
  9637. return;
  9638. if( skill_isNotOk_hom(skill_id, hd) )
  9639. return;
  9640. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9641. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9642. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9643. return;
  9644. if( hd->sc.data[SC_BASILICA] )
  9645. return;
  9646. lv = hom_checkskill(hd, skill_id);
  9647. if( skill_lv > lv )
  9648. skill_lv = lv;
  9649. if( skill_lv )
  9650. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9651. }
  9652. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  9653. {
  9654. int lv;
  9655. if( !md )
  9656. return;
  9657. if( skill_isNotOk_mercenary(skill_id, md) )
  9658. return;
  9659. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9660. target_id = md->bl.id;
  9661. if( md->ud.skilltimer != INVALID_TIMER )
  9662. {
  9663. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9664. }
  9665. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9666. return;
  9667. lv = mercenary_checkskill(md, skill_id);
  9668. if( skill_lv > lv )
  9669. skill_lv = lv;
  9670. if( skill_lv )
  9671. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9672. }
  9673. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  9674. {
  9675. int lv;
  9676. if( !md )
  9677. return;
  9678. if( skill_isNotOk_mercenary(skill_id, md) )
  9679. return;
  9680. if( md->ud.skilltimer != INVALID_TIMER )
  9681. return;
  9682. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9683. {
  9684. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9685. return;
  9686. }
  9687. if( md->sc.data[SC_BASILICA] )
  9688. return;
  9689. lv = mercenary_checkskill(md, skill_id);
  9690. if( skill_lv > lv )
  9691. skill_lv = lv;
  9692. if( skill_lv )
  9693. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9694. }
  9695. /// Request to use a targeted skill.
  9696. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9697. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9698. /// There are various variants of this packet, some of them have padding between fields.
  9699. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9700. {
  9701. uint16 skill_id, skill_lv;
  9702. int tmp, target_id;
  9703. unsigned int tick = gettick();
  9704. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9705. skill_lv = RFIFOW(fd,info->pos[0]);
  9706. skill_id = RFIFOW(fd,info->pos[1]);
  9707. target_id = RFIFOL(fd,info->pos[2]);
  9708. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9709. tmp = skill_get_inf(skill_id);
  9710. if (tmp&INF_GROUND_SKILL || !tmp)
  9711. return; //Using a ground/passive skill on a target? WRONG.
  9712. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9713. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9714. return;
  9715. }
  9716. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9717. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9718. return;
  9719. }
  9720. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9721. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  9722. sd->idletime = last_tick;
  9723. if( sd->npc_id ){
  9724. #ifdef RENEWAL
  9725. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9726. return;
  9727. #else
  9728. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9729. return;
  9730. #endif
  9731. }
  9732. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9733. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9734. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9735. return;
  9736. if( pc_issit(sd) )
  9737. return;
  9738. if( skill_isNotOk(skill_id, sd) )
  9739. return;
  9740. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9741. target_id = sd->bl.id; // never trust the client
  9742. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9743. target_id = sd->bl.id;
  9744. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9745. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9746. return;
  9747. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9748. if( sd->skillitem != skill_id ) {
  9749. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9750. return;
  9751. }
  9752. }
  9753. if( sd->sc.option&OPTION_COSTUME )
  9754. return;
  9755. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9756. return; // On basilica only caster can use Basilica again to stop it.
  9757. if( sd->menuskill_id ) {
  9758. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9759. clif_menuskill_clear(sd); //Cancel pet capture.
  9760. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9761. return; //Can't use skills while a menu is open.
  9762. }
  9763. if( sd->skillitem == skill_id ) {
  9764. if( skill_lv != sd->skillitemlv )
  9765. skill_lv = sd->skillitemlv;
  9766. if( !(tmp&INF_SELF_SKILL) )
  9767. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9768. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9769. return;
  9770. }
  9771. sd->skillitem = sd->skillitemlv = 0;
  9772. if( skill_id >= GD_SKILLBASE ) {
  9773. if( sd->state.gmaster_flag )
  9774. skill_lv = guild_checkskill(sd->guild, skill_id);
  9775. else
  9776. skill_lv = 0;
  9777. } else {
  9778. tmp = pc_checkskill(sd, skill_id);
  9779. if( skill_lv > tmp )
  9780. skill_lv = tmp;
  9781. }
  9782. pc_delinvincibletimer(sd);
  9783. if( skill_lv )
  9784. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9785. }
  9786. /*==========================================
  9787. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9788. *------------------------------------------*/
  9789. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9790. {
  9791. unsigned int tick = gettick();
  9792. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9793. return; //Using a target skill on the ground? WRONG.
  9794. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9795. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9796. return;
  9797. }
  9798. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9799. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9800. return;
  9801. }
  9802. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9803. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  9804. sd->idletime = last_tick;
  9805. if( skill_isNotOk(skill_id, sd) )
  9806. return;
  9807. if( skillmoreinfo != -1 ) {
  9808. if( pc_issit(sd) ) {
  9809. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9810. return;
  9811. }
  9812. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9813. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9814. }
  9815. if( sd->ud.skilltimer != INVALID_TIMER )
  9816. return;
  9817. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9818. if( sd->skillitem != skill_id ) {
  9819. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9820. return;
  9821. }
  9822. }
  9823. if( sd->sc.option&OPTION_COSTUME )
  9824. return;
  9825. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9826. return; // On basilica only caster can use Basilica again to stop it.
  9827. if( sd->menuskill_id ) {
  9828. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9829. clif_menuskill_clear(sd); //Cancel pet capture.
  9830. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9831. return; //Can't use skills while a menu is open.
  9832. }
  9833. pc_delinvincibletimer(sd);
  9834. if( sd->skillitem == skill_id ) {
  9835. if( skill_lv != sd->skillitemlv )
  9836. skill_lv = sd->skillitemlv;
  9837. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9838. } else {
  9839. int lv;
  9840. sd->skillitem = sd->skillitemlv = 0;
  9841. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9842. if( skill_lv > lv )
  9843. skill_lv = lv;
  9844. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9845. }
  9846. }
  9847. }
  9848. /// Request to use a ground skill.
  9849. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9850. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9851. /// There are various variants of this packet, some of them have padding between fields.
  9852. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9853. {
  9854. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9855. if (pc_cant_act(sd))
  9856. return;
  9857. if (pc_issit(sd))
  9858. return;
  9859. clif_parse_UseSkillToPosSub(fd, sd,
  9860. RFIFOW(fd,info->pos[0]), //skill lv
  9861. RFIFOW(fd,info->pos[1]), //skill num
  9862. RFIFOW(fd,info->pos[2]), //pos x
  9863. RFIFOW(fd,info->pos[3]), //pos y
  9864. -1 //Skill more info.
  9865. );
  9866. }
  9867. /// Request to use a ground skill with text.
  9868. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9869. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9870. /// There are various variants of this packet, some of them have padding between fields.
  9871. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9872. {
  9873. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9874. if (pc_cant_act(sd))
  9875. return;
  9876. if (pc_issit(sd))
  9877. return;
  9878. clif_parse_UseSkillToPosSub(fd, sd,
  9879. RFIFOW(fd,info->pos[0]), //Skill lv
  9880. RFIFOW(fd,info->pos[1]), //Skill num
  9881. RFIFOW(fd,info->pos[2]), //pos x
  9882. RFIFOW(fd,info->pos[3]), //pos y
  9883. info->pos[4] //skill more info
  9884. );
  9885. }
  9886. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9887. /// 011b <skill id>.W <map name>.16B
  9888. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9889. {
  9890. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9891. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9892. char map_name[MAP_NAME_LENGTH];
  9893. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9894. if(skill_id != sd->menuskill_id)
  9895. return;
  9896. //It is possible to use teleport with the storage window open bugreport:8027
  9897. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  9898. clif_menuskill_clear(sd);
  9899. return;
  9900. }
  9901. pc_delinvincibletimer(sd);
  9902. skill_castend_map(sd,skill_id,map_name);
  9903. }
  9904. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9905. /// 011d
  9906. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9907. {
  9908. if (!pc_isdead(sd))
  9909. pc_memo(sd,-1);
  9910. }
  9911. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9912. /// 018e <name id>.W { <material id>.W }*3
  9913. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9914. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9915. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  9916. int slot1 = RFIFOW(fd,info->pos[1]);
  9917. int slot2 = RFIFOW(fd,info->pos[2]);
  9918. int slot3 = RFIFOW(fd,info->pos[3]);
  9919. switch( sd->menuskill_id ) {
  9920. case -1:
  9921. case AM_PHARMACY:
  9922. case RK_RUNEMASTERY:
  9923. case GC_RESEARCHNEWPOISON:
  9924. break;
  9925. default:
  9926. return;
  9927. }
  9928. if (pc_istrading(sd)) {
  9929. //Make it fail to avoid shop exploits where you sell something different than you see.
  9930. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9931. clif_menuskill_clear(sd);
  9932. return;
  9933. }
  9934. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9935. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9936. clif_menuskill_clear(sd);
  9937. }
  9938. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9939. /// 025b <mk type>.W <name id>.W
  9940. /// mk type:
  9941. /// 1 = cooking
  9942. /// 2 = arrow
  9943. /// 3 = elemental
  9944. /// 4 = GN_MIX_COOKING
  9945. /// 5 = GN_MAKEBOMB
  9946. /// 6 = GN_S_PHARMACY
  9947. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9948. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9949. int type = RFIFOW(fd,info->pos[0]);
  9950. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  9951. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  9952. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9953. return;
  9954. if (pc_istrading(sd)) {
  9955. //Make it fail to avoid shop exploits where you sell something different than you see.
  9956. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9957. clif_menuskill_clear(sd);
  9958. return;
  9959. }
  9960. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9961. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9962. clif_menuskill_clear(sd);
  9963. }
  9964. /// Answer to repair weapon item selection dialog
  9965. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9966. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9967. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9968. {
  9969. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9970. return;
  9971. if (pc_istrading(sd)) {
  9972. //Make it fail to avoid shop exploits where you sell something different than you see.
  9973. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9974. clif_menuskill_clear(sd);
  9975. return;
  9976. }
  9977. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9978. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9979. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9980. //for(i = 0; i<MAX_SLOTS; i++)
  9981. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9982. clif_menuskill_clear(sd);
  9983. }
  9984. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9985. /// 0222 <index>.L
  9986. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9987. {
  9988. int idx;
  9989. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9990. return;
  9991. if (pc_istrading(sd)) {
  9992. //Make it fail to avoid shop exploits where you sell something different than you see.
  9993. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9994. clif_menuskill_clear(sd);
  9995. return;
  9996. }
  9997. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9998. skill_weaponrefine(sd, idx-2);
  9999. clif_menuskill_clear(sd);
  10000. }
  10001. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10002. /// 00b8 <npc id>.L <choice>.B
  10003. /// choice:
  10004. /// 1~254 = menu item
  10005. /// 255 = cancel
  10006. /// NOTE: If there were more than 254 items in the list, choice
  10007. /// overflows to choice%256.
  10008. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10009. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10010. int npc_id = RFIFOL(fd,info->pos[0]);
  10011. uint8 select = RFIFOB(fd,info->pos[1]);
  10012. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10013. #ifdef SECURE_NPCTIMEOUT
  10014. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10015. #endif
  10016. TBL_NPC* nd = map_id2nd(npc_id);
  10017. 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);
  10018. clif_GM_kick(NULL,sd);
  10019. #ifdef SECURE_NPCTIMEOUT
  10020. }
  10021. #endif
  10022. return;
  10023. }
  10024. sd->npc_menu = select;
  10025. npc_scriptcont(sd,npc_id, false);
  10026. }
  10027. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10028. /// 00b9 <npc id>.L
  10029. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10030. {
  10031. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10032. }
  10033. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10034. /// 0143 <npc id>.L <value>.L
  10035. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10036. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10037. int npcid = RFIFOL(fd,info->pos[0]);
  10038. int amount = (int)RFIFOL(fd,info->pos[1]);
  10039. sd->npc_amount = amount;
  10040. npc_scriptcont(sd, npcid, false);
  10041. }
  10042. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10043. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10044. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10045. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10046. int message_len = RFIFOW(fd,info->pos[0])-8;
  10047. int npcid = RFIFOL(fd,info->pos[1]);
  10048. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10049. if( message_len <= 0 )
  10050. return; // invalid input
  10051. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10052. npc_scriptcont(sd, npcid, false);
  10053. }
  10054. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10055. /// 0146 <npc id>.L
  10056. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10057. {
  10058. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10059. return;
  10060. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10061. }
  10062. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10063. /// 0178 <index>.W
  10064. /// index:
  10065. /// -1 = cancel
  10066. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10067. {
  10068. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10069. if (sd->menuskill_id != MC_IDENTIFY)
  10070. return;
  10071. if( idx == -1 ) {// cancel pressed
  10072. clif_menuskill_clear(sd);
  10073. return;
  10074. }
  10075. skill_identify(sd,idx-2);
  10076. clif_menuskill_clear(sd);
  10077. }
  10078. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10079. /// 01ae <name id>.W
  10080. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10081. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10082. if (pc_istrading(sd)) {
  10083. //Make it fail to avoid shop exploits where you sell something different than you see.
  10084. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10085. clif_menuskill_clear(sd);
  10086. return;
  10087. }
  10088. switch (sd->menuskill_id) {
  10089. case AC_MAKINGARROW:
  10090. skill_arrow_create(sd,nameid);
  10091. break;
  10092. case SA_CREATECON:
  10093. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  10094. break;
  10095. case WL_READING_SB:
  10096. skill_spellbook(sd,nameid);
  10097. break;
  10098. case GC_POISONINGWEAPON:
  10099. skill_poisoningweapon(sd,nameid);
  10100. break;
  10101. case NC_MAGICDECOY:
  10102. skill_magicdecoy(sd,nameid);
  10103. break;
  10104. }
  10105. clif_menuskill_clear(sd);
  10106. }
  10107. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10108. /// 01ce <skill id>.L
  10109. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10110. {
  10111. if (sd->menuskill_id != SA_AUTOSPELL)
  10112. return;
  10113. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10114. clif_menuskill_clear(sd);
  10115. }
  10116. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10117. /// 017a <card index>.W
  10118. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10119. {
  10120. if (sd->state.trading != 0)
  10121. return;
  10122. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10123. }
  10124. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10125. /// 017c <card index>.W <equip index>.W
  10126. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10127. {
  10128. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10129. if (sd->state.trading != 0)
  10130. return;
  10131. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10132. }
  10133. /// Request of character's name by char ID.
  10134. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10135. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10136. /// There are various variants of this packet, some of them have padding between fields.
  10137. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10138. {
  10139. int charid;
  10140. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10141. map_reqnickdb(sd, charid);
  10142. }
  10143. /// /resetskill /resetstate (CZ_RESET).
  10144. /// Request to reset stats or skills.
  10145. /// 0197 <type>.W
  10146. /// type:
  10147. /// 0 = state
  10148. /// 1 = skill
  10149. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10150. char cmd[15];
  10151. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10152. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10153. else
  10154. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10155. is_atcommand(fd, sd, cmd, 1);
  10156. }
  10157. /// /lb /nlb (CZ_LOCALBROADCAST).
  10158. /// Request to broadcast a message on current map.
  10159. /// 019c <packet len>.W <text>.?B
  10160. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10161. {
  10162. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10163. char command[CHAT_SIZE_MAX+16];
  10164. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10165. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10166. // as the length varies depending on the command used, just block unreasonably long strings
  10167. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10168. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10169. is_atcommand(fd, sd, command, 1);
  10170. }
  10171. /// Request to move an item from inventory to storage.
  10172. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10173. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10174. /// There are various variants of this packet, some of them have padding between fields.
  10175. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10176. {
  10177. int item_index, item_amount;
  10178. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10179. if (pc_istrading(sd))
  10180. return;
  10181. item_index = RFIFOW(fd,info->pos[0])-2;
  10182. item_amount = RFIFOL(fd,info->pos[1]);
  10183. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10184. return;
  10185. if (sd->state.storage_flag == 1)
  10186. storage_storageadd(sd, item_index, item_amount);
  10187. else
  10188. if (sd->state.storage_flag == 2)
  10189. gstorage_storageadd(sd, item_index, item_amount);
  10190. }
  10191. /// Request to move an item from storage to inventory.
  10192. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10193. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10194. /// There are various variants of this packet, some of them have padding between fields.
  10195. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10196. {
  10197. int item_index, item_amount;
  10198. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10199. item_index = RFIFOW(fd,info->pos[0])-1;
  10200. item_amount = RFIFOL(fd,info->pos[1]);
  10201. if (sd->state.storage_flag == 1)
  10202. storage_storageget(sd, item_index, item_amount);
  10203. else if(sd->state.storage_flag == 2)
  10204. gstorage_storageget(sd, item_index, item_amount);
  10205. }
  10206. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10207. /// 0129 <index>.W <amount>.L
  10208. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10209. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10210. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10211. int amount = RFIFOL(fd,info->pos[1]);
  10212. if( sd->state.vending )
  10213. return;
  10214. if (!pc_iscarton(sd))
  10215. return;
  10216. if (sd->state.storage_flag == 1)
  10217. storage_storageaddfromcart(sd, idx, amount);
  10218. else if (sd->state.storage_flag == 2)
  10219. gstorage_storageaddfromcart(sd, idx, amount);
  10220. }
  10221. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10222. /// 0128 <index>.W <amount>.L
  10223. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10224. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10225. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10226. int amount = RFIFOL(fd,info->pos[1]);
  10227. if( sd->state.vending )
  10228. return;
  10229. if (!pc_iscarton(sd))
  10230. return;
  10231. if (sd->state.storage_flag == 1)
  10232. storage_storagegettocart(sd, idx, amount);
  10233. else
  10234. if (sd->state.storage_flag == 2)
  10235. gstorage_storagegettocart(sd, idx, amount);
  10236. }
  10237. /// Request to close storage (CZ_CLOSE_STORE).
  10238. /// 00f7
  10239. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10240. {
  10241. if( sd->state.storage_flag == 1 )
  10242. storage_storageclose(sd);
  10243. else
  10244. if( sd->state.storage_flag == 2 )
  10245. gstorage_storageclose(sd);
  10246. }
  10247. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10248. /// 023a <info>.W
  10249. /// info:
  10250. /// 0 = password has not been set yet
  10251. /// 1 = storage is password-protected
  10252. /// 8 = too many wrong passwords
  10253. /// ? = ignored
  10254. /// NOTE: This packet is only available on certain non-kRO clients.
  10255. void clif_storagepassword(struct map_session_data* sd, short info)
  10256. {
  10257. int fd = sd->fd;
  10258. WFIFOHEAD(fd,packet_len(0x23a));
  10259. WFIFOW(fd,0) = 0x23a;
  10260. WFIFOW(fd,2) = info;
  10261. WFIFOSET(fd,packet_len(0x23a));
  10262. }
  10263. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10264. /// 023b <type>.W <password>.16B <new password>.16B
  10265. /// type:
  10266. /// 2 = change password
  10267. /// 3 = check password
  10268. /// NOTE: This packet is only available on certain non-kRO clients.
  10269. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10270. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10271. // int type = RFIFOW(fd,info->pos[0]);
  10272. // char* password = RFIFOP(fd,info->pos[1]);
  10273. // char* new_password = RFIFOP(fd,info->pos[2]);
  10274. // storage_changepass(sd,password,new_password);
  10275. }
  10276. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10277. /// 023c <result>.W <error count>.W
  10278. /// result:
  10279. /// 4 = password change success
  10280. /// 5 = password change failure
  10281. /// 6 = password check success
  10282. /// 7 = password check failure
  10283. /// 8 = too many wrong passwords
  10284. /// ? = ignored
  10285. /// NOTE: This packet is only available on certain non-kRO clients.
  10286. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10287. {
  10288. int fd = sd->fd;
  10289. WFIFOHEAD(fd,packet_len(0x23c));
  10290. WFIFOW(fd,0) = 0x23c;
  10291. WFIFOW(fd,2) = result;
  10292. WFIFOW(fd,4) = error_count;
  10293. WFIFOSET(fd,packet_len(0x23c));
  10294. }
  10295. /// Party creation request
  10296. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10297. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10298. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10299. name[NAME_LENGTH-1] = '\0';
  10300. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10301. clif_displaymessage(fd, msg_txt(sd,227));
  10302. return;
  10303. }
  10304. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10305. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10306. return;
  10307. }
  10308. party_create(sd,name,0,0);
  10309. }
  10310. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10311. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10312. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10313. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10314. int item1 = RFIFOB(fd,info->pos[1]);
  10315. int item2 = RFIFOB(fd,info->pos[2]);
  10316. name[NAME_LENGTH-1] = '\0';
  10317. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10318. clif_displaymessage(fd, msg_txt(sd,227));
  10319. return;
  10320. }
  10321. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10322. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10323. return;
  10324. }
  10325. party_create(sd,name,item1,item2);
  10326. }
  10327. /// Party invitation request
  10328. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10329. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10330. {
  10331. struct map_session_data *t_sd;
  10332. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10333. clif_displaymessage(fd, msg_txt(sd,227));
  10334. return;
  10335. }
  10336. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10337. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10338. clif_noask_sub(sd, t_sd, 1);
  10339. return;
  10340. }
  10341. party_invite(sd, t_sd);
  10342. }
  10343. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10344. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10345. struct map_session_data *t_sd;
  10346. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10347. name[NAME_LENGTH-1] = '\0';
  10348. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10349. clif_displaymessage(fd, msg_txt(sd,227));
  10350. return;
  10351. }
  10352. t_sd = map_nick2sd(name);
  10353. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10354. clif_noask_sub(sd, t_sd, 1);
  10355. return;
  10356. }
  10357. party_invite(sd, t_sd);
  10358. }
  10359. /// Party invitation reply
  10360. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10361. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10362. /// flag:
  10363. /// 0 = reject
  10364. /// 1 = accept
  10365. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10366. {
  10367. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10368. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10369. RFIFOL(fd,info->pos[1]));
  10370. }
  10371. //(CZ_PARTY_JOIN_REQ_ACK)
  10372. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10373. {
  10374. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10375. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10376. RFIFOB(fd,info->pos[1]));
  10377. }
  10378. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10379. /// 0100
  10380. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10381. {
  10382. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10383. clif_displaymessage(fd, msg_txt(sd,227));
  10384. return;
  10385. }
  10386. party_leave(sd);
  10387. }
  10388. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10389. /// 0103 <account id>.L <char name>.24B
  10390. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10391. {
  10392. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10393. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10394. clif_displaymessage(fd, msg_txt(sd,227));
  10395. return;
  10396. }
  10397. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10398. (char*)RFIFOP(fd,info->pos[1]));
  10399. }
  10400. /// Request to change party options.
  10401. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10402. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10403. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10404. {
  10405. struct party_data *p;
  10406. int i,expflag;
  10407. int cmd = RFIFOW(fd,0);
  10408. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10409. if( !sd->status.party_id )
  10410. return;
  10411. p = party_search(sd->status.party_id);
  10412. if( p == NULL )
  10413. return;
  10414. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10415. if( i == MAX_PARTY )
  10416. return; //Shouldn't happen
  10417. if( !p->party.member[i].leader )
  10418. return;
  10419. expflag = RFIFOL(fd,info->pos[0]);
  10420. if(cmd == 0x0102){ //Client can't change the item-field
  10421. party_changeoption(sd, expflag, p->party.item);
  10422. }
  10423. else {
  10424. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10425. party_changeoption(sd, expflag, itemflag);
  10426. }
  10427. }
  10428. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10429. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10430. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10431. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10432. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10433. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10434. char *name, *message;
  10435. int namelen, messagelen;
  10436. // validate packet and retrieve name and message
  10437. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10438. return;
  10439. if( is_atcommand(fd, sd, message, 1) )
  10440. return;
  10441. if (sd->sc.cant.chat)
  10442. return; //no "chatting" while muted.
  10443. if( battle_config.min_chat_delay )
  10444. { //[Skotlex]
  10445. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10446. return;
  10447. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10448. }
  10449. if (battle_config.idletime_option&IDLE_CHAT)
  10450. sd->idletime = last_tick;
  10451. party_send_message(sd, text, textlen);
  10452. }
  10453. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10454. /// 07da <account id>.L
  10455. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10456. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10457. }
  10458. /// Party Booking in KRO [Spiria]
  10459. ///
  10460. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10461. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10462. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10463. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10464. short level = RFIFOW(fd,info->pos[0]);
  10465. short mapid = RFIFOW(fd,info->pos[1]);
  10466. int idxpbj = info->pos[2];
  10467. short job[PARTY_BOOKING_JOBS];
  10468. int i;
  10469. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10470. job[i] = RFIFOB(fd,idxpbj+i*2);
  10471. party_booking_register(sd, level, mapid, job);
  10472. }
  10473. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10474. /// 0803 <result>.W
  10475. /// result:
  10476. /// 0 = success
  10477. /// 1 = failure
  10478. /// 2 = already registered
  10479. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10480. {
  10481. int fd = sd->fd;
  10482. WFIFOHEAD(fd,packet_len(0x803));
  10483. WFIFOW(fd,0) = 0x803;
  10484. WFIFOW(fd,2) = flag;
  10485. WFIFOSET(fd,packet_len(0x803));
  10486. }
  10487. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10488. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10489. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10490. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10491. short level = RFIFOW(fd,info->pos[0]);
  10492. short mapid = RFIFOW(fd,info->pos[1]);
  10493. short job = RFIFOW(fd,info->pos[2]);
  10494. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10495. short resultcount = RFIFOW(fd,info->pos[4]);
  10496. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10497. }
  10498. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10499. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10500. /// more results:
  10501. /// 0 = no
  10502. /// 1 = yes
  10503. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10504. {
  10505. int i, j;
  10506. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10507. struct party_booking_ad_info *pb_ad;
  10508. WFIFOHEAD(fd,size*count + 5);
  10509. WFIFOW(fd,0) = 0x805;
  10510. WFIFOW(fd,2) = size*count + 5;
  10511. WFIFOB(fd,4) = more_result;
  10512. for(i=0; i<count; i++)
  10513. {
  10514. pb_ad = results[i];
  10515. WFIFOL(fd,i*size+5) = pb_ad->index;
  10516. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10517. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10518. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10519. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10520. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10521. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10522. }
  10523. WFIFOSET(fd,WFIFOW(fd,2));
  10524. }
  10525. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10526. /// 0806
  10527. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10528. {
  10529. if(party_booking_delete(sd))
  10530. clif_PartyBookingDeleteAck(sd, 0);
  10531. }
  10532. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10533. /// 0807 <result>.W
  10534. /// result:
  10535. /// 0 = success
  10536. /// 1 = success (auto-removed expired ad)
  10537. /// 2 = failure
  10538. /// 3 = nothing registered
  10539. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10540. {
  10541. int fd = sd->fd;
  10542. WFIFOHEAD(fd,packet_len(0x807));
  10543. WFIFOW(fd,0) = 0x807;
  10544. WFIFOW(fd,2) = flag;
  10545. WFIFOSET(fd,packet_len(0x807));
  10546. }
  10547. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10548. /// 0808 { <job>.W }*6
  10549. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10550. {
  10551. short job[PARTY_BOOKING_JOBS];
  10552. int i;
  10553. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10554. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10555. job[i] = RFIFOW(fd,idxpbu+i*2);
  10556. party_booking_update(sd, job);
  10557. }
  10558. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10559. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10560. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10561. {
  10562. int i;
  10563. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10564. if(pb_ad == NULL) return;
  10565. WBUFW(buf,0) = 0x809;
  10566. WBUFL(buf,2) = pb_ad->index;
  10567. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10568. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10569. WBUFW(buf,34) = pb_ad->p_detail.level;
  10570. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10571. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10572. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10573. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10574. }
  10575. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10576. /// 080a <index>.L { <job>.W }*6
  10577. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10578. {
  10579. int i;
  10580. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10581. if(pb_ad == NULL) return;
  10582. WBUFW(buf,0) = 0x80a;
  10583. WBUFL(buf,2) = pb_ad->index;
  10584. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10585. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10586. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10587. }
  10588. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10589. /// 080b <index>.L
  10590. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10591. {
  10592. uint8 buf[6];
  10593. WBUFW(buf,0) = 0x80b;
  10594. WBUFL(buf,2) = index;
  10595. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10596. }
  10597. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10598. /// 012e
  10599. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10600. {
  10601. vending_closevending(sd);
  10602. }
  10603. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10604. /// 0130 <account id>.L
  10605. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10606. {
  10607. if( sd->npc_id ) {// using an NPC
  10608. return;
  10609. }
  10610. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10611. }
  10612. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10613. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10614. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10615. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10616. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10617. int id = (int)RFIFOL(fd,info->pos[1]);
  10618. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10619. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10620. // whether it fails or not, the buy window is closed
  10621. sd->vended_id = 0;
  10622. }
  10623. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10624. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10625. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10626. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10627. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10628. int aid = (int)RFIFOL(fd,info->pos[1]);
  10629. int uid = (int)RFIFOL(fd,info->pos[2]);
  10630. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10631. vending_purchasereq(sd, aid, uid, data, len/4);
  10632. // whether it fails or not, the buy window is closed
  10633. sd->vended_id = 0;
  10634. }
  10635. /// Confirm or cancel the shop preparation window.
  10636. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10637. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10638. /// result:
  10639. /// 0 = canceled
  10640. /// 1 = open
  10641. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10642. int cmd = RFIFOW(fd,0);
  10643. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10644. short len = (short)RFIFOW(fd,info->pos[0]);
  10645. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10646. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10647. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10648. len -= 84;
  10649. }
  10650. else { //(CZ_REQ_OPENSTORE2)
  10651. bool flag;
  10652. len -= 85;
  10653. flag = (bool)RFIFOB(fd,info->pos[2]);
  10654. if( !flag )
  10655. sd->state.prevend = 0;
  10656. }
  10657. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10658. return;
  10659. if( map[sd->bl.m].flag.novending ) {
  10660. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10661. return;
  10662. }
  10663. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10664. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10665. return;
  10666. }
  10667. if( message[0] == '\0' ) // invalid input
  10668. return;
  10669. vending_openvending(sd, message, data, len/8);
  10670. }
  10671. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10672. /// 0165 <char id>.L <guild name>.24B
  10673. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10674. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10675. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10676. name[NAME_LENGTH-1] = '\0';
  10677. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10678. clif_displaymessage(fd, msg_txt(sd,228));
  10679. return;
  10680. }
  10681. guild_create(sd, name);
  10682. }
  10683. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10684. /// 014d
  10685. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10686. {
  10687. clif_guild_masterormember(sd);
  10688. }
  10689. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10690. /// 014f <type>.L
  10691. /// type:
  10692. /// 0 = basic info
  10693. /// 1 = member manager
  10694. /// 2 = positions
  10695. /// 3 = skills
  10696. /// 4 = expulsion list
  10697. /// 5 = unknown (GM_ALLGUILDLIST)
  10698. /// 6 = notice
  10699. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10700. {
  10701. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10702. if( !sd->status.guild_id && !sd->bg_id )
  10703. return;
  10704. switch( type )
  10705. {
  10706. case 0: // Basic Information Guild, hostile alliance information
  10707. clif_guild_basicinfo(sd);
  10708. clif_guild_allianceinfo(sd);
  10709. break;
  10710. case 1: // Members list, list job title
  10711. clif_guild_positionnamelist(sd);
  10712. clif_guild_memberlist(sd);
  10713. break;
  10714. case 2: // List job title, title information list
  10715. clif_guild_positionnamelist(sd);
  10716. clif_guild_positioninfolist(sd);
  10717. break;
  10718. case 3: // Skill list
  10719. clif_guild_skillinfo(sd);
  10720. break;
  10721. case 4: // Expulsion list
  10722. clif_guild_expulsionlist(sd);
  10723. break;
  10724. default:
  10725. ShowError("clif: guild request info: unknown type %d\n", type);
  10726. break;
  10727. }
  10728. }
  10729. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10730. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10731. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10732. {
  10733. int i;
  10734. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10735. int len = RFIFOW(fd,info->pos[0]);
  10736. int idxgpos = info->pos[1];
  10737. if(!sd->state.gmaster_flag)
  10738. return;
  10739. for(i = idxgpos; i < len; i += 40 ){
  10740. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10741. }
  10742. }
  10743. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10744. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10745. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10746. {
  10747. int i;
  10748. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10749. int len = RFIFOW(fd,info->pos[0]);
  10750. int idxgpos = info->pos[1];
  10751. if(!sd->state.gmaster_flag)
  10752. return;
  10753. for(i=idxgpos;i<len;i+=12){
  10754. guild_change_memberposition(sd->status.guild_id,
  10755. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10756. }
  10757. }
  10758. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10759. /// 0151 <guild id>.L
  10760. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10761. {
  10762. struct guild* g;
  10763. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10764. if( (g = guild_search(guild_id)) != NULL )
  10765. clif_guild_emblem(sd,g);
  10766. }
  10767. /// Validates data of a guild emblem (compressed bitmap)
  10768. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10769. {
  10770. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10771. unsigned long buf_len = sizeof(buf);
  10772. int offset = 0;
  10773. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10774. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10775. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10776. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10777. ))
  10778. return -1;
  10779. if(battle_config.emblem_transparency_limit != 100) {
  10780. int i, transcount = 1, tmp[3];
  10781. for(i = offset; i < buf_len-1; i++) {
  10782. int j = i%3;
  10783. tmp[j] = RBUFL(buf,i);
  10784. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10785. transcount++;
  10786. }
  10787. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10788. return -2;
  10789. }
  10790. return 0;
  10791. }
  10792. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10793. /// 0153 <packet len>.W <emblem data>.?B
  10794. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10795. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10796. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10797. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10798. int emb_val=0;
  10799. if( !emblem_len || !sd->state.gmaster_flag )
  10800. return;
  10801. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10802. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10803. return;
  10804. }
  10805. emb_val = clif_validate_emblem(emblem, emblem_len);
  10806. if(emb_val ==-1 ){
  10807. 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);
  10808. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10809. return;
  10810. } else if(emb_val == -2){
  10811. char output[128];
  10812. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10813. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10814. return;
  10815. }
  10816. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10817. }
  10818. /// Guild notice update request (CZ_GUILD_NOTICE).
  10819. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10820. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10821. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10822. int guild_id = RFIFOL(fd,info->pos[0]);
  10823. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10824. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10825. if(!sd->state.gmaster_flag)
  10826. return;
  10827. // compensate for some client defects when using multilanguage mode
  10828. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10829. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10830. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10831. guild_change_notice(sd, guild_id, msg1, msg2);
  10832. }
  10833. // Helper function for guild invite functions
  10834. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10835. {
  10836. if (t_sd == NULL) // not online or does not exist
  10837. return 1;
  10838. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10839. clif_displaymessage(fd, msg_txt(sd,228));
  10840. return 1;
  10841. }
  10842. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10843. clif_noask_sub(sd, t_sd, 2);
  10844. return 1;
  10845. }
  10846. guild_invite(sd, t_sd);
  10847. return 0;
  10848. }
  10849. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10850. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10851. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10852. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10853. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10854. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10855. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10856. if (clif_sub_guild_invite(fd, sd, t_sd))
  10857. return;
  10858. }
  10859. /// Guild invite request (/guildinvite)
  10860. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10861. void
  10862. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10863. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10864. if (clif_sub_guild_invite(fd, sd, t_sd))
  10865. return;
  10866. }
  10867. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10868. /// 016b <guild id>.L <answer>.L
  10869. /// answer:
  10870. /// 0 = refuse
  10871. /// 1 = accept
  10872. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10873. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10874. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10875. RFIFOL(fd,info->pos[1]));
  10876. }
  10877. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10878. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10879. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10880. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10881. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10882. clif_displaymessage(fd, msg_txt(sd,228));
  10883. return;
  10884. }
  10885. if( sd->bg_id ) {
  10886. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10887. return;
  10888. }
  10889. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10890. RFIFOL(fd,info->pos[1]),
  10891. RFIFOL(fd,info->pos[2]),
  10892. (char*)RFIFOP(fd,info->pos[3]));
  10893. }
  10894. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10895. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10896. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10897. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10898. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10899. { // Guild locked.
  10900. clif_displaymessage(fd, msg_txt(sd,228));
  10901. return;
  10902. }
  10903. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10904. RFIFOL(fd,info->pos[1]),
  10905. RFIFOL(fd,info->pos[2]),
  10906. (char*)RFIFOP(fd,info->pos[3]));
  10907. }
  10908. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10909. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10910. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10911. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10912. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10913. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10914. char *name, *message;
  10915. int namelen, messagelen;
  10916. // validate packet and retrieve name and message
  10917. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10918. return;
  10919. if( is_atcommand(fd, sd, message, 1) )
  10920. return;
  10921. if (sd->sc.cant.chat)
  10922. return; //no "chatting" while muted.
  10923. if( battle_config.min_chat_delay )
  10924. { //[Skotlex]
  10925. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10926. return;
  10927. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10928. }
  10929. if (battle_config.idletime_option&IDLE_CHAT)
  10930. sd->idletime = last_tick;
  10931. if( sd->bg_id )
  10932. bg_send_message(sd, text, textlen);
  10933. else
  10934. guild_send_message(sd, text, textlen);
  10935. }
  10936. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10937. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10938. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10939. {
  10940. struct map_session_data *t_sd;
  10941. if(!sd->state.gmaster_flag)
  10942. return;
  10943. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10944. clif_displaymessage(fd, msg_txt(sd,228));
  10945. return;
  10946. }
  10947. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10948. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10949. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10950. // @noask [LuzZza]
  10951. if(t_sd && t_sd->state.noask) {
  10952. clif_noask_sub(sd, t_sd, 3);
  10953. return;
  10954. }
  10955. guild_reqalliance(sd,t_sd);
  10956. }
  10957. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10958. /// 0172 <inviter account id>.L <answer>.L
  10959. /// answer:
  10960. /// 0 = refuse
  10961. /// 1 = accept
  10962. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10963. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10964. guild_reply_reqalliance(sd,
  10965. RFIFOL(fd,info->pos[0]),
  10966. RFIFOL(fd,info->pos[1]));
  10967. }
  10968. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10969. /// 0183 <opponent guild id>.L <relation>.L
  10970. /// relation:
  10971. /// 0 = Ally
  10972. /// 1 = Enemy
  10973. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10974. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10975. if(!sd->state.gmaster_flag)
  10976. return;
  10977. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10978. clif_displaymessage(fd, msg_txt(sd,228));
  10979. return;
  10980. }
  10981. guild_delalliance(sd,
  10982. RFIFOL(fd,info->pos[0]),
  10983. RFIFOL(fd,info->pos[1]));
  10984. }
  10985. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10986. /// 0180 <account id>.L
  10987. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10988. {
  10989. struct map_session_data *t_sd;
  10990. if(!sd->state.gmaster_flag)
  10991. return;
  10992. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10993. clif_displaymessage(fd, msg_txt(sd,228));
  10994. return;
  10995. }
  10996. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10997. // @noask [LuzZza]
  10998. if(t_sd && t_sd->state.noask) {
  10999. clif_noask_sub(sd, t_sd, 4);
  11000. return;
  11001. }
  11002. guild_opposition(sd,t_sd);
  11003. }
  11004. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11005. /// 015d <key>.40B
  11006. /// key:
  11007. /// now guild name; might have been (intended) email, since the
  11008. /// field name and size is same as the one in CH_DELETE_CHAR.
  11009. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11010. {
  11011. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11012. clif_displaymessage(fd, msg_txt(sd,228));
  11013. return;
  11014. }
  11015. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11016. }
  11017. /// Pet
  11018. ///
  11019. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11020. /// 01a1 <type>.B
  11021. /// type:
  11022. /// 0 = pet information
  11023. /// 1 = feed
  11024. /// 2 = performance
  11025. /// 3 = return to egg
  11026. /// 4 = unequip accessory
  11027. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11028. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11029. }
  11030. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11031. /// 019f <id>.L
  11032. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11033. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11034. }
  11035. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11036. /// 01a7 <index>.W
  11037. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11038. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11039. return;
  11040. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11041. clif_menuskill_clear(sd);
  11042. }
  11043. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11044. /// 01a9 <data>.L
  11045. /// data:
  11046. /// is either emotion (@see enum emotion_type) or a compound value
  11047. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11048. /// entry (given in parentheses) in data\pettalktable.xml
  11049. /// act id:
  11050. /// 0 = feeding
  11051. /// 1 = hunting
  11052. /// 2 = danger
  11053. /// 3 = dead
  11054. /// 4 = normal (stand)
  11055. /// 5 = special performance (perfor_s)
  11056. /// 6 = level up (levelup)
  11057. /// 7 = performance 1 (perfor_1)
  11058. /// 8 = performance 2 (perfor_2)
  11059. /// 9 = performance 3 (perfor_3)
  11060. /// 10 = log-in greeting (connect)
  11061. /// hungry value:
  11062. /// 0 = very hungry (hungry)
  11063. /// 1 = hungry (bit_hungry)
  11064. /// 2 = satisfied (noting)
  11065. /// 3 = stuffed (full)
  11066. /// 4 = full (so_full)
  11067. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11068. {
  11069. if(sd->pd)
  11070. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11071. }
  11072. /// Request to change pet's name (CZ_RENAME_PET).
  11073. /// 01a5 <name>.24B
  11074. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11075. {
  11076. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11077. }
  11078. /// /kill (CZ_DISCONNECT_CHARACTER).
  11079. /// Request to disconnect a character.
  11080. /// 00cc <account id>.L
  11081. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11082. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11083. {
  11084. struct block_list *target;
  11085. int tid;
  11086. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11087. target = map_id2bl(tid);
  11088. if (!target) {
  11089. clif_GM_kickack(sd, 0);
  11090. return;
  11091. }
  11092. switch (target->type) {
  11093. case BL_PC:
  11094. {
  11095. char command[NAME_LENGTH+6];
  11096. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11097. is_atcommand(fd, sd, command, 1);
  11098. }
  11099. break;
  11100. /**
  11101. * This one does not invoke any atcommand, so we need to check for permissions.
  11102. */
  11103. case BL_MOB:
  11104. {
  11105. char command[100];
  11106. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11107. clif_GM_kickack(sd, 0);
  11108. return;
  11109. }
  11110. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11111. log_atcommand(sd, command);
  11112. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11113. }
  11114. break;
  11115. case BL_NPC:
  11116. {
  11117. struct npc_data* nd = (struct npc_data *)target;
  11118. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11119. npc_unload_duplicates(nd);
  11120. npc_unload(nd,true);
  11121. npc_read_event_script();
  11122. }
  11123. }
  11124. break;
  11125. default:
  11126. clif_GM_kickack(sd, 0);
  11127. }
  11128. }
  11129. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11130. /// Request to disconnect all characters.
  11131. /// 00ce
  11132. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11133. char cmd[15];
  11134. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11135. is_atcommand(fd, sd, cmd, 1);
  11136. }
  11137. /// /remove (CZ_REMOVE_AID).
  11138. /// Request to warp to a character with given login ID.
  11139. /// 01ba <account name>.24B
  11140. /// /shift (CZ_SHIFT).
  11141. /// Request to warp to a character with given name.
  11142. /// 01bb <char name>.24B
  11143. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11144. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11145. char *player_name;
  11146. char command[NAME_LENGTH+8];
  11147. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11148. player_name[NAME_LENGTH-1] = '\0';
  11149. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11150. is_atcommand(fd, sd, command, 1);
  11151. }
  11152. /// /remove (CZ_REMOVE_AID_SSO).
  11153. /// Request to warp to a character with given account ID.
  11154. /// 0843 <account id>.L
  11155. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11156. {
  11157. uint32 account_id;
  11158. struct map_session_data* pl_sd;
  11159. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11160. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11161. char command[NAME_LENGTH+8];
  11162. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11163. is_atcommand(fd, sd, command, 1);
  11164. }
  11165. }
  11166. /// /recall (CZ_RECALL).
  11167. /// Request to summon a player with given login ID to own position.
  11168. /// 01bc <account name>.24B
  11169. /// /summon (CZ_RECALL_GID).
  11170. /// Request to summon a player with given name to own position.
  11171. /// 01bd <char name>.24B
  11172. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11173. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11174. char *player_name;
  11175. char command [NAME_LENGTH+8];
  11176. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11177. player_name[NAME_LENGTH-1] = '\0';
  11178. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11179. is_atcommand(fd, sd, command, 1);
  11180. }
  11181. /// /recall (CZ_RECALL_SSO).
  11182. /// Request to summon a player with given account ID to own position.
  11183. /// 0842 <account id>.L
  11184. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11185. {
  11186. uint32 account_id;
  11187. struct map_session_data* pl_sd;
  11188. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11189. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11190. char command[NAME_LENGTH+8];
  11191. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11192. is_atcommand(fd, sd, command, 1);
  11193. }
  11194. }
  11195. /// /item /monster (CZ_ITEM_CREATE).
  11196. /// Request to execute GM commands.
  11197. /// Usage:
  11198. /// /item n - summon n monster or acquire n item/s
  11199. /// /item money - grants 2147483647 zenies
  11200. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11201. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11202. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11203. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11204. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11205. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11206. /// 013f <item/mob name>.24B
  11207. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11208. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11209. {
  11210. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11211. int mob_id = 0;
  11212. struct item_data *id = NULL;
  11213. struct mob_db *mob = NULL;
  11214. StringBuf command;
  11215. char *str;
  11216. //#if PACKETVER >= 20131218
  11217. // char str[100];
  11218. //#else
  11219. // char str[24];
  11220. //#endif
  11221. str = (char*)RFIFOP(fd,info->pos[0]);
  11222. if (!str || str[0] == '\0')
  11223. return;
  11224. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11225. return;
  11226. trim(str);
  11227. // Zeny
  11228. if( strcmpi(str, "money") == 0 ) {
  11229. StringBuf_Init(&command);
  11230. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11231. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11232. StringBuf_Destroy(&command);
  11233. return;
  11234. }
  11235. // Item
  11236. if( (id = itemdb_searchname(str)) ) {
  11237. StringBuf_Init(&command);
  11238. if( !itemdb_isstackable2(id) ) //Nonstackable
  11239. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11240. else {
  11241. #ifdef ENABLE_ITEM_GUID
  11242. if (id->flag.guid)
  11243. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11244. else
  11245. #endif
  11246. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11247. }
  11248. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11249. StringBuf_Destroy(&command);
  11250. return;
  11251. }
  11252. // Monster
  11253. if ((mob_id = mobdb_searchname(str)) == 0)
  11254. mob_id = mobdb_checkid(atoi(str));
  11255. if( (mob = mob_db(mob_id)) ) {
  11256. StringBuf_Init(&command);
  11257. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11258. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11259. StringBuf_Destroy(&command);
  11260. return;
  11261. }
  11262. }
  11263. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11264. /// 019d <effect state>.L
  11265. /// effect state:
  11266. /// TODO: Any OPTION_* ?
  11267. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11268. char cmd[6];
  11269. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11270. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11271. is_atcommand(fd, sd, cmd, 1);
  11272. }
  11273. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11274. /// 0149 <account id>.L <type>.B <value>.W
  11275. /// type:
  11276. /// 0 = positive points
  11277. /// 1 = negative points
  11278. /// 2 = self mute (+10 minutes)
  11279. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11280. {
  11281. int id, type, value;
  11282. struct map_session_data *dstsd;
  11283. char command[NAME_LENGTH+15];
  11284. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11285. id = RFIFOL(fd,info->pos[0]);
  11286. type = RFIFOB(fd,info->pos[1]);
  11287. value = RFIFOW(fd,info->pos[2]);
  11288. if( type == 0 )
  11289. value = -value;
  11290. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11291. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11292. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11293. return;
  11294. dstsd = map_id2sd(id);
  11295. if( dstsd == NULL )
  11296. return;
  11297. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11298. is_atcommand(fd, sd, command, 1);
  11299. }
  11300. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11301. /// GM adjustment of a player's manner value by -60.
  11302. /// 0212 <char name>.24B
  11303. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11304. {
  11305. char command[NAME_LENGTH+15];
  11306. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11307. name[NAME_LENGTH-1] = '\0';
  11308. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11309. is_atcommand(fd, sd, command, 1);
  11310. }
  11311. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11312. /// 01e0 <account id>.L <account name>.24B
  11313. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11314. {
  11315. WFIFOHEAD(fd,packet_len(0x1e0));
  11316. WFIFOW(fd,0) = 0x1e0;
  11317. WFIFOL(fd,2) = account_id;
  11318. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11319. WFIFOSET(fd,packet_len(0x1e0));
  11320. }
  11321. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11322. /// 01df <account id>.L
  11323. //! TODO: Figure out how does this actually work
  11324. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11325. {
  11326. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11327. /*
  11328. char query[30];
  11329. safesnprintf(query,sizeof(query),"%d", account_id);
  11330. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11331. */
  11332. clif_account_name(fd, account_id, "");
  11333. }
  11334. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11335. /// GM single cell type change request.
  11336. /// 0198 <x>.W <y>.W <type>.W
  11337. /// type:
  11338. /// 0 = not walkable
  11339. /// 1 = walkable
  11340. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11341. {
  11342. int x,y,type;
  11343. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11344. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11345. return;
  11346. x = RFIFOW(fd,info->pos[0]);
  11347. y = RFIFOW(fd,info->pos[1]);
  11348. type = RFIFOW(fd,info->pos[2]);
  11349. map_setgatcell(sd->bl.m,x,y,type);
  11350. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11351. //FIXME: once players leave the map, the client 'forgets' this information.
  11352. }
  11353. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11354. /// Request to allow/deny whispers from a nick.
  11355. /// 00cf <nick>.24B <type>.B
  11356. /// type:
  11357. /// 0 = (/ex nick) deny speech from nick
  11358. /// 1 = (/in nick) allow speech from nick
  11359. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11360. {
  11361. char* nick;
  11362. uint8 type;
  11363. int i;
  11364. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11365. nick = (char*)RFIFOP(fd,info->pos[0]);
  11366. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11367. type = RFIFOB(fd,info->pos[1]);
  11368. if( type == 0 ) { // Add name to ignore list (block)
  11369. if (strcmp(wisp_server_name, nick) == 0) {
  11370. clif_wisexin(sd, type, 1); // fail
  11371. return;
  11372. }
  11373. // try to find a free spot, while checking for duplicates at the same time
  11374. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11375. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11376. clif_wisexin(sd, type, 2); // too many blocks
  11377. return;
  11378. }
  11379. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11380. clif_wisexin(sd, type, 0); // Aegis reports success.
  11381. return;
  11382. }
  11383. //Insert in position i
  11384. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11385. } else { // Remove name from ignore list (unblock)
  11386. // find entry
  11387. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11388. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11389. clif_wisexin(sd, type, 1); // fail
  11390. return;
  11391. }
  11392. // move everything one place down to overwrite removed entry
  11393. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11394. // wipe last entry
  11395. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11396. }
  11397. clif_wisexin(sd, type, 0); // success
  11398. }
  11399. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11400. /// Request to allow/deny all whispers.
  11401. /// 00d0 <type>.B
  11402. /// type:
  11403. /// 0 = (/exall) deny all speech
  11404. /// 1 = (/inall) allow all speech
  11405. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11406. {
  11407. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11408. if( type == 0 ) {// Deny all
  11409. if( sd->state.ignoreAll ) {
  11410. flag = 1; // fail
  11411. } else {
  11412. sd->state.ignoreAll = 1;
  11413. flag = 0; // success
  11414. }
  11415. } else {//Unblock everyone
  11416. if( sd->state.ignoreAll ) {
  11417. sd->state.ignoreAll = 0;
  11418. flag = 0; // success
  11419. } else {
  11420. if (sd->ignore[0].name[0] != '\0')
  11421. { //Wipe the ignore list.
  11422. memset(sd->ignore, 0, sizeof(sd->ignore));
  11423. flag = 0; // success
  11424. } else {
  11425. flag = 1; // fail
  11426. }
  11427. }
  11428. }
  11429. clif_wisall(sd, type, flag);
  11430. }
  11431. /// Whisper ignore list (ZC_WHISPER_LIST).
  11432. /// 00d4 <packet len>.W { <char name>.24B }*
  11433. void clif_PMIgnoreList(struct map_session_data* sd)
  11434. {
  11435. int i, fd = sd->fd;
  11436. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11437. WFIFOW(fd,0) = 0xd4;
  11438. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11439. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11440. }
  11441. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11442. WFIFOSET(fd,WFIFOW(fd,2));
  11443. }
  11444. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11445. /// 00d3
  11446. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11447. {
  11448. clif_PMIgnoreList(sd);
  11449. }
  11450. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11451. /// 01e7
  11452. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11453. {
  11454. if (sd->state.doridori) return;
  11455. switch (sd->class_&MAPID_UPPERMASK) {
  11456. case MAPID_SOUL_LINKER:
  11457. case MAPID_STAR_GLADIATOR:
  11458. case MAPID_TAEKWON:
  11459. if (!sd->state.rest)
  11460. break;
  11461. case MAPID_SUPER_NOVICE:
  11462. case MAPID_SUPER_BABY:
  11463. case MAPID_SUPER_NOVICE_E:
  11464. case MAPID_SUPER_BABY_E:
  11465. sd->state.doridori=1;
  11466. break;
  11467. }
  11468. }
  11469. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11470. /// 01ed
  11471. /// Note: This packet is caused by 7 lines of any text, followed by
  11472. /// the prayer and an another line of any text. The prayer is
  11473. /// defined by lines 790~793 in data\msgstringtable.txt
  11474. /// "Dear angel, can you hear my voice?"
  11475. /// "I am" (space separated player name) "Super Novice~"
  11476. /// "Help me out~ Please~ T_T"
  11477. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11478. {
  11479. if( sd->class_&JOBL_SUPER_NOVICE ) {
  11480. unsigned int next = pc_nextbaseexp(sd);
  11481. if( next == 0 ) next = pc_thisbaseexp(sd);
  11482. if( next ) {
  11483. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11484. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11485. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  11486. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11487. }
  11488. }
  11489. }
  11490. }
  11491. /// Friends List
  11492. ///
  11493. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11494. /// 0206 <account id>.L <char id>.L <state>.B
  11495. /// state:
  11496. /// 0 = online
  11497. /// 1 = offline
  11498. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11499. {
  11500. int i, fd = sd->fd;
  11501. //Seek friend.
  11502. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11503. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11504. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11505. return; //Not found
  11506. WFIFOHEAD(fd,packet_len(0x206));
  11507. WFIFOW(fd, 0) = 0x206;
  11508. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11509. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11510. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11511. WFIFOSET(fd, packet_len(0x206));
  11512. }
  11513. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11514. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11515. {
  11516. uint32 account_id, char_id, online;
  11517. account_id = va_arg(ap, int);
  11518. char_id = va_arg(ap, int);
  11519. online = va_arg(ap, int);
  11520. clif_friendslist_toggle(sd, account_id, char_id, online);
  11521. return 0;
  11522. }
  11523. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11524. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11525. void clif_friendslist_send(struct map_session_data *sd)
  11526. {
  11527. int i = 0, n, fd = sd->fd;
  11528. // Send friends list
  11529. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11530. WFIFOW(fd, 0) = 0x201;
  11531. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11532. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11533. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11534. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11535. }
  11536. if (i) {
  11537. WFIFOW(fd,2) = 4 + 32 * i;
  11538. WFIFOSET(fd, WFIFOW(fd,2));
  11539. }
  11540. for (n = 0; n < i; n++) { //Sending the online players
  11541. if (map_charid2sd(sd->status.friends[n].char_id))
  11542. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11543. }
  11544. }
  11545. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11546. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11547. /// result:
  11548. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11549. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11550. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11551. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11552. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11553. {
  11554. int fd;
  11555. nullpo_retv(sd);
  11556. fd = sd->fd;
  11557. WFIFOHEAD(fd,packet_len(0x209));
  11558. WFIFOW(fd,0) = 0x209;
  11559. WFIFOW(fd,2) = type;
  11560. if (f_sd) {
  11561. WFIFOL(fd,4) = f_sd->status.account_id;
  11562. WFIFOL(fd,8) = f_sd->status.char_id;
  11563. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11564. }
  11565. WFIFOSET(fd, packet_len(0x209));
  11566. }
  11567. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11568. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11569. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  11570. {
  11571. int fd = sd->fd;
  11572. WFIFOHEAD(fd,packet_len(0x207));
  11573. WFIFOW(fd,0) = 0x207;
  11574. WFIFOL(fd,2) = account_id;
  11575. WFIFOL(fd,6) = char_id;
  11576. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11577. WFIFOSET(fd,packet_len(0x207));
  11578. }
  11579. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11580. /// 0202 <name>.24B
  11581. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11582. {
  11583. struct map_session_data *f_sd;
  11584. int i;
  11585. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11586. // ensure that the request player's friend list is not full
  11587. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11588. if( i == MAX_FRIENDS ) {
  11589. clif_friendslist_reqack(sd, f_sd, 2);
  11590. return;
  11591. }
  11592. // Friend doesn't exist (no player with this name)
  11593. if (f_sd == NULL) {
  11594. clif_displaymessage(fd, msg_txt(sd,3));
  11595. return;
  11596. }
  11597. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11598. return;
  11599. }
  11600. // @noask [LuzZza]
  11601. if(f_sd->state.noask) {
  11602. clif_noask_sub(sd, f_sd, 5);
  11603. return;
  11604. }
  11605. // Friend already exists
  11606. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11607. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11608. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11609. return;
  11610. }
  11611. }
  11612. f_sd->friend_req = sd->status.char_id;
  11613. sd->friend_req = f_sd->status.char_id;
  11614. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11615. }
  11616. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11617. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11618. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11619. /// reply:
  11620. /// 0 = rejected
  11621. /// 1 = accepted
  11622. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11623. {
  11624. struct map_session_data *f_sd;
  11625. uint32 account_id;
  11626. char reply;
  11627. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11628. account_id = RFIFOL(fd,info->pos[0]);
  11629. //char_id = RFIFOL(fd,info->pos[1]);
  11630. if(sd->packet_ver < 6)
  11631. reply = RFIFOB(fd,info->pos[2]);
  11632. else
  11633. reply = RFIFOL(fd,info->pos[2]);
  11634. if( sd->bl.id == account_id ) {// adding oneself as friend
  11635. return;
  11636. }
  11637. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11638. if (f_sd == NULL)
  11639. return;
  11640. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11641. clif_friendslist_reqack(f_sd, sd, 1);
  11642. else {
  11643. int i;
  11644. // Find an empty slot
  11645. for (i = 0; i < MAX_FRIENDS; i++)
  11646. if (f_sd->status.friends[i].char_id == 0)
  11647. break;
  11648. if (i == MAX_FRIENDS) {
  11649. clif_friendslist_reqack(f_sd, sd, 2);
  11650. return;
  11651. }
  11652. f_sd->status.friends[i].account_id = sd->status.account_id;
  11653. f_sd->status.friends[i].char_id = sd->status.char_id;
  11654. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11655. clif_friendslist_reqack(f_sd, sd, 0);
  11656. if (battle_config.friend_auto_add) {
  11657. // Also add f_sd to sd's friendlist.
  11658. for (i = 0; i < MAX_FRIENDS; i++) {
  11659. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11660. return; //No need to add anything.
  11661. if (sd->status.friends[i].char_id == 0)
  11662. break;
  11663. }
  11664. if (i == MAX_FRIENDS) {
  11665. clif_friendslist_reqack(sd, f_sd, 2);
  11666. return;
  11667. }
  11668. sd->status.friends[i].account_id = f_sd->status.account_id;
  11669. sd->status.friends[i].char_id = f_sd->status.char_id;
  11670. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11671. clif_friendslist_reqack(sd, f_sd, 0);
  11672. }
  11673. }
  11674. }
  11675. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11676. /// 0203 <account id>.L <char id>.L
  11677. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11678. {
  11679. struct map_session_data *f_sd = NULL;
  11680. uint32 account_id, char_id;
  11681. int i, j;
  11682. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11683. account_id = RFIFOL(fd,info->pos[0]);
  11684. char_id = RFIFOL(fd,info->pos[1]);
  11685. // Search friend
  11686. for (i = 0; i < MAX_FRIENDS &&
  11687. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11688. if (i == MAX_FRIENDS) {
  11689. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11690. return;
  11691. }
  11692. //remove from friend's list first
  11693. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11694. for (i = 0; i < MAX_FRIENDS &&
  11695. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11696. if (i != MAX_FRIENDS) {
  11697. // move all chars up
  11698. for(j = i + 1; j < MAX_FRIENDS; j++)
  11699. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11700. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11701. //should the guy be notified of some message? we should add it here if so
  11702. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11703. WFIFOW(f_sd->fd,0) = 0x20a;
  11704. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11705. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11706. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11707. }
  11708. } else { //friend not online -- ask char server to delete from his friendlist
  11709. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11710. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11711. return;
  11712. }
  11713. }
  11714. // We can now delete from original requester
  11715. for (i = 0; i < MAX_FRIENDS &&
  11716. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11717. // move all chars up
  11718. for(j = i + 1; j < MAX_FRIENDS; j++)
  11719. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11720. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11721. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11722. WFIFOHEAD(fd,packet_len(0x20a));
  11723. WFIFOW(fd,0) = 0x20a;
  11724. WFIFOL(fd,2) = account_id;
  11725. WFIFOL(fd,6) = char_id;
  11726. WFIFOSET(fd, packet_len(0x20a));
  11727. }
  11728. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11729. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11730. void clif_PVPInfo(struct map_session_data* sd)
  11731. {
  11732. int fd = sd->fd;
  11733. WFIFOHEAD(fd,packet_len(0x210));
  11734. WFIFOW(fd,0) = 0x210;
  11735. WFIFOL(fd,2) = sd->status.char_id;
  11736. WFIFOL(fd,6) = sd->status.account_id;
  11737. WFIFOL(fd,10) = sd->pvp_won; // times won
  11738. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11739. WFIFOL(fd,18) = sd->pvp_point;
  11740. WFIFOSET(fd, packet_len(0x210));
  11741. }
  11742. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11743. /// 020f <char id>.L <account id>.L
  11744. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11745. {
  11746. // TODO: Is there a way to use this on an another player (char/acc id)?
  11747. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11748. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11749. clif_PVPInfo(sd);
  11750. }
  11751. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11752. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11753. void clif_blacksmith(struct map_session_data* sd)
  11754. {
  11755. int i, fd = sd->fd;
  11756. const char* name;
  11757. WFIFOHEAD(fd,packet_len(0x219));
  11758. WFIFOW(fd,0) = 0x219;
  11759. //Packet size limits this list to 10 elements. [Skotlex]
  11760. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11761. if (smith_fame_list[i].id > 0) {
  11762. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11763. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11764. {
  11765. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11766. } else
  11767. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11768. } else
  11769. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11770. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11771. }
  11772. for(;i < 10; i++) { //In case the MAX is less than 10.
  11773. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11774. WFIFOL(fd, 242 + i * 4) = 0;
  11775. }
  11776. WFIFOSET(fd, packet_len(0x219));
  11777. }
  11778. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11779. /// 0217
  11780. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11781. {
  11782. clif_blacksmith(sd);
  11783. }
  11784. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11785. /// 021b <points>.L <total points>.L
  11786. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11787. {
  11788. int fd = sd->fd;
  11789. WFIFOHEAD(fd,packet_len(0x21b));
  11790. WFIFOW(fd,0) = 0x21b;
  11791. WFIFOL(fd,2) = points;
  11792. WFIFOL(fd,6) = sd->status.fame;
  11793. WFIFOSET(fd, packet_len(0x21b));
  11794. }
  11795. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11796. /// 021a { <name>.24B }*10 { <point>.L }*10
  11797. void clif_alchemist(struct map_session_data* sd)
  11798. {
  11799. int i, fd = sd->fd;
  11800. const char* name;
  11801. WFIFOHEAD(fd,packet_len(0x21a));
  11802. WFIFOW(fd,0) = 0x21a;
  11803. //Packet size limits this list to 10 elements. [Skotlex]
  11804. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11805. if (chemist_fame_list[i].id > 0) {
  11806. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11807. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11808. {
  11809. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11810. } else
  11811. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11812. } else
  11813. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11814. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11815. }
  11816. for(;i < 10; i++) { //In case the MAX is less than 10.
  11817. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11818. WFIFOL(fd, 242 + i * 4) = 0;
  11819. }
  11820. WFIFOSET(fd, packet_len(0x21a));
  11821. }
  11822. /// /alchemist (CZ_ALCHEMIST_RANK).
  11823. /// 0218
  11824. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11825. {
  11826. clif_alchemist(sd);
  11827. }
  11828. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11829. /// 021c <points>.L <total points>.L
  11830. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11831. {
  11832. int fd = sd->fd;
  11833. WFIFOHEAD(fd,packet_len(0x21c));
  11834. WFIFOW(fd,0) = 0x21c;
  11835. WFIFOL(fd,2) = points;
  11836. WFIFOL(fd,6) = sd->status.fame;
  11837. WFIFOSET(fd, packet_len(0x21c));
  11838. }
  11839. /// /taekwon list (ZC_TAEKWON_RANK).
  11840. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11841. void clif_taekwon(struct map_session_data* sd)
  11842. {
  11843. int i, fd = sd->fd;
  11844. const char* name;
  11845. WFIFOHEAD(fd,packet_len(0x226));
  11846. WFIFOW(fd,0) = 0x226;
  11847. //Packet size limits this list to 10 elements. [Skotlex]
  11848. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11849. if (taekwon_fame_list[i].id > 0) {
  11850. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11851. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11852. {
  11853. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11854. } else
  11855. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11856. } else
  11857. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11858. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11859. }
  11860. for(;i < 10; i++) { //In case the MAX is less than 10.
  11861. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11862. WFIFOL(fd, 242 + i * 4) = 0;
  11863. }
  11864. WFIFOSET(fd, packet_len(0x226));
  11865. }
  11866. /// /taekwon (CZ_TAEKWON_RANK).
  11867. /// 0225
  11868. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11869. {
  11870. clif_taekwon(sd);
  11871. }
  11872. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11873. /// 0224 <points>.L <total points>.L
  11874. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11875. {
  11876. int fd = sd->fd;
  11877. WFIFOHEAD(fd,packet_len(0x224));
  11878. WFIFOW(fd,0) = 0x224;
  11879. WFIFOL(fd,2) = points;
  11880. WFIFOL(fd,6) = sd->status.fame;
  11881. WFIFOSET(fd, packet_len(0x224));
  11882. }
  11883. /// /pk list (ZC_KILLER_RANK).
  11884. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11885. void clif_ranking_pk(struct map_session_data* sd)
  11886. {
  11887. int i, fd = sd->fd;
  11888. WFIFOHEAD(fd,packet_len(0x238));
  11889. WFIFOW(fd,0) = 0x238;
  11890. for(i=0;i<10;i++){
  11891. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11892. WFIFOL(fd,i*4+242) = 0;
  11893. }
  11894. WFIFOSET(fd, packet_len(0x238));
  11895. }
  11896. /// /pk (CZ_KILLER_RANK).
  11897. /// 0237
  11898. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11899. {
  11900. clif_ranking_pk(sd);
  11901. }
  11902. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11903. /// 0254 <which>.B
  11904. /// which: (unused atm for security purpose)
  11905. /// 0 = sun
  11906. /// 1 = moon
  11907. /// 2 = star
  11908. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11909. {
  11910. int i;
  11911. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11912. if (sd->menuskill_id != SG_FEEL)
  11913. return;
  11914. i = sd->menuskill_val-1;
  11915. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11916. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11917. sd->feel_map[i].m = sd->bl.m;
  11918. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11919. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11920. // clif_misceffect2(&sd->bl, 0x1b0);
  11921. // clif_misceffect2(&sd->bl, 0x21f);
  11922. clif_feel_info(sd, i, 0);
  11923. clif_menuskill_clear(sd);
  11924. }
  11925. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11926. /// 0253 <which>.B
  11927. /// which:
  11928. /// 0 = sun
  11929. /// 1 = moon
  11930. /// 2 = star
  11931. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11932. {
  11933. WFIFOHEAD(fd,packet_len(0x253));
  11934. WFIFOW(fd,0)=0x253;
  11935. WFIFOB(fd,2)=TOB(skill_lv-1);
  11936. WFIFOSET(fd, packet_len(0x253));
  11937. sd->menuskill_id = SG_FEEL;
  11938. sd->menuskill_val = skill_lv;
  11939. }
  11940. /// Request to change homunculus' name (CZ_RENAME_MER).
  11941. /// 0231 <name>.24B
  11942. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11943. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11944. }
  11945. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11946. /// 0234 <id>.L
  11947. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11948. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11949. struct block_list *bl = NULL;
  11950. struct unit_data *ud = NULL;
  11951. if( sd->md && sd->md->bl.id == id )
  11952. bl = &sd->md->bl;
  11953. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11954. bl = &sd->hd->bl; // Moving Homunculus
  11955. else
  11956. return;
  11957. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11958. ud = unit_bl2ud(bl);
  11959. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11960. }
  11961. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11962. /// 0232 <id>.L <position data>.3B
  11963. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11964. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11965. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11966. struct block_list *bl = NULL;
  11967. short x, y;
  11968. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11969. if( sd->md && sd->md->bl.id == id )
  11970. bl = &sd->md->bl; // Moving Mercenary
  11971. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11972. bl = &sd->hd->bl; // Moving Homunculus
  11973. else
  11974. return;
  11975. unit_walktoxy(bl, x, y, 4);
  11976. }
  11977. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11978. /// 0233 <id>.L <target id>.L <action>.B
  11979. /// action:
  11980. /// always 0
  11981. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11982. {
  11983. struct block_list *bl = NULL;
  11984. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11985. int id = RFIFOL(fd,info->pos[0]);
  11986. int target_id = RFIFOL(fd,info->pos[1]);
  11987. int action_type = RFIFOB(fd,info->pos[2]);
  11988. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11989. bl = &sd->hd->bl;
  11990. else if( sd->md && sd->md->bl.id == id )
  11991. bl = &sd->md->bl;
  11992. else return;
  11993. unit_stop_attack(bl);
  11994. unit_attack(bl, target_id, action_type != 0);
  11995. }
  11996. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11997. /// 022d <type>.W <command>.B
  11998. /// type:
  11999. /// always 0
  12000. /// command:
  12001. /// 0 = homunculus information
  12002. /// 1 = feed
  12003. /// 2 = delete
  12004. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12005. { //[orn]
  12006. int cmd = RFIFOW(fd,0);
  12007. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12008. if(!hom_is_active(sd->hd))
  12009. return;
  12010. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12011. }
  12012. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12013. /// 0292
  12014. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12015. {
  12016. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12017. int hpsp = 100;
  12018. if (item_position < 0) {
  12019. if (sd->sc.data[SC_LIGHT_OF_REGENE])
  12020. hpsp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12021. else
  12022. return;
  12023. }
  12024. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12025. return;
  12026. if (!status_revive(&sd->bl, hpsp, hpsp))
  12027. return;
  12028. if (item_position < 0)
  12029. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12030. else
  12031. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12032. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12033. }
  12034. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12035. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12036. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12037. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12038. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12039. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12040. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12041. void clif_check(int fd, struct map_session_data* pl_sd)
  12042. {
  12043. WFIFOHEAD(fd,packet_len(0x214));
  12044. WFIFOW(fd, 0) = 0x214;
  12045. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12046. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12047. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12048. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12049. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12050. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12051. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12052. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12053. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12054. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12055. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12056. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12057. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12058. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12059. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12060. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12061. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12062. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12063. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12064. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12065. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12066. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12067. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12068. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12069. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12070. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12071. WFIFOSET(fd,packet_len(0x214));
  12072. }
  12073. /// /check (CZ_REQ_STATUS_GM).
  12074. /// Request character's status values.
  12075. /// 0213 <char name>.24B
  12076. void clif_parse_Check(int fd, struct map_session_data *sd)
  12077. {
  12078. char charname[NAME_LENGTH];
  12079. struct map_session_data* pl_sd;
  12080. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12081. return;
  12082. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12083. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12084. {
  12085. return;
  12086. }
  12087. clif_check(fd, pl_sd);
  12088. }
  12089. /// MAIL SYSTEM
  12090. /// By Zephyrus
  12091. ///
  12092. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12093. /// 0255 <index>.W <result>.B
  12094. /// result:
  12095. /// 0 = success
  12096. /// 1 = failure
  12097. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12098. {
  12099. WFIFOHEAD(fd,packet_len(0x255));
  12100. WFIFOW(fd,0) = 0x255;
  12101. WFIFOW(fd,2) = index;
  12102. WFIFOB(fd,4) = flag;
  12103. WFIFOSET(fd,packet_len(0x255));
  12104. }
  12105. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12106. /// 0245 <result>.B
  12107. /// result:
  12108. /// 0 = success
  12109. /// 1 = failure
  12110. /// 2 = too many items
  12111. void clif_Mail_getattachment(int fd, uint8 flag)
  12112. {
  12113. WFIFOHEAD(fd,packet_len(0x245));
  12114. WFIFOW(fd,0) = 0x245;
  12115. WFIFOB(fd,2) = flag;
  12116. WFIFOSET(fd,packet_len(0x245));
  12117. }
  12118. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12119. /// 0249 <result>.B
  12120. /// result:
  12121. /// 0 = success
  12122. /// 1 = recipinent does not exist
  12123. void clif_Mail_send(int fd, bool fail)
  12124. {
  12125. WFIFOHEAD(fd,packet_len(0x249));
  12126. WFIFOW(fd,0) = 0x249;
  12127. WFIFOB(fd,2) = fail;
  12128. WFIFOSET(fd,packet_len(0x249));
  12129. }
  12130. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12131. /// 0257 <mail id>.L <result>.W
  12132. /// result:
  12133. /// 0 = success
  12134. /// 1 = failure
  12135. void clif_Mail_delete(int fd, int mail_id, short fail)
  12136. {
  12137. WFIFOHEAD(fd, packet_len(0x257));
  12138. WFIFOW(fd,0) = 0x257;
  12139. WFIFOL(fd,2) = mail_id;
  12140. WFIFOW(fd,6) = fail;
  12141. WFIFOSET(fd, packet_len(0x257));
  12142. }
  12143. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12144. /// 0274 <mail id>.L <result>.W
  12145. /// result:
  12146. /// 0 = success
  12147. /// 1 = failure
  12148. void clif_Mail_return(int fd, int mail_id, short fail)
  12149. {
  12150. WFIFOHEAD(fd,packet_len(0x274));
  12151. WFIFOW(fd,0) = 0x274;
  12152. WFIFOL(fd,2) = mail_id;
  12153. WFIFOW(fd,6) = fail;
  12154. WFIFOSET(fd,packet_len(0x274));
  12155. }
  12156. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12157. /// 024a <mail id>.L <title>.40B <sender>.24B
  12158. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12159. {
  12160. WFIFOHEAD(fd,packet_len(0x24a));
  12161. WFIFOW(fd,0) = 0x24a;
  12162. WFIFOL(fd,2) = mail_id;
  12163. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12164. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12165. WFIFOSET(fd,packet_len(0x24a));
  12166. }
  12167. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12168. /// 0260 <type>.L
  12169. /// type:
  12170. /// 0 = open
  12171. /// 1 = close
  12172. void clif_Mail_window(int fd, int flag)
  12173. {
  12174. WFIFOHEAD(fd,packet_len(0x260));
  12175. WFIFOW(fd,0) = 0x260;
  12176. WFIFOL(fd,2) = flag;
  12177. WFIFOSET(fd,packet_len(0x260));
  12178. }
  12179. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12180. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12181. /// read:
  12182. /// 0 = unread
  12183. /// 1 = read
  12184. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12185. {
  12186. int fd = sd->fd;
  12187. struct mail_data *md = &sd->mail.inbox;
  12188. struct mail_message *msg;
  12189. int len, i, j;
  12190. len = 8 + (73 * md->amount);
  12191. WFIFOHEAD(fd,len);
  12192. WFIFOW(fd,0) = 0x240;
  12193. WFIFOW(fd,2) = len;
  12194. WFIFOL(fd,4) = md->amount;
  12195. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12196. {
  12197. msg = &md->msg[i];
  12198. if (msg->id < 1)
  12199. continue;
  12200. WFIFOL(fd,8+73*j) = msg->id;
  12201. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12202. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12203. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12204. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12205. j++;
  12206. }
  12207. WFIFOSET(fd,len);
  12208. if( md->full ) {// TODO: is this official?
  12209. char output[100];
  12210. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12211. clif_disp_onlyself(sd, output, strlen(output));
  12212. }
  12213. }
  12214. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12215. /// 023f
  12216. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12217. {
  12218. struct mail_data* md = &sd->mail.inbox;
  12219. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12220. intif_Mail_requestinbox(sd->status.char_id, 1);
  12221. else
  12222. clif_Mail_refreshinbox(sd);
  12223. mail_removeitem(sd, 0);
  12224. mail_removezeny(sd, 0);
  12225. }
  12226. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12227. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12228. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12229. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12230. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12231. {
  12232. int i, fd = sd->fd;
  12233. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12234. if( i == MAIL_MAX_INBOX ) {
  12235. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12236. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12237. return;
  12238. } else {
  12239. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12240. struct item *item = &msg->item;
  12241. struct item_data *data;
  12242. int msg_len = strlen(msg->body), len;
  12243. if( msg_len == 0 ) {
  12244. strcpy(msg->body, "(no message)");
  12245. msg_len = strlen(msg->body);
  12246. }
  12247. len = 101 + msg_len;
  12248. WFIFOHEAD(fd,len);
  12249. WFIFOW(fd,0) = 0x242;
  12250. WFIFOW(fd,2) = len;
  12251. WFIFOL(fd,4) = msg->id;
  12252. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12253. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12254. WFIFOL(fd,72) = 0;
  12255. WFIFOL(fd,76) = msg->zeny;
  12256. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12257. WFIFOL(fd,80) = item->amount;
  12258. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12259. WFIFOW(fd,86) = data->type;
  12260. WFIFOB(fd,88) = item->identify;
  12261. WFIFOB(fd,89) = item->attribute;
  12262. WFIFOB(fd,90) = item->refine;
  12263. WFIFOW(fd,91) = item->card[0];
  12264. WFIFOW(fd,93) = item->card[1];
  12265. WFIFOW(fd,95) = item->card[2];
  12266. WFIFOW(fd,97) = item->card[3];
  12267. } else // no item, set all to zero
  12268. memset(WFIFOP(fd,80), 0x00, 19);
  12269. WFIFOB(fd,99) = (unsigned char)msg_len;
  12270. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12271. WFIFOSET(fd,len);
  12272. if (msg->status == MAIL_UNREAD) {
  12273. msg->status = MAIL_READ;
  12274. intif_Mail_read(mail_id);
  12275. clif_parse_Mail_refreshinbox(fd, sd);
  12276. }
  12277. }
  12278. }
  12279. /// Request to open a mail (CZ_MAIL_OPEN).
  12280. /// 0241 <mail id>.L
  12281. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12282. {
  12283. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12284. if( mail_id <= 0 )
  12285. return;
  12286. if( mail_invalid_operation(sd) )
  12287. return;
  12288. clif_Mail_read(sd, mail_id);
  12289. }
  12290. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12291. /// 0244 <mail id>.L
  12292. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12293. {
  12294. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12295. int i;
  12296. bool fail = false;
  12297. if( !chrif_isconnected() )
  12298. return;
  12299. if( mail_id <= 0 )
  12300. return;
  12301. if( mail_invalid_operation(sd) )
  12302. return;
  12303. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12304. if( i == MAIL_MAX_INBOX )
  12305. return;
  12306. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12307. return;
  12308. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12309. clif_Mail_getattachment(fd, 1);
  12310. return;
  12311. }
  12312. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12313. struct item_data *data;
  12314. unsigned int weight;
  12315. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12316. return;
  12317. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12318. case CHKADDITEM_NEW:
  12319. fail = ( pc_inventoryblank(sd) == 0 );
  12320. break;
  12321. case CHKADDITEM_OVERAMOUNT:
  12322. fail = true;
  12323. }
  12324. if( fail ) {
  12325. clif_Mail_getattachment(fd, 1);
  12326. return;
  12327. }
  12328. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12329. if( sd->weight + weight > sd->max_weight ) {
  12330. clif_Mail_getattachment(fd, 2);
  12331. return;
  12332. }
  12333. }
  12334. sd->mail.inbox.msg[i].zeny = 0;
  12335. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12336. clif_Mail_read(sd, mail_id);
  12337. intif_Mail_getattach(sd->status.char_id, mail_id);
  12338. }
  12339. /// Request to delete a mail (CZ_MAIL_DELETE).
  12340. /// 0243 <mail id>.L
  12341. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12342. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12343. int i;
  12344. if( !chrif_isconnected() )
  12345. return;
  12346. if( mail_id <= 0 )
  12347. return;
  12348. if( mail_invalid_operation(sd) )
  12349. return;
  12350. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12351. if (i < MAIL_MAX_INBOX) {
  12352. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12353. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12354. clif_Mail_delete(sd->fd, mail_id, 1);
  12355. return;
  12356. }
  12357. intif_Mail_delete(sd->status.char_id, mail_id);
  12358. }
  12359. }
  12360. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12361. /// 0273 <mail id>.L <receive name>.24B
  12362. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12363. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12364. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12365. int i;
  12366. if( mail_id <= 0 )
  12367. return;
  12368. if( mail_invalid_operation(sd) )
  12369. return;
  12370. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12371. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12372. intif_Mail_return(sd->status.char_id, mail_id);
  12373. else
  12374. clif_Mail_return(sd->fd, mail_id, 1);
  12375. }
  12376. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12377. /// 0247 <index>.W <amount>.L
  12378. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12379. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12380. int idx = RFIFOW(fd,info->pos[0]);
  12381. int amount = RFIFOL(fd,info->pos[1]);
  12382. unsigned char flag;
  12383. if( !chrif_isconnected() )
  12384. return;
  12385. if (idx < 0 || amount < 0)
  12386. return;
  12387. flag = mail_setitem(sd, idx, amount);
  12388. clif_Mail_setattachment(fd,idx,!flag);
  12389. }
  12390. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12391. /// 0246 <type>.W
  12392. /// type:
  12393. /// 0 = reset all
  12394. /// 1 = remove item
  12395. /// 2 = remove zeny
  12396. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12397. {
  12398. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12399. if (type == 0 || type == 1)
  12400. mail_removeitem(sd, 0);
  12401. if (type == 0 || type == 2)
  12402. mail_removezeny(sd, 0);
  12403. }
  12404. /// Request to send mail (CZ_MAIL_SEND).
  12405. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12406. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12407. {
  12408. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12409. if( !chrif_isconnected() )
  12410. return;
  12411. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12412. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12413. return;
  12414. }
  12415. mail_send(sd, (char*)RFIFOP(fd,info->pos[1]), (char*)RFIFOP(fd,info->pos[2]), (char*)RFIFOP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  12416. }
  12417. /// AUCTION SYSTEM
  12418. /// By Zephyrus
  12419. ///
  12420. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12421. /// 025f <type>.L
  12422. /// type:
  12423. /// 0 = open
  12424. /// 1 = close
  12425. void clif_Auction_openwindow(struct map_session_data *sd)
  12426. {
  12427. int fd = sd->fd;
  12428. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12429. return;
  12430. if( !battle_config.feature_auction )
  12431. return;
  12432. WFIFOHEAD(fd,packet_len(0x25f));
  12433. WFIFOW(fd,0) = 0x25f;
  12434. WFIFOL(fd,2) = 0;
  12435. WFIFOSET(fd,packet_len(0x25f));
  12436. }
  12437. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12438. /// 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 }*
  12439. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12440. {
  12441. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12442. struct auction_data auction;
  12443. struct item_data *item;
  12444. WFIFOHEAD(fd,12 + (count * 83));
  12445. WFIFOW(fd,0) = 0x252;
  12446. WFIFOW(fd,2) = 12 + (count * 83);
  12447. WFIFOL(fd,4) = pages;
  12448. WFIFOL(fd,8) = count;
  12449. for( i = 0; i < count; i++ ) {
  12450. int k = 12 + (i * 83);
  12451. memcpy(&auction, RBUFP(buf,i * len), len);
  12452. WFIFOL(fd,k) = auction.auction_id;
  12453. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12454. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12455. WFIFOW(fd,28+k) = item->view_id;
  12456. else
  12457. WFIFOW(fd,28+k) = auction.item.nameid;
  12458. WFIFOL(fd,30+k) = auction.type;
  12459. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12460. WFIFOB(fd,36+k) = auction.item.identify;
  12461. WFIFOB(fd,37+k) = auction.item.attribute;
  12462. WFIFOB(fd,38+k) = auction.item.refine;
  12463. WFIFOW(fd,39+k) = auction.item.card[0];
  12464. WFIFOW(fd,41+k) = auction.item.card[1];
  12465. WFIFOW(fd,43+k) = auction.item.card[2];
  12466. WFIFOW(fd,45+k) = auction.item.card[3];
  12467. WFIFOL(fd,47+k) = auction.price;
  12468. WFIFOL(fd,51+k) = auction.buynow;
  12469. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12470. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12471. }
  12472. WFIFOSET(fd,WFIFOW(fd,2));
  12473. }
  12474. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12475. /// 0256 <index>.W <result>.B
  12476. /// result:
  12477. /// 0 = success
  12478. /// 1 = failure
  12479. static void clif_Auction_setitem(int fd, int index, bool fail)
  12480. {
  12481. WFIFOHEAD(fd,packet_len(0x256));
  12482. WFIFOW(fd,0) = 0x256;
  12483. WFIFOW(fd,2) = index;
  12484. WFIFOB(fd,4) = fail;
  12485. WFIFOSET(fd,packet_len(0x256));
  12486. }
  12487. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12488. /// 024b <type>.W
  12489. /// type:
  12490. /// 0 = create (any other action in auction window)
  12491. /// 1 = cancel (cancel pressed on register tab)
  12492. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12493. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12494. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12495. if( sd->auction.amount > 0 )
  12496. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12497. sd->auction.amount = 0;
  12498. }
  12499. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12500. /// 024c <index>.W <count>.L
  12501. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12502. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12503. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12504. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12505. struct item_data *item;
  12506. if( !battle_config.feature_auction )
  12507. return;
  12508. if( sd->auction.amount > 0 )
  12509. sd->auction.amount = 0;
  12510. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12511. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12512. return;
  12513. }
  12514. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12515. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12516. return;
  12517. }
  12518. if( (item = itemdb_exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC || item->type == IT_SHADOWGEAR) )
  12519. { // Consumable or pets are not allowed
  12520. clif_Auction_setitem(sd->fd, idx, true);
  12521. return;
  12522. }
  12523. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12524. !sd->status.inventory[idx].identify ||
  12525. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12526. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12527. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12528. ) {
  12529. clif_Auction_setitem(sd->fd, idx, true);
  12530. return;
  12531. }
  12532. sd->auction.index = idx;
  12533. sd->auction.amount = amount;
  12534. clif_Auction_setitem(fd, idx + 2, false);
  12535. }
  12536. /// Result from an auction action (ZC_AUCTION_RESULT).
  12537. /// 0250 <result>.B
  12538. /// result:
  12539. /// 0 = You have failed to bid into the auction
  12540. /// 1 = You have successfully bid in the auction
  12541. /// 2 = The auction has been canceled
  12542. /// 3 = An auction with at least one bidder cannot be canceled
  12543. /// 4 = You cannot register more than 5 items in an auction at a time
  12544. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12545. /// 6 = You have won the auction
  12546. /// 7 = You have failed to win the auction
  12547. /// 8 = You do not have enough Zeny
  12548. /// 9 = You cannot place more than 5 bids at a time
  12549. void clif_Auction_message(int fd, unsigned char flag)
  12550. {
  12551. WFIFOHEAD(fd,packet_len(0x250));
  12552. WFIFOW(fd,0) = 0x250;
  12553. WFIFOB(fd,2) = flag;
  12554. WFIFOSET(fd,packet_len(0x250));
  12555. }
  12556. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12557. /// 025e <result>.W
  12558. /// result:
  12559. /// 0 = You have ended the auction
  12560. /// 1 = You cannot end the auction
  12561. /// 2 = Auction ID is incorrect
  12562. void clif_Auction_close(int fd, unsigned char flag)
  12563. {
  12564. WFIFOHEAD(fd,packet_len(0x25e));
  12565. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12566. WFIFOW(fd,2) = flag;
  12567. WFIFOSET(fd,packet_len(0x25e));
  12568. }
  12569. /// Request to add an auction (CZ_AUCTION_ADD).
  12570. /// 024d <now money>.L <max money>.L <delete hour>.W
  12571. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12572. {
  12573. struct auction_data auction;
  12574. struct item_data *item;
  12575. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12576. if( !battle_config.feature_auction )
  12577. return;
  12578. auction.price = RFIFOL(fd,info->pos[0]);
  12579. auction.buynow = RFIFOL(fd,info->pos[1]);
  12580. auction.hours = RFIFOW(fd,info->pos[2]);
  12581. // Invalid Situations...
  12582. if( sd->auction.amount < 1 ) {
  12583. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12584. return;
  12585. }
  12586. if( auction.price >= auction.buynow ) {
  12587. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12588. return;
  12589. }
  12590. if( auction.hours < 1 || auction.hours > 48 ) {
  12591. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12592. return;
  12593. }
  12594. // Auction checks...
  12595. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12596. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12597. clif_Auction_message(fd, 2); // The auction has been canceled
  12598. return;
  12599. }
  12600. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12601. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12602. return;
  12603. }
  12604. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12605. auction.buynow = battle_config.auction_maximumprice;
  12606. if( auction.price >= auction.buynow )
  12607. auction.price = auction.buynow - 1;
  12608. }
  12609. auction.auction_id = 0;
  12610. auction.seller_id = sd->status.char_id;
  12611. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12612. auction.buyer_id = 0;
  12613. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12614. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12615. {
  12616. clif_Auction_message(fd, 2); // The auction has been canceled
  12617. return;
  12618. }
  12619. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12620. { // Just in case
  12621. clif_Auction_message(fd, 2); // The auction has been canceled
  12622. return;
  12623. }
  12624. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12625. auction.type = item->type;
  12626. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12627. auction.item.amount = 1;
  12628. auction.timestamp = 0;
  12629. if( !intif_Auction_register(&auction) )
  12630. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12631. else
  12632. {
  12633. int zeny = auction.hours*battle_config.auction_feeperhour;
  12634. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12635. sd->auction.amount = 0;
  12636. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12637. }
  12638. }
  12639. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12640. /// 024e <auction id>.L
  12641. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12642. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12643. intif_Auction_cancel(sd->status.char_id, auction_id);
  12644. }
  12645. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12646. /// 025d <auction id>.L
  12647. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12648. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12649. intif_Auction_close(sd->status.char_id, auction_id);
  12650. }
  12651. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12652. /// 024f <auction id>.L <money>.L
  12653. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12654. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12655. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12656. int bid = RFIFOL(fd,info->pos[1]);
  12657. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12658. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12659. return;
  12660. }
  12661. if( bid <= 0 )
  12662. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12663. else if( bid > sd->status.zeny )
  12664. clif_Auction_message(fd, 8); // You do not have enough zeny
  12665. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12666. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12667. else {
  12668. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12669. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12670. }
  12671. }
  12672. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12673. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12674. /// search type:
  12675. /// 0 = armor
  12676. /// 1 = weapon
  12677. /// 2 = card
  12678. /// 3 = misc
  12679. /// 4 = name search
  12680. /// 5 = auction id search
  12681. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12682. char search_text[NAME_LENGTH];
  12683. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12684. short type = RFIFOW(fd,info->pos[0]);
  12685. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12686. int page = RFIFOW(fd,info->pos[3]);
  12687. if( !battle_config.feature_auction )
  12688. return;
  12689. clif_parse_Auction_cancelreg(fd, sd);
  12690. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12691. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12692. }
  12693. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12694. /// 025c <type>.W
  12695. /// type:
  12696. /// 0 = sell (own auctions)
  12697. /// 1 = buy (own bids)
  12698. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12699. {
  12700. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12701. if( !battle_config.feature_auction )
  12702. return;
  12703. clif_parse_Auction_cancelreg(fd, sd);
  12704. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12705. }
  12706. /// CASH/POINT SHOP
  12707. ///
  12708. void clif_cashshop_open( struct map_session_data* sd ){
  12709. WFIFOHEAD( sd->fd, 10 );
  12710. WFIFOW( sd->fd, 0 ) = 0x845;
  12711. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12712. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12713. WFIFOSET( sd->fd, 10 );
  12714. }
  12715. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12716. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12717. clif_cashshop_open( sd );
  12718. }
  12719. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12720. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12721. // No need to do anything here
  12722. }
  12723. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12724. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12725. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12726. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12727. int j;
  12728. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12729. return;
  12730. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12731. WFIFOW(fd, 0) = 0x8c0;
  12732. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12733. WFIFOL(fd, 4) = tab;
  12734. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12735. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12736. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  12737. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  12738. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12739. }
  12740. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12741. }
  12742. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12743. void clif_cashshop_list( int fd ){
  12744. int tab;
  12745. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12746. int length = 8 + cash_shop_items[tab].count * 6;
  12747. int i, offset;
  12748. WFIFOHEAD( fd, length );
  12749. WFIFOW( fd, 0 ) = 0x8ca;
  12750. WFIFOW( fd, 2 ) = length;
  12751. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12752. WFIFOW( fd, 6 ) = tab;
  12753. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12754. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  12755. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  12756. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12757. }
  12758. WFIFOSET( fd, length );
  12759. }
  12760. }
  12761. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12762. if( !sd->status.cashshop_sent ) {
  12763. clif_cashshop_list( fd );
  12764. sd->status.cashshop_sent = true;
  12765. }
  12766. }
  12767. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12768. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12769. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12770. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12771. {
  12772. int fd,i;
  12773. #if PACKETVER < 20070711
  12774. const int offset = 8;
  12775. #else
  12776. const int offset = 12;
  12777. #endif
  12778. nullpo_retv(sd);
  12779. nullpo_retv(nd);
  12780. fd = sd->fd;
  12781. sd->npc_shopid = nd->bl.id;
  12782. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12783. WFIFOW(fd,0) = 0x287;
  12784. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12785. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12786. #if PACKETVER >= 20070711
  12787. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12788. #endif
  12789. for( i = 0; i < nd->u.shop.count; i++ ) {
  12790. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12791. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12792. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12793. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12794. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12795. }
  12796. WFIFOSET(fd,WFIFOW(fd,2));
  12797. }
  12798. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12799. /// 0289 <cash point>.L <error>.W
  12800. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12801. /// error:
  12802. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12803. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12804. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12805. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12806. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12807. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12808. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12809. /// 7 = You can purchase up to 10 items.
  12810. /// 8 = Some items could not be purchased.
  12811. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12812. {
  12813. int fd = sd->fd;
  12814. WFIFOHEAD(fd, packet_len(0x289));
  12815. WFIFOW(fd,0) = 0x289;
  12816. WFIFOL(fd,2) = sd->cashPoints;
  12817. #if PACKETVER < 20070711
  12818. WFIFOW(fd,6) = TOW(error);
  12819. #else
  12820. WFIFOL(fd,6) = sd->kafraPoints;
  12821. WFIFOW(fd,10) = TOW(error);
  12822. #endif
  12823. WFIFOSET(fd, packet_len(0x289));
  12824. }
  12825. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  12826. WFIFOHEAD( sd->fd, 16 );
  12827. WFIFOW( sd->fd, 0 ) = 0x849;
  12828. WFIFOL( sd->fd, 2 ) = item_id;
  12829. WFIFOW( sd->fd, 6 ) = result;
  12830. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12831. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12832. WFIFOSET( sd->fd, 16 );
  12833. }
  12834. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12835. /// 0288 <name id>.W <amount>.W
  12836. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12837. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12838. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (PACKETVER >= 20130000)
  12839. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  12840. struct s_packet_db* info;
  12841. int cmd = RFIFOW(fd,0);
  12842. nullpo_retv(sd);
  12843. info = &packet_db[sd->packet_ver][cmd];
  12844. if( sd->state.trading || !sd->npc_shopid ) {
  12845. clif_cashshop_ack(sd,1);
  12846. return;
  12847. } else {
  12848. #if PACKETVER < 20101116
  12849. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  12850. short amount = RFIFOW(fd,info->pos[1]);
  12851. int points = RFIFOL(fd,info->pos[2]);
  12852. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  12853. #else
  12854. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12855. int len = RFIFOW(fd,info->pos[0]);
  12856. int points = RFIFOL(fd,info->pos[1]);
  12857. int count = RFIFOW(fd,info->pos[2]);
  12858. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12859. if( len < 10 || len != 10 + count * s_itl) {
  12860. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12861. return;
  12862. }
  12863. if(cmd == 0x848) {
  12864. if (cashshop_buylist( sd, points, count, item_list))
  12865. clif_cashshop_ack(sd,0);
  12866. return;
  12867. } else {
  12868. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  12869. return;
  12870. }
  12871. #endif
  12872. }
  12873. }
  12874. /// Adoption System
  12875. ///
  12876. /// Adoption message (ZC_BABYMSG).
  12877. /// 0216 <msg>.L
  12878. /// msg:
  12879. /// 0 = "You cannot adopt more than 1 child."
  12880. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12881. /// 2 = "You cannot adopt a married person."
  12882. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12883. {
  12884. int fd = sd->fd;
  12885. WFIFOHEAD(fd,6);
  12886. WFIFOW(fd,0) = 0x216;
  12887. WFIFOL(fd,2) = type;
  12888. WFIFOSET(fd,6);
  12889. }
  12890. /// Adoption confirmation (ZC_REQ_BABY).
  12891. /// 01f6 <account id>.L <char id>.L <name>.B
  12892. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12893. {
  12894. int fd = sd->fd;
  12895. WFIFOHEAD(fd,34);
  12896. WFIFOW(fd,0) = 0x1f6;
  12897. WFIFOL(fd,2) = src->status.account_id;
  12898. WFIFOL(fd,6) = p_id;
  12899. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12900. WFIFOSET(fd,34);
  12901. }
  12902. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12903. /// 01f9 <account id>.L
  12904. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12905. {
  12906. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12907. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12908. if( pc_can_Adopt(sd, p_sd, tsd) )
  12909. {
  12910. tsd->adopt_invite = sd->status.account_id;
  12911. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12912. }
  12913. }
  12914. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12915. /// 01f7 <account id>.L <char id>.L <answer>.L
  12916. /// answer:
  12917. /// 0 = rejected
  12918. /// 1 = accepted
  12919. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12920. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12921. int p1_id = RFIFOL(fd,info->pos[0]);
  12922. int p2_id = RFIFOL(fd,info->pos[1]);
  12923. int result = RFIFOL(fd,info->pos[2]);
  12924. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12925. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12926. int pid = sd->adopt_invite;
  12927. sd->adopt_invite = 0;
  12928. if( p1_sd == NULL || p2_sd == NULL )
  12929. return; // Both players need to be online
  12930. if( pid != p1_sd->status.account_id )
  12931. return; // Incorrect values
  12932. if( result == 0 )
  12933. return; // Rejected
  12934. pc_adoption(p1_sd, p2_sd, sd);
  12935. }
  12936. /// Convex Mirror (ZC_BOSS_INFO).
  12937. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12938. /// infoType:
  12939. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12940. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12941. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12942. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12943. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12944. {
  12945. WFIFOHEAD(fd,70);
  12946. memset(WFIFOP(fd,0),0,70);
  12947. WFIFOW(fd,0) = 0x293;
  12948. if( md != NULL ) {
  12949. if( md->bl.prev != NULL ) { // Boss on This Map
  12950. if( flag ) {
  12951. WFIFOB(fd,2) = 1;
  12952. WFIFOL(fd,3) = md->bl.x;
  12953. WFIFOL(fd,7) = md->bl.y;
  12954. } else
  12955. WFIFOB(fd,2) = 2; // First Time
  12956. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12957. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12958. unsigned int seconds;
  12959. int hours, minutes;
  12960. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12961. hours = seconds / (60 * 60);
  12962. seconds = seconds - (60 * 60 * hours);
  12963. minutes = seconds / 60;
  12964. WFIFOB(fd,2) = 3;
  12965. WFIFOW(fd,11) = hours; // Hours
  12966. WFIFOW(fd,13) = minutes; // Minutes
  12967. }
  12968. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12969. }
  12970. WFIFOSET(fd,70);
  12971. }
  12972. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12973. /// 02d6 <account id>.L
  12974. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12975. {
  12976. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12977. struct map_session_data* tsd = map_id2sd(aid);
  12978. if (!tsd)
  12979. return;
  12980. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12981. clif_viewequip_ack(sd, tsd);
  12982. else
  12983. clif_msg(sd, VIEW_EQUIP_FAIL);
  12984. }
  12985. /// Request to change equip window tick (CZ_CONFIG).
  12986. /// 02d8 <type>.L <flag>.L
  12987. /// type:
  12988. /// 0 = open equip window
  12989. /// flag:
  12990. /// 0 = disabled
  12991. /// 1 = enabled
  12992. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12993. {
  12994. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12995. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12996. sd->status.show_equip = flag;
  12997. clif_equiptickack(sd, flag);
  12998. }
  12999. /// Request to change party invitation tick.
  13000. /// value:
  13001. /// 0 = disabled
  13002. /// 1 = enabled
  13003. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13004. {
  13005. bool flag = RFIFOB(fd,6) ? true : false;
  13006. sd->status.allow_party = flag;
  13007. clif_partytickack(sd, flag);
  13008. }
  13009. /// Questlog System [Kevin] [Inkfish]
  13010. ///
  13011. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13012. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13013. void clif_quest_send_list(struct map_session_data * sd)
  13014. {
  13015. int fd = sd->fd;
  13016. int i;
  13017. int len = sd->avail_quests*5+8;
  13018. WFIFOHEAD(fd,len);
  13019. WFIFOW(fd, 0) = 0x2b1;
  13020. WFIFOW(fd, 2) = len;
  13021. WFIFOL(fd, 4) = sd->avail_quests;
  13022. for( i = 0; i < sd->avail_quests; i++ ) {
  13023. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  13024. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  13025. }
  13026. WFIFOSET(fd, len);
  13027. }
  13028. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13029. /// 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
  13030. void clif_quest_send_mission(struct map_session_data * sd)
  13031. {
  13032. int fd = sd->fd;
  13033. int i, j;
  13034. int len = sd->avail_quests*104+8;
  13035. struct mob_db *mob;
  13036. WFIFOHEAD(fd, len);
  13037. WFIFOW(fd, 0) = 0x2b2;
  13038. WFIFOW(fd, 2) = len;
  13039. WFIFOL(fd, 4) = sd->avail_quests;
  13040. for( i = 0; i < sd->avail_quests; i++ ) {
  13041. struct quest_db *qi = quest_db(sd->quest_log[i].quest_id);
  13042. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13043. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13044. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13045. WFIFOW(fd, i*104+20) = qi->num_objectives;
  13046. for( j = 0 ; j < qi->num_objectives; j++ ) {
  13047. WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
  13048. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13049. mob = mob_db(qi->mob[j]);
  13050. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13051. }
  13052. }
  13053. WFIFOSET(fd, len);
  13054. }
  13055. /// Notification about a new quest (ZC_ADD_QUEST).
  13056. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13057. void clif_quest_add(struct map_session_data * sd, struct quest * qd)
  13058. {
  13059. int fd = sd->fd;
  13060. int i;
  13061. struct quest_db *qi = quest_db(qd->quest_id);
  13062. WFIFOHEAD(fd, packet_len(0x2b3));
  13063. WFIFOW(fd, 0) = 0x2b3;
  13064. WFIFOL(fd, 2) = qd->quest_id;
  13065. WFIFOB(fd, 6) = qd->state;
  13066. WFIFOB(fd, 7) = qi->time;
  13067. WFIFOL(fd, 11) = qd->time;
  13068. WFIFOW(fd, 15) = qi->num_objectives;
  13069. for( i = 0; i < qi->num_objectives; i++ ) {
  13070. struct mob_db *mob;
  13071. WFIFOL(fd, i*30+17) = qi->mob[i];
  13072. WFIFOW(fd, i*30+21) = qd->count[i];
  13073. mob = mob_db(qi->mob[i]);
  13074. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13075. }
  13076. WFIFOSET(fd, packet_len(0x2b3));
  13077. }
  13078. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13079. /// 02b4 <quest id>.L
  13080. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  13081. {
  13082. int fd = sd->fd;
  13083. WFIFOHEAD(fd, packet_len(0x2b4));
  13084. WFIFOW(fd, 0) = 0x2b4;
  13085. WFIFOL(fd, 2) = quest_id;
  13086. WFIFOSET(fd, packet_len(0x2b4));
  13087. }
  13088. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13089. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13090. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd)
  13091. {
  13092. int fd = sd->fd;
  13093. int i;
  13094. struct quest_db *qi = quest_db(qd->quest_id);
  13095. int len = qi->num_objectives * 12 + 6;
  13096. WFIFOHEAD(fd, len);
  13097. WFIFOW(fd, 0) = 0x2b5;
  13098. WFIFOW(fd, 2) = len;
  13099. WFIFOW(fd, 4) = qi->num_objectives;
  13100. for( i = 0; i < qi->num_objectives; i++ ) {
  13101. WFIFOL(fd, i*12+6) = qd->quest_id;
  13102. WFIFOL(fd, i*12+10) = qi->mob[i];
  13103. WFIFOW(fd, i*12+14) = qi->count[i];
  13104. WFIFOW(fd, i*12+16) = qd->count[i];
  13105. }
  13106. WFIFOSET(fd, len);
  13107. }
  13108. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13109. /// 02b6 <quest id>.L <active>.B
  13110. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  13111. {
  13112. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13113. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13114. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13115. }
  13116. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13117. /// 02b7 <quest id>.L <active>.B
  13118. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  13119. {
  13120. int fd = sd->fd;
  13121. WFIFOHEAD(fd, packet_len(0x2b7));
  13122. WFIFOW(fd, 0) = 0x2b7;
  13123. WFIFOL(fd, 2) = quest_id;
  13124. WFIFOB(fd, 6) = active;
  13125. WFIFOSET(fd, packet_len(0x2b7));
  13126. }
  13127. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13128. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13129. /// effect:
  13130. /// 0 = none
  13131. /// 1 = exclamation mark icon
  13132. /// 2 = question mark icon
  13133. /// type:
  13134. /// 0 = yellow
  13135. /// 1 = orange
  13136. /// 2 = green
  13137. /// 3 = purple
  13138. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13139. {
  13140. #if PACKETVER >= 20090218
  13141. int fd = sd->fd;
  13142. WFIFOHEAD(fd, packet_len(0x446));
  13143. WFIFOW(fd, 0) = 0x446;
  13144. WFIFOL(fd, 2) = bl->id;
  13145. WFIFOW(fd, 6) = bl->x;
  13146. WFIFOW(fd, 8) = bl->y;
  13147. WFIFOW(fd, 10) = state;
  13148. WFIFOW(fd, 12) = color;
  13149. WFIFOSET(fd, packet_len(0x446));
  13150. #endif
  13151. }
  13152. /// Mercenary System
  13153. ///
  13154. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13155. /// 02a2 <var id>.W <value>.L
  13156. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13157. {
  13158. struct mercenary_data *md;
  13159. struct status_data *status;
  13160. int fd;
  13161. if( sd == NULL || (md = sd->md) == NULL )
  13162. return;
  13163. fd = sd->fd;
  13164. status = &md->battle_status;
  13165. WFIFOHEAD(fd,packet_len(0x2a2));
  13166. WFIFOW(fd,0) = 0x2a2;
  13167. WFIFOW(fd,2) = type;
  13168. switch( type ) {
  13169. case SP_ATK1:
  13170. {
  13171. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13172. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13173. }
  13174. break;
  13175. case SP_MATK1:
  13176. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13177. break;
  13178. case SP_HIT:
  13179. WFIFOL(fd,4) = status->hit;
  13180. break;
  13181. case SP_CRITICAL:
  13182. WFIFOL(fd,4) = status->cri/10;
  13183. break;
  13184. case SP_DEF1:
  13185. WFIFOL(fd,4) = status->def;
  13186. break;
  13187. case SP_MDEF1:
  13188. WFIFOL(fd,4) = status->mdef;
  13189. break;
  13190. case SP_MERCFLEE:
  13191. WFIFOL(fd,4) = status->flee;
  13192. break;
  13193. case SP_ASPD:
  13194. WFIFOL(fd,4) = status->amotion;
  13195. break;
  13196. case SP_HP:
  13197. WFIFOL(fd,4) = status->hp;
  13198. break;
  13199. case SP_MAXHP:
  13200. WFIFOL(fd,4) = status->max_hp;
  13201. break;
  13202. case SP_SP:
  13203. WFIFOL(fd,4) = status->sp;
  13204. break;
  13205. case SP_MAXSP:
  13206. WFIFOL(fd,4) = status->max_sp;
  13207. break;
  13208. case SP_MERCKILLS:
  13209. WFIFOL(fd,4) = md->mercenary.kill_count;
  13210. break;
  13211. case SP_MERCFAITH:
  13212. WFIFOL(fd,4) = mercenary_get_faith(md);
  13213. break;
  13214. }
  13215. WFIFOSET(fd,packet_len(0x2a2));
  13216. }
  13217. /// Mercenary base status data (ZC_MER_INIT).
  13218. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13219. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13220. /// <calls>.L <kills>.L <atk range>.W
  13221. void clif_mercenary_info(struct map_session_data *sd)
  13222. {
  13223. int fd;
  13224. struct mercenary_data *md;
  13225. struct status_data *status;
  13226. int atk;
  13227. if( sd == NULL || (md = sd->md) == NULL )
  13228. return;
  13229. fd = sd->fd;
  13230. status = &md->battle_status;
  13231. WFIFOHEAD(fd,packet_len(0x29b));
  13232. WFIFOW(fd,0) = 0x29b;
  13233. WFIFOL(fd,2) = md->bl.id;
  13234. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13235. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13236. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13237. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13238. WFIFOW(fd,10) = status->hit;
  13239. WFIFOW(fd,12) = status->cri/10;
  13240. WFIFOW(fd,14) = status->def;
  13241. WFIFOW(fd,16) = status->mdef;
  13242. WFIFOW(fd,18) = status->flee;
  13243. WFIFOW(fd,20) = status->amotion;
  13244. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13245. WFIFOW(fd,46) = md->db->lv;
  13246. WFIFOL(fd,48) = status->hp;
  13247. WFIFOL(fd,52) = status->max_hp;
  13248. WFIFOL(fd,56) = status->sp;
  13249. WFIFOL(fd,60) = status->max_sp;
  13250. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13251. WFIFOW(fd,68) = mercenary_get_faith(md);
  13252. WFIFOL(fd,70) = mercenary_get_calls(md);
  13253. WFIFOL(fd,74) = md->mercenary.kill_count;
  13254. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13255. WFIFOSET(fd,packet_len(0x29b));
  13256. }
  13257. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13258. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13259. void clif_mercenary_skillblock(struct map_session_data *sd)
  13260. {
  13261. struct mercenary_data *md;
  13262. int fd, i, len = 4;
  13263. if( sd == NULL || (md = sd->md) == NULL )
  13264. return;
  13265. fd = sd->fd;
  13266. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13267. WFIFOW(fd,0) = 0x29d;
  13268. for( i = 0; i < MAX_MERCSKILL; i++ )
  13269. {
  13270. int id, j;
  13271. if( (id = md->db->skill[i].id) == 0 )
  13272. continue;
  13273. j = id - MC_SKILLBASE;
  13274. WFIFOW(fd,len) = id;
  13275. WFIFOL(fd,len+2) = skill_get_inf(id);
  13276. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13277. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13278. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13279. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13280. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13281. len += 37;
  13282. }
  13283. WFIFOW(fd,2) = len;
  13284. WFIFOSET(fd,len);
  13285. }
  13286. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13287. /// 029f <command>.B
  13288. /// 1 = mercenary information
  13289. /// 2 = delete
  13290. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13291. {
  13292. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13293. if( sd->md == NULL )
  13294. return;
  13295. if( option == 2 ) mercenary_delete(sd->md, 2);
  13296. }
  13297. /// Mercenary Message
  13298. /// message:
  13299. /// 0 = Mercenary soldier's duty hour is over.
  13300. /// 1 = Your mercenary soldier has been killed.
  13301. /// 2 = Your mercenary soldier has been fired.
  13302. /// 3 = Your mercenary soldier has ran away.
  13303. void clif_mercenary_message(struct map_session_data* sd, int message){
  13304. clif_msg(sd, MERC_MSG_BASE + message);
  13305. }
  13306. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13307. /// 0298 <name id>.W <seconds>.L
  13308. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13309. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13310. WFIFOHEAD(fd,packet_len(0x298));
  13311. WFIFOW(fd,0) = 0x298;
  13312. WFIFOW(fd,2) = nameid;
  13313. WFIFOL(fd,4) = seconds;
  13314. WFIFOSET(fd,packet_len(0x298));
  13315. }
  13316. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13317. /// 0299 <index>.W <name id>.W
  13318. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13319. { // '<ItemName>' item has been deleted from the Inventory
  13320. WFIFOHEAD(fd,packet_len(0x299));
  13321. WFIFOW(fd,0) = 0x299;
  13322. WFIFOW(fd,2) = index+2;
  13323. WFIFOW(fd,4) = nameid;
  13324. WFIFOSET(fd,packet_len(0x299));
  13325. }
  13326. /// Book Reading (ZC_READ_BOOK).
  13327. /// 0294 <book id>.L <page>.L
  13328. void clif_readbook(int fd, int book_id, int page)
  13329. {
  13330. WFIFOHEAD(fd,packet_len(0x294));
  13331. WFIFOW(fd,0) = 0x294;
  13332. WFIFOL(fd,2) = book_id;
  13333. WFIFOL(fd,6) = page;
  13334. WFIFOSET(fd,packet_len(0x294));
  13335. }
  13336. /// Battlegrounds
  13337. ///
  13338. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13339. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13340. void clif_bg_hp(struct map_session_data *sd)
  13341. {
  13342. unsigned char buf[34];
  13343. const int cmd = 0x2e0;
  13344. nullpo_retv(sd);
  13345. WBUFW(buf,0) = cmd;
  13346. WBUFL(buf,2) = sd->status.account_id;
  13347. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13348. if( sd->battle_status.max_hp > INT16_MAX )
  13349. { // To correctly display the %hp bar. [Skotlex]
  13350. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13351. WBUFW(buf,32) = 100;
  13352. }
  13353. else
  13354. {
  13355. WBUFW(buf,30) = sd->battle_status.hp;
  13356. WBUFW(buf,32) = sd->battle_status.max_hp;
  13357. }
  13358. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13359. }
  13360. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13361. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13362. void clif_bg_xy(struct map_session_data *sd)
  13363. {
  13364. unsigned char buf[36];
  13365. nullpo_retv(sd);
  13366. WBUFW(buf,0)=0x2df;
  13367. WBUFL(buf,2)=sd->status.account_id;
  13368. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13369. WBUFW(buf,30)=sd->status.class_;
  13370. WBUFW(buf,32)=sd->bl.x;
  13371. WBUFW(buf,34)=sd->bl.y;
  13372. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13373. }
  13374. void clif_bg_xy_remove(struct map_session_data *sd)
  13375. {
  13376. unsigned char buf[36];
  13377. nullpo_retv(sd);
  13378. WBUFW(buf,0)=0x2df;
  13379. WBUFL(buf,2)=sd->status.account_id;
  13380. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13381. WBUFW(buf,30)=0;
  13382. WBUFW(buf,32)=-1;
  13383. WBUFW(buf,34)=-1;
  13384. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13385. }
  13386. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13387. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13388. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13389. {
  13390. struct map_session_data *sd;
  13391. unsigned char *buf;
  13392. if( (sd = bg_getavailablesd(bg)) == NULL )
  13393. return;
  13394. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13395. WBUFW(buf,0) = 0x2dc;
  13396. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13397. WBUFL(buf,4) = src_id;
  13398. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13399. memcpy(WBUFP(buf,32), mes, len);
  13400. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13401. if( buf )
  13402. aFree(buf);
  13403. }
  13404. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13405. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13406. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13407. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13408. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13409. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13410. char *name, *message;
  13411. int namelen, messagelen;
  13412. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13413. return;
  13414. if( is_atcommand(fd, sd, message, 1) )
  13415. return;
  13416. if (sd->sc.cant.chat)
  13417. return; //no "chatting" while muted.
  13418. if( battle_config.min_chat_delay ) {
  13419. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13420. return;
  13421. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13422. }
  13423. if (battle_config.idletime_option&IDLE_CHAT)
  13424. sd->idletime = last_tick;
  13425. bg_send_message(sd, text, textlen);
  13426. }
  13427. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13428. /// 02de <camp A points>.W <camp B points>.W
  13429. void clif_bg_updatescore(int16 m)
  13430. {
  13431. struct block_list bl;
  13432. unsigned char buf[6];
  13433. bl.id = 0;
  13434. bl.type = BL_NUL;
  13435. bl.m = m;
  13436. WBUFW(buf,0) = 0x2de;
  13437. WBUFW(buf,2) = map[m].bgscore_lion;
  13438. WBUFW(buf,4) = map[m].bgscore_eagle;
  13439. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13440. }
  13441. void clif_bg_updatescore_single(struct map_session_data *sd)
  13442. {
  13443. int fd;
  13444. nullpo_retv(sd);
  13445. fd = sd->fd;
  13446. WFIFOHEAD(fd,packet_len(0x2de));
  13447. WFIFOW(fd,0) = 0x2de;
  13448. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13449. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13450. WFIFOSET(fd,packet_len(0x2de));
  13451. }
  13452. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13453. /// 02dd <account id>.L <name>.24B <camp>.W
  13454. void clif_sendbgemblem_area(struct map_session_data *sd)
  13455. {
  13456. unsigned char buf[33];
  13457. nullpo_retv(sd);
  13458. WBUFW(buf, 0) = 0x2dd;
  13459. WBUFL(buf,2) = sd->bl.id;
  13460. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13461. WBUFW(buf,30) = sd->bg_id;
  13462. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13463. }
  13464. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13465. {
  13466. nullpo_retv(sd);
  13467. WFIFOHEAD(fd,32);
  13468. WFIFOW(fd,0) = 0x2dd;
  13469. WFIFOL(fd,2) = sd->bl.id;
  13470. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13471. WFIFOW(fd,30) = sd->bg_id;
  13472. WFIFOSET(fd,packet_len(0x2dd));
  13473. }
  13474. /// Custom Fonts (ZC_NOTIFY_FONT).
  13475. /// 02ef <account_id>.L <font id>.W
  13476. void clif_font(struct map_session_data *sd)
  13477. {
  13478. #if PACKETVER >= 20080102
  13479. unsigned char buf[8];
  13480. nullpo_retv(sd);
  13481. WBUFW(buf,0) = 0x2ef;
  13482. WBUFL(buf,2) = sd->bl.id;
  13483. WBUFW(buf,6) = sd->status.font;
  13484. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13485. #endif
  13486. }
  13487. /*==========================================
  13488. * Notifies party members of instance change
  13489. *------------------------------------------*/
  13490. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13491. {
  13492. #if PACKETVER >= 20071128
  13493. unsigned char buf[65];
  13494. if(!sd) return;
  13495. WBUFW(buf,0) = 0x2cb;
  13496. memcpy( WBUFP(buf,2), name, 62 );
  13497. WBUFW(buf,63) = num;
  13498. if(flag) // A timer has changed or been added
  13499. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13500. else // No notification
  13501. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13502. #endif
  13503. return;
  13504. }
  13505. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13506. {
  13507. #if PACKETVER >= 20071128
  13508. unsigned char buf[4];
  13509. if(!sd) return;
  13510. WBUFW(buf,0) = 0x2cc;
  13511. WBUFW(buf,2) = num;
  13512. if(flag) // A timer has changed or been added
  13513. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13514. else // No notification
  13515. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13516. #endif
  13517. return;
  13518. }
  13519. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13520. {
  13521. #if PACKETVER >= 20071128
  13522. unsigned char buf[71];
  13523. if(!sd) return; //party_getavailablesd can return NULL
  13524. WBUFW(buf,0) = 0x2cd;
  13525. memcpy( WBUFP(buf,2), name, 62 );
  13526. WBUFL(buf,63) = limit1;
  13527. WBUFL(buf,67) = limit2;
  13528. if(flag) // A timer has changed or been added
  13529. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13530. else // No notification
  13531. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13532. #endif
  13533. return;
  13534. }
  13535. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13536. {
  13537. #if PACKETVER >= 20071128
  13538. unsigned char buf[10];
  13539. if(!sd) return;
  13540. WBUFW(buf,0) = 0x2ce;
  13541. WBUFL(buf,2) = type;
  13542. WBUFL(buf,6) = limit;
  13543. if(flag) // A timer has changed or been added
  13544. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13545. else // No notification
  13546. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13547. #endif
  13548. return;
  13549. }
  13550. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13551. /// 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
  13552. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13553. {
  13554. #if PACKETVER >= 20071002
  13555. unsigned char buf[22];
  13556. struct item_data* id = itemdb_search(item_data->nameid);
  13557. WBUFW(buf,0) = 0x2b8;
  13558. WBUFL(buf,2) = sd->status.account_id;
  13559. WBUFW(buf,6) = item_data->nameid;
  13560. WBUFB(buf,8) = item_data->identify;
  13561. WBUFB(buf,9) = item_data->attribute;
  13562. WBUFB(buf,10) = item_data->refine;
  13563. clif_addcards(WBUFP(buf,11), item_data);
  13564. WBUFW(buf,19) = id->equip; // equip location
  13565. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13566. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13567. #endif
  13568. }
  13569. /// Display gained exp (ZC_NOTIFY_EXP).
  13570. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13571. /// var id:
  13572. /// SP_BASEEXP, SP_JOBEXP
  13573. /// exp type:
  13574. /// 0 = normal exp gain/loss
  13575. /// 1 = quest exp gain/loss
  13576. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13577. {
  13578. int fd;
  13579. nullpo_retv(sd);
  13580. fd = sd->fd;
  13581. WFIFOHEAD(fd, packet_len(0x7f6));
  13582. WFIFOW(fd,0) = 0x7f6;
  13583. WFIFOL(fd,2) = sd->bl.id;
  13584. WFIFOL(fd,6) = exp;
  13585. WFIFOW(fd,10) = type;
  13586. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13587. WFIFOSET(fd,packet_len(0x7f6));
  13588. }
  13589. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13590. /// type:
  13591. /// 0 = Displays 'value' for 5 seconds.
  13592. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13593. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13594. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13595. /// value:
  13596. /// 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).
  13597. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13598. {
  13599. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13600. WFIFOW(sd->fd,0) = 0x1b1;
  13601. WFIFOB(sd->fd,2) = type;
  13602. WFIFOL(sd->fd,3) = value;
  13603. WFIFOSET(sd->fd, packet_len(0x1b1));
  13604. }
  13605. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13606. /// 021d <state>.L
  13607. /// state:
  13608. /// 0 = Full effects
  13609. /// 1 = Reduced effects
  13610. ///
  13611. /// NOTE: The state is used on Aegis for sending skill unit packet
  13612. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13613. /// whenever possible. Due to the way the decision check is
  13614. /// constructed, this state tracking was rendered useless,
  13615. /// as the only skill unit, that is sent with 0x1c9 is
  13616. /// Graffiti.
  13617. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13618. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13619. sd->state.lesseffect = ( isLess != 0 );
  13620. }
  13621. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13622. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13623. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13624. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13625. int type = RFIFOL(fd,info->pos[1]);
  13626. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13627. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13628. if( sd->state.trading || sd->npc_shopid )
  13629. return;
  13630. if( flag == 0 || n == 0) {
  13631. clif_menuskill_clear(sd);
  13632. return; // Canceled by player.
  13633. }
  13634. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13635. clif_menuskill_clear(sd);
  13636. return; // Prevent hacking.
  13637. }
  13638. switch( type ) {
  13639. case 0: // Change Material
  13640. skill_changematerial(sd,n,item_list);
  13641. break;
  13642. case 1: // Level 1: Pure to Rough
  13643. case 2: // Level 2: Rough to Pure
  13644. skill_elementalanalysis(sd,n,type,item_list);
  13645. break;
  13646. }
  13647. clif_menuskill_clear(sd);
  13648. return;
  13649. }
  13650. /*==========================================
  13651. * Elemental System
  13652. *==========================================*/
  13653. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13654. struct elemental_data *ed;
  13655. struct status_data *status;
  13656. int fd;
  13657. if( sd == NULL || (ed = sd->ed) == NULL )
  13658. return;
  13659. fd = sd->fd;
  13660. status = &ed->battle_status;
  13661. WFIFOHEAD(fd,8);
  13662. WFIFOW(fd,0) = 0x81e;
  13663. WFIFOW(fd,2) = type;
  13664. switch( type ) {
  13665. case SP_HP:
  13666. WFIFOL(fd,4) = status->hp;
  13667. break;
  13668. case SP_MAXHP:
  13669. WFIFOL(fd,4) = status->max_hp;
  13670. break;
  13671. case SP_SP:
  13672. WFIFOL(fd,4) = status->sp;
  13673. break;
  13674. case SP_MAXSP:
  13675. WFIFOL(fd,4) = status->max_sp;
  13676. break;
  13677. }
  13678. WFIFOSET(fd,8);
  13679. }
  13680. void clif_elemental_info(struct map_session_data *sd) {
  13681. int fd;
  13682. struct elemental_data *ed;
  13683. struct status_data *status;
  13684. if( sd == NULL || (ed = sd->ed) == NULL )
  13685. return;
  13686. fd = sd->fd;
  13687. status = &ed->battle_status;
  13688. WFIFOHEAD(fd,22);
  13689. WFIFOW(fd, 0) = 0x81d;
  13690. WFIFOL(fd, 2) = ed->bl.id;
  13691. WFIFOL(fd, 6) = status->hp;
  13692. WFIFOL(fd,10) = status->max_hp;
  13693. WFIFOL(fd,14) = status->sp;
  13694. WFIFOL(fd,18) = status->max_sp;
  13695. WFIFOSET(fd,22);
  13696. }
  13697. /// Buying Store System
  13698. ///
  13699. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13700. /// 0810 <slots>.B
  13701. void clif_buyingstore_open(struct map_session_data* sd)
  13702. {
  13703. int fd = sd->fd;
  13704. WFIFOHEAD(fd,packet_len(0x810));
  13705. WFIFOW(fd,0) = 0x810;
  13706. WFIFOB(fd,2) = sd->buyingstore.slots;
  13707. WFIFOSET(fd,packet_len(0x810));
  13708. }
  13709. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13710. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13711. /// result:
  13712. /// 0 = cancel
  13713. /// 1 = open
  13714. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13715. {
  13716. const unsigned int blocksize = 8;
  13717. uint8* itemlist;
  13718. char storename[MESSAGE_SIZE];
  13719. unsigned char result;
  13720. int zenylimit;
  13721. unsigned int count, packet_len;
  13722. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13723. packet_len = RFIFOW(fd,info->pos[0]);
  13724. // TODO: Make this check global for all variable length packets.
  13725. if( packet_len < 89 )
  13726. {// minimum packet length
  13727. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13728. return;
  13729. }
  13730. zenylimit = RFIFOL(fd,info->pos[1]);
  13731. result = RFIFOL(fd,info->pos[2]);
  13732. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13733. itemlist = RFIFOP(fd,info->pos[4]);
  13734. // so that buyingstore_create knows, how many elements it has access to
  13735. packet_len-= info->pos[4];
  13736. if( packet_len%blocksize )
  13737. {
  13738. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13739. return;
  13740. }
  13741. count = packet_len/blocksize;
  13742. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13743. }
  13744. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13745. /// 0812 <result>.W <total weight>.L
  13746. /// result:
  13747. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13748. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13749. /// 8 = "No sale (purchase) information available." (0x705)
  13750. /// ? = nothing
  13751. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13752. {
  13753. int fd = sd->fd;
  13754. WFIFOHEAD(fd,packet_len(0x812));
  13755. WFIFOW(fd,0) = 0x812;
  13756. WFIFOW(fd,2) = result;
  13757. WFIFOL(fd,4) = weight;
  13758. WFIFOSET(fd,packet_len(0x812));
  13759. }
  13760. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13761. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13762. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13763. {
  13764. int fd = sd->fd;
  13765. unsigned int i;
  13766. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13767. WFIFOW(fd,0) = 0x813;
  13768. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13769. WFIFOL(fd,4) = sd->bl.id;
  13770. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13771. for( i = 0; i < sd->buyingstore.slots; i++ )
  13772. {
  13773. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13774. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13775. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13776. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13777. }
  13778. WFIFOSET(fd,WFIFOW(fd,2));
  13779. }
  13780. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13781. /// 0814 <account id>.L <store name>.80B
  13782. void clif_buyingstore_entry(struct map_session_data* sd)
  13783. {
  13784. uint8 buf[86];
  13785. WBUFW(buf,0) = 0x814;
  13786. WBUFL(buf,2) = sd->bl.id;
  13787. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13788. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13789. }
  13790. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13791. {
  13792. int fd = sd->fd;
  13793. WFIFOHEAD(fd,packet_len(0x814));
  13794. WFIFOW(fd,0) = 0x814;
  13795. WFIFOL(fd,2) = pl_sd->bl.id;
  13796. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13797. WFIFOSET(fd,packet_len(0x814));
  13798. }
  13799. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13800. /// 0815
  13801. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13802. {
  13803. buyingstore_close(sd);
  13804. }
  13805. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13806. /// 0816 <account id>.L
  13807. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13808. {
  13809. uint8 buf[6];
  13810. WBUFW(buf,0) = 0x816;
  13811. WBUFL(buf,2) = sd->bl.id;
  13812. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13813. }
  13814. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13815. {
  13816. int fd = sd->fd;
  13817. WFIFOHEAD(fd,packet_len(0x816));
  13818. WFIFOW(fd,0) = 0x816;
  13819. WFIFOL(fd,2) = pl_sd->bl.id;
  13820. WFIFOSET(fd,packet_len(0x816));
  13821. }
  13822. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13823. /// 0817 <account id>.L
  13824. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13825. {
  13826. uint32 account_id;
  13827. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13828. buyingstore_open(sd, account_id);
  13829. }
  13830. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13831. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13832. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13833. {
  13834. int fd = sd->fd;
  13835. unsigned int i;
  13836. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13837. WFIFOW(fd,0) = 0x818;
  13838. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13839. WFIFOL(fd,4) = pl_sd->bl.id;
  13840. WFIFOL(fd,8) = pl_sd->buyer_id;
  13841. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13842. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13843. {
  13844. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13845. 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.
  13846. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  13847. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13848. }
  13849. WFIFOSET(fd,WFIFOW(fd,2));
  13850. }
  13851. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13852. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13853. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13854. {
  13855. const unsigned int blocksize = 6;
  13856. uint8* itemlist;
  13857. uint32 account_id;
  13858. unsigned int count, packet_len, buyer_id;
  13859. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13860. packet_len = RFIFOW(fd,info->pos[0]);
  13861. if( packet_len < 12 )
  13862. {// minimum packet length
  13863. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13864. return;
  13865. }
  13866. account_id = RFIFOL(fd,info->pos[1]);
  13867. buyer_id = RFIFOL(fd,info->pos[2]);
  13868. itemlist = RFIFOP(fd,info->pos[3]);
  13869. // so that buyingstore_trade knows, how many elements it has access to
  13870. packet_len-= info->pos[3];
  13871. if( packet_len%blocksize )
  13872. {
  13873. 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);
  13874. return;
  13875. }
  13876. count = packet_len/blocksize;
  13877. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13878. }
  13879. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13880. /// 081a <result>.W
  13881. /// result:
  13882. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13883. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13884. /// ? = nothing
  13885. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13886. {
  13887. int fd = sd->fd;
  13888. WFIFOHEAD(fd,packet_len(0x81a));
  13889. WFIFOW(fd,0) = 0x81a;
  13890. WFIFOW(fd,2) = result;
  13891. WFIFOSET(fd,packet_len(0x81a));
  13892. }
  13893. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13894. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13895. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13896. {
  13897. int fd = sd->fd;
  13898. WFIFOHEAD(fd,packet_len(0x81b));
  13899. WFIFOW(fd,0) = 0x81b;
  13900. WFIFOW(fd,2) = nameid;
  13901. WFIFOW(fd,4) = amount; // amount of nameid received
  13902. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13903. WFIFOSET(fd,packet_len(0x81b));
  13904. }
  13905. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13906. /// 081c <index>.W <amount>.W <price>.L
  13907. /// message:
  13908. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13909. ///
  13910. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13911. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13912. {
  13913. int fd = sd->fd;
  13914. WFIFOHEAD(fd,packet_len(0x81c));
  13915. WFIFOW(fd,0) = 0x81c;
  13916. WFIFOW(fd,2) = index+2;
  13917. WFIFOW(fd,4) = amount;
  13918. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13919. WFIFOSET(fd,packet_len(0x81c));
  13920. }
  13921. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13922. /// 0824 <result>.W <name id>.W
  13923. /// result:
  13924. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13925. /// 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)
  13926. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13927. /// ? = nothing
  13928. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13929. {
  13930. int fd = sd->fd;
  13931. WFIFOHEAD(fd,packet_len(0x824));
  13932. WFIFOW(fd,0) = 0x824;
  13933. WFIFOW(fd,2) = result;
  13934. WFIFOW(fd,4) = nameid;
  13935. WFIFOSET(fd,packet_len(0x824));
  13936. }
  13937. /// Search Store Info System
  13938. ///
  13939. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13940. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13941. /// type:
  13942. /// 0 = Vending
  13943. /// 1 = Buying Store
  13944. ///
  13945. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13946. /// amount of card slots. If the client does not know about the item it
  13947. /// cannot be searched.
  13948. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13949. {
  13950. const unsigned int blocksize = 2;
  13951. const uint8* itemlist;
  13952. const uint8* cardlist;
  13953. unsigned char type;
  13954. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13955. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13956. packet_len = RFIFOW(fd,info->pos[0]);
  13957. if( packet_len < 15 )
  13958. {// minimum packet length
  13959. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13960. return;
  13961. }
  13962. type = RFIFOB(fd,info->pos[1]);
  13963. max_price = RFIFOL(fd,info->pos[2]);
  13964. min_price = RFIFOL(fd,info->pos[3]);
  13965. item_count = RFIFOB(fd,info->pos[4]);
  13966. card_count = RFIFOB(fd,info->pos[5]);
  13967. itemlist = RFIFOP(fd,info->pos[6]);
  13968. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13969. // check, if there is enough data for the claimed count of items
  13970. packet_len-= info->pos[6];
  13971. if( packet_len%blocksize )
  13972. {
  13973. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13974. return;
  13975. }
  13976. count = packet_len/blocksize;
  13977. if( count < item_count+card_count )
  13978. {
  13979. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13980. return;
  13981. }
  13982. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13983. }
  13984. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13985. /// 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 }*
  13986. /// is first page:
  13987. /// 0 = appends to existing results
  13988. /// 1 = clears previous results before displaying this result set
  13989. /// is next page:
  13990. /// 0 = no "next" label
  13991. /// 1 = "next" label to retrieve more results
  13992. void clif_search_store_info_ack(struct map_session_data* sd)
  13993. {
  13994. const unsigned int blocksize = MESSAGE_SIZE+26;
  13995. int fd = sd->fd;
  13996. unsigned int i, start, end;
  13997. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13998. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13999. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14000. WFIFOW(fd,0) = 0x836;
  14001. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14002. WFIFOB(fd,4) = !sd->searchstore.pages;
  14003. WFIFOB(fd,5) = searchstore_querynext(sd);
  14004. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14005. for( i = start; i < end; i++ ) {
  14006. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14007. struct item it;
  14008. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14009. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14010. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14011. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14012. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14013. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14014. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14015. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14016. // make-up an item for clif_addcards
  14017. memset(&it, 0, sizeof(it));
  14018. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14019. it.nameid = ssitem->nameid;
  14020. it.amount = ssitem->amount;
  14021. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14022. }
  14023. WFIFOSET(fd,WFIFOW(fd,2));
  14024. }
  14025. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14026. /// 0837 <reason>.B
  14027. /// reason:
  14028. /// 0 = "No matching stores were found." (0x70b)
  14029. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14030. /// 2 = "You cannot search anymore." (0x706)
  14031. /// 3 = "You cannot search yet." (0x708)
  14032. /// 4 = "No sale (purchase) information available." (0x705)
  14033. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14034. {
  14035. int fd = sd->fd;
  14036. WFIFOHEAD(fd,packet_len(0x837));
  14037. WFIFOW(fd,0) = 0x837;
  14038. WFIFOB(fd,2) = reason;
  14039. WFIFOSET(fd,packet_len(0x837));
  14040. }
  14041. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14042. /// 0838
  14043. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14044. {
  14045. searchstore_next(sd);
  14046. }
  14047. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14048. /// 083a <type>.W <remaining uses>.B
  14049. /// type:
  14050. /// 0 = Search Stores
  14051. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14052. void clif_open_search_store_info(struct map_session_data* sd)
  14053. {
  14054. int fd = sd->fd;
  14055. WFIFOHEAD(fd,packet_len(0x83a));
  14056. WFIFOW(fd,0) = 0x83a;
  14057. WFIFOW(fd,2) = sd->searchstore.effect;
  14058. #if PACKETVER > 20100701
  14059. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14060. #endif
  14061. WFIFOSET(fd,packet_len(0x83a));
  14062. }
  14063. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14064. /// 083b
  14065. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14066. {
  14067. searchstore_close(sd);
  14068. }
  14069. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14070. /// 083c <account id>.L <store id>.L <nameid>.W
  14071. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14072. {
  14073. unsigned short nameid;
  14074. uint32 account_id, store_id;
  14075. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14076. account_id = RFIFOL(fd,info->pos[0]);
  14077. store_id = RFIFOL(fd,info->pos[1]);
  14078. nameid = RFIFOW(fd,info->pos[2]);
  14079. searchstore_click(sd, account_id, store_id, nameid);
  14080. }
  14081. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14082. /// 083d <xPos>.W <yPos>.W
  14083. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14084. {
  14085. int fd = sd->fd;
  14086. WFIFOHEAD(fd,packet_len(0x83d));
  14087. WFIFOW(fd,0) = 0x83d;
  14088. WFIFOW(fd,2) = x;
  14089. WFIFOW(fd,4) = y;
  14090. WFIFOSET(fd,packet_len(0x83d));
  14091. }
  14092. /// Parse function for packet debugging.
  14093. void clif_parse_debug(int fd,struct map_session_data *sd)
  14094. {
  14095. int cmd, packet_len;
  14096. // clif_parse ensures, that there is at least 2 bytes of data
  14097. cmd = RFIFOW(fd,0);
  14098. if( sd ) {
  14099. packet_len = packet_db[sd->packet_ver][cmd].len;
  14100. if( packet_len == 0 )
  14101. {// unknown
  14102. packet_len = RFIFOREST(fd);
  14103. }
  14104. else if( packet_len == -1 )
  14105. {// variable length
  14106. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14107. }
  14108. 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);
  14109. }
  14110. else
  14111. {
  14112. packet_len = RFIFOREST(fd);
  14113. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14114. }
  14115. ShowDump(RFIFOP(fd,0), packet_len);
  14116. }
  14117. /*==========================================
  14118. * Server tells client to display a window similar to Magnifier (item) one
  14119. * Server populates the window with avilable elemental converter options according to player's inventory
  14120. *------------------------------------------*/
  14121. int clif_elementalconverter_list(struct map_session_data *sd) {
  14122. int i,c,view,fd;
  14123. nullpo_ret(sd);
  14124. /// Main client packet processing function
  14125. fd=sd->fd;
  14126. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14127. WFIFOW(fd, 0)=0x1ad;
  14128. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14129. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14130. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14131. WFIFOW(fd,c*2+ 4)= view;
  14132. else
  14133. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14134. c++;
  14135. }
  14136. }
  14137. WFIFOW(fd,2) = c*2+4;
  14138. WFIFOSET(fd, WFIFOW(fd,2));
  14139. if (c > 0) {
  14140. sd->menuskill_id = SA_CREATECON;
  14141. sd->menuskill_val = c;
  14142. }
  14143. return 0;
  14144. }
  14145. /**
  14146. * Rune Knight
  14147. **/
  14148. void clif_millenniumshield(struct block_list *bl, short shields) {
  14149. #if PACKETVER >= 20081217
  14150. unsigned char buf[10];
  14151. WBUFW(buf,0) = 0x440;
  14152. WBUFL(buf,2) = bl->id;
  14153. WBUFW(buf,6) = shields;
  14154. WBUFW(buf,8) = 0;
  14155. clif_send(buf,packet_len(0x440),bl,AREA);
  14156. #endif
  14157. }
  14158. /**
  14159. * Warlock
  14160. **/
  14161. /*==========================================
  14162. * Spellbook list [LimitLine/3CeAM]
  14163. *------------------------------------------*/
  14164. int clif_spellbook_list(struct map_session_data *sd)
  14165. {
  14166. int i, c;
  14167. int fd;
  14168. nullpo_ret(sd);
  14169. fd = sd->fd;
  14170. WFIFOHEAD(fd, 8 * 8 + 8);
  14171. WFIFOW(fd,0) = 0x1ad;
  14172. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14173. {
  14174. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14175. {
  14176. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14177. c++;
  14178. }
  14179. }
  14180. if( c > 0 )
  14181. {
  14182. WFIFOW(fd,2) = c * 2 + 4;
  14183. WFIFOSET(fd, WFIFOW(fd, 2));
  14184. sd->menuskill_id = WL_READING_SB;
  14185. sd->menuskill_val = c;
  14186. }
  14187. else{
  14188. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14189. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14190. }
  14191. return 1;
  14192. }
  14193. /**
  14194. * Mechanic
  14195. **/
  14196. /*==========================================
  14197. * Magic Decoy Material List
  14198. *------------------------------------------*/
  14199. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14200. int i, c;
  14201. int fd;
  14202. nullpo_ret(sd);
  14203. fd = sd->fd;
  14204. WFIFOHEAD(fd, 8 * 8 + 8);
  14205. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14206. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14207. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14208. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14209. c ++;
  14210. }
  14211. }
  14212. if( c > 0 ) {
  14213. sd->menuskill_id = NC_MAGICDECOY;
  14214. sd->menuskill_val = skill_lv;
  14215. sd->sc.comet_x = x;
  14216. sd->sc.comet_y = y;
  14217. WFIFOW(fd,2) = c * 2 + 4;
  14218. WFIFOSET(fd, WFIFOW(fd, 2));
  14219. } else {
  14220. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14221. return 0;
  14222. }
  14223. return 1;
  14224. }
  14225. /*==========================================
  14226. * Guillotine Cross Poisons List
  14227. *------------------------------------------*/
  14228. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14229. int i, c;
  14230. int fd;
  14231. nullpo_ret(sd);
  14232. fd = sd->fd;
  14233. WFIFOHEAD(fd, 8 * 8 + 8);
  14234. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14235. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14236. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14237. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14238. c ++;
  14239. }
  14240. }
  14241. if( c > 0 ) {
  14242. sd->menuskill_id = GC_POISONINGWEAPON;
  14243. sd->menuskill_val = skill_lv;
  14244. WFIFOW(fd,2) = c * 2 + 4;
  14245. WFIFOSET(fd, WFIFOW(fd, 2));
  14246. } else {
  14247. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14248. return 0;
  14249. }
  14250. return 1;
  14251. }
  14252. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14253. int fd, i, c;
  14254. nullpo_ret(sd);
  14255. fd = sd->fd;
  14256. if( !fd ) return 0;
  14257. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14258. return 0;
  14259. WFIFOHEAD(fd, 2 * 6 + 4);
  14260. WFIFOW(fd,0) = 0x442;
  14261. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14262. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14263. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14264. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14265. {
  14266. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14267. c++;
  14268. }
  14269. if( c > 0 ) {
  14270. WFIFOW(fd,2) = 8 + c * 2;
  14271. WFIFOL(fd,4) = c;
  14272. WFIFOSET(fd,WFIFOW(fd,2));
  14273. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14274. sd->menuskill_val = c;
  14275. } else {
  14276. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14277. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14278. }
  14279. return 1;
  14280. }
  14281. /*===========================================
  14282. * Skill list for Four Elemental Analysis
  14283. * and Change Material skills.
  14284. *------------------------------------------*/
  14285. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14286. {
  14287. #if PACKETVER >= 20090922
  14288. int fd;
  14289. nullpo_ret(sd);
  14290. sd->menuskill_id = skill_id; // To prevent hacking.
  14291. sd->menuskill_val = skill_lv;
  14292. if( skill_id == GN_CHANGEMATERIAL )
  14293. skill_lv = 0; // Changematerial
  14294. fd = sd->fd;
  14295. WFIFOHEAD(fd,packet_len(0x7e3));
  14296. WFIFOW(fd,0) = 0x7e3;
  14297. WFIFOL(fd,2) = skill_lv;
  14298. WFIFOL(fd,4) = 0;
  14299. WFIFOSET(fd,packet_len(0x7e3));
  14300. #endif
  14301. return 1;
  14302. }
  14303. // msgstringtable.txt
  14304. // 0x291 <line>.W
  14305. void clif_msgtable(int fd, int line) {
  14306. WFIFOHEAD(fd, packet_len(0x291));
  14307. WFIFOW(fd, 0) = 0x291;
  14308. WFIFOW(fd, 2) = line;
  14309. WFIFOSET(fd, packet_len(0x291));
  14310. }
  14311. // msgstringtable.txt
  14312. // 0x7e2 <line>.W <value>.L
  14313. void clif_msgtable_num(int fd, int line, int num) {
  14314. #if PACKETVER >= 20090805
  14315. WFIFOHEAD(fd, packet_len(0x7e2));
  14316. WFIFOW(fd, 0) = 0x7e2;
  14317. WFIFOW(fd, 2) = line;
  14318. WFIFOL(fd, 4) = num;
  14319. WFIFOSET(fd, packet_len(0x7e2));
  14320. #endif
  14321. }
  14322. /*==========================================
  14323. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14324. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14325. * RFIFOL(fd,2) - type (currently not used)
  14326. *------------------------------------------*/
  14327. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14328. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14329. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14330. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14331. return;
  14332. if( pc_istrading(sd) ) {
  14333. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14334. clif_menuskill_clear(sd);
  14335. return;
  14336. }
  14337. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14338. clif_menuskill_clear(sd);
  14339. }
  14340. /*==========================================
  14341. * Kagerou/Oboro amulet spirit
  14342. *------------------------------------------*/
  14343. void clif_talisman(struct map_session_data *sd,short type)
  14344. {
  14345. unsigned char buf[10];
  14346. nullpo_retv(sd);
  14347. WBUFW(buf,0)=0x08cf;
  14348. WBUFL(buf,2)=sd->bl.id;
  14349. WBUFW(buf,6)=type;
  14350. WBUFW(buf,8)=sd->talisman[type];
  14351. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14352. }
  14353. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14354. /// 0907 <index>.W
  14355. ///
  14356. /// R 0908 <index>.w <type>.b
  14357. /// type:
  14358. /// 0 = move item to personal tab
  14359. /// 1 = move item to normal tab
  14360. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14361. #if PACKETVER >= 20111122
  14362. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14363. int index = RFIFOW(fd,info->pos[0])-2;
  14364. int type = RFIFOB(fd, info->pos[1]);
  14365. /* can't move while dead. */
  14366. if(pc_isdead(sd)) {
  14367. return;
  14368. }
  14369. if (index < 0 || index >= MAX_INVENTORY)
  14370. return;
  14371. if ( sd->status.inventory[index].favorite && type == 1 )
  14372. sd->status.inventory[index].favorite = 0;
  14373. else if( type == 0 )
  14374. sd->status.inventory[index].favorite = 1;
  14375. else
  14376. return;/* nothing to do. */
  14377. clif_favorite_item(sd, index);
  14378. #endif
  14379. }
  14380. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14381. /// 0900 <index>.W <favorite>.B
  14382. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14383. int fd = sd->fd;
  14384. WFIFOHEAD(fd,packet_len(0x908));
  14385. WFIFOW(fd,0) = 0x908;
  14386. WFIFOW(fd,2) = index+2;
  14387. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14388. WFIFOSET(fd,packet_len(0x908));
  14389. }
  14390. void clif_snap( struct block_list *bl, short x, short y ) {
  14391. unsigned char buf[10];
  14392. WBUFW(buf,0) = 0x8d2;
  14393. WBUFL(buf,2) = bl->id;
  14394. WBUFW(buf,6) = x;
  14395. WBUFW(buf,8) = y;
  14396. if( disguised(bl) )
  14397. {
  14398. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14399. WBUFL(buf,2) = -bl->id;
  14400. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14401. } else
  14402. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14403. }
  14404. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14405. #if PACKETVER >= 20120404
  14406. WFIFOHEAD(fd,packet_len(0x977));
  14407. WFIFOW(fd,0) = 0x977;
  14408. WFIFOL(fd,2) = md->bl.id;
  14409. WFIFOL(fd,6) = md->status.hp;
  14410. WFIFOL(fd,10) = md->status.max_hp;
  14411. WFIFOSET(fd,packet_len(0x977));
  14412. #endif
  14413. }
  14414. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14415. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14416. return;
  14417. }
  14418. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14419. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14420. WFIFOW(sd->fd,0) = 0x2c9;
  14421. WFIFOB(sd->fd,2) = flag;
  14422. WFIFOSET(sd->fd, packet_len(0x2c9));
  14423. }
  14424. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14425. /// 0979 <world name>.24B <char name>.24B
  14426. void clif_ackworldinfo(struct map_session_data* sd) {
  14427. int fd;
  14428. nullpo_retv(sd);
  14429. fd = sd->fd;
  14430. WFIFOHEAD(fd,packet_len(0x979));
  14431. WFIFOW(fd,0)=0x979;
  14432. //AID -> world name ?
  14433. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14434. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14435. WFIFOSET(fd,packet_len(0x979));
  14436. }
  14437. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14438. /// 0978 <AID>.L
  14439. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14440. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14441. if(sd) clif_ackworldinfo(sd);
  14442. }
  14443. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14444. /// 0447
  14445. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14446. //if(sd)
  14447. ;
  14448. }
  14449. /// req world info (CZ_CLIENT_VERSION)
  14450. /// 044A <version>.L
  14451. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14452. //if(sd)
  14453. ;
  14454. }
  14455. /// Ranking list
  14456. /// ranking pointlist { <name>.24B <point>.L }*10
  14457. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14458. struct fame_list* list;
  14459. int skip = 0;
  14460. switch(rankingtype+1) { //to keep the same case as char.c
  14461. case 1: list = smith_fame_list; break;
  14462. case 2: list = chemist_fame_list; break;
  14463. case 3: list = taekwon_fame_list; break;
  14464. default: skip=1; break;
  14465. }
  14466. if(!skip) {
  14467. int i;
  14468. //Packet size limits this list to 10 elements. [Skotlex]
  14469. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14470. if (list[i].id > 0) {
  14471. const char* name;
  14472. if (strcmp(list[i].name, "-") == 0 &&
  14473. (name = map_charid2nick(list[i].id)) != NULL)
  14474. {
  14475. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14476. } else {
  14477. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14478. }
  14479. } else {
  14480. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14481. }
  14482. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14483. }
  14484. for(;i < 10; i++) { //In case the MAX is less than 10.
  14485. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14486. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14487. }
  14488. }
  14489. }
  14490. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14491. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14492. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14493. int mypoint = 0;
  14494. WBUFW(buf,0) = 0x97d;
  14495. WBUFW(buf,2) = rankingType;
  14496. clif_sub_ranklist(buf,4,sd,rankingType);
  14497. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14498. case MAPID_BLACKSMITH:
  14499. case MAPID_ALCHEMIST:
  14500. case MAPID_TAEKWON:
  14501. mypoint = sd->status.fame;
  14502. }
  14503. WBUFL(buf,284) = mypoint; //mypoint
  14504. clif_send(buf, 288, &sd->bl, SELF);
  14505. }
  14506. /*
  14507. * 097c <type> (CZ_REQ_RANKING)
  14508. * type
  14509. * 0: /blacksmith
  14510. * 1: /alchemist
  14511. * 2: /taekwon
  14512. * 3: /pk
  14513. * */
  14514. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14515. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14516. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14517. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14518. }
  14519. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14520. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14521. #if PACKETVER < 20130710
  14522. switch(rankingtype){
  14523. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14524. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14525. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14526. }
  14527. #else
  14528. int fd=sd->fd;
  14529. WFIFOHEAD(fd,14);
  14530. WFIFOW(fd,0) = 0x97e;
  14531. WFIFOW(fd,2) = rankingtype;
  14532. WFIFOL(fd,4) = point;
  14533. WFIFOL(fd,8) = sd->status.fame;
  14534. WFIFOSET(fd,12);
  14535. #endif
  14536. }
  14537. /**
  14538. * Transmit personal information to player. (rates)
  14539. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14540. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14541. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14542. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14543. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14544. * FIXME!
  14545. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14546. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14547. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14548. */
  14549. #ifdef VIP_ENABLE
  14550. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14551. if (sd) {
  14552. struct s_packet_db* info;
  14553. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14554. int cmd = 0, fd, i = 0;
  14555. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14556. int details_bexp[PINFO_MAX];
  14557. int details_drop[PINFO_MAX];
  14558. int details_penalty[PINFO_MAX];
  14559. int penalty_const;
  14560. /**
  14561. * Set for EXP
  14562. */
  14563. //0:PCRoom
  14564. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14565. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14566. details_bexp[0] = 0;
  14567. else {
  14568. if (details_bexp[0] < 100) {
  14569. details_bexp[0] = 100 - details_bexp[0];
  14570. details_bexp[0] = 0 - details_bexp[0];
  14571. }
  14572. else
  14573. details_bexp[0] = details_bexp[0] - 100;
  14574. }
  14575. //1:Premium
  14576. if (pc_isvip(sd)) {
  14577. details_bexp[1] = battle_config.vip_base_exp_increase;
  14578. if (details_bexp[1] < 0)
  14579. details_bexp[1] = 0 - details_bexp[1];
  14580. }
  14581. else
  14582. details_bexp[1] = 0;
  14583. //2:Server
  14584. details_bexp[2] = battle_config.base_exp_rate;
  14585. if (details_bexp[2] == 100)
  14586. details_bexp[2] = 0;
  14587. else {
  14588. if (details_bexp[2] < 100) {
  14589. details_bexp[2] = 100 - details_bexp[2];
  14590. details_bexp[2] = 0 - details_bexp[2];
  14591. }
  14592. else
  14593. details_bexp[2] = details_bexp[2] - 100;
  14594. }
  14595. //3:TPLUS
  14596. details_bexp[3] = 0;
  14597. /* End - EXP set*/
  14598. /**
  14599. * Set for Drop rate
  14600. */
  14601. //0:PCRoom
  14602. details_drop[0] = 0;
  14603. //1:Premium
  14604. details_drop[1] = battle_config.vip_drop_increase;
  14605. if (pc_isvip(sd)) {
  14606. if (details_drop[1] < 0)
  14607. details_drop[1] = 0 - details_drop[1];
  14608. }
  14609. else
  14610. details_drop[1] = 0;
  14611. //2:Server
  14612. details_drop[2] = battle_config.item_rate_common;
  14613. if (details_drop[2] == 100)
  14614. details_drop[2] = 0;
  14615. else {
  14616. if (details_drop[2] < 100) {
  14617. details_drop[2] = 100 - details_drop[2];
  14618. details_drop[2] = 0 - details_drop[2];
  14619. }
  14620. else
  14621. details_drop[2] = details_drop[2] - 100;
  14622. }
  14623. //3:TPLUS
  14624. details_drop[3] = 0;
  14625. /* End - Drop set*/
  14626. /**
  14627. * Set for Penalty rate
  14628. */
  14629. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14630. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14631. //0:PCRoom
  14632. details_penalty[0] = 0;
  14633. //1:Premium
  14634. if (pc_isvip(sd)) {
  14635. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14636. if (details_penalty[1] == 100)
  14637. details_penalty[1] = 0;
  14638. else {
  14639. if (details_penalty[1] < 100) {
  14640. details_penalty[1] = 100 - details_penalty[1];
  14641. details_penalty[1] = 0 - details_penalty[1];
  14642. }
  14643. else
  14644. details_penalty[1] = details_penalty[1] - 100;
  14645. }
  14646. }
  14647. else
  14648. details_penalty[1] = 0;
  14649. //2:Server
  14650. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14651. if (details_penalty[2] == 100)
  14652. details_penalty[2] = 0;
  14653. else {
  14654. if (details_penalty[2] < 100) {
  14655. details_penalty[2] = 100 - details_penalty[2];
  14656. details_penalty[2] = 0 - details_penalty[2];
  14657. }
  14658. else
  14659. details_penalty[2] = details_penalty[2] - 100;
  14660. }
  14661. //3:TPLUS
  14662. details_penalty[3] = 0;
  14663. /* End - Penalty set*/
  14664. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14665. info = &packet_db[sd->packet_ver][cmd];
  14666. len = info->len; //this is the base len without details
  14667. if(!len) return; //version as packet disable
  14668. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14669. szdetails = 7;
  14670. factor = 1;
  14671. }
  14672. else if (cmd == 0x097b) {
  14673. tot_baseexp *= factor;
  14674. tot_drop *= factor;
  14675. tot_penalty *= factor;
  14676. }
  14677. fd = sd->fd;
  14678. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14679. WFIFOW(fd,0) = cmd;
  14680. for (i = 0; i < maxinfotype; i++) {
  14681. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14682. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14683. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14684. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14685. tot_baseexp += details_bexp[i]*factor;
  14686. tot_drop += details_penalty[i]*factor;
  14687. tot_penalty += details_drop[i]*factor;
  14688. len += szdetails;
  14689. }
  14690. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14691. if (cmd == 0x08cb) { //0x08cb version
  14692. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14693. WFIFOW(fd,info->pos[2]) = tot_drop;
  14694. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14695. }
  14696. else { //2013-08-07aRagexe uses 0x097b
  14697. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14698. WFIFOL(fd,info->pos[2]) = tot_drop;
  14699. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14700. }
  14701. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14702. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14703. WFIFOSET(fd,len);
  14704. }
  14705. }
  14706. #endif
  14707. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14708. char cmd[30];
  14709. int t_aid = RFIFOL(fd,2);
  14710. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14711. is_atcommand(fd, sd, cmd, 1);
  14712. }
  14713. /**
  14714. * Marks Crimson Marker target on mini-map to the caster
  14715. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  14716. * @param fd
  14717. * @param bl Crimson Marker target
  14718. **/
  14719. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  14720. struct s_packet_db* info;
  14721. int cmd = 0;
  14722. int16 len;
  14723. unsigned char buf[11];
  14724. nullpo_retv(sd);
  14725. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  14726. if (!cmd)
  14727. cmd = 0x09C1; //default
  14728. info = &packet_db[sd->packet_ver][cmd];
  14729. if (!(len = info->len))
  14730. return;
  14731. WBUFW(buf, 0) = cmd;
  14732. WBUFL(buf, info->pos[0]) = bl->id;
  14733. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  14734. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  14735. clif_send(buf, len, &sd->bl, SELF);
  14736. }
  14737. /**
  14738. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  14739. **/
  14740. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  14741. struct s_packet_db *info = NULL;
  14742. int cmd = 0;
  14743. nullpo_retv(sd);
  14744. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  14745. info = &packet_db[sd->packet_ver][cmd];
  14746. if (!cmd || !info->len)
  14747. return;
  14748. WFIFOHEAD(sd->fd, info->len);
  14749. WFIFOW(sd->fd, 0) = cmd;
  14750. WFIFOW(sd->fd, info->pos[0]) = n+2;
  14751. WFIFOSET(sd->fd, info->len);
  14752. }
  14753. /// [Ind/Hercules]
  14754. void clif_showscript(struct block_list* bl, const char* message) {
  14755. char buf[256];
  14756. size_t len;
  14757. nullpo_retv(bl);
  14758. if(!message)
  14759. return;
  14760. len = strlen(message)+1;
  14761. if( len > sizeof(buf)-8 ) {
  14762. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  14763. len = sizeof(buf)-8;
  14764. }
  14765. WBUFW(buf,0) = 0x8b3;
  14766. WBUFW(buf,2) = (len+8);
  14767. WBUFL(buf,4) = bl->id;
  14768. safestrncpy((char *) WBUFP(buf,8), message, len);
  14769. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  14770. }
  14771. /// [Ind/Hercules]
  14772. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  14773. unsigned char buf[10];
  14774. nullpo_retv(sd);
  14775. WBUFW(buf,0) = 0x7fc;
  14776. WBUFL(buf,2) = prev_leader_aid;
  14777. WBUFL(buf,6) = new_leader_aid;
  14778. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  14779. }
  14780. /**
  14781. * !TODO: Special item that obtained, must be broadcasted by this packet
  14782. * 07fd ?? (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  14783. */
  14784. //void clif_broadcast_obtain_special_item() {}
  14785. #ifdef DUMP_UNKNOWN_PACKET
  14786. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  14787. {
  14788. const char* packet_txt = "save/packet.txt";
  14789. FILE* fp;
  14790. time_t time_server;
  14791. struct tm *datetime;
  14792. char datestr[512];
  14793. time(&time_server); // get time in seconds since 1/1/1970
  14794. datetime = localtime(&time_server); // convert seconds in structure
  14795. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14796. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14797. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14798. if( sd ) {
  14799. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s \n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14800. } else {
  14801. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14802. }
  14803. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14804. fprintf(fp, "\n");
  14805. fclose(fp);
  14806. } else {
  14807. ShowError("Failed to write '%s'.\n", packet_txt);
  14808. // Dump on console instead
  14809. if( sd ) {
  14810. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14811. } else {
  14812. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14813. }
  14814. ShowDump(RFIFOP(fd,0), packet_len);
  14815. }
  14816. }
  14817. #endif
  14818. /*==========================================
  14819. * Main client packet processing function
  14820. *------------------------------------------*/
  14821. static int clif_parse(int fd)
  14822. {
  14823. int cmd, packet_ver, packet_len, err;
  14824. TBL_PC* sd;
  14825. int pnum;
  14826. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14827. // Note: "click masters" can do 80+ clicks in 10 seconds
  14828. 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]
  14829. { // begin main client packet processing loop
  14830. sd = (TBL_PC *)session[fd]->session_data;
  14831. if (session[fd]->flag.eof) {
  14832. if (sd) {
  14833. if (sd->state.autotrade) {
  14834. //Disassociate character from the socket connection.
  14835. session[fd]->session_data = NULL;
  14836. sd->fd = 0;
  14837. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14838. } else
  14839. if (sd->state.active) {
  14840. // Player logout display [Valaris]
  14841. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14842. clif_quitsave(fd, sd);
  14843. } else {
  14844. //Unusual logout (during log on/off/map-changer procedure)
  14845. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14846. map_quit(sd);
  14847. }
  14848. } else {
  14849. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14850. }
  14851. do_close(fd);
  14852. return 0;
  14853. }
  14854. if (RFIFOREST(fd) < 2)
  14855. return 0;
  14856. cmd = RFIFOW(fd,0);
  14857. // identify client's packet version
  14858. if (sd) {
  14859. packet_ver = sd->packet_ver;
  14860. } else {
  14861. // check authentification packet to know packet version
  14862. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14863. if( err ) {// failed to identify packet version
  14864. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14865. err == 1 ? "" :
  14866. err == 2 ? ", possibly for having an invalid account_id" :
  14867. err == 3 ? ", possibly for having an invalid char_id." :
  14868. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14869. err == 4 ? ", possibly for having an invalid login_id1." :
  14870. err == 5 ? ", possibly for having an invalid client_tick." :
  14871. */
  14872. err == 6 ? ", possibly for having an invalid sex." :
  14873. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14874. WFIFOHEAD(fd,packet_len(0x6a));
  14875. WFIFOW(fd,0) = 0x6a;
  14876. WFIFOB(fd,2) = 3; // Rejected from Server
  14877. WFIFOSET(fd,packet_len(0x6a));
  14878. #ifdef DUMP_INVALID_PACKET
  14879. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14880. #endif
  14881. RFIFOSKIP(fd, RFIFOREST(fd));
  14882. set_eof(fd);
  14883. return 0;
  14884. }
  14885. }
  14886. // filter out invalid / unsupported packets
  14887. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14888. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14889. #ifdef DUMP_INVALID_PACKET
  14890. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14891. #endif
  14892. set_eof(fd);
  14893. return 0;
  14894. }
  14895. // determine real packet length
  14896. packet_len = packet_db[packet_ver][cmd].len;
  14897. if (packet_len == -1) { // variable-length packet
  14898. if (RFIFOREST(fd) < 4)
  14899. return 0;
  14900. packet_len = RFIFOW(fd,2);
  14901. if (packet_len < 4 || packet_len > 32768) {
  14902. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14903. #ifdef DUMP_INVALID_PACKET
  14904. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14905. #endif
  14906. set_eof(fd);
  14907. return 0;
  14908. }
  14909. }
  14910. if ((int)RFIFOREST(fd) < packet_len)
  14911. return 0; // not enough data received to form the packet
  14912. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14913. packet_db[packet_ver][cmd].func(fd, sd);
  14914. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14915. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14916. ; //Only valid packet when there is no session
  14917. else
  14918. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14919. ; //Only valid packet when player is not on a map
  14920. else
  14921. packet_db[packet_ver][cmd].func(fd, sd);
  14922. }
  14923. #ifdef DUMP_UNKNOWN_PACKET
  14924. else DumpUnknown(fd,sd,cmd,packet_len);
  14925. #endif
  14926. RFIFOSKIP(fd, packet_len);
  14927. }; // main loop end
  14928. return 0;
  14929. }
  14930. /*==========================================
  14931. * Reads packet_db.txt and setups its array reference
  14932. *------------------------------------------*/
  14933. void packetdb_readdb(void)
  14934. {
  14935. char line[1024];
  14936. int cmd,i,j;
  14937. int max_cmd=-1;
  14938. bool skip_ver = false;
  14939. int warned = 0;
  14940. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14941. int packet_len_table[MAX_PACKET_DB] = {
  14942. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14946. //#0x0040
  14947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14949. #if PACKETVER <= 20081217
  14950. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14951. #else
  14952. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14953. #endif
  14954. #if PACKETVER < 2
  14955. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14956. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14957. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14958. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14959. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14960. #else
  14961. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14962. #endif
  14963. //#0x0080
  14964. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14965. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14966. #if PACKETVER <= 20100622
  14967. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14968. #else
  14969. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14970. #endif
  14971. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14972. //#0x00C0
  14973. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14974. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14975. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14976. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14977. //#0x0100
  14978. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14979. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14980. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14981. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14982. //#0x0140
  14983. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14984. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14985. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14986. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14987. //#0x0180
  14988. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14989. #if PACKETVER < 1
  14990. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14991. #else // 196 comodo icon status display for later
  14992. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14993. #endif
  14994. #if PACKETVER < 20081126
  14995. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14996. #else // 0x1a2 changed (35->37)
  14997. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14998. #endif
  14999. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  15000. //#0x01C0, Set 0x1d5=-1
  15001. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  15002. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  15003. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  15004. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  15005. //#0x0200
  15006. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  15007. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  15008. #if PACKETVER < 20071106
  15009. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  15010. #else // 0x22c changed
  15011. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  15012. #endif
  15013. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  15014. //#0x0240
  15015. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  15016. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  15017. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15018. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15019. //#0x0280
  15020. #if PACKETVER < 20070711
  15021. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  15022. #else
  15023. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  15024. #endif
  15025. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  15026. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15027. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  15028. //#0x02C0
  15029. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  15030. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  15031. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  15032. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15033. //#0x0300
  15034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15038. //#0x0340
  15039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15043. //#0x0380
  15044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15048. //#0x03C0
  15049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15053. //#0x0400
  15054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  15058. //#0x0440
  15059. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  15060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15063. //#0x0480
  15064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15068. //#0x04C0
  15069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15073. //#0x0500
  15074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15078. //#0x0540
  15079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15083. //#0x0580
  15084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15088. //#0x05C0
  15089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15093. //#0x0600
  15094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15098. //#0x0640
  15099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15103. //#0x0680
  15104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15108. //#0x06C0
  15109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15113. //#0x0700
  15114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15118. //#0x0740
  15119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15123. //#0x0780
  15124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15128. //#0x07C0
  15129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15130. #if PACKETVER < 20090617
  15131. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15132. #else // 0x7d9 changed
  15133. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15134. #endif
  15135. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15136. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  15137. //#0x0800
  15138. #if PACKETVER < 20091229
  15139. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15140. #else // for Party booking ( PACKETVER >= 20091229 )
  15141. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15142. #endif
  15143. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15144. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15145. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15146. //#0x0840
  15147. #if PACKETVER < 20130000
  15148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15149. #else
  15150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15151. #endif
  15152. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  15153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15155. //#0x0880
  15156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15159. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15160. //#0x08C0
  15161. 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10,
  15162. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15165. //#0x0900
  15166. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15170. //#0x0940
  15171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15174. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15175. //#0x0980
  15176. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15177. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  15178. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15179. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15180. //#0x09C0
  15181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  15182. 0, 0, 0, 0, 2, 0, -1, 0, 2, 0, 0, 0, 0, 0, 0, 7,
  15183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15185. };
  15186. struct {
  15187. void (*func)(int, struct map_session_data *);
  15188. char *name;
  15189. } clif_parse_func[]={
  15190. {clif_parse_WantToConnection,"wanttoconnection"},
  15191. {clif_parse_LoadEndAck,"loadendack"},
  15192. {clif_parse_TickSend,"ticksend"},
  15193. {clif_parse_WalkToXY,"walktoxy"},
  15194. {clif_parse_QuitGame,"quitgame"},
  15195. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15196. {clif_parse_GlobalMessage,"globalmessage"},
  15197. {clif_parse_MapMove,"mapmove"},
  15198. {clif_parse_ChangeDir,"changedir"},
  15199. {clif_parse_Emotion,"emotion"},
  15200. {clif_parse_HowManyConnections,"howmanyconnections"},
  15201. {clif_parse_ActionRequest,"actionrequest"},
  15202. {clif_parse_Restart,"restart"},
  15203. {clif_parse_WisMessage,"wis"},
  15204. {clif_parse_Broadcast,"broadcast"},
  15205. {clif_parse_TakeItem,"takeitem"},
  15206. {clif_parse_DropItem,"dropitem"},
  15207. {clif_parse_UseItem,"useitem"},
  15208. {clif_parse_EquipItem,"equipitem"},
  15209. {clif_parse_UnequipItem,"unequipitem"},
  15210. {clif_parse_NpcClicked,"npcclicked"},
  15211. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15212. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15213. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15214. {clif_parse_CreateChatRoom,"createchatroom"},
  15215. {clif_parse_ChatAddMember,"chataddmember"},
  15216. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15217. {clif_parse_ChangeChatOwner,"changechatowner"},
  15218. {clif_parse_KickFromChat,"kickfromchat"},
  15219. {clif_parse_ChatLeave,"chatleave"},
  15220. {clif_parse_TradeRequest,"traderequest"},
  15221. {clif_parse_TradeAck,"tradeack"},
  15222. {clif_parse_TradeAddItem,"tradeadditem"},
  15223. {clif_parse_TradeOk,"tradeok"},
  15224. {clif_parse_TradeCancel,"tradecancel"},
  15225. {clif_parse_TradeCommit,"tradecommit"},
  15226. {clif_parse_StopAttack,"stopattack"},
  15227. {clif_parse_PutItemToCart,"putitemtocart"},
  15228. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15229. {clif_parse_RemoveOption,"removeoption"},
  15230. {clif_parse_ChangeCart,"changecart"},
  15231. {clif_parse_StatusUp,"statusup"},
  15232. {clif_parse_SkillUp,"skillup"},
  15233. {clif_parse_UseSkillToId,"useskilltoid"},
  15234. {clif_parse_UseSkillToPos,"useskilltopos"},
  15235. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15236. {clif_parse_UseSkillMap,"useskillmap"},
  15237. {clif_parse_RequestMemo,"requestmemo"},
  15238. {clif_parse_ProduceMix,"producemix"},
  15239. {clif_parse_Cooking,"cooking"},
  15240. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15241. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15242. {clif_parse_NpcAmountInput,"npcamountinput"},
  15243. {clif_parse_NpcStringInput,"npcstringinput"},
  15244. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15245. {clif_parse_ItemIdentify,"itemidentify"},
  15246. {clif_parse_SelectArrow,"selectarrow"},
  15247. {clif_parse_AutoSpell,"autospell"},
  15248. {clif_parse_UseCard,"usecard"},
  15249. {clif_parse_InsertCard,"insertcard"},
  15250. {clif_parse_RepairItem,"repairitem"},
  15251. {clif_parse_WeaponRefine,"weaponrefine"},
  15252. {clif_parse_SolveCharName,"solvecharname"},
  15253. {clif_parse_ResetChar,"resetchar"},
  15254. {clif_parse_LocalBroadcast,"localbroadcast"},
  15255. {clif_parse_MoveToKafra,"movetokafra"},
  15256. {clif_parse_MoveFromKafra,"movefromkafra"},
  15257. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15258. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15259. {clif_parse_CloseKafra,"closekafra"},
  15260. {clif_parse_CreateParty,"createparty"},
  15261. {clif_parse_CreateParty2,"createparty2"},
  15262. {clif_parse_PartyInvite,"partyinvite"},
  15263. {clif_parse_PartyInvite2,"partyinvite2"},
  15264. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15265. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15266. {clif_parse_LeaveParty,"leaveparty"},
  15267. {clif_parse_RemovePartyMember,"removepartymember"},
  15268. {clif_parse_PartyChangeOption,"partychangeoption"},
  15269. {clif_parse_PartyMessage,"partymessage"},
  15270. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15271. {clif_parse_CloseVending,"closevending"},
  15272. {clif_parse_VendingListReq,"vendinglistreq"},
  15273. {clif_parse_PurchaseReq,"purchasereq"},
  15274. {clif_parse_PurchaseReq2,"purchasereq2"},
  15275. {clif_parse_OpenVending,"openvending"},
  15276. {clif_parse_CreateGuild,"createguild"},
  15277. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15278. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15279. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15280. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15281. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15282. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15283. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15284. {clif_parse_GuildInvite,"guildinvite"},
  15285. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15286. {clif_parse_GuildLeave,"guildleave"},
  15287. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15288. {clif_parse_GuildMessage,"guildmessage"},
  15289. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15290. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15291. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15292. {clif_parse_GuildOpposition,"guildopposition"},
  15293. {clif_parse_GuildBreak,"guildbreak"},
  15294. {clif_parse_PetMenu,"petmenu"},
  15295. {clif_parse_CatchPet,"catchpet"},
  15296. {clif_parse_SelectEgg,"selectegg"},
  15297. {clif_parse_SendEmotion,"sendemotion"},
  15298. {clif_parse_ChangePetName,"changepetname"},
  15299. {clif_parse_GMKick,"gmkick"},
  15300. {clif_parse_GMHide,"gmhide"},
  15301. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15302. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15303. {clif_parse_GMKickAll,"killall"},
  15304. {clif_parse_GMRecall,"recall"},
  15305. {clif_parse_GMRecall,"summon"},
  15306. {clif_parse_GM_Item_Monster,"itemmonster"},
  15307. {clif_parse_GMShift,"remove"},
  15308. {clif_parse_GMShift,"shift"},
  15309. {clif_parse_GMChangeMapType,"changemaptype"},
  15310. {clif_parse_GMRc,"rc"},
  15311. {clif_parse_GMRecall2,"recall2"},
  15312. {clif_parse_GMRemove2,"remove2"},
  15313. {clif_parse_GMFullStrip,"gmfullstrip"},
  15314. {clif_parse_NoviceDoriDori,"sndoridori"},
  15315. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15316. {clif_parse_PMIgnore,"wisexin"},
  15317. {clif_parse_PMIgnoreList,"wisexlist"},
  15318. {clif_parse_PMIgnoreAll,"wisall"},
  15319. {clif_parse_FriendsListAdd,"friendslistadd"},
  15320. {clif_parse_FriendsListRemove,"friendslistremove"},
  15321. {clif_parse_FriendsListReply,"friendslistreply"},
  15322. {clif_parse_Blacksmith,"blacksmith"},
  15323. {clif_parse_Alchemist,"alchemist"},
  15324. {clif_parse_Taekwon,"taekwon"},
  15325. {clif_parse_RankingPk,"rankingpk"},
  15326. {clif_parse_FeelSaveOk,"feelsaveok"},
  15327. {clif_parse_debug,"debug"},
  15328. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15329. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15330. {clif_parse_HomMoveTo,"hommoveto"},
  15331. {clif_parse_HomAttack,"homattack"},
  15332. {clif_parse_HomMenu,"hommenu"},
  15333. {clif_parse_StoragePassword,"storagepassword"},
  15334. {clif_parse_Hotkey,"hotkey"},
  15335. {clif_parse_AutoRevive,"autorevive"},
  15336. {clif_parse_Check,"check"},
  15337. {clif_parse_Adopt_request,"adoptrequest"},
  15338. {clif_parse_Adopt_reply,"adoptreply"},
  15339. // MAIL SYSTEM
  15340. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15341. {clif_parse_Mail_read,"mailread"},
  15342. {clif_parse_Mail_getattach,"mailgetattach"},
  15343. {clif_parse_Mail_delete,"maildelete"},
  15344. {clif_parse_Mail_return,"mailreturn"},
  15345. {clif_parse_Mail_setattach,"mailsetattach"},
  15346. {clif_parse_Mail_winopen,"mailwinopen"},
  15347. {clif_parse_Mail_send,"mailsend"},
  15348. // AUCTION SYSTEM
  15349. {clif_parse_Auction_search,"auctionsearch"},
  15350. {clif_parse_Auction_buysell,"auctionbuysell"},
  15351. {clif_parse_Auction_setitem,"auctionsetitem"},
  15352. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15353. {clif_parse_Auction_register,"auctionregister"},
  15354. {clif_parse_Auction_cancel,"auctioncancel"},
  15355. {clif_parse_Auction_close,"auctionclose"},
  15356. {clif_parse_Auction_bid,"auctionbid"},
  15357. // Quest Log System
  15358. {clif_parse_questStateAck,"queststate"},
  15359. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15360. {clif_parse_EquipTick,"equiptickbox"},
  15361. {clif_parse_BattleChat,"battlechat"},
  15362. {clif_parse_mercenary_action,"mermenu"},
  15363. {clif_parse_progressbar,"progressbar"},
  15364. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15365. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15366. #if PACKETVER >= 20091229
  15367. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15368. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15369. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15370. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15371. #endif
  15372. {clif_parse_BankCheck,"bankcheck"},
  15373. {clif_parse_BankDeposit,"bankdeposit"},
  15374. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15375. {clif_parse_BankOpen,"bankopen"},
  15376. {clif_parse_BankClose,"bankclose"},
  15377. {clif_parse_PVPInfo,"pvpinfo"},
  15378. {clif_parse_LessEffect,"lesseffect"},
  15379. // Buying Store
  15380. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15381. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15382. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15383. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15384. // Store Search
  15385. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15386. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15387. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15388. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15389. // Cashshop
  15390. { clif_parse_cashshop_open_request, "cashshopopen" },
  15391. { clif_parse_cashshop_close, "cashshopclose" },
  15392. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15393. { clif_parse_cashshop_buy, "cashshopbuy" },
  15394. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15395. /* */
  15396. { clif_parse_MoveItem , "moveitem" },
  15397. { clif_parse_PartyTick, "partytick" },
  15398. { clif_parse_dull, "dull" },
  15399. { clif_parse_GuildInvite2 , "guildinvite2" },
  15400. { clif_parse_reqworldinfo, "reqworldinfo"},
  15401. { clif_parse_client_version, "clientversion"},
  15402. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15403. { clif_parse_ranklist, "ranklist"},
  15404. {NULL,NULL}
  15405. };
  15406. struct {
  15407. char *name; //function name
  15408. int funcidx; //
  15409. } clif_ack_func[]={ //hash
  15410. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15411. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15412. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15413. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15414. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15415. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15416. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15417. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15418. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  15419. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  15420. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  15421. };
  15422. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15423. int f;
  15424. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15425. memset(packet_db,0,sizeof(packet_db));
  15426. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15427. packet_len(i) = packet_len_table[i];
  15428. clif_config.packet_db_ver = MAX_PACKET_VER;
  15429. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  15430. FILE *fp;
  15431. int ln = 0;
  15432. int entries = 0;
  15433. char *str[64], *p, *str2[64], *p2;
  15434. sprintf(line, "%s/%s", db_path, filename[f]);
  15435. if( (fp = fopen(line,"r")) == NULL ) {
  15436. if (f == 0) {
  15437. ShowFatalError("Can't read %s\n", line);
  15438. exit(EXIT_FAILURE);
  15439. }
  15440. return;
  15441. }
  15442. while( fgets(line, sizeof(line), fp) ) {
  15443. char w1[256],w2[256];
  15444. ln++;
  15445. if(line[0]=='/' && line[1]=='/')
  15446. continue;
  15447. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  15448. if (strcmpi(w1,"packet_ver") == 0) {
  15449. int prev_ver = packet_ver;
  15450. skip_ver = false;
  15451. packet_ver = atoi(w2);
  15452. if ( packet_ver > MAX_PACKET_VER )
  15453. { //Check to avoid overflowing. [Skotlex]
  15454. if( (warned&1) == 0 )
  15455. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15456. warned &= 1;
  15457. skip_ver = true;
  15458. }
  15459. else if( packet_ver < 0 )
  15460. {
  15461. if( (warned&2) == 0 )
  15462. ShowWarning("Negative packet versions are not supported.\n");
  15463. warned &= 2;
  15464. skip_ver = true;
  15465. }
  15466. else if( packet_ver == SERVER )
  15467. {
  15468. if( (warned&4) == 0 )
  15469. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15470. warned &= 4;
  15471. skip_ver = true;
  15472. }
  15473. if( skip_ver )
  15474. {
  15475. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15476. packet_ver = prev_ver;
  15477. continue;
  15478. }
  15479. // copy from previous version into new version and continue
  15480. // - indicating all following packets should be read into the newer version
  15481. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15482. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15483. continue;
  15484. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15485. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  15486. clif_config.packet_db_ver = MAX_PACKET_VER;
  15487. else // to manually set the packet DB version
  15488. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15489. continue;
  15490. }
  15491. }
  15492. if( skip_ver )
  15493. continue; // Skipping current packet version
  15494. memset(str,0,sizeof(str));
  15495. for (j = 0, p = line; j < 4 && p; ++j) {
  15496. str[j] = p;
  15497. p = strchr(p,',');
  15498. if (p)
  15499. *p++=0;
  15500. }
  15501. if (str[0] == NULL)
  15502. continue;
  15503. cmd = strtol(str[0],(char **)NULL,0);
  15504. if(max_cmd < cmd)
  15505. max_cmd = cmd;
  15506. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15507. continue;
  15508. if(str[1]==NULL){
  15509. ShowError("packet_db: packet len error\n");
  15510. continue;
  15511. }
  15512. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15513. if(str[2]==NULL){
  15514. packet_db[packet_ver][cmd].func = NULL;
  15515. ln++;
  15516. continue;
  15517. }
  15518. // look up processing function by name
  15519. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15520. if( j < ARRAYLENGTH(clif_parse_func) )
  15521. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15522. else { //search if it's a mapped ack func
  15523. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15524. if( j < ARRAYLENGTH(clif_ack_func)) {
  15525. int fidx = clif_ack_func[j].funcidx;
  15526. packet_db_ack[packet_ver][fidx] = cmd;
  15527. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15528. }
  15529. }
  15530. // set the identifying cmd for the packet_db version
  15531. if (strcmp(str[2],"wanttoconnection")==0)
  15532. clif_config.connect_cmd[packet_ver] = cmd;
  15533. if(str[3]==NULL){
  15534. ShowError("packet_db: packet error\n");
  15535. exit(EXIT_FAILURE);
  15536. }
  15537. for(j = 0, p2 = str[3]; p2; j++){
  15538. short k;
  15539. str2[j] = p2;
  15540. p2 = strchr(p2,':');
  15541. if(p2)
  15542. *p2++=0;
  15543. k = atoi(str2[j]);
  15544. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15545. if( j >= MAX_PACKET_POS )
  15546. {
  15547. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15548. break;
  15549. }
  15550. packet_db[packet_ver][cmd].pos[j] = k;
  15551. }
  15552. entries++;
  15553. }
  15554. fclose(fp);
  15555. if(max_cmd > MAX_PACKET_DB) {
  15556. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15557. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15558. }
  15559. //Locate the nearest version that we still support. [Skotlex]
  15560. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  15561. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15562. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15563. }
  15564. sprintf(line, "%s/%s", db_path,filename[f]);
  15565. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  15566. }
  15567. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15568. }
  15569. /*==========================================
  15570. *
  15571. *------------------------------------------*/
  15572. void do_init_clif(void) {
  15573. const char* colors[COLOR_MAX] = {
  15574. "0xFF0000",
  15575. "0xFFFFFF",
  15576. "0xFFFF00",
  15577. };
  15578. int i;
  15579. /**
  15580. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15581. **/
  15582. for(i = 0; i < COLOR_MAX; i++) {
  15583. color_table[i] = strtoul(colors[i],NULL,0);
  15584. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15585. }
  15586. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15587. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15588. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15589. packetdb_readdb();
  15590. set_defaultparse(clif_parse);
  15591. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15592. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15593. exit(EXIT_FAILURE);
  15594. }
  15595. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15596. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15597. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15598. }
  15599. void do_final_clif(void) {
  15600. ers_destroy(delay_clearunit_ers);
  15601. }