clif.c 440 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919
  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/version.h"
  9. #include "../common/nullpo.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. 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. //To idenfity disguised characters.
  85. static inline bool disguised(struct block_list* bl)
  86. {
  87. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  88. }
  89. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  90. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max)
  91. {
  92. if( len > max )
  93. len = max;
  94. mes[len-1] = '\0';
  95. return len;
  96. }
  97. static char map_ip_str[128];
  98. static uint32 map_ip;
  99. static uint32 bind_ip = INADDR_ANY;
  100. static uint16 map_port = 5121;
  101. int map_fd;
  102. int clif_parse (int fd);
  103. /*==========================================
  104. * map鯖のip設定
  105. *------------------------------------------*/
  106. int clif_setip(const char* ip)
  107. {
  108. char ip_str[16];
  109. map_ip = host2ip(ip);
  110. if (!map_ip) {
  111. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  112. return 0;
  113. }
  114. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  115. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  116. return 1;
  117. }
  118. void clif_setbindip(const char* ip)
  119. {
  120. char ip_str[16];
  121. bind_ip = host2ip(ip);
  122. if (bind_ip) {
  123. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  124. } else {
  125. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  126. }
  127. }
  128. /*==========================================
  129. * Sets map port to 'port'
  130. * is run from map.c upon loading map server configuration
  131. *------------------------------------------*/
  132. void clif_setport(uint16 port)
  133. {
  134. map_port = port;
  135. }
  136. /*==========================================
  137. * Returns map server IP
  138. *------------------------------------------*/
  139. uint32 clif_getip(void)
  140. {
  141. return map_ip;
  142. }
  143. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  144. uint32 clif_refresh_ip(void)
  145. {
  146. uint32 new_ip;
  147. new_ip = host2ip(map_ip_str);
  148. if (new_ip && new_ip != map_ip) {
  149. map_ip = new_ip;
  150. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  151. return map_ip;
  152. }
  153. return 0;
  154. }
  155. /*==========================================
  156. * Returns map port which is set by clif_setport()
  157. *------------------------------------------*/
  158. uint16 clif_getport(void)
  159. {
  160. return map_port;
  161. }
  162. #if PACKETVER >= 20071106
  163. static inline unsigned char clif_bl_type(struct block_list *bl) {
  164. switch (bl->type) {
  165. case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
  166. case BL_ITEM: return 0x2; //ITEM_TYPE
  167. case BL_SKILL: return 0x3; //SKILL_TYPE
  168. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  169. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  170. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  171. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  172. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  173. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  174. // case BL_ELEM: return 0xA; //NPC_ELEMENTAL_TYPE
  175. default: return 0x1; //NPC_TYPE
  176. }
  177. }
  178. #endif
  179. /*==========================================
  180. * sub process of clif_send
  181. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  182. * In order to send area-wise packets, such as:
  183. * - AREA : everyone nearby your area
  184. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  185. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  186. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  187. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  188. *------------------------------------------*/
  189. int clif_send_sub(struct block_list *bl, va_list ap)
  190. {
  191. struct block_list *src_bl;
  192. struct map_session_data *sd;
  193. unsigned char *buf;
  194. int len, type, fd;
  195. nullpo_ret(bl);
  196. nullpo_ret(sd = (struct map_session_data *)bl);
  197. fd = sd->fd;
  198. if (!fd) //Don't send to disconnected clients.
  199. return 0;
  200. buf = va_arg(ap,unsigned char*);
  201. len = va_arg(ap,int);
  202. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  203. type = va_arg(ap,int);
  204. switch(type)
  205. {
  206. case AREA_WOS:
  207. if (bl == src_bl)
  208. return 0;
  209. break;
  210. case AREA_WOC:
  211. if (sd->chatID || bl == src_bl)
  212. return 0;
  213. break;
  214. case AREA_WOSC:
  215. {
  216. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  217. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  218. return 0;
  219. }
  220. break;
  221. }
  222. if (session[fd] == NULL)
  223. return 0;
  224. WFIFOHEAD(fd, len);
  225. if (WFIFOP(fd,0) == buf) {
  226. ShowError("WARNING: Invalid use of clif_send function\n");
  227. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  228. ShowError(" Please correct your code.\n");
  229. // don't send to not move the pointer of the packet for next sessions in the loop
  230. //WFIFOSET(fd,0);//## TODO is this ok?
  231. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  232. return 0;
  233. }
  234. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  235. memcpy(WFIFOP(fd,0), buf, len);
  236. WFIFOSET(fd,len);
  237. }
  238. return 0;
  239. }
  240. /*==========================================
  241. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  242. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  243. *------------------------------------------*/
  244. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  245. {
  246. int i;
  247. struct map_session_data *sd, *tsd;
  248. struct party_data *p = NULL;
  249. struct guild *g = NULL;
  250. struct battleground_data *bg = NULL;
  251. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  252. struct s_mapiterator* iter;
  253. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  254. nullpo_ret(bl);
  255. sd = BL_CAST(BL_PC, bl);
  256. switch(type) {
  257. case ALL_CLIENT: //All player clients.
  258. iter = mapit_getallusers();
  259. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  260. {
  261. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  262. { // packet must exist for the client version
  263. WFIFOHEAD(tsd->fd, len);
  264. memcpy(WFIFOP(tsd->fd,0), buf, len);
  265. WFIFOSET(tsd->fd,len);
  266. }
  267. }
  268. mapit_free(iter);
  269. break;
  270. case ALL_SAMEMAP: //All players on the same map
  271. iter = mapit_getallusers();
  272. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  273. {
  274. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  275. { // packet must exist for the client version
  276. WFIFOHEAD(tsd->fd, len);
  277. memcpy(WFIFOP(tsd->fd,0), buf, len);
  278. WFIFOSET(tsd->fd,len);
  279. }
  280. }
  281. mapit_free(iter);
  282. break;
  283. case AREA:
  284. case AREA_WOSC:
  285. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  286. clif_send (buf, len, bl, SELF);
  287. case AREA_WOC:
  288. case AREA_WOS:
  289. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  290. BL_PC, buf, len, bl, type);
  291. break;
  292. case AREA_CHAT_WOC:
  293. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  294. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  295. break;
  296. case CHAT:
  297. case CHAT_WOS:
  298. {
  299. struct chat_data *cd;
  300. if (sd) {
  301. cd = (struct chat_data*)map_id2bl(sd->chatID);
  302. } else if (bl->type == BL_CHAT) {
  303. cd = (struct chat_data*)bl;
  304. } else break;
  305. if (cd == NULL)
  306. break;
  307. for(i = 0; i < cd->users; i++) {
  308. if (type == CHAT_WOS && cd->usersd[i] == sd)
  309. continue;
  310. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  311. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  312. {
  313. WFIFOHEAD(fd,len);
  314. memcpy(WFIFOP(fd,0), buf, len);
  315. WFIFOSET(fd,len);
  316. }
  317. }
  318. }
  319. }
  320. break;
  321. case CHAT_MAINCHAT: //[LuzZza]
  322. iter = mapit_getallusers();
  323. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  324. {
  325. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  326. { // packet must exist for the client version
  327. WFIFOHEAD(tsd->fd, len);
  328. memcpy(WFIFOP(tsd->fd,0), buf, len);
  329. WFIFOSET(tsd->fd,len);
  330. }
  331. }
  332. mapit_free(iter);
  333. break;
  334. case PARTY_AREA:
  335. case PARTY_AREA_WOS:
  336. x0 = bl->x - AREA_SIZE;
  337. y0 = bl->y - AREA_SIZE;
  338. x1 = bl->x + AREA_SIZE;
  339. y1 = bl->y + AREA_SIZE;
  340. case PARTY:
  341. case PARTY_WOS:
  342. case PARTY_SAMEMAP:
  343. case PARTY_SAMEMAP_WOS:
  344. if (sd && sd->status.party_id)
  345. p = party_search(sd->status.party_id);
  346. if (p) {
  347. for(i=0;i<MAX_PARTY;i++){
  348. if( (sd = p->data[i].sd) == NULL )
  349. continue;
  350. if( !(fd=sd->fd) )
  351. continue;
  352. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  353. continue;
  354. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  355. continue;
  356. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  357. continue;
  358. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  359. { // packet must exist for the client version
  360. WFIFOHEAD(fd,len);
  361. memcpy(WFIFOP(fd,0), buf, len);
  362. WFIFOSET(fd,len);
  363. }
  364. }
  365. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  366. break;
  367. iter = mapit_getallusers();
  368. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  369. {
  370. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  371. { // packet must exist for the client version
  372. WFIFOHEAD(tsd->fd, len);
  373. memcpy(WFIFOP(tsd->fd,0), buf, len);
  374. WFIFOSET(tsd->fd,len);
  375. }
  376. }
  377. mapit_free(iter);
  378. }
  379. break;
  380. case DUEL:
  381. case DUEL_WOS:
  382. if (!sd || !sd->duel_group) break; //Invalid usage.
  383. iter = mapit_getallusers();
  384. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  385. {
  386. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  387. continue;
  388. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  389. { // packet must exist for the client version
  390. WFIFOHEAD(tsd->fd, len);
  391. memcpy(WFIFOP(tsd->fd,0), buf, len);
  392. WFIFOSET(tsd->fd,len);
  393. }
  394. }
  395. mapit_free(iter);
  396. break;
  397. case SELF:
  398. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  399. WFIFOHEAD(fd,len);
  400. memcpy(WFIFOP(fd,0), buf, len);
  401. WFIFOSET(fd,len);
  402. }
  403. break;
  404. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  405. case GUILD_AREA:
  406. case GUILD_AREA_WOS:
  407. x0 = bl->x - AREA_SIZE;
  408. y0 = bl->y - AREA_SIZE;
  409. x1 = bl->x + AREA_SIZE;
  410. y1 = bl->y + AREA_SIZE;
  411. case GUILD_SAMEMAP:
  412. case GUILD_SAMEMAP_WOS:
  413. case GUILD:
  414. case GUILD_WOS:
  415. case GUILD_NOBG:
  416. if (sd && sd->status.guild_id)
  417. g = guild_search(sd->status.guild_id);
  418. if (g) {
  419. for(i = 0; i < g->max_member; i++) {
  420. if( (sd = g->member[i].sd) != NULL )
  421. {
  422. if( !(fd=sd->fd) )
  423. continue;
  424. if( type == GUILD_NOBG && sd->bg_id )
  425. continue;
  426. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  427. continue;
  428. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  429. continue;
  430. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  431. continue;
  432. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  433. { // packet must exist for the client version
  434. WFIFOHEAD(fd,len);
  435. memcpy(WFIFOP(fd,0), buf, len);
  436. WFIFOSET(fd,len);
  437. }
  438. }
  439. }
  440. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  441. break;
  442. iter = mapit_getallusers();
  443. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  444. {
  445. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  446. { // packet must exist for the client version
  447. WFIFOHEAD(tsd->fd, len);
  448. memcpy(WFIFOP(tsd->fd,0), buf, len);
  449. WFIFOSET(tsd->fd,len);
  450. }
  451. }
  452. mapit_free(iter);
  453. }
  454. break;
  455. case BG_AREA:
  456. case BG_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 BG_SAMEMAP:
  462. case BG_SAMEMAP_WOS:
  463. case BG:
  464. case BG_WOS:
  465. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  466. {
  467. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  468. {
  469. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  470. continue;
  471. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  472. continue;
  473. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  474. continue;
  475. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  476. continue;
  477. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  478. { // packet must exist for the client version
  479. WFIFOHEAD(fd,len);
  480. memcpy(WFIFOP(fd,0), buf, len);
  481. WFIFOSET(fd,len);
  482. }
  483. }
  484. }
  485. break;
  486. default:
  487. ShowError("clif_send: Unrecognized type %d\n",type);
  488. return -1;
  489. }
  490. return 0;
  491. }
  492. /*==========================================
  493. * Tells client that its player is fully loaded and that it can proceed to the map screen
  494. * Provides client with player position and facing direction
  495. *------------------------------------------*/
  496. int clif_authok(struct map_session_data *sd)
  497. {
  498. int fd;
  499. if (!sd->fd)
  500. return 0;
  501. fd = sd->fd;
  502. WFIFOHEAD(fd, packet_len(0x73));
  503. WFIFOW(fd, 0) = 0x73;
  504. WFIFOL(fd, 2) = gettick();
  505. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  506. WFIFOB(fd, 9) = 5; // ignored
  507. WFIFOB(fd,10) = 5; // ignored
  508. WFIFOSET(fd,packet_len(0x73));
  509. return 0;
  510. }
  511. /*==========================================
  512. * Authentication failed/disconnect client.
  513. *------------------------------------------
  514. * The client closes it's socket and displays a message according to type:
  515. * 1 - server closed -> MsgStringTable[4]
  516. * 2 - ID already logged in -> MsgStringTable[5]
  517. * 3 - timeout/too much lag -> MsgStringTable[241]
  518. * 4 - server full -> MsgStringTable[264]
  519. * 5 - underaged -> MsgStringTable[305]
  520. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  521. * 9 - too many connections from this ip -> MsgStringTable[529]
  522. * 10 - out of available time paid for -> MsgStringTable[530]
  523. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  524. * other - disconnected -> MsgStringTable[3]
  525. */
  526. int clif_authfail_fd(int fd, int type)
  527. {
  528. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  529. return 0;
  530. WFIFOHEAD(fd, packet_len(0x81));
  531. WFIFOW(fd,0) = 0x81;
  532. WFIFOB(fd,2) = type;
  533. WFIFOSET(fd,packet_len(0x81));
  534. set_eof(fd);
  535. return 0;
  536. }
  537. /// Reply from char-server.
  538. /// Tells the player if it can connect to the char-server to select a character.
  539. /// ok=1 : client disconnects and tries to connect to the char-server
  540. int clif_charselectok(int id, uint8 ok)
  541. {
  542. struct map_session_data* sd;
  543. int fd;
  544. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  545. return 1;
  546. fd = sd->fd;
  547. WFIFOHEAD(fd,packet_len(0xb3));
  548. WFIFOW(fd,0) = 0xb3;
  549. WFIFOB(fd,2) = ok;
  550. WFIFOSET(fd,packet_len(0xb3));
  551. return 0;
  552. }
  553. /*==========================================
  554. * Makes an item appear on the ground
  555. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  556. *------------------------------------------*/
  557. int clif_dropflooritem(struct flooritem_data* fitem)
  558. {
  559. uint8 buf[17];
  560. int view;
  561. nullpo_ret(fitem);
  562. if (fitem->item_data.nameid <= 0)
  563. return 0;
  564. WBUFW(buf, 0) = 0x9e;
  565. WBUFL(buf, 2) = fitem->bl.id;
  566. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  567. WBUFB(buf, 8) = fitem->item_data.identify;
  568. WBUFW(buf, 9) = fitem->bl.x;
  569. WBUFW(buf,11) = fitem->bl.y;
  570. WBUFB(buf,13) = fitem->subx;
  571. WBUFB(buf,14) = fitem->suby;
  572. WBUFW(buf,15) = fitem->item_data.amount;
  573. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  574. return 0;
  575. }
  576. /*==========================================
  577. * Server tells client to remove item of ID ('fitem->bl.id') from FD player area
  578. * If FD is 0 it tells all clients nearby this item that it is gone
  579. *------------------------------------------*/
  580. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  581. {
  582. unsigned char buf[16];
  583. nullpo_ret(fitem);
  584. WBUFW(buf,0) = 0xa1;
  585. WBUFL(buf,2) = fitem->bl.id;
  586. if (fd == 0) {
  587. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  588. } else {
  589. WFIFOHEAD(fd,packet_len(0xa1));
  590. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  591. WFIFOSET(fd,packet_len(0xa1));
  592. }
  593. return 0;
  594. }
  595. /*==========================================
  596. * make a unit (char, npc, mob, homun) disappear to one client
  597. * id : the id of the unit
  598. * type: 0 - moved out of sight
  599. * 1 - died
  600. * 2 - respawned
  601. * 3 - teleported / logged out
  602. * fd : the target client
  603. *------------------------------------------*/
  604. int clif_clearunit_single(int id, clr_type type, int fd)
  605. {
  606. WFIFOHEAD(fd, packet_len(0x80));
  607. WFIFOW(fd,0) = 0x80;
  608. WFIFOL(fd,2) = id;
  609. WFIFOB(fd,6) = type;
  610. WFIFOSET(fd, packet_len(0x80));
  611. return 0;
  612. }
  613. /*==========================================
  614. * make a unit (char, npc, mob, homun) disappear to all clients in area
  615. * type: 0 - moved out of sight
  616. * 1 - died
  617. * 2 - respawned
  618. * 3 - teleported / logged out
  619. *------------------------------------------*/
  620. int clif_clearunit_area(struct block_list* bl, clr_type type)
  621. {
  622. unsigned char buf[16];
  623. nullpo_ret(bl);
  624. WBUFW(buf,0) = 0x80;
  625. WBUFL(buf,2) = bl->id;
  626. WBUFB(buf,6) = type;
  627. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  628. if(disguised(bl)) {
  629. WBUFL(buf,2) = -bl->id;
  630. clif_send(buf, packet_len(0x80), bl, SELF);
  631. }
  632. return 0;
  633. }
  634. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  635. {
  636. struct block_list *bl = (struct block_list *)data;
  637. clif_clearunit_area(bl, CLR_OUTSIGHT);
  638. aFree(bl);
  639. return 0;
  640. }
  641. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  642. {
  643. struct block_list *tbl;
  644. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  645. memcpy (tbl, bl, sizeof (struct block_list));
  646. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr_t)tbl);
  647. return 0;
  648. }
  649. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  650. {
  651. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  652. {
  653. *rhand = *lhand = 0;
  654. return;
  655. }
  656. #if PACKETVER < 4
  657. *rhand = sd->status.weapon;
  658. *lhand = sd->status.shield;
  659. #else
  660. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  661. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  662. {
  663. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  664. if (id->view_id > 0)
  665. *rhand = id->view_id;
  666. else
  667. *rhand = id->nameid;
  668. } else
  669. *rhand = 0;
  670. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  671. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  672. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  673. {
  674. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  675. if (id->view_id > 0)
  676. *lhand = id->view_id;
  677. else
  678. *lhand = id->nameid;
  679. } else
  680. *lhand = 0;
  681. #endif
  682. }
  683. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  684. static int clif_setlevel_sub(int lv)
  685. {
  686. if( lv < battle_config.max_lv )
  687. {
  688. ;
  689. }
  690. else if( lv < battle_config.aura_lv )
  691. {
  692. lv = battle_config.max_lv - 1;
  693. }
  694. else
  695. {
  696. lv = battle_config.max_lv;
  697. }
  698. return lv;
  699. }
  700. static int clif_setlevel(struct block_list* bl)
  701. {
  702. int lv = status_get_lv(bl);
  703. if( battle_config.client_limit_unit_lv&bl->type )
  704. return clif_setlevel_sub(lv);
  705. switch( bl->type )
  706. {
  707. case BL_NPC:
  708. case BL_PET:
  709. // npcs and pets do not have level
  710. return 0;
  711. }
  712. return lv;
  713. }
  714. /*==========================================
  715. * Prepares 'unit standing/spawning' packet
  716. *------------------------------------------*/
  717. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  718. {
  719. struct map_session_data* sd;
  720. struct status_change* sc = status_get_sc(bl);
  721. struct view_data* vd = status_get_viewdata(bl);
  722. unsigned char *buf = WBUFP(buffer,0);
  723. #if PACKETVER < 20091103
  724. bool type = !pcdb_checkid(vd->class_);
  725. #endif
  726. #if PACKETVER >= 7
  727. unsigned short offset = 0;
  728. #endif
  729. #if PACKETVER >= 20091103
  730. const char *name;
  731. #endif
  732. sd = BL_CAST(BL_PC, bl);
  733. #if PACKETVER < 20091103
  734. if(type)
  735. WBUFW(buf,0) = spawn?0x7c:0x78;
  736. else
  737. #endif
  738. #if PACKETVER < 4
  739. WBUFW(buf,0) = spawn?0x79:0x78;
  740. #elif PACKETVER < 7
  741. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  742. #elif PACKETVER < 20080102
  743. WBUFW(buf,0) = spawn?0x22b:0x22a;
  744. #elif PACKETVER < 20091103
  745. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  746. #elif PACKETVER < 20101124
  747. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  748. #else
  749. WBUFW(buf,0) = spawn?0x858:0x857;
  750. #endif
  751. #if PACKETVER >= 20091103
  752. name = status_get_name(bl);
  753. #if PACKETVER < 20110111
  754. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  755. #else
  756. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  757. #endif
  758. WBUFB(buf,4) = clif_bl_type(bl);
  759. offset+=3;
  760. buf = WBUFP(buffer,offset);
  761. #elif PACKETVER >= 20071106
  762. if (type) { //Non-player packets
  763. WBUFB(buf,2) = clif_bl_type(bl);
  764. offset++;
  765. buf = WBUFP(buffer,offset);
  766. }
  767. #endif
  768. WBUFL(buf, 2) = bl->id;
  769. WBUFW(buf, 6) = status_get_speed(bl);
  770. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  771. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  772. #if PACKETVER < 20091103
  773. if (type&&spawn) { //uses an older and different packet structure
  774. WBUFW(buf,12) = (sc)? sc->option : 0;
  775. WBUFW(buf,14) = vd->hair_style;
  776. WBUFW(buf,16) = vd->weapon;
  777. WBUFW(buf,18) = vd->head_bottom;
  778. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  779. WBUFW(buf,22) = vd->shield;
  780. } else {
  781. #endif
  782. #if PACKETVER >= 20091103
  783. WBUFL(buf,12) = (sc)? sc->option : 0;
  784. offset+=2;
  785. buf = WBUFP(buffer,offset);
  786. #elif PACKETVER >= 7
  787. if (!type) {
  788. WBUFL(buf,12) = (sc)? sc->option : 0;
  789. offset+=2;
  790. buf = WBUFP(buffer,offset);
  791. } else
  792. WBUFW(buf,12) = (sc)? sc->option : 0;
  793. #else
  794. WBUFW(buf,12) = (sc)? sc->option : 0;
  795. #endif
  796. WBUFW(buf,14) = vd->class_;
  797. WBUFW(buf,16) = vd->hair_style;
  798. WBUFW(buf,18) = vd->weapon;
  799. #if PACKETVER < 4
  800. WBUFW(buf,20) = vd->head_bottom;
  801. WBUFW(buf,22) = vd->shield;
  802. #else
  803. WBUFW(buf,20) = vd->shield;
  804. WBUFW(buf,22) = vd->head_bottom;
  805. #endif
  806. #if PACKETVER < 20091103
  807. }
  808. #endif
  809. WBUFW(buf,24) = vd->head_top;
  810. WBUFW(buf,26) = vd->head_mid;
  811. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  812. { //The hell, why flags work like this?
  813. WBUFL(buf,22) = status_get_emblem_id(bl);
  814. WBUFL(buf,26) = status_get_guild_id(bl);
  815. }
  816. WBUFW(buf,28) = vd->hair_color;
  817. WBUFW(buf,30) = vd->cloth_color;
  818. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  819. #if PACKETVER < 20091103
  820. if (type&&spawn) { //End of packet 0x7c
  821. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  822. WBUFB(buf,35) = vd->sex;
  823. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  824. WBUFB(buf,39) = 0;
  825. WBUFB(buf,40) = 0;
  826. return packet_len(0x7c);
  827. }
  828. #endif
  829. #if PACKETVER >= 20110111
  830. WBUFW(buf,34) = vd->robe;
  831. offset+= 2;
  832. buf = WBUFP(buffer,offset);
  833. #endif
  834. WBUFL(buf,34) = status_get_guild_id(bl);
  835. WBUFW(buf,38) = status_get_emblem_id(bl);
  836. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  837. #if PACKETVER >= 20091103
  838. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  839. offset+=2;
  840. buf = WBUFP(buffer,offset);
  841. #elif PACKETVER >= 7
  842. if (!type) {
  843. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  844. offset+=2;
  845. buf = WBUFP(buffer,offset);
  846. } else
  847. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  848. #else
  849. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  850. #endif
  851. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  852. WBUFB(buf,45) = vd->sex;
  853. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  854. WBUFB(buf,49) = (sd)? 5 : 0;
  855. WBUFB(buf,50) = (sd)? 5 : 0;
  856. if (!spawn) {
  857. WBUFB(buf,51) = vd->dead_sit;
  858. offset++;
  859. buf = WBUFP(buffer,offset);
  860. }
  861. WBUFW(buf,51) = clif_setlevel(bl);
  862. #if PACKETVER < 20091103
  863. if (type) //End for non-player packet
  864. return packet_len(WBUFW(buffer,0));
  865. #endif
  866. #if PACKETVER >= 20080102
  867. WBUFW(buf,53) = sd?sd->user_font:0;
  868. #endif
  869. #if PACKETVER >= 20091103
  870. strcpy((char*)WBUFP(buf,55), name);
  871. return WBUFW(buffer,2);
  872. #else
  873. return packet_len(WBUFW(buffer,0));
  874. #endif
  875. }
  876. /*==========================================
  877. * Prepares 'unit walking' packet
  878. *------------------------------------------*/
  879. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  880. {
  881. struct map_session_data* sd;
  882. struct status_change* sc = status_get_sc(bl);
  883. struct view_data* vd = status_get_viewdata(bl);
  884. unsigned char* buf = WBUFP(buffer,0);
  885. #if PACKETVER >= 7
  886. unsigned short offset = 0;
  887. #endif
  888. #if PACKETVER >= 20091103
  889. const char *name;
  890. #endif
  891. sd = BL_CAST(BL_PC, bl);
  892. #if PACKETVER < 4
  893. WBUFW(buf, 0) = 0x7b;
  894. #elif PACKETVER < 7
  895. WBUFW(buf, 0) = 0x1da;
  896. #elif PACKETVER < 20080102
  897. WBUFW(buf, 0) = 0x22c;
  898. #elif PACKETVER < 20091103
  899. WBUFW(buf, 0) = 0x2ec;
  900. #elif PACKETVER < 20101124
  901. WBUFW(buf, 0) = 0x7f7;
  902. #else
  903. WBUFW(buf, 0) = 0x856;
  904. #endif
  905. #if PACKETVER >= 20091103
  906. name = status_get_name(bl);
  907. #if PACKETVER < 20110111
  908. WBUFW(buf, 2) = 69+strlen(name);
  909. #else
  910. WBUFW(buf, 2) = 71+strlen(name);
  911. #endif
  912. offset+=2;
  913. buf = WBUFP(buffer,offset);
  914. #endif
  915. #if PACKETVER >= 20071106
  916. WBUFB(buf, 2) = clif_bl_type(bl);
  917. offset++;
  918. buf = WBUFP(buffer,offset);
  919. #endif
  920. WBUFL(buf, 2) = bl->id;
  921. WBUFW(buf, 6) = status_get_speed(bl);
  922. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  923. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  924. #if PACKETVER < 7
  925. WBUFW(buf,12) = (sc)? sc->option : 0;
  926. #else
  927. WBUFL(buf,12) = (sc)? sc->option : 0;
  928. offset+=2; //Shift the rest of elements by 2 bytes.
  929. buf = WBUFP(buffer,offset);
  930. #endif
  931. WBUFW(buf,14) = vd->class_;
  932. WBUFW(buf,16) = vd->hair_style;
  933. WBUFW(buf,18) = vd->weapon;
  934. #if PACKETVER < 4
  935. WBUFW(buf,20) = vd->head_bottom;
  936. WBUFL(buf,22) = gettick();
  937. WBUFW(buf,26) = vd->shield;
  938. #else
  939. WBUFW(buf,20) = vd->shield;
  940. WBUFW(buf,22) = vd->head_bottom;
  941. WBUFL(buf,24) = gettick();
  942. #endif
  943. WBUFW(buf,28) = vd->head_top;
  944. WBUFW(buf,30) = vd->head_mid;
  945. WBUFW(buf,32) = vd->hair_color;
  946. WBUFW(buf,34) = vd->cloth_color;
  947. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  948. #if PACKETVER >= 20110111
  949. WBUFW(buf,38) = vd->robe;
  950. offset+= 2;
  951. buf = WBUFP(buffer,offset);
  952. #endif
  953. WBUFL(buf,38) = status_get_guild_id(bl);
  954. WBUFW(buf,42) = status_get_emblem_id(bl);
  955. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  956. #if PACKETVER < 7
  957. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  958. #else
  959. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  960. offset+=2; //Shift the rest of elements by 2 bytes.
  961. buf = WBUFP(buffer,offset);
  962. #endif
  963. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  964. WBUFB(buf,49) = vd->sex;
  965. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  966. WBUFB(buf,56) = (sd)? 5 : 0;
  967. WBUFB(buf,57) = (sd)? 5 : 0;
  968. WBUFW(buf,58) = clif_setlevel(bl);
  969. #if PACKETVER >= 20080102
  970. WBUFW(buf,60) = sd?sd->user_font:0;
  971. #endif
  972. #if PACKETVER >= 20091103
  973. strcpy((char*)WBUFP(buf,62), name);
  974. return WBUFW(buffer,2);
  975. #else
  976. return packet_len(WBUFW(buffer,0));
  977. #endif
  978. }
  979. //Modifies the buffer for disguise characters and sends it to self.
  980. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  981. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  982. {
  983. #if PACKETVER >= 20091103
  984. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  985. WBUFL(buf,5)=-bl->id;
  986. #elif PACKETVER >= 20071106
  987. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  988. WBUFL(buf,3)=-bl->id;
  989. #else
  990. WBUFL(buf,2)=-bl->id;
  991. #endif
  992. clif_send(buf, len, bl, SELF);
  993. }
  994. /*==========================================
  995. * Acronym for 'clif_mob_class_change' used to tell clients around the monster that it's identity changed
  996. * for example, it's run when a pupa transforms into a creamy.
  997. *------------------------------------------*/
  998. int clif_class_change(struct block_list *bl,int class_,int type)
  999. {
  1000. unsigned char buf[16];
  1001. nullpo_ret(bl);
  1002. if(!pcdb_checkid(class_)) {
  1003. WBUFW(buf,0)=0x1b0;
  1004. WBUFL(buf,2)=bl->id;
  1005. WBUFB(buf,6)=type;
  1006. WBUFL(buf,7)=class_;
  1007. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1008. }
  1009. return 0;
  1010. }
  1011. /*==========================================
  1012. * Server tells client to display (sd->spiritball) amount of spiritballs on target of account id (sd->bl.id)
  1013. *------------------------------------------*/
  1014. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1015. {
  1016. WFIFOHEAD(fd, packet_len(0x1e1));
  1017. WFIFOW(fd,0)=0x1e1;
  1018. WFIFOL(fd,2)=sd->bl.id;
  1019. WFIFOW(fd,6)=sd->spiritball;
  1020. WFIFOSET(fd, packet_len(0x1e1));
  1021. }
  1022. /*==========================================
  1023. * Run when player changes map / refreshes
  1024. * Tells its client to display all weather settings being used by this map
  1025. *------------------------------------------*/
  1026. static void clif_weather_check(struct map_session_data *sd)
  1027. {
  1028. int m = sd->bl.m, fd = sd->fd;
  1029. if (map[m].flag.snow
  1030. || map[m].flag.clouds
  1031. || map[m].flag.fog
  1032. || map[m].flag.fireworks
  1033. || map[m].flag.sakura
  1034. || map[m].flag.leaves
  1035. /**
  1036. * No longer available, keeping here just in case it's back someday. [Ind]
  1037. **/
  1038. //|| map[m].flag.rain
  1039. || map[m].flag.clouds2)
  1040. {
  1041. if (map[m].flag.snow)
  1042. clif_specialeffect_single(&sd->bl, 162, fd);
  1043. if (map[m].flag.clouds)
  1044. clif_specialeffect_single(&sd->bl, 233, fd);
  1045. if (map[m].flag.clouds2)
  1046. clif_specialeffect_single(&sd->bl, 516, fd);
  1047. if (map[m].flag.fog)
  1048. clif_specialeffect_single(&sd->bl, 515, fd);
  1049. if (map[m].flag.fireworks) {
  1050. clif_specialeffect_single(&sd->bl, 297, fd);
  1051. clif_specialeffect_single(&sd->bl, 299, fd);
  1052. clif_specialeffect_single(&sd->bl, 301, fd);
  1053. }
  1054. if (map[m].flag.sakura)
  1055. clif_specialeffect_single(&sd->bl, 163, fd);
  1056. if (map[m].flag.leaves)
  1057. clif_specialeffect_single(&sd->bl, 333, fd);
  1058. /**
  1059. * No longer available, keeping here just in case it's back someday. [Ind]
  1060. **/
  1061. //if (map[m].flag.rain)
  1062. // clif_specialeffect_single(&sd->bl, 161, fd);
  1063. }
  1064. }
  1065. /**
  1066. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1067. **/
  1068. void clif_weather(int m)
  1069. {
  1070. struct s_mapiterator* iter;
  1071. struct map_session_data *sd=NULL;
  1072. iter = mapit_getallusers();
  1073. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1074. {
  1075. if( sd->bl.m == m )
  1076. clif_weather_check(sd);
  1077. }
  1078. mapit_free(iter);
  1079. }
  1080. /**
  1081. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1082. **/
  1083. int clif_spawn(struct block_list *bl)
  1084. {
  1085. unsigned char buf[128];
  1086. struct view_data *vd;
  1087. int len;
  1088. vd = status_get_viewdata(bl);
  1089. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1090. return 0;
  1091. len = clif_set_unit_idle(bl, buf,true);
  1092. clif_send(buf, len, bl, AREA_WOS);
  1093. if (disguised(bl))
  1094. clif_setdisguise(bl, buf, len);
  1095. if (vd->cloth_color)
  1096. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1097. switch (bl->type)
  1098. {
  1099. case BL_PC:
  1100. {
  1101. TBL_PC *sd = ((TBL_PC*)bl);
  1102. if (sd->spiritball > 0)
  1103. clif_spiritball(sd);
  1104. if(sd->state.size==2) // tiny/big players [Valaris]
  1105. clif_specialeffect(bl,423,AREA);
  1106. else if(sd->state.size==1)
  1107. clif_specialeffect(bl,421,AREA);
  1108. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1109. clif_sendbgemblem_area(sd);
  1110. if( sd->sc.option&OPTION_MOUNTING ) {
  1111. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1112. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1113. }
  1114. }
  1115. break;
  1116. case BL_MOB:
  1117. {
  1118. TBL_MOB *md = ((TBL_MOB*)bl);
  1119. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1120. clif_specialeffect(&md->bl,423,AREA);
  1121. else if(md->special_state.size==1)
  1122. clif_specialeffect(&md->bl,421,AREA);
  1123. }
  1124. break;
  1125. case BL_NPC:
  1126. {
  1127. TBL_NPC *nd = ((TBL_NPC*)bl);
  1128. if( nd->size == 2 )
  1129. clif_specialeffect(&nd->bl,423,AREA);
  1130. else if( nd->size == 1 )
  1131. clif_specialeffect(&nd->bl,421,AREA);
  1132. }
  1133. break;
  1134. case BL_PET:
  1135. if (vd->head_bottom)
  1136. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1137. break;
  1138. }
  1139. return 0;
  1140. }
  1141. //[orn]
  1142. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1143. {
  1144. struct status_data *status;
  1145. unsigned char buf[128];
  1146. nullpo_ret(hd);
  1147. status = &hd->battle_status;
  1148. memset(buf,0,packet_len(0x22e));
  1149. WBUFW(buf,0)=0x22e;
  1150. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1151. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1152. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1153. WBUFW(buf,27)=hd->homunculus.level;
  1154. WBUFW(buf,29)=hd->homunculus.hunger;
  1155. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1156. WBUFW(buf,33)=0; // equip id
  1157. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1158. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1159. WBUFW(buf,39)=status->hit;
  1160. if (battle_config.hom_setting&0x10)
  1161. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1162. else
  1163. WBUFW(buf,41)=status->cri/10;
  1164. WBUFW(buf,43)=status->def + status->vit ;
  1165. WBUFW(buf,45)=status->mdef;
  1166. WBUFW(buf,47)=status->flee;
  1167. WBUFW(buf,49)=(flag)?0:status->amotion;
  1168. if (status->max_hp > INT16_MAX) {
  1169. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1170. WBUFW(buf,53) = 100;
  1171. } else {
  1172. WBUFW(buf,51)=status->hp;
  1173. WBUFW(buf,53)=status->max_hp;
  1174. }
  1175. if (status->max_sp > INT16_MAX) {
  1176. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1177. WBUFW(buf,57) = 100;
  1178. } else {
  1179. WBUFW(buf,55)=status->sp;
  1180. WBUFW(buf,57)=status->max_sp;
  1181. }
  1182. WBUFL(buf,59)=hd->homunculus.exp;
  1183. WBUFL(buf,63)=hd->exp_next;
  1184. WBUFW(buf,67)=hd->homunculus.skillpts;
  1185. WBUFW(buf,69)=status_get_range(&hd->bl);
  1186. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1187. return 0;
  1188. }
  1189. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1190. { //[orn]
  1191. int fd = sd->fd;
  1192. WFIFOHEAD(fd, packet_len(0x230));
  1193. nullpo_retv(sd->hd);
  1194. WFIFOW(fd,0)=0x230;
  1195. WFIFOW(fd,2)=type; // FIXME: This is actually <type>.B <state>.B
  1196. WFIFOL(fd,4)=sd->hd->bl.id;
  1197. WFIFOL(fd,8)=param;
  1198. WFIFOSET(fd,packet_len(0x230));
  1199. return;
  1200. }
  1201. int clif_homskillinfoblock(struct map_session_data *sd)
  1202. { //[orn]
  1203. struct homun_data *hd;
  1204. int fd = sd->fd;
  1205. int i,j,len=4,id;
  1206. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1207. hd = sd->hd;
  1208. if ( !hd )
  1209. return 0 ;
  1210. WFIFOW(fd,0)=0x235;
  1211. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1212. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1213. j = id - HM_SKILLBASE;
  1214. WFIFOW(fd,len ) = id;
  1215. WFIFOW(fd,len+2) = skill_get_inf(id);
  1216. WFIFOW(fd,len+4) = 0;
  1217. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1218. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1219. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1220. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1221. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1222. len+=37;
  1223. }
  1224. }
  1225. WFIFOW(fd,2)=len;
  1226. WFIFOSET(fd,len);
  1227. return 0;
  1228. }
  1229. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1230. { //[orn]
  1231. struct homun_data *hd;
  1232. int fd, skillid;
  1233. nullpo_retv(sd);
  1234. skillid = skill_num - HM_SKILLBASE;
  1235. fd=sd->fd;
  1236. hd=sd->hd;
  1237. WFIFOHEAD(fd, packet_len(0x239));
  1238. WFIFOW(fd,0) = 0x239;
  1239. WFIFOW(fd,2) = skill_num;
  1240. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1241. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1242. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1243. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1244. WFIFOSET(fd,packet_len(0x239));
  1245. return;
  1246. }
  1247. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1248. {
  1249. int fd=sd->fd;
  1250. WFIFOHEAD(fd,packet_len(0x22f));
  1251. WFIFOW(fd,0)=0x22f;
  1252. WFIFOB(fd,2)=fail;
  1253. WFIFOW(fd,3)=foodid;
  1254. WFIFOSET(fd,packet_len(0x22f));
  1255. return 0;
  1256. }
  1257. /*==========================================
  1258. *
  1259. *------------------------------------------*/
  1260. int clif_walkok(struct map_session_data *sd)
  1261. {
  1262. int fd=sd->fd;
  1263. WFIFOHEAD(fd, packet_len(0x87));
  1264. WFIFOW(fd,0)=0x87;
  1265. WFIFOL(fd,2)=gettick();
  1266. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1267. WFIFOSET(fd,packet_len(0x87));
  1268. return 0;
  1269. }
  1270. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1271. {
  1272. uint8 buf[128];
  1273. int len;
  1274. len = clif_set_unit_walking(bl,ud,buf);
  1275. clif_send(buf,len,bl,AREA_WOS);
  1276. if (disguised(bl))
  1277. clif_setdisguise(bl, buf, len);
  1278. if(vd->cloth_color)
  1279. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1280. switch(bl->type)
  1281. {
  1282. case BL_PC:
  1283. {
  1284. TBL_PC *sd = ((TBL_PC*)bl);
  1285. // clif_movepc(sd);
  1286. if(sd->state.size==2) // tiny/big players [Valaris]
  1287. clif_specialeffect(&sd->bl,423,AREA);
  1288. else if(sd->state.size==1)
  1289. clif_specialeffect(&sd->bl,421,AREA);
  1290. }
  1291. break;
  1292. case BL_MOB:
  1293. {
  1294. TBL_MOB *md = ((TBL_MOB*)bl);
  1295. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1296. clif_specialeffect(&md->bl,423,AREA);
  1297. else if(md->special_state.size==1)
  1298. clif_specialeffect(&md->bl,421,AREA);
  1299. }
  1300. break;
  1301. case BL_PET:
  1302. if( vd->head_bottom )
  1303. {// needed to display pet equip properly
  1304. clif_pet_equip_area((TBL_PET*)bl);
  1305. }
  1306. break;
  1307. }
  1308. return;
  1309. }
  1310. /// Move the unit (does nothing if the client has no info about the unit)
  1311. /// Note: unit must not be self
  1312. void clif_move(struct unit_data *ud)
  1313. {
  1314. unsigned char buf[16];
  1315. struct view_data* vd;
  1316. struct block_list* bl = ud->bl;
  1317. vd = status_get_viewdata(bl);
  1318. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1319. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1320. if (ud->state.speed_changed) {
  1321. // Since we don't know how to update the speed of other objects,
  1322. // use the old walk packet to update the data.
  1323. ud->state.speed_changed = 0;
  1324. clif_move2(bl, vd, ud);
  1325. return;
  1326. }
  1327. WBUFW(buf,0)=0x86;
  1328. WBUFL(buf,2)=bl->id;
  1329. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1330. WBUFL(buf,12)=gettick();
  1331. clif_send(buf, 16, bl, AREA_WOS);
  1332. if (disguised(bl))
  1333. {
  1334. WBUFL(buf,2)=-bl->id;
  1335. clif_send(buf, 16, bl, SELF);
  1336. }
  1337. }
  1338. /*==========================================
  1339. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1340. *------------------------------------------*/
  1341. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1342. {
  1343. struct map_session_data *sd = NULL;
  1344. //Remove player from map server
  1345. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1346. map_quit(sd);
  1347. return 0;
  1348. }
  1349. /*==========================================
  1350. *
  1351. *------------------------------------------*/
  1352. void clif_quitsave(int fd,struct map_session_data *sd)
  1353. {
  1354. if (!battle_config.prevent_logout ||
  1355. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1356. map_quit(sd);
  1357. else if (sd->fd)
  1358. { //Disassociate session from player (session is deleted after this function was called)
  1359. //And set a timer to make him quit later.
  1360. session[sd->fd]->session_data = NULL;
  1361. sd->fd = 0;
  1362. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1363. }
  1364. }
  1365. /*==========================================
  1366. *
  1367. *------------------------------------------*/
  1368. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1369. {
  1370. int fd;
  1371. nullpo_retv(sd);
  1372. fd = sd->fd;
  1373. WFIFOHEAD(fd,packet_len(0x91));
  1374. WFIFOW(fd,0) = 0x91;
  1375. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1376. WFIFOW(fd,18) = x;
  1377. WFIFOW(fd,20) = y;
  1378. WFIFOSET(fd,packet_len(0x91));
  1379. }
  1380. /*==========================================
  1381. * Tells the client to connect to another map-server
  1382. *------------------------------------------*/
  1383. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1384. {
  1385. int fd;
  1386. nullpo_retv(sd);
  1387. fd = sd->fd;
  1388. WFIFOHEAD(fd,packet_len(0x92));
  1389. WFIFOW(fd,0) = 0x92;
  1390. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1391. WFIFOW(fd,18) = x;
  1392. WFIFOW(fd,20) = y;
  1393. WFIFOL(fd,22) = htonl(ip);
  1394. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1395. WFIFOSET(fd,packet_len(0x92));
  1396. }
  1397. void clif_blown(struct block_list *bl)
  1398. {
  1399. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1400. // clif_fixpos(bl);
  1401. clif_slide(bl, bl->x, bl->y);
  1402. }
  1403. /// Visually moves(slides) a character to x,y. If the target cell
  1404. /// isn't walkable, the char doesn't move at all. If the char is
  1405. /// sitting it will stand up.
  1406. /// S 0088 <gid>.L <x>.W <y>.W
  1407. void clif_fixpos(struct block_list *bl)
  1408. {
  1409. unsigned char buf[10];
  1410. nullpo_retv(bl);
  1411. WBUFW(buf,0) = 0x88;
  1412. WBUFL(buf,2) = bl->id;
  1413. WBUFW(buf,6) = bl->x;
  1414. WBUFW(buf,8) = bl->y;
  1415. clif_send(buf, packet_len(0x88), bl, AREA);
  1416. if( disguised(bl) )
  1417. {
  1418. WBUFL(buf,2) = -bl->id;
  1419. clif_send(buf, packet_len(0x88), bl, SELF);
  1420. }
  1421. }
  1422. /*==========================================
  1423. *
  1424. *------------------------------------------*/
  1425. int clif_npcbuysell(struct map_session_data* sd, int id)
  1426. {
  1427. int fd;
  1428. nullpo_ret(sd);
  1429. fd=sd->fd;
  1430. WFIFOHEAD(fd, packet_len(0xc4));
  1431. WFIFOW(fd,0)=0xc4;
  1432. WFIFOL(fd,2)=id;
  1433. WFIFOSET(fd,packet_len(0xc4));
  1434. return 0;
  1435. }
  1436. /*==========================================
  1437. *
  1438. *------------------------------------------*/
  1439. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1440. {
  1441. int fd,i,c;
  1442. nullpo_ret(sd);
  1443. nullpo_ret(nd);
  1444. fd = sd->fd;
  1445. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1446. WFIFOW(fd,0) = 0xc6;
  1447. c = 0;
  1448. for( i = 0; i < nd->u.shop.count; i++ )
  1449. {
  1450. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1451. int val = nd->u.shop.shop_item[i].value;
  1452. if( id == NULL )
  1453. continue;
  1454. WFIFOL(fd, 4+c*11) = val;
  1455. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1456. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1457. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1458. c++;
  1459. }
  1460. WFIFOW(fd,2) = 4 + c*11;
  1461. WFIFOSET(fd,WFIFOW(fd,2));
  1462. return 0;
  1463. }
  1464. /*==========================================
  1465. *
  1466. *------------------------------------------*/
  1467. int clif_selllist(struct map_session_data *sd)
  1468. {
  1469. int fd,i,c=0,val;
  1470. nullpo_ret(sd);
  1471. fd=sd->fd;
  1472. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1473. WFIFOW(fd,0)=0xc7;
  1474. for( i = 0; i < MAX_INVENTORY; i++ )
  1475. {
  1476. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1477. {
  1478. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1479. continue;
  1480. if( sd->status.inventory[i].expire_time )
  1481. continue; // Cannot Sell Rental Items
  1482. val=sd->inventory_data[i]->value_sell;
  1483. if( val < 0 )
  1484. continue;
  1485. WFIFOW(fd,4+c*10)=i+2;
  1486. WFIFOL(fd,6+c*10)=val;
  1487. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1488. c++;
  1489. }
  1490. }
  1491. WFIFOW(fd,2)=c*10+4;
  1492. WFIFOSET(fd,WFIFOW(fd,2));
  1493. return 0;
  1494. }
  1495. /// Client behavior (dialog window):
  1496. /// - disable mouse targeting
  1497. /// - open the dialog window
  1498. /// - set npcid of dialog window (0 by default)
  1499. /// - if set to clear on next mes, clear contents
  1500. /// - append this text
  1501. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1502. {
  1503. int fd = sd->fd;
  1504. int slen = strlen(mes) + 9;
  1505. WFIFOHEAD(fd, slen);
  1506. WFIFOW(fd,0)=0xb4;
  1507. WFIFOW(fd,2)=slen;
  1508. WFIFOL(fd,4)=npcid;
  1509. strcpy((char*)WFIFOP(fd,8),mes);
  1510. WFIFOSET(fd,WFIFOW(fd,2));
  1511. return 0;
  1512. }
  1513. /// Client behavior (dialog window):
  1514. /// - disable mouse targeting
  1515. /// - open the dialog window
  1516. /// - add 'next' button
  1517. /// When 'next' is pressed:
  1518. /// - S 00B9 <npcid of dialog window>.L
  1519. /// - set to clear on next mes
  1520. /// - remove 'next' button
  1521. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1522. {
  1523. int fd;
  1524. nullpo_ret(sd);
  1525. fd=sd->fd;
  1526. WFIFOHEAD(fd, packet_len(0xb5));
  1527. WFIFOW(fd,0)=0xb5;
  1528. WFIFOL(fd,2)=npcid;
  1529. WFIFOSET(fd,packet_len(0xb5));
  1530. return 0;
  1531. }
  1532. /// Client behavior:
  1533. /// - if dialog window is open:
  1534. /// - remove 'next' button
  1535. /// - add 'close' button
  1536. /// - else:
  1537. /// - enable mouse targeting
  1538. /// - close the dialog window
  1539. /// - close the menu window
  1540. /// When 'close' is pressed:
  1541. /// - enable mouse targeting
  1542. /// - close the dialog window
  1543. /// - close the menu window
  1544. /// - S 0146 <npcid of dialog window>.L
  1545. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1546. {
  1547. int fd;
  1548. nullpo_ret(sd);
  1549. fd=sd->fd;
  1550. WFIFOHEAD(fd, packet_len(0xb6));
  1551. WFIFOW(fd,0)=0xb6;
  1552. WFIFOL(fd,2)=npcid;
  1553. WFIFOSET(fd,packet_len(0xb6));
  1554. return 0;
  1555. }
  1556. /*==========================================
  1557. *
  1558. *------------------------------------------*/
  1559. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1560. {
  1561. unsigned char *buf;
  1562. int fd = sd->fd;
  1563. sd->state.using_fake_npc = 1;
  1564. WFIFOHEAD(fd, packet_len(0x78));
  1565. buf = WFIFOP(fd,0);
  1566. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1567. WBUFW(buf,0)=0x78;
  1568. #if PACKETVER >= 20071106
  1569. WBUFB(buf,2) = 0; //Unknown bit
  1570. buf = WFIFOP(fd,1);
  1571. #endif
  1572. WBUFL(buf,2)=npcid;
  1573. WBUFW(buf,14)=111;
  1574. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1575. WBUFB(buf,49)=5;
  1576. WBUFB(buf,50)=5;
  1577. WFIFOSET(fd, packet_len(0x78));
  1578. return;
  1579. }
  1580. /// Client behavior:
  1581. /// - disable mouse targeting
  1582. /// - close the menu window
  1583. /// - open the menu window
  1584. /// - add options to the menu (separated in the text by ":")
  1585. /// - set npcid of menu window
  1586. /// - if dialog window is open:
  1587. /// - remove 'next' button
  1588. /// When 'ok' is pressed:
  1589. /// - S 00B8 <npcid of menu window>.L <selected option>.B
  1590. /// - close the menu window
  1591. /// When 'cancel' is pressed:
  1592. /// - S 00B8 <npcid of menu window>.L <-1>.B
  1593. /// - enable mouse targeting
  1594. /// - close a bunch of windows...
  1595. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1596. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1597. /// TODO investigate behavior of other windows [FlavioJS]
  1598. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1599. {
  1600. int fd = sd->fd;
  1601. int slen = strlen(mes) + 8;
  1602. struct block_list *bl = NULL;
  1603. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1604. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1605. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1606. clif_sendfakenpc(sd, npcid);
  1607. WFIFOHEAD(fd, slen);
  1608. WFIFOW(fd,0)=0xb7;
  1609. WFIFOW(fd,2)=slen;
  1610. WFIFOL(fd,4)=npcid;
  1611. strcpy((char*)WFIFOP(fd,8),mes);
  1612. WFIFOSET(fd,WFIFOW(fd,2));
  1613. return 0;
  1614. }
  1615. /// Client behavior (inputnum window):
  1616. /// - if npcid exists in the client:
  1617. /// - open the inputnum window
  1618. /// - set npcid of inputnum window
  1619. /// When 'ok' is pressed:
  1620. /// - if inputnum window has text:
  1621. /// - if npcid exists in the client:
  1622. /// - S 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1623. /// - close inputnum window
  1624. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1625. {
  1626. int fd;
  1627. struct block_list *bl = NULL;
  1628. nullpo_ret(sd);
  1629. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1630. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1631. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1632. clif_sendfakenpc(sd, npcid);
  1633. fd=sd->fd;
  1634. WFIFOHEAD(fd, packet_len(0x142));
  1635. WFIFOW(fd,0)=0x142;
  1636. WFIFOL(fd,2)=npcid;
  1637. WFIFOSET(fd,packet_len(0x142));
  1638. return 0;
  1639. }
  1640. /// Client behavior (inputstr window):
  1641. /// - if npcid is 0 or npcid exists in the client:
  1642. /// - open the inputstr window
  1643. /// - set npcid of inputstr window
  1644. /// When 'ok' is pressed:
  1645. /// - if inputstr window has text and isn't an insult(manner.txt):
  1646. /// - if npcid is 0 or npcid exists in the client:
  1647. /// - S 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1648. /// - close inputstr window
  1649. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1650. {
  1651. int fd;
  1652. struct block_list *bl = NULL;
  1653. nullpo_ret(sd);
  1654. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1655. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1656. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1657. clif_sendfakenpc(sd, npcid);
  1658. fd=sd->fd;
  1659. WFIFOHEAD(fd, packet_len(0x1d4));
  1660. WFIFOW(fd,0)=0x1d4;
  1661. WFIFOL(fd,2)=npcid;
  1662. WFIFOSET(fd,packet_len(0x1d4));
  1663. return 0;
  1664. }
  1665. /// npc_id is ignored in the client
  1666. /// type=2 : Remove viewpoint
  1667. /// type=other : Show viewpoint
  1668. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1669. {
  1670. int fd;
  1671. nullpo_ret(sd);
  1672. fd=sd->fd;
  1673. WFIFOHEAD(fd, packet_len(0x144));
  1674. WFIFOW(fd,0)=0x144;
  1675. WFIFOL(fd,2)=npc_id;
  1676. WFIFOL(fd,6)=type;
  1677. WFIFOL(fd,10)=x;
  1678. WFIFOL(fd,14)=y;
  1679. WFIFOB(fd,18)=id;
  1680. WFIFOL(fd,19)=color;
  1681. WFIFOSET(fd,packet_len(0x144));
  1682. return 0;
  1683. }
  1684. /*==========================================
  1685. * Server tells client to display cutin of name 'image' to client, in position 'type' (255, etc)
  1686. *------------------------------------------*/
  1687. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1688. {
  1689. int fd;
  1690. nullpo_ret(sd);
  1691. fd=sd->fd;
  1692. WFIFOHEAD(fd, packet_len(0x1b3));
  1693. WFIFOW(fd,0)=0x1b3;
  1694. strncpy((char*)WFIFOP(fd,2),image,64);
  1695. WFIFOB(fd,66)=type;
  1696. WFIFOSET(fd,packet_len(0x1b3));
  1697. return 0;
  1698. }
  1699. /*==========================================
  1700. * Fills in card data from the given item and into the buffer. [Skotlex]
  1701. *------------------------------------------*/
  1702. static void clif_addcards(unsigned char* buf, struct item* item)
  1703. {
  1704. int i=0,j;
  1705. if( item == NULL ) { //Blank data
  1706. WBUFW(buf,0) = 0;
  1707. WBUFW(buf,2) = 0;
  1708. WBUFW(buf,4) = 0;
  1709. WBUFW(buf,6) = 0;
  1710. return;
  1711. }
  1712. if( item->card[0] == CARD0_PET ) { //pet eggs
  1713. WBUFW(buf,0) = 0;
  1714. WBUFW(buf,2) = 0;
  1715. WBUFW(buf,4) = 0;
  1716. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1717. return;
  1718. }
  1719. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1720. WBUFW(buf,0) = item->card[0];
  1721. WBUFW(buf,2) = item->card[1];
  1722. WBUFW(buf,4) = item->card[2];
  1723. WBUFW(buf,6) = item->card[3];
  1724. return;
  1725. }
  1726. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1727. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1728. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1729. //Normal items.
  1730. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1731. WBUFW(buf,0) = j;
  1732. else
  1733. WBUFW(buf,0) = item->card[i];
  1734. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1735. WBUFW(buf,2) = j;
  1736. else
  1737. WBUFW(buf,2) = item->card[i];
  1738. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1739. WBUFW(buf,4) = j;
  1740. else
  1741. WBUFW(buf,4) = item->card[i];
  1742. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1743. WBUFW(buf,6) = j;
  1744. else
  1745. WBUFW(buf,6) = item->card[i];
  1746. }
  1747. /*==========================================
  1748. * Server tells client he got item of index 'n' and amount 'amount',
  1749. * when 'fail' is 1 it tells the client it failed to receive said item
  1750. *------------------------------------------*/
  1751. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1752. {
  1753. int fd;
  1754. #if PACKETVER < 20071002
  1755. const int cmd = 0xa0;
  1756. #else
  1757. const int cmd = 0x2d4;
  1758. #endif
  1759. nullpo_ret(sd);
  1760. fd = sd->fd;
  1761. if( !session_isActive(fd) ) //Sasuke-
  1762. return 0;
  1763. WFIFOHEAD(fd,packet_len(cmd));
  1764. if( fail )
  1765. {
  1766. WFIFOW(fd,0)=cmd;
  1767. WFIFOW(fd,2)=n+2;
  1768. WFIFOW(fd,4)=amount;
  1769. WFIFOW(fd,6)=0;
  1770. WFIFOB(fd,8)=0;
  1771. WFIFOB(fd,9)=0;
  1772. WFIFOB(fd,10)=0;
  1773. WFIFOW(fd,11)=0;
  1774. WFIFOW(fd,13)=0;
  1775. WFIFOW(fd,15)=0;
  1776. WFIFOW(fd,17)=0;
  1777. WFIFOW(fd,19)=0;
  1778. WFIFOB(fd,21)=0;
  1779. WFIFOB(fd,22)=fail;
  1780. #if PACKETVER >= 20071002
  1781. WFIFOW(fd,23)=0;
  1782. WFIFOW(fd,25)=0;
  1783. WFIFOW(fd,27)=0;
  1784. #endif
  1785. }
  1786. else
  1787. {
  1788. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1789. return 1;
  1790. WFIFOW(fd,0)=cmd;
  1791. WFIFOW(fd,2)=n+2;
  1792. WFIFOW(fd,4)=amount;
  1793. if (sd->inventory_data[n]->view_id > 0)
  1794. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1795. else
  1796. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1797. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1798. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1799. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1800. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1801. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1802. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1803. WFIFOB(fd,22)=fail;
  1804. #if PACKETVER >= 20071002
  1805. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1806. WFIFOW(fd,27)=0;
  1807. #endif
  1808. }
  1809. WFIFOSET(fd,packet_len(cmd));
  1810. return 0;
  1811. }
  1812. /*==========================================
  1813. *
  1814. *------------------------------------------*/
  1815. int clif_dropitem(struct map_session_data *sd,int n,int amount)
  1816. {
  1817. int fd;
  1818. nullpo_ret(sd);
  1819. fd=sd->fd;
  1820. WFIFOHEAD(fd, packet_len(0xaf));
  1821. WFIFOW(fd,0)=0xaf;
  1822. WFIFOW(fd,2)=n+2;
  1823. WFIFOW(fd,4)=amount;
  1824. WFIFOSET(fd,packet_len(0xaf));
  1825. return 0;
  1826. }
  1827. /*==========================================
  1828. * Deletes an item from your inventory.
  1829. * Reason values:
  1830. * 0 - Normal
  1831. * 1 - Item used for a skill
  1832. * 2 - Refine failed
  1833. * 3 - Material changed
  1834. * 4 - Moved to storage
  1835. * 5 - Moved to cart
  1836. * 6 - Item sold
  1837. * 7 - Item dropped
  1838. *------------------------------------------*/
  1839. int clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1840. {
  1841. #if PACKETVER < 20091117
  1842. return clif_dropitem(sd,n,amount);
  1843. #else
  1844. int fd;
  1845. nullpo_ret(sd);
  1846. if (reason == 7)
  1847. return clif_dropitem(sd,n,amount);
  1848. fd=sd->fd;
  1849. WFIFOHEAD(fd, packet_len(0x7fa));
  1850. WFIFOW(fd,0)=0x7fa;
  1851. WFIFOW(fd,2)=reason;
  1852. WFIFOW(fd,4)=n+2;
  1853. WFIFOW(fd,6)=amount;
  1854. WFIFOSET(fd,packet_len(0x7fa));
  1855. return 0;
  1856. #endif
  1857. }
  1858. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1859. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1860. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1861. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1862. {
  1863. if (id->view_id > 0)
  1864. WBUFW(buf,n)=id->view_id;
  1865. else
  1866. WBUFW(buf,n)=i->nameid;
  1867. WBUFB(buf,n+2)=itemtype(id->type);
  1868. WBUFB(buf,n+3)=i->identify;
  1869. if (equip >= 0) { //Equippable item
  1870. WBUFW(buf,n+4)=equip;
  1871. WBUFW(buf,n+6)=i->equip;
  1872. WBUFB(buf,n+8)=i->attribute;
  1873. WBUFB(buf,n+9)=i->refine;
  1874. } else { //Stackable item.
  1875. WBUFW(buf,n+4)=i->amount;
  1876. if (equip == -2 && id->equip == EQP_AMMO)
  1877. WBUFW(buf,n+6)=EQP_AMMO;
  1878. else
  1879. WBUFW(buf,n+6)=0;
  1880. }
  1881. }
  1882. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1883. void clif_inventorylist(struct map_session_data *sd)
  1884. {
  1885. int i,n,ne,arrow=-1;
  1886. unsigned char *buf;
  1887. unsigned char *bufe;
  1888. #if PACKETVER < 5
  1889. const int s = 10; //Entry size.
  1890. #elif PACKETVER < 20080102
  1891. const int s = 18;
  1892. #else
  1893. const int s = 22;
  1894. #endif
  1895. #if PACKETVER < 20071002
  1896. const int se = 20;
  1897. #elif PACKETVER < 20100629
  1898. const int se = 26;
  1899. #else
  1900. const int se = 28;
  1901. #endif
  1902. buf = (unsigned char*)aMallocA(MAX_INVENTORY * s + 4);
  1903. bufe = (unsigned char*)aMallocA(MAX_INVENTORY * se + 4);
  1904. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  1905. {
  1906. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  1907. continue;
  1908. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  1909. { //Non-stackable (Equippable)
  1910. WBUFW(bufe,ne*se+4)=i+2;
  1911. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1912. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  1913. #if PACKETVER >= 20071002
  1914. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  1915. WBUFW(bufe,ne*se+28)=0; //Unknown
  1916. #endif
  1917. #if PACKETVER >= 20100629
  1918. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  1919. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  1920. else
  1921. WBUFW(bufe,ne*se+30)=0;
  1922. #endif
  1923. ne++;
  1924. }
  1925. else
  1926. { //Stackable.
  1927. WBUFW(buf,n*s+4)=i+2;
  1928. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1929. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  1930. arrow=i;
  1931. #if PACKETVER >= 5
  1932. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1933. #endif
  1934. #if PACKETVER >= 20080102
  1935. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  1936. #endif
  1937. n++;
  1938. }
  1939. }
  1940. if( n )
  1941. {
  1942. #if PACKETVER < 5
  1943. WBUFW(buf,0)=0xa3;
  1944. #elif PACKETVER < 20080102
  1945. WBUFW(buf,0)=0x1ee;
  1946. #else
  1947. WBUFW(buf,0)=0x2e8;
  1948. #endif
  1949. WBUFW(buf,2)=4+n*s;
  1950. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1951. }
  1952. if( arrow >= 0 )
  1953. clif_arrowequip(sd,arrow);
  1954. if( ne )
  1955. {
  1956. #if PACKETVER < 20071002
  1957. WBUFW(bufe,0)=0xa4;
  1958. #else
  1959. WBUFW(bufe,0)=0x2d0;
  1960. #endif
  1961. WBUFW(bufe,2)=4+ne*se;
  1962. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1963. }
  1964. if( buf ) aFree(buf);
  1965. if( bufe ) aFree(bufe);
  1966. }
  1967. //Required when items break/get-repaired. Only sends equippable item list.
  1968. void clif_equiplist(struct map_session_data *sd)
  1969. {
  1970. int i,n,fd = sd->fd;
  1971. unsigned char *buf;
  1972. #if PACKETVER < 20071002
  1973. const int cmd = 20;
  1974. #elif PACKETVER < 20100629
  1975. const int cmd = 26;
  1976. #else
  1977. const int cmd = 28;
  1978. #endif
  1979. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  1980. buf = WFIFOP(fd,0);
  1981. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1982. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1983. continue;
  1984. if(itemdb_isstackable2(sd->inventory_data[i]))
  1985. continue;
  1986. //Equippable
  1987. WBUFW(buf,n*cmd+4)=i+2;
  1988. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1989. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  1990. #if PACKETVER >= 20071002
  1991. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  1992. WBUFW(buf,n*cmd+28)=0; //Unknown
  1993. #endif
  1994. #if PACKETVER >= 20100629
  1995. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  1996. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  1997. else
  1998. WBUFW(buf,n*cmd+30)=0;
  1999. #endif
  2000. n++;
  2001. }
  2002. if (n) {
  2003. #if PACKETVER < 20071002
  2004. WBUFW(buf,0)=0xa4;
  2005. #else
  2006. WBUFW(buf,0)=0x2d0;
  2007. #endif
  2008. WBUFW(buf,2)=4+n*cmd;
  2009. WFIFOSET(fd,WFIFOW(fd,2));
  2010. }
  2011. }
  2012. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2013. {
  2014. struct item_data *id;
  2015. int i,n,ne;
  2016. unsigned char *buf;
  2017. unsigned char *bufe;
  2018. #if PACKETVER < 5
  2019. const int s = 10; //Entry size.
  2020. #elif PACKETVER < 20080102
  2021. const int s = 18;
  2022. #else
  2023. const int s = 22;
  2024. #endif
  2025. #if PACKETVER < 20071002
  2026. const int cmd = 20;
  2027. #elif PACKETVER < 20100629
  2028. const int cmd = 26;
  2029. #else
  2030. const int cmd = 28;
  2031. #endif
  2032. buf = (unsigned char*)aMallocA(items_length * s + 4);
  2033. bufe = (unsigned char*)aMallocA(items_length * cmd + 4);
  2034. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2035. {
  2036. if( items[i].nameid <= 0 )
  2037. continue;
  2038. id = itemdb_search(items[i].nameid);
  2039. if( !itemdb_isstackable2(id) )
  2040. { //Equippable
  2041. WBUFW(bufe,ne*cmd+4)=i+1;
  2042. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2043. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2044. #if PACKETVER >= 20071002
  2045. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2046. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2047. #endif
  2048. ne++;
  2049. }
  2050. else
  2051. { //Stackable
  2052. WBUFW(buf,n*s+4)=i+1;
  2053. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2054. #if PACKETVER >= 5
  2055. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2056. #endif
  2057. #if PACKETVER >= 20080102
  2058. WBUFL(buf,n*s+22)=items[i].expire_time;
  2059. #endif
  2060. n++;
  2061. }
  2062. }
  2063. if( n )
  2064. {
  2065. #if PACKETVER < 5
  2066. WBUFW(buf,0)=0xa5;
  2067. #elif PACKETVER < 20080102
  2068. WBUFW(buf,0)=0x1f0;
  2069. #else
  2070. WBUFW(buf,0)=0x2ea;
  2071. #endif
  2072. WBUFW(buf,2)=4+n*s;
  2073. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2074. }
  2075. if( ne )
  2076. {
  2077. #if PACKETVER < 20071002
  2078. WBUFW(bufe,0)=0xa6;
  2079. #else
  2080. WBUFW(bufe,0)=0x2d1;
  2081. #endif
  2082. WBUFW(bufe,2)=4+ne*cmd;
  2083. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2084. }
  2085. if( buf ) aFree(buf);
  2086. if( bufe ) aFree(bufe);
  2087. }
  2088. void clif_cartlist(struct map_session_data *sd)
  2089. {
  2090. struct item_data *id;
  2091. int i,n,ne;
  2092. unsigned char *buf;
  2093. unsigned char *bufe;
  2094. #if PACKETVER < 5
  2095. const int s = 10; //Entry size.
  2096. #elif PACKETVER < 20080102
  2097. const int s = 18;
  2098. #else
  2099. const int s = 22;
  2100. #endif
  2101. #if PACKETVER < 20071002
  2102. const int cmd = 20;
  2103. #elif PACKETVER < 20100629
  2104. const int cmd = 26;
  2105. #else
  2106. const int cmd = 28;
  2107. #endif
  2108. buf = (unsigned char*)aMallocA(MAX_CART * s + 4);
  2109. bufe = (unsigned char*)aMallocA(MAX_CART * cmd + 4);
  2110. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2111. {
  2112. if( sd->status.cart[i].nameid <= 0 )
  2113. continue;
  2114. id = itemdb_search(sd->status.cart[i].nameid);
  2115. if( !itemdb_isstackable2(id) )
  2116. { //Equippable
  2117. WBUFW(bufe,ne*cmd+4)=i+2;
  2118. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2119. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2120. #if PACKETVER >= 20071002
  2121. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2122. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2123. #endif
  2124. ne++;
  2125. }
  2126. else
  2127. { //Stackable
  2128. WBUFW(buf,n*s+4)=i+2;
  2129. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2130. #if PACKETVER >= 5
  2131. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2132. #endif
  2133. #if PACKETVER >= 20080102
  2134. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2135. #endif
  2136. n++;
  2137. }
  2138. }
  2139. if( n )
  2140. {
  2141. #if PACKETVER < 5
  2142. WBUFW(buf,0)=0x123;
  2143. #elif PACKETVER < 20080102
  2144. WBUFW(buf,0)=0x1ef;
  2145. #else
  2146. WBUFW(buf,0)=0x2e9;
  2147. #endif
  2148. WBUFW(buf,2)=4+n*s;
  2149. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2150. }
  2151. if( ne )
  2152. {
  2153. #if PACKETVER < 20071002
  2154. WBUFW(bufe,0)=0x122;
  2155. #else
  2156. WBUFW(bufe,0)=0x2d2;
  2157. #endif
  2158. WBUFW(bufe,2)=4+ne*cmd;
  2159. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2160. }
  2161. if( buf ) aFree(buf);
  2162. if( bufe ) aFree(bufe);
  2163. }
  2164. /// Client behaviour:
  2165. /// Closes the cart storage and removes all it's items from memory.
  2166. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2167. void clif_clearcart(int fd)
  2168. {
  2169. WFIFOHEAD(fd, packet_len(0x12b));
  2170. WFIFOW(fd,0) = 0x12b;
  2171. WFIFOSET(fd, packet_len(0x12b));
  2172. }
  2173. // Guild XY locators [Valaris]
  2174. int clif_guild_xy(struct map_session_data *sd)
  2175. {
  2176. unsigned char buf[10];
  2177. nullpo_ret(sd);
  2178. WBUFW(buf,0)=0x1eb;
  2179. WBUFL(buf,2)=sd->status.account_id;
  2180. WBUFW(buf,6)=sd->bl.x;
  2181. WBUFW(buf,8)=sd->bl.y;
  2182. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2183. return 0;
  2184. }
  2185. /*==========================================
  2186. * Sends x/y dot to a single fd. [Skotlex]
  2187. *------------------------------------------*/
  2188. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2189. {
  2190. if( sd->bg_id )
  2191. return 0;
  2192. WFIFOHEAD(fd,packet_len(0x1eb));
  2193. WFIFOW(fd,0)=0x1eb;
  2194. WFIFOL(fd,2)=sd->status.account_id;
  2195. WFIFOW(fd,6)=sd->bl.x;
  2196. WFIFOW(fd,8)=sd->bl.y;
  2197. WFIFOSET(fd,packet_len(0x1eb));
  2198. return 0;
  2199. }
  2200. // Guild XY locators [Valaris]
  2201. int clif_guild_xy_remove(struct map_session_data *sd)
  2202. {
  2203. unsigned char buf[10];
  2204. nullpo_ret(sd);
  2205. WBUFW(buf,0)=0x1eb;
  2206. WBUFL(buf,2)=sd->status.account_id;
  2207. WBUFW(buf,6)=-1;
  2208. WBUFW(buf,8)=-1;
  2209. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2210. return 0;
  2211. }
  2212. /*==========================================
  2213. * Server tells client that data 'type' has changed and sends it's new value
  2214. * For example, when server updates the client max weight, say, due to higher STR,
  2215. * It calls this function with SP_MAXWEIGHT type
  2216. *------------------------------------------*/
  2217. int clif_updatestatus(struct map_session_data *sd,int type)
  2218. {
  2219. int fd,len=8;
  2220. nullpo_ret(sd);
  2221. fd=sd->fd;
  2222. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2223. return 0;
  2224. WFIFOHEAD(fd, 14);
  2225. WFIFOW(fd,0)=0xb0;
  2226. WFIFOW(fd,2)=type;
  2227. switch(type){
  2228. // 00b0
  2229. case SP_WEIGHT:
  2230. pc_updateweightstatus(sd);
  2231. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2232. WFIFOW(fd,2)=type;
  2233. WFIFOL(fd,4)=sd->weight;
  2234. break;
  2235. case SP_MAXWEIGHT:
  2236. WFIFOL(fd,4)=sd->max_weight;
  2237. break;
  2238. case SP_SPEED:
  2239. WFIFOL(fd,4)=sd->battle_status.speed;
  2240. break;
  2241. case SP_BASELEVEL:
  2242. WFIFOL(fd,4)=sd->status.base_level;
  2243. break;
  2244. case SP_JOBLEVEL:
  2245. WFIFOL(fd,4)=sd->status.job_level;
  2246. break;
  2247. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2248. WFIFOL(fd,4)=sd->status.karma;
  2249. break;
  2250. case SP_MANNER:
  2251. WFIFOL(fd,4)=sd->status.manner;
  2252. break;
  2253. case SP_STATUSPOINT:
  2254. WFIFOL(fd,4)=sd->status.status_point;
  2255. break;
  2256. case SP_SKILLPOINT:
  2257. WFIFOL(fd,4)=sd->status.skill_point;
  2258. break;
  2259. case SP_HIT:
  2260. WFIFOL(fd,4)=sd->battle_status.hit;
  2261. break;
  2262. case SP_FLEE1:
  2263. WFIFOL(fd,4)=sd->battle_status.flee;
  2264. break;
  2265. case SP_FLEE2:
  2266. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2267. break;
  2268. case SP_MAXHP:
  2269. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2270. break;
  2271. case SP_MAXSP:
  2272. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2273. break;
  2274. case SP_HP:
  2275. WFIFOL(fd,4)=sd->battle_status.hp;
  2276. if( battle_config.disp_hpmeter )
  2277. clif_hpmeter(sd);
  2278. if( !battle_config.party_hp_mode && sd->status.party_id )
  2279. clif_party_hp(sd);
  2280. if( sd->bg_id )
  2281. clif_bg_hp(sd);
  2282. break;
  2283. case SP_SP:
  2284. WFIFOL(fd,4)=sd->battle_status.sp;
  2285. break;
  2286. case SP_ASPD:
  2287. WFIFOL(fd,4)=sd->battle_status.amotion;
  2288. break;
  2289. case SP_ATK1:
  2290. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  2291. break;
  2292. case SP_DEF1:
  2293. WFIFOL(fd,4)=sd->battle_status.def;
  2294. break;
  2295. case SP_MDEF1:
  2296. WFIFOL(fd,4)=sd->battle_status.mdef;
  2297. break;
  2298. case SP_ATK2:
  2299. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  2300. break;
  2301. case SP_DEF2:
  2302. WFIFOL(fd,4)=sd->battle_status.def2;
  2303. break;
  2304. case SP_MDEF2:
  2305. //negative check (in case you have something like Berserk active)
  2306. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2307. if (len < 0) len = 0;
  2308. WFIFOL(fd,4)= len;
  2309. len = 8;
  2310. break;
  2311. case SP_CRITICAL:
  2312. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2313. break;
  2314. case SP_MATK1:
  2315. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2316. break;
  2317. case SP_MATK2:
  2318. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2319. break;
  2320. case SP_ZENY:
  2321. WFIFOW(fd,0)=0xb1;
  2322. WFIFOL(fd,4)=sd->status.zeny;
  2323. break;
  2324. case SP_BASEEXP:
  2325. WFIFOW(fd,0)=0xb1;
  2326. WFIFOL(fd,4)=sd->status.base_exp;
  2327. break;
  2328. case SP_JOBEXP:
  2329. WFIFOW(fd,0)=0xb1;
  2330. WFIFOL(fd,4)=sd->status.job_exp;
  2331. break;
  2332. case SP_NEXTBASEEXP:
  2333. WFIFOW(fd,0)=0xb1;
  2334. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2335. break;
  2336. case SP_NEXTJOBEXP:
  2337. WFIFOW(fd,0)=0xb1;
  2338. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2339. break;
  2340. /**
  2341. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2342. **/
  2343. case SP_USTR:
  2344. case SP_UAGI:
  2345. case SP_UVIT:
  2346. case SP_UINT:
  2347. case SP_UDEX:
  2348. case SP_ULUK:
  2349. WFIFOW(fd,0)=0xbe;
  2350. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2351. len=5;
  2352. break;
  2353. /**
  2354. * Tells the client how far it is allowed to attack (weapon range)
  2355. **/
  2356. case SP_ATTACKRANGE:
  2357. WFIFOW(fd,0)=0x13a;
  2358. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2359. len=4;
  2360. break;
  2361. case SP_STR:
  2362. WFIFOW(fd,0)=0x141;
  2363. WFIFOL(fd,2)=type;
  2364. WFIFOL(fd,6)=sd->status.str;
  2365. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2366. len=14;
  2367. break;
  2368. case SP_AGI:
  2369. WFIFOW(fd,0)=0x141;
  2370. WFIFOL(fd,2)=type;
  2371. WFIFOL(fd,6)=sd->status.agi;
  2372. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2373. len=14;
  2374. break;
  2375. case SP_VIT:
  2376. WFIFOW(fd,0)=0x141;
  2377. WFIFOL(fd,2)=type;
  2378. WFIFOL(fd,6)=sd->status.vit;
  2379. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2380. len=14;
  2381. break;
  2382. case SP_INT:
  2383. WFIFOW(fd,0)=0x141;
  2384. WFIFOL(fd,2)=type;
  2385. WFIFOL(fd,6)=sd->status.int_;
  2386. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2387. len=14;
  2388. break;
  2389. case SP_DEX:
  2390. WFIFOW(fd,0)=0x141;
  2391. WFIFOL(fd,2)=type;
  2392. WFIFOL(fd,6)=sd->status.dex;
  2393. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2394. len=14;
  2395. break;
  2396. case SP_LUK:
  2397. WFIFOW(fd,0)=0x141;
  2398. WFIFOL(fd,2)=type;
  2399. WFIFOL(fd,6)=sd->status.luk;
  2400. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2401. len=14;
  2402. break;
  2403. case SP_CARTINFO:
  2404. WFIFOW(fd,0)=0x121;
  2405. WFIFOW(fd,2)=sd->cart_num;
  2406. WFIFOW(fd,4)=MAX_CART;
  2407. WFIFOL(fd,6)=sd->cart_weight;
  2408. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2409. len=14;
  2410. break;
  2411. default:
  2412. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2413. return 1;
  2414. }
  2415. WFIFOSET(fd,len);
  2416. return 0;
  2417. }
  2418. int clif_changestatus(struct block_list *bl,int type,int val)
  2419. {
  2420. unsigned char buf[12];
  2421. struct map_session_data *sd = NULL;
  2422. nullpo_ret(bl);
  2423. if(bl->type == BL_PC)
  2424. sd = (struct map_session_data *)bl;
  2425. if(sd){
  2426. WBUFW(buf,0)=0x1ab;
  2427. WBUFL(buf,2)=bl->id;
  2428. WBUFW(buf,6)=type;
  2429. switch(type){
  2430. case SP_MANNER:
  2431. WBUFL(buf,8)=val;
  2432. break;
  2433. default:
  2434. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2435. return 1;
  2436. }
  2437. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2438. }
  2439. return 0;
  2440. }
  2441. /*==========================================
  2442. * Updates BL unit view data to nearby clients
  2443. *------------------------------------------*/
  2444. void clif_changelook(struct block_list *bl,int type,int val)
  2445. {
  2446. unsigned char buf[16];
  2447. struct map_session_data* sd = NULL;
  2448. struct status_change* sc;
  2449. struct view_data* vd;
  2450. enum send_target target = AREA;
  2451. nullpo_retv(bl);
  2452. sd = BL_CAST(BL_PC, bl);
  2453. sc = status_get_sc(bl);
  2454. vd = status_get_viewdata(bl);
  2455. //nullpo_ret(vd);
  2456. if( vd ) //temp hack to let Warp Portal change appearance
  2457. switch(type)
  2458. {
  2459. case LOOK_WEAPON:
  2460. if (sd)
  2461. {
  2462. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2463. val = vd->weapon;
  2464. }
  2465. else vd->weapon = val;
  2466. break;
  2467. case LOOK_SHIELD:
  2468. if (sd)
  2469. {
  2470. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2471. val = vd->shield;
  2472. }
  2473. else vd->shield = val;
  2474. break;
  2475. case LOOK_BASE:
  2476. vd->class_ = val;
  2477. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2478. vd->weapon = vd->shield = 0;
  2479. if (vd->cloth_color && (
  2480. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2481. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2482. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2483. ))
  2484. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2485. break;
  2486. case LOOK_HAIR:
  2487. vd->hair_style = val;
  2488. break;
  2489. case LOOK_HEAD_BOTTOM:
  2490. vd->head_bottom = val;
  2491. break;
  2492. case LOOK_HEAD_TOP:
  2493. vd->head_top = val;
  2494. break;
  2495. case LOOK_HEAD_MID:
  2496. vd->head_mid = val;
  2497. break;
  2498. case LOOK_HAIR_COLOR:
  2499. vd->hair_color = val;
  2500. break;
  2501. case LOOK_CLOTHES_COLOR:
  2502. if (val && (
  2503. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2504. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2505. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2506. ))
  2507. val = 0;
  2508. vd->cloth_color = val;
  2509. break;
  2510. case LOOK_SHOES:
  2511. #if PACKETVER > 3
  2512. if (sd) {
  2513. int n;
  2514. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2515. if(sd->inventory_data[n]->view_id > 0)
  2516. val = sd->inventory_data[n]->view_id;
  2517. else
  2518. val = sd->status.inventory[n].nameid;
  2519. }
  2520. val = 0;
  2521. }
  2522. #endif
  2523. //Shoes? No packet uses this....
  2524. break;
  2525. case LOOK_BODY:
  2526. case LOOK_FLOOR:
  2527. // unknown purpose
  2528. break;
  2529. case LOOK_ROBE:
  2530. #if PACKETVER < 20110111
  2531. return;
  2532. #else
  2533. vd->robe = val;
  2534. #endif
  2535. break;
  2536. }
  2537. // prevent leaking the presence of GM-hidden objects
  2538. if( sc && sc->option&OPTION_INVISIBLE )
  2539. target = SELF;
  2540. #if PACKETVER < 4
  2541. WBUFW(buf,0)=0xc3;
  2542. WBUFL(buf,2)=bl->id;
  2543. WBUFB(buf,6)=type;
  2544. WBUFB(buf,7)=val;
  2545. clif_send(buf,packet_len(0xc3),bl,target);
  2546. #else
  2547. WBUFW(buf,0)=0x1d7;
  2548. WBUFL(buf,2)=bl->id;
  2549. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2550. WBUFB(buf,6)=LOOK_WEAPON;
  2551. WBUFW(buf,7)=vd->weapon;
  2552. WBUFW(buf,9)=vd->shield;
  2553. } else {
  2554. WBUFB(buf,6)=type;
  2555. WBUFL(buf,7)=val;
  2556. }
  2557. clif_send(buf,packet_len(0x1d7),bl,target);
  2558. #endif
  2559. }
  2560. //Sends a change-base-look packet required for traps as they are triggered.
  2561. void clif_changetraplook(struct block_list *bl,int val)
  2562. {
  2563. unsigned char buf[32];
  2564. #if PACKETVER < 4
  2565. WBUFW(buf,0)=0xc3;
  2566. WBUFL(buf,2)=bl->id;
  2567. WBUFB(buf,6)=LOOK_BASE;
  2568. WBUFB(buf,7)=val;
  2569. clif_send(buf,packet_len(0xc3),bl,AREA);
  2570. #else
  2571. WBUFW(buf,0)=0x1d7;
  2572. WBUFL(buf,2)=bl->id;
  2573. WBUFB(buf,6)=LOOK_BASE;
  2574. WBUFW(buf,7)=val;
  2575. WBUFW(buf,9)=0;
  2576. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2577. #endif
  2578. }
  2579. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2580. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2581. {
  2582. unsigned char buf[32];
  2583. #if PACKETVER < 4
  2584. WBUFW(buf,0)=0xc3;
  2585. WBUFL(buf,2)=id;
  2586. WBUFB(buf,6)=type;
  2587. WBUFB(buf,7)=val;
  2588. clif_send(buf,packet_len(0xc3),bl,target);
  2589. #else
  2590. WBUFW(buf,0)=0x1d7;
  2591. WBUFL(buf,2)=id;
  2592. WBUFB(buf,6)=type;
  2593. WBUFW(buf,7)=val;
  2594. WBUFW(buf,9)=0;
  2595. clif_send(buf,packet_len(0x1d7),bl,target);
  2596. #endif
  2597. return;
  2598. }
  2599. /*==========================================
  2600. *
  2601. *------------------------------------------*/
  2602. int clif_initialstatus(struct map_session_data *sd)
  2603. {
  2604. int fd;
  2605. unsigned char *buf;
  2606. nullpo_ret(sd);
  2607. fd=sd->fd;
  2608. WFIFOHEAD(fd,packet_len(0xbd));
  2609. buf=WFIFOP(fd,0);
  2610. WBUFW(buf,0)=0xbd;
  2611. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2612. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2613. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2614. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2615. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2616. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2617. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2618. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2619. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2620. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2621. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2622. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2623. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2624. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2625. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2626. WBUFW(buf,20) = sd->battle_status.matk_max;
  2627. WBUFW(buf,22) = sd->battle_status.matk_min;
  2628. WBUFW(buf,24) = sd->battle_status.def; // def
  2629. WBUFW(buf,26) = sd->battle_status.def2;
  2630. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2631. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2632. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2633. WBUFW(buf,30) = fd;
  2634. fd = sd->fd;
  2635. WBUFW(buf,32) = sd->battle_status.hit;
  2636. WBUFW(buf,34) = sd->battle_status.flee;
  2637. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2638. WBUFW(buf,38) = sd->battle_status.cri/10;
  2639. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2640. WBUFW(buf,42) = sd->status.manner; // FIXME: This is 'plusASPD', but what is it supposed to be?
  2641. WFIFOSET(fd,packet_len(0xbd));
  2642. clif_updatestatus(sd,SP_STR);
  2643. clif_updatestatus(sd,SP_AGI);
  2644. clif_updatestatus(sd,SP_VIT);
  2645. clif_updatestatus(sd,SP_INT);
  2646. clif_updatestatus(sd,SP_DEX);
  2647. clif_updatestatus(sd,SP_LUK);
  2648. clif_updatestatus(sd,SP_ATTACKRANGE);
  2649. clif_updatestatus(sd,SP_ASPD);
  2650. return 0;
  2651. }
  2652. /*==========================================
  2653. * Server tells client item idx 'val' is meant to be shown in equipment's window arrow slot
  2654. *------------------------------------------*/
  2655. int clif_arrowequip(struct map_session_data *sd,int val)
  2656. {
  2657. int fd;
  2658. nullpo_ret(sd);
  2659. pc_stop_attack(sd); // [Valaris]
  2660. fd=sd->fd;
  2661. WFIFOHEAD(fd, packet_len(0x013c));
  2662. WFIFOW(fd,0)=0x013c;
  2663. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2664. WFIFOSET(fd,packet_len(0x013c));
  2665. return 0;
  2666. }
  2667. /// Ammunition action message.
  2668. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2669. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2670. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2671. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2672. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2673. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2674. int clif_arrow_fail(struct map_session_data *sd,int type)
  2675. {
  2676. int fd;
  2677. nullpo_ret(sd);
  2678. fd=sd->fd;
  2679. WFIFOHEAD(fd, packet_len(0x013b));
  2680. WFIFOW(fd,0)=0x013b;
  2681. WFIFOW(fd,2)=type;
  2682. WFIFOSET(fd,packet_len(0x013b));
  2683. return 0;
  2684. }
  2685. /*==========================================
  2686. * Server tells client to display a window similar to Mangifier (item) one
  2687. * Server populates the window with avilable arrow crafting options according to player's inventory
  2688. *------------------------------------------*/
  2689. int clif_arrow_create_list(struct map_session_data *sd)
  2690. {
  2691. int i, c, j;
  2692. int fd;
  2693. nullpo_ret(sd);
  2694. fd = sd->fd;
  2695. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2696. WFIFOW(fd,0) = 0x1ad;
  2697. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2698. if (skill_arrow_db[i].nameid > 0 &&
  2699. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2700. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2701. {
  2702. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2703. WFIFOW(fd,c*2+4) = j;
  2704. else
  2705. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2706. c++;
  2707. }
  2708. }
  2709. WFIFOW(fd,2) = c*2+4;
  2710. WFIFOSET(fd, WFIFOW(fd,2));
  2711. if (c > 0) {
  2712. sd->menuskill_id = AC_MAKINGARROW;
  2713. sd->menuskill_val = c;
  2714. }
  2715. return 0;
  2716. }
  2717. /*==========================================
  2718. * Server tells client his response regarding the earlier request to increase status
  2719. *------------------------------------------*/
  2720. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2721. {
  2722. int fd;
  2723. nullpo_ret(sd);
  2724. fd=sd->fd;
  2725. WFIFOHEAD(fd,packet_len(0xbc));
  2726. WFIFOW(fd,0)=0xbc;
  2727. WFIFOW(fd,2)=type;
  2728. WFIFOB(fd,4)=ok;
  2729. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2730. WFIFOSET(fd,packet_len(0xbc));
  2731. return 0;
  2732. }
  2733. /*==========================================
  2734. *
  2735. *------------------------------------------*/
  2736. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2737. {
  2738. int fd;
  2739. nullpo_ret(sd);
  2740. fd=sd->fd;
  2741. WFIFOHEAD(fd,packet_len(0xaa));
  2742. WFIFOW(fd,0)=0xaa;
  2743. WFIFOW(fd,2)=n+2;
  2744. WFIFOW(fd,4)=pos;
  2745. #if PACKETVER < 20100629
  2746. WFIFOB(fd,6)=ok;
  2747. #else
  2748. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2749. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2750. else
  2751. WFIFOW(fd,6)=0;
  2752. WFIFOB(fd,8)=ok;
  2753. #endif
  2754. WFIFOSET(fd,packet_len(0xaa));
  2755. return 0;
  2756. }
  2757. /*==========================================
  2758. *
  2759. *------------------------------------------*/
  2760. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2761. {
  2762. int fd;
  2763. nullpo_ret(sd);
  2764. fd=sd->fd;
  2765. WFIFOHEAD(fd,packet_len(0xac));
  2766. WFIFOW(fd,0)=0xac;
  2767. WFIFOW(fd,2)=n+2;
  2768. WFIFOW(fd,4)=pos;
  2769. WFIFOB(fd,6)=ok;
  2770. WFIFOSET(fd,packet_len(0xac));
  2771. return 0;
  2772. }
  2773. /*==========================================
  2774. *
  2775. *------------------------------------------*/
  2776. int clif_misceffect(struct block_list* bl,int type)
  2777. {
  2778. unsigned char buf[32];
  2779. nullpo_ret(bl);
  2780. WBUFW(buf,0) = 0x19b;
  2781. WBUFL(buf,2) = bl->id;
  2782. WBUFL(buf,6) = type;
  2783. clif_send(buf,packet_len(0x19b),bl,AREA);
  2784. return 0;
  2785. }
  2786. /*==========================================
  2787. * Server tells BL unit and all nearby clients that his unit-view options (e.g. stone curse appearance) changed
  2788. *------------------------------------------*/
  2789. int clif_changeoption(struct block_list* bl)
  2790. {
  2791. unsigned char buf[32];
  2792. struct status_change *sc;
  2793. struct map_session_data* sd;
  2794. nullpo_ret(bl);
  2795. sc = status_get_sc(bl);
  2796. if (!sc) return 0; //How can an option change if there's no sc?
  2797. sd = BL_CAST(BL_PC, bl);
  2798. #if PACKETVER >= 7
  2799. WBUFW(buf,0) = 0x229;
  2800. WBUFL(buf,2) = bl->id;
  2801. WBUFW(buf,6) = sc->opt1;
  2802. WBUFW(buf,8) = sc->opt2;
  2803. WBUFL(buf,10) = sc->option;
  2804. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2805. if(disguised(bl)) {
  2806. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2807. WBUFL(buf,2) = -bl->id;
  2808. clif_send(buf,packet_len(0x229),bl,SELF);
  2809. WBUFL(buf,2) = bl->id;
  2810. WBUFL(buf,10) = OPTION_INVISIBLE;
  2811. clif_send(buf,packet_len(0x229),bl,SELF);
  2812. } else
  2813. clif_send(buf,packet_len(0x229),bl,AREA);
  2814. #else
  2815. WBUFW(buf,0) = 0x119;
  2816. WBUFL(buf,2) = bl->id;
  2817. WBUFW(buf,6) = sc->opt1;
  2818. WBUFW(buf,8) = sc->opt2;
  2819. WBUFW(buf,10) = sc->option;
  2820. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  2821. if(disguised(bl)) {
  2822. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2823. WBUFL(buf,2) = -bl->id;
  2824. clif_send(buf,packet_len(0x119),bl,SELF);
  2825. WBUFL(buf,2) = bl->id;
  2826. WBUFW(buf,10) = OPTION_INVISIBLE;
  2827. clif_send(buf,packet_len(0x119),bl,SELF);
  2828. } else
  2829. clif_send(buf,packet_len(0x119),bl,AREA);
  2830. #endif
  2831. return 0;
  2832. }
  2833. int clif_changeoption2(struct block_list* bl)
  2834. {
  2835. unsigned char buf[20];
  2836. struct status_change *sc;
  2837. sc = status_get_sc(bl);
  2838. if (!sc) return 0; //How can an option change if there's no sc?
  2839. WBUFW(buf,0) = 0x28a;
  2840. WBUFL(buf,2) = bl->id;
  2841. WBUFL(buf,6) = sc->option;
  2842. WBUFL(buf,10) = clif_setlevel(bl);
  2843. WBUFL(buf,14) = sc->opt3;
  2844. if(disguised(bl)) {
  2845. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2846. WBUFL(buf,2) = -bl->id;
  2847. clif_send(buf,packet_len(0x28a),bl,SELF);
  2848. WBUFL(buf,2) = bl->id;
  2849. WBUFL(buf,6) = OPTION_INVISIBLE;
  2850. clif_send(buf,packet_len(0x28a),bl,SELF);
  2851. } else
  2852. clif_send(buf,packet_len(0x28a),bl,AREA);
  2853. return 0;
  2854. }
  2855. /*==========================================
  2856. *
  2857. *------------------------------------------*/
  2858. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2859. {
  2860. nullpo_ret(sd);
  2861. if(!ok) {
  2862. int fd=sd->fd;
  2863. WFIFOHEAD(fd,packet_len(0xa8));
  2864. WFIFOW(fd,0)=0xa8;
  2865. WFIFOW(fd,2)=index+2;
  2866. WFIFOW(fd,4)=amount;
  2867. WFIFOB(fd,6)=ok;
  2868. WFIFOSET(fd,packet_len(0xa8));
  2869. }
  2870. else {
  2871. #if PACKETVER < 3
  2872. int fd=sd->fd;
  2873. WFIFOHEAD(fd,packet_len(0xa8));
  2874. WFIFOW(fd,0)=0xa8;
  2875. WFIFOW(fd,2)=index+2;
  2876. WFIFOW(fd,4)=amount;
  2877. WFIFOB(fd,6)=ok;
  2878. WFIFOSET(fd,packet_len(0xa8));
  2879. #else
  2880. unsigned char buf[32];
  2881. WBUFW(buf,0)=0x1c8;
  2882. WBUFW(buf,2)=index+2;
  2883. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2884. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2885. else
  2886. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2887. WBUFL(buf,6)=sd->bl.id;
  2888. WBUFW(buf,10)=amount;
  2889. WBUFB(buf,12)=ok;
  2890. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2891. #endif
  2892. }
  2893. return 0;
  2894. }
  2895. /// Inform client whether chatroom creation was successful or not
  2896. /// R 00d6 <flag>.B
  2897. /// flag:
  2898. /// 0 = Room has been successfully created (opens chat room)
  2899. /// 1 = Room limit exceeded
  2900. /// 2 = Same room already exists
  2901. void clif_createchat(struct map_session_data* sd, int flag)
  2902. {
  2903. int fd;
  2904. nullpo_retv(sd);
  2905. fd = sd->fd;
  2906. WFIFOHEAD(fd,packet_len(0xd6));
  2907. WFIFOW(fd,0) = 0xd6;
  2908. WFIFOB(fd,2) = flag;
  2909. WFIFOSET(fd,packet_len(0xd6));
  2910. }
  2911. /*==========================================
  2912. * Display a chat above the owner
  2913. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2914. *------------------------------------------*/
  2915. int clif_dispchat(struct chat_data* cd, int fd)
  2916. {
  2917. unsigned char buf[128];
  2918. uint8 type;
  2919. if( cd == NULL || cd->owner == NULL )
  2920. return 1;
  2921. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2922. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2923. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2924. : 1;
  2925. WBUFW(buf, 0) = 0xd7;
  2926. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2927. WBUFL(buf, 4) = cd->owner->id;
  2928. WBUFL(buf, 8) = cd->bl.id;
  2929. WBUFW(buf,12) = cd->limit;
  2930. WBUFW(buf,14) = cd->users;
  2931. WBUFB(buf,16) = type;
  2932. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2933. if( fd ) {
  2934. WFIFOHEAD(fd,WBUFW(buf,2));
  2935. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2936. WFIFOSET(fd,WBUFW(buf,2));
  2937. } else {
  2938. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2939. }
  2940. return 0;
  2941. }
  2942. /*==========================================
  2943. * Chatroom properties adjustment
  2944. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2945. *------------------------------------------*/
  2946. int clif_changechatstatus(struct chat_data* cd)
  2947. {
  2948. unsigned char buf[128];
  2949. if( cd == NULL || cd->usersd[0] == NULL )
  2950. return 1;
  2951. WBUFW(buf, 0) = 0xdf;
  2952. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2953. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2954. WBUFL(buf, 8) = cd->bl.id;
  2955. WBUFW(buf,12) = cd->limit;
  2956. WBUFW(buf,14) = cd->users;
  2957. WBUFB(buf,16) = cd->pub;
  2958. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2959. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2960. return 0;
  2961. }
  2962. /*==========================================
  2963. *
  2964. *------------------------------------------*/
  2965. int clif_clearchat(struct chat_data *cd,int fd)
  2966. {
  2967. unsigned char buf[32];
  2968. nullpo_ret(cd);
  2969. WBUFW(buf,0) = 0xd8;
  2970. WBUFL(buf,2) = cd->bl.id;
  2971. if( fd ) {
  2972. WFIFOHEAD(fd,packet_len(0xd8));
  2973. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2974. WFIFOSET(fd,packet_len(0xd8));
  2975. } else {
  2976. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2977. }
  2978. return 0;
  2979. }
  2980. /// Displays message (mostly) regarding join chat
  2981. /// failures
  2982. /// R 0x00da <flag>.B
  2983. /// flag:
  2984. /// 0 = The room is already full.
  2985. /// 1 = Incorrect password, please try again.
  2986. /// 2 = You have been kicked out of the room.
  2987. /// 4 = You don't have enough money.
  2988. /// 5 = You are not the required level.
  2989. /// 6 = Too high level for this job.
  2990. /// 7 = Not the suitable job for this type of work.
  2991. int clif_joinchatfail(struct map_session_data *sd,int flag)
  2992. {
  2993. int fd;
  2994. nullpo_ret(sd);
  2995. fd = sd->fd;
  2996. WFIFOHEAD(fd,packet_len(0xda));
  2997. WFIFOW(fd,0) = 0xda;
  2998. WFIFOB(fd,2) = flag;
  2999. WFIFOSET(fd,packet_len(0xda));
  3000. return 0;
  3001. }
  3002. /*==========================================
  3003. *
  3004. *------------------------------------------*/
  3005. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3006. {
  3007. int fd;
  3008. int i;
  3009. nullpo_ret(sd);
  3010. nullpo_ret(cd);
  3011. fd = sd->fd;
  3012. if (!session_isActive(fd))
  3013. return 0;
  3014. WFIFOHEAD(fd, 8 + (28*cd->users));
  3015. WFIFOW(fd, 0) = 0xdb;
  3016. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3017. WFIFOL(fd, 4) = cd->bl.id;
  3018. for (i = 0; i < cd->users; i++) {
  3019. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3020. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3021. }
  3022. WFIFOSET(fd, WFIFOW(fd, 2));
  3023. return 0;
  3024. }
  3025. /*==========================================
  3026. *
  3027. *------------------------------------------*/
  3028. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3029. {
  3030. unsigned char buf[32];
  3031. nullpo_ret(sd);
  3032. nullpo_ret(cd);
  3033. WBUFW(buf, 0) = 0x0dc;
  3034. WBUFW(buf, 2) = cd->users;
  3035. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3036. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3037. return 0;
  3038. }
  3039. /*==========================================
  3040. * Announce the new owner (ZC_ROLE_CHANGE)
  3041. * R 00e1 <role>.L <nick>.24B
  3042. *------------------------------------------*/
  3043. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3044. {
  3045. unsigned char buf[64];
  3046. nullpo_retv(sd);
  3047. nullpo_retv(cd);
  3048. WBUFW(buf, 0) = 0xe1;
  3049. WBUFL(buf, 2) = 1; // normal
  3050. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3051. WBUFW(buf,30) = 0xe1;
  3052. WBUFL(buf,32) = 0; // owner (menu)
  3053. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3054. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3055. }
  3056. /*==========================================
  3057. * Notify about user leaving the chatroom
  3058. * R 00dd <index>.w <nick>.24B <flag>.B
  3059. *------------------------------------------*/
  3060. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3061. {
  3062. unsigned char buf[32];
  3063. nullpo_retv(sd);
  3064. nullpo_retv(cd);
  3065. WBUFW(buf, 0) = 0xdd;
  3066. WBUFW(buf, 2) = cd->users-1;
  3067. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3068. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  3069. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3070. }
  3071. /*==========================================
  3072. * Opens a trade request window from char 'name'
  3073. * R 00e5 <nick>.24B
  3074. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  3075. *------------------------------------------*/
  3076. void clif_traderequest(struct map_session_data* sd, const char* name)
  3077. {
  3078. int fd = sd->fd;
  3079. #if PACKETVER < 6
  3080. WFIFOHEAD(fd,packet_len(0xe5));
  3081. WFIFOW(fd,0) = 0xe5;
  3082. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3083. WFIFOSET(fd,packet_len(0xe5));
  3084. #else
  3085. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3086. if( !tsd ) return;
  3087. WFIFOHEAD(fd,packet_len(0x1f4));
  3088. WFIFOW(fd,0) = 0x1f4;
  3089. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3090. WFIFOL(fd,26) = tsd->status.char_id;
  3091. WFIFOW(fd,30) = tsd->status.base_level;
  3092. WFIFOSET(fd,packet_len(0x1f4));
  3093. #endif
  3094. }
  3095. /*==========================================
  3096. * Reply to a trade-request.
  3097. * R 00e7 <type>.B
  3098. * R 01f5 <type>.B <charid>.L <baselvl>.W
  3099. * Type:
  3100. * 0: Char is too far
  3101. * 1: Character does not exist
  3102. * 2: Trade failed
  3103. * 3: Accept
  3104. * 4: Cancel
  3105. *------------------------------------------*/
  3106. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3107. {
  3108. int fd = sd->fd;
  3109. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3110. if( PACKETVER < 6 || !tsd ) {
  3111. WFIFOHEAD(fd,packet_len(0xe7));
  3112. WFIFOW(fd,0) = 0xe7;
  3113. WFIFOB(fd,2) = type;
  3114. WFIFOSET(fd,packet_len(0xe7));
  3115. } else {
  3116. WFIFOHEAD(fd,packet_len(0x1f5));
  3117. WFIFOW(fd,0) = 0x1f5;
  3118. WFIFOB(fd,2) = type;
  3119. WFIFOL(fd,3) = tsd->status.char_id;
  3120. WFIFOW(fd,7) = tsd->status.base_level;
  3121. WFIFOSET(fd,packet_len(0x1f5));
  3122. }
  3123. }
  3124. /*==========================================
  3125. * Server tells 'tsd' player client info on the items 'sd' player just added to the trade window
  3126. *------------------------------------------*/
  3127. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3128. {
  3129. int fd;
  3130. unsigned char *buf;
  3131. #if PACKETVER < 20100223
  3132. const int cmd = 0xe9;
  3133. #else
  3134. const int cmd = 0x80f;
  3135. #endif
  3136. nullpo_retv(sd);
  3137. nullpo_retv(tsd);
  3138. fd = tsd->fd;
  3139. buf = WFIFOP(fd,0);
  3140. WFIFOHEAD(fd,packet_len(cmd));
  3141. WBUFW(buf,0) = cmd;
  3142. if( index == 0 )
  3143. {
  3144. #if PACKETVER < 20100223
  3145. WBUFL(buf,2) = amount; //amount
  3146. WBUFW(buf,6) = 0; // type id
  3147. #else
  3148. WBUFW(buf,2) = 0; // type id
  3149. WBUFB(buf,4) = 0; // item type
  3150. WBUFL(buf,5) = amount; // amount
  3151. buf = WBUFP(buf,1); //Advance 1B
  3152. #endif
  3153. WBUFB(buf,8) = 0; //identify flag
  3154. WBUFB(buf,9) = 0; // attribute
  3155. WBUFB(buf,10)= 0; //refine
  3156. WBUFW(buf,11)= 0; //card (4w)
  3157. WBUFW(buf,13)= 0; //card (4w)
  3158. WBUFW(buf,15)= 0; //card (4w)
  3159. WBUFW(buf,17)= 0; //card (4w)
  3160. }
  3161. else
  3162. {
  3163. index -= 2; //index fix
  3164. #if PACKETVER < 20100223
  3165. WBUFL(buf,2) = amount; //amount
  3166. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3167. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3168. else
  3169. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3170. #else
  3171. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3172. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3173. else
  3174. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3175. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3176. WBUFL(buf,5) = amount; // amount
  3177. buf = WBUFP(buf,1); //Advance 1B
  3178. #endif
  3179. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3180. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3181. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3182. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3183. }
  3184. WFIFOSET(fd,packet_len(cmd));
  3185. }
  3186. /*==========================================
  3187. * Server tells client on the status of it's OK request
  3188. * fail 1 : the other person did 'ok'
  3189. * fail 0 : you did 'ok'
  3190. *------------------------------------------*/
  3191. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3192. {
  3193. int fd;
  3194. nullpo_retv(sd);
  3195. fd = sd->fd;
  3196. WFIFOHEAD(fd,packet_len(0xea));
  3197. WFIFOW(fd,0) = 0xea;
  3198. WFIFOW(fd,2) = index;
  3199. WFIFOB(fd,4) = fail;
  3200. WFIFOSET(fd,packet_len(0xea));
  3201. }
  3202. /*==========================================
  3203. * Server tells client on the status of it's lock request
  3204. * fail 1 : The other trader lock request
  3205. * fail 0 : Your lock request
  3206. *------------------------------------------*/
  3207. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3208. {
  3209. int fd;
  3210. nullpo_retv(sd);
  3211. fd = sd->fd;
  3212. WFIFOHEAD(fd,packet_len(0xec));
  3213. WFIFOW(fd,0) = 0xec;
  3214. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3215. WFIFOSET(fd,packet_len(0xec));
  3216. }
  3217. /*==========================================
  3218. * Server tells client it's trade request was cancelled
  3219. *------------------------------------------*/
  3220. void clif_tradecancelled(struct map_session_data* sd)
  3221. {
  3222. int fd;
  3223. nullpo_retv(sd);
  3224. fd = sd->fd;
  3225. WFIFOHEAD(fd,packet_len(0xee));
  3226. WFIFOW(fd,0) = 0xee;
  3227. WFIFOSET(fd,packet_len(0xee));
  3228. }
  3229. /*==========================================
  3230. * Server tells client the final status on his trade request
  3231. *------------------------------------------*/
  3232. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3233. {
  3234. int fd;
  3235. nullpo_retv(sd);
  3236. fd = sd->fd;
  3237. WFIFOHEAD(fd,packet_len(0xf0));
  3238. WFIFOW(fd,0) = 0xf0;
  3239. WFIFOB(fd,2) = fail;
  3240. WFIFOSET(fd,packet_len(0xf0));
  3241. }
  3242. /*==========================================
  3243. * Server tells client it's quantity of items in storage changed
  3244. *------------------------------------------*/
  3245. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  3246. {
  3247. int fd;
  3248. nullpo_retv(sd);
  3249. fd=sd->fd;
  3250. WFIFOHEAD(fd,packet_len(0xf2));
  3251. WFIFOW(fd,0) = 0xf2; // update storage amount
  3252. WFIFOW(fd,2) = amount; //items
  3253. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3254. WFIFOSET(fd,packet_len(0xf2));
  3255. }
  3256. /*==========================================
  3257. * Server tells client it's status on his request to add a item to storage
  3258. *------------------------------------------*/
  3259. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3260. {
  3261. int view,fd;
  3262. nullpo_retv(sd);
  3263. nullpo_retv(i);
  3264. fd=sd->fd;
  3265. view = itemdb_viewid(i->nameid);
  3266. #if PACKETVER < 5
  3267. WFIFOHEAD(fd,packet_len(0xf4));
  3268. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3269. WFIFOW(fd, 2) = index+1; // index
  3270. WFIFOL(fd, 4) = amount; // amount
  3271. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3272. WFIFOB(fd,10) = i->identify; //identify flag
  3273. WFIFOB(fd,11) = i->attribute; // attribute
  3274. WFIFOB(fd,12) = i->refine; //refine
  3275. clif_addcards(WFIFOP(fd,13), i);
  3276. WFIFOSET(fd,packet_len(0xf4));
  3277. #else
  3278. WFIFOHEAD(fd,packet_len(0x1c4));
  3279. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3280. WFIFOW(fd, 2) = index+1; // index
  3281. WFIFOL(fd, 4) = amount; // amount
  3282. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3283. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3284. WFIFOB(fd,11) = i->identify; //identify flag
  3285. WFIFOB(fd,12) = i->attribute; // attribute
  3286. WFIFOB(fd,13) = i->refine; //refine
  3287. clif_addcards(WFIFOP(fd,14), i);
  3288. WFIFOSET(fd,packet_len(0x1c4));
  3289. #endif
  3290. }
  3291. /*==========================================
  3292. *
  3293. *------------------------------------------*/
  3294. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  3295. {
  3296. int fd;
  3297. nullpo_retv(sd);
  3298. fd=sd->fd;
  3299. WFIFOHEAD(fd,packet_len(0xf2));
  3300. WFIFOW(fd,0) = 0xf2; // update storage amount
  3301. WFIFOW(fd,2) = amount; //items
  3302. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3303. WFIFOSET(fd,packet_len(0xf2));
  3304. }
  3305. /*==========================================
  3306. * Server tells client its status on his request to remove a item from storage
  3307. *------------------------------------------*/
  3308. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3309. {
  3310. int fd;
  3311. nullpo_retv(sd);
  3312. fd=sd->fd;
  3313. WFIFOHEAD(fd,packet_len(0xf6));
  3314. WFIFOW(fd,0)=0xf6; // Storage item removed
  3315. WFIFOW(fd,2)=index+1;
  3316. WFIFOL(fd,4)=amount;
  3317. WFIFOSET(fd,packet_len(0xf6));
  3318. }
  3319. /*==========================================
  3320. * Server tells client his storage was closed
  3321. *------------------------------------------*/
  3322. void clif_storageclose(struct map_session_data* sd)
  3323. {
  3324. int fd;
  3325. nullpo_retv(sd);
  3326. fd=sd->fd;
  3327. WFIFOHEAD(fd,packet_len(0xf8));
  3328. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3329. WFIFOSET(fd,packet_len(0xf8));
  3330. }
  3331. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3);
  3332. /*==========================================
  3333. * Server tells 'sd' player client the abouts of 'dstsd' player
  3334. *------------------------------------------*/
  3335. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3336. {
  3337. int gmlvl;
  3338. struct block_list *d_bl;
  3339. int i;
  3340. if(dstsd->chatID)
  3341. {
  3342. struct chat_data *cd;
  3343. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3344. if(cd && cd->usersd[0]==dstsd)
  3345. clif_dispchat(cd,sd->fd);
  3346. }
  3347. if( dstsd->state.vending )
  3348. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3349. if( dstsd->state.buyingstore )
  3350. clif_buyingstore_entry_single(sd, dstsd);
  3351. if(dstsd->spiritball > 0)
  3352. clif_spiritball_single(sd->fd, dstsd);
  3353. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3354. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3355. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3356. }
  3357. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3358. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3359. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd)) )
  3360. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3361. // display link (sd - dstsd) to sd
  3362. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3363. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3364. // display links (dstsd - devotees) to sd
  3365. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3366. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3367. // display link (dstsd - crusader) to sd
  3368. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3369. clif_devotion(d_bl, sd);
  3370. }
  3371. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3372. {
  3373. uint8 buf[128];
  3374. struct unit_data *ud;
  3375. struct view_data *vd;
  3376. int len;
  3377. vd = status_get_viewdata(bl);
  3378. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3379. return;
  3380. ud = unit_bl2ud(bl);
  3381. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3382. clif_send(buf,len,&sd->bl,SELF);
  3383. if (vd->cloth_color)
  3384. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3385. switch (bl->type)
  3386. {
  3387. case BL_PC:
  3388. {
  3389. TBL_PC* tsd = (TBL_PC*)bl;
  3390. clif_getareachar_pc(sd, tsd);
  3391. if(tsd->state.size==2) // tiny/big players [Valaris]
  3392. clif_specialeffect_single(bl,423,sd->fd);
  3393. else if(tsd->state.size==1)
  3394. clif_specialeffect_single(bl,421,sd->fd);
  3395. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3396. clif_sendbgemblem_single(sd->fd,tsd);
  3397. }
  3398. break;
  3399. case BL_MER: // Devotion Effects
  3400. if( ((TBL_MER*)bl)->devotion_flag )
  3401. clif_devotion(bl, sd);
  3402. break;
  3403. case BL_NPC:
  3404. {
  3405. TBL_NPC* nd = (TBL_NPC*)bl;
  3406. if( nd->chat_id )
  3407. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3408. if( nd->size == 2 )
  3409. clif_specialeffect_single(bl,423,sd->fd);
  3410. else if( nd->size == 1 )
  3411. clif_specialeffect_single(bl,421,sd->fd);
  3412. }
  3413. break;
  3414. case BL_MOB:
  3415. {
  3416. TBL_MOB* md = (TBL_MOB*)bl;
  3417. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3418. clif_specialeffect_single(bl,423,sd->fd);
  3419. else if(md->special_state.size==1)
  3420. clif_specialeffect_single(bl,421,sd->fd);
  3421. }
  3422. break;
  3423. case BL_PET:
  3424. if (vd->head_bottom)
  3425. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3426. break;
  3427. }
  3428. }
  3429. //Modifies the type of damage according to status changes [Skotlex]
  3430. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3431. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3432. {
  3433. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3434. }
  3435. /*==========================================
  3436. * Estimates walk delay based on the damage criteria. [Skotlex]
  3437. *------------------------------------------*/
  3438. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3439. {
  3440. if (type == 4 || type == 9 || damage <=0)
  3441. return 0;
  3442. if (bl->type == BL_PC) {
  3443. if (battle_config.pc_walk_delay_rate != 100)
  3444. delay = delay*battle_config.pc_walk_delay_rate/100;
  3445. } else
  3446. if (battle_config.walk_delay_rate != 100)
  3447. delay = delay*battle_config.walk_delay_rate/100;
  3448. if (div_ > 1) //Multi-hit skills mean higher delays.
  3449. delay += battle_config.multihit_delay*(div_-1);
  3450. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3451. }
  3452. /*==========================================
  3453. * Sends a 'damage' packet (src performs action on dst)
  3454. * R 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)
  3455. * R 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)
  3456. *
  3457. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3458. * type=01 pick up item
  3459. * type=02 sit down
  3460. * type=03 stand up
  3461. * type=04 reflected/absorbed damage?
  3462. * type=08 double attack
  3463. * type=09 don't display flinch animation (endure)
  3464. * type=0a critical hit
  3465. * type=0b lucky dodge
  3466. *------------------------------------------*/
  3467. 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)
  3468. {
  3469. unsigned char buf[33];
  3470. struct status_change *sc;
  3471. #if PACKETVER < 20071113
  3472. const int cmd = 0x8a;
  3473. #else
  3474. const int cmd = 0x2e1;
  3475. #endif
  3476. nullpo_ret(src);
  3477. nullpo_ret(dst);
  3478. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3479. sc = status_get_sc(dst);
  3480. if(sc && sc->count) {
  3481. if(sc->data[SC_HALLUCINATION]) {
  3482. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3483. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3484. }
  3485. }
  3486. WBUFW(buf,0)=cmd;
  3487. WBUFL(buf,2)=src->id;
  3488. WBUFL(buf,6)=dst->id;
  3489. WBUFL(buf,10)=tick;
  3490. WBUFL(buf,14)=sdelay;
  3491. WBUFL(buf,18)=ddelay;
  3492. #if PACKETVER < 20071113
  3493. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3494. WBUFW(buf,22)=damage?div:0;
  3495. WBUFW(buf,27)=damage2?div:0;
  3496. } else {
  3497. WBUFW(buf,22)=min(damage, INT16_MAX);
  3498. WBUFW(buf,27)=damage2;
  3499. }
  3500. WBUFW(buf,24)=div;
  3501. WBUFB(buf,26)=type;
  3502. #else
  3503. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3504. WBUFL(buf,22)=damage?div:0;
  3505. WBUFL(buf,29)=damage2?div:0;
  3506. } else {
  3507. WBUFL(buf,22)=damage;
  3508. WBUFL(buf,29)=damage2;
  3509. }
  3510. WBUFW(buf,26)=div;
  3511. WBUFB(buf,28)=type;
  3512. #endif
  3513. if(disguised(dst)) {
  3514. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3515. WBUFL(buf,6) = -dst->id;
  3516. clif_send(buf,packet_len(cmd),dst,SELF);
  3517. } else
  3518. clif_send(buf,packet_len(cmd),dst,AREA);
  3519. if(disguised(src)) {
  3520. WBUFL(buf,2) = -src->id;
  3521. if (disguised(dst))
  3522. WBUFL(buf,6) = dst->id;
  3523. #if PACKETVER < 20071113
  3524. if(damage > 0) WBUFW(buf,22) = -1;
  3525. if(damage2 > 0) WBUFW(buf,27) = -1;
  3526. #else
  3527. if(damage > 0) WBUFL(buf,22) = -1;
  3528. if(damage2 > 0) WBUFL(buf,29) = -1;
  3529. #endif
  3530. clif_send(buf,packet_len(cmd),src,SELF);
  3531. }
  3532. //Return adjusted can't walk delay for further processing.
  3533. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3534. }
  3535. /*==========================================
  3536. * src picks up dst
  3537. *------------------------------------------*/
  3538. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3539. {
  3540. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3541. unsigned char buf[32];
  3542. nullpo_retv(src);
  3543. nullpo_retv(dst);
  3544. WBUFW(buf, 0) = 0x8a;
  3545. WBUFL(buf, 2) = src->id;
  3546. WBUFL(buf, 6) = dst->id;
  3547. WBUFB(buf,26) = 1;
  3548. clif_send(buf, packet_len(0x8a), src, AREA);
  3549. }
  3550. /*==========================================
  3551. * inform clients in area that `bl` is sitting
  3552. *------------------------------------------*/
  3553. void clif_sitting(struct block_list* bl)
  3554. {
  3555. unsigned char buf[32];
  3556. nullpo_retv(bl);
  3557. WBUFW(buf, 0) = 0x8a;
  3558. WBUFL(buf, 2) = bl->id;
  3559. WBUFB(buf,26) = 2;
  3560. clif_send(buf, packet_len(0x8a), bl, AREA);
  3561. if(disguised(bl)) {
  3562. WBUFL(buf, 2) = - bl->id;
  3563. clif_send(buf, packet_len(0x8a), bl, SELF);
  3564. }
  3565. }
  3566. /*==========================================
  3567. * inform clients in area that `bl` is standing
  3568. *------------------------------------------*/
  3569. void clif_standing(struct block_list* bl)
  3570. {
  3571. unsigned char buf[32];
  3572. nullpo_retv(bl);
  3573. WBUFW(buf, 0) = 0x8a;
  3574. WBUFL(buf, 2) = bl->id;
  3575. WBUFB(buf,26) = 3;
  3576. clif_send(buf, packet_len(0x8a), bl, AREA);
  3577. if(disguised(bl)) {
  3578. WBUFL(buf, 2) = - bl->id;
  3579. clif_send(buf, packet_len(0x8a), bl, SELF);
  3580. }
  3581. }
  3582. /*==========================================
  3583. * Inform client(s) about a map-cell change
  3584. *------------------------------------------*/
  3585. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3586. {
  3587. unsigned char buf[32];
  3588. WBUFW(buf,0) = 0x192;
  3589. WBUFW(buf,2) = x;
  3590. WBUFW(buf,4) = y;
  3591. WBUFW(buf,6) = type;
  3592. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3593. if( fd )
  3594. {
  3595. WFIFOHEAD(fd,packet_len(0x192));
  3596. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3597. WFIFOSET(fd,packet_len(0x192));
  3598. }
  3599. else
  3600. {
  3601. struct block_list dummy_bl;
  3602. dummy_bl.type = BL_NUL;
  3603. dummy_bl.x = x;
  3604. dummy_bl.y = y;
  3605. dummy_bl.m = m;
  3606. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3607. }
  3608. }
  3609. /*==========================================
  3610. *
  3611. *------------------------------------------*/
  3612. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3613. {
  3614. int view,fd;
  3615. fd=sd->fd;
  3616. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3617. WFIFOHEAD(fd,packet_len(0x9d));
  3618. WFIFOW(fd,0)=0x9d;
  3619. WFIFOL(fd,2)=fitem->bl.id;
  3620. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3621. WFIFOW(fd,6)=view;
  3622. else
  3623. WFIFOW(fd,6)=fitem->item_data.nameid;
  3624. WFIFOB(fd,8)=fitem->item_data.identify;
  3625. WFIFOW(fd,9)=fitem->bl.x;
  3626. WFIFOW(fd,11)=fitem->bl.y;
  3627. WFIFOW(fd,13)=fitem->item_data.amount;
  3628. WFIFOB(fd,15)=fitem->subx;
  3629. WFIFOB(fd,16)=fitem->suby;
  3630. WFIFOSET(fd,packet_len(0x9d));
  3631. }
  3632. /*==========================================
  3633. * Server tells client 'sd' of all nearby skill units (e.g. safety wall)
  3634. *------------------------------------------*/
  3635. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3636. {
  3637. int fd = sd->fd;
  3638. #if PACKETVER >= 3
  3639. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3640. WFIFOHEAD(fd,packet_len(0x1c9));
  3641. WFIFOW(fd, 0)=0x1c9;
  3642. WFIFOL(fd, 2)=unit->bl.id;
  3643. WFIFOL(fd, 6)=unit->group->src_id;
  3644. WFIFOW(fd,10)=unit->bl.x;
  3645. WFIFOW(fd,12)=unit->bl.y;
  3646. WFIFOB(fd,14)=unit->group->unit_id;
  3647. WFIFOB(fd,15)=1;
  3648. WFIFOB(fd,16)=1;
  3649. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3650. WFIFOSET(fd,packet_len(0x1c9));
  3651. return;
  3652. }
  3653. #endif
  3654. WFIFOHEAD(fd,packet_len(0x11f));
  3655. WFIFOW(fd, 0)=0x11f;
  3656. WFIFOL(fd, 2)=unit->bl.id;
  3657. WFIFOL(fd, 6)=unit->group->src_id;
  3658. WFIFOW(fd,10)=unit->bl.x;
  3659. WFIFOW(fd,12)=unit->bl.y;
  3660. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3661. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3662. else
  3663. WFIFOB(fd,14)=unit->group->unit_id;
  3664. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3665. WFIFOSET(fd,packet_len(0x11f));
  3666. if(unit->group->skill_id == WZ_ICEWALL)
  3667. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3668. }
  3669. /*==========================================
  3670. * Server tells client to remove unit of id 'unit->bl.id'
  3671. *------------------------------------------*/
  3672. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3673. {
  3674. nullpo_retv(unit);
  3675. WFIFOHEAD(fd,packet_len(0x120));
  3676. WFIFOW(fd, 0)=0x120;
  3677. WFIFOL(fd, 2)=unit->bl.id;
  3678. WFIFOSET(fd,packet_len(0x120));
  3679. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3680. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3681. }
  3682. /*==========================================
  3683. * Server tells all clients in sight of 'unit->bl.id' ID to remove itself from sight (delete)
  3684. *------------------------------------------*/
  3685. void clif_skill_delunit(struct skill_unit *unit)
  3686. {
  3687. unsigned char buf[16];
  3688. nullpo_retv(unit);
  3689. WBUFW(buf, 0)=0x120;
  3690. WBUFL(buf, 2)=unit->bl.id;
  3691. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3692. }
  3693. /*==========================================
  3694. * Sent when an object gets ankle-snared (ZC_SKILL_UPDATE)
  3695. * Only affects units with class [139,153] client-side
  3696. * R 01ac <object id>.l
  3697. *------------------------------------------*/
  3698. void clif_skillunit_update(struct block_list* bl)
  3699. {
  3700. unsigned char buf[6];
  3701. nullpo_retv(bl);
  3702. WBUFW(buf,0) = 0x1ac;
  3703. WBUFL(buf,2) = bl->id;
  3704. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3705. }
  3706. /*==========================================
  3707. *
  3708. *------------------------------------------*/
  3709. int clif_getareachar(struct block_list* bl,va_list ap)
  3710. {
  3711. struct map_session_data *sd;
  3712. nullpo_ret(bl);
  3713. sd=va_arg(ap,struct map_session_data*);
  3714. if (sd == NULL || !sd->fd)
  3715. return 0;
  3716. switch(bl->type){
  3717. case BL_ITEM:
  3718. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3719. break;
  3720. case BL_SKILL:
  3721. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3722. break;
  3723. default:
  3724. if(&sd->bl == bl)
  3725. break;
  3726. clif_getareachar_unit(sd,bl);
  3727. break;
  3728. }
  3729. return 0;
  3730. }
  3731. /*==========================================
  3732. * tbl has gone out of view-size of bl
  3733. *------------------------------------------*/
  3734. int clif_outsight(struct block_list *bl,va_list ap)
  3735. {
  3736. struct block_list *tbl;
  3737. struct view_data *vd;
  3738. TBL_PC *sd, *tsd;
  3739. tbl=va_arg(ap,struct block_list*);
  3740. if(bl == tbl) return 0;
  3741. sd = BL_CAST(BL_PC, bl);
  3742. tsd = BL_CAST(BL_PC, tbl);
  3743. if (tsd && tsd->fd)
  3744. { //tsd has lost sight of the bl object.
  3745. switch(bl->type){
  3746. case BL_PC:
  3747. if (sd->vd.class_ != INVISIBLE_CLASS)
  3748. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3749. if(sd->chatID){
  3750. struct chat_data *cd;
  3751. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3752. if(cd->usersd[0]==sd)
  3753. clif_dispchat(cd,tsd->fd);
  3754. }
  3755. if( sd->state.vending )
  3756. clif_closevendingboard(bl,tsd->fd);
  3757. if( sd->state.buyingstore )
  3758. clif_buyingstore_disappear_entry_single(tsd, sd);
  3759. break;
  3760. case BL_ITEM:
  3761. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3762. break;
  3763. case BL_SKILL:
  3764. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3765. break;
  3766. default:
  3767. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3768. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3769. break;
  3770. }
  3771. }
  3772. if (sd && sd->fd)
  3773. { //sd is watching tbl go out of view.
  3774. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3775. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3776. }
  3777. return 0;
  3778. }
  3779. /*==========================================
  3780. * tbl has come into view of bl
  3781. *------------------------------------------*/
  3782. int clif_insight(struct block_list *bl,va_list ap)
  3783. {
  3784. struct block_list *tbl;
  3785. TBL_PC *sd, *tsd;
  3786. tbl=va_arg(ap,struct block_list*);
  3787. if (bl == tbl) return 0;
  3788. sd = BL_CAST(BL_PC, bl);
  3789. tsd = BL_CAST(BL_PC, tbl);
  3790. if (tsd && tsd->fd)
  3791. { //Tell tsd that bl entered into his view
  3792. switch(bl->type){
  3793. case BL_ITEM:
  3794. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3795. break;
  3796. case BL_SKILL:
  3797. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3798. break;
  3799. default:
  3800. clif_getareachar_unit(tsd,bl);
  3801. break;
  3802. }
  3803. }
  3804. if (sd && sd->fd)
  3805. { //Tell sd that tbl walked into his view
  3806. clif_getareachar_unit(sd,tbl);
  3807. }
  3808. return 0;
  3809. }
  3810. /*==========================================
  3811. * Server tells the client information on 'sd' player's skill tree
  3812. *------------------------------------------*/
  3813. int clif_skillinfoblock(struct map_session_data *sd)
  3814. {
  3815. int fd;
  3816. int i,len,id;
  3817. nullpo_ret(sd);
  3818. fd=sd->fd;
  3819. if (!fd) return 0;
  3820. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3821. WFIFOW(fd,0) = 0x10f;
  3822. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  3823. {
  3824. if( (id = sd->status.skill[i].id) != 0 )
  3825. {
  3826. WFIFOW(fd,len) = id;
  3827. WFIFOW(fd,len+2) = skill_get_inf(id);
  3828. WFIFOW(fd,len+4) = 0;
  3829. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3830. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3831. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3832. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3833. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  3834. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3835. else
  3836. WFIFOB(fd,len+36) = 0;
  3837. len += 37;
  3838. }
  3839. }
  3840. WFIFOW(fd,2)=len;
  3841. WFIFOSET(fd,len);
  3842. return 1;
  3843. }
  3844. /**
  3845. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  3846. **/
  3847. int clif_addskill(struct map_session_data *sd, int id )
  3848. {
  3849. int fd;
  3850. nullpo_ret(sd);
  3851. fd = sd->fd;
  3852. if (!fd) return 0;
  3853. if( sd->status.skill[id].id <= 0 )
  3854. return 0;
  3855. WFIFOHEAD(fd, packet_len(0x111));
  3856. WFIFOW(fd,0) = 0x111;
  3857. WFIFOW(fd,2) = id;
  3858. WFIFOW(fd,4) = skill_get_inf(id);
  3859. WFIFOW(fd,6) = 0;
  3860. WFIFOW(fd,8) = sd->status.skill[id].lv;
  3861. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  3862. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  3863. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3864. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  3865. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3866. else
  3867. WFIFOB(fd,38) = 0;
  3868. WFIFOSET(fd,packet_len(0x111));
  3869. return 1;
  3870. }
  3871. int clif_deleteskill(struct map_session_data *sd, int id)
  3872. {
  3873. #if PACKETVER >= 20081217
  3874. int fd;
  3875. nullpo_ret(sd);
  3876. fd = sd->fd;
  3877. if( !fd ) return 0;
  3878. WFIFOHEAD(fd,packet_len(0x441));
  3879. WFIFOW(fd,0) = 0x441;
  3880. WFIFOW(fd,2) = id;
  3881. WFIFOSET(fd,packet_len(0x441));
  3882. return 1;
  3883. #else
  3884. return clif_skillinfoblock(sd);
  3885. #endif
  3886. }
  3887. /*==========================================
  3888. * Server tells client it's skill of id 'skill_num' level changed
  3889. *------------------------------------------*/
  3890. int clif_skillup(struct map_session_data *sd,int skill_num)
  3891. {
  3892. int fd;
  3893. nullpo_ret(sd);
  3894. fd=sd->fd;
  3895. WFIFOHEAD(fd,packet_len(0x10e));
  3896. WFIFOW(fd,0) = 0x10e;
  3897. WFIFOW(fd,2) = skill_num;
  3898. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3899. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3900. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3901. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3902. WFIFOSET(fd,packet_len(0x10e));
  3903. return 0;
  3904. }
  3905. //PACKET_ZC_SKILLINFO_UPDATE2
  3906. //Like packet 0x0x10e, but also contains inf information
  3907. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  3908. {
  3909. const int fd = sd->fd;
  3910. WFIFOHEAD(fd,packet_len(0x7e1));
  3911. WFIFOW(fd,0) = 0x7e1;
  3912. WFIFOW(fd,2) = skill;
  3913. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  3914. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  3915. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  3916. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  3917. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  3918. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  3919. else
  3920. WFIFOB(fd,14) = 0;
  3921. WFIFOSET(fd,packet_len(0x7e1));
  3922. }
  3923. /// Notifies clients, that an object is about to use a skill (ZC_USESKILL_ACK/ZC_USESKILL_ACK2)
  3924. /// 013e <src id>.L <dst id>.L <x pos>.W <y pos>.W <skill id>.W <property>.L <delaytime>.L
  3925. /// 07fb <src id>.L <dst id>.L <x pos>.W <y pos>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B
  3926. /// property:
  3927. /// 0 = Yellow cast aura
  3928. /// 1 = Water elemental cast aura
  3929. /// 2 = Earth elemental cast aura
  3930. /// 3 = Fire elemental cast aura
  3931. /// 4 = Wind elemental cast aura
  3932. /// 5 = Poison elemental cast aura
  3933. /// 6 = Holy elemental cast aura
  3934. /// ? = like 0
  3935. /// is disposable:
  3936. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  3937. /// 1 = no text
  3938. 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)
  3939. {
  3940. #if PACKETVER < 20091124
  3941. const int cmd = 0x13e;
  3942. #else
  3943. const int cmd = 0x7fb;
  3944. #endif
  3945. unsigned char buf[32];
  3946. WBUFW(buf,0) = cmd;
  3947. WBUFL(buf,2) = src_id;
  3948. WBUFL(buf,6) = dst_id;
  3949. WBUFW(buf,10) = dst_x;
  3950. WBUFW(buf,12) = dst_y;
  3951. WBUFW(buf,14) = skill_num;
  3952. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  3953. WBUFL(buf,20) = casttime;
  3954. #if PACKETVER >= 20091124
  3955. WBUFB(buf,24) = 1; // isDisposable
  3956. #endif
  3957. if (disguised(bl)) {
  3958. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  3959. WBUFL(buf,2) = -src_id;
  3960. clif_send(buf,packet_len(cmd), bl, SELF);
  3961. } else
  3962. clif_send(buf,packet_len(cmd), bl, AREA);
  3963. }
  3964. /*==========================================
  3965. *
  3966. *------------------------------------------*/
  3967. int clif_skillcastcancel(struct block_list* bl)
  3968. {
  3969. unsigned char buf[16];
  3970. nullpo_ret(bl);
  3971. WBUFW(buf,0) = 0x1b9;
  3972. WBUFL(buf,2) = bl->id;
  3973. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3974. return 0;
  3975. }
  3976. /// only when type==0:
  3977. /// if(skill_id==NV_BASIC)
  3978. /// btype==0 "skill failed" MsgStringTable[159]
  3979. /// btype==1 "no emotions" MsgStringTable[160]
  3980. /// btype==2 "no sit" MsgStringTable[161]
  3981. /// btype==3 "no chat" MsgStringTable[162]
  3982. /// btype==4 "no party" MsgStringTable[163]
  3983. /// btype==5 "no shout" MsgStringTable[164]
  3984. /// btype==6 "no PKing" MsgStringTable[165]
  3985. /// btype==7 "no alligning" MsgStringTable[383]
  3986. /// btype>=8: ignored
  3987. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3988. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3989. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3990. /// otherwise "skill failed" MsgStringTable[204]
  3991. /// btype irrelevant
  3992. /// type==1 "insufficient SP" MsgStringTable[202]
  3993. /// type==2 "insufficient HP" MsgStringTable[203]
  3994. /// type==3 "insufficient materials" MsgStringTable[808]
  3995. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3996. /// type==5 "insufficient zeny" MsgStringTable[233]
  3997. /// type==6 "wrong weapon" MsgStringTable[239]
  3998. /// type==7 "red gemstone needed" MsgStringTable[246]
  3999. /// type==8 "blue gemstone needed" MsgStringTable[247]
  4000. /// type==9 "overweight" MsgStringTable[580]
  4001. /// type==10 "skill failed" MsgStringTable[285]
  4002. /// type>=11 ignored
  4003. ///
  4004. /// if(success!=0) doesn't display any of the previous messages
  4005. /// Note: when this packet is received an unknown flag is always set to 0,
  4006. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4007. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  4008. {
  4009. int fd;
  4010. if (!sd) { //Since this is the most common nullpo....
  4011. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4012. return 0;
  4013. }
  4014. fd=sd->fd;
  4015. if (!fd) return 0;
  4016. if(battle_config.display_skill_fail&1)
  4017. return 0; //Disable all skill failed messages
  4018. if(type==0x4 && !sd->state.showdelay)
  4019. return 0; //Disable delay failed messages
  4020. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4021. return 0;
  4022. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4023. return 0;
  4024. WFIFOHEAD(fd,packet_len(0x110));
  4025. WFIFOW(fd,0) = 0x110;
  4026. WFIFOW(fd,2) = skill_id;
  4027. WFIFOL(fd,4) = btype;
  4028. WFIFOB(fd,8) = 0;// success
  4029. WFIFOB(fd,9) = type;
  4030. WFIFOSET(fd,packet_len(0x110));
  4031. return 1;
  4032. }
  4033. /*==========================================
  4034. * skill cooldown display icon
  4035. * R 043d <skill ID>.w <tick>.l
  4036. *------------------------------------------*/
  4037. int clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  4038. {
  4039. #if PACKETVER>=20081112
  4040. int fd;
  4041. nullpo_ret(sd);
  4042. fd=sd->fd;
  4043. WFIFOHEAD(fd,packet_len(0x043d));
  4044. WFIFOW(fd,0) = 0x043d;
  4045. WFIFOW(fd,2) = skillid;
  4046. WFIFOL(fd,4) = tick;
  4047. WFIFOSET(fd,packet_len(0x043d));
  4048. #endif
  4049. return 0;
  4050. }
  4051. /*==========================================
  4052. * skill attack effect and damage
  4053. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  4054. *------------------------------------------*/
  4055. 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)
  4056. {
  4057. unsigned char buf[64];
  4058. struct status_change *sc;
  4059. nullpo_ret(src);
  4060. nullpo_ret(dst);
  4061. type = clif_calc_delay(type,div,damage,ddelay);
  4062. sc = status_get_sc(dst);
  4063. if(sc && sc->count) {
  4064. if(sc->data[SC_HALLUCINATION] && damage)
  4065. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  4066. }
  4067. #if PACKETVER < 3
  4068. WBUFW(buf,0)=0x114;
  4069. WBUFW(buf,2)=skill_id;
  4070. WBUFL(buf,4)=src->id;
  4071. WBUFL(buf,8)=dst->id;
  4072. WBUFL(buf,12)=tick;
  4073. WBUFL(buf,16)=sdelay;
  4074. WBUFL(buf,20)=ddelay;
  4075. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4076. WBUFW(buf,24)=damage?div:0;
  4077. } else {
  4078. WBUFW(buf,24)=damage;
  4079. }
  4080. WBUFW(buf,26)=skill_lv;
  4081. WBUFW(buf,28)=div;
  4082. WBUFB(buf,30)=type;
  4083. if (disguised(dst)) {
  4084. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4085. WBUFL(buf,8)=-dst->id;
  4086. clif_send(buf,packet_len(0x114),dst,SELF);
  4087. } else
  4088. clif_send(buf,packet_len(0x114),dst,AREA);
  4089. if(disguised(src)) {
  4090. WBUFL(buf,4)=-src->id;
  4091. if (disguised(dst))
  4092. WBUFL(buf,8)=dst->id;
  4093. if(damage > 0)
  4094. WBUFW(buf,24)=-1;
  4095. clif_send(buf,packet_len(0x114),src,SELF);
  4096. }
  4097. #else
  4098. WBUFW(buf,0)=0x1de;
  4099. WBUFW(buf,2)=skill_id;
  4100. WBUFL(buf,4)=src->id;
  4101. WBUFL(buf,8)=dst->id;
  4102. WBUFL(buf,12)=tick;
  4103. WBUFL(buf,16)=sdelay;
  4104. WBUFL(buf,20)=ddelay;
  4105. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4106. WBUFL(buf,24)=damage?div:0;
  4107. } else {
  4108. WBUFL(buf,24)=damage;
  4109. }
  4110. WBUFW(buf,28)=skill_lv;
  4111. WBUFW(buf,30)=div;
  4112. WBUFB(buf,32)=type;
  4113. if (disguised(dst)) {
  4114. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4115. WBUFL(buf,8)=-dst->id;
  4116. clif_send(buf,packet_len(0x1de),dst,SELF);
  4117. } else
  4118. clif_send(buf,packet_len(0x1de),dst,AREA);
  4119. if(disguised(src)) {
  4120. WBUFL(buf,4)=-src->id;
  4121. if (disguised(dst))
  4122. WBUFL(buf,8)=dst->id;
  4123. if(damage > 0)
  4124. WBUFL(buf,24)=-1;
  4125. clif_send(buf,packet_len(0x1de),src,SELF);
  4126. }
  4127. #endif
  4128. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4129. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4130. }
  4131. /*==========================================
  4132. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  4133. *------------------------------------------*/
  4134. /*
  4135. 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)
  4136. {
  4137. unsigned char buf[64];
  4138. struct status_change *sc;
  4139. nullpo_ret(src);
  4140. nullpo_ret(dst);
  4141. type = (type>0)?type:skill_get_hit(skill_id);
  4142. type = clif_calc_delay(type,div,damage,ddelay);
  4143. sc = status_get_sc(dst);
  4144. if(sc && sc->count) {
  4145. if(sc->data[SC_HALLUCINATION] && damage)
  4146. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  4147. }
  4148. WBUFW(buf,0)=0x115;
  4149. WBUFW(buf,2)=skill_id;
  4150. WBUFL(buf,4)=src->id;
  4151. WBUFL(buf,8)=dst->id;
  4152. WBUFL(buf,12)=tick;
  4153. WBUFL(buf,16)=sdelay;
  4154. WBUFL(buf,20)=ddelay;
  4155. WBUFW(buf,24)=dst->x;
  4156. WBUFW(buf,26)=dst->y;
  4157. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4158. WBUFW(buf,28)=damage?div:0;
  4159. } else {
  4160. WBUFW(buf,28)=damage;
  4161. }
  4162. WBUFW(buf,30)=skill_lv;
  4163. WBUFW(buf,32)=div;
  4164. WBUFB(buf,34)=type;
  4165. clif_send(buf,packet_len(0x115),src,AREA);
  4166. if(disguised(src)) {
  4167. WBUFL(buf,4)=-src->id;
  4168. if(damage > 0)
  4169. WBUFW(buf,28)=-1;
  4170. clif_send(buf,packet_len(0x115),src,SELF);
  4171. }
  4172. if (disguised(dst)) {
  4173. WBUFL(buf,8)=-dst->id;
  4174. if (disguised(src))
  4175. WBUFL(buf,4)=src->id;
  4176. else if(damage > 0)
  4177. WBUFW(buf,28)=-1;
  4178. clif_send(buf,packet_len(0x115),dst,SELF);
  4179. }
  4180. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4181. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4182. }
  4183. */
  4184. /*==========================================
  4185. * Server tells client(s) that 'src' casted a skill of nodamage type (e.g. heal) on 'dst'
  4186. *------------------------------------------*/
  4187. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  4188. {
  4189. unsigned char buf[32];
  4190. nullpo_ret(dst);
  4191. WBUFW(buf,0)=0x11a;
  4192. WBUFW(buf,2)=skill_id;
  4193. WBUFW(buf,4)=min(heal, INT16_MAX);
  4194. WBUFL(buf,6)=dst->id;
  4195. WBUFL(buf,10)=src?src->id:0;
  4196. WBUFB(buf,14)=fail;
  4197. if (disguised(dst)) {
  4198. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4199. WBUFL(buf,6)=-dst->id;
  4200. clif_send(buf,packet_len(0x11a),dst,SELF);
  4201. } else
  4202. clif_send(buf,packet_len(0x11a),dst,AREA);
  4203. if(src && disguised(src)) {
  4204. WBUFL(buf,10)=-src->id;
  4205. if (disguised(dst))
  4206. WBUFL(buf,6)=dst->id;
  4207. clif_send(buf,packet_len(0x11a),src,SELF);
  4208. }
  4209. return fail;
  4210. }
  4211. /*==========================================
  4212. * Server tells client 'src' to display effect of skill id 'skill_id' on location 'x' and 'y'
  4213. * 'val' is used for information that varies from skill to skill, usually it's the skill level
  4214. *------------------------------------------*/
  4215. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4216. {
  4217. unsigned char buf[32];
  4218. nullpo_ret(src);
  4219. WBUFW(buf,0)=0x117;
  4220. WBUFW(buf,2)=skill_id;
  4221. WBUFL(buf,4)=src->id;
  4222. WBUFW(buf,8)=val;
  4223. WBUFW(buf,10)=x;
  4224. WBUFW(buf,12)=y;
  4225. WBUFL(buf,14)=tick;
  4226. if(disguised(src)) {
  4227. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4228. WBUFL(buf,4)=-src->id;
  4229. clif_send(buf,packet_len(0x117),src,SELF);
  4230. } else
  4231. clif_send(buf,packet_len(0x117),src,AREA);
  4232. return 0;
  4233. }
  4234. /*==========================================
  4235. * Tells all client's nearby 'unit' sight range that it spawned
  4236. *------------------------------------------*/
  4237. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4238. void clif_skill_setunit(struct skill_unit *unit)
  4239. {
  4240. unsigned char buf[128];
  4241. nullpo_retv(unit);
  4242. #if PACKETVER >= 3
  4243. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4244. WBUFW(buf, 0)=0x1c9;
  4245. WBUFL(buf, 2)=unit->bl.id;
  4246. WBUFL(buf, 6)=unit->group->src_id;
  4247. WBUFW(buf,10)=unit->bl.x;
  4248. WBUFW(buf,12)=unit->bl.y;
  4249. WBUFB(buf,14)=unit->group->unit_id;
  4250. WBUFB(buf,15)=1;
  4251. WBUFB(buf,16)=1;
  4252. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4253. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4254. return;
  4255. }
  4256. #endif
  4257. WBUFW(buf, 0)=0x11f;
  4258. WBUFL(buf, 2)=unit->bl.id;
  4259. WBUFL(buf, 6)=unit->group->src_id;
  4260. WBUFW(buf,10)=unit->bl.x;
  4261. WBUFW(buf,12)=unit->bl.y;
  4262. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4263. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4264. else
  4265. WBUFB(buf,14)=unit->group->unit_id;
  4266. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4267. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4268. }
  4269. /*==========================================
  4270. * Used to display 'teleport' and 'warp portal' information on it's respective dialogs
  4271. *------------------------------------------*/
  4272. 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)
  4273. {
  4274. int fd;
  4275. nullpo_retv(sd);
  4276. fd = sd->fd;
  4277. WFIFOHEAD(fd,packet_len(0x11c));
  4278. WFIFOW(fd,0) = 0x11c;
  4279. WFIFOW(fd,2) = skill_num;
  4280. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4281. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4282. else // normal map name
  4283. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4284. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4285. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4286. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4287. WFIFOSET(fd,packet_len(0x11c));
  4288. sd->menuskill_id = skill_num;
  4289. if (skill_num == AL_WARP)
  4290. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4291. else
  4292. sd->menuskill_val = skill_lv;
  4293. }
  4294. /// Memo message.
  4295. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4296. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  4297. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  4298. ///
  4299. /// @param sd Who receives the message
  4300. /// @param type What message
  4301. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4302. {
  4303. int fd;
  4304. nullpo_retv(sd);
  4305. fd=sd->fd;
  4306. WFIFOHEAD(fd,packet_len(0x11e));
  4307. WFIFOW(fd,0)=0x11e;
  4308. WFIFOB(fd,2)=type;
  4309. WFIFOSET(fd,packet_len(0x11e));
  4310. }
  4311. /// Teleport message.
  4312. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4313. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  4314. ///
  4315. /// @param sd Who receives the message
  4316. /// @param type What message
  4317. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4318. {
  4319. int fd;
  4320. nullpo_retv(sd);
  4321. fd=sd->fd;
  4322. WFIFOHEAD(fd,packet_len(0x189));
  4323. WFIFOW(fd,0)=0x189;
  4324. WFIFOW(fd,2)=type;
  4325. WFIFOSET(fd,packet_len(0x189));
  4326. }
  4327. /*==========================================
  4328. * Server tells client to display 'estimation' (Sense) information for monster (bl) 'dst'
  4329. *------------------------------------------*/
  4330. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4331. {
  4332. struct status_data *status;
  4333. unsigned char buf[64];
  4334. int i;//, fix;
  4335. nullpo_ret(sd);
  4336. nullpo_ret(dst);
  4337. if( dst->type != BL_MOB )
  4338. return 0;
  4339. status = status_get_status_data(dst);
  4340. WBUFW(buf, 0)=0x18c;
  4341. WBUFW(buf, 2)=status_get_class(dst);
  4342. WBUFW(buf, 4)=status_get_lv(dst);
  4343. WBUFW(buf, 6)=status->size;
  4344. WBUFL(buf, 8)=status->hp;
  4345. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4346. +(battle_config.estimation_type&2?status->def2:0);
  4347. WBUFW(buf,14)=status->race;
  4348. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4349. +(battle_config.estimation_type&2?status->mdef2:0);
  4350. WBUFW(buf,18)= status->def_ele;
  4351. for(i=0;i<9;i++)
  4352. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4353. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4354. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4355. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4356. return 0;
  4357. }
  4358. /*==========================================
  4359. * Server tells client to display a window similar to Mangifier (item) one
  4360. * Server populates the window with avilable crafting options according to skill used to call this
  4361. *------------------------------------------*/
  4362. int clif_skill_produce_mix_list(struct map_session_data *sd, int skillid , int trigger)
  4363. {
  4364. int i,c,view,fd;
  4365. nullpo_ret(sd);
  4366. if(sd->menuskill_id == skillid)
  4367. return 0; //Avoid resending the menu twice or more times...
  4368. fd=sd->fd;
  4369. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4370. WFIFOW(fd, 0)=0x18d;
  4371. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4372. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4373. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4374. WFIFOW(fd,c*8+ 4)= view;
  4375. else
  4376. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4377. WFIFOW(fd,c*8+ 6)= 0x0012;
  4378. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4379. c++;
  4380. }
  4381. }
  4382. WFIFOW(fd, 2)=c*8+8;
  4383. WFIFOSET(fd,WFIFOW(fd,2));
  4384. if(c > 0) {
  4385. sd->menuskill_id = skillid;
  4386. sd->menuskill_val = trigger;
  4387. return 1;
  4388. }
  4389. return 0;
  4390. }
  4391. /*==========================================
  4392. *
  4393. *------------------------------------------*/
  4394. void clif_cooking_list(struct map_session_data *sd, int trigger)
  4395. {
  4396. int fd;
  4397. int i, c;
  4398. int view;
  4399. nullpo_retv(sd);
  4400. fd = sd->fd;
  4401. WFIFOHEAD(fd, 6 + 2*MAX_SKILL_PRODUCE_DB);
  4402. WFIFOW(fd,0) = 0x25a;
  4403. WFIFOW(fd,4) = 1; // list type
  4404. c = 0;
  4405. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ )
  4406. {
  4407. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) )
  4408. continue;
  4409. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4410. WFIFOW(fd, 6+2*c)= view;
  4411. else
  4412. WFIFOW(fd, 6+2*c)= skill_produce_db[i].nameid;
  4413. c++;
  4414. }
  4415. WFIFOW(fd,2) = 6 + 2*c;
  4416. WFIFOSET(fd,WFIFOW(fd,2));
  4417. //TODO: replace with proper solution
  4418. if( c > 0 )
  4419. {
  4420. sd->menuskill_id = AM_PHARMACY;
  4421. sd->menuskill_val = trigger;
  4422. }
  4423. }
  4424. /*==========================================
  4425. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4426. *------------------------------------------*/
  4427. int clif_status_load(struct block_list *bl,int type, int flag)
  4428. {
  4429. int fd;
  4430. if (type == SI_BLANK) //It shows nothing on the client...
  4431. return 0;
  4432. if (bl->type != BL_PC)
  4433. return 0;
  4434. fd = ((struct map_session_data*)bl)->fd;
  4435. WFIFOHEAD(fd,packet_len(0x196));
  4436. WFIFOW(fd,0)=0x0196;
  4437. WFIFOW(fd,2)=type;
  4438. WFIFOL(fd,4)=bl->id;
  4439. WFIFOB(fd,8)=flag; //Status start
  4440. WFIFOSET(fd, packet_len(0x196));
  4441. return 0;
  4442. }
  4443. /*==========================================
  4444. * Server tell's BL and nearby clients of his status change
  4445. *------------------------------------------*/
  4446. int clif_status_change(struct block_list *bl,int type,int flag,unsigned int tick,int val1, int val2, int val3)
  4447. {
  4448. unsigned char buf[32];
  4449. if (type == SI_BLANK) //It shows nothing on the client...
  4450. return 0;
  4451. nullpo_ret(bl);
  4452. if (type == SI_BLANK || type == SI_MAXIMIZEPOWER || type == SI_RIDING ||
  4453. type == SI_FALCON || type == SI_TRICKDEAD || type == SI_BROKENARMOR ||
  4454. type == SI_BROKENWEAPON || type == SI_WEIGHT50 || type == SI_WEIGHT90 ||
  4455. type == SI_TENSIONRELAX || type == SI_LANDENDOW || type == SI_AUTOBERSERK ||
  4456. type == SI_BUMP || type == SI_READYSTORM || type == SI_READYDOWN ||
  4457. type == SI_READYTURN || type == SI_READYCOUNTER || type == SI_DODGE ||
  4458. type == SI_DEVIL || type == SI_NIGHT || type == SI_INTRAVISION)
  4459. tick=0;
  4460. if( battle_config.display_status_timers && tick>0 )
  4461. WBUFW(buf,0)=0x043f;
  4462. else
  4463. WBUFW(buf,0)=0x0196;
  4464. WBUFW(buf,2)=type;
  4465. WBUFL(buf,4)=bl->id;
  4466. WBUFB(buf,8)=flag;
  4467. if( battle_config.display_status_timers && tick>0 )
  4468. {
  4469. WBUFL(buf,9)=tick;
  4470. WBUFL(buf,13) = val1;
  4471. WBUFL(buf,17) = val2;
  4472. WBUFL(buf,21) = val3;
  4473. }
  4474. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  4475. return 0;
  4476. }
  4477. /*==========================================
  4478. * Send message (modified by [Yor])
  4479. *------------------------------------------*/
  4480. int clif_displaymessage(const int fd, const char* mes)
  4481. {
  4482. // invalid pointer?
  4483. nullpo_retr(-1, mes);
  4484. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4485. if (fd == 0)
  4486. return 0;
  4487. else {
  4488. int len_mes = strlen(mes);
  4489. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4490. WFIFOHEAD(fd, 5 + len_mes);
  4491. WFIFOW(fd,0) = 0x8e;
  4492. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4493. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4494. WFIFOSET(fd, 5 + len_mes);
  4495. }
  4496. }
  4497. return 0;
  4498. }
  4499. /*==========================================
  4500. * Send broadcast message in yellow or blue (without font formatting).
  4501. * S 009A <len>.W <message>.?B
  4502. *------------------------------------------*/
  4503. int clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4504. {
  4505. int lp = type ? 4 : 0;
  4506. unsigned char *buf = (unsigned char*)aMallocA((4 + lp + len)*sizeof(unsigned char));
  4507. WBUFW(buf,0) = 0x9a;
  4508. WBUFW(buf,2) = 4 + lp + len;
  4509. if (type == 0x10) // bc_blue
  4510. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4511. else if (type == 0x20) // bc_woe
  4512. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4513. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4514. clif_send(buf, WBUFW(buf,2), bl, target);
  4515. if (buf)
  4516. aFree(buf);
  4517. return 0;
  4518. }
  4519. /*==========================================
  4520. * Displays a message on a 'bl' to all it's nearby clients
  4521. * Used by npc_globalmessage
  4522. *------------------------------------------*/
  4523. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4524. {
  4525. char buf[100];
  4526. int len;
  4527. nullpo_retv(bl);
  4528. if(!message)
  4529. return;
  4530. len = strlen(message)+1;
  4531. if( len > sizeof(buf)-8 )
  4532. {
  4533. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4534. len = sizeof(buf)-8;
  4535. }
  4536. WBUFW(buf,0)=0x8d;
  4537. WBUFW(buf,2)=len+8;
  4538. WBUFL(buf,4)=bl->id;
  4539. safestrncpy((char *) WBUFP(buf,8),message,len);
  4540. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4541. }
  4542. /*==========================================
  4543. * Send main chat message [LuzZza]
  4544. *------------------------------------------*/
  4545. void clif_MainChatMessage(const char* message)
  4546. {
  4547. uint8 buf[200];
  4548. int len;
  4549. if(!message)
  4550. return;
  4551. len = strlen(message)+1;
  4552. if (len+8 > sizeof(buf)) {
  4553. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4554. len = sizeof(buf)-8;
  4555. }
  4556. WBUFW(buf,0)=0x8d;
  4557. WBUFW(buf,2)=len+8;
  4558. WBUFL(buf,4)=0;
  4559. safestrncpy((char *) WBUFP(buf,8),message,len);
  4560. clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4561. }
  4562. /*==========================================
  4563. * Send broadcast message with font formatting.
  4564. * S 01C3 <len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4565. *------------------------------------------*/
  4566. int 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)
  4567. {
  4568. unsigned char *buf = (unsigned char*)aMallocA((16 + len)*sizeof(unsigned char));
  4569. WBUFW(buf,0) = 0x1c3;
  4570. WBUFW(buf,2) = len + 16;
  4571. WBUFL(buf,4) = fontColor;
  4572. WBUFW(buf,8) = fontType;
  4573. WBUFW(buf,10) = fontSize;
  4574. WBUFW(buf,12) = fontAlign;
  4575. WBUFW(buf,14) = fontY;
  4576. memcpy(WBUFP(buf,16), mes, len);
  4577. clif_send(buf, WBUFW(buf,2), bl, target);
  4578. if (buf)
  4579. aFree(buf);
  4580. return 0;
  4581. }
  4582. /*==========================================
  4583. * Server tells self client to heal self for 'val', is either SP_HP or SP_SP
  4584. * It displays these green and blue heal numbers that show up at your body and go up until they fade away
  4585. *------------------------------------------*/
  4586. int clif_heal(int fd,int type,int val)
  4587. {
  4588. WFIFOHEAD(fd,packet_len(0x13d));
  4589. WFIFOW(fd,0)=0x13d;
  4590. WFIFOW(fd,2)=type;
  4591. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4592. WFIFOSET(fd,packet_len(0x13d));
  4593. return 0;
  4594. }
  4595. /*==========================================
  4596. * Server tells nearby clients of 'bl' that it ressurected (and plays ress effect)
  4597. *------------------------------------------*/
  4598. int clif_resurrection(struct block_list *bl,int type)
  4599. {
  4600. unsigned char buf[16];
  4601. nullpo_ret(bl);
  4602. WBUFW(buf,0)=0x148;
  4603. WBUFL(buf,2)=bl->id;
  4604. WBUFW(buf,6)=type;
  4605. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4606. if (disguised(bl))
  4607. clif_spawn(bl);
  4608. return 0;
  4609. }
  4610. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4611. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4612. {
  4613. int fd;
  4614. nullpo_retv(sd);
  4615. fd=sd->fd;
  4616. WFIFOHEAD(fd,packet_len(0x199));
  4617. WFIFOW(fd,0)=0x199;
  4618. WFIFOW(fd,2)=property;
  4619. WFIFOSET(fd,packet_len(0x199));
  4620. }
  4621. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2)
  4622. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4623. {
  4624. int fd;
  4625. nullpo_retv(sd);
  4626. fd=sd->fd;
  4627. WFIFOHEAD(fd,packet_len(0x1D6));
  4628. WFIFOW(fd,0)=0x1D6;
  4629. WFIFOW(fd,2)=type;
  4630. WFIFOSET(fd,packet_len(0x1D6));
  4631. }
  4632. /*==========================================
  4633. * Server tells client on it's pvp rank and map status,
  4634. * (it controls the counter on the bottom right of the map existent in pvp rooms)
  4635. *------------------------------------------*/
  4636. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4637. {
  4638. if(type == 2) {
  4639. int fd = sd->fd;
  4640. WFIFOHEAD(fd,packet_len(0x19a));
  4641. WFIFOW(fd,0) = 0x19a;
  4642. WFIFOL(fd,2) = sd->bl.id;
  4643. WFIFOL(fd,6) = pvprank;
  4644. WFIFOL(fd,10) = pvpnum;
  4645. WFIFOSET(fd,packet_len(0x19a));
  4646. } else {
  4647. unsigned char buf[32];
  4648. WBUFW(buf,0) = 0x19a;
  4649. WBUFL(buf,2) = sd->bl.id;
  4650. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4651. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4652. else
  4653. WBUFL(buf,6) = pvprank;
  4654. WBUFL(buf,10) = pvpnum;
  4655. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4656. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4657. else if(!type)
  4658. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4659. else
  4660. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4661. }
  4662. return 0;
  4663. }
  4664. /*==========================================
  4665. *
  4666. *------------------------------------------*/
  4667. void clif_map_property_mapall(int map, enum map_property property)
  4668. {
  4669. struct block_list bl;
  4670. unsigned char buf[16];
  4671. bl.id = 0;
  4672. bl.type = BL_NUL;
  4673. bl.m = map;
  4674. WBUFW(buf,0)=0x199;
  4675. WBUFW(buf,2)=property;
  4676. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4677. }
  4678. /*==========================================
  4679. * Server tells client the status on refine of item index 'index' from refine 'val'
  4680. * Message displayed depends on 'fail' (broken(red) or success(blue))
  4681. *------------------------------------------*/
  4682. void clif_refine(int fd, int fail, int index, int val)
  4683. {
  4684. WFIFOHEAD(fd,packet_len(0x188));
  4685. WFIFOW(fd,0)=0x188;
  4686. WFIFOW(fd,2)=fail;
  4687. WFIFOW(fd,4)=index+2;
  4688. WFIFOW(fd,6)=val;
  4689. WFIFOSET(fd,packet_len(0x188));
  4690. }
  4691. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4692. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4693. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4694. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4695. void clif_upgrademessage(int fd, int result, int item_id)
  4696. {
  4697. WFIFOHEAD(fd,packet_len(0x223));
  4698. WFIFOW(fd,0)=0x223;
  4699. WFIFOL(fd,2)=result;
  4700. WFIFOW(fd,6)=item_id;
  4701. WFIFOSET(fd,packet_len(0x223));
  4702. }
  4703. /*==========================================
  4704. * Wisp/page is transmitted to the destination player
  4705. * R 0097 <len>.w <nick>.24B <message>.?B
  4706. * R 0097 <len>.w <nick>.24B <???>.L <message>.?B
  4707. *------------------------------------------*/
  4708. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4709. {
  4710. #if PACKETVER < 20091104
  4711. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4712. WFIFOW(fd,0) = 0x97;
  4713. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4714. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4715. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4716. WFIFOSET(fd,WFIFOW(fd,2));
  4717. #else
  4718. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4719. WFIFOW(fd,0) = 0x97;
  4720. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4721. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4722. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4723. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4724. WFIFOSET(fd,WFIFOW(fd,2));
  4725. #endif
  4726. return 0;
  4727. }
  4728. /*==========================================
  4729. * Inform the player about the result of his whisper action
  4730. * R 0098 <type>.B
  4731. * 0: success to send wisper
  4732. * 1: target character is not loged in
  4733. * 2: ignored by target
  4734. * 3: everyone ignored by target
  4735. *------------------------------------------*/
  4736. int clif_wis_end(int fd, int flag)
  4737. {
  4738. WFIFOHEAD(fd,packet_len(0x98));
  4739. WFIFOW(fd,0) = 0x98;
  4740. WFIFOW(fd,2) = flag;
  4741. WFIFOSET(fd,packet_len(0x98));
  4742. return 0;
  4743. }
  4744. /*==========================================
  4745. * Server tells client that char id 'charid' is to be assigned the name of 'name'
  4746. * This is used when client requests the server the name written in a item, e.g. crafted alche potions
  4747. *------------------------------------------*/
  4748. int clif_solved_charname(int fd, int charid, const char* name)
  4749. {
  4750. WFIFOHEAD(fd,packet_len(0x194));
  4751. WFIFOW(fd,0)=0x194;
  4752. WFIFOL(fd,2)=charid;
  4753. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4754. WFIFOSET(fd,packet_len(0x194));
  4755. return 0;
  4756. }
  4757. /*==========================================
  4758. * Server tells client to list all items that may be worn by card item of index 'idx'
  4759. *------------------------------------------*/
  4760. int clif_use_card(struct map_session_data *sd,int idx)
  4761. {
  4762. int i,c,ep;
  4763. int fd=sd->fd;
  4764. nullpo_ret(sd);
  4765. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4766. return 0;
  4767. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4768. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4769. ep=sd->inventory_data[idx]->equip;
  4770. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4771. WFIFOW(fd,0)=0x017b;
  4772. for(i=c=0;i<MAX_INVENTORY;i++){
  4773. int j;
  4774. if(sd->inventory_data[i] == NULL)
  4775. continue;
  4776. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4777. continue;
  4778. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4779. continue;
  4780. if(sd->status.inventory[i].identify==0 ) //Not identified
  4781. continue;
  4782. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4783. continue;
  4784. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4785. continue;
  4786. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4787. if( j == sd->inventory_data[i]->slot ) // No room
  4788. continue;
  4789. WFIFOW(fd,4+c*2)=i+2;
  4790. c++;
  4791. }
  4792. WFIFOW(fd,2)=4+c*2;
  4793. WFIFOSET(fd,WFIFOW(fd,2));
  4794. return 0;
  4795. }
  4796. /*==========================================
  4797. * Server tells client his status on the previous clif_use_card (failed or OK)
  4798. *------------------------------------------*/
  4799. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4800. {
  4801. int fd;
  4802. nullpo_ret(sd);
  4803. fd=sd->fd;
  4804. WFIFOHEAD(fd,packet_len(0x17d));
  4805. WFIFOW(fd,0)=0x17d;
  4806. WFIFOW(fd,2)=idx_equip+2;
  4807. WFIFOW(fd,4)=idx_card+2;
  4808. WFIFOB(fd,6)=flag;
  4809. WFIFOSET(fd,packet_len(0x17d));
  4810. return 0;
  4811. }
  4812. /*==========================================
  4813. * Server tells client it's list of unidentified items
  4814. *------------------------------------------*/
  4815. int clif_item_identify_list(struct map_session_data *sd)
  4816. {
  4817. int i,c;
  4818. int fd;
  4819. nullpo_ret(sd);
  4820. fd=sd->fd;
  4821. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4822. WFIFOW(fd,0)=0x177;
  4823. for(i=c=0;i<MAX_INVENTORY;i++){
  4824. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4825. WFIFOW(fd,c*2+4)=i+2;
  4826. c++;
  4827. }
  4828. }
  4829. if(c > 0) {
  4830. WFIFOW(fd,2)=c*2+4;
  4831. WFIFOSET(fd,WFIFOW(fd,2));
  4832. sd->menuskill_id = MC_IDENTIFY;
  4833. sd->menuskill_val = c;
  4834. }
  4835. return 0;
  4836. }
  4837. /*==========================================
  4838. * Server tells client his item of index 'idx' has been identified
  4839. *------------------------------------------*/
  4840. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4841. {
  4842. int fd;
  4843. nullpo_ret(sd);
  4844. fd=sd->fd;
  4845. WFIFOHEAD(fd,packet_len(0x179));
  4846. WFIFOW(fd, 0)=0x179;
  4847. WFIFOW(fd, 2)=idx+2;
  4848. WFIFOB(fd, 4)=flag;
  4849. WFIFOSET(fd,packet_len(0x179));
  4850. return 0;
  4851. }
  4852. /*==========================================
  4853. * Server tells client the list of broken items
  4854. *------------------------------------------*/
  4855. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4856. {
  4857. int i,c;
  4858. int fd;
  4859. int nameid;
  4860. nullpo_ret(sd);
  4861. nullpo_ret(dstsd);
  4862. fd=sd->fd;
  4863. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4864. WFIFOW(fd,0)=0x1fc;
  4865. for(i=c=0;i<MAX_INVENTORY;i++){
  4866. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4867. WFIFOW(fd,c*13+4) = i;
  4868. WFIFOW(fd,c*13+6) = nameid;
  4869. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4870. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4871. WFIFOB(fd,c*13+16)= c;
  4872. c++;
  4873. }
  4874. }
  4875. if(c > 0) {
  4876. WFIFOW(fd,2)=c*13+4;
  4877. WFIFOSET(fd,WFIFOW(fd,2));
  4878. sd->menuskill_id = BS_REPAIRWEAPON;
  4879. sd->menuskill_val = dstsd->bl.id;
  4880. }else
  4881. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4882. return 0;
  4883. }
  4884. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4885. {
  4886. int view,fd;
  4887. nullpo_ret(sd);
  4888. fd=sd->fd;
  4889. WFIFOHEAD(fd,packet_len(0x1fe));
  4890. WFIFOW(fd, 0)=0x1fe;
  4891. if((view = itemdb_viewid(nameid)) > 0)
  4892. WFIFOW(fd, 2)=view;
  4893. else
  4894. WFIFOW(fd, 2)=nameid;
  4895. WFIFOB(fd, 4)=flag;
  4896. WFIFOSET(fd,packet_len(0x1fe));
  4897. return 0;
  4898. }
  4899. /*==========================================
  4900. * Weapon Refining - Taken from jAthena
  4901. *------------------------------------------*/
  4902. int clif_item_refine_list(struct map_session_data *sd)
  4903. {
  4904. int i,c;
  4905. int fd;
  4906. int skilllv;
  4907. int wlv;
  4908. int refine_item[5];
  4909. nullpo_ret(sd);
  4910. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4911. fd=sd->fd;
  4912. refine_item[0] = -1;
  4913. refine_item[1] = pc_search_inventory(sd,1010);
  4914. refine_item[2] = pc_search_inventory(sd,1011);
  4915. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4916. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4917. WFIFOW(fd,0)=0x221;
  4918. for(i=c=0;i<MAX_INVENTORY;i++){
  4919. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4920. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4921. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4922. WFIFOW(fd,c*13+ 4)=i+2;
  4923. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4924. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4925. WFIFOW(fd,c*13+10)=0;
  4926. WFIFOB(fd,c*13+12)=c;
  4927. c++;
  4928. }
  4929. }
  4930. WFIFOW(fd,2)=c*13+4;
  4931. WFIFOSET(fd,WFIFOW(fd,2));
  4932. if (c > 0) {
  4933. sd->menuskill_id = WS_WEAPONREFINE;
  4934. sd->menuskill_val = skilllv;
  4935. }
  4936. return 0;
  4937. }
  4938. /*==========================================
  4939. * Server tells client to display the 'green skill name' at the top of the screen + target cursor,
  4940. * for skill 'skillid' of 'skilllv' level
  4941. * Used for example when player uses a skill scroll (e.g. Fire Bolt Scroll)
  4942. *------------------------------------------*/
  4943. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4944. {
  4945. int fd;
  4946. nullpo_ret(sd);
  4947. fd=sd->fd;
  4948. WFIFOHEAD(fd,packet_len(0x147));
  4949. WFIFOW(fd, 0)=0x147;
  4950. WFIFOW(fd, 2)=skillid;
  4951. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4952. WFIFOW(fd, 6)=0;
  4953. WFIFOW(fd, 8)=skilllv;
  4954. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4955. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4956. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4957. WFIFOB(fd,38)=0;
  4958. WFIFOSET(fd,packet_len(0x147));
  4959. return 0;
  4960. }
  4961. /*==========================================
  4962. * Server tells client it's status on trying to add item of index 'n' and amount 'amount' to it's cart
  4963. *------------------------------------------*/
  4964. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4965. {
  4966. int view,fd;
  4967. unsigned char *buf;
  4968. nullpo_ret(sd);
  4969. fd=sd->fd;
  4970. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4971. return 1;
  4972. #if PACKETVER < 5
  4973. WFIFOHEAD(fd,packet_len(0x124));
  4974. buf=WFIFOP(fd,0);
  4975. WBUFW(buf,0)=0x124;
  4976. WBUFW(buf,2)=n+2;
  4977. WBUFL(buf,4)=amount;
  4978. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4979. WBUFW(buf,8)=view;
  4980. else
  4981. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4982. WBUFB(buf,10)=sd->status.cart[n].identify;
  4983. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4984. WBUFB(buf,12)=sd->status.cart[n].refine;
  4985. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4986. WFIFOSET(fd,packet_len(0x124));
  4987. #else
  4988. WFIFOHEAD(fd,packet_len(0x1c5));
  4989. buf=WFIFOP(fd,0);
  4990. WBUFW(buf,0)=0x1c5;
  4991. WBUFW(buf,2)=n+2;
  4992. WBUFL(buf,4)=amount;
  4993. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4994. WBUFW(buf,8)=view;
  4995. else
  4996. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4997. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4998. WBUFB(buf,11)=sd->status.cart[n].identify;
  4999. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5000. WBUFB(buf,13)=sd->status.cart[n].refine;
  5001. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5002. WFIFOSET(fd,packet_len(0x1c5));
  5003. #endif
  5004. return 0;
  5005. }
  5006. /*==========================================
  5007. * Server tells client it's status on trying to remove item of index 'n' and amount 'amount' from it's cart to invent
  5008. *------------------------------------------*/
  5009. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5010. {
  5011. int fd;
  5012. nullpo_ret(sd);
  5013. fd=sd->fd;
  5014. WFIFOHEAD(fd,packet_len(0x125));
  5015. WFIFOW(fd,0)=0x125;
  5016. WFIFOW(fd,2)=n+2;
  5017. WFIFOL(fd,4)=amount;
  5018. WFIFOSET(fd,packet_len(0x125));
  5019. return 0;
  5020. }
  5021. /*==========================================
  5022. * Opens the shop creation menu.
  5023. * R 012d <num>.w
  5024. * 'num' is the number of allowed item slots
  5025. *------------------------------------------*/
  5026. void clif_openvendingreq(struct map_session_data* sd, int num)
  5027. {
  5028. int fd;
  5029. nullpo_retv(sd);
  5030. fd = sd->fd;
  5031. WFIFOHEAD(fd,packet_len(0x12d));
  5032. WFIFOW(fd,0) = 0x12d;
  5033. WFIFOW(fd,2) = num;
  5034. WFIFOSET(fd,packet_len(0x12d));
  5035. }
  5036. /*==========================================
  5037. * Displays a vending board to target/area
  5038. * R 0131 <ID>.l <message>.80B
  5039. *------------------------------------------*/
  5040. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5041. {
  5042. unsigned char buf[128];
  5043. nullpo_retv(bl);
  5044. WBUFW(buf,0) = 0x131;
  5045. WBUFL(buf,2) = bl->id;
  5046. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5047. if( fd ) {
  5048. WFIFOHEAD(fd,packet_len(0x131));
  5049. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5050. WFIFOSET(fd,packet_len(0x131));
  5051. } else {
  5052. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5053. }
  5054. }
  5055. /*==========================================
  5056. * Removes a vending board from screen
  5057. *------------------------------------------*/
  5058. void clif_closevendingboard(struct block_list* bl, int fd)
  5059. {
  5060. unsigned char buf[16];
  5061. nullpo_retv(bl);
  5062. WBUFW(buf,0) = 0x132;
  5063. WBUFL(buf,2) = bl->id;
  5064. if( fd ) {
  5065. WFIFOHEAD(fd,packet_len(0x132));
  5066. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5067. WFIFOSET(fd,packet_len(0x132));
  5068. } else {
  5069. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5070. }
  5071. }
  5072. /*==========================================
  5073. * Sends a list of items in a shop (ZC_PC_PURCHASE_ITEMLIST_FROMMC/ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  5074. * R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  5075. * R 0800 <len>.w <ID>.l <UniqueID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  5076. *------------------------------------------*/
  5077. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5078. {
  5079. int i,fd;
  5080. int count;
  5081. struct map_session_data* vsd;
  5082. #if PACKETVER < 20100105
  5083. const int cmd = 0x133;
  5084. const int offset = 8;
  5085. #else
  5086. const int cmd = 0x800;
  5087. const int offset = 12;
  5088. #endif
  5089. nullpo_retv(sd);
  5090. nullpo_retv(vending);
  5091. nullpo_retv(vsd=map_id2sd(id));
  5092. fd = sd->fd;
  5093. count = vsd->vend_num;
  5094. WFIFOHEAD(fd, offset+count*22);
  5095. WFIFOW(fd,0) = cmd;
  5096. WFIFOW(fd,2) = offset+count*22;
  5097. WFIFOL(fd,4) = id;
  5098. #if PACKETVER >= 20100105
  5099. WFIFOL(fd,8) = vsd->vender_id;
  5100. #endif
  5101. for( i = 0; i < count; i++ )
  5102. {
  5103. int index = vending[i].index;
  5104. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5105. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5106. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5107. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5108. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5109. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5110. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5111. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5112. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5113. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5114. }
  5115. WFIFOSET(fd,WFIFOW(fd,2));
  5116. }
  5117. /*==========================================
  5118. * Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC)
  5119. * R 0135 <index>.w <amount>.w <fail>.B
  5120. * fail=1 - not enough zeny
  5121. * fail=2 - overweight
  5122. * fail=4 - out of stock
  5123. * fail=5 - "cannot use an npc shop while in a trade"
  5124. * fail=6 - Because the store information was incorrect the item was not purchased.
  5125. * fail=7 - No sales information.
  5126. *------------------------------------------*/
  5127. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5128. {
  5129. int fd;
  5130. nullpo_retv(sd);
  5131. fd = sd->fd;
  5132. WFIFOHEAD(fd,packet_len(0x135));
  5133. WFIFOW(fd,0) = 0x135;
  5134. WFIFOW(fd,2) = index+2;
  5135. WFIFOW(fd,4) = amount;
  5136. WFIFOB(fd,6) = fail;
  5137. WFIFOSET(fd,packet_len(0x135));
  5138. }
  5139. /*==========================================
  5140. * Shop creation success
  5141. * R 0136 <len>.w <ID>.l {<value>.l <index>.w <amount>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B*
  5142. *------------------------------------------*/
  5143. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5144. {
  5145. int i,fd;
  5146. int count;
  5147. nullpo_retv(sd);
  5148. fd = sd->fd;
  5149. count = sd->vend_num;
  5150. WFIFOHEAD(fd, 8+count*22);
  5151. WFIFOW(fd,0) = 0x136;
  5152. WFIFOW(fd,2) = 8+count*22;
  5153. WFIFOL(fd,4) = id;
  5154. for( i = 0; i < count; i++ )
  5155. {
  5156. int index = vending[i].index;
  5157. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5158. WFIFOL(fd, 8+i*22) = vending[i].value;
  5159. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5160. WFIFOW(fd,14+i*22) = vending[i].amount;
  5161. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5162. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5163. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5164. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5165. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5166. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5167. }
  5168. WFIFOSET(fd,WFIFOW(fd,2));
  5169. }
  5170. /*==========================================
  5171. * Inform merchant that someone has bought an item.
  5172. * R 0137 <index>.w <amount>.w
  5173. *------------------------------------------*/
  5174. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5175. {
  5176. int fd;
  5177. nullpo_retv(sd);
  5178. fd = sd->fd;
  5179. WFIFOHEAD(fd,packet_len(0x137));
  5180. WFIFOW(fd,0) = 0x137;
  5181. WFIFOW(fd,2) = index+2;
  5182. WFIFOW(fd,4) = amount;
  5183. WFIFOSET(fd,packet_len(0x137));
  5184. }
  5185. /// Result of organizing a party.
  5186. /// R 00FA <result>.B
  5187. ///
  5188. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  5189. /// result=1 : MsgStringTable[78]="party name already exists"
  5190. /// result=2 : MsgStringTable[79]="already in a party"
  5191. /// result=other : nothing
  5192. int clif_party_created(struct map_session_data *sd,int result)
  5193. {
  5194. int fd;
  5195. nullpo_ret(sd);
  5196. fd=sd->fd;
  5197. WFIFOHEAD(fd,packet_len(0xfa));
  5198. WFIFOW(fd,0)=0xfa;
  5199. WFIFOB(fd,2)=result;
  5200. WFIFOSET(fd,packet_len(0xfa));
  5201. return 0;
  5202. }
  5203. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5204. {
  5205. unsigned char buf[96];
  5206. int i;
  5207. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5208. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5209. } else {
  5210. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5211. }
  5212. if (i >= MAX_PARTY) return 0; //Should never happen...
  5213. sd = p->data[i].sd;
  5214. WBUFW(buf, 0) = 0x1e9;
  5215. WBUFL(buf, 2) = sd->status.account_id;
  5216. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5217. WBUFW(buf,10) = sd->bl.x;
  5218. WBUFW(buf,12) = sd->bl.y;
  5219. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5220. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5221. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5222. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  5223. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5224. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5225. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5226. return 1;
  5227. }
  5228. /*==========================================
  5229. * Sends party information
  5230. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  5231. *------------------------------------------*/
  5232. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  5233. {
  5234. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5235. struct map_session_data* party_sd = NULL;
  5236. int i, c;
  5237. nullpo_ret(p);
  5238. WBUFW(buf,0) = 0xfb;
  5239. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5240. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5241. {
  5242. struct party_member* m = &p->party.member[i];
  5243. if(!m->account_id) continue;
  5244. if(party_sd == NULL) party_sd = p->data[i].sd;
  5245. WBUFL(buf,28+c*46) = m->account_id;
  5246. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5247. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5248. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5249. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5250. c++;
  5251. }
  5252. WBUFW(buf,2) = 28+c*46;
  5253. if(sd) { // send only to self
  5254. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5255. } else if (party_sd) { // send to whole party
  5256. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5257. }
  5258. return 0;
  5259. }
  5260. /*==========================================
  5261. * The player's 'party invite' state, sent during login
  5262. * R 02c9 <flag>.B
  5263. *------------------------------------------*/
  5264. void clif_partyinvitationstate(struct map_session_data* sd)
  5265. {
  5266. int fd;
  5267. nullpo_retv(sd);
  5268. fd = sd->fd;
  5269. WFIFOHEAD(fd, packet_len(0x2c9));
  5270. WFIFOW(fd, 0) = 0x2c9;
  5271. WFIFOB(fd, 2) = 0; // not implemented
  5272. WFIFOSET(fd, packet_len(0x2c9));
  5273. }
  5274. /// Party invitation request (ZC_REQ_JOIN_GROUP/ZC_PARTY_JOIN_REQ)
  5275. /// 00fe <party id>.L <party name>.24B
  5276. /// 02c6 <party id>.L <party name>.24B
  5277. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5278. {
  5279. #if PACKETVER < 20070821
  5280. const int cmd = 0xfe;
  5281. #else
  5282. const int cmd = 0x2c6;
  5283. #endif
  5284. int fd;
  5285. struct party_data *p;
  5286. nullpo_retv(sd);
  5287. nullpo_retv(tsd);
  5288. fd=tsd->fd;
  5289. if( (p=party_search(sd->status.party_id))==NULL )
  5290. return;
  5291. WFIFOHEAD(fd,packet_len(cmd));
  5292. WFIFOW(fd,0)=cmd;
  5293. WFIFOL(fd,2)=sd->status.party_id;
  5294. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5295. WFIFOSET(fd,packet_len(cmd));
  5296. }
  5297. /// Party invite result.
  5298. /// R 00fd <nick>.24S <result>.B
  5299. /// R 02c5 <nick>.24S <result>.L
  5300. /// result=0 : char is already in a party -> MsgStringTable[80]
  5301. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5302. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5303. /// result=3 : party is full -> MsgStringTable[83]
  5304. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5305. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5306. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5307. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5308. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5309. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5310. {
  5311. int fd;
  5312. nullpo_retv(sd);
  5313. fd=sd->fd;
  5314. #if PACKETVER < 20070904
  5315. if( result == 7 ) {
  5316. clif_displaymessage(fd, msg_txt(3));
  5317. return;
  5318. }
  5319. #endif
  5320. #if PACKETVER < 20070821
  5321. WFIFOHEAD(fd,packet_len(0xfd));
  5322. WFIFOW(fd,0) = 0xfd;
  5323. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5324. WFIFOB(fd,26) = result;
  5325. WFIFOSET(fd,packet_len(0xfd));
  5326. #else
  5327. WFIFOHEAD(fd,packet_len(0x2c5));
  5328. WFIFOW(fd,0) = 0x2c5;
  5329. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5330. WFIFOL(fd,26) = result;
  5331. WFIFOSET(fd,packet_len(0x2c5));
  5332. #endif
  5333. }
  5334. /*==========================================
  5335. * Server tells client (and it's party members) of a change in the party settings
  5336. * 'Flag' Options
  5337. * - 0x01 (exp)
  5338. * - 0x10 (item)
  5339. * - 0x100 (party member logged in / was added to party)
  5340. *------------------------------------------*/
  5341. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5342. {
  5343. unsigned char buf[16];
  5344. #if PACKETVER<20090603
  5345. const int cmd = 0x101;
  5346. #else
  5347. const int cmd = 0x7d8;
  5348. #endif
  5349. nullpo_ret(p);
  5350. if(!sd && flag==0){
  5351. int i;
  5352. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5353. if (i < MAX_PARTY)
  5354. sd = p->data[i].sd;
  5355. }
  5356. if(!sd) return 0;
  5357. WBUFW(buf,0)=cmd;
  5358. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5359. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5360. WBUFW(buf,4)=0;
  5361. #if PACKETVER>=20090603
  5362. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5363. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5364. #endif
  5365. if(flag==0)
  5366. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5367. else
  5368. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5369. return 0;
  5370. }
  5371. /*==========================================
  5372. * Server tells party members of party 'p' that 'sd' player left
  5373. *------------------------------------------*/
  5374. int clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5375. {
  5376. unsigned char buf[64];
  5377. int i;
  5378. nullpo_ret(p);
  5379. if(!sd && (flag&0xf0)==0)
  5380. {
  5381. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5382. if (i < MAX_PARTY)
  5383. sd = p->data[i].sd;
  5384. }
  5385. if(!sd) return 0;
  5386. WBUFW(buf,0)=0x105;
  5387. WBUFL(buf,2)=account_id;
  5388. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5389. WBUFB(buf,30)=flag&0x0f;
  5390. if((flag&0xf0)==0)
  5391. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5392. else
  5393. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5394. return 0;
  5395. }
  5396. /*==========================================
  5397. * Server deploys a message to all party members, called from party.c:party_recv_message()
  5398. *------------------------------------------*/
  5399. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5400. {
  5401. struct map_session_data *sd;
  5402. int i;
  5403. nullpo_ret(p);
  5404. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5405. if(i < MAX_PARTY){
  5406. unsigned char buf[1024];
  5407. sd = p->data[i].sd;
  5408. WBUFW(buf,0)=0x109;
  5409. WBUFW(buf,2)=len+8;
  5410. WBUFL(buf,4)=account_id;
  5411. memcpy(WBUFP(buf,8),mes,len);
  5412. clif_send(buf,len+8,&sd->bl,PARTY);
  5413. }
  5414. return 0;
  5415. }
  5416. /*==========================================
  5417. * Server tells all party members of 'sd' player that 'sd' player location changed
  5418. *------------------------------------------*/
  5419. int clif_party_xy(struct map_session_data *sd)
  5420. {
  5421. unsigned char buf[16];
  5422. nullpo_ret(sd);
  5423. WBUFW(buf,0)=0x107;
  5424. WBUFL(buf,2)=sd->status.account_id;
  5425. WBUFW(buf,6)=sd->bl.x;
  5426. WBUFW(buf,8)=sd->bl.y;
  5427. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5428. return 0;
  5429. }
  5430. /*==========================================
  5431. * Sends x/y dot to a single fd. [Skotlex]
  5432. *------------------------------------------*/
  5433. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5434. {
  5435. WFIFOHEAD(fd,packet_len(0x107));
  5436. WFIFOW(fd,0)=0x107;
  5437. WFIFOL(fd,2)=sd->status.account_id;
  5438. WFIFOW(fd,6)=sd->bl.x;
  5439. WFIFOW(fd,8)=sd->bl.y;
  5440. WFIFOSET(fd,packet_len(0x107));
  5441. return 0;
  5442. }
  5443. /*==========================================
  5444. * Server tells nearby party members of 'sd' that his hp bar has updated
  5445. *------------------------------------------*/
  5446. int clif_party_hp(struct map_session_data *sd)
  5447. {
  5448. unsigned char buf[16];
  5449. #if PACKETVER < 20100126
  5450. const int cmd = 0x106;
  5451. #else
  5452. const int cmd = 0x80e;
  5453. #endif
  5454. nullpo_ret(sd);
  5455. WBUFW(buf,0)=cmd;
  5456. WBUFL(buf,2)=sd->status.account_id;
  5457. #if PACKETVER < 20100126
  5458. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5459. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5460. WBUFW(buf,8) = 100;
  5461. } else {
  5462. WBUFW(buf,6) = sd->battle_status.hp;
  5463. WBUFW(buf,8) = sd->battle_status.max_hp;
  5464. }
  5465. #else
  5466. WBUFL(buf,6) = sd->battle_status.hp;
  5467. WBUFL(buf,10) = sd->battle_status.max_hp;
  5468. #endif
  5469. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5470. return 0;
  5471. }
  5472. /*==========================================
  5473. * Sends HP bar to a single fd. [Skotlex]
  5474. *------------------------------------------*/
  5475. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5476. {
  5477. #if PACKETVER < 20100126
  5478. const int cmd = 0x106;
  5479. #else
  5480. const int cmd = 0x80e;
  5481. #endif
  5482. WFIFOHEAD(fd,packet_len(cmd));
  5483. WFIFOW(fd,0) = cmd;
  5484. WFIFOL(fd,2) = id;
  5485. #if PACKETVER < 20100126
  5486. if( maxhp > INT16_MAX )
  5487. {// To correctly display the %hp bar. [Skotlex]
  5488. WFIFOW(fd,6) = hp/(maxhp/100);
  5489. WFIFOW(fd,8) = 100;
  5490. } else {
  5491. WFIFOW(fd,6) = hp;
  5492. WFIFOW(fd,8) = maxhp;
  5493. }
  5494. #else
  5495. WFIFOL(fd,6) = hp;
  5496. WFIFOL(fd,10) = maxhp;
  5497. #endif
  5498. WFIFOSET(fd, packet_len(cmd));
  5499. }
  5500. /*==========================================
  5501. *
  5502. *------------------------------------------*/
  5503. int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  5504. {
  5505. struct map_session_data *sd, *tsd;
  5506. int level;
  5507. #if PACKETVER < 20100126
  5508. const int cmd = 0x106;
  5509. #else
  5510. const int cmd = 0x80e;
  5511. #endif
  5512. sd = va_arg(ap, struct map_session_data *);
  5513. tsd = (TBL_PC *)bl;
  5514. nullpo_ret(sd);
  5515. nullpo_ret(tsd);
  5516. if( !tsd->fd || tsd == sd )
  5517. return 0;
  5518. if( (level = pc_isGM(tsd)) < battle_config.disp_hpmeter || level < pc_isGM(sd) )
  5519. return 0;
  5520. WFIFOHEAD(tsd->fd,packet_len(cmd));
  5521. WFIFOW(tsd->fd,0) = cmd;
  5522. WFIFOL(tsd->fd,2) = sd->status.account_id;
  5523. #if PACKETVER < 20100126
  5524. if( sd->battle_status.max_hp > INT16_MAX )
  5525. { //To correctly display the %hp bar. [Skotlex]
  5526. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5527. WFIFOW(tsd->fd,8) = 100;
  5528. } else {
  5529. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  5530. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  5531. }
  5532. #else
  5533. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  5534. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  5535. #endif
  5536. WFIFOSET(tsd->fd,packet_len(cmd));
  5537. return 0;
  5538. }
  5539. /*==========================================
  5540. * Server tells all nearby gms to 'sd' that 'sd' hp bar was updated
  5541. *------------------------------------------*/
  5542. int clif_hpmeter(struct map_session_data *sd)
  5543. {
  5544. nullpo_ret(sd);
  5545. if( battle_config.disp_hpmeter )
  5546. 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);
  5547. return 0;
  5548. }
  5549. /*==========================================
  5550. * (?) Server tells 'sd' party members that 'sd' state 'changed'
  5551. *------------------------------------------*/
  5552. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5553. {
  5554. unsigned char buf[128];
  5555. nullpo_retv(sd);
  5556. nullpo_retv(p);
  5557. WBUFW(buf, 0) = 0x104;
  5558. WBUFL(buf, 2) = sd->status.account_id;
  5559. WBUFL(buf, 6) = 0;
  5560. WBUFW(buf,10) = sd->bl.x;
  5561. WBUFW(buf,12) = sd->bl.y;
  5562. WBUFB(buf,14) = !online;
  5563. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5564. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5565. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5566. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5567. }
  5568. /*==========================================
  5569. * Server tells client to attack bl, if not in range of attack (rhw.range) it'll move to bl
  5570. * called from unit.c
  5571. *------------------------------------------*/
  5572. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5573. {
  5574. int fd;
  5575. nullpo_ret(sd);
  5576. nullpo_ret(bl);
  5577. fd=sd->fd;
  5578. WFIFOHEAD(fd,packet_len(0x139));
  5579. WFIFOW(fd, 0)=0x139;
  5580. WFIFOL(fd, 2)=bl->id;
  5581. WFIFOW(fd, 6)=bl->x;
  5582. WFIFOW(fd, 8)=bl->y;
  5583. WFIFOW(fd,10)=sd->bl.x;
  5584. WFIFOW(fd,12)=sd->bl.y;
  5585. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5586. WFIFOSET(fd,packet_len(0x139));
  5587. return 0;
  5588. }
  5589. /*==========================================
  5590. * Server tells client to display produce effect (refine-like), success or failure depends on 'flag'
  5591. *------------------------------------------*/
  5592. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5593. {
  5594. int view,fd;
  5595. nullpo_ret(sd);
  5596. fd = sd->fd;
  5597. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5598. WFIFOHEAD(fd,packet_len(0x18f));
  5599. WFIFOW(fd, 0)=0x18f;
  5600. WFIFOW(fd, 2)=flag;
  5601. if((view = itemdb_viewid(nameid)) > 0)
  5602. WFIFOW(fd, 4)=view;
  5603. else
  5604. WFIFOW(fd, 4)=nameid;
  5605. WFIFOSET(fd,packet_len(0x18f));
  5606. return 0;
  5607. }
  5608. // pet
  5609. int clif_catch_process(struct map_session_data *sd)
  5610. {
  5611. int fd;
  5612. nullpo_ret(sd);
  5613. fd=sd->fd;
  5614. WFIFOHEAD(fd,packet_len(0x19e));
  5615. WFIFOW(fd,0)=0x19e;
  5616. WFIFOSET(fd,packet_len(0x19e));
  5617. return 0;
  5618. }
  5619. int clif_pet_roulette(struct map_session_data *sd,int data)
  5620. {
  5621. int fd;
  5622. nullpo_ret(sd);
  5623. fd=sd->fd;
  5624. WFIFOHEAD(fd,packet_len(0x1a0));
  5625. WFIFOW(fd,0)=0x1a0;
  5626. WFIFOB(fd,2)=data;
  5627. WFIFOSET(fd,packet_len(0x1a0));
  5628. return 0;
  5629. }
  5630. /*==========================================
  5631. * Server tells client to list it's eggs (used in hatching window to select a egg)
  5632. *------------------------------------------*/
  5633. int clif_sendegg(struct map_session_data *sd)
  5634. {
  5635. //R 01a6 <len>.w <index>.w*
  5636. int i,n=0,fd;
  5637. nullpo_ret(sd);
  5638. fd=sd->fd;
  5639. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5640. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5641. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5642. return 0;
  5643. }
  5644. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5645. WFIFOW(fd,0)=0x1a6;
  5646. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5647. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5648. sd->inventory_data[i]->type!=IT_PETEGG ||
  5649. sd->status.inventory[i].amount<=0)
  5650. continue;
  5651. WFIFOW(fd,n*2+4)=i+2;
  5652. n++;
  5653. }
  5654. WFIFOW(fd,2)=4+n*2;
  5655. WFIFOSET(fd,WFIFOW(fd,2));
  5656. sd->menuskill_id = SA_TAMINGMONSTER;
  5657. sd->menuskill_val = -1;
  5658. return 0;
  5659. }
  5660. /*==========================================
  5661. * Sends a specific pet data update.
  5662. * type = 0 -> param = 0 (initial data)
  5663. * type = 1 -> param = intimacy value
  5664. * type = 2 -> param = hungry value
  5665. * type = 3 -> param = accessory id
  5666. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5667. * type = 5 -> param = hairstyle number
  5668. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5669. *------------------------------------------*/
  5670. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5671. {
  5672. uint8 buf[16];
  5673. nullpo_ret(pd);
  5674. WBUFW(buf,0) = 0x1a4;
  5675. WBUFB(buf,2) = type;
  5676. WBUFL(buf,3) = pd->bl.id;
  5677. WBUFL(buf,7) = param;
  5678. if (sd)
  5679. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5680. else
  5681. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5682. return 0;
  5683. }
  5684. int clif_send_petstatus(struct map_session_data *sd)
  5685. {
  5686. int fd;
  5687. struct s_pet *pet;
  5688. nullpo_ret(sd);
  5689. nullpo_ret(sd->pd);
  5690. fd=sd->fd;
  5691. pet = &sd->pd->pet;
  5692. WFIFOHEAD(fd,packet_len(0x1a2));
  5693. WFIFOW(fd,0)=0x1a2;
  5694. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5695. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5696. WFIFOW(fd,27)=pet->level;
  5697. WFIFOW(fd,29)=pet->hungry;
  5698. WFIFOW(fd,31)=pet->intimate;
  5699. WFIFOW(fd,33)=pet->equip;
  5700. #if PACKETVER >= 20081126
  5701. WFIFOW(fd,35)=pet->class_;
  5702. #endif
  5703. WFIFOSET(fd,packet_len(0x1a2));
  5704. return 0;
  5705. }
  5706. /*==========================================
  5707. *
  5708. *------------------------------------------*/
  5709. int clif_pet_emotion(struct pet_data *pd,int param)
  5710. {
  5711. unsigned char buf[16];
  5712. nullpo_ret(pd);
  5713. memset(buf,0,packet_len(0x1aa));
  5714. WBUFW(buf,0)=0x1aa;
  5715. WBUFL(buf,2)=pd->bl.id;
  5716. if(param >= 100 && pd->petDB->talk_convert_class) {
  5717. if(pd->petDB->talk_convert_class < 0)
  5718. return 0;
  5719. else if(pd->petDB->talk_convert_class > 0) {
  5720. param -= (pd->pet.class_ - 100)*100;
  5721. param += (pd->petDB->talk_convert_class - 100)*100;
  5722. }
  5723. }
  5724. WBUFL(buf,6)=param;
  5725. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5726. return 0;
  5727. }
  5728. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5729. {
  5730. int fd;
  5731. nullpo_ret(sd);
  5732. fd=sd->fd;
  5733. WFIFOHEAD(fd,packet_len(0x1a3));
  5734. WFIFOW(fd,0)=0x1a3;
  5735. WFIFOB(fd,2)=fail;
  5736. WFIFOW(fd,3)=foodid;
  5737. WFIFOSET(fd,packet_len(0x1a3));
  5738. return 0;
  5739. }
  5740. /*==========================================
  5741. * Server tells client to display autospell (Sage Skill) skill selection list
  5742. *------------------------------------------*/
  5743. int clif_autospell(struct map_session_data *sd,int skilllv)
  5744. {
  5745. int fd;
  5746. nullpo_ret(sd);
  5747. fd=sd->fd;
  5748. WFIFOHEAD(fd,packet_len(0x1cd));
  5749. WFIFOW(fd, 0)=0x1cd;
  5750. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5751. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5752. else
  5753. WFIFOL(fd,2)= 0x00000000;
  5754. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5755. WFIFOL(fd,6)= MG_COLDBOLT;
  5756. else
  5757. WFIFOL(fd,6)= 0x00000000;
  5758. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5759. WFIFOL(fd,10)= MG_FIREBOLT;
  5760. else
  5761. WFIFOL(fd,10)= 0x00000000;
  5762. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5763. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5764. else
  5765. WFIFOL(fd,14)= 0x00000000;
  5766. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5767. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5768. else
  5769. WFIFOL(fd,18)= 0x00000000;
  5770. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5771. WFIFOL(fd,22)= MG_FIREBALL;
  5772. else
  5773. WFIFOL(fd,22)= 0x00000000;
  5774. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5775. WFIFOL(fd,26)= MG_FROSTDIVER;
  5776. else
  5777. WFIFOL(fd,26)= 0x00000000;
  5778. WFIFOSET(fd,packet_len(0x1cd));
  5779. sd->menuskill_id = SA_AUTOSPELL;
  5780. sd->menuskill_val = skilllv;
  5781. return 0;
  5782. }
  5783. /*==========================================
  5784. * Devotion's visual effect
  5785. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5786. *------------------------------------------*/
  5787. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5788. {
  5789. unsigned char buf[56];
  5790. int i;
  5791. nullpo_retv(src);
  5792. memset(buf,0,packet_len(0x1cf));
  5793. WBUFW(buf,0) = 0x1cf;
  5794. WBUFL(buf,2) = src->id;
  5795. if( src->type == BL_MER )
  5796. {
  5797. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5798. if( md && md->master && md->devotion_flag )
  5799. WBUFL(buf,6) = md->master->bl.id;
  5800. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5801. }
  5802. else
  5803. {
  5804. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5805. if( sd == NULL )
  5806. return;
  5807. for( i = 0; i < 5; i++ )
  5808. WBUFL(buf,6+4*i) = sd->devotion[i];
  5809. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5810. }
  5811. if( tsd )
  5812. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5813. else
  5814. clif_send(buf, packet_len(0x1cf), src, AREA);
  5815. }
  5816. /*==========================================
  5817. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  5818. *------------------------------------------*/
  5819. int clif_spiritball(struct map_session_data *sd)
  5820. {
  5821. unsigned char buf[16];
  5822. nullpo_ret(sd);
  5823. WBUFW(buf,0)=0x1d0;
  5824. WBUFL(buf,2)=sd->bl.id;
  5825. WBUFW(buf,6)=sd->spiritball;
  5826. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5827. return 0;
  5828. }
  5829. /*==========================================
  5830. *
  5831. *------------------------------------------*/
  5832. int clif_combo_delay(struct block_list *bl,int wait)
  5833. {
  5834. unsigned char buf[32];
  5835. nullpo_ret(bl);
  5836. WBUFW(buf,0)=0x1d2;
  5837. WBUFL(buf,2)=bl->id;
  5838. WBUFL(buf,6)=wait;
  5839. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5840. return 0;
  5841. }
  5842. /*==========================================
  5843. * Server tells client to display blade stop animation 'link' from 'src' to 'dst_id' (account id of target)
  5844. * active toggles the state
  5845. *------------------------------------------*/
  5846. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5847. {
  5848. unsigned char buf[32];
  5849. nullpo_retv(src);
  5850. WBUFW(buf,0)=0x1d1;
  5851. WBUFL(buf,2)=src->id;
  5852. WBUFL(buf,6)=dst_id;
  5853. WBUFL(buf,10)=active;
  5854. clif_send(buf,packet_len(0x1d1),src,AREA);
  5855. }
  5856. /*==========================================
  5857. * Server tells clients nearby 'sd' (and itself) to display MvP killed effect on 'sd' player
  5858. *------------------------------------------*/
  5859. int clif_mvp_effect(struct map_session_data *sd)
  5860. {
  5861. unsigned char buf[16];
  5862. nullpo_ret(sd);
  5863. WBUFW(buf,0)=0x10c;
  5864. WBUFL(buf,2)=sd->bl.id;
  5865. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5866. return 0;
  5867. }
  5868. /*==========================================
  5869. * Server tells client to display mvp drop prize info to player 'sd' for item id 'nameid'
  5870. *------------------------------------------*/
  5871. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5872. {
  5873. int view,fd;
  5874. nullpo_ret(sd);
  5875. fd=sd->fd;
  5876. WFIFOHEAD(fd,packet_len(0x10a));
  5877. WFIFOW(fd,0)=0x10a;
  5878. if((view = itemdb_viewid(nameid)) > 0)
  5879. WFIFOW(fd,2)=view;
  5880. else
  5881. WFIFOW(fd,2)=nameid;
  5882. WFIFOSET(fd,packet_len(0x10a));
  5883. return 0;
  5884. }
  5885. /*==========================================
  5886. * Server tells client to display mvp exp prize to player 'sd' for amount 'exp'
  5887. *------------------------------------------*/
  5888. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5889. {
  5890. int fd;
  5891. nullpo_ret(sd);
  5892. fd=sd->fd;
  5893. WFIFOHEAD(fd,packet_len(0x10b));
  5894. WFIFOW(fd,0)=0x10b;
  5895. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  5896. WFIFOSET(fd,packet_len(0x10b));
  5897. return 0;
  5898. }
  5899. /*==========================================
  5900. * Guild creation result
  5901. * R 0167 <flag>.B
  5902. * flag = 0 -> "Guild has been created."
  5903. * flag = 1 -> "You are already in a Guild."
  5904. * flag = 2 -> "That Guild Name already exists."
  5905. * flag = 3 -> "You need the neccessary item to create a Guild."
  5906. *------------------------------------------*/
  5907. int clif_guild_created(struct map_session_data *sd,int flag)
  5908. {
  5909. int fd;
  5910. nullpo_ret(sd);
  5911. fd=sd->fd;
  5912. WFIFOHEAD(fd,packet_len(0x167));
  5913. WFIFOW(fd,0)=0x167;
  5914. WFIFOB(fd,2)=flag;
  5915. WFIFOSET(fd,packet_len(0x167));
  5916. return 0;
  5917. }
  5918. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID)
  5919. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  5920. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5921. {
  5922. int ps,fd;
  5923. nullpo_retv(sd);
  5924. nullpo_retv(g);
  5925. fd=sd->fd;
  5926. ps=guild_getposition(g,sd);
  5927. WFIFOHEAD(fd,packet_len(0x16c));
  5928. WFIFOW(fd,0)=0x16c;
  5929. WFIFOL(fd,2)=g->guild_id;
  5930. WFIFOL(fd,6)=g->emblem_id;
  5931. WFIFOL(fd,10)=g->position[ps].mode;
  5932. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  5933. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  5934. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5935. WFIFOSET(fd,packet_len(0x16c));
  5936. }
  5937. /*==========================================
  5938. * Server tells all members of 'g' guild that member of index 'idx' is online or offline (flag 1:0)
  5939. *------------------------------------------*/
  5940. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5941. {
  5942. unsigned char buf[64];
  5943. nullpo_ret(g);
  5944. WBUFW(buf, 0)=0x16d;
  5945. WBUFL(buf, 2)=g->member[idx].account_id;
  5946. WBUFL(buf, 6)=g->member[idx].char_id;
  5947. WBUFL(buf,10)=flag;
  5948. if(g->member[idx].sd==NULL){
  5949. struct map_session_data *sd=guild_getavailablesd(g);
  5950. if(sd!=NULL)
  5951. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5952. }else
  5953. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5954. return 0;
  5955. }
  5956. // Function `clif_guild_memberlogin_notice` sends info about
  5957. // logins and logouts of a guild member to the rest members.
  5958. // But at the 1st time (after a player login or map changing)
  5959. // the client won't show the message.
  5960. // So I suggest use this function for sending "first-time-info"
  5961. // to some player on entering the game or changing location.
  5962. // At next time the client would always show the message.
  5963. // The function sends all the statuses in the single packet
  5964. // to economize traffic. [LuzZza]
  5965. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5966. {
  5967. struct guild *g;
  5968. unsigned char buf[14*128];
  5969. int i, count=0, p_len;
  5970. nullpo_ret(sd);
  5971. p_len = packet_len(0x16d);
  5972. if(!(g = guild_search(sd->status.guild_id)))
  5973. return 0;
  5974. for(i=0; i<g->max_member; i++) {
  5975. if(g->member[i].account_id > 0 &&
  5976. g->member[i].account_id != sd->status.account_id) {
  5977. WBUFW(buf,count*p_len) = 0x16d;
  5978. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5979. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5980. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5981. count++;
  5982. }
  5983. }
  5984. clif_send(buf, p_len*count, &sd->bl, SELF);
  5985. return 0;
  5986. }
  5987. /*==========================================
  5988. * Tells 'sd' whether he is the guild master of his guild or not (relies on sd->state.gmaster_flag)
  5989. *------------------------------------------*/
  5990. int clif_guild_masterormember(struct map_session_data *sd)
  5991. {
  5992. int fd;
  5993. nullpo_ret(sd);
  5994. fd=sd->fd;
  5995. WFIFOHEAD(fd,packet_len(0x14e));
  5996. WFIFOW(fd,0) = 0x14e;
  5997. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5998. WFIFOSET(fd,packet_len(0x14e));
  5999. return 0;
  6000. }
  6001. /*==========================================
  6002. * Basic Info (Territories [Valaris])
  6003. *------------------------------------------*/
  6004. int clif_guild_basicinfo(struct map_session_data *sd)
  6005. {
  6006. int fd,i,t;
  6007. struct guild *g;
  6008. struct guild_castle *gc = NULL;
  6009. nullpo_ret(sd);
  6010. fd = sd->fd;
  6011. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6012. return 0;
  6013. WFIFOHEAD(fd,packet_len(0x1b6));
  6014. WFIFOW(fd, 0)=0x1b6;//0x150;
  6015. WFIFOL(fd, 2)=g->guild_id;
  6016. WFIFOL(fd, 6)=g->guild_lv;
  6017. WFIFOL(fd,10)=g->connect_member;
  6018. WFIFOL(fd,14)=g->max_member;
  6019. WFIFOL(fd,18)=g->average_lv;
  6020. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6021. WFIFOL(fd,26)=g->next_exp;
  6022. WFIFOL(fd,30)=0; // Tax Points
  6023. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  6024. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  6025. WFIFOL(fd,42)=g->emblem_id;
  6026. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6027. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6028. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  6029. {
  6030. gc = guild_castle_search(i);
  6031. if(gc && g->guild_id == gc->guild_id)
  6032. t++;
  6033. }
  6034. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  6035. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  6036. return 0;
  6037. }
  6038. /*==========================================
  6039. * Server tells client 'sd' it's guild alliances
  6040. *------------------------------------------*/
  6041. int clif_guild_allianceinfo(struct map_session_data *sd)
  6042. {
  6043. int fd,i,c;
  6044. struct guild *g;
  6045. nullpo_ret(sd);
  6046. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6047. return 0;
  6048. fd = sd->fd;
  6049. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6050. WFIFOW(fd, 0)=0x14c;
  6051. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6052. struct guild_alliance *a=&g->alliance[i];
  6053. if(a->guild_id>0){
  6054. WFIFOL(fd,c*32+4)=a->opposition;
  6055. WFIFOL(fd,c*32+8)=a->guild_id;
  6056. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6057. c++;
  6058. }
  6059. }
  6060. WFIFOW(fd, 2)=c*32+4;
  6061. WFIFOSET(fd,WFIFOW(fd,2));
  6062. return 0;
  6063. }
  6064. /*==========================================
  6065. * Server tells client it's guild member list
  6066. *------------------------------------------*/
  6067. int clif_guild_memberlist(struct map_session_data *sd)
  6068. {
  6069. int fd;
  6070. int i,c;
  6071. struct guild *g;
  6072. nullpo_ret(sd);
  6073. if( (fd = sd->fd) == 0 )
  6074. return 0;
  6075. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6076. return 0;
  6077. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6078. WFIFOW(fd, 0)=0x154;
  6079. for(i=0,c=0;i<g->max_member;i++){
  6080. struct guild_member *m=&g->member[i];
  6081. if(m->account_id==0)
  6082. continue;
  6083. WFIFOL(fd,c*104+ 4)=m->account_id;
  6084. WFIFOL(fd,c*104+ 8)=m->char_id;
  6085. WFIFOW(fd,c*104+12)=m->hair;
  6086. WFIFOW(fd,c*104+14)=m->hair_color;
  6087. WFIFOW(fd,c*104+16)=m->gender;
  6088. WFIFOW(fd,c*104+18)=m->class_;
  6089. WFIFOW(fd,c*104+20)=m->lv;
  6090. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6091. WFIFOL(fd,c*104+26)=m->online;
  6092. WFIFOL(fd,c*104+30)=m->position;
  6093. 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.
  6094. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6095. c++;
  6096. }
  6097. WFIFOW(fd, 2)=c*104+4;
  6098. WFIFOSET(fd,WFIFOW(fd,2));
  6099. return 0;
  6100. }
  6101. /*==========================================
  6102. * Server tell client it's guild position list
  6103. *------------------------------------------*/
  6104. int clif_guild_positionnamelist(struct map_session_data *sd)
  6105. {
  6106. int i,fd;
  6107. struct guild *g;
  6108. nullpo_ret(sd);
  6109. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6110. return 0;
  6111. fd = sd->fd;
  6112. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6113. WFIFOW(fd, 0)=0x166;
  6114. for(i=0;i<MAX_GUILDPOSITION;i++){
  6115. WFIFOL(fd,i*28+4)=i;
  6116. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6117. }
  6118. WFIFOW(fd,2)=i*28+4;
  6119. WFIFOSET(fd,WFIFOW(fd,2));
  6120. return 0;
  6121. }
  6122. /*==========================================
  6123. * Server tell client about it's guild position permissions and tax
  6124. *------------------------------------------*/
  6125. int clif_guild_positioninfolist(struct map_session_data *sd)
  6126. {
  6127. int i,fd;
  6128. struct guild *g;
  6129. nullpo_ret(sd);
  6130. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6131. return 0;
  6132. fd = sd->fd;
  6133. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6134. WFIFOW(fd, 0)=0x160;
  6135. for(i=0;i<MAX_GUILDPOSITION;i++){
  6136. struct guild_position *p=&g->position[i];
  6137. WFIFOL(fd,i*16+ 4)=i;
  6138. WFIFOL(fd,i*16+ 8)=p->mode;
  6139. WFIFOL(fd,i*16+12)=i;
  6140. WFIFOL(fd,i*16+16)=p->exp_mode;
  6141. }
  6142. WFIFOW(fd, 2)=i*16+4;
  6143. WFIFOSET(fd,WFIFOW(fd,2));
  6144. return 0;
  6145. }
  6146. /*==========================================
  6147. * Server tells client about position 'idx' information, being it changed
  6148. *------------------------------------------*/
  6149. int clif_guild_positionchanged(struct guild *g,int idx)
  6150. {
  6151. struct map_session_data *sd;
  6152. unsigned char buf[128];
  6153. nullpo_ret(g);
  6154. WBUFW(buf, 0)=0x174;
  6155. WBUFW(buf, 2)=44;
  6156. WBUFL(buf, 4)=idx;
  6157. WBUFL(buf, 8)=g->position[idx].mode;
  6158. WBUFL(buf,12)=idx;
  6159. WBUFL(buf,16)=g->position[idx].exp_mode;
  6160. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6161. if( (sd=guild_getavailablesd(g))!=NULL )
  6162. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6163. return 0;
  6164. }
  6165. /*==========================================
  6166. * Server tells client about a specific guild member index that changed
  6167. *------------------------------------------*/
  6168. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6169. {
  6170. struct map_session_data *sd;
  6171. unsigned char buf[64];
  6172. nullpo_ret(g);
  6173. WBUFW(buf, 0)=0x156;
  6174. WBUFW(buf, 2)=16;
  6175. WBUFL(buf, 4)=g->member[idx].account_id;
  6176. WBUFL(buf, 8)=g->member[idx].char_id;
  6177. WBUFL(buf,12)=g->member[idx].position;
  6178. if( (sd=guild_getavailablesd(g))!=NULL )
  6179. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6180. return 0;
  6181. }
  6182. /*==========================================
  6183. * Server tells client about this new cool emblem a specific guild got
  6184. *------------------------------------------*/
  6185. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6186. {
  6187. int fd;
  6188. nullpo_ret(sd);
  6189. nullpo_ret(g);
  6190. fd = sd->fd;
  6191. if( g->emblem_len <= 0 )
  6192. return 0;
  6193. WFIFOHEAD(fd,g->emblem_len+12);
  6194. WFIFOW(fd,0)=0x152;
  6195. WFIFOW(fd,2)=g->emblem_len+12;
  6196. WFIFOL(fd,4)=g->guild_id;
  6197. WFIFOL(fd,8)=g->emblem_id;
  6198. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6199. WFIFOSET(fd,WFIFOW(fd,2));
  6200. return 0;
  6201. }
  6202. /// Sends update of the guild id/emblem id to everyone in the area.
  6203. void clif_guild_emblem_area(struct block_list* bl)
  6204. {
  6205. uint8 buf[12];
  6206. nullpo_retv(bl);
  6207. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6208. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6209. WBUFW(buf,0) = 0x1B4;
  6210. WBUFL(buf,2) = bl->id;
  6211. WBUFL(buf,6) = status_get_guild_id(bl);
  6212. WBUFW(buf,10) = status_get_emblem_id(bl);
  6213. clif_send(buf, 12, bl, AREA_WOS);
  6214. }
  6215. /*==========================================
  6216. * Send guild skills
  6217. *------------------------------------------*/
  6218. int clif_guild_skillinfo(struct map_session_data* sd)
  6219. {
  6220. int fd;
  6221. struct guild* g;
  6222. int i,c;
  6223. nullpo_ret(sd);
  6224. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6225. return 0;
  6226. fd = sd->fd;
  6227. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6228. WFIFOW(fd,0) = 0x0162;
  6229. WFIFOW(fd,4) = g->skill_point;
  6230. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6231. {
  6232. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6233. {
  6234. int id = g->skill[i].id;
  6235. int p = 6 + c*37;
  6236. WFIFOW(fd,p+0) = id;
  6237. WFIFOW(fd,p+2) = skill_get_inf(id);
  6238. WFIFOW(fd,p+4) = 0;
  6239. WFIFOW(fd,p+6) = g->skill[i].lv;
  6240. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6241. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6242. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6243. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6244. c++;
  6245. }
  6246. }
  6247. WFIFOW(fd,2) = 6 + c*37;
  6248. WFIFOSET(fd,WFIFOW(fd,2));
  6249. return 0;
  6250. }
  6251. /*==========================================
  6252. * Sends guild notice to client
  6253. * R 016f <str1z>.60B <str2z>.120B
  6254. *------------------------------------------*/
  6255. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6256. {
  6257. int fd;
  6258. nullpo_ret(sd);
  6259. nullpo_ret(g);
  6260. fd = sd->fd;
  6261. if ( !session_isActive(fd) )
  6262. return 0;
  6263. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6264. return 0;
  6265. WFIFOHEAD(fd,packet_len(0x16f));
  6266. WFIFOW(fd,0) = 0x16f;
  6267. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6268. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6269. WFIFOSET(fd,packet_len(0x16f));
  6270. return 0;
  6271. }
  6272. /*==========================================
  6273. * Server tells client 'sd' that guild 'g' wants to invite him
  6274. *------------------------------------------*/
  6275. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6276. {
  6277. int fd;
  6278. nullpo_ret(sd);
  6279. nullpo_ret(g);
  6280. fd=sd->fd;
  6281. WFIFOHEAD(fd,packet_len(0x16a));
  6282. WFIFOW(fd,0)=0x16a;
  6283. WFIFOL(fd,2)=g->guild_id;
  6284. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6285. WFIFOSET(fd,packet_len(0x16a));
  6286. return 0;
  6287. }
  6288. /*==========================================
  6289. * Reply to invite request
  6290. * Flag:
  6291. * 0 = Already in guild.
  6292. * 1 = Offer rejected.
  6293. * 2 = Offer accepted.
  6294. * 3 = Guild full.
  6295. *------------------------------------------*/
  6296. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6297. {
  6298. int fd;
  6299. nullpo_ret(sd);
  6300. fd=sd->fd;
  6301. WFIFOHEAD(fd,packet_len(0x169));
  6302. WFIFOW(fd,0)=0x169;
  6303. WFIFOB(fd,2)=flag;
  6304. WFIFOSET(fd,packet_len(0x169));
  6305. return 0;
  6306. }
  6307. /*==========================================
  6308. * Server tells guild members of 'sd' that he left his guild for a reason
  6309. *------------------------------------------*/
  6310. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6311. {
  6312. unsigned char buf[128];
  6313. nullpo_ret(sd);
  6314. WBUFW(buf, 0)=0x15a;
  6315. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6316. memcpy(WBUFP(buf,26),mes,40);
  6317. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6318. return 0;
  6319. }
  6320. /*==========================================
  6321. * Server tells guild members of 'sd' that 'name' of account id 'account_id' was expelled for reason 'mes'
  6322. *------------------------------------------*/
  6323. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6324. {
  6325. unsigned char buf[128];
  6326. #if PACKETVER < 20100803
  6327. const unsigned short cmd = 0x15c;
  6328. #else
  6329. const unsigned short cmd = 0x839;
  6330. #endif
  6331. nullpo_retv(sd);
  6332. WBUFW(buf,0) = cmd;
  6333. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6334. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6335. #if PACKETVER < 20100803
  6336. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6337. #endif
  6338. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6339. }
  6340. /*==========================================
  6341. * Server tells client on sd's guild expulsion records
  6342. *------------------------------------------*/
  6343. void clif_guild_expulsionlist(struct map_session_data* sd)
  6344. {
  6345. #if PACKETVER < 20100803
  6346. const int offset = NAME_LENGTH*2+40;
  6347. #else
  6348. const int offset = NAME_LENGTH+40;
  6349. #endif
  6350. int fd, i, c = 0;
  6351. struct guild* g;
  6352. nullpo_retv(sd);
  6353. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6354. return;
  6355. fd = sd->fd;
  6356. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6357. WFIFOW(fd,0) = 0x163;
  6358. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6359. {
  6360. struct guild_expulsion* e = &g->expulsion[i];
  6361. if( e->account_id > 0 )
  6362. {
  6363. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6364. #if PACKETVER < 20100803
  6365. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6366. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6367. #else
  6368. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6369. #endif
  6370. c++;
  6371. }
  6372. }
  6373. WFIFOW(fd,2) = 4 + c*offset;
  6374. WFIFOSET(fd,WFIFOW(fd,2));
  6375. }
  6376. /// Notification of a guild chat message (ZC_GUILD_CHAT)
  6377. /// 017f <packet len>.W <message>.?B
  6378. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6379. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6380. struct map_session_data *sd;
  6381. uint8 buf[256];
  6382. if( len == 0 )
  6383. {
  6384. return;
  6385. }
  6386. else if( len > sizeof(buf)-5 )
  6387. {
  6388. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6389. len = sizeof(buf)-5;
  6390. }
  6391. WBUFW(buf, 0) = 0x17f;
  6392. WBUFW(buf, 2) = len + 5;
  6393. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6394. if ((sd = guild_getavailablesd(g)) != NULL)
  6395. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6396. }
  6397. /*==========================================
  6398. * Server tells client 'sd' that his guild skill 'skill_num' gone to level 'lv'
  6399. *------------------------------------------*/
  6400. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6401. {
  6402. int fd;
  6403. nullpo_ret(sd);
  6404. fd=sd->fd;
  6405. WFIFOHEAD(fd,11);
  6406. WFIFOW(fd,0) = 0x10e;
  6407. WFIFOW(fd,2) = skill_num;
  6408. WFIFOW(fd,4) = lv;
  6409. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6410. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6411. WFIFOB(fd,10) = 1;
  6412. WFIFOSET(fd,11);
  6413. return 0;
  6414. }
  6415. /*==========================================
  6416. * Server tells client 'sd' that 'account_id' from guild name 'name' wants to invite 'sd's guild for alliance
  6417. *------------------------------------------*/
  6418. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6419. {
  6420. int fd;
  6421. nullpo_ret(sd);
  6422. fd=sd->fd;
  6423. WFIFOHEAD(fd,packet_len(0x171));
  6424. WFIFOW(fd,0)=0x171;
  6425. WFIFOL(fd,2)=account_id;
  6426. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6427. WFIFOSET(fd,packet_len(0x171));
  6428. return 0;
  6429. }
  6430. /*==========================================
  6431. * Reply to alliance request.
  6432. * Flag values are:
  6433. * 0: Already allied.
  6434. * 1: You rejected the offer.
  6435. * 2: You accepted the offer.
  6436. * 3: They have too any alliances
  6437. * 4: You have too many alliances.
  6438. *------------------------------------------*/
  6439. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6440. {
  6441. int fd;
  6442. nullpo_ret(sd);
  6443. fd=sd->fd;
  6444. WFIFOHEAD(fd,packet_len(0x173));
  6445. WFIFOW(fd,0)=0x173;
  6446. WFIFOL(fd,2)=flag;
  6447. WFIFOSET(fd,packet_len(0x173));
  6448. return 0;
  6449. }
  6450. /*==========================================
  6451. * Server tells client 'sd' that guild_id is either in or out of it's alliance list (depend on flag)
  6452. *------------------------------------------*/
  6453. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6454. {
  6455. int fd;
  6456. nullpo_ret(sd);
  6457. fd = sd->fd;
  6458. if (fd <= 0)
  6459. return 0;
  6460. WFIFOHEAD(fd,packet_len(0x184));
  6461. WFIFOW(fd,0)=0x184;
  6462. WFIFOL(fd,2)=guild_id;
  6463. WFIFOL(fd,6)=flag;
  6464. WFIFOSET(fd,packet_len(0x184));
  6465. return 0;
  6466. }
  6467. /*==========================================
  6468. * Reply to opposition request
  6469. * Flag:
  6470. * 0 = Antagonist has been set.
  6471. * 1 = Guild has too many Antagonists.
  6472. * 2 = Already set as an Antagonist.
  6473. *------------------------------------------*/
  6474. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6475. {
  6476. int fd;
  6477. nullpo_ret(sd);
  6478. fd=sd->fd;
  6479. WFIFOHEAD(fd,packet_len(0x181));
  6480. WFIFOW(fd,0)=0x181;
  6481. WFIFOB(fd,2)=flag;
  6482. WFIFOSET(fd,packet_len(0x181));
  6483. return 0;
  6484. }
  6485. /*==========================================
  6486. * ギルド関係追加
  6487. *------------------------------------------*/
  6488. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6489. {
  6490. unsigned char buf[64];
  6491. WBUFW(fd,0)=0x185;
  6492. WBUFL(fd,2)=g->alliance[idx].opposition;
  6493. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6494. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6495. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6496. return 0;
  6497. }*/
  6498. /*==========================================
  6499. * Server tells client 'sd' that guild broke because of 'flag' reason
  6500. *------------------------------------------*/
  6501. int clif_guild_broken(struct map_session_data *sd,int flag)
  6502. {
  6503. int fd;
  6504. nullpo_ret(sd);
  6505. fd=sd->fd;
  6506. WFIFOHEAD(fd,packet_len(0x15e));
  6507. WFIFOW(fd,0)=0x15e;
  6508. WFIFOL(fd,2)=flag;
  6509. WFIFOSET(fd,packet_len(0x15e));
  6510. return 0;
  6511. }
  6512. /*==========================================
  6513. * Server tells all nearby clients of 'bl' to display emoticon number 'type'
  6514. *------------------------------------------*/
  6515. void clif_emotion(struct block_list *bl,int type)
  6516. {
  6517. unsigned char buf[8];
  6518. nullpo_retv(bl);
  6519. WBUFW(buf,0)=0xc0;
  6520. WBUFL(buf,2)=bl->id;
  6521. WBUFB(buf,6)=type;
  6522. clif_send(buf,packet_len(0xc0),bl,AREA);
  6523. }
  6524. /*==========================================
  6525. * Server tells all clients nearby 'bl' that he stepped in a talkie box (and displays the message)
  6526. *------------------------------------------*/
  6527. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6528. {
  6529. unsigned char buf[86];
  6530. nullpo_retv(bl);
  6531. WBUFW(buf,0) = 0x191;
  6532. WBUFL(buf,2) = bl->id;
  6533. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6534. clif_send(buf,packet_len(0x191),bl,AREA);
  6535. }
  6536. /*==========================================
  6537. * Server tells bl and nearby clients to display marriage effect
  6538. *------------------------------------------*/
  6539. void clif_wedding_effect(struct block_list *bl)
  6540. {
  6541. unsigned char buf[6];
  6542. nullpo_retv(bl);
  6543. WBUFW(buf,0) = 0x1ea;
  6544. WBUFL(buf,2) = bl->id;
  6545. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6546. }
  6547. /*==========================================
  6548. * Server tells client 'sd' to create a warp to call his partner (wedding skill)
  6549. *------------------------------------------*/
  6550. void clif_callpartner(struct map_session_data *sd)
  6551. {
  6552. unsigned char buf[26];
  6553. const char *p;
  6554. nullpo_retv(sd);
  6555. if(sd->status.partner_id){
  6556. WBUFW(buf,0)=0x1e6;
  6557. p = map_charid2nick(sd->status.partner_id);
  6558. if(p){
  6559. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6560. }else{
  6561. WBUFB(buf,2) = 0;
  6562. }
  6563. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6564. }
  6565. }
  6566. /*==========================================
  6567. * Marry [DracoRPG]
  6568. *------------------------------------------
  6569. void clif_marriage_process(struct map_session_data *sd)
  6570. {
  6571. int fd;
  6572. nullpo_retv(sd);
  6573. fd=sd->fd;
  6574. WFIFOHEAD(fd,packet_len(0x1e4));
  6575. WFIFOW(fd,0)=0x1e4;
  6576. WFIFOSET(fd,packet_len(0x1e4));
  6577. }
  6578. */
  6579. /*==========================================
  6580. * Notice of divorce
  6581. *------------------------------------------*/
  6582. void clif_divorced(struct map_session_data* sd, const char* name)
  6583. {
  6584. int fd;
  6585. nullpo_retv(sd);
  6586. fd=sd->fd;
  6587. WFIFOHEAD(fd,packet_len(0x205));
  6588. WFIFOW(fd,0)=0x205;
  6589. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6590. WFIFOSET(fd, packet_len(0x205));
  6591. }
  6592. /*==========================================
  6593. *
  6594. *------------------------------------------*/
  6595. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6596. {
  6597. nullpo_retv(sd);
  6598. WFIFOHEAD(fd,packet_len(0x1e2));
  6599. WFIFOW(fd,0)=0x1e2;
  6600. WFIFOSET(fd, packet_len(0x1e2));
  6601. }
  6602. /*==========================================
  6603. *
  6604. *------------------------------------------*/
  6605. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6606. {
  6607. clif_disp_message(&sd->bl, mes, len, SELF);
  6608. }
  6609. /*==========================================
  6610. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6611. *------------------------------------------*/
  6612. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6613. {
  6614. unsigned char buf[256];
  6615. if( len == 0 )
  6616. {
  6617. return;
  6618. }
  6619. else if( len > sizeof(buf)-5 )
  6620. {
  6621. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6622. len = sizeof(buf)-5;
  6623. }
  6624. WBUFW(buf, 0) = 0x17f;
  6625. WBUFW(buf, 2) = len + 5;
  6626. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6627. clif_send(buf, WBUFW(buf,2), src, target);
  6628. }
  6629. /*==========================================
  6630. *
  6631. *------------------------------------------*/
  6632. int clif_GM_kickack(struct map_session_data *sd, int id)
  6633. {
  6634. int fd;
  6635. nullpo_ret(sd);
  6636. fd = sd->fd;
  6637. WFIFOHEAD(fd,packet_len(0xcd));
  6638. WFIFOW(fd,0) = 0xcd;
  6639. WFIFOL(fd,2) = id;
  6640. WFIFOSET(fd, packet_len(0xcd));
  6641. return 0;
  6642. }
  6643. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6644. {
  6645. int fd = tsd->fd;
  6646. if( fd > 0 )
  6647. clif_authfail_fd(fd, 15);
  6648. else
  6649. map_quit(tsd);
  6650. if( sd )
  6651. clif_GM_kickack(sd,tsd->status.account_id);
  6652. }
  6653. /// Displays various manner-related status messages
  6654. /// R 014a <type>.L
  6655. /// type: 0 - "A manner point has been successfully aligned."
  6656. /// 1 - ?
  6657. /// 2 - ?
  6658. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6659. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6660. /// 5 - "You got a good point from %s."
  6661. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6662. {
  6663. int fd;
  6664. nullpo_retv(sd);
  6665. fd = sd->fd;
  6666. WFIFOHEAD(fd,packet_len(0x14a));
  6667. WFIFOW(fd,0) = 0x14a;
  6668. WFIFOL(fd,2) = type;
  6669. WFIFOSET(fd, packet_len(0x14a));
  6670. }
  6671. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6672. /// R 014b <type>.B <GM name>.24B
  6673. /// type: 0 - positive (unmute)
  6674. /// 1 - negative (mute)
  6675. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6676. {
  6677. int fd;
  6678. nullpo_retv(sd);
  6679. nullpo_retv(tsd);
  6680. fd = tsd->fd;
  6681. WFIFOHEAD(fd,packet_len(0x14b));
  6682. WFIFOW(fd,0) = 0x14b;
  6683. WFIFOB(fd,2) = type;
  6684. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6685. WFIFOSET(fd, packet_len(0x14b));
  6686. }
  6687. /*==========================================
  6688. * ? Unknown functionality : not called anywhere
  6689. *------------------------------------------*/
  6690. //int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6691. //{
  6692. // int fd;
  6693. //
  6694. // nullpo_ret(sd);
  6695. //
  6696. // fd=sd->fd;
  6697. // WFIFOHEAD(fd,packet_len(0xd1));
  6698. // WFIFOW(fd,0)=0xd1;
  6699. // WFIFOB(fd,2)=type;
  6700. // WFIFOB(fd,3)=flag;
  6701. // WFIFOSET(fd,packet_len(0xd1));
  6702. //
  6703. // return 0;
  6704. //}
  6705. /*==========================================
  6706. * ? Unknown functionality : not called anywhere
  6707. *------------------------------------------*/
  6708. //int clif_wisall(struct map_session_data *sd,int type,int flag)
  6709. //{
  6710. // int fd;
  6711. //
  6712. // nullpo_ret(sd);
  6713. //
  6714. // fd=sd->fd;
  6715. // WFIFOHEAD(fd,packet_len(0xd2));
  6716. // WFIFOW(fd,0)=0xd2;
  6717. // WFIFOB(fd,2)=type;
  6718. // WFIFOB(fd,3)=flag;
  6719. // WFIFOSET(fd,packet_len(0xd2));
  6720. //
  6721. // return 0;
  6722. //}
  6723. /*==========================================
  6724. * Play a BGM! [Rikter/Yommy]
  6725. *------------------------------------------*/
  6726. void clif_playBGM(struct map_session_data* sd, const char* name)
  6727. {
  6728. int fd;
  6729. nullpo_retv(sd);
  6730. fd = sd->fd;
  6731. WFIFOHEAD(fd,packet_len(0x7fe));
  6732. WFIFOW(fd,0) = 0x7fe;
  6733. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6734. WFIFOSET(fd,packet_len(0x7fe));
  6735. }
  6736. /*==========================================
  6737. * Server tells 'bl' to play a .wav music file in client's /wav/ folder named 'name'
  6738. * functionality of 'type' is unclear. it's normally sent as '0'
  6739. *------------------------------------------*/
  6740. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6741. {
  6742. int fd;
  6743. nullpo_retv(sd);
  6744. nullpo_retv(bl);
  6745. fd = sd->fd;
  6746. WFIFOHEAD(fd,packet_len(0x1d3));
  6747. WFIFOW(fd,0) = 0x1d3;
  6748. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6749. WFIFOB(fd,26) = type;
  6750. WFIFOL(fd,27) = 0;
  6751. WFIFOL(fd,31) = bl->id;
  6752. WFIFOSET(fd,packet_len(0x1d3));
  6753. return;
  6754. }
  6755. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6756. {
  6757. unsigned char buf[40];
  6758. nullpo_ret(bl);
  6759. WBUFW(buf,0) = 0x1d3;
  6760. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6761. WBUFB(buf,26) = type;
  6762. WBUFL(buf,27) = 0;
  6763. WBUFL(buf,31) = bl->id;
  6764. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6765. return 0;
  6766. }
  6767. // displaying special effects (npcs, weather, etc) [Valaris]
  6768. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6769. {
  6770. unsigned char buf[24];
  6771. nullpo_ret(bl);
  6772. memset(buf, 0, packet_len(0x1f3));
  6773. WBUFW(buf,0) = 0x1f3;
  6774. WBUFL(buf,2) = bl->id;
  6775. WBUFL(buf,6) = type;
  6776. clif_send(buf, packet_len(0x1f3), bl, target);
  6777. if (disguised(bl)) {
  6778. WBUFL(buf,2) = -bl->id;
  6779. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6780. }
  6781. return 0;
  6782. }
  6783. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6784. {
  6785. WFIFOHEAD(fd,10);
  6786. WFIFOW(fd,0) = 0x1f3;
  6787. WFIFOL(fd,2) = bl->id;
  6788. WFIFOL(fd,6) = type;
  6789. WFIFOSET(fd,10);
  6790. }
  6791. /******************************************************
  6792. * W.<packet> W.<LENGTH> L.<ID> L.<COLOR> S.<TEXT>
  6793. * Mob/NPC Color Talk [SnakeDrak]
  6794. ******************************************************/
  6795. int clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg)
  6796. {
  6797. unsigned short msg_len = strlen(msg) + 1;
  6798. uint8 buf[256];
  6799. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6800. nullpo_ret(bl);
  6801. if( msg_len > sizeof(buf)-12 )
  6802. {
  6803. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6804. msg_len = sizeof(buf)-12;
  6805. }
  6806. WBUFW(buf,0) = 0x2C1;
  6807. WBUFW(buf,2) = msg_len + 12;
  6808. WBUFL(buf,4) = bl->id;
  6809. WBUFL(buf,8) = color;
  6810. memcpy(WBUFP(buf,12), msg, msg_len);
  6811. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6812. return 0;
  6813. }
  6814. // messages (from mobs/npcs) [Valaris]
  6815. void clif_message(struct block_list* bl, const char* msg)
  6816. {
  6817. unsigned short msg_len = strlen(msg) + 1;
  6818. uint8 buf[256];
  6819. nullpo_retv(bl);
  6820. if( msg_len > sizeof(buf)-8 )
  6821. {
  6822. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6823. msg_len = sizeof(buf)-8;
  6824. }
  6825. WBUFW(buf,0) = 0x8d;
  6826. WBUFW(buf,2) = msg_len + 8;
  6827. WBUFL(buf,4) = bl->id;
  6828. safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  6829. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6830. }
  6831. // refresh the client's screen, getting rid of any effects
  6832. int clif_refresh(struct map_session_data *sd)
  6833. {
  6834. nullpo_retr(-1, sd);
  6835. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6836. clif_inventorylist(sd);
  6837. if(pc_iscarton(sd)) {
  6838. clif_cartlist(sd);
  6839. clif_updatestatus(sd,SP_CARTINFO);
  6840. }
  6841. clif_updatestatus(sd,SP_WEIGHT);
  6842. clif_updatestatus(sd,SP_MAXWEIGHT);
  6843. clif_updatestatus(sd,SP_STR);
  6844. clif_updatestatus(sd,SP_AGI);
  6845. clif_updatestatus(sd,SP_VIT);
  6846. clif_updatestatus(sd,SP_INT);
  6847. clif_updatestatus(sd,SP_DEX);
  6848. clif_updatestatus(sd,SP_LUK);
  6849. if (sd->spiritball)
  6850. clif_spiritball_single(sd->fd, sd);
  6851. if (sd->vd.cloth_color)
  6852. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6853. if(merc_is_hom_active(sd->hd))
  6854. clif_send_homdata(sd,0,0);
  6855. if( sd->md )
  6856. {
  6857. clif_mercenary_info(sd);
  6858. clif_mercenary_skillblock(sd);
  6859. }
  6860. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6861. clif_weather_check(sd);
  6862. if( sd->chatID )
  6863. chat_leavechat(sd,0);
  6864. if( sd->state.vending )
  6865. clif_openvending(sd, sd->bl.id, sd->vending);
  6866. if( pc_issit(sd) )
  6867. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6868. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6869. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  6870. else
  6871. clif_changed_dir(&sd->bl, SELF);
  6872. // unlike vending, resuming buyingstore crashes the client.
  6873. buyingstore_close(sd);
  6874. #ifndef TXT_ONLY
  6875. mail_clear(sd);
  6876. #endif
  6877. return 0;
  6878. }
  6879. /// Updates the object's (bl) name on client (ZC_ACK_REQNAME/ZC_ACK_REQNAMEALL)
  6880. /// 0095 <unit id>.L <char name>.24B
  6881. /// 0195 <unit id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B
  6882. int clif_charnameack (int fd, struct block_list *bl)
  6883. {
  6884. unsigned char buf[103];
  6885. int cmd = 0x95, i, ps = -1;
  6886. nullpo_ret(bl);
  6887. WBUFW(buf,0) = cmd;
  6888. WBUFL(buf,2) = bl->id;
  6889. switch( bl->type )
  6890. {
  6891. case BL_PC:
  6892. {
  6893. struct map_session_data *ssd = (struct map_session_data *)bl;
  6894. struct party_data *p = NULL;
  6895. struct guild *g = NULL;
  6896. //Requesting your own "shadow" name. [Skotlex]
  6897. if (ssd->fd == fd && ssd->disguise)
  6898. WBUFL(buf,2) = -bl->id;
  6899. if( ssd->fakename[0] )
  6900. {
  6901. WBUFW(buf, 0) = cmd = 0x195;
  6902. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6903. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  6904. break;
  6905. }
  6906. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6907. if( ssd->status.party_id )
  6908. {
  6909. p = party_search(ssd->status.party_id);
  6910. }
  6911. if( ssd->status.guild_id )
  6912. {
  6913. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  6914. {
  6915. 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);
  6916. if( i < g->max_member ) ps = g->member[i].position;
  6917. }
  6918. }
  6919. if( !battle_config.display_party_name && g == NULL )
  6920. {// do not display party unless the player is also in a guild
  6921. p = NULL;
  6922. }
  6923. if (p == NULL && g == NULL)
  6924. break;
  6925. WBUFW(buf, 0) = cmd = 0x195;
  6926. if (p)
  6927. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6928. else
  6929. WBUFB(buf,30) = 0;
  6930. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6931. {
  6932. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6933. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6934. } else { //Assume no guild.
  6935. WBUFB(buf,54) = 0;
  6936. WBUFB(buf,78) = 0;
  6937. }
  6938. }
  6939. break;
  6940. //[blackhole89]
  6941. case BL_HOM:
  6942. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6943. break;
  6944. case BL_MER:
  6945. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6946. break;
  6947. case BL_PET:
  6948. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6949. break;
  6950. case BL_NPC:
  6951. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6952. break;
  6953. case BL_MOB:
  6954. {
  6955. struct mob_data *md = (struct mob_data *)bl;
  6956. nullpo_ret(md);
  6957. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6958. if( md->guardian_data && md->guardian_data->guild_id )
  6959. {
  6960. WBUFW(buf, 0) = cmd = 0x195;
  6961. WBUFB(buf,30) = 0;
  6962. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6963. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6964. }
  6965. else if( battle_config.show_mob_info )
  6966. {
  6967. char mobhp[50], *str_p = mobhp;
  6968. WBUFW(buf, 0) = cmd = 0x195;
  6969. if( battle_config.show_mob_info&4 )
  6970. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6971. if( battle_config.show_mob_info&1 )
  6972. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6973. if( battle_config.show_mob_info&2 )
  6974. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6975. //Even thought mobhp ain't a name, we send it as one so the client
  6976. //can parse it. [Skotlex]
  6977. if( str_p != mobhp )
  6978. {
  6979. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6980. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6981. WBUFB(buf,54) = 0;
  6982. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6983. }
  6984. }
  6985. }
  6986. break;
  6987. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6988. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6989. // break;
  6990. return 0;
  6991. default:
  6992. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6993. return 0;
  6994. }
  6995. // if no receipient specified just update nearby clients
  6996. if (fd == 0)
  6997. clif_send(buf, packet_len(cmd), bl, AREA);
  6998. else {
  6999. WFIFOHEAD(fd, packet_len(cmd));
  7000. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7001. WFIFOSET(fd, packet_len(cmd));
  7002. }
  7003. return 0;
  7004. }
  7005. //Used to update when a char leaves a party/guild. [Skotlex]
  7006. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7007. int clif_charnameupdate (struct map_session_data *ssd)
  7008. {
  7009. unsigned char buf[103];
  7010. int cmd = 0x195, ps = -1, i;
  7011. struct party_data *p = NULL;
  7012. struct guild *g = NULL;
  7013. nullpo_ret(ssd);
  7014. if( ssd->fakename[0] )
  7015. return 0; //No need to update as the party/guild was not displayed anyway.
  7016. WBUFW(buf,0) = cmd;
  7017. WBUFL(buf,2) = ssd->bl.id;
  7018. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7019. if (!battle_config.display_party_name) {
  7020. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  7021. p = party_search(ssd->status.party_id);
  7022. }else{
  7023. if (ssd->status.party_id > 0)
  7024. p = party_search(ssd->status.party_id);
  7025. }
  7026. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  7027. {
  7028. 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);
  7029. if( i < g->max_member ) ps = g->member[i].position;
  7030. }
  7031. if( p )
  7032. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7033. else
  7034. WBUFB(buf,30) = 0;
  7035. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7036. {
  7037. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7038. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7039. }
  7040. else
  7041. {
  7042. WBUFB(buf,54) = 0;
  7043. WBUFB(buf,78) = 0;
  7044. }
  7045. // Update nearby clients
  7046. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7047. return 0;
  7048. }
  7049. /// Visually moves(instant) a character to x,y. The char moves even
  7050. /// when the target cell isn't walkable. If the char is sitting it
  7051. /// stays that way.
  7052. void clif_slide(struct block_list *bl, int x, int y)
  7053. {
  7054. unsigned char buf[10];
  7055. nullpo_retv(bl);
  7056. WBUFW(buf, 0) = 0x01ff;
  7057. WBUFL(buf, 2) = bl->id;
  7058. WBUFW(buf, 6) = x;
  7059. WBUFW(buf, 8) = y;
  7060. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7061. if( disguised(bl) )
  7062. {
  7063. WBUFL(buf,2) = -bl->id;
  7064. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7065. }
  7066. }
  7067. /*------------------------------------------
  7068. * @me command by lordalfa, rewritten implementation by Skotlex
  7069. *------------------------------------------*/
  7070. void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  7071. {
  7072. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7073. int len_mes = strlen(mes)+1; //Account for \0
  7074. if (len_mes > sizeof(buf)-8) {
  7075. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7076. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7077. }
  7078. // send message to others
  7079. WBUFW(buf,0) = 0x8d;
  7080. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7081. WBUFL(buf,4) = sd->bl.id;
  7082. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7083. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7084. // send back message to the speaker
  7085. WBUFW(buf,0) = 0x8e;
  7086. WBUFW(buf, 2) = len_mes + 4;
  7087. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7088. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7089. }
  7090. /*==========================
  7091. * Minimap fix [Kevin]
  7092. * Remove dot from minimap
  7093. *--------------------------*/
  7094. int clif_party_xy_remove(struct map_session_data *sd)
  7095. {
  7096. unsigned char buf[16];
  7097. nullpo_ret(sd);
  7098. WBUFW(buf,0)=0x107;
  7099. WBUFL(buf,2)=sd->status.account_id;
  7100. WBUFW(buf,6)=-1;
  7101. WBUFW(buf,8)=-1;
  7102. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7103. return 0;
  7104. }
  7105. //Displays gospel-buff information (thanks to Rayce):
  7106. //Type determines message based on this table:
  7107. /*
  7108. 0x15 End all negative status
  7109. 0x16 Immunity to all status
  7110. 0x17 MaxHP +100%
  7111. 0x18 MaxSP +100%
  7112. 0x19 All stats +20
  7113. 0x1c Enchant weapon with Holy element
  7114. 0x1d Enchant armor with Holy element
  7115. 0x1e DEF +25%
  7116. 0x1f ATK +100%
  7117. 0x20 HIT/Flee +50
  7118. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  7119. */
  7120. void clif_gospel_info(struct map_session_data *sd, int type)
  7121. {
  7122. int fd=sd->fd;
  7123. WFIFOHEAD(fd,packet_len(0x215));
  7124. WFIFOW(fd,0)=0x215;
  7125. WFIFOL(fd,2)=type;
  7126. WFIFOSET(fd, packet_len(0x215));
  7127. }
  7128. /// Multi purpose mission information packet (ZC_STARSKILL).
  7129. /// 0x20e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7130. /// result:
  7131. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7132. /// star:
  7133. /// 0 = Place of the Sun
  7134. /// 1 = Place of the Moon
  7135. /// 2 = Place of the Stars
  7136. /// 1 = Star Gladiator %s's %s: <mapname>
  7137. /// star:
  7138. /// 0 = Place of the Sun
  7139. /// 1 = Place of the Moon
  7140. /// 2 = Place of the Stars
  7141. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7142. /// star:
  7143. /// 0 = Target of the Sun
  7144. /// 1 = Target of the Moon
  7145. /// 2 = Target of the Stars
  7146. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7147. /// star:
  7148. /// 0 = Monster of the Sun
  7149. /// 1 = Monster of the Moon
  7150. /// 2 = Monster of the Stars
  7151. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7152. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7153. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7154. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7155. /// 40 = Target HP : <monster_id used as HP>
  7156. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7157. {
  7158. int fd = sd->fd;
  7159. WFIFOHEAD(fd,packet_len(0x20e));
  7160. WFIFOW(fd,0) = 0x20e;
  7161. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7162. WFIFOL(fd,26) = monster_id;
  7163. WFIFOB(fd,30) = star;
  7164. WFIFOB(fd,31) = result;
  7165. WFIFOSET(fd,packet_len(0x20e));
  7166. }
  7167. /*==========================================
  7168. * Info about Star Glaldiator save map [Komurka]
  7169. * type: 1: Information, 0: Map registered
  7170. *------------------------------------------*/
  7171. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7172. {
  7173. char mapname[MAP_NAME_LENGTH_EXT];
  7174. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7175. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7176. }
  7177. /*==========================================
  7178. * Info about Star Glaldiator hate mob [Komurka]
  7179. * type: 1: Register mob, 0: Information.
  7180. *------------------------------------------*/
  7181. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7182. {
  7183. if( pcdb_checkid(class_) )
  7184. {
  7185. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7186. }
  7187. else if( mobdb_checkid(class_) )
  7188. {
  7189. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7190. }
  7191. else
  7192. {
  7193. 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);
  7194. }
  7195. }
  7196. /*==========================================
  7197. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7198. *------------------------------------------*/
  7199. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7200. {
  7201. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7202. }
  7203. /*==========================================
  7204. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7205. *------------------------------------------*/
  7206. void clif_feel_hate_reset(struct map_session_data *sd)
  7207. {
  7208. clif_starskill(sd, "", 0, 0, 30);
  7209. }
  7210. /*==========================================
  7211. * Equip window (un)tick ack
  7212. * R 02d9 <zero>.L <flag>.L
  7213. *------------------------------------------*/
  7214. void clif_equiptickack(struct map_session_data* sd, int flag)
  7215. {
  7216. int fd;
  7217. nullpo_retv(sd);
  7218. fd = sd->fd;
  7219. WFIFOHEAD(fd, packet_len(0x2d9));
  7220. WFIFOW(fd, 0) = 0x2d9;
  7221. WFIFOL(fd, 2) = 0;
  7222. WFIFOL(fd, 6) = flag;
  7223. WFIFOSET(fd, packet_len(0x2d9));
  7224. }
  7225. /*==========================================
  7226. * The player's 'view equip' state, sent during login
  7227. * R 02da <flag>.B
  7228. *------------------------------------------*/
  7229. void clif_equipcheckbox(struct map_session_data* sd)
  7230. {
  7231. int fd;
  7232. nullpo_retv(sd);
  7233. fd = sd->fd;
  7234. WFIFOHEAD(fd, packet_len(0x2da));
  7235. WFIFOW(fd, 0) = 0x2da;
  7236. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7237. WFIFOSET(fd, packet_len(0x2da));
  7238. }
  7239. /// Sends info about a player's equipped items (ZC_EQUIPWIN_MICROSCOPE)
  7240. /// 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*
  7241. /// 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* (PACKETVER >= 20100629)
  7242. /// 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* (PACKETVER >= 20101124)
  7243. /// 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* (PACKETVER >= 20110111)
  7244. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7245. {
  7246. uint8* buf;
  7247. int i, n, fd, offset = 0;
  7248. #if PACKETVER < 20100629
  7249. const int s = 26;
  7250. #else
  7251. const int s = 28;
  7252. #endif
  7253. nullpo_retv(sd);
  7254. nullpo_retv(tsd);
  7255. fd = sd->fd;
  7256. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7257. buf = WFIFOP(fd,0);
  7258. #if PACKETVER < 20101124
  7259. WBUFW(buf, 0) = 0x2d7;
  7260. #else
  7261. WBUFW(buf, 0) = 0x859;
  7262. #endif
  7263. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7264. WBUFW(buf,28) = tsd->status.class_;
  7265. WBUFW(buf,30) = tsd->vd.hair_style;
  7266. WBUFW(buf,32) = tsd->vd.head_bottom;
  7267. WBUFW(buf,34) = tsd->vd.head_mid;
  7268. WBUFW(buf,36) = tsd->vd.head_top;
  7269. #if PACKETVER >= 20110111
  7270. WBUFW(buf,38) = tsd->vd.robe;
  7271. offset+= 2;
  7272. buf = WBUFP(buf,2);
  7273. #endif
  7274. WBUFW(buf,38) = tsd->vd.hair_color;
  7275. WBUFW(buf,40) = tsd->vd.cloth_color;
  7276. WBUFB(buf,42) = tsd->vd.sex;
  7277. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7278. {
  7279. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7280. continue;
  7281. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7282. continue;
  7283. // Inventory position
  7284. WBUFW(buf, n*s+43) = i + 2;
  7285. // Add refine, identify flag, element, etc.
  7286. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7287. // Add cards
  7288. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7289. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7290. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7291. WBUFW(buf, n*s+67) = 0;
  7292. #if PACKETVER >= 20100629
  7293. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7294. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7295. else
  7296. WBUFW(buf, n*s+69) = 0;
  7297. #endif
  7298. n++;
  7299. }
  7300. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7301. WFIFOSET(fd, WFIFOW(fd, 2));
  7302. }
  7303. /// Display msgstringtable.txt string (ZC_MSG)
  7304. /// R 0291 <message>.W
  7305. void clif_msg(struct map_session_data* sd, unsigned short id)
  7306. {
  7307. int fd;
  7308. nullpo_retv(sd);
  7309. fd = sd->fd;
  7310. WFIFOHEAD(fd, packet_len(0x291));
  7311. WFIFOW(fd, 0) = 0x291;
  7312. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7313. WFIFOSET(fd, packet_len(0x291));
  7314. }
  7315. /// View player equip request denied
  7316. void clif_viewequip_fail(struct map_session_data* sd)
  7317. {
  7318. clif_msg(sd, 0x54d);
  7319. }
  7320. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7321. /// Returns true if the packet was parsed successfully.
  7322. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7323. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7324. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7325. {
  7326. char *text, *name, *message;
  7327. unsigned int packetlen, textlen, namelen, messagelen;
  7328. int fd = sd->fd;
  7329. *name_ = NULL;
  7330. *namelen_ = 0;
  7331. *message_ = NULL;
  7332. *messagelen_ = 0;
  7333. packetlen = RFIFOW(fd,2);
  7334. // basic structure checks
  7335. if( packetlen > RFIFOREST(fd) )
  7336. { // there has to be enough data to read
  7337. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7338. return false;
  7339. }
  7340. if( packetlen < 4 + 1 )
  7341. { // 4-byte header and at least an empty string is expected
  7342. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7343. return false;
  7344. }
  7345. text = (char*)RFIFOP(fd,4);
  7346. textlen = packetlen - 4;
  7347. // process <name> part of the packet
  7348. if( format == 0 )
  7349. {// name and message are separated by ' : '
  7350. // validate name
  7351. name = text;
  7352. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7353. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7354. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7355. {
  7356. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7357. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7358. set_eof(fd); // Just kick them out to correct it.
  7359. return false;
  7360. }
  7361. message = name + namelen + 3;
  7362. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7363. }
  7364. else
  7365. {// name has fixed width
  7366. if( textlen < NAME_LENGTH + 1 )
  7367. {
  7368. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7369. return false;
  7370. }
  7371. // validate name
  7372. name = text;
  7373. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7374. if( name[namelen] != '\0' )
  7375. { // only restriction is that the name must be zero-terminated
  7376. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7377. return false;
  7378. }
  7379. message = name + NAME_LENGTH;
  7380. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7381. }
  7382. if( messagelen != strnlen(message, messagelen)+1 )
  7383. { // the declared length must match real length
  7384. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7385. return false;
  7386. }
  7387. // verify <message> part of the packet
  7388. if( message[messagelen-1] != '\0' )
  7389. { // message must be zero-terminated
  7390. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7391. return false;
  7392. }
  7393. if( messagelen > CHAT_SIZE_MAX-1 )
  7394. { // messages mustn't be too long
  7395. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7396. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7397. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7398. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7399. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7400. return false;
  7401. }
  7402. *name_ = name;
  7403. *namelen_ = namelen;
  7404. *message_ = message;
  7405. *messagelen_ = messagelen;
  7406. return true;
  7407. }
  7408. // ---------------------
  7409. // clif_guess_PacketVer
  7410. // ---------------------
  7411. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7412. // error codes:
  7413. // 0 - Success
  7414. // 1 - Unknown packet_ver
  7415. // 2 - Invalid account_id
  7416. // 3 - Invalid char_id
  7417. // 4 - Invalid login_id1 (reserved)
  7418. // 5 - Invalid client_tick (reserved)
  7419. // 6 - Invalid sex
  7420. // Only the first 'invalid' error that appears is used.
  7421. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7422. {
  7423. static int err = 1;
  7424. static int packet_ver = -1;
  7425. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7426. if (get_previous)
  7427. {//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]
  7428. if( error )
  7429. *error = err;
  7430. return packet_ver;
  7431. }
  7432. //By default, start searching on the default one.
  7433. err = 1;
  7434. packet_ver = clif_config.packet_db_ver;
  7435. cmd = RFIFOW(fd,0);
  7436. packet_len = RFIFOREST(fd);
  7437. #define SET_ERROR(n) \
  7438. if( err == 1 )\
  7439. err = n;\
  7440. //define SET_ERROR
  7441. // FIXME: If the packet is not received at once, this will FAIL.
  7442. // Figure out, when it happens, that only part of the packet is
  7443. // received, or fix the function to be able to deal with that
  7444. // case.
  7445. #define CHECK_PACKET_VER() \
  7446. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7447. ;/* not wanttoconnection or wrong length */\
  7448. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7449. { SET_ERROR(2); }/* invalid account_id */\
  7450. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7451. { SET_ERROR(3); }/* invalid char_id */\
  7452. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7453. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7454. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7455. { SET_ERROR(6); }/* invalid sex */\
  7456. else\
  7457. {\
  7458. err = 0;\
  7459. if( error )\
  7460. *error = 0;\
  7461. return packet_ver;\
  7462. }\
  7463. //define CHECK_PACKET_VER
  7464. CHECK_PACKET_VER();//Default packet version found.
  7465. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7466. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7467. CHECK_PACKET_VER();
  7468. }
  7469. if( error )
  7470. *error = err;
  7471. packet_ver = -1;
  7472. return -1;
  7473. #undef SET_ERROR
  7474. #undef CHECK_PACKET_VER
  7475. }
  7476. // ------------
  7477. // clif_parse_*
  7478. // ------------
  7479. // Parses incoming (player) connection
  7480. /*==========================================
  7481. *
  7482. *------------------------------------------*/
  7483. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7484. {
  7485. struct block_list* bl;
  7486. struct auth_node* node;
  7487. int cmd, account_id, char_id, login_id1, sex;
  7488. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7489. 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])
  7490. if (sd) {
  7491. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7492. return;
  7493. }
  7494. // Only valid packet version get here
  7495. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7496. cmd = RFIFOW(fd,0);
  7497. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7498. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7499. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7500. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7501. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7502. if( packet_ver < 5 || // reject really old client versions
  7503. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7504. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7505. {// packet version rejected
  7506. 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));
  7507. WFIFOHEAD(fd,packet_len(0x6a));
  7508. WFIFOW(fd,0) = 0x6a;
  7509. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7510. WFIFOSET(fd,packet_len(0x6a));
  7511. set_eof(fd);
  7512. return;
  7513. }
  7514. if( runflag != MAPSERVER_ST_RUNNING )
  7515. {// not allowed
  7516. clif_authfail_fd(fd,1);// server closed
  7517. return;
  7518. }
  7519. //Check for double login.
  7520. bl = map_id2bl(account_id);
  7521. if(bl && bl->type != BL_PC) {
  7522. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7523. WFIFOHEAD(fd,packet_len(0x6a));
  7524. WFIFOW(fd,0) = 0x6a;
  7525. WFIFOB(fd,2) = 3; // Rejected by server
  7526. WFIFOSET(fd,packet_len(0x6a));
  7527. set_eof(fd);
  7528. return;
  7529. }
  7530. if (bl ||
  7531. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7532. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7533. {
  7534. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7535. return;
  7536. }
  7537. CREATE(sd, TBL_PC, 1);
  7538. sd->fd = fd;
  7539. sd->packet_ver = packet_ver;
  7540. session[fd]->session_data = sd;
  7541. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7542. #if PACKETVER < 20070521
  7543. WFIFOHEAD(fd,4);
  7544. WFIFOL(fd,0) = sd->bl.id;
  7545. WFIFOSET(fd,4);
  7546. #else
  7547. WFIFOHEAD(fd,packet_len(0x283));
  7548. WFIFOW(fd,0) = 0x283;
  7549. WFIFOL(fd,2) = sd->bl.id;
  7550. WFIFOSET(fd,packet_len(0x283));
  7551. #endif
  7552. chrif_authreq(sd);
  7553. return;
  7554. }
  7555. /*==========================================
  7556. * 007d : Server/Client tells that he is able to proceed
  7557. * This is run by both server (from pc.c) and client (on map load/refresh
  7558. * (teleport/warping in same map also triggers this)
  7559. *------------------------------------------*/
  7560. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7561. {
  7562. if(sd->bl.prev != NULL)
  7563. return;
  7564. if (!sd->state.active)
  7565. { //Character loading is not complete yet!
  7566. //Let pc_reg_received reinvoke this when ready.
  7567. sd->state.connect_new = 0;
  7568. return;
  7569. }
  7570. if (sd->state.rewarp)
  7571. { //Rewarp player.
  7572. sd->state.rewarp = 0;
  7573. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7574. return;
  7575. }
  7576. // look
  7577. #if PACKETVER < 4
  7578. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7579. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7580. #else
  7581. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7582. #endif
  7583. if(sd->vd.cloth_color)
  7584. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7585. // item
  7586. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7587. pc_checkitem(sd);
  7588. // cart
  7589. if(pc_iscarton(sd)) {
  7590. clif_cartlist(sd);
  7591. clif_updatestatus(sd,SP_CARTINFO);
  7592. }
  7593. // weight
  7594. clif_updatestatus(sd,SP_WEIGHT);
  7595. clif_updatestatus(sd,SP_MAXWEIGHT);
  7596. // guild
  7597. // (needs to go before clif_spawn() to show guild emblems correctly)
  7598. if(sd->status.guild_id)
  7599. guild_send_memberinfoshort(sd,1);
  7600. if(battle_config.pc_invincible_time > 0) {
  7601. if(map_flag_gvg(sd->bl.m))
  7602. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7603. else
  7604. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7605. }
  7606. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7607. map_spawnmobs(sd->bl.m);
  7608. if( !(sd->sc.option&OPTION_INVISIBLE) )
  7609. {// increment the number of pvp players on the map
  7610. map[sd->bl.m].users_pvp++;
  7611. }
  7612. if( map[sd->bl.m].instance_id )
  7613. {
  7614. instance[map[sd->bl.m].instance_id].users++;
  7615. instance_check_idle(map[sd->bl.m].instance_id);
  7616. }
  7617. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7618. // reset the callshop flag if the player changes map
  7619. sd->state.callshop = 0;
  7620. map_addblock(&sd->bl);
  7621. clif_spawn(&sd->bl);
  7622. // Party
  7623. // (needs to go after clif_spawn() to show hp bars correctly)
  7624. if(sd->status.party_id) {
  7625. party_send_movemap(sd);
  7626. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7627. }
  7628. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7629. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7630. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7631. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7632. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7633. sd->pvp_rank = 0;
  7634. sd->pvp_lastusers = 0;
  7635. sd->pvp_point = 5;
  7636. sd->pvp_won = 0;
  7637. sd->pvp_lost = 0;
  7638. }
  7639. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7640. } else
  7641. // set flag, if it's a duel [LuzZza]
  7642. if(sd->duel_group)
  7643. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7644. if (map[sd->bl.m].flag.gvg_dungeon)
  7645. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7646. if( map_flag_gvg(sd->bl.m) )
  7647. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7648. // info about nearby objects
  7649. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7650. 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);
  7651. // pet
  7652. if( sd->pd )
  7653. {
  7654. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7655. { //Return the pet to egg. [Skotlex]
  7656. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7657. pet_menu(sd, 3); //Option 3 is return to egg.
  7658. }
  7659. else
  7660. {
  7661. map_addblock(&sd->pd->bl);
  7662. clif_spawn(&sd->pd->bl);
  7663. clif_send_petdata(sd,sd->pd,0,0);
  7664. clif_send_petstatus(sd);
  7665. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7666. }
  7667. }
  7668. //homunculus [blackhole89]
  7669. if( merc_is_hom_active(sd->hd) )
  7670. {
  7671. map_addblock(&sd->hd->bl);
  7672. clif_spawn(&sd->hd->bl);
  7673. clif_send_homdata(sd,0,0);
  7674. clif_hominfo(sd,sd->hd,1);
  7675. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7676. clif_homskillinfoblock(sd);
  7677. if( battle_config.hom_setting&0x8 )
  7678. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7679. if( !(battle_config.hom_setting&0x2) )
  7680. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7681. }
  7682. if( sd->md )
  7683. {
  7684. map_addblock(&sd->md->bl);
  7685. clif_spawn(&sd->md->bl);
  7686. clif_mercenary_info(sd);
  7687. clif_mercenary_skillblock(sd);
  7688. }
  7689. if(sd->state.connect_new) {
  7690. int lv;
  7691. sd->state.connect_new = 0;
  7692. clif_skillinfoblock(sd);
  7693. clif_hotkeys_send(sd);
  7694. clif_updatestatus(sd,SP_BASEEXP);
  7695. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7696. clif_updatestatus(sd,SP_JOBEXP);
  7697. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7698. clif_updatestatus(sd,SP_SKILLPOINT);
  7699. clif_initialstatus(sd);
  7700. if (sd->sc.option&OPTION_FALCON)
  7701. clif_status_load(&sd->bl, SI_FALCON, 1);
  7702. if (sd->sc.option&OPTION_RIDING)
  7703. clif_status_load(&sd->bl, SI_RIDING, 1);
  7704. if(sd->status.manner < 0)
  7705. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7706. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7707. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7708. if(sd->bl.m == sd->feel_map[0].m
  7709. || sd->bl.m == sd->feel_map[1].m
  7710. || sd->bl.m == sd->feel_map[2].m)
  7711. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7712. }
  7713. if(sd->pd && sd->pd->pet.intimate > 900)
  7714. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7715. if(merc_is_hom_active(sd->hd))
  7716. merc_hom_init_timers(sd->hd);
  7717. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7718. {
  7719. sd->state.night = 1;
  7720. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7721. }
  7722. // Notify everyone that this char logged in [Skotlex].
  7723. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7724. //Login Event
  7725. npc_script_event(sd, NPCE_LOGIN);
  7726. } else {
  7727. //For some reason the client "loses" these on warp/map-change.
  7728. clif_updatestatus(sd,SP_STR);
  7729. clif_updatestatus(sd,SP_AGI);
  7730. clif_updatestatus(sd,SP_VIT);
  7731. clif_updatestatus(sd,SP_INT);
  7732. clif_updatestatus(sd,SP_DEX);
  7733. clif_updatestatus(sd,SP_LUK);
  7734. // abort currently running script
  7735. sd->state.using_fake_npc = 0;
  7736. sd->state.menu_or_input = 0;
  7737. sd->npc_menu = 0;
  7738. if(sd->npc_id)
  7739. npc_event_dequeue(sd);
  7740. }
  7741. if( sd->state.changemap )
  7742. {// restore information that gets lost on map-change
  7743. #if PACKETVER >= 20070918
  7744. clif_partyinvitationstate(sd);
  7745. clif_equipcheckbox(sd);
  7746. #endif
  7747. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7748. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7749. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7750. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7751. { //Display night.
  7752. if( !sd->state.night )
  7753. {
  7754. sd->state.night = 1;
  7755. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7756. }
  7757. }
  7758. else if( sd->state.night )
  7759. { //Clear night display.
  7760. sd->state.night = 0;
  7761. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7762. }
  7763. if( map[sd->bl.m].flag.battleground )
  7764. {
  7765. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7766. if( map[sd->bl.m].flag.battleground == 2 )
  7767. clif_bg_updatescore_single(sd);
  7768. }
  7769. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7770. {
  7771. char output[128];
  7772. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7773. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7774. }
  7775. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7776. sd->state.changemap = false;
  7777. }
  7778. #ifndef TXT_ONLY
  7779. mail_clear(sd);
  7780. #endif
  7781. if(map[sd->bl.m].flag.loadevent) // Lance
  7782. npc_script_event(sd, NPCE_LOADMAP);
  7783. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7784. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7785. if (sd->sc.opt2) //Client loses these on warp.
  7786. clif_changeoption(&sd->bl);
  7787. clif_weather_check(sd);
  7788. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7789. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7790. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7791. else
  7792. sd->areanpc_id = 0;
  7793. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7794. if(pc_isdead(sd))
  7795. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7796. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7797. // else
  7798. // clif_changed_dir(&sd->bl, SELF);
  7799. // Trigger skill effects if you appear standing on them
  7800. if(!battle_config.pc_invincible_time)
  7801. skill_unit_move(&sd->bl,gettick(),1);
  7802. }
  7803. /*==========================================
  7804. *
  7805. *------------------------------------------*/
  7806. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7807. {
  7808. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7809. WFIFOHEAD(fd, packet_len(0x7f));
  7810. WFIFOW(fd,0)=0x7f;
  7811. WFIFOL(fd,2)=gettick();
  7812. WFIFOSET(fd,packet_len(0x7f));
  7813. // removed until the socket problems are fixed. [FlavioJS]
  7814. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7815. return;
  7816. }
  7817. void clif_hotkeys_send(struct map_session_data *sd) {
  7818. #ifdef HOTKEY_SAVING
  7819. const int fd = sd->fd;
  7820. int i;
  7821. #if PACKETVER<20090603
  7822. const int cmd = 0x02b9;
  7823. #else
  7824. const int cmd = 0x07d9;
  7825. #endif
  7826. if (!fd) return;
  7827. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7828. WFIFOW(fd, 0) = cmd;
  7829. for(i = 0; i < MAX_HOTKEYS; i++) {
  7830. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7831. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7832. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7833. }
  7834. WFIFOSET(fd, packet_len(cmd));
  7835. #endif
  7836. }
  7837. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7838. #ifdef HOTKEY_SAVING
  7839. unsigned short idx;
  7840. int cmd;
  7841. cmd = RFIFOW(fd, 0);
  7842. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7843. if (idx >= MAX_HOTKEYS) return;
  7844. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7845. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7846. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7847. return;
  7848. #endif
  7849. }
  7850. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  7851. {
  7852. int fd = sd->fd;
  7853. WFIFOHEAD(fd,packet_len(0x2f0));
  7854. WFIFOW(fd,0) = 0x2f0;
  7855. WFIFOL(fd,2) = color;
  7856. WFIFOL(fd,6) = second;
  7857. WFIFOSET(fd,packet_len(0x2f0));
  7858. }
  7859. void clif_progressbar_abort(struct map_session_data * sd)
  7860. {
  7861. int fd = sd->fd;
  7862. WFIFOHEAD(fd,packet_len(0x2f2));
  7863. WFIFOW(fd,0) = 0x2f2;
  7864. WFIFOSET(fd,packet_len(0x2f2));
  7865. }
  7866. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  7867. {
  7868. int npc_id = sd->progressbar.npc_id;
  7869. if( gettick() < sd->progressbar.timeout && sd->st )
  7870. sd->st->state = END;
  7871. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  7872. npc_scriptcont(sd, npc_id);
  7873. }
  7874. /*==========================================
  7875. *
  7876. *------------------------------------------*/
  7877. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7878. {
  7879. short x, y;
  7880. int cmd;
  7881. if (pc_isdead(sd)) {
  7882. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7883. return;
  7884. }
  7885. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7886. ; //You CAN walk on this OPT1 value.
  7887. else if( sd->progressbar.npc_id )
  7888. clif_progressbar_abort(sd);
  7889. else if (pc_cant_act(sd))
  7890. return;
  7891. if(sd->sc.data[SC_RUN])
  7892. return;
  7893. pc_delinvincibletimer(sd);
  7894. cmd = RFIFOW(fd,0);
  7895. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7896. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7897. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7898. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7899. //Set last idle time... [Skotlex]
  7900. sd->idletime = last_tick;
  7901. unit_walktoxy(&sd->bl, x, y, 4);
  7902. }
  7903. /*==========================================
  7904. *
  7905. *------------------------------------------*/
  7906. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7907. {
  7908. WFIFOHEAD(fd,packet_len(0x18b));
  7909. WFIFOW(fd,0) = 0x18b;
  7910. /* Rovert's prevent logout option fixed [Valaris] */
  7911. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  7912. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7913. {
  7914. set_eof(fd);
  7915. WFIFOW(fd,2)=0;
  7916. } else {
  7917. WFIFOW(fd,2)=1;
  7918. }
  7919. WFIFOSET(fd,packet_len(0x18b));
  7920. }
  7921. /// Requesting unit's name
  7922. /// S 0094 <object id>.l
  7923. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7924. {
  7925. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7926. struct block_list* bl;
  7927. //struct status_change *sc;
  7928. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7929. id = sd->bl.id;
  7930. bl = map_id2bl(id);
  7931. if( bl == NULL )
  7932. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7933. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  7934. return; // Block namerequests past view range
  7935. // 'see people in GM hide' cheat detection
  7936. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7937. sc = status_get_sc(bl);
  7938. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7939. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7940. pc_isGM(sd) < battle_config.hack_info_GM_level
  7941. ) {
  7942. char gm_msg[256];
  7943. 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);
  7944. ShowWarning(gm_msg);
  7945. // information is sent to all online GMs
  7946. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7947. return;
  7948. }
  7949. */
  7950. clif_charnameack(fd, bl);
  7951. }
  7952. /*==========================================
  7953. * Validates and processes global messages
  7954. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7955. *------------------------------------------*/
  7956. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7957. {
  7958. const char* text = (char*)RFIFOP(fd,4);
  7959. int textlen = RFIFOW(fd,2) - 4;
  7960. char *name, *message, *fakename = NULL;
  7961. int namelen, messagelen;
  7962. bool is_fake;
  7963. // validate packet and retrieve name and message
  7964. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7965. return;
  7966. if( is_atcommand(fd, sd, message, 1) )
  7967. return;
  7968. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7969. return;
  7970. if( battle_config.min_chat_delay )
  7971. { //[Skotlex]
  7972. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7973. return;
  7974. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7975. }
  7976. /**
  7977. * Fake Name Design by FatalEror (bug report #9)
  7978. **/
  7979. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  7980. fakename = (char*) malloc(strlen(sd->fakename)+messagelen+3);
  7981. strcpy(fakename, sd->fakename);
  7982. strcat(fakename, " : ");
  7983. strcat(fakename, message);
  7984. textlen = strlen(fakename) + 1;
  7985. }
  7986. // send message to others (using the send buffer for temp. storage)
  7987. WFIFOHEAD(fd, 8 + textlen);
  7988. WFIFOW(fd,0) = 0x8d;
  7989. WFIFOW(fd,2) = 8 + textlen;
  7990. WFIFOL(fd,4) = sd->bl.id;
  7991. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  7992. //FIXME: chat has range of 9 only
  7993. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7994. // send back message to the speaker
  7995. if( is_fake ) {
  7996. WFIFOW(fd,0) = 0x8e;
  7997. WFIFOW(fd,2) = textlen + 4;
  7998. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  7999. } else {
  8000. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8001. WFIFOW(fd,0) = 0x8e;
  8002. }
  8003. WFIFOSET(fd, WFIFOW(fd,2));
  8004. #ifdef PCRE_SUPPORT
  8005. // trigger listening npcs
  8006. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8007. #endif
  8008. // Chat logging type 'O' / Global Chat
  8009. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8010. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8011. return;
  8012. }
  8013. /*==========================================
  8014. * /mm /mapmove (as @rura GM command)
  8015. *------------------------------------------*/
  8016. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8017. {
  8018. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  8019. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  8020. char* map_name;
  8021. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8022. return;
  8023. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  8024. return;
  8025. map_name = (char*)RFIFOP(fd,2);
  8026. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8027. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8028. atcommand_mapmove(fd, sd, "@mapmove", output);
  8029. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  8030. {
  8031. sprintf(message, "/mm %s", output);
  8032. log_atcommand(sd, message);
  8033. }
  8034. return;
  8035. }
  8036. /*==========================================
  8037. *
  8038. *------------------------------------------*/
  8039. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8040. {
  8041. unsigned char buf[64];
  8042. WBUFW(buf,0) = 0x9c;
  8043. WBUFL(buf,2) = bl->id;
  8044. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8045. WBUFB(buf,8) = unit_getdir(bl);
  8046. clif_send(buf, packet_len(0x9c), bl, target);
  8047. if (disguised(bl)) {
  8048. WBUFL(buf,2) = -bl->id;
  8049. WBUFW(buf,6) = 0;
  8050. clif_send(buf, packet_len(0x9c), bl, SELF);
  8051. }
  8052. return;
  8053. }
  8054. /*==========================================
  8055. *
  8056. *------------------------------------------*/
  8057. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8058. {
  8059. unsigned char headdir, dir;
  8060. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8061. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8062. pc_setdir(sd, dir, headdir);
  8063. clif_changed_dir(&sd->bl, AREA_WOS);
  8064. return;
  8065. }
  8066. /*==========================================
  8067. *
  8068. *------------------------------------------*/
  8069. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8070. {
  8071. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8072. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8073. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8074. clif_skill_fail(sd, 1, 0, 1);
  8075. return;
  8076. }
  8077. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8078. if (sd->emotionlasttime >= time(NULL)) {
  8079. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  8080. clif_skill_fail(sd, 1, 0, 1);
  8081. return;
  8082. }
  8083. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  8084. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  8085. {// re-roll dice
  8086. emoticon = rand()%6+E_DICE1;
  8087. }
  8088. clif_emotion(&sd->bl, emoticon);
  8089. } else
  8090. clif_skill_fail(sd, 1, 0, 1);
  8091. }
  8092. /*==========================================
  8093. *
  8094. *------------------------------------------*/
  8095. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8096. {
  8097. WFIFOHEAD(fd,packet_len(0xc2));
  8098. WFIFOW(fd,0) = 0xc2;
  8099. WFIFOL(fd,2) = map_getusers();
  8100. WFIFOSET(fd,packet_len(0xc2));
  8101. }
  8102. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8103. {
  8104. if (pc_isdead(sd)) {
  8105. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8106. return;
  8107. }
  8108. if (sd->sc.count &&
  8109. (sd->sc.data[SC_TRICKDEAD] ||
  8110. sd->sc.data[SC_AUTOCOUNTER] ||
  8111. sd->sc.data[SC_BLADESTOP]))
  8112. return;
  8113. pc_stop_walking(sd, 1);
  8114. pc_stop_attack(sd);
  8115. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8116. target_id = sd->bl.id;
  8117. switch(action_type)
  8118. {
  8119. case 0x00: // once attack
  8120. case 0x07: // continuous attack
  8121. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8122. return;
  8123. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8124. return;
  8125. if( sd->sc.data[SC_BASILICA] )
  8126. return;
  8127. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8128. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8129. clif_skill_fail(sd, 1, 4, 0);
  8130. return;
  8131. }
  8132. }
  8133. pc_delinvincibletimer(sd);
  8134. sd->idletime = last_tick;
  8135. unit_attack(&sd->bl, target_id, action_type != 0);
  8136. break;
  8137. case 0x02: // sitdown
  8138. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8139. clif_skill_fail(sd, 1, 0, 2);
  8140. break;
  8141. }
  8142. if(pc_issit(sd)) {
  8143. //Bugged client? Just refresh them.
  8144. clif_sitting(&sd->bl);
  8145. return;
  8146. }
  8147. if (sd->ud.skilltimer != INVALID_TIMER || sd->sc.opt1)
  8148. break;
  8149. if (sd->sc.count && (
  8150. sd->sc.data[SC_DANCING] ||
  8151. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8152. )) //No sitting during these states either.
  8153. break;
  8154. pc_setsit(sd);
  8155. skill_sit(sd,1);
  8156. clif_sitting(&sd->bl);
  8157. break;
  8158. case 0x03: // standup
  8159. if (!pc_issit(sd)) {
  8160. //Bugged client? Just refresh them.
  8161. clif_standing(&sd->bl);
  8162. return;
  8163. }
  8164. pc_setstand(sd);
  8165. skill_sit(sd,0);
  8166. clif_standing(&sd->bl);
  8167. break;
  8168. }
  8169. }
  8170. /*==========================================
  8171. *
  8172. *------------------------------------------*/
  8173. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8174. {
  8175. clif_parse_ActionRequest_sub(sd,
  8176. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8177. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8178. gettick()
  8179. );
  8180. }
  8181. /*==========================================
  8182. *
  8183. *------------------------------------------*/
  8184. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8185. {
  8186. switch(RFIFOB(fd,2)) {
  8187. case 0x00:
  8188. pc_respawn(sd,CLR_RESPAWN);
  8189. break;
  8190. case 0x01:
  8191. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8192. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  8193. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8194. { //Send to char-server for character selection.
  8195. chrif_charselectreq(sd, session[fd]->client_addr);
  8196. } else {
  8197. WFIFOHEAD(fd,packet_len(0x18b));
  8198. WFIFOW(fd,0)=0x18b;
  8199. WFIFOW(fd,2)=1;
  8200. WFIFOSET(fd,packet_len(0x018b));
  8201. }
  8202. break;
  8203. }
  8204. }
  8205. /*==========================================
  8206. * Validates and processes whispered messages
  8207. * S 0096 <packet len>.w <nick>.24B <message>.?B
  8208. *------------------------------------------*/
  8209. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8210. {
  8211. struct map_session_data* dstsd;
  8212. int i;
  8213. char *target, *message;
  8214. int namelen, messagelen;
  8215. // validate packet and retrieve name and message
  8216. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8217. return;
  8218. if (is_atcommand(fd, sd, message, 1) )
  8219. return;
  8220. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8221. return;
  8222. if (battle_config.min_chat_delay)
  8223. { //[Skotlex]
  8224. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8225. return;
  8226. }
  8227. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8228. }
  8229. // Chat logging type 'W' / Whisper
  8230. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8231. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  8232. //-------------------------------------------------------//
  8233. // Lordalfa - Paperboy - To whisper NPC commands //
  8234. //-------------------------------------------------------//
  8235. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8236. {
  8237. char* str = target+4; //Skip the NPC: string part.
  8238. struct npc_data* npc;
  8239. if ((npc = npc_name2id(str)))
  8240. {
  8241. char split_data[10][50];
  8242. char *split;
  8243. char output[256];
  8244. str = message;
  8245. // skip codepage indicator, if detected
  8246. if( str[0] == '|' && strlen(str) >= 4 )
  8247. str += 3;
  8248. for( i = 0; i < 10; ++i )
  8249. {// Splits the message using '#' as separators
  8250. split = strchr(str,'#');
  8251. if( split == NULL )
  8252. { // use the remaining string
  8253. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8254. for( ++i; i < 10; ++i )
  8255. split_data[i][0] = '\0';
  8256. break;
  8257. }
  8258. *split = '\0';
  8259. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8260. str = split+1;
  8261. }
  8262. for( i = 0; i < 10; ++i )
  8263. {
  8264. sprintf(output, "@whispervar%d$", i);
  8265. set_var(sd,output,(char *) split_data[i]);
  8266. }
  8267. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8268. npc_event(sd,output,0); // Calls the NPC label
  8269. return;
  8270. }
  8271. }
  8272. // Main chat [LuzZza]
  8273. if(strcmpi(target, main_chat_nick) == 0)
  8274. {
  8275. if(!sd->state.mainchat)
  8276. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8277. else {
  8278. char output[256];
  8279. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  8280. intif_broadcast2(output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0);
  8281. }
  8282. // Chat logging type 'M' / Main Chat
  8283. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8284. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8285. return;
  8286. }
  8287. // searching destination character
  8288. dstsd = map_nick2sd(target);
  8289. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8290. {
  8291. // player is not on this map-server
  8292. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8293. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8294. // and if we ask for 'Test', we must not contact 'test' player
  8295. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8296. intif_wis_message(sd, target, message, messagelen);
  8297. return;
  8298. }
  8299. // if player ignores everyone
  8300. if (dstsd->state.ignoreAll)
  8301. {
  8302. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8303. clif_wis_end(fd, 1); // 1: target character is not loged in
  8304. else
  8305. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8306. return;
  8307. }
  8308. // if player ignores the source character
  8309. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8310. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8311. { // source char present in ignore list
  8312. clif_wis_end(fd, 2); // 2: ignored by target
  8313. return;
  8314. }
  8315. // if player is autotrading
  8316. if( dstsd->state.autotrade == 1 )
  8317. {
  8318. char output[256];
  8319. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8320. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8321. return;
  8322. }
  8323. // notify sender of success
  8324. clif_wis_end(fd, 0); // 0: success to send wisper
  8325. // Normal message
  8326. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8327. return;
  8328. }
  8329. /*==========================================
  8330. * /b /nb
  8331. * S 0099 <packet len>.w <text>.?B 00
  8332. *------------------------------------------*/
  8333. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8334. {
  8335. char* msg = (char*)RFIFOP(fd,4);
  8336. unsigned int len = RFIFOW(fd,2)-4;
  8337. int lv;
  8338. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8339. return;
  8340. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  8341. return;
  8342. // as the length varies depending on the command used, just block unreasonably long strings
  8343. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  8344. intif_broadcast(msg, len, 0);
  8345. if(log_config.gm && lv >= log_config.gm) {
  8346. char logmsg[CHAT_SIZE_MAX+4];
  8347. sprintf(logmsg, "/b %s", msg);
  8348. log_atcommand(sd, logmsg);
  8349. }
  8350. }
  8351. /*==========================================
  8352. *
  8353. *------------------------------------------*/
  8354. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8355. {
  8356. struct flooritem_data *fitem;
  8357. int map_object_id;
  8358. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8359. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8360. do {
  8361. if (pc_isdead(sd)) {
  8362. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8363. break;
  8364. }
  8365. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8366. break;
  8367. if (pc_cant_act(sd))
  8368. break;
  8369. if(sd->sc.count && (
  8370. sd->sc.data[SC_HIDING] ||
  8371. sd->sc.data[SC_CLOAKING] ||
  8372. sd->sc.data[SC_TRICKDEAD] ||
  8373. sd->sc.data[SC_BLADESTOP] ||
  8374. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8375. )
  8376. break;
  8377. if (!pc_takeitem(sd, fitem))
  8378. break;
  8379. return;
  8380. } while (0);
  8381. // Client REQUIRES a fail packet or you can no longer pick items.
  8382. clif_additem(sd,0,0,6);
  8383. }
  8384. /*==========================================
  8385. *
  8386. *------------------------------------------*/
  8387. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8388. {
  8389. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8390. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8391. for(;;) {
  8392. if (pc_isdead(sd))
  8393. break;
  8394. if (pc_cant_act(sd))
  8395. break;
  8396. if (sd->sc.count && (
  8397. sd->sc.data[SC_AUTOCOUNTER] ||
  8398. sd->sc.data[SC_BLADESTOP] ||
  8399. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8400. ))
  8401. break;
  8402. if (!pc_dropitem(sd, item_index, item_amount))
  8403. break;
  8404. return;
  8405. }
  8406. //Because the client does not like being ignored.
  8407. clif_dropitem(sd, item_index,0);
  8408. }
  8409. /*==========================================
  8410. *
  8411. *------------------------------------------*/
  8412. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8413. {
  8414. int n;
  8415. if (pc_isdead(sd)) {
  8416. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8417. return;
  8418. }
  8419. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8420. return;
  8421. //This flag enables you to use items while in an NPC. [Skotlex]
  8422. if (sd->npc_id) {
  8423. if (sd->npc_id != sd->npc_item_flag)
  8424. return;
  8425. } else
  8426. if (pc_istrading(sd))
  8427. return;
  8428. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8429. sd->idletime = last_tick;
  8430. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8431. if(n <0 || n >= MAX_INVENTORY)
  8432. return;
  8433. if (!pc_useitem(sd,n))
  8434. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8435. }
  8436. /*==========================================
  8437. *
  8438. *------------------------------------------*/
  8439. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8440. {
  8441. int index;
  8442. if(pc_isdead(sd)) {
  8443. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8444. return;
  8445. }
  8446. index = RFIFOW(fd,2)-2;
  8447. if (index < 0 || index >= MAX_INVENTORY)
  8448. return; //Out of bounds check.
  8449. if(sd->npc_id) {
  8450. if (sd->npc_id != sd->npc_item_flag)
  8451. return;
  8452. } else if (sd->state.storage_flag || sd->sc.opt1)
  8453. ; //You can equip/unequip stuff while storage is open/under status changes
  8454. else if (pc_cant_act(sd))
  8455. return;
  8456. if(!sd->status.inventory[index].identify) {
  8457. clif_equipitemack(sd,index,0,0); // fail
  8458. return;
  8459. }
  8460. if(!sd->inventory_data[index])
  8461. return;
  8462. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8463. pet_equipitem(sd,index);
  8464. return;
  8465. }
  8466. //Client doesn't send the position for ammo.
  8467. if(sd->inventory_data[index]->type == IT_AMMO)
  8468. pc_equipitem(sd,index,EQP_AMMO);
  8469. else
  8470. pc_equipitem(sd,index,RFIFOW(fd,4));
  8471. }
  8472. /*==========================================
  8473. *
  8474. *------------------------------------------*/
  8475. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8476. {
  8477. int index;
  8478. if(pc_isdead(sd)) {
  8479. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8480. return;
  8481. }
  8482. if (sd->state.storage_flag)
  8483. ; //You can equip/unequip stuff while storage is open.
  8484. else if (pc_cant_act(sd))
  8485. return;
  8486. index = RFIFOW(fd,2)-2;
  8487. pc_unequipitem(sd,index,1);
  8488. }
  8489. /*==========================================
  8490. *
  8491. *------------------------------------------*/
  8492. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8493. {
  8494. struct block_list *bl;
  8495. if(pc_isdead(sd)) {
  8496. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8497. return;
  8498. }
  8499. if (pc_cant_act(sd))
  8500. return;
  8501. bl = map_id2bl(RFIFOL(fd,2));
  8502. if (!bl) return;
  8503. switch (bl->type) {
  8504. case BL_MOB:
  8505. case BL_PC:
  8506. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8507. break;
  8508. case BL_NPC:
  8509. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8510. npc_click(sd,(TBL_NPC*)bl);
  8511. break;
  8512. }
  8513. return;
  8514. }
  8515. /*==========================================
  8516. *
  8517. *------------------------------------------*/
  8518. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8519. {
  8520. if (sd->state.trading)
  8521. return;
  8522. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8523. }
  8524. /// Request to buy chosen items from npc shop
  8525. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  8526. /// R 00ca <result>.b
  8527. /// result = 00 -> "The deal has successfully completed."
  8528. /// result = 01 -> "You do not have enough zeny."
  8529. /// result = 02 -> "You are over your Weight Limit."
  8530. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8531. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8532. {
  8533. int n = (RFIFOW(fd,2)-4) /4;
  8534. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8535. int result;
  8536. if( sd->state.trading || !sd->npc_shopid )
  8537. result = 1;
  8538. else
  8539. result = npc_buylist(sd,n,item_list);
  8540. sd->npc_shopid = 0; //Clear shop data.
  8541. WFIFOHEAD(fd,packet_len(0xca));
  8542. WFIFOW(fd,0) = 0xca;
  8543. WFIFOB(fd,2) = result;
  8544. WFIFOSET(fd,packet_len(0xca));
  8545. }
  8546. /// Request to sell chosen items to npc shop
  8547. /// R 00c9 <packet len>.W {<index>.W <amount>.W}.4B*
  8548. /// S 00cb <result>.B
  8549. /// result = 00 -> "The deal has successfully completed."
  8550. /// result = 01 -> "The deal has failed."
  8551. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8552. {
  8553. int fail=0,n;
  8554. unsigned short *item_list;
  8555. n = (RFIFOW(fd,2)-4) /4;
  8556. item_list = (unsigned short*)RFIFOP(fd,4);
  8557. if (sd->state.trading || !sd->npc_shopid)
  8558. fail = 1;
  8559. else
  8560. fail = npc_selllist(sd,n,item_list);
  8561. sd->npc_shopid = 0; //Clear shop data.
  8562. WFIFOHEAD(fd,packet_len(0xcb));
  8563. WFIFOW(fd,0)=0xcb;
  8564. WFIFOB(fd,2)=fail;
  8565. WFIFOSET(fd,packet_len(0xcb));
  8566. }
  8567. /*==========================================
  8568. * Chatroom creation request
  8569. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8570. *------------------------------------------*/
  8571. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8572. {
  8573. int len = RFIFOW(fd,2)-15;
  8574. int limit = RFIFOW(fd,4);
  8575. bool pub = (RFIFOB(fd,6) != 0);
  8576. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8577. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8578. char s_password[CHATROOM_PASS_SIZE];
  8579. char s_title[CHATROOM_TITLE_SIZE];
  8580. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8581. return;
  8582. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8583. clif_skill_fail(sd,1,0,3);
  8584. return;
  8585. }
  8586. if( len <= 0 )
  8587. return; // invalid input
  8588. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8589. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8590. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8591. }
  8592. /*==========================================
  8593. * Chatroom join request
  8594. * S 00d9 <chat ID>.l <passwd>.8B
  8595. *------------------------------------------*/
  8596. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8597. {
  8598. int chatid = RFIFOL(fd,2);
  8599. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8600. chat_joinchat(sd,chatid,password);
  8601. }
  8602. /*==========================================
  8603. * Chatroom properties adjustment request
  8604. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8605. *------------------------------------------*/
  8606. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8607. {
  8608. int len = RFIFOW(fd,2)-15;
  8609. int limit = RFIFOW(fd,4);
  8610. bool pub = (RFIFOB(fd,6) != 0);
  8611. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8612. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8613. char s_password[CHATROOM_PASS_SIZE];
  8614. char s_title[CHATROOM_TITLE_SIZE];
  8615. if( len <= 0 )
  8616. return; // invalid input
  8617. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8618. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8619. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8620. }
  8621. /*==========================================
  8622. * CZ_REQ_ROLE_CHANGE
  8623. * S 00e0 <role>.L <nick>.24B
  8624. * role:
  8625. * 0 = owner (ROOMROLE_OWNER)
  8626. * 1 = normal (ROOMROLE_GENERAL)
  8627. *------------------------------------------*/
  8628. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8629. {
  8630. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8631. }
  8632. /*==========================================
  8633. *
  8634. *------------------------------------------*/
  8635. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8636. {
  8637. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8638. }
  8639. /*==========================================
  8640. * Request to leave the current chatroom
  8641. * S 00e3
  8642. *------------------------------------------*/
  8643. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8644. {
  8645. chat_leavechat(sd,0);
  8646. }
  8647. //Handles notifying asker and rejecter of what has just ocurred.
  8648. //Type is used to determine the correct msg_txt to use:
  8649. //0:
  8650. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8651. {
  8652. const char* msg;
  8653. char output[256];
  8654. // Your request has been rejected by autoreject option.
  8655. msg = msg_txt(392);
  8656. clif_disp_onlyself(src, msg, strlen(msg));
  8657. //Notice that a request was rejected.
  8658. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8659. clif_disp_onlyself(target, output, strlen(output));
  8660. }
  8661. /*==========================================
  8662. * Client tells server to send a trade request to char id RFIFOL(fd,2)
  8663. *------------------------------------------*/
  8664. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8665. {
  8666. struct map_session_data *t_sd;
  8667. t_sd = map_id2sd(RFIFOL(fd,2));
  8668. if(!sd->chatID && pc_cant_act(sd))
  8669. return; //You can trade while in a chatroom.
  8670. // @noask [LuzZza]
  8671. if(t_sd && t_sd->state.noask) {
  8672. clif_noask_sub(sd, t_sd, 0);
  8673. return;
  8674. }
  8675. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8676. {
  8677. clif_skill_fail(sd,1,0,0);
  8678. return;
  8679. }
  8680. trade_traderequest(sd,t_sd);
  8681. }
  8682. /*==========================================
  8683. * Client tells server he replied to a trade request sent to him
  8684. *------------------------------------------*/
  8685. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8686. {
  8687. trade_tradeack(sd,RFIFOB(fd,2));
  8688. }
  8689. /*==========================================
  8690. * Client tells server to add RFIFOL(fd,4) quantity of item index RFIFOW(fd,2)
  8691. *------------------------------------------*/
  8692. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8693. {
  8694. short index = RFIFOW(fd,2);
  8695. int amount = RFIFOL(fd,4);
  8696. if( index == 0 )
  8697. trade_tradeaddzeny(sd, amount);
  8698. else
  8699. trade_tradeadditem(sd, index, (short)amount);
  8700. }
  8701. /*==========================================
  8702. * Client tells server player he is done adding items to his trade window
  8703. *------------------------------------------*/
  8704. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8705. {
  8706. trade_tradeok(sd);
  8707. }
  8708. /*==========================================
  8709. * Client tells server player cancelled the trade
  8710. *------------------------------------------*/
  8711. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8712. {
  8713. trade_tradecancel(sd);
  8714. }
  8715. /*==========================================
  8716. * Client tells server player 'locked' the trade screen (can't add/remove items)
  8717. *------------------------------------------*/
  8718. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8719. {
  8720. trade_tradecommit(sd);
  8721. }
  8722. /*==========================================
  8723. *
  8724. *------------------------------------------*/
  8725. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8726. {
  8727. pc_stop_attack(sd);
  8728. }
  8729. /*==========================================
  8730. * Client tells server player dragged (RFIFOL(fd,4))x of item idx RIFOFW(fd,2)-2 to cart
  8731. *------------------------------------------*/
  8732. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8733. {
  8734. if (pc_istrading(sd))
  8735. return;
  8736. if (!pc_iscarton(sd))
  8737. return;
  8738. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8739. }
  8740. /*==========================================
  8741. * Client tells server to take y (RFIFOL(fd,4)) amount of item (idx:RFIFOW(fd,2)-2) from cart and add to inventory
  8742. *------------------------------------------*/
  8743. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8744. {
  8745. if (!pc_iscarton(sd))
  8746. return;
  8747. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8748. }
  8749. /*==========================================
  8750. * Client tells server the user hit the 'OFF' button in the equip window (appears when mounting, with falcon, etc)
  8751. *------------------------------------------*/
  8752. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8753. {
  8754. /**
  8755. * Attempts to remove these options when this function is called (will remove all available)
  8756. **/
  8757. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  8758. }
  8759. /*==========================================
  8760. * Client tells server the user selected cart type 'type', comes from cart selection screen (Change Cart Skill)
  8761. *------------------------------------------*/
  8762. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8763. {
  8764. int type;
  8765. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8766. return;
  8767. type = (int)RFIFOW(fd,2);
  8768. if( (type == 5 && sd->status.base_level > 90) ||
  8769. (type == 4 && sd->status.base_level > 80) ||
  8770. (type == 3 && sd->status.base_level > 65) ||
  8771. (type == 2 && sd->status.base_level > 40) ||
  8772. (type == 1))
  8773. pc_setcart(sd,type);
  8774. }
  8775. /*==========================================
  8776. * Client tells Server to process a /str, /vit, etc(others)
  8777. *------------------------------------------*/
  8778. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8779. {
  8780. pc_statusup(sd,RFIFOW(fd,2));
  8781. }
  8782. /*==========================================
  8783. * Client tells server to level up skill (RFIFOW(fd,2)) by 1
  8784. *------------------------------------------*/
  8785. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8786. {
  8787. pc_skillup(sd,RFIFOW(fd,2));
  8788. }
  8789. 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)
  8790. {
  8791. int lv;
  8792. if( !hd )
  8793. return;
  8794. if( skillnotok_hom(skillnum, hd) )
  8795. return;
  8796. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8797. target_id = hd->bl.id;
  8798. if( hd->ud.skilltimer != INVALID_TIMER )
  8799. {
  8800. if( skillnum != SA_CASTCANCEL ) return;
  8801. }
  8802. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8803. return;
  8804. lv = merc_hom_checkskill(hd, skillnum);
  8805. if( skilllv > lv )
  8806. skilllv = lv;
  8807. if( skilllv )
  8808. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8809. }
  8810. 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)
  8811. {
  8812. int lv;
  8813. if( !md )
  8814. return;
  8815. if( skillnotok_mercenary(skillnum, md) )
  8816. return;
  8817. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8818. target_id = md->bl.id;
  8819. if( md->ud.skilltimer != INVALID_TIMER )
  8820. {
  8821. if( skillnum != SA_CASTCANCEL ) return;
  8822. }
  8823. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8824. return;
  8825. lv = mercenary_checkskill(md, skillnum);
  8826. if( skilllv > lv )
  8827. skilllv = lv;
  8828. if( skilllv )
  8829. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8830. }
  8831. 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)
  8832. {
  8833. int lv;
  8834. if( !md )
  8835. return;
  8836. if( skillnotok_mercenary(skillnum, md) )
  8837. return;
  8838. if( md->ud.skilltimer != INVALID_TIMER )
  8839. return;
  8840. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8841. {
  8842. clif_skill_fail(md->master, skillnum, 4, 0);
  8843. return;
  8844. }
  8845. if( md->sc.data[SC_BASILICA] )
  8846. return;
  8847. lv = mercenary_checkskill(md, skillnum);
  8848. if( skilllv > lv )
  8849. skilllv = lv;
  8850. if( skilllv )
  8851. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8852. }
  8853. /*==========================================
  8854. * Client tells server he'd like to use skill of id 'skillnum' and level 'skilllv' on 'target_id'
  8855. *------------------------------------------*/
  8856. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8857. {
  8858. short skillnum, skilllv;
  8859. int tmp, target_id;
  8860. unsigned int tick = gettick();
  8861. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8862. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8863. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8864. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8865. tmp = skill_get_inf(skillnum);
  8866. if (tmp&INF_GROUND_SKILL || !tmp)
  8867. return; //Using a ground/passive skill on a target? WRONG.
  8868. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8869. {
  8870. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8871. return;
  8872. }
  8873. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8874. {
  8875. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8876. return;
  8877. }
  8878. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8879. sd->idletime = last_tick;
  8880. if( pc_cant_act(sd) )
  8881. return;
  8882. if( pc_issit(sd) )
  8883. return;
  8884. if( skillnotok(skillnum, sd) )
  8885. return;
  8886. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  8887. target_id = sd->bl.id; // never trust the client
  8888. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8889. target_id = sd->bl.id;
  8890. if( sd->ud.skilltimer != INVALID_TIMER )
  8891. {
  8892. if( skillnum != SA_CASTCANCEL )
  8893. return;
  8894. }
  8895. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8896. {
  8897. if( sd->skillitem != skillnum )
  8898. {
  8899. clif_skill_fail(sd, skillnum, 4, 0);
  8900. return;
  8901. }
  8902. }
  8903. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8904. return;
  8905. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8906. return; // On basilica only caster can use Basilica again to stop it.
  8907. if( sd->menuskill_id )
  8908. {
  8909. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8910. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8911. else if( sd->menuskill_id != SA_AUTOSPELL )
  8912. return; //Can't use skills while a menu is open.
  8913. }
  8914. if( sd->skillitem == skillnum )
  8915. {
  8916. if( skilllv != sd->skillitemlv )
  8917. skilllv = sd->skillitemlv;
  8918. if( !(tmp&INF_SELF_SKILL) )
  8919. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  8920. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8921. return;
  8922. }
  8923. sd->skillitem = sd->skillitemlv = 0;
  8924. if( skillnum >= GD_SKILLBASE )
  8925. {
  8926. if( sd->state.gmaster_flag )
  8927. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8928. else
  8929. skilllv = 0;
  8930. }
  8931. else
  8932. {
  8933. tmp = pc_checkskill(sd, skillnum);
  8934. if( skilllv > tmp )
  8935. skilllv = tmp;
  8936. }
  8937. pc_delinvincibletimer(sd);
  8938. if( skilllv )
  8939. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8940. }
  8941. /*==========================================
  8942. * Client tells server he'd like to use AoE skill id 'skillnum' of level 'skilllv' on 'x','y' location
  8943. *------------------------------------------*/
  8944. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8945. {
  8946. int lv;
  8947. unsigned int tick = gettick();
  8948. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8949. return; //Using a target skill on the ground? WRONG.
  8950. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8951. {
  8952. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8953. return;
  8954. }
  8955. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8956. sd->idletime = last_tick;
  8957. if( skillnotok(skillnum, sd) )
  8958. return;
  8959. if( skillmoreinfo != -1 )
  8960. {
  8961. if( pc_issit(sd) )
  8962. {
  8963. clif_skill_fail(sd, skillnum, 0, 0);
  8964. return;
  8965. }
  8966. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8967. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8968. }
  8969. if( sd->ud.skilltimer != INVALID_TIMER )
  8970. return;
  8971. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8972. {
  8973. if( sd->skillitem != skillnum )
  8974. {
  8975. clif_skill_fail(sd, skillnum, 4, 0);
  8976. return;
  8977. }
  8978. }
  8979. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8980. return;
  8981. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8982. return; // On basilica only caster can use Basilica again to stop it.
  8983. if( sd->menuskill_id )
  8984. {
  8985. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8986. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8987. else if( sd->menuskill_id != SA_AUTOSPELL )
  8988. return; //Can't use skills while a menu is open.
  8989. }
  8990. pc_delinvincibletimer(sd);
  8991. if( sd->skillitem == skillnum )
  8992. {
  8993. if( skilllv != sd->skillitemlv )
  8994. skilllv = sd->skillitemlv;
  8995. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8996. }
  8997. else
  8998. {
  8999. sd->skillitem = sd->skillitemlv = 0;
  9000. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  9001. {
  9002. if( skilllv > lv )
  9003. skilllv = lv;
  9004. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  9005. }
  9006. }
  9007. }
  9008. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9009. {
  9010. if (pc_cant_act(sd))
  9011. return;
  9012. if (pc_issit(sd))
  9013. return;
  9014. clif_parse_UseSkillToPosSub(fd, sd,
  9015. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9016. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9017. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9018. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9019. -1 //Skill more info.
  9020. );
  9021. }
  9022. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9023. {
  9024. if (pc_cant_act(sd))
  9025. return;
  9026. if (pc_issit(sd))
  9027. return;
  9028. clif_parse_UseSkillToPosSub(fd, sd,
  9029. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9030. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9031. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9032. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9033. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9034. );
  9035. }
  9036. /*==========================================
  9037. * (?) I *think* this one is for skills cast on self, not entirely sure
  9038. *------------------------------------------*/
  9039. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9040. {
  9041. short skill_num = RFIFOW(fd,2);
  9042. char map_name[MAP_NAME_LENGTH];
  9043. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9044. if(skill_num != sd->menuskill_id)
  9045. return;
  9046. if( pc_cant_act(sd) )
  9047. {
  9048. sd->menuskill_id = sd->menuskill_val = 0;
  9049. return;
  9050. }
  9051. pc_delinvincibletimer(sd);
  9052. skill_castend_map(sd,skill_num,map_name);
  9053. }
  9054. /*==========================================
  9055. * Client tells server he did '/memo'
  9056. *------------------------------------------*/
  9057. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9058. {
  9059. if (!pc_isdead(sd))
  9060. pc_memo(sd,-1);
  9061. }
  9062. /*==========================================
  9063. * Client tells server he selected something from a crafting window (e.g. pharmacy)
  9064. *------------------------------------------*/
  9065. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9066. {
  9067. if( sd->menuskill_id != -1 && sd->menuskill_id != AM_PHARMACY && sd->menuskill_id != RK_RUNEMASTERY )
  9068. return;
  9069. if (pc_istrading(sd)) {
  9070. //Make it fail to avoid shop exploits where you sell something different than you see.
  9071. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9072. sd->menuskill_val = sd->menuskill_id = 0;
  9073. return;
  9074. }
  9075. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9076. sd->menuskill_val = sd->menuskill_id = 0;
  9077. }
  9078. /*==========================================
  9079. *
  9080. *------------------------------------------*/
  9081. void clif_parse_Cooking(int fd,struct map_session_data *sd)
  9082. {
  9083. //int type = RFIFOW(fd,2); // '1' for cooking, but what do other values mean?
  9084. int nameid = RFIFOW(fd,4);
  9085. if( sd->menuskill_id != AM_PHARMACY )
  9086. {
  9087. return;
  9088. }
  9089. if (pc_istrading(sd)) {
  9090. //Make it fail to avoid shop exploits where you sell something different than you see.
  9091. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9092. sd->menuskill_val = sd->menuskill_id = 0;
  9093. return;
  9094. }
  9095. skill_produce_mix(sd,0,nameid,0,0,0,1);
  9096. sd->menuskill_val = sd->menuskill_id = 0;
  9097. }
  9098. /*==========================================
  9099. * Client tells server he selected something in his 'repair item list'
  9100. *------------------------------------------*/
  9101. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9102. {
  9103. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9104. return;
  9105. if (pc_istrading(sd)) {
  9106. //Make it fail to avoid shop exploits where you sell something different than you see.
  9107. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9108. sd->menuskill_val = sd->menuskill_id = 0;
  9109. return;
  9110. }
  9111. skill_repairweapon(sd,RFIFOW(fd,2));
  9112. sd->menuskill_val = sd->menuskill_id = 0;
  9113. }
  9114. /*==========================================
  9115. *
  9116. *------------------------------------------*/
  9117. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9118. {
  9119. int idx;
  9120. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9121. return;
  9122. if (pc_istrading(sd)) {
  9123. //Make it fail to avoid shop exploits where you sell something different than you see.
  9124. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9125. sd->menuskill_val = sd->menuskill_id = 0;
  9126. return;
  9127. }
  9128. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9129. skill_weaponrefine(sd, idx-2);
  9130. sd->menuskill_val = sd->menuskill_id = 0;
  9131. }
  9132. /*==========================================
  9133. *
  9134. *------------------------------------------*/
  9135. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9136. {
  9137. int npc_id = RFIFOL(fd,2);
  9138. uint8 select = RFIFOB(fd,6);
  9139. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  9140. {
  9141. TBL_NPC* nd = map_id2nd(npc_id);
  9142. 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);
  9143. clif_GM_kick(NULL,sd);
  9144. return;
  9145. }
  9146. sd->npc_menu = select;
  9147. npc_scriptcont(sd,npc_id);
  9148. }
  9149. /*==========================================
  9150. *
  9151. *------------------------------------------*/
  9152. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9153. {
  9154. npc_scriptcont(sd,RFIFOL(fd,2));
  9155. }
  9156. /*==========================================
  9157. * Value entered into a NPC input box.
  9158. * S 0143 <npcID>.l <amount>.l
  9159. *------------------------------------------*/
  9160. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9161. {
  9162. int npcid = RFIFOL(fd,2);
  9163. int amount = (int)RFIFOL(fd,6);
  9164. sd->npc_amount = amount;
  9165. npc_scriptcont(sd, npcid);
  9166. }
  9167. /*==========================================
  9168. * Text entered into a NPC input box.
  9169. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  9170. *------------------------------------------*/
  9171. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9172. {
  9173. int message_len = RFIFOW(fd,2)-8;
  9174. int npcid = RFIFOL(fd,4);
  9175. const char* message = (char*)RFIFOP(fd,8);
  9176. if( message_len <= 0 )
  9177. return; // invalid input
  9178. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9179. npc_scriptcont(sd, npcid);
  9180. }
  9181. /*==========================================
  9182. *
  9183. *------------------------------------------*/
  9184. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9185. {
  9186. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9187. return;
  9188. npc_scriptcont(sd,RFIFOL(fd,2));
  9189. }
  9190. /*==========================================
  9191. * Client tells server he selected something in his 'magnifier item list'
  9192. *------------------------------------------*/
  9193. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9194. {
  9195. short idx = RFIFOW(fd,2);
  9196. if (sd->menuskill_id != MC_IDENTIFY)
  9197. return;
  9198. if( idx == -1 )
  9199. {// cancel pressed
  9200. sd->menuskill_val = sd->menuskill_id = 0;
  9201. return;
  9202. }
  9203. skill_identify(sd,idx-2);
  9204. sd->menuskill_val = sd->menuskill_id = 0;
  9205. }
  9206. /*==========================================
  9207. * Client tells server he selected something in his 'arrow crafting list'
  9208. *------------------------------------------*/
  9209. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9210. {
  9211. if (pc_istrading(sd)) {
  9212. //Make it fail to avoid shop exploits where you sell something different than you see.
  9213. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9214. sd->menuskill_val = sd->menuskill_id = 0;
  9215. return;
  9216. }
  9217. switch( sd->menuskill_id ) {
  9218. case AC_MAKINGARROW:
  9219. skill_arrow_create(sd,RFIFOW(fd,2));
  9220. break;
  9221. case WL_READING_SB:
  9222. skill_spellbook(sd,RFIFOW(fd,2));
  9223. break;
  9224. case GC_POISONINGWEAPON:
  9225. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9226. break;
  9227. case NC_MAGICDECOY:
  9228. skill_magicdecoy(sd,RFIFOW(fd,2));
  9229. break;
  9230. }
  9231. sd->menuskill_val = sd->menuskill_id = 0;
  9232. }
  9233. /*==========================================
  9234. * Client tells server he selected something in his 'autospell skill list'
  9235. *------------------------------------------*/
  9236. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9237. {
  9238. if (sd->menuskill_id != SA_AUTOSPELL)
  9239. return;
  9240. skill_autospell(sd,RFIFOW(fd,2));
  9241. sd->menuskill_val = sd->menuskill_id = 0;
  9242. }
  9243. /*==========================================
  9244. * Client tells server he clicked on a card item, requests the can-add-to list
  9245. *------------------------------------------*/
  9246. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9247. {
  9248. if (sd->state.trading != 0)
  9249. return;
  9250. clif_use_card(sd,RFIFOW(fd,2)-2);
  9251. }
  9252. /*==========================================
  9253. * Client tells server he selected something in his 'carding list' (the one that lists all items you got that can receive that card)
  9254. *------------------------------------------*/
  9255. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9256. {
  9257. if (sd->state.trading != 0)
  9258. return;
  9259. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9260. }
  9261. /*==========================================
  9262. * 0193 : Client asks server for nick reference to a specific char id
  9263. *------------------------------------------*/
  9264. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9265. {
  9266. int charid;
  9267. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9268. map_reqnickdb(sd, charid);
  9269. }
  9270. /*==========================================
  9271. * 0197 /resetskill /resetstate
  9272. *------------------------------------------*/
  9273. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  9274. {
  9275. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9276. return;
  9277. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  9278. return;
  9279. if( RFIFOW(fd,2) )
  9280. pc_resetskill(sd,1);
  9281. else
  9282. pc_resetstate(sd);
  9283. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  9284. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  9285. }
  9286. /*==========================================
  9287. * /lb /nlb
  9288. * S 019c <packet len>.w <text>.?B 00
  9289. *------------------------------------------*/
  9290. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9291. {
  9292. char* msg = (char*)RFIFOP(fd,4);
  9293. unsigned int len = RFIFOW(fd,2)-4;
  9294. int lv;
  9295. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9296. return;
  9297. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  9298. return;
  9299. // as the length varies depending on the command used, just block unreasonably long strings
  9300. len = mes_len_check(msg, len, CHAT_SIZE_MAX);
  9301. clif_broadcast(&sd->bl, msg, len, 0, ALL_SAMEMAP);
  9302. if( log_config.gm && lv >= log_config.gm ) {
  9303. char logmsg[CHAT_SIZE_MAX+5];
  9304. sprintf(logmsg, "/lb %s", msg);
  9305. log_atcommand(sd, logmsg);
  9306. }
  9307. }
  9308. /*==========================================
  9309. * Client tells server to move (item_amount) quantity of item idx (item_index) from inventory to storage
  9310. *------------------------------------------*/
  9311. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9312. {
  9313. int item_index, item_amount;
  9314. if (pc_istrading(sd))
  9315. return;
  9316. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9317. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9318. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9319. return;
  9320. if (sd->state.storage_flag == 1)
  9321. storage_storageadd(sd, item_index, item_amount);
  9322. else
  9323. if (sd->state.storage_flag == 2)
  9324. storage_guild_storageadd(sd, item_index, item_amount);
  9325. }
  9326. /*==========================================
  9327. * Client tells server to move (item_amount) quantity of item idx (item_index) from storage to inventory
  9328. *------------------------------------------*/
  9329. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9330. {
  9331. int item_index, item_amount;
  9332. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9333. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9334. if (sd->state.storage_flag == 1)
  9335. storage_storageget(sd, item_index, item_amount);
  9336. else
  9337. if(sd->state.storage_flag == 2)
  9338. storage_guild_storageget(sd, item_index, item_amount);
  9339. }
  9340. /*==========================================
  9341. * Client tells server to move RFIFOL(fd,4) quantity of item idx RFIFOW(fd,2) from cart to storage
  9342. *------------------------------------------*/
  9343. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9344. {
  9345. if( sd->state.vending )
  9346. return;
  9347. if (!pc_iscarton(sd))
  9348. return;
  9349. if (sd->state.storage_flag == 1)
  9350. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9351. else
  9352. if (sd->state.storage_flag == 2)
  9353. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9354. }
  9355. /*==========================================
  9356. * Client tells server to move RFIFOL(fd,4) quantity of item idx RFIFOW(fd,2) from storage to cart
  9357. *------------------------------------------*/
  9358. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9359. {
  9360. if( sd->state.vending )
  9361. return;
  9362. if (!pc_iscarton(sd))
  9363. return;
  9364. if (sd->state.storage_flag == 1)
  9365. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9366. else
  9367. if (sd->state.storage_flag == 2)
  9368. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9369. }
  9370. /*==========================================
  9371. * Client tells server to close the kafra
  9372. *------------------------------------------*/
  9373. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9374. {
  9375. if( sd->state.storage_flag == 1 )
  9376. storage_storageclose(sd);
  9377. else
  9378. if( sd->state.storage_flag == 2 )
  9379. storage_guild_storageclose(sd);
  9380. }
  9381. /*==========================================
  9382. * Kafra storage protection password system
  9383. *------------------------------------------*/
  9384. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9385. {
  9386. //TODO
  9387. }
  9388. /*==========================================
  9389. * Party creation request
  9390. * S 00f9 <party name>.24S
  9391. * S 01e8 <party name>.24S <share flag>.B <share type>.B
  9392. *------------------------------------------*/
  9393. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9394. {
  9395. char* name = (char*)RFIFOP(fd,2);
  9396. name[NAME_LENGTH-1] = '\0';
  9397. if( map[sd->bl.m].flag.partylock )
  9398. {// Party locked.
  9399. clif_displaymessage(fd, msg_txt(227));
  9400. return;
  9401. }
  9402. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9403. {
  9404. clif_skill_fail(sd,1,0,4);
  9405. return;
  9406. }
  9407. party_create(sd,name,0,0);
  9408. }
  9409. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9410. {
  9411. char* name = (char*)RFIFOP(fd,2);
  9412. int item1 = RFIFOB(fd,26);
  9413. int item2 = RFIFOB(fd,27);
  9414. name[NAME_LENGTH-1] = '\0';
  9415. if( map[sd->bl.m].flag.partylock )
  9416. {// Party locked.
  9417. clif_displaymessage(fd, msg_txt(227));
  9418. return;
  9419. }
  9420. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9421. {
  9422. clif_skill_fail(sd,1,0,4);
  9423. return;
  9424. }
  9425. party_create(sd,name,item1,item2);
  9426. }
  9427. /*==========================================
  9428. * Party invitation request
  9429. * S 00fc <account ID>.L
  9430. * S 02c4 <char name>.24S
  9431. *------------------------------------------*/
  9432. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9433. {
  9434. struct map_session_data *t_sd;
  9435. if(map[sd->bl.m].flag.partylock)
  9436. {// Party locked.
  9437. clif_displaymessage(fd, msg_txt(227));
  9438. return;
  9439. }
  9440. t_sd = map_id2sd(RFIFOL(fd,2));
  9441. if(t_sd && t_sd->state.noask)
  9442. {// @noask [LuzZza]
  9443. clif_noask_sub(sd, t_sd, 1);
  9444. return;
  9445. }
  9446. party_invite(sd, t_sd);
  9447. }
  9448. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9449. {
  9450. struct map_session_data *t_sd;
  9451. char *name = (char*)RFIFOP(fd,2);
  9452. name[NAME_LENGTH-1] = '\0';
  9453. if(map[sd->bl.m].flag.partylock)
  9454. {// Party locked.
  9455. clif_displaymessage(fd, msg_txt(227));
  9456. return;
  9457. }
  9458. t_sd = map_nick2sd(name);
  9459. if(t_sd && t_sd->state.noask)
  9460. {// @noask [LuzZza]
  9461. clif_noask_sub(sd, t_sd, 1);
  9462. return;
  9463. }
  9464. party_invite(sd, t_sd);
  9465. }
  9466. /// Party invitation reply (CZ_JOIN_GROUP/CZ_PARTY_JOIN_REQ_ACK)
  9467. /// 00ff <party id>.L <flag>.L
  9468. /// 02c7 <party id>.L <flag>.B
  9469. /// flag:
  9470. /// 0 = reject
  9471. /// 1 = accept
  9472. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9473. {
  9474. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9475. }
  9476. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9477. {
  9478. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9479. }
  9480. /*==========================================
  9481. * Client tells server to remove itself from it's party
  9482. *------------------------------------------*/
  9483. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9484. {
  9485. if(map[sd->bl.m].flag.partylock)
  9486. { //Guild locked.
  9487. clif_displaymessage(fd, msg_txt(227));
  9488. return;
  9489. }
  9490. party_leave(sd);
  9491. }
  9492. /*==========================================
  9493. * Client tells server to remove player account id RFIFOL(fd,2) with char name RFIFOP(fd,6) from his party
  9494. *------------------------------------------*/
  9495. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9496. {
  9497. if(map[sd->bl.m].flag.partylock)
  9498. { //Guild locked.
  9499. clif_displaymessage(fd, msg_txt(227));
  9500. return;
  9501. }
  9502. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9503. }
  9504. /*==========================================
  9505. * Client tells server to change it's party configuration
  9506. * - clients before 20090603
  9507. * -- It only may toggle exp sharing
  9508. * - 20090603 or newer
  9509. * -- It may toggle exp (RFIFOW(fd,2) and item sharing options (RFIFOB(fd,6) and RFIFOB(fd,7))
  9510. *------------------------------------------*/
  9511. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9512. {
  9513. struct party_data *p;
  9514. int i;
  9515. if( !sd->status.party_id )
  9516. return;
  9517. p = party_search(sd->status.party_id);
  9518. if( p == NULL )
  9519. return;
  9520. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9521. if( i == MAX_PARTY )
  9522. return; //Shouldn't happen
  9523. if( !p->party.member[i].leader )
  9524. return;
  9525. #if PACKETVER < 20090603
  9526. //Client can't change the item-field
  9527. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9528. #else
  9529. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)+(RFIFOB(fd,7)?2:0)));
  9530. #endif
  9531. }
  9532. /*==========================================
  9533. * Validates and processes party messages
  9534. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  9535. *------------------------------------------*/
  9536. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9537. {
  9538. const char* text = (char*)RFIFOP(fd,4);
  9539. int textlen = RFIFOW(fd,2) - 4;
  9540. char *name, *message;
  9541. int namelen, messagelen;
  9542. // validate packet and retrieve name and message
  9543. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9544. return;
  9545. if( is_atcommand(fd, sd, message, 1) )
  9546. return;
  9547. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9548. return;
  9549. if( battle_config.min_chat_delay )
  9550. { //[Skotlex]
  9551. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9552. return;
  9553. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9554. }
  9555. party_send_message(sd, text, textlen);
  9556. }
  9557. /*==========================================
  9558. * Changes Party Leader
  9559. * S 07da <account ID>.L
  9560. *------------------------------------------*/
  9561. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9562. {
  9563. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9564. }
  9565. /*==========================================
  9566. * Party Booking in KRO [Spiria]
  9567. *------------------------------------------*/
  9568. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9569. {
  9570. short level = RFIFOW(fd,2);
  9571. short mapid = RFIFOW(fd,4);
  9572. short job[PARTY_BOOKING_JOBS];
  9573. int i;
  9574. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9575. job[i] = RFIFOB(fd,6+i*2);
  9576. party_booking_register(sd, level, mapid, job);
  9577. }
  9578. /*==========================================
  9579. * flag: 0 - success, 1 - failed
  9580. *------------------------------------------*/
  9581. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9582. {
  9583. int fd = sd->fd;
  9584. WFIFOHEAD(fd,packet_len(0x803));
  9585. WFIFOW(fd,0) = 0x803;
  9586. WFIFOW(fd,2) = flag;
  9587. WFIFOSET(fd,packet_len(0x803));
  9588. }
  9589. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9590. {
  9591. short level = RFIFOW(fd,2);
  9592. short mapid = RFIFOW(fd,4);
  9593. short job = RFIFOW(fd,6);
  9594. unsigned long lastindex = RFIFOL(fd,8);
  9595. short resultcount = RFIFOB(fd,12);
  9596. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9597. }
  9598. /*==========================================
  9599. * more_result: 0 - no more, 1 - more
  9600. *------------------------------------------*/
  9601. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9602. {
  9603. int i, j;
  9604. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9605. struct party_booking_ad_info *pb_ad;
  9606. WFIFOHEAD(fd,size*count + 5);
  9607. WFIFOW(fd,0) = 0x805;
  9608. WFIFOW(fd,2) = size*count + 5;
  9609. WFIFOB(fd,4) = more_result;
  9610. for(i=0; i<count; i++)
  9611. {
  9612. pb_ad = results[i];
  9613. WFIFOL(fd,i*size+5) = pb_ad->index;
  9614. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9615. WFIFOL(fd,i*size+33) = pb_ad->starttime;
  9616. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9617. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9618. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9619. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9620. }
  9621. WFIFOSET(fd,WFIFOW(fd,2));
  9622. }
  9623. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9624. {
  9625. if(party_booking_delete(sd))
  9626. clif_PartyBookingDeleteAck(sd, 0);
  9627. }
  9628. /*==========================================
  9629. * flag: 0 - success, other - failed
  9630. *------------------------------------------*/
  9631. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9632. {
  9633. int fd = sd->fd;
  9634. WFIFOHEAD(fd,packet_len(0x807));
  9635. WFIFOW(fd,0) = 0x807;
  9636. WFIFOW(fd,2) = flag;
  9637. WFIFOSET(fd,packet_len(0x807));
  9638. }
  9639. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9640. {
  9641. short job[PARTY_BOOKING_JOBS];
  9642. int i;
  9643. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9644. job[i] = RFIFOW(fd,2+i*2);
  9645. party_booking_update(sd, job);
  9646. }
  9647. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9648. {
  9649. int i;
  9650. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9651. if(pb_ad == NULL) return;
  9652. WBUFW(buf,0) = 0x809;
  9653. WBUFL(buf,2) = pb_ad->index;
  9654. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9655. WBUFL(buf,30) = pb_ad->starttime;
  9656. WBUFW(buf,34) = pb_ad->p_detail.level;
  9657. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9658. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9659. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9660. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9661. }
  9662. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9663. {
  9664. int i;
  9665. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9666. if(pb_ad == NULL) return;
  9667. WBUFW(buf,0) = 0x80a;
  9668. WBUFL(buf,2) = pb_ad->index;
  9669. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9670. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9671. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9672. }
  9673. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9674. {
  9675. uint8 buf[6];
  9676. WBUFW(buf,0) = 0x80b;
  9677. WBUFL(buf,2) = index;
  9678. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9679. }
  9680. /*==========================================
  9681. * 露店閉鎖
  9682. *------------------------------------------*/
  9683. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9684. {
  9685. vending_closevending(sd);
  9686. }
  9687. /*==========================================
  9688. * 露店アイテムリスト要求
  9689. *------------------------------------------*/
  9690. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9691. {
  9692. if( sd->npc_id )
  9693. {// using an NPC
  9694. return;
  9695. }
  9696. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9697. }
  9698. /*==========================================
  9699. * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC)
  9700. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  9701. *------------------------------------------*/
  9702. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9703. {
  9704. int len = (int)RFIFOW(fd,2) - 8;
  9705. int id = (int)RFIFOL(fd,4);
  9706. const uint8* data = (uint8*)RFIFOP(fd,8);
  9707. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  9708. // whether it fails or not, the buy window is closed
  9709. sd->vended_id = 0;
  9710. }
  9711. /*==========================================
  9712. * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2)
  9713. * S 0801 <len>.w <AID>.l <UniqueID>.l {<amount>.w <index>.w}.4B*
  9714. *------------------------------------------*/
  9715. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9716. {
  9717. int len = (int)RFIFOW(fd,2) - 12;
  9718. int aid = (int)RFIFOL(fd,4);
  9719. int uid = (int)RFIFOL(fd,8);
  9720. const uint8* data = (uint8*)RFIFOP(fd,12);
  9721. vending_purchasereq(sd, aid, uid, data, len/4);
  9722. // whether it fails or not, the buy window is closed
  9723. sd->vended_id = 0;
  9724. }
  9725. /*==========================================
  9726. * Confirm or cancel the shop preparation window
  9727. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  9728. * flag: 0=cancel, 1=confirm
  9729. *------------------------------------------*/
  9730. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9731. {
  9732. short len = (short)RFIFOW(fd,2) - 85;
  9733. const char* message = (char*)RFIFOP(fd,4);
  9734. bool flag = (bool)RFIFOB(fd,84);
  9735. const uint8* data = (uint8*)RFIFOP(fd,85);
  9736. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9737. return;
  9738. if( map[sd->bl.m].flag.novending ) {
  9739. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9740. return;
  9741. }
  9742. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9743. clif_displaymessage (sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
  9744. return;
  9745. }
  9746. if( message[0] == '\0' ) // invalid input
  9747. return;
  9748. vending_openvending(sd, message, flag, data, len/8);
  9749. }
  9750. /*==========================================
  9751. * Guild creation request
  9752. * S 0165 <account id>.L <guild name>.24S
  9753. *------------------------------------------*/
  9754. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9755. {
  9756. char* name = (char*)RFIFOP(fd,6);
  9757. name[NAME_LENGTH-1] = '\0';
  9758. if(map[sd->bl.m].flag.guildlock)
  9759. { //Guild locked.
  9760. clif_displaymessage(fd, msg_txt(228));
  9761. return;
  9762. }
  9763. guild_create(sd, name);
  9764. }
  9765. /*==========================================
  9766. * ギルドマスターかどうか確認
  9767. *------------------------------------------*/
  9768. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9769. {
  9770. clif_guild_masterormember(sd);
  9771. }
  9772. /*==========================================
  9773. * ギルド情報要求
  9774. *------------------------------------------*/
  9775. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  9776. {
  9777. if( !sd->status.guild_id && !sd->bg_id )
  9778. return;
  9779. switch( RFIFOL(fd,2) )
  9780. {
  9781. case 0: // ギルド基本情報、同盟敵対情報
  9782. clif_guild_basicinfo(sd);
  9783. clif_guild_allianceinfo(sd);
  9784. break;
  9785. case 1: // メンバーリスト、役職名リスト
  9786. clif_guild_positionnamelist(sd);
  9787. clif_guild_memberlist(sd);
  9788. break;
  9789. case 2: // 役職名リスト、役職情報リスト
  9790. clif_guild_positionnamelist(sd);
  9791. clif_guild_positioninfolist(sd);
  9792. break;
  9793. case 3: // スキルリスト
  9794. clif_guild_skillinfo(sd);
  9795. break;
  9796. case 4: // 追放リスト
  9797. clif_guild_expulsionlist(sd);
  9798. break;
  9799. default:
  9800. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9801. break;
  9802. }
  9803. }
  9804. /*==========================================
  9805. * ギルド役職変更
  9806. *------------------------------------------*/
  9807. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  9808. {
  9809. int i;
  9810. if(!sd->state.gmaster_flag)
  9811. return;
  9812. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9813. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9814. }
  9815. }
  9816. /*==========================================
  9817. * ギルドメンバ役職変更
  9818. * S 0155 <packet len>.W {<account id>.L <char id>.L <idx>.L}
  9819. *------------------------------------------*/
  9820. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  9821. {
  9822. int i;
  9823. if(!sd->state.gmaster_flag)
  9824. return;
  9825. for(i=4;i<RFIFOW(fd,2);i+=12){
  9826. guild_change_memberposition(sd->status.guild_id,
  9827. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9828. }
  9829. }
  9830. /*==========================================
  9831. * ギルドエンブレム要求
  9832. *------------------------------------------*/
  9833. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  9834. {
  9835. struct guild* g;
  9836. int guild_id = RFIFOL(fd,2);
  9837. if( (g = guild_search(guild_id)) != NULL )
  9838. clif_guild_emblem(sd,g);
  9839. }
  9840. /// Validates data of a guild emblem (compressed bitmap)
  9841. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  9842. {
  9843. bool success;
  9844. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  9845. unsigned long buf_len = sizeof(buf);
  9846. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  9847. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  9848. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  9849. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  9850. ;
  9851. return success;
  9852. }
  9853. /*==========================================
  9854. * ギルドエンブレム変更
  9855. * S 0153 <packet len>.W <emblem data>.?B
  9856. *------------------------------------------*/
  9857. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  9858. {
  9859. unsigned long emblem_len = RFIFOW(fd,2)-4;
  9860. const uint8* emblem = RFIFOP(fd,4);
  9861. if( !emblem_len || !sd->state.gmaster_flag )
  9862. return;
  9863. if( !clif_validate_emblem(emblem, emblem_len) )
  9864. {
  9865. 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);
  9866. return;
  9867. }
  9868. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  9869. }
  9870. /*==========================================
  9871. * Guild notice update request
  9872. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  9873. *------------------------------------------*/
  9874. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  9875. {
  9876. int guild_id = RFIFOL(fd,2);
  9877. char* msg1 = (char*)RFIFOP(fd,6);
  9878. char* msg2 = (char*)RFIFOP(fd,66);
  9879. if(!sd->state.gmaster_flag)
  9880. return;
  9881. // compensate for some client defects when using multilanguage mode
  9882. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  9883. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  9884. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  9885. guild_change_notice(sd, guild_id, msg1, msg2);
  9886. }
  9887. /*==========================================
  9888. * Client tells server to invite account id RFIFOL(fd,2) to his guild
  9889. *------------------------------------------*/
  9890. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  9891. {
  9892. struct map_session_data *t_sd;
  9893. if(map[sd->bl.m].flag.guildlock)
  9894. { //Guild locked.
  9895. clif_displaymessage(fd, msg_txt(228));
  9896. return;
  9897. }
  9898. t_sd = map_id2sd(RFIFOL(fd,2));
  9899. // @noask [LuzZza]
  9900. if(t_sd && t_sd->state.noask) {
  9901. clif_noask_sub(sd, t_sd, 2);
  9902. return;
  9903. }
  9904. guild_invite(sd,t_sd);
  9905. }
  9906. /*==========================================
  9907. * Client tells server his reply on the request from guild ID RFIFOL(fd,2),
  9908. * - based on RFIFOB(fd,6) which is either 1 (accept) or 0 (reject)
  9909. *------------------------------------------*/
  9910. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  9911. {
  9912. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9913. }
  9914. /*==========================================
  9915. * Client tells server he wants to leave his current guild
  9916. *------------------------------------------*/
  9917. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9918. {
  9919. if(map[sd->bl.m].flag.guildlock)
  9920. { //Guild locked.
  9921. clif_displaymessage(fd, msg_txt(228));
  9922. return;
  9923. }
  9924. if( sd->bg_id )
  9925. {
  9926. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9927. return;
  9928. }
  9929. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9930. }
  9931. /*==========================================
  9932. * Request to expel a member of a guild
  9933. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.40B
  9934. *------------------------------------------*/
  9935. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9936. {
  9937. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  9938. { // Guild locked.
  9939. clif_displaymessage(fd, msg_txt(228));
  9940. return;
  9941. }
  9942. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9943. }
  9944. /*==========================================
  9945. * Validates and processes guild messages
  9946. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  9947. *------------------------------------------*/
  9948. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9949. {
  9950. const char* text = (char*)RFIFOP(fd,4);
  9951. int textlen = RFIFOW(fd,2) - 4;
  9952. char *name, *message;
  9953. int namelen, messagelen;
  9954. // validate packet and retrieve name and message
  9955. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9956. return;
  9957. if( is_atcommand(fd, sd, message, 1) )
  9958. return;
  9959. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9960. return;
  9961. if( battle_config.min_chat_delay )
  9962. { //[Skotlex]
  9963. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9964. return;
  9965. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9966. }
  9967. if( sd->bg_id )
  9968. bg_send_message(sd, text, textlen);
  9969. else
  9970. guild_send_message(sd, text, textlen);
  9971. }
  9972. /*==========================================
  9973. * Client tells server he'd like to send a alliance request to account id RFIFOL(fd,2)
  9974. *------------------------------------------*/
  9975. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9976. {
  9977. struct map_session_data *t_sd;
  9978. if(!sd->state.gmaster_flag)
  9979. return;
  9980. if(map[sd->bl.m].flag.guildlock)
  9981. { //Guild locked.
  9982. clif_displaymessage(fd, msg_txt(228));
  9983. return;
  9984. }
  9985. t_sd = map_id2sd(RFIFOL(fd,2));
  9986. // @noask [LuzZza]
  9987. if(t_sd && t_sd->state.noask) {
  9988. clif_noask_sub(sd, t_sd, 3);
  9989. return;
  9990. }
  9991. guild_reqalliance(sd,t_sd);
  9992. }
  9993. /*==========================================
  9994. * Client tells server his response to the alliance request from,
  9995. * Guild ID RFIFOL(fd,2) based on RFIFOL(fd,6) which is 1 (accepted) or 0 (rejected)
  9996. *------------------------------------------*/
  9997. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9998. {
  9999. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10000. }
  10001. /*==========================================
  10002. * Client tells server he'd like to delete alliance from guild ID RFIFOL(fd,2),
  10003. * RFIFOL(fd,6) returns a 1 or 0 flag but apparently it is no longer used
  10004. *------------------------------------------*/
  10005. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10006. {
  10007. if(!sd->state.gmaster_flag)
  10008. return;
  10009. if(map[sd->bl.m].flag.guildlock)
  10010. { //Guild locked.
  10011. clif_displaymessage(fd, msg_txt(228));
  10012. return;
  10013. }
  10014. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10015. }
  10016. /*==========================================
  10017. * Client tells server he'd like his guild to be set antagonist of account id RFIFOL(fd,2)'s guild
  10018. *------------------------------------------*/
  10019. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10020. {
  10021. struct map_session_data *t_sd;
  10022. if(!sd->state.gmaster_flag)
  10023. return;
  10024. if(map[sd->bl.m].flag.guildlock)
  10025. { //Guild locked.
  10026. clif_displaymessage(fd, msg_txt(228));
  10027. return;
  10028. }
  10029. t_sd = map_id2sd(RFIFOL(fd,2));
  10030. // @noask [LuzZza]
  10031. if(t_sd && t_sd->state.noask) {
  10032. clif_noask_sub(sd, t_sd, 4);
  10033. return;
  10034. }
  10035. guild_opposition(sd,t_sd);
  10036. }
  10037. /*==========================================
  10038. * Client tells server he'd like to break (delete) his own guild
  10039. *------------------------------------------*/
  10040. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10041. {
  10042. if( map[sd->bl.m].flag.guildlock )
  10043. { //Guild locked.
  10044. clif_displaymessage(fd, msg_txt(228));
  10045. return;
  10046. }
  10047. guild_break(sd,(char*)RFIFOP(fd,2));
  10048. }
  10049. // pet
  10050. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10051. {
  10052. pet_menu(sd,RFIFOB(fd,2));
  10053. }
  10054. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10055. {
  10056. pet_catch_process2(sd,RFIFOL(fd,2));
  10057. }
  10058. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10059. {
  10060. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10061. {
  10062. //Forged packet, disconnect them [Kevin]
  10063. clif_authfail_fd(fd, 0);
  10064. return;
  10065. }
  10066. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10067. sd->menuskill_val = sd->menuskill_id = 0;
  10068. }
  10069. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10070. {
  10071. if(sd->pd)
  10072. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10073. }
  10074. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10075. {
  10076. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10077. }
  10078. /*==========================================
  10079. * /kill <account_id>
  10080. * (or right click menu for GM "(name) force to quit")
  10081. * S 00cc <id>.L
  10082. *------------------------------------------*/
  10083. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10084. {
  10085. struct block_list *target;
  10086. int tid,lv;
  10087. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10088. return;
  10089. tid = RFIFOL(fd,2);
  10090. target = map_id2bl(tid);
  10091. if (!target) {
  10092. clif_GM_kickack(sd, 0);
  10093. return;
  10094. }
  10095. switch (target->type) {
  10096. case BL_PC:
  10097. {
  10098. struct map_session_data *tsd = (struct map_session_data *)target;
  10099. if (pc_isGM(sd) <= pc_isGM(tsd))
  10100. {
  10101. clif_GM_kickack(sd, 0);
  10102. return;
  10103. }
  10104. lv = get_atcommand_level(atcommand_kick);
  10105. if( pc_isGM(sd) < lv )
  10106. {
  10107. clif_GM_kickack(sd, 0);
  10108. return;
  10109. }
  10110. if(log_config.gm && lv >= log_config.gm) {
  10111. char message[256];
  10112. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  10113. log_atcommand(sd, message);
  10114. }
  10115. clif_GM_kick(sd, tsd);
  10116. }
  10117. break;
  10118. case BL_MOB:
  10119. {
  10120. lv = get_atcommand_level(atcommand_killmonster);
  10121. if( pc_isGM(sd) < lv )
  10122. {
  10123. clif_GM_kickack(sd, 0);
  10124. return;
  10125. }
  10126. if(log_config.gm && lv >= log_config.gm) {
  10127. char message[256];
  10128. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10129. log_atcommand(sd, message);
  10130. }
  10131. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10132. }
  10133. break;
  10134. case BL_NPC:
  10135. {
  10136. struct npc_data* nd = (struct npc_data *)target;
  10137. lv = get_atcommand_level(atcommand_unloadnpc);
  10138. if( pc_isGM(sd) < lv )
  10139. {
  10140. clif_GM_kickack(sd, 0);
  10141. return;
  10142. }
  10143. if( log_config.gm && lv >= log_config.gm ) {
  10144. char message[256];
  10145. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10146. log_atcommand(sd, message);
  10147. }
  10148. // copy-pasted from atcommand_unloadnpc
  10149. npc_unload_duplicates(nd);
  10150. npc_unload(nd); // invalidates 'target'
  10151. npc_read_event_script();
  10152. }
  10153. break;
  10154. default:
  10155. clif_GM_kickack(sd, 0);
  10156. }
  10157. }
  10158. /*==========================================
  10159. * /killall
  10160. *------------------------------------------*/
  10161. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  10162. {
  10163. is_atcommand(fd, sd, "@kickall", 1);
  10164. }
  10165. /*==========================================
  10166. * /remove <account name>
  10167. * /shift <char name>
  10168. *------------------------------------------*/
  10169. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10170. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10171. char *player_name;
  10172. int lv;
  10173. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10174. return;
  10175. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  10176. return;
  10177. player_name = (char*)RFIFOP(fd,2);
  10178. player_name[NAME_LENGTH-1] = '\0';
  10179. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  10180. if( log_config.gm && lv >= log_config.gm ) {
  10181. char message[NAME_LENGTH+7];
  10182. sprintf(message, "/shift %s", player_name);
  10183. log_atcommand(sd, message);
  10184. }
  10185. }
  10186. /// Warps oneself to the location of the character given by account id ( /remove <account id> ).
  10187. /// R 0843 <account id>.L
  10188. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10189. {
  10190. int account_id, lv;
  10191. struct map_session_data* pl_sd;
  10192. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10193. {
  10194. return;
  10195. }
  10196. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_jumpto) ) )
  10197. {
  10198. return;
  10199. }
  10200. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10201. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  10202. {
  10203. pc_warpto(sd, pl_sd);
  10204. }
  10205. if( log_config.gm && lv >= log_config.gm )
  10206. {
  10207. char message[32];
  10208. sprintf(message, "/remove %d", account_id);
  10209. log_atcommand(sd, message);
  10210. }
  10211. }
  10212. /*==========================================
  10213. * /recall <account name>
  10214. * /summon <char name>
  10215. *------------------------------------------*/
  10216. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10217. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10218. char *player_name;
  10219. int lv;
  10220. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10221. return;
  10222. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  10223. return;
  10224. player_name = (char*)RFIFOP(fd,2);
  10225. player_name[NAME_LENGTH-1] = '\0';
  10226. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  10227. if( log_config.gm && lv >= log_config.gm ) {
  10228. char message[NAME_LENGTH+8];
  10229. sprintf(message, "/recall %s", player_name);
  10230. log_atcommand(sd, message);
  10231. }
  10232. }
  10233. /// Summons a character given by account id to one's own position ( /recall <account id> )
  10234. /// R 0842 <account id>.L
  10235. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10236. {
  10237. int account_id, lv;
  10238. struct map_session_data* pl_sd;
  10239. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10240. {
  10241. return;
  10242. }
  10243. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_recall) ) )
  10244. {
  10245. return;
  10246. }
  10247. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10248. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  10249. {
  10250. pc_recall(sd, pl_sd);
  10251. }
  10252. if( log_config.gm && lv >= log_config.gm )
  10253. {
  10254. char message[32];
  10255. sprintf(message, "/recall %d", account_id);
  10256. log_atcommand(sd, message);
  10257. }
  10258. }
  10259. /*==========================================
  10260. * /monster /item
  10261. * R 01F3 <name>.24B
  10262. *------------------------------------------*/
  10263. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10264. {
  10265. char *monster_item_name;
  10266. char message[NAME_LENGTH+10]; //For logging.
  10267. int level;
  10268. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10269. return;
  10270. monster_item_name = (char*)RFIFOP(fd,2);
  10271. monster_item_name[NAME_LENGTH-1] = '\0';
  10272. if( mobdb_searchname(monster_item_name) ) {
  10273. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  10274. return;
  10275. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  10276. if( log_config.gm && level >= log_config.gm )
  10277. { //Log action. [Skotlex]
  10278. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  10279. log_atcommand(sd, message);
  10280. }
  10281. return;
  10282. }
  10283. if( itemdb_searchname(monster_item_name) == NULL )
  10284. return;
  10285. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  10286. return;
  10287. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  10288. if( log_config.gm && level >= log_config.gm )
  10289. { //Log action. [Skotlex]
  10290. sprintf(message, "@item %s", monster_item_name);
  10291. log_atcommand(sd, message);
  10292. }
  10293. }
  10294. /*==========================================
  10295. * /hide
  10296. *------------------------------------------*/
  10297. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  10298. {
  10299. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10300. return;
  10301. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  10302. return;
  10303. if( sd->sc.option & OPTION_INVISIBLE ) {
  10304. sd->sc.option &= ~OPTION_INVISIBLE;
  10305. if (sd->disguise)
  10306. status_set_viewdata(&sd->bl, sd->disguise);
  10307. else
  10308. status_set_viewdata(&sd->bl, sd->status.class_);
  10309. clif_displaymessage(fd, "Invisible: Off.");
  10310. } else {
  10311. sd->sc.option |= OPTION_INVISIBLE;
  10312. sd->vd.class_ = INVISIBLE_CLASS;
  10313. clif_displaymessage(fd, "Invisible: On.");
  10314. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  10315. log_atcommand(sd, "/hide");
  10316. }
  10317. clif_changeoption(&sd->bl);
  10318. }
  10319. /*==========================================
  10320. * GM adjustment of a player's manner value (right-click GM menu)
  10321. * S 0149 <id>.L <type>.B <value>.W
  10322. * type: 0 - positive points
  10323. * 1 - negative points
  10324. * 2 - self mute (+10 minutes)
  10325. *------------------------------------------*/
  10326. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10327. {
  10328. int id, type, value, level;
  10329. struct map_session_data *dstsd;
  10330. id = RFIFOL(fd,2);
  10331. type = RFIFOB(fd,6);
  10332. value = RFIFOW(fd,7);
  10333. if( type == 0 )
  10334. value = 0 - value;
  10335. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10336. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10337. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  10338. return;
  10339. dstsd = map_id2sd(id);
  10340. if( dstsd == NULL )
  10341. return;
  10342. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  10343. {
  10344. clif_manner_message(sd, 0);
  10345. clif_manner_message(dstsd, 5);
  10346. if( dstsd->status.manner < value ) {
  10347. dstsd->status.manner -= value;
  10348. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10349. } else {
  10350. dstsd->status.manner = 0;
  10351. status_change_end(&dstsd->bl, SC_NOCHAT, INVALID_TIMER);
  10352. }
  10353. if( type != 2 )
  10354. clif_GM_silence(sd, dstsd, type);
  10355. }
  10356. }
  10357. /*==========================================
  10358. * GM adjustment of a player's manner value by -60 (using name)
  10359. * /rc <name>
  10360. * S 0212 <name>.24B
  10361. *------------------------------------------*/
  10362. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10363. {
  10364. char* name = (char*)RFIFOP(fd,2);
  10365. struct map_session_data* dstsd;
  10366. name[23] = '\0';
  10367. dstsd = map_nick2sd(name);
  10368. if( dstsd == NULL )
  10369. return;
  10370. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  10371. {
  10372. clif_manner_message(sd, 0);
  10373. clif_manner_message(dstsd, 3);
  10374. dstsd->status.manner -= 60;
  10375. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10376. clif_GM_silence(sd, dstsd, 1);
  10377. }
  10378. }
  10379. /*==========================================
  10380. * GM requesting account name (for right-click gm menu)
  10381. * S 01df <id>.L
  10382. * R 01e0 <id>.L <name>.24B
  10383. *------------------------------------------*/
  10384. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10385. {
  10386. int tid;
  10387. tid = RFIFOL(fd,2);
  10388. //TODO: find out if this works for any player or only for authorized GMs
  10389. WFIFOHEAD(fd,packet_len(0x1e0));
  10390. WFIFOW(fd,0) = 0x1e0;
  10391. WFIFOL(fd,2) = tid;
  10392. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10393. WFIFOSET(fd, packet_len(0x1e0));
  10394. }
  10395. /*==========================================
  10396. * GM single cell type change request
  10397. * /changemaptype <x> <y> <type:0-1>
  10398. * S 0198 <x>.W <y>.W <gat>.W
  10399. *------------------------------------------*/
  10400. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10401. {
  10402. int x,y,type;
  10403. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10404. return;
  10405. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  10406. return;
  10407. x = RFIFOW(fd,2);
  10408. y = RFIFOW(fd,4);
  10409. type = RFIFOW(fd,6);
  10410. map_setgatcell(sd->bl.m,x,y,type);
  10411. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10412. //FIXME: once players leave the map, the client 'forgets' this information.
  10413. }
  10414. /// S 00cf <nick>.24B <type>.B
  10415. /// type: 0 (/ex nick) deny speech from nick
  10416. /// 1 (/in nick) allow speech from nick
  10417. ///
  10418. /// R 00d1 <type>.B <result>.B
  10419. /// type: 0: deny, 1: allow
  10420. /// result: 0: success, 1: fail 2: list full
  10421. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10422. {
  10423. char output[512];
  10424. char* nick;
  10425. uint8 type;
  10426. int i;
  10427. nick = (char*)RFIFOP(fd,2); // speed up
  10428. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10429. type = RFIFOB(fd,26);
  10430. WFIFOHEAD(fd,packet_len(0xd1));
  10431. WFIFOW(fd,0) = 0x0d1;
  10432. WFIFOB(fd,2) = type;
  10433. if( type == 0 )
  10434. { // Add name to ignore list (block)
  10435. // Bot-check...
  10436. if (strcmp(wisp_server_name, nick) == 0)
  10437. { // to find possible bot users who automaticaly ignore people
  10438. sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  10439. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  10440. WFIFOB(fd,3) = 1; // fail
  10441. WFIFOSET(fd, packet_len(0x0d1));
  10442. return;
  10443. }
  10444. // try to find a free spot, while checking for duplicates at the same time
  10445. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10446. if( i == MAX_IGNORE_LIST )
  10447. {// no space for new entry
  10448. WFIFOB(fd,3) = 2; // fail
  10449. WFIFOSET(fd, packet_len(0x0d1));
  10450. return;
  10451. }
  10452. if( sd->ignore[i].name[0] != '\0' )
  10453. {// name already exists
  10454. WFIFOB(fd,3) = 0; // Aegis reports success.
  10455. WFIFOSET(fd, packet_len(0x0d1));
  10456. return;
  10457. }
  10458. //Insert in position i
  10459. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10460. WFIFOB(fd,3) = 0; // success
  10461. WFIFOSET(fd, packet_len(0x0d1));
  10462. }
  10463. else
  10464. { // Remove name from ignore list (unblock)
  10465. // find entry
  10466. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10467. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10468. { //Not found
  10469. WFIFOB(fd,3) = 1; // fail
  10470. WFIFOSET(fd, packet_len(0x0d1));
  10471. return;
  10472. }
  10473. // move everything one place down to overwrite removed entry
  10474. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10475. // wipe last entry
  10476. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10477. WFIFOB(fd,3) = 0; // success
  10478. WFIFOSET(fd, packet_len(0x0d1));
  10479. }
  10480. return;
  10481. }
  10482. /// S 00d0 <type>.B
  10483. /// type: 0 (/exall) deny all speech
  10484. /// 1 (/inall) allow all speech
  10485. ///
  10486. /// R 00d2 <type>.B <fail>.B
  10487. /// type: 0: deny, 1: allow
  10488. /// fail: 0: success, 1: fail
  10489. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10490. {
  10491. WFIFOHEAD(fd,packet_len(0xd2));
  10492. WFIFOW(fd,0) = 0x0d2;
  10493. WFIFOB(fd,2) = RFIFOB(fd,2);
  10494. if( RFIFOB(fd,2) == 0 )
  10495. {// Deny all
  10496. if( sd->state.ignoreAll ) {
  10497. WFIFOB(fd,3) = 1; // fail
  10498. } else {
  10499. sd->state.ignoreAll = 1;
  10500. WFIFOB(fd,3) = 0; // success
  10501. }
  10502. }
  10503. else
  10504. {//Unblock everyone
  10505. if( sd->state.ignoreAll ) {
  10506. sd->state.ignoreAll = 0;
  10507. WFIFOB(fd,3) = 0; // success
  10508. } else {
  10509. if (sd->ignore[0].name[0] != '\0')
  10510. { //Wipe the ignore list.
  10511. memset(sd->ignore, 0, sizeof(sd->ignore));
  10512. WFIFOB(fd,3) = 0; // success
  10513. } else {
  10514. WFIFOB(fd,3) = 1; // fail
  10515. }
  10516. }
  10517. }
  10518. WFIFOSET(fd, packet_len(0x0d2));
  10519. return;
  10520. }
  10521. /*==========================================
  10522. * Client tells server he'd like the server to list him his ignore list
  10523. *------------------------------------------*/
  10524. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10525. {
  10526. int i;
  10527. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10528. WFIFOW(fd,0) = 0xd4;
  10529. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10530. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10531. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10532. WFIFOSET(fd, WFIFOW(fd,2));
  10533. return;
  10534. }
  10535. /*==========================================
  10536. * Client tells server he did a /doridori
  10537. *------------------------------------------*/
  10538. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10539. {
  10540. if (sd->state.doridori) return;
  10541. switch (sd->class_&MAPID_UPPERMASK)
  10542. {
  10543. case MAPID_SOUL_LINKER:
  10544. case MAPID_STAR_GLADIATOR:
  10545. case MAPID_TAEKWON:
  10546. if (!sd->state.rest)
  10547. break;
  10548. case MAPID_SUPER_NOVICE:
  10549. sd->state.doridori=1;
  10550. break;
  10551. }
  10552. return;
  10553. }
  10554. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI)
  10555. /// 01ed
  10556. /// Note: This packet is caused by 7 lines of any text, followed by
  10557. /// the prayer and an another line of any text. The prayer is
  10558. /// defined by lines 791~794 in data\msgstringtable.txt
  10559. /// "Dear angel, can you hear my voice?"
  10560. /// "I am" (space separated player name) "Super Novice~"
  10561. /// "Help me out~ Please~ T_T"
  10562. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10563. {
  10564. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10565. {
  10566. unsigned int next = pc_nextbaseexp(sd);
  10567. if( next == 0 ) next = pc_thisbaseexp(sd);
  10568. if( next )
  10569. {
  10570. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10571. if( percent && ( percent%100 ) == 0 )
  10572. {// 10.0%, 20.0%, ..., 90.0%
  10573. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10574. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10575. }
  10576. }
  10577. }
  10578. }
  10579. /*==========================================
  10580. * Friends List
  10581. *------------------------------------------*/
  10582. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10583. { //Toggles a single friend online/offline [Skotlex]
  10584. int i, fd = sd->fd;
  10585. //Seek friend.
  10586. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10587. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10588. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10589. return; //Not found
  10590. WFIFOHEAD(fd,packet_len(0x206));
  10591. WFIFOW(fd, 0) = 0x206;
  10592. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10593. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10594. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10595. WFIFOSET(fd, packet_len(0x206));
  10596. }
  10597. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10598. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10599. {
  10600. int account_id, char_id, online;
  10601. account_id = va_arg(ap, int);
  10602. char_id = va_arg(ap, int);
  10603. online = va_arg(ap, int);
  10604. clif_friendslist_toggle(sd, account_id, char_id, online);
  10605. return 0;
  10606. }
  10607. //For sending the whole friends list.
  10608. void clif_friendslist_send(struct map_session_data *sd)
  10609. {
  10610. int i = 0, n, fd = sd->fd;
  10611. // Send friends list
  10612. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10613. WFIFOW(fd, 0) = 0x201;
  10614. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10615. {
  10616. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10617. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10618. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10619. }
  10620. if (i) {
  10621. WFIFOW(fd,2) = 4 + 32 * i;
  10622. WFIFOSET(fd, WFIFOW(fd,2));
  10623. }
  10624. for (n = 0; n < i; n++)
  10625. { //Sending the online players
  10626. if (map_charid2sd(sd->status.friends[n].char_id))
  10627. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10628. }
  10629. }
  10630. /// Reply for add friend request: (success => type 0)
  10631. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  10632. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  10633. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  10634. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  10635. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10636. {
  10637. int fd;
  10638. nullpo_retv(sd);
  10639. fd = sd->fd;
  10640. WFIFOHEAD(fd,packet_len(0x209));
  10641. WFIFOW(fd,0) = 0x209;
  10642. WFIFOW(fd,2) = type;
  10643. if (f_sd)
  10644. {
  10645. WFIFOL(fd,4) = f_sd->status.account_id;
  10646. WFIFOL(fd,8) = f_sd->status.char_id;
  10647. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10648. }
  10649. WFIFOSET(fd, packet_len(0x209));
  10650. }
  10651. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10652. {
  10653. struct map_session_data *f_sd;
  10654. int i, f_fd;
  10655. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10656. // Friend doesn't exist (no player with this name)
  10657. if (f_sd == NULL) {
  10658. clif_displaymessage(fd, msg_txt(3));
  10659. return;
  10660. }
  10661. if( sd->bl.id == f_sd->bl.id )
  10662. {// adding oneself as friend
  10663. return;
  10664. }
  10665. // @noask [LuzZza]
  10666. if(f_sd->state.noask) {
  10667. clif_noask_sub(sd, f_sd, 5);
  10668. return;
  10669. }
  10670. // Friend already exists
  10671. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10672. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10673. clif_displaymessage(fd, "Friend already exists.");
  10674. return;
  10675. }
  10676. }
  10677. if (i == MAX_FRIENDS) {
  10678. //No space, list full.
  10679. clif_friendslist_reqack(sd, f_sd, 2);
  10680. return;
  10681. }
  10682. f_fd = f_sd->fd;
  10683. WFIFOHEAD(f_fd,packet_len(0x207));
  10684. WFIFOW(f_fd,0) = 0x207;
  10685. WFIFOL(f_fd,2) = sd->status.account_id;
  10686. WFIFOL(f_fd,6) = sd->status.char_id;
  10687. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10688. WFIFOSET(f_fd, packet_len(0x207));
  10689. return;
  10690. }
  10691. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10692. {
  10693. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  10694. struct map_session_data *f_sd;
  10695. int char_id, account_id;
  10696. char reply;
  10697. account_id = RFIFOL(fd,2);
  10698. char_id = RFIFOL(fd,6);
  10699. reply = RFIFOB(fd,10);
  10700. if( sd->bl.id == account_id )
  10701. {// adding oneself as friend
  10702. return;
  10703. }
  10704. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10705. if (f_sd == NULL)
  10706. return;
  10707. if (reply == 0)
  10708. clif_friendslist_reqack(f_sd, sd, 1);
  10709. else {
  10710. int i;
  10711. // Find an empty slot
  10712. for (i = 0; i < MAX_FRIENDS; i++)
  10713. if (f_sd->status.friends[i].char_id == 0)
  10714. break;
  10715. if (i == MAX_FRIENDS) {
  10716. clif_friendslist_reqack(f_sd, sd, 2);
  10717. return;
  10718. }
  10719. f_sd->status.friends[i].account_id = sd->status.account_id;
  10720. f_sd->status.friends[i].char_id = sd->status.char_id;
  10721. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10722. clif_friendslist_reqack(f_sd, sd, 0);
  10723. if (battle_config.friend_auto_add) {
  10724. // Also add f_sd to sd's friendlist.
  10725. for (i = 0; i < MAX_FRIENDS; i++) {
  10726. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10727. return; //No need to add anything.
  10728. if (sd->status.friends[i].char_id == 0)
  10729. break;
  10730. }
  10731. if (i == MAX_FRIENDS) {
  10732. clif_friendslist_reqack(sd, f_sd, 2);
  10733. return;
  10734. }
  10735. sd->status.friends[i].account_id = f_sd->status.account_id;
  10736. sd->status.friends[i].char_id = f_sd->status.char_id;
  10737. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10738. clif_friendslist_reqack(sd, f_sd, 0);
  10739. }
  10740. }
  10741. return;
  10742. }
  10743. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10744. {
  10745. // 0x203 </o> <ID to be removed W 4B>
  10746. int account_id, char_id;
  10747. int i, j;
  10748. account_id = RFIFOL(fd,2);
  10749. char_id = RFIFOL(fd,6);
  10750. // Search friend
  10751. for (i = 0; i < MAX_FRIENDS &&
  10752. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10753. if (i == MAX_FRIENDS) {
  10754. clif_displaymessage(fd, "Name not found in list.");
  10755. return;
  10756. }
  10757. // move all chars down
  10758. for(j = i + 1; j < MAX_FRIENDS; j++)
  10759. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10760. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10761. clif_displaymessage(fd, "Friend removed");
  10762. WFIFOHEAD(fd,packet_len(0x20a));
  10763. WFIFOW(fd,0) = 0x20a;
  10764. WFIFOL(fd,2) = account_id;
  10765. WFIFOL(fd,6) = char_id;
  10766. WFIFOSET(fd, packet_len(0x20a));
  10767. // clif_friendslist_send(sd); //This is not needed anymore.
  10768. return;
  10769. }
  10770. /*==========================================
  10771. * /pvpinfo (CZ_REQ_PVPPOINT & ZC_ACK_PVPPOINT)
  10772. * R 020f <char id>.L <account id>.L
  10773. * S 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  10774. *------------------------------------------*/
  10775. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10776. {
  10777. WFIFOHEAD(fd,packet_len(0x210));
  10778. WFIFOW(fd,0) = 0x210;
  10779. WFIFOL(fd,2) = sd->status.char_id;
  10780. WFIFOL(fd,6) = sd->status.account_id;
  10781. WFIFOL(fd,10) = sd->pvp_won; // times won
  10782. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10783. WFIFOL(fd,18) = sd->pvp_point;
  10784. WFIFOSET(fd, packet_len(0x210));
  10785. }
  10786. /*==========================================
  10787. * /blacksmith
  10788. * S 0217
  10789. *------------------------------------------*/
  10790. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10791. {
  10792. int i;
  10793. const char* name;
  10794. WFIFOHEAD(fd,packet_len(0x219));
  10795. WFIFOW(fd,0) = 0x219;
  10796. //Packet size limits this list to 10 elements. [Skotlex]
  10797. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10798. if (smith_fame_list[i].id > 0) {
  10799. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10800. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10801. {
  10802. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10803. } else
  10804. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10805. } else
  10806. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10807. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10808. }
  10809. for(;i < 10; i++) { //In case the MAX is less than 10.
  10810. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10811. WFIFOL(fd, 242 + i * 4) = 0;
  10812. }
  10813. WFIFOSET(fd, packet_len(0x219));
  10814. }
  10815. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10816. {
  10817. int fd = sd->fd;
  10818. WFIFOHEAD(fd,packet_len(0x21b));
  10819. WFIFOW(fd,0) = 0x21b;
  10820. WFIFOL(fd,2) = points;
  10821. WFIFOL(fd,6) = sd->status.fame;
  10822. WFIFOSET(fd, packet_len(0x21b));
  10823. return 0;
  10824. }
  10825. /*==========================================
  10826. * /alchemist
  10827. * S 0218
  10828. *------------------------------------------*/
  10829. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10830. {
  10831. int i;
  10832. const char* name;
  10833. WFIFOHEAD(fd,packet_len(0x21a));
  10834. WFIFOW(fd,0) = 0x21a;
  10835. //Packet size limits this list to 10 elements. [Skotlex]
  10836. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10837. if (chemist_fame_list[i].id > 0) {
  10838. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10839. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10840. {
  10841. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10842. } else
  10843. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10844. } else
  10845. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10846. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10847. }
  10848. for(;i < 10; i++) { //In case the MAX is less than 10.
  10849. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10850. WFIFOL(fd, 242 + i * 4) = 0;
  10851. }
  10852. WFIFOSET(fd, packet_len(0x21a));
  10853. }
  10854. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10855. {
  10856. int fd = sd->fd;
  10857. WFIFOHEAD(fd,packet_len(0x21c));
  10858. WFIFOW(fd,0) = 0x21c;
  10859. WFIFOL(fd,2) = points;
  10860. WFIFOL(fd,6) = sd->status.fame;
  10861. WFIFOSET(fd, packet_len(0x21c));
  10862. return 0;
  10863. }
  10864. /*==========================================
  10865. * /taekwon
  10866. * S 0225
  10867. *------------------------------------------*/
  10868. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10869. {
  10870. int i;
  10871. const char* name;
  10872. WFIFOHEAD(fd,packet_len(0x226));
  10873. WFIFOW(fd,0) = 0x226;
  10874. //Packet size limits this list to 10 elements. [Skotlex]
  10875. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10876. if (taekwon_fame_list[i].id > 0) {
  10877. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10878. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10879. {
  10880. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10881. } else
  10882. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10883. } else
  10884. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10885. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10886. }
  10887. for(;i < 10; i++) { //In case the MAX is less than 10.
  10888. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10889. WFIFOL(fd, 242 + i * 4) = 0;
  10890. }
  10891. WFIFOSET(fd, packet_len(0x226));
  10892. }
  10893. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10894. {
  10895. int fd = sd->fd;
  10896. WFIFOHEAD(fd,packet_len(0x224));
  10897. WFIFOW(fd,0) = 0x224;
  10898. WFIFOL(fd,2) = points;
  10899. WFIFOL(fd,6) = sd->status.fame;
  10900. WFIFOSET(fd, packet_len(0x224));
  10901. return 0;
  10902. }
  10903. /*==========================================
  10904. * /pk
  10905. * S 0237
  10906. *------------------------------------------*/
  10907. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10908. {
  10909. int i;
  10910. WFIFOHEAD(fd,packet_len(0x238));
  10911. WFIFOW(fd,0) = 0x238;
  10912. for(i=0;i<10;i++){
  10913. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10914. WFIFOL(fd,i*4+242) = 0;
  10915. }
  10916. WFIFOSET(fd, packet_len(0x238));
  10917. return;
  10918. }
  10919. /*==========================================
  10920. * SG Feel save OK [Komurka]
  10921. *------------------------------------------*/
  10922. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10923. {
  10924. int i;
  10925. if (sd->menuskill_id != SG_FEEL)
  10926. return;
  10927. i = sd->menuskill_val-1;
  10928. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  10929. sd->feel_map[i].index = map_id2index(sd->bl.m);
  10930. sd->feel_map[i].m = sd->bl.m;
  10931. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  10932. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10933. // clif_misceffect2(&sd->bl, 0x1b0);
  10934. // clif_misceffect2(&sd->bl, 0x21f);
  10935. clif_feel_info(sd, i, 0);
  10936. sd->menuskill_val = sd->menuskill_id = 0;
  10937. }
  10938. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE)
  10939. void clif_feel_req(int fd, struct map_session_data *sd, int skilllv)
  10940. {
  10941. WFIFOHEAD(fd,packet_len(0x253));
  10942. WFIFOW(fd,0)=0x253;
  10943. WFIFOSET(fd, packet_len(0x253));
  10944. sd->menuskill_id = SG_FEEL;
  10945. sd->menuskill_val = skilllv;
  10946. }
  10947. /*==========================================
  10948. * Homunculus packets
  10949. *------------------------------------------*/
  10950. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  10951. {
  10952. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  10953. }
  10954. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  10955. {
  10956. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10957. struct block_list *bl = NULL;
  10958. struct unit_data *ud = NULL;
  10959. if( sd->md && sd->md->bl.id == id )
  10960. bl = &sd->md->bl;
  10961. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10962. bl = &sd->hd->bl; // Moving Homunculus
  10963. else return;
  10964. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  10965. ud = unit_bl2ud(bl);
  10966. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  10967. }
  10968. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  10969. {
  10970. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10971. struct block_list *bl = NULL;
  10972. short x, y, cmd;
  10973. cmd = RFIFOW(fd,0);
  10974. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10975. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  10976. if( sd->md && sd->md->bl.id == id )
  10977. bl = &sd->md->bl; // Moving Mercenary
  10978. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10979. bl = &sd->hd->bl; // Moving Homunculus
  10980. else return;
  10981. unit_walktoxy(bl, x, y, 4);
  10982. }
  10983. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  10984. {
  10985. struct block_list *bl = NULL;
  10986. int id = RFIFOL(fd,2),
  10987. target_id = RFIFOL(fd,6),
  10988. action_type = RFIFOB(fd,10);
  10989. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10990. bl = &sd->hd->bl;
  10991. else if( sd->md && sd->md->bl.id == id )
  10992. bl = &sd->md->bl;
  10993. else return;
  10994. unit_stop_attack(bl);
  10995. unit_attack(bl, target_id, action_type != 0);
  10996. }
  10997. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  10998. { //[orn]
  10999. int cmd;
  11000. cmd = RFIFOW(fd,0);
  11001. if(!merc_is_hom_active(sd->hd))
  11002. return;
  11003. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  11004. }
  11005. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11006. {
  11007. int item_position = pc_search_inventory(sd, 7621);
  11008. if (item_position < 0)
  11009. return;
  11010. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11011. return;
  11012. if (!status_revive(&sd->bl, 100, 100))
  11013. return;
  11014. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11015. pc_delitem(sd, item_position, 1, 0, 1);
  11016. }
  11017. /// Information about character's status values (ZC_ACK_STATUS_GM)
  11018. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11019. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11020. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11021. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11022. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11023. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11024. void clif_check(int fd, struct map_session_data* pl_sd)
  11025. {
  11026. WFIFOHEAD(fd,packet_len(0x214));
  11027. WFIFOW(fd, 0) = 0x214;
  11028. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11029. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11030. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11031. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11032. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11033. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11034. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11035. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11036. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11037. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11038. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11039. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11040. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11041. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11042. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11043. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11044. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11045. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11046. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11047. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11048. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11049. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11050. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11051. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11052. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11053. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be?
  11054. WFIFOSET(fd,packet_len(0x214));
  11055. }
  11056. /// Request character's status values (CZ_REQ_STATUS_GM)
  11057. /// /check <char name>
  11058. /// 0213 <char name>.24B
  11059. void clif_parse_Check(int fd, struct map_session_data *sd)
  11060. {
  11061. char charname[NAME_LENGTH];
  11062. struct map_session_data* pl_sd;
  11063. if( pc_isGM(sd) < battle_config.gm_check_minlevel )
  11064. {
  11065. return;
  11066. }
  11067. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11068. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_isGM(sd) < pc_isGM(pl_sd) )
  11069. {
  11070. return;
  11071. }
  11072. clif_check(fd, pl_sd);
  11073. }
  11074. #ifndef TXT_ONLY
  11075. /*==========================================
  11076. * MAIL SYSTEM
  11077. * By Zephyrus
  11078. *==========================================*/
  11079. /*------------------------------------------
  11080. * Reply to Set Attachment operation
  11081. * 0 : Successfully attached item to mail
  11082. * 1 : Fail to set the attachment
  11083. *------------------------------------------*/
  11084. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11085. {
  11086. WFIFOHEAD(fd,packet_len(0x255));
  11087. WFIFOW(fd,0) = 0x255;
  11088. WFIFOW(fd,2) = index;
  11089. WFIFOB(fd,4) = flag;
  11090. WFIFOSET(fd,packet_len(0x255));
  11091. }
  11092. /*------------------------------------------
  11093. * Reply to Get Attachment operation
  11094. * 0 : Successfully added attachment to Inventory
  11095. * 1 : Fail to set the item to inventory
  11096. * 2 : Weight problems
  11097. *------------------------------------------*/
  11098. void clif_Mail_getattachment(int fd, uint8 flag)
  11099. {
  11100. WFIFOHEAD(fd,packet_len(0x245));
  11101. WFIFOW(fd,0) = 0x245;
  11102. WFIFOB(fd,2) = flag;
  11103. WFIFOSET(fd,packet_len(0x245));
  11104. }
  11105. /*------------------------------------------
  11106. * Send Mail ack
  11107. * 0 : Message Send Ok
  11108. * 1 : Recipient does not exist
  11109. *------------------------------------------*/
  11110. void clif_Mail_send(int fd, bool fail)
  11111. {
  11112. WFIFOHEAD(fd,packet_len(0x249));
  11113. WFIFOW(fd,0) = 0x249;
  11114. WFIFOB(fd,2) = fail;
  11115. WFIFOSET(fd,packet_len(0x249));
  11116. }
  11117. /*------------------------------------------
  11118. * Delete Mail ack
  11119. * 0 : Delete ok
  11120. * 1 : Delete failed
  11121. *------------------------------------------*/
  11122. void clif_Mail_delete(int fd, int mail_id, short fail)
  11123. {
  11124. WFIFOHEAD(fd, packet_len(0x257));
  11125. WFIFOW(fd,0) = 0x257;
  11126. WFIFOL(fd,2) = mail_id;
  11127. WFIFOW(fd,6) = fail;
  11128. WFIFOSET(fd, packet_len(0x257));
  11129. }
  11130. /*------------------------------------------
  11131. * Return Mail ack
  11132. * 0 : Mail returned to the sender
  11133. * 1 : The mail does not exist
  11134. *------------------------------------------*/
  11135. void clif_Mail_return(int fd, int mail_id, short fail)
  11136. {
  11137. WFIFOHEAD(fd,packet_len(0x274));
  11138. WFIFOW(fd,0) = 0x274;
  11139. WFIFOL(fd,2) = mail_id;
  11140. WFIFOW(fd,6) = fail;
  11141. WFIFOSET(fd,packet_len(0x274));
  11142. }
  11143. /*------------------------------------------
  11144. * You have New Mail
  11145. *------------------------------------------*/
  11146. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11147. {
  11148. WFIFOHEAD(fd,packet_len(0x24a));
  11149. WFIFOW(fd,0) = 0x24a;
  11150. WFIFOL(fd,2) = mail_id;
  11151. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  11152. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  11153. WFIFOSET(fd,packet_len(0x24a));
  11154. }
  11155. /*------------------------------------------
  11156. * Handles Mail Window on Client
  11157. * flag : 0 open | 1 close
  11158. *------------------------------------------*/
  11159. void clif_Mail_window(int fd, int flag)
  11160. {
  11161. WFIFOHEAD(fd,packet_len(0x260));
  11162. WFIFOW(fd,0) = 0x260;
  11163. WFIFOL(fd,2) = flag;
  11164. WFIFOSET(fd,packet_len(0x260));
  11165. }
  11166. /*------------------------------------------
  11167. * Send Inbox Data to Client
  11168. *------------------------------------------*/
  11169. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11170. {
  11171. int fd = sd->fd;
  11172. struct mail_data *md = &sd->mail.inbox;
  11173. struct mail_message *msg;
  11174. int len, i, j;
  11175. len = 8 + (73 * md->amount);
  11176. WFIFOHEAD(fd,len);
  11177. WFIFOW(fd,0) = 0x240;
  11178. WFIFOW(fd,2) = len;
  11179. WFIFOL(fd,4) = md->amount;
  11180. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11181. {
  11182. msg = &md->msg[i];
  11183. if (msg->id < 1)
  11184. continue;
  11185. WFIFOL(fd,8+73*j) = msg->id;
  11186. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11187. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  11188. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11189. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11190. j++;
  11191. }
  11192. WFIFOSET(fd,len);
  11193. if( md->full )
  11194. {
  11195. char output[100];
  11196. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11197. clif_disp_onlyself(sd, output, strlen(output));
  11198. }
  11199. }
  11200. /*------------------------------------------
  11201. * Client Request Inbox List
  11202. *------------------------------------------*/
  11203. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11204. {
  11205. struct mail_data* md = &sd->mail.inbox;
  11206. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11207. intif_Mail_requestinbox(sd->status.char_id, 1);
  11208. else
  11209. clif_Mail_refreshinbox(sd);
  11210. mail_removeitem(sd, 0);
  11211. mail_removezeny(sd, 0);
  11212. }
  11213. /*------------------------------------------
  11214. * Read Message
  11215. *------------------------------------------*/
  11216. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11217. {
  11218. int i, fd = sd->fd;
  11219. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11220. if( i == MAIL_MAX_INBOX )
  11221. {
  11222. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11223. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11224. return;
  11225. }
  11226. else
  11227. {
  11228. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11229. struct item *item = &msg->item;
  11230. struct item_data *data;
  11231. int msg_len = strlen(msg->body), len;
  11232. if( msg_len == 0 ) {
  11233. strcpy(msg->body, "(no message)");
  11234. msg_len = strlen(msg->body);
  11235. }
  11236. len = 101 + msg_len;
  11237. WFIFOHEAD(fd,len);
  11238. WFIFOW(fd,0) = 0x242;
  11239. WFIFOW(fd,2) = len;
  11240. WFIFOL(fd,4) = msg->id;
  11241. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11242. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11243. WFIFOL(fd,72) = 0;
  11244. WFIFOL(fd,76) = msg->zeny;
  11245. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  11246. {
  11247. WFIFOL(fd,80) = item->amount;
  11248. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11249. WFIFOW(fd,86) = data->type;
  11250. WFIFOB(fd,88) = item->identify;
  11251. WFIFOB(fd,89) = item->attribute;
  11252. WFIFOB(fd,90) = item->refine;
  11253. WFIFOW(fd,91) = item->card[0];
  11254. WFIFOW(fd,93) = item->card[1];
  11255. WFIFOW(fd,95) = item->card[2];
  11256. WFIFOW(fd,97) = item->card[3];
  11257. }
  11258. else // no item, set all to zero
  11259. memset(WFIFOP(fd,80), 0x00, 19);
  11260. WFIFOB(fd,99) = (unsigned char)msg_len;
  11261. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11262. WFIFOSET(fd,len);
  11263. if (msg->status == MAIL_UNREAD) {
  11264. msg->status = MAIL_READ;
  11265. intif_Mail_read(mail_id);
  11266. clif_parse_Mail_refreshinbox(fd, sd);
  11267. }
  11268. }
  11269. }
  11270. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11271. {
  11272. int mail_id = RFIFOL(fd,2);
  11273. if( mail_id <= 0 )
  11274. return;
  11275. if( mail_invalid_operation(sd) )
  11276. return;
  11277. clif_Mail_read(sd, RFIFOL(fd,2));
  11278. }
  11279. /*------------------------------------------
  11280. * Get Attachment from Message
  11281. *------------------------------------------*/
  11282. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11283. {
  11284. int mail_id = RFIFOL(fd,2);
  11285. int i;
  11286. bool fail = false;
  11287. if( mail_id <= 0 )
  11288. return;
  11289. if( mail_invalid_operation(sd) )
  11290. return;
  11291. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11292. if( i == MAIL_MAX_INBOX )
  11293. return;
  11294. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11295. return;
  11296. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11297. {
  11298. struct item_data *data;
  11299. unsigned int weight;
  11300. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11301. return;
  11302. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11303. {
  11304. case ADDITEM_NEW:
  11305. fail = ( pc_inventoryblank(sd) == 0 );
  11306. break;
  11307. case ADDITEM_OVERAMOUNT:
  11308. fail = true;
  11309. }
  11310. if( fail )
  11311. {
  11312. clif_Mail_getattachment(fd, 1);
  11313. return;
  11314. }
  11315. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11316. if( sd->weight + weight > sd->max_weight )
  11317. {
  11318. clif_Mail_getattachment(fd, 2);
  11319. return;
  11320. }
  11321. }
  11322. sd->mail.inbox.msg[i].zeny = 0;
  11323. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11324. clif_Mail_read(sd, mail_id);
  11325. intif_Mail_getattach(sd->status.char_id, mail_id);
  11326. }
  11327. /*------------------------------------------
  11328. * Delete Message
  11329. *------------------------------------------*/
  11330. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11331. {
  11332. int mail_id = RFIFOL(fd,2);
  11333. int i;
  11334. if( mail_id <= 0 )
  11335. return;
  11336. if( mail_invalid_operation(sd) )
  11337. return;
  11338. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11339. if (i < MAIL_MAX_INBOX)
  11340. {
  11341. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11342. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11343. {// can't delete mail without removing attachment first
  11344. clif_Mail_delete(sd->fd, mail_id, 1);
  11345. return;
  11346. }
  11347. intif_Mail_delete(sd->status.char_id, mail_id);
  11348. }
  11349. }
  11350. /*------------------------------------------
  11351. * Return Mail Message
  11352. *------------------------------------------*/
  11353. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11354. {
  11355. int mail_id = RFIFOL(fd,2);
  11356. int i;
  11357. if( mail_id <= 0 )
  11358. return;
  11359. if( mail_invalid_operation(sd) )
  11360. return;
  11361. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11362. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11363. intif_Mail_return(sd->status.char_id, mail_id);
  11364. else
  11365. clif_Mail_return(sd->fd, mail_id, 1);
  11366. }
  11367. /*------------------------------------------
  11368. * Set Attachment
  11369. *------------------------------------------*/
  11370. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11371. {
  11372. int idx = RFIFOW(fd,2);
  11373. int amount = RFIFOL(fd,4);
  11374. unsigned char flag;
  11375. if (idx < 0 || amount < 0)
  11376. return;
  11377. flag = mail_setitem(sd, idx, amount);
  11378. clif_Mail_setattachment(fd,idx,flag);
  11379. }
  11380. /*------------------------------------------
  11381. * Mail Window Operation
  11382. * S 0246 <flag>.W
  11383. * 0 : Switch to 'new mail' window, or Close mailbox
  11384. * 1 : ???
  11385. * 2 : Zeny entering start
  11386. *------------------------------------------*/
  11387. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11388. {
  11389. int flag = RFIFOW(fd,2);
  11390. if (flag == 0 || flag == 1)
  11391. mail_removeitem(sd, 0);
  11392. if (flag == 0 || flag == 2)
  11393. mail_removezeny(sd, 0);
  11394. }
  11395. /*------------------------------------------
  11396. * Send Mail
  11397. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  11398. *------------------------------------------*/
  11399. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11400. {
  11401. struct mail_message msg;
  11402. int body_len;
  11403. if( sd->state.trading )
  11404. return;
  11405. if( RFIFOW(fd,2) < 69 ) {
  11406. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11407. return;
  11408. }
  11409. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11410. {
  11411. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11412. clif_Mail_send(fd, true); // fail
  11413. return;
  11414. }
  11415. body_len = RFIFOB(fd,68);
  11416. if (body_len > MAIL_BODY_LENGTH)
  11417. body_len = MAIL_BODY_LENGTH;
  11418. if( !mail_setattachment(sd, &msg) )
  11419. { // Invalid Append condition
  11420. clif_Mail_send(sd->fd, true); // fail
  11421. mail_removeitem(sd,0);
  11422. mail_removezeny(sd,0);
  11423. return;
  11424. }
  11425. msg.id = 0; // id will be assigned by charserver
  11426. msg.send_id = sd->status.char_id;
  11427. msg.dest_id = 0; // will attempt to resolve name
  11428. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11429. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11430. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11431. if (body_len)
  11432. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11433. else
  11434. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11435. msg.timestamp = time(NULL);
  11436. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11437. mail_deliveryfail(sd, &msg);
  11438. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11439. }
  11440. /*==========================================
  11441. * AUCTION SYSTEM
  11442. * By Zephyrus
  11443. *==========================================*/
  11444. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS)
  11445. /// 025f <type>.L
  11446. /// type:
  11447. /// 0 = open
  11448. /// 1 = close
  11449. void clif_Auction_openwindow(struct map_session_data *sd)
  11450. {
  11451. int fd = sd->fd;
  11452. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11453. return;
  11454. WFIFOHEAD(fd,packet_len(0x25f));
  11455. WFIFOW(fd,0) = 0x25f;
  11456. WFIFOL(fd,2) = 0;
  11457. WFIFOSET(fd,packet_len(0x25f));
  11458. }
  11459. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH)
  11460. /// 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 }*
  11461. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11462. {
  11463. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11464. struct auction_data auction;
  11465. struct item_data *item;
  11466. int k;
  11467. WFIFOHEAD(fd,12 + (count * 83));
  11468. WFIFOW(fd,0) = 0x252;
  11469. WFIFOW(fd,2) = 12 + (count * 83);
  11470. WFIFOL(fd,4) = pages;
  11471. WFIFOL(fd,8) = count;
  11472. for( i = 0; i < count; i++ )
  11473. {
  11474. memcpy(&auction, RBUFP(buf,i * len), len);
  11475. k = 12 + (i * 83);
  11476. WFIFOL(fd,k) = auction.auction_id;
  11477. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11478. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11479. WFIFOW(fd,28+k) = item->view_id;
  11480. else
  11481. WFIFOW(fd,28+k) = auction.item.nameid;
  11482. WFIFOL(fd,30+k) = auction.type;
  11483. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11484. WFIFOB(fd,36+k) = auction.item.identify;
  11485. WFIFOB(fd,37+k) = auction.item.attribute;
  11486. WFIFOB(fd,38+k) = auction.item.refine;
  11487. WFIFOW(fd,39+k) = auction.item.card[0];
  11488. WFIFOW(fd,41+k) = auction.item.card[1];
  11489. WFIFOW(fd,43+k) = auction.item.card[2];
  11490. WFIFOW(fd,45+k) = auction.item.card[3];
  11491. WFIFOL(fd,47+k) = auction.price;
  11492. WFIFOL(fd,51+k) = auction.buynow;
  11493. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11494. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11495. }
  11496. WFIFOSET(fd,WFIFOW(fd,2));
  11497. }
  11498. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM)
  11499. /// 0256 <index>.W <result>.B
  11500. /// result:
  11501. /// 0 = success
  11502. /// 1 = failure
  11503. static void clif_Auction_setitem(int fd, int index, bool fail)
  11504. {
  11505. WFIFOHEAD(fd,packet_len(0x256));
  11506. WFIFOW(fd,0) = 0x256;
  11507. WFIFOW(fd,2) = index;
  11508. WFIFOB(fd,4) = fail;
  11509. WFIFOSET(fd,packet_len(0x256));
  11510. }
  11511. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE)
  11512. /// 024b <type>.W
  11513. /// type:
  11514. /// 0 = create (any other action in auction window)
  11515. /// 1 = cancel (cancel pressed on register tab)
  11516. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11517. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11518. {
  11519. if( sd->auction.amount > 0 )
  11520. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11521. sd->auction.amount = 0;
  11522. }
  11523. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM)
  11524. /// 024c <index>.W <count>.L
  11525. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11526. {
  11527. int idx = RFIFOW(fd,2) - 2;
  11528. int amount = RFIFOL(fd,4); // Always 1
  11529. struct item_data *item;
  11530. if( sd->auction.amount > 0 )
  11531. sd->auction.amount = 0;
  11532. if( idx < 0 || idx >= MAX_INVENTORY )
  11533. {
  11534. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11535. return;
  11536. }
  11537. if( amount != 1 || amount > sd->status.inventory[idx].amount )
  11538. { // By client, amount is always set to 1. Maybe this is a future implementation.
  11539. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11540. return;
  11541. }
  11542. 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) )
  11543. { // Consumible or pets are not allowed
  11544. clif_Auction_setitem(sd->fd, idx, true);
  11545. return;
  11546. }
  11547. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
  11548. { // Quest Item or something else
  11549. clif_Auction_setitem(sd->fd, idx, true);
  11550. return;
  11551. }
  11552. sd->auction.index = idx;
  11553. sd->auction.amount = amount;
  11554. clif_Auction_setitem(fd, idx + 2, false);
  11555. }
  11556. /// Result from an auction action (ZC_AUCTION_RESULT)
  11557. /// 0250 <result>.B
  11558. /// result:
  11559. /// 0 = You have failed to bid into the auction
  11560. /// 1 = You have successfully bid in the auction
  11561. /// 2 = The auction has been canceled
  11562. /// 3 = An auction with at least one bidder cannot be canceled
  11563. /// 4 = You cannot register more than 5 items in an auction at a time
  11564. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11565. /// 6 = You have won the auction
  11566. /// 7 = You have failed to win the auction
  11567. /// 8 = You do not have enough Zeny
  11568. /// 9 = You cannot place more than 5 bids at a time
  11569. void clif_Auction_message(int fd, unsigned char flag)
  11570. {
  11571. WFIFOHEAD(fd,packet_len(0x250));
  11572. WFIFOW(fd,0) = 0x250;
  11573. WFIFOB(fd,2) = flag;
  11574. WFIFOSET(fd,packet_len(0x250));
  11575. }
  11576. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP)
  11577. /// 025e <result>.W
  11578. /// result:
  11579. /// 0 = You have ended the auction
  11580. /// 1 = You cannot end the auction
  11581. /// 2 = Auction ID is incorrect
  11582. void clif_Auction_close(int fd, unsigned char flag)
  11583. {
  11584. WFIFOHEAD(fd,packet_len(0x25e));
  11585. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11586. WFIFOW(fd,2) = flag;
  11587. WFIFOSET(fd,packet_len(0x25e));
  11588. }
  11589. /// Request to add an auction (CZ_AUCTION_ADD)
  11590. /// 024d <now money>.L <max money>.L <delete hour>.W
  11591. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11592. {
  11593. struct auction_data auction;
  11594. struct item_data *item;
  11595. auction.price = RFIFOL(fd,2);
  11596. auction.buynow = RFIFOL(fd,6);
  11597. auction.hours = RFIFOW(fd,10);
  11598. // Invalid Situations...
  11599. if( sd->auction.amount < 1 )
  11600. {
  11601. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11602. return;
  11603. }
  11604. if( auction.price >= auction.buynow )
  11605. {
  11606. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11607. return;
  11608. }
  11609. if( auction.hours < 1 || auction.hours > 48 )
  11610. {
  11611. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11612. return;
  11613. }
  11614. // Auction checks...
  11615. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11616. {
  11617. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11618. return;
  11619. }
  11620. if( auction.buynow > battle_config.auction_maximumprice )
  11621. { // Zeny Limits
  11622. auction.buynow = battle_config.auction_maximumprice;
  11623. if( auction.price >= auction.buynow )
  11624. auction.price = auction.buynow - 1;
  11625. }
  11626. auction.auction_id = 0;
  11627. auction.seller_id = sd->status.char_id;
  11628. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11629. auction.buyer_id = 0;
  11630. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11631. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11632. {
  11633. clif_Auction_message(fd, 2); // The auction has been canceled
  11634. return;
  11635. }
  11636. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11637. { // Just in case
  11638. clif_Auction_message(fd, 2); // The auction has been canceled
  11639. return;
  11640. }
  11641. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11642. auction.type = item->type;
  11643. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11644. auction.item.amount = 1;
  11645. auction.timestamp = 0;
  11646. if( !intif_Auction_register(&auction) )
  11647. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11648. else
  11649. {
  11650. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6);
  11651. sd->auction.amount = 0;
  11652. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  11653. }
  11654. }
  11655. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL)
  11656. /// 024e <auction id>.L
  11657. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11658. {
  11659. unsigned int auction_id = RFIFOL(fd,2);
  11660. intif_Auction_cancel(sd->status.char_id, auction_id);
  11661. }
  11662. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP)
  11663. /// 025d <auction id>.L
  11664. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11665. {
  11666. unsigned int auction_id = RFIFOL(fd,2);
  11667. intif_Auction_close(sd->status.char_id, auction_id);
  11668. }
  11669. /// Places a bid on an auction (CZ_AUCTION_BUY)
  11670. /// 024f <auction id>.L <money>.L
  11671. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11672. {
  11673. unsigned int auction_id = RFIFOL(fd,2);
  11674. int bid = RFIFOL(fd,6);
  11675. if( !pc_can_give_items(pc_isGM(sd)) )
  11676. { //They aren't supposed to give zeny [Inkfish]
  11677. clif_displaymessage(sd->fd, msg_txt(246));
  11678. return;
  11679. }
  11680. if( bid <= 0 )
  11681. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11682. else if( bid > sd->status.zeny )
  11683. clif_Auction_message(fd, 8); // You do not have enough zeny
  11684. else
  11685. {
  11686. pc_payzeny(sd, bid);
  11687. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11688. }
  11689. }
  11690. /// Auction Search (CZ_AUCTION_ITEM_SEARCH)
  11691. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  11692. /// search type:
  11693. /// 0 = armor
  11694. /// 1 = weapon
  11695. /// 2 = card
  11696. /// 3 = misc
  11697. /// 4 = name search
  11698. /// 5 = auction id search
  11699. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11700. {
  11701. char search_text[NAME_LENGTH];
  11702. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11703. int price = RFIFOL(fd,4); // FIXME: bug #5071
  11704. clif_parse_Auction_cancelreg(fd, sd);
  11705. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  11706. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11707. }
  11708. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO)
  11709. /// 025c <type>.W
  11710. /// type:
  11711. /// 0 = sell (own auctions)
  11712. /// 1 = buy (own bids)
  11713. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11714. {
  11715. short type = RFIFOW(fd,2) + 6;
  11716. clif_parse_Auction_cancelreg(fd, sd);
  11717. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11718. }
  11719. #endif
  11720. /*==========================================
  11721. * CASH/POINT SHOP
  11722. *==========================================*/
  11723. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST)
  11724. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  11725. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  11726. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11727. {
  11728. int fd,i;
  11729. #if PACKETVER < 20070711
  11730. const int offset = 8;
  11731. #else
  11732. const int offset = 12;
  11733. #endif
  11734. nullpo_retv(sd);
  11735. nullpo_retv(nd);
  11736. fd = sd->fd;
  11737. sd->npc_shopid = nd->bl.id;
  11738. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  11739. WFIFOW(fd,0) = 0x287;
  11740. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  11741. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11742. #if PACKETVER >= 20070711
  11743. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11744. #endif
  11745. for( i = 0; i < nd->u.shop.count; i++ )
  11746. {
  11747. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11748. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  11749. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  11750. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  11751. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11752. }
  11753. WFIFOSET(fd,WFIFOW(fd,2));
  11754. }
  11755. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE)
  11756. /// S 0289 <cash point>.L <error>.W
  11757. /// S 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  11758. ///
  11759. /// @param error
  11760. /// 0: The deal has successfully completed. (ERROR_TYPE_NONE)
  11761. /// 1: The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11762. /// 2: The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11763. /// 3: You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11764. /// 4: You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11765. /// 5: The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11766. /// 6: You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11767. /// 7: You can purchase up to 10 items.
  11768. /// 8: Some items could not be purchased.
  11769. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11770. {
  11771. int fd = sd->fd;
  11772. WFIFOHEAD(fd, packet_len(0x289));
  11773. WFIFOW(fd,0) = 0x289;
  11774. WFIFOL(fd,2) = sd->cashPoints;
  11775. #if PACKETVER < 20070711
  11776. WFIFOW(fd,6) = TOW(error);
  11777. #else
  11778. WFIFOL(fd,6) = sd->kafraPoints;
  11779. WFIFOW(fd,10) = TOW(error);
  11780. #endif
  11781. WFIFOSET(fd, packet_len(0x289));
  11782. }
  11783. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  11784. /// 0288 <name id>.W <amount>.W
  11785. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  11786. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  11787. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11788. {
  11789. int fail = 0, amount, points = 0;
  11790. short nameid;
  11791. nullpo_retv(sd);
  11792. nameid = RFIFOW(fd,2);
  11793. amount = RFIFOW(fd,4);
  11794. #if PACKETVER >= 20070711
  11795. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  11796. #endif
  11797. if( sd->state.trading || !sd->npc_shopid )
  11798. fail = 1;
  11799. else
  11800. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11801. clif_cashshop_ack(sd, fail);
  11802. }
  11803. /*==========================================
  11804. * Adoption System
  11805. *==========================================*/
  11806. // 0 : "You cannot adopt more than 1 child."
  11807. // 1 : "You must be at least character level 70 in order to adopt someone."
  11808. // 2 : "You cannot adopt a married person."
  11809. void clif_Adopt_reply(struct map_session_data *sd, int type)
  11810. {
  11811. int fd = sd->fd;
  11812. WFIFOHEAD(fd,6);
  11813. WFIFOW(fd,0) = 0x0216;
  11814. WFIFOL(fd,2) = type;
  11815. WFIFOSET(fd,6);
  11816. }
  11817. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  11818. {
  11819. int fd = sd->fd;
  11820. WFIFOHEAD(fd,34);
  11821. WFIFOW(fd,0) = 0x01f6;
  11822. WFIFOL(fd,2) = src->status.account_id;
  11823. WFIFOL(fd,6) = p_id;
  11824. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  11825. WFIFOSET(fd,34);
  11826. }
  11827. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  11828. {
  11829. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  11830. if( pc_can_Adopt(sd, p_sd, tsd) )
  11831. {
  11832. tsd->adopt_invite = sd->status.account_id;
  11833. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  11834. }
  11835. }
  11836. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  11837. {
  11838. int p1_id = RFIFOL(fd,2);
  11839. int p2_id = RFIFOL(fd,6);
  11840. int result = RFIFOL(fd,10);
  11841. struct map_session_data* p1_sd = map_id2sd(p1_id);
  11842. struct map_session_data* p2_sd = map_id2sd(p2_id);
  11843. int pid = sd->adopt_invite;
  11844. sd->adopt_invite = 0;
  11845. if( p1_sd == NULL || p2_sd == NULL )
  11846. return; // Both players need to be online
  11847. if( pid != p1_sd->status.account_id )
  11848. return; // Incorrect values
  11849. if( result == 0 )
  11850. return; // Rejected
  11851. pc_adoption(p1_sd, p2_sd, sd);
  11852. }
  11853. /*==========================================
  11854. * Convex Mirror (ZC_BOSS_INFO)
  11855. * S 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  11856. * infoType:
  11857. * 0 = No boss on this map (BOSS_INFO_NOT).
  11858. * 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  11859. * 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  11860. * 3 = Boss is dead (BOSS_INFO_DEAD).
  11861. *==========================================*/
  11862. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  11863. {
  11864. WFIFOHEAD(fd,70);
  11865. memset(WFIFOP(fd,0),0,70);
  11866. WFIFOW(fd,0) = 0x0293;
  11867. if( md != NULL )
  11868. {
  11869. if( md->bl.prev != NULL )
  11870. { // Boss on This Map
  11871. if( flag )
  11872. {
  11873. WFIFOB(fd,2) = 1;
  11874. WFIFOL(fd,3) = md->bl.x;
  11875. WFIFOL(fd,7) = md->bl.y;
  11876. }
  11877. else
  11878. WFIFOB(fd,2) = 2; // First Time
  11879. }
  11880. else if (md->spawn_timer != INVALID_TIMER)
  11881. { // Boss is Dead
  11882. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  11883. unsigned int seconds;
  11884. int hours, minutes;
  11885. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  11886. hours = seconds / (60 * 60);
  11887. seconds = seconds - (60 * 60 * hours);
  11888. minutes = seconds / 60;
  11889. WFIFOB(fd,2) = 3;
  11890. WFIFOW(fd,11) = hours; // Hours
  11891. WFIFOW(fd,13) = minutes; // Minutes
  11892. }
  11893. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  11894. }
  11895. WFIFOSET(fd,70);
  11896. }
  11897. /*==========================================
  11898. * Requesting equip of a player
  11899. *------------------------------------------*/
  11900. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  11901. {
  11902. int charid = RFIFOL(fd, 2);
  11903. struct map_session_data* tsd = map_id2sd(charid);
  11904. if (!tsd)
  11905. return;
  11906. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  11907. clif_viewequip_ack(sd, tsd);
  11908. else
  11909. clif_viewequip_fail(sd);
  11910. }
  11911. /*==========================================
  11912. * Equip window (un)tick
  11913. * S 02d8 <zero?>.L <flag>.L
  11914. *------------------------------------------*/
  11915. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  11916. {
  11917. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  11918. sd->status.show_equip = flag;
  11919. clif_equiptickack(sd, flag);
  11920. }
  11921. /*==========================================
  11922. * Questlog System [Kevin] [Inkfish]
  11923. *------------------------------------------*/
  11924. //* 02B1 <packet_len>.W <quest_num>.L { <quest_id>.L <state>.B }.5B*
  11925. void clif_quest_send_list(struct map_session_data * sd)
  11926. {
  11927. int fd = sd->fd;
  11928. int i;
  11929. int len = sd->avail_quests*5+8;
  11930. WFIFOHEAD(fd,len);
  11931. WFIFOW(fd, 0) = 0x02B1;
  11932. WFIFOW(fd, 2) = len;
  11933. WFIFOL(fd, 4) = sd->avail_quests;
  11934. for( i = 0; i < sd->avail_quests; i++ )
  11935. {
  11936. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  11937. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  11938. }
  11939. WFIFOSET(fd, len);
  11940. }
  11941. //* 02B2 <packet_len>.W <quest_num>.L { <quest_id>.L <start time>.L <expire time>.L <num mobs>.W {<mob id>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  11942. void clif_quest_send_mission(struct map_session_data * sd)
  11943. {
  11944. int fd = sd->fd;
  11945. int i, j;
  11946. int len = sd->avail_quests*104+8;
  11947. struct mob_db *mob;
  11948. WFIFOHEAD(fd, len);
  11949. WFIFOW(fd, 0) = 0x02B2;
  11950. WFIFOW(fd, 2) = len;
  11951. WFIFOL(fd, 4) = sd->avail_quests;
  11952. for( i = 0; i < sd->avail_quests; i++ )
  11953. {
  11954. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  11955. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  11956. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  11957. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  11958. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  11959. {
  11960. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  11961. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  11962. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  11963. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  11964. }
  11965. }
  11966. WFIFOSET(fd, len);
  11967. }
  11968. //* 02B3 <quest_id>.L <state>.B <start time>.L <expire time>.L <num mobs>.W {<mob id>.L <mob count>.W <Mob Name>.24B}.30B[3]
  11969. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  11970. {
  11971. int fd = sd->fd;
  11972. int i;
  11973. struct mob_db *mob;
  11974. WFIFOHEAD(fd, packet_len(0x02B3));
  11975. WFIFOW(fd, 0) = 0x02B3;
  11976. WFIFOL(fd, 2) = qd->quest_id;
  11977. WFIFOB(fd, 6) = qd->state;
  11978. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  11979. WFIFOL(fd, 11) = qd->time;
  11980. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  11981. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11982. {
  11983. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  11984. WFIFOW(fd, i*30+21) = qd->count[i];
  11985. mob = mob_db(quest_db[index].mob[i]);
  11986. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  11987. }
  11988. WFIFOSET(fd, packet_len(0x02B3));
  11989. }
  11990. //* 02B4 <quest_id>.L
  11991. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  11992. {
  11993. int fd = sd->fd;
  11994. WFIFOHEAD(fd, packet_len(0x02B4));
  11995. WFIFOW(fd, 0) = 0x02B4;
  11996. WFIFOL(fd, 2) = quest_id;
  11997. WFIFOSET(fd, packet_len(0x02B4));
  11998. }
  11999. //* 02b5 <packet_len>.w <mob_num>.w { <quest_id>.d <mob_id>.d <count_total>.w <count_partial>.w }.mob_num
  12000. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12001. {
  12002. int fd = sd->fd;
  12003. int i;
  12004. int len = quest_db[index].num_objectives*12+6;
  12005. WFIFOHEAD(fd, len);
  12006. WFIFOW(fd, 0) = 0x02B5;
  12007. WFIFOW(fd, 2) = len;
  12008. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12009. for( i = 0; i < quest_db[index].num_objectives; i++ )
  12010. {
  12011. WFIFOL(fd, i*12+6) = qd->quest_id;
  12012. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12013. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12014. WFIFOW(fd, i*12+16) = qd->count[i];
  12015. }
  12016. WFIFOSET(fd, len);
  12017. }
  12018. //* 02B6 <quest_id>.L <state>.B
  12019. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12020. {
  12021. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12022. }
  12023. //* 02B7 <quest_id>.L <state_to>.B
  12024. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12025. {
  12026. int fd = sd->fd;
  12027. WFIFOHEAD(fd, packet_len(0x02B7));
  12028. WFIFOW(fd, 0) = 0x02B7;
  12029. WFIFOL(fd, 2) = quest_id;
  12030. WFIFOB(fd, 6) = active;
  12031. WFIFOSET(fd, packet_len(0x02B7));
  12032. }
  12033. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12034. {
  12035. #if PACKETVER >= 20090218
  12036. int fd = sd->fd;
  12037. WFIFOHEAD(fd, packet_len(0x446));
  12038. WFIFOW(fd, 0) = 0x446;
  12039. WFIFOL(fd, 2) = bl->id;
  12040. WFIFOW(fd, 6) = bl->x;
  12041. WFIFOW(fd, 8) = bl->y;
  12042. WFIFOW(fd, 10) = state;
  12043. WFIFOW(fd, 12) = color;
  12044. WFIFOSET(fd, packet_len(0x446));
  12045. #endif
  12046. }
  12047. /*==========================================
  12048. * Mercenary System
  12049. *==========================================*/
  12050. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12051. {
  12052. struct mercenary_data *md;
  12053. struct status_data *status;
  12054. int fd;
  12055. if( sd == NULL || (md = sd->md) == NULL )
  12056. return;
  12057. fd = sd->fd;
  12058. status = &md->battle_status;
  12059. WFIFOHEAD(fd,8);
  12060. WFIFOW(fd,0) = 0x02a2;
  12061. WFIFOW(fd,2) = type;
  12062. switch( type )
  12063. {
  12064. case SP_ATK1:
  12065. {
  12066. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12067. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12068. }
  12069. break;
  12070. case SP_MATK1:
  12071. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12072. break;
  12073. case SP_HIT:
  12074. WFIFOL(fd,4) = status->hit;
  12075. break;
  12076. case SP_CRITICAL:
  12077. WFIFOL(fd,4) = status->cri/10;
  12078. break;
  12079. case SP_DEF1:
  12080. WFIFOL(fd,4) = status->def;
  12081. break;
  12082. case SP_MDEF1:
  12083. WFIFOL(fd,4) = status->mdef;
  12084. break;
  12085. case SP_MERCFLEE:
  12086. WFIFOL(fd,4) = status->flee;
  12087. break;
  12088. case SP_ASPD:
  12089. WFIFOL(fd,4) = status->amotion;
  12090. break;
  12091. case SP_HP:
  12092. WFIFOL(fd,4) = status->hp;
  12093. break;
  12094. case SP_MAXHP:
  12095. WFIFOL(fd,4) = status->max_hp;
  12096. break;
  12097. case SP_SP:
  12098. WFIFOL(fd,4) = status->sp;
  12099. break;
  12100. case SP_MAXSP:
  12101. WFIFOL(fd,4) = status->max_sp;
  12102. break;
  12103. case SP_MERCKILLS:
  12104. WFIFOL(fd,4) = md->mercenary.kill_count;
  12105. break;
  12106. case SP_MERCFAITH:
  12107. WFIFOL(fd,4) = mercenary_get_faith(md);
  12108. break;
  12109. }
  12110. WFIFOSET(fd,8);
  12111. }
  12112. void clif_mercenary_info(struct map_session_data *sd)
  12113. {
  12114. int fd;
  12115. struct mercenary_data *md;
  12116. struct status_data *status;
  12117. int atk;
  12118. if( sd == NULL || (md = sd->md) == NULL )
  12119. return;
  12120. fd = sd->fd;
  12121. status = &md->battle_status;
  12122. WFIFOHEAD(fd,80);
  12123. WFIFOW(fd,0) = 0x029b;
  12124. WFIFOL(fd,2) = md->bl.id;
  12125. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12126. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12127. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12128. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12129. WFIFOW(fd,10) = status->hit;
  12130. WFIFOW(fd,12) = status->cri/10;
  12131. WFIFOW(fd,14) = status->def;
  12132. WFIFOW(fd,16) = status->mdef;
  12133. WFIFOW(fd,18) = status->flee;
  12134. WFIFOW(fd,20) = status->amotion;
  12135. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12136. WFIFOW(fd,46) = md->db->lv;
  12137. WFIFOL(fd,48) = status->hp;
  12138. WFIFOL(fd,52) = status->max_hp;
  12139. WFIFOL(fd,56) = status->sp;
  12140. WFIFOL(fd,60) = status->max_sp;
  12141. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12142. WFIFOW(fd,68) = mercenary_get_faith(md);
  12143. WFIFOL(fd,70) = mercenary_get_calls(md);
  12144. WFIFOL(fd,74) = md->mercenary.kill_count;
  12145. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12146. WFIFOSET(fd,80);
  12147. }
  12148. void clif_mercenary_skillblock(struct map_session_data *sd)
  12149. {
  12150. struct mercenary_data *md;
  12151. int fd, i, len = 4, id, j;
  12152. if( sd == NULL || (md = sd->md) == NULL )
  12153. return;
  12154. fd = sd->fd;
  12155. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12156. WFIFOW(fd,0) = 0x029d;
  12157. for( i = 0; i < MAX_MERCSKILL; i++ )
  12158. {
  12159. if( (id = md->db->skill[i].id) == 0 )
  12160. continue;
  12161. j = id - MC_SKILLBASE;
  12162. WFIFOW(fd,len) = id;
  12163. WFIFOW(fd,len+2) = skill_get_inf(id);
  12164. WFIFOW(fd,len+4) = 0;
  12165. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12166. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12167. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12168. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12169. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12170. len += 37;
  12171. }
  12172. WFIFOW(fd,2) = len;
  12173. WFIFOSET(fd,len);
  12174. }
  12175. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12176. {
  12177. int option = RFIFOB(fd,2);
  12178. if( sd->md == NULL )
  12179. return;
  12180. if( option == 2 ) merc_delete(sd->md, 2);
  12181. }
  12182. /*------------------------------------------
  12183. * Mercenary Message
  12184. * 0 = Mercenary soldier's duty hour is over.
  12185. * 1 = Your mercenary soldier has been killed.
  12186. * 2 = Your mercenary soldier has been fired.
  12187. * 3 = Your mercenary soldier has ran away.
  12188. *------------------------------------------*/
  12189. void clif_mercenary_message(struct map_session_data* sd, int message)
  12190. {
  12191. clif_msg(sd, 1266 + message);
  12192. }
  12193. /*------------------------------------------
  12194. * Rental System Messages
  12195. *------------------------------------------*/
  12196. void clif_rental_time(int fd, int nameid, int seconds)
  12197. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12198. WFIFOHEAD(fd,8);
  12199. WFIFOW(fd,0) = 0x0298;
  12200. WFIFOW(fd,2) = nameid;
  12201. WFIFOL(fd,4) = seconds;
  12202. WFIFOSET(fd,8);
  12203. }
  12204. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12205. /// 0299 <index>.W <nameid>.W
  12206. void clif_rental_expired(int fd, int index, int nameid)
  12207. { // '<ItemName>' item has been deleted from the Inventory
  12208. WFIFOHEAD(fd,6);
  12209. WFIFOW(fd,0) = 0x0299;
  12210. WFIFOW(fd,2) = index+2;
  12211. WFIFOW(fd,4) = nameid;
  12212. WFIFOSET(fd,6);
  12213. }
  12214. /*------------------------------------------
  12215. * Book Reading
  12216. *------------------------------------------*/
  12217. void clif_readbook(int fd, int book_id, int page)
  12218. {
  12219. WFIFOHEAD(fd,10);
  12220. WFIFOW(fd,0) = 0x0294;
  12221. WFIFOL(fd,2) = book_id;
  12222. WFIFOL(fd,6) = page;
  12223. WFIFOSET(fd,10);
  12224. }
  12225. /*------------------------------------------
  12226. * BattleGround Packets
  12227. *------------------------------------------*/
  12228. int clif_bg_hp(struct map_session_data *sd)
  12229. {
  12230. unsigned char buf[16];
  12231. #if PACKETVER < 20100126
  12232. const int cmd = 0x106;
  12233. #else
  12234. const int cmd = 0x80e;
  12235. #endif
  12236. nullpo_ret(sd);
  12237. WBUFW(buf,0)=cmd;
  12238. WBUFL(buf,2) = sd->status.account_id;
  12239. #if PACKETVER < 20100126
  12240. if( sd->battle_status.max_hp > INT16_MAX )
  12241. { // To correctly display the %hp bar. [Skotlex]
  12242. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12243. WBUFW(buf,8) = 100;
  12244. }
  12245. else
  12246. {
  12247. WBUFW(buf,6) = sd->battle_status.hp;
  12248. WBUFW(buf,8) = sd->battle_status.max_hp;
  12249. }
  12250. #else
  12251. WBUFL(buf,6) = sd->battle_status.hp;
  12252. WBUFL(buf,10) = sd->battle_status.max_hp;
  12253. #endif
  12254. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12255. return 0;
  12256. }
  12257. int clif_bg_xy(struct map_session_data *sd)
  12258. {
  12259. unsigned char buf[10];
  12260. nullpo_ret(sd);
  12261. WBUFW(buf,0)=0x1eb;
  12262. WBUFL(buf,2)=sd->status.account_id;
  12263. WBUFW(buf,6)=sd->bl.x;
  12264. WBUFW(buf,8)=sd->bl.y;
  12265. clif_send(buf, packet_len(0x1eb), &sd->bl, BG_SAMEMAP_WOS);
  12266. return 0;
  12267. }
  12268. int clif_bg_xy_remove(struct map_session_data *sd)
  12269. {
  12270. unsigned char buf[10];
  12271. nullpo_ret(sd);
  12272. WBUFW(buf,0)=0x1eb;
  12273. WBUFL(buf,2)=sd->status.account_id;
  12274. WBUFW(buf,6)=-1;
  12275. WBUFW(buf,8)=-1;
  12276. clif_send(buf,packet_len(0x1eb),&sd->bl,BG_SAMEMAP_WOS);
  12277. return 0;
  12278. }
  12279. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT)
  12280. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12281. int clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12282. {
  12283. struct map_session_data *sd;
  12284. unsigned char *buf;
  12285. if( (sd = bg_getavailablesd(bg)) == NULL )
  12286. return 0;
  12287. buf = (unsigned char*)aMallocA((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12288. WBUFW(buf,0) = 0x2dc;
  12289. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12290. WBUFL(buf,4) = src_id;
  12291. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12292. memcpy(WBUFP(buf,32), mes, len);
  12293. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12294. if( buf ) aFree(buf);
  12295. return 0;
  12296. }
  12297. /*==========================================
  12298. * Validates and processes battlechat messages [pakpil]
  12299. * S 0x2db <packet len>.w <text>.?B (<name> : <message>) 00
  12300. *------------------------------------------*/
  12301. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12302. {
  12303. const char* text = (char*)RFIFOP(fd,4);
  12304. int textlen = RFIFOW(fd,2) - 4;
  12305. char *name, *message;
  12306. int namelen, messagelen;
  12307. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12308. return;
  12309. if( is_atcommand(fd, sd, message, 1) )
  12310. return;
  12311. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12312. return;
  12313. if( battle_config.min_chat_delay )
  12314. {
  12315. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12316. return;
  12317. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12318. }
  12319. bg_send_message(sd, text, textlen);
  12320. }
  12321. int clif_bg_updatescore(int m)
  12322. {
  12323. struct block_list bl;
  12324. unsigned char buf[6];
  12325. bl.id = 0;
  12326. bl.type = BL_NUL;
  12327. bl.m = m;
  12328. WBUFW(buf,0) = 0x2de;
  12329. WBUFW(buf,2) = map[m].bgscore_lion;
  12330. WBUFW(buf,4) = map[m].bgscore_eagle;
  12331. clif_send(buf,6,&bl,ALL_SAMEMAP);
  12332. return 0;
  12333. }
  12334. int clif_bg_updatescore_single(struct map_session_data *sd)
  12335. {
  12336. int fd;
  12337. nullpo_ret(sd);
  12338. fd = sd->fd;
  12339. WFIFOHEAD(fd,6);
  12340. WFIFOW(fd,0) = 0x2de;
  12341. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12342. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12343. WFIFOSET(fd,6);
  12344. return 0;
  12345. }
  12346. int clif_sendbgemblem_area(struct map_session_data *sd)
  12347. {
  12348. unsigned char buf[33];
  12349. nullpo_ret(sd);
  12350. WBUFW(buf, 0) = 0x2dd;
  12351. WBUFL(buf,2) = sd->bl.id;
  12352. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12353. WBUFW(buf,30) = sd->bg_id;
  12354. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12355. return 0;
  12356. }
  12357. int clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12358. {
  12359. nullpo_ret(sd);
  12360. WFIFOHEAD(fd,32);
  12361. WFIFOW(fd,0) = 0x2dd;
  12362. WFIFOL(fd,2) = sd->bl.id;
  12363. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12364. WFIFOW(fd,30) = sd->bg_id;
  12365. WFIFOSET(fd,packet_len(0x2dd));
  12366. return 0;
  12367. }
  12368. /*==========================================
  12369. * Custom Fonts
  12370. * S 0x2ef <account_id>.l <font id>.w
  12371. *------------------------------------------*/
  12372. int clif_font(struct map_session_data *sd)
  12373. {
  12374. unsigned char buf[8];
  12375. nullpo_ret(sd);
  12376. WBUFW(buf,0) = 0x2ef;
  12377. WBUFL(buf,2) = sd->bl.id;
  12378. WBUFW(buf,6) = sd->user_font;
  12379. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12380. return 1;
  12381. }
  12382. /*==========================================
  12383. * Instancing Window
  12384. *------------------------------------------*/
  12385. int clif_instance(int instance_id, int type, int flag)
  12386. {
  12387. struct map_session_data *sd;
  12388. struct party_data *p;
  12389. unsigned char buf[255];
  12390. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12391. return 0;
  12392. switch( type )
  12393. {
  12394. case 1:
  12395. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12396. // Required to start the instancing information window on Client
  12397. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12398. WBUFW(buf,0) = 0x02CB;
  12399. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12400. WBUFW(buf,63) = flag;
  12401. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12402. break;
  12403. case 2:
  12404. // S 0x2cc <Standby Position>.W
  12405. // To announce Instancing queue creation if no maps available
  12406. WBUFW(buf,0) = 0x02CC;
  12407. WBUFW(buf,2) = flag;
  12408. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12409. break;
  12410. case 3:
  12411. case 4:
  12412. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12413. WBUFW(buf,0) = 0x02CD;
  12414. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12415. if( type == 3 )
  12416. {
  12417. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12418. WBUFL(buf,67) = 0;
  12419. }
  12420. else
  12421. {
  12422. WBUFL(buf,63) = 0;
  12423. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12424. }
  12425. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12426. break;
  12427. case 5:
  12428. // S 0x2ce <Message ID>.L
  12429. // 0 = Notification (EnterLimitDate update?)
  12430. // 1 = The Memorial Dungeon expired; it has been destroyed
  12431. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12432. // 3 = The Memorial Dungeon has been removed.
  12433. // 4 = Create failure (removes the instance window)
  12434. WBUFW(buf,0) = 0x02CE;
  12435. WBUFL(buf,2) = flag;
  12436. //WBUFL(buf,6) = EnterLimitDate;
  12437. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12438. break;
  12439. }
  12440. return 0;
  12441. }
  12442. void clif_instance_join(int fd, int instance_id)
  12443. {
  12444. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12445. {
  12446. WFIFOHEAD(fd,packet_len(0x02CD));
  12447. WFIFOW(fd,0) = 0x02CD;
  12448. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12449. WFIFOL(fd,63) = 0;
  12450. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12451. WFIFOSET(fd,packet_len(0x02CD));
  12452. }
  12453. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12454. {
  12455. WFIFOHEAD(fd,packet_len(0x02CD));
  12456. WFIFOW(fd,0) = 0x02CD;
  12457. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12458. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12459. WFIFOL(fd,67) = 0;
  12460. WFIFOSET(fd,packet_len(0x02CD));
  12461. }
  12462. else
  12463. {
  12464. WFIFOHEAD(fd,packet_len(0x02CB));
  12465. WFIFOW(fd,0) = 0x02CB;
  12466. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12467. WFIFOW(fd,63) = 0;
  12468. WFIFOSET(fd,packet_len(0x02CB));
  12469. }
  12470. }
  12471. void clif_instance_leave(int fd)
  12472. {
  12473. WFIFOHEAD(fd,packet_len(0x02CE));
  12474. WFIFOW(fd,0) = 0x02ce;
  12475. WFIFOL(fd,2) = 4;
  12476. WFIFOSET(fd,packet_len(0x02CE));
  12477. }
  12478. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12479. {
  12480. #if PACKETVER >= 20071002
  12481. unsigned char buf[22];
  12482. struct item_data* id = itemdb_search(item_data->nameid);
  12483. WBUFW(buf,0)=0x2b8;
  12484. WBUFL(buf,2) = sd->status.account_id;
  12485. WBUFW(buf,6) = item_data->nameid;
  12486. WBUFB(buf,8) = item_data->identify;
  12487. WBUFB(buf,9) = item_data->attribute;
  12488. WBUFB(buf,10) = item_data->refine;
  12489. clif_addcards(WBUFP(buf,11), item_data);
  12490. WBUFW(buf,19) = id->equip; // equip location
  12491. WBUFB(buf,21) = itemtype(id->type); // item type
  12492. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12493. #endif
  12494. }
  12495. // Display gain exp
  12496. // type = 1 -> base_exp
  12497. // type = 2 -> job_exp
  12498. // flag = 0 -> normal exp gain/lost
  12499. // flag = 1 -> quest exp gain/lost
  12500. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12501. {
  12502. int fd;
  12503. nullpo_retv(sd);
  12504. fd = sd->fd;
  12505. WFIFOHEAD(fd, packet_len(0x7f6));
  12506. WFIFOW(fd,0) = 0x7f6;
  12507. WFIFOL(fd,2) = sd->bl.id;
  12508. WFIFOL(fd,6) = exp;
  12509. WFIFOW(fd,10) = type;
  12510. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12511. WFIFOSET(fd,packet_len(0x7f6));
  12512. return;
  12513. }
  12514. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12515. /// type:
  12516. /// 0: Displays 'value' for 5 seconds.
  12517. /// 1: Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12518. /// 2: Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12519. /// 3: Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12520. /// value:
  12521. /// 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).
  12522. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12523. {
  12524. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12525. WFIFOW(sd->fd,0) = 0x1b1;
  12526. WFIFOB(sd->fd,0) = type;
  12527. WFIFOL(sd->fd,0) = value;
  12528. WFIFOSET(sd->fd, packet_len(0x1b1));
  12529. }
  12530. /// Notification of the state of client command /effect (CZ_LESSEFFECT)
  12531. /// 021d <state>.L
  12532. /// state:
  12533. /// 0 = Full effects
  12534. /// 1 = Reduced effects
  12535. ///
  12536. /// @note The state is used on Aegis for sending skill unit packet
  12537. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12538. /// whenever possible. Due to the way the decision check is
  12539. /// constructed, this state tracking was rendered useless,
  12540. /// as the only skill unit, that is sent with 0x1c9 is
  12541. /// Graffiti.
  12542. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12543. {
  12544. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12545. sd->state.lesseffect = ( isLess != 0 );
  12546. }
  12547. /// Buying Store System
  12548. ///
  12549. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE)
  12550. /// 0810 <slots>.B
  12551. void clif_buyingstore_open(struct map_session_data* sd)
  12552. {
  12553. int fd = sd->fd;
  12554. WFIFOHEAD(fd,packet_len(0x810));
  12555. WFIFOW(fd,0) = 0x810;
  12556. WFIFOB(fd,2) = sd->buyingstore.slots;
  12557. WFIFOSET(fd,packet_len(0x810));
  12558. }
  12559. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE)
  12560. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12561. /// result:
  12562. /// 0 = cancel
  12563. /// 1 = open
  12564. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12565. {
  12566. const unsigned int blocksize = 8;
  12567. uint8* itemlist;
  12568. char storename[MESSAGE_SIZE];
  12569. unsigned char result;
  12570. int zenylimit;
  12571. unsigned int count, packet_len;
  12572. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12573. packet_len = RFIFOW(fd,info->pos[0]);
  12574. // TODO: Make this check global for all variable length packets.
  12575. if( packet_len < 89 )
  12576. {// minimum packet length
  12577. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12578. return;
  12579. }
  12580. zenylimit = RFIFOL(fd,info->pos[1]);
  12581. result = RFIFOL(fd,info->pos[2]);
  12582. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12583. itemlist = RFIFOP(fd,info->pos[4]);
  12584. // so that buyingstore_create knows, how many elements it has access to
  12585. packet_len-= info->pos[4];
  12586. if( packet_len%blocksize )
  12587. {
  12588. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12589. return;
  12590. }
  12591. count = packet_len/blocksize;
  12592. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  12593. }
  12594. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER)
  12595. /// 0812 <result>.W <total weight>.L
  12596. /// result:
  12597. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  12598. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  12599. /// 8 = "No sale (purchase) information available." (0x705)
  12600. /// other = nothing
  12601. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  12602. {
  12603. int fd = sd->fd;
  12604. WFIFOHEAD(fd,packet_len(0x812));
  12605. WFIFOW(fd,0) = 0x812;
  12606. WFIFOW(fd,2) = result;
  12607. WFIFOL(fd,4) = weight;
  12608. WFIFOSET(fd,packet_len(0x812));
  12609. }
  12610. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE)
  12611. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  12612. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  12613. {
  12614. int fd = sd->fd;
  12615. unsigned int i;
  12616. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  12617. WFIFOW(fd,0) = 0x813;
  12618. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  12619. WFIFOL(fd,4) = sd->bl.id;
  12620. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  12621. for( i = 0; i < sd->buyingstore.slots; i++ )
  12622. {
  12623. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  12624. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  12625. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  12626. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  12627. }
  12628. WFIFOSET(fd,WFIFOW(fd,2));
  12629. }
  12630. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY)
  12631. /// 0814 <account id>.L <store name>.80B
  12632. void clif_buyingstore_entry(struct map_session_data* sd)
  12633. {
  12634. uint8 buf[86];
  12635. WBUFW(buf,0) = 0x814;
  12636. WBUFL(buf,2) = sd->bl.id;
  12637. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  12638. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  12639. }
  12640. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12641. {
  12642. int fd = sd->fd;
  12643. WFIFOHEAD(fd,packet_len(0x814));
  12644. WFIFOW(fd,0) = 0x814;
  12645. WFIFOL(fd,2) = pl_sd->bl.id;
  12646. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  12647. WFIFOSET(fd,packet_len(0x814));
  12648. }
  12649. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE)
  12650. /// 0815
  12651. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  12652. {
  12653. buyingstore_close(sd);
  12654. }
  12655. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY)
  12656. /// 0816 <account id>.L
  12657. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  12658. {
  12659. uint8 buf[6];
  12660. WBUFW(buf,0) = 0x816;
  12661. WBUFL(buf,2) = sd->bl.id;
  12662. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  12663. }
  12664. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12665. {
  12666. int fd = sd->fd;
  12667. WFIFOHEAD(fd,packet_len(0x816));
  12668. WFIFOW(fd,0) = 0x816;
  12669. WFIFOL(fd,2) = pl_sd->bl.id;
  12670. WFIFOSET(fd,packet_len(0x816));
  12671. }
  12672. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE)
  12673. /// 0817 <account id>.L
  12674. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  12675. {
  12676. int account_id;
  12677. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12678. buyingstore_open(sd, account_id);
  12679. }
  12680. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE)
  12681. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  12682. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  12683. {
  12684. int fd = sd->fd;
  12685. unsigned int i;
  12686. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  12687. WFIFOW(fd,0) = 0x818;
  12688. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  12689. WFIFOL(fd,4) = pl_sd->bl.id;
  12690. WFIFOL(fd,8) = pl_sd->buyer_id;
  12691. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  12692. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  12693. {
  12694. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  12695. 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.
  12696. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  12697. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  12698. }
  12699. WFIFOSET(fd,WFIFOW(fd,2));
  12700. }
  12701. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE)
  12702. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  12703. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  12704. {
  12705. const unsigned int blocksize = 6;
  12706. uint8* itemlist;
  12707. int account_id;
  12708. unsigned int count, packet_len, buyer_id;
  12709. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12710. packet_len = RFIFOW(fd,info->pos[0]);
  12711. if( packet_len < 12 )
  12712. {// minimum packet length
  12713. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  12714. return;
  12715. }
  12716. account_id = RFIFOL(fd,info->pos[1]);
  12717. buyer_id = RFIFOL(fd,info->pos[2]);
  12718. itemlist = RFIFOP(fd,info->pos[3]);
  12719. // so that buyingstore_trade knows, how many elements it has access to
  12720. packet_len-= info->pos[3];
  12721. if( packet_len%blocksize )
  12722. {
  12723. 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);
  12724. return;
  12725. }
  12726. count = packet_len/blocksize;
  12727. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  12728. }
  12729. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER)
  12730. /// 081a <result>.W
  12731. /// result:
  12732. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  12733. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  12734. /// other = nothing
  12735. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  12736. {
  12737. int fd = sd->fd;
  12738. WFIFOHEAD(fd,packet_len(0x81a));
  12739. WFIFOW(fd,0) = 0x81a;
  12740. WFIFOW(fd,2) = result;
  12741. WFIFOSET(fd,packet_len(0x81a));
  12742. }
  12743. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  12744. /// 081b <name id>.W <amount>.W <limit zeny>.L
  12745. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  12746. {
  12747. int fd = sd->fd;
  12748. WFIFOHEAD(fd,packet_len(0x81b));
  12749. WFIFOW(fd,0) = 0x81b;
  12750. WFIFOW(fd,2) = nameid;
  12751. WFIFOW(fd,4) = amount; // amount of nameid received
  12752. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  12753. WFIFOSET(fd,packet_len(0x81b));
  12754. }
  12755. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE)
  12756. /// 081c <index>.W <amount>.W <price>.L
  12757. /// message:
  12758. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  12759. ///
  12760. /// @note This function has to be called _instead_ of clif_delitem/clif_dropitem.
  12761. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  12762. {
  12763. int fd = sd->fd;
  12764. WFIFOHEAD(fd,packet_len(0x81c));
  12765. WFIFOW(fd,0) = 0x81c;
  12766. WFIFOW(fd,2) = index+2;
  12767. WFIFOW(fd,4) = amount;
  12768. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  12769. WFIFOSET(fd,packet_len(0x81c));
  12770. }
  12771. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER)
  12772. /// 0824 <result>.W <name id>.W
  12773. /// result:
  12774. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  12775. /// 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)
  12776. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  12777. /// other = nothing
  12778. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  12779. {
  12780. int fd = sd->fd;
  12781. WFIFOHEAD(fd,packet_len(0x824));
  12782. WFIFOW(fd,0) = 0x824;
  12783. WFIFOW(fd,2) = result;
  12784. WFIFOW(fd,4) = nameid;
  12785. WFIFOSET(fd,packet_len(0x824));
  12786. }
  12787. /// Search Store Info System
  12788. ///
  12789. /// Request to search for stores (CZ_SEARCH_STORE_INFO)
  12790. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  12791. /// type:
  12792. /// 0 = Vending
  12793. /// 1 = Buying Store
  12794. ///
  12795. /// @note The client determines the item ids by specifying a name and optionally,
  12796. /// amount of card slots. If the client does not know about the item it
  12797. /// cannot be searched.
  12798. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  12799. {
  12800. const unsigned int blocksize = 2;
  12801. const uint8* itemlist;
  12802. const uint8* cardlist;
  12803. unsigned char type;
  12804. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  12805. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12806. packet_len = RFIFOW(fd,info->pos[0]);
  12807. if( packet_len < 15 )
  12808. {// minimum packet length
  12809. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  12810. return;
  12811. }
  12812. type = RFIFOB(fd,info->pos[1]);
  12813. max_price = RFIFOL(fd,info->pos[2]);
  12814. min_price = RFIFOL(fd,info->pos[3]);
  12815. item_count = RFIFOB(fd,info->pos[4]);
  12816. card_count = RFIFOB(fd,info->pos[5]);
  12817. itemlist = RFIFOP(fd,info->pos[6]);
  12818. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  12819. // check, if there is enough data for the claimed count of items
  12820. packet_len-= info->pos[6];
  12821. if( packet_len%blocksize )
  12822. {
  12823. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12824. return;
  12825. }
  12826. count = packet_len/blocksize;
  12827. if( count < item_count+card_count )
  12828. {
  12829. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  12830. return;
  12831. }
  12832. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  12833. }
  12834. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK)
  12835. /// 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 }*
  12836. /// is first page:
  12837. /// 0 = appends to existing results
  12838. /// 1 = clears previous results before displaying this result set
  12839. /// is next page:
  12840. /// 0 = no "next" label
  12841. /// 1 = "next" label to retrieve more results
  12842. void clif_search_store_info_ack(struct map_session_data* sd)
  12843. {
  12844. const unsigned int blocksize = MESSAGE_SIZE+26;
  12845. int fd = sd->fd;
  12846. unsigned int i, start, end;
  12847. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  12848. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  12849. WFIFOHEAD(fd,7+(end-start)*blocksize);
  12850. WFIFOW(fd,0) = 0x836;
  12851. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  12852. WFIFOB(fd,4) = !sd->searchstore.pages;
  12853. WFIFOB(fd,5) = searchstore_querynext(sd);
  12854. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  12855. for( i = start; i < end; i++ )
  12856. {
  12857. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  12858. struct item it;
  12859. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  12860. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  12861. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  12862. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  12863. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  12864. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  12865. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  12866. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  12867. // make-up an item for clif_addcards
  12868. memset(&it, 0, sizeof(it));
  12869. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  12870. it.nameid = ssitem->nameid;
  12871. it.amount = ssitem->amount;
  12872. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  12873. }
  12874. WFIFOSET(fd,WFIFOW(fd,2));
  12875. }
  12876. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED)
  12877. /// 0837 <reason>.B
  12878. /// reason:
  12879. /// 0 = "No matching stores were found." (0x70b)
  12880. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  12881. /// 2 = "You cannot search anymore." (0x706)
  12882. /// 3 = "You cannot search yet." (0x708)
  12883. /// 4 = "No sale (purchase) information available." (0x705)
  12884. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  12885. {
  12886. int fd = sd->fd;
  12887. WFIFOHEAD(fd,packet_len(0x837));
  12888. WFIFOW(fd,0) = 0x837;
  12889. WFIFOB(fd,2) = reason;
  12890. WFIFOSET(fd,packet_len(0x837));
  12891. }
  12892. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE)
  12893. /// 0838
  12894. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  12895. {
  12896. searchstore_next(sd);
  12897. }
  12898. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO)
  12899. /// 083a <type>.W <remaining uses>.B
  12900. /// type:
  12901. /// 0 = Search Stores
  12902. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  12903. void clif_open_search_store_info(struct map_session_data* sd)
  12904. {
  12905. int fd = sd->fd;
  12906. WFIFOHEAD(fd,packet_len(0x83a));
  12907. WFIFOW(fd,0) = 0x83a;
  12908. WFIFOW(fd,2) = sd->searchstore.effect;
  12909. #if PACKETVER > 20100701
  12910. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  12911. #endif
  12912. WFIFOSET(fd,packet_len(0x83a));
  12913. }
  12914. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO)
  12915. /// 083b
  12916. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  12917. {
  12918. searchstore_close(sd);
  12919. }
  12920. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK)
  12921. /// 083c <account id>.L <store id>.L <nameid>.W
  12922. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  12923. {
  12924. unsigned short nameid;
  12925. int account_id, store_id;
  12926. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12927. account_id = RFIFOL(fd,info->pos[0]);
  12928. store_id = RFIFOL(fd,info->pos[1]);
  12929. nameid = RFIFOW(fd,info->pos[2]);
  12930. searchstore_click(sd, account_id, store_id, nameid);
  12931. }
  12932. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK)
  12933. /// 083d <xPos>.W <yPos>.W
  12934. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  12935. {
  12936. int fd = sd->fd;
  12937. WFIFOHEAD(fd,packet_len(0x83d));
  12938. WFIFOW(fd,0) = 0x83d;
  12939. WFIFOW(fd,2) = x;
  12940. WFIFOW(fd,4) = y;
  12941. WFIFOSET(fd,packet_len(0x83d));
  12942. }
  12943. /// Parse function for packet debugging
  12944. void clif_parse_debug(int fd,struct map_session_data *sd)
  12945. {
  12946. int cmd, packet_len;
  12947. // clif_parse ensures, that there is at least 2 bytes of data
  12948. cmd = RFIFOW(fd,0);
  12949. if( sd )
  12950. {
  12951. packet_len = packet_db[sd->packet_ver][cmd].len;
  12952. if( packet_len == 0 )
  12953. {// unknown
  12954. packet_len = RFIFOREST(fd);
  12955. }
  12956. else if( packet_len == -1 )
  12957. {// variable length
  12958. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  12959. }
  12960. 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);
  12961. }
  12962. else
  12963. {
  12964. packet_len = RFIFOREST(fd);
  12965. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  12966. }
  12967. ShowDump(RFIFOP(fd,0), packet_len);
  12968. }
  12969. /**
  12970. * Rune Knight
  12971. **/
  12972. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  12973. #if PACKETVER >= 20081217
  12974. unsigned char buf[10];
  12975. WBUFW(buf,0) = 0x440;
  12976. WBUFL(buf,2) = sd->bl.id;
  12977. WBUFW(buf,6) = shields;
  12978. WBUFW(buf,8) = 0;
  12979. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  12980. #endif
  12981. }
  12982. /**
  12983. * Warlock
  12984. **/
  12985. /*==========================================
  12986. * Spellbook list [LimitLine/3CeAM]
  12987. *------------------------------------------*/
  12988. int clif_spellbook_list(struct map_session_data *sd)
  12989. {
  12990. int i, c;
  12991. int fd;
  12992. nullpo_ret(sd);
  12993. fd = sd->fd;
  12994. WFIFOHEAD(fd, 8 * 8 + 8);
  12995. WFIFOW(fd,0) = 0x1ad;
  12996. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  12997. {
  12998. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  12999. {
  13000. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13001. c ++;
  13002. }
  13003. }
  13004. if( c > 0 )
  13005. {
  13006. WFIFOW(fd,2) = c * 2 + 4;
  13007. WFIFOSET(fd, WFIFOW(fd, 2));
  13008. sd->menuskill_id = WL_READING_SB;
  13009. sd->menuskill_val = c;
  13010. }
  13011. else
  13012. status_change_end(&sd->bl,SC_STOP,-1);
  13013. return 1;
  13014. }
  13015. /**
  13016. * Mechanic
  13017. **/
  13018. /*==========================================
  13019. * Magic Decoy Material List
  13020. *------------------------------------------*/
  13021. int clif_magicdecoy_list(struct map_session_data *sd, int skill_lv, short x, short y) {
  13022. int i, c;
  13023. int fd;
  13024. nullpo_ret(sd);
  13025. fd = sd->fd;
  13026. WFIFOHEAD(fd, 8 * 8 + 8);
  13027. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13028. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13029. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13030. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13031. c ++;
  13032. }
  13033. }
  13034. if( c > 0 ) {
  13035. sd->menuskill_id = NC_MAGICDECOY;
  13036. sd->menuskill_val = skill_lv;
  13037. sd->sc.comet_x = x;
  13038. sd->sc.comet_y = y;
  13039. WFIFOW(fd,2) = c * 2 + 4;
  13040. WFIFOSET(fd, WFIFOW(fd, 2));
  13041. } else {
  13042. clif_skill_fail(sd,NC_MAGICDECOY,0,0);
  13043. return 0;
  13044. }
  13045. return 1;
  13046. }
  13047. /**
  13048. * Guilotine Cross
  13049. **/
  13050. /*==========================================
  13051. * Guillotine Cross Poisons List
  13052. *------------------------------------------*/
  13053. int clif_poison_list(struct map_session_data *sd, int skill_lv) {
  13054. int i, c;
  13055. int fd;
  13056. nullpo_ret(sd);
  13057. fd = sd->fd;
  13058. WFIFOHEAD(fd, 8 * 8 + 8);
  13059. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13060. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13061. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13062. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13063. c ++;
  13064. }
  13065. }
  13066. if( c > 0 ) {
  13067. sd->menuskill_id = GC_POISONINGWEAPON;
  13068. sd->menuskill_val = skill_lv;
  13069. WFIFOW(fd,2) = c * 2 + 4;
  13070. WFIFOSET(fd, WFIFOW(fd, 2));
  13071. } else {
  13072. clif_skill_fail(sd,GC_POISONINGWEAPON,0x2b,0);
  13073. return 0;
  13074. }
  13075. return 1;
  13076. }
  13077. /**
  13078. * Sends a new status without a tick (currently used by the new mounts)
  13079. **/
  13080. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13081. unsigned char buf[32];
  13082. nullpo_ret(bl);
  13083. WBUFW(buf,0)=0x043f;
  13084. WBUFW(buf,2)=type;
  13085. WBUFL(buf,4)=bl->id;
  13086. WBUFB(buf,8)=flag;
  13087. WBUFL(buf,9) = 0;
  13088. WBUFL(buf,13) = val1;
  13089. WBUFL(buf,17) = val2;
  13090. WBUFL(buf,21) = val3;
  13091. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  13092. return 0;
  13093. }
  13094. //Notifies FD of ID's type
  13095. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13096. WFIFOHEAD(fd, packet_len(0x043f));
  13097. WFIFOW(fd,0)=0x043f;
  13098. WFIFOW(fd,2)=type;
  13099. WFIFOL(fd,4)=id;
  13100. WFIFOB(fd,8)=flag;
  13101. WFIFOL(fd,9) = 0;
  13102. WFIFOL(fd,13) = val1;
  13103. WFIFOL(fd,17) = val2;
  13104. WFIFOL(fd,21) = val3;
  13105. WFIFOSET(fd, packet_len(0x043f));
  13106. return 0;
  13107. }
  13108. // msgstringtable.txt
  13109. // 0x291 <line>.W
  13110. void clif_msgtable(int fd, int line) {
  13111. WFIFOHEAD(fd, packet_len(0x291));
  13112. WFIFOW(fd, 0) = 0x291;
  13113. WFIFOW(fd, 2) = line;
  13114. WFIFOSET(fd, packet_len(0x291));
  13115. }
  13116. // msgstringtable.txt
  13117. // 0x7e2 <line>.W <value>.L
  13118. void clif_msgtable_num(int fd, int line, int num) {
  13119. #if PACKETVER >= 20090805
  13120. WFIFOHEAD(fd, packet_len(0x7e2));
  13121. WFIFOW(fd, 0) = 0x7e2;
  13122. WFIFOW(fd, 2) = line;
  13123. WFIFOL(fd, 4) = num;
  13124. WFIFOSET(fd, packet_len(0x7e2));
  13125. #endif
  13126. }
  13127. /*==========================================
  13128. * Main client packet processing function
  13129. *------------------------------------------*/
  13130. int clif_parse(int fd)
  13131. {
  13132. int cmd, packet_ver, packet_len, err;
  13133. TBL_PC* sd;
  13134. int pnum;
  13135. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13136. // Note: "click masters" can do 80+ clicks in 10 seconds
  13137. 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]
  13138. { // begin main client packet processing loop
  13139. sd = (TBL_PC *)session[fd]->session_data;
  13140. if (session[fd]->flag.eof) {
  13141. if (sd) {
  13142. if (sd->state.autotrade) {
  13143. //Disassociate character from the socket connection.
  13144. session[fd]->session_data = NULL;
  13145. sd->fd = 0;
  13146. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  13147. } else
  13148. if (sd->state.active) {
  13149. // Player logout display [Valaris]
  13150. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  13151. clif_quitsave(fd, sd);
  13152. } else {
  13153. //Unusual logout (during log on/off/map-changer procedure)
  13154. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13155. map_quit(sd);
  13156. }
  13157. } else {
  13158. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13159. }
  13160. do_close(fd);
  13161. return 0;
  13162. }
  13163. if (RFIFOREST(fd) < 2)
  13164. return 0;
  13165. cmd = RFIFOW(fd,0);
  13166. // identify client's packet version
  13167. if (sd) {
  13168. packet_ver = sd->packet_ver;
  13169. } else {
  13170. // check authentification packet to know packet version
  13171. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13172. if( err )
  13173. {// failed to identify packet version
  13174. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  13175. err == 1 ? "" :
  13176. err == 2 ? ", possibly for having an invalid account_id" :
  13177. err == 3 ? ", possibly for having an invalid char_id." :
  13178. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13179. err == 4 ? ", possibly for having an invalid login_id1." :
  13180. err == 5 ? ", possibly for having an invalid client_tick." :
  13181. */
  13182. err == 6 ? ", possibly for having an invalid sex." :
  13183. ". ERROR invalid error code"));
  13184. WFIFOHEAD(fd,packet_len(0x6a));
  13185. WFIFOW(fd,0) = 0x6a;
  13186. WFIFOB(fd,2) = 3; // Rejected from Server
  13187. WFIFOSET(fd,packet_len(0x6a));
  13188. #ifdef DUMP_INVALID_PACKET
  13189. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13190. #endif
  13191. RFIFOSKIP(fd, RFIFOREST(fd));
  13192. set_eof(fd);
  13193. return 0;
  13194. }
  13195. }
  13196. // filter out invalid / unsupported packets
  13197. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13198. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13199. #ifdef DUMP_INVALID_PACKET
  13200. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13201. #endif
  13202. set_eof(fd);
  13203. return 0;
  13204. }
  13205. // determine real packet length
  13206. packet_len = packet_db[packet_ver][cmd].len;
  13207. if (packet_len == -1) { // variable-length packet
  13208. if (RFIFOREST(fd) < 4)
  13209. return 0;
  13210. packet_len = RFIFOW(fd,2);
  13211. if (packet_len < 4 || packet_len > 32768) {
  13212. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13213. #ifdef DUMP_INVALID_PACKET
  13214. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13215. #endif
  13216. set_eof(fd);
  13217. return 0;
  13218. }
  13219. }
  13220. if ((int)RFIFOREST(fd) < packet_len)
  13221. return 0; // not enough data received to form the packet
  13222. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13223. packet_db[packet_ver][cmd].func(fd, sd);
  13224. else
  13225. if( packet_db[packet_ver][cmd].func != NULL )
  13226. {
  13227. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13228. ; //Only valid packet when there is no session
  13229. else
  13230. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13231. ; //Only valid packet when player is not on a map
  13232. else
  13233. if( sd && session[sd->fd]->flag.eof )
  13234. ; //No more packets accepted
  13235. else
  13236. packet_db[packet_ver][cmd].func(fd, sd);
  13237. }
  13238. #ifdef DUMP_UNKNOWN_PACKET
  13239. else
  13240. {
  13241. const char* packet_txt = "save/packet.txt";
  13242. FILE* fp;
  13243. if((fp = fopen(packet_txt, "a"))!=NULL)
  13244. {
  13245. if( sd )
  13246. {
  13247. 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);
  13248. }
  13249. else
  13250. {
  13251. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13252. }
  13253. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13254. fprintf(fp, "\n");
  13255. fclose(fp);
  13256. }
  13257. else
  13258. {
  13259. ShowError("Failed to write '%s'.\n", packet_txt);
  13260. // Dump on console instead
  13261. if( sd )
  13262. {
  13263. 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);
  13264. }
  13265. else
  13266. {
  13267. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13268. }
  13269. ShowDump(RFIFOP(fd,0), packet_len);
  13270. }
  13271. }
  13272. #endif
  13273. RFIFOSKIP(fd, packet_len);
  13274. }; // main loop end
  13275. return 0;
  13276. }
  13277. /*==========================================
  13278. * Reads packet_db.txt and setups its array reference
  13279. *------------------------------------------*/
  13280. static int packetdb_readdb(void)
  13281. {
  13282. FILE *fp;
  13283. char line[1024];
  13284. int ln=0;
  13285. int cmd,i,j,packet_ver;
  13286. int max_cmd=-1;
  13287. int skip_ver = 0;
  13288. int warned = 0;
  13289. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13290. int packet_len_table[MAX_PACKET_DB] = {
  13291. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. //#0x0040
  13296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13298. #if PACKETVER <= 20081217
  13299. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13300. #else
  13301. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13302. #endif
  13303. #if PACKETVER < 2
  13304. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13305. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  13306. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13307. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13308. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13309. #else
  13310. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13311. #endif
  13312. //#0x0080
  13313. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13314. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13315. #if PACKETVER <= 20100622
  13316. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13317. #else
  13318. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13319. #endif
  13320. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13321. //#0x00C0
  13322. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13323. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13324. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13325. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13326. //#0x0100
  13327. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13328. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13329. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13330. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13331. //#0x0140
  13332. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13333. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13334. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13335. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13336. //#0x0180
  13337. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13338. #if PACKETVER < 1
  13339. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13340. #else // 196 comodo以降 状態表示アイコン用
  13341. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13342. #endif
  13343. #if PACKETVER < 20081126
  13344. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13345. #else // 0x1a2 changed (35->37)
  13346. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13347. #endif
  13348. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13349. //#0x01C0, Set 0x1d5=-1
  13350. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13351. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13352. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13353. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13354. //#0x0200
  13355. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13356. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13357. #if PACKETVER < 20071106
  13358. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13359. #else // 0x22c changed
  13360. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13361. #endif
  13362. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, -1, -1, 4, 2,
  13363. //#0x0240
  13364. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13365. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13366. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13367. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13368. //#0x0280
  13369. #if PACKETVER < 20070711
  13370. 0, 0, 0, 6, 0, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  13371. #else
  13372. 0, 0, 0, 6, 0, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13373. #endif
  13374. 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13376. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
  13377. //#0x02C0
  13378. 0, 0, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13379. 0, 0, 0, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 0,
  13380. 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 59, 60, 8,
  13381. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13382. //#0x0300
  13383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13387. //#0x0340
  13388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13392. //#0x0380
  13393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13397. //#0x03C0
  13398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13402. //#0x0400
  13403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  13407. //#0x0440
  13408. 0, 4, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13412. //#0x0480
  13413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13417. //#0x04C0
  13418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13422. //#0x0500
  13423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13427. //#0x0540
  13428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13432. //#0x0580
  13433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13437. //#0x05C0
  13438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13442. //#0x0600
  13443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13447. //#0x0640
  13448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13452. //#0x0680
  13453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13457. //#0x06C0
  13458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13462. //#0x0700
  13463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  13467. //#0x0740
  13468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13472. //#0x0780
  13473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13477. //#0x07C0
  13478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13479. #if PACKETVER < 20090617
  13480. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  13481. #else // 0x7d9 changed
  13482. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  13483. #endif
  13484. 0, 15, 0, 0, 0, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  13485. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  13486. //#0x0800
  13487. #if PACKETVER < 20091229
  13488. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  13489. #else // for Party booking ( PACKETVER >= 20091229 )
  13490. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  13491. #endif
  13492. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  13493. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13494. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  13495. //#0x0840
  13496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13497. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  13498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13500. };
  13501. struct {
  13502. void (*func)(int, struct map_session_data *);
  13503. char *name;
  13504. } clif_parse_func[]={
  13505. {clif_parse_WantToConnection,"wanttoconnection"},
  13506. {clif_parse_LoadEndAck,"loadendack"},
  13507. {clif_parse_TickSend,"ticksend"},
  13508. {clif_parse_WalkToXY,"walktoxy"},
  13509. {clif_parse_QuitGame,"quitgame"},
  13510. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  13511. {clif_parse_GlobalMessage,"globalmessage"},
  13512. {clif_parse_MapMove,"mapmove"},
  13513. {clif_parse_ChangeDir,"changedir"},
  13514. {clif_parse_Emotion,"emotion"},
  13515. {clif_parse_HowManyConnections,"howmanyconnections"},
  13516. {clif_parse_ActionRequest,"actionrequest"},
  13517. {clif_parse_Restart,"restart"},
  13518. {clif_parse_WisMessage,"wis"},
  13519. {clif_parse_Broadcast,"broadcast"},
  13520. {clif_parse_TakeItem,"takeitem"},
  13521. {clif_parse_DropItem,"dropitem"},
  13522. {clif_parse_UseItem,"useitem"},
  13523. {clif_parse_EquipItem,"equipitem"},
  13524. {clif_parse_UnequipItem,"unequipitem"},
  13525. {clif_parse_NpcClicked,"npcclicked"},
  13526. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  13527. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  13528. {clif_parse_NpcSellListSend,"npcselllistsend"},
  13529. {clif_parse_CreateChatRoom,"createchatroom"},
  13530. {clif_parse_ChatAddMember,"chataddmember"},
  13531. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  13532. {clif_parse_ChangeChatOwner,"changechatowner"},
  13533. {clif_parse_KickFromChat,"kickfromchat"},
  13534. {clif_parse_ChatLeave,"chatleave"},
  13535. {clif_parse_TradeRequest,"traderequest"},
  13536. {clif_parse_TradeAck,"tradeack"},
  13537. {clif_parse_TradeAddItem,"tradeadditem"},
  13538. {clif_parse_TradeOk,"tradeok"},
  13539. {clif_parse_TradeCancel,"tradecancel"},
  13540. {clif_parse_TradeCommit,"tradecommit"},
  13541. {clif_parse_StopAttack,"stopattack"},
  13542. {clif_parse_PutItemToCart,"putitemtocart"},
  13543. {clif_parse_GetItemFromCart,"getitemfromcart"},
  13544. {clif_parse_RemoveOption,"removeoption"},
  13545. {clif_parse_ChangeCart,"changecart"},
  13546. {clif_parse_StatusUp,"statusup"},
  13547. {clif_parse_SkillUp,"skillup"},
  13548. {clif_parse_UseSkillToId,"useskilltoid"},
  13549. {clif_parse_UseSkillToPos,"useskilltopos"},
  13550. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  13551. {clif_parse_UseSkillMap,"useskillmap"},
  13552. {clif_parse_RequestMemo,"requestmemo"},
  13553. {clif_parse_ProduceMix,"producemix"},
  13554. {clif_parse_Cooking,"cooking"},
  13555. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  13556. {clif_parse_NpcNextClicked,"npcnextclicked"},
  13557. {clif_parse_NpcAmountInput,"npcamountinput"},
  13558. {clif_parse_NpcStringInput,"npcstringinput"},
  13559. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  13560. {clif_parse_ItemIdentify,"itemidentify"},
  13561. {clif_parse_SelectArrow,"selectarrow"},
  13562. {clif_parse_AutoSpell,"autospell"},
  13563. {clif_parse_UseCard,"usecard"},
  13564. {clif_parse_InsertCard,"insertcard"},
  13565. {clif_parse_RepairItem,"repairitem"},
  13566. {clif_parse_WeaponRefine,"weaponrefine"},
  13567. {clif_parse_SolveCharName,"solvecharname"},
  13568. {clif_parse_ResetChar,"resetchar"},
  13569. {clif_parse_LocalBroadcast,"localbroadcast"},
  13570. {clif_parse_MoveToKafra,"movetokafra"},
  13571. {clif_parse_MoveFromKafra,"movefromkafra"},
  13572. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  13573. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  13574. {clif_parse_CloseKafra,"closekafra"},
  13575. {clif_parse_CreateParty,"createparty"},
  13576. {clif_parse_CreateParty2,"createparty2"},
  13577. {clif_parse_PartyInvite,"partyinvite"},
  13578. {clif_parse_PartyInvite2,"partyinvite2"},
  13579. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  13580. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  13581. {clif_parse_LeaveParty,"leaveparty"},
  13582. {clif_parse_RemovePartyMember,"removepartymember"},
  13583. {clif_parse_PartyChangeOption,"partychangeoption"},
  13584. {clif_parse_PartyMessage,"partymessage"},
  13585. {clif_parse_PartyChangeLeader,"partychangeleader"},
  13586. {clif_parse_CloseVending,"closevending"},
  13587. {clif_parse_VendingListReq,"vendinglistreq"},
  13588. {clif_parse_PurchaseReq,"purchasereq"},
  13589. {clif_parse_PurchaseReq2,"purchasereq2"},
  13590. {clif_parse_OpenVending,"openvending"},
  13591. {clif_parse_CreateGuild,"createguild"},
  13592. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  13593. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  13594. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  13595. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  13596. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  13597. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  13598. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  13599. {clif_parse_GuildInvite,"guildinvite"},
  13600. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  13601. {clif_parse_GuildLeave,"guildleave"},
  13602. {clif_parse_GuildExpulsion,"guildexpulsion"},
  13603. {clif_parse_GuildMessage,"guildmessage"},
  13604. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  13605. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  13606. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  13607. {clif_parse_GuildOpposition,"guildopposition"},
  13608. {clif_parse_GuildBreak,"guildbreak"},
  13609. {clif_parse_PetMenu,"petmenu"},
  13610. {clif_parse_CatchPet,"catchpet"},
  13611. {clif_parse_SelectEgg,"selectegg"},
  13612. {clif_parse_SendEmotion,"sendemotion"},
  13613. {clif_parse_ChangePetName,"changepetname"},
  13614. {clif_parse_GMKick,"gmkick"},
  13615. {clif_parse_GMHide,"gmhide"},
  13616. {clif_parse_GMReqNoChat,"gmreqnochat"},
  13617. {clif_parse_GMReqAccountName,"gmreqaccname"},
  13618. {clif_parse_GMKickAll,"killall"},
  13619. {clif_parse_GMRecall,"recall"},
  13620. {clif_parse_GMRecall,"summon"},
  13621. {clif_parse_GM_Monster_Item,"itemmonster"},
  13622. {clif_parse_GMShift,"remove"},
  13623. {clif_parse_GMShift,"shift"},
  13624. {clif_parse_GMChangeMapType,"changemaptype"},
  13625. {clif_parse_GMRc,"rc"},
  13626. {clif_parse_GMRecall2,"recall2"},
  13627. {clif_parse_GMRemove2,"remove2"},
  13628. {clif_parse_NoviceDoriDori,"sndoridori"},
  13629. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  13630. {clif_parse_PMIgnore,"wisexin"},
  13631. {clif_parse_PMIgnoreList,"wisexlist"},
  13632. {clif_parse_PMIgnoreAll,"wisall"},
  13633. {clif_parse_FriendsListAdd,"friendslistadd"},
  13634. {clif_parse_FriendsListRemove,"friendslistremove"},
  13635. {clif_parse_FriendsListReply,"friendslistreply"},
  13636. {clif_parse_Blacksmith,"blacksmith"},
  13637. {clif_parse_Alchemist,"alchemist"},
  13638. {clif_parse_Taekwon,"taekwon"},
  13639. {clif_parse_RankingPk,"rankingpk"},
  13640. {clif_parse_FeelSaveOk,"feelsaveok"},
  13641. {clif_parse_debug,"debug"},
  13642. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  13643. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  13644. {clif_parse_HomMoveTo,"hommoveto"},
  13645. {clif_parse_HomAttack,"homattack"},
  13646. {clif_parse_HomMenu,"hommenu"},
  13647. {clif_parse_StoragePassword,"storagepassword"},
  13648. {clif_parse_Hotkey,"hotkey"},
  13649. {clif_parse_AutoRevive,"autorevive"},
  13650. {clif_parse_Check,"check"},
  13651. {clif_parse_Adopt_request,"adoptrequest"},
  13652. {clif_parse_Adopt_reply,"adoptreply"},
  13653. #ifndef TXT_ONLY
  13654. // MAIL SYSTEM
  13655. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  13656. {clif_parse_Mail_read,"mailread"},
  13657. {clif_parse_Mail_getattach,"mailgetattach"},
  13658. {clif_parse_Mail_delete,"maildelete"},
  13659. {clif_parse_Mail_return,"mailreturn"},
  13660. {clif_parse_Mail_setattach,"mailsetattach"},
  13661. {clif_parse_Mail_winopen,"mailwinopen"},
  13662. {clif_parse_Mail_send,"mailsend"},
  13663. // AUCTION SYSTEM
  13664. {clif_parse_Auction_search,"auctionsearch"},
  13665. {clif_parse_Auction_buysell,"auctionbuysell"},
  13666. {clif_parse_Auction_setitem,"auctionsetitem"},
  13667. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  13668. {clif_parse_Auction_register,"auctionregister"},
  13669. {clif_parse_Auction_cancel,"auctioncancel"},
  13670. {clif_parse_Auction_close,"auctionclose"},
  13671. {clif_parse_Auction_bid,"auctionbid"},
  13672. // Quest Log System
  13673. {clif_parse_questStateAck,"queststate"},
  13674. #endif
  13675. {clif_parse_cashshop_buy,"cashshopbuy"},
  13676. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  13677. {clif_parse_EquipTick,"equiptickbox"},
  13678. {clif_parse_BattleChat,"battlechat"},
  13679. {clif_parse_mercenary_action,"mermenu"},
  13680. {clif_parse_progressbar,"progressbar"},
  13681. #if PACKETVER >= 20091229
  13682. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  13683. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  13684. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  13685. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  13686. #endif
  13687. {clif_parse_PVPInfo,"pvpinfo"},
  13688. {clif_parse_LessEffect,"lesseffect"},
  13689. // Buying Store
  13690. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  13691. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  13692. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  13693. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  13694. // Store Search
  13695. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  13696. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  13697. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  13698. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  13699. {NULL,NULL}
  13700. };
  13701. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  13702. memset(packet_db,0,sizeof(packet_db));
  13703. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  13704. packet_len(i) = packet_len_table[i];
  13705. sprintf(line, "%s/packet_db.txt", db_path);
  13706. if( (fp=fopen(line,"r"))==NULL ){
  13707. ShowFatalError("can't read %s\n", line);
  13708. exit(EXIT_FAILURE);
  13709. }
  13710. clif_config.packet_db_ver = MAX_PACKET_VER;
  13711. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  13712. while( fgets(line, sizeof(line), fp) )
  13713. {
  13714. ln++;
  13715. if(line[0]=='/' && line[1]=='/')
  13716. continue;
  13717. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  13718. {
  13719. if(strcmpi(w1,"packet_ver")==0) {
  13720. int prev_ver = packet_ver;
  13721. skip_ver = 0;
  13722. packet_ver = atoi(w2);
  13723. if ( packet_ver > MAX_PACKET_VER )
  13724. { //Check to avoid overflowing. [Skotlex]
  13725. if( (warned&1) == 0 )
  13726. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  13727. warned &= 1;
  13728. skip_ver = 1;
  13729. }
  13730. else if( packet_ver < 0 )
  13731. {
  13732. if( (warned&2) == 0 )
  13733. ShowWarning("Negative packet versions are not supported.\n");
  13734. warned &= 2;
  13735. skip_ver = 1;
  13736. }
  13737. else if( packet_ver == SERVER )
  13738. {
  13739. if( (warned&4) == 0 )
  13740. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  13741. warned &= 4;
  13742. skip_ver = 1;
  13743. }
  13744. if( skip_ver )
  13745. {
  13746. ShowWarning("Skipping packet version %d.\n", packet_ver);
  13747. packet_ver = prev_ver;
  13748. continue;
  13749. }
  13750. // copy from previous version into new version and continue
  13751. // - indicating all following packets should be read into the newer version
  13752. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  13753. continue;
  13754. } else if(strcmpi(w1,"packet_db_ver")==0) {
  13755. if(strcmpi(w2,"default")==0) //This is the preferred version.
  13756. clif_config.packet_db_ver = MAX_PACKET_VER;
  13757. else // to manually set the packet DB version
  13758. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  13759. continue;
  13760. }
  13761. }
  13762. if( skip_ver != 0 )
  13763. continue; // Skipping current packet version
  13764. memset(str,0,sizeof(str));
  13765. for(j=0,p=line;j<4 && p; ++j)
  13766. {
  13767. str[j]=p;
  13768. p=strchr(p,',');
  13769. if(p) *p++=0;
  13770. }
  13771. if(str[0]==NULL)
  13772. continue;
  13773. cmd=strtol(str[0],(char **)NULL,0);
  13774. if(max_cmd < cmd)
  13775. max_cmd = cmd;
  13776. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  13777. continue;
  13778. if(str[1]==NULL){
  13779. ShowError("packet_db: packet len error\n");
  13780. continue;
  13781. }
  13782. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  13783. if(str[2]==NULL){
  13784. packet_db[packet_ver][cmd].func = NULL;
  13785. ln++;
  13786. continue;
  13787. }
  13788. // look up processing function by name
  13789. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  13790. if( j < ARRAYLENGTH(clif_parse_func) )
  13791. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  13792. // set the identifying cmd for the packet_db version
  13793. if (strcmp(str[2],"wanttoconnection")==0)
  13794. clif_config.connect_cmd[packet_ver] = cmd;
  13795. if(str[3]==NULL){
  13796. ShowError("packet_db: packet error\n");
  13797. exit(EXIT_FAILURE);
  13798. }
  13799. for(j=0,p2=str[3];p2;j++){
  13800. short k;
  13801. str2[j]=p2;
  13802. p2=strchr(p2,':');
  13803. if(p2) *p2++=0;
  13804. k = atoi(str2[j]);
  13805. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  13806. if( j >= MAX_PACKET_POS )
  13807. {
  13808. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  13809. break;
  13810. }
  13811. packet_db[packet_ver][cmd].pos[j] = k;
  13812. }
  13813. }
  13814. fclose(fp);
  13815. if(max_cmd > MAX_PACKET_DB)
  13816. {
  13817. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  13818. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  13819. }
  13820. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  13821. { //Locate the nearest version that we still support. [Skotlex]
  13822. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  13823. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  13824. }
  13825. 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);
  13826. return 0;
  13827. }
  13828. /*==========================================
  13829. *
  13830. *------------------------------------------*/
  13831. int do_init_clif(void)
  13832. {
  13833. clif_config.packet_db_ver = -1; // the main packet version of the DB
  13834. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  13835. memset(packet_db,0,sizeof(packet_db));
  13836. //Using the packet_db file is the only way to set up packets now [Skotlex]
  13837. packetdb_readdb();
  13838. set_defaultparse(clif_parse);
  13839. if( make_listen_bind(bind_ip,map_port) == -1 )
  13840. {
  13841. ShowFatalError("can't bind game port\n");
  13842. exit(EXIT_FAILURE);
  13843. }
  13844. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  13845. add_timer_func_list(clif_delayquit, "clif_delayquit");
  13846. return 0;
  13847. }