clif.c 445 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/grfio.h"
  7. #include "../common/malloc.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/random.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "map.h"
  14. #include "chrif.h"
  15. #include "pc.h"
  16. #include "status.h"
  17. #include "npc.h"
  18. #include "itemdb.h"
  19. #include "chat.h"
  20. #include "trade.h"
  21. #include "storage.h"
  22. #include "script.h"
  23. #include "skill.h"
  24. #include "atcommand.h"
  25. #include "intif.h"
  26. #include "battle.h"
  27. #include "battleground.h"
  28. #include "mob.h"
  29. #include "party.h"
  30. #include "unit.h"
  31. #include "guild.h"
  32. #include "vending.h"
  33. #include "pet.h"
  34. #include "homunculus.h"
  35. #include "instance.h"
  36. #include "mercenary.h"
  37. #include "log.h"
  38. #include "clif.h"
  39. #include "mail.h"
  40. #include "quest.h"
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <stdarg.h>
  45. #include <time.h>
  46. //#define DUMP_UNKNOWN_PACKET
  47. //#define DUMP_INVALID_PACKET
  48. struct Clif_Config {
  49. int packet_db_ver; //Preferred packet version.
  50. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  51. } clif_config;
  52. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  53. //Converts item type in case of pet eggs.
  54. static inline int itemtype(int type)
  55. {
  56. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  57. }
  58. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
  59. {
  60. p += pos;
  61. p[0] = (uint8)(x>>2);
  62. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  63. p[2] = (uint8)((y<<4) | (dir&0xf));
  64. }
  65. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  66. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  67. {
  68. p += pos;
  69. p[0] = (uint8)(x0>>2);
  70. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  71. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  72. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  73. p[4] = (uint8)y1;
  74. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  75. }
  76. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir)
  77. {
  78. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  79. }
  80. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  81. {
  82. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  83. }
  84. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir)
  85. {
  86. p += pos;
  87. if( x )
  88. {
  89. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  90. }
  91. if( y )
  92. {
  93. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  94. }
  95. if( dir )
  96. {
  97. dir[0] = ( p[2] & 0x0f );
  98. }
  99. }
  100. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  101. {
  102. p += pos;
  103. if( x0 )
  104. {
  105. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  106. }
  107. if( y0 )
  108. {
  109. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  110. }
  111. if( x1 )
  112. {
  113. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  114. }
  115. if( y1 )
  116. {
  117. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  118. }
  119. if( sx0 )
  120. {
  121. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  122. }
  123. if( sy0 )
  124. {
  125. sy0[0] = ( p[5] & 0x0f ) >> 0;
  126. }
  127. }
  128. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir)
  129. {
  130. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  131. }
  132. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  133. {
  134. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  135. }
  136. //To idenfity disguised characters.
  137. static inline bool disguised(struct block_list* bl)
  138. {
  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. {
  144. if( len > max )
  145. len = max;
  146. mes[len-1] = '\0';
  147. return len;
  148. }
  149. static char map_ip_str[128];
  150. static uint32 map_ip;
  151. static uint32 bind_ip = INADDR_ANY;
  152. static uint16 map_port = 5121;
  153. int map_fd;
  154. static int clif_parse (int fd);
  155. /*==========================================
  156. * map鯖のip設定
  157. *------------------------------------------*/
  158. int clif_setip(const char* ip)
  159. {
  160. char ip_str[16];
  161. map_ip = host2ip(ip);
  162. if (!map_ip) {
  163. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  164. return 0;
  165. }
  166. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  167. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  168. return 1;
  169. }
  170. void clif_setbindip(const char* ip)
  171. {
  172. char ip_str[16];
  173. bind_ip = host2ip(ip);
  174. if (bind_ip) {
  175. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  176. } else {
  177. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  178. }
  179. }
  180. /*==========================================
  181. * Sets map port to 'port'
  182. * is run from map.c upon loading map server configuration
  183. *------------------------------------------*/
  184. void clif_setport(uint16 port)
  185. {
  186. map_port = port;
  187. }
  188. /*==========================================
  189. * Returns map server IP
  190. *------------------------------------------*/
  191. uint32 clif_getip(void)
  192. {
  193. return map_ip;
  194. }
  195. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  196. uint32 clif_refresh_ip(void)
  197. {
  198. uint32 new_ip;
  199. new_ip = host2ip(map_ip_str);
  200. if (new_ip && new_ip != map_ip) {
  201. map_ip = new_ip;
  202. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  203. return map_ip;
  204. }
  205. return 0;
  206. }
  207. /*==========================================
  208. * Returns map port which is set by clif_setport()
  209. *------------------------------------------*/
  210. uint16 clif_getport(void)
  211. {
  212. return map_port;
  213. }
  214. static inline unsigned char clif_bl_type(struct block_list *bl) {
  215. switch (bl->type) {
  216. case BL_PC: return disguised(bl)?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 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. /*==========================================
  230. * sub process of clif_send
  231. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  232. * In order to send area-wise packets, such as:
  233. * - AREA : everyone nearby your area
  234. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  235. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  236. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  237. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  238. *------------------------------------------*/
  239. static int clif_send_sub(struct block_list *bl, va_list ap)
  240. {
  241. struct block_list *src_bl;
  242. struct map_session_data *sd;
  243. unsigned char *buf;
  244. int len, type, fd;
  245. nullpo_ret(bl);
  246. nullpo_ret(sd = (struct map_session_data *)bl);
  247. fd = sd->fd;
  248. if (!fd) //Don't send to disconnected clients.
  249. return 0;
  250. buf = va_arg(ap,unsigned char*);
  251. len = va_arg(ap,int);
  252. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  253. type = va_arg(ap,int);
  254. switch(type)
  255. {
  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. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  267. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  268. return 0;
  269. }
  270. break;
  271. }
  272. if (session[fd] == NULL)
  273. return 0;
  274. WFIFOHEAD(fd, len);
  275. if (WFIFOP(fd,0) == buf) {
  276. ShowError("WARNING: Invalid use of clif_send function\n");
  277. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  278. ShowError(" Please correct your code.\n");
  279. // don't send to not move the pointer of the packet for next sessions in the loop
  280. //WFIFOSET(fd,0);//## TODO is this ok?
  281. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  282. return 0;
  283. }
  284. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  285. memcpy(WFIFOP(fd,0), buf, len);
  286. WFIFOSET(fd,len);
  287. }
  288. return 0;
  289. }
  290. /*==========================================
  291. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  292. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  293. *------------------------------------------*/
  294. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  295. {
  296. int i;
  297. struct map_session_data *sd, *tsd;
  298. struct party_data *p = NULL;
  299. struct guild *g = NULL;
  300. struct battleground_data *bg = NULL;
  301. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  302. struct s_mapiterator* iter;
  303. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  304. nullpo_ret(bl);
  305. sd = BL_CAST(BL_PC, bl);
  306. switch(type) {
  307. case ALL_CLIENT: //All player clients.
  308. iter = mapit_getallusers();
  309. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  310. {
  311. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  312. { // packet must exist for the client version
  313. WFIFOHEAD(tsd->fd, len);
  314. memcpy(WFIFOP(tsd->fd,0), buf, len);
  315. WFIFOSET(tsd->fd,len);
  316. }
  317. }
  318. mapit_free(iter);
  319. break;
  320. case ALL_SAMEMAP: //All players on the same map
  321. iter = mapit_getallusers();
  322. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  323. {
  324. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  325. { // packet must exist for the client version
  326. WFIFOHEAD(tsd->fd, len);
  327. memcpy(WFIFOP(tsd->fd,0), buf, len);
  328. WFIFOSET(tsd->fd,len);
  329. }
  330. }
  331. mapit_free(iter);
  332. break;
  333. case AREA:
  334. case AREA_WOSC:
  335. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  336. clif_send (buf, len, bl, SELF);
  337. case AREA_WOC:
  338. case AREA_WOS:
  339. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  340. BL_PC, buf, len, bl, type);
  341. break;
  342. case AREA_CHAT_WOC:
  343. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  344. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  345. break;
  346. case CHAT:
  347. case CHAT_WOS:
  348. {
  349. struct chat_data *cd;
  350. if (sd) {
  351. cd = (struct chat_data*)map_id2bl(sd->chatID);
  352. } else if (bl->type == BL_CHAT) {
  353. cd = (struct chat_data*)bl;
  354. } else break;
  355. if (cd == NULL)
  356. break;
  357. for(i = 0; i < cd->users; i++) {
  358. if (type == CHAT_WOS && cd->usersd[i] == sd)
  359. continue;
  360. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  361. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  362. {
  363. WFIFOHEAD(fd,len);
  364. memcpy(WFIFOP(fd,0), buf, len);
  365. WFIFOSET(fd,len);
  366. }
  367. }
  368. }
  369. }
  370. break;
  371. case CHAT_MAINCHAT: //[LuzZza]
  372. iter = mapit_getallusers();
  373. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  374. {
  375. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  376. { // packet must exist for the client version
  377. WFIFOHEAD(tsd->fd, len);
  378. memcpy(WFIFOP(tsd->fd,0), buf, len);
  379. WFIFOSET(tsd->fd,len);
  380. }
  381. }
  382. mapit_free(iter);
  383. break;
  384. case PARTY_AREA:
  385. case PARTY_AREA_WOS:
  386. x0 = bl->x - AREA_SIZE;
  387. y0 = bl->y - AREA_SIZE;
  388. x1 = bl->x + AREA_SIZE;
  389. y1 = bl->y + AREA_SIZE;
  390. case PARTY:
  391. case PARTY_WOS:
  392. case PARTY_SAMEMAP:
  393. case PARTY_SAMEMAP_WOS:
  394. if (sd && sd->status.party_id)
  395. p = party_search(sd->status.party_id);
  396. if (p) {
  397. for(i=0;i<MAX_PARTY;i++){
  398. if( (sd = p->data[i].sd) == NULL )
  399. continue;
  400. if( !(fd=sd->fd) )
  401. continue;
  402. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  403. continue;
  404. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  405. continue;
  406. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  407. continue;
  408. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  409. { // packet must exist for the client version
  410. WFIFOHEAD(fd,len);
  411. memcpy(WFIFOP(fd,0), buf, len);
  412. WFIFOSET(fd,len);
  413. }
  414. }
  415. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  416. break;
  417. iter = mapit_getallusers();
  418. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  419. {
  420. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  421. { // packet must exist for the client version
  422. WFIFOHEAD(tsd->fd, len);
  423. memcpy(WFIFOP(tsd->fd,0), buf, len);
  424. WFIFOSET(tsd->fd,len);
  425. }
  426. }
  427. mapit_free(iter);
  428. }
  429. break;
  430. case DUEL:
  431. case DUEL_WOS:
  432. if (!sd || !sd->duel_group) break; //Invalid usage.
  433. iter = mapit_getallusers();
  434. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  435. {
  436. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  437. continue;
  438. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  439. { // packet must exist for the client version
  440. WFIFOHEAD(tsd->fd, len);
  441. memcpy(WFIFOP(tsd->fd,0), buf, len);
  442. WFIFOSET(tsd->fd,len);
  443. }
  444. }
  445. mapit_free(iter);
  446. break;
  447. case SELF:
  448. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  449. WFIFOHEAD(fd,len);
  450. memcpy(WFIFOP(fd,0), buf, len);
  451. WFIFOSET(fd,len);
  452. }
  453. break;
  454. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  455. case GUILD_AREA:
  456. case GUILD_AREA_WOS:
  457. x0 = bl->x - AREA_SIZE;
  458. y0 = bl->y - AREA_SIZE;
  459. x1 = bl->x + AREA_SIZE;
  460. y1 = bl->y + AREA_SIZE;
  461. case GUILD_SAMEMAP:
  462. case GUILD_SAMEMAP_WOS:
  463. case GUILD:
  464. case GUILD_WOS:
  465. case GUILD_NOBG:
  466. if (sd && sd->status.guild_id)
  467. g = guild_search(sd->status.guild_id);
  468. if (g) {
  469. for(i = 0; i < g->max_member; i++) {
  470. if( (sd = g->member[i].sd) != NULL )
  471. {
  472. if( !(fd=sd->fd) )
  473. continue;
  474. if( type == GUILD_NOBG && sd->bg_id )
  475. continue;
  476. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  477. continue;
  478. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  479. continue;
  480. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  481. continue;
  482. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  483. { // packet must exist for the client version
  484. WFIFOHEAD(fd,len);
  485. memcpy(WFIFOP(fd,0), buf, len);
  486. WFIFOSET(fd,len);
  487. }
  488. }
  489. }
  490. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  491. break;
  492. iter = mapit_getallusers();
  493. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  494. {
  495. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  496. { // packet must exist for the client version
  497. WFIFOHEAD(tsd->fd, len);
  498. memcpy(WFIFOP(tsd->fd,0), buf, len);
  499. WFIFOSET(tsd->fd,len);
  500. }
  501. }
  502. mapit_free(iter);
  503. }
  504. break;
  505. case BG_AREA:
  506. case BG_AREA_WOS:
  507. x0 = bl->x - AREA_SIZE;
  508. y0 = bl->y - AREA_SIZE;
  509. x1 = bl->x + AREA_SIZE;
  510. y1 = bl->y + AREA_SIZE;
  511. case BG_SAMEMAP:
  512. case BG_SAMEMAP_WOS:
  513. case BG:
  514. case BG_WOS:
  515. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  516. {
  517. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  518. {
  519. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  520. continue;
  521. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  522. continue;
  523. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  524. continue;
  525. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  526. continue;
  527. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  528. { // packet must exist for the client version
  529. WFIFOHEAD(fd,len);
  530. memcpy(WFIFOP(fd,0), buf, len);
  531. WFIFOSET(fd,len);
  532. }
  533. }
  534. }
  535. break;
  536. default:
  537. ShowError("clif_send: Unrecognized type %d\n",type);
  538. return -1;
  539. }
  540. return 0;
  541. }
  542. /// Notifies the client, that it's connection attempt was accepted.
  543. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  544. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  545. void clif_authok(struct map_session_data *sd)
  546. {
  547. const int cmd = 0x2eb;
  548. int fd = sd->fd;
  549. WFIFOHEAD(fd,packet_len(cmd));
  550. WFIFOW(fd, 0) = cmd;
  551. WFIFOL(fd, 2) = gettick();
  552. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  553. WFIFOB(fd, 9) = 5; // ignored
  554. WFIFOB(fd,10) = 5; // ignored
  555. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  556. WFIFOSET(fd,packet_len(cmd));
  557. }
  558. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  559. /// 0074 <error code>.B
  560. /// error code:
  561. /// 0 = client type mismatch
  562. /// 1 = ID mismatch
  563. /// 2 = mobile - out of available time
  564. /// 3 = mobile - already logged in
  565. /// 4 = mobile - waiting state
  566. void clif_authrefuse(int fd, uint8 error_code)
  567. {
  568. WFIFOHEAD(fd,packet_len(0x74));
  569. WFIFOW(fd,0) = 0x74;
  570. WFIFOB(fd,2) = error_code;
  571. WFIFOSET(fd,packet_len(0x74));
  572. }
  573. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  574. /// 0081 <error code>.B
  575. /// error code:
  576. /// 0 = BAN_UNFAIR
  577. /// 1 = server closed -> MsgStringTable[4]
  578. /// 2 = ID already logged in -> MsgStringTable[5]
  579. /// 3 = timeout/too much lag -> MsgStringTable[241]
  580. /// 4 = server full -> MsgStringTable[264]
  581. /// 5 = underaged -> MsgStringTable[305]
  582. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  583. /// 9 = too many connections from this ip -> MsgStringTable[529]
  584. /// 10 = out of available time paid for -> MsgStringTable[530]
  585. /// 11 = BAN_PAY_SUSPEND
  586. /// 12 = BAN_PAY_CHANGE
  587. /// 13 = BAN_PAY_WRONGIP
  588. /// 14 = BAN_PAY_PNGAMEROOM
  589. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  590. /// 16 = BAN_JAPAN_REFUSE1
  591. /// 17 = BAN_JAPAN_REFUSE2
  592. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  593. /// 100 = BAN_PC_IP_UNFAIR
  594. /// 101 = BAN_PC_IP_COUNT_ALL
  595. /// 102 = BAN_PC_IP_COUNT
  596. /// 103 = BAN_GRAVITY_MEM_AGREE
  597. /// 104 = BAN_GAME_MEM_AGREE
  598. /// 105 = BAN_HAN_VALID
  599. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  600. /// 107 = BAN_OVER_CHARACTER_LIST
  601. /// 108 = BAN_IP_BLOCK
  602. /// 109 = BAN_INVALID_PWD_CNT
  603. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  604. /// ? = disconnected -> MsgStringTable[3]
  605. void clif_authfail_fd(int fd, int type)
  606. {
  607. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  608. return;
  609. WFIFOHEAD(fd, packet_len(0x81));
  610. WFIFOW(fd,0) = 0x81;
  611. WFIFOB(fd,2) = type;
  612. WFIFOSET(fd,packet_len(0x81));
  613. set_eof(fd);
  614. }
  615. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  616. /// 00b3 <type>.B
  617. /// type:
  618. /// 1 = disconnect, char-select
  619. /// ? = nothing
  620. void clif_charselectok(int id, uint8 ok)
  621. {
  622. struct map_session_data* sd;
  623. int fd;
  624. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  625. return;
  626. fd = sd->fd;
  627. WFIFOHEAD(fd,packet_len(0xb3));
  628. WFIFOW(fd,0) = 0xb3;
  629. WFIFOB(fd,2) = ok;
  630. WFIFOSET(fd,packet_len(0xb3));
  631. }
  632. /// Makes an item appear on the ground.
  633. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  634. /// 084b (ZC_ITEM_FALL_ENTRY4)
  635. void clif_dropflooritem(struct flooritem_data* fitem)
  636. {
  637. uint8 buf[17];
  638. int view;
  639. nullpo_retv(fitem);
  640. if (fitem->item_data.nameid <= 0)
  641. return;
  642. WBUFW(buf, 0) = 0x9e;
  643. WBUFL(buf, 2) = fitem->bl.id;
  644. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  645. WBUFB(buf, 8) = fitem->item_data.identify;
  646. WBUFW(buf, 9) = fitem->bl.x;
  647. WBUFW(buf,11) = fitem->bl.y;
  648. WBUFB(buf,13) = fitem->subx;
  649. WBUFB(buf,14) = fitem->suby;
  650. WBUFW(buf,15) = fitem->item_data.amount;
  651. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  652. }
  653. /// Makes an item disappear from the ground.
  654. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  655. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  656. {
  657. unsigned char buf[16];
  658. nullpo_retv(fitem);
  659. WBUFW(buf,0) = 0xa1;
  660. WBUFL(buf,2) = fitem->bl.id;
  661. if (fd == 0) {
  662. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  663. } else {
  664. WFIFOHEAD(fd,packet_len(0xa1));
  665. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  666. WFIFOSET(fd,packet_len(0xa1));
  667. }
  668. }
  669. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  670. /// 0080 <id>.L <type>.B
  671. /// type:
  672. /// 0 = out of sight
  673. /// 1 = died
  674. /// 2 = logged out
  675. /// 3 = teleport
  676. /// 4 = trickdead
  677. void clif_clearunit_single(int id, clr_type type, int fd)
  678. {
  679. WFIFOHEAD(fd, packet_len(0x80));
  680. WFIFOW(fd,0) = 0x80;
  681. WFIFOL(fd,2) = id;
  682. WFIFOB(fd,6) = type;
  683. WFIFOSET(fd, packet_len(0x80));
  684. }
  685. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  686. /// 0080 <id>.L <type>.B
  687. /// type:
  688. /// 0 = out of sight
  689. /// 1 = died
  690. /// 2 = logged out
  691. /// 3 = teleport
  692. /// 4 = trickdead
  693. void clif_clearunit_area(struct block_list* bl, clr_type type)
  694. {
  695. unsigned char buf[8];
  696. nullpo_retv(bl);
  697. WBUFW(buf,0) = 0x80;
  698. WBUFL(buf,2) = bl->id;
  699. WBUFB(buf,6) = type;
  700. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  701. if(disguised(bl)) {
  702. WBUFL(buf,2) = -bl->id;
  703. clif_send(buf, packet_len(0x80), bl, SELF);
  704. }
  705. }
  706. /// Used to make monsters with player-sprites disappear after dying
  707. /// like normal monsters, because the client does not remove those
  708. /// automatically.
  709. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  710. {
  711. struct block_list *bl = (struct block_list *)data;
  712. clif_clearunit_area(bl, (clr_type) id);
  713. aFree(bl);
  714. return 0;
  715. }
  716. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  717. {
  718. struct block_list *tbl;
  719. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  720. memcpy (tbl, bl, sizeof (struct block_list));
  721. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  722. }
  723. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  724. {
  725. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  726. {
  727. *rhand = *lhand = 0;
  728. return;
  729. }
  730. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  731. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  732. {
  733. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  734. if (id->view_id > 0)
  735. *rhand = id->view_id;
  736. else
  737. *rhand = id->nameid;
  738. } else
  739. *rhand = 0;
  740. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  741. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  742. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  743. {
  744. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  745. if (id->view_id > 0)
  746. *lhand = id->view_id;
  747. else
  748. *lhand = id->nameid;
  749. } else
  750. *lhand = 0;
  751. }
  752. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  753. static int clif_setlevel_sub(int lv)
  754. {
  755. if( lv < battle_config.max_lv )
  756. {
  757. ;
  758. }
  759. else if( lv < battle_config.aura_lv )
  760. {
  761. lv = battle_config.max_lv - 1;
  762. }
  763. else
  764. {
  765. lv = battle_config.max_lv;
  766. }
  767. return lv;
  768. }
  769. static int clif_setlevel(struct block_list* bl)
  770. {
  771. int lv = status_get_lv(bl);
  772. if( battle_config.client_limit_unit_lv&bl->type )
  773. return clif_setlevel_sub(lv);
  774. switch( bl->type )
  775. {
  776. case BL_NPC:
  777. case BL_PET:
  778. // npcs and pets do not have level
  779. return 0;
  780. }
  781. return lv;
  782. }
  783. /*==========================================
  784. * Prepares 'unit standing/spawning' packet
  785. *------------------------------------------*/
  786. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  787. {
  788. struct map_session_data* sd;
  789. struct status_change* sc = status_get_sc(bl);
  790. struct view_data* vd = status_get_viewdata(bl);
  791. unsigned char *buf = WBUFP(buffer,0);
  792. unsigned short offset = 0;
  793. const char *name;
  794. sd = BL_CAST(BL_PC, bl);
  795. #if PACKETVER < 20101124
  796. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  797. #else
  798. WBUFW(buf,0) = spawn?0x858:0x857;
  799. #endif
  800. #if PACKETVER >= 20091103
  801. name = status_get_name(bl);
  802. #if PACKETVER < 20110111
  803. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  804. #else
  805. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  806. #endif
  807. WBUFB(buf,4) = clif_bl_type(bl);
  808. offset+=3;
  809. buf = WBUFP(buffer,offset);
  810. #elif PACKETVER >= 20071106
  811. if (type) { //Non-player packets
  812. WBUFB(buf,2) = clif_bl_type(bl);
  813. offset++;
  814. buf = WBUFP(buffer,offset);
  815. }
  816. #endif
  817. WBUFL(buf, 2) = bl->id;
  818. WBUFW(buf, 6) = status_get_speed(bl);
  819. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  820. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  821. #if PACKETVER >= 20091103
  822. WBUFL(buf,12) = (sc)? sc->option : 0;
  823. offset+=2;
  824. buf = WBUFP(buffer,offset);
  825. #elif PACKETVER >= 7
  826. if (!type) {
  827. WBUFL(buf,12) = (sc)? sc->option : 0;
  828. offset+=2;
  829. buf = WBUFP(buffer,offset);
  830. } else
  831. WBUFW(buf,12) = (sc)? sc->option : 0;
  832. #else
  833. WBUFW(buf,12) = (sc)? sc->option : 0;
  834. #endif
  835. WBUFW(buf,14) = vd->class_;
  836. WBUFW(buf,16) = vd->hair_style;
  837. WBUFW(buf,18) = vd->weapon;
  838. WBUFW(buf,20) = vd->shield;
  839. WBUFW(buf,22) = vd->head_bottom;
  840. WBUFW(buf,24) = vd->head_top;
  841. WBUFW(buf,26) = vd->head_mid;
  842. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  843. { //The hell, why flags work like this?
  844. WBUFW(buf,22) = status_get_emblem_id(bl);
  845. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  846. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  847. }
  848. WBUFW(buf,28) = vd->hair_color;
  849. WBUFW(buf,30) = vd->cloth_color;
  850. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  851. #if PACKETVER >= 20110111
  852. WBUFW(buf,34) = vd->robe;
  853. offset+= 2;
  854. buf = WBUFP(buffer,offset);
  855. #endif
  856. WBUFL(buf,34) = status_get_guild_id(bl);
  857. WBUFW(buf,38) = status_get_emblem_id(bl);
  858. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  859. #if PACKETVER >= 20091103
  860. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  861. offset+=2;
  862. buf = WBUFP(buffer,offset);
  863. #elif PACKETVER >= 7
  864. if (!type) {
  865. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  866. offset+=2;
  867. buf = WBUFP(buffer,offset);
  868. } else
  869. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  870. #else
  871. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  872. #endif
  873. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  874. WBUFB(buf,45) = vd->sex;
  875. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  876. WBUFB(buf,49) = (sd)? 5 : 0;
  877. WBUFB(buf,50) = (sd)? 5 : 0;
  878. if (!spawn) {
  879. WBUFB(buf,51) = vd->dead_sit;
  880. offset++;
  881. buf = WBUFP(buffer,offset);
  882. }
  883. WBUFW(buf,51) = clif_setlevel(bl);
  884. WBUFW(buf,53) = sd?sd->user_font:0;
  885. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  886. return WBUFW(buffer,2);
  887. }
  888. /*==========================================
  889. * Prepares 'unit walking' packet
  890. *------------------------------------------*/
  891. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  892. {
  893. struct map_session_data* sd;
  894. struct status_change* sc = status_get_sc(bl);
  895. struct view_data* vd = status_get_viewdata(bl);
  896. unsigned char* buf = WBUFP(buffer,0);
  897. unsigned short offset = 0;
  898. const char *name;
  899. sd = BL_CAST(BL_PC, bl);
  900. #if PACKETVER < 20101124
  901. WBUFW(buf, 0) = 0x7f7;
  902. #else
  903. WBUFW(buf, 0) = 0x856;
  904. #endif
  905. name = status_get_name(bl);
  906. #if PACKETVER < 20110111
  907. WBUFW(buf, 2) = 69+strlen(name);
  908. #else
  909. WBUFW(buf, 2) = 71+strlen(name);
  910. #endif
  911. offset+=2;
  912. buf = WBUFP(buffer,offset);
  913. WBUFB(buf, 2) = clif_bl_type(bl);
  914. offset++;
  915. buf = WBUFP(buffer,offset);
  916. WBUFL(buf, 2) = bl->id;
  917. WBUFW(buf, 6) = status_get_speed(bl);
  918. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  919. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  920. WBUFL(buf,12) = (sc)? sc->option : 0;
  921. offset+=2; //Shift the rest of elements by 2 bytes.
  922. buf = WBUFP(buffer,offset);
  923. WBUFW(buf,14) = vd->class_;
  924. WBUFW(buf,16) = vd->hair_style;
  925. WBUFW(buf,18) = vd->weapon;
  926. WBUFW(buf,20) = vd->shield;
  927. WBUFW(buf,22) = vd->head_bottom;
  928. WBUFL(buf,24) = gettick();
  929. WBUFW(buf,28) = vd->head_top;
  930. WBUFW(buf,30) = vd->head_mid;
  931. WBUFW(buf,32) = vd->hair_color;
  932. WBUFW(buf,34) = vd->cloth_color;
  933. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  934. #if PACKETVER >= 20110111
  935. WBUFW(buf,38) = vd->robe;
  936. offset+= 2;
  937. buf = WBUFP(buffer,offset);
  938. #endif
  939. WBUFL(buf,38) = status_get_guild_id(bl);
  940. WBUFW(buf,42) = status_get_emblem_id(bl);
  941. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  942. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  943. offset+=2; //Shift the rest of elements by 2 bytes.
  944. buf = WBUFP(buffer,offset);
  945. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  946. WBUFB(buf,49) = vd->sex;
  947. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  948. WBUFB(buf,56) = (sd)? 5 : 0;
  949. WBUFB(buf,57) = (sd)? 5 : 0;
  950. WBUFW(buf,58) = clif_setlevel(bl);
  951. WBUFW(buf,60) = sd?sd->user_font:0;
  952. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  953. return WBUFW(buffer,2);
  954. }
  955. //Modifies the buffer for disguise characters and sends it to self.
  956. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  957. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  958. {
  959. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  960. WBUFL(buf,5)=-bl->id;
  961. clif_send(buf, len, bl, SELF);
  962. }
  963. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  964. /// 01b0 <id>.L <type>.B <value>.L
  965. /// type:
  966. /// unused
  967. void clif_class_change(struct block_list *bl,int class_,int type)
  968. {
  969. unsigned char buf[16];
  970. nullpo_retv(bl);
  971. if(!pcdb_checkid(class_))
  972. {// player classes yield missing sprites
  973. WBUFW(buf,0)=0x1b0;
  974. WBUFL(buf,2)=bl->id;
  975. WBUFB(buf,6)=type;
  976. WBUFL(buf,7)=class_;
  977. clif_send(buf,packet_len(0x1b0),bl,AREA);
  978. }
  979. }
  980. /// Notifies the client of an object's spirits.
  981. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  982. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  983. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  984. {
  985. WFIFOHEAD(fd, packet_len(0x1e1));
  986. WFIFOW(fd,0)=0x1e1;
  987. WFIFOL(fd,2)=sd->bl.id;
  988. WFIFOW(fd,6)=sd->spiritball;
  989. WFIFOSET(fd, packet_len(0x1e1));
  990. }
  991. /*==========================================
  992. * Run when player changes map / refreshes
  993. * Tells its client to display all weather settings being used by this map
  994. *------------------------------------------*/
  995. static void clif_weather_check(struct map_session_data *sd)
  996. {
  997. int m = sd->bl.m, fd = sd->fd;
  998. if (map[m].flag.snow
  999. || map[m].flag.clouds
  1000. || map[m].flag.fog
  1001. || map[m].flag.fireworks
  1002. || map[m].flag.sakura
  1003. || map[m].flag.leaves
  1004. /**
  1005. * No longer available, keeping here just in case it's back someday. [Ind]
  1006. **/
  1007. //|| map[m].flag.rain
  1008. || map[m].flag.clouds2)
  1009. {
  1010. if (map[m].flag.snow)
  1011. clif_specialeffect_single(&sd->bl, 162, fd);
  1012. if (map[m].flag.clouds)
  1013. clif_specialeffect_single(&sd->bl, 233, fd);
  1014. if (map[m].flag.clouds2)
  1015. clif_specialeffect_single(&sd->bl, 516, fd);
  1016. if (map[m].flag.fog)
  1017. clif_specialeffect_single(&sd->bl, 515, fd);
  1018. if (map[m].flag.fireworks) {
  1019. clif_specialeffect_single(&sd->bl, 297, fd);
  1020. clif_specialeffect_single(&sd->bl, 299, fd);
  1021. clif_specialeffect_single(&sd->bl, 301, fd);
  1022. }
  1023. if (map[m].flag.sakura)
  1024. clif_specialeffect_single(&sd->bl, 163, fd);
  1025. if (map[m].flag.leaves)
  1026. clif_specialeffect_single(&sd->bl, 333, fd);
  1027. /**
  1028. * No longer available, keeping here just in case it's back someday. [Ind]
  1029. **/
  1030. //if (map[m].flag.rain)
  1031. // clif_specialeffect_single(&sd->bl, 161, fd);
  1032. }
  1033. }
  1034. /**
  1035. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1036. **/
  1037. void clif_weather(int m)
  1038. {
  1039. struct s_mapiterator* iter;
  1040. struct map_session_data *sd=NULL;
  1041. iter = mapit_getallusers();
  1042. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1043. {
  1044. if( sd->bl.m == m )
  1045. clif_weather_check(sd);
  1046. }
  1047. mapit_free(iter);
  1048. }
  1049. /**
  1050. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1051. **/
  1052. int clif_spawn(struct block_list *bl)
  1053. {
  1054. unsigned char buf[128];
  1055. struct view_data *vd;
  1056. int len;
  1057. vd = status_get_viewdata(bl);
  1058. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1059. return 0;
  1060. /**
  1061. * Hide NPC from maya purple card.
  1062. **/
  1063. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1064. return 0;
  1065. len = clif_set_unit_idle(bl, buf,true);
  1066. clif_send(buf, len, bl, AREA_WOS);
  1067. if (disguised(bl))
  1068. clif_setdisguise(bl, buf, len);
  1069. if (vd->cloth_color)
  1070. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1071. switch (bl->type)
  1072. {
  1073. case BL_PC:
  1074. {
  1075. TBL_PC *sd = ((TBL_PC*)bl);
  1076. if (sd->spiritball > 0)
  1077. clif_spiritball(sd);
  1078. if(sd->state.size==2) // tiny/big players [Valaris]
  1079. clif_specialeffect(bl,423,AREA);
  1080. else if(sd->state.size==1)
  1081. clif_specialeffect(bl,421,AREA);
  1082. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1083. clif_sendbgemblem_area(sd);
  1084. if( sd->sc.option&OPTION_MOUNTING ) {
  1085. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1086. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1087. }
  1088. }
  1089. break;
  1090. case BL_MOB:
  1091. {
  1092. TBL_MOB *md = ((TBL_MOB*)bl);
  1093. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1094. clif_specialeffect(&md->bl,423,AREA);
  1095. else if(md->special_state.size==1)
  1096. clif_specialeffect(&md->bl,421,AREA);
  1097. }
  1098. break;
  1099. case BL_NPC:
  1100. {
  1101. TBL_NPC *nd = ((TBL_NPC*)bl);
  1102. if( nd->size == 2 )
  1103. clif_specialeffect(&nd->bl,423,AREA);
  1104. else if( nd->size == 1 )
  1105. clif_specialeffect(&nd->bl,421,AREA);
  1106. }
  1107. break;
  1108. case BL_PET:
  1109. if (vd->head_bottom)
  1110. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1111. break;
  1112. }
  1113. return 0;
  1114. }
  1115. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1116. /// 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
  1117. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1118. {
  1119. struct status_data *status;
  1120. unsigned char buf[128];
  1121. nullpo_retv(hd);
  1122. status = &hd->battle_status;
  1123. memset(buf,0,packet_len(0x22e));
  1124. WBUFW(buf,0)=0x22e;
  1125. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1126. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1127. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1128. WBUFW(buf,27)=hd->homunculus.level;
  1129. WBUFW(buf,29)=hd->homunculus.hunger;
  1130. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1131. WBUFW(buf,33)=0; // equip id
  1132. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1133. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1134. WBUFW(buf,39)=status->hit;
  1135. if (battle_config.hom_setting&0x10)
  1136. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1137. else
  1138. WBUFW(buf,41)=status->cri/10;
  1139. WBUFW(buf,43)=status->def + status->vit ;
  1140. WBUFW(buf,45)=status->mdef;
  1141. WBUFW(buf,47)=status->flee;
  1142. WBUFW(buf,49)=(flag)?0:status->amotion;
  1143. if (status->max_hp > INT16_MAX) {
  1144. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1145. WBUFW(buf,53) = 100;
  1146. } else {
  1147. WBUFW(buf,51)=status->hp;
  1148. WBUFW(buf,53)=status->max_hp;
  1149. }
  1150. if (status->max_sp > INT16_MAX) {
  1151. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1152. WBUFW(buf,57) = 100;
  1153. } else {
  1154. WBUFW(buf,55)=status->sp;
  1155. WBUFW(buf,57)=status->max_sp;
  1156. }
  1157. WBUFL(buf,59)=hd->homunculus.exp;
  1158. WBUFL(buf,63)=hd->exp_next;
  1159. WBUFW(buf,67)=hd->homunculus.skillpts;
  1160. WBUFW(buf,69)=status_get_range(&hd->bl);
  1161. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1162. }
  1163. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1164. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1165. /// type:
  1166. /// unused
  1167. /// state:
  1168. /// 0 = pre-init
  1169. /// 1 = intimacy
  1170. /// 2 = hunger
  1171. /// 3 = accessory?
  1172. /// ? = ignored
  1173. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1174. { //[orn]
  1175. int fd = sd->fd;
  1176. WFIFOHEAD(fd, packet_len(0x230));
  1177. WFIFOW(fd,0)=0x230;
  1178. WFIFOB(fd,2)=0;
  1179. WFIFOB(fd,3)=state;
  1180. WFIFOL(fd,4)=sd->hd->bl.id;
  1181. WFIFOL(fd,8)=param;
  1182. WFIFOSET(fd,packet_len(0x230));
  1183. }
  1184. int clif_homskillinfoblock(struct map_session_data *sd)
  1185. { //[orn]
  1186. struct homun_data *hd;
  1187. int fd = sd->fd;
  1188. int i,j,len=4,id;
  1189. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1190. hd = sd->hd;
  1191. if ( !hd )
  1192. return 0 ;
  1193. WFIFOW(fd,0)=0x235;
  1194. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1195. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1196. j = id - HM_SKILLBASE;
  1197. WFIFOW(fd,len ) = id;
  1198. WFIFOW(fd,len+2) = skill_get_inf(id);
  1199. WFIFOW(fd,len+4) = 0;
  1200. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1201. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1202. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1203. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1204. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1205. len+=37;
  1206. }
  1207. }
  1208. WFIFOW(fd,2)=len;
  1209. WFIFOSET(fd,len);
  1210. return 0;
  1211. }
  1212. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1213. { //[orn]
  1214. struct homun_data *hd;
  1215. int fd, skillid;
  1216. nullpo_retv(sd);
  1217. skillid = skill_num - HM_SKILLBASE;
  1218. fd=sd->fd;
  1219. hd=sd->hd;
  1220. WFIFOHEAD(fd, packet_len(0x239));
  1221. WFIFOW(fd,0) = 0x239;
  1222. WFIFOW(fd,2) = skill_num;
  1223. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1224. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1225. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1226. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1227. WFIFOSET(fd,packet_len(0x239));
  1228. }
  1229. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1230. {
  1231. int fd=sd->fd;
  1232. WFIFOHEAD(fd,packet_len(0x22f));
  1233. WFIFOW(fd,0)=0x22f;
  1234. WFIFOB(fd,2)=fail;
  1235. WFIFOW(fd,3)=foodid;
  1236. WFIFOSET(fd,packet_len(0x22f));
  1237. return 0;
  1238. }
  1239. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1240. /// 0087 <walk start time>.L <walk data>.6B
  1241. void clif_walkok(struct map_session_data *sd)
  1242. {
  1243. int fd=sd->fd;
  1244. WFIFOHEAD(fd, packet_len(0x87));
  1245. WFIFOW(fd,0)=0x87;
  1246. WFIFOL(fd,2)=gettick();
  1247. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1248. WFIFOSET(fd,packet_len(0x87));
  1249. }
  1250. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1251. {
  1252. uint8 buf[128];
  1253. int len;
  1254. len = clif_set_unit_walking(bl,ud,buf);
  1255. clif_send(buf,len,bl,AREA_WOS);
  1256. if (disguised(bl))
  1257. clif_setdisguise(bl, buf, len);
  1258. if(vd->cloth_color)
  1259. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1260. switch(bl->type)
  1261. {
  1262. case BL_PC:
  1263. {
  1264. TBL_PC *sd = ((TBL_PC*)bl);
  1265. // clif_movepc(sd);
  1266. if(sd->state.size==2) // tiny/big players [Valaris]
  1267. clif_specialeffect(&sd->bl,423,AREA);
  1268. else if(sd->state.size==1)
  1269. clif_specialeffect(&sd->bl,421,AREA);
  1270. }
  1271. break;
  1272. case BL_MOB:
  1273. {
  1274. TBL_MOB *md = ((TBL_MOB*)bl);
  1275. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1276. clif_specialeffect(&md->bl,423,AREA);
  1277. else if(md->special_state.size==1)
  1278. clif_specialeffect(&md->bl,421,AREA);
  1279. }
  1280. break;
  1281. case BL_PET:
  1282. if( vd->head_bottom )
  1283. {// needed to display pet equip properly
  1284. clif_pet_equip_area((TBL_PET*)bl);
  1285. }
  1286. break;
  1287. }
  1288. }
  1289. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1290. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1291. /// Note: unit must not be self
  1292. void clif_move(struct unit_data *ud)
  1293. {
  1294. unsigned char buf[16];
  1295. struct view_data* vd;
  1296. struct block_list* bl = ud->bl;
  1297. vd = status_get_viewdata(bl);
  1298. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1299. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1300. /**
  1301. * Hide NPC from maya purple card.
  1302. **/
  1303. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1304. return;
  1305. if (ud->state.speed_changed) {
  1306. // Since we don't know how to update the speed of other objects,
  1307. // use the old walk packet to update the data.
  1308. ud->state.speed_changed = 0;
  1309. clif_move2(bl, vd, ud);
  1310. return;
  1311. }
  1312. WBUFW(buf,0)=0x86;
  1313. WBUFL(buf,2)=bl->id;
  1314. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1315. WBUFL(buf,12)=gettick();
  1316. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1317. if (disguised(bl))
  1318. {
  1319. WBUFL(buf,2)=-bl->id;
  1320. clif_send(buf, packet_len(0x86), bl, SELF);
  1321. }
  1322. }
  1323. /*==========================================
  1324. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1325. *------------------------------------------*/
  1326. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1327. {
  1328. struct map_session_data *sd = NULL;
  1329. //Remove player from map server
  1330. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1331. map_quit(sd);
  1332. return 0;
  1333. }
  1334. /*==========================================
  1335. *
  1336. *------------------------------------------*/
  1337. void clif_quitsave(int fd,struct map_session_data *sd)
  1338. {
  1339. if (!battle_config.prevent_logout ||
  1340. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1341. map_quit(sd);
  1342. else if (sd->fd)
  1343. { //Disassociate session from player (session is deleted after this function was called)
  1344. //And set a timer to make him quit later.
  1345. session[sd->fd]->session_data = NULL;
  1346. sd->fd = 0;
  1347. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1348. }
  1349. }
  1350. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1351. /// 0091 <map name>.16B <x>.W <y>.W
  1352. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1353. {
  1354. int fd;
  1355. nullpo_retv(sd);
  1356. fd = sd->fd;
  1357. WFIFOHEAD(fd,packet_len(0x91));
  1358. WFIFOW(fd,0) = 0x91;
  1359. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1360. WFIFOW(fd,18) = x;
  1361. WFIFOW(fd,20) = y;
  1362. WFIFOSET(fd,packet_len(0x91));
  1363. }
  1364. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1365. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1366. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1367. {
  1368. int fd;
  1369. nullpo_retv(sd);
  1370. fd = sd->fd;
  1371. WFIFOHEAD(fd,packet_len(0x92));
  1372. WFIFOW(fd,0) = 0x92;
  1373. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1374. WFIFOW(fd,18) = x;
  1375. WFIFOW(fd,20) = y;
  1376. WFIFOL(fd,22) = htonl(ip);
  1377. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1378. WFIFOSET(fd,packet_len(0x92));
  1379. }
  1380. void clif_blown(struct block_list *bl)
  1381. {
  1382. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1383. // clif_fixpos(bl);
  1384. clif_slide(bl, bl->x, bl->y);
  1385. }
  1386. /// Visually moves(slides) a character to x,y. If the target cell
  1387. /// isn't walkable, the char doesn't move at all. If the char is
  1388. /// sitting it will stand up (ZC_STOPMOVE).
  1389. /// 0088 <id>.L <x>.W <y>.W
  1390. void clif_fixpos(struct block_list *bl)
  1391. {
  1392. unsigned char buf[10];
  1393. nullpo_retv(bl);
  1394. WBUFW(buf,0) = 0x88;
  1395. WBUFL(buf,2) = bl->id;
  1396. WBUFW(buf,6) = bl->x;
  1397. WBUFW(buf,8) = bl->y;
  1398. clif_send(buf, packet_len(0x88), bl, AREA);
  1399. if( disguised(bl) )
  1400. {
  1401. WBUFL(buf,2) = -bl->id;
  1402. clif_send(buf, packet_len(0x88), bl, SELF);
  1403. }
  1404. }
  1405. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1406. /// 00c4 <shop id>.L
  1407. void clif_npcbuysell(struct map_session_data* sd, int id)
  1408. {
  1409. int fd;
  1410. nullpo_retv(sd);
  1411. fd=sd->fd;
  1412. WFIFOHEAD(fd, packet_len(0xc4));
  1413. WFIFOW(fd,0)=0xc4;
  1414. WFIFOL(fd,2)=id;
  1415. WFIFOSET(fd,packet_len(0xc4));
  1416. }
  1417. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1418. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1419. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1420. {
  1421. int fd,i,c;
  1422. nullpo_retv(sd);
  1423. nullpo_retv(nd);
  1424. fd = sd->fd;
  1425. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1426. WFIFOW(fd,0) = 0xc6;
  1427. c = 0;
  1428. for( i = 0; i < nd->u.shop.count; i++ )
  1429. {
  1430. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1431. int val = nd->u.shop.shop_item[i].value;
  1432. if( id == NULL )
  1433. continue;
  1434. WFIFOL(fd, 4+c*11) = val;
  1435. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1436. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1437. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1438. c++;
  1439. }
  1440. WFIFOW(fd,2) = 4 + c*11;
  1441. WFIFOSET(fd,WFIFOW(fd,2));
  1442. }
  1443. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1444. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1445. void clif_selllist(struct map_session_data *sd)
  1446. {
  1447. int fd,i,c=0,val;
  1448. nullpo_retv(sd);
  1449. fd=sd->fd;
  1450. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1451. WFIFOW(fd,0)=0xc7;
  1452. for( i = 0; i < MAX_INVENTORY; i++ )
  1453. {
  1454. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1455. {
  1456. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1457. continue;
  1458. if( sd->status.inventory[i].expire_time )
  1459. continue; // Cannot Sell Rental Items
  1460. val=sd->inventory_data[i]->value_sell;
  1461. if( val < 0 )
  1462. continue;
  1463. WFIFOW(fd,4+c*10)=i+2;
  1464. WFIFOL(fd,6+c*10)=val;
  1465. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1466. c++;
  1467. }
  1468. }
  1469. WFIFOW(fd,2)=c*10+4;
  1470. WFIFOSET(fd,WFIFOW(fd,2));
  1471. }
  1472. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1473. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1474. /// Client behavior (dialog window):
  1475. /// - disable mouse targeting
  1476. /// - open the dialog window
  1477. /// - set npcid of dialog window (0 by default)
  1478. /// - if set to clear on next mes, clear contents
  1479. /// - append this text
  1480. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1481. {
  1482. int fd = sd->fd;
  1483. int slen = strlen(mes) + 9;
  1484. WFIFOHEAD(fd, slen);
  1485. WFIFOW(fd,0)=0xb4;
  1486. WFIFOW(fd,2)=slen;
  1487. WFIFOL(fd,4)=npcid;
  1488. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1489. WFIFOSET(fd,WFIFOW(fd,2));
  1490. }
  1491. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1492. /// 00b5 <npc id>.L
  1493. /// Client behavior (dialog window):
  1494. /// - disable mouse targeting
  1495. /// - open the dialog window
  1496. /// - add 'next' button
  1497. /// When 'next' is pressed:
  1498. /// - 00B9 <npcid of dialog window>.L
  1499. /// - set to clear on next mes
  1500. /// - remove 'next' button
  1501. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1502. {
  1503. int fd;
  1504. nullpo_retv(sd);
  1505. fd=sd->fd;
  1506. WFIFOHEAD(fd, packet_len(0xb5));
  1507. WFIFOW(fd,0)=0xb5;
  1508. WFIFOL(fd,2)=npcid;
  1509. WFIFOSET(fd,packet_len(0xb5));
  1510. }
  1511. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1512. /// 00b6 <npc id>.L
  1513. /// Client behavior:
  1514. /// - if dialog window is open:
  1515. /// - remove 'next' button
  1516. /// - add 'close' button
  1517. /// - else:
  1518. /// - enable mouse targeting
  1519. /// - close the dialog window
  1520. /// - close the menu window
  1521. /// When 'close' is pressed:
  1522. /// - enable mouse targeting
  1523. /// - close the dialog window
  1524. /// - close the menu window
  1525. /// - 0146 <npcid of dialog window>.L
  1526. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1527. {
  1528. int fd;
  1529. nullpo_retv(sd);
  1530. fd=sd->fd;
  1531. WFIFOHEAD(fd, packet_len(0xb6));
  1532. WFIFOW(fd,0)=0xb6;
  1533. WFIFOL(fd,2)=npcid;
  1534. WFIFOSET(fd,packet_len(0xb6));
  1535. }
  1536. /*==========================================
  1537. *
  1538. *------------------------------------------*/
  1539. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1540. {
  1541. unsigned char *buf;
  1542. int fd = sd->fd;
  1543. sd->state.using_fake_npc = 1;
  1544. WFIFOHEAD(fd, packet_len(0x78));
  1545. buf = WFIFOP(fd,0);
  1546. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1547. WBUFW(buf,0)=0x78;
  1548. WBUFB(buf,2) = 0; // object type
  1549. buf = WFIFOP(fd,1);
  1550. WBUFL(buf,2)=npcid;
  1551. WBUFW(buf,14)=111;
  1552. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1553. WBUFB(buf,49)=5;
  1554. WBUFB(buf,50)=5;
  1555. WFIFOSET(fd, packet_len(0x78));
  1556. }
  1557. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1558. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1559. /// Client behavior:
  1560. /// - disable mouse targeting
  1561. /// - close the menu window
  1562. /// - open the menu window
  1563. /// - add options to the menu (separated in the text by ":")
  1564. /// - set npcid of menu window
  1565. /// - if dialog window is open:
  1566. /// - remove 'next' button
  1567. /// When 'ok' is pressed:
  1568. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1569. /// - close the menu window
  1570. /// When 'cancel' is pressed:
  1571. /// - 00B8 <npcid of menu window>.L <-1>.B
  1572. /// - enable mouse targeting
  1573. /// - close a bunch of windows...
  1574. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1575. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1576. /// TODO investigate behavior of other windows [FlavioJS]
  1577. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1578. {
  1579. int fd = sd->fd;
  1580. int slen = strlen(mes) + 9;
  1581. struct block_list *bl = NULL;
  1582. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1583. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1584. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1585. clif_sendfakenpc(sd, npcid);
  1586. WFIFOHEAD(fd, slen);
  1587. WFIFOW(fd,0)=0xb7;
  1588. WFIFOW(fd,2)=slen;
  1589. WFIFOL(fd,4)=npcid;
  1590. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1591. WFIFOSET(fd,WFIFOW(fd,2));
  1592. }
  1593. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1594. /// 0142 <npc id>.L
  1595. /// Client behavior (inputnum window):
  1596. /// - if npcid exists in the client:
  1597. /// - open the inputnum window
  1598. /// - set npcid of inputnum window
  1599. /// When 'ok' is pressed:
  1600. /// - if inputnum window has text:
  1601. /// - if npcid exists in the client:
  1602. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1603. /// - close inputnum window
  1604. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1605. {
  1606. int fd;
  1607. struct block_list *bl = NULL;
  1608. nullpo_retv(sd);
  1609. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1610. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1611. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1612. clif_sendfakenpc(sd, npcid);
  1613. fd=sd->fd;
  1614. WFIFOHEAD(fd, packet_len(0x142));
  1615. WFIFOW(fd,0)=0x142;
  1616. WFIFOL(fd,2)=npcid;
  1617. WFIFOSET(fd,packet_len(0x142));
  1618. }
  1619. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1620. /// 01d4 <npc id>.L
  1621. /// Client behavior (inputstr window):
  1622. /// - if npcid is 0 or npcid exists in the client:
  1623. /// - open the inputstr window
  1624. /// - set npcid of inputstr window
  1625. /// When 'ok' is pressed:
  1626. /// - if inputstr window has text and isn't an insult(manner.txt):
  1627. /// - if npcid is 0 or npcid exists in the client:
  1628. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1629. /// - close inputstr window
  1630. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1631. {
  1632. int fd;
  1633. struct block_list *bl = NULL;
  1634. nullpo_retv(sd);
  1635. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1636. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1637. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1638. clif_sendfakenpc(sd, npcid);
  1639. fd=sd->fd;
  1640. WFIFOHEAD(fd, packet_len(0x1d4));
  1641. WFIFOW(fd,0)=0x1d4;
  1642. WFIFOL(fd,2)=npcid;
  1643. WFIFOSET(fd,packet_len(0x1d4));
  1644. }
  1645. /// Marks a position on client's minimap (ZC_COMPASS).
  1646. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1647. /// npc id:
  1648. /// is ignored in the client
  1649. /// type:
  1650. /// 0 = display mark for 15 seconds
  1651. /// 1 = display mark until dead or teleported
  1652. /// 2 = remove mark
  1653. /// color:
  1654. /// 0x00RRGGBB
  1655. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1656. {
  1657. int fd;
  1658. nullpo_retv(sd);
  1659. fd=sd->fd;
  1660. WFIFOHEAD(fd, packet_len(0x144));
  1661. WFIFOW(fd,0)=0x144;
  1662. WFIFOL(fd,2)=npc_id;
  1663. WFIFOL(fd,6)=type;
  1664. WFIFOL(fd,10)=x;
  1665. WFIFOL(fd,14)=y;
  1666. WFIFOB(fd,18)=id;
  1667. WFIFOL(fd,19)=color;
  1668. WFIFOSET(fd,packet_len(0x144));
  1669. }
  1670. /// Displays an illustration image.
  1671. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1672. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1673. /// type:
  1674. /// 0 = bottom left corner
  1675. /// 1 = bottom middle
  1676. /// 2 = bottom right corner
  1677. /// 3 = middle of screen, inside a movable window
  1678. /// 4 = middle of screen, movable with a close button, chrome-less
  1679. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1680. {
  1681. int fd;
  1682. nullpo_retv(sd);
  1683. fd=sd->fd;
  1684. WFIFOHEAD(fd, packet_len(0x1b3));
  1685. WFIFOW(fd,0)=0x1b3;
  1686. strncpy((char*)WFIFOP(fd,2),image,64);
  1687. WFIFOB(fd,66)=type;
  1688. WFIFOSET(fd,packet_len(0x1b3));
  1689. }
  1690. /*==========================================
  1691. * Fills in card data from the given item and into the buffer. [Skotlex]
  1692. *------------------------------------------*/
  1693. static void clif_addcards(unsigned char* buf, struct item* item)
  1694. {
  1695. int i=0,j;
  1696. if( item == NULL ) { //Blank data
  1697. WBUFW(buf,0) = 0;
  1698. WBUFW(buf,2) = 0;
  1699. WBUFW(buf,4) = 0;
  1700. WBUFW(buf,6) = 0;
  1701. return;
  1702. }
  1703. if( item->card[0] == CARD0_PET ) { //pet eggs
  1704. WBUFW(buf,0) = 0;
  1705. WBUFW(buf,2) = 0;
  1706. WBUFW(buf,4) = 0;
  1707. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1708. return;
  1709. }
  1710. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1711. WBUFW(buf,0) = item->card[0];
  1712. WBUFW(buf,2) = item->card[1];
  1713. WBUFW(buf,4) = item->card[2];
  1714. WBUFW(buf,6) = item->card[3];
  1715. return;
  1716. }
  1717. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1718. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1719. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1720. //Normal items.
  1721. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1722. WBUFW(buf,0) = j;
  1723. else
  1724. WBUFW(buf,0) = item->card[i];
  1725. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1726. WBUFW(buf,2) = j;
  1727. else
  1728. WBUFW(buf,2) = item->card[i];
  1729. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1730. WBUFW(buf,4) = j;
  1731. else
  1732. WBUFW(buf,4) = item->card[i];
  1733. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1734. WBUFW(buf,6) = j;
  1735. else
  1736. WBUFW(buf,6) = item->card[i];
  1737. }
  1738. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1739. /// 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)
  1740. /// 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)
  1741. /// 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)
  1742. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1743. {
  1744. int fd;
  1745. const int cmd = 0x2d4;
  1746. nullpo_retv(sd);
  1747. fd = sd->fd;
  1748. if( !session_isActive(fd) ) //Sasuke-
  1749. return;
  1750. WFIFOHEAD(fd,packet_len(cmd));
  1751. if( fail )
  1752. {
  1753. WFIFOW(fd,0)=cmd;
  1754. WFIFOW(fd,2)=n+2;
  1755. WFIFOW(fd,4)=amount;
  1756. WFIFOW(fd,6)=0;
  1757. WFIFOB(fd,8)=0;
  1758. WFIFOB(fd,9)=0;
  1759. WFIFOB(fd,10)=0;
  1760. WFIFOW(fd,11)=0;
  1761. WFIFOW(fd,13)=0;
  1762. WFIFOW(fd,15)=0;
  1763. WFIFOW(fd,17)=0;
  1764. WFIFOW(fd,19)=0;
  1765. WFIFOB(fd,21)=0;
  1766. WFIFOB(fd,22)=fail;
  1767. WFIFOL(fd,23)=0;
  1768. WFIFOW(fd,27)=0; // unknown
  1769. }
  1770. else
  1771. {
  1772. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1773. return;
  1774. WFIFOW(fd,0)=cmd;
  1775. WFIFOW(fd,2)=n+2;
  1776. WFIFOW(fd,4)=amount;
  1777. if (sd->inventory_data[n]->view_id > 0)
  1778. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1779. else
  1780. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1781. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1782. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1783. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1784. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1785. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1786. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1787. WFIFOB(fd,22)=fail;
  1788. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1789. WFIFOW(fd,27)=0; // unknown
  1790. }
  1791. WFIFOSET(fd,packet_len(cmd));
  1792. }
  1793. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1794. /// 00af <index>.W <amount>.W
  1795. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1796. {
  1797. int fd;
  1798. nullpo_retv(sd);
  1799. fd=sd->fd;
  1800. WFIFOHEAD(fd, packet_len(0xaf));
  1801. WFIFOW(fd,0)=0xaf;
  1802. WFIFOW(fd,2)=n+2;
  1803. WFIFOW(fd,4)=amount;
  1804. WFIFOSET(fd,packet_len(0xaf));
  1805. }
  1806. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1807. /// 07fa <delete type>.W <index>.W <amount>.W
  1808. /// delete type:
  1809. /// 0 = Normal
  1810. /// 1 = Item used for a skill
  1811. /// 2 = Refine failed
  1812. /// 3 = Material changed
  1813. /// 4 = Moved to storage
  1814. /// 5 = Moved to cart
  1815. /// 6 = Item sold
  1816. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1817. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1818. {
  1819. int fd;
  1820. nullpo_retv(sd);
  1821. fd=sd->fd;
  1822. WFIFOHEAD(fd, packet_len(0x7fa));
  1823. WFIFOW(fd,0)=0x7fa;
  1824. WFIFOW(fd,2)=reason;
  1825. WFIFOW(fd,4)=n+2;
  1826. WFIFOW(fd,6)=amount;
  1827. WFIFOSET(fd,packet_len(0x7fa));
  1828. }
  1829. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1830. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1831. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1832. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1833. {
  1834. if (id->view_id > 0)
  1835. WBUFW(buf,n)=id->view_id;
  1836. else
  1837. WBUFW(buf,n)=i->nameid;
  1838. WBUFB(buf,n+2)=itemtype(id->type);
  1839. WBUFB(buf,n+3)=i->identify;
  1840. if (equip >= 0) { //Equippable item
  1841. WBUFW(buf,n+4)=equip;
  1842. WBUFW(buf,n+6)=i->equip;
  1843. WBUFB(buf,n+8)=i->attribute;
  1844. WBUFB(buf,n+9)=i->refine;
  1845. } else { //Stackable item.
  1846. WBUFW(buf,n+4)=i->amount;
  1847. if (equip == -2 && id->equip == EQP_AMMO)
  1848. WBUFW(buf,n+6)=EQP_AMMO;
  1849. else
  1850. WBUFW(buf,n+6)=0;
  1851. }
  1852. }
  1853. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1854. void clif_inventorylist(struct map_session_data *sd)
  1855. {
  1856. int i,n,ne,arrow=-1;
  1857. unsigned char *buf;
  1858. unsigned char *bufe;
  1859. const int s = 22;
  1860. #if PACKETVER < 20100629
  1861. const int se = 26;
  1862. #else
  1863. const int se = 28;
  1864. #endif
  1865. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  1866. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  1867. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  1868. {
  1869. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  1870. continue;
  1871. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  1872. { //Non-stackable (Equippable)
  1873. WBUFW(bufe,ne*se+4)=i+2;
  1874. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1875. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  1876. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  1877. WBUFW(bufe,ne*se+28)=0; //Unknown
  1878. #if PACKETVER >= 20100629
  1879. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  1880. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  1881. else
  1882. WBUFW(bufe,ne*se+30)=0;
  1883. #endif
  1884. ne++;
  1885. }
  1886. else
  1887. { //Stackable.
  1888. WBUFW(buf,n*s+4)=i+2;
  1889. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1890. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  1891. arrow=i;
  1892. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1893. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  1894. n++;
  1895. }
  1896. }
  1897. if( n )
  1898. {
  1899. WBUFW(buf,0)=0x2e8;
  1900. WBUFW(buf,2)=4+n*s;
  1901. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1902. }
  1903. if( arrow >= 0 )
  1904. clif_arrowequip(sd,arrow);
  1905. if( ne )
  1906. {
  1907. WBUFW(bufe,0)=0x2d0;
  1908. WBUFW(bufe,2)=4+ne*se;
  1909. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1910. }
  1911. if( buf ) aFree(buf);
  1912. if( bufe ) aFree(bufe);
  1913. }
  1914. //Required when items break/get-repaired. Only sends equippable item list.
  1915. void clif_equiplist(struct map_session_data *sd)
  1916. {
  1917. int i,n,fd = sd->fd;
  1918. unsigned char *buf;
  1919. #if PACKETVER < 20100629
  1920. const int cmd = 26;
  1921. #else
  1922. const int cmd = 28;
  1923. #endif
  1924. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  1925. buf = WFIFOP(fd,0);
  1926. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1927. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1928. continue;
  1929. if(itemdb_isstackable2(sd->inventory_data[i]))
  1930. continue;
  1931. //Equippable
  1932. WBUFW(buf,n*cmd+4)=i+2;
  1933. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1934. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  1935. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  1936. WBUFW(buf,n*cmd+28)=0; //Unknown
  1937. #if PACKETVER >= 20100629
  1938. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  1939. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  1940. else
  1941. WBUFW(buf,n*cmd+30)=0;
  1942. #endif
  1943. n++;
  1944. }
  1945. if (n) {
  1946. WBUFW(buf,0)=0x2d0;
  1947. WBUFW(buf,2)=4+n*cmd;
  1948. WFIFOSET(fd,WFIFOW(fd,2));
  1949. }
  1950. }
  1951. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  1952. {
  1953. struct item_data *id;
  1954. int i,n,ne;
  1955. unsigned char *buf;
  1956. unsigned char *bufe;
  1957. const int s = 22;
  1958. #if PACKETVER < 20100629
  1959. const int cmd = 26;
  1960. #else
  1961. const int cmd = 28;
  1962. #endif
  1963. buf = (unsigned char*)aMalloc(items_length * s + 4);
  1964. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  1965. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  1966. {
  1967. if( items[i].nameid <= 0 )
  1968. continue;
  1969. id = itemdb_search(items[i].nameid);
  1970. if( !itemdb_isstackable2(id) )
  1971. { //Equippable
  1972. WBUFW(bufe,ne*cmd+4)=i+1;
  1973. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  1974. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  1975. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  1976. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  1977. ne++;
  1978. }
  1979. else
  1980. { //Stackable
  1981. WBUFW(buf,n*s+4)=i+1;
  1982. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  1983. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  1984. WBUFL(buf,n*s+22)=items[i].expire_time;
  1985. n++;
  1986. }
  1987. }
  1988. if( n )
  1989. {
  1990. WBUFW(buf,0)=0x2ea;
  1991. WBUFW(buf,2)=4+n*s;
  1992. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1993. }
  1994. if( ne )
  1995. {
  1996. WBUFW(bufe,0)=0x2d1;
  1997. WBUFW(bufe,2)=4+ne*cmd;
  1998. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1999. }
  2000. if( buf ) aFree(buf);
  2001. if( bufe ) aFree(bufe);
  2002. }
  2003. void clif_cartlist(struct map_session_data *sd)
  2004. {
  2005. struct item_data *id;
  2006. int i,n,ne;
  2007. unsigned char *buf;
  2008. unsigned char *bufe;
  2009. const int s = 22;
  2010. #if PACKETVER < 20100629
  2011. const int cmd = 26;
  2012. #else
  2013. const int cmd = 28;
  2014. #endif
  2015. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2016. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2017. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2018. {
  2019. if( sd->status.cart[i].nameid <= 0 )
  2020. continue;
  2021. id = itemdb_search(sd->status.cart[i].nameid);
  2022. if( !itemdb_isstackable2(id) )
  2023. { //Equippable
  2024. WBUFW(bufe,ne*cmd+4)=i+2;
  2025. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2026. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2027. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2028. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2029. ne++;
  2030. }
  2031. else
  2032. { //Stackable
  2033. WBUFW(buf,n*s+4)=i+2;
  2034. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2035. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2036. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2037. n++;
  2038. }
  2039. }
  2040. if( n )
  2041. {
  2042. WBUFW(buf,0)=0x2e9;
  2043. WBUFW(buf,2)=4+n*s;
  2044. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2045. }
  2046. if( ne )
  2047. {
  2048. WBUFW(bufe,0)=0x2d2;
  2049. WBUFW(bufe,2)=4+ne*cmd;
  2050. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2051. }
  2052. if( buf ) aFree(buf);
  2053. if( bufe ) aFree(bufe);
  2054. }
  2055. /// Removes cart (ZC_CARTOFF).
  2056. /// 012b
  2057. /// Client behaviour:
  2058. /// Closes the cart storage and removes all it's items from memory.
  2059. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2060. void clif_clearcart(int fd)
  2061. {
  2062. WFIFOHEAD(fd, packet_len(0x12b));
  2063. WFIFOW(fd,0) = 0x12b;
  2064. WFIFOSET(fd, packet_len(0x12b));
  2065. }
  2066. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2067. /// 01eb <account id>.L <x>.W <y>.W
  2068. void clif_guild_xy(struct map_session_data *sd)
  2069. {
  2070. unsigned char buf[10];
  2071. nullpo_retv(sd);
  2072. WBUFW(buf,0)=0x1eb;
  2073. WBUFL(buf,2)=sd->status.account_id;
  2074. WBUFW(buf,6)=sd->bl.x;
  2075. WBUFW(buf,8)=sd->bl.y;
  2076. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2077. }
  2078. /*==========================================
  2079. * Sends x/y dot to a single fd. [Skotlex]
  2080. *------------------------------------------*/
  2081. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2082. {
  2083. if( sd->bg_id )
  2084. return;
  2085. WFIFOHEAD(fd,packet_len(0x1eb));
  2086. WFIFOW(fd,0)=0x1eb;
  2087. WFIFOL(fd,2)=sd->status.account_id;
  2088. WFIFOW(fd,6)=sd->bl.x;
  2089. WFIFOW(fd,8)=sd->bl.y;
  2090. WFIFOSET(fd,packet_len(0x1eb));
  2091. }
  2092. // Guild XY locators [Valaris]
  2093. void clif_guild_xy_remove(struct map_session_data *sd)
  2094. {
  2095. unsigned char buf[10];
  2096. nullpo_retv(sd);
  2097. WBUFW(buf,0)=0x1eb;
  2098. WBUFL(buf,2)=sd->status.account_id;
  2099. WBUFW(buf,6)=-1;
  2100. WBUFW(buf,8)=-1;
  2101. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2102. }
  2103. /*==========================================
  2104. *
  2105. *------------------------------------------*/
  2106. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2107. {
  2108. struct map_session_data *sd, *tsd;
  2109. #if PACKETVER < 20100126
  2110. const int cmd = 0x106;
  2111. #else
  2112. const int cmd = 0x80e;
  2113. #endif
  2114. sd = va_arg(ap, struct map_session_data *);
  2115. tsd = (TBL_PC *)bl;
  2116. nullpo_ret(sd);
  2117. nullpo_ret(tsd);
  2118. if( !tsd->fd || tsd == sd )
  2119. return 0;
  2120. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2121. return 0;
  2122. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2123. WFIFOW(tsd->fd,0) = cmd;
  2124. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2125. #if PACKETVER < 20100126
  2126. if( sd->battle_status.max_hp > INT16_MAX )
  2127. { //To correctly display the %hp bar. [Skotlex]
  2128. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2129. WFIFOW(tsd->fd,8) = 100;
  2130. } else {
  2131. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2132. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2133. }
  2134. #else
  2135. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2136. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2137. #endif
  2138. WFIFOSET(tsd->fd,packet_len(cmd));
  2139. return 0;
  2140. }
  2141. /*==========================================
  2142. * Server tells all players that are allowed to view HP bars
  2143. * and are nearby 'sd' that 'sd' hp bar was updated.
  2144. *------------------------------------------*/
  2145. static int clif_hpmeter(struct map_session_data *sd)
  2146. {
  2147. nullpo_ret(sd);
  2148. 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);
  2149. return 0;
  2150. }
  2151. /// Notifies client of a character parameter change.
  2152. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2153. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2154. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2155. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2156. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2157. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2158. /// TODO: Extract individual packets.
  2159. /// FIXME: Packet lengths from packet_len(cmd)
  2160. void clif_updatestatus(struct map_session_data *sd,int type)
  2161. {
  2162. int fd,len=8;
  2163. nullpo_retv(sd);
  2164. fd=sd->fd;
  2165. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2166. return;
  2167. WFIFOHEAD(fd, 14);
  2168. WFIFOW(fd,0)=0xb0;
  2169. WFIFOW(fd,2)=type;
  2170. switch(type){
  2171. // 00b0
  2172. case SP_WEIGHT:
  2173. pc_updateweightstatus(sd);
  2174. WFIFOHEAD(fd,14);
  2175. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2176. WFIFOW(fd,2)=type;
  2177. WFIFOL(fd,4)=sd->weight;
  2178. break;
  2179. case SP_MAXWEIGHT:
  2180. WFIFOL(fd,4)=sd->max_weight;
  2181. break;
  2182. case SP_SPEED:
  2183. WFIFOL(fd,4)=sd->battle_status.speed;
  2184. break;
  2185. case SP_BASELEVEL:
  2186. WFIFOL(fd,4)=sd->status.base_level;
  2187. break;
  2188. case SP_JOBLEVEL:
  2189. WFIFOL(fd,4)=sd->status.job_level;
  2190. break;
  2191. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2192. WFIFOL(fd,4)=sd->status.karma;
  2193. break;
  2194. case SP_MANNER:
  2195. WFIFOL(fd,4)=sd->status.manner;
  2196. break;
  2197. case SP_STATUSPOINT:
  2198. WFIFOL(fd,4)=sd->status.status_point;
  2199. break;
  2200. case SP_SKILLPOINT:
  2201. WFIFOL(fd,4)=sd->status.skill_point;
  2202. break;
  2203. case SP_HIT:
  2204. WFIFOL(fd,4)=sd->battle_status.hit;
  2205. break;
  2206. case SP_FLEE1:
  2207. WFIFOL(fd,4)=sd->battle_status.flee;
  2208. break;
  2209. case SP_FLEE2:
  2210. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2211. break;
  2212. case SP_MAXHP:
  2213. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2214. break;
  2215. case SP_MAXSP:
  2216. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2217. break;
  2218. case SP_HP:
  2219. WFIFOL(fd,4)=sd->battle_status.hp;
  2220. // TODO: Won't these overwrite the current packet?
  2221. clif_hpmeter(sd);
  2222. if( !battle_config.party_hp_mode && sd->status.party_id )
  2223. clif_party_hp(sd);
  2224. if( sd->bg_id )
  2225. clif_bg_hp(sd);
  2226. break;
  2227. case SP_SP:
  2228. WFIFOL(fd,4)=sd->battle_status.sp;
  2229. break;
  2230. case SP_ASPD:
  2231. WFIFOL(fd,4)=sd->battle_status.amotion;
  2232. break;
  2233. case SP_ATK1:
  2234. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2235. break;
  2236. case SP_DEF1:
  2237. WFIFOL(fd,4)=sd->battle_status.def;
  2238. break;
  2239. case SP_MDEF1:
  2240. WFIFOL(fd,4)=sd->battle_status.mdef;
  2241. break;
  2242. case SP_ATK2:
  2243. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2244. break;
  2245. case SP_DEF2:
  2246. WFIFOL(fd,4)=sd->battle_status.def2;
  2247. break;
  2248. case SP_MDEF2:
  2249. {
  2250. //negative check (in case you have something like Berserk active)
  2251. int mdef2 = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2252. WFIFOL(fd,4)= ( mdef2 < 0 ) ? 0 : mdef2;
  2253. break;
  2254. }
  2255. case SP_CRITICAL:
  2256. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2257. break;
  2258. case SP_MATK1:
  2259. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2260. break;
  2261. case SP_MATK2:
  2262. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2263. break;
  2264. case SP_ZENY:
  2265. WFIFOW(fd,0)=0xb1;
  2266. WFIFOL(fd,4)=sd->status.zeny;
  2267. break;
  2268. case SP_BASEEXP:
  2269. WFIFOW(fd,0)=0xb1;
  2270. WFIFOL(fd,4)=sd->status.base_exp;
  2271. break;
  2272. case SP_JOBEXP:
  2273. WFIFOW(fd,0)=0xb1;
  2274. WFIFOL(fd,4)=sd->status.job_exp;
  2275. break;
  2276. case SP_NEXTBASEEXP:
  2277. WFIFOW(fd,0)=0xb1;
  2278. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2279. break;
  2280. case SP_NEXTJOBEXP:
  2281. WFIFOW(fd,0)=0xb1;
  2282. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2283. break;
  2284. /**
  2285. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2286. **/
  2287. case SP_USTR:
  2288. case SP_UAGI:
  2289. case SP_UVIT:
  2290. case SP_UINT:
  2291. case SP_UDEX:
  2292. case SP_ULUK:
  2293. WFIFOW(fd,0)=0xbe;
  2294. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2295. len=5;
  2296. break;
  2297. /**
  2298. * Tells the client how far it is allowed to attack (weapon range)
  2299. **/
  2300. case SP_ATTACKRANGE:
  2301. WFIFOW(fd,0)=0x13a;
  2302. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2303. len=4;
  2304. break;
  2305. case SP_STR:
  2306. WFIFOW(fd,0)=0x141;
  2307. WFIFOL(fd,2)=type;
  2308. WFIFOL(fd,6)=sd->status.str;
  2309. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2310. len=14;
  2311. break;
  2312. case SP_AGI:
  2313. WFIFOW(fd,0)=0x141;
  2314. WFIFOL(fd,2)=type;
  2315. WFIFOL(fd,6)=sd->status.agi;
  2316. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2317. len=14;
  2318. break;
  2319. case SP_VIT:
  2320. WFIFOW(fd,0)=0x141;
  2321. WFIFOL(fd,2)=type;
  2322. WFIFOL(fd,6)=sd->status.vit;
  2323. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2324. len=14;
  2325. break;
  2326. case SP_INT:
  2327. WFIFOW(fd,0)=0x141;
  2328. WFIFOL(fd,2)=type;
  2329. WFIFOL(fd,6)=sd->status.int_;
  2330. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2331. len=14;
  2332. break;
  2333. case SP_DEX:
  2334. WFIFOW(fd,0)=0x141;
  2335. WFIFOL(fd,2)=type;
  2336. WFIFOL(fd,6)=sd->status.dex;
  2337. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2338. len=14;
  2339. break;
  2340. case SP_LUK:
  2341. WFIFOW(fd,0)=0x141;
  2342. WFIFOL(fd,2)=type;
  2343. WFIFOL(fd,6)=sd->status.luk;
  2344. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2345. len=14;
  2346. break;
  2347. case SP_CARTINFO:
  2348. WFIFOW(fd,0)=0x121;
  2349. WFIFOW(fd,2)=sd->cart_num;
  2350. WFIFOW(fd,4)=MAX_CART;
  2351. WFIFOL(fd,6)=sd->cart_weight;
  2352. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2353. len=14;
  2354. break;
  2355. default:
  2356. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2357. return;
  2358. }
  2359. WFIFOSET(fd,len);
  2360. }
  2361. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2362. /// 01ab <account id>.L <var id>.W <value>.L
  2363. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2364. {
  2365. unsigned char buf[12];
  2366. nullpo_retv(sd);
  2367. WBUFW(buf,0)=0x1ab;
  2368. WBUFL(buf,2)=sd->bl.id;
  2369. WBUFW(buf,6)=type;
  2370. switch(type)
  2371. {
  2372. case SP_MANNER:
  2373. WBUFL(buf,8)=val;
  2374. break;
  2375. default:
  2376. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2377. return;
  2378. }
  2379. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2380. }
  2381. /// Updates sprite/style properties of an object.
  2382. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2383. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2384. void clif_changelook(struct block_list *bl,int type,int val)
  2385. {
  2386. unsigned char buf[16];
  2387. struct map_session_data* sd = NULL;
  2388. struct status_change* sc;
  2389. struct view_data* vd;
  2390. enum send_target target = AREA;
  2391. nullpo_retv(bl);
  2392. sd = BL_CAST(BL_PC, bl);
  2393. sc = status_get_sc(bl);
  2394. vd = status_get_viewdata(bl);
  2395. //nullpo_ret(vd);
  2396. if( vd ) //temp hack to let Warp Portal change appearance
  2397. switch(type)
  2398. {
  2399. case LOOK_WEAPON:
  2400. if (sd)
  2401. {
  2402. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2403. val = vd->weapon;
  2404. }
  2405. else vd->weapon = val;
  2406. break;
  2407. case LOOK_SHIELD:
  2408. if (sd)
  2409. {
  2410. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2411. val = vd->shield;
  2412. }
  2413. else vd->shield = val;
  2414. break;
  2415. case LOOK_BASE:
  2416. vd->class_ = val;
  2417. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2418. vd->weapon = vd->shield = 0;
  2419. if (vd->cloth_color && (
  2420. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2421. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2422. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2423. ))
  2424. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2425. break;
  2426. case LOOK_HAIR:
  2427. vd->hair_style = val;
  2428. break;
  2429. case LOOK_HEAD_BOTTOM:
  2430. vd->head_bottom = val;
  2431. break;
  2432. case LOOK_HEAD_TOP:
  2433. vd->head_top = val;
  2434. break;
  2435. case LOOK_HEAD_MID:
  2436. vd->head_mid = val;
  2437. break;
  2438. case LOOK_HAIR_COLOR:
  2439. vd->hair_color = val;
  2440. break;
  2441. case LOOK_CLOTHES_COLOR:
  2442. if (val && (
  2443. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2444. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2445. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2446. ))
  2447. val = 0;
  2448. vd->cloth_color = val;
  2449. break;
  2450. case LOOK_SHOES:
  2451. if (sd) {
  2452. int n;
  2453. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2454. if(sd->inventory_data[n]->view_id > 0)
  2455. val = sd->inventory_data[n]->view_id;
  2456. else
  2457. val = sd->status.inventory[n].nameid;
  2458. }
  2459. val = 0;
  2460. }
  2461. //Shoes? No packet uses this....
  2462. break;
  2463. case LOOK_BODY:
  2464. case LOOK_FLOOR:
  2465. // unknown purpose
  2466. break;
  2467. case LOOK_ROBE:
  2468. #if PACKETVER < 20110111
  2469. return;
  2470. #else
  2471. vd->robe = val;
  2472. #endif
  2473. break;
  2474. }
  2475. // prevent leaking the presence of GM-hidden objects
  2476. if( sc && sc->option&OPTION_INVISIBLE )
  2477. target = SELF;
  2478. WBUFW(buf,0)=0x1d7;
  2479. WBUFL(buf,2)=bl->id;
  2480. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2481. WBUFB(buf,6)=LOOK_WEAPON;
  2482. WBUFW(buf,7)=vd->weapon;
  2483. WBUFW(buf,9)=vd->shield;
  2484. } else {
  2485. WBUFB(buf,6)=type;
  2486. WBUFL(buf,7)=val;
  2487. }
  2488. clif_send(buf,packet_len(0x1d7),bl,target);
  2489. }
  2490. //Sends a change-base-look packet required for traps as they are triggered.
  2491. void clif_changetraplook(struct block_list *bl,int val)
  2492. {
  2493. unsigned char buf[32];
  2494. WBUFW(buf,0)=0x1d7;
  2495. WBUFL(buf,2)=bl->id;
  2496. WBUFB(buf,6)=LOOK_BASE;
  2497. WBUFW(buf,7)=val;
  2498. WBUFW(buf,9)=0;
  2499. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2500. }
  2501. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2502. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2503. {
  2504. unsigned char buf[32];
  2505. WBUFW(buf,0)=0x1d7;
  2506. WBUFL(buf,2)=id;
  2507. WBUFB(buf,6)=type;
  2508. WBUFW(buf,7)=val;
  2509. WBUFW(buf,9)=0;
  2510. clif_send(buf,packet_len(0x1d7),bl,target);
  2511. return;
  2512. }
  2513. /// Character status (ZC_STATUS).
  2514. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2515. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2516. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2517. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2518. void clif_initialstatus(struct map_session_data *sd)
  2519. {
  2520. int fd, mdef2;
  2521. unsigned char *buf;
  2522. nullpo_retv(sd);
  2523. fd=sd->fd;
  2524. WFIFOHEAD(fd,packet_len(0xbd));
  2525. buf=WFIFOP(fd,0);
  2526. WBUFW(buf,0)=0xbd;
  2527. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2528. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2529. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2530. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2531. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2532. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2533. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2534. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2535. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2536. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2537. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2538. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2539. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2540. WBUFW(buf,16) = pc_leftside_atk(sd);
  2541. WBUFW(buf,18) = pc_rightside_atk(sd);
  2542. WBUFW(buf,20) = sd->battle_status.matk_max;
  2543. WBUFW(buf,22) = sd->battle_status.matk_min;
  2544. WBUFW(buf,24) = sd->battle_status.def; // def
  2545. WBUFW(buf,26) = sd->battle_status.def2;
  2546. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2547. mdef2 = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2548. WBUFW(buf,30) = ( mdef2 < 0 ) ? 0 : mdef2; //Negative check for Frenzy'ed characters.
  2549. WBUFW(buf,32) = sd->battle_status.hit;
  2550. WBUFW(buf,34) = sd->battle_status.flee;
  2551. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2552. WBUFW(buf,38) = sd->battle_status.cri/10;
  2553. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2554. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2555. WFIFOSET(fd,packet_len(0xbd));
  2556. clif_updatestatus(sd,SP_STR);
  2557. clif_updatestatus(sd,SP_AGI);
  2558. clif_updatestatus(sd,SP_VIT);
  2559. clif_updatestatus(sd,SP_INT);
  2560. clif_updatestatus(sd,SP_DEX);
  2561. clif_updatestatus(sd,SP_LUK);
  2562. clif_updatestatus(sd,SP_ATTACKRANGE);
  2563. clif_updatestatus(sd,SP_ASPD);
  2564. }
  2565. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2566. /// 013c <index>.W
  2567. void clif_arrowequip(struct map_session_data *sd,int val)
  2568. {
  2569. int fd;
  2570. nullpo_retv(sd);
  2571. pc_stop_attack(sd); // [Valaris]
  2572. fd=sd->fd;
  2573. WFIFOHEAD(fd, packet_len(0x013c));
  2574. WFIFOW(fd,0)=0x013c;
  2575. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2576. WFIFOSET(fd,packet_len(0x013c));
  2577. }
  2578. /// Ammunition action message (ZC_ACTION_FAILURE).
  2579. /// 013b <type>.W
  2580. /// type:
  2581. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2582. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2583. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2584. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2585. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2586. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2587. void clif_arrow_fail(struct map_session_data *sd,int type)
  2588. {
  2589. int fd;
  2590. nullpo_retv(sd);
  2591. fd=sd->fd;
  2592. WFIFOHEAD(fd, packet_len(0x013b));
  2593. WFIFOW(fd,0)=0x013b;
  2594. WFIFOW(fd,2)=type;
  2595. WFIFOSET(fd,packet_len(0x013b));
  2596. }
  2597. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2598. /// 01ad <packet len>.W { <name id>.W }*
  2599. void clif_arrow_create_list(struct map_session_data *sd)
  2600. {
  2601. int i, c, j;
  2602. int fd;
  2603. nullpo_retv(sd);
  2604. fd = sd->fd;
  2605. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2606. WFIFOW(fd,0) = 0x1ad;
  2607. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2608. if (skill_arrow_db[i].nameid > 0 &&
  2609. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2610. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2611. {
  2612. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2613. WFIFOW(fd,c*2+4) = j;
  2614. else
  2615. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2616. c++;
  2617. }
  2618. }
  2619. WFIFOW(fd,2) = c*2+4;
  2620. WFIFOSET(fd, WFIFOW(fd,2));
  2621. if (c > 0) {
  2622. sd->menuskill_id = AC_MAKINGARROW;
  2623. sd->menuskill_val = c;
  2624. }
  2625. }
  2626. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2627. /// 00bc <status id>.W <result>.B <value>.B
  2628. /// status id:
  2629. /// SP_STR ~ SP_LUK
  2630. /// result:
  2631. /// 0 = failure
  2632. /// 1 = success
  2633. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2634. {
  2635. int fd;
  2636. nullpo_retv(sd);
  2637. fd=sd->fd;
  2638. WFIFOHEAD(fd,packet_len(0xbc));
  2639. WFIFOW(fd,0)=0xbc;
  2640. WFIFOW(fd,2)=type;
  2641. WFIFOB(fd,4)=ok;
  2642. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2643. WFIFOSET(fd,packet_len(0xbc));
  2644. }
  2645. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2646. /// 00aa <index>.W <equip location>.W <result>.B
  2647. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2648. /// result:
  2649. /// 0 = failure
  2650. /// 1 = success
  2651. /// 2 = failure due to low level
  2652. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2653. {
  2654. int fd;
  2655. nullpo_retv(sd);
  2656. fd=sd->fd;
  2657. WFIFOHEAD(fd,packet_len(0xaa));
  2658. WFIFOW(fd,0)=0xaa;
  2659. WFIFOW(fd,2)=n+2;
  2660. WFIFOW(fd,4)=pos;
  2661. #if PACKETVER < 20100629
  2662. WFIFOB(fd,6)=ok;
  2663. #else
  2664. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2665. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2666. else
  2667. WFIFOW(fd,6)=0;
  2668. WFIFOB(fd,8)=ok;
  2669. #endif
  2670. WFIFOSET(fd,packet_len(0xaa));
  2671. }
  2672. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2673. /// 00ac <index>.W <equip location>.W <result>.B
  2674. /// result:
  2675. /// 0 = failure
  2676. /// 1 = success
  2677. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2678. {
  2679. int fd;
  2680. nullpo_retv(sd);
  2681. fd=sd->fd;
  2682. WFIFOHEAD(fd,packet_len(0xac));
  2683. WFIFOW(fd,0)=0xac;
  2684. WFIFOW(fd,2)=n+2;
  2685. WFIFOW(fd,4)=pos;
  2686. WFIFOB(fd,6)=ok;
  2687. WFIFOSET(fd,packet_len(0xac));
  2688. }
  2689. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2690. /// 019b <id>.L <effect id>.L
  2691. /// effect id:
  2692. /// 0 = base level up
  2693. /// 1 = job level up
  2694. /// 2 = refine failure
  2695. /// 3 = refine success
  2696. /// 4 = game over
  2697. /// 5 = pharmacy success
  2698. /// 6 = pharmacy failure
  2699. /// 7 = base level up (super novice)
  2700. /// 8 = job level up (super novice)
  2701. /// 9 = base level up (taekwon)
  2702. void clif_misceffect(struct block_list* bl,int type)
  2703. {
  2704. unsigned char buf[32];
  2705. nullpo_retv(bl);
  2706. WBUFW(buf,0) = 0x19b;
  2707. WBUFL(buf,2) = bl->id;
  2708. WBUFL(buf,6) = type;
  2709. clif_send(buf,packet_len(0x19b),bl,AREA);
  2710. }
  2711. /// Notifies clients in the area of a state change.
  2712. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  2713. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  2714. void clif_changeoption(struct block_list* bl)
  2715. {
  2716. unsigned char buf[32];
  2717. struct status_change *sc;
  2718. struct map_session_data* sd;
  2719. nullpo_retv(bl);
  2720. sc = status_get_sc(bl);
  2721. if (!sc) return; //How can an option change if there's no sc?
  2722. sd = BL_CAST(BL_PC, bl);
  2723. WBUFW(buf,0) = 0x229;
  2724. WBUFL(buf,2) = bl->id;
  2725. WBUFW(buf,6) = sc->opt1;
  2726. WBUFW(buf,8) = sc->opt2;
  2727. WBUFL(buf,10) = sc->option;
  2728. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2729. if(disguised(bl)) {
  2730. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2731. WBUFL(buf,2) = -bl->id;
  2732. clif_send(buf,packet_len(0x229),bl,SELF);
  2733. WBUFL(buf,2) = bl->id;
  2734. WBUFL(buf,10) = OPTION_INVISIBLE;
  2735. clif_send(buf,packet_len(0x229),bl,SELF);
  2736. } else
  2737. clif_send(buf,packet_len(0x229),bl,AREA);
  2738. }
  2739. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  2740. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  2741. void clif_changeoption2(struct block_list* bl)
  2742. {
  2743. unsigned char buf[20];
  2744. struct status_change *sc;
  2745. sc = status_get_sc(bl);
  2746. if (!sc) return; //How can an option change if there's no sc?
  2747. WBUFW(buf,0) = 0x28a;
  2748. WBUFL(buf,2) = bl->id;
  2749. WBUFL(buf,6) = sc->option;
  2750. WBUFL(buf,10) = clif_setlevel(bl);
  2751. WBUFL(buf,14) = sc->opt3;
  2752. if(disguised(bl)) {
  2753. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2754. WBUFL(buf,2) = -bl->id;
  2755. clif_send(buf,packet_len(0x28a),bl,SELF);
  2756. WBUFL(buf,2) = bl->id;
  2757. WBUFL(buf,6) = OPTION_INVISIBLE;
  2758. clif_send(buf,packet_len(0x28a),bl,SELF);
  2759. } else
  2760. clif_send(buf,packet_len(0x28a),bl,AREA);
  2761. }
  2762. /// Notifies the client about the result of an item use request.
  2763. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  2764. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  2765. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  2766. {
  2767. nullpo_retv(sd);
  2768. if(!ok) {
  2769. int fd=sd->fd;
  2770. WFIFOHEAD(fd,packet_len(0xa8));
  2771. WFIFOW(fd,0)=0xa8;
  2772. WFIFOW(fd,2)=index+2;
  2773. WFIFOW(fd,4)=amount;
  2774. WFIFOB(fd,6)=ok;
  2775. WFIFOSET(fd,packet_len(0xa8));
  2776. }
  2777. else {
  2778. unsigned char buf[32];
  2779. WBUFW(buf,0)=0x1c8;
  2780. WBUFW(buf,2)=index+2;
  2781. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2782. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2783. else
  2784. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2785. WBUFL(buf,6)=sd->bl.id;
  2786. WBUFW(buf,10)=amount;
  2787. WBUFB(buf,12)=ok;
  2788. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2789. }
  2790. }
  2791. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  2792. /// 00d6 <flag>.B
  2793. /// flag:
  2794. /// 0 = Room has been successfully created (opens chat room)
  2795. /// 1 = Room limit exceeded
  2796. /// 2 = Same room already exists
  2797. void clif_createchat(struct map_session_data* sd, int flag)
  2798. {
  2799. int fd;
  2800. nullpo_retv(sd);
  2801. fd = sd->fd;
  2802. WFIFOHEAD(fd,packet_len(0xd6));
  2803. WFIFOW(fd,0) = 0xd6;
  2804. WFIFOB(fd,2) = flag;
  2805. WFIFOSET(fd,packet_len(0xd6));
  2806. }
  2807. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  2808. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  2809. /// type:
  2810. /// 0 = private (password protected)
  2811. /// 1 = public
  2812. /// 2 = arena (npc waiting room)
  2813. /// 3 = PK zone (non-clickable)
  2814. void clif_dispchat(struct chat_data* cd, int fd)
  2815. {
  2816. unsigned char buf[128];
  2817. uint8 type;
  2818. if( cd == NULL || cd->owner == NULL )
  2819. return;
  2820. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2821. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2822. : 1;
  2823. WBUFW(buf, 0) = 0xd7;
  2824. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2825. WBUFL(buf, 4) = cd->owner->id;
  2826. WBUFL(buf, 8) = cd->bl.id;
  2827. WBUFW(buf,12) = cd->limit;
  2828. WBUFW(buf,14) = cd->users;
  2829. WBUFB(buf,16) = type;
  2830. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2831. if( fd ) {
  2832. WFIFOHEAD(fd,WBUFW(buf,2));
  2833. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2834. WFIFOSET(fd,WBUFW(buf,2));
  2835. } else {
  2836. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2837. }
  2838. }
  2839. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  2840. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  2841. /// type:
  2842. /// 0 = private (password protected)
  2843. /// 1 = public
  2844. /// 2 = arena (npc waiting room)
  2845. /// 3 = PK zone (non-clickable)
  2846. void clif_changechatstatus(struct chat_data* cd)
  2847. {
  2848. unsigned char buf[128];
  2849. uint8 type;
  2850. if( cd == NULL || cd->usersd[0] == NULL )
  2851. return;
  2852. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2853. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2854. : 1;
  2855. WBUFW(buf, 0) = 0xdf;
  2856. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2857. WBUFL(buf, 4) = cd->owner->id;
  2858. WBUFL(buf, 8) = cd->bl.id;
  2859. WBUFW(buf,12) = cd->limit;
  2860. WBUFW(buf,14) = cd->users;
  2861. WBUFB(buf,16) = type;
  2862. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2863. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  2864. }
  2865. /// Removes the chatroom (ZC_DESTROY_ROOM).
  2866. /// 00d8 <chat id>.L
  2867. void clif_clearchat(struct chat_data *cd,int fd)
  2868. {
  2869. unsigned char buf[32];
  2870. nullpo_retv(cd);
  2871. WBUFW(buf,0) = 0xd8;
  2872. WBUFL(buf,2) = cd->bl.id;
  2873. if( fd ) {
  2874. WFIFOHEAD(fd,packet_len(0xd8));
  2875. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2876. WFIFOSET(fd,packet_len(0xd8));
  2877. } else {
  2878. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2879. }
  2880. }
  2881. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  2882. /// 00da <result>.B
  2883. /// result:
  2884. /// 0 = room full
  2885. /// 1 = wrong password
  2886. /// 2 = kicked
  2887. /// 3 = success (no message)
  2888. /// 4 = no enough zeny
  2889. /// 5 = too low level
  2890. /// 6 = too high level
  2891. /// 7 = unsuitable job class
  2892. void clif_joinchatfail(struct map_session_data *sd,int flag)
  2893. {
  2894. int fd;
  2895. nullpo_retv(sd);
  2896. fd = sd->fd;
  2897. WFIFOHEAD(fd,packet_len(0xda));
  2898. WFIFOW(fd,0) = 0xda;
  2899. WFIFOB(fd,2) = flag;
  2900. WFIFOSET(fd,packet_len(0xda));
  2901. }
  2902. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  2903. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  2904. /// role:
  2905. /// 0 = owner (menu)
  2906. /// 1 = normal
  2907. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2908. {
  2909. int fd;
  2910. int i;
  2911. nullpo_retv(sd);
  2912. nullpo_retv(cd);
  2913. fd = sd->fd;
  2914. if (!session_isActive(fd))
  2915. return;
  2916. WFIFOHEAD(fd, 8 + (28*cd->users));
  2917. WFIFOW(fd, 0) = 0xdb;
  2918. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2919. WFIFOL(fd, 4) = cd->bl.id;
  2920. for (i = 0; i < cd->users; i++) {
  2921. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2922. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2923. }
  2924. WFIFOSET(fd, WFIFOW(fd, 2));
  2925. }
  2926. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  2927. /// 00dc <users>.W <name>.24B
  2928. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2929. {
  2930. unsigned char buf[32];
  2931. nullpo_retv(sd);
  2932. nullpo_retv(cd);
  2933. WBUFW(buf, 0) = 0xdc;
  2934. WBUFW(buf, 2) = cd->users;
  2935. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2936. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2937. }
  2938. /// Announce the new owner (ZC_ROLE_CHANGE).
  2939. /// 00e1 <role>.L <nick>.24B
  2940. /// role:
  2941. /// 0 = owner (menu)
  2942. /// 1 = normal
  2943. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2944. {
  2945. unsigned char buf[64];
  2946. nullpo_retv(sd);
  2947. nullpo_retv(cd);
  2948. WBUFW(buf, 0) = 0xe1;
  2949. WBUFL(buf, 2) = 1;
  2950. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2951. WBUFW(buf,30) = 0xe1;
  2952. WBUFL(buf,32) = 0;
  2953. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2954. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2955. }
  2956. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  2957. /// 00dd <users>.W <nick>.24B <flag>.B
  2958. /// flag:
  2959. /// 0 = left
  2960. /// 1 = kicked
  2961. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2962. {
  2963. unsigned char buf[32];
  2964. nullpo_retv(sd);
  2965. nullpo_retv(cd);
  2966. WBUFW(buf, 0) = 0xdd;
  2967. WBUFW(buf, 2) = cd->users-1;
  2968. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2969. WBUFB(buf,28) = flag;
  2970. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2971. }
  2972. /// Opens a trade request window from char 'name'.
  2973. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  2974. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  2975. void clif_traderequest(struct map_session_data* sd, const char* name)
  2976. {
  2977. int fd = sd->fd;
  2978. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2979. if( !tsd ) return;
  2980. WFIFOHEAD(fd,packet_len(0x1f4));
  2981. WFIFOW(fd,0) = 0x1f4;
  2982. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2983. WFIFOL(fd,26) = tsd->status.char_id;
  2984. WFIFOW(fd,30) = tsd->status.base_level;
  2985. WFIFOSET(fd,packet_len(0x1f4));
  2986. }
  2987. /// Reply to a trade-request.
  2988. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  2989. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  2990. /// result:
  2991. /// 0 = Char is too far
  2992. /// 1 = Character does not exist
  2993. /// 2 = Trade failed
  2994. /// 3 = Accept
  2995. /// 4 = Cancel
  2996. /// 5 = Busy
  2997. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2998. {
  2999. int fd = sd->fd;
  3000. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3001. if (!tsd) {
  3002. WFIFOHEAD(fd,packet_len(0xe7));
  3003. WFIFOW(fd,0) = 0xe7;
  3004. WFIFOB(fd,2) = type;
  3005. WFIFOSET(fd,packet_len(0xe7));
  3006. } else {
  3007. WFIFOHEAD(fd,packet_len(0x1f5));
  3008. WFIFOW(fd,0) = 0x1f5;
  3009. WFIFOB(fd,2) = type;
  3010. WFIFOL(fd,3) = tsd->status.char_id;
  3011. WFIFOW(fd,7) = tsd->status.base_level;
  3012. WFIFOSET(fd,packet_len(0x1f5));
  3013. }
  3014. }
  3015. /// Notifies the client about an item from other player in current trade.
  3016. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3017. /// 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)
  3018. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3019. {
  3020. int fd;
  3021. unsigned char *buf;
  3022. #if PACKETVER < 20100223
  3023. const int cmd = 0xe9;
  3024. #else
  3025. const int cmd = 0x80f;
  3026. #endif
  3027. nullpo_retv(sd);
  3028. nullpo_retv(tsd);
  3029. fd = tsd->fd;
  3030. buf = WFIFOP(fd,0);
  3031. WFIFOHEAD(fd,packet_len(cmd));
  3032. WBUFW(buf,0) = cmd;
  3033. if( index == 0 )
  3034. {
  3035. #if PACKETVER < 20100223
  3036. WBUFL(buf,2) = amount; //amount
  3037. WBUFW(buf,6) = 0; // type id
  3038. #else
  3039. WBUFW(buf,2) = 0; // type id
  3040. WBUFB(buf,4) = 0; // item type
  3041. WBUFL(buf,5) = amount; // amount
  3042. buf = WBUFP(buf,1); //Advance 1B
  3043. #endif
  3044. WBUFB(buf,8) = 0; //identify flag
  3045. WBUFB(buf,9) = 0; // attribute
  3046. WBUFB(buf,10)= 0; //refine
  3047. WBUFW(buf,11)= 0; //card (4w)
  3048. WBUFW(buf,13)= 0; //card (4w)
  3049. WBUFW(buf,15)= 0; //card (4w)
  3050. WBUFW(buf,17)= 0; //card (4w)
  3051. }
  3052. else
  3053. {
  3054. index -= 2; //index fix
  3055. #if PACKETVER < 20100223
  3056. WBUFL(buf,2) = amount; //amount
  3057. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3058. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3059. else
  3060. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3061. #else
  3062. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3063. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3064. else
  3065. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3066. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3067. WBUFL(buf,5) = amount; // amount
  3068. buf = WBUFP(buf,1); //Advance 1B
  3069. #endif
  3070. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3071. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3072. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3073. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3074. }
  3075. WFIFOSET(fd,packet_len(cmd));
  3076. }
  3077. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3078. /// 00ea <index>.W <result>.B
  3079. /// result:
  3080. /// 0 = success
  3081. /// 1 = overweight
  3082. /// 2 = trade canceled
  3083. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3084. {
  3085. int fd;
  3086. nullpo_retv(sd);
  3087. fd = sd->fd;
  3088. WFIFOHEAD(fd,packet_len(0xea));
  3089. WFIFOW(fd,0) = 0xea;
  3090. WFIFOW(fd,2) = index;
  3091. WFIFOB(fd,4) = fail;
  3092. WFIFOSET(fd,packet_len(0xea));
  3093. }
  3094. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3095. /// 00ec <who>.B
  3096. /// who:
  3097. /// 0 = self
  3098. /// 1 = other player
  3099. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3100. {
  3101. int fd;
  3102. nullpo_retv(sd);
  3103. fd = sd->fd;
  3104. WFIFOHEAD(fd,packet_len(0xec));
  3105. WFIFOW(fd,0) = 0xec;
  3106. WFIFOB(fd,2) = fail;
  3107. WFIFOSET(fd,packet_len(0xec));
  3108. }
  3109. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3110. /// 00ee
  3111. void clif_tradecancelled(struct map_session_data* sd)
  3112. {
  3113. int fd;
  3114. nullpo_retv(sd);
  3115. fd = sd->fd;
  3116. WFIFOHEAD(fd,packet_len(0xee));
  3117. WFIFOW(fd,0) = 0xee;
  3118. WFIFOSET(fd,packet_len(0xee));
  3119. }
  3120. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3121. /// 00f0 <result>.B
  3122. /// result:
  3123. /// 0 = success
  3124. /// 1 = failure
  3125. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3126. {
  3127. int fd;
  3128. nullpo_retv(sd);
  3129. fd = sd->fd;
  3130. WFIFOHEAD(fd,packet_len(0xf0));
  3131. WFIFOW(fd,0) = 0xf0;
  3132. WFIFOB(fd,2) = fail;
  3133. WFIFOSET(fd,packet_len(0xf0));
  3134. }
  3135. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3136. /// 00f1
  3137. /// NOTE: Unknown purpose. Items are not removed until the window is
  3138. /// refreshed (ex. by putting another item in there).
  3139. void clif_tradeundo(struct map_session_data* sd)
  3140. {
  3141. int fd = sd->fd;
  3142. WFIFOHEAD(fd,packet_len(0xf1));
  3143. WFIFOW(fd,0) = 0xf1;
  3144. WFIFOSET(fd,packet_len(0xf1));
  3145. }
  3146. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3147. /// 00f2 <current count>.W <max count>.W
  3148. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3149. {
  3150. int fd;
  3151. nullpo_retv(sd);
  3152. fd=sd->fd;
  3153. WFIFOHEAD(fd,packet_len(0xf2));
  3154. WFIFOW(fd,0) = 0xf2;
  3155. WFIFOW(fd,2) = amount;
  3156. WFIFOW(fd,4) = max_amount;
  3157. WFIFOSET(fd,packet_len(0xf2));
  3158. }
  3159. /// Notifies the client of an item being added to the storage.
  3160. /// 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)
  3161. /// 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)
  3162. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3163. {
  3164. int view,fd;
  3165. nullpo_retv(sd);
  3166. nullpo_retv(i);
  3167. fd=sd->fd;
  3168. view = itemdb_viewid(i->nameid);
  3169. WFIFOHEAD(fd,packet_len(0x1c4));
  3170. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3171. WFIFOW(fd, 2) = index+1; // index
  3172. WFIFOL(fd, 4) = amount; // amount
  3173. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3174. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3175. WFIFOB(fd,11) = i->identify; //identify flag
  3176. WFIFOB(fd,12) = i->attribute; // attribute
  3177. WFIFOB(fd,13) = i->refine; //refine
  3178. clif_addcards(WFIFOP(fd,14), i);
  3179. WFIFOSET(fd,packet_len(0x1c4));
  3180. }
  3181. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3182. /// 00f6 <index>.W <amount>.L
  3183. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3184. {
  3185. int fd;
  3186. nullpo_retv(sd);
  3187. fd=sd->fd;
  3188. WFIFOHEAD(fd,packet_len(0xf6));
  3189. WFIFOW(fd,0)=0xf6; // Storage item removed
  3190. WFIFOW(fd,2)=index+1;
  3191. WFIFOL(fd,4)=amount;
  3192. WFIFOSET(fd,packet_len(0xf6));
  3193. }
  3194. /// Closes storage (ZC_CLOSE_STORE).
  3195. /// 00f8
  3196. void clif_storageclose(struct map_session_data* sd)
  3197. {
  3198. int fd;
  3199. nullpo_retv(sd);
  3200. fd=sd->fd;
  3201. WFIFOHEAD(fd,packet_len(0xf8));
  3202. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3203. WFIFOSET(fd,packet_len(0xf8));
  3204. }
  3205. /*==========================================
  3206. * Server tells 'sd' player client the abouts of 'dstsd' player
  3207. *------------------------------------------*/
  3208. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3209. {
  3210. struct block_list *d_bl;
  3211. int i;
  3212. if( dstsd->chatID ) {
  3213. struct chat_data *cd = NULL;
  3214. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3215. clif_dispchat(cd,sd->fd);
  3216. } else if( dstsd->state.vending )
  3217. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3218. else if( dstsd->state.buyingstore )
  3219. clif_buyingstore_entry_single(sd, dstsd);
  3220. if(dstsd->spiritball > 0)
  3221. clif_spiritball_single(sd->fd, dstsd);
  3222. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3223. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3224. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3225. }
  3226. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3227. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3228. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3229. )
  3230. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3231. // display link (sd - dstsd) to sd
  3232. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3233. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3234. // display links (dstsd - devotees) to sd
  3235. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3236. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3237. // display link (dstsd - crusader) to sd
  3238. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3239. clif_devotion(d_bl, sd);
  3240. }
  3241. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3242. {
  3243. uint8 buf[128];
  3244. struct unit_data *ud;
  3245. struct view_data *vd;
  3246. int len;
  3247. vd = status_get_viewdata(bl);
  3248. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3249. return;
  3250. /**
  3251. * Hide NPC from maya purple card.
  3252. **/
  3253. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3254. return;
  3255. ud = unit_bl2ud(bl);
  3256. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3257. clif_send(buf,len,&sd->bl,SELF);
  3258. if (vd->cloth_color)
  3259. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3260. switch (bl->type)
  3261. {
  3262. case BL_PC:
  3263. {
  3264. TBL_PC* tsd = (TBL_PC*)bl;
  3265. clif_getareachar_pc(sd, tsd);
  3266. if(tsd->state.size==2) // tiny/big players [Valaris]
  3267. clif_specialeffect_single(bl,423,sd->fd);
  3268. else if(tsd->state.size==1)
  3269. clif_specialeffect_single(bl,421,sd->fd);
  3270. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3271. clif_sendbgemblem_single(sd->fd,tsd);
  3272. }
  3273. break;
  3274. case BL_MER: // Devotion Effects
  3275. if( ((TBL_MER*)bl)->devotion_flag )
  3276. clif_devotion(bl, sd);
  3277. break;
  3278. case BL_NPC:
  3279. {
  3280. TBL_NPC* nd = (TBL_NPC*)bl;
  3281. if( nd->chat_id )
  3282. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3283. if( nd->size == 2 )
  3284. clif_specialeffect_single(bl,423,sd->fd);
  3285. else if( nd->size == 1 )
  3286. clif_specialeffect_single(bl,421,sd->fd);
  3287. }
  3288. break;
  3289. case BL_MOB:
  3290. {
  3291. TBL_MOB* md = (TBL_MOB*)bl;
  3292. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3293. clif_specialeffect_single(bl,423,sd->fd);
  3294. else if(md->special_state.size==1)
  3295. clif_specialeffect_single(bl,421,sd->fd);
  3296. }
  3297. break;
  3298. case BL_PET:
  3299. if (vd->head_bottom)
  3300. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3301. break;
  3302. }
  3303. }
  3304. //Modifies the type of damage according to status changes [Skotlex]
  3305. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3306. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3307. {
  3308. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3309. }
  3310. /*==========================================
  3311. * Estimates walk delay based on the damage criteria. [Skotlex]
  3312. *------------------------------------------*/
  3313. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3314. {
  3315. if (type == 4 || type == 9 || damage <=0)
  3316. return 0;
  3317. if (bl->type == BL_PC) {
  3318. if (battle_config.pc_walk_delay_rate != 100)
  3319. delay = delay*battle_config.pc_walk_delay_rate/100;
  3320. } else
  3321. if (battle_config.walk_delay_rate != 100)
  3322. delay = delay*battle_config.walk_delay_rate/100;
  3323. if (div_ > 1) //Multi-hit skills mean higher delays.
  3324. delay += battle_config.multihit_delay*(div_-1);
  3325. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3326. }
  3327. /// Sends a 'damage' packet (src performs action on dst)
  3328. /// 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)
  3329. /// 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)
  3330. /// type:
  3331. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3332. /// 1 = pick up item
  3333. /// 2 = sit down
  3334. /// 3 = stand up
  3335. /// 4 = damage (endure)
  3336. /// 5 = (splash?)
  3337. /// 6 = (skill?)
  3338. /// 7 = (repeat damage?)
  3339. /// 8 = multi-hit damage
  3340. /// 9 = multi-hit damage (endure)
  3341. /// 10 = critical hit
  3342. /// 11 = lucky dodge
  3343. /// 12 = (touch skill?)
  3344. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
  3345. {
  3346. unsigned char buf[33];
  3347. struct status_change *sc;
  3348. const int cmd = 0x2e1;
  3349. nullpo_ret(src);
  3350. nullpo_ret(dst);
  3351. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3352. sc = status_get_sc(dst);
  3353. if(sc && sc->count) {
  3354. if(sc->data[SC_HALLUCINATION]) {
  3355. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3356. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3357. }
  3358. }
  3359. WBUFW(buf,0)=cmd;
  3360. WBUFL(buf,2)=src->id;
  3361. WBUFL(buf,6)=dst->id;
  3362. WBUFL(buf,10)=tick;
  3363. WBUFL(buf,14)=sdelay;
  3364. WBUFL(buf,18)=ddelay;
  3365. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3366. WBUFL(buf,22)=damage?div:0;
  3367. WBUFL(buf,29)=damage2?div:0;
  3368. } else {
  3369. WBUFL(buf,22)=damage;
  3370. WBUFL(buf,29)=damage2;
  3371. }
  3372. WBUFW(buf,26)=div;
  3373. WBUFB(buf,28)=type;
  3374. if(disguised(dst)) {
  3375. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3376. WBUFL(buf,6) = -dst->id;
  3377. clif_send(buf,packet_len(cmd),dst,SELF);
  3378. } else
  3379. clif_send(buf,packet_len(cmd),dst,AREA);
  3380. if(disguised(src)) {
  3381. WBUFL(buf,2) = -src->id;
  3382. if (disguised(dst))
  3383. WBUFL(buf,6) = dst->id;
  3384. if(damage > 0) WBUFL(buf,22) = -1;
  3385. if(damage2 > 0) WBUFL(buf,29) = -1;
  3386. clif_send(buf,packet_len(cmd),src,SELF);
  3387. }
  3388. //Return adjusted can't walk delay for further processing.
  3389. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3390. }
  3391. /*==========================================
  3392. * src picks up dst
  3393. *------------------------------------------*/
  3394. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3395. {
  3396. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3397. unsigned char buf[32];
  3398. nullpo_retv(src);
  3399. nullpo_retv(dst);
  3400. WBUFW(buf, 0) = 0x8a;
  3401. WBUFL(buf, 2) = src->id;
  3402. WBUFL(buf, 6) = dst->id;
  3403. WBUFB(buf,26) = 1;
  3404. clif_send(buf, packet_len(0x8a), src, AREA);
  3405. }
  3406. /*==========================================
  3407. * inform clients in area that `bl` is sitting
  3408. *------------------------------------------*/
  3409. void clif_sitting(struct block_list* bl)
  3410. {
  3411. unsigned char buf[32];
  3412. nullpo_retv(bl);
  3413. WBUFW(buf, 0) = 0x8a;
  3414. WBUFL(buf, 2) = bl->id;
  3415. WBUFB(buf,26) = 2;
  3416. clif_send(buf, packet_len(0x8a), bl, AREA);
  3417. if(disguised(bl)) {
  3418. WBUFL(buf, 2) = - bl->id;
  3419. clif_send(buf, packet_len(0x8a), bl, SELF);
  3420. }
  3421. }
  3422. /*==========================================
  3423. * inform clients in area that `bl` is standing
  3424. *------------------------------------------*/
  3425. void clif_standing(struct block_list* bl)
  3426. {
  3427. unsigned char buf[32];
  3428. nullpo_retv(bl);
  3429. WBUFW(buf, 0) = 0x8a;
  3430. WBUFL(buf, 2) = bl->id;
  3431. WBUFB(buf,26) = 3;
  3432. clif_send(buf, packet_len(0x8a), bl, AREA);
  3433. if(disguised(bl)) {
  3434. WBUFL(buf, 2) = - bl->id;
  3435. clif_send(buf, packet_len(0x8a), bl, SELF);
  3436. }
  3437. }
  3438. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3439. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3440. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3441. {
  3442. unsigned char buf[32];
  3443. WBUFW(buf,0) = 0x192;
  3444. WBUFW(buf,2) = x;
  3445. WBUFW(buf,4) = y;
  3446. WBUFW(buf,6) = type;
  3447. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3448. if( fd )
  3449. {
  3450. WFIFOHEAD(fd,packet_len(0x192));
  3451. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3452. WFIFOSET(fd,packet_len(0x192));
  3453. }
  3454. else
  3455. {
  3456. struct block_list dummy_bl;
  3457. dummy_bl.type = BL_NUL;
  3458. dummy_bl.x = x;
  3459. dummy_bl.y = y;
  3460. dummy_bl.m = m;
  3461. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3462. }
  3463. }
  3464. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3465. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3466. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3467. {
  3468. int view,fd;
  3469. fd=sd->fd;
  3470. WFIFOHEAD(fd,packet_len(0x9d));
  3471. WFIFOW(fd,0)=0x9d;
  3472. WFIFOL(fd,2)=fitem->bl.id;
  3473. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3474. WFIFOW(fd,6)=view;
  3475. else
  3476. WFIFOW(fd,6)=fitem->item_data.nameid;
  3477. WFIFOB(fd,8)=fitem->item_data.identify;
  3478. WFIFOW(fd,9)=fitem->bl.x;
  3479. WFIFOW(fd,11)=fitem->bl.y;
  3480. WFIFOW(fd,13)=fitem->item_data.amount;
  3481. WFIFOB(fd,15)=fitem->subx;
  3482. WFIFOB(fd,16)=fitem->suby;
  3483. WFIFOSET(fd,packet_len(0x9d));
  3484. }
  3485. /// Notifies the client of a skill unit.
  3486. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3487. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3488. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3489. {
  3490. int fd = sd->fd;
  3491. if( unit->group->state.guildaura )
  3492. return;
  3493. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3494. WFIFOHEAD(fd,packet_len(0x1c9));
  3495. WFIFOW(fd, 0)=0x1c9;
  3496. WFIFOL(fd, 2)=unit->bl.id;
  3497. WFIFOL(fd, 6)=unit->group->src_id;
  3498. WFIFOW(fd,10)=unit->bl.x;
  3499. WFIFOW(fd,12)=unit->bl.y;
  3500. WFIFOB(fd,14)=unit->group->unit_id;
  3501. WFIFOB(fd,15)=1;
  3502. WFIFOB(fd,16)=1;
  3503. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3504. WFIFOSET(fd,packet_len(0x1c9));
  3505. return;
  3506. }
  3507. WFIFOHEAD(fd,packet_len(0x11f));
  3508. WFIFOW(fd, 0)=0x11f;
  3509. WFIFOL(fd, 2)=unit->bl.id;
  3510. WFIFOL(fd, 6)=unit->group->src_id;
  3511. WFIFOW(fd,10)=unit->bl.x;
  3512. WFIFOW(fd,12)=unit->bl.y;
  3513. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3514. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3515. else
  3516. WFIFOB(fd,14)=unit->group->unit_id;
  3517. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3518. WFIFOSET(fd,packet_len(0x11f));
  3519. if(unit->group->skill_id == WZ_ICEWALL)
  3520. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3521. }
  3522. /*==========================================
  3523. * Server tells client to remove unit of id 'unit->bl.id'
  3524. *------------------------------------------*/
  3525. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3526. {
  3527. nullpo_retv(unit);
  3528. WFIFOHEAD(fd,packet_len(0x120));
  3529. WFIFOW(fd, 0)=0x120;
  3530. WFIFOL(fd, 2)=unit->bl.id;
  3531. WFIFOSET(fd,packet_len(0x120));
  3532. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3533. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3534. }
  3535. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3536. /// 0120 <id>.L
  3537. void clif_skill_delunit(struct skill_unit *unit)
  3538. {
  3539. unsigned char buf[16];
  3540. nullpo_retv(unit);
  3541. WBUFW(buf, 0)=0x120;
  3542. WBUFL(buf, 2)=unit->bl.id;
  3543. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3544. }
  3545. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3546. /// 01ac <id>.L
  3547. /// Only affects units with class [139,153] client-side.
  3548. void clif_skillunit_update(struct block_list* bl)
  3549. {
  3550. unsigned char buf[6];
  3551. nullpo_retv(bl);
  3552. WBUFW(buf,0) = 0x1ac;
  3553. WBUFL(buf,2) = bl->id;
  3554. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3555. }
  3556. /*==========================================
  3557. *
  3558. *------------------------------------------*/
  3559. static int clif_getareachar(struct block_list* bl,va_list ap)
  3560. {
  3561. struct map_session_data *sd;
  3562. nullpo_ret(bl);
  3563. sd=va_arg(ap,struct map_session_data*);
  3564. if (sd == NULL || !sd->fd)
  3565. return 0;
  3566. switch(bl->type){
  3567. case BL_ITEM:
  3568. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3569. break;
  3570. case BL_SKILL:
  3571. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3572. break;
  3573. default:
  3574. if(&sd->bl == bl)
  3575. break;
  3576. clif_getareachar_unit(sd,bl);
  3577. break;
  3578. }
  3579. return 0;
  3580. }
  3581. /*==========================================
  3582. * tbl has gone out of view-size of bl
  3583. *------------------------------------------*/
  3584. int clif_outsight(struct block_list *bl,va_list ap)
  3585. {
  3586. struct block_list *tbl;
  3587. struct view_data *vd;
  3588. TBL_PC *sd, *tsd;
  3589. tbl=va_arg(ap,struct block_list*);
  3590. if(bl == tbl) return 0;
  3591. sd = BL_CAST(BL_PC, bl);
  3592. tsd = BL_CAST(BL_PC, tbl);
  3593. if (tsd && tsd->fd)
  3594. { //tsd has lost sight of the bl object.
  3595. switch(bl->type){
  3596. case BL_PC:
  3597. if (sd->vd.class_ != INVISIBLE_CLASS)
  3598. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3599. if(sd->chatID){
  3600. struct chat_data *cd;
  3601. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3602. if(cd->usersd[0]==sd)
  3603. clif_dispchat(cd,tsd->fd);
  3604. }
  3605. if( sd->state.vending )
  3606. clif_closevendingboard(bl,tsd->fd);
  3607. if( sd->state.buyingstore )
  3608. clif_buyingstore_disappear_entry_single(tsd, sd);
  3609. break;
  3610. case BL_ITEM:
  3611. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3612. break;
  3613. case BL_SKILL:
  3614. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3615. break;
  3616. case BL_NPC:
  3617. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  3618. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3619. break;
  3620. default:
  3621. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3622. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3623. break;
  3624. }
  3625. }
  3626. if (sd && sd->fd)
  3627. { //sd is watching tbl go out of view.
  3628. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  3629. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  3630. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3631. }
  3632. return 0;
  3633. }
  3634. /*==========================================
  3635. * tbl has come into view of bl
  3636. *------------------------------------------*/
  3637. int clif_insight(struct block_list *bl,va_list ap)
  3638. {
  3639. struct block_list *tbl;
  3640. TBL_PC *sd, *tsd;
  3641. tbl=va_arg(ap,struct block_list*);
  3642. if (bl == tbl) return 0;
  3643. sd = BL_CAST(BL_PC, bl);
  3644. tsd = BL_CAST(BL_PC, tbl);
  3645. if (tsd && tsd->fd)
  3646. { //Tell tsd that bl entered into his view
  3647. switch(bl->type){
  3648. case BL_ITEM:
  3649. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3650. break;
  3651. case BL_SKILL:
  3652. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3653. break;
  3654. default:
  3655. clif_getareachar_unit(tsd,bl);
  3656. break;
  3657. }
  3658. }
  3659. if (sd && sd->fd)
  3660. { //Tell sd that tbl walked into his view
  3661. clif_getareachar_unit(sd,tbl);
  3662. }
  3663. return 0;
  3664. }
  3665. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  3666. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  3667. void clif_skillinfoblock(struct map_session_data *sd)
  3668. {
  3669. int fd;
  3670. int i,len,id;
  3671. nullpo_retv(sd);
  3672. fd=sd->fd;
  3673. if (!fd) return;
  3674. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3675. WFIFOW(fd,0) = 0x10f;
  3676. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  3677. {
  3678. if( (id = sd->status.skill[i].id) != 0 )
  3679. {
  3680. // workaround for bugreport:5348
  3681. if (len + 37 > 8192)
  3682. break;
  3683. WFIFOW(fd,len) = id;
  3684. WFIFOL(fd,len+2) = skill_get_inf(id);
  3685. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3686. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3687. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3688. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3689. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  3690. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3691. else
  3692. WFIFOB(fd,len+36) = 0;
  3693. len += 37;
  3694. }
  3695. }
  3696. WFIFOW(fd,2)=len;
  3697. WFIFOSET(fd,len);
  3698. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  3699. for ( ; i < MAX_SKILL; i++)
  3700. {
  3701. if( (id = sd->status.skill[i].id) != 0 )
  3702. {
  3703. clif_addskill(sd, id);
  3704. clif_skillinfo(sd, id, 0);
  3705. }
  3706. }
  3707. }
  3708. /**
  3709. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  3710. **/
  3711. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  3712. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  3713. void clif_addskill(struct map_session_data *sd, int id)
  3714. {
  3715. int fd;
  3716. nullpo_retv(sd);
  3717. fd = sd->fd;
  3718. if (!fd) return;
  3719. if( sd->status.skill[id].id <= 0 )
  3720. return;
  3721. WFIFOHEAD(fd, packet_len(0x111));
  3722. WFIFOW(fd,0) = 0x111;
  3723. WFIFOW(fd,2) = id;
  3724. WFIFOL(fd,4) = skill_get_inf(id);
  3725. WFIFOW(fd,8) = sd->status.skill[id].lv;
  3726. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  3727. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  3728. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3729. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  3730. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3731. else
  3732. WFIFOB(fd,38) = 0;
  3733. WFIFOSET(fd,packet_len(0x111));
  3734. }
  3735. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  3736. /// 0441 <skill id>.W
  3737. void clif_deleteskill(struct map_session_data *sd, int id)
  3738. {
  3739. int fd;
  3740. nullpo_retv(sd);
  3741. fd = sd->fd;
  3742. if( !fd ) return;
  3743. WFIFOHEAD(fd,packet_len(0x441));
  3744. WFIFOW(fd,0) = 0x441;
  3745. WFIFOW(fd,2) = id;
  3746. WFIFOSET(fd,packet_len(0x441));
  3747. }
  3748. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  3749. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  3750. void clif_skillup(struct map_session_data *sd,int skill_num)
  3751. {
  3752. int fd;
  3753. nullpo_retv(sd);
  3754. fd=sd->fd;
  3755. WFIFOHEAD(fd,packet_len(0x10e));
  3756. WFIFOW(fd,0) = 0x10e;
  3757. WFIFOW(fd,2) = skill_num;
  3758. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3759. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3760. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3761. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3762. WFIFOSET(fd,packet_len(0x10e));
  3763. }
  3764. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  3765. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  3766. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  3767. {
  3768. const int fd = sd->fd;
  3769. WFIFOHEAD(fd,packet_len(0x7e1));
  3770. WFIFOW(fd,0) = 0x7e1;
  3771. WFIFOW(fd,2) = skill;
  3772. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  3773. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  3774. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  3775. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  3776. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  3777. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  3778. else
  3779. WFIFOB(fd,14) = 0;
  3780. WFIFOSET(fd,packet_len(0x7e1));
  3781. }
  3782. /// Notifies clients in area, that an object is about to use a skill.
  3783. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  3784. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  3785. /// property:
  3786. /// 0 = Yellow cast aura
  3787. /// 1 = Water elemental cast aura
  3788. /// 2 = Earth elemental cast aura
  3789. /// 3 = Fire elemental cast aura
  3790. /// 4 = Wind elemental cast aura
  3791. /// 5 = Poison elemental cast aura
  3792. /// 6 = Holy elemental cast aura
  3793. /// ? = like 0
  3794. /// is disposable:
  3795. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  3796. /// 1 = no text
  3797. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, int skill_num, int property, int casttime)
  3798. {
  3799. const int cmd = 0x7fb;
  3800. unsigned char buf[32];
  3801. WBUFW(buf,0) = cmd;
  3802. WBUFL(buf,2) = src_id;
  3803. WBUFL(buf,6) = dst_id;
  3804. WBUFW(buf,10) = dst_x;
  3805. WBUFW(buf,12) = dst_y;
  3806. WBUFW(buf,14) = skill_num;
  3807. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  3808. WBUFL(buf,20) = casttime;
  3809. WBUFB(buf,24) = 0; // isDisposable
  3810. if (disguised(bl)) {
  3811. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  3812. WBUFL(buf,2) = -src_id;
  3813. clif_send(buf,packet_len(cmd), bl, SELF);
  3814. } else
  3815. clif_send(buf,packet_len(cmd), bl, AREA);
  3816. }
  3817. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  3818. /// 01b9 <id>.L
  3819. void clif_skillcastcancel(struct block_list* bl)
  3820. {
  3821. unsigned char buf[16];
  3822. nullpo_retv(bl);
  3823. WBUFW(buf,0) = 0x1b9;
  3824. WBUFL(buf,2) = bl->id;
  3825. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3826. }
  3827. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  3828. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  3829. /// num (only used when skill id = NV_BASIC and cause = 0):
  3830. /// 0 = "skill failed" MsgStringTable[159]
  3831. /// 1 = "no emotions" MsgStringTable[160]
  3832. /// 2 = "no sit" MsgStringTable[161]
  3833. /// 3 = "no chat" MsgStringTable[162]
  3834. /// 4 = "no party" MsgStringTable[163]
  3835. /// 5 = "no shout" MsgStringTable[164]
  3836. /// 6 = "no PKing" MsgStringTable[165]
  3837. /// 7 = "no alligning" MsgStringTable[383]
  3838. /// ? = ignored
  3839. /// cause:
  3840. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  3841. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  3842. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  3843. /// "skill failed" MsgStringTable[204] (otherwise)
  3844. /// ... = @see enum useskill_fail_cause
  3845. /// ? = ignored
  3846. ///
  3847. /// if(result!=0) doesn't display any of the previous messages
  3848. /// Note: when this packet is received an unknown flag is always set to 0,
  3849. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3850. void clif_skill_fail(struct map_session_data *sd,int skill_id,enum useskill_fail_cause cause,int btype)
  3851. {
  3852. int fd;
  3853. if (!sd) { //Since this is the most common nullpo....
  3854. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3855. return;
  3856. }
  3857. fd=sd->fd;
  3858. if (!fd) return;
  3859. if(battle_config.display_skill_fail&1)
  3860. return; //Disable all skill failed messages
  3861. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  3862. return; //Disable delay failed messages
  3863. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3864. return;
  3865. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3866. return;
  3867. WFIFOHEAD(fd,packet_len(0x110));
  3868. WFIFOW(fd,0) = 0x110;
  3869. WFIFOW(fd,2) = skill_id;
  3870. WFIFOL(fd,4) = btype;
  3871. WFIFOB(fd,8) = 0;// success
  3872. WFIFOB(fd,9) = cause;
  3873. WFIFOSET(fd,packet_len(0x110));
  3874. }
  3875. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  3876. /// 043d <skill ID>.W <tick>.L
  3877. void clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  3878. {
  3879. int fd;
  3880. nullpo_retv(sd);
  3881. fd=sd->fd;
  3882. WFIFOHEAD(fd,packet_len(0x43d));
  3883. WFIFOW(fd,0) = 0x43d;
  3884. WFIFOW(fd,2) = skillid;
  3885. WFIFOL(fd,4) = tick;
  3886. WFIFOSET(fd,packet_len(0x43d));
  3887. }
  3888. /// Skill attack effect and damage.
  3889. /// 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)
  3890. /// 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)
  3891. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3892. {
  3893. unsigned char buf[64];
  3894. struct status_change *sc;
  3895. nullpo_ret(src);
  3896. nullpo_ret(dst);
  3897. type = clif_calc_delay(type,div,damage,ddelay);
  3898. sc = status_get_sc(dst);
  3899. if(sc && sc->count) {
  3900. if(sc->data[SC_HALLUCINATION] && damage)
  3901. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3902. }
  3903. WBUFW(buf,0)=0x1de;
  3904. WBUFW(buf,2)=skill_id;
  3905. WBUFL(buf,4)=src->id;
  3906. WBUFL(buf,8)=dst->id;
  3907. WBUFL(buf,12)=tick;
  3908. WBUFL(buf,16)=sdelay;
  3909. WBUFL(buf,20)=ddelay;
  3910. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3911. WBUFL(buf,24)=damage?div:0;
  3912. } else {
  3913. WBUFL(buf,24)=damage;
  3914. }
  3915. WBUFW(buf,28)=skill_lv;
  3916. WBUFW(buf,30)=div;
  3917. WBUFB(buf,32)=type;
  3918. if (disguised(dst)) {
  3919. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3920. WBUFL(buf,8)=-dst->id;
  3921. clif_send(buf,packet_len(0x1de),dst,SELF);
  3922. } else
  3923. clif_send(buf,packet_len(0x1de),dst,AREA);
  3924. if(disguised(src)) {
  3925. WBUFL(buf,4)=-src->id;
  3926. if (disguised(dst))
  3927. WBUFL(buf,8)=dst->id;
  3928. if(damage > 0)
  3929. WBUFL(buf,24)=-1;
  3930. clif_send(buf,packet_len(0x1de),src,SELF);
  3931. }
  3932. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3933. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3934. }
  3935. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  3936. /// 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
  3937. /*
  3938. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3939. {
  3940. unsigned char buf[64];
  3941. struct status_change *sc;
  3942. nullpo_ret(src);
  3943. nullpo_ret(dst);
  3944. type = (type>0)?type:skill_get_hit(skill_id);
  3945. type = clif_calc_delay(type,div,damage,ddelay);
  3946. sc = status_get_sc(dst);
  3947. if(sc && sc->count) {
  3948. if(sc->data[SC_HALLUCINATION] && damage)
  3949. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3950. }
  3951. WBUFW(buf,0)=0x115;
  3952. WBUFW(buf,2)=skill_id;
  3953. WBUFL(buf,4)=src->id;
  3954. WBUFL(buf,8)=dst->id;
  3955. WBUFL(buf,12)=tick;
  3956. WBUFL(buf,16)=sdelay;
  3957. WBUFL(buf,20)=ddelay;
  3958. WBUFW(buf,24)=dst->x;
  3959. WBUFW(buf,26)=dst->y;
  3960. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3961. WBUFW(buf,28)=damage?div:0;
  3962. } else {
  3963. WBUFW(buf,28)=damage;
  3964. }
  3965. WBUFW(buf,30)=skill_lv;
  3966. WBUFW(buf,32)=div;
  3967. WBUFB(buf,34)=type;
  3968. clif_send(buf,packet_len(0x115),src,AREA);
  3969. if(disguised(src)) {
  3970. WBUFL(buf,4)=-src->id;
  3971. if(damage > 0)
  3972. WBUFW(buf,28)=-1;
  3973. clif_send(buf,packet_len(0x115),src,SELF);
  3974. }
  3975. if (disguised(dst)) {
  3976. WBUFL(buf,8)=-dst->id;
  3977. if (disguised(src))
  3978. WBUFL(buf,4)=src->id;
  3979. else if(damage > 0)
  3980. WBUFW(buf,28)=-1;
  3981. clif_send(buf,packet_len(0x115),dst,SELF);
  3982. }
  3983. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3984. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3985. }
  3986. */
  3987. /// Non-damaging skill effect (ZC_USE_SKILL).
  3988. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  3989. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3990. {
  3991. unsigned char buf[32];
  3992. nullpo_ret(dst);
  3993. WBUFW(buf,0)=0x11a;
  3994. WBUFW(buf,2)=skill_id;
  3995. WBUFW(buf,4)=min(heal, INT16_MAX);
  3996. WBUFL(buf,6)=dst->id;
  3997. WBUFL(buf,10)=src?src->id:0;
  3998. WBUFB(buf,14)=fail;
  3999. if (disguised(dst)) {
  4000. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4001. WBUFL(buf,6)=-dst->id;
  4002. clif_send(buf,packet_len(0x11a),dst,SELF);
  4003. } else
  4004. clif_send(buf,packet_len(0x11a),dst,AREA);
  4005. if(src && disguised(src)) {
  4006. WBUFL(buf,10)=-src->id;
  4007. if (disguised(dst))
  4008. WBUFL(buf,6)=dst->id;
  4009. clif_send(buf,packet_len(0x11a),src,SELF);
  4010. }
  4011. return fail;
  4012. }
  4013. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4014. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4015. void clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4016. {
  4017. unsigned char buf[32];
  4018. nullpo_retv(src);
  4019. WBUFW(buf,0)=0x117;
  4020. WBUFW(buf,2)=skill_id;
  4021. WBUFL(buf,4)=src->id;
  4022. WBUFW(buf,8)=val;
  4023. WBUFW(buf,10)=x;
  4024. WBUFW(buf,12)=y;
  4025. WBUFL(buf,14)=tick;
  4026. if(disguised(src)) {
  4027. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4028. WBUFL(buf,4)=-src->id;
  4029. clif_send(buf,packet_len(0x117),src,SELF);
  4030. } else
  4031. clif_send(buf,packet_len(0x117),src,AREA);
  4032. }
  4033. /*==========================================
  4034. * Tells all client's nearby 'unit' sight range that it spawned
  4035. *------------------------------------------*/
  4036. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4037. void clif_skill_setunit(struct skill_unit *unit)
  4038. {
  4039. unsigned char buf[128];
  4040. nullpo_retv(unit);
  4041. if( unit->group->state.guildaura )
  4042. return;
  4043. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4044. WBUFW(buf, 0)=0x1c9;
  4045. WBUFL(buf, 2)=unit->bl.id;
  4046. WBUFL(buf, 6)=unit->group->src_id;
  4047. WBUFW(buf,10)=unit->bl.x;
  4048. WBUFW(buf,12)=unit->bl.y;
  4049. WBUFB(buf,14)=unit->group->unit_id;
  4050. WBUFB(buf,15)=1;
  4051. WBUFB(buf,16)=1;
  4052. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4053. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4054. return;
  4055. }
  4056. WBUFW(buf, 0)=0x11f;
  4057. WBUFL(buf, 2)=unit->bl.id;
  4058. WBUFL(buf, 6)=unit->group->src_id;
  4059. WBUFW(buf,10)=unit->bl.x;
  4060. WBUFW(buf,12)=unit->bl.y;
  4061. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4062. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4063. else
  4064. WBUFB(buf,14)=unit->group->unit_id;
  4065. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4066. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4067. }
  4068. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4069. /// 011c <skill id>.W { <map name>.16B }*4
  4070. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4071. {
  4072. int fd;
  4073. nullpo_retv(sd);
  4074. fd = sd->fd;
  4075. WFIFOHEAD(fd,packet_len(0x11c));
  4076. WFIFOW(fd,0) = 0x11c;
  4077. WFIFOW(fd,2) = skill_num;
  4078. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4079. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4080. else // normal map name
  4081. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4082. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4083. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4084. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4085. WFIFOSET(fd,packet_len(0x11c));
  4086. sd->menuskill_id = skill_num;
  4087. if (skill_num == AL_WARP)
  4088. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4089. else
  4090. sd->menuskill_val = skill_lv;
  4091. }
  4092. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4093. /// 011e <type>.B
  4094. /// type:
  4095. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4096. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4097. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4098. ///
  4099. /// @param sd Who receives the message
  4100. /// @param type What message
  4101. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4102. {
  4103. int fd;
  4104. nullpo_retv(sd);
  4105. fd=sd->fd;
  4106. WFIFOHEAD(fd,packet_len(0x11e));
  4107. WFIFOW(fd,0)=0x11e;
  4108. WFIFOB(fd,2)=type;
  4109. WFIFOSET(fd,packet_len(0x11e));
  4110. }
  4111. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4112. /// 0189 <type>.W
  4113. /// type:
  4114. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4115. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4116. ///
  4117. /// @param sd Who receives the message
  4118. /// @param type What message
  4119. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4120. {
  4121. int fd;
  4122. nullpo_retv(sd);
  4123. fd=sd->fd;
  4124. WFIFOHEAD(fd,packet_len(0x189));
  4125. WFIFOW(fd,0)=0x189;
  4126. WFIFOW(fd,2)=type;
  4127. WFIFOSET(fd,packet_len(0x189));
  4128. }
  4129. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4130. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4131. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4132. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4133. {
  4134. struct status_data *status;
  4135. unsigned char buf[64];
  4136. int i;//, fix;
  4137. nullpo_retv(sd);
  4138. nullpo_retv(dst);
  4139. if( dst->type != BL_MOB )
  4140. return;
  4141. status = status_get_status_data(dst);
  4142. WBUFW(buf, 0)=0x18c;
  4143. WBUFW(buf, 2)=status_get_class(dst);
  4144. WBUFW(buf, 4)=status_get_lv(dst);
  4145. WBUFW(buf, 6)=status->size;
  4146. WBUFL(buf, 8)=status->hp;
  4147. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4148. +(battle_config.estimation_type&2?status->def2:0);
  4149. WBUFW(buf,14)=status->race;
  4150. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4151. +(battle_config.estimation_type&2?status->mdef2:0);
  4152. WBUFW(buf,18)= status->def_ele;
  4153. for(i=0;i<9;i++)
  4154. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4155. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4156. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4157. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4158. }
  4159. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4160. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4161. /// material id:
  4162. /// unused by the client
  4163. void clif_skill_produce_mix_list(struct map_session_data *sd, int skillid , int trigger)
  4164. {
  4165. int i,c,view,fd;
  4166. nullpo_retv(sd);
  4167. if(sd->menuskill_id == skillid)
  4168. return; //Avoid resending the menu twice or more times...
  4169. fd=sd->fd;
  4170. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4171. WFIFOW(fd, 0)=0x18d;
  4172. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4173. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4174. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4175. WFIFOW(fd,c*8+ 4)= view;
  4176. else
  4177. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4178. WFIFOW(fd,c*8+ 6)= 0;
  4179. WFIFOW(fd,c*8+ 8)= 0;
  4180. WFIFOW(fd,c*8+10)= 0;
  4181. c++;
  4182. }
  4183. }
  4184. WFIFOW(fd, 2)=c*8+8;
  4185. WFIFOSET(fd,WFIFOW(fd,2));
  4186. if(c > 0) {
  4187. sd->menuskill_id = skillid;
  4188. sd->menuskill_val = trigger;
  4189. return;
  4190. }
  4191. }
  4192. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4193. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4194. /// mk type:
  4195. /// 1 = cooking
  4196. /// 2 = arrow
  4197. /// 3 = elemental
  4198. /// 4 = GN_MIX_COOKING
  4199. /// 5 = GN_MAKEBOMB
  4200. /// 6 = GN_S_PHARMACY
  4201. void clif_cooking_list(struct map_session_data *sd, int trigger)
  4202. {
  4203. int fd;
  4204. int i, c;
  4205. int view;
  4206. nullpo_retv(sd);
  4207. fd = sd->fd;
  4208. WFIFOHEAD(fd, 6 + 2*MAX_SKILL_PRODUCE_DB);
  4209. WFIFOW(fd,0) = 0x25a;
  4210. WFIFOW(fd,4) = 1; // list type
  4211. c = 0;
  4212. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ )
  4213. {
  4214. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) )
  4215. continue;
  4216. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4217. WFIFOW(fd, 6+2*c)= view;
  4218. else
  4219. WFIFOW(fd, 6+2*c)= skill_produce_db[i].nameid;
  4220. c++;
  4221. }
  4222. WFIFOW(fd,2) = 6 + 2*c;
  4223. WFIFOSET(fd,WFIFOW(fd,2));
  4224. //TODO: replace with proper solution
  4225. if( c > 0 )
  4226. {
  4227. sd->menuskill_id = AM_PHARMACY;
  4228. sd->menuskill_val = trigger;
  4229. }
  4230. }
  4231. /// Notifies clients of a status change.
  4232. /// 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)]
  4233. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4234. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4235. {
  4236. unsigned char buf[32];
  4237. struct map_session_data *sd;
  4238. if (type == SI_BLANK) //It shows nothing on the client...
  4239. return;
  4240. nullpo_retv(bl);
  4241. sd = BL_CAST(BL_PC, bl);
  4242. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4243. return;
  4244. if(flag && battle_config.display_status_timers && sd)
  4245. WBUFW(buf,0)=0x43f;
  4246. else
  4247. WBUFW(buf,0)=0x196;
  4248. WBUFW(buf,2)=type;
  4249. WBUFL(buf,4)=bl->id;
  4250. WBUFB(buf,8)=flag;
  4251. if(flag && battle_config.display_status_timers && sd)
  4252. {
  4253. if (tick <= 0)
  4254. tick = 9999; // this is indeed what official servers do
  4255. WBUFL(buf,9) = tick;
  4256. WBUFL(buf,13) = val1;
  4257. WBUFL(buf,17) = val2;
  4258. WBUFL(buf,21) = val3;
  4259. }
  4260. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4261. }
  4262. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4263. /// 008e <packet len>.W <message>.?B
  4264. void clif_displaymessage(const int fd, const char* mes)
  4265. {
  4266. nullpo_retv(mes);
  4267. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4268. if (fd == 0)
  4269. ;
  4270. else {
  4271. char *message, *line;
  4272. message = aStrdup(mes);
  4273. line = strtok(message, "\n");
  4274. while(line != NULL) {
  4275. int len = strlen(line);
  4276. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4277. WFIFOHEAD(fd, 5 + len);
  4278. WFIFOW(fd,0) = 0x8e;
  4279. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4280. memcpy(WFIFOP(fd,4), line, len + 1);
  4281. WFIFOSET(fd, 5 + len);
  4282. }
  4283. line = strtok(NULL, "\n");
  4284. }
  4285. aFree(message);
  4286. }
  4287. }
  4288. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4289. /// 009a <packet len>.W <message>.?B
  4290. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4291. {
  4292. int lp = type ? 4 : 0;
  4293. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4294. WBUFW(buf,0) = 0x9a;
  4295. WBUFW(buf,2) = 4 + lp + len;
  4296. if (type == 0x10) // bc_blue
  4297. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4298. else if (type == 0x20) // bc_woe
  4299. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4300. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4301. clif_send(buf, WBUFW(buf,2), bl, target);
  4302. if (buf)
  4303. aFree(buf);
  4304. }
  4305. /*==========================================
  4306. * Displays a message on a 'bl' to all it's nearby clients
  4307. * Used by npc_globalmessage
  4308. *------------------------------------------*/
  4309. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4310. {
  4311. char buf[100];
  4312. int len;
  4313. nullpo_retv(bl);
  4314. if(!message)
  4315. return;
  4316. len = strlen(message)+1;
  4317. if( len > sizeof(buf)-8 )
  4318. {
  4319. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4320. len = sizeof(buf)-8;
  4321. }
  4322. WBUFW(buf,0)=0x8d;
  4323. WBUFW(buf,2)=len+8;
  4324. WBUFL(buf,4)=bl->id;
  4325. safestrncpy((char *) WBUFP(buf,8),message,len);
  4326. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4327. }
  4328. /*==========================================
  4329. * Send main chat message [LuzZza]
  4330. *------------------------------------------*/
  4331. void clif_MainChatMessage(const char* message)
  4332. {
  4333. uint8 buf[200];
  4334. int len;
  4335. if(!message)
  4336. return;
  4337. len = strlen(message)+1;
  4338. if (len+8 > sizeof(buf)) {
  4339. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4340. len = sizeof(buf)-8;
  4341. }
  4342. WBUFW(buf,0)=0x8d;
  4343. WBUFW(buf,2)=len+8;
  4344. WBUFL(buf,4)=0;
  4345. safestrncpy((char *) WBUFP(buf,8),message,len);
  4346. clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4347. }
  4348. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4349. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4350. 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)
  4351. {
  4352. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4353. WBUFW(buf,0) = 0x1c3;
  4354. WBUFW(buf,2) = len + 16;
  4355. WBUFL(buf,4) = fontColor;
  4356. WBUFW(buf,8) = fontType;
  4357. WBUFW(buf,10) = fontSize;
  4358. WBUFW(buf,12) = fontAlign;
  4359. WBUFW(buf,14) = fontY;
  4360. memcpy(WBUFP(buf,16), mes, len);
  4361. clif_send(buf, WBUFW(buf,2), bl, target);
  4362. if (buf)
  4363. aFree(buf);
  4364. }
  4365. /// Displays heal effect (ZC_RECOVERY).
  4366. /// 013d <var id>.W <amount>.W
  4367. /// var id:
  4368. /// 5 = HP (SP_HP)
  4369. /// 7 = SP (SP_SP)
  4370. /// ? = ignored
  4371. void clif_heal(int fd,int type,int val)
  4372. {
  4373. WFIFOHEAD(fd,packet_len(0x13d));
  4374. WFIFOW(fd,0)=0x13d;
  4375. WFIFOW(fd,2)=type;
  4376. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4377. WFIFOSET(fd,packet_len(0x13d));
  4378. }
  4379. /// Displays resurrection effect (ZC_RESURRECTION).
  4380. /// 0148 <id>.L <type>.W
  4381. /// type:
  4382. /// ignored
  4383. void clif_resurrection(struct block_list *bl,int type)
  4384. {
  4385. unsigned char buf[16];
  4386. nullpo_retv(bl);
  4387. WBUFW(buf,0)=0x148;
  4388. WBUFL(buf,2)=bl->id;
  4389. WBUFW(buf,6)=0;
  4390. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4391. if (disguised(bl))
  4392. clif_spawn(bl);
  4393. }
  4394. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4395. /// 0199 <type>.W
  4396. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4397. {
  4398. int fd;
  4399. nullpo_retv(sd);
  4400. fd=sd->fd;
  4401. WFIFOHEAD(fd,packet_len(0x199));
  4402. WFIFOW(fd,0)=0x199;
  4403. WFIFOW(fd,2)=property;
  4404. WFIFOSET(fd,packet_len(0x199));
  4405. }
  4406. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4407. /// 01d6 <type>.W
  4408. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4409. {
  4410. int fd;
  4411. nullpo_retv(sd);
  4412. fd=sd->fd;
  4413. WFIFOHEAD(fd,packet_len(0x1D6));
  4414. WFIFOW(fd,0)=0x1D6;
  4415. WFIFOW(fd,2)=type;
  4416. WFIFOSET(fd,packet_len(0x1D6));
  4417. }
  4418. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4419. /// 019a <id>.L <ranking>.L <total>.L
  4420. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4421. {
  4422. if(type == 2) {
  4423. int fd = sd->fd;
  4424. WFIFOHEAD(fd,packet_len(0x19a));
  4425. WFIFOW(fd,0) = 0x19a;
  4426. WFIFOL(fd,2) = sd->bl.id;
  4427. WFIFOL(fd,6) = pvprank;
  4428. WFIFOL(fd,10) = pvpnum;
  4429. WFIFOSET(fd,packet_len(0x19a));
  4430. } else {
  4431. unsigned char buf[32];
  4432. WBUFW(buf,0) = 0x19a;
  4433. WBUFL(buf,2) = sd->bl.id;
  4434. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4435. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4436. else
  4437. WBUFL(buf,6) = pvprank;
  4438. WBUFL(buf,10) = pvpnum;
  4439. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4440. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4441. else if(!type)
  4442. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4443. else
  4444. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4445. }
  4446. }
  4447. /*==========================================
  4448. *
  4449. *------------------------------------------*/
  4450. void clif_map_property_mapall(int map, enum map_property property)
  4451. {
  4452. struct block_list bl;
  4453. unsigned char buf[16];
  4454. bl.id = 0;
  4455. bl.type = BL_NUL;
  4456. bl.m = map;
  4457. WBUFW(buf,0)=0x199;
  4458. WBUFW(buf,2)=property;
  4459. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4460. }
  4461. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4462. /// 0188 <result>.W <index>.W <refine>.W
  4463. /// result:
  4464. /// 0 = success
  4465. /// 1 = failure
  4466. /// 2 = downgrade
  4467. void clif_refine(int fd, int fail, int index, int val)
  4468. {
  4469. WFIFOHEAD(fd,packet_len(0x188));
  4470. WFIFOW(fd,0)=0x188;
  4471. WFIFOW(fd,2)=fail;
  4472. WFIFOW(fd,4)=index+2;
  4473. WFIFOW(fd,6)=val;
  4474. WFIFOSET(fd,packet_len(0x188));
  4475. }
  4476. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4477. /// 0223 <result>.L <nameid>.W
  4478. /// result:
  4479. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4480. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4481. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4482. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4483. void clif_upgrademessage(int fd, int result, int item_id)
  4484. {
  4485. WFIFOHEAD(fd,packet_len(0x223));
  4486. WFIFOW(fd,0)=0x223;
  4487. WFIFOL(fd,2)=result;
  4488. WFIFOW(fd,6)=item_id;
  4489. WFIFOSET(fd,packet_len(0x223));
  4490. }
  4491. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4492. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4493. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4494. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4495. {
  4496. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4497. WFIFOW(fd,0) = 0x97;
  4498. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4499. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4500. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4501. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  4502. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4503. WFIFOSET(fd,WFIFOW(fd,2));
  4504. }
  4505. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  4506. /// 0098 <result>.B
  4507. /// result:
  4508. /// 0 = success to send wisper
  4509. /// 1 = target character is not loged in
  4510. /// 2 = ignored by target
  4511. /// 3 = everyone ignored by target
  4512. void clif_wis_end(int fd, int flag)
  4513. {
  4514. WFIFOHEAD(fd,packet_len(0x98));
  4515. WFIFOW(fd,0) = 0x98;
  4516. WFIFOW(fd,2) = flag;
  4517. WFIFOSET(fd,packet_len(0x98));
  4518. }
  4519. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  4520. /// 0194 <char id>.L <name>.24B
  4521. void clif_solved_charname(int fd, int charid, const char* name)
  4522. {
  4523. WFIFOHEAD(fd,packet_len(0x194));
  4524. WFIFOW(fd,0)=0x194;
  4525. WFIFOL(fd,2)=charid;
  4526. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4527. WFIFOSET(fd,packet_len(0x194));
  4528. }
  4529. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  4530. /// 017b <packet len>.W { <name id>.W }*
  4531. void clif_use_card(struct map_session_data *sd,int idx)
  4532. {
  4533. int i,c,ep;
  4534. int fd=sd->fd;
  4535. nullpo_retv(sd);
  4536. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4537. return;
  4538. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4539. return; //Avoid parsing invalid item indexes (no card/no item)
  4540. ep=sd->inventory_data[idx]->equip;
  4541. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4542. WFIFOW(fd,0)=0x17b;
  4543. for(i=c=0;i<MAX_INVENTORY;i++){
  4544. int j;
  4545. if(sd->inventory_data[i] == NULL)
  4546. continue;
  4547. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4548. continue;
  4549. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4550. continue;
  4551. if(sd->status.inventory[i].identify==0 ) //Not identified
  4552. continue;
  4553. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4554. continue;
  4555. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4556. continue;
  4557. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4558. if( j == sd->inventory_data[i]->slot ) // No room
  4559. continue;
  4560. WFIFOW(fd,4+c*2)=i+2;
  4561. c++;
  4562. }
  4563. WFIFOW(fd,2)=4+c*2;
  4564. WFIFOSET(fd,WFIFOW(fd,2));
  4565. }
  4566. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  4567. /// 017d <equip index>.W <card index>.W <result>.B
  4568. /// result:
  4569. /// 0 = success
  4570. /// 1 = failure
  4571. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4572. {
  4573. int fd;
  4574. nullpo_retv(sd);
  4575. fd=sd->fd;
  4576. WFIFOHEAD(fd,packet_len(0x17d));
  4577. WFIFOW(fd,0)=0x17d;
  4578. WFIFOW(fd,2)=idx_equip+2;
  4579. WFIFOW(fd,4)=idx_card+2;
  4580. WFIFOB(fd,6)=flag;
  4581. WFIFOSET(fd,packet_len(0x17d));
  4582. }
  4583. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  4584. /// 0177 <packet len>.W { <name id>.W }*
  4585. void clif_item_identify_list(struct map_session_data *sd)
  4586. {
  4587. int i,c;
  4588. int fd;
  4589. nullpo_retv(sd);
  4590. fd=sd->fd;
  4591. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4592. WFIFOW(fd,0)=0x177;
  4593. for(i=c=0;i<MAX_INVENTORY;i++){
  4594. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4595. WFIFOW(fd,c*2+4)=i+2;
  4596. c++;
  4597. }
  4598. }
  4599. if(c > 0) {
  4600. WFIFOW(fd,2)=c*2+4;
  4601. WFIFOSET(fd,WFIFOW(fd,2));
  4602. sd->menuskill_id = MC_IDENTIFY;
  4603. sd->menuskill_val = c;
  4604. }
  4605. }
  4606. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  4607. /// 0179 <index>.W <result>.B
  4608. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4609. {
  4610. int fd;
  4611. nullpo_retv(sd);
  4612. fd=sd->fd;
  4613. WFIFOHEAD(fd,packet_len(0x179));
  4614. WFIFOW(fd, 0)=0x179;
  4615. WFIFOW(fd, 2)=idx+2;
  4616. WFIFOB(fd, 4)=flag;
  4617. WFIFOSET(fd,packet_len(0x179));
  4618. }
  4619. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  4620. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  4621. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4622. {
  4623. int i,c;
  4624. int fd;
  4625. int nameid;
  4626. nullpo_retv(sd);
  4627. nullpo_retv(dstsd);
  4628. fd=sd->fd;
  4629. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4630. WFIFOW(fd,0)=0x1fc;
  4631. for(i=c=0;i<MAX_INVENTORY;i++){
  4632. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4633. WFIFOW(fd,c*13+4) = i;
  4634. WFIFOW(fd,c*13+6) = nameid;
  4635. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  4636. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  4637. c++;
  4638. }
  4639. }
  4640. if(c > 0) {
  4641. WFIFOW(fd,2)=c*13+4;
  4642. WFIFOSET(fd,WFIFOW(fd,2));
  4643. sd->menuskill_id = BS_REPAIRWEAPON;
  4644. sd->menuskill_val = dstsd->bl.id;
  4645. }else
  4646. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  4647. }
  4648. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  4649. /// 01fe <index>.W <result>.B
  4650. void clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4651. {
  4652. int view,fd;
  4653. nullpo_retv(sd);
  4654. fd=sd->fd;
  4655. WFIFOHEAD(fd,packet_len(0x1fe));
  4656. WFIFOW(fd, 0)=0x1fe;
  4657. // FIXME: this is inventory index
  4658. if((view = itemdb_viewid(nameid)) > 0)
  4659. WFIFOW(fd, 2)=view;
  4660. else
  4661. WFIFOW(fd, 2)=nameid;
  4662. WFIFOB(fd, 4)=flag;
  4663. WFIFOSET(fd,packet_len(0x1fe));
  4664. }
  4665. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  4666. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  4667. void clif_item_refine_list(struct map_session_data *sd)
  4668. {
  4669. int i,c;
  4670. int fd;
  4671. int skilllv;
  4672. int wlv;
  4673. int refine_item[5];
  4674. nullpo_retv(sd);
  4675. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4676. fd=sd->fd;
  4677. refine_item[0] = -1;
  4678. refine_item[1] = pc_search_inventory(sd,1010);
  4679. refine_item[2] = pc_search_inventory(sd,1011);
  4680. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4681. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4682. WFIFOW(fd,0)=0x221;
  4683. for(i=c=0;i<MAX_INVENTORY;i++){
  4684. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4685. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4686. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  4687. WFIFOW(fd,c*13+ 4)=i+2;
  4688. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4689. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  4690. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  4691. c++;
  4692. }
  4693. }
  4694. WFIFOW(fd,2)=c*13+4;
  4695. WFIFOSET(fd,WFIFOW(fd,2));
  4696. if (c > 0) {
  4697. sd->menuskill_id = WS_WEAPONREFINE;
  4698. sd->menuskill_val = skilllv;
  4699. }
  4700. }
  4701. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  4702. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  4703. void clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4704. {
  4705. int fd;
  4706. nullpo_retv(sd);
  4707. fd=sd->fd;
  4708. WFIFOHEAD(fd,packet_len(0x147));
  4709. WFIFOW(fd, 0)=0x147;
  4710. WFIFOW(fd, 2)=skillid;
  4711. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4712. WFIFOW(fd, 6)=0;
  4713. WFIFOW(fd, 8)=skilllv;
  4714. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4715. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4716. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4717. WFIFOB(fd,38)=0;
  4718. WFIFOSET(fd,packet_len(0x147));
  4719. }
  4720. /// Adds an item to character's cart.
  4721. /// 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)
  4722. /// 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)
  4723. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4724. {
  4725. int view,fd;
  4726. unsigned char *buf;
  4727. nullpo_retv(sd);
  4728. fd=sd->fd;
  4729. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4730. return;
  4731. WFIFOHEAD(fd,packet_len(0x1c5));
  4732. buf=WFIFOP(fd,0);
  4733. WBUFW(buf,0)=0x1c5;
  4734. WBUFW(buf,2)=n+2;
  4735. WBUFL(buf,4)=amount;
  4736. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4737. WBUFW(buf,8)=view;
  4738. else
  4739. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4740. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4741. WBUFB(buf,11)=sd->status.cart[n].identify;
  4742. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4743. WBUFB(buf,13)=sd->status.cart[n].refine;
  4744. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4745. WFIFOSET(fd,packet_len(0x1c5));
  4746. }
  4747. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  4748. /// 0125 <index>.W <amount>.L
  4749. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4750. {
  4751. int fd;
  4752. nullpo_retv(sd);
  4753. fd=sd->fd;
  4754. WFIFOHEAD(fd,packet_len(0x125));
  4755. WFIFOW(fd,0)=0x125;
  4756. WFIFOW(fd,2)=n+2;
  4757. WFIFOL(fd,4)=amount;
  4758. WFIFOSET(fd,packet_len(0x125));
  4759. }
  4760. /// Opens the shop creation menu (ZC_OPENSTORE).
  4761. /// 012d <num>.W
  4762. /// num:
  4763. /// number of allowed item slots
  4764. void clif_openvendingreq(struct map_session_data* sd, int num)
  4765. {
  4766. int fd;
  4767. nullpo_retv(sd);
  4768. fd = sd->fd;
  4769. WFIFOHEAD(fd,packet_len(0x12d));
  4770. WFIFOW(fd,0) = 0x12d;
  4771. WFIFOW(fd,2) = num;
  4772. WFIFOSET(fd,packet_len(0x12d));
  4773. }
  4774. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  4775. /// 0131 <owner id>.L <message>.80B
  4776. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4777. {
  4778. unsigned char buf[128];
  4779. nullpo_retv(bl);
  4780. WBUFW(buf,0) = 0x131;
  4781. WBUFL(buf,2) = bl->id;
  4782. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4783. if( fd ) {
  4784. WFIFOHEAD(fd,packet_len(0x131));
  4785. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4786. WFIFOSET(fd,packet_len(0x131));
  4787. } else {
  4788. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4789. }
  4790. }
  4791. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  4792. /// 0132 <owner id>.L
  4793. void clif_closevendingboard(struct block_list* bl, int fd)
  4794. {
  4795. unsigned char buf[16];
  4796. nullpo_retv(bl);
  4797. WBUFW(buf,0) = 0x132;
  4798. WBUFL(buf,2) = bl->id;
  4799. if( fd ) {
  4800. WFIFOHEAD(fd,packet_len(0x132));
  4801. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4802. WFIFOSET(fd,packet_len(0x132));
  4803. } else {
  4804. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4805. }
  4806. }
  4807. /// Sends a list of items in a shop.
  4808. /// 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)
  4809. /// 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)
  4810. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4811. {
  4812. int i,fd;
  4813. int count;
  4814. struct map_session_data* vsd;
  4815. #if PACKETVER < 20100105
  4816. const int cmd = 0x133;
  4817. const int offset = 8;
  4818. #else
  4819. const int cmd = 0x800;
  4820. const int offset = 12;
  4821. #endif
  4822. nullpo_retv(sd);
  4823. nullpo_retv(vending);
  4824. nullpo_retv(vsd=map_id2sd(id));
  4825. fd = sd->fd;
  4826. count = vsd->vend_num;
  4827. WFIFOHEAD(fd, offset+count*22);
  4828. WFIFOW(fd,0) = cmd;
  4829. WFIFOW(fd,2) = offset+count*22;
  4830. WFIFOL(fd,4) = id;
  4831. #if PACKETVER >= 20100105
  4832. WFIFOL(fd,8) = vsd->vender_id;
  4833. #endif
  4834. for( i = 0; i < count; i++ )
  4835. {
  4836. int index = vending[i].index;
  4837. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4838. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  4839. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  4840. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  4841. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  4842. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4843. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  4844. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  4845. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  4846. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  4847. }
  4848. WFIFOSET(fd,WFIFOW(fd,2));
  4849. }
  4850. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  4851. /// 0135 <index>.W <amount>.W <result>.B
  4852. /// result:
  4853. /// 0 = success
  4854. /// 1 = not enough zeny
  4855. /// 2 = overweight
  4856. /// 4 = out of stock
  4857. /// 5 = "cannot use an npc shop while in a trade"
  4858. /// 6 = Because the store information was incorrect the item was not purchased.
  4859. /// 7 = No sales information.
  4860. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4861. {
  4862. int fd;
  4863. nullpo_retv(sd);
  4864. fd = sd->fd;
  4865. WFIFOHEAD(fd,packet_len(0x135));
  4866. WFIFOW(fd,0) = 0x135;
  4867. WFIFOW(fd,2) = index+2;
  4868. WFIFOW(fd,4) = amount;
  4869. WFIFOB(fd,6) = fail;
  4870. WFIFOSET(fd,packet_len(0x135));
  4871. }
  4872. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  4873. /// 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 }*
  4874. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4875. {
  4876. int i,fd;
  4877. int count;
  4878. nullpo_retv(sd);
  4879. fd = sd->fd;
  4880. count = sd->vend_num;
  4881. WFIFOHEAD(fd, 8+count*22);
  4882. WFIFOW(fd,0) = 0x136;
  4883. WFIFOW(fd,2) = 8+count*22;
  4884. WFIFOL(fd,4) = id;
  4885. for( i = 0; i < count; i++ )
  4886. {
  4887. int index = vending[i].index;
  4888. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4889. WFIFOL(fd, 8+i*22) = vending[i].value;
  4890. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4891. WFIFOW(fd,14+i*22) = vending[i].amount;
  4892. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4893. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4894. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4895. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4896. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4897. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4898. }
  4899. WFIFOSET(fd,WFIFOW(fd,2));
  4900. }
  4901. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  4902. /// 0137 <index>.W <amount>.W
  4903. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4904. {
  4905. int fd;
  4906. nullpo_retv(sd);
  4907. fd = sd->fd;
  4908. WFIFOHEAD(fd,packet_len(0x137));
  4909. WFIFOW(fd,0) = 0x137;
  4910. WFIFOW(fd,2) = index+2;
  4911. WFIFOW(fd,4) = amount;
  4912. WFIFOSET(fd,packet_len(0x137));
  4913. }
  4914. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  4915. /// 00fa <result>.B
  4916. /// result:
  4917. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  4918. /// 1 = MsgStringTable[78]="party name already exists"
  4919. /// 2 = MsgStringTable[79]="already in a party"
  4920. /// 3 = cannot organize parties on this map
  4921. /// ? = nothing
  4922. void clif_party_created(struct map_session_data *sd,int result)
  4923. {
  4924. int fd;
  4925. nullpo_retv(sd);
  4926. fd=sd->fd;
  4927. WFIFOHEAD(fd,packet_len(0xfa));
  4928. WFIFOW(fd,0)=0xfa;
  4929. WFIFOB(fd,2)=result;
  4930. WFIFOSET(fd,packet_len(0xfa));
  4931. }
  4932. /// Adds new member to a party.
  4933. /// 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)
  4934. /// 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)
  4935. /// role:
  4936. /// 0 = leader
  4937. /// 1 = normal
  4938. /// state:
  4939. /// 0 = connected
  4940. /// 1 = disconnected
  4941. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4942. {
  4943. unsigned char buf[81];
  4944. int i;
  4945. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4946. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4947. } else {
  4948. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4949. }
  4950. if (i >= MAX_PARTY) return; //Should never happen...
  4951. sd = p->data[i].sd;
  4952. WBUFW(buf, 0) = 0x1e9;
  4953. WBUFL(buf, 2) = sd->status.account_id;
  4954. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4955. WBUFW(buf,10) = sd->bl.x;
  4956. WBUFW(buf,12) = sd->bl.y;
  4957. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4958. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4959. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4960. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4961. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4962. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4963. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4964. }
  4965. /// Sends party information (ZC_GROUP_LIST).
  4966. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  4967. /// role:
  4968. /// 0 = leader
  4969. /// 1 = normal
  4970. /// state:
  4971. /// 0 = connected
  4972. /// 1 = disconnected
  4973. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  4974. {
  4975. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4976. struct map_session_data* party_sd = NULL;
  4977. int i, c;
  4978. nullpo_retv(p);
  4979. WBUFW(buf,0) = 0xfb;
  4980. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4981. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4982. {
  4983. struct party_member* m = &p->party.member[i];
  4984. if(!m->account_id) continue;
  4985. if(party_sd == NULL) party_sd = p->data[i].sd;
  4986. WBUFL(buf,28+c*46) = m->account_id;
  4987. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4988. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4989. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4990. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4991. c++;
  4992. }
  4993. WBUFW(buf,2) = 28+c*46;
  4994. if(sd) { // send only to self
  4995. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4996. } else if (party_sd) { // send to whole party
  4997. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4998. }
  4999. }
  5000. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5001. /// 02c9 <flag>.B
  5002. /// flag:
  5003. /// 0 = allow party invites
  5004. /// 1 = auto-deny party invites
  5005. void clif_partyinvitationstate(struct map_session_data* sd)
  5006. {
  5007. int fd;
  5008. nullpo_retv(sd);
  5009. fd = sd->fd;
  5010. WFIFOHEAD(fd, packet_len(0x2c9));
  5011. WFIFOW(fd, 0) = 0x2c9;
  5012. WFIFOB(fd, 2) = 0; // not implemented
  5013. WFIFOSET(fd, packet_len(0x2c9));
  5014. }
  5015. /// Party invitation request.
  5016. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5017. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5018. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5019. {
  5020. #if PACKETVER < 20070821
  5021. const int cmd = 0xfe;
  5022. #else
  5023. const int cmd = 0x2c6;
  5024. #endif
  5025. int fd;
  5026. struct party_data *p;
  5027. nullpo_retv(sd);
  5028. nullpo_retv(tsd);
  5029. fd=tsd->fd;
  5030. if( (p=party_search(sd->status.party_id))==NULL )
  5031. return;
  5032. WFIFOHEAD(fd,packet_len(cmd));
  5033. WFIFOW(fd,0)=cmd;
  5034. WFIFOL(fd,2)=sd->status.party_id;
  5035. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5036. WFIFOSET(fd,packet_len(cmd));
  5037. }
  5038. /// Party invite result.
  5039. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5040. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5041. /// result=0 : char is already in a party -> MsgStringTable[80]
  5042. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5043. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5044. /// result=3 : party is full -> MsgStringTable[83]
  5045. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5046. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5047. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5048. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5049. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5050. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5051. {
  5052. int fd;
  5053. nullpo_retv(sd);
  5054. fd=sd->fd;
  5055. WFIFOHEAD(fd,packet_len(0x2c5));
  5056. WFIFOW(fd,0) = 0x2c5;
  5057. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5058. WFIFOL(fd,26) = result;
  5059. WFIFOSET(fd,packet_len(0x2c5));
  5060. }
  5061. /// Updates party settings.
  5062. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5063. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5064. /// exp option:
  5065. /// 0 = exp sharing disabled
  5066. /// 1 = exp sharing enabled
  5067. /// 2 = cannot change exp sharing
  5068. ///
  5069. /// flag:
  5070. /// 0 = send to party
  5071. /// 1 = send to sd
  5072. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5073. {
  5074. unsigned char buf[16];
  5075. const int cmd = 0x7d8;
  5076. nullpo_retv(p);
  5077. if(!sd && flag==0){
  5078. int i;
  5079. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5080. if (i < MAX_PARTY)
  5081. sd = p->data[i].sd;
  5082. }
  5083. if(!sd) return;
  5084. WBUFW(buf,0)=cmd;
  5085. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5086. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5087. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5088. if(flag==0)
  5089. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5090. else
  5091. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5092. }
  5093. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5094. /// result:
  5095. /// 0 = leave
  5096. /// 1 = expel
  5097. /// 2 = cannot leave party on this map
  5098. /// 3 = cannot expel from party on this map
  5099. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5100. {
  5101. unsigned char buf[64];
  5102. int i;
  5103. nullpo_retv(p);
  5104. if(!sd && (flag&0xf0)==0)
  5105. {
  5106. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5107. if (i < MAX_PARTY)
  5108. sd = p->data[i].sd;
  5109. }
  5110. if(!sd) return;
  5111. WBUFW(buf,0)=0x105;
  5112. WBUFL(buf,2)=account_id;
  5113. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5114. WBUFB(buf,30)=flag&0x0f;
  5115. if((flag&0xf0)==0)
  5116. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5117. else
  5118. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5119. }
  5120. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5121. /// 0109 <packet len>.W <account id>.L <message>.?B
  5122. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5123. {
  5124. struct map_session_data *sd;
  5125. int i;
  5126. nullpo_retv(p);
  5127. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5128. if(i < MAX_PARTY){
  5129. unsigned char buf[1024];
  5130. sd = p->data[i].sd;
  5131. WBUFW(buf,0)=0x109;
  5132. WBUFW(buf,2)=len+8;
  5133. WBUFL(buf,4)=account_id;
  5134. memcpy(WBUFP(buf,8),mes,len); // FIXME: buffer size check
  5135. clif_send(buf,len+8,&sd->bl,PARTY);
  5136. }
  5137. }
  5138. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5139. /// 0107 <account id>.L <x>.W <y>.W
  5140. void clif_party_xy(struct map_session_data *sd)
  5141. {
  5142. unsigned char buf[16];
  5143. nullpo_retv(sd);
  5144. WBUFW(buf,0)=0x107;
  5145. WBUFL(buf,2)=sd->status.account_id;
  5146. WBUFW(buf,6)=sd->bl.x;
  5147. WBUFW(buf,8)=sd->bl.y;
  5148. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5149. }
  5150. /*==========================================
  5151. * Sends x/y dot to a single fd. [Skotlex]
  5152. *------------------------------------------*/
  5153. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5154. {
  5155. WFIFOHEAD(fd,packet_len(0x107));
  5156. WFIFOW(fd,0)=0x107;
  5157. WFIFOL(fd,2)=sd->status.account_id;
  5158. WFIFOW(fd,6)=sd->bl.x;
  5159. WFIFOW(fd,8)=sd->bl.y;
  5160. WFIFOSET(fd,packet_len(0x107));
  5161. }
  5162. /// Updates HP bar of a party member.
  5163. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5164. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5165. void clif_party_hp(struct map_session_data *sd)
  5166. {
  5167. unsigned char buf[16];
  5168. #if PACKETVER < 20100126
  5169. const int cmd = 0x106;
  5170. #else
  5171. const int cmd = 0x80e;
  5172. #endif
  5173. nullpo_retv(sd);
  5174. WBUFW(buf,0)=cmd;
  5175. WBUFL(buf,2)=sd->status.account_id;
  5176. #if PACKETVER < 20100126
  5177. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5178. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5179. WBUFW(buf,8) = 100;
  5180. } else {
  5181. WBUFW(buf,6) = sd->battle_status.hp;
  5182. WBUFW(buf,8) = sd->battle_status.max_hp;
  5183. }
  5184. #else
  5185. WBUFL(buf,6) = sd->battle_status.hp;
  5186. WBUFL(buf,10) = sd->battle_status.max_hp;
  5187. #endif
  5188. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5189. }
  5190. /*==========================================
  5191. * Sends HP bar to a single fd. [Skotlex]
  5192. *------------------------------------------*/
  5193. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5194. {
  5195. #if PACKETVER < 20100126
  5196. const int cmd = 0x106;
  5197. #else
  5198. const int cmd = 0x80e;
  5199. #endif
  5200. WFIFOHEAD(fd,packet_len(cmd));
  5201. WFIFOW(fd,0) = cmd;
  5202. WFIFOL(fd,2) = id;
  5203. #if PACKETVER < 20100126
  5204. if( maxhp > INT16_MAX )
  5205. {// To correctly display the %hp bar. [Skotlex]
  5206. WFIFOW(fd,6) = hp/(maxhp/100);
  5207. WFIFOW(fd,8) = 100;
  5208. } else {
  5209. WFIFOW(fd,6) = hp;
  5210. WFIFOW(fd,8) = maxhp;
  5211. }
  5212. #else
  5213. WFIFOL(fd,6) = hp;
  5214. WFIFOL(fd,10) = maxhp;
  5215. #endif
  5216. WFIFOSET(fd, packet_len(cmd));
  5217. }
  5218. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5219. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5220. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5221. {
  5222. int fd;
  5223. nullpo_retv(sd);
  5224. nullpo_retv(bl);
  5225. fd=sd->fd;
  5226. WFIFOHEAD(fd,packet_len(0x139));
  5227. WFIFOW(fd, 0)=0x139;
  5228. WFIFOL(fd, 2)=bl->id;
  5229. WFIFOW(fd, 6)=bl->x;
  5230. WFIFOW(fd, 8)=bl->y;
  5231. WFIFOW(fd,10)=sd->bl.x;
  5232. WFIFOW(fd,12)=sd->bl.y;
  5233. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5234. WFIFOSET(fd,packet_len(0x139));
  5235. }
  5236. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5237. /// 018f <result>.W <name id>.W
  5238. /// result:
  5239. /// 0 = success
  5240. /// 1 = failure
  5241. /// 2 = success (alchemist)
  5242. /// 3 = failure (alchemist)
  5243. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5244. {
  5245. int view,fd;
  5246. nullpo_retv(sd);
  5247. fd = sd->fd;
  5248. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5249. WFIFOHEAD(fd,packet_len(0x18f));
  5250. WFIFOW(fd, 0)=0x18f;
  5251. WFIFOW(fd, 2)=flag;
  5252. if((view = itemdb_viewid(nameid)) > 0)
  5253. WFIFOW(fd, 4)=view;
  5254. else
  5255. WFIFOW(fd, 4)=nameid;
  5256. WFIFOSET(fd,packet_len(0x18f));
  5257. }
  5258. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5259. /// 019e
  5260. void clif_catch_process(struct map_session_data *sd)
  5261. {
  5262. int fd;
  5263. nullpo_retv(sd);
  5264. fd=sd->fd;
  5265. WFIFOHEAD(fd,packet_len(0x19e));
  5266. WFIFOW(fd,0)=0x19e;
  5267. WFIFOSET(fd,packet_len(0x19e));
  5268. }
  5269. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5270. /// 01a0 <result>.B
  5271. /// 0 = failure
  5272. /// 1 = success
  5273. void clif_pet_roulette(struct map_session_data *sd,int data)
  5274. {
  5275. int fd;
  5276. nullpo_retv(sd);
  5277. fd=sd->fd;
  5278. WFIFOHEAD(fd,packet_len(0x1a0));
  5279. WFIFOW(fd,0)=0x1a0;
  5280. WFIFOB(fd,2)=data;
  5281. WFIFOSET(fd,packet_len(0x1a0));
  5282. }
  5283. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5284. /// 01a6 <packet len>.W { <index>.W }*
  5285. void clif_sendegg(struct map_session_data *sd)
  5286. {
  5287. int i,n=0,fd;
  5288. nullpo_retv(sd);
  5289. fd=sd->fd;
  5290. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5291. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5292. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5293. return;
  5294. }
  5295. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5296. WFIFOW(fd,0)=0x1a6;
  5297. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5298. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5299. sd->inventory_data[i]->type!=IT_PETEGG ||
  5300. sd->status.inventory[i].amount<=0)
  5301. continue;
  5302. WFIFOW(fd,n*2+4)=i+2;
  5303. n++;
  5304. }
  5305. WFIFOW(fd,2)=4+n*2;
  5306. WFIFOSET(fd,WFIFOW(fd,2));
  5307. sd->menuskill_id = SA_TAMINGMONSTER;
  5308. sd->menuskill_val = -1;
  5309. }
  5310. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5311. /// 01a4 <type>.B <id>.L <data>.L
  5312. /// type:
  5313. /// 0 = pre-init (data = 0)
  5314. /// 1 = intimacy (data = 0~4)
  5315. /// 2 = hunger (data = 0~4)
  5316. /// 3 = accessory
  5317. /// 4 = performance (data = 1~3: normal, 4: special)
  5318. /// 5 = hairstyle
  5319. ///
  5320. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5321. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5322. {
  5323. uint8 buf[16];
  5324. nullpo_retv(pd);
  5325. WBUFW(buf,0) = 0x1a4;
  5326. WBUFB(buf,2) = type;
  5327. WBUFL(buf,3) = pd->bl.id;
  5328. WBUFL(buf,7) = param;
  5329. if (sd)
  5330. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5331. else
  5332. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5333. }
  5334. /// Pet's base data (ZC_PROPERTY_PET).
  5335. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5336. void clif_send_petstatus(struct map_session_data *sd)
  5337. {
  5338. int fd;
  5339. struct s_pet *pet;
  5340. nullpo_retv(sd);
  5341. nullpo_retv(sd->pd);
  5342. fd=sd->fd;
  5343. pet = &sd->pd->pet;
  5344. WFIFOHEAD(fd,packet_len(0x1a2));
  5345. WFIFOW(fd,0)=0x1a2;
  5346. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5347. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5348. WFIFOW(fd,27)=pet->level;
  5349. WFIFOW(fd,29)=pet->hungry;
  5350. WFIFOW(fd,31)=pet->intimate;
  5351. WFIFOW(fd,33)=pet->equip;
  5352. WFIFOW(fd,35)=pet->class_;
  5353. WFIFOSET(fd,packet_len(0x1a2));
  5354. }
  5355. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5356. /// 01aa <id>.L <data>.L
  5357. /// data:
  5358. /// @see CZ_PET_ACT.
  5359. void clif_pet_emotion(struct pet_data *pd,int param)
  5360. {
  5361. unsigned char buf[16];
  5362. nullpo_retv(pd);
  5363. memset(buf,0,packet_len(0x1aa));
  5364. WBUFW(buf,0)=0x1aa;
  5365. WBUFL(buf,2)=pd->bl.id;
  5366. if(param >= 100 && pd->petDB->talk_convert_class) {
  5367. if(pd->petDB->talk_convert_class < 0)
  5368. return;
  5369. else if(pd->petDB->talk_convert_class > 0) {
  5370. // replace mob_id component of talk/act data
  5371. param -= (pd->pet.class_ - 100)*100;
  5372. param += (pd->petDB->talk_convert_class - 100)*100;
  5373. }
  5374. }
  5375. WBUFL(buf,6)=param;
  5376. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5377. }
  5378. /// Result of request to feed a pet (ZC_FEED_PET).
  5379. /// 01a3 <result>.B <name id>.W
  5380. /// result:
  5381. /// 0 = failure
  5382. /// 1 = success
  5383. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5384. {
  5385. int fd;
  5386. nullpo_retv(sd);
  5387. fd=sd->fd;
  5388. WFIFOHEAD(fd,packet_len(0x1a3));
  5389. WFIFOW(fd,0)=0x1a3;
  5390. WFIFOB(fd,2)=fail;
  5391. WFIFOW(fd,3)=foodid;
  5392. WFIFOSET(fd,packet_len(0x1a3));
  5393. }
  5394. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5395. /// 01cd { <skill id>.L }*7
  5396. void clif_autospell(struct map_session_data *sd,int skilllv)
  5397. {
  5398. int fd;
  5399. nullpo_retv(sd);
  5400. fd=sd->fd;
  5401. WFIFOHEAD(fd,packet_len(0x1cd));
  5402. WFIFOW(fd, 0)=0x1cd;
  5403. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5404. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5405. else
  5406. WFIFOL(fd,2)= 0x00000000;
  5407. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5408. WFIFOL(fd,6)= MG_COLDBOLT;
  5409. else
  5410. WFIFOL(fd,6)= 0x00000000;
  5411. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5412. WFIFOL(fd,10)= MG_FIREBOLT;
  5413. else
  5414. WFIFOL(fd,10)= 0x00000000;
  5415. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5416. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5417. else
  5418. WFIFOL(fd,14)= 0x00000000;
  5419. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5420. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5421. else
  5422. WFIFOL(fd,18)= 0x00000000;
  5423. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5424. WFIFOL(fd,22)= MG_FIREBALL;
  5425. else
  5426. WFIFOL(fd,22)= 0x00000000;
  5427. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5428. WFIFOL(fd,26)= MG_FROSTDIVER;
  5429. else
  5430. WFIFOL(fd,26)= 0x00000000;
  5431. WFIFOSET(fd,packet_len(0x1cd));
  5432. sd->menuskill_id = SA_AUTOSPELL;
  5433. sd->menuskill_val = skilllv;
  5434. }
  5435. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5436. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5437. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5438. {
  5439. unsigned char buf[56];
  5440. int i;
  5441. nullpo_retv(src);
  5442. memset(buf,0,packet_len(0x1cf));
  5443. WBUFW(buf,0) = 0x1cf;
  5444. WBUFL(buf,2) = src->id;
  5445. if( src->type == BL_MER )
  5446. {
  5447. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5448. if( md && md->master && md->devotion_flag )
  5449. WBUFL(buf,6) = md->master->bl.id;
  5450. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5451. }
  5452. else
  5453. {
  5454. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5455. if( sd == NULL )
  5456. return;
  5457. for( i = 0; i < 5; i++ )
  5458. WBUFL(buf,6+4*i) = sd->devotion[i];
  5459. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5460. }
  5461. if( tsd )
  5462. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5463. else
  5464. clif_send(buf, packet_len(0x1cf), src, AREA);
  5465. }
  5466. /// Notifies clients in an area of an object's spirits.
  5467. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  5468. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  5469. void clif_spiritball(struct map_session_data *sd)
  5470. {
  5471. unsigned char buf[8];
  5472. nullpo_retv(sd);
  5473. WBUFW(buf,0)=0x1d0;
  5474. WBUFL(buf,2)=sd->bl.id;
  5475. WBUFW(buf,6)=sd->spiritball;
  5476. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5477. }
  5478. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  5479. /// 01d2 <account id>.L <delay>.L
  5480. void clif_combo_delay(struct block_list *bl,int wait)
  5481. {
  5482. unsigned char buf[32];
  5483. nullpo_retv(bl);
  5484. WBUFW(buf,0)=0x1d2;
  5485. WBUFL(buf,2)=bl->id;
  5486. WBUFL(buf,6)=wait;
  5487. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5488. }
  5489. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  5490. /// 01d1 <src id>.L <dst id>.L <flag>.L
  5491. /// flag:
  5492. /// 0 = inactive
  5493. /// 1 = active
  5494. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5495. {
  5496. unsigned char buf[32];
  5497. nullpo_retv(src);
  5498. WBUFW(buf,0)=0x1d1;
  5499. WBUFL(buf,2)=src->id;
  5500. WBUFL(buf,6)=dst_id;
  5501. WBUFL(buf,10)=active;
  5502. clif_send(buf,packet_len(0x1d1),src,AREA);
  5503. }
  5504. /// MVP effect (ZC_MVP).
  5505. /// 010c <account id>.L
  5506. void clif_mvp_effect(struct map_session_data *sd)
  5507. {
  5508. unsigned char buf[16];
  5509. nullpo_retv(sd);
  5510. WBUFW(buf,0)=0x10c;
  5511. WBUFL(buf,2)=sd->bl.id;
  5512. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5513. }
  5514. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  5515. /// 010a <name id>.W
  5516. void clif_mvp_item(struct map_session_data *sd,int nameid)
  5517. {
  5518. int view,fd;
  5519. nullpo_retv(sd);
  5520. fd=sd->fd;
  5521. WFIFOHEAD(fd,packet_len(0x10a));
  5522. WFIFOW(fd,0)=0x10a;
  5523. if((view = itemdb_viewid(nameid)) > 0)
  5524. WFIFOW(fd,2)=view;
  5525. else
  5526. WFIFOW(fd,2)=nameid;
  5527. WFIFOSET(fd,packet_len(0x10a));
  5528. }
  5529. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  5530. /// 010b <exp>.L
  5531. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5532. {
  5533. int fd;
  5534. nullpo_retv(sd);
  5535. fd=sd->fd;
  5536. WFIFOHEAD(fd,packet_len(0x10b));
  5537. WFIFOW(fd,0)=0x10b;
  5538. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  5539. WFIFOSET(fd,packet_len(0x10b));
  5540. }
  5541. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  5542. /// 010d
  5543. ///
  5544. /// "You are the MVP, but cannot obtain the reward because
  5545. /// you are overweight."
  5546. void clif_mvp_noitem(struct map_session_data* sd)
  5547. {
  5548. int fd = sd->fd;
  5549. WFIFOHEAD(fd,packet_len(0x10d));
  5550. WFIFOW(fd,0) = 0x10d;
  5551. WFIFOSET(fd,packet_len(0x10d));
  5552. }
  5553. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  5554. /// 0167 <result>.B
  5555. /// result:
  5556. /// 0 = "Guild has been created."
  5557. /// 1 = "You are already in a Guild."
  5558. /// 2 = "That Guild Name already exists."
  5559. /// 3 = "You need the neccessary item to create a Guild."
  5560. void clif_guild_created(struct map_session_data *sd,int flag)
  5561. {
  5562. int fd;
  5563. nullpo_retv(sd);
  5564. fd=sd->fd;
  5565. WFIFOHEAD(fd,packet_len(0x167));
  5566. WFIFOW(fd,0)=0x167;
  5567. WFIFOB(fd,2)=flag;
  5568. WFIFOSET(fd,packet_len(0x167));
  5569. }
  5570. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  5571. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  5572. /// mode:
  5573. /// &0x01 = allow invite
  5574. /// &0x10 = allow expel
  5575. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5576. {
  5577. int ps,fd;
  5578. nullpo_retv(sd);
  5579. nullpo_retv(g);
  5580. fd=sd->fd;
  5581. ps=guild_getposition(g,sd);
  5582. WFIFOHEAD(fd,packet_len(0x16c));
  5583. WFIFOW(fd,0)=0x16c;
  5584. WFIFOL(fd,2)=g->guild_id;
  5585. WFIFOL(fd,6)=g->emblem_id;
  5586. WFIFOL(fd,10)=g->position[ps].mode;
  5587. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  5588. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  5589. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5590. WFIFOSET(fd,packet_len(0x16c));
  5591. }
  5592. /// Guild member login notice.
  5593. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  5594. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  5595. /// status:
  5596. /// 0 = offline
  5597. /// 1 = online
  5598. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5599. {
  5600. unsigned char buf[64];
  5601. struct map_session_data* sd;
  5602. nullpo_retv(g);
  5603. WBUFW(buf, 0)=0x1f2;
  5604. WBUFL(buf, 2)=g->member[idx].account_id;
  5605. WBUFL(buf, 6)=g->member[idx].char_id;
  5606. WBUFL(buf,10)=flag;
  5607. if( ( sd = g->member[idx].sd ) != NULL )
  5608. {
  5609. WBUFW(buf,14) = sd->status.sex;
  5610. WBUFW(buf,16) = sd->status.hair;
  5611. WBUFW(buf,18) = sd->status.hair_color;
  5612. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  5613. }
  5614. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  5615. {
  5616. WBUFW(buf,14) = 0;
  5617. WBUFW(buf,16) = 0;
  5618. WBUFW(buf,18) = 0;
  5619. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  5620. }
  5621. }
  5622. // Function `clif_guild_memberlogin_notice` sends info about
  5623. // logins and logouts of a guild member to the rest members.
  5624. // But at the 1st time (after a player login or map changing)
  5625. // the client won't show the message.
  5626. // So I suggest use this function for sending "first-time-info"
  5627. // to some player on entering the game or changing location.
  5628. // At next time the client would always show the message.
  5629. // The function sends all the statuses in the single packet
  5630. // to economize traffic. [LuzZza]
  5631. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  5632. {
  5633. struct guild *g;
  5634. unsigned char buf[14*128];
  5635. int i, count=0, p_len;
  5636. nullpo_retv(sd);
  5637. p_len = packet_len(0x16d);
  5638. if(!(g = guild_search(sd->status.guild_id)))
  5639. return;
  5640. for(i=0; i<g->max_member; i++) {
  5641. if(g->member[i].account_id > 0 &&
  5642. g->member[i].account_id != sd->status.account_id) {
  5643. WBUFW(buf,count*p_len) = 0x16d;
  5644. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5645. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5646. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5647. count++;
  5648. }
  5649. }
  5650. clif_send(buf, p_len*count, &sd->bl, SELF);
  5651. }
  5652. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  5653. /// 014e <menu flag>.L
  5654. /// menu flag:
  5655. /// 0x00 = Basic Info (always on)
  5656. /// &0x01 = Member manager
  5657. /// &0x02 = Positions
  5658. /// &0x04 = Skills
  5659. /// &0x10 = Expulsion list
  5660. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  5661. /// &0x80 = Notice
  5662. void clif_guild_masterormember(struct map_session_data *sd)
  5663. {
  5664. int fd;
  5665. nullpo_retv(sd);
  5666. fd=sd->fd;
  5667. WFIFOHEAD(fd,packet_len(0x14e));
  5668. WFIFOW(fd,0) = 0x14e;
  5669. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5670. WFIFOSET(fd,packet_len(0x14e));
  5671. }
  5672. /// Guild basic information (Territories [Valaris])
  5673. /// 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)
  5674. /// 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)
  5675. void clif_guild_basicinfo(struct map_session_data *sd) {
  5676. int fd;
  5677. struct guild *g;
  5678. nullpo_retv(sd);
  5679. fd = sd->fd;
  5680. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5681. return;
  5682. WFIFOHEAD(fd,packet_len(0x1b6));
  5683. WFIFOW(fd, 0)=0x1b6;//0x150;
  5684. WFIFOL(fd, 2)=g->guild_id;
  5685. WFIFOL(fd, 6)=g->guild_lv;
  5686. WFIFOL(fd,10)=g->connect_member;
  5687. WFIFOL(fd,14)=g->max_member;
  5688. WFIFOL(fd,18)=g->average_lv;
  5689. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  5690. WFIFOL(fd,26)=g->next_exp;
  5691. WFIFOL(fd,30)=0; // Tax Points
  5692. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  5693. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  5694. WFIFOL(fd,42)=g->emblem_id;
  5695. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5696. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5697. safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
  5698. WFIFOL(fd,110) = 0; // zeny
  5699. WFIFOSET(fd,packet_len(0x1b6));
  5700. }
  5701. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  5702. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  5703. void clif_guild_allianceinfo(struct map_session_data *sd)
  5704. {
  5705. int fd,i,c;
  5706. struct guild *g;
  5707. nullpo_retv(sd);
  5708. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5709. return;
  5710. fd = sd->fd;
  5711. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5712. WFIFOW(fd, 0)=0x14c;
  5713. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5714. struct guild_alliance *a=&g->alliance[i];
  5715. if(a->guild_id>0){
  5716. WFIFOL(fd,c*32+4)=a->opposition;
  5717. WFIFOL(fd,c*32+8)=a->guild_id;
  5718. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5719. c++;
  5720. }
  5721. }
  5722. WFIFOW(fd, 2)=c*32+4;
  5723. WFIFOSET(fd,WFIFOW(fd,2));
  5724. }
  5725. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  5726. /// 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 }*
  5727. /// state:
  5728. /// 0 = offline
  5729. /// 1 = online
  5730. /// memo:
  5731. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  5732. void clif_guild_memberlist(struct map_session_data *sd)
  5733. {
  5734. int fd;
  5735. int i,c;
  5736. struct guild *g;
  5737. nullpo_retv(sd);
  5738. if( (fd = sd->fd) == 0 )
  5739. return;
  5740. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5741. return;
  5742. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5743. WFIFOW(fd, 0)=0x154;
  5744. for(i=0,c=0;i<g->max_member;i++){
  5745. struct guild_member *m=&g->member[i];
  5746. if(m->account_id==0)
  5747. continue;
  5748. WFIFOL(fd,c*104+ 4)=m->account_id;
  5749. WFIFOL(fd,c*104+ 8)=m->char_id;
  5750. WFIFOW(fd,c*104+12)=m->hair;
  5751. WFIFOW(fd,c*104+14)=m->hair_color;
  5752. WFIFOW(fd,c*104+16)=m->gender;
  5753. WFIFOW(fd,c*104+18)=m->class_;
  5754. WFIFOW(fd,c*104+20)=m->lv;
  5755. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  5756. WFIFOL(fd,c*104+26)=m->online;
  5757. WFIFOL(fd,c*104+30)=m->position;
  5758. 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.
  5759. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5760. c++;
  5761. }
  5762. WFIFOW(fd, 2)=c*104+4;
  5763. WFIFOSET(fd,WFIFOW(fd,2));
  5764. }
  5765. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  5766. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  5767. void clif_guild_positionnamelist(struct map_session_data *sd)
  5768. {
  5769. int i,fd;
  5770. struct guild *g;
  5771. nullpo_retv(sd);
  5772. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5773. return;
  5774. fd = sd->fd;
  5775. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5776. WFIFOW(fd, 0)=0x166;
  5777. for(i=0;i<MAX_GUILDPOSITION;i++){
  5778. WFIFOL(fd,i*28+4)=i;
  5779. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5780. }
  5781. WFIFOW(fd,2)=i*28+4;
  5782. WFIFOSET(fd,WFIFOW(fd,2));
  5783. }
  5784. /// Guild position information (ZC_POSITION_INFO).
  5785. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  5786. /// mode:
  5787. /// &0x01 = allow invite
  5788. /// &0x10 = allow expel
  5789. /// ranking:
  5790. /// TODO
  5791. void clif_guild_positioninfolist(struct map_session_data *sd)
  5792. {
  5793. int i,fd;
  5794. struct guild *g;
  5795. nullpo_retv(sd);
  5796. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5797. return;
  5798. fd = sd->fd;
  5799. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5800. WFIFOW(fd, 0)=0x160;
  5801. for(i=0;i<MAX_GUILDPOSITION;i++){
  5802. struct guild_position *p=&g->position[i];
  5803. WFIFOL(fd,i*16+ 4)=i;
  5804. WFIFOL(fd,i*16+ 8)=p->mode;
  5805. WFIFOL(fd,i*16+12)=i;
  5806. WFIFOL(fd,i*16+16)=p->exp_mode;
  5807. }
  5808. WFIFOW(fd, 2)=i*16+4;
  5809. WFIFOSET(fd,WFIFOW(fd,2));
  5810. }
  5811. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  5812. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  5813. /// mode:
  5814. /// &0x01 = allow invite
  5815. /// &0x10 = allow expel
  5816. /// ranking:
  5817. /// TODO
  5818. void clif_guild_positionchanged(struct guild *g,int idx)
  5819. {
  5820. // FIXME: This packet is intended to update the clients after a
  5821. // commit of position info changes, not sending one packet per
  5822. // position.
  5823. struct map_session_data *sd;
  5824. unsigned char buf[128];
  5825. nullpo_retv(g);
  5826. WBUFW(buf, 0)=0x174;
  5827. WBUFW(buf, 2)=44; // packet len
  5828. // GUILD_REG_POSITION_INFO{
  5829. WBUFL(buf, 4)=idx;
  5830. WBUFL(buf, 8)=g->position[idx].mode;
  5831. WBUFL(buf,12)=idx;
  5832. WBUFL(buf,16)=g->position[idx].exp_mode;
  5833. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5834. // }*
  5835. if( (sd=guild_getavailablesd(g))!=NULL )
  5836. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5837. }
  5838. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  5839. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  5840. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  5841. {
  5842. // FIXME: This packet is intended to update the clients after a
  5843. // commit of member position assignment changes, not sending one
  5844. // packet per position.
  5845. struct map_session_data *sd;
  5846. unsigned char buf[64];
  5847. nullpo_retv(g);
  5848. WBUFW(buf, 0)=0x156;
  5849. WBUFW(buf, 2)=16; // packet len
  5850. // MEMBER_POSITION_INFO{
  5851. WBUFL(buf, 4)=g->member[idx].account_id;
  5852. WBUFL(buf, 8)=g->member[idx].char_id;
  5853. WBUFL(buf,12)=g->member[idx].position;
  5854. // }*
  5855. if( (sd=guild_getavailablesd(g))!=NULL )
  5856. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5857. }
  5858. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  5859. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  5860. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5861. {
  5862. int fd;
  5863. nullpo_retv(sd);
  5864. nullpo_retv(g);
  5865. fd = sd->fd;
  5866. if( g->emblem_len <= 0 )
  5867. return;
  5868. WFIFOHEAD(fd,g->emblem_len+12);
  5869. WFIFOW(fd,0)=0x152;
  5870. WFIFOW(fd,2)=g->emblem_len+12;
  5871. WFIFOL(fd,4)=g->guild_id;
  5872. WFIFOL(fd,8)=g->emblem_id;
  5873. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5874. WFIFOSET(fd,WFIFOW(fd,2));
  5875. }
  5876. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  5877. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  5878. void clif_guild_emblem_area(struct block_list* bl)
  5879. {
  5880. uint8 buf[12];
  5881. nullpo_retv(bl);
  5882. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5883. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5884. WBUFW(buf,0) = 0x1b4;
  5885. WBUFL(buf,2) = bl->id;
  5886. WBUFL(buf,6) = status_get_guild_id(bl);
  5887. WBUFW(buf,10) = status_get_emblem_id(bl);
  5888. clif_send(buf, 12, bl, AREA_WOS);
  5889. }
  5890. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  5891. /// 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 }*
  5892. void clif_guild_skillinfo(struct map_session_data* sd)
  5893. {
  5894. int fd;
  5895. struct guild* g;
  5896. int i,c;
  5897. nullpo_retv(sd);
  5898. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5899. return;
  5900. fd = sd->fd;
  5901. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5902. WFIFOW(fd,0) = 0x0162;
  5903. WFIFOW(fd,4) = g->skill_point;
  5904. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5905. {
  5906. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5907. {
  5908. int id = g->skill[i].id;
  5909. int p = 6 + c*37;
  5910. WFIFOW(fd,p+0) = id;
  5911. WFIFOL(fd,p+2) = skill_get_inf(id);
  5912. WFIFOW(fd,p+6) = g->skill[i].lv;
  5913. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5914. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5915. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5916. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5917. c++;
  5918. }
  5919. }
  5920. WFIFOW(fd,2) = 6 + c*37;
  5921. WFIFOSET(fd,WFIFOW(fd,2));
  5922. }
  5923. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  5924. /// 016f <subject>.60B <notice>.120B
  5925. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5926. {
  5927. int fd;
  5928. nullpo_retv(sd);
  5929. nullpo_retv(g);
  5930. fd = sd->fd;
  5931. if ( !session_isActive(fd) )
  5932. return;
  5933. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5934. return;
  5935. WFIFOHEAD(fd,packet_len(0x16f));
  5936. WFIFOW(fd,0) = 0x16f;
  5937. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  5938. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  5939. WFIFOSET(fd,packet_len(0x16f));
  5940. }
  5941. /// Guild invite (ZC_REQ_JOIN_GUILD).
  5942. /// 016a <guild id>.L <guild name>.24B
  5943. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5944. {
  5945. int fd;
  5946. nullpo_retv(sd);
  5947. nullpo_retv(g);
  5948. fd=sd->fd;
  5949. WFIFOHEAD(fd,packet_len(0x16a));
  5950. WFIFOW(fd,0)=0x16a;
  5951. WFIFOL(fd,2)=g->guild_id;
  5952. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5953. WFIFOSET(fd,packet_len(0x16a));
  5954. }
  5955. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  5956. /// 0169 <answer>.B
  5957. /// answer:
  5958. /// 0 = Already in guild.
  5959. /// 1 = Offer rejected.
  5960. /// 2 = Offer accepted.
  5961. /// 3 = Guild full.
  5962. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  5963. {
  5964. int fd;
  5965. nullpo_retv(sd);
  5966. fd=sd->fd;
  5967. WFIFOHEAD(fd,packet_len(0x169));
  5968. WFIFOW(fd,0)=0x169;
  5969. WFIFOB(fd,2)=flag;
  5970. WFIFOSET(fd,packet_len(0x169));
  5971. }
  5972. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  5973. /// 015a <char name>.24B <reason>.40B
  5974. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5975. {
  5976. unsigned char buf[128];
  5977. nullpo_retv(sd);
  5978. WBUFW(buf, 0)=0x15a;
  5979. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5980. memcpy(WBUFP(buf,26),mes,40);
  5981. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  5982. }
  5983. /// Notifies clients of a guild of an expelled member.
  5984. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  5985. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  5986. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  5987. {
  5988. unsigned char buf[128];
  5989. #if PACKETVER < 20100803
  5990. const unsigned short cmd = 0x15c;
  5991. #else
  5992. const unsigned short cmd = 0x839;
  5993. #endif
  5994. nullpo_retv(sd);
  5995. WBUFW(buf,0) = cmd;
  5996. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  5997. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  5998. #if PACKETVER < 20100803
  5999. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6000. #endif
  6001. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6002. }
  6003. /// Guild expulsion list (ZC_BAN_LIST).
  6004. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6005. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6006. void clif_guild_expulsionlist(struct map_session_data* sd)
  6007. {
  6008. #if PACKETVER < 20100803
  6009. const int offset = NAME_LENGTH*2+40;
  6010. #else
  6011. const int offset = NAME_LENGTH+40;
  6012. #endif
  6013. int fd, i, c = 0;
  6014. struct guild* g;
  6015. nullpo_retv(sd);
  6016. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6017. return;
  6018. fd = sd->fd;
  6019. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6020. WFIFOW(fd,0) = 0x163;
  6021. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6022. {
  6023. struct guild_expulsion* e = &g->expulsion[i];
  6024. if( e->account_id > 0 )
  6025. {
  6026. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6027. #if PACKETVER < 20100803
  6028. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6029. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6030. #else
  6031. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6032. #endif
  6033. c++;
  6034. }
  6035. }
  6036. WFIFOW(fd,2) = 4 + c*offset;
  6037. WFIFOSET(fd,WFIFOW(fd,2));
  6038. }
  6039. /// Guild chat message (ZC_GUILD_CHAT).
  6040. /// 017f <packet len>.W <message>.?B
  6041. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6042. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6043. struct map_session_data *sd;
  6044. uint8 buf[256];
  6045. if( len == 0 )
  6046. {
  6047. return;
  6048. }
  6049. else if( len > sizeof(buf)-5 )
  6050. {
  6051. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6052. len = sizeof(buf)-5;
  6053. }
  6054. WBUFW(buf, 0) = 0x17f;
  6055. WBUFW(buf, 2) = len + 5;
  6056. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6057. if ((sd = guild_getavailablesd(g)) != NULL)
  6058. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6059. }
  6060. /*==========================================
  6061. * Server tells client 'sd' that his guild skill 'skill_num' gone to level 'lv'
  6062. *------------------------------------------*/
  6063. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6064. {// TODO: Merge with clif_skillup (same packet).
  6065. int fd;
  6066. nullpo_ret(sd);
  6067. fd=sd->fd;
  6068. WFIFOHEAD(fd,11);
  6069. WFIFOW(fd,0) = 0x10e;
  6070. WFIFOW(fd,2) = skill_num;
  6071. WFIFOW(fd,4) = lv;
  6072. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6073. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6074. WFIFOB(fd,10) = 1;
  6075. WFIFOSET(fd,11);
  6076. return 0;
  6077. }
  6078. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6079. /// 0171 <inviter account id>.L <guild name>.24B
  6080. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6081. {
  6082. int fd;
  6083. nullpo_retv(sd);
  6084. fd=sd->fd;
  6085. WFIFOHEAD(fd,packet_len(0x171));
  6086. WFIFOW(fd,0)=0x171;
  6087. WFIFOL(fd,2)=account_id;
  6088. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6089. WFIFOSET(fd,packet_len(0x171));
  6090. }
  6091. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6092. /// 0173 <answer>.B
  6093. /// answer:
  6094. /// 0 = Already allied.
  6095. /// 1 = You rejected the offer.
  6096. /// 2 = You accepted the offer.
  6097. /// 3 = They have too any alliances.
  6098. /// 4 = You have too many alliances.
  6099. /// 5 = Alliances are disabled.
  6100. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6101. {
  6102. int fd;
  6103. nullpo_retv(sd);
  6104. fd=sd->fd;
  6105. WFIFOHEAD(fd,packet_len(0x173));
  6106. WFIFOW(fd,0)=0x173;
  6107. WFIFOL(fd,2)=flag;
  6108. WFIFOSET(fd,packet_len(0x173));
  6109. }
  6110. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6111. /// 0184 <other guild id>.L <relation>.L
  6112. /// relation:
  6113. /// 0 = Ally
  6114. /// 1 = Enemy
  6115. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6116. {
  6117. int fd;
  6118. nullpo_retv(sd);
  6119. fd = sd->fd;
  6120. if (fd <= 0)
  6121. return;
  6122. WFIFOHEAD(fd,packet_len(0x184));
  6123. WFIFOW(fd,0)=0x184;
  6124. WFIFOL(fd,2)=guild_id;
  6125. WFIFOL(fd,6)=flag;
  6126. WFIFOSET(fd,packet_len(0x184));
  6127. }
  6128. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6129. /// 0181 <result>.B
  6130. /// result:
  6131. /// 0 = Antagonist has been set.
  6132. /// 1 = Guild has too many Antagonists.
  6133. /// 2 = Already set as an Antagonist.
  6134. /// 3 = Antagonists are disabled.
  6135. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6136. {
  6137. int fd;
  6138. nullpo_retv(sd);
  6139. fd=sd->fd;
  6140. WFIFOHEAD(fd,packet_len(0x181));
  6141. WFIFOW(fd,0)=0x181;
  6142. WFIFOB(fd,2)=flag;
  6143. WFIFOSET(fd,packet_len(0x181));
  6144. }
  6145. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6146. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6147. /*
  6148. void clif_guild_allianceadded(struct guild *g,int idx)
  6149. {
  6150. unsigned char buf[64];
  6151. WBUFW(buf,0)=0x185;
  6152. WBUFL(buf,2)=g->alliance[idx].opposition;
  6153. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6154. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6155. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6156. }
  6157. */
  6158. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6159. /// 015e <reason>.L
  6160. /// 0 = success
  6161. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6162. /// 2 = there are still members in the guild
  6163. void clif_guild_broken(struct map_session_data *sd,int flag)
  6164. {
  6165. int fd;
  6166. nullpo_retv(sd);
  6167. fd=sd->fd;
  6168. WFIFOHEAD(fd,packet_len(0x15e));
  6169. WFIFOW(fd,0)=0x15e;
  6170. WFIFOL(fd,2)=flag;
  6171. WFIFOSET(fd,packet_len(0x15e));
  6172. }
  6173. /// Displays emotion on an object (ZC_EMOTION).
  6174. /// 00c0 <id>.L <type>.B
  6175. /// type:
  6176. /// enum emotion_type
  6177. void clif_emotion(struct block_list *bl,int type)
  6178. {
  6179. unsigned char buf[8];
  6180. nullpo_retv(bl);
  6181. WBUFW(buf,0)=0xc0;
  6182. WBUFL(buf,2)=bl->id;
  6183. WBUFB(buf,6)=type;
  6184. clif_send(buf,packet_len(0xc0),bl,AREA);
  6185. }
  6186. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6187. /// 0191 <id>.L <contents>.80B
  6188. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6189. {
  6190. unsigned char buf[MESSAGE_SIZE+6];
  6191. nullpo_retv(bl);
  6192. WBUFW(buf,0) = 0x191;
  6193. WBUFL(buf,2) = bl->id;
  6194. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6195. clif_send(buf,packet_len(0x191),bl,AREA);
  6196. }
  6197. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6198. /// 01ea <id>.L
  6199. void clif_wedding_effect(struct block_list *bl)
  6200. {
  6201. unsigned char buf[6];
  6202. nullpo_retv(bl);
  6203. WBUFW(buf,0) = 0x1ea;
  6204. WBUFL(buf,2) = bl->id;
  6205. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6206. }
  6207. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6208. /// 01e6 <partner name>.24B
  6209. void clif_callpartner(struct map_session_data *sd)
  6210. {
  6211. unsigned char buf[26];
  6212. const char *p;
  6213. nullpo_retv(sd);
  6214. // TODO: Send zero-length name if no partner (to initialize the client buffer).
  6215. if(sd->status.partner_id){
  6216. WBUFW(buf,0)=0x1e6;
  6217. p = map_charid2nick(sd->status.partner_id);
  6218. if(p){
  6219. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6220. }else{
  6221. WBUFB(buf,2) = 0;
  6222. }
  6223. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6224. }
  6225. }
  6226. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6227. /// 01e4
  6228. /// This packet while still implemented by the client is no longer being officially used.
  6229. /*
  6230. void clif_marriage_process(struct map_session_data *sd)
  6231. {
  6232. int fd;
  6233. nullpo_retv(sd);
  6234. fd=sd->fd;
  6235. WFIFOHEAD(fd,packet_len(0x1e4));
  6236. WFIFOW(fd,0)=0x1e4;
  6237. WFIFOSET(fd,packet_len(0x1e4));
  6238. }
  6239. */
  6240. /// Notice of divorce (ZC_DIVORCE).
  6241. /// 0205 <partner name>.24B
  6242. void clif_divorced(struct map_session_data* sd, const char* name)
  6243. {
  6244. int fd;
  6245. nullpo_retv(sd);
  6246. fd=sd->fd;
  6247. WFIFOHEAD(fd,packet_len(0x205));
  6248. WFIFOW(fd,0)=0x205;
  6249. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6250. WFIFOSET(fd, packet_len(0x205));
  6251. }
  6252. /// Marriage proposal (ZC_REQ_COUPLE).
  6253. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6254. /// This packet while still implemented by the client is no longer being officially used.
  6255. /*
  6256. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6257. {
  6258. nullpo_retv(sd);
  6259. WFIFOHEAD(fd,packet_len(0x1e2));
  6260. WFIFOW(fd,0) = 0x1e2;
  6261. WFIFOL(fd,2) = ssd->status.account_id;
  6262. WFIFOL(fd,6) = ssd->status.char_id;
  6263. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6264. WFIFOSET(fd, packet_len(0x1e2));
  6265. }
  6266. */
  6267. /*==========================================
  6268. *
  6269. *------------------------------------------*/
  6270. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6271. {
  6272. clif_disp_message(&sd->bl, mes, len, SELF);
  6273. }
  6274. /*==========================================
  6275. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6276. *------------------------------------------*/
  6277. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6278. {
  6279. unsigned char buf[256];
  6280. if( len == 0 )
  6281. {
  6282. return;
  6283. }
  6284. else if( len > sizeof(buf)-5 )
  6285. {
  6286. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6287. len = sizeof(buf)-5;
  6288. }
  6289. WBUFW(buf, 0) = 0x17f;
  6290. WBUFW(buf, 2) = len + 5;
  6291. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6292. clif_send(buf, WBUFW(buf,2), src, target);
  6293. }
  6294. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6295. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6296. /// 00cd <result>.B
  6297. /// result:
  6298. /// 0 = failure
  6299. /// 1 = success
  6300. void clif_GM_kickack(struct map_session_data *sd, int id)
  6301. {
  6302. int fd;
  6303. nullpo_retv(sd);
  6304. fd = sd->fd;
  6305. WFIFOHEAD(fd,packet_len(0xcd));
  6306. WFIFOW(fd,0) = 0xcd;
  6307. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6308. WFIFOSET(fd, packet_len(0xcd));
  6309. }
  6310. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6311. {
  6312. int fd = tsd->fd;
  6313. if( fd > 0 )
  6314. clif_authfail_fd(fd, 15);
  6315. else
  6316. map_quit(tsd);
  6317. if( sd )
  6318. clif_GM_kickack(sd,tsd->status.account_id);
  6319. }
  6320. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6321. /// 014a <result>.L
  6322. /// result:
  6323. /// 0 = "A manner point has been successfully aligned."
  6324. /// 1 = MP_FAILURE_EXHAUST
  6325. /// 2 = MP_FAILURE_ALREADY_GIVING
  6326. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6327. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6328. /// 5 = "You got a good point from %s."
  6329. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6330. {
  6331. int fd;
  6332. nullpo_retv(sd);
  6333. fd = sd->fd;
  6334. WFIFOHEAD(fd,packet_len(0x14a));
  6335. WFIFOW(fd,0) = 0x14a;
  6336. WFIFOL(fd,2) = type;
  6337. WFIFOSET(fd, packet_len(0x14a));
  6338. }
  6339. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6340. /// 014b <type>.B <GM name>.24B
  6341. /// type:
  6342. /// 0 = positive (unmute)
  6343. /// 1 = negative (mute)
  6344. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6345. {
  6346. int fd;
  6347. nullpo_retv(sd);
  6348. nullpo_retv(tsd);
  6349. fd = tsd->fd;
  6350. WFIFOHEAD(fd,packet_len(0x14b));
  6351. WFIFOW(fd,0) = 0x14b;
  6352. WFIFOB(fd,2) = type;
  6353. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6354. WFIFOSET(fd, packet_len(0x14b));
  6355. }
  6356. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6357. /// 00d1 <type>.B <result>.B
  6358. /// type:
  6359. /// 0 = /ex (deny)
  6360. /// 1 = /in (allow)
  6361. /// result:
  6362. /// 0 = success
  6363. /// 1 = failure
  6364. /// 2 = too many blocks
  6365. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6366. {
  6367. int fd;
  6368. nullpo_retv(sd);
  6369. fd=sd->fd;
  6370. WFIFOHEAD(fd,packet_len(0xd1));
  6371. WFIFOW(fd,0)=0xd1;
  6372. WFIFOB(fd,2)=type;
  6373. WFIFOB(fd,3)=flag;
  6374. WFIFOSET(fd,packet_len(0xd1));
  6375. }
  6376. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6377. /// 00d2 <type>.B <result>.B
  6378. /// type:
  6379. /// 0 = /exall (deny)
  6380. /// 1 = /inall (allow)
  6381. /// result:
  6382. /// 0 = success
  6383. /// 1 = failure
  6384. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6385. {
  6386. int fd;
  6387. nullpo_retv(sd);
  6388. fd=sd->fd;
  6389. WFIFOHEAD(fd,packet_len(0xd2));
  6390. WFIFOW(fd,0)=0xd2;
  6391. WFIFOB(fd,2)=type;
  6392. WFIFOB(fd,3)=flag;
  6393. WFIFOSET(fd,packet_len(0xd2));
  6394. }
  6395. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6396. /// 07fe <bgm>.24B
  6397. void clif_playBGM(struct map_session_data* sd, const char* name)
  6398. {
  6399. int fd;
  6400. nullpo_retv(sd);
  6401. fd = sd->fd;
  6402. WFIFOHEAD(fd,packet_len(0x7fe));
  6403. WFIFOW(fd,0) = 0x7fe;
  6404. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6405. WFIFOSET(fd,packet_len(0x7fe));
  6406. }
  6407. /// Plays/stops a wave sound (ZC_SOUND).
  6408. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6409. /// file name:
  6410. /// relative to data\wav
  6411. /// act:
  6412. /// 0 = play (once)
  6413. /// 1 = play (repeat, does not work)
  6414. /// 2 = stops all sound instances of file name (does not work)
  6415. /// term:
  6416. /// unknown purpose, only relevant to act = 1
  6417. /// npc id:
  6418. /// The accustic direction of the sound is determined by the
  6419. /// relative position of the NPC to the player (3D sound).
  6420. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6421. {
  6422. int fd;
  6423. nullpo_retv(sd);
  6424. nullpo_retv(bl);
  6425. fd = sd->fd;
  6426. WFIFOHEAD(fd,packet_len(0x1d3));
  6427. WFIFOW(fd,0) = 0x1d3;
  6428. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6429. WFIFOB(fd,26) = type;
  6430. WFIFOL(fd,27) = 0;
  6431. WFIFOL(fd,31) = bl->id;
  6432. WFIFOSET(fd,packet_len(0x1d3));
  6433. }
  6434. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6435. {
  6436. unsigned char buf[40];
  6437. nullpo_retv(bl);
  6438. WBUFW(buf,0) = 0x1d3;
  6439. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6440. WBUFB(buf,26) = type;
  6441. WBUFL(buf,27) = 0;
  6442. WBUFL(buf,31) = bl->id;
  6443. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6444. }
  6445. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6446. /// 01f3 <id>.L <effect id>.L
  6447. /// effect id:
  6448. /// @see doc/effect_list.txt
  6449. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6450. {
  6451. unsigned char buf[24];
  6452. nullpo_retv(bl);
  6453. memset(buf, 0, packet_len(0x1f3));
  6454. WBUFW(buf,0) = 0x1f3;
  6455. WBUFL(buf,2) = bl->id;
  6456. WBUFL(buf,6) = type;
  6457. clif_send(buf, packet_len(0x1f3), bl, target);
  6458. if (disguised(bl)) {
  6459. WBUFL(buf,2) = -bl->id;
  6460. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6461. }
  6462. }
  6463. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6464. {
  6465. WFIFOHEAD(fd,10);
  6466. WFIFOW(fd,0) = 0x1f3;
  6467. WFIFOL(fd,2) = bl->id;
  6468. WFIFOL(fd,6) = type;
  6469. WFIFOSET(fd,10);
  6470. }
  6471. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  6472. /// 0284 <id>.L <effect id>.L <num data>.L
  6473. /// effect id:
  6474. /// @see doc/effect_list.txt
  6475. /// num data:
  6476. /// effect-dependent value
  6477. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  6478. {
  6479. uint8 buf[14];
  6480. WBUFW(buf,0) = 0x284;
  6481. WBUFL(buf,2) = bl->id;
  6482. WBUFL(buf,6) = effect_id;
  6483. WBUFL(buf,10) = num;
  6484. clif_send(buf, packet_len(0x284), bl, target);
  6485. if( disguised(bl) )
  6486. {
  6487. WBUFL(buf,2) = -bl->id;
  6488. clif_send(buf, packet_len(0x284), bl, SELF);
  6489. }
  6490. }
  6491. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  6492. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6493. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  6494. unsigned short msg_len = strlen(msg) + 1;
  6495. WFIFOHEAD(sd->fd,msg_len + 12);
  6496. WFIFOW(sd->fd,0) = 0x2C1;
  6497. WFIFOW(sd->fd,2) = msg_len + 12;
  6498. WFIFOL(sd->fd,4) = 0;
  6499. WFIFOL(sd->fd,8) = color_table[color];
  6500. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  6501. clif_send(WFIFOP(sd->fd,0), WFIFOW(sd->fd,2), &sd->bl, SELF);
  6502. return 0;
  6503. }
  6504. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  6505. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  6506. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  6507. unsigned short msg_len = strlen(msg) + 1;
  6508. uint8 buf[256];
  6509. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6510. nullpo_retv(bl);
  6511. if( msg_len > sizeof(buf)-12 )
  6512. {
  6513. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6514. msg_len = sizeof(buf)-12;
  6515. }
  6516. WBUFW(buf,0) = 0x2C1;
  6517. WBUFW(buf,2) = msg_len + 12;
  6518. WBUFL(buf,4) = bl->id;
  6519. WBUFL(buf,8) = color;
  6520. memcpy(WBUFP(buf,12), msg, msg_len);
  6521. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6522. }
  6523. /// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  6524. /// 008d <packet len>.W <id>.L <message>.?B
  6525. void clif_message(struct block_list* bl, const char* msg)
  6526. {
  6527. unsigned short msg_len = strlen(msg) + 1;
  6528. uint8 buf[256];
  6529. // TODO: Merge with other 0x8d functions.
  6530. nullpo_retv(bl);
  6531. if( msg_len > sizeof(buf)-8 )
  6532. {
  6533. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6534. msg_len = sizeof(buf)-8;
  6535. }
  6536. WBUFW(buf,0) = 0x8d;
  6537. WBUFW(buf,2) = msg_len + 8;
  6538. WBUFL(buf,4) = bl->id;
  6539. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  6540. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6541. }
  6542. // refresh the client's screen, getting rid of any effects
  6543. void clif_refresh(struct map_session_data *sd)
  6544. {
  6545. nullpo_retv(sd);
  6546. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6547. clif_inventorylist(sd);
  6548. if(pc_iscarton(sd)) {
  6549. clif_cartlist(sd);
  6550. clif_updatestatus(sd,SP_CARTINFO);
  6551. }
  6552. clif_updatestatus(sd,SP_WEIGHT);
  6553. clif_updatestatus(sd,SP_MAXWEIGHT);
  6554. clif_updatestatus(sd,SP_STR);
  6555. clif_updatestatus(sd,SP_AGI);
  6556. clif_updatestatus(sd,SP_VIT);
  6557. clif_updatestatus(sd,SP_INT);
  6558. clif_updatestatus(sd,SP_DEX);
  6559. clif_updatestatus(sd,SP_LUK);
  6560. if (sd->spiritball)
  6561. clif_spiritball_single(sd->fd, sd);
  6562. if (sd->vd.cloth_color)
  6563. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6564. if(merc_is_hom_active(sd->hd))
  6565. clif_send_homdata(sd,SP_ACK,0);
  6566. if( sd->md )
  6567. {
  6568. clif_mercenary_info(sd);
  6569. clif_mercenary_skillblock(sd);
  6570. }
  6571. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6572. clif_weather_check(sd);
  6573. if( sd->chatID )
  6574. chat_leavechat(sd,0);
  6575. if( sd->state.vending )
  6576. clif_openvending(sd, sd->bl.id, sd->vending);
  6577. if( pc_issit(sd) )
  6578. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6579. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  6580. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  6581. else
  6582. clif_changed_dir(&sd->bl, SELF);
  6583. // unlike vending, resuming buyingstore crashes the client.
  6584. buyingstore_close(sd);
  6585. mail_clear(sd);
  6586. }
  6587. /// Updates the object's (bl) name on client.
  6588. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  6589. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  6590. void clif_charnameack (int fd, struct block_list *bl)
  6591. {
  6592. unsigned char buf[103];
  6593. int cmd = 0x95, i, ps = -1;
  6594. nullpo_retv(bl);
  6595. WBUFW(buf,0) = cmd;
  6596. WBUFL(buf,2) = bl->id;
  6597. switch( bl->type )
  6598. {
  6599. case BL_PC:
  6600. {
  6601. struct map_session_data *ssd = (struct map_session_data *)bl;
  6602. struct party_data *p = NULL;
  6603. struct guild *g = NULL;
  6604. //Requesting your own "shadow" name. [Skotlex]
  6605. if (ssd->fd == fd && ssd->disguise)
  6606. WBUFL(buf,2) = -bl->id;
  6607. if( ssd->fakename[0] )
  6608. {
  6609. WBUFW(buf, 0) = cmd = 0x195;
  6610. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6611. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  6612. break;
  6613. }
  6614. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6615. if( ssd->status.party_id )
  6616. {
  6617. p = party_search(ssd->status.party_id);
  6618. }
  6619. if( ssd->status.guild_id )
  6620. {
  6621. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  6622. {
  6623. 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);
  6624. if( i < g->max_member ) ps = g->member[i].position;
  6625. }
  6626. }
  6627. if( !battle_config.display_party_name && g == NULL )
  6628. {// do not display party unless the player is also in a guild
  6629. p = NULL;
  6630. }
  6631. if (p == NULL && g == NULL)
  6632. break;
  6633. WBUFW(buf, 0) = cmd = 0x195;
  6634. if (p)
  6635. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6636. else
  6637. WBUFB(buf,30) = 0;
  6638. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6639. {
  6640. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6641. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6642. } else { //Assume no guild.
  6643. WBUFB(buf,54) = 0;
  6644. WBUFB(buf,78) = 0;
  6645. }
  6646. }
  6647. break;
  6648. //[blackhole89]
  6649. case BL_HOM:
  6650. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6651. break;
  6652. case BL_MER:
  6653. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6654. break;
  6655. case BL_PET:
  6656. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6657. break;
  6658. case BL_NPC:
  6659. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6660. break;
  6661. case BL_MOB:
  6662. {
  6663. struct mob_data *md = (struct mob_data *)bl;
  6664. nullpo_retv(md);
  6665. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6666. if( md->guardian_data && md->guardian_data->guild_id )
  6667. {
  6668. WBUFW(buf, 0) = cmd = 0x195;
  6669. WBUFB(buf,30) = 0;
  6670. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6671. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6672. }
  6673. else if( battle_config.show_mob_info )
  6674. {
  6675. char mobhp[50], *str_p = mobhp;
  6676. WBUFW(buf, 0) = cmd = 0x195;
  6677. if( battle_config.show_mob_info&4 )
  6678. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6679. if( battle_config.show_mob_info&1 )
  6680. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6681. if( battle_config.show_mob_info&2 )
  6682. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6683. //Even thought mobhp ain't a name, we send it as one so the client
  6684. //can parse it. [Skotlex]
  6685. if( str_p != mobhp )
  6686. {
  6687. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6688. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6689. WBUFB(buf,54) = 0;
  6690. WBUFB(buf,78) = 0;
  6691. }
  6692. }
  6693. }
  6694. break;
  6695. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6696. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6697. // break;
  6698. return;
  6699. default:
  6700. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6701. return;
  6702. }
  6703. // if no receipient specified just update nearby clients
  6704. if (fd == 0)
  6705. clif_send(buf, packet_len(cmd), bl, AREA);
  6706. else {
  6707. WFIFOHEAD(fd, packet_len(cmd));
  6708. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6709. WFIFOSET(fd, packet_len(cmd));
  6710. }
  6711. }
  6712. //Used to update when a char leaves a party/guild. [Skotlex]
  6713. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6714. void clif_charnameupdate (struct map_session_data *ssd)
  6715. {
  6716. unsigned char buf[103];
  6717. int cmd = 0x195, ps = -1, i;
  6718. struct party_data *p = NULL;
  6719. struct guild *g = NULL;
  6720. nullpo_retv(ssd);
  6721. if( ssd->fakename[0] )
  6722. return; //No need to update as the party/guild was not displayed anyway.
  6723. WBUFW(buf,0) = cmd;
  6724. WBUFL(buf,2) = ssd->bl.id;
  6725. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6726. if (!battle_config.display_party_name) {
  6727. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  6728. p = party_search(ssd->status.party_id);
  6729. }else{
  6730. if (ssd->status.party_id > 0)
  6731. p = party_search(ssd->status.party_id);
  6732. }
  6733. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6734. {
  6735. 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);
  6736. if( i < g->max_member ) ps = g->member[i].position;
  6737. }
  6738. if( p )
  6739. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6740. else
  6741. WBUFB(buf,30) = 0;
  6742. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  6743. {
  6744. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6745. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6746. }
  6747. else
  6748. {
  6749. WBUFB(buf,54) = 0;
  6750. WBUFB(buf,78) = 0;
  6751. }
  6752. // Update nearby clients
  6753. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6754. }
  6755. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  6756. /// 01ff <id>.L <x>.W <y>.W
  6757. ///
  6758. /// Visually moves(instant) a character to x,y. The char moves even
  6759. /// when the target cell isn't walkable. If the char is sitting it
  6760. /// stays that way.
  6761. void clif_slide(struct block_list *bl, int x, int y)
  6762. {
  6763. unsigned char buf[10];
  6764. nullpo_retv(bl);
  6765. WBUFW(buf, 0) = 0x01ff;
  6766. WBUFL(buf, 2) = bl->id;
  6767. WBUFW(buf, 6) = x;
  6768. WBUFW(buf, 8) = y;
  6769. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6770. if( disguised(bl) )
  6771. {
  6772. WBUFL(buf,2) = -bl->id;
  6773. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6774. }
  6775. }
  6776. /*------------------------------------------
  6777. * @me command by lordalfa, rewritten implementation by Skotlex
  6778. *------------------------------------------*/
  6779. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6780. {
  6781. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6782. int len_mes = strlen(mes)+1; //Account for \0
  6783. if (len_mes > sizeof(buf)-8) {
  6784. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6785. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  6786. }
  6787. // send message to others
  6788. WBUFW(buf,0) = 0x8d;
  6789. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6790. WBUFL(buf,4) = sd->bl.id;
  6791. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  6792. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6793. // send back message to the speaker
  6794. WBUFW(buf,0) = 0x8e;
  6795. WBUFW(buf, 2) = len_mes + 4;
  6796. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  6797. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6798. }
  6799. /*==========================
  6800. * Minimap fix [Kevin]
  6801. * Remove dot from minimap
  6802. *--------------------------*/
  6803. void clif_party_xy_remove(struct map_session_data *sd)
  6804. {
  6805. unsigned char buf[16];
  6806. nullpo_retv(sd);
  6807. WBUFW(buf,0)=0x107;
  6808. WBUFL(buf,2)=sd->status.account_id;
  6809. WBUFW(buf,6)=-1;
  6810. WBUFW(buf,8)=-1;
  6811. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6812. }
  6813. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  6814. /// 0215 <msg id>.L
  6815. /// msg id:
  6816. /// 0x15 = End all negative status (PA_GOSPEL)
  6817. /// 0x16 = Immunity to all status (PA_GOSPEL)
  6818. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  6819. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  6820. /// 0x19 = All stats +20 (PA_GOSPEL)
  6821. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  6822. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  6823. /// 0x1e = DEF +25% (PA_GOSPEL)
  6824. /// 0x1f = ATK +100% (PA_GOSPEL)
  6825. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  6826. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  6827. /// ? = nothing
  6828. void clif_gospel_info(struct map_session_data *sd, int type)
  6829. {
  6830. int fd=sd->fd;
  6831. WFIFOHEAD(fd,packet_len(0x215));
  6832. WFIFOW(fd,0)=0x215;
  6833. WFIFOL(fd,2)=type;
  6834. WFIFOSET(fd, packet_len(0x215));
  6835. }
  6836. /// Multi-purpose mission information packet (ZC_STARSKILL).
  6837. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  6838. /// result:
  6839. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  6840. /// star:
  6841. /// 0 = Place of the Sun
  6842. /// 1 = Place of the Moon
  6843. /// 2 = Place of the Stars
  6844. /// 1 = Star Gladiator %s's %s: <mapname>
  6845. /// star:
  6846. /// 0 = Place of the Sun
  6847. /// 1 = Place of the Moon
  6848. /// 2 = Place of the Stars
  6849. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  6850. /// star:
  6851. /// 0 = Target of the Sun
  6852. /// 1 = Target of the Moon
  6853. /// 2 = Target of the Stars
  6854. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  6855. /// star:
  6856. /// 0 = Monster of the Sun
  6857. /// 1 = Monster of the Moon
  6858. /// 2 = Monster of the Stars
  6859. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  6860. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  6861. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  6862. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  6863. /// 40 = Target HP : <monster_id used as HP>
  6864. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  6865. {
  6866. int fd = sd->fd;
  6867. WFIFOHEAD(fd,packet_len(0x20e));
  6868. WFIFOW(fd,0) = 0x20e;
  6869. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  6870. WFIFOL(fd,26) = monster_id;
  6871. WFIFOB(fd,30) = star;
  6872. WFIFOB(fd,31) = result;
  6873. WFIFOSET(fd,packet_len(0x20e));
  6874. }
  6875. /*==========================================
  6876. * Info about Star Glaldiator save map [Komurka]
  6877. * type: 1: Information, 0: Map registered
  6878. *------------------------------------------*/
  6879. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6880. {
  6881. char mapname[MAP_NAME_LENGTH_EXT];
  6882. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  6883. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  6884. }
  6885. /*==========================================
  6886. * Info about Star Glaldiator hate mob [Komurka]
  6887. * type: 1: Register mob, 0: Information.
  6888. *------------------------------------------*/
  6889. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6890. {
  6891. if( pcdb_checkid(class_) )
  6892. {
  6893. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  6894. }
  6895. else if( mobdb_checkid(class_) )
  6896. {
  6897. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  6898. }
  6899. else
  6900. {
  6901. 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);
  6902. }
  6903. }
  6904. /*==========================================
  6905. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6906. *------------------------------------------*/
  6907. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6908. {
  6909. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  6910. }
  6911. /*==========================================
  6912. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6913. *------------------------------------------*/
  6914. void clif_feel_hate_reset(struct map_session_data *sd)
  6915. {
  6916. clif_starskill(sd, "", 0, 0, 30);
  6917. }
  6918. /// Equip window (un)tick ack (ZC_CONFIG).
  6919. /// 02d9 <type>.L <value>.L
  6920. /// type:
  6921. /// 0 = open equip window
  6922. /// value:
  6923. /// 0 = disabled
  6924. /// 1 = enabled
  6925. void clif_equiptickack(struct map_session_data* sd, int flag)
  6926. {
  6927. int fd;
  6928. nullpo_retv(sd);
  6929. fd = sd->fd;
  6930. WFIFOHEAD(fd, packet_len(0x2d9));
  6931. WFIFOW(fd, 0) = 0x2d9;
  6932. WFIFOL(fd, 2) = 0;
  6933. WFIFOL(fd, 6) = flag;
  6934. WFIFOSET(fd, packet_len(0x2d9));
  6935. }
  6936. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  6937. /// 02da <open equip window>.B
  6938. /// open equip window:
  6939. /// 0 = disabled
  6940. /// 1 = enabled
  6941. void clif_equipcheckbox(struct map_session_data* sd)
  6942. {
  6943. int fd;
  6944. nullpo_retv(sd);
  6945. fd = sd->fd;
  6946. WFIFOHEAD(fd, packet_len(0x2da));
  6947. WFIFOW(fd, 0) = 0x2da;
  6948. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6949. WFIFOSET(fd, packet_len(0x2da));
  6950. }
  6951. /// Sends info about a player's equipped items.
  6952. /// 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)
  6953. /// 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)
  6954. /// 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)
  6955. /// 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)
  6956. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6957. {
  6958. uint8* buf;
  6959. int i, n, fd, offset = 0;
  6960. #if PACKETVER < 20100629
  6961. const int s = 26;
  6962. #else
  6963. const int s = 28;
  6964. #endif
  6965. nullpo_retv(sd);
  6966. nullpo_retv(tsd);
  6967. fd = sd->fd;
  6968. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  6969. buf = WFIFOP(fd,0);
  6970. #if PACKETVER < 20101124
  6971. WBUFW(buf, 0) = 0x2d7;
  6972. #else
  6973. WBUFW(buf, 0) = 0x859;
  6974. #endif
  6975. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  6976. WBUFW(buf,28) = tsd->status.class_;
  6977. WBUFW(buf,30) = tsd->vd.hair_style;
  6978. WBUFW(buf,32) = tsd->vd.head_bottom;
  6979. WBUFW(buf,34) = tsd->vd.head_mid;
  6980. WBUFW(buf,36) = tsd->vd.head_top;
  6981. #if PACKETVER >= 20110111
  6982. WBUFW(buf,38) = tsd->vd.robe;
  6983. offset+= 2;
  6984. buf = WBUFP(buf,2);
  6985. #endif
  6986. WBUFW(buf,38) = tsd->vd.hair_color;
  6987. WBUFW(buf,40) = tsd->vd.cloth_color;
  6988. WBUFB(buf,42) = tsd->vd.sex;
  6989. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6990. {
  6991. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6992. continue;
  6993. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  6994. continue;
  6995. // Inventory position
  6996. WBUFW(buf, n*s+43) = i + 2;
  6997. // Add refine, identify flag, element, etc.
  6998. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6999. // Add cards
  7000. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7001. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7002. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7003. WBUFW(buf, n*s+67) = 0;
  7004. #if PACKETVER >= 20100629
  7005. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7006. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7007. else
  7008. WBUFW(buf, n*s+69) = 0;
  7009. #endif
  7010. n++;
  7011. }
  7012. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7013. WFIFOSET(fd, WFIFOW(fd, 2));
  7014. }
  7015. /// Display msgstringtable.txt string (ZC_MSG).
  7016. /// 0291 <message>.W
  7017. void clif_msg(struct map_session_data* sd, unsigned short id)
  7018. {
  7019. int fd;
  7020. nullpo_retv(sd);
  7021. fd = sd->fd;
  7022. WFIFOHEAD(fd, packet_len(0x291));
  7023. WFIFOW(fd, 0) = 0x291;
  7024. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7025. WFIFOSET(fd, packet_len(0x291));
  7026. }
  7027. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7028. /// 0x7e2 <message>.W <value>.L
  7029. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7030. {
  7031. int fd = sd->fd;
  7032. WFIFOHEAD(fd, packet_len(0x7e2));
  7033. WFIFOW(fd,0) = 0x7e2;
  7034. WFIFOW(fd,2) = id;
  7035. WFIFOL(fd,4) = value;
  7036. WFIFOSET(fd, packet_len(0x7e2));
  7037. }
  7038. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7039. /// 07e6 <skill id>.W <msg id>.L
  7040. ///
  7041. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7042. /// "[SkillName] Message"
  7043. void clif_msg_skill(struct map_session_data* sd, unsigned short skill_id, int msg_id)
  7044. {
  7045. int fd = sd->fd;
  7046. WFIFOHEAD(fd, packet_len(0x7e6));
  7047. WFIFOW(fd,0) = 0x7e6;
  7048. WFIFOW(fd,2) = skill_id;
  7049. WFIFOL(fd,4) = msg_id;
  7050. WFIFOSET(fd, packet_len(0x7e6));
  7051. }
  7052. /// View player equip request denied
  7053. void clif_viewequip_fail(struct map_session_data* sd)
  7054. {
  7055. clif_msg(sd, 0x54d);
  7056. }
  7057. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7058. /// Returns true if the packet was parsed successfully.
  7059. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7060. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7061. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7062. {
  7063. char *text, *name, *message;
  7064. unsigned int packetlen, textlen, namelen, messagelen;
  7065. int fd = sd->fd;
  7066. *name_ = NULL;
  7067. *namelen_ = 0;
  7068. *message_ = NULL;
  7069. *messagelen_ = 0;
  7070. packetlen = RFIFOW(fd,2);
  7071. // basic structure checks
  7072. if( packetlen < 4 + 1 )
  7073. { // 4-byte header and at least an empty string is expected
  7074. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7075. return false;
  7076. }
  7077. text = (char*)RFIFOP(fd,4);
  7078. textlen = packetlen - 4;
  7079. // process <name> part of the packet
  7080. if( format == 0 )
  7081. {// name and message are separated by ' : '
  7082. // validate name
  7083. name = text;
  7084. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7085. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7086. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7087. {
  7088. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7089. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7090. set_eof(fd); // Just kick them out to correct it.
  7091. return false;
  7092. }
  7093. message = name + namelen + 3;
  7094. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7095. }
  7096. else
  7097. {// name has fixed width
  7098. if( textlen < NAME_LENGTH + 1 )
  7099. {
  7100. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7101. return false;
  7102. }
  7103. // validate name
  7104. name = text;
  7105. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7106. if( name[namelen] != '\0' )
  7107. { // only restriction is that the name must be zero-terminated
  7108. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7109. return false;
  7110. }
  7111. message = name + NAME_LENGTH;
  7112. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7113. }
  7114. if( messagelen != strnlen(message, messagelen)+1 )
  7115. { // the declared length must match real length
  7116. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7117. return false;
  7118. }
  7119. // verify <message> part of the packet
  7120. if( message[messagelen-1] != '\0' )
  7121. { // message must be zero-terminated
  7122. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7123. return false;
  7124. }
  7125. if( messagelen > CHAT_SIZE_MAX-1 )
  7126. { // messages mustn't be too long
  7127. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7128. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7129. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7130. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7131. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7132. return false;
  7133. }
  7134. *name_ = name;
  7135. *namelen_ = namelen;
  7136. *message_ = message;
  7137. *messagelen_ = messagelen;
  7138. return true;
  7139. }
  7140. // ---------------------
  7141. // clif_guess_PacketVer
  7142. // ---------------------
  7143. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7144. // error codes:
  7145. // 0 - Success
  7146. // 1 - Unknown packet_ver
  7147. // 2 - Invalid account_id
  7148. // 3 - Invalid char_id
  7149. // 4 - Invalid login_id1 (reserved)
  7150. // 5 - Invalid client_tick (reserved)
  7151. // 6 - Invalid sex
  7152. // Only the first 'invalid' error that appears is used.
  7153. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7154. {
  7155. static int err = 1;
  7156. static int packet_ver = -1;
  7157. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7158. if (get_previous)
  7159. {//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]
  7160. if( error )
  7161. *error = err;
  7162. return packet_ver;
  7163. }
  7164. //By default, start searching on the default one.
  7165. err = 1;
  7166. packet_ver = clif_config.packet_db_ver;
  7167. cmd = RFIFOW(fd,0);
  7168. packet_len = RFIFOREST(fd);
  7169. #define SET_ERROR(n) \
  7170. if( err == 1 )\
  7171. err = n;\
  7172. //define SET_ERROR
  7173. // FIXME: If the packet is not received at once, this will FAIL.
  7174. // Figure out, when it happens, that only part of the packet is
  7175. // received, or fix the function to be able to deal with that
  7176. // case.
  7177. #define CHECK_PACKET_VER() \
  7178. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7179. ;/* not wanttoconnection or wrong length */\
  7180. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7181. { SET_ERROR(2); }/* invalid account_id */\
  7182. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7183. { SET_ERROR(3); }/* invalid char_id */\
  7184. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7185. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7186. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7187. { SET_ERROR(6); }/* invalid sex */\
  7188. else\
  7189. {\
  7190. err = 0;\
  7191. if( error )\
  7192. *error = 0;\
  7193. return packet_ver;\
  7194. }\
  7195. //define CHECK_PACKET_VER
  7196. CHECK_PACKET_VER();//Default packet version found.
  7197. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7198. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7199. CHECK_PACKET_VER();
  7200. }
  7201. if( error )
  7202. *error = err;
  7203. packet_ver = -1;
  7204. return -1;
  7205. #undef SET_ERROR
  7206. #undef CHECK_PACKET_VER
  7207. }
  7208. // ------------
  7209. // clif_parse_*
  7210. // ------------
  7211. // Parses incoming (player) connection
  7212. /// Request to connect to map-server.
  7213. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7214. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7215. /// There are various variants of this packet, some of them have padding between fields.
  7216. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7217. {
  7218. struct block_list* bl;
  7219. struct auth_node* node;
  7220. int cmd, account_id, char_id, login_id1, sex;
  7221. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7222. 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])
  7223. if (sd) {
  7224. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7225. return;
  7226. }
  7227. // Only valid packet version get here
  7228. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7229. cmd = RFIFOW(fd,0);
  7230. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7231. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7232. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7233. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7234. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7235. if( packet_ver < 5 || // reject really old client versions
  7236. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7237. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7238. {// packet version rejected
  7239. 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));
  7240. WFIFOHEAD(fd,packet_len(0x6a));
  7241. WFIFOW(fd,0) = 0x6a;
  7242. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7243. WFIFOSET(fd,packet_len(0x6a));
  7244. set_eof(fd);
  7245. return;
  7246. }
  7247. if( runflag != MAPSERVER_ST_RUNNING )
  7248. {// not allowed
  7249. clif_authfail_fd(fd,1);// server closed
  7250. return;
  7251. }
  7252. //Check for double login.
  7253. bl = map_id2bl(account_id);
  7254. if(bl && bl->type != BL_PC) {
  7255. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7256. WFIFOHEAD(fd,packet_len(0x6a));
  7257. WFIFOW(fd,0) = 0x6a;
  7258. WFIFOB(fd,2) = 3; // Rejected by server
  7259. WFIFOSET(fd,packet_len(0x6a));
  7260. set_eof(fd);
  7261. return;
  7262. }
  7263. if (bl ||
  7264. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7265. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7266. {
  7267. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7268. return;
  7269. }
  7270. CREATE(sd, TBL_PC, 1);
  7271. sd->fd = fd;
  7272. sd->packet_ver = packet_ver;
  7273. session[fd]->session_data = sd;
  7274. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7275. WFIFOHEAD(fd,packet_len(0x283));
  7276. WFIFOW(fd,0) = 0x283;
  7277. WFIFOL(fd,2) = sd->bl.id;
  7278. WFIFOSET(fd,packet_len(0x283));
  7279. chrif_authreq(sd);
  7280. return;
  7281. }
  7282. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7283. /// 007d
  7284. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7285. {
  7286. if(sd->bl.prev != NULL)
  7287. return;
  7288. if (!sd->state.active)
  7289. { //Character loading is not complete yet!
  7290. //Let pc_reg_received reinvoke this when ready.
  7291. sd->state.connect_new = 0;
  7292. return;
  7293. }
  7294. if (sd->state.rewarp)
  7295. { //Rewarp player.
  7296. sd->state.rewarp = 0;
  7297. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7298. return;
  7299. }
  7300. sd->state.warping = 0;
  7301. // look
  7302. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7303. if(sd->vd.cloth_color)
  7304. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7305. // item
  7306. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7307. pc_checkitem(sd);
  7308. // cart
  7309. if(pc_iscarton(sd)) {
  7310. clif_cartlist(sd);
  7311. clif_updatestatus(sd,SP_CARTINFO);
  7312. }
  7313. // weight
  7314. clif_updatestatus(sd,SP_WEIGHT);
  7315. clif_updatestatus(sd,SP_MAXWEIGHT);
  7316. // guild
  7317. // (needs to go before clif_spawn() to show guild emblems correctly)
  7318. if(sd->status.guild_id)
  7319. guild_send_memberinfoshort(sd,1);
  7320. if(battle_config.pc_invincible_time > 0) {
  7321. if(map_flag_gvg(sd->bl.m))
  7322. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7323. else
  7324. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7325. }
  7326. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7327. map_spawnmobs(sd->bl.m);
  7328. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7329. {// increment the number of pvp players on the map
  7330. map[sd->bl.m].users_pvp++;
  7331. }
  7332. if( map[sd->bl.m].instance_id )
  7333. {
  7334. instance[map[sd->bl.m].instance_id].users++;
  7335. instance_check_idle(map[sd->bl.m].instance_id);
  7336. }
  7337. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7338. // reset the callshop flag if the player changes map
  7339. sd->state.callshop = 0;
  7340. map_addblock(&sd->bl);
  7341. clif_spawn(&sd->bl);
  7342. // Party
  7343. // (needs to go after clif_spawn() to show hp bars correctly)
  7344. if(sd->status.party_id) {
  7345. party_send_movemap(sd);
  7346. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7347. }
  7348. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7349. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7350. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7351. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7352. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7353. sd->pvp_rank = 0;
  7354. sd->pvp_lastusers = 0;
  7355. sd->pvp_point = 5;
  7356. sd->pvp_won = 0;
  7357. sd->pvp_lost = 0;
  7358. }
  7359. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7360. } else
  7361. // set flag, if it's a duel [LuzZza]
  7362. if(sd->duel_group)
  7363. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7364. if (map[sd->bl.m].flag.gvg_dungeon)
  7365. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7366. if( map_flag_gvg(sd->bl.m) )
  7367. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7368. // info about nearby objects
  7369. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7370. 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);
  7371. // pet
  7372. if( sd->pd )
  7373. {
  7374. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7375. { //Return the pet to egg. [Skotlex]
  7376. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7377. pet_menu(sd, 3); //Option 3 is return to egg.
  7378. }
  7379. else
  7380. {
  7381. map_addblock(&sd->pd->bl);
  7382. clif_spawn(&sd->pd->bl);
  7383. clif_send_petdata(sd,sd->pd,0,0);
  7384. clif_send_petstatus(sd);
  7385. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7386. }
  7387. }
  7388. //homunculus [blackhole89]
  7389. if( merc_is_hom_active(sd->hd) )
  7390. {
  7391. map_addblock(&sd->hd->bl);
  7392. clif_spawn(&sd->hd->bl);
  7393. clif_send_homdata(sd,SP_ACK,0);
  7394. clif_hominfo(sd,sd->hd,1);
  7395. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7396. clif_homskillinfoblock(sd);
  7397. if( battle_config.hom_setting&0x8 )
  7398. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7399. if( !(battle_config.hom_setting&0x2) )
  7400. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7401. }
  7402. if( sd->md )
  7403. {
  7404. map_addblock(&sd->md->bl);
  7405. clif_spawn(&sd->md->bl);
  7406. clif_mercenary_info(sd);
  7407. clif_mercenary_skillblock(sd);
  7408. }
  7409. if(sd->state.connect_new) {
  7410. int lv;
  7411. sd->state.connect_new = 0;
  7412. clif_skillinfoblock(sd);
  7413. clif_hotkeys_send(sd);
  7414. clif_updatestatus(sd,SP_BASEEXP);
  7415. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7416. clif_updatestatus(sd,SP_JOBEXP);
  7417. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7418. clif_updatestatus(sd,SP_SKILLPOINT);
  7419. clif_initialstatus(sd);
  7420. if (sd->sc.option&OPTION_FALCON)
  7421. clif_status_load(&sd->bl, SI_FALCON, 1);
  7422. if (sd->sc.option&OPTION_RIDING)
  7423. clif_status_load(&sd->bl, SI_RIDING, 1);
  7424. if(sd->status.manner < 0)
  7425. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7426. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7427. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7428. if(sd->bl.m == sd->feel_map[0].m
  7429. || sd->bl.m == sd->feel_map[1].m
  7430. || sd->bl.m == sd->feel_map[2].m)
  7431. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7432. }
  7433. if(sd->pd && sd->pd->pet.intimate > 900)
  7434. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7435. if(merc_is_hom_active(sd->hd))
  7436. merc_hom_init_timers(sd->hd);
  7437. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7438. {
  7439. sd->state.night = 1;
  7440. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7441. }
  7442. // Notify everyone that this char logged in [Skotlex].
  7443. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7444. //Login Event
  7445. npc_script_event(sd, NPCE_LOGIN);
  7446. } else {
  7447. //For some reason the client "loses" these on warp/map-change.
  7448. clif_updatestatus(sd,SP_STR);
  7449. clif_updatestatus(sd,SP_AGI);
  7450. clif_updatestatus(sd,SP_VIT);
  7451. clif_updatestatus(sd,SP_INT);
  7452. clif_updatestatus(sd,SP_DEX);
  7453. clif_updatestatus(sd,SP_LUK);
  7454. // abort currently running script
  7455. sd->state.using_fake_npc = 0;
  7456. sd->state.menu_or_input = 0;
  7457. sd->npc_menu = 0;
  7458. if(sd->npc_id)
  7459. npc_event_dequeue(sd);
  7460. }
  7461. if( sd->state.changemap )
  7462. {// restore information that gets lost on map-change
  7463. clif_partyinvitationstate(sd);
  7464. clif_equipcheckbox(sd);
  7465. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7466. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7467. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7468. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7469. { //Display night.
  7470. if( !sd->state.night )
  7471. {
  7472. sd->state.night = 1;
  7473. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7474. }
  7475. }
  7476. else if( sd->state.night )
  7477. { //Clear night display.
  7478. sd->state.night = 0;
  7479. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7480. }
  7481. if( map[sd->bl.m].flag.battleground )
  7482. {
  7483. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7484. if( map[sd->bl.m].flag.battleground == 2 )
  7485. clif_bg_updatescore_single(sd);
  7486. }
  7487. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7488. {
  7489. char output[128];
  7490. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7491. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7492. }
  7493. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7494. sd->state.changemap = false;
  7495. }
  7496. mail_clear(sd);
  7497. /* Guild Aura Init */
  7498. if( sd->state.gmaster_flag ) {
  7499. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  7500. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  7501. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  7502. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  7503. }
  7504. if(map[sd->bl.m].flag.loadevent) // Lance
  7505. npc_script_event(sd, NPCE_LOADMAP);
  7506. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7507. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7508. if (sd->sc.opt2) //Client loses these on warp.
  7509. clif_changeoption(&sd->bl);
  7510. clif_weather_check(sd);
  7511. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7512. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7513. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7514. else
  7515. sd->areanpc_id = 0;
  7516. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7517. if(pc_isdead(sd))
  7518. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7519. else {
  7520. skill_usave_trigger(sd);
  7521. clif_changed_dir(&sd->bl, SELF);
  7522. }
  7523. // Trigger skill effects if you appear standing on them
  7524. if(!battle_config.pc_invincible_time)
  7525. skill_unit_move(&sd->bl,gettick(),1);
  7526. }
  7527. /// Request for server's tick.
  7528. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  7529. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  7530. /// There are various variants of this packet, some of them have padding between fields.
  7531. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7532. {
  7533. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7534. WFIFOHEAD(fd, packet_len(0x7f));
  7535. WFIFOW(fd,0)=0x7f;
  7536. WFIFOL(fd,2)=gettick();
  7537. WFIFOSET(fd,packet_len(0x7f));
  7538. // removed until the socket problems are fixed. [FlavioJS]
  7539. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7540. }
  7541. /// Sends hotkey bar.
  7542. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  7543. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  7544. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  7545. void clif_hotkeys_send(struct map_session_data *sd) {
  7546. #ifdef HOTKEY_SAVING
  7547. const int fd = sd->fd;
  7548. int i;
  7549. const int cmd = 0x07d9;
  7550. if (!fd) return;
  7551. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7552. WFIFOW(fd, 0) = cmd;
  7553. for(i = 0; i < MAX_HOTKEYS; i++) {
  7554. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7555. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7556. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7557. }
  7558. WFIFOSET(fd, packet_len(cmd));
  7559. #endif
  7560. }
  7561. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  7562. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  7563. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7564. #ifdef HOTKEY_SAVING
  7565. unsigned short idx;
  7566. int cmd;
  7567. cmd = RFIFOW(fd, 0);
  7568. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7569. if (idx >= MAX_HOTKEYS) return;
  7570. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7571. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7572. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7573. #endif
  7574. }
  7575. /// Displays cast-like progress bar (ZC_PROGRESS).
  7576. /// 02f0 <color>.L <time>.L
  7577. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  7578. {
  7579. int fd = sd->fd;
  7580. WFIFOHEAD(fd,packet_len(0x2f0));
  7581. WFIFOW(fd,0) = 0x2f0;
  7582. WFIFOL(fd,2) = color;
  7583. WFIFOL(fd,6) = second;
  7584. WFIFOSET(fd,packet_len(0x2f0));
  7585. }
  7586. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  7587. /// 02f2
  7588. void clif_progressbar_abort(struct map_session_data * sd)
  7589. {
  7590. int fd = sd->fd;
  7591. WFIFOHEAD(fd,packet_len(0x2f2));
  7592. WFIFOW(fd,0) = 0x2f2;
  7593. WFIFOSET(fd,packet_len(0x2f2));
  7594. }
  7595. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  7596. /// 02f1
  7597. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  7598. {
  7599. int npc_id = sd->progressbar.npc_id;
  7600. if( gettick() < sd->progressbar.timeout && sd->st )
  7601. sd->st->state = END;
  7602. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  7603. npc_scriptcont(sd, npc_id);
  7604. }
  7605. /// Request to walk to a certain position on the current map.
  7606. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  7607. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  7608. /// There are various variants of this packet, some of them have padding between fields.
  7609. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7610. {
  7611. short x, y;
  7612. if (pc_isdead(sd)) {
  7613. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7614. return;
  7615. }
  7616. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  7617. ; //You CAN walk on this OPT1 value.
  7618. else if( sd->progressbar.npc_id )
  7619. clif_progressbar_abort(sd);
  7620. else if (pc_cant_act(sd))
  7621. return;
  7622. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  7623. return;
  7624. pc_delinvincibletimer(sd);
  7625. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  7626. //Set last idle time... [Skotlex]
  7627. sd->idletime = last_tick;
  7628. unit_walktoxy(&sd->bl, x, y, 4);
  7629. }
  7630. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  7631. /// 018a <type>.W
  7632. /// type:
  7633. /// 0 = quit
  7634. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7635. {
  7636. WFIFOHEAD(fd,packet_len(0x18b));
  7637. WFIFOW(fd,0) = 0x18b;
  7638. /* Rovert's prevent logout option fixed [Valaris] */
  7639. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  7640. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7641. {
  7642. set_eof(fd);
  7643. WFIFOW(fd,2)=0;
  7644. } else {
  7645. WFIFOW(fd,2)=1;
  7646. }
  7647. WFIFOSET(fd,packet_len(0x18b));
  7648. }
  7649. /// Requesting unit's name.
  7650. /// 0094 <id>.L (CZ_REQNAME)
  7651. /// 0368 <id>.L (CZ_REQNAME2)
  7652. /// There are various variants of this packet, some of them have padding between fields.
  7653. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7654. {
  7655. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7656. struct block_list* bl;
  7657. //struct status_change *sc;
  7658. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7659. id = sd->bl.id;
  7660. bl = map_id2bl(id);
  7661. if( bl == NULL )
  7662. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7663. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  7664. return; // Block namerequests past view range
  7665. // 'see people in GM hide' cheat detection
  7666. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7667. sc = status_get_sc(bl);
  7668. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7669. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7670. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  7671. ) {
  7672. char gm_msg[256];
  7673. 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);
  7674. ShowWarning(gm_msg);
  7675. // information is sent to all online GMs
  7676. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7677. return;
  7678. }
  7679. */
  7680. clif_charnameack(fd, bl);
  7681. }
  7682. /// Validates and processes global messages
  7683. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  7684. /// There are various variants of this packet.
  7685. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7686. {
  7687. const char* text = (char*)RFIFOP(fd,4);
  7688. int textlen = RFIFOW(fd,2) - 4;
  7689. char *name, *message, *fakename = NULL;
  7690. int namelen, messagelen;
  7691. bool is_fake;
  7692. // validate packet and retrieve name and message
  7693. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7694. return;
  7695. if( is_atcommand(fd, sd, message, 1) )
  7696. return;
  7697. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7698. return;
  7699. if( battle_config.min_chat_delay )
  7700. { //[Skotlex]
  7701. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7702. return;
  7703. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7704. }
  7705. /**
  7706. * Fake Name Design by FatalEror (bug report #9)
  7707. **/
  7708. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  7709. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  7710. strcpy(fakename, sd->fakename);
  7711. strcat(fakename, " : ");
  7712. strcat(fakename, message);
  7713. textlen = strlen(fakename) + 1;
  7714. }
  7715. // send message to others (using the send buffer for temp. storage)
  7716. WFIFOHEAD(fd, 8 + textlen);
  7717. WFIFOW(fd,0) = 0x8d;
  7718. WFIFOW(fd,2) = 8 + textlen;
  7719. WFIFOL(fd,4) = sd->bl.id;
  7720. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  7721. //FIXME: chat has range of 9 only
  7722. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7723. // send back message to the speaker
  7724. if( is_fake ) {
  7725. WFIFOW(fd,0) = 0x8e;
  7726. WFIFOW(fd,2) = textlen + 4;
  7727. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  7728. aFree(fakename);
  7729. } else {
  7730. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7731. WFIFOW(fd,0) = 0x8e;
  7732. }
  7733. WFIFOSET(fd, WFIFOW(fd,2));
  7734. #ifdef PCRE_SUPPORT
  7735. // trigger listening npcs
  7736. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7737. #endif
  7738. // Chat logging type 'O' / Global Chat
  7739. 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);
  7740. }
  7741. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  7742. /// Request to warp to a map on given coordinates.
  7743. /// 0140 <map name>.16B <x>.W <y>.W
  7744. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7745. {
  7746. char command[MAP_NAME_LENGTH_EXT+25];
  7747. char* map_name;
  7748. map_name = (char*)RFIFOP(fd,2);
  7749. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7750. sprintf(command, "@mapmove %s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7751. is_atcommand(fd, sd, command, 1);
  7752. }
  7753. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  7754. /// 009c <id>.L <head dir>.W <dir>.B
  7755. /// head dir:
  7756. /// 0 = straight
  7757. /// 1 = turned CW
  7758. /// 2 = turned CCW
  7759. /// dir:
  7760. /// 0 = north
  7761. /// 1 = northwest
  7762. /// 2 = west
  7763. /// 3 = southwest
  7764. /// 4 = south
  7765. /// 5 = southeast
  7766. /// 6 = east
  7767. /// 7 = northeast
  7768. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7769. {
  7770. unsigned char buf[64];
  7771. WBUFW(buf,0) = 0x9c;
  7772. WBUFL(buf,2) = bl->id;
  7773. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7774. WBUFB(buf,8) = unit_getdir(bl);
  7775. clif_send(buf, packet_len(0x9c), bl, target);
  7776. if (disguised(bl)) {
  7777. WBUFL(buf,2) = -bl->id;
  7778. WBUFW(buf,6) = 0;
  7779. clif_send(buf, packet_len(0x9c), bl, SELF);
  7780. }
  7781. }
  7782. /// Request to change own body and head direction.
  7783. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  7784. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  7785. /// There are various variants of this packet, some of them have padding between fields.
  7786. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7787. {
  7788. unsigned char headdir, dir;
  7789. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7790. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7791. pc_setdir(sd, dir, headdir);
  7792. clif_changed_dir(&sd->bl, AREA_WOS);
  7793. }
  7794. /// Request to show an emotion (CZ_REQ_EMOTION).
  7795. /// 00bf <type>.B
  7796. /// type:
  7797. /// @see enum emotion_type
  7798. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7799. {
  7800. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7801. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7802. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  7803. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  7804. return;
  7805. }
  7806. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7807. if (sd->emotionlasttime >= time(NULL)) {
  7808. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7809. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  7810. return;
  7811. }
  7812. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7813. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  7814. {// re-roll dice
  7815. emoticon = rnd()%6+E_DICE1;
  7816. }
  7817. clif_emotion(&sd->bl, emoticon);
  7818. } else
  7819. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  7820. }
  7821. /// /w /who (CZ_REQ_USER_COUNT).
  7822. /// Request to display amount of currently connected players.
  7823. /// 00c1
  7824. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7825. {
  7826. WFIFOHEAD(fd,packet_len(0xc2));
  7827. WFIFOW(fd,0) = 0xc2;
  7828. WFIFOL(fd,2) = map_getusers();
  7829. WFIFOSET(fd,packet_len(0xc2));
  7830. }
  7831. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7832. {
  7833. if (pc_isdead(sd)) {
  7834. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7835. return;
  7836. }
  7837. if (sd->sc.count &&
  7838. (sd->sc.data[SC_TRICKDEAD] ||
  7839. sd->sc.data[SC_AUTOCOUNTER] ||
  7840. sd->sc.data[SC_BLADESTOP]))
  7841. return;
  7842. pc_stop_walking(sd, 1);
  7843. pc_stop_attack(sd);
  7844. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7845. target_id = sd->bl.id;
  7846. switch(action_type)
  7847. {
  7848. case 0x00: // once attack
  7849. case 0x07: // continuous attack
  7850. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7851. return;
  7852. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7853. return;
  7854. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  7855. return;
  7856. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7857. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7858. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  7859. return;
  7860. }
  7861. }
  7862. pc_delinvincibletimer(sd);
  7863. sd->idletime = last_tick;
  7864. unit_attack(&sd->bl, target_id, action_type != 0);
  7865. break;
  7866. case 0x02: // sitdown
  7867. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7868. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  7869. break;
  7870. }
  7871. if(pc_issit(sd)) {
  7872. //Bugged client? Just refresh them.
  7873. clif_sitting(&sd->bl);
  7874. return;
  7875. }
  7876. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  7877. break;
  7878. if (sd->sc.count && (
  7879. sd->sc.data[SC_DANCING] ||
  7880. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7881. )) //No sitting during these states either.
  7882. break;
  7883. pc_setsit(sd);
  7884. skill_sit(sd,1);
  7885. clif_sitting(&sd->bl);
  7886. break;
  7887. case 0x03: // standup
  7888. if (!pc_issit(sd)) {
  7889. //Bugged client? Just refresh them.
  7890. clif_standing(&sd->bl);
  7891. return;
  7892. }
  7893. pc_setstand(sd);
  7894. skill_sit(sd,0);
  7895. clif_standing(&sd->bl);
  7896. break;
  7897. }
  7898. }
  7899. /// Request for an action.
  7900. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  7901. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  7902. /// action:
  7903. /// 0 = attack
  7904. /// 1 = pick up item
  7905. /// 2 = sit down
  7906. /// 3 = stand up
  7907. /// 7 = continous attack
  7908. /// 12 = (touch skill?)
  7909. /// There are various variants of this packet, some of them have padding between fields.
  7910. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7911. {
  7912. clif_parse_ActionRequest_sub(sd,
  7913. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7914. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7915. gettick()
  7916. );
  7917. }
  7918. /// Response to the death/system menu (CZ_RESTART).
  7919. /// 00b2 <type>.B
  7920. /// type:
  7921. /// 0 = restart (respawn)
  7922. /// 1 = char-select (disconnect)
  7923. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7924. {
  7925. switch(RFIFOB(fd,2)) {
  7926. case 0x00:
  7927. pc_respawn(sd,CLR_RESPAWN);
  7928. break;
  7929. case 0x01:
  7930. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7931. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  7932. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7933. { //Send to char-server for character selection.
  7934. chrif_charselectreq(sd, session[fd]->client_addr);
  7935. } else {
  7936. WFIFOHEAD(fd,packet_len(0x18b));
  7937. WFIFOW(fd,0)=0x18b;
  7938. WFIFOW(fd,2)=1;
  7939. WFIFOSET(fd,packet_len(0x018b));
  7940. }
  7941. break;
  7942. }
  7943. }
  7944. /// Validates and processes whispered messages (CZ_WHISPER).
  7945. /// 0096 <packet len>.W <nick>.24B <message>.?B
  7946. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7947. {
  7948. struct map_session_data* dstsd;
  7949. int i;
  7950. char *target, *message;
  7951. int namelen, messagelen;
  7952. // validate packet and retrieve name and message
  7953. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7954. return;
  7955. if (is_atcommand(fd, sd, message, 1) )
  7956. return;
  7957. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7958. return;
  7959. if (battle_config.min_chat_delay)
  7960. { //[Skotlex]
  7961. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7962. return;
  7963. }
  7964. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7965. }
  7966. // Chat logging type 'W' / Whisper
  7967. 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);
  7968. //-------------------------------------------------------//
  7969. // Lordalfa - Paperboy - To whisper NPC commands //
  7970. //-------------------------------------------------------//
  7971. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7972. {
  7973. char* str = target+4; //Skip the NPC: string part.
  7974. struct npc_data* npc;
  7975. if ((npc = npc_name2id(str)))
  7976. {
  7977. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  7978. char *split;
  7979. char output[256];
  7980. str = message;
  7981. // skip codepage indicator, if detected
  7982. if( str[0] == '|' && strlen(str) >= 4 )
  7983. str += 3;
  7984. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  7985. {// Splits the message using '#' as separators
  7986. split = strchr(str,'#');
  7987. if( split == NULL )
  7988. { // use the remaining string
  7989. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7990. for( ++i; i < NUM_WHISPER_VAR; ++i )
  7991. split_data[i][0] = '\0';
  7992. break;
  7993. }
  7994. *split = '\0';
  7995. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7996. str = split+1;
  7997. }
  7998. for( i = 0; i < NUM_WHISPER_VAR; ++i )
  7999. {
  8000. sprintf(output, "@whispervar%d$", i);
  8001. set_var(sd,output,(char *) split_data[i]);
  8002. }
  8003. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8004. npc_event(sd,output,0); // Calls the NPC label
  8005. return;
  8006. }
  8007. }
  8008. // Main chat [LuzZza]
  8009. if(strcmpi(target, main_chat_nick) == 0)
  8010. {
  8011. if(!sd->state.mainchat)
  8012. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8013. else {
  8014. // send the main message using inter-server system
  8015. intif_main_message( sd, message );
  8016. }
  8017. return;
  8018. }
  8019. // searching destination character
  8020. dstsd = map_nick2sd(target);
  8021. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8022. {
  8023. // player is not on this map-server
  8024. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8025. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8026. // and if we ask for 'Test', we must not contact 'test' player
  8027. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8028. intif_wis_message(sd, target, message, messagelen);
  8029. return;
  8030. }
  8031. // if player ignores everyone
  8032. if (dstsd->state.ignoreAll)
  8033. {
  8034. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8035. clif_wis_end(fd, 1); // 1: target character is not loged in
  8036. else
  8037. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8038. return;
  8039. }
  8040. // if player ignores the source character
  8041. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8042. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8043. { // source char present in ignore list
  8044. clif_wis_end(fd, 2); // 2: ignored by target
  8045. return;
  8046. }
  8047. // if player is autotrading
  8048. if( dstsd->state.autotrade == 1 )
  8049. {
  8050. char output[256];
  8051. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8052. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8053. return;
  8054. }
  8055. // notify sender of success
  8056. clif_wis_end(fd, 0); // 0: success to send wisper
  8057. // Normal message
  8058. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8059. }
  8060. /// /b /nb (CZ_BROADCAST).
  8061. /// Request to broadcast a message on whole server.
  8062. /// 0099 <packet len>.W <text>.?B 00
  8063. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8064. {
  8065. char command[CHAT_SIZE_MAX+11];
  8066. char* msg = (char*)RFIFOP(fd,4);
  8067. unsigned int len = RFIFOW(fd,2)-4;
  8068. // as the length varies depending on the command used, just block unreasonably long strings
  8069. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  8070. sprintf(command, "@kami %s", msg);
  8071. is_atcommand(fd, sd, command, 1);
  8072. }
  8073. /// Request to pick up an item.
  8074. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8075. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8076. /// There are various variants of this packet, some of them have padding between fields.
  8077. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8078. {
  8079. struct flooritem_data *fitem;
  8080. int map_object_id;
  8081. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8082. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8083. do {
  8084. if (pc_isdead(sd)) {
  8085. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8086. break;
  8087. }
  8088. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8089. break;
  8090. if (pc_cant_act(sd))
  8091. break;
  8092. if(sd->sc.count && (
  8093. sd->sc.data[SC_HIDING] ||
  8094. sd->sc.data[SC_CLOAKING] ||
  8095. sd->sc.data[SC_TRICKDEAD] ||
  8096. sd->sc.data[SC_BLADESTOP] ||
  8097. sd->sc.data[SC_CLOAKINGEXCEED] ||
  8098. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8099. )
  8100. break;
  8101. if (!pc_takeitem(sd, fitem))
  8102. break;
  8103. return;
  8104. } while (0);
  8105. // Client REQUIRES a fail packet or you can no longer pick items.
  8106. clif_additem(sd,0,0,6);
  8107. }
  8108. /// Request to drop an item.
  8109. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8110. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8111. /// There are various variants of this packet, some of them have padding between fields.
  8112. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8113. {
  8114. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8115. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8116. for(;;) {
  8117. if (pc_isdead(sd))
  8118. break;
  8119. if (pc_cant_act(sd))
  8120. break;
  8121. if (sd->sc.count && (
  8122. sd->sc.data[SC_AUTOCOUNTER] ||
  8123. sd->sc.data[SC_BLADESTOP] ||
  8124. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8125. ))
  8126. break;
  8127. if (!pc_dropitem(sd, item_index, item_amount))
  8128. break;
  8129. return;
  8130. }
  8131. //Because the client does not like being ignored.
  8132. clif_dropitem(sd, item_index,0);
  8133. }
  8134. /// Request to use an item.
  8135. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8136. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8137. /// There are various variants of this packet, some of them have padding between fields.
  8138. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8139. {
  8140. int n;
  8141. if (pc_isdead(sd)) {
  8142. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8143. return;
  8144. }
  8145. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  8146. return;
  8147. //This flag enables you to use items while in an NPC. [Skotlex]
  8148. if (sd->npc_id) {
  8149. if (sd->npc_id != sd->npc_item_flag)
  8150. return;
  8151. } else
  8152. if (pc_istrading(sd))
  8153. return;
  8154. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8155. sd->idletime = last_tick;
  8156. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8157. if(n <0 || n >= MAX_INVENTORY)
  8158. return;
  8159. if (!pc_useitem(sd,n))
  8160. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8161. }
  8162. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8163. /// 00a9 <index>.W <position>.W
  8164. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8165. {
  8166. int index;
  8167. if(pc_isdead(sd)) {
  8168. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8169. return;
  8170. }
  8171. index = RFIFOW(fd,2)-2;
  8172. if (index < 0 || index >= MAX_INVENTORY)
  8173. return; //Out of bounds check.
  8174. if(sd->npc_id) {
  8175. if (sd->npc_id != sd->npc_item_flag)
  8176. return;
  8177. } else if (sd->state.storage_flag || sd->sc.opt1)
  8178. ; //You can equip/unequip stuff while storage is open/under status changes
  8179. else if (pc_cant_act(sd))
  8180. return;
  8181. if(!sd->status.inventory[index].identify) {
  8182. clif_equipitemack(sd,index,0,0); // fail
  8183. return;
  8184. }
  8185. if(!sd->inventory_data[index])
  8186. return;
  8187. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8188. pet_equipitem(sd,index);
  8189. return;
  8190. }
  8191. //Client doesn't send the position for ammo.
  8192. if(sd->inventory_data[index]->type == IT_AMMO)
  8193. pc_equipitem(sd,index,EQP_AMMO);
  8194. else
  8195. pc_equipitem(sd,index,RFIFOW(fd,4));
  8196. }
  8197. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8198. /// 00ab <index>.W
  8199. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8200. {
  8201. int index;
  8202. if(pc_isdead(sd)) {
  8203. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8204. return;
  8205. }
  8206. if (sd->state.storage_flag || sd->sc.opt1)
  8207. ; //You can equip/unequip stuff while storage is open/under status changes
  8208. else if (pc_cant_act(sd))
  8209. return;
  8210. index = RFIFOW(fd,2)-2;
  8211. pc_unequipitem(sd,index,1);
  8212. }
  8213. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8214. /// 0090 <id>.L <type>.B
  8215. /// type:
  8216. /// 1 = click
  8217. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8218. {
  8219. struct block_list *bl;
  8220. if(pc_isdead(sd)) {
  8221. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8222. return;
  8223. }
  8224. if (pc_cant_act(sd))
  8225. return;
  8226. bl = map_id2bl(RFIFOL(fd,2));
  8227. if (!bl) return;
  8228. switch (bl->type) {
  8229. case BL_MOB:
  8230. case BL_PC:
  8231. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8232. break;
  8233. case BL_NPC:
  8234. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8235. npc_click(sd,(TBL_NPC*)bl);
  8236. break;
  8237. }
  8238. }
  8239. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8240. /// 00c5 <id>.L <type>.B
  8241. /// type:
  8242. /// 0 = buy
  8243. /// 1 = sell
  8244. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8245. {
  8246. if (sd->state.trading)
  8247. return;
  8248. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8249. }
  8250. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8251. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8252. ///
  8253. /// R 00ca <result>.b
  8254. /// result = 00 -> "The deal has successfully completed."
  8255. /// result = 01 -> "You do not have enough zeny."
  8256. /// result = 02 -> "You are over your Weight Limit."
  8257. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8258. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8259. {
  8260. int n = (RFIFOW(fd,2)-4) /4;
  8261. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8262. int result;
  8263. if( sd->state.trading || !sd->npc_shopid )
  8264. result = 1;
  8265. else
  8266. result = npc_buylist(sd,n,item_list);
  8267. sd->npc_shopid = 0; //Clear shop data.
  8268. WFIFOHEAD(fd,packet_len(0xca));
  8269. WFIFOW(fd,0) = 0xca;
  8270. WFIFOB(fd,2) = result;
  8271. WFIFOSET(fd,packet_len(0xca));
  8272. }
  8273. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8274. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8275. ///
  8276. /// S 00cb <result>.B
  8277. /// result = 00 -> "The deal has successfully completed."
  8278. /// result = 01 -> "The deal has failed."
  8279. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8280. {
  8281. int fail=0,n;
  8282. unsigned short *item_list;
  8283. n = (RFIFOW(fd,2)-4) /4;
  8284. item_list = (unsigned short*)RFIFOP(fd,4);
  8285. if (sd->state.trading || !sd->npc_shopid)
  8286. fail = 1;
  8287. else
  8288. fail = npc_selllist(sd,n,item_list);
  8289. sd->npc_shopid = 0; //Clear shop data.
  8290. WFIFOHEAD(fd,packet_len(0xcb));
  8291. WFIFOW(fd,0)=0xcb;
  8292. WFIFOB(fd,2)=fail;
  8293. WFIFOSET(fd,packet_len(0xcb));
  8294. }
  8295. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8296. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8297. /// type:
  8298. /// 0 = private
  8299. /// 1 = public
  8300. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8301. {
  8302. int len = RFIFOW(fd,2)-15;
  8303. int limit = RFIFOW(fd,4);
  8304. bool pub = (RFIFOB(fd,6) != 0);
  8305. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8306. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8307. char s_password[CHATROOM_PASS_SIZE];
  8308. char s_title[CHATROOM_TITLE_SIZE];
  8309. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8310. return;
  8311. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8312. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8313. return;
  8314. }
  8315. if( len <= 0 )
  8316. return; // invalid input
  8317. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8318. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8319. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8320. }
  8321. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8322. /// 00d9 <chat ID>.L <passwd>.8B
  8323. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8324. {
  8325. int chatid = RFIFOL(fd,2);
  8326. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8327. chat_joinchat(sd,chatid,password);
  8328. }
  8329. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8330. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8331. /// type:
  8332. /// 0 = private
  8333. /// 1 = public
  8334. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8335. {
  8336. int len = RFIFOW(fd,2)-15;
  8337. int limit = RFIFOW(fd,4);
  8338. bool pub = (RFIFOB(fd,6) != 0);
  8339. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8340. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8341. char s_password[CHATROOM_PASS_SIZE];
  8342. char s_title[CHATROOM_TITLE_SIZE];
  8343. if( len <= 0 )
  8344. return; // invalid input
  8345. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8346. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8347. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8348. }
  8349. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8350. /// 00e0 <role>.L <nick>.24B
  8351. /// role:
  8352. /// 0 = owner
  8353. /// 1 = normal
  8354. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8355. {
  8356. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8357. }
  8358. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8359. /// 00e2 <name>.24B
  8360. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8361. {
  8362. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8363. }
  8364. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8365. /// 00e3
  8366. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8367. {
  8368. chat_leavechat(sd,0);
  8369. }
  8370. //Handles notifying asker and rejecter of what has just ocurred.
  8371. //Type is used to determine the correct msg_txt to use:
  8372. //0:
  8373. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8374. {
  8375. const char* msg;
  8376. char output[256];
  8377. // Your request has been rejected by autoreject option.
  8378. msg = msg_txt(392);
  8379. clif_disp_onlyself(src, msg, strlen(msg));
  8380. //Notice that a request was rejected.
  8381. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8382. clif_disp_onlyself(target, output, strlen(output));
  8383. }
  8384. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8385. /// 00e4 <account id>.L
  8386. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8387. {
  8388. struct map_session_data *t_sd;
  8389. t_sd = map_id2sd(RFIFOL(fd,2));
  8390. if(!sd->chatID && pc_cant_act(sd))
  8391. return; //You can trade while in a chatroom.
  8392. // @noask [LuzZza]
  8393. if(t_sd && t_sd->state.noask) {
  8394. clif_noask_sub(sd, t_sd, 0);
  8395. return;
  8396. }
  8397. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8398. {
  8399. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8400. return;
  8401. }
  8402. trade_traderequest(sd,t_sd);
  8403. }
  8404. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8405. /// 00e6 <result>.B
  8406. /// result:
  8407. /// 3 = accepted
  8408. /// 4 = rejected
  8409. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8410. {
  8411. trade_tradeack(sd,RFIFOB(fd,2));
  8412. }
  8413. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  8414. /// 00e8 <index>.W <amount>.L
  8415. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8416. {
  8417. short index = RFIFOW(fd,2);
  8418. int amount = RFIFOL(fd,4);
  8419. if( index == 0 )
  8420. trade_tradeaddzeny(sd, amount);
  8421. else
  8422. trade_tradeadditem(sd, index, (short)amount);
  8423. }
  8424. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  8425. /// 00eb
  8426. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8427. {
  8428. trade_tradeok(sd);
  8429. }
  8430. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  8431. /// 00ed
  8432. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8433. {
  8434. trade_tradecancel(sd);
  8435. }
  8436. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  8437. /// 00ef
  8438. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8439. {
  8440. trade_tradecommit(sd);
  8441. }
  8442. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  8443. /// 0118
  8444. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8445. {
  8446. pc_stop_attack(sd);
  8447. }
  8448. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  8449. /// 0126 <index>.W <amount>.L
  8450. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8451. {
  8452. if (pc_istrading(sd))
  8453. return;
  8454. if (!pc_iscarton(sd))
  8455. return;
  8456. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8457. }
  8458. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  8459. /// 0127 <index>.W <amount>.L
  8460. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8461. {
  8462. if (!pc_iscarton(sd))
  8463. return;
  8464. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8465. }
  8466. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  8467. /// 012a
  8468. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8469. {
  8470. /**
  8471. * Attempts to remove these options when this function is called (will remove all available)
  8472. **/
  8473. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  8474. }
  8475. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  8476. /// 01af <num>.W
  8477. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8478. {
  8479. int type;
  8480. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8481. return;
  8482. type = (int)RFIFOW(fd,2);
  8483. if( (type == 5 && sd->status.base_level > 90) ||
  8484. (type == 4 && sd->status.base_level > 80) ||
  8485. (type == 3 && sd->status.base_level > 65) ||
  8486. (type == 2 && sd->status.base_level > 40) ||
  8487. (type == 1))
  8488. pc_setcart(sd,type);
  8489. }
  8490. /// Request to increase status (CZ_STATUS_CHANGE).
  8491. /// 00bb <status id>.W <amount>.B
  8492. /// status id:
  8493. /// SP_STR ~ SP_LUK
  8494. /// amount:
  8495. /// client sends always 1 for this, even when using /str+ and
  8496. /// the like
  8497. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8498. {
  8499. pc_statusup(sd,RFIFOW(fd,2));
  8500. }
  8501. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  8502. /// 0112 <skill id>.W
  8503. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8504. {
  8505. pc_skillup(sd,RFIFOW(fd,2));
  8506. }
  8507. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8508. {
  8509. int lv;
  8510. if( !hd )
  8511. return;
  8512. if( skillnotok_hom(skillnum, hd) )
  8513. return;
  8514. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8515. target_id = hd->bl.id;
  8516. if( hd->ud.skilltimer != INVALID_TIMER )
  8517. {
  8518. if( skillnum != SA_CASTCANCEL ) return;
  8519. }
  8520. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8521. return;
  8522. lv = merc_hom_checkskill(hd, skillnum);
  8523. if( skilllv > lv )
  8524. skilllv = lv;
  8525. if( skilllv )
  8526. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8527. }
  8528. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8529. {
  8530. int lv;
  8531. if( !md )
  8532. return;
  8533. if( skillnotok_mercenary(skillnum, md) )
  8534. return;
  8535. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8536. target_id = md->bl.id;
  8537. if( md->ud.skilltimer != INVALID_TIMER )
  8538. {
  8539. if( skillnum != SA_CASTCANCEL ) return;
  8540. }
  8541. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8542. return;
  8543. lv = mercenary_checkskill(md, skillnum);
  8544. if( skilllv > lv )
  8545. skilllv = lv;
  8546. if( skilllv )
  8547. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8548. }
  8549. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  8550. {
  8551. int lv;
  8552. if( !md )
  8553. return;
  8554. if( skillnotok_mercenary(skillnum, md) )
  8555. return;
  8556. if( md->ud.skilltimer != INVALID_TIMER )
  8557. return;
  8558. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8559. {
  8560. clif_skill_fail(md->master, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  8561. return;
  8562. }
  8563. if( md->sc.data[SC_BASILICA] )
  8564. return;
  8565. lv = mercenary_checkskill(md, skillnum);
  8566. if( skilllv > lv )
  8567. skilllv = lv;
  8568. if( skilllv )
  8569. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8570. }
  8571. /// Request to use a targeted skill.
  8572. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  8573. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  8574. /// There are various variants of this packet, some of them have padding between fields.
  8575. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8576. {
  8577. short skillnum, skilllv;
  8578. int tmp, target_id;
  8579. unsigned int tick = gettick();
  8580. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8581. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8582. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8583. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8584. tmp = skill_get_inf(skillnum);
  8585. if (tmp&INF_GROUND_SKILL || !tmp)
  8586. return; //Using a ground/passive skill on a target? WRONG.
  8587. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8588. {
  8589. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8590. return;
  8591. }
  8592. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8593. {
  8594. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8595. return;
  8596. }
  8597. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8598. sd->idletime = last_tick;
  8599. if( pc_cant_act(sd) )
  8600. return;
  8601. if( pc_issit(sd) )
  8602. return;
  8603. if( skillnotok(skillnum, sd) )
  8604. return;
  8605. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  8606. target_id = sd->bl.id; // never trust the client
  8607. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8608. target_id = sd->bl.id;
  8609. if( sd->ud.skilltimer != INVALID_TIMER )
  8610. {
  8611. if( skillnum != SA_CASTCANCEL )
  8612. return;
  8613. }
  8614. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8615. {
  8616. if( sd->skillitem != skillnum )
  8617. {
  8618. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  8619. return;
  8620. }
  8621. }
  8622. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8623. return;
  8624. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8625. return; // On basilica only caster can use Basilica again to stop it.
  8626. if( sd->menuskill_id )
  8627. {
  8628. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8629. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8630. else if( sd->menuskill_id != SA_AUTOSPELL )
  8631. return; //Can't use skills while a menu is open.
  8632. }
  8633. if( sd->skillitem == skillnum )
  8634. {
  8635. if( skilllv != sd->skillitemlv )
  8636. skilllv = sd->skillitemlv;
  8637. if( !(tmp&INF_SELF_SKILL) )
  8638. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  8639. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8640. return;
  8641. }
  8642. sd->skillitem = sd->skillitemlv = 0;
  8643. if( skillnum >= GD_SKILLBASE )
  8644. {
  8645. if( sd->state.gmaster_flag )
  8646. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8647. else
  8648. skilllv = 0;
  8649. }
  8650. else
  8651. {
  8652. tmp = pc_checkskill(sd, skillnum);
  8653. if( skilllv > tmp )
  8654. skilllv = tmp;
  8655. }
  8656. pc_delinvincibletimer(sd);
  8657. if( skilllv )
  8658. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8659. }
  8660. /*==========================================
  8661. * Client tells server he'd like to use AoE skill id 'skillnum' of level 'skilllv' on 'x','y' location
  8662. *------------------------------------------*/
  8663. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8664. {
  8665. unsigned int tick = gettick();
  8666. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8667. return; //Using a target skill on the ground? WRONG.
  8668. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8669. {
  8670. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8671. return;
  8672. }
  8673. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8674. sd->idletime = last_tick;
  8675. if( skillnotok(skillnum, sd) )
  8676. return;
  8677. if( skillmoreinfo != -1 )
  8678. {
  8679. if( pc_issit(sd) )
  8680. {
  8681. clif_skill_fail(sd, skillnum, USESKILL_FAIL_LEVEL, 0);
  8682. return;
  8683. }
  8684. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8685. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8686. }
  8687. if( sd->ud.skilltimer != INVALID_TIMER )
  8688. return;
  8689. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8690. {
  8691. if( sd->skillitem != skillnum )
  8692. {
  8693. clif_skill_fail(sd, skillnum, USESKILL_FAIL_SKILLINTERVAL, 0);
  8694. return;
  8695. }
  8696. }
  8697. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8698. return;
  8699. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8700. return; // On basilica only caster can use Basilica again to stop it.
  8701. if( sd->menuskill_id )
  8702. {
  8703. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8704. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8705. else if( sd->menuskill_id != SA_AUTOSPELL )
  8706. return; //Can't use skills while a menu is open.
  8707. }
  8708. pc_delinvincibletimer(sd);
  8709. if( sd->skillitem == skillnum )
  8710. {
  8711. if( skilllv != sd->skillitemlv )
  8712. skilllv = sd->skillitemlv;
  8713. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8714. }
  8715. else
  8716. {
  8717. int lv;
  8718. sd->skillitem = sd->skillitemlv = 0;
  8719. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8720. {
  8721. if( skilllv > lv )
  8722. skilllv = lv;
  8723. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8724. }
  8725. }
  8726. }
  8727. /// Request to use a ground skill.
  8728. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  8729. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  8730. /// There are various variants of this packet, some of them have padding between fields.
  8731. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8732. {
  8733. if (pc_cant_act(sd))
  8734. return;
  8735. if (pc_issit(sd))
  8736. return;
  8737. clif_parse_UseSkillToPosSub(fd, sd,
  8738. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8739. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8740. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8741. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8742. -1 //Skill more info.
  8743. );
  8744. }
  8745. /// Request to use a ground skill with text.
  8746. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  8747. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  8748. /// There are various variants of this packet, some of them have padding between fields.
  8749. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8750. {
  8751. if (pc_cant_act(sd))
  8752. return;
  8753. if (pc_issit(sd))
  8754. return;
  8755. clif_parse_UseSkillToPosSub(fd, sd,
  8756. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8757. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8758. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8759. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8760. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8761. );
  8762. }
  8763. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  8764. /// 011b <skill id>.W <map name>.16B
  8765. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8766. {
  8767. short skill_num = RFIFOW(fd,2);
  8768. char map_name[MAP_NAME_LENGTH];
  8769. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8770. if(skill_num != sd->menuskill_id)
  8771. return;
  8772. if( pc_cant_act(sd) )
  8773. {
  8774. sd->menuskill_id = sd->menuskill_val = 0;
  8775. return;
  8776. }
  8777. pc_delinvincibletimer(sd);
  8778. skill_castend_map(sd,skill_num,map_name);
  8779. }
  8780. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  8781. /// 011d
  8782. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8783. {
  8784. if (!pc_isdead(sd))
  8785. pc_memo(sd,-1);
  8786. }
  8787. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  8788. /// 018e <name id>.W { <material id>.W }*3
  8789. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8790. {
  8791. switch( sd->menuskill_id ) {
  8792. case -1:
  8793. case AM_PHARMACY:
  8794. case RK_RUNEMASTERY:
  8795. case GC_CREATENEWPOISON:
  8796. break;
  8797. default:
  8798. return;
  8799. }
  8800. if (pc_istrading(sd)) {
  8801. //Make it fail to avoid shop exploits where you sell something different than you see.
  8802. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  8803. sd->menuskill_val = sd->menuskill_id = 0;
  8804. return;
  8805. }
  8806. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  8807. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8808. sd->menuskill_val = sd->menuskill_id = 0;
  8809. }
  8810. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  8811. /// 025b <mk type>.W <name id>.W
  8812. /// mk type:
  8813. /// 1 = cooking
  8814. /// 2 = arrow
  8815. /// 3 = elemental
  8816. /// 4 = GN_MIX_COOKING
  8817. /// 5 = GN_MAKEBOMB
  8818. /// 6 = GN_S_PHARMACY
  8819. void clif_parse_Cooking(int fd,struct map_session_data *sd)
  8820. {
  8821. //int type = RFIFOW(fd,2);
  8822. int nameid = RFIFOW(fd,4);
  8823. if( sd->menuskill_id != AM_PHARMACY ) {
  8824. return;
  8825. }
  8826. if (pc_istrading(sd)) {
  8827. //Make it fail to avoid shop exploits where you sell something different than you see.
  8828. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  8829. sd->menuskill_val = sd->menuskill_id = 0;
  8830. return;
  8831. }
  8832. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  8833. skill_produce_mix(sd,0,nameid,0,0,0,1);
  8834. sd->menuskill_val = sd->menuskill_id = 0;
  8835. }
  8836. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  8837. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  8838. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8839. {
  8840. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8841. return;
  8842. if (pc_istrading(sd)) {
  8843. //Make it fail to avoid shop exploits where you sell something different than you see.
  8844. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  8845. sd->menuskill_val = sd->menuskill_id = 0;
  8846. return;
  8847. }
  8848. skill_repairweapon(sd,RFIFOW(fd,2));
  8849. sd->menuskill_val = sd->menuskill_id = 0;
  8850. }
  8851. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  8852. /// 0222 <index>.L
  8853. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8854. {
  8855. int idx;
  8856. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8857. return;
  8858. if (pc_istrading(sd)) {
  8859. //Make it fail to avoid shop exploits where you sell something different than you see.
  8860. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  8861. sd->menuskill_val = sd->menuskill_id = 0;
  8862. return;
  8863. }
  8864. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8865. skill_weaponrefine(sd, idx-2);
  8866. sd->menuskill_val = sd->menuskill_id = 0;
  8867. }
  8868. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  8869. /// 00b8 <npc id>.L <choice>.B
  8870. /// choice:
  8871. /// 1~254 = menu item
  8872. /// 255 = cancel
  8873. /// NOTE: If there were more than 254 items in the list, choice
  8874. /// overflows to choice%256.
  8875. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8876. {
  8877. int npc_id = RFIFOL(fd,2);
  8878. uint8 select = RFIFOB(fd,6);
  8879. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  8880. {
  8881. TBL_NPC* nd = map_id2nd(npc_id);
  8882. 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);
  8883. clif_GM_kick(NULL,sd);
  8884. return;
  8885. }
  8886. sd->npc_menu = select;
  8887. npc_scriptcont(sd,npc_id);
  8888. }
  8889. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  8890. /// 00b9 <npc id>.L
  8891. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8892. {
  8893. npc_scriptcont(sd,RFIFOL(fd,2));
  8894. }
  8895. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  8896. /// 0143 <npc id>.L <value>.L
  8897. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8898. {
  8899. int npcid = RFIFOL(fd,2);
  8900. int amount = (int)RFIFOL(fd,6);
  8901. sd->npc_amount = amount;
  8902. npc_scriptcont(sd, npcid);
  8903. }
  8904. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  8905. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  8906. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8907. {
  8908. int message_len = RFIFOW(fd,2)-8;
  8909. int npcid = RFIFOL(fd,4);
  8910. const char* message = (char*)RFIFOP(fd,8);
  8911. if( message_len <= 0 )
  8912. return; // invalid input
  8913. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8914. npc_scriptcont(sd, npcid);
  8915. }
  8916. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  8917. /// 0146 <npc id>.L
  8918. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8919. {
  8920. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8921. return;
  8922. npc_scriptcont(sd,RFIFOL(fd,2));
  8923. }
  8924. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  8925. /// 0178 <index>.W
  8926. /// index:
  8927. /// -1 = cancel
  8928. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8929. {
  8930. short idx = RFIFOW(fd,2);
  8931. if (sd->menuskill_id != MC_IDENTIFY)
  8932. return;
  8933. if( idx == -1 )
  8934. {// cancel pressed
  8935. sd->menuskill_val = sd->menuskill_id = 0;
  8936. return;
  8937. }
  8938. skill_identify(sd,idx-2);
  8939. sd->menuskill_val = sd->menuskill_id = 0;
  8940. }
  8941. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  8942. /// 01ae <name id>.W
  8943. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8944. {
  8945. if (pc_istrading(sd)) {
  8946. //Make it fail to avoid shop exploits where you sell something different than you see.
  8947. clif_skill_fail(sd,sd->ud.skillid,USESKILL_FAIL_LEVEL,0);
  8948. sd->menuskill_val = sd->menuskill_id = 0;
  8949. return;
  8950. }
  8951. switch( sd->menuskill_id ) {
  8952. case AC_MAKINGARROW:
  8953. skill_arrow_create(sd,RFIFOW(fd,2));
  8954. break;
  8955. case SA_CREATECON:
  8956. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  8957. break;
  8958. case WL_READING_SB:
  8959. skill_spellbook(sd,RFIFOW(fd,2));
  8960. break;
  8961. case GC_POISONINGWEAPON:
  8962. skill_poisoningweapon(sd,RFIFOW(fd,2));
  8963. break;
  8964. case NC_MAGICDECOY:
  8965. skill_magicdecoy(sd,RFIFOW(fd,2));
  8966. break;
  8967. }
  8968. sd->menuskill_val = sd->menuskill_id = 0;
  8969. }
  8970. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  8971. /// 01ce <skill id>.L
  8972. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8973. {
  8974. if (sd->menuskill_id != SA_AUTOSPELL)
  8975. return;
  8976. skill_autospell(sd,RFIFOL(fd,2));
  8977. sd->menuskill_val = sd->menuskill_id = 0;
  8978. }
  8979. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  8980. /// 017a <card index>.W
  8981. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8982. {
  8983. if (sd->state.trading != 0)
  8984. return;
  8985. clif_use_card(sd,RFIFOW(fd,2)-2);
  8986. }
  8987. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  8988. /// 017c <card index>.W <equip index>.W
  8989. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8990. {
  8991. if (sd->state.trading != 0)
  8992. return;
  8993. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8994. }
  8995. /// Request of character's name by char ID.
  8996. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  8997. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  8998. /// There are various variants of this packet, some of them have padding between fields.
  8999. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9000. {
  9001. int charid;
  9002. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9003. map_reqnickdb(sd, charid);
  9004. }
  9005. /// /resetskill /resetstate (CZ_RESET).
  9006. /// Request to reset stats or skills.
  9007. /// 0197 <type>.W
  9008. /// type:
  9009. /// 0 = state
  9010. /// 1 = skill
  9011. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  9012. {
  9013. if( RFIFOW(fd,2) )
  9014. is_atcommand(fd, sd, "@resetskill", 1);
  9015. else
  9016. is_atcommand(fd, sd, "@resetstat", 1);
  9017. }
  9018. /// /lb /nlb (CZ_LOCALBROADCAST).
  9019. /// Request to broadcast a message on current map.
  9020. /// 019c <packet len>.W <text>.?B
  9021. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9022. {
  9023. char command[CHAT_SIZE_MAX+16];
  9024. char* msg = (char*)RFIFOP(fd,4);
  9025. unsigned int len = RFIFOW(fd,2)-4;
  9026. // as the length varies depending on the command used, just block unreasonably long strings
  9027. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  9028. sprintf(command, "@lkami %s", msg);
  9029. is_atcommand(fd, sd, command, 1);
  9030. }
  9031. /// Request to move an item from inventory to storage.
  9032. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9033. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9034. /// There are various variants of this packet, some of them have padding between fields.
  9035. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9036. {
  9037. int item_index, item_amount;
  9038. if (pc_istrading(sd))
  9039. return;
  9040. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9041. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9042. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9043. return;
  9044. if (sd->state.storage_flag == 1)
  9045. storage_storageadd(sd, item_index, item_amount);
  9046. else
  9047. if (sd->state.storage_flag == 2)
  9048. storage_guild_storageadd(sd, item_index, item_amount);
  9049. }
  9050. /// Request to move an item from storage to inventory.
  9051. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9052. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9053. /// There are various variants of this packet, some of them have padding between fields.
  9054. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9055. {
  9056. int item_index, item_amount;
  9057. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9058. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9059. if (sd->state.storage_flag == 1)
  9060. storage_storageget(sd, item_index, item_amount);
  9061. else
  9062. if(sd->state.storage_flag == 2)
  9063. storage_guild_storageget(sd, item_index, item_amount);
  9064. }
  9065. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9066. /// 0129 <index>.W <amount>.L
  9067. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9068. {
  9069. if( sd->state.vending )
  9070. return;
  9071. if (!pc_iscarton(sd))
  9072. return;
  9073. if (sd->state.storage_flag == 1)
  9074. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9075. else
  9076. if (sd->state.storage_flag == 2)
  9077. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9078. }
  9079. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9080. /// 0128 <index>.W <amount>.L
  9081. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9082. {
  9083. if( sd->state.vending )
  9084. return;
  9085. if (!pc_iscarton(sd))
  9086. return;
  9087. if (sd->state.storage_flag == 1)
  9088. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9089. else
  9090. if (sd->state.storage_flag == 2)
  9091. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9092. }
  9093. /// Request to close storage (CZ_CLOSE_STORE).
  9094. /// 00f7
  9095. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9096. {
  9097. if( sd->state.storage_flag == 1 )
  9098. storage_storageclose(sd);
  9099. else
  9100. if( sd->state.storage_flag == 2 )
  9101. storage_guild_storageclose(sd);
  9102. }
  9103. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9104. /// 023a <info>.W
  9105. /// info:
  9106. /// 0 = password has not been set yet
  9107. /// 1 = storage is password-protected
  9108. /// 8 = too many wrong passwords
  9109. /// ? = ignored
  9110. /// NOTE: This packet is only available on certain non-kRO clients.
  9111. void clif_storagepassword(struct map_session_data* sd, short info)
  9112. {
  9113. int fd = sd->fd;
  9114. WFIFOHEAD(fd,packet_len(0x23a));
  9115. WFIFOW(fd,0) = 0x23a;
  9116. WFIFOW(fd,2) = info;
  9117. WFIFOSET(fd,packet_len(0x23a));
  9118. }
  9119. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9120. /// 023b <type>.W <password>.16B <new password>.16B
  9121. /// type:
  9122. /// 2 = change password
  9123. /// 3 = check password
  9124. /// NOTE: This packet is only available on certain non-kRO clients.
  9125. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9126. {
  9127. //TODO
  9128. }
  9129. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9130. /// 023c <result>.W <error count>.W
  9131. /// result:
  9132. /// 4 = password change success
  9133. /// 5 = password change failure
  9134. /// 6 = password check success
  9135. /// 7 = password check failure
  9136. /// 8 = too many wrong passwords
  9137. /// ? = ignored
  9138. /// NOTE: This packet is only available on certain non-kRO clients.
  9139. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9140. {
  9141. int fd = sd->fd;
  9142. WFIFOHEAD(fd,packet_len(0x23c));
  9143. WFIFOW(fd,0) = 0x23c;
  9144. WFIFOW(fd,2) = result;
  9145. WFIFOW(fd,4) = error_count;
  9146. WFIFOSET(fd,packet_len(0x23c));
  9147. }
  9148. /// Party creation request
  9149. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9150. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9151. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9152. {
  9153. char* name = (char*)RFIFOP(fd,2);
  9154. name[NAME_LENGTH-1] = '\0';
  9155. if( map[sd->bl.m].flag.partylock )
  9156. {// Party locked.
  9157. clif_displaymessage(fd, msg_txt(227));
  9158. return;
  9159. }
  9160. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9161. {
  9162. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9163. return;
  9164. }
  9165. party_create(sd,name,0,0);
  9166. }
  9167. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9168. {
  9169. char* name = (char*)RFIFOP(fd,2);
  9170. int item1 = RFIFOB(fd,26);
  9171. int item2 = RFIFOB(fd,27);
  9172. name[NAME_LENGTH-1] = '\0';
  9173. if( map[sd->bl.m].flag.partylock )
  9174. {// Party locked.
  9175. clif_displaymessage(fd, msg_txt(227));
  9176. return;
  9177. }
  9178. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9179. {
  9180. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9181. return;
  9182. }
  9183. party_create(sd,name,item1,item2);
  9184. }
  9185. /// Party invitation request
  9186. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9187. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9188. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9189. {
  9190. struct map_session_data *t_sd;
  9191. if(map[sd->bl.m].flag.partylock)
  9192. {// Party locked.
  9193. clif_displaymessage(fd, msg_txt(227));
  9194. return;
  9195. }
  9196. t_sd = map_id2sd(RFIFOL(fd,2));
  9197. if(t_sd && t_sd->state.noask)
  9198. {// @noask [LuzZza]
  9199. clif_noask_sub(sd, t_sd, 1);
  9200. return;
  9201. }
  9202. party_invite(sd, t_sd);
  9203. }
  9204. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9205. {
  9206. struct map_session_data *t_sd;
  9207. char *name = (char*)RFIFOP(fd,2);
  9208. name[NAME_LENGTH-1] = '\0';
  9209. if(map[sd->bl.m].flag.partylock)
  9210. {// Party locked.
  9211. clif_displaymessage(fd, msg_txt(227));
  9212. return;
  9213. }
  9214. t_sd = map_nick2sd(name);
  9215. if(t_sd && t_sd->state.noask)
  9216. {// @noask [LuzZza]
  9217. clif_noask_sub(sd, t_sd, 1);
  9218. return;
  9219. }
  9220. party_invite(sd, t_sd);
  9221. }
  9222. /// Party invitation reply
  9223. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9224. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9225. /// flag:
  9226. /// 0 = reject
  9227. /// 1 = accept
  9228. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9229. {
  9230. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9231. }
  9232. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9233. {
  9234. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9235. }
  9236. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9237. /// 0100
  9238. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9239. {
  9240. if(map[sd->bl.m].flag.partylock)
  9241. { //Guild locked.
  9242. clif_displaymessage(fd, msg_txt(227));
  9243. return;
  9244. }
  9245. party_leave(sd);
  9246. }
  9247. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9248. /// 0103 <account id>.L <char name>.24B
  9249. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9250. {
  9251. if(map[sd->bl.m].flag.partylock)
  9252. { //Guild locked.
  9253. clif_displaymessage(fd, msg_txt(227));
  9254. return;
  9255. }
  9256. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9257. }
  9258. /// Request to change party options.
  9259. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9260. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9261. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9262. {
  9263. struct party_data *p;
  9264. int i;
  9265. if( !sd->status.party_id )
  9266. return;
  9267. p = party_search(sd->status.party_id);
  9268. if( p == NULL )
  9269. return;
  9270. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9271. if( i == MAX_PARTY )
  9272. return; //Shouldn't happen
  9273. if( !p->party.member[i].leader )
  9274. return;
  9275. #if PACKETVER < 20090603
  9276. //Client can't change the item-field
  9277. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9278. #else
  9279. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9280. #endif
  9281. }
  9282. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9283. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9284. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9285. {
  9286. const char* text = (char*)RFIFOP(fd,4);
  9287. int textlen = RFIFOW(fd,2) - 4;
  9288. char *name, *message;
  9289. int namelen, messagelen;
  9290. // validate packet and retrieve name and message
  9291. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9292. return;
  9293. if( is_atcommand(fd, sd, message, 1) )
  9294. return;
  9295. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9296. return;
  9297. if( battle_config.min_chat_delay )
  9298. { //[Skotlex]
  9299. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9300. return;
  9301. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9302. }
  9303. party_send_message(sd, text, textlen);
  9304. }
  9305. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9306. /// 07da <account id>.L
  9307. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9308. {
  9309. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9310. }
  9311. /// Party Booking in KRO [Spiria]
  9312. ///
  9313. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9314. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9315. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9316. {
  9317. short level = RFIFOW(fd,2);
  9318. short mapid = RFIFOW(fd,4);
  9319. short job[PARTY_BOOKING_JOBS];
  9320. int i;
  9321. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9322. job[i] = RFIFOB(fd,6+i*2);
  9323. party_booking_register(sd, level, mapid, job);
  9324. }
  9325. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9326. /// 0803 <result>.W
  9327. /// result:
  9328. /// 0 = success
  9329. /// 1 = failure
  9330. /// 2 = already registered
  9331. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9332. {
  9333. int fd = sd->fd;
  9334. WFIFOHEAD(fd,packet_len(0x803));
  9335. WFIFOW(fd,0) = 0x803;
  9336. WFIFOW(fd,2) = flag;
  9337. WFIFOSET(fd,packet_len(0x803));
  9338. }
  9339. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9340. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9341. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9342. {
  9343. short level = RFIFOW(fd,2);
  9344. short mapid = RFIFOW(fd,4);
  9345. short job = RFIFOW(fd,6);
  9346. unsigned long lastindex = RFIFOL(fd,8);
  9347. short resultcount = RFIFOW(fd,12);
  9348. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9349. }
  9350. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9351. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9352. /// more results:
  9353. /// 0 = no
  9354. /// 1 = yes
  9355. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9356. {
  9357. int i, j;
  9358. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9359. struct party_booking_ad_info *pb_ad;
  9360. WFIFOHEAD(fd,size*count + 5);
  9361. WFIFOW(fd,0) = 0x805;
  9362. WFIFOW(fd,2) = size*count + 5;
  9363. WFIFOB(fd,4) = more_result;
  9364. for(i=0; i<count; i++)
  9365. {
  9366. pb_ad = results[i];
  9367. WFIFOL(fd,i*size+5) = pb_ad->index;
  9368. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9369. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9370. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9371. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9372. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9373. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9374. }
  9375. WFIFOSET(fd,WFIFOW(fd,2));
  9376. }
  9377. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9378. /// 0806
  9379. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9380. {
  9381. if(party_booking_delete(sd))
  9382. clif_PartyBookingDeleteAck(sd, 0);
  9383. }
  9384. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9385. /// 0807 <result>.W
  9386. /// result:
  9387. /// 0 = success
  9388. /// 1 = success (auto-removed expired ad)
  9389. /// 2 = failure
  9390. /// 3 = nothing registered
  9391. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9392. {
  9393. int fd = sd->fd;
  9394. WFIFOHEAD(fd,packet_len(0x807));
  9395. WFIFOW(fd,0) = 0x807;
  9396. WFIFOW(fd,2) = flag;
  9397. WFIFOSET(fd,packet_len(0x807));
  9398. }
  9399. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  9400. /// 0808 { <job>.W }*6
  9401. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9402. {
  9403. short job[PARTY_BOOKING_JOBS];
  9404. int i;
  9405. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9406. job[i] = RFIFOW(fd,2+i*2);
  9407. party_booking_update(sd, job);
  9408. }
  9409. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  9410. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  9411. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9412. {
  9413. int i;
  9414. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9415. if(pb_ad == NULL) return;
  9416. WBUFW(buf,0) = 0x809;
  9417. WBUFL(buf,2) = pb_ad->index;
  9418. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9419. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  9420. WBUFW(buf,34) = pb_ad->p_detail.level;
  9421. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9422. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9423. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9424. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9425. }
  9426. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  9427. /// 080a <index>.L { <job>.W }*6
  9428. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9429. {
  9430. int i;
  9431. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9432. if(pb_ad == NULL) return;
  9433. WBUFW(buf,0) = 0x80a;
  9434. WBUFL(buf,2) = pb_ad->index;
  9435. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9436. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9437. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9438. }
  9439. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  9440. /// 080b <index>.L
  9441. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9442. {
  9443. uint8 buf[6];
  9444. WBUFW(buf,0) = 0x80b;
  9445. WBUFL(buf,2) = index;
  9446. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9447. }
  9448. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  9449. /// 012e
  9450. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9451. {
  9452. vending_closevending(sd);
  9453. }
  9454. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  9455. /// 0130 <account id>.L
  9456. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9457. {
  9458. if( sd->npc_id )
  9459. {// using an NPC
  9460. return;
  9461. }
  9462. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9463. }
  9464. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  9465. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  9466. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9467. {
  9468. int len = (int)RFIFOW(fd,2) - 8;
  9469. int id = (int)RFIFOL(fd,4);
  9470. const uint8* data = (uint8*)RFIFOP(fd,8);
  9471. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  9472. // whether it fails or not, the buy window is closed
  9473. sd->vended_id = 0;
  9474. }
  9475. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  9476. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  9477. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9478. {
  9479. int len = (int)RFIFOW(fd,2) - 12;
  9480. int aid = (int)RFIFOL(fd,4);
  9481. int uid = (int)RFIFOL(fd,8);
  9482. const uint8* data = (uint8*)RFIFOP(fd,12);
  9483. vending_purchasereq(sd, aid, uid, data, len/4);
  9484. // whether it fails or not, the buy window is closed
  9485. sd->vended_id = 0;
  9486. }
  9487. /// Confirm or cancel the shop preparation window.
  9488. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  9489. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  9490. /// result:
  9491. /// 0 = canceled
  9492. /// 1 = open
  9493. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9494. {
  9495. short len = (short)RFIFOW(fd,2) - 85;
  9496. const char* message = (char*)RFIFOP(fd,4);
  9497. bool flag = (bool)RFIFOB(fd,84);
  9498. const uint8* data = (uint8*)RFIFOP(fd,85);
  9499. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9500. return;
  9501. if( map[sd->bl.m].flag.novending ) {
  9502. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9503. return;
  9504. }
  9505. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9506. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  9507. return;
  9508. }
  9509. if( message[0] == '\0' ) // invalid input
  9510. return;
  9511. vending_openvending(sd, message, flag, data, len/8);
  9512. }
  9513. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  9514. /// 0165 <char id>.L <guild name>.24B
  9515. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9516. {
  9517. char* name = (char*)RFIFOP(fd,6);
  9518. name[NAME_LENGTH-1] = '\0';
  9519. if(map[sd->bl.m].flag.guildlock)
  9520. { //Guild locked.
  9521. clif_displaymessage(fd, msg_txt(228));
  9522. return;
  9523. }
  9524. guild_create(sd, name);
  9525. }
  9526. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  9527. /// 014d
  9528. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9529. {
  9530. clif_guild_masterormember(sd);
  9531. }
  9532. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  9533. /// 014f <type>.L
  9534. /// type:
  9535. /// 0 = basic info
  9536. /// 1 = member manager
  9537. /// 2 = positions
  9538. /// 3 = skills
  9539. /// 4 = expulsion list
  9540. /// 5 = unknown (GM_ALLGUILDLIST)
  9541. /// 6 = notice
  9542. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  9543. {
  9544. if( !sd->status.guild_id && !sd->bg_id )
  9545. return;
  9546. switch( RFIFOL(fd,2) )
  9547. {
  9548. case 0: // ギルド基本情報、同盟敵対情報
  9549. clif_guild_basicinfo(sd);
  9550. clif_guild_allianceinfo(sd);
  9551. break;
  9552. case 1: // メンバーリスト、役職名リスト
  9553. clif_guild_positionnamelist(sd);
  9554. clif_guild_memberlist(sd);
  9555. break;
  9556. case 2: // 役職名リスト、役職情報リスト
  9557. clif_guild_positionnamelist(sd);
  9558. clif_guild_positioninfolist(sd);
  9559. break;
  9560. case 3: // スキルリスト
  9561. clif_guild_skillinfo(sd);
  9562. break;
  9563. case 4: // 追放リスト
  9564. clif_guild_expulsionlist(sd);
  9565. break;
  9566. default:
  9567. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9568. break;
  9569. }
  9570. }
  9571. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  9572. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  9573. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  9574. {
  9575. int i;
  9576. if(!sd->state.gmaster_flag)
  9577. return;
  9578. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9579. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9580. }
  9581. }
  9582. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  9583. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  9584. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  9585. {
  9586. int i;
  9587. if(!sd->state.gmaster_flag)
  9588. return;
  9589. for(i=4;i<RFIFOW(fd,2);i+=12){
  9590. guild_change_memberposition(sd->status.guild_id,
  9591. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9592. }
  9593. }
  9594. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  9595. /// 0151 <guild id>.L
  9596. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  9597. {
  9598. struct guild* g;
  9599. int guild_id = RFIFOL(fd,2);
  9600. if( (g = guild_search(guild_id)) != NULL )
  9601. clif_guild_emblem(sd,g);
  9602. }
  9603. /// Validates data of a guild emblem (compressed bitmap)
  9604. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  9605. {
  9606. bool success;
  9607. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  9608. unsigned long buf_len = sizeof(buf);
  9609. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  9610. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  9611. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  9612. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  9613. ;
  9614. return success;
  9615. }
  9616. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  9617. /// 0153 <packet len>.W <emblem data>.?B
  9618. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  9619. {
  9620. unsigned long emblem_len = RFIFOW(fd,2)-4;
  9621. const uint8* emblem = RFIFOP(fd,4);
  9622. if( !emblem_len || !sd->state.gmaster_flag )
  9623. return;
  9624. if( !clif_validate_emblem(emblem, emblem_len) )
  9625. {
  9626. 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);
  9627. return;
  9628. }
  9629. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  9630. }
  9631. /// Guild notice update request (CZ_GUILD_NOTICE).
  9632. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  9633. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  9634. {
  9635. int guild_id = RFIFOL(fd,2);
  9636. char* msg1 = (char*)RFIFOP(fd,6);
  9637. char* msg2 = (char*)RFIFOP(fd,66);
  9638. if(!sd->state.gmaster_flag)
  9639. return;
  9640. // compensate for some client defects when using multilanguage mode
  9641. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  9642. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  9643. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  9644. guild_change_notice(sd, guild_id, msg1, msg2);
  9645. }
  9646. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  9647. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  9648. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  9649. {
  9650. struct map_session_data *t_sd;
  9651. if(map[sd->bl.m].flag.guildlock)
  9652. { //Guild locked.
  9653. clif_displaymessage(fd, msg_txt(228));
  9654. return;
  9655. }
  9656. t_sd = map_id2sd(RFIFOL(fd,2));
  9657. // @noask [LuzZza]
  9658. if(t_sd && t_sd->state.noask) {
  9659. clif_noask_sub(sd, t_sd, 2);
  9660. return;
  9661. }
  9662. guild_invite(sd,t_sd);
  9663. }
  9664. /// Answer to guild invitation (CZ_JOIN_GUILD).
  9665. /// 016b <guild id>.L <answer>.L
  9666. /// answer:
  9667. /// 0 = refuse
  9668. /// 1 = accept
  9669. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  9670. {
  9671. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9672. }
  9673. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  9674. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  9675. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9676. {
  9677. if(map[sd->bl.m].flag.guildlock)
  9678. { //Guild locked.
  9679. clif_displaymessage(fd, msg_txt(228));
  9680. return;
  9681. }
  9682. if( sd->bg_id )
  9683. {
  9684. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9685. return;
  9686. }
  9687. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9688. }
  9689. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  9690. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  9691. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9692. {
  9693. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  9694. { // Guild locked.
  9695. clif_displaymessage(fd, msg_txt(228));
  9696. return;
  9697. }
  9698. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9699. }
  9700. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  9701. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  9702. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9703. {
  9704. const char* text = (char*)RFIFOP(fd,4);
  9705. int textlen = RFIFOW(fd,2) - 4;
  9706. char *name, *message;
  9707. int namelen, messagelen;
  9708. // validate packet and retrieve name and message
  9709. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9710. return;
  9711. if( is_atcommand(fd, sd, message, 1) )
  9712. return;
  9713. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9714. return;
  9715. if( battle_config.min_chat_delay )
  9716. { //[Skotlex]
  9717. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9718. return;
  9719. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9720. }
  9721. if( sd->bg_id )
  9722. bg_send_message(sd, text, textlen);
  9723. else
  9724. guild_send_message(sd, text, textlen);
  9725. }
  9726. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  9727. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  9728. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9729. {
  9730. struct map_session_data *t_sd;
  9731. if(!sd->state.gmaster_flag)
  9732. return;
  9733. if(map[sd->bl.m].flag.guildlock)
  9734. { //Guild locked.
  9735. clif_displaymessage(fd, msg_txt(228));
  9736. return;
  9737. }
  9738. t_sd = map_id2sd(RFIFOL(fd,2));
  9739. // @noask [LuzZza]
  9740. if(t_sd && t_sd->state.noask) {
  9741. clif_noask_sub(sd, t_sd, 3);
  9742. return;
  9743. }
  9744. guild_reqalliance(sd,t_sd);
  9745. }
  9746. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  9747. /// 0172 <inviter account id>.L <answer>.L
  9748. /// answer:
  9749. /// 0 = refuse
  9750. /// 1 = accept
  9751. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9752. {
  9753. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9754. }
  9755. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  9756. /// 0183 <opponent guild id>.L <relation>.L
  9757. /// relation:
  9758. /// 0 = Ally
  9759. /// 1 = Enemy
  9760. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9761. {
  9762. if(!sd->state.gmaster_flag)
  9763. return;
  9764. if(map[sd->bl.m].flag.guildlock)
  9765. { //Guild locked.
  9766. clif_displaymessage(fd, msg_txt(228));
  9767. return;
  9768. }
  9769. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9770. }
  9771. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  9772. /// 0180 <account id>.L
  9773. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9774. {
  9775. struct map_session_data *t_sd;
  9776. if(!sd->state.gmaster_flag)
  9777. return;
  9778. if(map[sd->bl.m].flag.guildlock)
  9779. { //Guild locked.
  9780. clif_displaymessage(fd, msg_txt(228));
  9781. return;
  9782. }
  9783. t_sd = map_id2sd(RFIFOL(fd,2));
  9784. // @noask [LuzZza]
  9785. if(t_sd && t_sd->state.noask) {
  9786. clif_noask_sub(sd, t_sd, 4);
  9787. return;
  9788. }
  9789. guild_opposition(sd,t_sd);
  9790. }
  9791. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  9792. /// 015d <key>.40B
  9793. /// key:
  9794. /// now guild name; might have been (intended) email, since the
  9795. /// field name and size is same as the one in CH_DELETE_CHAR.
  9796. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9797. {
  9798. if( map[sd->bl.m].flag.guildlock )
  9799. { //Guild locked.
  9800. clif_displaymessage(fd, msg_txt(228));
  9801. return;
  9802. }
  9803. guild_break(sd,(char*)RFIFOP(fd,2));
  9804. }
  9805. /// Pet
  9806. ///
  9807. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  9808. /// 01a1 <type>.B
  9809. /// type:
  9810. /// 0 = pet information
  9811. /// 1 = feed
  9812. /// 2 = performance
  9813. /// 3 = return to egg
  9814. /// 4 = unequip accessory
  9815. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9816. {
  9817. pet_menu(sd,RFIFOB(fd,2));
  9818. }
  9819. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  9820. /// 019f <id>.L
  9821. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9822. {
  9823. pet_catch_process2(sd,RFIFOL(fd,2));
  9824. }
  9825. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  9826. /// 01a7 <index>.W
  9827. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9828. {
  9829. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9830. {
  9831. //Forged packet, disconnect them [Kevin]
  9832. clif_authfail_fd(fd, 0);
  9833. return;
  9834. }
  9835. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9836. sd->menuskill_val = sd->menuskill_id = 0;
  9837. }
  9838. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  9839. /// 01a9 <data>.L
  9840. /// data:
  9841. /// is either emotion (@see enum emotion_type) or a compound value
  9842. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  9843. /// entry (given in parentheses) in data\pettalktable.xml
  9844. /// act id:
  9845. /// 0 = feeding
  9846. /// 1 = hunting
  9847. /// 2 = danger
  9848. /// 3 = dead
  9849. /// 4 = normal (stand)
  9850. /// 5 = special performance (perfor_s)
  9851. /// 6 = level up (levelup)
  9852. /// 7 = performance 1 (perfor_1)
  9853. /// 8 = performance 2 (perfor_2)
  9854. /// 9 = performance 3 (perfor_3)
  9855. /// 10 = log-in greeting (connect)
  9856. /// hungry value:
  9857. /// 0 = very hungry (hungry)
  9858. /// 1 = hungry (bit_hungry)
  9859. /// 2 = satisfied (noting)
  9860. /// 3 = stuffed (full)
  9861. /// 4 = full (so_full)
  9862. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9863. {
  9864. if(sd->pd)
  9865. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9866. }
  9867. /// Request to change pet's name (CZ_RENAME_PET).
  9868. /// 01a5 <name>.24B
  9869. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9870. {
  9871. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9872. }
  9873. /// /kill (CZ_DISCONNECT_CHARACTER).
  9874. /// Request to disconnect a character.
  9875. /// 00cc <account id>.L
  9876. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  9877. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9878. {
  9879. struct block_list *target;
  9880. int tid;
  9881. tid = RFIFOL(fd,2);
  9882. target = map_id2bl(tid);
  9883. if (!target) {
  9884. clif_GM_kickack(sd, 0);
  9885. return;
  9886. }
  9887. switch (target->type) {
  9888. case BL_PC:
  9889. {
  9890. char command[NAME_LENGTH+6];
  9891. sprintf(command, "@kick %s", status_get_name(target));
  9892. is_atcommand(fd, sd, command, 1);
  9893. }
  9894. break;
  9895. /**
  9896. * This one does not invoke any atcommand, so we need to check for permissions.
  9897. */
  9898. case BL_MOB:
  9899. {
  9900. char command[100];
  9901. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  9902. clif_GM_kickack(sd, 0);
  9903. return;
  9904. }
  9905. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9906. log_atcommand(sd, command);
  9907. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  9908. }
  9909. break;
  9910. case BL_NPC:
  9911. {
  9912. char command[NAME_LENGTH+11];
  9913. sprintf(command, "@unloadnpc %s", status_get_name(target));
  9914. is_atcommand(fd, sd, command, 1);
  9915. }
  9916. break;
  9917. default:
  9918. clif_GM_kickack(sd, 0);
  9919. }
  9920. }
  9921. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  9922. /// Request to disconnect all characters.
  9923. /// 00ce
  9924. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9925. {
  9926. is_atcommand(fd, sd, "@kickall", 1);
  9927. }
  9928. /// /remove (CZ_REMOVE_AID).
  9929. /// Request to warp to a character with given login ID.
  9930. /// 01ba <account name>.24B
  9931. /// /shift (CZ_SHIFT).
  9932. /// Request to warp to a character with given name.
  9933. /// 01bb <char name>.24B
  9934. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9935. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  9936. char *player_name;
  9937. char command[NAME_LENGTH+8];
  9938. player_name = (char*)RFIFOP(fd,2);
  9939. player_name[NAME_LENGTH-1] = '\0';
  9940. sprintf(command, "@jumpto %s", player_name);
  9941. is_atcommand(fd, sd, command, 1);
  9942. }
  9943. /// /remove (CZ_REMOVE_AID_SSO).
  9944. /// Request to warp to a character with given account ID.
  9945. /// 0843 <account id>.L
  9946. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  9947. {
  9948. int account_id;
  9949. struct map_session_data* pl_sd;
  9950. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9951. if( (pl_sd = map_id2sd(account_id)) != NULL )
  9952. {
  9953. char command[NAME_LENGTH+8];
  9954. sprintf(command, "@jumpto %s", pl_sd->status.name);
  9955. is_atcommand(fd, sd, command, 1);
  9956. }
  9957. }
  9958. /// /recall (CZ_RECALL).
  9959. /// Request to summon a player with given login ID to own position.
  9960. /// 01bc <account name>.24B
  9961. /// /summon (CZ_RECALL_GID).
  9962. /// Request to summon a player with given name to own position.
  9963. /// 01bd <char name>.24B
  9964. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9965. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  9966. char *player_name;
  9967. char command [NAME_LENGTH+8];
  9968. player_name = (char*)RFIFOP(fd,2);
  9969. player_name[NAME_LENGTH-1] = '\0';
  9970. sprintf(command, "@recall %s", player_name);
  9971. is_atcommand(fd, sd, command, 1);
  9972. }
  9973. /// /recall (CZ_RECALL_SSO).
  9974. /// Request to summon a player with given account ID to own position.
  9975. /// 0842 <account id>.L
  9976. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  9977. {
  9978. int account_id;
  9979. struct map_session_data* pl_sd;
  9980. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9981. if( (pl_sd = map_id2sd(account_id)) != NULL )
  9982. {
  9983. char command[NAME_LENGTH+8];
  9984. sprintf(command, "@recall %s", pl_sd->status.name);
  9985. is_atcommand(fd, sd, command, 1);
  9986. }
  9987. }
  9988. /// /item /monster (CZ_ITEM_CREATE).
  9989. /// Request to make items or spawn monsters.
  9990. /// 013f <item/mob name>.24B
  9991. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9992. {
  9993. char *monster_item_name;
  9994. char command[NAME_LENGTH+10];
  9995. monster_item_name = (char*)RFIFOP(fd,2);
  9996. monster_item_name[NAME_LENGTH-1] = '\0';
  9997. if( mobdb_searchname(monster_item_name) ) {
  9998. snprintf(command, sizeof(command)-1, "@monster %s", monster_item_name);
  9999. is_atcommand(fd, sd, command, 1);
  10000. return;
  10001. }
  10002. if( itemdb_searchname(monster_item_name) ) {
  10003. snprintf(command, sizeof(command)-1, "@item %s", monster_item_name);
  10004. is_atcommand(fd, sd, command, 1);
  10005. return;
  10006. }
  10007. }
  10008. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10009. /// 019d <effect state>.L
  10010. /// effect state:
  10011. /// TODO: Any OPTION_* ?
  10012. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  10013. {
  10014. is_atcommand(fd, sd, "@hide", 1);
  10015. }
  10016. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10017. /// 0149 <account id>.L <type>.B <value>.W
  10018. /// type:
  10019. /// 0 = positive points
  10020. /// 1 = negative points
  10021. /// 2 = self mute (+10 minutes)
  10022. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10023. {
  10024. int id, type, value;
  10025. struct map_session_data *dstsd;
  10026. char command[NAME_LENGTH+15];
  10027. id = RFIFOL(fd,2);
  10028. type = RFIFOB(fd,6);
  10029. value = RFIFOW(fd,7);
  10030. if( type == 0 )
  10031. value = -value;
  10032. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10033. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10034. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10035. return;
  10036. dstsd = map_id2sd(id);
  10037. if( dstsd == NULL )
  10038. return;
  10039. sprintf(command, "@mute %d %s", value, dstsd->status.name);
  10040. is_atcommand(fd, sd, command, 1);
  10041. }
  10042. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10043. /// GM adjustment of a player's manner value by -60.
  10044. /// 0212 <char name>.24B
  10045. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10046. {
  10047. char command[NAME_LENGTH+15];
  10048. char *name = (char*)RFIFOP(fd,2);
  10049. name[NAME_LENGTH-1] = '\0';
  10050. sprintf(command, "@mute %d %s", 60, name);
  10051. is_atcommand(fd, sd, command, 1);
  10052. }
  10053. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10054. /// 01df <account id>.L
  10055. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10056. /// 01e0 <account id>.L <account name>.24B
  10057. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10058. {
  10059. int tid;
  10060. tid = RFIFOL(fd,2);
  10061. //TODO: find out if this works for any player or only for authorized GMs
  10062. WFIFOHEAD(fd,packet_len(0x1e0));
  10063. WFIFOW(fd,0) = 0x1e0;
  10064. WFIFOL(fd,2) = tid;
  10065. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10066. WFIFOSET(fd, packet_len(0x1e0));
  10067. }
  10068. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10069. /// GM single cell type change request.
  10070. /// 0198 <x>.W <y>.W <type>.W
  10071. /// type:
  10072. /// 0 = not walkable
  10073. /// 1 = walkable
  10074. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10075. {
  10076. int x,y,type;
  10077. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10078. return;
  10079. x = RFIFOW(fd,2);
  10080. y = RFIFOW(fd,4);
  10081. type = RFIFOW(fd,6);
  10082. map_setgatcell(sd->bl.m,x,y,type);
  10083. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10084. //FIXME: once players leave the map, the client 'forgets' this information.
  10085. }
  10086. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10087. /// Request to allow/deny whispers from a nick.
  10088. /// 00cf <nick>.24B <type>.B
  10089. /// type:
  10090. /// 0 = (/ex nick) deny speech from nick
  10091. /// 1 = (/in nick) allow speech from nick
  10092. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10093. {
  10094. char* nick;
  10095. uint8 type;
  10096. int i;
  10097. nick = (char*)RFIFOP(fd,2); // speed up
  10098. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10099. type = RFIFOB(fd,26);
  10100. // FIXME: Use clif_wisexin.
  10101. WFIFOHEAD(fd,packet_len(0xd1));
  10102. WFIFOW(fd,0) = 0x0d1;
  10103. WFIFOB(fd,2) = type;
  10104. if( type == 0 )
  10105. { // Add name to ignore list (block)
  10106. if (strcmp(wisp_server_name, nick) == 0) {
  10107. WFIFOB(fd,3) = 1; // fail
  10108. WFIFOSET(fd, packet_len(0x0d1));
  10109. return;
  10110. }
  10111. // try to find a free spot, while checking for duplicates at the same time
  10112. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10113. if( i == MAX_IGNORE_LIST )
  10114. {// no space for new entry
  10115. WFIFOB(fd,3) = 2; // fail
  10116. WFIFOSET(fd, packet_len(0x0d1));
  10117. return;
  10118. }
  10119. if( sd->ignore[i].name[0] != '\0' )
  10120. {// name already exists
  10121. WFIFOB(fd,3) = 0; // Aegis reports success.
  10122. WFIFOSET(fd, packet_len(0x0d1));
  10123. return;
  10124. }
  10125. //Insert in position i
  10126. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10127. WFIFOB(fd,3) = 0; // success
  10128. WFIFOSET(fd, packet_len(0x0d1));
  10129. }
  10130. else
  10131. { // Remove name from ignore list (unblock)
  10132. // find entry
  10133. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10134. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10135. { //Not found
  10136. WFIFOB(fd,3) = 1; // fail
  10137. WFIFOSET(fd, packet_len(0x0d1));
  10138. return;
  10139. }
  10140. // move everything one place down to overwrite removed entry
  10141. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10142. // wipe last entry
  10143. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10144. WFIFOB(fd,3) = 0; // success
  10145. WFIFOSET(fd, packet_len(0x0d1));
  10146. }
  10147. }
  10148. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10149. /// Request to allow/deny all whispers.
  10150. /// 00d0 <type>.B
  10151. /// type:
  10152. /// 0 = (/exall) deny all speech
  10153. /// 1 = (/inall) allow all speech
  10154. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10155. {
  10156. // FIXME: Use clif_wisall.
  10157. WFIFOHEAD(fd,packet_len(0xd2));
  10158. WFIFOW(fd,0) = 0x0d2;
  10159. WFIFOB(fd,2) = RFIFOB(fd,2);
  10160. if( RFIFOB(fd,2) == 0 )
  10161. {// Deny all
  10162. if( sd->state.ignoreAll ) {
  10163. WFIFOB(fd,3) = 1; // fail
  10164. } else {
  10165. sd->state.ignoreAll = 1;
  10166. WFIFOB(fd,3) = 0; // success
  10167. }
  10168. }
  10169. else
  10170. {//Unblock everyone
  10171. if( sd->state.ignoreAll ) {
  10172. sd->state.ignoreAll = 0;
  10173. WFIFOB(fd,3) = 0; // success
  10174. } else {
  10175. if (sd->ignore[0].name[0] != '\0')
  10176. { //Wipe the ignore list.
  10177. memset(sd->ignore, 0, sizeof(sd->ignore));
  10178. WFIFOB(fd,3) = 0; // success
  10179. } else {
  10180. WFIFOB(fd,3) = 1; // fail
  10181. }
  10182. }
  10183. }
  10184. WFIFOSET(fd, packet_len(0x0d2));
  10185. }
  10186. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10187. /// 00d3
  10188. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10189. {
  10190. int i;
  10191. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10192. WFIFOW(fd,0) = 0xd4;
  10193. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10194. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10195. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10196. WFIFOSET(fd, WFIFOW(fd,2));
  10197. }
  10198. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10199. /// 01e7
  10200. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10201. {
  10202. if (sd->state.doridori) return;
  10203. switch (sd->class_&MAPID_UPPERMASK)
  10204. {
  10205. case MAPID_SOUL_LINKER:
  10206. case MAPID_STAR_GLADIATOR:
  10207. case MAPID_TAEKWON:
  10208. if (!sd->state.rest)
  10209. break;
  10210. case MAPID_SUPER_NOVICE:
  10211. sd->state.doridori=1;
  10212. break;
  10213. }
  10214. }
  10215. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10216. /// 01ed
  10217. /// Note: This packet is caused by 7 lines of any text, followed by
  10218. /// the prayer and an another line of any text. The prayer is
  10219. /// defined by lines 790~793 in data\msgstringtable.txt
  10220. /// "Dear angel, can you hear my voice?"
  10221. /// "I am" (space separated player name) "Super Novice~"
  10222. /// "Help me out~ Please~ T_T"
  10223. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10224. {
  10225. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10226. {
  10227. unsigned int next = pc_nextbaseexp(sd);
  10228. if( next == 0 ) next = pc_thisbaseexp(sd);
  10229. if( next )
  10230. {
  10231. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10232. if( percent && ( percent%100 ) == 0 )
  10233. {// 10.0%, 20.0%, ..., 90.0%
  10234. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10235. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10236. }
  10237. }
  10238. }
  10239. }
  10240. /// Friends List
  10241. ///
  10242. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10243. /// 0206 <account id>.L <char id>.L <state>.B
  10244. /// state:
  10245. /// 0 = online
  10246. /// 1 = offline
  10247. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10248. {
  10249. int i, fd = sd->fd;
  10250. //Seek friend.
  10251. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10252. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10253. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10254. return; //Not found
  10255. WFIFOHEAD(fd,packet_len(0x206));
  10256. WFIFOW(fd, 0) = 0x206;
  10257. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10258. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10259. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10260. WFIFOSET(fd, packet_len(0x206));
  10261. }
  10262. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10263. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10264. {
  10265. int account_id, char_id, online;
  10266. account_id = va_arg(ap, int);
  10267. char_id = va_arg(ap, int);
  10268. online = va_arg(ap, int);
  10269. clif_friendslist_toggle(sd, account_id, char_id, online);
  10270. return 0;
  10271. }
  10272. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10273. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10274. void clif_friendslist_send(struct map_session_data *sd)
  10275. {
  10276. int i = 0, n, fd = sd->fd;
  10277. // Send friends list
  10278. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10279. WFIFOW(fd, 0) = 0x201;
  10280. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10281. {
  10282. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10283. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10284. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10285. }
  10286. if (i) {
  10287. WFIFOW(fd,2) = 4 + 32 * i;
  10288. WFIFOSET(fd, WFIFOW(fd,2));
  10289. }
  10290. for (n = 0; n < i; n++)
  10291. { //Sending the online players
  10292. if (map_charid2sd(sd->status.friends[n].char_id))
  10293. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10294. }
  10295. }
  10296. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10297. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10298. /// result:
  10299. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10300. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10301. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10302. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10303. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10304. {
  10305. int fd;
  10306. nullpo_retv(sd);
  10307. fd = sd->fd;
  10308. WFIFOHEAD(fd,packet_len(0x209));
  10309. WFIFOW(fd,0) = 0x209;
  10310. WFIFOW(fd,2) = type;
  10311. if (f_sd)
  10312. {
  10313. WFIFOL(fd,4) = f_sd->status.account_id;
  10314. WFIFOL(fd,8) = f_sd->status.char_id;
  10315. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10316. }
  10317. WFIFOSET(fd, packet_len(0x209));
  10318. }
  10319. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10320. /// 0202 <name>.24B
  10321. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10322. {
  10323. struct map_session_data *f_sd;
  10324. int i, f_fd;
  10325. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10326. // ensure that the request player's friend list is not full
  10327. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10328. if( i == MAX_FRIENDS ) {
  10329. clif_friendslist_reqack(sd, f_sd, 2);
  10330. return;
  10331. }
  10332. // Friend doesn't exist (no player with this name)
  10333. if (f_sd == NULL) {
  10334. clif_displaymessage(fd, msg_txt(3));
  10335. return;
  10336. }
  10337. if( sd->bl.id == f_sd->bl.id )
  10338. {// adding oneself as friend
  10339. return;
  10340. }
  10341. // @noask [LuzZza]
  10342. if(f_sd->state.noask) {
  10343. clif_noask_sub(sd, f_sd, 5);
  10344. return;
  10345. }
  10346. // Friend already exists
  10347. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10348. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10349. clif_displaymessage(fd, "Friend already exists.");
  10350. return;
  10351. }
  10352. }
  10353. f_sd->friend_req = sd->status.char_id;
  10354. sd->friend_req = f_sd->status.char_id;
  10355. f_fd = f_sd->fd;
  10356. WFIFOHEAD(f_fd,packet_len(0x207));
  10357. WFIFOW(f_fd,0) = 0x207;
  10358. WFIFOL(f_fd,2) = sd->status.account_id;
  10359. WFIFOL(f_fd,6) = sd->status.char_id;
  10360. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10361. WFIFOSET(f_fd, packet_len(0x207));
  10362. }
  10363. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10364. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10365. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10366. /// result:
  10367. /// 0 = rejected
  10368. /// 1 = accepted
  10369. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10370. {
  10371. struct map_session_data *f_sd;
  10372. int char_id, account_id;
  10373. char reply;
  10374. account_id = RFIFOL(fd,2);
  10375. char_id = RFIFOL(fd,6);
  10376. reply = RFIFOL(fd,10);
  10377. if( sd->bl.id == account_id )
  10378. {// adding oneself as friend
  10379. return;
  10380. }
  10381. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10382. if (f_sd == NULL)
  10383. return;
  10384. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10385. clif_friendslist_reqack(f_sd, sd, 1);
  10386. else {
  10387. int i;
  10388. // Find an empty slot
  10389. for (i = 0; i < MAX_FRIENDS; i++)
  10390. if (f_sd->status.friends[i].char_id == 0)
  10391. break;
  10392. if (i == MAX_FRIENDS) {
  10393. clif_friendslist_reqack(f_sd, sd, 2);
  10394. return;
  10395. }
  10396. f_sd->status.friends[i].account_id = sd->status.account_id;
  10397. f_sd->status.friends[i].char_id = sd->status.char_id;
  10398. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10399. clif_friendslist_reqack(f_sd, sd, 0);
  10400. if (battle_config.friend_auto_add) {
  10401. // Also add f_sd to sd's friendlist.
  10402. for (i = 0; i < MAX_FRIENDS; i++) {
  10403. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10404. return; //No need to add anything.
  10405. if (sd->status.friends[i].char_id == 0)
  10406. break;
  10407. }
  10408. if (i == MAX_FRIENDS) {
  10409. clif_friendslist_reqack(sd, f_sd, 2);
  10410. return;
  10411. }
  10412. sd->status.friends[i].account_id = f_sd->status.account_id;
  10413. sd->status.friends[i].char_id = f_sd->status.char_id;
  10414. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10415. clif_friendslist_reqack(sd, f_sd, 0);
  10416. }
  10417. }
  10418. }
  10419. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  10420. /// 0203 <account id>.L <char id>.L
  10421. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10422. {
  10423. struct map_session_data *f_sd = NULL;
  10424. int account_id, char_id;
  10425. int i, j;
  10426. account_id = RFIFOL(fd,2);
  10427. char_id = RFIFOL(fd,6);
  10428. // Search friend
  10429. for (i = 0; i < MAX_FRIENDS &&
  10430. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10431. if (i == MAX_FRIENDS) {
  10432. clif_displaymessage(fd, "Name not found in list.");
  10433. return;
  10434. }
  10435. //remove from friend's list first
  10436. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  10437. for (i = 0; i < MAX_FRIENDS &&
  10438. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  10439. if (i != MAX_FRIENDS) {
  10440. // move all chars up
  10441. for(j = i + 1; j < MAX_FRIENDS; j++)
  10442. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  10443. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  10444. //should the guy be notified of some message? we should add it here if so
  10445. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  10446. WFIFOW(f_sd->fd,0) = 0x20a;
  10447. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  10448. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  10449. WFIFOSET(f_sd->fd, packet_len(0x20a));
  10450. }
  10451. } else { //friend not online -- ask char server to delete from his friendlist
  10452. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  10453. clif_displaymessage(fd, "This action can't be performed at the moment. Please try again later.");
  10454. return;
  10455. }
  10456. }
  10457. // We can now delete from original requester
  10458. for (i = 0; i < MAX_FRIENDS &&
  10459. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10460. // move all chars up
  10461. for(j = i + 1; j < MAX_FRIENDS; j++)
  10462. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10463. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10464. clif_displaymessage(fd, "Friend removed");
  10465. WFIFOHEAD(fd,packet_len(0x20a));
  10466. WFIFOW(fd,0) = 0x20a;
  10467. WFIFOL(fd,2) = account_id;
  10468. WFIFOL(fd,6) = char_id;
  10469. WFIFOSET(fd, packet_len(0x20a));
  10470. // clif_friendslist_send(sd); //This is not needed anymore.
  10471. }
  10472. /// /pvpinfo (CZ_REQ_PVPPOINT).
  10473. /// 020f <char id>.L <account id>.L
  10474. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  10475. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  10476. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10477. {
  10478. WFIFOHEAD(fd,packet_len(0x210));
  10479. WFIFOW(fd,0) = 0x210;
  10480. WFIFOL(fd,2) = sd->status.char_id;
  10481. WFIFOL(fd,6) = sd->status.account_id;
  10482. WFIFOL(fd,10) = sd->pvp_won; // times won
  10483. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10484. WFIFOL(fd,18) = sd->pvp_point;
  10485. WFIFOSET(fd, packet_len(0x210));
  10486. }
  10487. /// /blacksmith (CZ_BLACKSMITH_RANK).
  10488. /// 0217
  10489. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  10490. /// 0219 { <name>.24B }*10 { <point>.L }*10
  10491. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10492. {
  10493. int i;
  10494. const char* name;
  10495. WFIFOHEAD(fd,packet_len(0x219));
  10496. WFIFOW(fd,0) = 0x219;
  10497. //Packet size limits this list to 10 elements. [Skotlex]
  10498. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10499. if (smith_fame_list[i].id > 0) {
  10500. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10501. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10502. {
  10503. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10504. } else
  10505. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10506. } else
  10507. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10508. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10509. }
  10510. for(;i < 10; i++) { //In case the MAX is less than 10.
  10511. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10512. WFIFOL(fd, 242 + i * 4) = 0;
  10513. }
  10514. WFIFOSET(fd, packet_len(0x219));
  10515. }
  10516. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  10517. /// 021b <points>.L <total points>.L
  10518. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  10519. {
  10520. int fd = sd->fd;
  10521. WFIFOHEAD(fd,packet_len(0x21b));
  10522. WFIFOW(fd,0) = 0x21b;
  10523. WFIFOL(fd,2) = points;
  10524. WFIFOL(fd,6) = sd->status.fame;
  10525. WFIFOSET(fd, packet_len(0x21b));
  10526. }
  10527. /// /alchemist (CZ_ALCHEMIST_RANK).
  10528. /// 0218
  10529. /// /alchemist list (ZC_ALCHEMIST_RANK).
  10530. /// 021a { <name>.24B }*10 { <point>.L }*10
  10531. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10532. {
  10533. int i;
  10534. const char* name;
  10535. WFIFOHEAD(fd,packet_len(0x21a));
  10536. WFIFOW(fd,0) = 0x21a;
  10537. //Packet size limits this list to 10 elements. [Skotlex]
  10538. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10539. if (chemist_fame_list[i].id > 0) {
  10540. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10541. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10542. {
  10543. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10544. } else
  10545. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10546. } else
  10547. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10548. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10549. }
  10550. for(;i < 10; i++) { //In case the MAX is less than 10.
  10551. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10552. WFIFOL(fd, 242 + i * 4) = 0;
  10553. }
  10554. WFIFOSET(fd, packet_len(0x21a));
  10555. }
  10556. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  10557. /// 021c <points>.L <total points>.L
  10558. void clif_fame_alchemist(struct map_session_data *sd, int points)
  10559. {
  10560. int fd = sd->fd;
  10561. WFIFOHEAD(fd,packet_len(0x21c));
  10562. WFIFOW(fd,0) = 0x21c;
  10563. WFIFOL(fd,2) = points;
  10564. WFIFOL(fd,6) = sd->status.fame;
  10565. WFIFOSET(fd, packet_len(0x21c));
  10566. }
  10567. /// /taekwon (CZ_TAEKWON_RANK).
  10568. /// 0225
  10569. /// /taekwon list (ZC_TAEKWON_RANK).
  10570. /// 0226 { <name>.24B }*10 { <point>.L }*10
  10571. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10572. {
  10573. int i;
  10574. const char* name;
  10575. WFIFOHEAD(fd,packet_len(0x226));
  10576. WFIFOW(fd,0) = 0x226;
  10577. //Packet size limits this list to 10 elements. [Skotlex]
  10578. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10579. if (taekwon_fame_list[i].id > 0) {
  10580. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10581. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10582. {
  10583. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10584. } else
  10585. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10586. } else
  10587. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10588. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10589. }
  10590. for(;i < 10; i++) { //In case the MAX is less than 10.
  10591. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10592. WFIFOL(fd, 242 + i * 4) = 0;
  10593. }
  10594. WFIFOSET(fd, packet_len(0x226));
  10595. }
  10596. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  10597. /// 0224 <points>.L <total points>.L
  10598. void clif_fame_taekwon(struct map_session_data *sd, int points)
  10599. {
  10600. int fd = sd->fd;
  10601. WFIFOHEAD(fd,packet_len(0x224));
  10602. WFIFOW(fd,0) = 0x224;
  10603. WFIFOL(fd,2) = points;
  10604. WFIFOL(fd,6) = sd->status.fame;
  10605. WFIFOSET(fd, packet_len(0x224));
  10606. }
  10607. /// /pk (CZ_KILLER_RANK).
  10608. /// 0237
  10609. /// /pk list (ZC_KILLER_RANK).
  10610. /// 0238 { <name>.24B }*10 { <point>.L }*10
  10611. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10612. {
  10613. int i;
  10614. WFIFOHEAD(fd,packet_len(0x238));
  10615. WFIFOW(fd,0) = 0x238;
  10616. for(i=0;i<10;i++){
  10617. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10618. WFIFOL(fd,i*4+242) = 0;
  10619. }
  10620. WFIFOSET(fd, packet_len(0x238));
  10621. }
  10622. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  10623. /// 0254 <which>.B
  10624. /// which:
  10625. /// 0 = sun
  10626. /// 1 = moon
  10627. /// 2 = star
  10628. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10629. {
  10630. int i;
  10631. if (sd->menuskill_id != SG_FEEL)
  10632. return;
  10633. i = sd->menuskill_val-1;
  10634. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  10635. sd->feel_map[i].index = map_id2index(sd->bl.m);
  10636. sd->feel_map[i].m = sd->bl.m;
  10637. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  10638. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10639. // clif_misceffect2(&sd->bl, 0x1b0);
  10640. // clif_misceffect2(&sd->bl, 0x21f);
  10641. clif_feel_info(sd, i, 0);
  10642. sd->menuskill_val = sd->menuskill_id = 0;
  10643. }
  10644. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  10645. /// 0253 <which>.B
  10646. /// which:
  10647. /// 0 = sun
  10648. /// 1 = moon
  10649. /// 2 = star
  10650. void clif_feel_req(int fd, struct map_session_data *sd, int skilllv)
  10651. {
  10652. WFIFOHEAD(fd,packet_len(0x253));
  10653. WFIFOW(fd,0)=0x253;
  10654. WFIFOB(fd,2)=TOB(skilllv-1);
  10655. WFIFOSET(fd, packet_len(0x253));
  10656. sd->menuskill_id = SG_FEEL;
  10657. sd->menuskill_val = skilllv;
  10658. }
  10659. /// Request to change homunculus' name (CZ_RENAME_MER).
  10660. /// 0231 <name>.24B
  10661. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  10662. {
  10663. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  10664. }
  10665. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  10666. /// 0234 <id>.L
  10667. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  10668. {
  10669. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10670. struct block_list *bl = NULL;
  10671. struct unit_data *ud = NULL;
  10672. if( sd->md && sd->md->bl.id == id )
  10673. bl = &sd->md->bl;
  10674. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10675. bl = &sd->hd->bl; // Moving Homunculus
  10676. else
  10677. return;
  10678. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  10679. ud = unit_bl2ud(bl);
  10680. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  10681. }
  10682. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  10683. /// 0232 <id>.L <position data>.3B
  10684. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  10685. {
  10686. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10687. struct block_list *bl = NULL;
  10688. short x, y;
  10689. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  10690. if( sd->md && sd->md->bl.id == id )
  10691. bl = &sd->md->bl; // Moving Mercenary
  10692. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10693. bl = &sd->hd->bl; // Moving Homunculus
  10694. else
  10695. return;
  10696. unit_walktoxy(bl, x, y, 4);
  10697. }
  10698. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  10699. /// 0233 <id>.L <target id>.L <action>.B
  10700. /// action:
  10701. /// always 0
  10702. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  10703. {
  10704. struct block_list *bl = NULL;
  10705. int id = RFIFOL(fd,2),
  10706. target_id = RFIFOL(fd,6),
  10707. action_type = RFIFOB(fd,10);
  10708. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10709. bl = &sd->hd->bl;
  10710. else if( sd->md && sd->md->bl.id == id )
  10711. bl = &sd->md->bl;
  10712. else return;
  10713. unit_stop_attack(bl);
  10714. unit_attack(bl, target_id, action_type != 0);
  10715. }
  10716. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  10717. /// 022d <type>.W <command>.B
  10718. /// type:
  10719. /// always 0
  10720. /// command:
  10721. /// 0 = homunculus information
  10722. /// 1 = feed
  10723. /// 2 = delete
  10724. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  10725. { //[orn]
  10726. int cmd;
  10727. cmd = RFIFOW(fd,0);
  10728. if(!merc_is_hom_active(sd->hd))
  10729. return;
  10730. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  10731. }
  10732. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  10733. /// 0292
  10734. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  10735. {
  10736. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  10737. if (item_position < 0)
  10738. return;
  10739. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  10740. return;
  10741. if (!status_revive(&sd->bl, 100, 100))
  10742. return;
  10743. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  10744. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  10745. }
  10746. /// Information about character's status values (ZC_ACK_STATUS_GM).
  10747. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  10748. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  10749. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  10750. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  10751. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  10752. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  10753. void clif_check(int fd, struct map_session_data* pl_sd)
  10754. {
  10755. WFIFOHEAD(fd,packet_len(0x214));
  10756. WFIFOW(fd, 0) = 0x214;
  10757. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  10758. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  10759. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  10760. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  10761. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  10762. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  10763. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  10764. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  10765. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  10766. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  10767. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  10768. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  10769. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  10770. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  10771. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  10772. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  10773. WFIFOW(fd,22) = pl_sd->battle_status.def;
  10774. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  10775. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  10776. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  10777. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  10778. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  10779. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  10780. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  10781. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  10782. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be?
  10783. WFIFOSET(fd,packet_len(0x214));
  10784. }
  10785. /// /check (CZ_REQ_STATUS_GM).
  10786. /// Request character's status values.
  10787. /// 0213 <char name>.24B
  10788. void clif_parse_Check(int fd, struct map_session_data *sd)
  10789. {
  10790. char charname[NAME_LENGTH];
  10791. struct map_session_data* pl_sd;
  10792. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  10793. return;
  10794. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  10795. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  10796. {
  10797. return;
  10798. }
  10799. clif_check(fd, pl_sd);
  10800. }
  10801. /// MAIL SYSTEM
  10802. /// By Zephyrus
  10803. ///
  10804. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  10805. /// 0255 <index>.W <result>.B
  10806. /// result:
  10807. /// 0 = success
  10808. /// 1 = failure
  10809. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  10810. {
  10811. WFIFOHEAD(fd,packet_len(0x255));
  10812. WFIFOW(fd,0) = 0x255;
  10813. WFIFOW(fd,2) = index;
  10814. WFIFOB(fd,4) = flag;
  10815. WFIFOSET(fd,packet_len(0x255));
  10816. }
  10817. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  10818. /// 0245 <result>.B
  10819. /// result:
  10820. /// 0 = success
  10821. /// 1 = failure
  10822. /// 2 = too many items
  10823. void clif_Mail_getattachment(int fd, uint8 flag)
  10824. {
  10825. WFIFOHEAD(fd,packet_len(0x245));
  10826. WFIFOW(fd,0) = 0x245;
  10827. WFIFOB(fd,2) = flag;
  10828. WFIFOSET(fd,packet_len(0x245));
  10829. }
  10830. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  10831. /// 0249 <result>.B
  10832. /// result:
  10833. /// 0 = success
  10834. /// 1 = recipinent does not exist
  10835. void clif_Mail_send(int fd, bool fail)
  10836. {
  10837. WFIFOHEAD(fd,packet_len(0x249));
  10838. WFIFOW(fd,0) = 0x249;
  10839. WFIFOB(fd,2) = fail;
  10840. WFIFOSET(fd,packet_len(0x249));
  10841. }
  10842. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  10843. /// 0257 <mail id>.L <result>.W
  10844. /// result:
  10845. /// 0 = success
  10846. /// 1 = failure
  10847. void clif_Mail_delete(int fd, int mail_id, short fail)
  10848. {
  10849. WFIFOHEAD(fd, packet_len(0x257));
  10850. WFIFOW(fd,0) = 0x257;
  10851. WFIFOL(fd,2) = mail_id;
  10852. WFIFOW(fd,6) = fail;
  10853. WFIFOSET(fd, packet_len(0x257));
  10854. }
  10855. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  10856. /// 0274 <mail id>.L <result>.W
  10857. /// result:
  10858. /// 0 = success
  10859. /// 1 = failure
  10860. void clif_Mail_return(int fd, int mail_id, short fail)
  10861. {
  10862. WFIFOHEAD(fd,packet_len(0x274));
  10863. WFIFOW(fd,0) = 0x274;
  10864. WFIFOL(fd,2) = mail_id;
  10865. WFIFOW(fd,6) = fail;
  10866. WFIFOSET(fd,packet_len(0x274));
  10867. }
  10868. /// Notification about new mail (ZC_MAIL_RECEIVE).
  10869. /// 024a <mail id>.L <title>.40B <sender>.24B
  10870. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10871. {
  10872. WFIFOHEAD(fd,packet_len(0x24a));
  10873. WFIFOW(fd,0) = 0x24a;
  10874. WFIFOL(fd,2) = mail_id;
  10875. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  10876. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  10877. WFIFOSET(fd,packet_len(0x24a));
  10878. }
  10879. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  10880. /// 0260 <type>.L
  10881. /// type:
  10882. /// 0 = open
  10883. /// 1 = close
  10884. void clif_Mail_window(int fd, int flag)
  10885. {
  10886. WFIFOHEAD(fd,packet_len(0x260));
  10887. WFIFOW(fd,0) = 0x260;
  10888. WFIFOL(fd,2) = flag;
  10889. WFIFOSET(fd,packet_len(0x260));
  10890. }
  10891. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  10892. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  10893. /// read:
  10894. /// 0 = unread
  10895. /// 1 = read
  10896. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10897. {
  10898. int fd = sd->fd;
  10899. struct mail_data *md = &sd->mail.inbox;
  10900. struct mail_message *msg;
  10901. int len, i, j;
  10902. len = 8 + (73 * md->amount);
  10903. WFIFOHEAD(fd,len);
  10904. WFIFOW(fd,0) = 0x240;
  10905. WFIFOW(fd,2) = len;
  10906. WFIFOL(fd,4) = md->amount;
  10907. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10908. {
  10909. msg = &md->msg[i];
  10910. if (msg->id < 1)
  10911. continue;
  10912. WFIFOL(fd,8+73*j) = msg->id;
  10913. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10914. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  10915. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10916. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10917. j++;
  10918. }
  10919. WFIFOSET(fd,len);
  10920. if( md->full )
  10921. {// TODO: is this official?
  10922. char output[100];
  10923. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10924. clif_disp_onlyself(sd, output, strlen(output));
  10925. }
  10926. }
  10927. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  10928. /// 023f
  10929. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10930. {
  10931. struct mail_data* md = &sd->mail.inbox;
  10932. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10933. intif_Mail_requestinbox(sd->status.char_id, 1);
  10934. else
  10935. clif_Mail_refreshinbox(sd);
  10936. mail_removeitem(sd, 0);
  10937. mail_removezeny(sd, 0);
  10938. }
  10939. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  10940. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  10941. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  10942. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  10943. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10944. {
  10945. int i, fd = sd->fd;
  10946. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10947. if( i == MAIL_MAX_INBOX )
  10948. {
  10949. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10950. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10951. return;
  10952. }
  10953. else
  10954. {
  10955. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10956. struct item *item = &msg->item;
  10957. struct item_data *data;
  10958. int msg_len = strlen(msg->body), len;
  10959. if( msg_len == 0 ) {
  10960. strcpy(msg->body, "(no message)");
  10961. msg_len = strlen(msg->body);
  10962. }
  10963. len = 101 + msg_len;
  10964. WFIFOHEAD(fd,len);
  10965. WFIFOW(fd,0) = 0x242;
  10966. WFIFOW(fd,2) = len;
  10967. WFIFOL(fd,4) = msg->id;
  10968. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10969. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10970. WFIFOL(fd,72) = 0;
  10971. WFIFOL(fd,76) = msg->zeny;
  10972. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  10973. {
  10974. WFIFOL(fd,80) = item->amount;
  10975. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10976. WFIFOW(fd,86) = data->type;
  10977. WFIFOB(fd,88) = item->identify;
  10978. WFIFOB(fd,89) = item->attribute;
  10979. WFIFOB(fd,90) = item->refine;
  10980. WFIFOW(fd,91) = item->card[0];
  10981. WFIFOW(fd,93) = item->card[1];
  10982. WFIFOW(fd,95) = item->card[2];
  10983. WFIFOW(fd,97) = item->card[3];
  10984. }
  10985. else // no item, set all to zero
  10986. memset(WFIFOP(fd,80), 0x00, 19);
  10987. WFIFOB(fd,99) = (unsigned char)msg_len;
  10988. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10989. WFIFOSET(fd,len);
  10990. if (msg->status == MAIL_UNREAD) {
  10991. msg->status = MAIL_READ;
  10992. intif_Mail_read(mail_id);
  10993. clif_parse_Mail_refreshinbox(fd, sd);
  10994. }
  10995. }
  10996. }
  10997. /// Request to open a mail (CZ_MAIL_OPEN).
  10998. /// 0241 <mail id>.L
  10999. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11000. {
  11001. int mail_id = RFIFOL(fd,2);
  11002. if( mail_id <= 0 )
  11003. return;
  11004. if( mail_invalid_operation(sd) )
  11005. return;
  11006. clif_Mail_read(sd, RFIFOL(fd,2));
  11007. }
  11008. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11009. /// 0244 <mail id>.L
  11010. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11011. {
  11012. int mail_id = RFIFOL(fd,2);
  11013. int i;
  11014. bool fail = false;
  11015. if( mail_id <= 0 )
  11016. return;
  11017. if( mail_invalid_operation(sd) )
  11018. return;
  11019. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11020. if( i == MAIL_MAX_INBOX )
  11021. return;
  11022. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11023. return;
  11024. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY )
  11025. {
  11026. clif_Mail_getattachment(fd, 1);
  11027. return;
  11028. }
  11029. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11030. {
  11031. struct item_data *data;
  11032. unsigned int weight;
  11033. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11034. return;
  11035. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11036. {
  11037. case ADDITEM_NEW:
  11038. fail = ( pc_inventoryblank(sd) == 0 );
  11039. break;
  11040. case ADDITEM_OVERAMOUNT:
  11041. fail = true;
  11042. }
  11043. if( fail )
  11044. {
  11045. clif_Mail_getattachment(fd, 1);
  11046. return;
  11047. }
  11048. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11049. if( sd->weight + weight > sd->max_weight )
  11050. {
  11051. clif_Mail_getattachment(fd, 2);
  11052. return;
  11053. }
  11054. }
  11055. sd->mail.inbox.msg[i].zeny = 0;
  11056. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11057. clif_Mail_read(sd, mail_id);
  11058. intif_Mail_getattach(sd->status.char_id, mail_id);
  11059. }
  11060. /// Request to delete a mail (CZ_MAIL_DELETE).
  11061. /// 0243 <mail id>.L
  11062. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11063. {
  11064. int mail_id = RFIFOL(fd,2);
  11065. int i;
  11066. if( mail_id <= 0 )
  11067. return;
  11068. if( mail_invalid_operation(sd) )
  11069. return;
  11070. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11071. if (i < MAIL_MAX_INBOX)
  11072. {
  11073. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11074. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11075. {// can't delete mail without removing attachment first
  11076. clif_Mail_delete(sd->fd, mail_id, 1);
  11077. return;
  11078. }
  11079. intif_Mail_delete(sd->status.char_id, mail_id);
  11080. }
  11081. }
  11082. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11083. /// 0273 <mail id>.L <receive name>.24B
  11084. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11085. {
  11086. int mail_id = RFIFOL(fd,2);
  11087. int i;
  11088. if( mail_id <= 0 )
  11089. return;
  11090. if( mail_invalid_operation(sd) )
  11091. return;
  11092. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11093. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11094. intif_Mail_return(sd->status.char_id, mail_id);
  11095. else
  11096. clif_Mail_return(sd->fd, mail_id, 1);
  11097. }
  11098. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11099. /// 0247 <index>.W <amount>.L
  11100. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11101. {
  11102. int idx = RFIFOW(fd,2);
  11103. int amount = RFIFOL(fd,4);
  11104. unsigned char flag;
  11105. if (idx < 0 || amount < 0)
  11106. return;
  11107. flag = mail_setitem(sd, idx, amount);
  11108. clif_Mail_setattachment(fd,idx,flag);
  11109. }
  11110. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11111. /// 0246 <type>.W
  11112. /// type:
  11113. /// 0 = reset all
  11114. /// 1 = remove item
  11115. /// 2 = remove zeny
  11116. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11117. {
  11118. int flag = RFIFOW(fd,2);
  11119. if (flag == 0 || flag == 1)
  11120. mail_removeitem(sd, 0);
  11121. if (flag == 0 || flag == 2)
  11122. mail_removezeny(sd, 0);
  11123. }
  11124. /// Request to send mail (CZ_MAIL_SEND).
  11125. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11126. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11127. {
  11128. struct mail_message msg;
  11129. int body_len;
  11130. if( sd->state.trading )
  11131. return;
  11132. if( RFIFOW(fd,2) < 69 ) {
  11133. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11134. return;
  11135. }
  11136. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11137. {
  11138. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11139. clif_Mail_send(fd, true); // fail
  11140. return;
  11141. }
  11142. body_len = RFIFOB(fd,68);
  11143. if (body_len > MAIL_BODY_LENGTH)
  11144. body_len = MAIL_BODY_LENGTH;
  11145. if( !mail_setattachment(sd, &msg) )
  11146. { // Invalid Append condition
  11147. clif_Mail_send(sd->fd, true); // fail
  11148. mail_removeitem(sd,0);
  11149. mail_removezeny(sd,0);
  11150. return;
  11151. }
  11152. msg.id = 0; // id will be assigned by charserver
  11153. msg.send_id = sd->status.char_id;
  11154. msg.dest_id = 0; // will attempt to resolve name
  11155. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11156. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11157. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11158. if (body_len)
  11159. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11160. else
  11161. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11162. msg.timestamp = time(NULL);
  11163. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11164. mail_deliveryfail(sd, &msg);
  11165. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11166. }
  11167. /// AUCTION SYSTEM
  11168. /// By Zephyrus
  11169. ///
  11170. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11171. /// 025f <type>.L
  11172. /// type:
  11173. /// 0 = open
  11174. /// 1 = close
  11175. void clif_Auction_openwindow(struct map_session_data *sd)
  11176. {
  11177. int fd = sd->fd;
  11178. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11179. return;
  11180. WFIFOHEAD(fd,packet_len(0x25f));
  11181. WFIFOW(fd,0) = 0x25f;
  11182. WFIFOL(fd,2) = 0;
  11183. WFIFOSET(fd,packet_len(0x25f));
  11184. }
  11185. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11186. /// 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 }*
  11187. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11188. {
  11189. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11190. struct auction_data auction;
  11191. struct item_data *item;
  11192. int k;
  11193. WFIFOHEAD(fd,12 + (count * 83));
  11194. WFIFOW(fd,0) = 0x252;
  11195. WFIFOW(fd,2) = 12 + (count * 83);
  11196. WFIFOL(fd,4) = pages;
  11197. WFIFOL(fd,8) = count;
  11198. for( i = 0; i < count; i++ )
  11199. {
  11200. memcpy(&auction, RBUFP(buf,i * len), len);
  11201. k = 12 + (i * 83);
  11202. WFIFOL(fd,k) = auction.auction_id;
  11203. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11204. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11205. WFIFOW(fd,28+k) = item->view_id;
  11206. else
  11207. WFIFOW(fd,28+k) = auction.item.nameid;
  11208. WFIFOL(fd,30+k) = auction.type;
  11209. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11210. WFIFOB(fd,36+k) = auction.item.identify;
  11211. WFIFOB(fd,37+k) = auction.item.attribute;
  11212. WFIFOB(fd,38+k) = auction.item.refine;
  11213. WFIFOW(fd,39+k) = auction.item.card[0];
  11214. WFIFOW(fd,41+k) = auction.item.card[1];
  11215. WFIFOW(fd,43+k) = auction.item.card[2];
  11216. WFIFOW(fd,45+k) = auction.item.card[3];
  11217. WFIFOL(fd,47+k) = auction.price;
  11218. WFIFOL(fd,51+k) = auction.buynow;
  11219. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11220. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11221. }
  11222. WFIFOSET(fd,WFIFOW(fd,2));
  11223. }
  11224. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11225. /// 0256 <index>.W <result>.B
  11226. /// result:
  11227. /// 0 = success
  11228. /// 1 = failure
  11229. static void clif_Auction_setitem(int fd, int index, bool fail)
  11230. {
  11231. WFIFOHEAD(fd,packet_len(0x256));
  11232. WFIFOW(fd,0) = 0x256;
  11233. WFIFOW(fd,2) = index;
  11234. WFIFOB(fd,4) = fail;
  11235. WFIFOSET(fd,packet_len(0x256));
  11236. }
  11237. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11238. /// 024b <type>.W
  11239. /// type:
  11240. /// 0 = create (any other action in auction window)
  11241. /// 1 = cancel (cancel pressed on register tab)
  11242. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11243. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11244. {
  11245. if( sd->auction.amount > 0 )
  11246. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11247. sd->auction.amount = 0;
  11248. }
  11249. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11250. /// 024c <index>.W <count>.L
  11251. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11252. {
  11253. int idx = RFIFOW(fd,2) - 2;
  11254. int amount = RFIFOL(fd,4); // Always 1
  11255. struct item_data *item;
  11256. if( sd->auction.amount > 0 )
  11257. sd->auction.amount = 0;
  11258. if( idx < 0 || idx >= MAX_INVENTORY )
  11259. {
  11260. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11261. return;
  11262. }
  11263. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11264. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11265. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11266. return;
  11267. }
  11268. 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) )
  11269. { // Consumable or pets are not allowed
  11270. clif_Auction_setitem(sd->fd, idx, true);
  11271. return;
  11272. }
  11273. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11274. !sd->status.inventory[idx].identify ||
  11275. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11276. clif_Auction_setitem(sd->fd, idx, true);
  11277. return;
  11278. }
  11279. sd->auction.index = idx;
  11280. sd->auction.amount = amount;
  11281. clif_Auction_setitem(fd, idx + 2, false);
  11282. }
  11283. /// Result from an auction action (ZC_AUCTION_RESULT).
  11284. /// 0250 <result>.B
  11285. /// result:
  11286. /// 0 = You have failed to bid into the auction
  11287. /// 1 = You have successfully bid in the auction
  11288. /// 2 = The auction has been canceled
  11289. /// 3 = An auction with at least one bidder cannot be canceled
  11290. /// 4 = You cannot register more than 5 items in an auction at a time
  11291. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11292. /// 6 = You have won the auction
  11293. /// 7 = You have failed to win the auction
  11294. /// 8 = You do not have enough Zeny
  11295. /// 9 = You cannot place more than 5 bids at a time
  11296. void clif_Auction_message(int fd, unsigned char flag)
  11297. {
  11298. WFIFOHEAD(fd,packet_len(0x250));
  11299. WFIFOW(fd,0) = 0x250;
  11300. WFIFOB(fd,2) = flag;
  11301. WFIFOSET(fd,packet_len(0x250));
  11302. }
  11303. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11304. /// 025e <result>.W
  11305. /// result:
  11306. /// 0 = You have ended the auction
  11307. /// 1 = You cannot end the auction
  11308. /// 2 = Auction ID is incorrect
  11309. void clif_Auction_close(int fd, unsigned char flag)
  11310. {
  11311. WFIFOHEAD(fd,packet_len(0x25e));
  11312. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11313. WFIFOW(fd,2) = flag;
  11314. WFIFOSET(fd,packet_len(0x25e));
  11315. }
  11316. /// Request to add an auction (CZ_AUCTION_ADD).
  11317. /// 024d <now money>.L <max money>.L <delete hour>.W
  11318. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11319. {
  11320. struct auction_data auction;
  11321. struct item_data *item;
  11322. auction.price = RFIFOL(fd,2);
  11323. auction.buynow = RFIFOL(fd,6);
  11324. auction.hours = RFIFOW(fd,10);
  11325. // Invalid Situations...
  11326. if( sd->auction.amount < 1 )
  11327. {
  11328. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11329. return;
  11330. }
  11331. if( auction.price >= auction.buynow )
  11332. {
  11333. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11334. return;
  11335. }
  11336. if( auction.hours < 1 || auction.hours > 48 )
  11337. {
  11338. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11339. return;
  11340. }
  11341. // Auction checks...
  11342. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11343. {
  11344. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11345. return;
  11346. }
  11347. if( auction.buynow > battle_config.auction_maximumprice )
  11348. { // Zeny Limits
  11349. auction.buynow = battle_config.auction_maximumprice;
  11350. if( auction.price >= auction.buynow )
  11351. auction.price = auction.buynow - 1;
  11352. }
  11353. auction.auction_id = 0;
  11354. auction.seller_id = sd->status.char_id;
  11355. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11356. auction.buyer_id = 0;
  11357. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11358. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11359. {
  11360. clif_Auction_message(fd, 2); // The auction has been canceled
  11361. return;
  11362. }
  11363. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11364. { // Just in case
  11365. clif_Auction_message(fd, 2); // The auction has been canceled
  11366. return;
  11367. }
  11368. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11369. auction.type = item->type;
  11370. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11371. auction.item.amount = 1;
  11372. auction.timestamp = 0;
  11373. if( !intif_Auction_register(&auction) )
  11374. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11375. else
  11376. {
  11377. int zeny = auction.hours*battle_config.auction_feeperhour;
  11378. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11379. sd->auction.amount = 0;
  11380. log_zeny(sd, LOG_TYPE_AUCTION, sd, -zeny);
  11381. pc_payzeny(sd, zeny);
  11382. }
  11383. }
  11384. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11385. /// 024e <auction id>.L
  11386. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11387. {
  11388. unsigned int auction_id = RFIFOL(fd,2);
  11389. intif_Auction_cancel(sd->status.char_id, auction_id);
  11390. }
  11391. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11392. /// 025d <auction id>.L
  11393. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11394. {
  11395. unsigned int auction_id = RFIFOL(fd,2);
  11396. intif_Auction_close(sd->status.char_id, auction_id);
  11397. }
  11398. /// Places a bid on an auction (CZ_AUCTION_BUY).
  11399. /// 024f <auction id>.L <money>.L
  11400. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11401. {
  11402. unsigned int auction_id = RFIFOL(fd,2);
  11403. int bid = RFIFOL(fd,6);
  11404. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  11405. clif_displaymessage(sd->fd, msg_txt(246));
  11406. return;
  11407. }
  11408. if( bid <= 0 )
  11409. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11410. else if( bid > sd->status.zeny )
  11411. clif_Auction_message(fd, 8); // You do not have enough zeny
  11412. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  11413. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11414. else {
  11415. log_zeny(sd, LOG_TYPE_AUCTION, sd, -bid);
  11416. pc_payzeny(sd, bid);
  11417. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11418. }
  11419. }
  11420. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  11421. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  11422. /// search type:
  11423. /// 0 = armor
  11424. /// 1 = weapon
  11425. /// 2 = card
  11426. /// 3 = misc
  11427. /// 4 = name search
  11428. /// 5 = auction id search
  11429. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11430. {
  11431. char search_text[NAME_LENGTH];
  11432. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11433. int price = RFIFOL(fd,4); // FIXME: bug #5071
  11434. clif_parse_Auction_cancelreg(fd, sd);
  11435. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  11436. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11437. }
  11438. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  11439. /// 025c <type>.W
  11440. /// type:
  11441. /// 0 = sell (own auctions)
  11442. /// 1 = buy (own bids)
  11443. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11444. {
  11445. short type = RFIFOW(fd,2) + 6;
  11446. clif_parse_Auction_cancelreg(fd, sd);
  11447. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11448. }
  11449. /// CASH/POINT SHOP
  11450. ///
  11451. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  11452. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  11453. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  11454. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11455. {
  11456. int fd,i;
  11457. const int offset = 12;
  11458. nullpo_retv(sd);
  11459. nullpo_retv(nd);
  11460. fd = sd->fd;
  11461. sd->npc_shopid = nd->bl.id;
  11462. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  11463. WFIFOW(fd,0) = 0x287;
  11464. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  11465. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11466. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11467. for( i = 0; i < nd->u.shop.count; i++ )
  11468. {
  11469. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11470. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  11471. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  11472. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  11473. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11474. }
  11475. WFIFOSET(fd,WFIFOW(fd,2));
  11476. }
  11477. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  11478. /// 0289 <cash point>.L <error>.W
  11479. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  11480. /// error:
  11481. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  11482. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11483. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11484. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11485. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11486. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11487. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11488. /// 7 = You can purchase up to 10 items.
  11489. /// 8 = Some items could not be purchased.
  11490. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11491. {
  11492. int fd = sd->fd;
  11493. WFIFOHEAD(fd, packet_len(0x289));
  11494. WFIFOW(fd,0) = 0x289;
  11495. WFIFOL(fd,2) = sd->cashPoints;
  11496. WFIFOL(fd,6) = sd->kafraPoints;
  11497. WFIFOW(fd,10) = TOW(error);
  11498. WFIFOSET(fd, packet_len(0x289));
  11499. }
  11500. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  11501. /// 0288 <name id>.W <amount>.W
  11502. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  11503. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  11504. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11505. {
  11506. int fail = 0;
  11507. nullpo_retv(sd);
  11508. if( sd->state.trading || !sd->npc_shopid )
  11509. fail = 1;
  11510. else
  11511. {
  11512. #if PACKETVER < 20101116
  11513. short nameid = RFIFOW(fd,2);
  11514. short amount = RFIFOW(fd,4);
  11515. int points = RFIFOL(fd,6);
  11516. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11517. #else
  11518. int len = RFIFOW(fd,2);
  11519. int points = RFIFOL(fd,4);
  11520. int count = RFIFOW(fd,8);
  11521. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  11522. if( len < 10 || len != 10 + count * 4)
  11523. {
  11524. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  11525. return;
  11526. }
  11527. fail = npc_cashshop_buylist(sd,points,count,item_list);
  11528. #endif
  11529. }
  11530. clif_cashshop_ack(sd,fail);
  11531. }
  11532. /// Adoption System
  11533. ///
  11534. /// Adoption message (ZC_BABYMSG).
  11535. /// 0216 <msg>.L
  11536. /// msg:
  11537. /// 0 = "You cannot adopt more than 1 child."
  11538. /// 1 = "You must be at least character level 70 in order to adopt someone."
  11539. /// 2 = "You cannot adopt a married person."
  11540. void clif_Adopt_reply(struct map_session_data *sd, int type)
  11541. {
  11542. int fd = sd->fd;
  11543. WFIFOHEAD(fd,6);
  11544. WFIFOW(fd,0) = 0x216;
  11545. WFIFOL(fd,2) = type;
  11546. WFIFOSET(fd,6);
  11547. }
  11548. /// Adoption confirmation (ZC_REQ_BABY).
  11549. /// 01f6 <account id>.L <char id>.L <name>.B
  11550. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  11551. {
  11552. int fd = sd->fd;
  11553. WFIFOHEAD(fd,34);
  11554. WFIFOW(fd,0) = 0x1f6;
  11555. WFIFOL(fd,2) = src->status.account_id;
  11556. WFIFOL(fd,6) = p_id;
  11557. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  11558. WFIFOSET(fd,34);
  11559. }
  11560. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  11561. /// 01f9 <account id>.L
  11562. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  11563. {
  11564. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  11565. if( pc_can_Adopt(sd, p_sd, tsd) )
  11566. {
  11567. tsd->adopt_invite = sd->status.account_id;
  11568. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  11569. }
  11570. }
  11571. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  11572. /// 01f7 <account id>.L <char id>.L <answer>.L
  11573. /// answer:
  11574. /// 0 = rejected
  11575. /// 1 = accepted
  11576. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  11577. {
  11578. int p1_id = RFIFOL(fd,2);
  11579. int p2_id = RFIFOL(fd,6);
  11580. int result = RFIFOL(fd,10);
  11581. struct map_session_data* p1_sd = map_id2sd(p1_id);
  11582. struct map_session_data* p2_sd = map_id2sd(p2_id);
  11583. int pid = sd->adopt_invite;
  11584. sd->adopt_invite = 0;
  11585. if( p1_sd == NULL || p2_sd == NULL )
  11586. return; // Both players need to be online
  11587. if( pid != p1_sd->status.account_id )
  11588. return; // Incorrect values
  11589. if( result == 0 )
  11590. return; // Rejected
  11591. pc_adoption(p1_sd, p2_sd, sd);
  11592. }
  11593. /// Convex Mirror (ZC_BOSS_INFO).
  11594. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  11595. /// infoType:
  11596. /// 0 = No boss on this map (BOSS_INFO_NOT).
  11597. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  11598. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  11599. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  11600. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  11601. {
  11602. WFIFOHEAD(fd,70);
  11603. memset(WFIFOP(fd,0),0,70);
  11604. WFIFOW(fd,0) = 0x293;
  11605. if( md != NULL )
  11606. {
  11607. if( md->bl.prev != NULL )
  11608. { // Boss on This Map
  11609. if( flag )
  11610. {
  11611. WFIFOB(fd,2) = 1;
  11612. WFIFOL(fd,3) = md->bl.x;
  11613. WFIFOL(fd,7) = md->bl.y;
  11614. }
  11615. else
  11616. WFIFOB(fd,2) = 2; // First Time
  11617. }
  11618. else if (md->spawn_timer != INVALID_TIMER)
  11619. { // Boss is Dead
  11620. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  11621. unsigned int seconds;
  11622. int hours, minutes;
  11623. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  11624. hours = seconds / (60 * 60);
  11625. seconds = seconds - (60 * 60 * hours);
  11626. minutes = seconds / 60;
  11627. WFIFOB(fd,2) = 3;
  11628. WFIFOW(fd,11) = hours; // Hours
  11629. WFIFOW(fd,13) = minutes; // Minutes
  11630. }
  11631. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  11632. }
  11633. WFIFOSET(fd,70);
  11634. }
  11635. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  11636. /// 02d6 <account id>.L
  11637. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  11638. {
  11639. int charid = RFIFOL(fd, 2);
  11640. struct map_session_data* tsd = map_id2sd(charid);
  11641. if (!tsd)
  11642. return;
  11643. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  11644. clif_viewequip_ack(sd, tsd);
  11645. else
  11646. clif_viewequip_fail(sd);
  11647. }
  11648. /// Request to change equip window tick (CZ_CONFIG).
  11649. /// 02d8 <type>.L <value>.L
  11650. /// type:
  11651. /// 0 = open equip window
  11652. /// value:
  11653. /// 0 = disabled
  11654. /// 1 = enabled
  11655. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  11656. {
  11657. bool flag = (bool)RFIFOL(fd,6);
  11658. sd->status.show_equip = flag;
  11659. clif_equiptickack(sd, flag);
  11660. }
  11661. /// Questlog System [Kevin] [Inkfish]
  11662. ///
  11663. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  11664. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  11665. void clif_quest_send_list(struct map_session_data * sd)
  11666. {
  11667. int fd = sd->fd;
  11668. int i;
  11669. int len = sd->avail_quests*5+8;
  11670. WFIFOHEAD(fd,len);
  11671. WFIFOW(fd, 0) = 0x2b1;
  11672. WFIFOW(fd, 2) = len;
  11673. WFIFOL(fd, 4) = sd->avail_quests;
  11674. for( i = 0; i < sd->avail_quests; i++ )
  11675. {
  11676. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  11677. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  11678. }
  11679. WFIFOSET(fd, len);
  11680. }
  11681. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  11682. /// 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
  11683. void clif_quest_send_mission(struct map_session_data * sd)
  11684. {
  11685. int fd = sd->fd;
  11686. int i, j;
  11687. int len = sd->avail_quests*104+8;
  11688. struct mob_db *mob;
  11689. WFIFOHEAD(fd, len);
  11690. WFIFOW(fd, 0) = 0x2b2;
  11691. WFIFOW(fd, 2) = len;
  11692. WFIFOL(fd, 4) = sd->avail_quests;
  11693. for( i = 0; i < sd->avail_quests; i++ )
  11694. {
  11695. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  11696. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  11697. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  11698. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  11699. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  11700. {
  11701. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  11702. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  11703. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  11704. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  11705. }
  11706. }
  11707. WFIFOSET(fd, len);
  11708. }
  11709. /// Notification about a new quest (ZC_ADD_QUEST).
  11710. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  11711. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  11712. {
  11713. int fd = sd->fd;
  11714. int i;
  11715. struct mob_db *mob;
  11716. WFIFOHEAD(fd, packet_len(0x2b3));
  11717. WFIFOW(fd, 0) = 0x2b3;
  11718. WFIFOL(fd, 2) = qd->quest_id;
  11719. WFIFOB(fd, 6) = qd->state;
  11720. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  11721. WFIFOL(fd, 11) = qd->time;
  11722. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  11723. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11724. {
  11725. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  11726. WFIFOW(fd, i*30+21) = qd->count[i];
  11727. mob = mob_db(quest_db[index].mob[i]);
  11728. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  11729. }
  11730. WFIFOSET(fd, packet_len(0x2b3));
  11731. }
  11732. /// Notification about a quest being removed (ZC_DEL_QUEST).
  11733. /// 02b4 <quest id>.L
  11734. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  11735. {
  11736. int fd = sd->fd;
  11737. WFIFOHEAD(fd, packet_len(0x2b4));
  11738. WFIFOW(fd, 0) = 0x2b4;
  11739. WFIFOL(fd, 2) = quest_id;
  11740. WFIFOSET(fd, packet_len(0x2b4));
  11741. }
  11742. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  11743. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  11744. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  11745. {
  11746. int fd = sd->fd;
  11747. int i;
  11748. int len = quest_db[index].num_objectives*12+6;
  11749. WFIFOHEAD(fd, len);
  11750. WFIFOW(fd, 0) = 0x2b5;
  11751. WFIFOW(fd, 2) = len;
  11752. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  11753. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11754. {
  11755. WFIFOL(fd, i*12+6) = qd->quest_id;
  11756. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  11757. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  11758. WFIFOW(fd, i*12+16) = qd->count[i];
  11759. }
  11760. WFIFOSET(fd, len);
  11761. }
  11762. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  11763. /// 02b6 <quest id>.L <active>.B
  11764. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  11765. {
  11766. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  11767. }
  11768. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  11769. /// 02b7 <quest id>.L <active>.B
  11770. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  11771. {
  11772. int fd = sd->fd;
  11773. WFIFOHEAD(fd, packet_len(0x2b7));
  11774. WFIFOW(fd, 0) = 0x2b7;
  11775. WFIFOL(fd, 2) = quest_id;
  11776. WFIFOB(fd, 6) = active;
  11777. WFIFOSET(fd, packet_len(0x2b7));
  11778. }
  11779. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  11780. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  11781. /// effect:
  11782. /// 0 = none
  11783. /// 1 = exclamation mark icon
  11784. /// 2 = question mark icon
  11785. /// type:
  11786. /// 0 = yellow
  11787. /// 1 = orange
  11788. /// 2 = green
  11789. /// 3 = purple
  11790. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  11791. {
  11792. int fd = sd->fd;
  11793. WFIFOHEAD(fd, packet_len(0x446));
  11794. WFIFOW(fd, 0) = 0x446;
  11795. WFIFOL(fd, 2) = bl->id;
  11796. WFIFOW(fd, 6) = bl->x;
  11797. WFIFOW(fd, 8) = bl->y;
  11798. WFIFOW(fd, 10) = state;
  11799. WFIFOW(fd, 12) = color;
  11800. WFIFOSET(fd, packet_len(0x446));
  11801. }
  11802. /// Mercenary System
  11803. ///
  11804. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  11805. /// 02a2 <var id>.W <value>.L
  11806. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  11807. {
  11808. struct mercenary_data *md;
  11809. struct status_data *status;
  11810. int fd;
  11811. if( sd == NULL || (md = sd->md) == NULL )
  11812. return;
  11813. fd = sd->fd;
  11814. status = &md->battle_status;
  11815. WFIFOHEAD(fd,packet_len(0x2a2));
  11816. WFIFOW(fd,0) = 0x2a2;
  11817. WFIFOW(fd,2) = type;
  11818. switch( type )
  11819. {
  11820. case SP_ATK1:
  11821. {
  11822. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11823. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  11824. }
  11825. break;
  11826. case SP_MATK1:
  11827. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  11828. break;
  11829. case SP_HIT:
  11830. WFIFOL(fd,4) = status->hit;
  11831. break;
  11832. case SP_CRITICAL:
  11833. WFIFOL(fd,4) = status->cri/10;
  11834. break;
  11835. case SP_DEF1:
  11836. WFIFOL(fd,4) = status->def;
  11837. break;
  11838. case SP_MDEF1:
  11839. WFIFOL(fd,4) = status->mdef;
  11840. break;
  11841. case SP_MERCFLEE:
  11842. WFIFOL(fd,4) = status->flee;
  11843. break;
  11844. case SP_ASPD:
  11845. WFIFOL(fd,4) = status->amotion;
  11846. break;
  11847. case SP_HP:
  11848. WFIFOL(fd,4) = status->hp;
  11849. break;
  11850. case SP_MAXHP:
  11851. WFIFOL(fd,4) = status->max_hp;
  11852. break;
  11853. case SP_SP:
  11854. WFIFOL(fd,4) = status->sp;
  11855. break;
  11856. case SP_MAXSP:
  11857. WFIFOL(fd,4) = status->max_sp;
  11858. break;
  11859. case SP_MERCKILLS:
  11860. WFIFOL(fd,4) = md->mercenary.kill_count;
  11861. break;
  11862. case SP_MERCFAITH:
  11863. WFIFOL(fd,4) = mercenary_get_faith(md);
  11864. break;
  11865. }
  11866. WFIFOSET(fd,packet_len(0x2a2));
  11867. }
  11868. /// Mercenary base status data (ZC_MER_INIT).
  11869. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  11870. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  11871. /// <calls>.L <kills>.L <atk range>.W
  11872. void clif_mercenary_info(struct map_session_data *sd)
  11873. {
  11874. int fd;
  11875. struct mercenary_data *md;
  11876. struct status_data *status;
  11877. int atk;
  11878. if( sd == NULL || (md = sd->md) == NULL )
  11879. return;
  11880. fd = sd->fd;
  11881. status = &md->battle_status;
  11882. WFIFOHEAD(fd,packet_len(0x29b));
  11883. WFIFOW(fd,0) = 0x29b;
  11884. WFIFOL(fd,2) = md->bl.id;
  11885. // Mercenary shows ATK as a random value between ATK ~ ATK2
  11886. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11887. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  11888. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  11889. WFIFOW(fd,10) = status->hit;
  11890. WFIFOW(fd,12) = status->cri/10;
  11891. WFIFOW(fd,14) = status->def;
  11892. WFIFOW(fd,16) = status->mdef;
  11893. WFIFOW(fd,18) = status->flee;
  11894. WFIFOW(fd,20) = status->amotion;
  11895. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  11896. WFIFOW(fd,46) = md->db->lv;
  11897. WFIFOL(fd,48) = status->hp;
  11898. WFIFOL(fd,52) = status->max_hp;
  11899. WFIFOL(fd,56) = status->sp;
  11900. WFIFOL(fd,60) = status->max_sp;
  11901. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  11902. WFIFOW(fd,68) = mercenary_get_faith(md);
  11903. WFIFOL(fd,70) = mercenary_get_calls(md);
  11904. WFIFOL(fd,74) = md->mercenary.kill_count;
  11905. WFIFOW(fd,78) = md->battle_status.rhw.range;
  11906. WFIFOSET(fd,packet_len(0x29b));
  11907. }
  11908. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  11909. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  11910. void clif_mercenary_skillblock(struct map_session_data *sd)
  11911. {
  11912. struct mercenary_data *md;
  11913. int fd, i, len = 4, id, j;
  11914. if( sd == NULL || (md = sd->md) == NULL )
  11915. return;
  11916. fd = sd->fd;
  11917. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  11918. WFIFOW(fd,0) = 0x29d;
  11919. for( i = 0; i < MAX_MERCSKILL; i++ )
  11920. {
  11921. if( (id = md->db->skill[i].id) == 0 )
  11922. continue;
  11923. j = id - MC_SKILLBASE;
  11924. WFIFOW(fd,len) = id;
  11925. WFIFOL(fd,len+2) = skill_get_inf(id);
  11926. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  11927. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  11928. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  11929. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  11930. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  11931. len += 37;
  11932. }
  11933. WFIFOW(fd,2) = len;
  11934. WFIFOSET(fd,len);
  11935. }
  11936. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  11937. /// 029f <command>.B
  11938. /// 1 = mercenary information
  11939. /// 2 = delete
  11940. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  11941. {
  11942. int option = RFIFOB(fd,2);
  11943. if( sd->md == NULL )
  11944. return;
  11945. if( option == 2 ) merc_delete(sd->md, 2);
  11946. }
  11947. /// Mercenary Message
  11948. /// message:
  11949. /// 0 = Mercenary soldier's duty hour is over.
  11950. /// 1 = Your mercenary soldier has been killed.
  11951. /// 2 = Your mercenary soldier has been fired.
  11952. /// 3 = Your mercenary soldier has ran away.
  11953. void clif_mercenary_message(struct map_session_data* sd, int message)
  11954. {
  11955. clif_msg(sd, 1266 + message);
  11956. }
  11957. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  11958. /// 0298 <name id>.W <seconds>.L
  11959. void clif_rental_time(int fd, int nameid, int seconds)
  11960. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  11961. WFIFOHEAD(fd,packet_len(0x298));
  11962. WFIFOW(fd,0) = 0x298;
  11963. WFIFOW(fd,2) = nameid;
  11964. WFIFOL(fd,4) = seconds;
  11965. WFIFOSET(fd,packet_len(0x298));
  11966. }
  11967. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  11968. /// 0299 <index>.W <name id>.W
  11969. void clif_rental_expired(int fd, int index, int nameid)
  11970. { // '<ItemName>' item has been deleted from the Inventory
  11971. WFIFOHEAD(fd,packet_len(0x299));
  11972. WFIFOW(fd,0) = 0x299;
  11973. WFIFOW(fd,2) = index+2;
  11974. WFIFOW(fd,4) = nameid;
  11975. WFIFOSET(fd,packet_len(0x299));
  11976. }
  11977. /// Book Reading (ZC_READ_BOOK).
  11978. /// 0294 <book id>.L <page>.L
  11979. void clif_readbook(int fd, int book_id, int page)
  11980. {
  11981. WFIFOHEAD(fd,packet_len(0x294));
  11982. WFIFOW(fd,0) = 0x294;
  11983. WFIFOL(fd,2) = book_id;
  11984. WFIFOL(fd,6) = page;
  11985. WFIFOSET(fd,packet_len(0x294));
  11986. }
  11987. /// Battlegrounds
  11988. ///
  11989. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  11990. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  11991. void clif_bg_hp(struct map_session_data *sd)
  11992. {
  11993. unsigned char buf[34];
  11994. const int cmd = 0x2e0;
  11995. nullpo_retv(sd);
  11996. WBUFW(buf,0) = cmd;
  11997. WBUFL(buf,2) = sd->status.account_id;
  11998. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  11999. if( sd->battle_status.max_hp > INT16_MAX )
  12000. { // To correctly display the %hp bar. [Skotlex]
  12001. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12002. WBUFW(buf,32) = 100;
  12003. }
  12004. else
  12005. {
  12006. WBUFW(buf,30) = sd->battle_status.hp;
  12007. WBUFW(buf,32) = sd->battle_status.max_hp;
  12008. }
  12009. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12010. }
  12011. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12012. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12013. void clif_bg_xy(struct map_session_data *sd)
  12014. {
  12015. unsigned char buf[36];
  12016. nullpo_retv(sd);
  12017. WBUFW(buf,0)=0x2df;
  12018. WBUFL(buf,2)=sd->status.account_id;
  12019. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12020. WBUFW(buf,30)=sd->status.class_;
  12021. WBUFW(buf,32)=sd->bl.x;
  12022. WBUFW(buf,34)=sd->bl.y;
  12023. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12024. }
  12025. void clif_bg_xy_remove(struct map_session_data *sd)
  12026. {
  12027. unsigned char buf[36];
  12028. nullpo_retv(sd);
  12029. WBUFW(buf,0)=0x2df;
  12030. WBUFL(buf,2)=sd->status.account_id;
  12031. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12032. WBUFW(buf,30)=0;
  12033. WBUFW(buf,32)=-1;
  12034. WBUFW(buf,34)=-1;
  12035. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12036. }
  12037. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12038. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12039. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12040. {
  12041. struct map_session_data *sd;
  12042. unsigned char *buf;
  12043. if( (sd = bg_getavailablesd(bg)) == NULL )
  12044. return;
  12045. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12046. WBUFW(buf,0) = 0x2dc;
  12047. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12048. WBUFL(buf,4) = src_id;
  12049. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12050. memcpy(WBUFP(buf,32), mes, len);
  12051. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12052. if( buf )
  12053. aFree(buf);
  12054. }
  12055. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12056. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12057. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12058. {
  12059. const char* text = (char*)RFIFOP(fd,4);
  12060. int textlen = RFIFOW(fd,2) - 4;
  12061. char *name, *message;
  12062. int namelen, messagelen;
  12063. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12064. return;
  12065. if( is_atcommand(fd, sd, message, 1) )
  12066. return;
  12067. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12068. return;
  12069. if( battle_config.min_chat_delay )
  12070. {
  12071. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12072. return;
  12073. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12074. }
  12075. bg_send_message(sd, text, textlen);
  12076. }
  12077. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12078. /// 02de <camp A points>.W <camp B points>.W
  12079. void clif_bg_updatescore(int m)
  12080. {
  12081. struct block_list bl;
  12082. unsigned char buf[6];
  12083. bl.id = 0;
  12084. bl.type = BL_NUL;
  12085. bl.m = m;
  12086. WBUFW(buf,0) = 0x2de;
  12087. WBUFW(buf,2) = map[m].bgscore_lion;
  12088. WBUFW(buf,4) = map[m].bgscore_eagle;
  12089. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12090. }
  12091. void clif_bg_updatescore_single(struct map_session_data *sd)
  12092. {
  12093. int fd;
  12094. nullpo_retv(sd);
  12095. fd = sd->fd;
  12096. WFIFOHEAD(fd,packet_len(0x2de));
  12097. WFIFOW(fd,0) = 0x2de;
  12098. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12099. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12100. WFIFOSET(fd,packet_len(0x2de));
  12101. }
  12102. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12103. /// 02dd <account id>.L <name>.24B <camp>.W
  12104. void clif_sendbgemblem_area(struct map_session_data *sd)
  12105. {
  12106. unsigned char buf[33];
  12107. nullpo_retv(sd);
  12108. WBUFW(buf, 0) = 0x2dd;
  12109. WBUFL(buf,2) = sd->bl.id;
  12110. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12111. WBUFW(buf,30) = sd->bg_id;
  12112. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12113. }
  12114. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12115. {
  12116. nullpo_retv(sd);
  12117. WFIFOHEAD(fd,32);
  12118. WFIFOW(fd,0) = 0x2dd;
  12119. WFIFOL(fd,2) = sd->bl.id;
  12120. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12121. WFIFOW(fd,30) = sd->bg_id;
  12122. WFIFOSET(fd,packet_len(0x2dd));
  12123. }
  12124. /// Custom Fonts (ZC_NOTIFY_FONT).
  12125. /// 02ef <account_id>.L <font id>.W
  12126. void clif_font(struct map_session_data *sd)
  12127. {
  12128. #if PACKETVER >= 20080102
  12129. unsigned char buf[8];
  12130. nullpo_retv(sd);
  12131. WBUFW(buf,0) = 0x2ef;
  12132. WBUFL(buf,2) = sd->bl.id;
  12133. WBUFW(buf,6) = sd->user_font;
  12134. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12135. #endif
  12136. }
  12137. /*==========================================
  12138. * Instancing Window
  12139. *------------------------------------------*/
  12140. int clif_instance(int instance_id, int type, int flag)
  12141. {
  12142. struct map_session_data *sd;
  12143. struct party_data *p;
  12144. unsigned char buf[255];
  12145. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12146. return 0;
  12147. switch( type )
  12148. {
  12149. case 1:
  12150. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12151. // Required to start the instancing information window on Client
  12152. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12153. WBUFW(buf,0) = 0x02CB;
  12154. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12155. WBUFW(buf,63) = flag;
  12156. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12157. break;
  12158. case 2:
  12159. // S 0x2cc <Standby Position>.W
  12160. // To announce Instancing queue creation if no maps available
  12161. WBUFW(buf,0) = 0x02CC;
  12162. WBUFW(buf,2) = flag;
  12163. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12164. break;
  12165. case 3:
  12166. case 4:
  12167. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12168. WBUFW(buf,0) = 0x02CD;
  12169. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12170. if( type == 3 )
  12171. {
  12172. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12173. WBUFL(buf,67) = 0;
  12174. }
  12175. else
  12176. {
  12177. WBUFL(buf,63) = 0;
  12178. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12179. }
  12180. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12181. break;
  12182. case 5:
  12183. // S 0x2ce <Message ID>.L
  12184. // 0 = Notification (EnterLimitDate update?)
  12185. // 1 = The Memorial Dungeon expired; it has been destroyed
  12186. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12187. // 3 = The Memorial Dungeon has been removed.
  12188. // 4 = Create failure (removes the instance window)
  12189. WBUFW(buf,0) = 0x02CE;
  12190. WBUFL(buf,2) = flag;
  12191. //WBUFL(buf,6) = EnterLimitDate;
  12192. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12193. break;
  12194. }
  12195. return 0;
  12196. }
  12197. void clif_instance_join(int fd, int instance_id)
  12198. {
  12199. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12200. {
  12201. WFIFOHEAD(fd,packet_len(0x02CD));
  12202. WFIFOW(fd,0) = 0x02CD;
  12203. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12204. WFIFOL(fd,63) = 0;
  12205. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12206. WFIFOSET(fd,packet_len(0x02CD));
  12207. }
  12208. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12209. {
  12210. WFIFOHEAD(fd,packet_len(0x02CD));
  12211. WFIFOW(fd,0) = 0x02CD;
  12212. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12213. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12214. WFIFOL(fd,67) = 0;
  12215. WFIFOSET(fd,packet_len(0x02CD));
  12216. }
  12217. else
  12218. {
  12219. WFIFOHEAD(fd,packet_len(0x02CB));
  12220. WFIFOW(fd,0) = 0x02CB;
  12221. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12222. WFIFOW(fd,63) = 0;
  12223. WFIFOSET(fd,packet_len(0x02CB));
  12224. }
  12225. }
  12226. void clif_instance_leave(int fd)
  12227. {
  12228. WFIFOHEAD(fd,packet_len(0x02CE));
  12229. WFIFOW(fd,0) = 0x02ce;
  12230. WFIFOL(fd,2) = 4;
  12231. WFIFOSET(fd,packet_len(0x02CE));
  12232. }
  12233. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12234. /// 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
  12235. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12236. {
  12237. unsigned char buf[22];
  12238. struct item_data* id = itemdb_search(item_data->nameid);
  12239. WBUFW(buf,0) = 0x2b8;
  12240. WBUFL(buf,2) = sd->status.account_id;
  12241. WBUFW(buf,6) = item_data->nameid;
  12242. WBUFB(buf,8) = item_data->identify;
  12243. WBUFB(buf,9) = item_data->attribute;
  12244. WBUFB(buf,10) = item_data->refine;
  12245. clif_addcards(WBUFP(buf,11), item_data);
  12246. WBUFW(buf,19) = id->equip; // equip location
  12247. WBUFB(buf,21) = itemtype(id->type); // item type
  12248. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12249. }
  12250. /// Display gained exp (ZC_NOTIFY_EXP).
  12251. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12252. /// var id:
  12253. /// SP_BASEEXP, SP_JOBEXP
  12254. /// exp type:
  12255. /// 0 = normal exp gain/loss
  12256. /// 1 = quest exp gain/loss
  12257. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12258. {
  12259. int fd;
  12260. nullpo_retv(sd);
  12261. fd = sd->fd;
  12262. WFIFOHEAD(fd, packet_len(0x7f6));
  12263. WFIFOW(fd,0) = 0x7f6;
  12264. WFIFOL(fd,2) = sd->bl.id;
  12265. WFIFOL(fd,6) = exp;
  12266. WFIFOW(fd,10) = type;
  12267. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12268. WFIFOSET(fd,packet_len(0x7f6));
  12269. }
  12270. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12271. /// type:
  12272. /// 0 = Displays 'value' for 5 seconds.
  12273. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12274. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12275. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12276. /// value:
  12277. /// 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).
  12278. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12279. {
  12280. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12281. WFIFOW(sd->fd,0) = 0x1b1;
  12282. WFIFOB(sd->fd,2) = type;
  12283. WFIFOL(sd->fd,3) = value;
  12284. WFIFOSET(sd->fd, packet_len(0x1b1));
  12285. }
  12286. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12287. /// 021d <state>.L
  12288. /// state:
  12289. /// 0 = Full effects
  12290. /// 1 = Reduced effects
  12291. ///
  12292. /// NOTE: The state is used on Aegis for sending skill unit packet
  12293. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12294. /// whenever possible. Due to the way the decision check is
  12295. /// constructed, this state tracking was rendered useless,
  12296. /// as the only skill unit, that is sent with 0x1c9 is
  12297. /// Graffiti.
  12298. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12299. {
  12300. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12301. sd->state.lesseffect = ( isLess != 0 );
  12302. }
  12303. /// Buying Store System
  12304. ///
  12305. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12306. /// 0810 <slots>.B
  12307. void clif_buyingstore_open(struct map_session_data* sd)
  12308. {
  12309. int fd = sd->fd;
  12310. WFIFOHEAD(fd,packet_len(0x810));
  12311. WFIFOW(fd,0) = 0x810;
  12312. WFIFOB(fd,2) = sd->buyingstore.slots;
  12313. WFIFOSET(fd,packet_len(0x810));
  12314. }
  12315. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12316. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12317. /// result:
  12318. /// 0 = cancel
  12319. /// 1 = open
  12320. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12321. {
  12322. const unsigned int blocksize = 8;
  12323. uint8* itemlist;
  12324. char storename[MESSAGE_SIZE];
  12325. unsigned char result;
  12326. int zenylimit;
  12327. unsigned int count, packet_len;
  12328. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12329. packet_len = RFIFOW(fd,info->pos[0]);
  12330. // TODO: Make this check global for all variable length packets.
  12331. if( packet_len < 89 )
  12332. {// minimum packet length
  12333. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12334. return;
  12335. }
  12336. zenylimit = RFIFOL(fd,info->pos[1]);
  12337. result = RFIFOL(fd,info->pos[2]);
  12338. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12339. itemlist = RFIFOP(fd,info->pos[4]);
  12340. // so that buyingstore_create knows, how many elements it has access to
  12341. packet_len-= info->pos[4];
  12342. if( packet_len%blocksize )
  12343. {
  12344. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12345. return;
  12346. }
  12347. count = packet_len/blocksize;
  12348. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  12349. }
  12350. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  12351. /// 0812 <result>.W <total weight>.L
  12352. /// result:
  12353. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  12354. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  12355. /// 8 = "No sale (purchase) information available." (0x705)
  12356. /// ? = nothing
  12357. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  12358. {
  12359. int fd = sd->fd;
  12360. WFIFOHEAD(fd,packet_len(0x812));
  12361. WFIFOW(fd,0) = 0x812;
  12362. WFIFOW(fd,2) = result;
  12363. WFIFOL(fd,4) = weight;
  12364. WFIFOSET(fd,packet_len(0x812));
  12365. }
  12366. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  12367. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  12368. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  12369. {
  12370. int fd = sd->fd;
  12371. unsigned int i;
  12372. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  12373. WFIFOW(fd,0) = 0x813;
  12374. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  12375. WFIFOL(fd,4) = sd->bl.id;
  12376. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  12377. for( i = 0; i < sd->buyingstore.slots; i++ )
  12378. {
  12379. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  12380. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  12381. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  12382. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  12383. }
  12384. WFIFOSET(fd,WFIFOW(fd,2));
  12385. }
  12386. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  12387. /// 0814 <account id>.L <store name>.80B
  12388. void clif_buyingstore_entry(struct map_session_data* sd)
  12389. {
  12390. uint8 buf[86];
  12391. WBUFW(buf,0) = 0x814;
  12392. WBUFL(buf,2) = sd->bl.id;
  12393. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  12394. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  12395. }
  12396. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12397. {
  12398. int fd = sd->fd;
  12399. WFIFOHEAD(fd,packet_len(0x814));
  12400. WFIFOW(fd,0) = 0x814;
  12401. WFIFOL(fd,2) = pl_sd->bl.id;
  12402. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  12403. WFIFOSET(fd,packet_len(0x814));
  12404. }
  12405. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  12406. /// 0815
  12407. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  12408. {
  12409. buyingstore_close(sd);
  12410. }
  12411. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  12412. /// 0816 <account id>.L
  12413. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  12414. {
  12415. uint8 buf[6];
  12416. WBUFW(buf,0) = 0x816;
  12417. WBUFL(buf,2) = sd->bl.id;
  12418. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  12419. }
  12420. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12421. {
  12422. int fd = sd->fd;
  12423. WFIFOHEAD(fd,packet_len(0x816));
  12424. WFIFOW(fd,0) = 0x816;
  12425. WFIFOL(fd,2) = pl_sd->bl.id;
  12426. WFIFOSET(fd,packet_len(0x816));
  12427. }
  12428. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  12429. /// 0817 <account id>.L
  12430. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  12431. {
  12432. int account_id;
  12433. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12434. buyingstore_open(sd, account_id);
  12435. }
  12436. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  12437. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  12438. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  12439. {
  12440. int fd = sd->fd;
  12441. unsigned int i;
  12442. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  12443. WFIFOW(fd,0) = 0x818;
  12444. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  12445. WFIFOL(fd,4) = pl_sd->bl.id;
  12446. WFIFOL(fd,8) = pl_sd->buyer_id;
  12447. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  12448. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  12449. {
  12450. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  12451. 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.
  12452. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  12453. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  12454. }
  12455. WFIFOSET(fd,WFIFOW(fd,2));
  12456. }
  12457. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  12458. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  12459. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  12460. {
  12461. const unsigned int blocksize = 6;
  12462. uint8* itemlist;
  12463. int account_id;
  12464. unsigned int count, packet_len, buyer_id;
  12465. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12466. packet_len = RFIFOW(fd,info->pos[0]);
  12467. if( packet_len < 12 )
  12468. {// minimum packet length
  12469. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  12470. return;
  12471. }
  12472. account_id = RFIFOL(fd,info->pos[1]);
  12473. buyer_id = RFIFOL(fd,info->pos[2]);
  12474. itemlist = RFIFOP(fd,info->pos[3]);
  12475. // so that buyingstore_trade knows, how many elements it has access to
  12476. packet_len-= info->pos[3];
  12477. if( packet_len%blocksize )
  12478. {
  12479. 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);
  12480. return;
  12481. }
  12482. count = packet_len/blocksize;
  12483. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  12484. }
  12485. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  12486. /// 081a <result>.W
  12487. /// result:
  12488. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  12489. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  12490. /// ? = nothing
  12491. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  12492. {
  12493. int fd = sd->fd;
  12494. WFIFOHEAD(fd,packet_len(0x81a));
  12495. WFIFOW(fd,0) = 0x81a;
  12496. WFIFOW(fd,2) = result;
  12497. WFIFOSET(fd,packet_len(0x81a));
  12498. }
  12499. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  12500. /// 081b <name id>.W <amount>.W <limit zeny>.L
  12501. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  12502. {
  12503. int fd = sd->fd;
  12504. WFIFOHEAD(fd,packet_len(0x81b));
  12505. WFIFOW(fd,0) = 0x81b;
  12506. WFIFOW(fd,2) = nameid;
  12507. WFIFOW(fd,4) = amount; // amount of nameid received
  12508. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  12509. WFIFOSET(fd,packet_len(0x81b));
  12510. }
  12511. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  12512. /// 081c <index>.W <amount>.W <price>.L
  12513. /// message:
  12514. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  12515. ///
  12516. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  12517. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  12518. {
  12519. int fd = sd->fd;
  12520. WFIFOHEAD(fd,packet_len(0x81c));
  12521. WFIFOW(fd,0) = 0x81c;
  12522. WFIFOW(fd,2) = index+2;
  12523. WFIFOW(fd,4) = amount;
  12524. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  12525. WFIFOSET(fd,packet_len(0x81c));
  12526. }
  12527. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  12528. /// 0824 <result>.W <name id>.W
  12529. /// result:
  12530. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  12531. /// 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)
  12532. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  12533. /// ? = nothing
  12534. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  12535. {
  12536. int fd = sd->fd;
  12537. WFIFOHEAD(fd,packet_len(0x824));
  12538. WFIFOW(fd,0) = 0x824;
  12539. WFIFOW(fd,2) = result;
  12540. WFIFOW(fd,4) = nameid;
  12541. WFIFOSET(fd,packet_len(0x824));
  12542. }
  12543. /// Search Store Info System
  12544. ///
  12545. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  12546. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  12547. /// type:
  12548. /// 0 = Vending
  12549. /// 1 = Buying Store
  12550. ///
  12551. /// NOTE: The client determines the item ids by specifying a name and optionally,
  12552. /// amount of card slots. If the client does not know about the item it
  12553. /// cannot be searched.
  12554. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  12555. {
  12556. const unsigned int blocksize = 2;
  12557. const uint8* itemlist;
  12558. const uint8* cardlist;
  12559. unsigned char type;
  12560. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  12561. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12562. packet_len = RFIFOW(fd,info->pos[0]);
  12563. if( packet_len < 15 )
  12564. {// minimum packet length
  12565. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  12566. return;
  12567. }
  12568. type = RFIFOB(fd,info->pos[1]);
  12569. max_price = RFIFOL(fd,info->pos[2]);
  12570. min_price = RFIFOL(fd,info->pos[3]);
  12571. item_count = RFIFOB(fd,info->pos[4]);
  12572. card_count = RFIFOB(fd,info->pos[5]);
  12573. itemlist = RFIFOP(fd,info->pos[6]);
  12574. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  12575. // check, if there is enough data for the claimed count of items
  12576. packet_len-= info->pos[6];
  12577. if( packet_len%blocksize )
  12578. {
  12579. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12580. return;
  12581. }
  12582. count = packet_len/blocksize;
  12583. if( count < item_count+card_count )
  12584. {
  12585. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  12586. return;
  12587. }
  12588. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  12589. }
  12590. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  12591. /// 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 }*
  12592. /// is first page:
  12593. /// 0 = appends to existing results
  12594. /// 1 = clears previous results before displaying this result set
  12595. /// is next page:
  12596. /// 0 = no "next" label
  12597. /// 1 = "next" label to retrieve more results
  12598. void clif_search_store_info_ack(struct map_session_data* sd)
  12599. {
  12600. const unsigned int blocksize = MESSAGE_SIZE+26;
  12601. int fd = sd->fd;
  12602. unsigned int i, start, end;
  12603. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  12604. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  12605. WFIFOHEAD(fd,7+(end-start)*blocksize);
  12606. WFIFOW(fd,0) = 0x836;
  12607. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  12608. WFIFOB(fd,4) = !sd->searchstore.pages;
  12609. WFIFOB(fd,5) = searchstore_querynext(sd);
  12610. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  12611. for( i = start; i < end; i++ )
  12612. {
  12613. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  12614. struct item it;
  12615. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  12616. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  12617. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  12618. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  12619. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  12620. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  12621. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  12622. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  12623. // make-up an item for clif_addcards
  12624. memset(&it, 0, sizeof(it));
  12625. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  12626. it.nameid = ssitem->nameid;
  12627. it.amount = ssitem->amount;
  12628. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  12629. }
  12630. WFIFOSET(fd,WFIFOW(fd,2));
  12631. }
  12632. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  12633. /// 0837 <reason>.B
  12634. /// reason:
  12635. /// 0 = "No matching stores were found." (0x70b)
  12636. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  12637. /// 2 = "You cannot search anymore." (0x706)
  12638. /// 3 = "You cannot search yet." (0x708)
  12639. /// 4 = "No sale (purchase) information available." (0x705)
  12640. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  12641. {
  12642. int fd = sd->fd;
  12643. WFIFOHEAD(fd,packet_len(0x837));
  12644. WFIFOW(fd,0) = 0x837;
  12645. WFIFOB(fd,2) = reason;
  12646. WFIFOSET(fd,packet_len(0x837));
  12647. }
  12648. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  12649. /// 0838
  12650. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  12651. {
  12652. searchstore_next(sd);
  12653. }
  12654. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  12655. /// 083a <type>.W <remaining uses>.B
  12656. /// type:
  12657. /// 0 = Search Stores
  12658. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  12659. void clif_open_search_store_info(struct map_session_data* sd)
  12660. {
  12661. int fd = sd->fd;
  12662. WFIFOHEAD(fd,packet_len(0x83a));
  12663. WFIFOW(fd,0) = 0x83a;
  12664. WFIFOW(fd,2) = sd->searchstore.effect;
  12665. #if PACKETVER > 20100701
  12666. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  12667. #endif
  12668. WFIFOSET(fd,packet_len(0x83a));
  12669. }
  12670. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  12671. /// 083b
  12672. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  12673. {
  12674. searchstore_close(sd);
  12675. }
  12676. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  12677. /// 083c <account id>.L <store id>.L <nameid>.W
  12678. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  12679. {
  12680. unsigned short nameid;
  12681. int account_id, store_id;
  12682. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12683. account_id = RFIFOL(fd,info->pos[0]);
  12684. store_id = RFIFOL(fd,info->pos[1]);
  12685. nameid = RFIFOW(fd,info->pos[2]);
  12686. searchstore_click(sd, account_id, store_id, nameid);
  12687. }
  12688. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  12689. /// 083d <xPos>.W <yPos>.W
  12690. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  12691. {
  12692. int fd = sd->fd;
  12693. WFIFOHEAD(fd,packet_len(0x83d));
  12694. WFIFOW(fd,0) = 0x83d;
  12695. WFIFOW(fd,2) = x;
  12696. WFIFOW(fd,4) = y;
  12697. WFIFOSET(fd,packet_len(0x83d));
  12698. }
  12699. /// Parse function for packet debugging.
  12700. void clif_parse_debug(int fd,struct map_session_data *sd)
  12701. {
  12702. int cmd, packet_len;
  12703. // clif_parse ensures, that there is at least 2 bytes of data
  12704. cmd = RFIFOW(fd,0);
  12705. if( sd )
  12706. {
  12707. packet_len = packet_db[sd->packet_ver][cmd].len;
  12708. if( packet_len == 0 )
  12709. {// unknown
  12710. packet_len = RFIFOREST(fd);
  12711. }
  12712. else if( packet_len == -1 )
  12713. {// variable length
  12714. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  12715. }
  12716. 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);
  12717. }
  12718. else
  12719. {
  12720. packet_len = RFIFOREST(fd);
  12721. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  12722. }
  12723. ShowDump(RFIFOP(fd,0), packet_len);
  12724. }
  12725. /*==========================================
  12726. * Server tells client to display a window similar to Magnifier (item) one
  12727. * Server populates the window with avilable elemental converter options according to player's inventory
  12728. *------------------------------------------*/
  12729. int clif_elementalconverter_list(struct map_session_data *sd) {
  12730. int i,c,view,fd;
  12731. nullpo_ret(sd);
  12732. /// Main client packet processing function
  12733. fd=sd->fd;
  12734. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  12735. WFIFOW(fd, 0)=0x1ad;
  12736. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  12737. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  12738. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  12739. WFIFOW(fd,c*2+ 4)= view;
  12740. else
  12741. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  12742. c++;
  12743. }
  12744. }
  12745. WFIFOW(fd,2) = c*2+4;
  12746. WFIFOSET(fd, WFIFOW(fd,2));
  12747. if (c > 0) {
  12748. sd->menuskill_id = SA_CREATECON;
  12749. sd->menuskill_val = c;
  12750. }
  12751. return 0;
  12752. }
  12753. /**
  12754. * Rune Knight
  12755. **/
  12756. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  12757. #if PACKETVER >= 20081217
  12758. unsigned char buf[10];
  12759. WBUFW(buf,0) = 0x440;
  12760. WBUFL(buf,2) = sd->bl.id;
  12761. WBUFW(buf,6) = shields;
  12762. WBUFW(buf,8) = 0;
  12763. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  12764. #endif
  12765. }
  12766. /**
  12767. * Warlock
  12768. **/
  12769. /*==========================================
  12770. * Spellbook list [LimitLine/3CeAM]
  12771. *------------------------------------------*/
  12772. int clif_spellbook_list(struct map_session_data *sd)
  12773. {
  12774. int i, c;
  12775. int fd;
  12776. nullpo_ret(sd);
  12777. fd = sd->fd;
  12778. WFIFOHEAD(fd, 8 * 8 + 8);
  12779. WFIFOW(fd,0) = 0x1ad;
  12780. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  12781. {
  12782. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  12783. {
  12784. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  12785. c ++;
  12786. }
  12787. }
  12788. if( c > 0 )
  12789. {
  12790. WFIFOW(fd,2) = c * 2 + 4;
  12791. WFIFOSET(fd, WFIFOW(fd, 2));
  12792. sd->menuskill_id = WL_READING_SB;
  12793. sd->menuskill_val = c;
  12794. }
  12795. else
  12796. status_change_end(&sd->bl,SC_STOP,-1);
  12797. return 1;
  12798. }
  12799. /**
  12800. * Mechanic
  12801. **/
  12802. /*==========================================
  12803. * Magic Decoy Material List
  12804. *------------------------------------------*/
  12805. int clif_magicdecoy_list(struct map_session_data *sd, int skill_lv, short x, short y) {
  12806. int i, c;
  12807. int fd;
  12808. nullpo_ret(sd);
  12809. fd = sd->fd;
  12810. WFIFOHEAD(fd, 8 * 8 + 8);
  12811. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  12812. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  12813. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  12814. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  12815. c ++;
  12816. }
  12817. }
  12818. if( c > 0 ) {
  12819. sd->menuskill_id = NC_MAGICDECOY;
  12820. sd->menuskill_val = skill_lv;
  12821. sd->sc.comet_x = x;
  12822. sd->sc.comet_y = y;
  12823. WFIFOW(fd,2) = c * 2 + 4;
  12824. WFIFOSET(fd, WFIFOW(fd, 2));
  12825. } else {
  12826. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  12827. return 0;
  12828. }
  12829. return 1;
  12830. }
  12831. /**
  12832. * Guilotine Cross
  12833. **/
  12834. /*==========================================
  12835. * Guillotine Cross Poisons List
  12836. *------------------------------------------*/
  12837. int clif_poison_list(struct map_session_data *sd, int skill_lv) {
  12838. int i, c;
  12839. int fd;
  12840. nullpo_ret(sd);
  12841. fd = sd->fd;
  12842. WFIFOHEAD(fd, 8 * 8 + 8);
  12843. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  12844. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  12845. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  12846. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  12847. c ++;
  12848. }
  12849. }
  12850. if( c > 0 ) {
  12851. sd->menuskill_id = GC_POISONINGWEAPON;
  12852. sd->menuskill_val = skill_lv;
  12853. WFIFOW(fd,2) = c * 2 + 4;
  12854. WFIFOSET(fd, WFIFOW(fd, 2));
  12855. } else {
  12856. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  12857. return 0;
  12858. }
  12859. return 1;
  12860. }
  12861. int clif_autoshadowspell_list(struct map_session_data *sd) {
  12862. int fd, i, c;
  12863. nullpo_ret(sd);
  12864. fd = sd->fd;
  12865. if( !fd ) return 0;
  12866. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  12867. return 0;
  12868. WFIFOHEAD(fd, 2 * 6 + 4);
  12869. WFIFOW(fd,0) = 0x442;
  12870. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  12871. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  12872. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  12873. { // Can't auto cast both Extended class and 3rd class skills.
  12874. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  12875. c++;
  12876. }
  12877. if( c > 0 ) {
  12878. WFIFOW(fd,2) = 8 + c * 2;
  12879. WFIFOL(fd,4) = c;
  12880. WFIFOSET(fd,WFIFOW(fd,2));
  12881. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  12882. sd->menuskill_val = c;
  12883. } else {
  12884. status_change_end(&sd->bl,SC_STOP,-1);
  12885. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,0x15,0);
  12886. }
  12887. return 1;
  12888. }
  12889. /**
  12890. * Sends a new status without a tick (currently used by the new mounts)
  12891. **/
  12892. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  12893. unsigned char buf[32];
  12894. nullpo_ret(bl);
  12895. WBUFW(buf,0)=0x043f;
  12896. WBUFW(buf,2)=type;
  12897. WBUFL(buf,4)=bl->id;
  12898. WBUFB(buf,8)=flag;
  12899. WBUFL(buf,9) = 0;
  12900. WBUFL(buf,13) = val1;
  12901. WBUFL(buf,17) = val2;
  12902. WBUFL(buf,21) = val3;
  12903. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  12904. return 0;
  12905. }
  12906. //Notifies FD of ID's type
  12907. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  12908. WFIFOHEAD(fd, packet_len(0x043f));
  12909. WFIFOW(fd,0)=0x043f;
  12910. WFIFOW(fd,2)=type;
  12911. WFIFOL(fd,4)=id;
  12912. WFIFOB(fd,8)=flag;
  12913. WFIFOL(fd,9) = 0;
  12914. WFIFOL(fd,13) = val1;
  12915. WFIFOL(fd,17) = val2;
  12916. WFIFOL(fd,21) = val3;
  12917. WFIFOSET(fd, packet_len(0x043f));
  12918. return 0;
  12919. }
  12920. // msgstringtable.txt
  12921. // 0x291 <line>.W
  12922. void clif_msgtable(int fd, int line) {
  12923. WFIFOHEAD(fd, packet_len(0x291));
  12924. WFIFOW(fd, 0) = 0x291;
  12925. WFIFOW(fd, 2) = line;
  12926. WFIFOSET(fd, packet_len(0x291));
  12927. }
  12928. // msgstringtable.txt
  12929. // 0x7e2 <line>.W <value>.L
  12930. void clif_msgtable_num(int fd, int line, int num) {
  12931. #if PACKETVER >= 20090805
  12932. WFIFOHEAD(fd, packet_len(0x7e2));
  12933. WFIFOW(fd, 0) = 0x7e2;
  12934. WFIFOW(fd, 2) = line;
  12935. WFIFOL(fd, 4) = num;
  12936. WFIFOSET(fd, packet_len(0x7e2));
  12937. #endif
  12938. }
  12939. /*==========================================
  12940. * used by SC_AUTOSHADOWSPELL
  12941. *------------------------------------------*/
  12942. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  12943. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  12944. return;
  12945. if( pc_istrading(sd) ) {
  12946. clif_skill_fail(sd,sd->ud.skillid,0,0);
  12947. sd->menuskill_val = sd->menuskill_id = 0;
  12948. return;
  12949. }
  12950. skill_select_menu(sd,RFIFOL(fd,2),RFIFOW(fd,6));
  12951. sd->menuskill_val = sd->menuskill_id = 0;
  12952. }
  12953. /*==========================================
  12954. * Main client packet processing function
  12955. *------------------------------------------*/
  12956. static int clif_parse(int fd)
  12957. {
  12958. int cmd, packet_ver, packet_len, err;
  12959. TBL_PC* sd;
  12960. int pnum;
  12961. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  12962. // Note: "click masters" can do 80+ clicks in 10 seconds
  12963. 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]
  12964. { // begin main client packet processing loop
  12965. sd = (TBL_PC *)session[fd]->session_data;
  12966. if (session[fd]->flag.eof) {
  12967. if (sd) {
  12968. if (sd->state.autotrade) {
  12969. //Disassociate character from the socket connection.
  12970. session[fd]->session_data = NULL;
  12971. sd->fd = 0;
  12972. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  12973. } else
  12974. if (sd->state.active) {
  12975. // Player logout display [Valaris]
  12976. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  12977. clif_quitsave(fd, sd);
  12978. } else {
  12979. //Unusual logout (during log on/off/map-changer procedure)
  12980. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  12981. map_quit(sd);
  12982. }
  12983. } else {
  12984. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  12985. }
  12986. do_close(fd);
  12987. return 0;
  12988. }
  12989. if (RFIFOREST(fd) < 2)
  12990. return 0;
  12991. cmd = RFIFOW(fd,0);
  12992. // identify client's packet version
  12993. if (sd) {
  12994. packet_ver = sd->packet_ver;
  12995. } else {
  12996. // check authentification packet to know packet version
  12997. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  12998. if( err )
  12999. {// failed to identify packet version
  13000. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  13001. err == 1 ? "" :
  13002. err == 2 ? ", possibly for having an invalid account_id" :
  13003. err == 3 ? ", possibly for having an invalid char_id." :
  13004. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13005. err == 4 ? ", possibly for having an invalid login_id1." :
  13006. err == 5 ? ", possibly for having an invalid client_tick." :
  13007. */
  13008. err == 6 ? ", possibly for having an invalid sex." :
  13009. ". ERROR invalid error code"));
  13010. WFIFOHEAD(fd,packet_len(0x6a));
  13011. WFIFOW(fd,0) = 0x6a;
  13012. WFIFOB(fd,2) = 3; // Rejected from Server
  13013. WFIFOSET(fd,packet_len(0x6a));
  13014. #ifdef DUMP_INVALID_PACKET
  13015. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13016. #endif
  13017. RFIFOSKIP(fd, RFIFOREST(fd));
  13018. set_eof(fd);
  13019. return 0;
  13020. }
  13021. }
  13022. // filter out invalid / unsupported packets
  13023. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13024. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13025. #ifdef DUMP_INVALID_PACKET
  13026. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13027. #endif
  13028. set_eof(fd);
  13029. return 0;
  13030. }
  13031. // determine real packet length
  13032. packet_len = packet_db[packet_ver][cmd].len;
  13033. if (packet_len == -1) { // variable-length packet
  13034. if (RFIFOREST(fd) < 4)
  13035. return 0;
  13036. packet_len = RFIFOW(fd,2);
  13037. if (packet_len < 4 || packet_len > 32768) {
  13038. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13039. #ifdef DUMP_INVALID_PACKET
  13040. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13041. #endif
  13042. set_eof(fd);
  13043. return 0;
  13044. }
  13045. }
  13046. if ((int)RFIFOREST(fd) < packet_len)
  13047. return 0; // not enough data received to form the packet
  13048. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13049. packet_db[packet_ver][cmd].func(fd, sd);
  13050. else
  13051. if( packet_db[packet_ver][cmd].func != NULL )
  13052. {
  13053. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13054. ; //Only valid packet when there is no session
  13055. else
  13056. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13057. ; //Only valid packet when player is not on a map
  13058. else
  13059. if( sd && session[sd->fd]->flag.eof )
  13060. ; //No more packets accepted
  13061. else
  13062. packet_db[packet_ver][cmd].func(fd, sd);
  13063. }
  13064. #ifdef DUMP_UNKNOWN_PACKET
  13065. else
  13066. {
  13067. const char* packet_txt = "save/packet.txt";
  13068. FILE* fp;
  13069. if((fp = fopen(packet_txt, "a"))!=NULL)
  13070. {
  13071. if( sd )
  13072. {
  13073. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  13074. }
  13075. else
  13076. {
  13077. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13078. }
  13079. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13080. fprintf(fp, "\n");
  13081. fclose(fp);
  13082. }
  13083. else
  13084. {
  13085. ShowError("Failed to write '%s'.\n", packet_txt);
  13086. // Dump on console instead
  13087. if( sd )
  13088. {
  13089. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  13090. }
  13091. else
  13092. {
  13093. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13094. }
  13095. ShowDump(RFIFOP(fd,0), packet_len);
  13096. }
  13097. }
  13098. #endif
  13099. RFIFOSKIP(fd, packet_len);
  13100. }; // main loop end
  13101. return 0;
  13102. }
  13103. /*==========================================
  13104. * Reads packet_db.txt and setups its array reference
  13105. *------------------------------------------*/
  13106. static int packetdb_readdb(void)
  13107. {
  13108. FILE *fp;
  13109. char line[1024];
  13110. int ln=0;
  13111. int cmd,i,j,packet_ver;
  13112. int max_cmd=-1;
  13113. int skip_ver = 0;
  13114. int warned = 0;
  13115. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13116. int packet_len_table[MAX_PACKET_DB] = {
  13117. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13121. //#0x0040
  13122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13124. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13125. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13126. //#0x0080
  13127. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13128. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13129. #if PACKETVER <= 20100622
  13130. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13131. #else
  13132. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13133. #endif
  13134. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13135. //#0x00C0
  13136. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13137. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13138. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13139. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13140. //#0x0100
  13141. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13142. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13143. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13144. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13145. //#0x0140
  13146. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13147. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13148. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13149. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13150. //#0x0180
  13151. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13152. // 196 comodo以降 状態表示アイコン用
  13153. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13154. // 0x1a2 changed (35->37)
  13155. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13156. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13157. //#0x01C0, Set 0x1d5=-1
  13158. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13159. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13160. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13161. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13162. //#0x0200
  13163. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13164. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13165. // 0x22c changed
  13166. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13167. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13168. //#0x0240
  13169. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13170. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13171. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13172. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13173. //#0x0280
  13174. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13175. 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13177. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
  13178. //#0x02C0
  13179. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13180. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  13181. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  13182. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13183. //#0x0300
  13184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13188. //#0x0340
  13189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13193. //#0x0380
  13194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13198. //#0x03C0
  13199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13203. //#0x0400
  13204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  13208. //#0x0440
  13209. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  13210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13213. //#0x0480
  13214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13218. //#0x04C0
  13219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13223. //#0x0500
  13224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13228. //#0x0540
  13229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13233. //#0x0580
  13234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13238. //#0x05C0
  13239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13243. //#0x0600
  13244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13248. //#0x0640
  13249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13253. //#0x0680
  13254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13258. //#0x06C0
  13259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13263. //#0x0700
  13264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13268. //#0x0740
  13269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13273. //#0x0780
  13274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13278. //#0x07C0
  13279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13280. // 0x7d9 changed
  13281. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  13282. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  13283. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  13284. //#0x0800
  13285. // for Party booking ( PACKETVER >= 20091229 )
  13286. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  13287. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  13288. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13289. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  13290. //#0x0840
  13291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13292. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  13293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13295. };
  13296. struct {
  13297. void (*func)(int, struct map_session_data *);
  13298. char *name;
  13299. } clif_parse_func[]={
  13300. {clif_parse_WantToConnection,"wanttoconnection"},
  13301. {clif_parse_LoadEndAck,"loadendack"},
  13302. {clif_parse_TickSend,"ticksend"},
  13303. {clif_parse_WalkToXY,"walktoxy"},
  13304. {clif_parse_QuitGame,"quitgame"},
  13305. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  13306. {clif_parse_GlobalMessage,"globalmessage"},
  13307. {clif_parse_MapMove,"mapmove"},
  13308. {clif_parse_ChangeDir,"changedir"},
  13309. {clif_parse_Emotion,"emotion"},
  13310. {clif_parse_HowManyConnections,"howmanyconnections"},
  13311. {clif_parse_ActionRequest,"actionrequest"},
  13312. {clif_parse_Restart,"restart"},
  13313. {clif_parse_WisMessage,"wis"},
  13314. {clif_parse_Broadcast,"broadcast"},
  13315. {clif_parse_TakeItem,"takeitem"},
  13316. {clif_parse_DropItem,"dropitem"},
  13317. {clif_parse_UseItem,"useitem"},
  13318. {clif_parse_EquipItem,"equipitem"},
  13319. {clif_parse_UnequipItem,"unequipitem"},
  13320. {clif_parse_NpcClicked,"npcclicked"},
  13321. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  13322. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  13323. {clif_parse_NpcSellListSend,"npcselllistsend"},
  13324. {clif_parse_CreateChatRoom,"createchatroom"},
  13325. {clif_parse_ChatAddMember,"chataddmember"},
  13326. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  13327. {clif_parse_ChangeChatOwner,"changechatowner"},
  13328. {clif_parse_KickFromChat,"kickfromchat"},
  13329. {clif_parse_ChatLeave,"chatleave"},
  13330. {clif_parse_TradeRequest,"traderequest"},
  13331. {clif_parse_TradeAck,"tradeack"},
  13332. {clif_parse_TradeAddItem,"tradeadditem"},
  13333. {clif_parse_TradeOk,"tradeok"},
  13334. {clif_parse_TradeCancel,"tradecancel"},
  13335. {clif_parse_TradeCommit,"tradecommit"},
  13336. {clif_parse_StopAttack,"stopattack"},
  13337. {clif_parse_PutItemToCart,"putitemtocart"},
  13338. {clif_parse_GetItemFromCart,"getitemfromcart"},
  13339. {clif_parse_RemoveOption,"removeoption"},
  13340. {clif_parse_ChangeCart,"changecart"},
  13341. {clif_parse_StatusUp,"statusup"},
  13342. {clif_parse_SkillUp,"skillup"},
  13343. {clif_parse_UseSkillToId,"useskilltoid"},
  13344. {clif_parse_UseSkillToPos,"useskilltopos"},
  13345. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  13346. {clif_parse_UseSkillMap,"useskillmap"},
  13347. {clif_parse_RequestMemo,"requestmemo"},
  13348. {clif_parse_ProduceMix,"producemix"},
  13349. {clif_parse_Cooking,"cooking"},
  13350. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  13351. {clif_parse_NpcNextClicked,"npcnextclicked"},
  13352. {clif_parse_NpcAmountInput,"npcamountinput"},
  13353. {clif_parse_NpcStringInput,"npcstringinput"},
  13354. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  13355. {clif_parse_ItemIdentify,"itemidentify"},
  13356. {clif_parse_SelectArrow,"selectarrow"},
  13357. {clif_parse_AutoSpell,"autospell"},
  13358. {clif_parse_UseCard,"usecard"},
  13359. {clif_parse_InsertCard,"insertcard"},
  13360. {clif_parse_RepairItem,"repairitem"},
  13361. {clif_parse_WeaponRefine,"weaponrefine"},
  13362. {clif_parse_SolveCharName,"solvecharname"},
  13363. {clif_parse_ResetChar,"resetchar"},
  13364. {clif_parse_LocalBroadcast,"localbroadcast"},
  13365. {clif_parse_MoveToKafra,"movetokafra"},
  13366. {clif_parse_MoveFromKafra,"movefromkafra"},
  13367. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  13368. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  13369. {clif_parse_CloseKafra,"closekafra"},
  13370. {clif_parse_CreateParty,"createparty"},
  13371. {clif_parse_CreateParty2,"createparty2"},
  13372. {clif_parse_PartyInvite,"partyinvite"},
  13373. {clif_parse_PartyInvite2,"partyinvite2"},
  13374. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  13375. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  13376. {clif_parse_LeaveParty,"leaveparty"},
  13377. {clif_parse_RemovePartyMember,"removepartymember"},
  13378. {clif_parse_PartyChangeOption,"partychangeoption"},
  13379. {clif_parse_PartyMessage,"partymessage"},
  13380. {clif_parse_PartyChangeLeader,"partychangeleader"},
  13381. {clif_parse_CloseVending,"closevending"},
  13382. {clif_parse_VendingListReq,"vendinglistreq"},
  13383. {clif_parse_PurchaseReq,"purchasereq"},
  13384. {clif_parse_PurchaseReq2,"purchasereq2"},
  13385. {clif_parse_OpenVending,"openvending"},
  13386. {clif_parse_CreateGuild,"createguild"},
  13387. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  13388. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  13389. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  13390. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  13391. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  13392. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  13393. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  13394. {clif_parse_GuildInvite,"guildinvite"},
  13395. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  13396. {clif_parse_GuildLeave,"guildleave"},
  13397. {clif_parse_GuildExpulsion,"guildexpulsion"},
  13398. {clif_parse_GuildMessage,"guildmessage"},
  13399. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  13400. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  13401. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  13402. {clif_parse_GuildOpposition,"guildopposition"},
  13403. {clif_parse_GuildBreak,"guildbreak"},
  13404. {clif_parse_PetMenu,"petmenu"},
  13405. {clif_parse_CatchPet,"catchpet"},
  13406. {clif_parse_SelectEgg,"selectegg"},
  13407. {clif_parse_SendEmotion,"sendemotion"},
  13408. {clif_parse_ChangePetName,"changepetname"},
  13409. {clif_parse_GMKick,"gmkick"},
  13410. {clif_parse_GMHide,"gmhide"},
  13411. {clif_parse_GMReqNoChat,"gmreqnochat"},
  13412. {clif_parse_GMReqAccountName,"gmreqaccname"},
  13413. {clif_parse_GMKickAll,"killall"},
  13414. {clif_parse_GMRecall,"recall"},
  13415. {clif_parse_GMRecall,"summon"},
  13416. {clif_parse_GM_Monster_Item,"itemmonster"},
  13417. {clif_parse_GMShift,"remove"},
  13418. {clif_parse_GMShift,"shift"},
  13419. {clif_parse_GMChangeMapType,"changemaptype"},
  13420. {clif_parse_GMRc,"rc"},
  13421. {clif_parse_GMRecall2,"recall2"},
  13422. {clif_parse_GMRemove2,"remove2"},
  13423. {clif_parse_NoviceDoriDori,"sndoridori"},
  13424. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  13425. {clif_parse_PMIgnore,"wisexin"},
  13426. {clif_parse_PMIgnoreList,"wisexlist"},
  13427. {clif_parse_PMIgnoreAll,"wisall"},
  13428. {clif_parse_FriendsListAdd,"friendslistadd"},
  13429. {clif_parse_FriendsListRemove,"friendslistremove"},
  13430. {clif_parse_FriendsListReply,"friendslistreply"},
  13431. {clif_parse_Blacksmith,"blacksmith"},
  13432. {clif_parse_Alchemist,"alchemist"},
  13433. {clif_parse_Taekwon,"taekwon"},
  13434. {clif_parse_RankingPk,"rankingpk"},
  13435. {clif_parse_FeelSaveOk,"feelsaveok"},
  13436. {clif_parse_debug,"debug"},
  13437. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  13438. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  13439. {clif_parse_HomMoveTo,"hommoveto"},
  13440. {clif_parse_HomAttack,"homattack"},
  13441. {clif_parse_HomMenu,"hommenu"},
  13442. {clif_parse_StoragePassword,"storagepassword"},
  13443. {clif_parse_Hotkey,"hotkey"},
  13444. {clif_parse_AutoRevive,"autorevive"},
  13445. {clif_parse_Check,"check"},
  13446. {clif_parse_Adopt_request,"adoptrequest"},
  13447. {clif_parse_Adopt_reply,"adoptreply"},
  13448. // MAIL SYSTEM
  13449. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  13450. {clif_parse_Mail_read,"mailread"},
  13451. {clif_parse_Mail_getattach,"mailgetattach"},
  13452. {clif_parse_Mail_delete,"maildelete"},
  13453. {clif_parse_Mail_return,"mailreturn"},
  13454. {clif_parse_Mail_setattach,"mailsetattach"},
  13455. {clif_parse_Mail_winopen,"mailwinopen"},
  13456. {clif_parse_Mail_send,"mailsend"},
  13457. // AUCTION SYSTEM
  13458. {clif_parse_Auction_search,"auctionsearch"},
  13459. {clif_parse_Auction_buysell,"auctionbuysell"},
  13460. {clif_parse_Auction_setitem,"auctionsetitem"},
  13461. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  13462. {clif_parse_Auction_register,"auctionregister"},
  13463. {clif_parse_Auction_cancel,"auctioncancel"},
  13464. {clif_parse_Auction_close,"auctionclose"},
  13465. {clif_parse_Auction_bid,"auctionbid"},
  13466. // Quest Log System
  13467. {clif_parse_questStateAck,"queststate"},
  13468. {clif_parse_cashshop_buy,"cashshopbuy"},
  13469. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  13470. {clif_parse_EquipTick,"equiptickbox"},
  13471. {clif_parse_BattleChat,"battlechat"},
  13472. {clif_parse_mercenary_action,"mermenu"},
  13473. {clif_parse_progressbar,"progressbar"},
  13474. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  13475. #if PACKETVER >= 20091229
  13476. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  13477. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  13478. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  13479. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  13480. #endif
  13481. {clif_parse_PVPInfo,"pvpinfo"},
  13482. {clif_parse_LessEffect,"lesseffect"},
  13483. // Buying Store
  13484. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  13485. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  13486. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  13487. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  13488. // Store Search
  13489. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  13490. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  13491. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  13492. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  13493. {NULL,NULL}
  13494. };
  13495. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  13496. memset(packet_db,0,sizeof(packet_db));
  13497. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  13498. packet_len(i) = packet_len_table[i];
  13499. sprintf(line, "%s/packet_db.txt", db_path);
  13500. if( (fp=fopen(line,"r"))==NULL ){
  13501. ShowFatalError("can't read %s\n", line);
  13502. exit(EXIT_FAILURE);
  13503. }
  13504. clif_config.packet_db_ver = MAX_PACKET_VER;
  13505. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  13506. while( fgets(line, sizeof(line), fp) )
  13507. {
  13508. ln++;
  13509. if(line[0]=='/' && line[1]=='/')
  13510. continue;
  13511. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  13512. {
  13513. if(strcmpi(w1,"packet_ver")==0) {
  13514. int prev_ver = packet_ver;
  13515. skip_ver = 0;
  13516. packet_ver = atoi(w2);
  13517. if ( packet_ver > MAX_PACKET_VER )
  13518. { //Check to avoid overflowing. [Skotlex]
  13519. if( (warned&1) == 0 )
  13520. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  13521. warned &= 1;
  13522. skip_ver = 1;
  13523. }
  13524. else if( packet_ver < 0 )
  13525. {
  13526. if( (warned&2) == 0 )
  13527. ShowWarning("Negative packet versions are not supported.\n");
  13528. warned &= 2;
  13529. skip_ver = 1;
  13530. }
  13531. else if( packet_ver == SERVER )
  13532. {
  13533. if( (warned&4) == 0 )
  13534. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  13535. warned &= 4;
  13536. skip_ver = 1;
  13537. }
  13538. if( skip_ver )
  13539. {
  13540. ShowWarning("Skipping packet version %d.\n", packet_ver);
  13541. packet_ver = prev_ver;
  13542. continue;
  13543. }
  13544. // copy from previous version into new version and continue
  13545. // - indicating all following packets should be read into the newer version
  13546. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  13547. continue;
  13548. } else if(strcmpi(w1,"packet_db_ver")==0) {
  13549. if(strcmpi(w2,"default")==0) //This is the preferred version.
  13550. clif_config.packet_db_ver = MAX_PACKET_VER;
  13551. else // to manually set the packet DB version
  13552. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  13553. continue;
  13554. }
  13555. }
  13556. if( skip_ver != 0 )
  13557. continue; // Skipping current packet version
  13558. memset(str,0,sizeof(str));
  13559. for(j=0,p=line;j<4 && p; ++j)
  13560. {
  13561. str[j]=p;
  13562. p=strchr(p,',');
  13563. if(p) *p++=0;
  13564. }
  13565. if(str[0]==NULL)
  13566. continue;
  13567. cmd=strtol(str[0],(char **)NULL,0);
  13568. if(max_cmd < cmd)
  13569. max_cmd = cmd;
  13570. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  13571. continue;
  13572. if(str[1]==NULL){
  13573. ShowError("packet_db: packet len error\n");
  13574. continue;
  13575. }
  13576. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  13577. if(str[2]==NULL){
  13578. packet_db[packet_ver][cmd].func = NULL;
  13579. ln++;
  13580. continue;
  13581. }
  13582. // look up processing function by name
  13583. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  13584. if( j < ARRAYLENGTH(clif_parse_func) )
  13585. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  13586. // set the identifying cmd for the packet_db version
  13587. if (strcmp(str[2],"wanttoconnection")==0)
  13588. clif_config.connect_cmd[packet_ver] = cmd;
  13589. if(str[3]==NULL){
  13590. ShowError("packet_db: packet error\n");
  13591. exit(EXIT_FAILURE);
  13592. }
  13593. for(j=0,p2=str[3];p2;j++){
  13594. short k;
  13595. str2[j]=p2;
  13596. p2=strchr(p2,':');
  13597. if(p2) *p2++=0;
  13598. k = atoi(str2[j]);
  13599. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  13600. if( j >= MAX_PACKET_POS )
  13601. {
  13602. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  13603. break;
  13604. }
  13605. packet_db[packet_ver][cmd].pos[j] = k;
  13606. }
  13607. }
  13608. fclose(fp);
  13609. if(max_cmd > MAX_PACKET_DB)
  13610. {
  13611. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  13612. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  13613. }
  13614. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  13615. { //Locate the nearest version that we still support. [Skotlex]
  13616. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  13617. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  13618. }
  13619. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'. Using default packet version: "CL_WHITE"%d"CL_RESET".\n", "packet_db.txt", clif_config.packet_db_ver);
  13620. return 0;
  13621. }
  13622. /*==========================================
  13623. *
  13624. *------------------------------------------*/
  13625. int do_init_clif(void) {
  13626. const char* colors[COLOR_MAX] = { "0xFF0000" };
  13627. int i;
  13628. /**
  13629. * Setup Color Table (saves unnecessary load of strtoul on every call)
  13630. **/
  13631. for(i = 0; i < COLOR_MAX; i++) {
  13632. color_table[i] = strtoul(colors[i],NULL,0);
  13633. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  13634. }
  13635. clif_config.packet_db_ver = -1; // the main packet version of the DB
  13636. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  13637. memset(packet_db,0,sizeof(packet_db));
  13638. //Using the packet_db file is the only way to set up packets now [Skotlex]
  13639. packetdb_readdb();
  13640. set_defaultparse(clif_parse);
  13641. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  13642. ShowFatalError("can't bind game port\n");
  13643. exit(EXIT_FAILURE);
  13644. }
  13645. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  13646. add_timer_func_list(clif_delayquit, "clif_delayquit");
  13647. return 0;
  13648. }