clif.c 523 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298
  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 : 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 : 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 : 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,int ok)
  3013. {
  3014. int fd,header,offs=0,success;
  3015. #if PACKETVER < 20110824
  3016. header = 0xaa;
  3017. success = (ok==1);
  3018. #elif PACKETVER < 20120925
  3019. header = 0x8d0;
  3020. success = ok ? 0:1;
  3021. #else
  3022. header = 0x999;
  3023. success = ok ? 0:1;
  3024. #endif
  3025. nullpo_retv(sd);
  3026. fd=sd->fd;
  3027. WFIFOHEAD(fd,packet_len(header));
  3028. WFIFOW(fd,offs+0)=header;
  3029. WFIFOW(fd,offs+2)=n+2;
  3030. #if PACKETVER >= 20120925
  3031. WFIFOL(fd,offs+4)=pos;
  3032. offs+=2;
  3033. #else
  3034. WFIFOW(fd,offs+4)=(int)pos;
  3035. #endif
  3036. #if PACKETVER < 20100629
  3037. WFIFOB(fd,offs+6)=success;
  3038. #else
  3039. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3040. WFIFOW(fd,offs+6)=sd->inventory_data[n]->look;
  3041. else
  3042. WFIFOW(fd,offs+6)=0;
  3043. WFIFOB(fd,offs+8)=success;
  3044. #endif
  3045. WFIFOSET(fd,packet_len(header));
  3046. }
  3047. /// Notifies the client about the result of a request to take off an item.
  3048. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3049. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3050. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3051. /// @ok : //inversed for v2 v5
  3052. /// 0 = failure
  3053. /// 1 = success
  3054. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3055. {
  3056. int fd,header,offs=0;
  3057. #if PACKETVER >= 20130000
  3058. header = 0x99a;
  3059. ok = ok ? 0:1;
  3060. #elif PACKETVER >= 20110824
  3061. header = 0x8d1;
  3062. ok = ok ? 0:1;
  3063. #else
  3064. header = 0xac;
  3065. #endif
  3066. nullpo_retv(sd);
  3067. fd=sd->fd;
  3068. WFIFOHEAD(fd,packet_len(header));
  3069. WFIFOW(fd,offs+0)=header;
  3070. WFIFOW(fd,offs+2)=n+2;
  3071. #if PACKETVER >= 20130000
  3072. WFIFOL(fd,offs+4)=pos;
  3073. offs +=2;
  3074. #else
  3075. WFIFOW(fd,offs+4)=pos;
  3076. #endif
  3077. WFIFOB(fd,offs+6)=ok;
  3078. WFIFOSET(fd,packet_len(header));
  3079. }
  3080. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3081. /// 019b <id>.L <effect id>.L
  3082. /// effect id:
  3083. /// 0 = base level up
  3084. /// 1 = job level up
  3085. /// 2 = refine failure
  3086. /// 3 = refine success
  3087. /// 4 = game over
  3088. /// 5 = pharmacy success
  3089. /// 6 = pharmacy failure
  3090. /// 7 = base level up (super novice)
  3091. /// 8 = job level up (super novice)
  3092. /// 9 = base level up (taekwon)
  3093. void clif_misceffect(struct block_list* bl,int type)
  3094. {
  3095. unsigned char buf[32];
  3096. nullpo_retv(bl);
  3097. WBUFW(buf,0) = 0x19b;
  3098. WBUFL(buf,2) = bl->id;
  3099. WBUFL(buf,6) = type;
  3100. clif_send(buf,packet_len(0x19b),bl,AREA);
  3101. }
  3102. /// Notifies clients in the area of a state change.
  3103. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3104. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3105. void clif_changeoption(struct block_list* bl)
  3106. {
  3107. unsigned char buf[32];
  3108. struct status_change *sc;
  3109. struct map_session_data* sd;
  3110. nullpo_retv(bl);
  3111. sc = status_get_sc(bl);
  3112. if (!sc) return; //How can an option change if there's no sc?
  3113. sd = BL_CAST(BL_PC, bl);
  3114. #if PACKETVER >= 7
  3115. WBUFW(buf,0) = 0x229;
  3116. WBUFL(buf,2) = bl->id;
  3117. WBUFW(buf,6) = sc->opt1;
  3118. WBUFW(buf,8) = sc->opt2;
  3119. WBUFL(buf,10) = sc->option;
  3120. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3121. if(disguised(bl)) {
  3122. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3123. WBUFL(buf,2) = -bl->id;
  3124. clif_send(buf,packet_len(0x229),bl,SELF);
  3125. WBUFL(buf,2) = bl->id;
  3126. WBUFL(buf,10) = OPTION_INVISIBLE;
  3127. clif_send(buf,packet_len(0x229),bl,SELF);
  3128. } else
  3129. clif_send(buf,packet_len(0x229),bl,AREA);
  3130. #else
  3131. WBUFW(buf,0) = 0x119;
  3132. WBUFL(buf,2) = bl->id;
  3133. WBUFW(buf,6) = sc->opt1;
  3134. WBUFW(buf,8) = sc->opt2;
  3135. WBUFW(buf,10) = sc->option;
  3136. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3137. if(disguised(bl)) {
  3138. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3139. WBUFL(buf,2) = -bl->id;
  3140. clif_send(buf,packet_len(0x119),bl,SELF);
  3141. WBUFL(buf,2) = bl->id;
  3142. WBUFW(buf,10) = OPTION_INVISIBLE;
  3143. clif_send(buf,packet_len(0x119),bl,SELF);
  3144. } else
  3145. clif_send(buf,packet_len(0x119),bl,AREA);
  3146. #endif
  3147. }
  3148. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3149. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3150. void clif_changeoption2(struct block_list* bl)
  3151. {
  3152. unsigned char buf[20];
  3153. struct status_change *sc;
  3154. sc = status_get_sc(bl);
  3155. if (!sc) return; //How can an option change if there's no sc?
  3156. WBUFW(buf,0) = 0x28a;
  3157. WBUFL(buf,2) = bl->id;
  3158. WBUFL(buf,6) = sc->option;
  3159. WBUFL(buf,10) = clif_setlevel(bl);
  3160. WBUFL(buf,14) = sc->opt3;
  3161. if(disguised(bl)) {
  3162. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3163. WBUFL(buf,2) = -bl->id;
  3164. clif_send(buf,packet_len(0x28a),bl,SELF);
  3165. WBUFL(buf,2) = bl->id;
  3166. WBUFL(buf,6) = OPTION_INVISIBLE;
  3167. clif_send(buf,packet_len(0x28a),bl,SELF);
  3168. } else
  3169. clif_send(buf,packet_len(0x28a),bl,AREA);
  3170. }
  3171. /// Notifies the client about the result of an item use request.
  3172. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3173. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3174. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3175. {
  3176. nullpo_retv(sd);
  3177. if(!ok) {
  3178. int fd=sd->fd;
  3179. WFIFOHEAD(fd,packet_len(0xa8));
  3180. WFIFOW(fd,0)=0xa8;
  3181. WFIFOW(fd,2)=index+2;
  3182. WFIFOW(fd,4)=amount;
  3183. WFIFOB(fd,6)=ok;
  3184. WFIFOSET(fd,packet_len(0xa8));
  3185. }
  3186. else {
  3187. #if PACKETVER < 3
  3188. int fd=sd->fd;
  3189. WFIFOHEAD(fd,packet_len(0xa8));
  3190. WFIFOW(fd,0)=0xa8;
  3191. WFIFOW(fd,2)=index+2;
  3192. WFIFOW(fd,4)=amount;
  3193. WFIFOB(fd,6)=ok;
  3194. WFIFOSET(fd,packet_len(0xa8));
  3195. #else
  3196. unsigned char buf[32];
  3197. WBUFW(buf,0)=0x1c8;
  3198. WBUFW(buf,2)=index+2;
  3199. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3200. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3201. else
  3202. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3203. WBUFL(buf,6)=sd->bl.id;
  3204. WBUFW(buf,10)=amount;
  3205. WBUFB(buf,12)=ok;
  3206. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3207. #endif
  3208. }
  3209. }
  3210. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3211. /// 00d6 <flag>.B
  3212. /// flag:
  3213. /// 0 = Room has been successfully created (opens chat room)
  3214. /// 1 = Room limit exceeded
  3215. /// 2 = Same room already exists
  3216. void clif_createchat(struct map_session_data* sd, int flag)
  3217. {
  3218. int fd;
  3219. nullpo_retv(sd);
  3220. fd = sd->fd;
  3221. WFIFOHEAD(fd,packet_len(0xd6));
  3222. WFIFOW(fd,0) = 0xd6;
  3223. WFIFOB(fd,2) = flag;
  3224. WFIFOSET(fd,packet_len(0xd6));
  3225. }
  3226. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3227. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3228. /// type:
  3229. /// 0 = private (password protected)
  3230. /// 1 = public
  3231. /// 2 = arena (npc waiting room)
  3232. /// 3 = PK zone (non-clickable)
  3233. void clif_dispchat(struct chat_data* cd, int fd)
  3234. {
  3235. unsigned char buf[128];
  3236. uint8 type;
  3237. if( cd == NULL || cd->owner == NULL )
  3238. return;
  3239. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3240. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3241. : 1;
  3242. WBUFW(buf, 0) = 0xd7;
  3243. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3244. WBUFL(buf, 4) = cd->owner->id;
  3245. WBUFL(buf, 8) = cd->bl.id;
  3246. WBUFW(buf,12) = cd->limit;
  3247. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3248. WBUFB(buf,16) = type;
  3249. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3250. if( fd ) {
  3251. WFIFOHEAD(fd,WBUFW(buf,2));
  3252. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3253. WFIFOSET(fd,WBUFW(buf,2));
  3254. } else {
  3255. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3256. }
  3257. }
  3258. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3259. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3260. /// type:
  3261. /// 0 = private (password protected)
  3262. /// 1 = public
  3263. /// 2 = arena (npc waiting room)
  3264. /// 3 = PK zone (non-clickable)
  3265. void clif_changechatstatus(struct chat_data* cd)
  3266. {
  3267. unsigned char buf[128];
  3268. uint8 type;
  3269. if( cd == NULL || cd->usersd[0] == NULL )
  3270. return;
  3271. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3272. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3273. : 1;
  3274. WBUFW(buf, 0) = 0xdf;
  3275. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3276. WBUFL(buf, 4) = cd->owner->id;
  3277. WBUFL(buf, 8) = cd->bl.id;
  3278. WBUFW(buf,12) = cd->limit;
  3279. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3280. WBUFB(buf,16) = type;
  3281. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3282. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3283. }
  3284. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3285. /// 00d8 <chat id>.L
  3286. void clif_clearchat(struct chat_data *cd,int fd)
  3287. {
  3288. unsigned char buf[32];
  3289. nullpo_retv(cd);
  3290. WBUFW(buf,0) = 0xd8;
  3291. WBUFL(buf,2) = cd->bl.id;
  3292. if( fd ) {
  3293. WFIFOHEAD(fd,packet_len(0xd8));
  3294. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3295. WFIFOSET(fd,packet_len(0xd8));
  3296. } else {
  3297. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3298. }
  3299. }
  3300. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3301. /// 00da <result>.B
  3302. /// result:
  3303. /// 0 = room full
  3304. /// 1 = wrong password
  3305. /// 2 = kicked
  3306. /// 3 = success (no message)
  3307. /// 4 = no enough zeny
  3308. /// 5 = too low level
  3309. /// 6 = too high level
  3310. /// 7 = unsuitable job class
  3311. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3312. {
  3313. int fd;
  3314. nullpo_retv(sd);
  3315. fd = sd->fd;
  3316. WFIFOHEAD(fd,packet_len(0xda));
  3317. WFIFOW(fd,0) = 0xda;
  3318. WFIFOB(fd,2) = flag;
  3319. WFIFOSET(fd,packet_len(0xda));
  3320. }
  3321. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3322. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3323. /// role:
  3324. /// 0 = owner (menu)
  3325. /// 1 = normal
  3326. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3327. {
  3328. int fd;
  3329. int i,t;
  3330. nullpo_retv(sd);
  3331. nullpo_retv(cd);
  3332. fd = sd->fd;
  3333. if (!session_isActive(fd))
  3334. return;
  3335. t = (int)(cd->owner->type == BL_NPC);
  3336. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3337. WFIFOW(fd, 0) = 0xdb;
  3338. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3339. WFIFOL(fd, 4) = cd->bl.id;
  3340. if(cd->owner->type == BL_NPC){
  3341. WFIFOL(fd, 30) = 1;
  3342. WFIFOL(fd, 8) = 0;
  3343. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3344. for (i = 0; i < cd->users; i++) {
  3345. WFIFOL(fd, 8+(i+1)*28) = 1;
  3346. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3347. }
  3348. } else
  3349. for (i = 0; i < cd->users; i++) {
  3350. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3351. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3352. }
  3353. WFIFOSET(fd, WFIFOW(fd, 2));
  3354. }
  3355. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3356. /// 00dc <users>.W <name>.24B
  3357. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3358. {
  3359. unsigned char buf[29];
  3360. nullpo_retv(sd);
  3361. nullpo_retv(cd);
  3362. WBUFW(buf, 0) = 0xdc;
  3363. WBUFW(buf, 2) = cd->users;
  3364. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3365. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3366. }
  3367. /// Announce the new owner (ZC_ROLE_CHANGE).
  3368. /// 00e1 <role>.L <nick>.24B
  3369. /// role:
  3370. /// 0 = owner (menu)
  3371. /// 1 = normal
  3372. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3373. {
  3374. unsigned char buf[64];
  3375. nullpo_retv(sd);
  3376. nullpo_retv(cd);
  3377. WBUFW(buf, 0) = 0xe1;
  3378. WBUFL(buf, 2) = 1;
  3379. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3380. WBUFW(buf,30) = 0xe1;
  3381. WBUFL(buf,32) = 0;
  3382. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3383. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3384. }
  3385. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3386. /// 00dd <users>.W <nick>.24B <flag>.B
  3387. /// flag:
  3388. /// 0 = left
  3389. /// 1 = kicked
  3390. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3391. {
  3392. unsigned char buf[32];
  3393. nullpo_retv(sd);
  3394. nullpo_retv(cd);
  3395. WBUFW(buf, 0) = 0xdd;
  3396. WBUFW(buf, 2) = cd->users-1;
  3397. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3398. WBUFB(buf,28) = flag;
  3399. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3400. }
  3401. /// Opens a trade request window from char 'name'.
  3402. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3403. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3404. void clif_traderequest(struct map_session_data* sd, const char* name)
  3405. {
  3406. int fd = sd->fd;
  3407. #if PACKETVER < 6
  3408. WFIFOHEAD(fd,packet_len(0xe5));
  3409. WFIFOW(fd,0) = 0xe5;
  3410. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3411. WFIFOSET(fd,packet_len(0xe5));
  3412. #else
  3413. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3414. if( !tsd ) return;
  3415. WFIFOHEAD(fd,packet_len(0x1f4));
  3416. WFIFOW(fd,0) = 0x1f4;
  3417. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3418. WFIFOL(fd,26) = tsd->status.char_id;
  3419. WFIFOW(fd,30) = tsd->status.base_level;
  3420. WFIFOSET(fd,packet_len(0x1f4));
  3421. #endif
  3422. }
  3423. /// Reply to a trade-request.
  3424. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3425. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3426. /// result:
  3427. /// 0 = Char is too far
  3428. /// 1 = Character does not exist
  3429. /// 2 = Trade failed
  3430. /// 3 = Accept
  3431. /// 4 = Cancel
  3432. /// 5 = Busy
  3433. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3434. {
  3435. int fd = sd->fd;
  3436. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3437. if( PACKETVER < 6 || !tsd ) {
  3438. WFIFOHEAD(fd,packet_len(0xe7));
  3439. WFIFOW(fd,0) = 0xe7;
  3440. WFIFOB(fd,2) = type;
  3441. WFIFOSET(fd,packet_len(0xe7));
  3442. } else {
  3443. WFIFOHEAD(fd,packet_len(0x1f5));
  3444. WFIFOW(fd,0) = 0x1f5;
  3445. WFIFOB(fd,2) = type;
  3446. WFIFOL(fd,3) = tsd->status.char_id;
  3447. WFIFOW(fd,7) = tsd->status.base_level;
  3448. WFIFOSET(fd,packet_len(0x1f5));
  3449. }
  3450. }
  3451. /// Notifies the client about an item from other player in current trade.
  3452. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3453. /// 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)
  3454. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3455. {
  3456. int fd;
  3457. unsigned char *buf;
  3458. #if PACKETVER < 20100223
  3459. const int cmd = 0xe9;
  3460. #else
  3461. const int cmd = 0x80f;
  3462. #endif
  3463. nullpo_retv(sd);
  3464. nullpo_retv(tsd);
  3465. fd = tsd->fd;
  3466. buf = WFIFOP(fd,0);
  3467. WFIFOHEAD(fd,packet_len(cmd));
  3468. WBUFW(buf,0) = cmd;
  3469. if( index == 0 )
  3470. {
  3471. #if PACKETVER < 20100223
  3472. WBUFL(buf,2) = amount; //amount
  3473. WBUFW(buf,6) = 0; // type id
  3474. #else
  3475. WBUFW(buf,2) = 0; // type id
  3476. WBUFB(buf,4) = 0; // item type
  3477. WBUFL(buf,5) = amount; // amount
  3478. buf = WBUFP(buf,1); //Advance 1B
  3479. #endif
  3480. WBUFB(buf,8) = 0; //identify flag
  3481. WBUFB(buf,9) = 0; // attribute
  3482. WBUFB(buf,10)= 0; //refine
  3483. WBUFW(buf,11)= 0; //card (4w)
  3484. WBUFW(buf,13)= 0; //card (4w)
  3485. WBUFW(buf,15)= 0; //card (4w)
  3486. WBUFW(buf,17)= 0; //card (4w)
  3487. }
  3488. else
  3489. {
  3490. index -= 2; //index fix
  3491. #if PACKETVER < 20100223
  3492. WBUFL(buf,2) = amount; //amount
  3493. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3494. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3495. else
  3496. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3497. #else
  3498. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3499. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3500. else
  3501. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3502. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3503. WBUFL(buf,5) = amount; // amount
  3504. buf = WBUFP(buf,1); //Advance 1B
  3505. #endif
  3506. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3507. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3508. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3509. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3510. }
  3511. WFIFOSET(fd,packet_len(cmd));
  3512. }
  3513. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3514. /// 00ea <index>.W <result>.B
  3515. /// result:
  3516. /// 0 = success
  3517. /// 1 = overweight
  3518. /// 2 = trade canceled
  3519. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3520. {
  3521. int fd;
  3522. nullpo_retv(sd);
  3523. fd = sd->fd;
  3524. WFIFOHEAD(fd,packet_len(0xea));
  3525. WFIFOW(fd,0) = 0xea;
  3526. WFIFOW(fd,2) = index;
  3527. WFIFOB(fd,4) = fail;
  3528. WFIFOSET(fd,packet_len(0xea));
  3529. }
  3530. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3531. /// 00ec <who>.B
  3532. /// who:
  3533. /// 0 = self
  3534. /// 1 = other player
  3535. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3536. {
  3537. int fd;
  3538. nullpo_retv(sd);
  3539. fd = sd->fd;
  3540. WFIFOHEAD(fd,packet_len(0xec));
  3541. WFIFOW(fd,0) = 0xec;
  3542. WFIFOB(fd,2) = fail;
  3543. WFIFOSET(fd,packet_len(0xec));
  3544. }
  3545. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3546. /// 00ee
  3547. void clif_tradecancelled(struct map_session_data* sd)
  3548. {
  3549. int fd;
  3550. nullpo_retv(sd);
  3551. fd = sd->fd;
  3552. WFIFOHEAD(fd,packet_len(0xee));
  3553. WFIFOW(fd,0) = 0xee;
  3554. WFIFOSET(fd,packet_len(0xee));
  3555. }
  3556. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3557. /// 00f0 <result>.B
  3558. /// result:
  3559. /// 0 = success
  3560. /// 1 = failure
  3561. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3562. {
  3563. int fd;
  3564. nullpo_retv(sd);
  3565. fd = sd->fd;
  3566. WFIFOHEAD(fd,packet_len(0xf0));
  3567. WFIFOW(fd,0) = 0xf0;
  3568. WFIFOB(fd,2) = fail;
  3569. WFIFOSET(fd,packet_len(0xf0));
  3570. }
  3571. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3572. /// 00f1
  3573. /// NOTE: Unknown purpose. Items are not removed until the window is
  3574. /// refreshed (ex. by putting another item in there).
  3575. void clif_tradeundo(struct map_session_data* sd)
  3576. {
  3577. int fd = sd->fd;
  3578. WFIFOHEAD(fd,packet_len(0xf1));
  3579. WFIFOW(fd,0) = 0xf1;
  3580. WFIFOSET(fd,packet_len(0xf1));
  3581. }
  3582. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3583. /// 00f2 <current count>.W <max count>.W
  3584. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3585. {
  3586. int fd;
  3587. nullpo_retv(sd);
  3588. fd=sd->fd;
  3589. WFIFOHEAD(fd,packet_len(0xf2));
  3590. WFIFOW(fd,0) = 0xf2;
  3591. WFIFOW(fd,2) = amount;
  3592. WFIFOW(fd,4) = max_amount;
  3593. WFIFOSET(fd,packet_len(0xf2));
  3594. }
  3595. /// Notifies the client of an item being added to the storage.
  3596. /// 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)
  3597. /// 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)
  3598. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3599. {
  3600. int view,fd;
  3601. nullpo_retv(sd);
  3602. nullpo_retv(i);
  3603. fd=sd->fd;
  3604. view = itemdb_viewid(i->nameid);
  3605. #if PACKETVER < 5
  3606. WFIFOHEAD(fd,packet_len(0xf4));
  3607. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3608. WFIFOW(fd, 2) = index+1; // index
  3609. WFIFOL(fd, 4) = amount; // amount
  3610. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3611. WFIFOB(fd,10) = i->identify; //identify flag
  3612. WFIFOB(fd,11) = i->attribute; // attribute
  3613. WFIFOB(fd,12) = i->refine; //refine
  3614. clif_addcards(WFIFOP(fd,13), i);
  3615. WFIFOSET(fd,packet_len(0xf4));
  3616. #else
  3617. WFIFOHEAD(fd,packet_len(0x1c4));
  3618. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3619. WFIFOW(fd, 2) = index+1; // index
  3620. WFIFOL(fd, 4) = amount; // amount
  3621. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3622. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3623. WFIFOB(fd,11) = i->identify; //identify flag
  3624. WFIFOB(fd,12) = i->attribute; // attribute
  3625. WFIFOB(fd,13) = i->refine; //refine
  3626. clif_addcards(WFIFOP(fd,14), i);
  3627. WFIFOSET(fd,packet_len(0x1c4));
  3628. #endif
  3629. }
  3630. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3631. /// 00f6 <index>.W <amount>.L
  3632. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3633. {
  3634. int fd;
  3635. nullpo_retv(sd);
  3636. fd=sd->fd;
  3637. WFIFOHEAD(fd,packet_len(0xf6));
  3638. WFIFOW(fd,0)=0xf6; // Storage item removed
  3639. WFIFOW(fd,2)=index+1;
  3640. WFIFOL(fd,4)=amount;
  3641. WFIFOSET(fd,packet_len(0xf6));
  3642. }
  3643. /// Closes storage (ZC_CLOSE_STORE).
  3644. /// 00f8
  3645. void clif_storageclose(struct map_session_data* sd)
  3646. {
  3647. int fd;
  3648. nullpo_retv(sd);
  3649. fd=sd->fd;
  3650. WFIFOHEAD(fd,packet_len(0xf8));
  3651. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3652. WFIFOSET(fd,packet_len(0xf8));
  3653. }
  3654. /*==========================================
  3655. * Server tells 'sd' player client the abouts of 'dstsd' player
  3656. *------------------------------------------*/
  3657. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3658. {
  3659. struct block_list *d_bl;
  3660. int i;
  3661. if( dstsd->chatID ) {
  3662. struct chat_data *cd = NULL;
  3663. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3664. clif_dispchat(cd,sd->fd);
  3665. } else if( dstsd->state.vending )
  3666. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3667. else if( dstsd->state.buyingstore )
  3668. clif_buyingstore_entry_single(sd, dstsd);
  3669. if(dstsd->spiritball > 0)
  3670. clif_spiritball_single(sd->fd, dstsd);
  3671. for(i = 1; i < 5; i++){
  3672. if( dstsd->talisman[i] > 0 )
  3673. clif_talisman_single(sd->fd, dstsd, i);
  3674. }
  3675. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3676. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3677. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3678. else
  3679. 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);
  3680. }
  3681. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3682. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3683. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3684. )
  3685. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3686. // display link (sd - dstsd) to sd
  3687. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3688. if( i < MAX_DEVOTION )
  3689. clif_devotion(&sd->bl, sd);
  3690. // display links (dstsd - devotees) to sd
  3691. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3692. if( i < MAX_DEVOTION )
  3693. clif_devotion(&dstsd->bl, sd);
  3694. // display link (dstsd - crusader) to sd
  3695. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3696. clif_devotion(d_bl, sd);
  3697. }
  3698. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3699. {
  3700. uint8 buf[128];
  3701. struct unit_data *ud;
  3702. struct view_data *vd;
  3703. int len;
  3704. vd = status_get_viewdata(bl);
  3705. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3706. return;
  3707. /**
  3708. * Hide NPC from maya purple card.
  3709. **/
  3710. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3711. return;
  3712. ud = unit_bl2ud(bl);
  3713. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3714. clif_send(buf,len,&sd->bl,SELF);
  3715. if (vd->cloth_color)
  3716. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3717. switch (bl->type)
  3718. {
  3719. case BL_PC:
  3720. {
  3721. TBL_PC* tsd = (TBL_PC*)bl;
  3722. clif_getareachar_pc(sd, tsd);
  3723. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3724. clif_specialeffect_single(bl,423,sd->fd);
  3725. else if(tsd->state.size==SZ_MEDIUM)
  3726. clif_specialeffect_single(bl,421,sd->fd);
  3727. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3728. clif_sendbgemblem_single(sd->fd,tsd);
  3729. if ( tsd->status.robe )
  3730. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3731. if (!&tsd->sc)
  3732. break;
  3733. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3734. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3735. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3736. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3737. if( tsd->sc.data[SC_MOONSTAR] )
  3738. clif_status_load(bl,SI_MOONSTAR,1);
  3739. if( tsd->sc.data[SC_SUPER_STAR] )
  3740. clif_status_load(bl,SI_SUPER_STAR,1);
  3741. if( tsd->sc.data[SC_ALL_RIDING] )
  3742. clif_status_load(bl,SI_ALL_RIDING,1);
  3743. }
  3744. break;
  3745. case BL_MER: // Devotion Effects
  3746. if( ((TBL_MER*)bl)->devotion_flag )
  3747. clif_devotion(bl, sd);
  3748. break;
  3749. case BL_NPC:
  3750. {
  3751. TBL_NPC* nd = (TBL_NPC*)bl;
  3752. if( nd->chat_id )
  3753. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3754. if( nd->size == SZ_BIG )
  3755. clif_specialeffect_single(bl,423,sd->fd);
  3756. else if( nd->size == SZ_MEDIUM )
  3757. clif_specialeffect_single(bl,421,sd->fd);
  3758. }
  3759. break;
  3760. case BL_MOB:
  3761. {
  3762. TBL_MOB* md = (TBL_MOB*)bl;
  3763. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3764. clif_specialeffect_single(bl,423,sd->fd);
  3765. else if(md->special_state.size==SZ_MEDIUM)
  3766. clif_specialeffect_single(bl,421,sd->fd);
  3767. #if PACKETVER >= 20120404
  3768. if( !(md->status.mode&MD_BOSS) ){
  3769. int i;
  3770. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3771. if( md->dmglog[i].id == sd->status.char_id )
  3772. clif_monster_hp_bar(md, sd->fd);
  3773. }
  3774. #endif
  3775. }
  3776. break;
  3777. case BL_PET:
  3778. if (vd->head_bottom)
  3779. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3780. break;
  3781. }
  3782. }
  3783. //Modifies the type of damage according to status changes [Skotlex]
  3784. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3785. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  3786. {
  3787. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  3788. }
  3789. /*==========================================
  3790. * Estimates walk delay based on the damage criteria. [Skotlex]
  3791. *------------------------------------------*/
  3792. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  3793. {
  3794. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  3795. return 0;
  3796. if (bl->type == BL_PC) {
  3797. if (battle_config.pc_walk_delay_rate != 100)
  3798. delay = delay*battle_config.pc_walk_delay_rate/100;
  3799. } else
  3800. if (battle_config.walk_delay_rate != 100)
  3801. delay = delay*battle_config.walk_delay_rate/100;
  3802. if (div_ > 1) //Multi-hit skills mean higher delays.
  3803. delay += battle_config.multihit_delay*(div_-1);
  3804. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3805. }
  3806. /// Sends a 'damage' packet (src performs action on dst)
  3807. /// 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)
  3808. /// 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)
  3809. /// 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
  3810. /// type:
  3811. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3812. /// 1 = pick up item
  3813. /// 2 = sit down
  3814. /// 3 = stand up
  3815. /// 4 = damage (endure)
  3816. /// 5 = (splash?)
  3817. /// 6 = (skill?)
  3818. /// 7 = (repeat damage?)
  3819. /// 8 = multi-hit damage
  3820. /// 9 = multi-hit damage (endure)
  3821. /// 10 = critical hit
  3822. /// 11 = lucky dodge
  3823. /// 12 = (touch skill?)
  3824. 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)
  3825. {
  3826. unsigned char buf[33];
  3827. struct status_change *sc;
  3828. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3829. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3830. #if PACKETVER < 20071113
  3831. const int cmd = 0x8a;
  3832. #else
  3833. const int cmd = 0x2e1;
  3834. #endif
  3835. nullpo_ret(src);
  3836. nullpo_ret(dst);
  3837. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3838. sc = status_get_sc(dst);
  3839. if(sc && sc->count) {
  3840. if(sc->data[SC_HALLUCINATION]) {
  3841. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3842. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3843. }
  3844. }
  3845. WBUFW(buf,0)=cmd;
  3846. WBUFL(buf,2)=src->id;
  3847. WBUFL(buf,6)=dst->id;
  3848. WBUFL(buf,10)=tick;
  3849. WBUFL(buf,14)=sdelay;
  3850. WBUFL(buf,18)=ddelay;
  3851. #if PACKETVER < 20071113
  3852. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3853. WBUFW(buf,22)=damage?div:0;
  3854. WBUFW(buf,27)=damage2?div:0;
  3855. } else {
  3856. WBUFW(buf,22)=min(damage, INT16_MAX);
  3857. WBUFW(buf,27)=damage2;
  3858. }
  3859. WBUFW(buf,24)=div;
  3860. WBUFB(buf,26)=type;
  3861. #else
  3862. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3863. WBUFL(buf,22)=damage?div:0;
  3864. WBUFL(buf,29)=damage2?div:0;
  3865. } else {
  3866. WBUFL(buf,22)=damage;
  3867. WBUFL(buf,29)=damage2;
  3868. }
  3869. WBUFW(buf,26)=div;
  3870. WBUFB(buf,28)=type;
  3871. #endif
  3872. if(disguised(dst)) {
  3873. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3874. WBUFL(buf,6) = -dst->id;
  3875. clif_send(buf,packet_len(cmd),dst,SELF);
  3876. } else
  3877. clif_send(buf,packet_len(cmd),dst,AREA);
  3878. if(disguised(src)) {
  3879. WBUFL(buf,2) = -src->id;
  3880. if (disguised(dst))
  3881. WBUFL(buf,6) = dst->id;
  3882. #if PACKETVER < 20071113
  3883. if(damage > 0) WBUFW(buf,22) = -1;
  3884. if(damage2 > 0) WBUFW(buf,27) = -1;
  3885. #else
  3886. if(damage > 0) WBUFL(buf,22) = -1;
  3887. if(damage2 > 0) WBUFL(buf,29) = -1;
  3888. #endif
  3889. clif_send(buf,packet_len(cmd),src,SELF);
  3890. }
  3891. if(src == dst) {
  3892. unit_setdir(src,unit_getdir(src));
  3893. }
  3894. //Return adjusted can't walk delay for further processing.
  3895. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3896. }
  3897. /*==========================================
  3898. * src picks up dst
  3899. *------------------------------------------*/
  3900. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3901. {
  3902. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  3903. unsigned char buf[32];
  3904. nullpo_retv(src);
  3905. nullpo_retv(dst);
  3906. WBUFW(buf, 0) = 0x8a;
  3907. WBUFL(buf, 2) = src->id;
  3908. WBUFL(buf, 6) = dst->id;
  3909. WBUFB(buf,26) = 1;
  3910. clif_send(buf, packet_len(0x8a), src, AREA);
  3911. }
  3912. /*==========================================
  3913. * inform clients in area that `bl` is sitting
  3914. *------------------------------------------*/
  3915. void clif_sitting(struct block_list* bl)
  3916. {
  3917. unsigned char buf[32];
  3918. nullpo_retv(bl);
  3919. WBUFW(buf, 0) = 0x8a;
  3920. WBUFL(buf, 2) = bl->id;
  3921. WBUFB(buf,26) = 2;
  3922. clif_send(buf, packet_len(0x8a), bl, AREA);
  3923. if(disguised(bl)) {
  3924. WBUFL(buf, 2) = - bl->id;
  3925. clif_send(buf, packet_len(0x8a), bl, SELF);
  3926. }
  3927. }
  3928. /*==========================================
  3929. * inform clients in area that `bl` is standing
  3930. *------------------------------------------*/
  3931. void clif_standing(struct block_list* bl)
  3932. {
  3933. unsigned char buf[32];
  3934. nullpo_retv(bl);
  3935. WBUFW(buf, 0) = 0x8a;
  3936. WBUFL(buf, 2) = bl->id;
  3937. WBUFB(buf,26) = 3;
  3938. clif_send(buf, packet_len(0x8a), bl, AREA);
  3939. if(disguised(bl)) {
  3940. WBUFL(buf, 2) = - bl->id;
  3941. clif_send(buf, packet_len(0x8a), bl, SELF);
  3942. }
  3943. }
  3944. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3945. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3946. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3947. {
  3948. unsigned char buf[32];
  3949. WBUFW(buf,0) = 0x192;
  3950. WBUFW(buf,2) = x;
  3951. WBUFW(buf,4) = y;
  3952. WBUFW(buf,6) = type;
  3953. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  3954. if( fd )
  3955. {
  3956. WFIFOHEAD(fd,packet_len(0x192));
  3957. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3958. WFIFOSET(fd,packet_len(0x192));
  3959. }
  3960. else
  3961. {
  3962. struct block_list dummy_bl;
  3963. dummy_bl.type = BL_NUL;
  3964. dummy_bl.x = x;
  3965. dummy_bl.y = y;
  3966. dummy_bl.m = m;
  3967. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3968. }
  3969. }
  3970. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3971. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3972. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3973. {
  3974. int view,fd;
  3975. fd=sd->fd;
  3976. WFIFOHEAD(fd,packet_len(0x9d));
  3977. WFIFOW(fd,0)=0x9d;
  3978. WFIFOL(fd,2)=fitem->bl.id;
  3979. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  3980. WFIFOW(fd,6)=view;
  3981. else
  3982. WFIFOW(fd,6)=fitem->item.nameid;
  3983. WFIFOB(fd,8)=fitem->item.identify;
  3984. WFIFOW(fd,9)=fitem->bl.x;
  3985. WFIFOW(fd,11)=fitem->bl.y;
  3986. WFIFOW(fd,13)=fitem->item.amount;
  3987. WFIFOB(fd,15)=fitem->subx;
  3988. WFIFOB(fd,16)=fitem->suby;
  3989. WFIFOSET(fd,packet_len(0x9d));
  3990. }
  3991. /// Notifes client about Graffiti
  3992. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3993. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  3994. unsigned char buf[128];
  3995. nullpo_retv(bl);
  3996. nullpo_retv(unit);
  3997. WBUFW(buf, 0) = 0x1c9;
  3998. WBUFL(buf, 2) = unit->bl.id;
  3999. WBUFL(buf, 6) = unit->group->src_id;
  4000. WBUFW(buf,10) = unit->bl.x;
  4001. WBUFW(buf,12) = unit->bl.y;
  4002. WBUFB(buf,14) = unit->group->unit_id;
  4003. WBUFB(buf,15) = 1;
  4004. WBUFB(buf,16) = 1;
  4005. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4006. clif_send(buf,packet_len(0x1c9),bl,target);
  4007. }
  4008. /// Notifies the client of a skill unit.
  4009. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4010. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4011. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4012. /// 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)
  4013. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4014. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4015. unsigned char buf[128];
  4016. nullpo_retv(bl);
  4017. nullpo_retv(unit);
  4018. if (bl->type == BL_PC)
  4019. fd = ((TBL_PC*)bl)->fd;
  4020. if (unit->group->state.guildaura)
  4021. return;
  4022. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  4023. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for traps.
  4024. else if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4025. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4026. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4027. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  4028. else
  4029. unit_id = unit->group->unit_id;
  4030. #if PACKETVER >= 3
  4031. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4032. clif_graffiti(bl, unit, target);
  4033. return;
  4034. }
  4035. #endif
  4036. #if PACKETVER <= 20120702
  4037. header = 0x011f;
  4038. //#if PACKETVER < 20110718
  4039. // header = 0x011f;
  4040. //#elif PACKETVER < 20121212
  4041. // header = 0x08c7;
  4042. #elif PACKETVER < 20130731
  4043. header = 0x099f;
  4044. #else
  4045. header = 0x09ca;
  4046. #endif
  4047. len = packet_len(header);
  4048. WBUFW(buf,pos) = header;
  4049. if (header != 0x011f) {
  4050. WBUFW(buf, pos+2) = len;
  4051. pos += 2;
  4052. }
  4053. WBUFL(buf,pos+2) = unit->bl.id;
  4054. WBUFL(buf,pos+6) = unit->group->src_id;
  4055. WBUFW(buf,pos+10) = unit->bl.x;
  4056. WBUFW(buf,pos+12) = unit->bl.y;
  4057. switch (header) {
  4058. case 0x011f:
  4059. WBUFB(buf,pos+14) = unit_id;
  4060. WBUFB(buf,pos+15) = 1;
  4061. break;
  4062. case 0x08c7:
  4063. WBUFB(buf,pos+14) = unit_id;
  4064. WBUFW(buf,pos+15) = unit->range;
  4065. WBUFB(buf,pos+17) = 1;
  4066. break;
  4067. case 0x099f:
  4068. WBUFL(buf,pos+14) = unit_id;
  4069. WBUFW(buf,pos+18) = unit->range;
  4070. WBUFB(buf,pos+20) = 1;
  4071. break;
  4072. case 0x09ca:
  4073. WBUFL(buf,pos+14) = unit_id;
  4074. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4075. WBUFB(buf,pos+19) = 1;
  4076. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4077. break;
  4078. }
  4079. clif_send(buf, len, bl, target);
  4080. if (unit->group->skill_id == WZ_ICEWALL)
  4081. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4082. }
  4083. /*==========================================
  4084. * Server tells client to remove unit of id 'unit->bl.id'
  4085. *------------------------------------------*/
  4086. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4087. {
  4088. nullpo_retv(unit);
  4089. WFIFOHEAD(fd,packet_len(0x120));
  4090. WFIFOW(fd, 0)=0x120;
  4091. WFIFOL(fd, 2)=unit->bl.id;
  4092. WFIFOSET(fd,packet_len(0x120));
  4093. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4094. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4095. }
  4096. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4097. /// 0120 <id>.L
  4098. void clif_skill_delunit(struct skill_unit *unit)
  4099. {
  4100. unsigned char buf[16];
  4101. nullpo_retv(unit);
  4102. WBUFW(buf, 0)=0x120;
  4103. WBUFL(buf, 2)=unit->bl.id;
  4104. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4105. }
  4106. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4107. /// 01ac <id>.L
  4108. /// Only affects units with class [139,153] client-side.
  4109. void clif_skillunit_update(struct block_list* bl)
  4110. {
  4111. unsigned char buf[6];
  4112. nullpo_retv(bl);
  4113. WBUFW(buf,0) = 0x1ac;
  4114. WBUFL(buf,2) = bl->id;
  4115. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4116. }
  4117. /*==========================================
  4118. *
  4119. *------------------------------------------*/
  4120. static int clif_getareachar(struct block_list* bl,va_list ap)
  4121. {
  4122. struct map_session_data *sd;
  4123. nullpo_ret(bl);
  4124. sd=va_arg(ap,struct map_session_data*);
  4125. if (sd == NULL || !sd->fd)
  4126. return 0;
  4127. switch(bl->type){
  4128. case BL_ITEM:
  4129. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4130. break;
  4131. case BL_SKILL:
  4132. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF);
  4133. break;
  4134. default:
  4135. if(&sd->bl == bl)
  4136. break;
  4137. clif_getareachar_unit(sd,bl);
  4138. break;
  4139. }
  4140. return 0;
  4141. }
  4142. /*==========================================
  4143. * tbl has gone out of view-size of bl
  4144. *------------------------------------------*/
  4145. int clif_outsight(struct block_list *bl,va_list ap)
  4146. {
  4147. struct block_list *tbl;
  4148. struct view_data *vd;
  4149. TBL_PC *sd, *tsd;
  4150. tbl=va_arg(ap,struct block_list*);
  4151. if(bl == tbl) return 0;
  4152. sd = BL_CAST(BL_PC, bl);
  4153. tsd = BL_CAST(BL_PC, tbl);
  4154. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4155. nullpo_ret(bl);
  4156. switch(bl->type){
  4157. case BL_PC:
  4158. if(sd->vd.class_ != INVISIBLE_CLASS)
  4159. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4160. if(sd->chatID){
  4161. struct chat_data *cd;
  4162. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4163. if(cd->usersd[0]==sd)
  4164. clif_dispchat(cd,tsd->fd);
  4165. }
  4166. if(sd->state.vending)
  4167. clif_closevendingboard(bl,tsd->fd);
  4168. if(sd->state.buyingstore)
  4169. clif_buyingstore_disappear_entry_single(tsd, sd);
  4170. break;
  4171. case BL_ITEM:
  4172. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4173. break;
  4174. case BL_SKILL:
  4175. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4176. break;
  4177. case BL_NPC:
  4178. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4179. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4180. break;
  4181. default:
  4182. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4183. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4184. break;
  4185. }
  4186. }
  4187. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4188. nullpo_ret(tbl);
  4189. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4190. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4191. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4192. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4193. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4194. }
  4195. return 0;
  4196. }
  4197. /*==========================================
  4198. * tbl has come into view of bl
  4199. *------------------------------------------*/
  4200. int clif_insight(struct block_list *bl,va_list ap)
  4201. {
  4202. struct block_list *tbl;
  4203. TBL_PC *sd, *tsd;
  4204. tbl=va_arg(ap,struct block_list*);
  4205. if (bl == tbl) return 0;
  4206. sd = BL_CAST(BL_PC, bl);
  4207. tsd = BL_CAST(BL_PC, tbl);
  4208. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4209. switch(bl->type){
  4210. case BL_ITEM:
  4211. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4212. break;
  4213. case BL_SKILL:
  4214. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF);
  4215. break;
  4216. default:
  4217. clif_getareachar_unit(tsd,bl);
  4218. break;
  4219. }
  4220. }
  4221. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4222. clif_getareachar_unit(sd,tbl);
  4223. }
  4224. return 0;
  4225. }
  4226. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4227. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4228. void clif_skillinfoblock(struct map_session_data *sd)
  4229. {
  4230. int fd;
  4231. int i,len,id;
  4232. nullpo_retv(sd);
  4233. fd=sd->fd;
  4234. if (!fd) return;
  4235. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4236. WFIFOW(fd,0) = 0x10f;
  4237. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4238. {
  4239. if( (id = sd->status.skill[i].id) != 0 )
  4240. {
  4241. // workaround for bugreport:5348
  4242. if (len + 37 > 8192)
  4243. break;
  4244. WFIFOW(fd,len) = id;
  4245. WFIFOL(fd,len+2) = skill_get_inf(id);
  4246. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4247. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4248. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4249. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4250. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4251. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4252. else
  4253. WFIFOB(fd,len+36) = 0;
  4254. len += 37;
  4255. }
  4256. }
  4257. WFIFOW(fd,2)=len;
  4258. WFIFOSET(fd,len);
  4259. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4260. for ( ; i < MAX_SKILL; i++)
  4261. {
  4262. if( (id = sd->status.skill[i].id) != 0 )
  4263. {
  4264. clif_addskill(sd, id);
  4265. clif_skillinfo(sd, id, 0);
  4266. }
  4267. }
  4268. }
  4269. /**
  4270. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4271. **/
  4272. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4273. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4274. void clif_addskill(struct map_session_data *sd, int id)
  4275. {
  4276. int fd;
  4277. nullpo_retv(sd);
  4278. fd = sd->fd;
  4279. if (!fd) return;
  4280. if( sd->status.skill[id].id <= 0 )
  4281. return;
  4282. WFIFOHEAD(fd, packet_len(0x111));
  4283. WFIFOW(fd,0) = 0x111;
  4284. WFIFOW(fd,2) = id;
  4285. WFIFOL(fd,4) = skill_get_inf(id);
  4286. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4287. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4288. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4289. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4290. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4291. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4292. else
  4293. WFIFOB(fd,38) = 0;
  4294. WFIFOSET(fd,packet_len(0x111));
  4295. }
  4296. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4297. /// 0441 <skill id>.W
  4298. void clif_deleteskill(struct map_session_data *sd, int id)
  4299. {
  4300. #if PACKETVER >= 20081217
  4301. int fd;
  4302. nullpo_retv(sd);
  4303. fd = sd->fd;
  4304. if( !fd ) return;
  4305. WFIFOHEAD(fd,packet_len(0x441));
  4306. WFIFOW(fd,0) = 0x441;
  4307. WFIFOW(fd,2) = id;
  4308. WFIFOSET(fd,packet_len(0x441));
  4309. #endif
  4310. clif_skillinfoblock(sd);
  4311. }
  4312. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4313. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4314. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4315. int fd;
  4316. nullpo_retv(sd);
  4317. fd = sd->fd;
  4318. WFIFOHEAD(fd, packet_len(0x10e));
  4319. WFIFOW(fd, 0) = 0x10e;
  4320. WFIFOW(fd, 2) = skill_id;
  4321. WFIFOW(fd, 4) = lv;
  4322. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4323. WFIFOW(fd, 8) = range;
  4324. WFIFOB(fd, 10) = upgradable;
  4325. WFIFOSET(fd, packet_len(0x10e));
  4326. }
  4327. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4328. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4329. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4330. {
  4331. const int fd = sd->fd;
  4332. WFIFOHEAD(fd,packet_len(0x7e1));
  4333. WFIFOW(fd,0) = 0x7e1;
  4334. WFIFOW(fd,2) = skill;
  4335. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4336. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4337. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4338. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4339. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4340. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4341. else
  4342. WFIFOB(fd,14) = 0;
  4343. WFIFOSET(fd,packet_len(0x7e1));
  4344. }
  4345. /// Notifies clients in area, that an object is about to use a skill.
  4346. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4347. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4348. /// property:
  4349. /// 0 = Yellow cast aura
  4350. /// 1 = Water elemental cast aura
  4351. /// 2 = Earth elemental cast aura
  4352. /// 3 = Fire elemental cast aura
  4353. /// 4 = Wind elemental cast aura
  4354. /// 5 = Poison elemental cast aura
  4355. /// 6 = Holy elemental cast aura
  4356. /// ? = like 0
  4357. /// is disposable:
  4358. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4359. /// 1 = no text
  4360. 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)
  4361. {
  4362. #if PACKETVER < 20091124
  4363. const int cmd = 0x13e;
  4364. #else
  4365. const int cmd = 0x7fb;
  4366. #endif
  4367. unsigned char buf[32];
  4368. WBUFW(buf,0) = cmd;
  4369. WBUFL(buf,2) = src_id;
  4370. WBUFL(buf,6) = dst_id;
  4371. WBUFW(buf,10) = dst_x;
  4372. WBUFW(buf,12) = dst_y;
  4373. WBUFW(buf,14) = skill_id;
  4374. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4375. WBUFL(buf,20) = casttime;
  4376. #if PACKETVER >= 20091124
  4377. WBUFB(buf,24) = 0; // isDisposable
  4378. #endif
  4379. if (disguised(bl)) {
  4380. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4381. WBUFL(buf,2) = -src_id;
  4382. clif_send(buf,packet_len(cmd), bl, SELF);
  4383. } else
  4384. clif_send(buf,packet_len(cmd), bl, AREA);
  4385. }
  4386. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4387. /// 01b9 <id>.L
  4388. void clif_skillcastcancel(struct block_list* bl)
  4389. {
  4390. unsigned char buf[16];
  4391. nullpo_retv(bl);
  4392. WBUFW(buf,0) = 0x1b9;
  4393. WBUFL(buf,2) = bl->id;
  4394. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4395. }
  4396. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4397. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4398. /// num (only used when skill id = NV_BASIC and cause = 0):
  4399. /// 0 = "skill failed" MsgStringTable[159]
  4400. /// 1 = "no emotions" MsgStringTable[160]
  4401. /// 2 = "no sit" MsgStringTable[161]
  4402. /// 3 = "no chat" MsgStringTable[162]
  4403. /// 4 = "no party" MsgStringTable[163]
  4404. /// 5 = "no shout" MsgStringTable[164]
  4405. /// 6 = "no PKing" MsgStringTable[165]
  4406. /// 7 = "no alligning" MsgStringTable[383]
  4407. /// ? = ignored
  4408. /// cause:
  4409. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4410. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4411. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4412. /// "skill failed" MsgStringTable[204] (otherwise)
  4413. /// ... = @see enum useskill_fail_cause
  4414. /// ? = ignored
  4415. ///
  4416. /// if(result!=0) doesn't display any of the previous messages
  4417. /// Note: when this packet is received an unknown flag is always set to 0,
  4418. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4419. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4420. {
  4421. int fd;
  4422. if (!sd) { //Since this is the most common nullpo....
  4423. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4424. return;
  4425. }
  4426. fd=sd->fd;
  4427. if (!fd) return;
  4428. if(battle_config.display_skill_fail&1)
  4429. return; //Disable all skill failed messages
  4430. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4431. return; //Disable delay failed messages
  4432. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4433. return;
  4434. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4435. return;
  4436. WFIFOHEAD(fd,packet_len(0x110));
  4437. WFIFOW(fd,0) = 0x110;
  4438. WFIFOW(fd,2) = skill_id;
  4439. WFIFOL(fd,4) = btype;
  4440. WFIFOB(fd,8) = 0;// success
  4441. WFIFOB(fd,9) = cause;
  4442. WFIFOSET(fd,packet_len(0x110));
  4443. }
  4444. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4445. /// 043d <skill ID>.W <tick>.L
  4446. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4447. {
  4448. #if PACKETVER>=20081112
  4449. int fd;
  4450. nullpo_retv(sd);
  4451. fd=sd->fd;
  4452. WFIFOHEAD(fd,packet_len(0x43d));
  4453. WFIFOW(fd,0) = 0x43d;
  4454. WFIFOW(fd,2) = skill_id;
  4455. WFIFOL(fd,4) = tick;
  4456. WFIFOSET(fd,packet_len(0x43d));
  4457. #endif
  4458. }
  4459. /// Skill attack effect and damage.
  4460. /// 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)
  4461. /// 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)
  4462. 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)
  4463. {
  4464. unsigned char buf[64];
  4465. struct status_change *sc;
  4466. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4467. nullpo_ret(src);
  4468. nullpo_ret(dst);
  4469. type = clif_calc_delay(type,div,damage,ddelay);
  4470. #if PACKETVER >= 20131223
  4471. if( type == 6 ) type = 8;
  4472. #endif
  4473. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4474. if(sc->data[SC_HALLUCINATION] && damage)
  4475. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4476. }
  4477. #if PACKETVER < 3
  4478. WBUFW(buf,0)=0x114;
  4479. WBUFW(buf,2)=skill_id;
  4480. WBUFL(buf,4)=src->id;
  4481. WBUFL(buf,8)=dst->id;
  4482. WBUFL(buf,12)=tick;
  4483. WBUFL(buf,16)=sdelay;
  4484. WBUFL(buf,20)=ddelay;
  4485. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4486. WBUFW(buf,24)=damage?div:0;
  4487. } else {
  4488. WBUFW(buf,24)=damage;
  4489. }
  4490. WBUFW(buf,26)=skill_lv;
  4491. WBUFW(buf,28)=div;
  4492. WBUFB(buf,30)=type;
  4493. if (disguised(dst)) {
  4494. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4495. WBUFL(buf,8)=-dst->id;
  4496. clif_send(buf,packet_len(0x114),dst,SELF);
  4497. } else
  4498. clif_send(buf,packet_len(0x114),dst,AREA);
  4499. if(disguised(src)) {
  4500. WBUFL(buf,4)=-src->id;
  4501. if (disguised(dst))
  4502. WBUFL(buf,8)=dst->id;
  4503. if(damage > 0)
  4504. WBUFW(buf,24)=-1;
  4505. clif_send(buf,packet_len(0x114),src,SELF);
  4506. }
  4507. #else
  4508. WBUFW(buf,0)=0x1de;
  4509. WBUFW(buf,2)=skill_id;
  4510. WBUFL(buf,4)=src->id;
  4511. WBUFL(buf,8)=dst->id;
  4512. WBUFL(buf,12)=tick;
  4513. WBUFL(buf,16)=sdelay;
  4514. WBUFL(buf,20)=ddelay;
  4515. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4516. WBUFL(buf,24)=damage?div:0;
  4517. } else {
  4518. WBUFL(buf,24)=damage;
  4519. }
  4520. WBUFW(buf,28)=skill_lv;
  4521. WBUFW(buf,30)=div;
  4522. WBUFB(buf,32)=type;
  4523. if (disguised(dst)) {
  4524. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4525. WBUFL(buf,8)=-dst->id;
  4526. clif_send(buf,packet_len(0x1de),dst,SELF);
  4527. } else
  4528. clif_send(buf,packet_len(0x1de),dst,AREA);
  4529. if(disguised(src)) {
  4530. WBUFL(buf,4)=-src->id;
  4531. if (disguised(dst))
  4532. WBUFL(buf,8)=dst->id;
  4533. if(damage > 0)
  4534. WBUFL(buf,24)=-1;
  4535. clif_send(buf,packet_len(0x1de),src,SELF);
  4536. }
  4537. #endif
  4538. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4539. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4540. }
  4541. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4542. /// 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
  4543. /*
  4544. 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)
  4545. {
  4546. unsigned char buf[64];
  4547. struct status_change *sc;
  4548. nullpo_ret(src);
  4549. nullpo_ret(dst);
  4550. type = (type>0)?type:skill_get_hit(skill_id);
  4551. type = clif_calc_delay(type,div,damage,ddelay);
  4552. sc = status_get_sc(dst);
  4553. if(sc && sc->count) {
  4554. if(sc->data[SC_HALLUCINATION] && damage)
  4555. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4556. }
  4557. WBUFW(buf,0)=0x115;
  4558. WBUFW(buf,2)=skill_id;
  4559. WBUFL(buf,4)=src->id;
  4560. WBUFL(buf,8)=dst->id;
  4561. WBUFL(buf,12)=tick;
  4562. WBUFL(buf,16)=sdelay;
  4563. WBUFL(buf,20)=ddelay;
  4564. WBUFW(buf,24)=dst->x;
  4565. WBUFW(buf,26)=dst->y;
  4566. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4567. WBUFW(buf,28)=damage?div:0;
  4568. } else {
  4569. WBUFW(buf,28)=damage;
  4570. }
  4571. WBUFW(buf,30)=skill_lv;
  4572. WBUFW(buf,32)=div;
  4573. WBUFB(buf,34)=type;
  4574. clif_send(buf,packet_len(0x115),src,AREA);
  4575. if(disguised(src)) {
  4576. WBUFL(buf,4)=-src->id;
  4577. if(damage > 0)
  4578. WBUFW(buf,28)=-1;
  4579. clif_send(buf,packet_len(0x115),src,SELF);
  4580. }
  4581. if (disguised(dst)) {
  4582. WBUFL(buf,8)=-dst->id;
  4583. if (disguised(src))
  4584. WBUFL(buf,4)=src->id;
  4585. else if(damage > 0)
  4586. WBUFW(buf,28)=-1;
  4587. clif_send(buf,packet_len(0x115),dst,SELF);
  4588. }
  4589. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4590. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4591. }
  4592. */
  4593. /// Non-damaging skill effect (ZC_USE_SKILL).
  4594. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4595. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4596. {
  4597. unsigned char buf[32];
  4598. nullpo_ret(dst);
  4599. WBUFW(buf,0)=0x11a;
  4600. WBUFW(buf,2)=skill_id;
  4601. WBUFW(buf,4)=min(heal, INT16_MAX);
  4602. WBUFL(buf,6)=dst->id;
  4603. WBUFL(buf,10)=src?src->id:0;
  4604. WBUFB(buf,14)=fail;
  4605. if (disguised(dst)) {
  4606. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4607. WBUFL(buf,6)=-dst->id;
  4608. clif_send(buf,packet_len(0x11a),dst,SELF);
  4609. } else
  4610. clif_send(buf,packet_len(0x11a),dst,AREA);
  4611. if(src && disguised(src)) {
  4612. WBUFL(buf,10)=-src->id;
  4613. if (disguised(dst))
  4614. WBUFL(buf,6)=dst->id;
  4615. clif_send(buf,packet_len(0x11a),src,SELF);
  4616. }
  4617. return fail;
  4618. }
  4619. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4620. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4621. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4622. {
  4623. unsigned char buf[32];
  4624. nullpo_retv(src);
  4625. WBUFW(buf,0)=0x117;
  4626. WBUFW(buf,2)=skill_id;
  4627. WBUFL(buf,4)=src->id;
  4628. WBUFW(buf,8)=val;
  4629. WBUFW(buf,10)=x;
  4630. WBUFW(buf,12)=y;
  4631. WBUFL(buf,14)=tick;
  4632. if(disguised(src)) {
  4633. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4634. WBUFL(buf,4)=-src->id;
  4635. clif_send(buf,packet_len(0x117),src,SELF);
  4636. } else
  4637. clif_send(buf,packet_len(0x117),src,AREA);
  4638. }
  4639. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4640. /// 011c <skill id>.W { <map name>.16B }*4
  4641. 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)
  4642. {
  4643. int fd;
  4644. nullpo_retv(sd);
  4645. fd = sd->fd;
  4646. WFIFOHEAD(fd,packet_len(0x11c));
  4647. WFIFOW(fd,0) = 0x11c;
  4648. WFIFOW(fd,2) = skill_id;
  4649. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4650. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4651. else // normal map name
  4652. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4653. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4654. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4655. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4656. WFIFOSET(fd,packet_len(0x11c));
  4657. sd->menuskill_id = skill_id;
  4658. if (skill_id == AL_WARP)
  4659. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4660. else
  4661. sd->menuskill_val = skill_lv;
  4662. }
  4663. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4664. /// 011e <type>.B
  4665. /// type:
  4666. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4667. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4668. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4669. ///
  4670. /// @param sd Who receives the message
  4671. /// @param type What message
  4672. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4673. {
  4674. int fd;
  4675. nullpo_retv(sd);
  4676. fd=sd->fd;
  4677. WFIFOHEAD(fd,packet_len(0x11e));
  4678. WFIFOW(fd,0)=0x11e;
  4679. WFIFOB(fd,2)=type;
  4680. WFIFOSET(fd,packet_len(0x11e));
  4681. }
  4682. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4683. /// 0189 <type>.W
  4684. /// type:
  4685. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4686. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4687. ///
  4688. /// @param sd Who receives the message
  4689. /// @param type What message
  4690. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4691. {
  4692. int fd;
  4693. nullpo_retv(sd);
  4694. fd=sd->fd;
  4695. WFIFOHEAD(fd,packet_len(0x189));
  4696. WFIFOW(fd,0)=0x189;
  4697. WFIFOW(fd,2)=type;
  4698. WFIFOSET(fd,packet_len(0x189));
  4699. }
  4700. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4701. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4702. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4703. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4704. {
  4705. struct status_data *status;
  4706. unsigned char buf[64];
  4707. int i;//, fix;
  4708. nullpo_retv(sd);
  4709. nullpo_retv(dst);
  4710. if( dst->type != BL_MOB )
  4711. return;
  4712. status = status_get_status_data(dst);
  4713. WBUFW(buf, 0)=0x18c;
  4714. WBUFW(buf, 2)=status_get_class(dst);
  4715. WBUFW(buf, 4)=status_get_lv(dst);
  4716. WBUFW(buf, 6)=status->size;
  4717. WBUFL(buf, 8)=status->hp;
  4718. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4719. +(battle_config.estimation_type&2?status->def2:0);
  4720. WBUFW(buf,14)=status->race;
  4721. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4722. +(battle_config.estimation_type&2?status->mdef2:0);
  4723. WBUFW(buf,18)= status->def_ele;
  4724. for(i=0;i<9;i++)
  4725. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4726. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4727. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4728. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4729. }
  4730. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4731. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4732. /// material id:
  4733. /// unused by the client
  4734. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4735. {
  4736. int i,c,view,fd;
  4737. nullpo_retv(sd);
  4738. if (sd->menuskill_id == skill_id)
  4739. return; //Avoid resending the menu twice or more times...
  4740. if (skill_id == GC_CREATENEWPOISON)
  4741. skill_id = GC_RESEARCHNEWPOISON;
  4742. fd = sd->fd;
  4743. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4744. WFIFOW(fd, 0) = 0x18d;
  4745. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  4746. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4747. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  4748. )
  4749. {
  4750. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4751. WFIFOW(fd,c*8+ 4) = view;
  4752. else
  4753. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  4754. WFIFOW(fd,c*8+ 6) = 0;
  4755. WFIFOW(fd,c*8+ 8) = 0;
  4756. WFIFOW(fd,c*8+10) = 0;
  4757. c++;
  4758. }
  4759. }
  4760. WFIFOW(fd, 2) = c*8+8;
  4761. WFIFOSET(fd,WFIFOW(fd,2));
  4762. if (c > 0) {
  4763. sd->menuskill_id = skill_id;
  4764. sd->menuskill_val = trigger;
  4765. return;
  4766. }
  4767. }
  4768. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4769. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4770. /// mk type:
  4771. /// 1 = cooking
  4772. /// 2 = arrow
  4773. /// 3 = elemental
  4774. /// 4 = GN_MIX_COOKING
  4775. /// 5 = GN_MAKEBOMB
  4776. /// 6 = GN_S_PHARMACY
  4777. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4778. {
  4779. int fd;
  4780. int i, c;
  4781. int view;
  4782. nullpo_retv(sd);
  4783. fd = sd->fd;
  4784. if(sd->menuskill_id == skill_id)
  4785. return; //Avoid resending the menu twice or more times...
  4786. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4787. WFIFOW(fd,0) = 0x25a;
  4788. WFIFOW(fd,4) = list_type; // list type
  4789. c = 0;
  4790. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4791. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4792. continue;
  4793. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4794. WFIFOW(fd, 6 + 2 * c) = view;
  4795. else
  4796. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4797. c++;
  4798. }
  4799. if( c > 0 || skill_id == AM_PHARMACY) {
  4800. sd->menuskill_id = skill_id;
  4801. sd->menuskill_val = trigger;
  4802. sd->menuskill_val2 = qty; // amount.
  4803. WFIFOW(fd,2) = 6 + 2 * c;
  4804. WFIFOSET(fd,WFIFOW(fd,2));
  4805. } else {
  4806. clif_menuskill_clear(sd);
  4807. #if PACKETVER >= 20090922
  4808. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  4809. #else
  4810. WFIFOW(fd,2) = 6 + 2 * c;
  4811. WFIFOSET(fd,WFIFOW(fd,2));
  4812. #endif
  4813. }
  4814. }
  4815. /// Notifies clients of a status change.
  4816. /// 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)]
  4817. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4818. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  4819. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4820. {
  4821. unsigned char buf[32];
  4822. struct map_session_data *sd;
  4823. if (type == SI_BLANK) //It shows nothing on the client...
  4824. return;
  4825. nullpo_retv(bl);
  4826. sd = BL_CAST(BL_PC, bl);
  4827. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4828. return;
  4829. #if PACKETVER >= 20120618
  4830. if(flag && battle_config.display_status_timers && sd)
  4831. WBUFW(buf,0)=0x983;
  4832. else
  4833. #elif PACKETVER >= 20090121
  4834. if(flag && battle_config.display_status_timers && sd)
  4835. WBUFW(buf,0)=0x43f;
  4836. else
  4837. #endif
  4838. WBUFW(buf,0)=0x196;
  4839. WBUFW(buf,2)=type;
  4840. WBUFL(buf,4)=bl->id;
  4841. WBUFB(buf,8)=flag;
  4842. #if PACKETVER >= 20120618
  4843. if(flag && battle_config.display_status_timers && sd) {
  4844. if (tick <= 0)
  4845. tick = 9999; // this is indeed what official servers do
  4846. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4847. WBUFL(buf,13)=tick;
  4848. WBUFL(buf,17) = val1;
  4849. WBUFL(buf,21) = val2;
  4850. WBUFL(buf,25) = val3;
  4851. }
  4852. #elif PACKETVER >= 20090121
  4853. if(flag && battle_config.display_status_timers && sd) {
  4854. if (tick <= 0)
  4855. tick = 9999; // this is indeed what official servers do
  4856. WBUFL(buf,9) = tick;
  4857. WBUFL(buf,13) = val1;
  4858. WBUFL(buf,17) = val2;
  4859. WBUFL(buf,21) = val3;
  4860. }
  4861. #endif
  4862. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4863. }
  4864. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  4865. unsigned char buf[32];
  4866. if (type == SI_BLANK) //It shows nothing on the client
  4867. return;
  4868. nullpo_retv(bl);
  4869. WBUFW(buf,0) = 0x43f;
  4870. WBUFW(buf,2) = type;
  4871. WBUFL(buf,4) = tid;
  4872. WBUFB(buf,8) = 1;
  4873. WBUFL(buf,9) = 9999;
  4874. WBUFL(buf,13) = val1;
  4875. WBUFL(buf,17) = val2;
  4876. WBUFL(buf,21) = val3;
  4877. clif_send(buf,packet_len(0x43f),bl,target);
  4878. }
  4879. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  4880. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  4881. //! TODO
  4882. //void clif_efst_enter();
  4883. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4884. /// 008e <packet len>.W <message>.?B
  4885. void clif_displaymessage(const int fd, const char* mes)
  4886. {
  4887. nullpo_retv(mes);
  4888. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4889. if (fd == 0)
  4890. ;
  4891. else {
  4892. char *message, *line;
  4893. message = aStrdup(mes);
  4894. line = strtok(message, "\n");
  4895. while(line != NULL) {
  4896. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4897. int len = strnlen(line, 255);
  4898. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4899. WFIFOHEAD(fd, 5 + len);
  4900. WFIFOW(fd,0) = 0x8e;
  4901. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4902. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4903. WFIFOSET(fd, 5 + len);
  4904. }
  4905. line = strtok(NULL, "\n");
  4906. }
  4907. aFree(message);
  4908. }
  4909. }
  4910. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4911. /// 009a <packet len>.W <message>.?B
  4912. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4913. {
  4914. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  4915. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4916. WBUFW(buf,0) = 0x9a;
  4917. WBUFW(buf,2) = 4 + lp + len;
  4918. if (type&BC_BLUE)
  4919. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4920. else if (type&BC_WOE)
  4921. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4922. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4923. clif_send(buf, WBUFW(buf,2), bl, target);
  4924. if (buf)
  4925. aFree(buf);
  4926. }
  4927. /*==========================================
  4928. * Displays a message on a 'bl' to all it's nearby clients
  4929. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4930. *------------------------------------------*/
  4931. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4932. char buf[100];
  4933. int len;
  4934. nullpo_retv(bl);
  4935. if(!message)
  4936. return;
  4937. len = strlen(message)+1;
  4938. if( len > sizeof(buf)-8 ) {
  4939. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4940. len = sizeof(buf)-8;
  4941. }
  4942. WBUFW(buf,0)=0x8d;
  4943. WBUFW(buf,2)=len+8;
  4944. WBUFL(buf,4)=bl->id;
  4945. safestrncpy((char *) WBUFP(buf,8),message,len);
  4946. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4947. }
  4948. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4949. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4950. 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)
  4951. {
  4952. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4953. WBUFW(buf,0) = 0x1c3;
  4954. WBUFW(buf,2) = len + 16;
  4955. WBUFL(buf,4) = fontColor;
  4956. WBUFW(buf,8) = fontType;
  4957. WBUFW(buf,10) = fontSize;
  4958. WBUFW(buf,12) = fontAlign;
  4959. WBUFW(buf,14) = fontY;
  4960. memcpy(WBUFP(buf,16), mes, len);
  4961. clif_send(buf, WBUFW(buf,2), bl, target);
  4962. if (buf)
  4963. aFree(buf);
  4964. }
  4965. /*
  4966. * Display *msg from *sd to all *users in channel
  4967. */
  4968. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4969. DBIterator *iter;
  4970. struct map_session_data *user;
  4971. unsigned short msg_len = strlen(msg) + 1;
  4972. WFIFOHEAD(sd->fd,msg_len + 12);
  4973. WFIFOW(sd->fd,0) = 0x2C1;
  4974. WFIFOW(sd->fd,2) = msg_len + 12;
  4975. WFIFOL(sd->fd,4) = 0;
  4976. WFIFOL(sd->fd,8) = channel_config.colors[color];
  4977. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4978. iter = db_iterator(channel->users);
  4979. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4980. if( user->fd == sd->fd )
  4981. continue;
  4982. WFIFOHEAD(user->fd,msg_len + 12);
  4983. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4984. WFIFOSET(user->fd, msg_len + 12);
  4985. }
  4986. dbi_destroy(iter);
  4987. WFIFOSET(sd->fd, msg_len + 12);
  4988. }
  4989. /// Displays heal effect (ZC_RECOVERY).
  4990. /// 013d <var id>.W <amount>.W
  4991. /// var id:
  4992. /// 5 = HP (SP_HP)
  4993. /// 7 = SP (SP_SP)
  4994. /// ? = ignored
  4995. void clif_heal(int fd,int type,int val)
  4996. {
  4997. WFIFOHEAD(fd,packet_len(0x13d));
  4998. WFIFOW(fd,0)=0x13d;
  4999. WFIFOW(fd,2)=type;
  5000. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  5001. WFIFOSET(fd,packet_len(0x13d));
  5002. }
  5003. /// Displays resurrection effect (ZC_RESURRECTION).
  5004. /// 0148 <id>.L <type>.W
  5005. /// type:
  5006. /// ignored
  5007. void clif_resurrection(struct block_list *bl,int type)
  5008. {
  5009. unsigned char buf[16];
  5010. nullpo_retv(bl);
  5011. WBUFW(buf,0)=0x148;
  5012. WBUFL(buf,2)=bl->id;
  5013. WBUFW(buf,6)=0;
  5014. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5015. if (disguised(bl))
  5016. clif_spawn(bl);
  5017. }
  5018. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5019. /// 0199 <type>.W
  5020. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5021. {
  5022. int fd;
  5023. nullpo_retv(sd);
  5024. fd=sd->fd;
  5025. WFIFOHEAD(fd,packet_len(0x199));
  5026. WFIFOW(fd,0)=0x199;
  5027. WFIFOW(fd,2)=property;
  5028. WFIFOSET(fd,packet_len(0x199));
  5029. }
  5030. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5031. #if PACKETVER >= 20121010
  5032. unsigned char buf[8];
  5033. unsigned int NotifyProperty =
  5034. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5035. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5036. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5037. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5038. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5039. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5040. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5041. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5042. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5043. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5044. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5045. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5046. WBUFW(buf,0)=0x99b;
  5047. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5048. WBUFL(buf,4)=NotifyProperty;
  5049. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5050. clif_send(buf,packet_len(0x99b),bl,t);
  5051. #endif
  5052. }
  5053. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5054. /// 01d6 <type>.W
  5055. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5056. {
  5057. int fd;
  5058. nullpo_retv(sd);
  5059. fd=sd->fd;
  5060. WFIFOHEAD(fd,packet_len(0x1D6));
  5061. WFIFOW(fd,0)=0x1D6;
  5062. WFIFOW(fd,2)=type;
  5063. WFIFOSET(fd,packet_len(0x1D6));
  5064. }
  5065. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5066. /// 019a <id>.L <ranking>.L <total>.L
  5067. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5068. {
  5069. if(type == 2) {
  5070. int fd = sd->fd;
  5071. WFIFOHEAD(fd,packet_len(0x19a));
  5072. WFIFOW(fd,0) = 0x19a;
  5073. WFIFOL(fd,2) = sd->bl.id;
  5074. WFIFOL(fd,6) = pvprank;
  5075. WFIFOL(fd,10) = pvpnum;
  5076. WFIFOSET(fd,packet_len(0x19a));
  5077. } else {
  5078. unsigned char buf[32];
  5079. WBUFW(buf,0) = 0x19a;
  5080. WBUFL(buf,2) = sd->bl.id;
  5081. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5082. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5083. else
  5084. WBUFL(buf,6) = pvprank;
  5085. WBUFL(buf,10) = pvpnum;
  5086. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5087. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5088. else if(!type)
  5089. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5090. else
  5091. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5092. }
  5093. }
  5094. /*==========================================
  5095. *
  5096. *------------------------------------------*/
  5097. void clif_map_property_mapall(int map_idx, enum map_property property)
  5098. {
  5099. struct block_list bl;
  5100. unsigned char buf[16];
  5101. bl.id = 0;
  5102. bl.type = BL_NUL;
  5103. bl.m = map_idx;
  5104. WBUFW(buf,0)=0x199;
  5105. WBUFW(buf,2)=property;
  5106. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5107. }
  5108. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5109. /// 0188 <result>.W <index>.W <refine>.W
  5110. /// result:
  5111. /// 0 = success
  5112. /// 1 = failure
  5113. /// 2 = downgrade
  5114. void clif_refine(int fd, int fail, int index, int val)
  5115. {
  5116. WFIFOHEAD(fd,packet_len(0x188));
  5117. WFIFOW(fd,0)=0x188;
  5118. WFIFOW(fd,2)=fail;
  5119. WFIFOW(fd,4)=index+2;
  5120. WFIFOW(fd,6)=val;
  5121. WFIFOSET(fd,packet_len(0x188));
  5122. }
  5123. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5124. /// 0223 <result>.L <nameid>.W
  5125. /// result:
  5126. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5127. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5128. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5129. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5130. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5131. {
  5132. WFIFOHEAD(fd,packet_len(0x223));
  5133. WFIFOW(fd,0)=0x223;
  5134. WFIFOL(fd,2)=result;
  5135. WFIFOW(fd,6)=item_id;
  5136. WFIFOSET(fd,packet_len(0x223));
  5137. }
  5138. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5139. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5140. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5141. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5142. {
  5143. #if PACKETVER < 20091104
  5144. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5145. WFIFOW(fd,0) = 0x97;
  5146. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5147. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5148. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5149. WFIFOSET(fd,WFIFOW(fd,2));
  5150. #else
  5151. struct map_session_data *ssd = map_nick2sd(nick);
  5152. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5153. WFIFOW(fd,0) = 0x97;
  5154. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5155. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5156. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5157. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5158. WFIFOSET(fd,WFIFOW(fd,2));
  5159. #endif
  5160. }
  5161. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5162. /// 0098 <result>.B
  5163. /// result:
  5164. /// 0 = success to send wisper
  5165. /// 1 = target character is not loged in
  5166. /// 2 = ignored by target
  5167. /// 3 = everyone ignored by target
  5168. void clif_wis_end(int fd, int result)
  5169. {
  5170. struct map_session_data *sd = (session_isValid(fd) ? session[fd]->session_data : NULL);
  5171. if (!sd)
  5172. return;
  5173. #if PACKETVER >= 20131223
  5174. WFIFOHEAD(fd,packet_len(0x9df));
  5175. WFIFOW(fd,0) = 0x9df;
  5176. WFIFOB(fd,2) = (char)result;
  5177. WFIFOL(fd,3) = 0;
  5178. WFIFOSET(fd,packet_len(0x9df));
  5179. #else
  5180. WFIFOHEAD(fd,packet_len(0x98));
  5181. WFIFOW(fd,0) = 0x98;
  5182. WFIFOB(fd,2) = (char)result;
  5183. WFIFOSET(fd,packet_len(0x98));
  5184. #endif
  5185. }
  5186. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5187. /// 0194 <char id>.L <name>.24B
  5188. void clif_solved_charname(int fd, int charid, const char* name)
  5189. {
  5190. WFIFOHEAD(fd,packet_len(0x194));
  5191. WFIFOW(fd,0)=0x194;
  5192. WFIFOL(fd,2)=charid;
  5193. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5194. WFIFOSET(fd,packet_len(0x194));
  5195. }
  5196. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5197. /// 017b <packet len>.W { <name id>.W }*
  5198. void clif_use_card(struct map_session_data *sd,int idx)
  5199. {
  5200. int i,c,ep;
  5201. int fd=sd->fd;
  5202. nullpo_retv(sd);
  5203. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5204. return;
  5205. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5206. return; //Avoid parsing invalid item indexes (no card/no item)
  5207. ep=sd->inventory_data[idx]->equip;
  5208. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5209. WFIFOW(fd,0)=0x17b;
  5210. for(i=c=0;i<MAX_INVENTORY;i++){
  5211. int j;
  5212. if(sd->inventory_data[i] == NULL)
  5213. continue;
  5214. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5215. continue;
  5216. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5217. continue;
  5218. if(sd->status.inventory[i].identify==0 ) //Not identified
  5219. continue;
  5220. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5221. continue;
  5222. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5223. continue;
  5224. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5225. if( j == sd->inventory_data[i]->slot ) // No room
  5226. continue;
  5227. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5228. continue;
  5229. WFIFOW(fd,4+c*2)=i+2;
  5230. c++;
  5231. }
  5232. if( !c ) return; // no item is available for card insertion
  5233. WFIFOW(fd,2)=4+c*2;
  5234. WFIFOSET(fd,WFIFOW(fd,2));
  5235. }
  5236. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5237. /// 017d <equip index>.W <card index>.W <result>.B
  5238. /// result:
  5239. /// 0 = success
  5240. /// 1 = failure
  5241. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5242. {
  5243. int fd;
  5244. nullpo_retv(sd);
  5245. fd=sd->fd;
  5246. WFIFOHEAD(fd,packet_len(0x17d));
  5247. WFIFOW(fd,0)=0x17d;
  5248. WFIFOW(fd,2)=idx_equip+2;
  5249. WFIFOW(fd,4)=idx_card+2;
  5250. WFIFOB(fd,6)=flag;
  5251. WFIFOSET(fd,packet_len(0x17d));
  5252. }
  5253. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5254. /// 0177 <packet len>.W { <name id>.W }*
  5255. void clif_item_identify_list(struct map_session_data *sd)
  5256. {
  5257. int i,c;
  5258. int fd;
  5259. nullpo_retv(sd);
  5260. fd=sd->fd;
  5261. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5262. WFIFOW(fd,0)=0x177;
  5263. for(i=c=0;i<MAX_INVENTORY;i++){
  5264. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5265. WFIFOW(fd,c*2+4)=i+2;
  5266. c++;
  5267. }
  5268. }
  5269. if(c > 0) {
  5270. WFIFOW(fd,2)=c*2+4;
  5271. WFIFOSET(fd,WFIFOW(fd,2));
  5272. sd->menuskill_id = MC_IDENTIFY;
  5273. sd->menuskill_val = c;
  5274. }
  5275. }
  5276. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5277. /// 0179 <index>.W <result>.B
  5278. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5279. {
  5280. int fd;
  5281. nullpo_retv(sd);
  5282. fd=sd->fd;
  5283. WFIFOHEAD(fd,packet_len(0x179));
  5284. WFIFOW(fd, 0)=0x179;
  5285. WFIFOW(fd, 2)=idx+2;
  5286. WFIFOB(fd, 4)=flag;
  5287. WFIFOSET(fd,packet_len(0x179));
  5288. }
  5289. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5290. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5291. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5292. {
  5293. int i,c;
  5294. int fd;
  5295. nullpo_retv(sd);
  5296. nullpo_retv(dstsd);
  5297. fd=sd->fd;
  5298. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5299. WFIFOW(fd,0)=0x1fc;
  5300. for(i=c=0;i<MAX_INVENTORY;i++){
  5301. unsigned short nameid;
  5302. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5303. WFIFOW(fd,c*13+4) = i;
  5304. WFIFOW(fd,c*13+6) = nameid;
  5305. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5306. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5307. c++;
  5308. }
  5309. }
  5310. if(c > 0) {
  5311. WFIFOW(fd,2)=c*13+4;
  5312. WFIFOSET(fd,WFIFOW(fd,2));
  5313. sd->menuskill_id = BS_REPAIRWEAPON;
  5314. sd->menuskill_val = dstsd->bl.id;
  5315. sd->menuskill_val2 = lv;
  5316. }else
  5317. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5318. }
  5319. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5320. /// 01fe <index>.W <result>.B
  5321. /// index:
  5322. /// ignored (inventory index)
  5323. /// result:
  5324. /// 0 = Item repair success.
  5325. /// 1 = Item repair failure.
  5326. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5327. {
  5328. int fd;
  5329. nullpo_retv(sd);
  5330. fd = sd->fd;
  5331. WFIFOHEAD(fd,packet_len(0x1fe));
  5332. WFIFOW(fd, 0)=0x1fe;
  5333. WFIFOW(fd, 2)=idx+2;
  5334. WFIFOB(fd, 4)=flag;
  5335. WFIFOSET(fd,packet_len(0x1fe));
  5336. }
  5337. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5338. /// 02bb <equip location>.W <account id>.L
  5339. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5340. {
  5341. int fd = sd->fd;
  5342. WFIFOHEAD(fd,packet_len(0x2bb));
  5343. WFIFOW(fd,0) = 0x2bb;
  5344. WFIFOW(fd,2) = position;
  5345. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5346. WFIFOSET(fd,packet_len(0x2bb));
  5347. }
  5348. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5349. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5350. void clif_item_refine_list(struct map_session_data *sd)
  5351. {
  5352. int i,c;
  5353. int fd;
  5354. uint16 skill_lv;
  5355. int refine_item[5];
  5356. nullpo_retv(sd);
  5357. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5358. fd=sd->fd;
  5359. refine_item[0] = -1;
  5360. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5361. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5362. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5363. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5364. WFIFOW(fd,0)=0x221;
  5365. for(i=c=0;i<MAX_INVENTORY;i++){
  5366. unsigned char wlv;
  5367. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5368. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5369. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5370. WFIFOW(fd,c*13+ 4)=i+2;
  5371. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5372. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5373. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5374. c++;
  5375. }
  5376. }
  5377. WFIFOW(fd,2)=c*13+4;
  5378. WFIFOSET(fd,WFIFOW(fd,2));
  5379. if (c > 0) {
  5380. sd->menuskill_id = WS_WEAPONREFINE;
  5381. sd->menuskill_val = skill_lv;
  5382. }
  5383. }
  5384. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5385. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5386. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5387. {
  5388. int fd;
  5389. nullpo_retv(sd);
  5390. fd=sd->fd;
  5391. WFIFOHEAD(fd,packet_len(0x147));
  5392. WFIFOW(fd, 0)=0x147;
  5393. WFIFOW(fd, 2)=skill_id;
  5394. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5395. WFIFOW(fd, 6)=0;
  5396. WFIFOW(fd, 8)=skill_lv;
  5397. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5398. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5399. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5400. WFIFOB(fd,38)=0;
  5401. WFIFOSET(fd,packet_len(0x147));
  5402. }
  5403. /// Adds an item to character's cart.
  5404. /// 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)
  5405. /// 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)
  5406. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5407. {
  5408. int view,fd;
  5409. unsigned char *buf;
  5410. nullpo_retv(sd);
  5411. fd=sd->fd;
  5412. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5413. return;
  5414. #if PACKETVER < 5
  5415. WFIFOHEAD(fd,packet_len(0x124));
  5416. buf=WFIFOP(fd,0);
  5417. WBUFW(buf,0)=0x124;
  5418. WBUFW(buf,2)=n+2;
  5419. WBUFL(buf,4)=amount;
  5420. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5421. WBUFW(buf,8)=view;
  5422. else
  5423. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5424. WBUFB(buf,10)=sd->status.cart[n].identify;
  5425. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5426. WBUFB(buf,12)=sd->status.cart[n].refine;
  5427. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5428. WFIFOSET(fd,packet_len(0x124));
  5429. #else
  5430. WFIFOHEAD(fd,packet_len(0x1c5));
  5431. buf=WFIFOP(fd,0);
  5432. WBUFW(buf,0)=0x1c5;
  5433. WBUFW(buf,2)=n+2;
  5434. WBUFL(buf,4)=amount;
  5435. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5436. WBUFW(buf,8)=view;
  5437. else
  5438. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5439. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5440. WBUFB(buf,11)=sd->status.cart[n].identify;
  5441. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5442. WBUFB(buf,13)=sd->status.cart[n].refine;
  5443. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5444. WFIFOSET(fd,packet_len(0x1c5));
  5445. #endif
  5446. }
  5447. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5448. /* Acknowledge an item have been added to cart
  5449. * 012c <result>B
  5450. * result :
  5451. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5452. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5453. */
  5454. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5455. {
  5456. int fd;
  5457. unsigned char *buf;
  5458. nullpo_retv(sd);
  5459. fd = sd->fd;
  5460. buf = WFIFOP(fd,0);
  5461. WBUFW(buf,0) = 0x12c;
  5462. WBUFB(buf,2) = flag;
  5463. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5464. }
  5465. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5466. void clif_bank_open(struct map_session_data *sd){
  5467. int fd;
  5468. nullpo_retv(sd);
  5469. fd = sd->fd;
  5470. WFIFOHEAD(fd,4);
  5471. WFIFOW(fd,0) = 0x09b7;
  5472. WFIFOW(fd,2) = 0;
  5473. WFIFOSET(fd,4);
  5474. }
  5475. /*
  5476. * Request to Open the banking system
  5477. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5478. */
  5479. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5480. //TODO check if preventing trade or stuff like that
  5481. //also mark something in case char ain't available for saving, should we check now ?
  5482. nullpo_retv(sd);
  5483. if( !battle_config.feature_banking ) {
  5484. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5485. return;
  5486. }
  5487. else {
  5488. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5489. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5490. if(sd->status.account_id == aid){
  5491. sd->state.banking = 1;
  5492. //request save ?
  5493. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5494. //on succes open bank ?
  5495. clif_bank_open(sd);
  5496. }
  5497. }
  5498. }
  5499. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5500. void clif_bank_close(struct map_session_data *sd){
  5501. int fd;
  5502. nullpo_retv(sd);
  5503. fd = sd->fd;
  5504. WFIFOHEAD(fd,4);
  5505. WFIFOW(fd,0) = 0x09B9;
  5506. WFIFOW(fd,2) = 0;
  5507. WFIFOSET(fd,4);
  5508. }
  5509. /*
  5510. * Request to close the banking system
  5511. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5512. */
  5513. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5514. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5515. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5516. nullpo_retv(sd);
  5517. if( !battle_config.feature_banking ) {
  5518. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5519. //still allow to go trough to not stuck player if we have disable it while they was in
  5520. }
  5521. if(sd->status.account_id == aid){
  5522. sd->state.banking = 0;
  5523. clif_bank_close(sd);
  5524. }
  5525. }
  5526. /*
  5527. * Display how much we got in bank (I suppose)
  5528. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5529. */
  5530. void clif_Bank_Check(struct map_session_data* sd) {
  5531. unsigned char buf[13];
  5532. struct s_packet_db* info;
  5533. int16 len;
  5534. int cmd = 0;
  5535. nullpo_retv(sd);
  5536. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5537. if(!cmd) cmd = 0x09A6; //default
  5538. info = &packet_db[sd->packet_ver][cmd];
  5539. len = info->len;
  5540. if(!len) return; //version as packet disable
  5541. // sd->state.banking = 1; //mark opening and closing
  5542. WBUFW(buf,0) = cmd;
  5543. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5544. WBUFW(buf,info->pos[1]) = 0; //reason
  5545. clif_send(buf,len,&sd->bl,SELF);
  5546. }
  5547. /*
  5548. * Requesting the data in bank
  5549. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5550. */
  5551. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5552. nullpo_retv(sd);
  5553. if( !battle_config.feature_banking ) {
  5554. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5555. return;
  5556. }
  5557. else {
  5558. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5559. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5560. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5561. clif_Bank_Check(sd);
  5562. }
  5563. }
  5564. /*
  5565. * Acknowledge of deposit some money in bank
  5566. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5567. */
  5568. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5569. unsigned char buf[17];
  5570. struct s_packet_db* info;
  5571. int16 len;
  5572. int cmd =0;
  5573. nullpo_retv(sd);
  5574. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5575. if(!cmd) cmd = 0x09A8;
  5576. info = &packet_db[sd->packet_ver][cmd];
  5577. len = info->len;
  5578. if(!len) return; //version as packet disable
  5579. WBUFW(buf,0) = cmd;
  5580. WBUFW(buf,info->pos[0]) = (short)reason;
  5581. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5582. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5583. clif_send(buf,len,&sd->bl,SELF);
  5584. }
  5585. /*
  5586. * Request saving some money in bank
  5587. * @author : original [Yommy/Hercules]
  5588. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5589. */
  5590. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5591. nullpo_retv(sd);
  5592. if( !battle_config.feature_banking ) {
  5593. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5594. return;
  5595. }
  5596. else {
  5597. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5598. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5599. int money = RFIFOL(fd,info->pos[1]);
  5600. if(sd->status.account_id == aid){
  5601. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5602. clif_bank_deposit(sd,reason);
  5603. }
  5604. }
  5605. }
  5606. /*
  5607. * Acknowledge of withdrawing some money from bank
  5608. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5609. */
  5610. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5611. unsigned char buf[17];
  5612. struct s_packet_db* info;
  5613. int16 len;
  5614. int cmd;
  5615. nullpo_retv(sd);
  5616. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5617. if(!cmd) cmd = 0x09AA;
  5618. info = &packet_db[sd->packet_ver][cmd];
  5619. len = info->len;
  5620. if(!len) return; //version as packet disable
  5621. WBUFW(buf,0) = cmd;
  5622. WBUFW(buf,info->pos[0]) = (short)reason;
  5623. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5624. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5625. clif_send(buf,len,&sd->bl,SELF);
  5626. }
  5627. /*
  5628. * Request Withdrawing some money from bank
  5629. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5630. */
  5631. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5632. nullpo_retv(sd);
  5633. if( !battle_config.feature_banking ) {
  5634. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5635. return;
  5636. }
  5637. else {
  5638. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5639. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5640. int money = RFIFOL(fd,info->pos[1]);
  5641. if(sd->status.account_id == aid){
  5642. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5643. clif_bank_withdraw(sd,reason);
  5644. }
  5645. }
  5646. }
  5647. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5648. /// 0125 <index>.W <amount>.L
  5649. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5650. {
  5651. int fd;
  5652. nullpo_retv(sd);
  5653. fd=sd->fd;
  5654. WFIFOHEAD(fd,packet_len(0x125));
  5655. WFIFOW(fd,0)=0x125;
  5656. WFIFOW(fd,2)=n+2;
  5657. WFIFOL(fd,4)=amount;
  5658. WFIFOSET(fd,packet_len(0x125));
  5659. }
  5660. /// Opens the shop creation menu (ZC_OPENSTORE).
  5661. /// 012d <num>.W
  5662. /// num:
  5663. /// number of allowed item slots
  5664. void clif_openvendingreq(struct map_session_data* sd, int num)
  5665. {
  5666. int fd;
  5667. nullpo_retv(sd);
  5668. fd = sd->fd;
  5669. WFIFOHEAD(fd,packet_len(0x12d));
  5670. WFIFOW(fd,0) = 0x12d;
  5671. WFIFOW(fd,2) = num;
  5672. WFIFOSET(fd,packet_len(0x12d));
  5673. }
  5674. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5675. /// 0131 <owner id>.L <message>.80B
  5676. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5677. {
  5678. unsigned char buf[128];
  5679. nullpo_retv(bl);
  5680. WBUFW(buf,0) = 0x131;
  5681. WBUFL(buf,2) = bl->id;
  5682. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5683. if( fd ) {
  5684. WFIFOHEAD(fd,packet_len(0x131));
  5685. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5686. WFIFOSET(fd,packet_len(0x131));
  5687. } else {
  5688. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5689. }
  5690. }
  5691. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5692. /// 0132 <owner id>.L
  5693. void clif_closevendingboard(struct block_list* bl, int fd)
  5694. {
  5695. unsigned char buf[16];
  5696. nullpo_retv(bl);
  5697. WBUFW(buf,0) = 0x132;
  5698. WBUFL(buf,2) = bl->id;
  5699. if( fd ) {
  5700. WFIFOHEAD(fd,packet_len(0x132));
  5701. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5702. WFIFOSET(fd,packet_len(0x132));
  5703. } else {
  5704. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5705. }
  5706. }
  5707. /// Sends a list of items in a shop.
  5708. /// 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)
  5709. /// 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)
  5710. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5711. {
  5712. int i,fd;
  5713. int count;
  5714. struct map_session_data* vsd;
  5715. #if PACKETVER < 20100105
  5716. const int cmd = 0x133;
  5717. const int offset = 8;
  5718. #else
  5719. const int cmd = 0x800;
  5720. const int offset = 12;
  5721. #endif
  5722. nullpo_retv(sd);
  5723. nullpo_retv(vending);
  5724. nullpo_retv(vsd=map_id2sd(id));
  5725. fd = sd->fd;
  5726. count = vsd->vend_num;
  5727. WFIFOHEAD(fd, offset+count*22);
  5728. WFIFOW(fd,0) = cmd;
  5729. WFIFOW(fd,2) = offset+count*22;
  5730. WFIFOL(fd,4) = id;
  5731. #if PACKETVER >= 20100105
  5732. WFIFOL(fd,8) = vsd->vender_id;
  5733. #endif
  5734. for( i = 0; i < count; i++ )
  5735. {
  5736. int index = vending[i].index;
  5737. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5738. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5739. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5740. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5741. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5742. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5743. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5744. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5745. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5746. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5747. }
  5748. WFIFOSET(fd,WFIFOW(fd,2));
  5749. }
  5750. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5751. /// 0135 <index>.W <amount>.W <result>.B
  5752. /// result:
  5753. /// 0 = success
  5754. /// 1 = not enough zeny
  5755. /// 2 = overweight
  5756. /// 4 = out of stock
  5757. /// 5 = "cannot use an npc shop while in a trade"
  5758. /// 6 = Because the store information was incorrect the item was not purchased.
  5759. /// 7 = No sales information.
  5760. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5761. {
  5762. int fd;
  5763. nullpo_retv(sd);
  5764. fd = sd->fd;
  5765. WFIFOHEAD(fd,packet_len(0x135));
  5766. WFIFOW(fd,0) = 0x135;
  5767. WFIFOW(fd,2) = index+2;
  5768. WFIFOW(fd,4) = amount;
  5769. WFIFOB(fd,6) = fail;
  5770. WFIFOSET(fd,packet_len(0x135));
  5771. }
  5772. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5773. /// 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 }*
  5774. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5775. {
  5776. int i,fd;
  5777. int count;
  5778. nullpo_retv(sd);
  5779. fd = sd->fd;
  5780. count = sd->vend_num;
  5781. WFIFOHEAD(fd, 8+count*22);
  5782. WFIFOW(fd,0) = 0x136;
  5783. WFIFOW(fd,2) = 8+count*22;
  5784. WFIFOL(fd,4) = id;
  5785. for( i = 0; i < count; i++ ) {
  5786. int index = vending[i].index;
  5787. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5788. WFIFOL(fd, 8+i*22) = vending[i].value;
  5789. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5790. WFIFOW(fd,14+i*22) = vending[i].amount;
  5791. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5792. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5793. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5794. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5795. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5796. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5797. }
  5798. WFIFOSET(fd,WFIFOW(fd,2));
  5799. }
  5800. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5801. /// 0137 <index>.W <amount>.W
  5802. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5803. {
  5804. int fd;
  5805. nullpo_retv(sd);
  5806. fd = sd->fd;
  5807. WFIFOHEAD(fd,packet_len(0x137));
  5808. WFIFOW(fd,0) = 0x137;
  5809. WFIFOW(fd,2) = index+2;
  5810. WFIFOW(fd,4) = amount;
  5811. WFIFOSET(fd,packet_len(0x137));
  5812. }
  5813. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5814. /// 00fa <result>.B
  5815. /// result:
  5816. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5817. /// 1 = MsgStringTable[78]="party name already exists"
  5818. /// 2 = MsgStringTable[79]="already in a party"
  5819. /// 3 = cannot organize parties on this map
  5820. /// ? = nothing
  5821. void clif_party_created(struct map_session_data *sd,int result)
  5822. {
  5823. int fd;
  5824. nullpo_retv(sd);
  5825. fd=sd->fd;
  5826. WFIFOHEAD(fd,packet_len(0xfa));
  5827. WFIFOW(fd,0)=0xfa;
  5828. WFIFOB(fd,2)=result;
  5829. WFIFOSET(fd,packet_len(0xfa));
  5830. }
  5831. /// Adds new member to a party.
  5832. /// 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)
  5833. /// 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)
  5834. /// role:
  5835. /// 0 = leader
  5836. /// 1 = normal
  5837. /// state:
  5838. /// 0 = connected
  5839. /// 1 = disconnected
  5840. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5841. {
  5842. unsigned char buf[81];
  5843. int i;
  5844. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5845. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5846. } else {
  5847. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5848. }
  5849. if (i >= MAX_PARTY) return; //Should never happen...
  5850. sd = p->data[i].sd;
  5851. WBUFW(buf, 0) = 0x1e9;
  5852. WBUFL(buf, 2) = sd->status.account_id;
  5853. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5854. WBUFW(buf,10) = sd->bl.x;
  5855. WBUFW(buf,12) = sd->bl.y;
  5856. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5857. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5858. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5859. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  5860. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5861. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5862. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5863. }
  5864. /// Sends party information (ZC_GROUP_LIST).
  5865. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5866. /// role:
  5867. /// 0 = leader
  5868. /// 1 = normal
  5869. /// state:
  5870. /// 0 = connected
  5871. /// 1 = disconnected
  5872. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5873. {
  5874. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5875. struct map_session_data* party_sd = NULL;
  5876. int i, c;
  5877. nullpo_retv(p);
  5878. WBUFW(buf,0) = 0xfb;
  5879. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5880. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5881. {
  5882. struct party_member* m = &p->party.member[i];
  5883. if(!m->account_id) continue;
  5884. if(party_sd == NULL) party_sd = p->data[i].sd;
  5885. WBUFL(buf,28+c*46) = m->account_id;
  5886. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5887. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5888. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5889. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5890. c++;
  5891. }
  5892. WBUFW(buf,2) = 28+c*46;
  5893. if(sd) { // send only to self
  5894. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5895. } else if (party_sd) { // send to whole party
  5896. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5897. }
  5898. }
  5899. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5900. /// 02c9 <flag>.B
  5901. /// flag:
  5902. /// 0 = allow party invites
  5903. /// 1 = auto-deny party invites
  5904. void clif_partyinvitationstate(struct map_session_data* sd)
  5905. {
  5906. int fd;
  5907. nullpo_retv(sd);
  5908. fd = sd->fd;
  5909. WFIFOHEAD(fd, packet_len(0x2c9));
  5910. WFIFOW(fd, 0) = 0x2c9;
  5911. WFIFOB(fd, 2) = 0; // not implemented
  5912. WFIFOSET(fd, packet_len(0x2c9));
  5913. }
  5914. /// Party invitation request.
  5915. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5916. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5917. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5918. {
  5919. #if PACKETVER < 20070821
  5920. const int cmd = 0xfe;
  5921. #else
  5922. const int cmd = 0x2c6;
  5923. #endif
  5924. int fd;
  5925. struct party_data *p;
  5926. nullpo_retv(sd);
  5927. nullpo_retv(tsd);
  5928. fd=tsd->fd;
  5929. if( (p=party_search(sd->status.party_id))==NULL )
  5930. return;
  5931. WFIFOHEAD(fd,packet_len(cmd));
  5932. WFIFOW(fd,0)=cmd;
  5933. WFIFOL(fd,2)=sd->status.party_id;
  5934. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5935. WFIFOSET(fd,packet_len(cmd));
  5936. }
  5937. /// Party invite result.
  5938. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5939. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5940. /// result=0 : char is already in a party -> MsgStringTable[80]
  5941. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5942. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5943. /// result=3 : party is full -> MsgStringTable[83]
  5944. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5945. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5946. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5947. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5948. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5949. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5950. {
  5951. int fd;
  5952. nullpo_retv(sd);
  5953. fd=sd->fd;
  5954. #if PACKETVER < 20070904
  5955. if( result == 7 ) {
  5956. clif_displaymessage(fd, msg_txt(sd,3));
  5957. return;
  5958. }
  5959. #endif
  5960. #if PACKETVER < 20070821
  5961. WFIFOHEAD(fd,packet_len(0xfd));
  5962. WFIFOW(fd,0) = 0xfd;
  5963. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5964. WFIFOB(fd,26) = result;
  5965. WFIFOSET(fd,packet_len(0xfd));
  5966. #else
  5967. WFIFOHEAD(fd,packet_len(0x2c5));
  5968. WFIFOW(fd,0) = 0x2c5;
  5969. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5970. WFIFOL(fd,26) = result;
  5971. WFIFOSET(fd,packet_len(0x2c5));
  5972. #endif
  5973. }
  5974. /// Updates party settings.
  5975. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5976. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5977. /// exp option:
  5978. /// 0 = exp sharing disabled
  5979. /// 1 = exp sharing enabled
  5980. /// 2 = cannot change exp sharing
  5981. ///
  5982. /// flag:
  5983. /// 0 = send to party
  5984. /// 1 = send to sd
  5985. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5986. {
  5987. unsigned char buf[16];
  5988. #if PACKETVER < 20090603
  5989. const int cmd = 0x101;
  5990. #else
  5991. const int cmd = 0x7d8;
  5992. #endif
  5993. nullpo_retv(p);
  5994. if(!sd && flag==0){
  5995. int i;
  5996. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5997. if (i < MAX_PARTY)
  5998. sd = p->data[i].sd;
  5999. }
  6000. if(!sd) return;
  6001. WBUFW(buf,0)=cmd;
  6002. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6003. #if PACKETVER >= 20090603
  6004. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6005. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6006. #endif
  6007. if(flag==0)
  6008. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6009. else
  6010. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6011. }
  6012. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6013. /// result:
  6014. /// 0 = leave
  6015. /// 1 = expel
  6016. /// 2 = cannot leave party on this map
  6017. /// 3 = cannot expel from party on this map
  6018. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  6019. {
  6020. unsigned char buf[64];
  6021. nullpo_retv(p);
  6022. if(!sd && (flag&0xf0)==0)
  6023. {
  6024. int i;
  6025. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6026. if (i < MAX_PARTY)
  6027. sd = p->data[i].sd;
  6028. }
  6029. if(!sd) return;
  6030. WBUFW(buf,0)=0x105;
  6031. WBUFL(buf,2)=account_id;
  6032. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6033. WBUFB(buf,30)=flag&0x0f;
  6034. if((flag&0xf0)==0)
  6035. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6036. else
  6037. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6038. }
  6039. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6040. /// 0109 <packet len>.W <account id>.L <message>.?B
  6041. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  6042. {
  6043. struct map_session_data *sd;
  6044. int i;
  6045. nullpo_retv(p);
  6046. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6047. if(i < MAX_PARTY){
  6048. unsigned char buf[1024];
  6049. if( len > sizeof(buf)-8 )
  6050. {
  6051. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6052. len = sizeof(buf)-8;
  6053. }
  6054. sd = p->data[i].sd;
  6055. WBUFW(buf,0)=0x109;
  6056. WBUFW(buf,2)=len+8;
  6057. WBUFL(buf,4)=account_id;
  6058. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6059. clif_send(buf,len+8,&sd->bl,PARTY);
  6060. }
  6061. }
  6062. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6063. /// 0107 <account id>.L <x>.W <y>.W
  6064. void clif_party_xy(struct map_session_data *sd)
  6065. {
  6066. unsigned char buf[16];
  6067. nullpo_retv(sd);
  6068. WBUFW(buf,0)=0x107;
  6069. WBUFL(buf,2)=sd->status.account_id;
  6070. WBUFW(buf,6)=sd->bl.x;
  6071. WBUFW(buf,8)=sd->bl.y;
  6072. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6073. }
  6074. /*==========================================
  6075. * Sends x/y dot to a single fd. [Skotlex]
  6076. *------------------------------------------*/
  6077. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6078. {
  6079. WFIFOHEAD(fd,packet_len(0x107));
  6080. WFIFOW(fd,0)=0x107;
  6081. WFIFOL(fd,2)=sd->status.account_id;
  6082. WFIFOW(fd,6)=sd->bl.x;
  6083. WFIFOW(fd,8)=sd->bl.y;
  6084. WFIFOSET(fd,packet_len(0x107));
  6085. }
  6086. /// Updates HP bar of a party member.
  6087. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6088. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6089. void clif_party_hp(struct map_session_data *sd)
  6090. {
  6091. unsigned char buf[16];
  6092. #if PACKETVER < 20100126
  6093. const int cmd = 0x106;
  6094. #else
  6095. const int cmd = 0x80e;
  6096. #endif
  6097. nullpo_retv(sd);
  6098. WBUFW(buf,0)=cmd;
  6099. WBUFL(buf,2)=sd->status.account_id;
  6100. #if PACKETVER < 20100126
  6101. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6102. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6103. WBUFW(buf,8) = 100;
  6104. } else {
  6105. WBUFW(buf,6) = sd->battle_status.hp;
  6106. WBUFW(buf,8) = sd->battle_status.max_hp;
  6107. }
  6108. #else
  6109. WBUFL(buf,6) = sd->battle_status.hp;
  6110. WBUFL(buf,10) = sd->battle_status.max_hp;
  6111. #endif
  6112. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6113. }
  6114. /*==========================================
  6115. * Sends HP bar to a single fd. [Skotlex]
  6116. *------------------------------------------*/
  6117. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6118. {
  6119. #if PACKETVER < 20100126
  6120. const int cmd = 0x106;
  6121. #else
  6122. const int cmd = 0x80e;
  6123. #endif
  6124. WFIFOHEAD(fd,packet_len(cmd));
  6125. WFIFOW(fd,0) = cmd;
  6126. WFIFOL(fd,2) = id;
  6127. #if PACKETVER < 20100126
  6128. if( maxhp > INT16_MAX )
  6129. {// To correctly display the %hp bar. [Skotlex]
  6130. WFIFOW(fd,6) = hp/(maxhp/100);
  6131. WFIFOW(fd,8) = 100;
  6132. } else {
  6133. WFIFOW(fd,6) = hp;
  6134. WFIFOW(fd,8) = maxhp;
  6135. }
  6136. #else
  6137. WFIFOL(fd,6) = hp;
  6138. WFIFOL(fd,10) = maxhp;
  6139. #endif
  6140. WFIFOSET(fd, packet_len(cmd));
  6141. }
  6142. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6143. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6144. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6145. {
  6146. int fd;
  6147. nullpo_retv(sd);
  6148. nullpo_retv(bl);
  6149. fd=sd->fd;
  6150. WFIFOHEAD(fd,packet_len(0x139));
  6151. WFIFOW(fd, 0)=0x139;
  6152. WFIFOL(fd, 2)=bl->id;
  6153. WFIFOW(fd, 6)=bl->x;
  6154. WFIFOW(fd, 8)=bl->y;
  6155. WFIFOW(fd,10)=sd->bl.x;
  6156. WFIFOW(fd,12)=sd->bl.y;
  6157. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6158. WFIFOSET(fd,packet_len(0x139));
  6159. }
  6160. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6161. /// 018f <result>.W <name id>.W
  6162. /// result:
  6163. /// 0 = success
  6164. /// 1 = failure
  6165. /// 2 = success (alchemist)
  6166. /// 3 = failure (alchemist)
  6167. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6168. {
  6169. int view,fd;
  6170. nullpo_retv(sd);
  6171. fd = sd->fd;
  6172. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6173. WFIFOHEAD(fd,packet_len(0x18f));
  6174. WFIFOW(fd, 0)=0x18f;
  6175. WFIFOW(fd, 2)=flag;
  6176. if((view = itemdb_viewid(nameid)) > 0)
  6177. WFIFOW(fd, 4)=view;
  6178. else
  6179. WFIFOW(fd, 4)=nameid;
  6180. WFIFOSET(fd,packet_len(0x18f));
  6181. }
  6182. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6183. /// 019e
  6184. void clif_catch_process(struct map_session_data *sd)
  6185. {
  6186. int fd;
  6187. nullpo_retv(sd);
  6188. fd=sd->fd;
  6189. WFIFOHEAD(fd,packet_len(0x19e));
  6190. WFIFOW(fd,0)=0x19e;
  6191. WFIFOSET(fd,packet_len(0x19e));
  6192. }
  6193. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6194. /// 01a0 <result>.B
  6195. /// 0 = failure
  6196. /// 1 = success
  6197. void clif_pet_roulette(struct map_session_data *sd,int data)
  6198. {
  6199. int fd;
  6200. nullpo_retv(sd);
  6201. fd=sd->fd;
  6202. WFIFOHEAD(fd,packet_len(0x1a0));
  6203. WFIFOW(fd,0)=0x1a0;
  6204. WFIFOB(fd,2)=data;
  6205. WFIFOSET(fd,packet_len(0x1a0));
  6206. }
  6207. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6208. /// 01a6 <packet len>.W { <index>.W }*
  6209. void clif_sendegg(struct map_session_data *sd)
  6210. {
  6211. int i,n=0,fd;
  6212. nullpo_retv(sd);
  6213. fd=sd->fd;
  6214. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6215. clif_displaymessage(fd, msg_txt(sd,666));
  6216. return;
  6217. }
  6218. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6219. WFIFOW(fd,0)=0x1a6;
  6220. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6221. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6222. sd->inventory_data[i]->type!=IT_PETEGG ||
  6223. sd->status.inventory[i].amount<=0)
  6224. continue;
  6225. WFIFOW(fd,n*2+4)=i+2;
  6226. n++;
  6227. }
  6228. WFIFOW(fd,2)=4+n*2;
  6229. WFIFOSET(fd,WFIFOW(fd,2));
  6230. sd->menuskill_id = SA_TAMINGMONSTER;
  6231. sd->menuskill_val = -1;
  6232. }
  6233. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6234. /// 01a4 <type>.B <id>.L <data>.L
  6235. /// type:
  6236. /// 0 = pre-init (data = 0)
  6237. /// 1 = intimacy (data = 0~4)
  6238. /// 2 = hunger (data = 0~4)
  6239. /// 3 = accessory
  6240. /// 4 = performance (data = 1~3: normal, 4: special)
  6241. /// 5 = hairstyle
  6242. ///
  6243. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6244. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6245. {
  6246. uint8 buf[16];
  6247. nullpo_retv(pd);
  6248. WBUFW(buf,0) = 0x1a4;
  6249. WBUFB(buf,2) = type;
  6250. WBUFL(buf,3) = pd->bl.id;
  6251. WBUFL(buf,7) = param;
  6252. if (sd)
  6253. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6254. else
  6255. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6256. }
  6257. /// Pet's base data (ZC_PROPERTY_PET).
  6258. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6259. void clif_send_petstatus(struct map_session_data *sd)
  6260. {
  6261. int fd;
  6262. struct s_pet *pet;
  6263. nullpo_retv(sd);
  6264. nullpo_retv(sd->pd);
  6265. fd=sd->fd;
  6266. pet = &sd->pd->pet;
  6267. WFIFOHEAD(fd,packet_len(0x1a2));
  6268. WFIFOW(fd,0)=0x1a2;
  6269. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6270. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6271. WFIFOW(fd,27)=pet->level;
  6272. WFIFOW(fd,29)=pet->hungry;
  6273. WFIFOW(fd,31)=pet->intimate;
  6274. WFIFOW(fd,33)=pet->equip;
  6275. #if PACKETVER >= 20081126
  6276. WFIFOW(fd,35)=pet->class_;
  6277. #endif
  6278. WFIFOSET(fd,packet_len(0x1a2));
  6279. }
  6280. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6281. /// 01aa <id>.L <data>.L
  6282. /// data:
  6283. /// @see CZ_PET_ACT.
  6284. void clif_pet_emotion(struct pet_data *pd,int param)
  6285. {
  6286. unsigned char buf[16];
  6287. nullpo_retv(pd);
  6288. memset(buf,0,packet_len(0x1aa));
  6289. WBUFW(buf,0)=0x1aa;
  6290. WBUFL(buf,2)=pd->bl.id;
  6291. if(param >= 100 && pd->petDB->talk_convert_class) {
  6292. if(pd->petDB->talk_convert_class < 0)
  6293. return;
  6294. else if(pd->petDB->talk_convert_class > 0) {
  6295. // replace mob_id component of talk/act data
  6296. param -= (pd->pet.class_ - 100)*100;
  6297. param += (pd->petDB->talk_convert_class - 100)*100;
  6298. }
  6299. }
  6300. WBUFL(buf,6)=param;
  6301. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6302. }
  6303. /// Result of request to feed a pet (ZC_FEED_PET).
  6304. /// 01a3 <result>.B <name id>.W
  6305. /// result:
  6306. /// 0 = failure
  6307. /// 1 = success
  6308. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6309. {
  6310. int fd;
  6311. nullpo_retv(sd);
  6312. fd=sd->fd;
  6313. WFIFOHEAD(fd,packet_len(0x1a3));
  6314. WFIFOW(fd,0)=0x1a3;
  6315. WFIFOB(fd,2)=fail;
  6316. WFIFOW(fd,3)=foodid;
  6317. WFIFOSET(fd,packet_len(0x1a3));
  6318. }
  6319. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6320. /// 01cd { <skill id>.L }*7
  6321. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6322. {
  6323. int fd;
  6324. nullpo_retv(sd);
  6325. fd=sd->fd;
  6326. WFIFOHEAD(fd,packet_len(0x1cd));
  6327. WFIFOW(fd, 0)=0x1cd;
  6328. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6329. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6330. else
  6331. WFIFOL(fd,2)= 0x00000000;
  6332. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6333. WFIFOL(fd,6)= MG_COLDBOLT;
  6334. else
  6335. WFIFOL(fd,6)= 0x00000000;
  6336. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6337. WFIFOL(fd,10)= MG_FIREBOLT;
  6338. else
  6339. WFIFOL(fd,10)= 0x00000000;
  6340. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6341. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6342. else
  6343. WFIFOL(fd,14)= 0x00000000;
  6344. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6345. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6346. else
  6347. WFIFOL(fd,18)= 0x00000000;
  6348. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6349. WFIFOL(fd,22)= MG_FIREBALL;
  6350. else
  6351. WFIFOL(fd,22)= 0x00000000;
  6352. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6353. WFIFOL(fd,26)= MG_FROSTDIVER;
  6354. else
  6355. WFIFOL(fd,26)= 0x00000000;
  6356. WFIFOSET(fd,packet_len(0x1cd));
  6357. sd->menuskill_id = SA_AUTOSPELL;
  6358. sd->menuskill_val = skill_lv;
  6359. }
  6360. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6361. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6362. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6363. {
  6364. unsigned char buf[56];
  6365. nullpo_retv(src);
  6366. memset(buf,0,packet_len(0x1cf));
  6367. WBUFW(buf,0) = 0x1cf;
  6368. WBUFL(buf,2) = src->id;
  6369. if( src->type == BL_MER )
  6370. {
  6371. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6372. if( md && md->master && md->devotion_flag )
  6373. WBUFL(buf,6) = md->master->bl.id;
  6374. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6375. }
  6376. else
  6377. {
  6378. int i;
  6379. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6380. if( sd == NULL )
  6381. return;
  6382. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6383. WBUFL(buf,6+4*i) = sd->devotion[i];
  6384. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6385. }
  6386. if( tsd )
  6387. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6388. else
  6389. clif_send(buf, packet_len(0x1cf), src, AREA);
  6390. }
  6391. /*==========================================
  6392. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6393. * Notifies clients in an area of an object's spirits.
  6394. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6395. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6396. *------------------------------------------*/
  6397. void clif_spiritball(struct block_list *bl) {
  6398. unsigned char buf[16];
  6399. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6400. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6401. nullpo_retv(bl);
  6402. WBUFW(buf, 0) = 0x1d0;
  6403. WBUFL(buf, 2) = bl->id;
  6404. WBUFW(buf, 6) = 0; //init to 0
  6405. switch(bl->type){
  6406. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6407. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6408. }
  6409. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6410. }
  6411. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6412. /// 01d2 <account id>.L <delay>.L
  6413. void clif_combo_delay(struct block_list *bl,int wait)
  6414. {
  6415. unsigned char buf[32];
  6416. nullpo_retv(bl);
  6417. WBUFW(buf,0)=0x1d2;
  6418. WBUFL(buf,2)=bl->id;
  6419. WBUFL(buf,6)=wait;
  6420. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6421. }
  6422. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6423. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6424. /// flag:
  6425. /// 0 = inactive
  6426. /// 1 = active
  6427. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6428. {
  6429. unsigned char buf[32];
  6430. nullpo_retv(src);
  6431. WBUFW(buf,0)=0x1d1;
  6432. WBUFL(buf,2)=src->id;
  6433. WBUFL(buf,6)=dst_id;
  6434. WBUFL(buf,10)=active;
  6435. clif_send(buf,packet_len(0x1d1),src,AREA);
  6436. }
  6437. /// MVP effect (ZC_MVP).
  6438. /// 010c <account id>.L
  6439. void clif_mvp_effect(struct map_session_data *sd)
  6440. {
  6441. unsigned char buf[16];
  6442. nullpo_retv(sd);
  6443. WBUFW(buf,0)=0x10c;
  6444. WBUFL(buf,2)=sd->bl.id;
  6445. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6446. }
  6447. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6448. /// 010a <name id>.W
  6449. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6450. {
  6451. int view,fd;
  6452. nullpo_retv(sd);
  6453. fd=sd->fd;
  6454. WFIFOHEAD(fd,packet_len(0x10a));
  6455. WFIFOW(fd,0)=0x10a;
  6456. if((view = itemdb_viewid(nameid)) > 0)
  6457. WFIFOW(fd,2)=view;
  6458. else
  6459. WFIFOW(fd,2)=nameid;
  6460. WFIFOSET(fd,packet_len(0x10a));
  6461. }
  6462. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6463. /// 010b <exp>.L
  6464. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6465. {
  6466. int fd;
  6467. nullpo_retv(sd);
  6468. fd=sd->fd;
  6469. WFIFOHEAD(fd,packet_len(0x10b));
  6470. WFIFOW(fd,0)=0x10b;
  6471. WFIFOL(fd,2)=min(exp,UINT32_MAX);
  6472. WFIFOSET(fd,packet_len(0x10b));
  6473. }
  6474. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6475. /// 010d
  6476. ///
  6477. /// "You are the MVP, but cannot obtain the reward because
  6478. /// you are overweight."
  6479. void clif_mvp_noitem(struct map_session_data* sd)
  6480. {
  6481. int fd = sd->fd;
  6482. WFIFOHEAD(fd,packet_len(0x10d));
  6483. WFIFOW(fd,0) = 0x10d;
  6484. WFIFOSET(fd,packet_len(0x10d));
  6485. }
  6486. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6487. /// 0167 <result>.B
  6488. /// result:
  6489. /// 0 = "Guild has been created."
  6490. /// 1 = "You are already in a Guild."
  6491. /// 2 = "That Guild Name already exists."
  6492. /// 3 = "You need the neccessary item to create a Guild."
  6493. void clif_guild_created(struct map_session_data *sd,int flag)
  6494. {
  6495. int fd;
  6496. nullpo_retv(sd);
  6497. fd=sd->fd;
  6498. WFIFOHEAD(fd,packet_len(0x167));
  6499. WFIFOW(fd,0)=0x167;
  6500. WFIFOB(fd,2)=flag;
  6501. WFIFOSET(fd,packet_len(0x167));
  6502. }
  6503. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6504. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6505. /// mode:
  6506. /// &0x01 = allow invite
  6507. /// &0x10 = allow expel
  6508. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6509. {
  6510. int ps,fd;
  6511. nullpo_retv(sd);
  6512. nullpo_retv(g);
  6513. fd=sd->fd;
  6514. ps=guild_getposition(g,sd);
  6515. WFIFOHEAD(fd,packet_len(0x16c));
  6516. WFIFOW(fd,0)=0x16c;
  6517. WFIFOL(fd,2)=g->guild_id;
  6518. WFIFOL(fd,6)=g->emblem_id;
  6519. WFIFOL(fd,10)=g->position[ps].mode;
  6520. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6521. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6522. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6523. WFIFOSET(fd,packet_len(0x16c));
  6524. }
  6525. /// Guild member login notice.
  6526. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6527. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6528. /// status:
  6529. /// 0 = offline
  6530. /// 1 = online
  6531. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6532. {
  6533. unsigned char buf[64];
  6534. struct map_session_data* sd;
  6535. nullpo_retv(g);
  6536. WBUFW(buf, 0)=0x1f2;
  6537. WBUFL(buf, 2)=g->member[idx].account_id;
  6538. WBUFL(buf, 6)=g->member[idx].char_id;
  6539. WBUFL(buf,10)=flag;
  6540. if( ( sd = g->member[idx].sd ) != NULL )
  6541. {
  6542. WBUFW(buf,14) = sd->status.sex;
  6543. WBUFW(buf,16) = sd->status.hair;
  6544. WBUFW(buf,18) = sd->status.hair_color;
  6545. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6546. }
  6547. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6548. {
  6549. WBUFW(buf,14) = 0;
  6550. WBUFW(buf,16) = 0;
  6551. WBUFW(buf,18) = 0;
  6552. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6553. }
  6554. }
  6555. // Function `clif_guild_memberlogin_notice` sends info about
  6556. // logins and logouts of a guild member to the rest members.
  6557. // But at the 1st time (after a player login or map changing)
  6558. // the client won't show the message.
  6559. // So I suggest use this function for sending "first-time-info"
  6560. // to some player on entering the game or changing location.
  6561. // At next time the client would always show the message.
  6562. // The function sends all the statuses in the single packet
  6563. // to economize traffic. [LuzZza]
  6564. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6565. {
  6566. struct guild *g;
  6567. unsigned char buf[14*128];
  6568. int i, count=0, p_len;
  6569. nullpo_retv(sd);
  6570. p_len = packet_len(0x16d);
  6571. if(!(g = sd->guild))
  6572. return;
  6573. for(i=0; i<g->max_member; i++) {
  6574. if(g->member[i].account_id > 0 &&
  6575. g->member[i].account_id != sd->status.account_id) {
  6576. WBUFW(buf,count*p_len) = 0x16d;
  6577. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6578. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6579. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6580. count++;
  6581. }
  6582. }
  6583. clif_send(buf, p_len*count, &sd->bl, SELF);
  6584. }
  6585. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6586. /// 014e <menu flag>.L
  6587. /// menu flag:
  6588. /// 0x00 = Basic Info (always on)
  6589. /// &0x01 = Member manager
  6590. /// &0x02 = Positions
  6591. /// &0x04 = Skills
  6592. /// &0x10 = Expulsion list
  6593. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6594. /// &0x80 = Notice
  6595. void clif_guild_masterormember(struct map_session_data *sd)
  6596. {
  6597. int fd;
  6598. nullpo_retv(sd);
  6599. fd=sd->fd;
  6600. WFIFOHEAD(fd,packet_len(0x14e));
  6601. WFIFOW(fd,0) = 0x14e;
  6602. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6603. WFIFOSET(fd,packet_len(0x14e));
  6604. }
  6605. /// Guild basic information (Territories [Valaris])
  6606. /// 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)
  6607. /// 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)
  6608. void clif_guild_basicinfo(struct map_session_data *sd) {
  6609. int fd;
  6610. struct guild *g;
  6611. nullpo_retv(sd);
  6612. fd = sd->fd;
  6613. if( (g = sd->guild) == NULL )
  6614. return;
  6615. WFIFOHEAD(fd,packet_len(0x1b6));
  6616. WFIFOW(fd, 0)=0x1b6;//0x150;
  6617. WFIFOL(fd, 2)=g->guild_id;
  6618. WFIFOL(fd, 6)=g->guild_lv;
  6619. WFIFOL(fd,10)=g->connect_member;
  6620. WFIFOL(fd,14)=g->max_member;
  6621. WFIFOL(fd,18)=g->average_lv;
  6622. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6623. WFIFOL(fd,26)=g->next_exp;
  6624. WFIFOL(fd,30)=0; // Tax Points
  6625. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6626. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6627. WFIFOL(fd,42)=g->emblem_id;
  6628. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6629. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6630. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6631. WFIFOL(fd,110) = 0; // zeny
  6632. WFIFOSET(fd,packet_len(0x1b6));
  6633. }
  6634. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6635. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6636. void clif_guild_allianceinfo(struct map_session_data *sd)
  6637. {
  6638. int fd,i,c;
  6639. struct guild *g;
  6640. nullpo_retv(sd);
  6641. if( (g = sd->guild) == NULL )
  6642. return;
  6643. fd = sd->fd;
  6644. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6645. WFIFOW(fd, 0)=0x14c;
  6646. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6647. struct guild_alliance *a=&g->alliance[i];
  6648. if(a->guild_id>0){
  6649. WFIFOL(fd,c*32+4)=a->opposition;
  6650. WFIFOL(fd,c*32+8)=a->guild_id;
  6651. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6652. c++;
  6653. }
  6654. }
  6655. WFIFOW(fd, 2)=c*32+4;
  6656. WFIFOSET(fd,WFIFOW(fd,2));
  6657. }
  6658. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6659. /// 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 }*
  6660. /// state:
  6661. /// 0 = offline
  6662. /// 1 = online
  6663. /// memo:
  6664. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6665. void clif_guild_memberlist(struct map_session_data *sd)
  6666. {
  6667. int fd;
  6668. int i,c;
  6669. struct guild *g;
  6670. nullpo_retv(sd);
  6671. if( (fd = sd->fd) == 0 )
  6672. return;
  6673. if( (g = sd->guild) == NULL )
  6674. return;
  6675. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6676. WFIFOW(fd, 0)=0x154;
  6677. for(i=0,c=0;i<g->max_member;i++){
  6678. struct guild_member *m=&g->member[i];
  6679. if(m->account_id==0)
  6680. continue;
  6681. WFIFOL(fd,c*104+ 4)=m->account_id;
  6682. WFIFOL(fd,c*104+ 8)=m->char_id;
  6683. WFIFOW(fd,c*104+12)=m->hair;
  6684. WFIFOW(fd,c*104+14)=m->hair_color;
  6685. WFIFOW(fd,c*104+16)=m->gender;
  6686. WFIFOW(fd,c*104+18)=m->class_;
  6687. WFIFOW(fd,c*104+20)=m->lv;
  6688. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6689. WFIFOL(fd,c*104+26)=m->online;
  6690. WFIFOL(fd,c*104+30)=m->position;
  6691. 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.
  6692. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6693. c++;
  6694. }
  6695. WFIFOW(fd, 2)=c*104+4;
  6696. WFIFOSET(fd,WFIFOW(fd,2));
  6697. }
  6698. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6699. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6700. void clif_guild_positionnamelist(struct map_session_data *sd)
  6701. {
  6702. int i,fd;
  6703. struct guild *g;
  6704. nullpo_retv(sd);
  6705. if( (g = sd->guild) == NULL )
  6706. return;
  6707. fd = sd->fd;
  6708. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6709. WFIFOW(fd, 0)=0x166;
  6710. for(i=0;i<MAX_GUILDPOSITION;i++){
  6711. WFIFOL(fd,i*28+4)=i;
  6712. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6713. }
  6714. WFIFOW(fd,2)=i*28+4;
  6715. WFIFOSET(fd,WFIFOW(fd,2));
  6716. }
  6717. /// Guild position information (ZC_POSITION_INFO).
  6718. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6719. /// mode:
  6720. /// &0x01 = allow invite
  6721. /// &0x10 = allow expel
  6722. /// ranking:
  6723. /// TODO
  6724. void clif_guild_positioninfolist(struct map_session_data *sd)
  6725. {
  6726. int i,fd;
  6727. struct guild *g;
  6728. nullpo_retv(sd);
  6729. if( (g = sd->guild) == NULL )
  6730. return;
  6731. fd = sd->fd;
  6732. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6733. WFIFOW(fd, 0)=0x160;
  6734. for(i=0;i<MAX_GUILDPOSITION;i++){
  6735. struct guild_position *p=&g->position[i];
  6736. WFIFOL(fd,i*16+ 4)=i;
  6737. WFIFOL(fd,i*16+ 8)=p->mode;
  6738. WFIFOL(fd,i*16+12)=i;
  6739. WFIFOL(fd,i*16+16)=p->exp_mode;
  6740. }
  6741. WFIFOW(fd, 2)=i*16+4;
  6742. WFIFOSET(fd,WFIFOW(fd,2));
  6743. }
  6744. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6745. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6746. /// mode:
  6747. /// &0x01 = allow invite
  6748. /// &0x10 = allow expel
  6749. /// ranking:
  6750. /// TODO
  6751. void clif_guild_positionchanged(struct guild *g,int idx)
  6752. {
  6753. // FIXME: This packet is intended to update the clients after a
  6754. // commit of position info changes, not sending one packet per
  6755. // position.
  6756. struct map_session_data *sd;
  6757. unsigned char buf[128];
  6758. nullpo_retv(g);
  6759. WBUFW(buf, 0)=0x174;
  6760. WBUFW(buf, 2)=44; // packet len
  6761. // GUILD_REG_POSITION_INFO{
  6762. WBUFL(buf, 4)=idx;
  6763. WBUFL(buf, 8)=g->position[idx].mode;
  6764. WBUFL(buf,12)=idx;
  6765. WBUFL(buf,16)=g->position[idx].exp_mode;
  6766. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6767. // }*
  6768. if( (sd=guild_getavailablesd(g))!=NULL )
  6769. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6770. }
  6771. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6772. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6773. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6774. {
  6775. // FIXME: This packet is intended to update the clients after a
  6776. // commit of member position assignment changes, not sending one
  6777. // packet per position.
  6778. struct map_session_data *sd;
  6779. unsigned char buf[64];
  6780. nullpo_retv(g);
  6781. WBUFW(buf, 0)=0x156;
  6782. WBUFW(buf, 2)=16; // packet len
  6783. // MEMBER_POSITION_INFO{
  6784. WBUFL(buf, 4)=g->member[idx].account_id;
  6785. WBUFL(buf, 8)=g->member[idx].char_id;
  6786. WBUFL(buf,12)=g->member[idx].position;
  6787. // }*
  6788. if( (sd=guild_getavailablesd(g))!=NULL )
  6789. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6790. }
  6791. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6792. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6793. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6794. {
  6795. int fd;
  6796. nullpo_retv(sd);
  6797. nullpo_retv(g);
  6798. fd = sd->fd;
  6799. if( g->emblem_len <= 0 )
  6800. return;
  6801. WFIFOHEAD(fd,g->emblem_len+12);
  6802. WFIFOW(fd,0)=0x152;
  6803. WFIFOW(fd,2)=g->emblem_len+12;
  6804. WFIFOL(fd,4)=g->guild_id;
  6805. WFIFOL(fd,8)=g->emblem_id;
  6806. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6807. WFIFOSET(fd,WFIFOW(fd,2));
  6808. }
  6809. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6810. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6811. void clif_guild_emblem_area(struct block_list* bl)
  6812. {
  6813. uint8 buf[12];
  6814. nullpo_retv(bl);
  6815. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6816. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6817. WBUFW(buf,0) = 0x1b4;
  6818. WBUFL(buf,2) = bl->id;
  6819. WBUFL(buf,6) = status_get_guild_id(bl);
  6820. WBUFW(buf,10) = status_get_emblem_id(bl);
  6821. clif_send(buf, 12, bl, AREA_WOS);
  6822. }
  6823. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6824. /// 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 }*
  6825. void clif_guild_skillinfo(struct map_session_data* sd)
  6826. {
  6827. int fd;
  6828. struct guild* g;
  6829. int i,c;
  6830. nullpo_retv(sd);
  6831. if( (g = sd->guild) == NULL )
  6832. return;
  6833. fd = sd->fd;
  6834. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6835. WFIFOW(fd,0) = 0x0162;
  6836. WFIFOW(fd,4) = g->skill_point;
  6837. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6838. {
  6839. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6840. {
  6841. int id = g->skill[i].id;
  6842. int p = 6 + c*37;
  6843. WFIFOW(fd,p+0) = id;
  6844. WFIFOL(fd,p+2) = skill_get_inf(id);
  6845. WFIFOW(fd,p+6) = g->skill[i].lv;
  6846. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6847. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6848. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6849. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6850. c++;
  6851. }
  6852. }
  6853. WFIFOW(fd,2) = 6 + c*37;
  6854. WFIFOSET(fd,WFIFOW(fd,2));
  6855. }
  6856. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6857. /// 016f <subject>.60B <notice>.120B
  6858. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6859. {
  6860. int fd;
  6861. nullpo_retv(sd);
  6862. nullpo_retv(g);
  6863. fd = sd->fd;
  6864. if ( !session_isActive(fd) )
  6865. return;
  6866. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6867. return;
  6868. WFIFOHEAD(fd,packet_len(0x16f));
  6869. WFIFOW(fd,0) = 0x16f;
  6870. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6871. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6872. WFIFOSET(fd,packet_len(0x16f));
  6873. }
  6874. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6875. /// 016a <guild id>.L <guild name>.24B
  6876. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6877. {
  6878. int fd;
  6879. nullpo_retv(sd);
  6880. nullpo_retv(g);
  6881. fd=sd->fd;
  6882. WFIFOHEAD(fd,packet_len(0x16a));
  6883. WFIFOW(fd,0)=0x16a;
  6884. WFIFOL(fd,2)=g->guild_id;
  6885. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6886. WFIFOSET(fd,packet_len(0x16a));
  6887. }
  6888. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6889. /// 0169 <answer>.B
  6890. /// answer:
  6891. /// 0 = Already in guild.
  6892. /// 1 = Offer rejected.
  6893. /// 2 = Offer accepted.
  6894. /// 3 = Guild full.
  6895. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6896. {
  6897. int fd;
  6898. nullpo_retv(sd);
  6899. fd=sd->fd;
  6900. WFIFOHEAD(fd,packet_len(0x169));
  6901. WFIFOW(fd,0)=0x169;
  6902. WFIFOB(fd,2)=flag;
  6903. WFIFOSET(fd,packet_len(0x169));
  6904. }
  6905. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6906. /// 015a <char name>.24B <reason>.40B
  6907. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6908. {
  6909. unsigned char buf[128];
  6910. nullpo_retv(sd);
  6911. WBUFW(buf, 0)=0x15a;
  6912. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6913. memcpy(WBUFP(buf,26),mes,40);
  6914. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6915. }
  6916. /// Notifies clients of a guild of an expelled member.
  6917. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6918. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6919. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6920. {
  6921. unsigned char buf[128];
  6922. #if PACKETVER < 20100803
  6923. const unsigned short cmd = 0x15c;
  6924. #else
  6925. const unsigned short cmd = 0x839;
  6926. #endif
  6927. nullpo_retv(sd);
  6928. WBUFW(buf,0) = cmd;
  6929. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6930. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6931. #if PACKETVER < 20100803
  6932. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6933. #endif
  6934. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6935. }
  6936. /// Guild expulsion list (ZC_BAN_LIST).
  6937. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6938. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6939. void clif_guild_expulsionlist(struct map_session_data* sd)
  6940. {
  6941. #if PACKETVER < 20100803
  6942. const int offset = NAME_LENGTH*2+40;
  6943. #else
  6944. const int offset = NAME_LENGTH+40;
  6945. #endif
  6946. int fd, i, c = 0;
  6947. struct guild* g;
  6948. nullpo_retv(sd);
  6949. if( (g = sd->guild) == NULL )
  6950. return;
  6951. fd = sd->fd;
  6952. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6953. WFIFOW(fd,0) = 0x163;
  6954. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6955. {
  6956. struct guild_expulsion* e = &g->expulsion[i];
  6957. if( e->account_id > 0 )
  6958. {
  6959. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6960. #if PACKETVER < 20100803
  6961. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6962. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6963. #else
  6964. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6965. #endif
  6966. c++;
  6967. }
  6968. }
  6969. WFIFOW(fd,2) = 4 + c*offset;
  6970. WFIFOSET(fd,WFIFOW(fd,2));
  6971. }
  6972. /// Guild chat message (ZC_GUILD_CHAT).
  6973. /// 017f <packet len>.W <message>.?B
  6974. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6975. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6976. struct map_session_data *sd;
  6977. uint8 buf[256];
  6978. if( len == 0 )
  6979. {
  6980. return;
  6981. }
  6982. else if( len > sizeof(buf)-5 )
  6983. {
  6984. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6985. len = sizeof(buf)-5;
  6986. }
  6987. WBUFW(buf, 0) = 0x17f;
  6988. WBUFW(buf, 2) = len + 5;
  6989. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6990. if ((sd = guild_getavailablesd(g)) != NULL)
  6991. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6992. }
  6993. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6994. /// 0171 <inviter account id>.L <guild name>.24B
  6995. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6996. {
  6997. int fd;
  6998. nullpo_retv(sd);
  6999. fd=sd->fd;
  7000. WFIFOHEAD(fd,packet_len(0x171));
  7001. WFIFOW(fd,0)=0x171;
  7002. WFIFOL(fd,2)=account_id;
  7003. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7004. WFIFOSET(fd,packet_len(0x171));
  7005. }
  7006. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7007. /// 0173 <answer>.B
  7008. /// answer:
  7009. /// 0 = Already allied.
  7010. /// 1 = You rejected the offer.
  7011. /// 2 = You accepted the offer.
  7012. /// 3 = They have too any alliances.
  7013. /// 4 = You have too many alliances.
  7014. /// 5 = Alliances are disabled.
  7015. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7016. {
  7017. int fd;
  7018. nullpo_retv(sd);
  7019. fd=sd->fd;
  7020. WFIFOHEAD(fd,packet_len(0x173));
  7021. WFIFOW(fd,0)=0x173;
  7022. WFIFOL(fd,2)=flag;
  7023. WFIFOSET(fd,packet_len(0x173));
  7024. }
  7025. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7026. /// 0184 <other guild id>.L <relation>.L
  7027. /// relation:
  7028. /// 0 = Ally
  7029. /// 1 = Enemy
  7030. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7031. {
  7032. int fd;
  7033. nullpo_retv(sd);
  7034. fd = sd->fd;
  7035. if (fd <= 0)
  7036. return;
  7037. WFIFOHEAD(fd,packet_len(0x184));
  7038. WFIFOW(fd,0)=0x184;
  7039. WFIFOL(fd,2)=guild_id;
  7040. WFIFOL(fd,6)=flag;
  7041. WFIFOSET(fd,packet_len(0x184));
  7042. }
  7043. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7044. /// 0181 <result>.B
  7045. /// result:
  7046. /// 0 = Antagonist has been set.
  7047. /// 1 = Guild has too many Antagonists.
  7048. /// 2 = Already set as an Antagonist.
  7049. /// 3 = Antagonists are disabled.
  7050. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7051. {
  7052. int fd;
  7053. nullpo_retv(sd);
  7054. fd=sd->fd;
  7055. WFIFOHEAD(fd,packet_len(0x181));
  7056. WFIFOW(fd,0)=0x181;
  7057. WFIFOB(fd,2)=flag;
  7058. WFIFOSET(fd,packet_len(0x181));
  7059. }
  7060. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7061. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7062. /*
  7063. void clif_guild_allianceadded(struct guild *g,int idx)
  7064. {
  7065. unsigned char buf[64];
  7066. WBUFW(buf,0)=0x185;
  7067. WBUFL(buf,2)=g->alliance[idx].opposition;
  7068. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7069. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7070. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7071. }
  7072. */
  7073. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7074. /// 015e <reason>.L
  7075. /// 0 = success
  7076. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7077. /// 2 = there are still members in the guild
  7078. void clif_guild_broken(struct map_session_data *sd,int flag)
  7079. {
  7080. int fd;
  7081. nullpo_retv(sd);
  7082. fd=sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x15e));
  7084. WFIFOW(fd,0)=0x15e;
  7085. WFIFOL(fd,2)=flag;
  7086. WFIFOSET(fd,packet_len(0x15e));
  7087. }
  7088. /// Displays emotion on an object (ZC_EMOTION).
  7089. /// 00c0 <id>.L <type>.B
  7090. /// type:
  7091. /// enum emotion_type
  7092. void clif_emotion(struct block_list *bl,int type)
  7093. {
  7094. unsigned char buf[8];
  7095. nullpo_retv(bl);
  7096. WBUFW(buf,0)=0xc0;
  7097. WBUFL(buf,2)=bl->id;
  7098. WBUFB(buf,6)=type;
  7099. clif_send(buf,packet_len(0xc0),bl,AREA);
  7100. }
  7101. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7102. /// 0191 <id>.L <contents>.80B
  7103. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7104. {
  7105. unsigned char buf[MESSAGE_SIZE+6];
  7106. nullpo_retv(bl);
  7107. WBUFW(buf,0) = 0x191;
  7108. WBUFL(buf,2) = bl->id;
  7109. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7110. clif_send(buf,packet_len(0x191),bl,AREA);
  7111. }
  7112. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7113. /// 01ea <id>.L
  7114. void clif_wedding_effect(struct block_list *bl)
  7115. {
  7116. unsigned char buf[6];
  7117. nullpo_retv(bl);
  7118. WBUFW(buf,0) = 0x1ea;
  7119. WBUFL(buf,2) = bl->id;
  7120. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7121. }
  7122. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7123. /// 01e6 <partner name>.24B
  7124. void clif_callpartner(struct map_session_data *sd)
  7125. {
  7126. unsigned char buf[26];
  7127. nullpo_retv(sd);
  7128. WBUFW(buf,0) = 0x1e6;
  7129. if( sd->status.partner_id ) {
  7130. const char *p = map_charid2nick(sd->status.partner_id);
  7131. struct map_session_data *p_sd = pc_get_partner(sd);
  7132. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7133. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7134. else
  7135. WBUFB(buf,2) = 0;
  7136. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7137. WBUFB(buf,2) = 0;
  7138. }
  7139. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7140. }
  7141. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7142. /// 01e4
  7143. /// This packet while still implemented by the client is no longer being officially used.
  7144. /*
  7145. void clif_marriage_process(struct map_session_data *sd)
  7146. {
  7147. int fd;
  7148. nullpo_retv(sd);
  7149. fd=sd->fd;
  7150. WFIFOHEAD(fd,packet_len(0x1e4));
  7151. WFIFOW(fd,0)=0x1e4;
  7152. WFIFOSET(fd,packet_len(0x1e4));
  7153. }
  7154. */
  7155. /// Notice of divorce (ZC_DIVORCE).
  7156. /// 0205 <partner name>.24B
  7157. void clif_divorced(struct map_session_data* sd, const char* name)
  7158. {
  7159. int fd;
  7160. nullpo_retv(sd);
  7161. fd=sd->fd;
  7162. WFIFOHEAD(fd,packet_len(0x205));
  7163. WFIFOW(fd,0)=0x205;
  7164. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7165. WFIFOSET(fd, packet_len(0x205));
  7166. }
  7167. /// Marriage proposal (ZC_REQ_COUPLE).
  7168. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7169. /// This packet while still implemented by the client is no longer being officially used.
  7170. /*
  7171. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7172. {
  7173. nullpo_retv(sd);
  7174. WFIFOHEAD(fd,packet_len(0x1e2));
  7175. WFIFOW(fd,0) = 0x1e2;
  7176. WFIFOL(fd,2) = ssd->status.account_id;
  7177. WFIFOL(fd,6) = ssd->status.char_id;
  7178. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7179. WFIFOSET(fd, packet_len(0x1e2));
  7180. }
  7181. */
  7182. /*==========================================
  7183. *
  7184. *------------------------------------------*/
  7185. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7186. {
  7187. clif_disp_message(&sd->bl, mes, len, SELF);
  7188. }
  7189. /*==========================================
  7190. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7191. *------------------------------------------*/
  7192. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7193. {
  7194. unsigned char buf[256];
  7195. if( len == 0 ) {
  7196. return;
  7197. } else if( len > sizeof(buf)-5 ) {
  7198. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7199. len = sizeof(buf)-5;
  7200. }
  7201. WBUFW(buf, 0) = 0x17f;
  7202. WBUFW(buf, 2) = len + 5;
  7203. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7204. clif_send(buf, WBUFW(buf,2), src, target);
  7205. }
  7206. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7207. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7208. /// 00cd <result>.B
  7209. /// result:
  7210. /// 0 = failure
  7211. /// 1 = success
  7212. void clif_GM_kickack(struct map_session_data *sd, int id)
  7213. {
  7214. int fd;
  7215. nullpo_retv(sd);
  7216. fd = sd->fd;
  7217. WFIFOHEAD(fd,packet_len(0xcd));
  7218. WFIFOW(fd,0) = 0xcd;
  7219. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7220. WFIFOSET(fd, packet_len(0xcd));
  7221. }
  7222. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7223. {
  7224. int fd = tsd->fd;
  7225. if( fd > 0 )
  7226. clif_authfail_fd(fd, 15);
  7227. else {
  7228. // Close vending/buyingstore
  7229. if (sd) {
  7230. if (tsd->state.vending)
  7231. vending_closevending(tsd);
  7232. else if (tsd->state.buyingstore)
  7233. buyingstore_close(tsd);
  7234. }
  7235. map_quit(tsd);
  7236. }
  7237. if( sd )
  7238. clif_GM_kickack(sd,tsd->status.account_id);
  7239. }
  7240. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7241. /// 014a <result>.L
  7242. /// result:
  7243. /// 0 = "A manner point has been successfully aligned."
  7244. /// 1 = MP_FAILURE_EXHAUST
  7245. /// 2 = MP_FAILURE_ALREADY_GIVING
  7246. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7247. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7248. /// 5 = "You got a good point from %s."
  7249. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7250. {
  7251. int fd;
  7252. nullpo_retv(sd);
  7253. fd = sd->fd;
  7254. WFIFOHEAD(fd,packet_len(0x14a));
  7255. WFIFOW(fd,0) = 0x14a;
  7256. WFIFOL(fd,2) = type;
  7257. WFIFOSET(fd, packet_len(0x14a));
  7258. }
  7259. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7260. /// 014b <type>.B <GM name>.24B
  7261. /// type:
  7262. /// 0 = positive (unmute)
  7263. /// 1 = negative (mute)
  7264. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7265. {
  7266. int fd;
  7267. nullpo_retv(sd);
  7268. nullpo_retv(tsd);
  7269. fd = tsd->fd;
  7270. WFIFOHEAD(fd,packet_len(0x14b));
  7271. WFIFOW(fd,0) = 0x14b;
  7272. WFIFOB(fd,2) = type;
  7273. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7274. WFIFOSET(fd, packet_len(0x14b));
  7275. }
  7276. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7277. /// 00d1 <type>.B <result>.B
  7278. /// type:
  7279. /// 0 = /ex (deny)
  7280. /// 1 = /in (allow)
  7281. /// result:
  7282. /// 0 = success
  7283. /// 1 = failure
  7284. /// 2 = too many blocks
  7285. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7286. {
  7287. int fd;
  7288. nullpo_retv(sd);
  7289. fd=sd->fd;
  7290. WFIFOHEAD(fd,packet_len(0xd1));
  7291. WFIFOW(fd,0)=0xd1;
  7292. WFIFOB(fd,2)=type;
  7293. WFIFOB(fd,3)=flag;
  7294. WFIFOSET(fd,packet_len(0xd1));
  7295. }
  7296. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7297. /// 00d2 <type>.B <result>.B
  7298. /// type:
  7299. /// 0 = /exall (deny)
  7300. /// 1 = /inall (allow)
  7301. /// result:
  7302. /// 0 = success
  7303. /// 1 = failure
  7304. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7305. {
  7306. int fd;
  7307. nullpo_retv(sd);
  7308. fd=sd->fd;
  7309. WFIFOHEAD(fd,packet_len(0xd2));
  7310. WFIFOW(fd,0)=0xd2;
  7311. WFIFOB(fd,2)=type;
  7312. WFIFOB(fd,3)=flag;
  7313. WFIFOSET(fd,packet_len(0xd2));
  7314. }
  7315. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7316. /// 07fe <bgm>.24B
  7317. void clif_playBGM(struct map_session_data* sd, const char* name)
  7318. {
  7319. int fd;
  7320. nullpo_retv(sd);
  7321. fd = sd->fd;
  7322. WFIFOHEAD(fd,packet_len(0x7fe));
  7323. WFIFOW(fd,0) = 0x7fe;
  7324. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7325. WFIFOSET(fd,packet_len(0x7fe));
  7326. }
  7327. /// Plays/stops a wave sound (ZC_SOUND).
  7328. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7329. /// file name:
  7330. /// relative to data\wav
  7331. /// act:
  7332. /// 0 = play (once)
  7333. /// 1 = play (repeat, does not work)
  7334. /// 2 = stops all sound instances of file name (does not work)
  7335. /// term:
  7336. /// unknown purpose, only relevant to act = 1
  7337. /// npc id:
  7338. /// The accustic direction of the sound is determined by the
  7339. /// relative position of the NPC to the player (3D sound).
  7340. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7341. {
  7342. int fd;
  7343. nullpo_retv(sd);
  7344. nullpo_retv(bl);
  7345. fd = sd->fd;
  7346. WFIFOHEAD(fd,packet_len(0x1d3));
  7347. WFIFOW(fd,0) = 0x1d3;
  7348. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7349. WFIFOB(fd,26) = type;
  7350. WFIFOL(fd,27) = 0;
  7351. WFIFOL(fd,31) = bl->id;
  7352. WFIFOSET(fd,packet_len(0x1d3));
  7353. }
  7354. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7355. {
  7356. unsigned char buf[40];
  7357. nullpo_retv(bl);
  7358. WBUFW(buf,0) = 0x1d3;
  7359. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7360. WBUFB(buf,26) = type;
  7361. WBUFL(buf,27) = 0;
  7362. WBUFL(buf,31) = bl->id;
  7363. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7364. }
  7365. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7366. /// 01f3 <id>.L <effect id>.L
  7367. /// effect id:
  7368. /// @see doc/effect_list.txt
  7369. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7370. {
  7371. unsigned char buf[24];
  7372. nullpo_retv(bl);
  7373. memset(buf, 0, packet_len(0x1f3));
  7374. WBUFW(buf,0) = 0x1f3;
  7375. WBUFL(buf,2) = bl->id;
  7376. WBUFL(buf,6) = type;
  7377. clif_send(buf, packet_len(0x1f3), bl, target);
  7378. if (disguised(bl)) {
  7379. WBUFL(buf,2) = -bl->id;
  7380. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7381. }
  7382. }
  7383. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7384. {
  7385. WFIFOHEAD(fd,10);
  7386. WFIFOW(fd,0) = 0x1f3;
  7387. WFIFOL(fd,2) = bl->id;
  7388. WFIFOL(fd,6) = type;
  7389. WFIFOSET(fd,10);
  7390. }
  7391. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7392. /// 0284 <id>.L <effect id>.L <num data>.L
  7393. /// effect id:
  7394. /// @see doc/effect_list.txt
  7395. /// num data:
  7396. /// effect-dependent value
  7397. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7398. {
  7399. uint8 buf[14];
  7400. WBUFW(buf,0) = 0x284;
  7401. WBUFL(buf,2) = bl->id;
  7402. WBUFL(buf,6) = effect_id;
  7403. WBUFL(buf,10) = num;
  7404. clif_send(buf, packet_len(0x284), bl, target);
  7405. if( disguised(bl) )
  7406. {
  7407. WBUFL(buf,2) = -bl->id;
  7408. clif_send(buf, packet_len(0x284), bl, SELF);
  7409. }
  7410. }
  7411. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7412. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7413. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7414. unsigned short msg_len = strlen(msg) + 1;
  7415. WFIFOHEAD(sd->fd,msg_len + 12);
  7416. WFIFOW(sd->fd,0) = 0x2C1;
  7417. WFIFOW(sd->fd,2) = msg_len + 12;
  7418. WFIFOL(sd->fd,4) = 0;
  7419. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7420. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7421. WFIFOSET(sd->fd, msg_len + 12);
  7422. return 0;
  7423. }
  7424. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7425. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7426. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7427. unsigned short msg_len = strlen(msg) + 1;
  7428. uint8 buf[256];
  7429. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7430. nullpo_retv(bl);
  7431. if( msg_len > sizeof(buf)-12 ) {
  7432. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7433. msg_len = sizeof(buf)-12;
  7434. }
  7435. WBUFW(buf,0) = 0x2C1;
  7436. WBUFW(buf,2) = msg_len + 12;
  7437. WBUFL(buf,4) = bl->id;
  7438. WBUFL(buf,8) = color;
  7439. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7440. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7441. }
  7442. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7443. {
  7444. int fd;
  7445. unsigned short msg_len = strlen(msg) + 1;
  7446. nullpo_retv(sd);
  7447. if(msg_len > 0) {
  7448. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7449. fd = sd->fd;
  7450. WFIFOHEAD(fd, msg_len+12);
  7451. WFIFOW(fd,0) = 0x2C1;
  7452. WFIFOW(fd,2) = msg_len+12;
  7453. WFIFOL(fd,4) = 0;
  7454. WFIFOL(fd,8) = color;
  7455. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7456. WFIFOSET(fd, WFIFOW(fd,2));
  7457. }
  7458. }
  7459. /**
  7460. * Notifies the client that the storage window is still open
  7461. *
  7462. * Should only be used in cases where the client closed the
  7463. * storage window without server's consent
  7464. */
  7465. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7466. // Notify the client that the storage is open
  7467. if( sd->state.storage_flag == 1 ) {
  7468. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7469. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7470. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7471. }
  7472. // Notify the client that the gstorage is open otherwise it will
  7473. // remain locked forever and nobody will be able to access it
  7474. if( sd->state.storage_flag == 2 ) {
  7475. struct guild_storage *gstor = guild2storage2(sd->status.guild_id);
  7476. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7477. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7478. else {
  7479. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7480. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7481. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7482. }
  7483. }
  7484. }
  7485. // refresh the client's screen, getting rid of any effects
  7486. void clif_refresh(struct map_session_data *sd)
  7487. {
  7488. int i;
  7489. nullpo_retv(sd);
  7490. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7491. clif_inventorylist(sd);
  7492. if(pc_iscarton(sd)) {
  7493. clif_cartlist(sd);
  7494. clif_updatestatus(sd,SP_CARTINFO);
  7495. }
  7496. clif_updatestatus(sd,SP_WEIGHT);
  7497. clif_updatestatus(sd,SP_MAXWEIGHT);
  7498. clif_updatestatus(sd,SP_STR);
  7499. clif_updatestatus(sd,SP_AGI);
  7500. clif_updatestatus(sd,SP_VIT);
  7501. clif_updatestatus(sd,SP_INT);
  7502. clif_updatestatus(sd,SP_DEX);
  7503. clif_updatestatus(sd,SP_LUK);
  7504. if (sd->spiritball)
  7505. clif_spiritball_single(sd->fd, sd);
  7506. for(i = 1; i < 5; i++){
  7507. if( sd->talisman[i] > 0 )
  7508. clif_talisman_single(sd->fd, sd, i);
  7509. }
  7510. if (sd->vd.cloth_color)
  7511. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7512. if(hom_is_active(sd->hd))
  7513. clif_send_homdata(sd,SP_ACK,0);
  7514. if( sd->md ) {
  7515. clif_mercenary_info(sd);
  7516. clif_mercenary_skillblock(sd);
  7517. }
  7518. if( sd->ed )
  7519. clif_elemental_info(sd);
  7520. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7521. clif_weather_check(sd);
  7522. if( sd->chatID )
  7523. chat_leavechat(sd,0);
  7524. if( sd->state.vending )
  7525. clif_openvending(sd, sd->bl.id, sd->vending);
  7526. if( pc_issit(sd) )
  7527. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7528. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7529. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7530. else
  7531. clif_changed_dir(&sd->bl, SELF);
  7532. // unlike vending, resuming buyingstore crashes the client.
  7533. buyingstore_close(sd);
  7534. mail_clear(sd);
  7535. if( disguised(&sd->bl) ) {/* refresh-da */
  7536. short disguise = sd->disguise;
  7537. pc_disguise(sd, 0);
  7538. pc_disguise(sd, disguise);
  7539. }
  7540. clif_refresh_storagewindow(sd);
  7541. }
  7542. /// Updates the object's (bl) name on client.
  7543. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7544. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7545. void clif_charnameack (int fd, struct block_list *bl)
  7546. {
  7547. unsigned char buf[103];
  7548. int cmd = 0x95;
  7549. nullpo_retv(bl);
  7550. WBUFW(buf,0) = cmd;
  7551. WBUFL(buf,2) = bl->id;
  7552. switch( bl->type )
  7553. {
  7554. case BL_PC:
  7555. {
  7556. struct map_session_data *ssd = (struct map_session_data *)bl;
  7557. struct party_data *p = NULL;
  7558. struct guild *g = NULL;
  7559. int ps = -1;
  7560. //Requesting your own "shadow" name. [Skotlex]
  7561. if (ssd->fd == fd && ssd->disguise)
  7562. WBUFL(buf,2) = -bl->id;
  7563. if( ssd->fakename[0] ) {
  7564. WBUFW(buf, 0) = cmd = 0x195;
  7565. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7566. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7567. break;
  7568. }
  7569. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7570. if( ssd->status.party_id ) {
  7571. p = party_search(ssd->status.party_id);
  7572. }
  7573. if( ssd->status.guild_id ) {
  7574. if( ( g = ssd->guild ) != NULL ) {
  7575. int i;
  7576. 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);
  7577. if( i < g->max_member ) ps = g->member[i].position;
  7578. }
  7579. }
  7580. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7581. p = NULL;
  7582. }
  7583. if (p == NULL && g == NULL)
  7584. break;
  7585. WBUFW(buf, 0) = cmd = 0x195;
  7586. if (p)
  7587. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7588. else
  7589. WBUFB(buf,30) = 0;
  7590. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7591. {
  7592. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7593. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7594. } else { //Assume no guild.
  7595. WBUFB(buf,54) = 0;
  7596. WBUFB(buf,78) = 0;
  7597. }
  7598. }
  7599. break;
  7600. //[blackhole89]
  7601. case BL_HOM:
  7602. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7603. break;
  7604. case BL_MER:
  7605. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7606. break;
  7607. case BL_PET:
  7608. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7609. break;
  7610. case BL_NPC:
  7611. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7612. break;
  7613. case BL_MOB:
  7614. {
  7615. struct mob_data *md = (struct mob_data *)bl;
  7616. nullpo_retv(md);
  7617. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7618. if( md->guardian_data && md->guardian_data->guild_id )
  7619. {
  7620. WBUFW(buf, 0) = cmd = 0x195;
  7621. WBUFB(buf,30) = 0;
  7622. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7623. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7624. }
  7625. else if( battle_config.show_mob_info )
  7626. {
  7627. char mobhp[50], *str_p = mobhp;
  7628. WBUFW(buf, 0) = cmd = 0x195;
  7629. if( battle_config.show_mob_info&4 )
  7630. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7631. if( battle_config.show_mob_info&1 )
  7632. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7633. if( battle_config.show_mob_info&2 )
  7634. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7635. //Even thought mobhp ain't a name, we send it as one so the client
  7636. //can parse it. [Skotlex]
  7637. if( str_p != mobhp )
  7638. {
  7639. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7640. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7641. WBUFB(buf,54) = 0;
  7642. WBUFB(buf,78) = 0;
  7643. }
  7644. }
  7645. }
  7646. break;
  7647. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7648. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7649. // break;
  7650. return;
  7651. case BL_ELEM:
  7652. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7653. break;
  7654. default:
  7655. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7656. return;
  7657. }
  7658. // if no receipient specified just update nearby clients
  7659. if (fd == 0)
  7660. clif_send(buf, packet_len(cmd), bl, AREA);
  7661. else {
  7662. WFIFOHEAD(fd, packet_len(cmd));
  7663. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7664. WFIFOSET(fd, packet_len(cmd));
  7665. }
  7666. }
  7667. //Used to update when a char leaves a party/guild. [Skotlex]
  7668. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7669. void clif_charnameupdate (struct map_session_data *ssd)
  7670. {
  7671. unsigned char buf[103];
  7672. int cmd = 0x195, ps = -1;
  7673. struct party_data *p = NULL;
  7674. struct guild *g = NULL;
  7675. nullpo_retv(ssd);
  7676. if( ssd->fakename[0] )
  7677. return; //No need to update as the party/guild was not displayed anyway.
  7678. WBUFW(buf,0) = cmd;
  7679. WBUFL(buf,2) = ssd->bl.id;
  7680. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7681. if (!battle_config.display_party_name) {
  7682. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7683. p = party_search(ssd->status.party_id);
  7684. }else{
  7685. if (ssd->status.party_id > 0)
  7686. p = party_search(ssd->status.party_id);
  7687. }
  7688. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7689. {
  7690. int i;
  7691. 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);
  7692. if( i < g->max_member ) ps = g->member[i].position;
  7693. }
  7694. if( p )
  7695. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7696. else
  7697. WBUFB(buf,30) = 0;
  7698. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7699. {
  7700. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7701. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7702. }
  7703. else
  7704. {
  7705. WBUFB(buf,54) = 0;
  7706. WBUFB(buf,78) = 0;
  7707. }
  7708. // Update nearby clients
  7709. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7710. }
  7711. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7712. /// 01ff <id>.L <x>.W <y>.W
  7713. ///
  7714. /// Visually moves(instant) a character to x,y. The char moves even
  7715. /// when the target cell isn't walkable. If the char is sitting it
  7716. /// stays that way.
  7717. void clif_slide(struct block_list *bl, int x, int y)
  7718. {
  7719. unsigned char buf[10];
  7720. nullpo_retv(bl);
  7721. WBUFW(buf, 0) = 0x01ff;
  7722. WBUFL(buf, 2) = bl->id;
  7723. WBUFW(buf, 6) = x;
  7724. WBUFW(buf, 8) = y;
  7725. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7726. if( disguised(bl) )
  7727. {
  7728. WBUFL(buf,2) = -bl->id;
  7729. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7730. }
  7731. }
  7732. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7733. /// 008d <packet len>.W <id>.L <message>.?B
  7734. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7735. {
  7736. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7737. int len_mes = strlen(mes)+1; //Account for \0
  7738. if (len_mes > sizeof(buf)-8) {
  7739. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7740. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7741. }
  7742. // send message to others
  7743. WBUFW(buf,0) = 0x8d;
  7744. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7745. WBUFL(buf,4) = bl->id;
  7746. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7747. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7748. // send back message to the speaker
  7749. if( bl->type == BL_PC ) {
  7750. WBUFW(buf,0) = 0x8e;
  7751. WBUFW(buf, 2) = len_mes + 4;
  7752. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7753. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7754. }
  7755. }
  7756. /*==========================
  7757. * Minimap fix [Kevin]
  7758. * Remove dot from minimap
  7759. *--------------------------*/
  7760. void clif_party_xy_remove(struct map_session_data *sd)
  7761. {
  7762. unsigned char buf[16];
  7763. nullpo_retv(sd);
  7764. WBUFW(buf,0)=0x107;
  7765. WBUFL(buf,2)=sd->status.account_id;
  7766. WBUFW(buf,6)=-1;
  7767. WBUFW(buf,8)=-1;
  7768. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7769. }
  7770. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7771. /// 0215 <msg id>.L
  7772. /// msg id:
  7773. /// 0x15 = End all negative status (PA_GOSPEL)
  7774. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7775. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7776. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7777. /// 0x19 = All stats +20 (PA_GOSPEL)
  7778. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7779. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7780. /// 0x1e = DEF +25% (PA_GOSPEL)
  7781. /// 0x1f = ATK +100% (PA_GOSPEL)
  7782. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7783. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7784. /// ? = nothing
  7785. void clif_gospel_info(struct map_session_data *sd, int type)
  7786. {
  7787. int fd=sd->fd;
  7788. WFIFOHEAD(fd,packet_len(0x215));
  7789. WFIFOW(fd,0)=0x215;
  7790. WFIFOL(fd,2)=type;
  7791. WFIFOSET(fd, packet_len(0x215));
  7792. }
  7793. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7794. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7795. /// result:
  7796. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7797. /// star:
  7798. /// 0 = Place of the Sun
  7799. /// 1 = Place of the Moon
  7800. /// 2 = Place of the Stars
  7801. /// 1 = Star Gladiator %s's %s: <mapname>
  7802. /// star:
  7803. /// 0 = Place of the Sun
  7804. /// 1 = Place of the Moon
  7805. /// 2 = Place of the Stars
  7806. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7807. /// star:
  7808. /// 0 = Target of the Sun
  7809. /// 1 = Target of the Moon
  7810. /// 2 = Target of the Stars
  7811. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7812. /// star:
  7813. /// 0 = Monster of the Sun
  7814. /// 1 = Monster of the Moon
  7815. /// 2 = Monster of the Stars
  7816. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7817. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7818. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7819. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7820. /// 40 = Target HP : <monster_id used as HP>
  7821. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7822. {
  7823. int fd = sd->fd;
  7824. WFIFOHEAD(fd,packet_len(0x20e));
  7825. WFIFOW(fd,0) = 0x20e;
  7826. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7827. WFIFOL(fd,26) = monster_id;
  7828. WFIFOB(fd,30) = star;
  7829. WFIFOB(fd,31) = result;
  7830. WFIFOSET(fd,packet_len(0x20e));
  7831. }
  7832. /*==========================================
  7833. * Info about Star Glaldiator save map [Komurka]
  7834. * type: 1: Information, 0: Map registered
  7835. *------------------------------------------*/
  7836. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7837. {
  7838. char mapname[MAP_NAME_LENGTH_EXT];
  7839. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7840. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7841. }
  7842. /*==========================================
  7843. * Info about Star Glaldiator hate mob [Komurka]
  7844. * type: 1: Register mob, 0: Information.
  7845. *------------------------------------------*/
  7846. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7847. {
  7848. if( pcdb_checkid(class_) ) {
  7849. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7850. } else if( mobdb_checkid(class_) ) {
  7851. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7852. } else {
  7853. 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);
  7854. }
  7855. }
  7856. /*==========================================
  7857. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7858. *------------------------------------------*/
  7859. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7860. {
  7861. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7862. }
  7863. /*==========================================
  7864. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7865. *------------------------------------------*/
  7866. void clif_feel_hate_reset(struct map_session_data *sd)
  7867. {
  7868. clif_starskill(sd, "", 0, 0, 30);
  7869. }
  7870. /// Equip window (un)tick ack (ZC_CONFIG).
  7871. /// 02d9 <type>.L <value>.L
  7872. /// type:
  7873. /// 0 = open equip window
  7874. /// value:
  7875. /// 0 = disabled
  7876. /// 1 = enabled
  7877. void clif_equiptickack(struct map_session_data* sd, int flag)
  7878. {
  7879. int fd;
  7880. nullpo_retv(sd);
  7881. fd = sd->fd;
  7882. WFIFOHEAD(fd, packet_len(0x2d9));
  7883. WFIFOW(fd, 0) = 0x2d9;
  7884. WFIFOL(fd, 2) = 0;
  7885. WFIFOL(fd, 6) = flag;
  7886. WFIFOSET(fd, packet_len(0x2d9));
  7887. }
  7888. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7889. /// 02da <open equip window>.B
  7890. /// open equip window:
  7891. /// 0 = disabled
  7892. /// 1 = enabled
  7893. void clif_equipcheckbox(struct map_session_data* sd)
  7894. {
  7895. int fd;
  7896. nullpo_retv(sd);
  7897. fd = sd->fd;
  7898. WFIFOHEAD(fd, packet_len(0x2da));
  7899. WFIFOW(fd, 0) = 0x2da;
  7900. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7901. WFIFOSET(fd, packet_len(0x2da));
  7902. }
  7903. /// Sends info about a player's equipped items.
  7904. /// 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)
  7905. /// 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)
  7906. /// 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)
  7907. /// 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)
  7908. /// 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)
  7909. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7910. {
  7911. uint8* buf;
  7912. int i, n, fd, offset = 0;
  7913. #if PACKETVER < 20100629
  7914. const int s = 26;
  7915. #elif PACKETVER < 20120925
  7916. const int s = 28;
  7917. #else
  7918. const int s = 31;
  7919. #endif
  7920. nullpo_retv(sd);
  7921. nullpo_retv(tsd);
  7922. fd = sd->fd;
  7923. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7924. buf = WFIFOP(fd,0);
  7925. #if PACKETVER < 20101124
  7926. WBUFW(buf, 0) = 0x2d7;
  7927. #elif PACKETVER < 20120925
  7928. WBUFW(buf, 0) = 0x859;
  7929. #else
  7930. WBUFW(buf, 0) = 0x997;
  7931. #endif
  7932. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7933. WBUFW(buf,28) = tsd->status.class_;
  7934. WBUFW(buf,30) = tsd->vd.hair_style;
  7935. WBUFW(buf,32) = tsd->vd.head_bottom;
  7936. WBUFW(buf,34) = tsd->vd.head_mid;
  7937. WBUFW(buf,36) = tsd->vd.head_top;
  7938. #if PACKETVER >= 20110111
  7939. WBUFW(buf,38) = tsd->vd.robe;
  7940. offset+= 2;
  7941. buf = WBUFP(buf,2);
  7942. #endif
  7943. WBUFW(buf,38) = tsd->vd.hair_color;
  7944. WBUFW(buf,40) = tsd->vd.cloth_color;
  7945. WBUFB(buf,42) = tsd->vd.sex;
  7946. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7947. {
  7948. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7949. continue;
  7950. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7951. continue;
  7952. // Add item info : refine, identify flag, element, etc.
  7953. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7954. n++;
  7955. }
  7956. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7957. WFIFOSET(fd, WFIFOW(fd, 2));
  7958. }
  7959. /// Display msgstringtable.txt string (ZC_MSG).
  7960. /// 0291 <message>.W
  7961. void clif_msg(struct map_session_data* sd, unsigned short id)
  7962. {
  7963. int fd;
  7964. nullpo_retv(sd);
  7965. fd = sd->fd;
  7966. WFIFOHEAD(fd, packet_len(0x291));
  7967. WFIFOW(fd, 0) = 0x291;
  7968. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7969. WFIFOSET(fd, packet_len(0x291));
  7970. }
  7971. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7972. /// 0x7e2 <message>.W <value>.L
  7973. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7974. {
  7975. int fd = sd->fd;
  7976. WFIFOHEAD(fd, packet_len(0x7e2));
  7977. WFIFOW(fd,0) = 0x7e2;
  7978. WFIFOW(fd,2) = id;
  7979. WFIFOL(fd,4) = value;
  7980. WFIFOSET(fd, packet_len(0x7e2));
  7981. }
  7982. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7983. /// 07e6 <skill id>.W <msg id>.L
  7984. ///
  7985. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7986. /// "[SkillName] Message"
  7987. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7988. {
  7989. int fd = sd->fd;
  7990. WFIFOHEAD(fd, packet_len(0x7e6));
  7991. WFIFOW(fd,0) = 0x7e6;
  7992. WFIFOW(fd,2) = skill_id;
  7993. WFIFOL(fd,4) = msg_id;
  7994. WFIFOSET(fd, packet_len(0x7e6));
  7995. }
  7996. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7997. /// Returns true if the packet was parsed successfully.
  7998. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7999. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8000. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  8001. {
  8002. char *text, *name, *message;
  8003. unsigned int packetlen, textlen, namelen, messagelen;
  8004. int fd = sd->fd;
  8005. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8006. *name_ = NULL;
  8007. *namelen_ = 0;
  8008. *message_ = NULL;
  8009. *messagelen_ = 0;
  8010. packetlen = RFIFOW(fd,info->pos[0]);
  8011. // basic structure checks
  8012. if( packetlen < 4 + 1 )
  8013. { // 4-byte header and at least an empty string is expected
  8014. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8015. return false;
  8016. }
  8017. text = (char*)RFIFOP(fd,info->pos[1]);
  8018. textlen = packetlen - 4;
  8019. // process <name> part of the packet
  8020. if( format == 0 )
  8021. {// name and message are separated by ' : '
  8022. // validate name
  8023. name = text;
  8024. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8025. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8026. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8027. {
  8028. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8029. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8030. set_eof(fd); // Just kick them out to correct it.
  8031. return false;
  8032. }
  8033. message = name + namelen + 3;
  8034. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8035. }
  8036. else
  8037. {// name has fixed width
  8038. if( textlen < NAME_LENGTH + 1 )
  8039. {
  8040. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8041. return false;
  8042. }
  8043. // validate name
  8044. name = text;
  8045. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8046. if( name[namelen] != '\0' )
  8047. { // only restriction is that the name must be zero-terminated
  8048. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8049. return false;
  8050. }
  8051. message = name + NAME_LENGTH;
  8052. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8053. }
  8054. if( messagelen != strnlen(message, messagelen)+1 )
  8055. { // the declared length must match real length
  8056. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8057. return false;
  8058. }
  8059. // verify <message> part of the packet
  8060. if( message[messagelen-1] != '\0' )
  8061. { // message must be zero-terminated
  8062. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8063. return false;
  8064. }
  8065. if( messagelen > CHAT_SIZE_MAX-1 )
  8066. { // messages mustn't be too long
  8067. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8068. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8069. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8070. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8071. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8072. return false;
  8073. }
  8074. *name_ = name;
  8075. *namelen_ = namelen;
  8076. *message_ = message;
  8077. *messagelen_ = messagelen;
  8078. return true;
  8079. }
  8080. // ---------------------
  8081. // clif_guess_PacketVer
  8082. // ---------------------
  8083. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8084. // error codes:
  8085. // 0 - Success
  8086. // 1 - Unknown packet_ver
  8087. // 2 - Invalid account_id
  8088. // 3 - Invalid char_id
  8089. // 4 - Invalid login_id1 (reserved)
  8090. // 5 - Invalid client_tick (reserved)
  8091. // 6 - Invalid sex
  8092. // Only the first 'invalid' error that appears is used.
  8093. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8094. {
  8095. static int err = 1;
  8096. static int packet_ver = -1;
  8097. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  8098. if (get_previous)
  8099. {//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]
  8100. if( error )
  8101. *error = err;
  8102. return packet_ver;
  8103. }
  8104. //By default, start searching on the default one.
  8105. err = 1;
  8106. packet_ver = clif_config.packet_db_ver;
  8107. cmd = RFIFOW(fd,0);
  8108. packet_len = RFIFOREST(fd);
  8109. #define SET_ERROR(n) \
  8110. if( err == 1 )\
  8111. err = n;\
  8112. //define SET_ERROR
  8113. // FIXME: If the packet is not received at once, this will FAIL.
  8114. // Figure out, when it happens, that only part of the packet is
  8115. // received, or fix the function to be able to deal with that
  8116. // case.
  8117. #define CHECK_PACKET_VER() \
  8118. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8119. ;/* not wanttoconnection or wrong length */\
  8120. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8121. { SET_ERROR(2); }/* invalid account_id */\
  8122. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8123. { SET_ERROR(3); }/* invalid char_id */\
  8124. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8125. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8126. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8127. { SET_ERROR(6); }/* invalid sex */\
  8128. else\
  8129. {\
  8130. err = 0;\
  8131. if( error )\
  8132. *error = 0;\
  8133. return packet_ver;\
  8134. }\
  8135. //define CHECK_PACKET_VER
  8136. CHECK_PACKET_VER();//Default packet version found.
  8137. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8138. CHECK_PACKET_VER();
  8139. }
  8140. if( error )
  8141. *error = err;
  8142. packet_ver = -1;
  8143. return -1;
  8144. #undef SET_ERROR
  8145. #undef CHECK_PACKET_VER
  8146. }
  8147. // ------------
  8148. // clif_parse_*
  8149. // ------------
  8150. // Parses incoming (player) connection
  8151. /// Request to connect to map-server.
  8152. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8153. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8154. /// There are various variants of this packet, some of them have padding between fields.
  8155. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8156. {
  8157. struct block_list* bl;
  8158. struct auth_node* node;
  8159. int cmd, account_id, char_id, login_id1, sex;
  8160. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8161. 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])
  8162. if (sd) {
  8163. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8164. return;
  8165. }
  8166. // Only valid packet version get here
  8167. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8168. cmd = RFIFOW(fd,0);
  8169. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8170. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8171. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8172. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8173. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8174. if( packet_ver < 5 || // reject really old client versions
  8175. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8176. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8177. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8178. {// packet version rejected
  8179. 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));
  8180. WFIFOHEAD(fd,packet_len(0x6a));
  8181. WFIFOW(fd,0) = 0x6a;
  8182. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8183. WFIFOSET(fd,packet_len(0x6a));
  8184. set_eof(fd);
  8185. return;
  8186. }
  8187. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8188. clif_authfail_fd(fd,1);// server closed
  8189. return;
  8190. }
  8191. //Check for double login.
  8192. bl = map_id2bl(account_id);
  8193. if(bl && bl->type != BL_PC) {
  8194. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8195. WFIFOHEAD(fd,packet_len(0x6a));
  8196. WFIFOW(fd,0) = 0x6a;
  8197. WFIFOB(fd,2) = 3; // Rejected by server
  8198. WFIFOSET(fd,packet_len(0x6a));
  8199. set_eof(fd);
  8200. return;
  8201. }
  8202. if (bl ||
  8203. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8204. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8205. {
  8206. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8207. return;
  8208. }
  8209. CREATE(sd, TBL_PC, 1);
  8210. sd->fd = fd;
  8211. sd->packet_ver = packet_ver;
  8212. session[fd]->session_data = sd;
  8213. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8214. #if PACKETVER < 20070521
  8215. WFIFOHEAD(fd,4);
  8216. WFIFOL(fd,0) = sd->bl.id;
  8217. WFIFOSET(fd,4);
  8218. #else
  8219. WFIFOHEAD(fd,packet_len(0x283));
  8220. WFIFOW(fd,0) = 0x283;
  8221. WFIFOL(fd,2) = sd->bl.id;
  8222. WFIFOSET(fd,packet_len(0x283));
  8223. #endif
  8224. chrif_authreq(sd,false);
  8225. }
  8226. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8227. /// 007d
  8228. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8229. {
  8230. int i;
  8231. bool guild_notice = false;
  8232. if(sd->bl.prev != NULL)
  8233. return;
  8234. if (!sd->state.active) { //Character loading is not complete yet!
  8235. //Let pc_reg_received reinvoke this when ready.
  8236. sd->state.connect_new = 0;
  8237. return;
  8238. }
  8239. if (sd->state.rewarp) { //Rewarp player.
  8240. sd->state.rewarp = 0;
  8241. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8242. return;
  8243. }
  8244. sd->state.warping = 0;
  8245. // look
  8246. #if PACKETVER < 4
  8247. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8248. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8249. #else
  8250. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8251. #endif
  8252. if(sd->vd.cloth_color)
  8253. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8254. // item
  8255. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8256. pc_checkitem(sd);
  8257. // cart
  8258. if(pc_iscarton(sd)) {
  8259. clif_cartlist(sd);
  8260. clif_updatestatus(sd,SP_CARTINFO);
  8261. }
  8262. // weight
  8263. clif_updatestatus(sd,SP_WEIGHT);
  8264. clif_updatestatus(sd,SP_MAXWEIGHT);
  8265. // guild
  8266. // (needs to go before clif_spawn() to show guild emblems correctly)
  8267. if(sd->status.guild_id)
  8268. guild_send_memberinfoshort(sd,1);
  8269. if(battle_config.pc_invincible_time > 0) {
  8270. if(map_flag_gvg(sd->bl.m))
  8271. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8272. else
  8273. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8274. }
  8275. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8276. map_spawnmobs(sd->bl.m);
  8277. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8278. map[sd->bl.m].users_pvp++;
  8279. }
  8280. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8281. // reset the callshop flag if the player changes map
  8282. sd->state.callshop = 0;
  8283. if(map_addblock(&sd->bl))
  8284. return;
  8285. clif_spawn(&sd->bl);
  8286. // Party
  8287. // (needs to go after clif_spawn() to show hp bars correctly)
  8288. if(sd->status.party_id) {
  8289. party_send_movemap(sd);
  8290. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8291. }
  8292. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8293. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8294. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8295. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8296. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8297. sd->pvp_rank = 0;
  8298. sd->pvp_lastusers = 0;
  8299. sd->pvp_point = 5;
  8300. sd->pvp_won = 0;
  8301. sd->pvp_lost = 0;
  8302. }
  8303. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8304. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8305. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8306. if (map[sd->bl.m].flag.gvg_dungeon)
  8307. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8308. if( map_flag_gvg(sd->bl.m) )
  8309. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8310. // info about nearby objects
  8311. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8312. 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);
  8313. // pet
  8314. if( sd->pd ) {
  8315. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8316. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8317. pet_menu(sd, 3); //Option 3 is return to egg.
  8318. } else {
  8319. if(map_addblock(&sd->pd->bl))
  8320. return;
  8321. clif_spawn(&sd->pd->bl);
  8322. clif_send_petdata(sd,sd->pd,0,0);
  8323. clif_send_petstatus(sd);
  8324. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8325. }
  8326. }
  8327. //homunculus [blackhole89]
  8328. if( hom_is_active(sd->hd) ) {
  8329. if(map_addblock(&sd->hd->bl))
  8330. return;
  8331. clif_spawn(&sd->hd->bl);
  8332. clif_send_homdata(sd,SP_ACK,0);
  8333. clif_hominfo(sd,sd->hd,1);
  8334. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8335. clif_homskillinfoblock(sd);
  8336. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8337. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8338. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8339. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8340. }
  8341. if( sd->md ) {
  8342. if(map_addblock(&sd->md->bl))
  8343. return;
  8344. clif_spawn(&sd->md->bl);
  8345. clif_mercenary_info(sd);
  8346. clif_mercenary_skillblock(sd);
  8347. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8348. }
  8349. if( sd->ed ) {
  8350. map_addblock(&sd->ed->bl);
  8351. clif_spawn(&sd->ed->bl);
  8352. clif_elemental_info(sd);
  8353. clif_elemental_updatestatus(sd,SP_HP);
  8354. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8355. clif_elemental_updatestatus(sd,SP_SP);
  8356. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8357. }
  8358. if(sd->state.connect_new) {
  8359. int lv;
  8360. guild_notice = true;
  8361. sd->state.connect_new = 0;
  8362. clif_skillinfoblock(sd);
  8363. clif_hotkeys_send(sd);
  8364. clif_updatestatus(sd,SP_BASEEXP);
  8365. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8366. clif_updatestatus(sd,SP_JOBEXP);
  8367. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8368. clif_updatestatus(sd,SP_SKILLPOINT);
  8369. clif_initialstatus(sd);
  8370. if (sd->sc.option&OPTION_FALCON)
  8371. clif_status_load(&sd->bl, SI_FALCON, 1);
  8372. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8373. clif_status_load(&sd->bl, SI_RIDING, 1);
  8374. else if (sd->sc.option&OPTION_WUGRIDER)
  8375. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8376. else if (sd->sc.data[SC_ALL_RIDING])
  8377. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8378. if(sd->status.manner < 0)
  8379. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8380. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8381. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8382. if(sd->bl.m == sd->feel_map[0].m
  8383. || sd->bl.m == sd->feel_map[1].m
  8384. || sd->bl.m == sd->feel_map[2].m)
  8385. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8386. }
  8387. if(sd->pd && sd->pd->pet.intimate > 900)
  8388. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8389. if(hom_is_active(sd->hd))
  8390. hom_init_timers(sd->hd);
  8391. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8392. sd->state.night = 1;
  8393. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8394. }
  8395. // Notify everyone that this char logged in [Skotlex].
  8396. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8397. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8398. //Login Event
  8399. npc_script_event(sd, NPCE_LOGIN);
  8400. }
  8401. } else {
  8402. //For some reason the client "loses" these on warp/map-change.
  8403. clif_updatestatus(sd,SP_STR);
  8404. clif_updatestatus(sd,SP_AGI);
  8405. clif_updatestatus(sd,SP_VIT);
  8406. clif_updatestatus(sd,SP_INT);
  8407. clif_updatestatus(sd,SP_DEX);
  8408. clif_updatestatus(sd,SP_LUK);
  8409. // abort currently running script
  8410. sd->state.using_fake_npc = 0;
  8411. sd->state.menu_or_input = 0;
  8412. sd->npc_menu = 0;
  8413. if(sd->npc_id)
  8414. npc_event_dequeue(sd);
  8415. }
  8416. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8417. #if PACKETVER >= 20070918
  8418. clif_partyinvitationstate(sd);
  8419. clif_equipcheckbox(sd);
  8420. #endif
  8421. #ifdef VIP_ENABLE
  8422. if (!sd->disableshowrate) {
  8423. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8424. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8425. }
  8426. #endif
  8427. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8428. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8429. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8430. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8431. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8432. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8433. { //Display night.
  8434. if( !sd->state.night )
  8435. {
  8436. sd->state.night = 1;
  8437. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8438. }
  8439. }
  8440. else if( sd->state.night )
  8441. { //Clear night display.
  8442. sd->state.night = 0;
  8443. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8444. }
  8445. if( map[sd->bl.m].flag.battleground )
  8446. {
  8447. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8448. if( map[sd->bl.m].flag.battleground == 2 )
  8449. clif_bg_updatescore_single(sd);
  8450. }
  8451. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8452. {
  8453. char output[128];
  8454. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8455. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8456. }
  8457. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8458. map[sd->bl.m].hpmeter_visible++;
  8459. sd->state.hpmeter_visible = 1;
  8460. }
  8461. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8462. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8463. sd->state.changemap = false;
  8464. // Instances do not need their own channels
  8465. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8466. channel_mjoin(sd); //join new map
  8467. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8468. clif_guild_notice(sd, sd->guild); // Displays at end
  8469. mail_clear(sd);
  8470. clif_maptypeproperty2(&sd->bl,SELF);
  8471. /* Guild Aura Init */
  8472. if( sd->state.gmaster_flag ) {
  8473. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8474. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8475. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8476. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8477. }
  8478. if( sd->state.vending ) { /* show we have a vending */
  8479. clif_openvending(sd,sd->bl.id,sd->vending);
  8480. clif_showvendingboard(&sd->bl,sd->message,0);
  8481. }
  8482. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8483. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8484. npc_script_event(sd, NPCE_LOADMAP);
  8485. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8486. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8487. if (sd->sc.opt2) //Client loses these on warp.
  8488. clif_changeoption(&sd->bl);
  8489. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8490. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8491. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8492. }
  8493. clif_weather_check(sd);
  8494. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8495. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8496. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8497. else
  8498. sd->areanpc_id = 0;
  8499. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8500. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8501. pc_setdead(sd);
  8502. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8503. if(pc_isdead(sd))
  8504. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8505. else {
  8506. skill_usave_trigger(sd);
  8507. if (battle_config.spawn_direction)
  8508. clif_changed_dir(&sd->bl, SELF);
  8509. }
  8510. // Trigger skill effects if you appear standing on them
  8511. if(!battle_config.pc_invincible_time)
  8512. skill_unit_move(&sd->bl,gettick(),1);
  8513. // NPC Quest / Event Icon Check [Kisuka]
  8514. #if PACKETVER >= 20090218
  8515. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8516. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8517. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8518. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8519. if( sd->class_ == qi->job )
  8520. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8521. } else {
  8522. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8523. }
  8524. }
  8525. }
  8526. #endif
  8527. }
  8528. /// Server's tick (ZC_NOTIFY_TIME).
  8529. /// 007f <time>.L
  8530. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8531. {
  8532. int fd = sd->fd;
  8533. WFIFOHEAD(fd,packet_len(0x7f));
  8534. WFIFOW(fd,0) = 0x7f;
  8535. WFIFOL(fd,2) = time;
  8536. WFIFOSET(fd,packet_len(0x7f));
  8537. }
  8538. /// Request for server's tick.
  8539. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8540. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8541. /// There are various variants of this packet, some of them have padding between fields.
  8542. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8543. {
  8544. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8545. clif_notify_time(sd, gettick());
  8546. }
  8547. /// Sends hotkey bar.
  8548. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8549. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8550. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8551. void clif_hotkeys_send(struct map_session_data *sd) {
  8552. #ifdef HOTKEY_SAVING
  8553. const int fd = sd->fd;
  8554. int i;
  8555. #if PACKETVER < 20090603
  8556. const int cmd = 0x2b9;
  8557. #else
  8558. const int cmd = 0x7d9;
  8559. #endif
  8560. if (!fd) return;
  8561. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8562. WFIFOW(fd, 0) = cmd;
  8563. for(i = 0; i < MAX_HOTKEYS; i++) {
  8564. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8565. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8566. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8567. }
  8568. WFIFOSET(fd, packet_len(cmd));
  8569. #endif
  8570. }
  8571. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8572. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8573. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8574. #ifdef HOTKEY_SAVING
  8575. unsigned short idx;
  8576. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8577. idx = RFIFOW(fd, info->pos[0]);
  8578. if (idx >= MAX_HOTKEYS) return;
  8579. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8580. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8581. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8582. #endif
  8583. }
  8584. /// Displays cast-like progress bar (ZC_PROGRESS).
  8585. /// 02f0 <color>.L <time>.L
  8586. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8587. {
  8588. int fd = sd->fd;
  8589. WFIFOHEAD(fd,packet_len(0x2f0));
  8590. WFIFOW(fd,0) = 0x2f0;
  8591. WFIFOL(fd,2) = color;
  8592. WFIFOL(fd,6) = second;
  8593. WFIFOSET(fd,packet_len(0x2f0));
  8594. }
  8595. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8596. /// 02f2
  8597. void clif_progressbar_abort(struct map_session_data * sd)
  8598. {
  8599. int fd = sd->fd;
  8600. WFIFOHEAD(fd,packet_len(0x2f2));
  8601. WFIFOW(fd,0) = 0x2f2;
  8602. WFIFOSET(fd,packet_len(0x2f2));
  8603. }
  8604. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8605. /// 02f1
  8606. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8607. {
  8608. int npc_id = sd->progressbar.npc_id;
  8609. if( gettick() < sd->progressbar.timeout && sd->st )
  8610. sd->st->state = END;
  8611. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8612. npc_scriptcont(sd, npc_id, false);
  8613. }
  8614. /// Request to walk to a certain position on the current map.
  8615. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8616. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8617. /// There are various variants of this packet, some of them have padding between fields.
  8618. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8619. {
  8620. short x, y;
  8621. if (pc_isdead(sd)) {
  8622. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8623. return;
  8624. }
  8625. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8626. ; //You CAN walk on this OPT1 value.
  8627. else if( sd->progressbar.npc_id )
  8628. clif_progressbar_abort(sd);
  8629. else if (pc_cant_act(sd))
  8630. return;
  8631. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8632. return;
  8633. // Cloaking wall check is actually updated when you click to process next movement
  8634. // not when you move each cell. This is official behaviour.
  8635. if (sd->sc.data[SC_CLOAKING])
  8636. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8637. pc_delinvincibletimer(sd);
  8638. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8639. //Set last idle time... [Skotlex]
  8640. if (battle_config.idletime_option&IDLE_WALK)
  8641. sd->idletime = last_tick;
  8642. unit_walktoxy(&sd->bl, x, y, 4);
  8643. }
  8644. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8645. /// 018b <result>.W
  8646. /// result:
  8647. /// 0 = disconnect (quit)
  8648. /// 1 = cannot disconnect (wait 10 seconds)
  8649. /// ? = ignored
  8650. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8651. {
  8652. int fd = sd->fd;
  8653. WFIFOHEAD(fd,packet_len(0x18b));
  8654. WFIFOW(fd,0) = 0x18b;
  8655. WFIFOW(fd,2) = result;
  8656. WFIFOSET(fd,packet_len(0x18b));
  8657. }
  8658. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8659. /// 018a <type>.W
  8660. /// type:
  8661. /// 0 = quit
  8662. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8663. {
  8664. /* Rovert's prevent logout option fixed [Valaris] */
  8665. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8666. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8667. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8668. {
  8669. set_eof(fd);
  8670. pc_damage_log_clear(sd,0);
  8671. clif_disconnect_ack(sd, 0);
  8672. } else {
  8673. clif_disconnect_ack(sd, 1);
  8674. }
  8675. }
  8676. /// Requesting unit's name.
  8677. /// 0094 <id>.L (CZ_REQNAME)
  8678. /// 0368 <id>.L (CZ_REQNAME2)
  8679. /// There are various variants of this packet, some of them have padding between fields.
  8680. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8681. {
  8682. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8683. struct block_list* bl;
  8684. //struct status_change *sc;
  8685. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8686. id = sd->bl.id;
  8687. bl = map_id2bl(id);
  8688. if( bl == NULL )
  8689. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8690. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8691. return; // Block namerequests past view range
  8692. // 'see people in GM hide' cheat detection
  8693. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8694. sc = status_get_sc(bl);
  8695. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8696. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8697. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8698. ) {
  8699. char gm_msg[256];
  8700. 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);
  8701. ShowWarning(gm_msg);
  8702. // information is sent to all online GMs
  8703. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8704. return;
  8705. }
  8706. */
  8707. clif_charnameack(fd, bl);
  8708. }
  8709. /// Validates and processes global messages
  8710. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8711. /// There are various variants of this packet.
  8712. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8713. {
  8714. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8715. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8716. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8717. char *name, *message, *fakename = NULL;
  8718. int namelen, messagelen;
  8719. bool is_fake;
  8720. // validate packet and retrieve name and message
  8721. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8722. return;
  8723. if( is_atcommand(fd, sd, message, 1) )
  8724. return;
  8725. if (sd->sc.cant.chat)
  8726. return; //no "chatting" while muted.
  8727. if( battle_config.min_chat_delay ) { //[Skotlex]
  8728. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8729. return;
  8730. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8731. }
  8732. if (battle_config.idletime_option&IDLE_CHAT)
  8733. sd->idletime = last_tick;
  8734. if( sd->gcbind ) {
  8735. channel_send(sd->gcbind,sd,message);
  8736. return;
  8737. }
  8738. /**
  8739. * Fake Name Design by FatalEror (bug report #9)
  8740. **/
  8741. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8742. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8743. strcpy(fakename, sd->fakename);
  8744. strcat(fakename, " : ");
  8745. strcat(fakename, message);
  8746. textlen = strlen(fakename) + 1;
  8747. }
  8748. // send message to others (using the send buffer for temp. storage)
  8749. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8750. // send back message to the speaker
  8751. if( is_fake ) {
  8752. WFIFOW(fd,0) = 0x8e;
  8753. WFIFOW(fd,2) = textlen + 4;
  8754. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8755. aFree(fakename);
  8756. } else {
  8757. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8758. WFIFOW(fd,0) = 0x8e;
  8759. }
  8760. WFIFOSET(fd, WFIFOW(fd,2));
  8761. #ifdef PCRE_SUPPORT
  8762. // trigger listening npcs
  8763. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8764. #endif
  8765. // Chat logging type 'O' / Global Chat
  8766. 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);
  8767. }
  8768. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8769. /// Request to warp to a map on given coordinates.
  8770. /// 0140 <map name>.16B <x>.W <y>.W
  8771. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8772. {
  8773. char command[MAP_NAME_LENGTH_EXT+25];
  8774. char* map_name;
  8775. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8776. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8777. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8778. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8779. RFIFOW(fd,info->pos[1]), //x
  8780. RFIFOW(fd,info->pos[2])); //y
  8781. is_atcommand(fd, sd, command, 1);
  8782. }
  8783. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8784. /// 009c <id>.L <head dir>.W <dir>.B
  8785. /// head dir:
  8786. /// 0 = straight
  8787. /// 1 = turned CW
  8788. /// 2 = turned CCW
  8789. /// dir:
  8790. /// 0 = north
  8791. /// 1 = northwest
  8792. /// 2 = west
  8793. /// 3 = southwest
  8794. /// 4 = south
  8795. /// 5 = southeast
  8796. /// 6 = east
  8797. /// 7 = northeast
  8798. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8799. {
  8800. unsigned char buf[64];
  8801. WBUFW(buf,0) = 0x9c;
  8802. WBUFL(buf,2) = bl->id;
  8803. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8804. WBUFB(buf,8) = unit_getdir(bl);
  8805. clif_send(buf, packet_len(0x9c), bl, target);
  8806. if (disguised(bl)) {
  8807. WBUFL(buf,2) = -bl->id;
  8808. WBUFW(buf,6) = 0;
  8809. clif_send(buf, packet_len(0x9c), bl, SELF);
  8810. }
  8811. }
  8812. /// Request to change own body and head direction.
  8813. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8814. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8815. /// There are various variants of this packet, some of them have padding between fields.
  8816. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8817. {
  8818. unsigned char headdir, dir;
  8819. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8820. headdir = RFIFOB(fd,info->pos[0]);
  8821. dir = RFIFOB(fd,info->pos[1]);
  8822. pc_setdir(sd, dir, headdir);
  8823. clif_changed_dir(&sd->bl, AREA_WOS);
  8824. }
  8825. /// Request to show an emotion (CZ_REQ_EMOTION).
  8826. /// 00bf <type>.B
  8827. /// type:
  8828. /// @see enum emotion_type
  8829. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8830. {
  8831. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8832. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8833. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8834. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8835. return;
  8836. }
  8837. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8838. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8839. sd->emotionlasttime = time(NULL);
  8840. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8841. return;
  8842. }
  8843. sd->emotionlasttime = time(NULL);
  8844. if (battle_config.idletime_option&IDLE_EMOTION)
  8845. sd->idletime = last_tick;
  8846. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8847. emoticon = rnd()%6+E_DICE1;
  8848. }
  8849. clif_emotion(&sd->bl, emoticon);
  8850. } else
  8851. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8852. }
  8853. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8854. /// 00c2 <count>.L
  8855. void clif_user_count(struct map_session_data* sd, int count)
  8856. {
  8857. int fd = sd->fd;
  8858. WFIFOHEAD(fd,packet_len(0xc2));
  8859. WFIFOW(fd,0) = 0xc2;
  8860. WFIFOL(fd,2) = count;
  8861. WFIFOSET(fd,packet_len(0xc2));
  8862. }
  8863. /// /w /who (CZ_REQ_USER_COUNT).
  8864. /// Request to display amount of currently connected players.
  8865. /// 00c1
  8866. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8867. {
  8868. clif_user_count(sd, map_getusers());
  8869. }
  8870. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8871. {
  8872. if (pc_isdead(sd)) {
  8873. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8874. return;
  8875. }
  8876. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  8877. // (not all are included in pc_can_attack)
  8878. if (sd->sc.count &&
  8879. (sd->sc.data[SC_TRICKDEAD] ||
  8880. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  8881. sd->sc.data[SC_BLADESTOP] ||
  8882. sd->sc.data[SC__MANHOLE] ))
  8883. return;
  8884. if(action_type != 0x00 && action_type != 0x07)
  8885. pc_stop_walking(sd, 1);
  8886. pc_stop_attack(sd);
  8887. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8888. target_id = sd->bl.id;
  8889. switch(action_type)
  8890. {
  8891. case 0x00: // once attack
  8892. case 0x07: // continuous attack
  8893. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8894. return;
  8895. if( sd->sc.option&OPTION_COSTUME )
  8896. return;
  8897. if( sd->sc.option&OPTION_COSTUME )
  8898. return;
  8899. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8900. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8901. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8902. return;
  8903. }
  8904. }
  8905. pc_delinvincibletimer(sd);
  8906. if (battle_config.idletime_option&IDLE_ATTACK)
  8907. sd->idletime = last_tick;
  8908. unit_attack(&sd->bl, target_id, action_type != 0);
  8909. break;
  8910. case 0x02: // sitdown
  8911. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8912. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8913. break;
  8914. }
  8915. if(pc_issit(sd)) {
  8916. //Bugged client? Just refresh them.
  8917. clif_sitting(&sd->bl);
  8918. return;
  8919. }
  8920. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8921. break;
  8922. if (sd->sc.count && (
  8923. sd->sc.data[SC_DANCING] ||
  8924. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8925. )) //No sitting during these states either.
  8926. break;
  8927. if (battle_config.idletime_option&IDLE_SIT)
  8928. sd->idletime = last_tick;
  8929. pc_setsit(sd);
  8930. skill_sit(sd, 1);
  8931. clif_sitting(&sd->bl);
  8932. break;
  8933. case 0x03: // standup
  8934. if (!pc_issit(sd)) {
  8935. //Bugged client? Just refresh them.
  8936. clif_standing(&sd->bl);
  8937. return;
  8938. }
  8939. if (pc_setstand(sd, false)) {
  8940. if (battle_config.idletime_option&IDLE_SIT)
  8941. sd->idletime = last_tick;
  8942. skill_sit(sd, 0);
  8943. clif_standing(&sd->bl);
  8944. }
  8945. break;
  8946. }
  8947. }
  8948. /// Request for an action.
  8949. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8950. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8951. /// action:
  8952. /// 0 = attack
  8953. /// 1 = pick up item
  8954. /// 2 = sit down
  8955. /// 3 = stand up
  8956. /// 7 = continous attack
  8957. /// 12 = (touch skill?)
  8958. /// There are various variants of this packet, some of them have padding between fields.
  8959. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8960. {
  8961. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8962. clif_parse_ActionRequest_sub(sd,
  8963. RFIFOB(fd,info->pos[1]),
  8964. RFIFOL(fd,info->pos[0]),
  8965. gettick()
  8966. );
  8967. }
  8968. /// Response to the death/system menu (CZ_RESTART).
  8969. /// 00b2 <type>.B
  8970. /// type:
  8971. /// 0 = restart (respawn)
  8972. /// 1 = char-select (disconnect)
  8973. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8974. {
  8975. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8976. case 0x00:
  8977. pc_respawn(sd,CLR_OUTSIGHT);
  8978. break;
  8979. case 0x01:
  8980. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8981. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8982. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8983. { //Send to char-server for character selection.
  8984. pc_damage_log_clear(sd,0);
  8985. chrif_charselectreq(sd, session[fd]->client_addr);
  8986. } else {
  8987. clif_disconnect_ack(sd, 1);
  8988. }
  8989. break;
  8990. }
  8991. }
  8992. /// Validates and processes whispered messages (CZ_WHISPER).
  8993. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8994. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8995. {
  8996. struct map_session_data* dstsd;
  8997. int i;
  8998. char *target, *message;
  8999. int namelen, messagelen;
  9000. // validate packet and retrieve name and message
  9001. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9002. return;
  9003. if ( is_atcommand(fd, sd, message, 1) )
  9004. return;
  9005. if (sd->sc.cant.chat)
  9006. return; //no "chatting" while muted.
  9007. if (battle_config.min_chat_delay) { //[Skotlex]
  9008. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9009. return;
  9010. }
  9011. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9012. }
  9013. if (battle_config.idletime_option&IDLE_CHAT)
  9014. sd->idletime = last_tick;
  9015. // Chat logging type 'W' / Whisper
  9016. 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);
  9017. //-------------------------------------------------------//
  9018. // Lordalfa - Paperboy - To whisper NPC commands //
  9019. //-------------------------------------------------------//
  9020. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9021. {
  9022. char* str = target+4; //Skip the NPC: string part.
  9023. struct npc_data* npc;
  9024. if ((npc = npc_name2id(str))) {
  9025. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9026. char *split;
  9027. char output[256];
  9028. str = message;
  9029. // skip codepage indicator, if detected
  9030. if( str[0] == '|' && strlen(str) >= 4 )
  9031. str += 3;
  9032. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9033. split = strchr(str,'#');
  9034. if( split == NULL ) { // use the remaining string
  9035. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9036. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9037. split_data[i][0] = '\0';
  9038. break;
  9039. }
  9040. *split = '\0';
  9041. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9042. str = split+1;
  9043. }
  9044. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9045. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9046. set_var(sd,output,(char *) split_data[i]);
  9047. }
  9048. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9049. npc_event(sd,output,0); // Calls the NPC label
  9050. return;
  9051. }
  9052. } else if( target[0] == '#' ) {
  9053. struct Channel *channel = NULL;
  9054. char* chname = target;
  9055. channel = channel_name2channel(chname,sd,3);
  9056. if(channel){
  9057. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9058. channel_send(channel,sd,message);
  9059. }
  9060. else if( channel->pass[0] == '\0') { //no pass needed
  9061. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9062. }
  9063. else {
  9064. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9065. }
  9066. return;
  9067. }
  9068. }
  9069. // searching destination character
  9070. dstsd = map_nick2sd(target);
  9071. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9072. // player is not on this map-server
  9073. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9074. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9075. // and if we ask for 'Test', we must not contact 'test' player
  9076. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9077. intif_wis_message(sd, target, message, messagelen);
  9078. return;
  9079. }
  9080. // if player ignores everyone
  9081. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9082. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9083. clif_wis_end(fd, 1); // 1: target character is not logged in
  9084. else
  9085. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9086. return;
  9087. }
  9088. // if player is autotrading
  9089. if (dstsd->state.autotrade == 1) {
  9090. char output[256];
  9091. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9092. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9093. return;
  9094. }
  9095. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9096. // if player ignores the source character
  9097. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9098. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9099. clif_wis_end(fd, 2); // 2: ignored by target
  9100. return;
  9101. }
  9102. }
  9103. // notify sender of success
  9104. clif_wis_end(fd, 0); // 0: success to send wisper
  9105. // Normal message
  9106. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9107. }
  9108. /// /b /nb (CZ_BROADCAST).
  9109. /// Request to broadcast a message on whole server.
  9110. /// 0099 <packet len>.W <text>.?B 00
  9111. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9112. char command[CHAT_SIZE_MAX+11];
  9113. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9114. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9115. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9116. // as the length varies depending on the command used, just block unreasonably long strings
  9117. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9118. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9119. is_atcommand(fd, sd, command, 1);
  9120. }
  9121. /// Request to pick up an item.
  9122. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9123. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9124. /// There are various variants of this packet, some of them have padding between fields.
  9125. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9126. {
  9127. struct flooritem_data *fitem;
  9128. int map_object_id;
  9129. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9130. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9131. do {
  9132. if (pc_isdead(sd)) {
  9133. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9134. break;
  9135. }
  9136. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9137. break;
  9138. if (pc_cant_act(sd))
  9139. break;
  9140. if (!pc_takeitem(sd, fitem))
  9141. break;
  9142. return;
  9143. } while (0);
  9144. // Client REQUIRES a fail packet or you can no longer pick items.
  9145. clif_additem(sd,0,0,6);
  9146. }
  9147. /// Request to drop an item.
  9148. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9149. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9150. /// There are various variants of this packet, some of them have padding between fields.
  9151. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9152. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9153. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9154. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9155. for(;;) {
  9156. if (pc_isdead(sd))
  9157. break;
  9158. if (pc_cant_act2(sd) || sd->npc_id)
  9159. break;
  9160. if (sd->sc.count && (
  9161. sd->sc.data[SC_AUTOCOUNTER] ||
  9162. sd->sc.data[SC_BLADESTOP] ||
  9163. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9164. ))
  9165. break;
  9166. if (!pc_dropitem(sd, item_index, item_amount))
  9167. break;
  9168. if (battle_config.idletime_option&IDLE_DROPITEM)
  9169. sd->idletime = last_tick;
  9170. return;
  9171. }
  9172. //Because the client does not like being ignored.
  9173. clif_dropitem(sd, item_index,0);
  9174. }
  9175. /// Request to use an item.
  9176. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9177. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9178. /// There are various variants of this packet, some of them have padding between fields.
  9179. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9180. {
  9181. int n;
  9182. if (pc_isdead(sd)) {
  9183. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9184. return;
  9185. }
  9186. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9187. return;
  9188. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9189. if (battle_config.idletime_option&IDLE_USEITEM)
  9190. sd->idletime = last_tick;
  9191. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9192. if(n <0 || n >= MAX_INVENTORY)
  9193. return;
  9194. if (!pc_useitem(sd,n))
  9195. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9196. }
  9197. /// Request to equip an item
  9198. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9199. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9200. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9201. {
  9202. int index;
  9203. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9204. if(pc_isdead(sd)) {
  9205. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9206. return;
  9207. }
  9208. index = RFIFOW(fd,info->pos[0])-2;
  9209. if (index < 0 || index >= MAX_INVENTORY)
  9210. return; //Out of bounds check.
  9211. if(sd->npc_id && !sd->npc_item_flag) {
  9212. return;
  9213. } else if (sd->state.storage_flag || sd->sc.opt1)
  9214. ; //You can equip/unequip stuff while storage is open/under status changes
  9215. else if (pc_cant_act2(sd))
  9216. return;
  9217. if(!sd->status.inventory[index].identify) {
  9218. clif_equipitemack(sd,index,0,0); // fail
  9219. return;
  9220. }
  9221. if(!sd->inventory_data[index])
  9222. return;
  9223. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9224. pet_equipitem(sd,index);
  9225. return;
  9226. }
  9227. if (battle_config.idletime_option&IDLE_USEITEM)
  9228. sd->idletime = last_tick;
  9229. //Client doesn't send the position for ammo.
  9230. if(sd->inventory_data[index]->type == IT_AMMO)
  9231. pc_equipitem(sd,index,EQP_AMMO);
  9232. else {
  9233. int req_pos;
  9234. #if PACKETVER >= 20120925
  9235. req_pos = RFIFOL(fd,info->pos[1]);
  9236. #else
  9237. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9238. #endif
  9239. pc_equipitem(sd,index,req_pos);
  9240. }
  9241. }
  9242. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9243. /// 00ab <index>.W
  9244. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9245. {
  9246. int index;
  9247. if(pc_isdead(sd)) {
  9248. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9249. return;
  9250. }
  9251. if (sd->npc_id && !sd->npc_item_flag) {
  9252. return;
  9253. } else if (sd->state.storage_flag || sd->sc.opt1)
  9254. ; //You can equip/unequip stuff while storage is open/under status changes
  9255. else if (pc_cant_act2(sd))
  9256. return;
  9257. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9258. if (battle_config.idletime_option&IDLE_USEITEM)
  9259. sd->idletime = last_tick;
  9260. pc_unequipitem(sd,index,1);
  9261. }
  9262. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9263. /// 0090 <id>.L <type>.B
  9264. /// type:
  9265. /// 1 = click
  9266. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9267. {
  9268. struct block_list *bl;
  9269. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9270. if(pc_isdead(sd)) {
  9271. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9272. return;
  9273. }
  9274. if (pc_cant_act2(sd) || sd->npc_id)
  9275. return;
  9276. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9277. //type = RFIFOB(fd,info->pos[1]);
  9278. if (!bl) return;
  9279. switch (bl->type) {
  9280. case BL_MOB:
  9281. case BL_PC:
  9282. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9283. break;
  9284. case BL_NPC:
  9285. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9286. npc_click(sd,(TBL_NPC*)bl);
  9287. break;
  9288. }
  9289. }
  9290. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9291. /// 00c5 <id>.L <type>.B
  9292. /// type:
  9293. /// 0 = buy
  9294. /// 1 = sell
  9295. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9296. {
  9297. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9298. if (sd->state.trading)
  9299. return;
  9300. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9301. }
  9302. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9303. /// 00ca <result>.B
  9304. /// result:
  9305. /// 0 = "The deal has successfully completed."
  9306. /// 1 = "You do not have enough zeny."
  9307. /// 2 = "You are over your Weight Limit."
  9308. /// 3 = "Out of the maximum capacity, you have too many items."
  9309. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9310. {
  9311. int fd = sd->fd;
  9312. WFIFOHEAD(fd,packet_len(0xca));
  9313. WFIFOW(fd,0) = 0xca;
  9314. WFIFOB(fd,2) = result;
  9315. WFIFOSET(fd,packet_len(0xca));
  9316. }
  9317. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9318. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9319. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9320. {
  9321. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9322. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9323. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9324. int result;
  9325. if( sd->state.trading || !sd->npc_shopid )
  9326. result = 1;
  9327. else
  9328. result = npc_buylist(sd,n,item_list);
  9329. sd->npc_shopid = 0; //Clear shop data.
  9330. clif_npc_buy_result(sd, result);
  9331. }
  9332. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9333. /// 00cb <result>.B
  9334. /// result:
  9335. /// 0 = "The deal has successfully completed."
  9336. /// 1 = "The deal has failed."
  9337. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9338. {
  9339. int fd = sd->fd;
  9340. WFIFOHEAD(fd,packet_len(0xcb));
  9341. WFIFOW(fd,0) = 0xcb;
  9342. WFIFOB(fd,2) = result;
  9343. WFIFOSET(fd,packet_len(0xcb));
  9344. }
  9345. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9346. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9347. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9348. {
  9349. int fail=0,n;
  9350. unsigned short *item_list;
  9351. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9352. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9353. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9354. if (sd->state.trading || !sd->npc_shopid)
  9355. fail = 1;
  9356. else
  9357. fail = npc_selllist(sd,n,item_list);
  9358. sd->npc_shopid = 0; //Clear shop data.
  9359. clif_npc_sell_result(sd, fail);
  9360. }
  9361. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9362. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9363. /// type:
  9364. /// 0 = private
  9365. /// 1 = public
  9366. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9367. {
  9368. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9369. int len = RFIFOW(fd,info->pos[0])-15;
  9370. int limit = RFIFOW(fd,info->pos[1]);
  9371. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9372. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9373. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9374. char s_password[CHATROOM_PASS_SIZE];
  9375. char s_title[CHATROOM_TITLE_SIZE];
  9376. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9377. return;
  9378. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9379. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9380. return;
  9381. }
  9382. if( npc_isnear(&sd->bl) ) {
  9383. // uncomment to send msg_txt.
  9384. //char output[150];
  9385. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9386. //clif_displaymessage(sd->fd, output);
  9387. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9388. return;
  9389. }
  9390. if( len <= 0 )
  9391. return; // invalid input
  9392. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9393. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9394. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9395. }
  9396. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9397. /// 00d9 <chat ID>.L <passwd>.8B
  9398. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9399. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9400. int chatid = RFIFOL(fd,info->pos[0]);
  9401. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9402. chat_joinchat(sd,chatid,password);
  9403. }
  9404. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9405. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9406. /// type:
  9407. /// 0 = private
  9408. /// 1 = public
  9409. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9410. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9411. int len = RFIFOW(fd,info->pos[0])-15;
  9412. int limit = RFIFOW(fd,info->pos[1]);
  9413. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9414. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9415. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9416. char s_password[CHATROOM_PASS_SIZE];
  9417. char s_title[CHATROOM_TITLE_SIZE];
  9418. if( len <= 0 )
  9419. return; // invalid input
  9420. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9421. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9422. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9423. }
  9424. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9425. /// 00e0 <role>.L <nick>.24B
  9426. /// role:
  9427. /// 0 = owner
  9428. /// 1 = normal
  9429. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9430. {
  9431. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9432. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9433. }
  9434. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9435. /// 00e2 <name>.24B
  9436. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9437. {
  9438. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9439. }
  9440. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9441. /// 00e3
  9442. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9443. {
  9444. chat_leavechat(sd,0);
  9445. }
  9446. //Handles notifying asker and rejecter of what has just ocurred.
  9447. //Type is used to determine the correct msg_txt to use:
  9448. //0:
  9449. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9450. {
  9451. const char* msg;
  9452. char output[256];
  9453. // Your request has been rejected by autoreject option.
  9454. msg = msg_txt(sd,392);
  9455. clif_disp_onlyself(sd, msg, strlen(msg));
  9456. //Notice that a request was rejected.
  9457. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9458. clif_disp_onlyself(tsd, output, strlen(output));
  9459. }
  9460. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9461. /// 00e4 <account id>.L
  9462. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9463. {
  9464. struct map_session_data *t_sd;
  9465. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9466. if(!sd->chatID && pc_cant_act(sd))
  9467. return; //You can trade while in a chatroom.
  9468. // @noask [LuzZza]
  9469. if(t_sd && t_sd->state.noask) {
  9470. clif_noask_sub(sd, t_sd, 0);
  9471. return;
  9472. }
  9473. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9474. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9475. return;
  9476. }
  9477. trade_traderequest(sd,t_sd);
  9478. }
  9479. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9480. /// 00e6 <result>.B
  9481. /// result:
  9482. /// 3 = accepted
  9483. /// 4 = rejected
  9484. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9485. {
  9486. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9487. }
  9488. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9489. /// 00e8 <index>.W <amount>.L
  9490. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9491. {
  9492. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9493. short index = RFIFOW(fd,info->pos[0]);
  9494. int amount = RFIFOL(fd,info->pos[1]);
  9495. if( index == 0 )
  9496. trade_tradeaddzeny(sd, amount);
  9497. else
  9498. trade_tradeadditem(sd, index, (short)amount);
  9499. }
  9500. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9501. /// 00eb
  9502. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9503. {
  9504. trade_tradeok(sd);
  9505. }
  9506. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9507. /// 00ed
  9508. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9509. {
  9510. trade_tradecancel(sd);
  9511. }
  9512. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9513. /// 00ef
  9514. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9515. {
  9516. trade_tradecommit(sd);
  9517. }
  9518. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9519. /// 0118
  9520. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9521. {
  9522. pc_stop_attack(sd);
  9523. }
  9524. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9525. /// 0126 <index>.W <amount>.L
  9526. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9527. {
  9528. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9529. if (pc_istrading(sd))
  9530. return;
  9531. if (!pc_iscarton(sd))
  9532. return;
  9533. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9534. }
  9535. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9536. /// 0127 <index>.W <amount>.L
  9537. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9538. {
  9539. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9540. if (!pc_iscarton(sd))
  9541. return;
  9542. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9543. }
  9544. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9545. /// 012a
  9546. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9547. {
  9548. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9549. #ifdef NEW_CARTS
  9550. && sd->sc.data[SC_PUSH_CART] )
  9551. pc_setcart(sd,0);
  9552. #else
  9553. )
  9554. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9555. #endif
  9556. else // priority to remove this option before we can clear cart
  9557. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9558. }
  9559. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9560. /// 01af <num>.W
  9561. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9562. {// TODO: State tracking?
  9563. int type;
  9564. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9565. return;
  9566. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9567. #ifdef NEW_CARTS
  9568. if( (type == 9 && sd->status.base_level > 131) ||
  9569. (type == 8 && sd->status.base_level > 121) ||
  9570. (type == 7 && sd->status.base_level > 111) ||
  9571. (type == 6 && sd->status.base_level > 101) ||
  9572. (type == 5 && sd->status.base_level > 90) ||
  9573. (type == 4 && sd->status.base_level > 80) ||
  9574. (type == 3 && sd->status.base_level > 65) ||
  9575. (type == 2 && sd->status.base_level > 40) ||
  9576. (type == 1))
  9577. #else
  9578. if( (type == 5 && sd->status.base_level > 90) ||
  9579. (type == 4 && sd->status.base_level > 80) ||
  9580. (type == 3 && sd->status.base_level > 65) ||
  9581. (type == 2 && sd->status.base_level > 40) ||
  9582. (type == 1))
  9583. #endif
  9584. pc_setcart(sd,type);
  9585. }
  9586. /// Request to increase status (CZ_STATUS_CHANGE).
  9587. /// 00bb <status id>.W <amount>.B
  9588. /// status id:
  9589. /// SP_STR ~ SP_LUK
  9590. /// amount:
  9591. /// Old clients always send 1 for this, even when using /str+ and the like.
  9592. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9593. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9594. {
  9595. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9596. if( increase_amount < 0 ) {
  9597. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9598. fd, increase_amount);
  9599. }
  9600. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9601. }
  9602. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9603. /// 0112 <skill id>.W
  9604. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9605. {
  9606. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9607. }
  9608. 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)
  9609. {
  9610. int lv;
  9611. if( !hd )
  9612. return;
  9613. if( skill_isNotOk_hom(skill_id, hd) )
  9614. return;
  9615. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9616. target_id = hd->bl.id;
  9617. if( hd->ud.skilltimer != INVALID_TIMER )
  9618. {
  9619. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9620. }
  9621. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9622. return;
  9623. lv = hom_checkskill(hd, skill_id);
  9624. if( skill_lv > lv )
  9625. skill_lv = lv;
  9626. if( skill_lv )
  9627. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9628. }
  9629. 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)
  9630. {
  9631. int lv;
  9632. if( !hd )
  9633. return;
  9634. if( skill_isNotOk_hom(skill_id, hd) )
  9635. return;
  9636. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9637. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9638. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9639. return;
  9640. if( hd->sc.data[SC_BASILICA] )
  9641. return;
  9642. lv = hom_checkskill(hd, skill_id);
  9643. if( skill_lv > lv )
  9644. skill_lv = lv;
  9645. if( skill_lv )
  9646. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9647. }
  9648. 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)
  9649. {
  9650. int lv;
  9651. if( !md )
  9652. return;
  9653. if( skill_isNotOk_mercenary(skill_id, md) )
  9654. return;
  9655. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9656. target_id = md->bl.id;
  9657. if( md->ud.skilltimer != INVALID_TIMER )
  9658. {
  9659. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9660. }
  9661. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9662. return;
  9663. lv = mercenary_checkskill(md, skill_id);
  9664. if( skill_lv > lv )
  9665. skill_lv = lv;
  9666. if( skill_lv )
  9667. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9668. }
  9669. 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)
  9670. {
  9671. int lv;
  9672. if( !md )
  9673. return;
  9674. if( skill_isNotOk_mercenary(skill_id, md) )
  9675. return;
  9676. if( md->ud.skilltimer != INVALID_TIMER )
  9677. return;
  9678. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9679. {
  9680. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9681. return;
  9682. }
  9683. if( md->sc.data[SC_BASILICA] )
  9684. return;
  9685. lv = mercenary_checkskill(md, skill_id);
  9686. if( skill_lv > lv )
  9687. skill_lv = lv;
  9688. if( skill_lv )
  9689. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9690. }
  9691. /// Request to use a targeted skill.
  9692. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9693. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9694. /// There are various variants of this packet, some of them have padding between fields.
  9695. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9696. {
  9697. uint16 skill_id, skill_lv;
  9698. int tmp, target_id;
  9699. unsigned int tick = gettick();
  9700. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9701. skill_lv = RFIFOW(fd,info->pos[0]);
  9702. skill_id = RFIFOW(fd,info->pos[1]);
  9703. target_id = RFIFOL(fd,info->pos[2]);
  9704. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9705. tmp = skill_get_inf(skill_id);
  9706. if (tmp&INF_GROUND_SKILL || !tmp)
  9707. return; //Using a ground/passive skill on a target? WRONG.
  9708. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9709. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9710. return;
  9711. }
  9712. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9713. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9714. return;
  9715. }
  9716. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9717. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  9718. sd->idletime = last_tick;
  9719. if( sd->npc_id ){
  9720. #ifdef RENEWAL
  9721. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9722. return;
  9723. #else
  9724. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9725. return;
  9726. #endif
  9727. }
  9728. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9729. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9730. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9731. return;
  9732. if( pc_issit(sd) )
  9733. return;
  9734. if( skill_isNotOk(skill_id, sd) )
  9735. return;
  9736. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9737. target_id = sd->bl.id; // never trust the client
  9738. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9739. target_id = sd->bl.id;
  9740. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9741. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9742. return;
  9743. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9744. if( sd->skillitem != skill_id ) {
  9745. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9746. return;
  9747. }
  9748. }
  9749. if( sd->sc.option&OPTION_COSTUME )
  9750. return;
  9751. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9752. return; // On basilica only caster can use Basilica again to stop it.
  9753. if( sd->menuskill_id ) {
  9754. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9755. clif_menuskill_clear(sd); //Cancel pet capture.
  9756. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9757. return; //Can't use skills while a menu is open.
  9758. }
  9759. if( sd->skillitem == skill_id ) {
  9760. if( skill_lv != sd->skillitemlv )
  9761. skill_lv = sd->skillitemlv;
  9762. if( !(tmp&INF_SELF_SKILL) )
  9763. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9764. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9765. return;
  9766. }
  9767. sd->skillitem = sd->skillitemlv = 0;
  9768. if( skill_id >= GD_SKILLBASE ) {
  9769. if( sd->state.gmaster_flag )
  9770. skill_lv = guild_checkskill(sd->guild, skill_id);
  9771. else
  9772. skill_lv = 0;
  9773. } else {
  9774. tmp = pc_checkskill(sd, skill_id);
  9775. if( skill_lv > tmp )
  9776. skill_lv = tmp;
  9777. }
  9778. pc_delinvincibletimer(sd);
  9779. if( skill_lv )
  9780. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9781. }
  9782. /*==========================================
  9783. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9784. *------------------------------------------*/
  9785. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9786. {
  9787. unsigned int tick = gettick();
  9788. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9789. return; //Using a target skill on the ground? WRONG.
  9790. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9791. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9792. return;
  9793. }
  9794. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9795. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9796. return;
  9797. }
  9798. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9799. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  9800. sd->idletime = last_tick;
  9801. if( skill_isNotOk(skill_id, sd) )
  9802. return;
  9803. if( skillmoreinfo != -1 ) {
  9804. if( pc_issit(sd) ) {
  9805. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9806. return;
  9807. }
  9808. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9809. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9810. }
  9811. if( sd->ud.skilltimer != INVALID_TIMER )
  9812. return;
  9813. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9814. if( sd->skillitem != skill_id ) {
  9815. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9816. return;
  9817. }
  9818. }
  9819. if( sd->sc.option&OPTION_COSTUME )
  9820. return;
  9821. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9822. return; // On basilica only caster can use Basilica again to stop it.
  9823. if( sd->menuskill_id ) {
  9824. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9825. clif_menuskill_clear(sd); //Cancel pet capture.
  9826. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9827. return; //Can't use skills while a menu is open.
  9828. }
  9829. pc_delinvincibletimer(sd);
  9830. if( sd->skillitem == skill_id ) {
  9831. if( skill_lv != sd->skillitemlv )
  9832. skill_lv = sd->skillitemlv;
  9833. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9834. } else {
  9835. int lv;
  9836. sd->skillitem = sd->skillitemlv = 0;
  9837. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9838. if( skill_lv > lv )
  9839. skill_lv = lv;
  9840. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9841. }
  9842. }
  9843. }
  9844. /// Request to use a ground skill.
  9845. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9846. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9847. /// There are various variants of this packet, some of them have padding between fields.
  9848. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9849. {
  9850. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9851. if (pc_cant_act(sd))
  9852. return;
  9853. if (pc_issit(sd))
  9854. return;
  9855. clif_parse_UseSkillToPosSub(fd, sd,
  9856. RFIFOW(fd,info->pos[0]), //skill lv
  9857. RFIFOW(fd,info->pos[1]), //skill num
  9858. RFIFOW(fd,info->pos[2]), //pos x
  9859. RFIFOW(fd,info->pos[3]), //pos y
  9860. -1 //Skill more info.
  9861. );
  9862. }
  9863. /// Request to use a ground skill with text.
  9864. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9865. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9866. /// There are various variants of this packet, some of them have padding between fields.
  9867. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9868. {
  9869. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9870. if (pc_cant_act(sd))
  9871. return;
  9872. if (pc_issit(sd))
  9873. return;
  9874. clif_parse_UseSkillToPosSub(fd, sd,
  9875. RFIFOW(fd,info->pos[0]), //Skill lv
  9876. RFIFOW(fd,info->pos[1]), //Skill num
  9877. RFIFOW(fd,info->pos[2]), //pos x
  9878. RFIFOW(fd,info->pos[3]), //pos y
  9879. info->pos[4] //skill more info
  9880. );
  9881. }
  9882. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9883. /// 011b <skill id>.W <map name>.16B
  9884. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9885. {
  9886. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9887. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9888. char map_name[MAP_NAME_LENGTH];
  9889. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9890. if(skill_id != sd->menuskill_id)
  9891. return;
  9892. //It is possible to use teleport with the storage window open bugreport:8027
  9893. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  9894. clif_menuskill_clear(sd);
  9895. return;
  9896. }
  9897. pc_delinvincibletimer(sd);
  9898. skill_castend_map(sd,skill_id,map_name);
  9899. }
  9900. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9901. /// 011d
  9902. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9903. {
  9904. if (!pc_isdead(sd))
  9905. pc_memo(sd,-1);
  9906. }
  9907. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9908. /// 018e <name id>.W { <material id>.W }*3
  9909. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9910. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9911. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  9912. int slot1 = RFIFOW(fd,info->pos[1]);
  9913. int slot2 = RFIFOW(fd,info->pos[2]);
  9914. int slot3 = RFIFOW(fd,info->pos[3]);
  9915. switch( sd->menuskill_id ) {
  9916. case -1:
  9917. case AM_PHARMACY:
  9918. case RK_RUNEMASTERY:
  9919. case GC_RESEARCHNEWPOISON:
  9920. break;
  9921. default:
  9922. return;
  9923. }
  9924. if (pc_istrading(sd)) {
  9925. //Make it fail to avoid shop exploits where you sell something different than you see.
  9926. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9927. clif_menuskill_clear(sd);
  9928. return;
  9929. }
  9930. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9931. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9932. clif_menuskill_clear(sd);
  9933. }
  9934. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9935. /// 025b <mk type>.W <name id>.W
  9936. /// mk type:
  9937. /// 1 = cooking
  9938. /// 2 = arrow
  9939. /// 3 = elemental
  9940. /// 4 = GN_MIX_COOKING
  9941. /// 5 = GN_MAKEBOMB
  9942. /// 6 = GN_S_PHARMACY
  9943. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9944. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9945. int type = RFIFOW(fd,info->pos[0]);
  9946. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  9947. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  9948. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9949. return;
  9950. if (pc_istrading(sd)) {
  9951. //Make it fail to avoid shop exploits where you sell something different than you see.
  9952. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9953. clif_menuskill_clear(sd);
  9954. return;
  9955. }
  9956. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9957. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9958. clif_menuskill_clear(sd);
  9959. }
  9960. /// Answer to repair weapon item selection dialog
  9961. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9962. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9963. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9964. {
  9965. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9966. return;
  9967. if (pc_istrading(sd)) {
  9968. //Make it fail to avoid shop exploits where you sell something different than you see.
  9969. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9970. clif_menuskill_clear(sd);
  9971. return;
  9972. }
  9973. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9974. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9975. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9976. //for(i = 0; i<MAX_SLOTS; i++)
  9977. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9978. clif_menuskill_clear(sd);
  9979. }
  9980. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9981. /// 0222 <index>.L
  9982. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9983. {
  9984. int idx;
  9985. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9986. return;
  9987. if (pc_istrading(sd)) {
  9988. //Make it fail to avoid shop exploits where you sell something different than you see.
  9989. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9990. clif_menuskill_clear(sd);
  9991. return;
  9992. }
  9993. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9994. skill_weaponrefine(sd, idx-2);
  9995. clif_menuskill_clear(sd);
  9996. }
  9997. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9998. /// 00b8 <npc id>.L <choice>.B
  9999. /// choice:
  10000. /// 1~254 = menu item
  10001. /// 255 = cancel
  10002. /// NOTE: If there were more than 254 items in the list, choice
  10003. /// overflows to choice%256.
  10004. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10005. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10006. int npc_id = RFIFOL(fd,info->pos[0]);
  10007. uint8 select = RFIFOB(fd,info->pos[1]);
  10008. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10009. #ifdef SECURE_NPCTIMEOUT
  10010. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10011. #endif
  10012. TBL_NPC* nd = map_id2nd(npc_id);
  10013. 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);
  10014. clif_GM_kick(NULL,sd);
  10015. #ifdef SECURE_NPCTIMEOUT
  10016. }
  10017. #endif
  10018. return;
  10019. }
  10020. sd->npc_menu = select;
  10021. npc_scriptcont(sd,npc_id, false);
  10022. }
  10023. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10024. /// 00b9 <npc id>.L
  10025. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10026. {
  10027. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10028. }
  10029. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10030. /// 0143 <npc id>.L <value>.L
  10031. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10032. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10033. int npcid = RFIFOL(fd,info->pos[0]);
  10034. int amount = (int)RFIFOL(fd,info->pos[1]);
  10035. sd->npc_amount = amount;
  10036. npc_scriptcont(sd, npcid, false);
  10037. }
  10038. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10039. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10040. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10041. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10042. int message_len = RFIFOW(fd,info->pos[0])-8;
  10043. int npcid = RFIFOL(fd,info->pos[1]);
  10044. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10045. if( message_len <= 0 )
  10046. return; // invalid input
  10047. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10048. npc_scriptcont(sd, npcid, false);
  10049. }
  10050. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10051. /// 0146 <npc id>.L
  10052. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10053. {
  10054. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10055. return;
  10056. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10057. }
  10058. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10059. /// 0178 <index>.W
  10060. /// index:
  10061. /// -1 = cancel
  10062. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10063. {
  10064. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10065. if (sd->menuskill_id != MC_IDENTIFY)
  10066. return;
  10067. if( idx == -1 ) {// cancel pressed
  10068. clif_menuskill_clear(sd);
  10069. return;
  10070. }
  10071. skill_identify(sd,idx-2);
  10072. clif_menuskill_clear(sd);
  10073. }
  10074. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10075. /// 01ae <name id>.W
  10076. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10077. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10078. if (pc_istrading(sd)) {
  10079. //Make it fail to avoid shop exploits where you sell something different than you see.
  10080. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10081. clif_menuskill_clear(sd);
  10082. return;
  10083. }
  10084. switch (sd->menuskill_id) {
  10085. case AC_MAKINGARROW:
  10086. skill_arrow_create(sd,nameid);
  10087. break;
  10088. case SA_CREATECON:
  10089. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  10090. break;
  10091. case WL_READING_SB:
  10092. skill_spellbook(sd,nameid);
  10093. break;
  10094. case GC_POISONINGWEAPON:
  10095. skill_poisoningweapon(sd,nameid);
  10096. break;
  10097. case NC_MAGICDECOY:
  10098. skill_magicdecoy(sd,nameid);
  10099. break;
  10100. }
  10101. clif_menuskill_clear(sd);
  10102. }
  10103. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10104. /// 01ce <skill id>.L
  10105. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10106. {
  10107. if (sd->menuskill_id != SA_AUTOSPELL)
  10108. return;
  10109. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10110. clif_menuskill_clear(sd);
  10111. }
  10112. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10113. /// 017a <card index>.W
  10114. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10115. {
  10116. if (sd->state.trading != 0)
  10117. return;
  10118. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10119. }
  10120. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10121. /// 017c <card index>.W <equip index>.W
  10122. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10123. {
  10124. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10125. if (sd->state.trading != 0)
  10126. return;
  10127. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10128. }
  10129. /// Request of character's name by char ID.
  10130. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10131. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10132. /// There are various variants of this packet, some of them have padding between fields.
  10133. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10134. {
  10135. int charid;
  10136. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10137. map_reqnickdb(sd, charid);
  10138. }
  10139. /// /resetskill /resetstate (CZ_RESET).
  10140. /// Request to reset stats or skills.
  10141. /// 0197 <type>.W
  10142. /// type:
  10143. /// 0 = state
  10144. /// 1 = skill
  10145. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10146. char cmd[15];
  10147. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10148. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10149. else
  10150. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10151. is_atcommand(fd, sd, cmd, 1);
  10152. }
  10153. /// /lb /nlb (CZ_LOCALBROADCAST).
  10154. /// Request to broadcast a message on current map.
  10155. /// 019c <packet len>.W <text>.?B
  10156. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10157. {
  10158. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10159. char command[CHAT_SIZE_MAX+16];
  10160. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10161. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10162. // as the length varies depending on the command used, just block unreasonably long strings
  10163. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10164. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10165. is_atcommand(fd, sd, command, 1);
  10166. }
  10167. /// Request to move an item from inventory to storage.
  10168. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10169. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10170. /// There are various variants of this packet, some of them have padding between fields.
  10171. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10172. {
  10173. int item_index, item_amount;
  10174. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10175. if (pc_istrading(sd))
  10176. return;
  10177. item_index = RFIFOW(fd,info->pos[0])-2;
  10178. item_amount = RFIFOL(fd,info->pos[1]);
  10179. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10180. return;
  10181. if (sd->state.storage_flag == 1)
  10182. storage_storageadd(sd, item_index, item_amount);
  10183. else
  10184. if (sd->state.storage_flag == 2)
  10185. storage_guild_storageadd(sd, item_index, item_amount);
  10186. }
  10187. /// Request to move an item from storage to inventory.
  10188. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10189. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10190. /// There are various variants of this packet, some of them have padding between fields.
  10191. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10192. {
  10193. int item_index, item_amount;
  10194. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10195. item_index = RFIFOW(fd,info->pos[0])-1;
  10196. item_amount = RFIFOL(fd,info->pos[1]);
  10197. if (sd->state.storage_flag == 1)
  10198. storage_storageget(sd, item_index, item_amount);
  10199. else if(sd->state.storage_flag == 2)
  10200. storage_guild_storageget(sd, item_index, item_amount);
  10201. }
  10202. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10203. /// 0129 <index>.W <amount>.L
  10204. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10205. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10206. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10207. int amount = RFIFOL(fd,info->pos[1]);
  10208. if( sd->state.vending )
  10209. return;
  10210. if (!pc_iscarton(sd))
  10211. return;
  10212. if (sd->state.storage_flag == 1)
  10213. storage_storageaddfromcart(sd, idx, amount);
  10214. else if (sd->state.storage_flag == 2)
  10215. storage_guild_storageaddfromcart(sd, idx, amount);
  10216. }
  10217. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10218. /// 0128 <index>.W <amount>.L
  10219. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10220. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10221. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10222. int amount = RFIFOL(fd,info->pos[1]);
  10223. if( sd->state.vending )
  10224. return;
  10225. if (!pc_iscarton(sd))
  10226. return;
  10227. if (sd->state.storage_flag == 1)
  10228. storage_storagegettocart(sd, idx, amount);
  10229. else
  10230. if (sd->state.storage_flag == 2)
  10231. storage_guild_storagegettocart(sd, idx, amount);
  10232. }
  10233. /// Request to close storage (CZ_CLOSE_STORE).
  10234. /// 00f7
  10235. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10236. {
  10237. if( sd->state.storage_flag == 1 )
  10238. storage_storageclose(sd);
  10239. else
  10240. if( sd->state.storage_flag == 2 )
  10241. storage_guild_storageclose(sd);
  10242. }
  10243. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10244. /// 023a <info>.W
  10245. /// info:
  10246. /// 0 = password has not been set yet
  10247. /// 1 = storage is password-protected
  10248. /// 8 = too many wrong passwords
  10249. /// ? = ignored
  10250. /// NOTE: This packet is only available on certain non-kRO clients.
  10251. void clif_storagepassword(struct map_session_data* sd, short info)
  10252. {
  10253. int fd = sd->fd;
  10254. WFIFOHEAD(fd,packet_len(0x23a));
  10255. WFIFOW(fd,0) = 0x23a;
  10256. WFIFOW(fd,2) = info;
  10257. WFIFOSET(fd,packet_len(0x23a));
  10258. }
  10259. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10260. /// 023b <type>.W <password>.16B <new password>.16B
  10261. /// type:
  10262. /// 2 = change password
  10263. /// 3 = check password
  10264. /// NOTE: This packet is only available on certain non-kRO clients.
  10265. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10266. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10267. // int type = RFIFOW(fd,info->pos[0]);
  10268. // char* password = RFIFOP(fd,info->pos[1]);
  10269. // char* new_password = RFIFOP(fd,info->pos[2]);
  10270. // storage_changepass(sd,password,new_password);
  10271. }
  10272. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10273. /// 023c <result>.W <error count>.W
  10274. /// result:
  10275. /// 4 = password change success
  10276. /// 5 = password change failure
  10277. /// 6 = password check success
  10278. /// 7 = password check failure
  10279. /// 8 = too many wrong passwords
  10280. /// ? = ignored
  10281. /// NOTE: This packet is only available on certain non-kRO clients.
  10282. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10283. {
  10284. int fd = sd->fd;
  10285. WFIFOHEAD(fd,packet_len(0x23c));
  10286. WFIFOW(fd,0) = 0x23c;
  10287. WFIFOW(fd,2) = result;
  10288. WFIFOW(fd,4) = error_count;
  10289. WFIFOSET(fd,packet_len(0x23c));
  10290. }
  10291. /// Party creation request
  10292. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10293. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10294. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10295. name[NAME_LENGTH-1] = '\0';
  10296. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10297. clif_displaymessage(fd, msg_txt(sd,227));
  10298. return;
  10299. }
  10300. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10301. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10302. return;
  10303. }
  10304. party_create(sd,name,0,0);
  10305. }
  10306. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10307. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10308. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10309. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10310. int item1 = RFIFOB(fd,info->pos[1]);
  10311. int item2 = RFIFOB(fd,info->pos[2]);
  10312. name[NAME_LENGTH-1] = '\0';
  10313. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10314. clif_displaymessage(fd, msg_txt(sd,227));
  10315. return;
  10316. }
  10317. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10318. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10319. return;
  10320. }
  10321. party_create(sd,name,item1,item2);
  10322. }
  10323. /// Party invitation request
  10324. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10325. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10326. {
  10327. struct map_session_data *t_sd;
  10328. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10329. clif_displaymessage(fd, msg_txt(sd,227));
  10330. return;
  10331. }
  10332. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10333. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10334. clif_noask_sub(sd, t_sd, 1);
  10335. return;
  10336. }
  10337. party_invite(sd, t_sd);
  10338. }
  10339. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10340. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10341. struct map_session_data *t_sd;
  10342. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10343. name[NAME_LENGTH-1] = '\0';
  10344. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10345. clif_displaymessage(fd, msg_txt(sd,227));
  10346. return;
  10347. }
  10348. t_sd = map_nick2sd(name);
  10349. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10350. clif_noask_sub(sd, t_sd, 1);
  10351. return;
  10352. }
  10353. party_invite(sd, t_sd);
  10354. }
  10355. /// Party invitation reply
  10356. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10357. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10358. /// flag:
  10359. /// 0 = reject
  10360. /// 1 = accept
  10361. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10362. {
  10363. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10364. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10365. RFIFOL(fd,info->pos[1]));
  10366. }
  10367. //(CZ_PARTY_JOIN_REQ_ACK)
  10368. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10369. {
  10370. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10371. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10372. RFIFOB(fd,info->pos[1]));
  10373. }
  10374. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10375. /// 0100
  10376. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10377. {
  10378. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10379. clif_displaymessage(fd, msg_txt(sd,227));
  10380. return;
  10381. }
  10382. party_leave(sd);
  10383. }
  10384. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10385. /// 0103 <account id>.L <char name>.24B
  10386. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10387. {
  10388. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10389. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10390. clif_displaymessage(fd, msg_txt(sd,227));
  10391. return;
  10392. }
  10393. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10394. (char*)RFIFOP(fd,info->pos[1]));
  10395. }
  10396. /// Request to change party options.
  10397. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10398. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10399. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10400. {
  10401. struct party_data *p;
  10402. int i,expflag;
  10403. int cmd = RFIFOW(fd,0);
  10404. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10405. if( !sd->status.party_id )
  10406. return;
  10407. p = party_search(sd->status.party_id);
  10408. if( p == NULL )
  10409. return;
  10410. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10411. if( i == MAX_PARTY )
  10412. return; //Shouldn't happen
  10413. if( !p->party.member[i].leader )
  10414. return;
  10415. expflag = RFIFOL(fd,info->pos[0]);
  10416. if(cmd == 0x0102){ //Client can't change the item-field
  10417. party_changeoption(sd, expflag, p->party.item);
  10418. }
  10419. else {
  10420. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10421. party_changeoption(sd, expflag, itemflag);
  10422. }
  10423. }
  10424. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10425. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10426. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10427. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10428. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10429. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10430. char *name, *message;
  10431. int namelen, messagelen;
  10432. // validate packet and retrieve name and message
  10433. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10434. return;
  10435. if( is_atcommand(fd, sd, message, 1) )
  10436. return;
  10437. if (sd->sc.cant.chat)
  10438. return; //no "chatting" while muted.
  10439. if( battle_config.min_chat_delay )
  10440. { //[Skotlex]
  10441. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10442. return;
  10443. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10444. }
  10445. if (battle_config.idletime_option&IDLE_CHAT)
  10446. sd->idletime = last_tick;
  10447. party_send_message(sd, text, textlen);
  10448. }
  10449. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10450. /// 07da <account id>.L
  10451. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10452. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10453. }
  10454. /// Party Booking in KRO [Spiria]
  10455. ///
  10456. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10457. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10458. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10459. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10460. short level = RFIFOW(fd,info->pos[0]);
  10461. short mapid = RFIFOW(fd,info->pos[1]);
  10462. int idxpbj = info->pos[2];
  10463. short job[PARTY_BOOKING_JOBS];
  10464. int i;
  10465. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10466. job[i] = RFIFOB(fd,idxpbj+i*2);
  10467. party_booking_register(sd, level, mapid, job);
  10468. }
  10469. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10470. /// 0803 <result>.W
  10471. /// result:
  10472. /// 0 = success
  10473. /// 1 = failure
  10474. /// 2 = already registered
  10475. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10476. {
  10477. int fd = sd->fd;
  10478. WFIFOHEAD(fd,packet_len(0x803));
  10479. WFIFOW(fd,0) = 0x803;
  10480. WFIFOW(fd,2) = flag;
  10481. WFIFOSET(fd,packet_len(0x803));
  10482. }
  10483. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10484. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10485. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10486. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10487. short level = RFIFOW(fd,info->pos[0]);
  10488. short mapid = RFIFOW(fd,info->pos[1]);
  10489. short job = RFIFOW(fd,info->pos[2]);
  10490. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10491. short resultcount = RFIFOW(fd,info->pos[4]);
  10492. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10493. }
  10494. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10495. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10496. /// more results:
  10497. /// 0 = no
  10498. /// 1 = yes
  10499. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10500. {
  10501. int i, j;
  10502. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10503. struct party_booking_ad_info *pb_ad;
  10504. WFIFOHEAD(fd,size*count + 5);
  10505. WFIFOW(fd,0) = 0x805;
  10506. WFIFOW(fd,2) = size*count + 5;
  10507. WFIFOB(fd,4) = more_result;
  10508. for(i=0; i<count; i++)
  10509. {
  10510. pb_ad = results[i];
  10511. WFIFOL(fd,i*size+5) = pb_ad->index;
  10512. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10513. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10514. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10515. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10516. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10517. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10518. }
  10519. WFIFOSET(fd,WFIFOW(fd,2));
  10520. }
  10521. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10522. /// 0806
  10523. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10524. {
  10525. if(party_booking_delete(sd))
  10526. clif_PartyBookingDeleteAck(sd, 0);
  10527. }
  10528. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10529. /// 0807 <result>.W
  10530. /// result:
  10531. /// 0 = success
  10532. /// 1 = success (auto-removed expired ad)
  10533. /// 2 = failure
  10534. /// 3 = nothing registered
  10535. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10536. {
  10537. int fd = sd->fd;
  10538. WFIFOHEAD(fd,packet_len(0x807));
  10539. WFIFOW(fd,0) = 0x807;
  10540. WFIFOW(fd,2) = flag;
  10541. WFIFOSET(fd,packet_len(0x807));
  10542. }
  10543. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10544. /// 0808 { <job>.W }*6
  10545. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10546. {
  10547. short job[PARTY_BOOKING_JOBS];
  10548. int i;
  10549. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10550. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10551. job[i] = RFIFOW(fd,idxpbu+i*2);
  10552. party_booking_update(sd, job);
  10553. }
  10554. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10555. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10556. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10557. {
  10558. int i;
  10559. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10560. if(pb_ad == NULL) return;
  10561. WBUFW(buf,0) = 0x809;
  10562. WBUFL(buf,2) = pb_ad->index;
  10563. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10564. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10565. WBUFW(buf,34) = pb_ad->p_detail.level;
  10566. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10567. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10568. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10569. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10570. }
  10571. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10572. /// 080a <index>.L { <job>.W }*6
  10573. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10574. {
  10575. int i;
  10576. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10577. if(pb_ad == NULL) return;
  10578. WBUFW(buf,0) = 0x80a;
  10579. WBUFL(buf,2) = pb_ad->index;
  10580. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10581. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10582. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10583. }
  10584. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10585. /// 080b <index>.L
  10586. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10587. {
  10588. uint8 buf[6];
  10589. WBUFW(buf,0) = 0x80b;
  10590. WBUFL(buf,2) = index;
  10591. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10592. }
  10593. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10594. /// 012e
  10595. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10596. {
  10597. vending_closevending(sd);
  10598. }
  10599. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10600. /// 0130 <account id>.L
  10601. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10602. {
  10603. if( sd->npc_id ) {// using an NPC
  10604. return;
  10605. }
  10606. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10607. }
  10608. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10609. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10610. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10611. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10612. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10613. int id = (int)RFIFOL(fd,info->pos[1]);
  10614. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10615. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10616. // whether it fails or not, the buy window is closed
  10617. sd->vended_id = 0;
  10618. }
  10619. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10620. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10621. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10622. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10623. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10624. int aid = (int)RFIFOL(fd,info->pos[1]);
  10625. int uid = (int)RFIFOL(fd,info->pos[2]);
  10626. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10627. vending_purchasereq(sd, aid, uid, data, len/4);
  10628. // whether it fails or not, the buy window is closed
  10629. sd->vended_id = 0;
  10630. }
  10631. /// Confirm or cancel the shop preparation window.
  10632. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10633. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10634. /// result:
  10635. /// 0 = canceled
  10636. /// 1 = open
  10637. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10638. int cmd = RFIFOW(fd,0);
  10639. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10640. short len = (short)RFIFOW(fd,info->pos[0]);
  10641. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10642. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10643. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10644. len -= 84;
  10645. }
  10646. else { //(CZ_REQ_OPENSTORE2)
  10647. bool flag;
  10648. len -= 85;
  10649. flag = (bool)RFIFOB(fd,info->pos[2]);
  10650. if( !flag )
  10651. sd->state.prevend = 0;
  10652. }
  10653. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10654. return;
  10655. if( map[sd->bl.m].flag.novending ) {
  10656. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10657. return;
  10658. }
  10659. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10660. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10661. return;
  10662. }
  10663. if( message[0] == '\0' ) // invalid input
  10664. return;
  10665. vending_openvending(sd, message, data, len/8);
  10666. }
  10667. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10668. /// 0165 <char id>.L <guild name>.24B
  10669. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10670. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10671. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10672. name[NAME_LENGTH-1] = '\0';
  10673. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10674. clif_displaymessage(fd, msg_txt(sd,228));
  10675. return;
  10676. }
  10677. guild_create(sd, name);
  10678. }
  10679. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10680. /// 014d
  10681. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10682. {
  10683. clif_guild_masterormember(sd);
  10684. }
  10685. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10686. /// 014f <type>.L
  10687. /// type:
  10688. /// 0 = basic info
  10689. /// 1 = member manager
  10690. /// 2 = positions
  10691. /// 3 = skills
  10692. /// 4 = expulsion list
  10693. /// 5 = unknown (GM_ALLGUILDLIST)
  10694. /// 6 = notice
  10695. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10696. {
  10697. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10698. if( !sd->status.guild_id && !sd->bg_id )
  10699. return;
  10700. switch( type )
  10701. {
  10702. case 0: // Basic Information Guild, hostile alliance information
  10703. clif_guild_basicinfo(sd);
  10704. clif_guild_allianceinfo(sd);
  10705. break;
  10706. case 1: // Members list, list job title
  10707. clif_guild_positionnamelist(sd);
  10708. clif_guild_memberlist(sd);
  10709. break;
  10710. case 2: // List job title, title information list
  10711. clif_guild_positionnamelist(sd);
  10712. clif_guild_positioninfolist(sd);
  10713. break;
  10714. case 3: // Skill list
  10715. clif_guild_skillinfo(sd);
  10716. break;
  10717. case 4: // Expulsion list
  10718. clif_guild_expulsionlist(sd);
  10719. break;
  10720. default:
  10721. ShowError("clif: guild request info: unknown type %d\n", type);
  10722. break;
  10723. }
  10724. }
  10725. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10726. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10727. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10728. {
  10729. int i;
  10730. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10731. int len = RFIFOW(fd,info->pos[0]);
  10732. int idxgpos = info->pos[1];
  10733. if(!sd->state.gmaster_flag)
  10734. return;
  10735. for(i = idxgpos; i < len; i += 40 ){
  10736. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10737. }
  10738. }
  10739. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10740. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10741. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10742. {
  10743. int i;
  10744. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10745. int len = RFIFOW(fd,info->pos[0]);
  10746. int idxgpos = info->pos[1];
  10747. if(!sd->state.gmaster_flag)
  10748. return;
  10749. for(i=idxgpos;i<len;i+=12){
  10750. guild_change_memberposition(sd->status.guild_id,
  10751. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10752. }
  10753. }
  10754. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10755. /// 0151 <guild id>.L
  10756. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10757. {
  10758. struct guild* g;
  10759. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10760. if( (g = guild_search(guild_id)) != NULL )
  10761. clif_guild_emblem(sd,g);
  10762. }
  10763. /// Validates data of a guild emblem (compressed bitmap)
  10764. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10765. {
  10766. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10767. unsigned long buf_len = sizeof(buf);
  10768. int offset = 0;
  10769. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10770. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10771. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10772. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10773. ))
  10774. return -1;
  10775. if(battle_config.emblem_transparency_limit != 100) {
  10776. int i, transcount = 1, tmp[3];
  10777. for(i = offset; i < buf_len-1; i++) {
  10778. int j = i%3;
  10779. tmp[j] = RBUFL(buf,i);
  10780. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10781. transcount++;
  10782. }
  10783. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10784. return -2;
  10785. }
  10786. return 0;
  10787. }
  10788. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10789. /// 0153 <packet len>.W <emblem data>.?B
  10790. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10791. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10792. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10793. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10794. int emb_val=0;
  10795. if( !emblem_len || !sd->state.gmaster_flag )
  10796. return;
  10797. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10798. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10799. return;
  10800. }
  10801. emb_val = clif_validate_emblem(emblem, emblem_len);
  10802. if(emb_val ==-1 ){
  10803. 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);
  10804. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10805. return;
  10806. } else if(emb_val == -2){
  10807. char output[128];
  10808. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10809. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10810. return;
  10811. }
  10812. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10813. }
  10814. /// Guild notice update request (CZ_GUILD_NOTICE).
  10815. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10816. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10817. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10818. int guild_id = RFIFOL(fd,info->pos[0]);
  10819. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10820. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10821. if(!sd->state.gmaster_flag)
  10822. return;
  10823. // compensate for some client defects when using multilanguage mode
  10824. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10825. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10826. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10827. guild_change_notice(sd, guild_id, msg1, msg2);
  10828. }
  10829. // Helper function for guild invite functions
  10830. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10831. {
  10832. if (t_sd == NULL) // not online or does not exist
  10833. return 1;
  10834. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10835. clif_displaymessage(fd, msg_txt(sd,228));
  10836. return 1;
  10837. }
  10838. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10839. clif_noask_sub(sd, t_sd, 2);
  10840. return 1;
  10841. }
  10842. guild_invite(sd, t_sd);
  10843. return 0;
  10844. }
  10845. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10846. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10847. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10848. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10849. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10850. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10851. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10852. if (clif_sub_guild_invite(fd, sd, t_sd))
  10853. return;
  10854. }
  10855. /// Guild invite request (/guildinvite)
  10856. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10857. void
  10858. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10859. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10860. if (clif_sub_guild_invite(fd, sd, t_sd))
  10861. return;
  10862. }
  10863. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10864. /// 016b <guild id>.L <answer>.L
  10865. /// answer:
  10866. /// 0 = refuse
  10867. /// 1 = accept
  10868. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10869. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10870. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10871. RFIFOL(fd,info->pos[1]));
  10872. }
  10873. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10874. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10875. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10876. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10877. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10878. clif_displaymessage(fd, msg_txt(sd,228));
  10879. return;
  10880. }
  10881. if( sd->bg_id ) {
  10882. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10883. return;
  10884. }
  10885. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10886. RFIFOL(fd,info->pos[1]),
  10887. RFIFOL(fd,info->pos[2]),
  10888. (char*)RFIFOP(fd,info->pos[3]));
  10889. }
  10890. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10891. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10892. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10893. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10894. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10895. { // Guild locked.
  10896. clif_displaymessage(fd, msg_txt(sd,228));
  10897. return;
  10898. }
  10899. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10900. RFIFOL(fd,info->pos[1]),
  10901. RFIFOL(fd,info->pos[2]),
  10902. (char*)RFIFOP(fd,info->pos[3]));
  10903. }
  10904. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10905. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10906. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10907. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10908. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10909. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10910. char *name, *message;
  10911. int namelen, messagelen;
  10912. // validate packet and retrieve name and message
  10913. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10914. return;
  10915. if( is_atcommand(fd, sd, message, 1) )
  10916. return;
  10917. if (sd->sc.cant.chat)
  10918. return; //no "chatting" while muted.
  10919. if( battle_config.min_chat_delay )
  10920. { //[Skotlex]
  10921. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10922. return;
  10923. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10924. }
  10925. if (battle_config.idletime_option&IDLE_CHAT)
  10926. sd->idletime = last_tick;
  10927. if( sd->bg_id )
  10928. bg_send_message(sd, text, textlen);
  10929. else
  10930. guild_send_message(sd, text, textlen);
  10931. }
  10932. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10933. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10934. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10935. {
  10936. struct map_session_data *t_sd;
  10937. if(!sd->state.gmaster_flag)
  10938. return;
  10939. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10940. clif_displaymessage(fd, msg_txt(sd,228));
  10941. return;
  10942. }
  10943. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10944. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10945. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10946. // @noask [LuzZza]
  10947. if(t_sd && t_sd->state.noask) {
  10948. clif_noask_sub(sd, t_sd, 3);
  10949. return;
  10950. }
  10951. guild_reqalliance(sd,t_sd);
  10952. }
  10953. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10954. /// 0172 <inviter account id>.L <answer>.L
  10955. /// answer:
  10956. /// 0 = refuse
  10957. /// 1 = accept
  10958. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10959. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10960. guild_reply_reqalliance(sd,
  10961. RFIFOL(fd,info->pos[0]),
  10962. RFIFOL(fd,info->pos[1]));
  10963. }
  10964. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10965. /// 0183 <opponent guild id>.L <relation>.L
  10966. /// relation:
  10967. /// 0 = Ally
  10968. /// 1 = Enemy
  10969. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10970. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10971. if(!sd->state.gmaster_flag)
  10972. return;
  10973. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10974. clif_displaymessage(fd, msg_txt(sd,228));
  10975. return;
  10976. }
  10977. guild_delalliance(sd,
  10978. RFIFOL(fd,info->pos[0]),
  10979. RFIFOL(fd,info->pos[1]));
  10980. }
  10981. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10982. /// 0180 <account id>.L
  10983. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10984. {
  10985. struct map_session_data *t_sd;
  10986. if(!sd->state.gmaster_flag)
  10987. return;
  10988. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10989. clif_displaymessage(fd, msg_txt(sd,228));
  10990. return;
  10991. }
  10992. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10993. // @noask [LuzZza]
  10994. if(t_sd && t_sd->state.noask) {
  10995. clif_noask_sub(sd, t_sd, 4);
  10996. return;
  10997. }
  10998. guild_opposition(sd,t_sd);
  10999. }
  11000. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11001. /// 015d <key>.40B
  11002. /// key:
  11003. /// now guild name; might have been (intended) email, since the
  11004. /// field name and size is same as the one in CH_DELETE_CHAR.
  11005. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11006. {
  11007. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11008. clif_displaymessage(fd, msg_txt(sd,228));
  11009. return;
  11010. }
  11011. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11012. }
  11013. /// Pet
  11014. ///
  11015. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11016. /// 01a1 <type>.B
  11017. /// type:
  11018. /// 0 = pet information
  11019. /// 1 = feed
  11020. /// 2 = performance
  11021. /// 3 = return to egg
  11022. /// 4 = unequip accessory
  11023. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11024. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11025. }
  11026. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11027. /// 019f <id>.L
  11028. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11029. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11030. }
  11031. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11032. /// 01a7 <index>.W
  11033. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11034. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11035. return;
  11036. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11037. clif_menuskill_clear(sd);
  11038. }
  11039. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11040. /// 01a9 <data>.L
  11041. /// data:
  11042. /// is either emotion (@see enum emotion_type) or a compound value
  11043. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11044. /// entry (given in parentheses) in data\pettalktable.xml
  11045. /// act id:
  11046. /// 0 = feeding
  11047. /// 1 = hunting
  11048. /// 2 = danger
  11049. /// 3 = dead
  11050. /// 4 = normal (stand)
  11051. /// 5 = special performance (perfor_s)
  11052. /// 6 = level up (levelup)
  11053. /// 7 = performance 1 (perfor_1)
  11054. /// 8 = performance 2 (perfor_2)
  11055. /// 9 = performance 3 (perfor_3)
  11056. /// 10 = log-in greeting (connect)
  11057. /// hungry value:
  11058. /// 0 = very hungry (hungry)
  11059. /// 1 = hungry (bit_hungry)
  11060. /// 2 = satisfied (noting)
  11061. /// 3 = stuffed (full)
  11062. /// 4 = full (so_full)
  11063. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11064. {
  11065. if(sd->pd)
  11066. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11067. }
  11068. /// Request to change pet's name (CZ_RENAME_PET).
  11069. /// 01a5 <name>.24B
  11070. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11071. {
  11072. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11073. }
  11074. /// /kill (CZ_DISCONNECT_CHARACTER).
  11075. /// Request to disconnect a character.
  11076. /// 00cc <account id>.L
  11077. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11078. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11079. {
  11080. struct block_list *target;
  11081. int tid;
  11082. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11083. target = map_id2bl(tid);
  11084. if (!target) {
  11085. clif_GM_kickack(sd, 0);
  11086. return;
  11087. }
  11088. switch (target->type) {
  11089. case BL_PC:
  11090. {
  11091. char command[NAME_LENGTH+6];
  11092. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11093. is_atcommand(fd, sd, command, 1);
  11094. }
  11095. break;
  11096. /**
  11097. * This one does not invoke any atcommand, so we need to check for permissions.
  11098. */
  11099. case BL_MOB:
  11100. {
  11101. char command[100];
  11102. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11103. clif_GM_kickack(sd, 0);
  11104. return;
  11105. }
  11106. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11107. log_atcommand(sd, command);
  11108. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11109. }
  11110. break;
  11111. case BL_NPC:
  11112. {
  11113. struct npc_data* nd = (struct npc_data *)target;
  11114. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11115. npc_unload_duplicates(nd);
  11116. npc_unload(nd,true);
  11117. npc_read_event_script();
  11118. }
  11119. }
  11120. break;
  11121. default:
  11122. clif_GM_kickack(sd, 0);
  11123. }
  11124. }
  11125. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11126. /// Request to disconnect all characters.
  11127. /// 00ce
  11128. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11129. char cmd[15];
  11130. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11131. is_atcommand(fd, sd, cmd, 1);
  11132. }
  11133. /// /remove (CZ_REMOVE_AID).
  11134. /// Request to warp to a character with given login ID.
  11135. /// 01ba <account name>.24B
  11136. /// /shift (CZ_SHIFT).
  11137. /// Request to warp to a character with given name.
  11138. /// 01bb <char name>.24B
  11139. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11140. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11141. char *player_name;
  11142. char command[NAME_LENGTH+8];
  11143. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11144. player_name[NAME_LENGTH-1] = '\0';
  11145. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11146. is_atcommand(fd, sd, command, 1);
  11147. }
  11148. /// /remove (CZ_REMOVE_AID_SSO).
  11149. /// Request to warp to a character with given account ID.
  11150. /// 0843 <account id>.L
  11151. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11152. {
  11153. int account_id;
  11154. struct map_session_data* pl_sd;
  11155. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11156. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11157. char command[NAME_LENGTH+8];
  11158. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11159. is_atcommand(fd, sd, command, 1);
  11160. }
  11161. }
  11162. /// /recall (CZ_RECALL).
  11163. /// Request to summon a player with given login ID to own position.
  11164. /// 01bc <account name>.24B
  11165. /// /summon (CZ_RECALL_GID).
  11166. /// Request to summon a player with given name to own position.
  11167. /// 01bd <char name>.24B
  11168. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11169. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11170. char *player_name;
  11171. char command [NAME_LENGTH+8];
  11172. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11173. player_name[NAME_LENGTH-1] = '\0';
  11174. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11175. is_atcommand(fd, sd, command, 1);
  11176. }
  11177. /// /recall (CZ_RECALL_SSO).
  11178. /// Request to summon a player with given account ID to own position.
  11179. /// 0842 <account id>.L
  11180. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11181. {
  11182. int account_id;
  11183. struct map_session_data* pl_sd;
  11184. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11185. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11186. char command[NAME_LENGTH+8];
  11187. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11188. is_atcommand(fd, sd, command, 1);
  11189. }
  11190. }
  11191. /// /item /monster (CZ_ITEM_CREATE).
  11192. /// Request to execute GM commands.
  11193. /// Usage:
  11194. /// /item n - summon n monster or acquire n item/s
  11195. /// /item money - grants 2147483647 zenies
  11196. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11197. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11198. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11199. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11200. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11201. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11202. /// 013f <item/mob name>.24B
  11203. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11204. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11205. {
  11206. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11207. int mob_id = 0;
  11208. struct item_data *id = NULL;
  11209. struct mob_db *mob = NULL;
  11210. StringBuf command;
  11211. char *str;
  11212. //#if PACKETVER >= 20131218
  11213. // char str[100];
  11214. //#else
  11215. // char str[24];
  11216. //#endif
  11217. str = (char*)RFIFOP(fd,info->pos[0]);
  11218. if (!str || str[0] == '\0')
  11219. return;
  11220. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11221. return;
  11222. trim(str);
  11223. // Zeny
  11224. if( strcmpi(str, "money") == 0 ) {
  11225. StringBuf_Init(&command);
  11226. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11227. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11228. StringBuf_Destroy(&command);
  11229. return;
  11230. }
  11231. // Item
  11232. if( (id = itemdb_searchname(str)) ) {
  11233. StringBuf_Init(&command);
  11234. if( !itemdb_isstackable2(id) ) //Nonstackable
  11235. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11236. else
  11237. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11238. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11239. StringBuf_Destroy(&command);
  11240. return;
  11241. }
  11242. // Monster
  11243. if ((mob_id = mobdb_searchname(str)) == 0)
  11244. mob_id = mobdb_checkid(atoi(str));
  11245. if( (mob = mob_db(mob_id)) ) {
  11246. StringBuf_Init(&command);
  11247. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11248. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11249. StringBuf_Destroy(&command);
  11250. return;
  11251. }
  11252. }
  11253. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11254. /// 019d <effect state>.L
  11255. /// effect state:
  11256. /// TODO: Any OPTION_* ?
  11257. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11258. char cmd[6];
  11259. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11260. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11261. is_atcommand(fd, sd, cmd, 1);
  11262. }
  11263. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11264. /// 0149 <account id>.L <type>.B <value>.W
  11265. /// type:
  11266. /// 0 = positive points
  11267. /// 1 = negative points
  11268. /// 2 = self mute (+10 minutes)
  11269. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11270. {
  11271. int id, type, value;
  11272. struct map_session_data *dstsd;
  11273. char command[NAME_LENGTH+15];
  11274. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11275. id = RFIFOL(fd,info->pos[0]);
  11276. type = RFIFOB(fd,info->pos[1]);
  11277. value = RFIFOW(fd,info->pos[2]);
  11278. if( type == 0 )
  11279. value = -value;
  11280. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11281. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11282. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11283. return;
  11284. dstsd = map_id2sd(id);
  11285. if( dstsd == NULL )
  11286. return;
  11287. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11288. is_atcommand(fd, sd, command, 1);
  11289. }
  11290. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11291. /// GM adjustment of a player's manner value by -60.
  11292. /// 0212 <char name>.24B
  11293. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11294. {
  11295. char command[NAME_LENGTH+15];
  11296. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11297. name[NAME_LENGTH-1] = '\0';
  11298. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11299. is_atcommand(fd, sd, command, 1);
  11300. }
  11301. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11302. /// 01e0 <account id>.L <account name>.24B
  11303. void clif_account_name(int fd, int account_id, const char* accname)
  11304. {
  11305. WFIFOHEAD(fd,packet_len(0x1e0));
  11306. WFIFOW(fd,0) = 0x1e0;
  11307. WFIFOL(fd,2) = account_id;
  11308. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11309. WFIFOSET(fd,packet_len(0x1e0));
  11310. }
  11311. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11312. /// 01df <account id>.L
  11313. //! TODO: Figure out how does this actually work
  11314. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11315. {
  11316. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11317. /*
  11318. char query[30];
  11319. safesnprintf(query,sizeof(query),"%d", account_id);
  11320. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11321. */
  11322. clif_account_name(fd, account_id, "");
  11323. }
  11324. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11325. /// GM single cell type change request.
  11326. /// 0198 <x>.W <y>.W <type>.W
  11327. /// type:
  11328. /// 0 = not walkable
  11329. /// 1 = walkable
  11330. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11331. {
  11332. int x,y,type;
  11333. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11334. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11335. return;
  11336. x = RFIFOW(fd,info->pos[0]);
  11337. y = RFIFOW(fd,info->pos[1]);
  11338. type = RFIFOW(fd,info->pos[2]);
  11339. map_setgatcell(sd->bl.m,x,y,type);
  11340. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11341. //FIXME: once players leave the map, the client 'forgets' this information.
  11342. }
  11343. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11344. /// Request to allow/deny whispers from a nick.
  11345. /// 00cf <nick>.24B <type>.B
  11346. /// type:
  11347. /// 0 = (/ex nick) deny speech from nick
  11348. /// 1 = (/in nick) allow speech from nick
  11349. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11350. {
  11351. char* nick;
  11352. uint8 type;
  11353. int i;
  11354. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11355. nick = (char*)RFIFOP(fd,info->pos[0]);
  11356. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11357. type = RFIFOB(fd,info->pos[1]);
  11358. if( type == 0 ) { // Add name to ignore list (block)
  11359. if (strcmp(wisp_server_name, nick) == 0) {
  11360. clif_wisexin(sd, type, 1); // fail
  11361. return;
  11362. }
  11363. // try to find a free spot, while checking for duplicates at the same time
  11364. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11365. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11366. clif_wisexin(sd, type, 2); // too many blocks
  11367. return;
  11368. }
  11369. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11370. clif_wisexin(sd, type, 0); // Aegis reports success.
  11371. return;
  11372. }
  11373. //Insert in position i
  11374. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11375. } else { // Remove name from ignore list (unblock)
  11376. // find entry
  11377. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11378. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11379. clif_wisexin(sd, type, 1); // fail
  11380. return;
  11381. }
  11382. // move everything one place down to overwrite removed entry
  11383. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11384. // wipe last entry
  11385. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11386. }
  11387. clif_wisexin(sd, type, 0); // success
  11388. }
  11389. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11390. /// Request to allow/deny all whispers.
  11391. /// 00d0 <type>.B
  11392. /// type:
  11393. /// 0 = (/exall) deny all speech
  11394. /// 1 = (/inall) allow all speech
  11395. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11396. {
  11397. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11398. if( type == 0 ) {// Deny all
  11399. if( sd->state.ignoreAll ) {
  11400. flag = 1; // fail
  11401. } else {
  11402. sd->state.ignoreAll = 1;
  11403. flag = 0; // success
  11404. }
  11405. } else {//Unblock everyone
  11406. if( sd->state.ignoreAll ) {
  11407. sd->state.ignoreAll = 0;
  11408. flag = 0; // success
  11409. } else {
  11410. if (sd->ignore[0].name[0] != '\0')
  11411. { //Wipe the ignore list.
  11412. memset(sd->ignore, 0, sizeof(sd->ignore));
  11413. flag = 0; // success
  11414. } else {
  11415. flag = 1; // fail
  11416. }
  11417. }
  11418. }
  11419. clif_wisall(sd, type, flag);
  11420. }
  11421. /// Whisper ignore list (ZC_WHISPER_LIST).
  11422. /// 00d4 <packet len>.W { <char name>.24B }*
  11423. void clif_PMIgnoreList(struct map_session_data* sd)
  11424. {
  11425. int i, fd = sd->fd;
  11426. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11427. WFIFOW(fd,0) = 0xd4;
  11428. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11429. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11430. }
  11431. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11432. WFIFOSET(fd,WFIFOW(fd,2));
  11433. }
  11434. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11435. /// 00d3
  11436. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11437. {
  11438. clif_PMIgnoreList(sd);
  11439. }
  11440. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11441. /// 01e7
  11442. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11443. {
  11444. if (sd->state.doridori) return;
  11445. switch (sd->class_&MAPID_UPPERMASK) {
  11446. case MAPID_SOUL_LINKER:
  11447. case MAPID_STAR_GLADIATOR:
  11448. case MAPID_TAEKWON:
  11449. if (!sd->state.rest)
  11450. break;
  11451. case MAPID_SUPER_NOVICE:
  11452. case MAPID_SUPER_BABY:
  11453. case MAPID_SUPER_NOVICE_E:
  11454. case MAPID_SUPER_BABY_E:
  11455. sd->state.doridori=1;
  11456. break;
  11457. }
  11458. }
  11459. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11460. /// 01ed
  11461. /// Note: This packet is caused by 7 lines of any text, followed by
  11462. /// the prayer and an another line of any text. The prayer is
  11463. /// defined by lines 790~793 in data\msgstringtable.txt
  11464. /// "Dear angel, can you hear my voice?"
  11465. /// "I am" (space separated player name) "Super Novice~"
  11466. /// "Help me out~ Please~ T_T"
  11467. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11468. {
  11469. if( sd->class_&JOBL_SUPER_NOVICE ) {
  11470. unsigned int next = pc_nextbaseexp(sd);
  11471. if( next == 0 ) next = pc_thisbaseexp(sd);
  11472. if( next ) {
  11473. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11474. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11475. 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]
  11476. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11477. }
  11478. }
  11479. }
  11480. }
  11481. /// Friends List
  11482. ///
  11483. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11484. /// 0206 <account id>.L <char id>.L <state>.B
  11485. /// state:
  11486. /// 0 = online
  11487. /// 1 = offline
  11488. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  11489. {
  11490. int i, fd = sd->fd;
  11491. //Seek friend.
  11492. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11493. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11494. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11495. return; //Not found
  11496. WFIFOHEAD(fd,packet_len(0x206));
  11497. WFIFOW(fd, 0) = 0x206;
  11498. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11499. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11500. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11501. WFIFOSET(fd, packet_len(0x206));
  11502. }
  11503. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11504. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11505. {
  11506. int account_id, char_id, online;
  11507. account_id = va_arg(ap, int);
  11508. char_id = va_arg(ap, int);
  11509. online = va_arg(ap, int);
  11510. clif_friendslist_toggle(sd, account_id, char_id, online);
  11511. return 0;
  11512. }
  11513. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11514. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11515. void clif_friendslist_send(struct map_session_data *sd)
  11516. {
  11517. int i = 0, n, fd = sd->fd;
  11518. // Send friends list
  11519. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11520. WFIFOW(fd, 0) = 0x201;
  11521. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11522. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11523. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11524. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11525. }
  11526. if (i) {
  11527. WFIFOW(fd,2) = 4 + 32 * i;
  11528. WFIFOSET(fd, WFIFOW(fd,2));
  11529. }
  11530. for (n = 0; n < i; n++) { //Sending the online players
  11531. if (map_charid2sd(sd->status.friends[n].char_id))
  11532. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11533. }
  11534. }
  11535. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11536. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11537. /// result:
  11538. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11539. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11540. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11541. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11542. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11543. {
  11544. int fd;
  11545. nullpo_retv(sd);
  11546. fd = sd->fd;
  11547. WFIFOHEAD(fd,packet_len(0x209));
  11548. WFIFOW(fd,0) = 0x209;
  11549. WFIFOW(fd,2) = type;
  11550. if (f_sd) {
  11551. WFIFOL(fd,4) = f_sd->status.account_id;
  11552. WFIFOL(fd,8) = f_sd->status.char_id;
  11553. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11554. }
  11555. WFIFOSET(fd, packet_len(0x209));
  11556. }
  11557. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11558. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11559. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  11560. {
  11561. int fd = sd->fd;
  11562. WFIFOHEAD(fd,packet_len(0x207));
  11563. WFIFOW(fd,0) = 0x207;
  11564. WFIFOL(fd,2) = account_id;
  11565. WFIFOL(fd,6) = char_id;
  11566. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11567. WFIFOSET(fd,packet_len(0x207));
  11568. }
  11569. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11570. /// 0202 <name>.24B
  11571. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11572. {
  11573. struct map_session_data *f_sd;
  11574. int i;
  11575. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11576. // ensure that the request player's friend list is not full
  11577. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11578. if( i == MAX_FRIENDS ) {
  11579. clif_friendslist_reqack(sd, f_sd, 2);
  11580. return;
  11581. }
  11582. // Friend doesn't exist (no player with this name)
  11583. if (f_sd == NULL) {
  11584. clif_displaymessage(fd, msg_txt(sd,3));
  11585. return;
  11586. }
  11587. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11588. return;
  11589. }
  11590. // @noask [LuzZza]
  11591. if(f_sd->state.noask) {
  11592. clif_noask_sub(sd, f_sd, 5);
  11593. return;
  11594. }
  11595. // Friend already exists
  11596. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11597. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11598. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11599. return;
  11600. }
  11601. }
  11602. f_sd->friend_req = sd->status.char_id;
  11603. sd->friend_req = f_sd->status.char_id;
  11604. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11605. }
  11606. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11607. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11608. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11609. /// reply:
  11610. /// 0 = rejected
  11611. /// 1 = accepted
  11612. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11613. {
  11614. struct map_session_data *f_sd;
  11615. int account_id;
  11616. char reply;
  11617. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11618. account_id = RFIFOL(fd,info->pos[0]);
  11619. //char_id = RFIFOL(fd,info->pos[1]);
  11620. if(sd->packet_ver < 6)
  11621. reply = RFIFOB(fd,info->pos[2]);
  11622. else
  11623. reply = RFIFOL(fd,info->pos[2]);
  11624. if( sd->bl.id == account_id ) {// adding oneself as friend
  11625. return;
  11626. }
  11627. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11628. if (f_sd == NULL)
  11629. return;
  11630. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11631. clif_friendslist_reqack(f_sd, sd, 1);
  11632. else {
  11633. int i;
  11634. // Find an empty slot
  11635. for (i = 0; i < MAX_FRIENDS; i++)
  11636. if (f_sd->status.friends[i].char_id == 0)
  11637. break;
  11638. if (i == MAX_FRIENDS) {
  11639. clif_friendslist_reqack(f_sd, sd, 2);
  11640. return;
  11641. }
  11642. f_sd->status.friends[i].account_id = sd->status.account_id;
  11643. f_sd->status.friends[i].char_id = sd->status.char_id;
  11644. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11645. clif_friendslist_reqack(f_sd, sd, 0);
  11646. if (battle_config.friend_auto_add) {
  11647. // Also add f_sd to sd's friendlist.
  11648. for (i = 0; i < MAX_FRIENDS; i++) {
  11649. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11650. return; //No need to add anything.
  11651. if (sd->status.friends[i].char_id == 0)
  11652. break;
  11653. }
  11654. if (i == MAX_FRIENDS) {
  11655. clif_friendslist_reqack(sd, f_sd, 2);
  11656. return;
  11657. }
  11658. sd->status.friends[i].account_id = f_sd->status.account_id;
  11659. sd->status.friends[i].char_id = f_sd->status.char_id;
  11660. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11661. clif_friendslist_reqack(sd, f_sd, 0);
  11662. }
  11663. }
  11664. }
  11665. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11666. /// 0203 <account id>.L <char id>.L
  11667. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11668. {
  11669. struct map_session_data *f_sd = NULL;
  11670. int account_id, char_id;
  11671. int i, j;
  11672. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11673. account_id = RFIFOL(fd,info->pos[0]);
  11674. char_id = RFIFOL(fd,info->pos[1]);
  11675. // Search friend
  11676. for (i = 0; i < MAX_FRIENDS &&
  11677. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11678. if (i == MAX_FRIENDS) {
  11679. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11680. return;
  11681. }
  11682. //remove from friend's list first
  11683. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11684. for (i = 0; i < MAX_FRIENDS &&
  11685. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11686. if (i != MAX_FRIENDS) {
  11687. // move all chars up
  11688. for(j = i + 1; j < MAX_FRIENDS; j++)
  11689. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11690. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11691. //should the guy be notified of some message? we should add it here if so
  11692. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11693. WFIFOW(f_sd->fd,0) = 0x20a;
  11694. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11695. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11696. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11697. }
  11698. } else { //friend not online -- ask char server to delete from his friendlist
  11699. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11700. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11701. return;
  11702. }
  11703. }
  11704. // We can now delete from original requester
  11705. for (i = 0; i < MAX_FRIENDS &&
  11706. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11707. // move all chars up
  11708. for(j = i + 1; j < MAX_FRIENDS; j++)
  11709. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11710. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11711. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11712. WFIFOHEAD(fd,packet_len(0x20a));
  11713. WFIFOW(fd,0) = 0x20a;
  11714. WFIFOL(fd,2) = account_id;
  11715. WFIFOL(fd,6) = char_id;
  11716. WFIFOSET(fd, packet_len(0x20a));
  11717. }
  11718. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11719. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11720. void clif_PVPInfo(struct map_session_data* sd)
  11721. {
  11722. int fd = sd->fd;
  11723. WFIFOHEAD(fd,packet_len(0x210));
  11724. WFIFOW(fd,0) = 0x210;
  11725. WFIFOL(fd,2) = sd->status.char_id;
  11726. WFIFOL(fd,6) = sd->status.account_id;
  11727. WFIFOL(fd,10) = sd->pvp_won; // times won
  11728. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11729. WFIFOL(fd,18) = sd->pvp_point;
  11730. WFIFOSET(fd, packet_len(0x210));
  11731. }
  11732. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11733. /// 020f <char id>.L <account id>.L
  11734. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11735. {
  11736. // TODO: Is there a way to use this on an another player (char/acc id)?
  11737. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11738. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11739. clif_PVPInfo(sd);
  11740. }
  11741. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11742. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11743. void clif_blacksmith(struct map_session_data* sd)
  11744. {
  11745. int i, fd = sd->fd;
  11746. const char* name;
  11747. WFIFOHEAD(fd,packet_len(0x219));
  11748. WFIFOW(fd,0) = 0x219;
  11749. //Packet size limits this list to 10 elements. [Skotlex]
  11750. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11751. if (smith_fame_list[i].id > 0) {
  11752. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11753. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11754. {
  11755. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11756. } else
  11757. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11758. } else
  11759. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11760. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11761. }
  11762. for(;i < 10; i++) { //In case the MAX is less than 10.
  11763. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11764. WFIFOL(fd, 242 + i * 4) = 0;
  11765. }
  11766. WFIFOSET(fd, packet_len(0x219));
  11767. }
  11768. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11769. /// 0217
  11770. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11771. {
  11772. clif_blacksmith(sd);
  11773. }
  11774. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11775. /// 021b <points>.L <total points>.L
  11776. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11777. {
  11778. int fd = sd->fd;
  11779. WFIFOHEAD(fd,packet_len(0x21b));
  11780. WFIFOW(fd,0) = 0x21b;
  11781. WFIFOL(fd,2) = points;
  11782. WFIFOL(fd,6) = sd->status.fame;
  11783. WFIFOSET(fd, packet_len(0x21b));
  11784. }
  11785. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11786. /// 021a { <name>.24B }*10 { <point>.L }*10
  11787. void clif_alchemist(struct map_session_data* sd)
  11788. {
  11789. int i, fd = sd->fd;
  11790. const char* name;
  11791. WFIFOHEAD(fd,packet_len(0x21a));
  11792. WFIFOW(fd,0) = 0x21a;
  11793. //Packet size limits this list to 10 elements. [Skotlex]
  11794. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11795. if (chemist_fame_list[i].id > 0) {
  11796. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11797. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11798. {
  11799. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11800. } else
  11801. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11802. } else
  11803. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11804. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11805. }
  11806. for(;i < 10; i++) { //In case the MAX is less than 10.
  11807. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11808. WFIFOL(fd, 242 + i * 4) = 0;
  11809. }
  11810. WFIFOSET(fd, packet_len(0x21a));
  11811. }
  11812. /// /alchemist (CZ_ALCHEMIST_RANK).
  11813. /// 0218
  11814. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11815. {
  11816. clif_alchemist(sd);
  11817. }
  11818. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11819. /// 021c <points>.L <total points>.L
  11820. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11821. {
  11822. int fd = sd->fd;
  11823. WFIFOHEAD(fd,packet_len(0x21c));
  11824. WFIFOW(fd,0) = 0x21c;
  11825. WFIFOL(fd,2) = points;
  11826. WFIFOL(fd,6) = sd->status.fame;
  11827. WFIFOSET(fd, packet_len(0x21c));
  11828. }
  11829. /// /taekwon list (ZC_TAEKWON_RANK).
  11830. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11831. void clif_taekwon(struct map_session_data* sd)
  11832. {
  11833. int i, fd = sd->fd;
  11834. const char* name;
  11835. WFIFOHEAD(fd,packet_len(0x226));
  11836. WFIFOW(fd,0) = 0x226;
  11837. //Packet size limits this list to 10 elements. [Skotlex]
  11838. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11839. if (taekwon_fame_list[i].id > 0) {
  11840. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11841. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11842. {
  11843. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11844. } else
  11845. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11846. } else
  11847. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11848. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11849. }
  11850. for(;i < 10; i++) { //In case the MAX is less than 10.
  11851. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11852. WFIFOL(fd, 242 + i * 4) = 0;
  11853. }
  11854. WFIFOSET(fd, packet_len(0x226));
  11855. }
  11856. /// /taekwon (CZ_TAEKWON_RANK).
  11857. /// 0225
  11858. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11859. {
  11860. clif_taekwon(sd);
  11861. }
  11862. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11863. /// 0224 <points>.L <total points>.L
  11864. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11865. {
  11866. int fd = sd->fd;
  11867. WFIFOHEAD(fd,packet_len(0x224));
  11868. WFIFOW(fd,0) = 0x224;
  11869. WFIFOL(fd,2) = points;
  11870. WFIFOL(fd,6) = sd->status.fame;
  11871. WFIFOSET(fd, packet_len(0x224));
  11872. }
  11873. /// /pk list (ZC_KILLER_RANK).
  11874. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11875. void clif_ranking_pk(struct map_session_data* sd)
  11876. {
  11877. int i, fd = sd->fd;
  11878. WFIFOHEAD(fd,packet_len(0x238));
  11879. WFIFOW(fd,0) = 0x238;
  11880. for(i=0;i<10;i++){
  11881. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11882. WFIFOL(fd,i*4+242) = 0;
  11883. }
  11884. WFIFOSET(fd, packet_len(0x238));
  11885. }
  11886. /// /pk (CZ_KILLER_RANK).
  11887. /// 0237
  11888. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11889. {
  11890. clif_ranking_pk(sd);
  11891. }
  11892. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11893. /// 0254 <which>.B
  11894. /// which: (unused atm for security purpose)
  11895. /// 0 = sun
  11896. /// 1 = moon
  11897. /// 2 = star
  11898. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11899. {
  11900. int i;
  11901. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11902. if (sd->menuskill_id != SG_FEEL)
  11903. return;
  11904. i = sd->menuskill_val-1;
  11905. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11906. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11907. sd->feel_map[i].m = sd->bl.m;
  11908. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11909. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11910. // clif_misceffect2(&sd->bl, 0x1b0);
  11911. // clif_misceffect2(&sd->bl, 0x21f);
  11912. clif_feel_info(sd, i, 0);
  11913. clif_menuskill_clear(sd);
  11914. }
  11915. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11916. /// 0253 <which>.B
  11917. /// which:
  11918. /// 0 = sun
  11919. /// 1 = moon
  11920. /// 2 = star
  11921. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11922. {
  11923. WFIFOHEAD(fd,packet_len(0x253));
  11924. WFIFOW(fd,0)=0x253;
  11925. WFIFOB(fd,2)=TOB(skill_lv-1);
  11926. WFIFOSET(fd, packet_len(0x253));
  11927. sd->menuskill_id = SG_FEEL;
  11928. sd->menuskill_val = skill_lv;
  11929. }
  11930. /// Request to change homunculus' name (CZ_RENAME_MER).
  11931. /// 0231 <name>.24B
  11932. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11933. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11934. }
  11935. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11936. /// 0234 <id>.L
  11937. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11938. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11939. struct block_list *bl = NULL;
  11940. struct unit_data *ud = NULL;
  11941. if( sd->md && sd->md->bl.id == id )
  11942. bl = &sd->md->bl;
  11943. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11944. bl = &sd->hd->bl; // Moving Homunculus
  11945. else
  11946. return;
  11947. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11948. ud = unit_bl2ud(bl);
  11949. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11950. }
  11951. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11952. /// 0232 <id>.L <position data>.3B
  11953. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11954. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11955. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11956. struct block_list *bl = NULL;
  11957. short x, y;
  11958. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11959. if( sd->md && sd->md->bl.id == id )
  11960. bl = &sd->md->bl; // Moving Mercenary
  11961. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11962. bl = &sd->hd->bl; // Moving Homunculus
  11963. else
  11964. return;
  11965. unit_walktoxy(bl, x, y, 4);
  11966. }
  11967. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11968. /// 0233 <id>.L <target id>.L <action>.B
  11969. /// action:
  11970. /// always 0
  11971. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11972. {
  11973. struct block_list *bl = NULL;
  11974. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11975. int id = RFIFOL(fd,info->pos[0]);
  11976. int target_id = RFIFOL(fd,info->pos[1]);
  11977. int action_type = RFIFOB(fd,info->pos[2]);
  11978. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11979. bl = &sd->hd->bl;
  11980. else if( sd->md && sd->md->bl.id == id )
  11981. bl = &sd->md->bl;
  11982. else return;
  11983. unit_stop_attack(bl);
  11984. unit_attack(bl, target_id, action_type != 0);
  11985. }
  11986. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11987. /// 022d <type>.W <command>.B
  11988. /// type:
  11989. /// always 0
  11990. /// command:
  11991. /// 0 = homunculus information
  11992. /// 1 = feed
  11993. /// 2 = delete
  11994. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11995. { //[orn]
  11996. int cmd = RFIFOW(fd,0);
  11997. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11998. if(!hom_is_active(sd->hd))
  11999. return;
  12000. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12001. }
  12002. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12003. /// 0292
  12004. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12005. {
  12006. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12007. int hpsp = 100;
  12008. if (item_position < 0) {
  12009. if (sd->sc.data[SC_LIGHT_OF_REGENE])
  12010. hpsp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12011. else
  12012. return;
  12013. }
  12014. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12015. return;
  12016. if (!status_revive(&sd->bl, hpsp, hpsp))
  12017. return;
  12018. if (item_position < 0)
  12019. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12020. else
  12021. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12022. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12023. }
  12024. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12025. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12026. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12027. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12028. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12029. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12030. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12031. void clif_check(int fd, struct map_session_data* pl_sd)
  12032. {
  12033. WFIFOHEAD(fd,packet_len(0x214));
  12034. WFIFOW(fd, 0) = 0x214;
  12035. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12036. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12037. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12038. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12039. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12040. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12041. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12042. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12043. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12044. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12045. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12046. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12047. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12048. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12049. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12050. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12051. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12052. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12053. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12054. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12055. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12056. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12057. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12058. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12059. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12060. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12061. WFIFOSET(fd,packet_len(0x214));
  12062. }
  12063. /// /check (CZ_REQ_STATUS_GM).
  12064. /// Request character's status values.
  12065. /// 0213 <char name>.24B
  12066. void clif_parse_Check(int fd, struct map_session_data *sd)
  12067. {
  12068. char charname[NAME_LENGTH];
  12069. struct map_session_data* pl_sd;
  12070. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12071. return;
  12072. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12073. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12074. {
  12075. return;
  12076. }
  12077. clif_check(fd, pl_sd);
  12078. }
  12079. /// MAIL SYSTEM
  12080. /// By Zephyrus
  12081. ///
  12082. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12083. /// 0255 <index>.W <result>.B
  12084. /// result:
  12085. /// 0 = success
  12086. /// 1 = failure
  12087. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12088. {
  12089. WFIFOHEAD(fd,packet_len(0x255));
  12090. WFIFOW(fd,0) = 0x255;
  12091. WFIFOW(fd,2) = index;
  12092. WFIFOB(fd,4) = flag;
  12093. WFIFOSET(fd,packet_len(0x255));
  12094. }
  12095. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12096. /// 0245 <result>.B
  12097. /// result:
  12098. /// 0 = success
  12099. /// 1 = failure
  12100. /// 2 = too many items
  12101. void clif_Mail_getattachment(int fd, uint8 flag)
  12102. {
  12103. WFIFOHEAD(fd,packet_len(0x245));
  12104. WFIFOW(fd,0) = 0x245;
  12105. WFIFOB(fd,2) = flag;
  12106. WFIFOSET(fd,packet_len(0x245));
  12107. }
  12108. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12109. /// 0249 <result>.B
  12110. /// result:
  12111. /// 0 = success
  12112. /// 1 = recipinent does not exist
  12113. void clif_Mail_send(int fd, bool fail)
  12114. {
  12115. WFIFOHEAD(fd,packet_len(0x249));
  12116. WFIFOW(fd,0) = 0x249;
  12117. WFIFOB(fd,2) = fail;
  12118. WFIFOSET(fd,packet_len(0x249));
  12119. }
  12120. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12121. /// 0257 <mail id>.L <result>.W
  12122. /// result:
  12123. /// 0 = success
  12124. /// 1 = failure
  12125. void clif_Mail_delete(int fd, int mail_id, short fail)
  12126. {
  12127. WFIFOHEAD(fd, packet_len(0x257));
  12128. WFIFOW(fd,0) = 0x257;
  12129. WFIFOL(fd,2) = mail_id;
  12130. WFIFOW(fd,6) = fail;
  12131. WFIFOSET(fd, packet_len(0x257));
  12132. }
  12133. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12134. /// 0274 <mail id>.L <result>.W
  12135. /// result:
  12136. /// 0 = success
  12137. /// 1 = failure
  12138. void clif_Mail_return(int fd, int mail_id, short fail)
  12139. {
  12140. WFIFOHEAD(fd,packet_len(0x274));
  12141. WFIFOW(fd,0) = 0x274;
  12142. WFIFOL(fd,2) = mail_id;
  12143. WFIFOW(fd,6) = fail;
  12144. WFIFOSET(fd,packet_len(0x274));
  12145. }
  12146. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12147. /// 024a <mail id>.L <title>.40B <sender>.24B
  12148. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12149. {
  12150. WFIFOHEAD(fd,packet_len(0x24a));
  12151. WFIFOW(fd,0) = 0x24a;
  12152. WFIFOL(fd,2) = mail_id;
  12153. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12154. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12155. WFIFOSET(fd,packet_len(0x24a));
  12156. }
  12157. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12158. /// 0260 <type>.L
  12159. /// type:
  12160. /// 0 = open
  12161. /// 1 = close
  12162. void clif_Mail_window(int fd, int flag)
  12163. {
  12164. WFIFOHEAD(fd,packet_len(0x260));
  12165. WFIFOW(fd,0) = 0x260;
  12166. WFIFOL(fd,2) = flag;
  12167. WFIFOSET(fd,packet_len(0x260));
  12168. }
  12169. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12170. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12171. /// read:
  12172. /// 0 = unread
  12173. /// 1 = read
  12174. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12175. {
  12176. int fd = sd->fd;
  12177. struct mail_data *md = &sd->mail.inbox;
  12178. struct mail_message *msg;
  12179. int len, i, j;
  12180. len = 8 + (73 * md->amount);
  12181. WFIFOHEAD(fd,len);
  12182. WFIFOW(fd,0) = 0x240;
  12183. WFIFOW(fd,2) = len;
  12184. WFIFOL(fd,4) = md->amount;
  12185. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12186. {
  12187. msg = &md->msg[i];
  12188. if (msg->id < 1)
  12189. continue;
  12190. WFIFOL(fd,8+73*j) = msg->id;
  12191. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12192. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12193. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12194. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12195. j++;
  12196. }
  12197. WFIFOSET(fd,len);
  12198. if( md->full ) {// TODO: is this official?
  12199. char output[100];
  12200. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12201. clif_disp_onlyself(sd, output, strlen(output));
  12202. }
  12203. }
  12204. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12205. /// 023f
  12206. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12207. {
  12208. struct mail_data* md = &sd->mail.inbox;
  12209. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12210. intif_Mail_requestinbox(sd->status.char_id, 1);
  12211. else
  12212. clif_Mail_refreshinbox(sd);
  12213. mail_removeitem(sd, 0);
  12214. mail_removezeny(sd, 0);
  12215. }
  12216. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12217. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12218. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12219. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12220. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12221. {
  12222. int i, fd = sd->fd;
  12223. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12224. if( i == MAIL_MAX_INBOX ) {
  12225. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12226. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12227. return;
  12228. } else {
  12229. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12230. struct item *item = &msg->item;
  12231. struct item_data *data;
  12232. int msg_len = strlen(msg->body), len;
  12233. if( msg_len == 0 ) {
  12234. strcpy(msg->body, "(no message)");
  12235. msg_len = strlen(msg->body);
  12236. }
  12237. len = 101 + msg_len;
  12238. WFIFOHEAD(fd,len);
  12239. WFIFOW(fd,0) = 0x242;
  12240. WFIFOW(fd,2) = len;
  12241. WFIFOL(fd,4) = msg->id;
  12242. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12243. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12244. WFIFOL(fd,72) = 0;
  12245. WFIFOL(fd,76) = msg->zeny;
  12246. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12247. WFIFOL(fd,80) = item->amount;
  12248. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12249. WFIFOW(fd,86) = data->type;
  12250. WFIFOB(fd,88) = item->identify;
  12251. WFIFOB(fd,89) = item->attribute;
  12252. WFIFOB(fd,90) = item->refine;
  12253. WFIFOW(fd,91) = item->card[0];
  12254. WFIFOW(fd,93) = item->card[1];
  12255. WFIFOW(fd,95) = item->card[2];
  12256. WFIFOW(fd,97) = item->card[3];
  12257. } else // no item, set all to zero
  12258. memset(WFIFOP(fd,80), 0x00, 19);
  12259. WFIFOB(fd,99) = (unsigned char)msg_len;
  12260. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12261. WFIFOSET(fd,len);
  12262. if (msg->status == MAIL_UNREAD) {
  12263. msg->status = MAIL_READ;
  12264. intif_Mail_read(mail_id);
  12265. clif_parse_Mail_refreshinbox(fd, sd);
  12266. }
  12267. }
  12268. }
  12269. /// Request to open a mail (CZ_MAIL_OPEN).
  12270. /// 0241 <mail id>.L
  12271. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12272. {
  12273. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12274. if( mail_id <= 0 )
  12275. return;
  12276. if( mail_invalid_operation(sd) )
  12277. return;
  12278. clif_Mail_read(sd, mail_id);
  12279. }
  12280. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12281. /// 0244 <mail id>.L
  12282. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12283. {
  12284. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12285. int i;
  12286. bool fail = false;
  12287. if( !chrif_isconnected() )
  12288. return;
  12289. if( mail_id <= 0 )
  12290. return;
  12291. if( mail_invalid_operation(sd) )
  12292. return;
  12293. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12294. if( i == MAIL_MAX_INBOX )
  12295. return;
  12296. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12297. return;
  12298. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12299. clif_Mail_getattachment(fd, 1);
  12300. return;
  12301. }
  12302. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12303. struct item_data *data;
  12304. unsigned int weight;
  12305. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12306. return;
  12307. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12308. case CHKADDITEM_NEW:
  12309. fail = ( pc_inventoryblank(sd) == 0 );
  12310. break;
  12311. case CHKADDITEM_OVERAMOUNT:
  12312. fail = true;
  12313. }
  12314. if( fail ) {
  12315. clif_Mail_getattachment(fd, 1);
  12316. return;
  12317. }
  12318. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12319. if( sd->weight + weight > sd->max_weight ) {
  12320. clif_Mail_getattachment(fd, 2);
  12321. return;
  12322. }
  12323. }
  12324. sd->mail.inbox.msg[i].zeny = 0;
  12325. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12326. clif_Mail_read(sd, mail_id);
  12327. intif_Mail_getattach(sd->status.char_id, mail_id);
  12328. }
  12329. /// Request to delete a mail (CZ_MAIL_DELETE).
  12330. /// 0243 <mail id>.L
  12331. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12332. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12333. int i;
  12334. if( !chrif_isconnected() )
  12335. return;
  12336. if( mail_id <= 0 )
  12337. return;
  12338. if( mail_invalid_operation(sd) )
  12339. return;
  12340. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12341. if (i < MAIL_MAX_INBOX) {
  12342. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12343. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12344. clif_Mail_delete(sd->fd, mail_id, 1);
  12345. return;
  12346. }
  12347. intif_Mail_delete(sd->status.char_id, mail_id);
  12348. }
  12349. }
  12350. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12351. /// 0273 <mail id>.L <receive name>.24B
  12352. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12353. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12354. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12355. int i;
  12356. if( mail_id <= 0 )
  12357. return;
  12358. if( mail_invalid_operation(sd) )
  12359. return;
  12360. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12361. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12362. intif_Mail_return(sd->status.char_id, mail_id);
  12363. else
  12364. clif_Mail_return(sd->fd, mail_id, 1);
  12365. }
  12366. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12367. /// 0247 <index>.W <amount>.L
  12368. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12369. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12370. int idx = RFIFOW(fd,info->pos[0]);
  12371. int amount = RFIFOL(fd,info->pos[1]);
  12372. unsigned char flag;
  12373. if( !chrif_isconnected() )
  12374. return;
  12375. if (idx < 0 || amount < 0)
  12376. return;
  12377. flag = mail_setitem(sd, idx, amount);
  12378. clif_Mail_setattachment(fd,idx,!flag);
  12379. }
  12380. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12381. /// 0246 <type>.W
  12382. /// type:
  12383. /// 0 = reset all
  12384. /// 1 = remove item
  12385. /// 2 = remove zeny
  12386. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12387. {
  12388. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12389. if (type == 0 || type == 1)
  12390. mail_removeitem(sd, 0);
  12391. if (type == 0 || type == 2)
  12392. mail_removezeny(sd, 0);
  12393. }
  12394. /// Request to send mail (CZ_MAIL_SEND).
  12395. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12396. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12397. {
  12398. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12399. if( !chrif_isconnected() )
  12400. return;
  12401. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12402. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12403. return;
  12404. }
  12405. 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]));
  12406. }
  12407. /// AUCTION SYSTEM
  12408. /// By Zephyrus
  12409. ///
  12410. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12411. /// 025f <type>.L
  12412. /// type:
  12413. /// 0 = open
  12414. /// 1 = close
  12415. void clif_Auction_openwindow(struct map_session_data *sd)
  12416. {
  12417. int fd = sd->fd;
  12418. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12419. return;
  12420. if( !battle_config.feature_auction )
  12421. return;
  12422. WFIFOHEAD(fd,packet_len(0x25f));
  12423. WFIFOW(fd,0) = 0x25f;
  12424. WFIFOL(fd,2) = 0;
  12425. WFIFOSET(fd,packet_len(0x25f));
  12426. }
  12427. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12428. /// 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 }*
  12429. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12430. {
  12431. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12432. struct auction_data auction;
  12433. struct item_data *item;
  12434. WFIFOHEAD(fd,12 + (count * 83));
  12435. WFIFOW(fd,0) = 0x252;
  12436. WFIFOW(fd,2) = 12 + (count * 83);
  12437. WFIFOL(fd,4) = pages;
  12438. WFIFOL(fd,8) = count;
  12439. for( i = 0; i < count; i++ ) {
  12440. int k = 12 + (i * 83);
  12441. memcpy(&auction, RBUFP(buf,i * len), len);
  12442. WFIFOL(fd,k) = auction.auction_id;
  12443. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12444. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12445. WFIFOW(fd,28+k) = item->view_id;
  12446. else
  12447. WFIFOW(fd,28+k) = auction.item.nameid;
  12448. WFIFOL(fd,30+k) = auction.type;
  12449. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12450. WFIFOB(fd,36+k) = auction.item.identify;
  12451. WFIFOB(fd,37+k) = auction.item.attribute;
  12452. WFIFOB(fd,38+k) = auction.item.refine;
  12453. WFIFOW(fd,39+k) = auction.item.card[0];
  12454. WFIFOW(fd,41+k) = auction.item.card[1];
  12455. WFIFOW(fd,43+k) = auction.item.card[2];
  12456. WFIFOW(fd,45+k) = auction.item.card[3];
  12457. WFIFOL(fd,47+k) = auction.price;
  12458. WFIFOL(fd,51+k) = auction.buynow;
  12459. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12460. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12461. }
  12462. WFIFOSET(fd,WFIFOW(fd,2));
  12463. }
  12464. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12465. /// 0256 <index>.W <result>.B
  12466. /// result:
  12467. /// 0 = success
  12468. /// 1 = failure
  12469. static void clif_Auction_setitem(int fd, int index, bool fail)
  12470. {
  12471. WFIFOHEAD(fd,packet_len(0x256));
  12472. WFIFOW(fd,0) = 0x256;
  12473. WFIFOW(fd,2) = index;
  12474. WFIFOB(fd,4) = fail;
  12475. WFIFOSET(fd,packet_len(0x256));
  12476. }
  12477. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12478. /// 024b <type>.W
  12479. /// type:
  12480. /// 0 = create (any other action in auction window)
  12481. /// 1 = cancel (cancel pressed on register tab)
  12482. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12483. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12484. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12485. if( sd->auction.amount > 0 )
  12486. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12487. sd->auction.amount = 0;
  12488. }
  12489. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12490. /// 024c <index>.W <count>.L
  12491. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12492. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12493. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12494. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12495. struct item_data *item;
  12496. if( !battle_config.feature_auction )
  12497. return;
  12498. if( sd->auction.amount > 0 )
  12499. sd->auction.amount = 0;
  12500. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12501. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12502. return;
  12503. }
  12504. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12505. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12506. return;
  12507. }
  12508. 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) )
  12509. { // Consumable or pets are not allowed
  12510. clif_Auction_setitem(sd->fd, idx, true);
  12511. return;
  12512. }
  12513. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12514. !sd->status.inventory[idx].identify ||
  12515. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12516. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12517. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12518. ) {
  12519. clif_Auction_setitem(sd->fd, idx, true);
  12520. return;
  12521. }
  12522. sd->auction.index = idx;
  12523. sd->auction.amount = amount;
  12524. clif_Auction_setitem(fd, idx + 2, false);
  12525. }
  12526. /// Result from an auction action (ZC_AUCTION_RESULT).
  12527. /// 0250 <result>.B
  12528. /// result:
  12529. /// 0 = You have failed to bid into the auction
  12530. /// 1 = You have successfully bid in the auction
  12531. /// 2 = The auction has been canceled
  12532. /// 3 = An auction with at least one bidder cannot be canceled
  12533. /// 4 = You cannot register more than 5 items in an auction at a time
  12534. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12535. /// 6 = You have won the auction
  12536. /// 7 = You have failed to win the auction
  12537. /// 8 = You do not have enough Zeny
  12538. /// 9 = You cannot place more than 5 bids at a time
  12539. void clif_Auction_message(int fd, unsigned char flag)
  12540. {
  12541. WFIFOHEAD(fd,packet_len(0x250));
  12542. WFIFOW(fd,0) = 0x250;
  12543. WFIFOB(fd,2) = flag;
  12544. WFIFOSET(fd,packet_len(0x250));
  12545. }
  12546. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12547. /// 025e <result>.W
  12548. /// result:
  12549. /// 0 = You have ended the auction
  12550. /// 1 = You cannot end the auction
  12551. /// 2 = Auction ID is incorrect
  12552. void clif_Auction_close(int fd, unsigned char flag)
  12553. {
  12554. WFIFOHEAD(fd,packet_len(0x25e));
  12555. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12556. WFIFOW(fd,2) = flag;
  12557. WFIFOSET(fd,packet_len(0x25e));
  12558. }
  12559. /// Request to add an auction (CZ_AUCTION_ADD).
  12560. /// 024d <now money>.L <max money>.L <delete hour>.W
  12561. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12562. {
  12563. struct auction_data auction;
  12564. struct item_data *item;
  12565. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12566. if( !battle_config.feature_auction )
  12567. return;
  12568. auction.price = RFIFOL(fd,info->pos[0]);
  12569. auction.buynow = RFIFOL(fd,info->pos[1]);
  12570. auction.hours = RFIFOW(fd,info->pos[2]);
  12571. // Invalid Situations...
  12572. if( sd->auction.amount < 1 ) {
  12573. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12574. return;
  12575. }
  12576. if( auction.price >= auction.buynow ) {
  12577. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12578. return;
  12579. }
  12580. if( auction.hours < 1 || auction.hours > 48 ) {
  12581. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12582. return;
  12583. }
  12584. // Auction checks...
  12585. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12586. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12587. clif_Auction_message(fd, 2); // The auction has been canceled
  12588. return;
  12589. }
  12590. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12591. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12592. return;
  12593. }
  12594. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12595. auction.buynow = battle_config.auction_maximumprice;
  12596. if( auction.price >= auction.buynow )
  12597. auction.price = auction.buynow - 1;
  12598. }
  12599. auction.auction_id = 0;
  12600. auction.seller_id = sd->status.char_id;
  12601. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12602. auction.buyer_id = 0;
  12603. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12604. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12605. {
  12606. clif_Auction_message(fd, 2); // The auction has been canceled
  12607. return;
  12608. }
  12609. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12610. { // Just in case
  12611. clif_Auction_message(fd, 2); // The auction has been canceled
  12612. return;
  12613. }
  12614. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12615. auction.type = item->type;
  12616. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12617. auction.item.amount = 1;
  12618. auction.timestamp = 0;
  12619. if( !intif_Auction_register(&auction) )
  12620. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12621. else
  12622. {
  12623. int zeny = auction.hours*battle_config.auction_feeperhour;
  12624. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12625. sd->auction.amount = 0;
  12626. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12627. }
  12628. }
  12629. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12630. /// 024e <auction id>.L
  12631. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12632. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12633. intif_Auction_cancel(sd->status.char_id, auction_id);
  12634. }
  12635. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12636. /// 025d <auction id>.L
  12637. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12638. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12639. intif_Auction_close(sd->status.char_id, auction_id);
  12640. }
  12641. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12642. /// 024f <auction id>.L <money>.L
  12643. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12644. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12645. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12646. int bid = RFIFOL(fd,info->pos[1]);
  12647. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12648. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12649. return;
  12650. }
  12651. if( bid <= 0 )
  12652. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12653. else if( bid > sd->status.zeny )
  12654. clif_Auction_message(fd, 8); // You do not have enough zeny
  12655. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12656. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12657. else {
  12658. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12659. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12660. }
  12661. }
  12662. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12663. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12664. /// search type:
  12665. /// 0 = armor
  12666. /// 1 = weapon
  12667. /// 2 = card
  12668. /// 3 = misc
  12669. /// 4 = name search
  12670. /// 5 = auction id search
  12671. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12672. char search_text[NAME_LENGTH];
  12673. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12674. short type = RFIFOW(fd,info->pos[0]);
  12675. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12676. int page = RFIFOW(fd,info->pos[3]);
  12677. if( !battle_config.feature_auction )
  12678. return;
  12679. clif_parse_Auction_cancelreg(fd, sd);
  12680. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12681. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12682. }
  12683. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12684. /// 025c <type>.W
  12685. /// type:
  12686. /// 0 = sell (own auctions)
  12687. /// 1 = buy (own bids)
  12688. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12689. {
  12690. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12691. if( !battle_config.feature_auction )
  12692. return;
  12693. clif_parse_Auction_cancelreg(fd, sd);
  12694. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12695. }
  12696. /// CASH/POINT SHOP
  12697. ///
  12698. void clif_cashshop_open( struct map_session_data* sd ){
  12699. WFIFOHEAD( sd->fd, 10 );
  12700. WFIFOW( sd->fd, 0 ) = 0x845;
  12701. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12702. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12703. WFIFOSET( sd->fd, 10 );
  12704. }
  12705. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12706. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12707. clif_cashshop_open( sd );
  12708. }
  12709. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12710. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12711. // No need to do anything here
  12712. }
  12713. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12714. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12715. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12716. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12717. int j;
  12718. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12719. return;
  12720. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12721. WFIFOW(fd, 0) = 0x8c0;
  12722. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12723. WFIFOL(fd, 4) = tab;
  12724. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12725. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12726. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  12727. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  12728. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12729. }
  12730. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12731. }
  12732. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12733. void clif_cashshop_list( int fd ){
  12734. int tab;
  12735. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12736. int length = 8 + cash_shop_items[tab].count * 6;
  12737. int i, offset;
  12738. WFIFOHEAD( fd, length );
  12739. WFIFOW( fd, 0 ) = 0x8ca;
  12740. WFIFOW( fd, 2 ) = length;
  12741. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12742. WFIFOW( fd, 6 ) = tab;
  12743. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12744. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  12745. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  12746. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12747. }
  12748. WFIFOSET( fd, length );
  12749. }
  12750. }
  12751. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12752. if( !sd->status.cashshop_sent ) {
  12753. clif_cashshop_list( fd );
  12754. sd->status.cashshop_sent = true;
  12755. }
  12756. }
  12757. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12758. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12759. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12760. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12761. {
  12762. int fd,i;
  12763. #if PACKETVER < 20070711
  12764. const int offset = 8;
  12765. #else
  12766. const int offset = 12;
  12767. #endif
  12768. nullpo_retv(sd);
  12769. nullpo_retv(nd);
  12770. fd = sd->fd;
  12771. sd->npc_shopid = nd->bl.id;
  12772. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12773. WFIFOW(fd,0) = 0x287;
  12774. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12775. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12776. #if PACKETVER >= 20070711
  12777. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12778. #endif
  12779. for( i = 0; i < nd->u.shop.count; i++ ) {
  12780. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12781. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12782. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12783. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12784. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12785. }
  12786. WFIFOSET(fd,WFIFOW(fd,2));
  12787. }
  12788. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12789. /// 0289 <cash point>.L <error>.W
  12790. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12791. /// error:
  12792. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12793. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12794. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12795. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12796. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12797. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12798. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12799. /// 7 = You can purchase up to 10 items.
  12800. /// 8 = Some items could not be purchased.
  12801. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12802. {
  12803. int fd = sd->fd;
  12804. WFIFOHEAD(fd, packet_len(0x289));
  12805. WFIFOW(fd,0) = 0x289;
  12806. WFIFOL(fd,2) = sd->cashPoints;
  12807. #if PACKETVER < 20070711
  12808. WFIFOW(fd,6) = TOW(error);
  12809. #else
  12810. WFIFOL(fd,6) = sd->kafraPoints;
  12811. WFIFOW(fd,10) = TOW(error);
  12812. #endif
  12813. WFIFOSET(fd, packet_len(0x289));
  12814. }
  12815. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  12816. WFIFOHEAD( sd->fd, 16 );
  12817. WFIFOW( sd->fd, 0 ) = 0x849;
  12818. WFIFOL( sd->fd, 2 ) = item_id;
  12819. WFIFOW( sd->fd, 6 ) = result;
  12820. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12821. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12822. WFIFOSET( sd->fd, 16 );
  12823. }
  12824. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12825. /// 0288 <name id>.W <amount>.W
  12826. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12827. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12828. /// 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)
  12829. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  12830. struct s_packet_db* info;
  12831. int cmd = RFIFOW(fd,0);
  12832. nullpo_retv(sd);
  12833. info = &packet_db[sd->packet_ver][cmd];
  12834. if( sd->state.trading || !sd->npc_shopid ) {
  12835. clif_cashshop_ack(sd,1);
  12836. return;
  12837. } else {
  12838. #if PACKETVER < 20101116
  12839. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  12840. short amount = RFIFOW(fd,info->pos[1]);
  12841. int points = RFIFOL(fd,info->pos[2]);
  12842. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  12843. #else
  12844. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12845. int len = RFIFOW(fd,info->pos[0]);
  12846. int points = RFIFOL(fd,info->pos[1]);
  12847. int count = RFIFOW(fd,info->pos[2]);
  12848. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12849. if( len < 10 || len != 10 + count * s_itl) {
  12850. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12851. return;
  12852. }
  12853. if(cmd == 0x848) {
  12854. if (cashshop_buylist( sd, points, count, item_list))
  12855. clif_cashshop_ack(sd,0);
  12856. return;
  12857. } else {
  12858. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  12859. return;
  12860. }
  12861. #endif
  12862. }
  12863. }
  12864. /// Adoption System
  12865. ///
  12866. /// Adoption message (ZC_BABYMSG).
  12867. /// 0216 <msg>.L
  12868. /// msg:
  12869. /// 0 = "You cannot adopt more than 1 child."
  12870. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12871. /// 2 = "You cannot adopt a married person."
  12872. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12873. {
  12874. int fd = sd->fd;
  12875. WFIFOHEAD(fd,6);
  12876. WFIFOW(fd,0) = 0x216;
  12877. WFIFOL(fd,2) = type;
  12878. WFIFOSET(fd,6);
  12879. }
  12880. /// Adoption confirmation (ZC_REQ_BABY).
  12881. /// 01f6 <account id>.L <char id>.L <name>.B
  12882. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12883. {
  12884. int fd = sd->fd;
  12885. WFIFOHEAD(fd,34);
  12886. WFIFOW(fd,0) = 0x1f6;
  12887. WFIFOL(fd,2) = src->status.account_id;
  12888. WFIFOL(fd,6) = p_id;
  12889. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12890. WFIFOSET(fd,34);
  12891. }
  12892. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12893. /// 01f9 <account id>.L
  12894. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12895. {
  12896. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12897. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12898. if( pc_can_Adopt(sd, p_sd, tsd) )
  12899. {
  12900. tsd->adopt_invite = sd->status.account_id;
  12901. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12902. }
  12903. }
  12904. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12905. /// 01f7 <account id>.L <char id>.L <answer>.L
  12906. /// answer:
  12907. /// 0 = rejected
  12908. /// 1 = accepted
  12909. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12910. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12911. int p1_id = RFIFOL(fd,info->pos[0]);
  12912. int p2_id = RFIFOL(fd,info->pos[1]);
  12913. int result = RFIFOL(fd,info->pos[2]);
  12914. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12915. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12916. int pid = sd->adopt_invite;
  12917. sd->adopt_invite = 0;
  12918. if( p1_sd == NULL || p2_sd == NULL )
  12919. return; // Both players need to be online
  12920. if( pid != p1_sd->status.account_id )
  12921. return; // Incorrect values
  12922. if( result == 0 )
  12923. return; // Rejected
  12924. pc_adoption(p1_sd, p2_sd, sd);
  12925. }
  12926. /// Convex Mirror (ZC_BOSS_INFO).
  12927. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12928. /// infoType:
  12929. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12930. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12931. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12932. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12933. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12934. {
  12935. WFIFOHEAD(fd,70);
  12936. memset(WFIFOP(fd,0),0,70);
  12937. WFIFOW(fd,0) = 0x293;
  12938. if( md != NULL ) {
  12939. if( md->bl.prev != NULL ) { // Boss on This Map
  12940. if( flag ) {
  12941. WFIFOB(fd,2) = 1;
  12942. WFIFOL(fd,3) = md->bl.x;
  12943. WFIFOL(fd,7) = md->bl.y;
  12944. } else
  12945. WFIFOB(fd,2) = 2; // First Time
  12946. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12947. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12948. unsigned int seconds;
  12949. int hours, minutes;
  12950. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12951. hours = seconds / (60 * 60);
  12952. seconds = seconds - (60 * 60 * hours);
  12953. minutes = seconds / 60;
  12954. WFIFOB(fd,2) = 3;
  12955. WFIFOW(fd,11) = hours; // Hours
  12956. WFIFOW(fd,13) = minutes; // Minutes
  12957. }
  12958. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12959. }
  12960. WFIFOSET(fd,70);
  12961. }
  12962. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12963. /// 02d6 <account id>.L
  12964. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12965. {
  12966. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12967. struct map_session_data* tsd = map_id2sd(aid);
  12968. if (!tsd)
  12969. return;
  12970. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12971. clif_viewequip_ack(sd, tsd);
  12972. else
  12973. clif_msg(sd, VIEW_EQUIP_FAIL);
  12974. }
  12975. /// Request to change equip window tick (CZ_CONFIG).
  12976. /// 02d8 <type>.L <flag>.L
  12977. /// type:
  12978. /// 0 = open equip window
  12979. /// flag:
  12980. /// 0 = disabled
  12981. /// 1 = enabled
  12982. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12983. {
  12984. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12985. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12986. sd->status.show_equip = flag;
  12987. clif_equiptickack(sd, flag);
  12988. }
  12989. /// Request to change party invitation tick.
  12990. /// value:
  12991. /// 0 = disabled
  12992. /// 1 = enabled
  12993. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  12994. {
  12995. bool flag = RFIFOB(fd,6) ? true : false;
  12996. sd->status.allow_party = flag;
  12997. clif_partytickack(sd, flag);
  12998. }
  12999. /// Questlog System [Kevin] [Inkfish]
  13000. ///
  13001. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13002. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13003. void clif_quest_send_list(struct map_session_data * sd)
  13004. {
  13005. int fd = sd->fd;
  13006. int i;
  13007. int len = sd->avail_quests*5+8;
  13008. WFIFOHEAD(fd,len);
  13009. WFIFOW(fd, 0) = 0x2b1;
  13010. WFIFOW(fd, 2) = len;
  13011. WFIFOL(fd, 4) = sd->avail_quests;
  13012. for( i = 0; i < sd->avail_quests; i++ ) {
  13013. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  13014. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  13015. }
  13016. WFIFOSET(fd, len);
  13017. }
  13018. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13019. /// 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
  13020. void clif_quest_send_mission(struct map_session_data * sd)
  13021. {
  13022. int fd = sd->fd;
  13023. int i, j;
  13024. int len = sd->avail_quests*104+8;
  13025. struct mob_db *mob;
  13026. WFIFOHEAD(fd, len);
  13027. WFIFOW(fd, 0) = 0x2b2;
  13028. WFIFOW(fd, 2) = len;
  13029. WFIFOL(fd, 4) = sd->avail_quests;
  13030. for( i = 0; i < sd->avail_quests; i++ ) {
  13031. struct quest_db *qi = quest_db(sd->quest_log[i].quest_id);
  13032. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13033. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13034. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13035. WFIFOW(fd, i*104+20) = qi->num_objectives;
  13036. for( j = 0 ; j < qi->num_objectives; j++ ) {
  13037. WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
  13038. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13039. mob = mob_db(qi->mob[j]);
  13040. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13041. }
  13042. }
  13043. WFIFOSET(fd, len);
  13044. }
  13045. /// Notification about a new quest (ZC_ADD_QUEST).
  13046. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13047. void clif_quest_add(struct map_session_data * sd, struct quest * qd)
  13048. {
  13049. int fd = sd->fd;
  13050. int i;
  13051. struct quest_db *qi = quest_db(qd->quest_id);
  13052. WFIFOHEAD(fd, packet_len(0x2b3));
  13053. WFIFOW(fd, 0) = 0x2b3;
  13054. WFIFOL(fd, 2) = qd->quest_id;
  13055. WFIFOB(fd, 6) = qd->state;
  13056. WFIFOB(fd, 7) = qi->time;
  13057. WFIFOL(fd, 11) = qd->time;
  13058. WFIFOW(fd, 15) = qi->num_objectives;
  13059. for( i = 0; i < qi->num_objectives; i++ ) {
  13060. struct mob_db *mob;
  13061. WFIFOL(fd, i*30+17) = qi->mob[i];
  13062. WFIFOW(fd, i*30+21) = qd->count[i];
  13063. mob = mob_db(qi->mob[i]);
  13064. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13065. }
  13066. WFIFOSET(fd, packet_len(0x2b3));
  13067. }
  13068. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13069. /// 02b4 <quest id>.L
  13070. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  13071. {
  13072. int fd = sd->fd;
  13073. WFIFOHEAD(fd, packet_len(0x2b4));
  13074. WFIFOW(fd, 0) = 0x2b4;
  13075. WFIFOL(fd, 2) = quest_id;
  13076. WFIFOSET(fd, packet_len(0x2b4));
  13077. }
  13078. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13079. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13080. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd)
  13081. {
  13082. int fd = sd->fd;
  13083. int i;
  13084. struct quest_db *qi = quest_db(qd->quest_id);
  13085. int len = qi->num_objectives * 12 + 6;
  13086. WFIFOHEAD(fd, len);
  13087. WFIFOW(fd, 0) = 0x2b5;
  13088. WFIFOW(fd, 2) = len;
  13089. WFIFOW(fd, 4) = qi->num_objectives;
  13090. for( i = 0; i < qi->num_objectives; i++ ) {
  13091. WFIFOL(fd, i*12+6) = qd->quest_id;
  13092. WFIFOL(fd, i*12+10) = qi->mob[i];
  13093. WFIFOW(fd, i*12+14) = qi->count[i];
  13094. WFIFOW(fd, i*12+16) = qd->count[i];
  13095. }
  13096. WFIFOSET(fd, len);
  13097. }
  13098. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13099. /// 02b6 <quest id>.L <active>.B
  13100. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  13101. {
  13102. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13103. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13104. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13105. }
  13106. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13107. /// 02b7 <quest id>.L <active>.B
  13108. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  13109. {
  13110. int fd = sd->fd;
  13111. WFIFOHEAD(fd, packet_len(0x2b7));
  13112. WFIFOW(fd, 0) = 0x2b7;
  13113. WFIFOL(fd, 2) = quest_id;
  13114. WFIFOB(fd, 6) = active;
  13115. WFIFOSET(fd, packet_len(0x2b7));
  13116. }
  13117. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13118. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13119. /// effect:
  13120. /// 0 = none
  13121. /// 1 = exclamation mark icon
  13122. /// 2 = question mark icon
  13123. /// type:
  13124. /// 0 = yellow
  13125. /// 1 = orange
  13126. /// 2 = green
  13127. /// 3 = purple
  13128. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13129. {
  13130. #if PACKETVER >= 20090218
  13131. int fd = sd->fd;
  13132. WFIFOHEAD(fd, packet_len(0x446));
  13133. WFIFOW(fd, 0) = 0x446;
  13134. WFIFOL(fd, 2) = bl->id;
  13135. WFIFOW(fd, 6) = bl->x;
  13136. WFIFOW(fd, 8) = bl->y;
  13137. WFIFOW(fd, 10) = state;
  13138. WFIFOW(fd, 12) = color;
  13139. WFIFOSET(fd, packet_len(0x446));
  13140. #endif
  13141. }
  13142. /// Mercenary System
  13143. ///
  13144. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13145. /// 02a2 <var id>.W <value>.L
  13146. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13147. {
  13148. struct mercenary_data *md;
  13149. struct status_data *status;
  13150. int fd;
  13151. if( sd == NULL || (md = sd->md) == NULL )
  13152. return;
  13153. fd = sd->fd;
  13154. status = &md->battle_status;
  13155. WFIFOHEAD(fd,packet_len(0x2a2));
  13156. WFIFOW(fd,0) = 0x2a2;
  13157. WFIFOW(fd,2) = type;
  13158. switch( type ) {
  13159. case SP_ATK1:
  13160. {
  13161. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13162. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13163. }
  13164. break;
  13165. case SP_MATK1:
  13166. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13167. break;
  13168. case SP_HIT:
  13169. WFIFOL(fd,4) = status->hit;
  13170. break;
  13171. case SP_CRITICAL:
  13172. WFIFOL(fd,4) = status->cri/10;
  13173. break;
  13174. case SP_DEF1:
  13175. WFIFOL(fd,4) = status->def;
  13176. break;
  13177. case SP_MDEF1:
  13178. WFIFOL(fd,4) = status->mdef;
  13179. break;
  13180. case SP_MERCFLEE:
  13181. WFIFOL(fd,4) = status->flee;
  13182. break;
  13183. case SP_ASPD:
  13184. WFIFOL(fd,4) = status->amotion;
  13185. break;
  13186. case SP_HP:
  13187. WFIFOL(fd,4) = status->hp;
  13188. break;
  13189. case SP_MAXHP:
  13190. WFIFOL(fd,4) = status->max_hp;
  13191. break;
  13192. case SP_SP:
  13193. WFIFOL(fd,4) = status->sp;
  13194. break;
  13195. case SP_MAXSP:
  13196. WFIFOL(fd,4) = status->max_sp;
  13197. break;
  13198. case SP_MERCKILLS:
  13199. WFIFOL(fd,4) = md->mercenary.kill_count;
  13200. break;
  13201. case SP_MERCFAITH:
  13202. WFIFOL(fd,4) = mercenary_get_faith(md);
  13203. break;
  13204. }
  13205. WFIFOSET(fd,packet_len(0x2a2));
  13206. }
  13207. /// Mercenary base status data (ZC_MER_INIT).
  13208. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13209. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13210. /// <calls>.L <kills>.L <atk range>.W
  13211. void clif_mercenary_info(struct map_session_data *sd)
  13212. {
  13213. int fd;
  13214. struct mercenary_data *md;
  13215. struct status_data *status;
  13216. int atk;
  13217. if( sd == NULL || (md = sd->md) == NULL )
  13218. return;
  13219. fd = sd->fd;
  13220. status = &md->battle_status;
  13221. WFIFOHEAD(fd,packet_len(0x29b));
  13222. WFIFOW(fd,0) = 0x29b;
  13223. WFIFOL(fd,2) = md->bl.id;
  13224. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13225. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13226. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13227. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13228. WFIFOW(fd,10) = status->hit;
  13229. WFIFOW(fd,12) = status->cri/10;
  13230. WFIFOW(fd,14) = status->def;
  13231. WFIFOW(fd,16) = status->mdef;
  13232. WFIFOW(fd,18) = status->flee;
  13233. WFIFOW(fd,20) = status->amotion;
  13234. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13235. WFIFOW(fd,46) = md->db->lv;
  13236. WFIFOL(fd,48) = status->hp;
  13237. WFIFOL(fd,52) = status->max_hp;
  13238. WFIFOL(fd,56) = status->sp;
  13239. WFIFOL(fd,60) = status->max_sp;
  13240. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13241. WFIFOW(fd,68) = mercenary_get_faith(md);
  13242. WFIFOL(fd,70) = mercenary_get_calls(md);
  13243. WFIFOL(fd,74) = md->mercenary.kill_count;
  13244. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13245. WFIFOSET(fd,packet_len(0x29b));
  13246. }
  13247. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13248. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13249. void clif_mercenary_skillblock(struct map_session_data *sd)
  13250. {
  13251. struct mercenary_data *md;
  13252. int fd, i, len = 4;
  13253. if( sd == NULL || (md = sd->md) == NULL )
  13254. return;
  13255. fd = sd->fd;
  13256. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13257. WFIFOW(fd,0) = 0x29d;
  13258. for( i = 0; i < MAX_MERCSKILL; i++ )
  13259. {
  13260. int id, j;
  13261. if( (id = md->db->skill[i].id) == 0 )
  13262. continue;
  13263. j = id - MC_SKILLBASE;
  13264. WFIFOW(fd,len) = id;
  13265. WFIFOL(fd,len+2) = skill_get_inf(id);
  13266. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13267. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13268. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13269. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13270. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13271. len += 37;
  13272. }
  13273. WFIFOW(fd,2) = len;
  13274. WFIFOSET(fd,len);
  13275. }
  13276. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13277. /// 029f <command>.B
  13278. /// 1 = mercenary information
  13279. /// 2 = delete
  13280. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13281. {
  13282. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13283. if( sd->md == NULL )
  13284. return;
  13285. if( option == 2 ) mercenary_delete(sd->md, 2);
  13286. }
  13287. /// Mercenary Message
  13288. /// message:
  13289. /// 0 = Mercenary soldier's duty hour is over.
  13290. /// 1 = Your mercenary soldier has been killed.
  13291. /// 2 = Your mercenary soldier has been fired.
  13292. /// 3 = Your mercenary soldier has ran away.
  13293. void clif_mercenary_message(struct map_session_data* sd, int message){
  13294. clif_msg(sd, MERC_MSG_BASE + message);
  13295. }
  13296. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13297. /// 0298 <name id>.W <seconds>.L
  13298. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13299. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13300. WFIFOHEAD(fd,packet_len(0x298));
  13301. WFIFOW(fd,0) = 0x298;
  13302. WFIFOW(fd,2) = nameid;
  13303. WFIFOL(fd,4) = seconds;
  13304. WFIFOSET(fd,packet_len(0x298));
  13305. }
  13306. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13307. /// 0299 <index>.W <name id>.W
  13308. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13309. { // '<ItemName>' item has been deleted from the Inventory
  13310. WFIFOHEAD(fd,packet_len(0x299));
  13311. WFIFOW(fd,0) = 0x299;
  13312. WFIFOW(fd,2) = index+2;
  13313. WFIFOW(fd,4) = nameid;
  13314. WFIFOSET(fd,packet_len(0x299));
  13315. }
  13316. /// Book Reading (ZC_READ_BOOK).
  13317. /// 0294 <book id>.L <page>.L
  13318. void clif_readbook(int fd, int book_id, int page)
  13319. {
  13320. WFIFOHEAD(fd,packet_len(0x294));
  13321. WFIFOW(fd,0) = 0x294;
  13322. WFIFOL(fd,2) = book_id;
  13323. WFIFOL(fd,6) = page;
  13324. WFIFOSET(fd,packet_len(0x294));
  13325. }
  13326. /// Battlegrounds
  13327. ///
  13328. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13329. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13330. void clif_bg_hp(struct map_session_data *sd)
  13331. {
  13332. unsigned char buf[34];
  13333. const int cmd = 0x2e0;
  13334. nullpo_retv(sd);
  13335. WBUFW(buf,0) = cmd;
  13336. WBUFL(buf,2) = sd->status.account_id;
  13337. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13338. if( sd->battle_status.max_hp > INT16_MAX )
  13339. { // To correctly display the %hp bar. [Skotlex]
  13340. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13341. WBUFW(buf,32) = 100;
  13342. }
  13343. else
  13344. {
  13345. WBUFW(buf,30) = sd->battle_status.hp;
  13346. WBUFW(buf,32) = sd->battle_status.max_hp;
  13347. }
  13348. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13349. }
  13350. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13351. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13352. void clif_bg_xy(struct map_session_data *sd)
  13353. {
  13354. unsigned char buf[36];
  13355. nullpo_retv(sd);
  13356. WBUFW(buf,0)=0x2df;
  13357. WBUFL(buf,2)=sd->status.account_id;
  13358. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13359. WBUFW(buf,30)=sd->status.class_;
  13360. WBUFW(buf,32)=sd->bl.x;
  13361. WBUFW(buf,34)=sd->bl.y;
  13362. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13363. }
  13364. void clif_bg_xy_remove(struct map_session_data *sd)
  13365. {
  13366. unsigned char buf[36];
  13367. nullpo_retv(sd);
  13368. WBUFW(buf,0)=0x2df;
  13369. WBUFL(buf,2)=sd->status.account_id;
  13370. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13371. WBUFW(buf,30)=0;
  13372. WBUFW(buf,32)=-1;
  13373. WBUFW(buf,34)=-1;
  13374. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13375. }
  13376. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13377. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13378. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13379. {
  13380. struct map_session_data *sd;
  13381. unsigned char *buf;
  13382. if( (sd = bg_getavailablesd(bg)) == NULL )
  13383. return;
  13384. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13385. WBUFW(buf,0) = 0x2dc;
  13386. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13387. WBUFL(buf,4) = src_id;
  13388. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13389. memcpy(WBUFP(buf,32), mes, len);
  13390. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13391. if( buf )
  13392. aFree(buf);
  13393. }
  13394. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13395. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13396. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13397. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13398. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13399. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13400. char *name, *message;
  13401. int namelen, messagelen;
  13402. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13403. return;
  13404. if( is_atcommand(fd, sd, message, 1) )
  13405. return;
  13406. if (sd->sc.cant.chat)
  13407. return; //no "chatting" while muted.
  13408. if( battle_config.min_chat_delay ) {
  13409. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13410. return;
  13411. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13412. }
  13413. if (battle_config.idletime_option&IDLE_CHAT)
  13414. sd->idletime = last_tick;
  13415. bg_send_message(sd, text, textlen);
  13416. }
  13417. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13418. /// 02de <camp A points>.W <camp B points>.W
  13419. void clif_bg_updatescore(int16 m)
  13420. {
  13421. struct block_list bl;
  13422. unsigned char buf[6];
  13423. bl.id = 0;
  13424. bl.type = BL_NUL;
  13425. bl.m = m;
  13426. WBUFW(buf,0) = 0x2de;
  13427. WBUFW(buf,2) = map[m].bgscore_lion;
  13428. WBUFW(buf,4) = map[m].bgscore_eagle;
  13429. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13430. }
  13431. void clif_bg_updatescore_single(struct map_session_data *sd)
  13432. {
  13433. int fd;
  13434. nullpo_retv(sd);
  13435. fd = sd->fd;
  13436. WFIFOHEAD(fd,packet_len(0x2de));
  13437. WFIFOW(fd,0) = 0x2de;
  13438. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13439. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13440. WFIFOSET(fd,packet_len(0x2de));
  13441. }
  13442. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13443. /// 02dd <account id>.L <name>.24B <camp>.W
  13444. void clif_sendbgemblem_area(struct map_session_data *sd)
  13445. {
  13446. unsigned char buf[33];
  13447. nullpo_retv(sd);
  13448. WBUFW(buf, 0) = 0x2dd;
  13449. WBUFL(buf,2) = sd->bl.id;
  13450. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13451. WBUFW(buf,30) = sd->bg_id;
  13452. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13453. }
  13454. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13455. {
  13456. nullpo_retv(sd);
  13457. WFIFOHEAD(fd,32);
  13458. WFIFOW(fd,0) = 0x2dd;
  13459. WFIFOL(fd,2) = sd->bl.id;
  13460. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13461. WFIFOW(fd,30) = sd->bg_id;
  13462. WFIFOSET(fd,packet_len(0x2dd));
  13463. }
  13464. /// Custom Fonts (ZC_NOTIFY_FONT).
  13465. /// 02ef <account_id>.L <font id>.W
  13466. void clif_font(struct map_session_data *sd)
  13467. {
  13468. #if PACKETVER >= 20080102
  13469. unsigned char buf[8];
  13470. nullpo_retv(sd);
  13471. WBUFW(buf,0) = 0x2ef;
  13472. WBUFL(buf,2) = sd->bl.id;
  13473. WBUFW(buf,6) = sd->status.font;
  13474. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13475. #endif
  13476. }
  13477. /*==========================================
  13478. * Notifies party members of instance change
  13479. *------------------------------------------*/
  13480. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13481. {
  13482. #if PACKETVER >= 20071128
  13483. unsigned char buf[65];
  13484. if(!sd) return;
  13485. WBUFW(buf,0) = 0x2cb;
  13486. memcpy( WBUFP(buf,2), name, 62 );
  13487. WBUFW(buf,63) = num;
  13488. if(flag) // A timer has changed or been added
  13489. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13490. else // No notification
  13491. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13492. #endif
  13493. return;
  13494. }
  13495. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13496. {
  13497. #if PACKETVER >= 20071128
  13498. unsigned char buf[4];
  13499. if(!sd) return;
  13500. WBUFW(buf,0) = 0x2cc;
  13501. WBUFW(buf,2) = num;
  13502. if(flag) // A timer has changed or been added
  13503. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13504. else // No notification
  13505. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13506. #endif
  13507. return;
  13508. }
  13509. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13510. {
  13511. #if PACKETVER >= 20071128
  13512. unsigned char buf[71];
  13513. if(!sd) return; //party_getavailablesd can return NULL
  13514. WBUFW(buf,0) = 0x2cd;
  13515. memcpy( WBUFP(buf,2), name, 62 );
  13516. WBUFL(buf,63) = limit1;
  13517. WBUFL(buf,67) = limit2;
  13518. if(flag) // A timer has changed or been added
  13519. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13520. else // No notification
  13521. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13522. #endif
  13523. return;
  13524. }
  13525. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13526. {
  13527. #if PACKETVER >= 20071128
  13528. unsigned char buf[10];
  13529. if(!sd) return;
  13530. WBUFW(buf,0) = 0x2ce;
  13531. WBUFL(buf,2) = type;
  13532. WBUFL(buf,6) = limit;
  13533. if(flag) // A timer has changed or been added
  13534. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13535. else // No notification
  13536. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13537. #endif
  13538. return;
  13539. }
  13540. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13541. /// 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
  13542. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13543. {
  13544. #if PACKETVER >= 20071002
  13545. unsigned char buf[22];
  13546. struct item_data* id = itemdb_search(item_data->nameid);
  13547. WBUFW(buf,0) = 0x2b8;
  13548. WBUFL(buf,2) = sd->status.account_id;
  13549. WBUFW(buf,6) = item_data->nameid;
  13550. WBUFB(buf,8) = item_data->identify;
  13551. WBUFB(buf,9) = item_data->attribute;
  13552. WBUFB(buf,10) = item_data->refine;
  13553. clif_addcards(WBUFP(buf,11), item_data);
  13554. WBUFW(buf,19) = id->equip; // equip location
  13555. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13556. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13557. #endif
  13558. }
  13559. /// Display gained exp (ZC_NOTIFY_EXP).
  13560. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13561. /// var id:
  13562. /// SP_BASEEXP, SP_JOBEXP
  13563. /// exp type:
  13564. /// 0 = normal exp gain/loss
  13565. /// 1 = quest exp gain/loss
  13566. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13567. {
  13568. int fd;
  13569. nullpo_retv(sd);
  13570. fd = sd->fd;
  13571. WFIFOHEAD(fd, packet_len(0x7f6));
  13572. WFIFOW(fd,0) = 0x7f6;
  13573. WFIFOL(fd,2) = sd->bl.id;
  13574. WFIFOL(fd,6) = exp;
  13575. WFIFOW(fd,10) = type;
  13576. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13577. WFIFOSET(fd,packet_len(0x7f6));
  13578. }
  13579. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13580. /// type:
  13581. /// 0 = Displays 'value' for 5 seconds.
  13582. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13583. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13584. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13585. /// value:
  13586. /// 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).
  13587. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13588. {
  13589. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13590. WFIFOW(sd->fd,0) = 0x1b1;
  13591. WFIFOB(sd->fd,2) = type;
  13592. WFIFOL(sd->fd,3) = value;
  13593. WFIFOSET(sd->fd, packet_len(0x1b1));
  13594. }
  13595. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13596. /// 021d <state>.L
  13597. /// state:
  13598. /// 0 = Full effects
  13599. /// 1 = Reduced effects
  13600. ///
  13601. /// NOTE: The state is used on Aegis for sending skill unit packet
  13602. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13603. /// whenever possible. Due to the way the decision check is
  13604. /// constructed, this state tracking was rendered useless,
  13605. /// as the only skill unit, that is sent with 0x1c9 is
  13606. /// Graffiti.
  13607. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13608. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13609. sd->state.lesseffect = ( isLess != 0 );
  13610. }
  13611. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13612. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13613. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13614. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13615. int type = RFIFOL(fd,info->pos[1]);
  13616. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13617. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13618. if( sd->state.trading || sd->npc_shopid )
  13619. return;
  13620. if( flag == 0 || n == 0) {
  13621. clif_menuskill_clear(sd);
  13622. return; // Canceled by player.
  13623. }
  13624. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13625. clif_menuskill_clear(sd);
  13626. return; // Prevent hacking.
  13627. }
  13628. switch( type ) {
  13629. case 0: // Change Material
  13630. skill_changematerial(sd,n,item_list);
  13631. break;
  13632. case 1: // Level 1: Pure to Rough
  13633. case 2: // Level 2: Rough to Pure
  13634. skill_elementalanalysis(sd,n,type,item_list);
  13635. break;
  13636. }
  13637. clif_menuskill_clear(sd);
  13638. return;
  13639. }
  13640. /*==========================================
  13641. * Elemental System
  13642. *==========================================*/
  13643. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13644. struct elemental_data *ed;
  13645. struct status_data *status;
  13646. int fd;
  13647. if( sd == NULL || (ed = sd->ed) == NULL )
  13648. return;
  13649. fd = sd->fd;
  13650. status = &ed->battle_status;
  13651. WFIFOHEAD(fd,8);
  13652. WFIFOW(fd,0) = 0x81e;
  13653. WFIFOW(fd,2) = type;
  13654. switch( type ) {
  13655. case SP_HP:
  13656. WFIFOL(fd,4) = status->hp;
  13657. break;
  13658. case SP_MAXHP:
  13659. WFIFOL(fd,4) = status->max_hp;
  13660. break;
  13661. case SP_SP:
  13662. WFIFOL(fd,4) = status->sp;
  13663. break;
  13664. case SP_MAXSP:
  13665. WFIFOL(fd,4) = status->max_sp;
  13666. break;
  13667. }
  13668. WFIFOSET(fd,8);
  13669. }
  13670. void clif_elemental_info(struct map_session_data *sd) {
  13671. int fd;
  13672. struct elemental_data *ed;
  13673. struct status_data *status;
  13674. if( sd == NULL || (ed = sd->ed) == NULL )
  13675. return;
  13676. fd = sd->fd;
  13677. status = &ed->battle_status;
  13678. WFIFOHEAD(fd,22);
  13679. WFIFOW(fd, 0) = 0x81d;
  13680. WFIFOL(fd, 2) = ed->bl.id;
  13681. WFIFOL(fd, 6) = status->hp;
  13682. WFIFOL(fd,10) = status->max_hp;
  13683. WFIFOL(fd,14) = status->sp;
  13684. WFIFOL(fd,18) = status->max_sp;
  13685. WFIFOSET(fd,22);
  13686. }
  13687. /// Buying Store System
  13688. ///
  13689. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13690. /// 0810 <slots>.B
  13691. void clif_buyingstore_open(struct map_session_data* sd)
  13692. {
  13693. int fd = sd->fd;
  13694. WFIFOHEAD(fd,packet_len(0x810));
  13695. WFIFOW(fd,0) = 0x810;
  13696. WFIFOB(fd,2) = sd->buyingstore.slots;
  13697. WFIFOSET(fd,packet_len(0x810));
  13698. }
  13699. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13700. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13701. /// result:
  13702. /// 0 = cancel
  13703. /// 1 = open
  13704. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13705. {
  13706. const unsigned int blocksize = 8;
  13707. uint8* itemlist;
  13708. char storename[MESSAGE_SIZE];
  13709. unsigned char result;
  13710. int zenylimit;
  13711. unsigned int count, packet_len;
  13712. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13713. packet_len = RFIFOW(fd,info->pos[0]);
  13714. // TODO: Make this check global for all variable length packets.
  13715. if( packet_len < 89 )
  13716. {// minimum packet length
  13717. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13718. return;
  13719. }
  13720. zenylimit = RFIFOL(fd,info->pos[1]);
  13721. result = RFIFOL(fd,info->pos[2]);
  13722. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13723. itemlist = RFIFOP(fd,info->pos[4]);
  13724. // so that buyingstore_create knows, how many elements it has access to
  13725. packet_len-= info->pos[4];
  13726. if( packet_len%blocksize )
  13727. {
  13728. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13729. return;
  13730. }
  13731. count = packet_len/blocksize;
  13732. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13733. }
  13734. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13735. /// 0812 <result>.W <total weight>.L
  13736. /// result:
  13737. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13738. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13739. /// 8 = "No sale (purchase) information available." (0x705)
  13740. /// ? = nothing
  13741. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13742. {
  13743. int fd = sd->fd;
  13744. WFIFOHEAD(fd,packet_len(0x812));
  13745. WFIFOW(fd,0) = 0x812;
  13746. WFIFOW(fd,2) = result;
  13747. WFIFOL(fd,4) = weight;
  13748. WFIFOSET(fd,packet_len(0x812));
  13749. }
  13750. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13751. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13752. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13753. {
  13754. int fd = sd->fd;
  13755. unsigned int i;
  13756. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13757. WFIFOW(fd,0) = 0x813;
  13758. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13759. WFIFOL(fd,4) = sd->bl.id;
  13760. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13761. for( i = 0; i < sd->buyingstore.slots; i++ )
  13762. {
  13763. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13764. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13765. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13766. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13767. }
  13768. WFIFOSET(fd,WFIFOW(fd,2));
  13769. }
  13770. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13771. /// 0814 <account id>.L <store name>.80B
  13772. void clif_buyingstore_entry(struct map_session_data* sd)
  13773. {
  13774. uint8 buf[86];
  13775. WBUFW(buf,0) = 0x814;
  13776. WBUFL(buf,2) = sd->bl.id;
  13777. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13778. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13779. }
  13780. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13781. {
  13782. int fd = sd->fd;
  13783. WFIFOHEAD(fd,packet_len(0x814));
  13784. WFIFOW(fd,0) = 0x814;
  13785. WFIFOL(fd,2) = pl_sd->bl.id;
  13786. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13787. WFIFOSET(fd,packet_len(0x814));
  13788. }
  13789. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13790. /// 0815
  13791. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13792. {
  13793. buyingstore_close(sd);
  13794. }
  13795. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13796. /// 0816 <account id>.L
  13797. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13798. {
  13799. uint8 buf[6];
  13800. WBUFW(buf,0) = 0x816;
  13801. WBUFL(buf,2) = sd->bl.id;
  13802. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13803. }
  13804. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13805. {
  13806. int fd = sd->fd;
  13807. WFIFOHEAD(fd,packet_len(0x816));
  13808. WFIFOW(fd,0) = 0x816;
  13809. WFIFOL(fd,2) = pl_sd->bl.id;
  13810. WFIFOSET(fd,packet_len(0x816));
  13811. }
  13812. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13813. /// 0817 <account id>.L
  13814. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13815. {
  13816. int account_id;
  13817. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13818. buyingstore_open(sd, account_id);
  13819. }
  13820. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13821. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13822. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13823. {
  13824. int fd = sd->fd;
  13825. unsigned int i;
  13826. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13827. WFIFOW(fd,0) = 0x818;
  13828. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13829. WFIFOL(fd,4) = pl_sd->bl.id;
  13830. WFIFOL(fd,8) = pl_sd->buyer_id;
  13831. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13832. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13833. {
  13834. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13835. 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.
  13836. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  13837. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13838. }
  13839. WFIFOSET(fd,WFIFOW(fd,2));
  13840. }
  13841. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13842. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13843. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13844. {
  13845. const unsigned int blocksize = 6;
  13846. uint8* itemlist;
  13847. int account_id;
  13848. unsigned int count, packet_len, buyer_id;
  13849. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13850. packet_len = RFIFOW(fd,info->pos[0]);
  13851. if( packet_len < 12 )
  13852. {// minimum packet length
  13853. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13854. return;
  13855. }
  13856. account_id = RFIFOL(fd,info->pos[1]);
  13857. buyer_id = RFIFOL(fd,info->pos[2]);
  13858. itemlist = RFIFOP(fd,info->pos[3]);
  13859. // so that buyingstore_trade knows, how many elements it has access to
  13860. packet_len-= info->pos[3];
  13861. if( packet_len%blocksize )
  13862. {
  13863. 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);
  13864. return;
  13865. }
  13866. count = packet_len/blocksize;
  13867. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13868. }
  13869. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13870. /// 081a <result>.W
  13871. /// result:
  13872. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13873. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13874. /// ? = nothing
  13875. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13876. {
  13877. int fd = sd->fd;
  13878. WFIFOHEAD(fd,packet_len(0x81a));
  13879. WFIFOW(fd,0) = 0x81a;
  13880. WFIFOW(fd,2) = result;
  13881. WFIFOSET(fd,packet_len(0x81a));
  13882. }
  13883. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13884. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13885. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13886. {
  13887. int fd = sd->fd;
  13888. WFIFOHEAD(fd,packet_len(0x81b));
  13889. WFIFOW(fd,0) = 0x81b;
  13890. WFIFOW(fd,2) = nameid;
  13891. WFIFOW(fd,4) = amount; // amount of nameid received
  13892. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13893. WFIFOSET(fd,packet_len(0x81b));
  13894. }
  13895. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13896. /// 081c <index>.W <amount>.W <price>.L
  13897. /// message:
  13898. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13899. ///
  13900. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13901. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13902. {
  13903. int fd = sd->fd;
  13904. WFIFOHEAD(fd,packet_len(0x81c));
  13905. WFIFOW(fd,0) = 0x81c;
  13906. WFIFOW(fd,2) = index+2;
  13907. WFIFOW(fd,4) = amount;
  13908. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13909. WFIFOSET(fd,packet_len(0x81c));
  13910. }
  13911. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13912. /// 0824 <result>.W <name id>.W
  13913. /// result:
  13914. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13915. /// 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)
  13916. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13917. /// ? = nothing
  13918. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13919. {
  13920. int fd = sd->fd;
  13921. WFIFOHEAD(fd,packet_len(0x824));
  13922. WFIFOW(fd,0) = 0x824;
  13923. WFIFOW(fd,2) = result;
  13924. WFIFOW(fd,4) = nameid;
  13925. WFIFOSET(fd,packet_len(0x824));
  13926. }
  13927. /// Search Store Info System
  13928. ///
  13929. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13930. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13931. /// type:
  13932. /// 0 = Vending
  13933. /// 1 = Buying Store
  13934. ///
  13935. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13936. /// amount of card slots. If the client does not know about the item it
  13937. /// cannot be searched.
  13938. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13939. {
  13940. const unsigned int blocksize = 2;
  13941. const uint8* itemlist;
  13942. const uint8* cardlist;
  13943. unsigned char type;
  13944. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13945. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13946. packet_len = RFIFOW(fd,info->pos[0]);
  13947. if( packet_len < 15 )
  13948. {// minimum packet length
  13949. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13950. return;
  13951. }
  13952. type = RFIFOB(fd,info->pos[1]);
  13953. max_price = RFIFOL(fd,info->pos[2]);
  13954. min_price = RFIFOL(fd,info->pos[3]);
  13955. item_count = RFIFOB(fd,info->pos[4]);
  13956. card_count = RFIFOB(fd,info->pos[5]);
  13957. itemlist = RFIFOP(fd,info->pos[6]);
  13958. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13959. // check, if there is enough data for the claimed count of items
  13960. packet_len-= info->pos[6];
  13961. if( packet_len%blocksize )
  13962. {
  13963. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13964. return;
  13965. }
  13966. count = packet_len/blocksize;
  13967. if( count < item_count+card_count )
  13968. {
  13969. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13970. return;
  13971. }
  13972. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13973. }
  13974. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13975. /// 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 }*
  13976. /// is first page:
  13977. /// 0 = appends to existing results
  13978. /// 1 = clears previous results before displaying this result set
  13979. /// is next page:
  13980. /// 0 = no "next" label
  13981. /// 1 = "next" label to retrieve more results
  13982. void clif_search_store_info_ack(struct map_session_data* sd)
  13983. {
  13984. const unsigned int blocksize = MESSAGE_SIZE+26;
  13985. int fd = sd->fd;
  13986. unsigned int i, start, end;
  13987. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13988. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13989. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13990. WFIFOW(fd,0) = 0x836;
  13991. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13992. WFIFOB(fd,4) = !sd->searchstore.pages;
  13993. WFIFOB(fd,5) = searchstore_querynext(sd);
  13994. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13995. for( i = start; i < end; i++ ) {
  13996. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13997. struct item it;
  13998. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13999. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14000. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14001. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14002. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14003. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14004. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14005. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14006. // make-up an item for clif_addcards
  14007. memset(&it, 0, sizeof(it));
  14008. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14009. it.nameid = ssitem->nameid;
  14010. it.amount = ssitem->amount;
  14011. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14012. }
  14013. WFIFOSET(fd,WFIFOW(fd,2));
  14014. }
  14015. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14016. /// 0837 <reason>.B
  14017. /// reason:
  14018. /// 0 = "No matching stores were found." (0x70b)
  14019. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14020. /// 2 = "You cannot search anymore." (0x706)
  14021. /// 3 = "You cannot search yet." (0x708)
  14022. /// 4 = "No sale (purchase) information available." (0x705)
  14023. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14024. {
  14025. int fd = sd->fd;
  14026. WFIFOHEAD(fd,packet_len(0x837));
  14027. WFIFOW(fd,0) = 0x837;
  14028. WFIFOB(fd,2) = reason;
  14029. WFIFOSET(fd,packet_len(0x837));
  14030. }
  14031. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14032. /// 0838
  14033. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14034. {
  14035. searchstore_next(sd);
  14036. }
  14037. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14038. /// 083a <type>.W <remaining uses>.B
  14039. /// type:
  14040. /// 0 = Search Stores
  14041. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14042. void clif_open_search_store_info(struct map_session_data* sd)
  14043. {
  14044. int fd = sd->fd;
  14045. WFIFOHEAD(fd,packet_len(0x83a));
  14046. WFIFOW(fd,0) = 0x83a;
  14047. WFIFOW(fd,2) = sd->searchstore.effect;
  14048. #if PACKETVER > 20100701
  14049. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14050. #endif
  14051. WFIFOSET(fd,packet_len(0x83a));
  14052. }
  14053. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14054. /// 083b
  14055. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14056. {
  14057. searchstore_close(sd);
  14058. }
  14059. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14060. /// 083c <account id>.L <store id>.L <nameid>.W
  14061. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14062. {
  14063. unsigned short nameid;
  14064. int account_id, store_id;
  14065. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14066. account_id = RFIFOL(fd,info->pos[0]);
  14067. store_id = RFIFOL(fd,info->pos[1]);
  14068. nameid = RFIFOW(fd,info->pos[2]);
  14069. searchstore_click(sd, account_id, store_id, nameid);
  14070. }
  14071. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14072. /// 083d <xPos>.W <yPos>.W
  14073. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14074. {
  14075. int fd = sd->fd;
  14076. WFIFOHEAD(fd,packet_len(0x83d));
  14077. WFIFOW(fd,0) = 0x83d;
  14078. WFIFOW(fd,2) = x;
  14079. WFIFOW(fd,4) = y;
  14080. WFIFOSET(fd,packet_len(0x83d));
  14081. }
  14082. /// Parse function for packet debugging.
  14083. void clif_parse_debug(int fd,struct map_session_data *sd)
  14084. {
  14085. int cmd, packet_len;
  14086. // clif_parse ensures, that there is at least 2 bytes of data
  14087. cmd = RFIFOW(fd,0);
  14088. if( sd ) {
  14089. packet_len = packet_db[sd->packet_ver][cmd].len;
  14090. if( packet_len == 0 )
  14091. {// unknown
  14092. packet_len = RFIFOREST(fd);
  14093. }
  14094. else if( packet_len == -1 )
  14095. {// variable length
  14096. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14097. }
  14098. 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);
  14099. }
  14100. else
  14101. {
  14102. packet_len = RFIFOREST(fd);
  14103. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14104. }
  14105. ShowDump(RFIFOP(fd,0), packet_len);
  14106. }
  14107. /*==========================================
  14108. * Server tells client to display a window similar to Magnifier (item) one
  14109. * Server populates the window with avilable elemental converter options according to player's inventory
  14110. *------------------------------------------*/
  14111. int clif_elementalconverter_list(struct map_session_data *sd) {
  14112. int i,c,view,fd;
  14113. nullpo_ret(sd);
  14114. /// Main client packet processing function
  14115. fd=sd->fd;
  14116. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14117. WFIFOW(fd, 0)=0x1ad;
  14118. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14119. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14120. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14121. WFIFOW(fd,c*2+ 4)= view;
  14122. else
  14123. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14124. c++;
  14125. }
  14126. }
  14127. WFIFOW(fd,2) = c*2+4;
  14128. WFIFOSET(fd, WFIFOW(fd,2));
  14129. if (c > 0) {
  14130. sd->menuskill_id = SA_CREATECON;
  14131. sd->menuskill_val = c;
  14132. }
  14133. return 0;
  14134. }
  14135. /**
  14136. * Rune Knight
  14137. **/
  14138. void clif_millenniumshield(struct block_list *bl, short shields) {
  14139. #if PACKETVER >= 20081217
  14140. unsigned char buf[10];
  14141. WBUFW(buf,0) = 0x440;
  14142. WBUFL(buf,2) = bl->id;
  14143. WBUFW(buf,6) = shields;
  14144. WBUFW(buf,8) = 0;
  14145. clif_send(buf,packet_len(0x440),bl,AREA);
  14146. #endif
  14147. }
  14148. /**
  14149. * Warlock
  14150. **/
  14151. /*==========================================
  14152. * Spellbook list [LimitLine/3CeAM]
  14153. *------------------------------------------*/
  14154. int clif_spellbook_list(struct map_session_data *sd)
  14155. {
  14156. int i, c;
  14157. int fd;
  14158. nullpo_ret(sd);
  14159. fd = sd->fd;
  14160. WFIFOHEAD(fd, 8 * 8 + 8);
  14161. WFIFOW(fd,0) = 0x1ad;
  14162. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14163. {
  14164. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14165. {
  14166. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14167. c++;
  14168. }
  14169. }
  14170. if( c > 0 )
  14171. {
  14172. WFIFOW(fd,2) = c * 2 + 4;
  14173. WFIFOSET(fd, WFIFOW(fd, 2));
  14174. sd->menuskill_id = WL_READING_SB;
  14175. sd->menuskill_val = c;
  14176. }
  14177. else{
  14178. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14179. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14180. }
  14181. return 1;
  14182. }
  14183. /**
  14184. * Mechanic
  14185. **/
  14186. /*==========================================
  14187. * Magic Decoy Material List
  14188. *------------------------------------------*/
  14189. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14190. int i, c;
  14191. int fd;
  14192. nullpo_ret(sd);
  14193. fd = sd->fd;
  14194. WFIFOHEAD(fd, 8 * 8 + 8);
  14195. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14196. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14197. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14198. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14199. c ++;
  14200. }
  14201. }
  14202. if( c > 0 ) {
  14203. sd->menuskill_id = NC_MAGICDECOY;
  14204. sd->menuskill_val = skill_lv;
  14205. sd->sc.comet_x = x;
  14206. sd->sc.comet_y = y;
  14207. WFIFOW(fd,2) = c * 2 + 4;
  14208. WFIFOSET(fd, WFIFOW(fd, 2));
  14209. } else {
  14210. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14211. return 0;
  14212. }
  14213. return 1;
  14214. }
  14215. /*==========================================
  14216. * Guillotine Cross Poisons List
  14217. *------------------------------------------*/
  14218. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14219. int i, c;
  14220. int fd;
  14221. nullpo_ret(sd);
  14222. fd = sd->fd;
  14223. WFIFOHEAD(fd, 8 * 8 + 8);
  14224. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14225. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14226. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14227. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14228. c ++;
  14229. }
  14230. }
  14231. if( c > 0 ) {
  14232. sd->menuskill_id = GC_POISONINGWEAPON;
  14233. sd->menuskill_val = skill_lv;
  14234. WFIFOW(fd,2) = c * 2 + 4;
  14235. WFIFOSET(fd, WFIFOW(fd, 2));
  14236. } else {
  14237. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14238. return 0;
  14239. }
  14240. return 1;
  14241. }
  14242. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14243. int fd, i, c;
  14244. nullpo_ret(sd);
  14245. fd = sd->fd;
  14246. if( !fd ) return 0;
  14247. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14248. return 0;
  14249. WFIFOHEAD(fd, 2 * 6 + 4);
  14250. WFIFOW(fd,0) = 0x442;
  14251. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14252. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14253. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14254. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14255. {
  14256. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14257. c++;
  14258. }
  14259. if( c > 0 ) {
  14260. WFIFOW(fd,2) = 8 + c * 2;
  14261. WFIFOL(fd,4) = c;
  14262. WFIFOSET(fd,WFIFOW(fd,2));
  14263. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14264. sd->menuskill_val = c;
  14265. } else {
  14266. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14267. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14268. }
  14269. return 1;
  14270. }
  14271. /*===========================================
  14272. * Skill list for Four Elemental Analysis
  14273. * and Change Material skills.
  14274. *------------------------------------------*/
  14275. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14276. {
  14277. #if PACKETVER >= 20090922
  14278. int fd;
  14279. nullpo_ret(sd);
  14280. sd->menuskill_id = skill_id; // To prevent hacking.
  14281. sd->menuskill_val = skill_lv;
  14282. if( skill_id == GN_CHANGEMATERIAL )
  14283. skill_lv = 0; // Changematerial
  14284. fd = sd->fd;
  14285. WFIFOHEAD(fd,packet_len(0x7e3));
  14286. WFIFOW(fd,0) = 0x7e3;
  14287. WFIFOL(fd,2) = skill_lv;
  14288. WFIFOL(fd,4) = 0;
  14289. WFIFOSET(fd,packet_len(0x7e3));
  14290. #endif
  14291. return 1;
  14292. }
  14293. // msgstringtable.txt
  14294. // 0x291 <line>.W
  14295. void clif_msgtable(int fd, int line) {
  14296. WFIFOHEAD(fd, packet_len(0x291));
  14297. WFIFOW(fd, 0) = 0x291;
  14298. WFIFOW(fd, 2) = line;
  14299. WFIFOSET(fd, packet_len(0x291));
  14300. }
  14301. // msgstringtable.txt
  14302. // 0x7e2 <line>.W <value>.L
  14303. void clif_msgtable_num(int fd, int line, int num) {
  14304. #if PACKETVER >= 20090805
  14305. WFIFOHEAD(fd, packet_len(0x7e2));
  14306. WFIFOW(fd, 0) = 0x7e2;
  14307. WFIFOW(fd, 2) = line;
  14308. WFIFOL(fd, 4) = num;
  14309. WFIFOSET(fd, packet_len(0x7e2));
  14310. #endif
  14311. }
  14312. /*==========================================
  14313. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14314. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14315. * RFIFOL(fd,2) - type (currently not used)
  14316. *------------------------------------------*/
  14317. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14318. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14319. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14320. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14321. return;
  14322. if( pc_istrading(sd) ) {
  14323. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14324. clif_menuskill_clear(sd);
  14325. return;
  14326. }
  14327. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14328. clif_menuskill_clear(sd);
  14329. }
  14330. /*==========================================
  14331. * Kagerou/Oboro amulet spirit
  14332. *------------------------------------------*/
  14333. void clif_talisman(struct map_session_data *sd,short type)
  14334. {
  14335. unsigned char buf[10];
  14336. nullpo_retv(sd);
  14337. WBUFW(buf,0)=0x08cf;
  14338. WBUFL(buf,2)=sd->bl.id;
  14339. WBUFW(buf,6)=type;
  14340. WBUFW(buf,8)=sd->talisman[type];
  14341. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14342. }
  14343. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14344. /// 0907 <index>.W
  14345. ///
  14346. /// R 0908 <index>.w <type>.b
  14347. /// type:
  14348. /// 0 = move item to personal tab
  14349. /// 1 = move item to normal tab
  14350. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14351. #if PACKETVER >= 20111122
  14352. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14353. int index = RFIFOW(fd,info->pos[0])-2;
  14354. int type = RFIFOB(fd, info->pos[1]);
  14355. /* can't move while dead. */
  14356. if(pc_isdead(sd)) {
  14357. return;
  14358. }
  14359. if (index < 0 || index >= MAX_INVENTORY)
  14360. return;
  14361. if ( sd->status.inventory[index].favorite && type == 1 )
  14362. sd->status.inventory[index].favorite = 0;
  14363. else if( type == 0 )
  14364. sd->status.inventory[index].favorite = 1;
  14365. else
  14366. return;/* nothing to do. */
  14367. clif_favorite_item(sd, index);
  14368. #endif
  14369. }
  14370. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14371. /// 0900 <index>.W <favorite>.B
  14372. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14373. int fd = sd->fd;
  14374. WFIFOHEAD(fd,packet_len(0x908));
  14375. WFIFOW(fd,0) = 0x908;
  14376. WFIFOW(fd,2) = index+2;
  14377. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14378. WFIFOSET(fd,packet_len(0x908));
  14379. }
  14380. void clif_snap( struct block_list *bl, short x, short y ) {
  14381. unsigned char buf[10];
  14382. WBUFW(buf,0) = 0x8d2;
  14383. WBUFL(buf,2) = bl->id;
  14384. WBUFW(buf,6) = x;
  14385. WBUFW(buf,8) = y;
  14386. clif_send(buf,packet_len(0x8d2),bl,AREA);
  14387. }
  14388. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14389. #if PACKETVER >= 20120404
  14390. WFIFOHEAD(fd,packet_len(0x977));
  14391. WFIFOW(fd,0) = 0x977;
  14392. WFIFOL(fd,2) = md->bl.id;
  14393. WFIFOL(fd,6) = md->status.hp;
  14394. WFIFOL(fd,10) = md->status.max_hp;
  14395. WFIFOSET(fd,packet_len(0x977));
  14396. #endif
  14397. }
  14398. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14399. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14400. return;
  14401. }
  14402. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14403. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14404. WFIFOW(sd->fd,0) = 0x2c9;
  14405. WFIFOB(sd->fd,2) = flag;
  14406. WFIFOSET(sd->fd, packet_len(0x2c9));
  14407. }
  14408. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14409. /// 0979 <world name>.24B <char name>.24B
  14410. void clif_ackworldinfo(struct map_session_data* sd) {
  14411. int fd;
  14412. nullpo_retv(sd);
  14413. fd = sd->fd;
  14414. WFIFOHEAD(fd,packet_len(0x979));
  14415. WFIFOW(fd,0)=0x979;
  14416. //AID -> world name ?
  14417. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14418. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14419. WFIFOSET(fd,packet_len(0x979));
  14420. }
  14421. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14422. /// 0978 <AID>.L
  14423. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14424. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14425. if(sd) clif_ackworldinfo(sd);
  14426. }
  14427. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14428. /// 0447
  14429. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14430. //if(sd)
  14431. ;
  14432. }
  14433. /// req world info (CZ_CLIENT_VERSION)
  14434. /// 044A <version>.L
  14435. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14436. //if(sd)
  14437. ;
  14438. }
  14439. /// Ranking list
  14440. /// ranking pointlist { <name>.24B <point>.L }*10
  14441. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14442. struct fame_list* list;
  14443. int skip = 0;
  14444. switch(rankingtype+1) { //to keep the same case as char.c
  14445. case 1: list = smith_fame_list; break;
  14446. case 2: list = chemist_fame_list; break;
  14447. case 3: list = taekwon_fame_list; break;
  14448. default: skip=1; break;
  14449. }
  14450. if(!skip) {
  14451. int i;
  14452. //Packet size limits this list to 10 elements. [Skotlex]
  14453. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14454. if (list[i].id > 0) {
  14455. const char* name;
  14456. if (strcmp(list[i].name, "-") == 0 &&
  14457. (name = map_charid2nick(list[i].id)) != NULL)
  14458. {
  14459. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14460. } else {
  14461. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14462. }
  14463. } else {
  14464. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14465. }
  14466. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14467. }
  14468. for(;i < 10; i++) { //In case the MAX is less than 10.
  14469. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14470. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14471. }
  14472. }
  14473. }
  14474. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14475. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14476. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14477. int mypoint = 0;
  14478. WBUFW(buf,0) = 0x97d;
  14479. WBUFW(buf,2) = rankingType;
  14480. clif_sub_ranklist(buf,4,sd,rankingType);
  14481. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14482. case MAPID_BLACKSMITH:
  14483. case MAPID_ALCHEMIST:
  14484. case MAPID_TAEKWON:
  14485. mypoint = sd->status.fame;
  14486. }
  14487. WBUFL(buf,284) = mypoint; //mypoint
  14488. clif_send(buf, 288, &sd->bl, SELF);
  14489. }
  14490. /*
  14491. * 097c <type> (CZ_REQ_RANKING)
  14492. * type
  14493. * 0: /blacksmith
  14494. * 1: /alchemist
  14495. * 2: /taekwon
  14496. * 3: /pk
  14497. * */
  14498. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14499. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14500. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14501. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14502. }
  14503. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14504. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14505. #if PACKETVER < 20130710
  14506. switch(rankingtype){
  14507. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14508. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14509. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14510. }
  14511. #else
  14512. int fd=sd->fd;
  14513. WFIFOHEAD(fd,14);
  14514. WFIFOW(fd,0) = 0x97e;
  14515. WFIFOW(fd,2) = rankingtype;
  14516. WFIFOL(fd,4) = point;
  14517. WFIFOL(fd,8) = sd->status.fame;
  14518. WFIFOSET(fd,12);
  14519. #endif
  14520. }
  14521. /**
  14522. * Transmit personal information to player. (rates)
  14523. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14524. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14525. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14526. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14527. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14528. * FIXME!
  14529. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14530. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14531. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14532. */
  14533. #ifdef VIP_ENABLE
  14534. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14535. if (sd) {
  14536. struct s_packet_db* info;
  14537. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14538. int cmd = 0, fd, i = 0;
  14539. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14540. int details_bexp[PINFO_MAX];
  14541. int details_drop[PINFO_MAX];
  14542. int details_penalty[PINFO_MAX];
  14543. int penalty_const;
  14544. /**
  14545. * Set for EXP
  14546. */
  14547. //0:PCRoom
  14548. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14549. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14550. details_bexp[0] = 0;
  14551. else {
  14552. if (details_bexp[0] < 100) {
  14553. details_bexp[0] = 100 - details_bexp[0];
  14554. details_bexp[0] = 0 - details_bexp[0];
  14555. }
  14556. else
  14557. details_bexp[0] = details_bexp[0] - 100;
  14558. }
  14559. //1:Premium
  14560. if (pc_isvip(sd)) {
  14561. details_bexp[1] = battle_config.vip_base_exp_increase;
  14562. if (details_bexp[1] < 0)
  14563. details_bexp[1] = 0 - details_bexp[1];
  14564. }
  14565. else
  14566. details_bexp[1] = 0;
  14567. //2:Server
  14568. details_bexp[2] = battle_config.base_exp_rate;
  14569. if (details_bexp[2] == 100)
  14570. details_bexp[2] = 0;
  14571. else {
  14572. if (details_bexp[2] < 100) {
  14573. details_bexp[2] = 100 - details_bexp[2];
  14574. details_bexp[2] = 0 - details_bexp[2];
  14575. }
  14576. else
  14577. details_bexp[2] = details_bexp[2] - 100;
  14578. }
  14579. //3:TPLUS
  14580. details_bexp[3] = 0;
  14581. /* End - EXP set*/
  14582. /**
  14583. * Set for Drop rate
  14584. */
  14585. //0:PCRoom
  14586. details_drop[0] = 0;
  14587. //1:Premium
  14588. details_drop[1] = battle_config.vip_drop_increase;
  14589. if (pc_isvip(sd)) {
  14590. if (details_drop[1] < 0)
  14591. details_drop[1] = 0 - details_drop[1];
  14592. }
  14593. else
  14594. details_drop[1] = 0;
  14595. //2:Server
  14596. details_drop[2] = battle_config.item_rate_common;
  14597. if (details_drop[2] == 100)
  14598. details_drop[2] = 0;
  14599. else {
  14600. if (details_drop[2] < 100) {
  14601. details_drop[2] = 100 - details_drop[2];
  14602. details_drop[2] = 0 - details_drop[2];
  14603. }
  14604. else
  14605. details_drop[2] = details_drop[2] - 100;
  14606. }
  14607. //3:TPLUS
  14608. details_drop[3] = 0;
  14609. /* End - Drop set*/
  14610. /**
  14611. * Set for Penalty rate
  14612. */
  14613. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14614. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14615. //0:PCRoom
  14616. details_penalty[0] = 0;
  14617. //1:Premium
  14618. if (pc_isvip(sd)) {
  14619. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14620. if (details_penalty[1] == 100)
  14621. details_penalty[1] = 0;
  14622. else {
  14623. if (details_penalty[1] < 100) {
  14624. details_penalty[1] = 100 - details_penalty[1];
  14625. details_penalty[1] = 0 - details_penalty[1];
  14626. }
  14627. else
  14628. details_penalty[1] = details_penalty[1] - 100;
  14629. }
  14630. }
  14631. else
  14632. details_penalty[1] = 0;
  14633. //2:Server
  14634. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14635. if (details_penalty[2] == 100)
  14636. details_penalty[2] = 0;
  14637. else {
  14638. if (details_penalty[2] < 100) {
  14639. details_penalty[2] = 100 - details_penalty[2];
  14640. details_penalty[2] = 0 - details_penalty[2];
  14641. }
  14642. else
  14643. details_penalty[2] = details_penalty[2] - 100;
  14644. }
  14645. //3:TPLUS
  14646. details_penalty[3] = 0;
  14647. /* End - Penalty set*/
  14648. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14649. info = &packet_db[sd->packet_ver][cmd];
  14650. len = info->len; //this is the base len without details
  14651. if(!len) return; //version as packet disable
  14652. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14653. szdetails = 7;
  14654. factor = 1;
  14655. }
  14656. else if (cmd == 0x097b) {
  14657. tot_baseexp *= factor;
  14658. tot_drop *= factor;
  14659. tot_penalty *= factor;
  14660. }
  14661. fd = sd->fd;
  14662. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14663. WFIFOW(fd,0) = cmd;
  14664. for (i = 0; i < maxinfotype; i++) {
  14665. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14666. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14667. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14668. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14669. tot_baseexp += details_bexp[i]*factor;
  14670. tot_drop += details_penalty[i]*factor;
  14671. tot_penalty += details_drop[i]*factor;
  14672. len += szdetails;
  14673. }
  14674. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14675. if (cmd == 0x08cb) { //0x08cb version
  14676. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14677. WFIFOW(fd,info->pos[2]) = tot_drop;
  14678. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14679. }
  14680. else { //2013-08-07aRagexe uses 0x097b
  14681. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14682. WFIFOL(fd,info->pos[2]) = tot_drop;
  14683. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14684. }
  14685. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14686. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14687. WFIFOSET(fd,len);
  14688. }
  14689. }
  14690. #endif
  14691. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14692. char cmd[30];
  14693. int t_aid = RFIFOL(fd,2);
  14694. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14695. is_atcommand(fd, sd, cmd, 1);
  14696. }
  14697. /**
  14698. * Marks Crimson Marker target on mini-map to the caster
  14699. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  14700. * @param fd
  14701. * @param bl Crimson Marker target
  14702. **/
  14703. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  14704. struct s_packet_db* info;
  14705. int cmd = 0;
  14706. int16 len;
  14707. unsigned char buf[11];
  14708. nullpo_retv(sd);
  14709. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  14710. if (!cmd)
  14711. cmd = 0x09C1; //default
  14712. info = &packet_db[sd->packet_ver][cmd];
  14713. if (!(len = info->len))
  14714. return;
  14715. WBUFW(buf, 0) = cmd;
  14716. WBUFL(buf, info->pos[0]) = bl->id;
  14717. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  14718. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  14719. clif_send(buf, len, &sd->bl, SELF);
  14720. }
  14721. /// [Ind/Hercules]
  14722. void clif_showscript(struct block_list* bl, const char* message) {
  14723. char buf[256];
  14724. size_t len;
  14725. nullpo_retv(bl);
  14726. if(!message)
  14727. return;
  14728. len = strlen(message)+1;
  14729. if( len > sizeof(buf)-8 ) {
  14730. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  14731. len = sizeof(buf)-8;
  14732. }
  14733. WBUFW(buf,0) = 0x8b3;
  14734. WBUFW(buf,2) = (len+8);
  14735. WBUFL(buf,4) = bl->id;
  14736. safestrncpy((char *) WBUFP(buf,8), message, len);
  14737. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  14738. }
  14739. /// [Ind/Hercules]
  14740. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  14741. unsigned char buf[10];
  14742. nullpo_retv(sd);
  14743. WBUFW(buf,0) = 0x7fc;
  14744. WBUFL(buf,2) = prev_leader_aid;
  14745. WBUFL(buf,6) = new_leader_aid;
  14746. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  14747. }
  14748. /**
  14749. * !TODO: Special item that obtained, must be broadcasted by this packet
  14750. * 07fd ?? (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  14751. */
  14752. //void clif_broadcast_obtain_special_item() {}
  14753. #ifdef DUMP_UNKNOWN_PACKET
  14754. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  14755. {
  14756. const char* packet_txt = "save/packet.txt";
  14757. FILE* fp;
  14758. time_t time_server;
  14759. struct tm *datetime;
  14760. char datestr[512];
  14761. time(&time_server); // get time in seconds since 1/1/1970
  14762. datetime = localtime(&time_server); // convert seconds in structure
  14763. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14764. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14765. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14766. if( sd ) {
  14767. 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);
  14768. } else {
  14769. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14770. }
  14771. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14772. fprintf(fp, "\n");
  14773. fclose(fp);
  14774. } else {
  14775. ShowError("Failed to write '%s'.\n", packet_txt);
  14776. // Dump on console instead
  14777. if( sd ) {
  14778. 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);
  14779. } else {
  14780. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14781. }
  14782. ShowDump(RFIFOP(fd,0), packet_len);
  14783. }
  14784. }
  14785. #endif
  14786. /*==========================================
  14787. * Main client packet processing function
  14788. *------------------------------------------*/
  14789. static int clif_parse(int fd)
  14790. {
  14791. int cmd, packet_ver, packet_len, err;
  14792. TBL_PC* sd;
  14793. int pnum;
  14794. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14795. // Note: "click masters" can do 80+ clicks in 10 seconds
  14796. 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]
  14797. { // begin main client packet processing loop
  14798. sd = (TBL_PC *)session[fd]->session_data;
  14799. if (session[fd]->flag.eof) {
  14800. if (sd) {
  14801. if (sd->state.autotrade) {
  14802. //Disassociate character from the socket connection.
  14803. session[fd]->session_data = NULL;
  14804. sd->fd = 0;
  14805. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14806. } else
  14807. if (sd->state.active) {
  14808. // Player logout display [Valaris]
  14809. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14810. clif_quitsave(fd, sd);
  14811. } else {
  14812. //Unusual logout (during log on/off/map-changer procedure)
  14813. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14814. map_quit(sd);
  14815. }
  14816. } else {
  14817. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14818. }
  14819. do_close(fd);
  14820. return 0;
  14821. }
  14822. if (RFIFOREST(fd) < 2)
  14823. return 0;
  14824. cmd = RFIFOW(fd,0);
  14825. // identify client's packet version
  14826. if (sd) {
  14827. packet_ver = sd->packet_ver;
  14828. } else {
  14829. // check authentification packet to know packet version
  14830. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14831. if( err ) {// failed to identify packet version
  14832. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14833. err == 1 ? "" :
  14834. err == 2 ? ", possibly for having an invalid account_id" :
  14835. err == 3 ? ", possibly for having an invalid char_id." :
  14836. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14837. err == 4 ? ", possibly for having an invalid login_id1." :
  14838. err == 5 ? ", possibly for having an invalid client_tick." :
  14839. */
  14840. err == 6 ? ", possibly for having an invalid sex." :
  14841. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14842. WFIFOHEAD(fd,packet_len(0x6a));
  14843. WFIFOW(fd,0) = 0x6a;
  14844. WFIFOB(fd,2) = 3; // Rejected from Server
  14845. WFIFOSET(fd,packet_len(0x6a));
  14846. #ifdef DUMP_INVALID_PACKET
  14847. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14848. #endif
  14849. RFIFOSKIP(fd, RFIFOREST(fd));
  14850. set_eof(fd);
  14851. return 0;
  14852. }
  14853. }
  14854. // filter out invalid / unsupported packets
  14855. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14856. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14857. #ifdef DUMP_INVALID_PACKET
  14858. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14859. #endif
  14860. set_eof(fd);
  14861. return 0;
  14862. }
  14863. // determine real packet length
  14864. packet_len = packet_db[packet_ver][cmd].len;
  14865. if (packet_len == -1) { // variable-length packet
  14866. if (RFIFOREST(fd) < 4)
  14867. return 0;
  14868. packet_len = RFIFOW(fd,2);
  14869. if (packet_len < 4 || packet_len > 32768) {
  14870. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14871. #ifdef DUMP_INVALID_PACKET
  14872. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14873. #endif
  14874. set_eof(fd);
  14875. return 0;
  14876. }
  14877. }
  14878. if ((int)RFIFOREST(fd) < packet_len)
  14879. return 0; // not enough data received to form the packet
  14880. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14881. packet_db[packet_ver][cmd].func(fd, sd);
  14882. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14883. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14884. ; //Only valid packet when there is no session
  14885. else
  14886. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14887. ; //Only valid packet when player is not on a map
  14888. else
  14889. packet_db[packet_ver][cmd].func(fd, sd);
  14890. }
  14891. #ifdef DUMP_UNKNOWN_PACKET
  14892. else DumpUnknown(fd,sd,cmd,packet_len);
  14893. #endif
  14894. RFIFOSKIP(fd, packet_len);
  14895. }; // main loop end
  14896. return 0;
  14897. }
  14898. /*==========================================
  14899. * Reads packet_db.txt and setups its array reference
  14900. *------------------------------------------*/
  14901. void packetdb_readdb(void)
  14902. {
  14903. char line[1024];
  14904. int cmd,i,j;
  14905. int max_cmd=-1;
  14906. bool skip_ver = false;
  14907. int warned = 0;
  14908. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14909. int packet_len_table[MAX_PACKET_DB] = {
  14910. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14914. //#0x0040
  14915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14917. #if PACKETVER <= 20081217
  14918. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14919. #else
  14920. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14921. #endif
  14922. #if PACKETVER < 2
  14923. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14924. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14925. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14926. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14927. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14928. #else
  14929. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14930. #endif
  14931. //#0x0080
  14932. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14933. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14934. #if PACKETVER <= 20100622
  14935. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14936. #else
  14937. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14938. #endif
  14939. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14940. //#0x00C0
  14941. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14942. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14943. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14944. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14945. //#0x0100
  14946. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14947. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14948. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14949. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14950. //#0x0140
  14951. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14952. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14953. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14954. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14955. //#0x0180
  14956. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14957. #if PACKETVER < 1
  14958. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14959. #else // 196 comodo icon status display for later
  14960. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14961. #endif
  14962. #if PACKETVER < 20081126
  14963. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14964. #else // 0x1a2 changed (35->37)
  14965. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14966. #endif
  14967. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14968. //#0x01C0, Set 0x1d5=-1
  14969. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14970. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14971. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14972. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14973. //#0x0200
  14974. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14975. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14976. #if PACKETVER < 20071106
  14977. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14978. #else // 0x22c changed
  14979. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14980. #endif
  14981. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14982. //#0x0240
  14983. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14984. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14985. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14986. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14987. //#0x0280
  14988. #if PACKETVER < 20070711
  14989. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14990. #else
  14991. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14992. #endif
  14993. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14994. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14995. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14996. //#0x02C0
  14997. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14998. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14999. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  15000. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15001. //#0x0300
  15002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15006. //#0x0340
  15007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15011. //#0x0380
  15012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15016. //#0x03C0
  15017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15021. //#0x0400
  15022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  15026. //#0x0440
  15027. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  15028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15031. //#0x0480
  15032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x04C0
  15037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0500
  15042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 25,
  15046. //#0x0540
  15047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0580
  15052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x05C0
  15057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15061. //#0x0600
  15062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 25,
  15066. //#0x0640
  15067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0680
  15072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x06C0
  15077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0700
  15082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 25,
  15086. //#0x0740
  15087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0780
  15092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x07C0
  15097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15098. #if PACKETVER < 20090617
  15099. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15100. #else // 0x7d9 changed
  15101. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15102. #endif
  15103. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15104. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  15105. //#0x0800
  15106. #if PACKETVER < 20091229
  15107. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15108. #else // for Party booking ( PACKETVER >= 20091229 )
  15109. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15110. #endif
  15111. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15112. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15113. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15114. //#0x0840
  15115. #if PACKETVER < 20130000
  15116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15117. #else
  15118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15119. #endif
  15120. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 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. //#0x0880
  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, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15128. //#0x08C0
  15129. 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10,
  15130. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15133. //#0x0900
  15134. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15138. //#0x0940
  15139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15142. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15143. //#0x0980
  15144. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15145. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  15146. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15147. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15148. //#0x09C0
  15149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  15150. 0, 0, 0, 0, 2, 0, -1, 0, 2, 0, 0, 0, 0, 0, 0, 7,
  15151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15153. };
  15154. struct {
  15155. void (*func)(int, struct map_session_data *);
  15156. char *name;
  15157. } clif_parse_func[]={
  15158. {clif_parse_WantToConnection,"wanttoconnection"},
  15159. {clif_parse_LoadEndAck,"loadendack"},
  15160. {clif_parse_TickSend,"ticksend"},
  15161. {clif_parse_WalkToXY,"walktoxy"},
  15162. {clif_parse_QuitGame,"quitgame"},
  15163. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15164. {clif_parse_GlobalMessage,"globalmessage"},
  15165. {clif_parse_MapMove,"mapmove"},
  15166. {clif_parse_ChangeDir,"changedir"},
  15167. {clif_parse_Emotion,"emotion"},
  15168. {clif_parse_HowManyConnections,"howmanyconnections"},
  15169. {clif_parse_ActionRequest,"actionrequest"},
  15170. {clif_parse_Restart,"restart"},
  15171. {clif_parse_WisMessage,"wis"},
  15172. {clif_parse_Broadcast,"broadcast"},
  15173. {clif_parse_TakeItem,"takeitem"},
  15174. {clif_parse_DropItem,"dropitem"},
  15175. {clif_parse_UseItem,"useitem"},
  15176. {clif_parse_EquipItem,"equipitem"},
  15177. {clif_parse_UnequipItem,"unequipitem"},
  15178. {clif_parse_NpcClicked,"npcclicked"},
  15179. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15180. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15181. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15182. {clif_parse_CreateChatRoom,"createchatroom"},
  15183. {clif_parse_ChatAddMember,"chataddmember"},
  15184. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15185. {clif_parse_ChangeChatOwner,"changechatowner"},
  15186. {clif_parse_KickFromChat,"kickfromchat"},
  15187. {clif_parse_ChatLeave,"chatleave"},
  15188. {clif_parse_TradeRequest,"traderequest"},
  15189. {clif_parse_TradeAck,"tradeack"},
  15190. {clif_parse_TradeAddItem,"tradeadditem"},
  15191. {clif_parse_TradeOk,"tradeok"},
  15192. {clif_parse_TradeCancel,"tradecancel"},
  15193. {clif_parse_TradeCommit,"tradecommit"},
  15194. {clif_parse_StopAttack,"stopattack"},
  15195. {clif_parse_PutItemToCart,"putitemtocart"},
  15196. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15197. {clif_parse_RemoveOption,"removeoption"},
  15198. {clif_parse_ChangeCart,"changecart"},
  15199. {clif_parse_StatusUp,"statusup"},
  15200. {clif_parse_SkillUp,"skillup"},
  15201. {clif_parse_UseSkillToId,"useskilltoid"},
  15202. {clif_parse_UseSkillToPos,"useskilltopos"},
  15203. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15204. {clif_parse_UseSkillMap,"useskillmap"},
  15205. {clif_parse_RequestMemo,"requestmemo"},
  15206. {clif_parse_ProduceMix,"producemix"},
  15207. {clif_parse_Cooking,"cooking"},
  15208. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15209. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15210. {clif_parse_NpcAmountInput,"npcamountinput"},
  15211. {clif_parse_NpcStringInput,"npcstringinput"},
  15212. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15213. {clif_parse_ItemIdentify,"itemidentify"},
  15214. {clif_parse_SelectArrow,"selectarrow"},
  15215. {clif_parse_AutoSpell,"autospell"},
  15216. {clif_parse_UseCard,"usecard"},
  15217. {clif_parse_InsertCard,"insertcard"},
  15218. {clif_parse_RepairItem,"repairitem"},
  15219. {clif_parse_WeaponRefine,"weaponrefine"},
  15220. {clif_parse_SolveCharName,"solvecharname"},
  15221. {clif_parse_ResetChar,"resetchar"},
  15222. {clif_parse_LocalBroadcast,"localbroadcast"},
  15223. {clif_parse_MoveToKafra,"movetokafra"},
  15224. {clif_parse_MoveFromKafra,"movefromkafra"},
  15225. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15226. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15227. {clif_parse_CloseKafra,"closekafra"},
  15228. {clif_parse_CreateParty,"createparty"},
  15229. {clif_parse_CreateParty2,"createparty2"},
  15230. {clif_parse_PartyInvite,"partyinvite"},
  15231. {clif_parse_PartyInvite2,"partyinvite2"},
  15232. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15233. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15234. {clif_parse_LeaveParty,"leaveparty"},
  15235. {clif_parse_RemovePartyMember,"removepartymember"},
  15236. {clif_parse_PartyChangeOption,"partychangeoption"},
  15237. {clif_parse_PartyMessage,"partymessage"},
  15238. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15239. {clif_parse_CloseVending,"closevending"},
  15240. {clif_parse_VendingListReq,"vendinglistreq"},
  15241. {clif_parse_PurchaseReq,"purchasereq"},
  15242. {clif_parse_PurchaseReq2,"purchasereq2"},
  15243. {clif_parse_OpenVending,"openvending"},
  15244. {clif_parse_CreateGuild,"createguild"},
  15245. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15246. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15247. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15248. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15249. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15250. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15251. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15252. {clif_parse_GuildInvite,"guildinvite"},
  15253. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15254. {clif_parse_GuildLeave,"guildleave"},
  15255. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15256. {clif_parse_GuildMessage,"guildmessage"},
  15257. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15258. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15259. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15260. {clif_parse_GuildOpposition,"guildopposition"},
  15261. {clif_parse_GuildBreak,"guildbreak"},
  15262. {clif_parse_PetMenu,"petmenu"},
  15263. {clif_parse_CatchPet,"catchpet"},
  15264. {clif_parse_SelectEgg,"selectegg"},
  15265. {clif_parse_SendEmotion,"sendemotion"},
  15266. {clif_parse_ChangePetName,"changepetname"},
  15267. {clif_parse_GMKick,"gmkick"},
  15268. {clif_parse_GMHide,"gmhide"},
  15269. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15270. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15271. {clif_parse_GMKickAll,"killall"},
  15272. {clif_parse_GMRecall,"recall"},
  15273. {clif_parse_GMRecall,"summon"},
  15274. {clif_parse_GM_Item_Monster,"itemmonster"},
  15275. {clif_parse_GMShift,"remove"},
  15276. {clif_parse_GMShift,"shift"},
  15277. {clif_parse_GMChangeMapType,"changemaptype"},
  15278. {clif_parse_GMRc,"rc"},
  15279. {clif_parse_GMRecall2,"recall2"},
  15280. {clif_parse_GMRemove2,"remove2"},
  15281. {clif_parse_GMFullStrip,"gmfullstrip"},
  15282. {clif_parse_NoviceDoriDori,"sndoridori"},
  15283. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15284. {clif_parse_PMIgnore,"wisexin"},
  15285. {clif_parse_PMIgnoreList,"wisexlist"},
  15286. {clif_parse_PMIgnoreAll,"wisall"},
  15287. {clif_parse_FriendsListAdd,"friendslistadd"},
  15288. {clif_parse_FriendsListRemove,"friendslistremove"},
  15289. {clif_parse_FriendsListReply,"friendslistreply"},
  15290. {clif_parse_Blacksmith,"blacksmith"},
  15291. {clif_parse_Alchemist,"alchemist"},
  15292. {clif_parse_Taekwon,"taekwon"},
  15293. {clif_parse_RankingPk,"rankingpk"},
  15294. {clif_parse_FeelSaveOk,"feelsaveok"},
  15295. {clif_parse_debug,"debug"},
  15296. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15297. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15298. {clif_parse_HomMoveTo,"hommoveto"},
  15299. {clif_parse_HomAttack,"homattack"},
  15300. {clif_parse_HomMenu,"hommenu"},
  15301. {clif_parse_StoragePassword,"storagepassword"},
  15302. {clif_parse_Hotkey,"hotkey"},
  15303. {clif_parse_AutoRevive,"autorevive"},
  15304. {clif_parse_Check,"check"},
  15305. {clif_parse_Adopt_request,"adoptrequest"},
  15306. {clif_parse_Adopt_reply,"adoptreply"},
  15307. // MAIL SYSTEM
  15308. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15309. {clif_parse_Mail_read,"mailread"},
  15310. {clif_parse_Mail_getattach,"mailgetattach"},
  15311. {clif_parse_Mail_delete,"maildelete"},
  15312. {clif_parse_Mail_return,"mailreturn"},
  15313. {clif_parse_Mail_setattach,"mailsetattach"},
  15314. {clif_parse_Mail_winopen,"mailwinopen"},
  15315. {clif_parse_Mail_send,"mailsend"},
  15316. // AUCTION SYSTEM
  15317. {clif_parse_Auction_search,"auctionsearch"},
  15318. {clif_parse_Auction_buysell,"auctionbuysell"},
  15319. {clif_parse_Auction_setitem,"auctionsetitem"},
  15320. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15321. {clif_parse_Auction_register,"auctionregister"},
  15322. {clif_parse_Auction_cancel,"auctioncancel"},
  15323. {clif_parse_Auction_close,"auctionclose"},
  15324. {clif_parse_Auction_bid,"auctionbid"},
  15325. // Quest Log System
  15326. {clif_parse_questStateAck,"queststate"},
  15327. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15328. {clif_parse_EquipTick,"equiptickbox"},
  15329. {clif_parse_BattleChat,"battlechat"},
  15330. {clif_parse_mercenary_action,"mermenu"},
  15331. {clif_parse_progressbar,"progressbar"},
  15332. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15333. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15334. #if PACKETVER >= 20091229
  15335. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15336. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15337. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15338. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15339. #endif
  15340. {clif_parse_BankCheck,"bankcheck"},
  15341. {clif_parse_BankDeposit,"bankdeposit"},
  15342. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15343. {clif_parse_BankOpen,"bankopen"},
  15344. {clif_parse_BankClose,"bankclose"},
  15345. {clif_parse_PVPInfo,"pvpinfo"},
  15346. {clif_parse_LessEffect,"lesseffect"},
  15347. // Buying Store
  15348. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15349. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15350. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15351. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15352. // Store Search
  15353. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15354. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15355. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15356. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15357. // Cashshop
  15358. { clif_parse_cashshop_open_request, "cashshopopen" },
  15359. { clif_parse_cashshop_close, "cashshopclose" },
  15360. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15361. { clif_parse_cashshop_buy, "cashshopbuy" },
  15362. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15363. /* */
  15364. { clif_parse_MoveItem , "moveitem" },
  15365. { clif_parse_PartyTick, "partytick" },
  15366. { clif_parse_dull, "dull" },
  15367. { clif_parse_GuildInvite2 , "guildinvite2" },
  15368. { clif_parse_reqworldinfo, "reqworldinfo"},
  15369. { clif_parse_client_version, "clientversion"},
  15370. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15371. { clif_parse_ranklist, "ranklist"},
  15372. {NULL,NULL}
  15373. };
  15374. struct {
  15375. char *name; //function name
  15376. int funcidx; //
  15377. } clif_ack_func[]={ //hash
  15378. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15379. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15380. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15381. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15382. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15383. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15384. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15385. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15386. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  15387. };
  15388. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15389. int f;
  15390. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15391. memset(packet_db,0,sizeof(packet_db));
  15392. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15393. packet_len(i) = packet_len_table[i];
  15394. clif_config.packet_db_ver = MAX_PACKET_VER;
  15395. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  15396. FILE *fp;
  15397. int ln = 0;
  15398. int entries = 0;
  15399. char *str[64], *p, *str2[64], *p2;
  15400. sprintf(line, "%s/%s", db_path, filename[f]);
  15401. if( (fp = fopen(line,"r")) == NULL ) {
  15402. if (f == 0) {
  15403. ShowFatalError("Can't read %s\n", line);
  15404. exit(EXIT_FAILURE);
  15405. }
  15406. return;
  15407. }
  15408. while( fgets(line, sizeof(line), fp) ) {
  15409. char w1[256],w2[256];
  15410. ln++;
  15411. if(line[0]=='/' && line[1]=='/')
  15412. continue;
  15413. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  15414. if (strcmpi(w1,"packet_ver") == 0) {
  15415. int prev_ver = packet_ver;
  15416. skip_ver = false;
  15417. packet_ver = atoi(w2);
  15418. if ( packet_ver > MAX_PACKET_VER )
  15419. { //Check to avoid overflowing. [Skotlex]
  15420. if( (warned&1) == 0 )
  15421. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15422. warned &= 1;
  15423. skip_ver = true;
  15424. }
  15425. else if( packet_ver < 0 )
  15426. {
  15427. if( (warned&2) == 0 )
  15428. ShowWarning("Negative packet versions are not supported.\n");
  15429. warned &= 2;
  15430. skip_ver = true;
  15431. }
  15432. else if( packet_ver == SERVER )
  15433. {
  15434. if( (warned&4) == 0 )
  15435. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15436. warned &= 4;
  15437. skip_ver = true;
  15438. }
  15439. if( skip_ver )
  15440. {
  15441. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15442. packet_ver = prev_ver;
  15443. continue;
  15444. }
  15445. // copy from previous version into new version and continue
  15446. // - indicating all following packets should be read into the newer version
  15447. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15448. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15449. continue;
  15450. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15451. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  15452. clif_config.packet_db_ver = MAX_PACKET_VER;
  15453. else // to manually set the packet DB version
  15454. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15455. continue;
  15456. }
  15457. }
  15458. if( skip_ver )
  15459. continue; // Skipping current packet version
  15460. memset(str,0,sizeof(str));
  15461. for (j = 0, p = line; j < 4 && p; ++j) {
  15462. str[j] = p;
  15463. p = strchr(p,',');
  15464. if (p)
  15465. *p++=0;
  15466. }
  15467. if (str[0] == NULL)
  15468. continue;
  15469. cmd = strtol(str[0],(char **)NULL,0);
  15470. if(max_cmd < cmd)
  15471. max_cmd = cmd;
  15472. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15473. continue;
  15474. if(str[1]==NULL){
  15475. ShowError("packet_db: packet len error\n");
  15476. continue;
  15477. }
  15478. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15479. if(str[2]==NULL){
  15480. packet_db[packet_ver][cmd].func = NULL;
  15481. ln++;
  15482. continue;
  15483. }
  15484. // look up processing function by name
  15485. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15486. if( j < ARRAYLENGTH(clif_parse_func) )
  15487. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15488. else { //search if it's a mapped ack func
  15489. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15490. if( j < ARRAYLENGTH(clif_ack_func)) {
  15491. int fidx = clif_ack_func[j].funcidx;
  15492. packet_db_ack[packet_ver][fidx] = cmd;
  15493. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15494. }
  15495. }
  15496. // set the identifying cmd for the packet_db version
  15497. if (strcmp(str[2],"wanttoconnection")==0)
  15498. clif_config.connect_cmd[packet_ver] = cmd;
  15499. if(str[3]==NULL){
  15500. ShowError("packet_db: packet error\n");
  15501. exit(EXIT_FAILURE);
  15502. }
  15503. for(j = 0, p2 = str[3]; p2; j++){
  15504. short k;
  15505. str2[j] = p2;
  15506. p2 = strchr(p2,':');
  15507. if(p2)
  15508. *p2++=0;
  15509. k = atoi(str2[j]);
  15510. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15511. if( j >= MAX_PACKET_POS )
  15512. {
  15513. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15514. break;
  15515. }
  15516. packet_db[packet_ver][cmd].pos[j] = k;
  15517. }
  15518. entries++;
  15519. }
  15520. fclose(fp);
  15521. if(max_cmd > MAX_PACKET_DB) {
  15522. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15523. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15524. }
  15525. //Locate the nearest version that we still support. [Skotlex]
  15526. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  15527. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15528. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15529. }
  15530. sprintf(line, "%s/%s", db_path,filename[f]);
  15531. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  15532. }
  15533. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15534. }
  15535. /*==========================================
  15536. *
  15537. *------------------------------------------*/
  15538. void do_init_clif(void) {
  15539. const char* colors[COLOR_MAX] = {
  15540. "0xFF0000",
  15541. "0xFFFFFF",
  15542. "0xFFFF00",
  15543. };
  15544. int i;
  15545. /**
  15546. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15547. **/
  15548. for(i = 0; i < COLOR_MAX; i++) {
  15549. color_table[i] = strtoul(colors[i],NULL,0);
  15550. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15551. }
  15552. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15553. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15554. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15555. packetdb_readdb();
  15556. set_defaultparse(clif_parse);
  15557. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15558. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15559. exit(EXIT_FAILURE);
  15560. }
  15561. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15562. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15563. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15564. }
  15565. void do_final_clif(void) {
  15566. ers_destroy(delay_clearunit_ers);
  15567. }