clif.c 414 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315
  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/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "intif.h"
  25. #include "battle.h"
  26. #include "battleground.h"
  27. #include "mob.h"
  28. #include "party.h"
  29. #include "unit.h"
  30. #include "guild.h"
  31. #include "vending.h"
  32. #include "pet.h"
  33. #include "homunculus.h"
  34. #include "instance.h"
  35. #include "mercenary.h"
  36. #include "log.h"
  37. #include "clif.h"
  38. #include "mail.h"
  39. #include "quest.h"
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <stdarg.h>
  44. #include <time.h>
  45. //#define DUMP_UNKNOWN_PACKET
  46. //#define DUMP_INVALID_PACKET
  47. struct Clif_Config {
  48. int packet_db_ver; //Preferred packet version.
  49. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  50. } clif_config;
  51. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  52. //Converts item type in case of pet eggs.
  53. inline int itemtype(int type)
  54. {
  55. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  56. }
  57. #define WBUFPOS(p,pos,x,y,dir) \
  58. do { \
  59. uint8 *__p = (p); \
  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. } while(0)
  65. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  66. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  67. do { \
  68. uint8 *__p = (p); \
  69. __p+=(pos); \
  70. __p[0]=(uint8)((x0)>>2); \
  71. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  72. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  73. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  74. __p[4]=(uint8)(y1); \
  75. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  76. } while(0)
  77. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  78. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  79. //To idenfity disguised characters.
  80. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  81. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  82. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  83. static char map_ip_str[128];
  84. static uint32 map_ip;
  85. static uint32 bind_ip = INADDR_ANY;
  86. static uint16 map_port = 5121;
  87. int map_fd;
  88. int clif_parse (int fd);
  89. /*==========================================
  90. * map鯖のip設定
  91. *------------------------------------------*/
  92. int clif_setip(const char* ip)
  93. {
  94. char ip_str[16];
  95. map_ip = host2ip(ip);
  96. if (!map_ip) {
  97. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  98. return 0;
  99. }
  100. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  101. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  102. return 1;
  103. }
  104. void clif_setbindip(const char* ip)
  105. {
  106. char ip_str[16];
  107. bind_ip = host2ip(ip);
  108. if (bind_ip) {
  109. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  110. } else {
  111. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  112. }
  113. }
  114. /*==========================================
  115. * map鯖のport設定
  116. *------------------------------------------*/
  117. void clif_setport(uint16 port)
  118. {
  119. map_port = port;
  120. }
  121. /*==========================================
  122. * map鯖のip読み出し
  123. *------------------------------------------*/
  124. uint32 clif_getip(void)
  125. {
  126. return map_ip;
  127. }
  128. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  129. uint32 clif_refresh_ip(void)
  130. {
  131. uint32 new_ip;
  132. new_ip = host2ip(map_ip_str);
  133. if (new_ip && new_ip != map_ip) {
  134. map_ip = new_ip;
  135. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  136. return map_ip;
  137. }
  138. return 0;
  139. }
  140. /*==========================================
  141. * map鯖のport読み出し
  142. *------------------------------------------*/
  143. uint16 clif_getport(void)
  144. {
  145. return map_port;
  146. }
  147. #if PACKETVER >= 20071106
  148. static inline unsigned char clif_bl_type(struct block_list *bl) {
  149. switch (bl->type) {
  150. case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
  151. case BL_ITEM: return 0x2; //ITEM_TYPE
  152. case BL_SKILL: return 0x3; //SKILL_TYPE
  153. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  154. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  155. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  156. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  157. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  158. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  159. // case BL_ELEM: return 0xA; //NPC_ELEMENTAL_TYPE
  160. default: return 0x1; //NPC_TYPE
  161. }
  162. }
  163. #endif
  164. /*==========================================
  165. * clif_sendでAREA*指定時用
  166. *------------------------------------------*/
  167. int clif_send_sub(struct block_list *bl, va_list ap)
  168. {
  169. struct block_list *src_bl;
  170. struct map_session_data *sd;
  171. unsigned char *buf;
  172. int len, type, fd;
  173. nullpo_ret(bl);
  174. nullpo_ret(sd = (struct map_session_data *)bl);
  175. fd = sd->fd;
  176. if (!fd) //Don't send to disconnected clients.
  177. return 0;
  178. buf = va_arg(ap,unsigned char*);
  179. len = va_arg(ap,int);
  180. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  181. type = va_arg(ap,int);
  182. switch(type)
  183. {
  184. case AREA_WOS:
  185. if (bl == src_bl)
  186. return 0;
  187. break;
  188. case AREA_WOC:
  189. if (sd->chatID || bl == src_bl)
  190. return 0;
  191. break;
  192. case AREA_WOSC:
  193. {
  194. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  195. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  196. return 0;
  197. }
  198. break;
  199. }
  200. if (session[fd] == NULL)
  201. return 0;
  202. WFIFOHEAD(fd, len);
  203. if (WFIFOP(fd,0) == buf) {
  204. ShowError("WARNING: Invalid use of clif_send function\n");
  205. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  206. ShowError(" Please correct your code.\n");
  207. // don't send to not move the pointer of the packet for next sessions in the loop
  208. //WFIFOSET(fd,0);//## TODO is this ok?
  209. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  210. return 0;
  211. }
  212. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  213. memcpy(WFIFOP(fd,0), buf, len);
  214. WFIFOSET(fd,len);
  215. }
  216. return 0;
  217. }
  218. /*==========================================
  219. *
  220. *------------------------------------------*/
  221. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  222. {
  223. int i;
  224. struct map_session_data *sd, *tsd;
  225. struct party_data *p = NULL;
  226. struct guild *g = NULL;
  227. struct battleground_data *bg = NULL;
  228. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  229. struct s_mapiterator* iter;
  230. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  231. nullpo_ret(bl);
  232. sd = BL_CAST(BL_PC, bl);
  233. switch(type) {
  234. case ALL_CLIENT: //All player clients.
  235. iter = mapit_getallusers();
  236. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  237. {
  238. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  239. { // packet must exist for the client version
  240. WFIFOHEAD(tsd->fd, len);
  241. memcpy(WFIFOP(tsd->fd,0), buf, len);
  242. WFIFOSET(tsd->fd,len);
  243. }
  244. }
  245. mapit_free(iter);
  246. break;
  247. case ALL_SAMEMAP: //All players on the same map
  248. iter = mapit_getallusers();
  249. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  250. {
  251. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  252. { // packet must exist for the client version
  253. WFIFOHEAD(tsd->fd, len);
  254. memcpy(WFIFOP(tsd->fd,0), buf, len);
  255. WFIFOSET(tsd->fd,len);
  256. }
  257. }
  258. mapit_free(iter);
  259. break;
  260. case AREA:
  261. case AREA_WOSC:
  262. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  263. clif_send (buf, len, bl, SELF);
  264. case AREA_WOC:
  265. case AREA_WOS:
  266. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  267. BL_PC, buf, len, bl, type);
  268. break;
  269. case AREA_CHAT_WOC:
  270. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  271. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  272. break;
  273. case CHAT:
  274. case CHAT_WOS:
  275. {
  276. struct chat_data *cd;
  277. if (sd) {
  278. cd = (struct chat_data*)map_id2bl(sd->chatID);
  279. } else if (bl->type == BL_CHAT) {
  280. cd = (struct chat_data*)bl;
  281. } else break;
  282. if (cd == NULL)
  283. break;
  284. for(i = 0; i < cd->users; i++) {
  285. if (type == CHAT_WOS && cd->usersd[i] == sd)
  286. continue;
  287. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  288. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  289. {
  290. WFIFOHEAD(fd,len);
  291. memcpy(WFIFOP(fd,0), buf, len);
  292. WFIFOSET(fd,len);
  293. }
  294. }
  295. }
  296. }
  297. break;
  298. case CHAT_MAINCHAT: //[LuzZza]
  299. iter = mapit_getallusers();
  300. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  301. {
  302. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  303. { // packet must exist for the client version
  304. WFIFOHEAD(tsd->fd, len);
  305. memcpy(WFIFOP(tsd->fd,0), buf, len);
  306. WFIFOSET(tsd->fd,len);
  307. }
  308. }
  309. mapit_free(iter);
  310. break;
  311. case PARTY_AREA:
  312. case PARTY_AREA_WOS:
  313. x0 = bl->x - AREA_SIZE;
  314. y0 = bl->y - AREA_SIZE;
  315. x1 = bl->x + AREA_SIZE;
  316. y1 = bl->y + AREA_SIZE;
  317. case PARTY:
  318. case PARTY_WOS:
  319. case PARTY_SAMEMAP:
  320. case PARTY_SAMEMAP_WOS:
  321. if (sd && sd->status.party_id)
  322. p = party_search(sd->status.party_id);
  323. if (p) {
  324. for(i=0;i<MAX_PARTY;i++){
  325. if( (sd = p->data[i].sd) == NULL )
  326. continue;
  327. if( !(fd=sd->fd) )
  328. continue;
  329. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  330. continue;
  331. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  332. continue;
  333. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  334. continue;
  335. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  336. { // packet must exist for the client version
  337. WFIFOHEAD(fd,len);
  338. memcpy(WFIFOP(fd,0), buf, len);
  339. WFIFOSET(fd,len);
  340. }
  341. }
  342. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  343. break;
  344. iter = mapit_getallusers();
  345. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  346. {
  347. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  348. { // packet must exist for the client version
  349. WFIFOHEAD(tsd->fd, len);
  350. memcpy(WFIFOP(tsd->fd,0), buf, len);
  351. WFIFOSET(tsd->fd,len);
  352. }
  353. }
  354. mapit_free(iter);
  355. }
  356. break;
  357. case DUEL:
  358. case DUEL_WOS:
  359. if (!sd || !sd->duel_group) break; //Invalid usage.
  360. iter = mapit_getallusers();
  361. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  362. {
  363. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  364. continue;
  365. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  366. { // packet must exist for the client version
  367. WFIFOHEAD(tsd->fd, len);
  368. memcpy(WFIFOP(tsd->fd,0), buf, len);
  369. WFIFOSET(tsd->fd,len);
  370. }
  371. }
  372. mapit_free(iter);
  373. break;
  374. case SELF:
  375. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  376. WFIFOHEAD(fd,len);
  377. memcpy(WFIFOP(fd,0), buf, len);
  378. WFIFOSET(fd,len);
  379. }
  380. break;
  381. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  382. case GUILD_AREA:
  383. case GUILD_AREA_WOS:
  384. x0 = bl->x - AREA_SIZE;
  385. y0 = bl->y - AREA_SIZE;
  386. x1 = bl->x + AREA_SIZE;
  387. y1 = bl->y + AREA_SIZE;
  388. case GUILD_SAMEMAP:
  389. case GUILD_SAMEMAP_WOS:
  390. case GUILD:
  391. case GUILD_WOS:
  392. case GUILD_NOBG:
  393. if (sd && sd->status.guild_id)
  394. g = guild_search(sd->status.guild_id);
  395. if (g) {
  396. for(i = 0; i < g->max_member; i++) {
  397. if( (sd = g->member[i].sd) != NULL )
  398. {
  399. if( !(fd=sd->fd) )
  400. continue;
  401. if( type == GUILD_NOBG && sd->state.bg_id )
  402. continue;
  403. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  404. continue;
  405. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  406. continue;
  407. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  408. continue;
  409. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  410. { // packet must exist for the client version
  411. WFIFOHEAD(fd,len);
  412. memcpy(WFIFOP(fd,0), buf, len);
  413. WFIFOSET(fd,len);
  414. }
  415. }
  416. }
  417. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  418. break;
  419. iter = mapit_getallusers();
  420. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  421. {
  422. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  423. { // packet must exist for the client version
  424. WFIFOHEAD(tsd->fd, len);
  425. memcpy(WFIFOP(tsd->fd,0), buf, len);
  426. WFIFOSET(tsd->fd,len);
  427. }
  428. }
  429. mapit_free(iter);
  430. }
  431. break;
  432. case BG_AREA:
  433. case BG_AREA_WOS:
  434. x0 = bl->x - AREA_SIZE;
  435. y0 = bl->y - AREA_SIZE;
  436. x1 = bl->x + AREA_SIZE;
  437. y1 = bl->y + AREA_SIZE;
  438. case BG_SAMEMAP:
  439. case BG_SAMEMAP_WOS:
  440. case BG:
  441. case BG_WOS:
  442. if( sd && sd->state.bg_id && (bg = bg_team_search(sd->state.bg_id)) != NULL )
  443. {
  444. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  445. {
  446. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  447. continue;
  448. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  449. continue;
  450. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  451. continue;
  452. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  453. continue;
  454. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  455. { // packet must exist for the client version
  456. WFIFOHEAD(fd,len);
  457. memcpy(WFIFOP(fd,0), buf, len);
  458. WFIFOSET(fd,len);
  459. }
  460. }
  461. }
  462. break;
  463. default:
  464. ShowError("clif_send: Unrecognized type %d\n",type);
  465. return -1;
  466. }
  467. return 0;
  468. }
  469. //
  470. // パケット作って送信
  471. //
  472. /*==========================================
  473. *
  474. *------------------------------------------*/
  475. int clif_authok(struct map_session_data *sd)
  476. {
  477. int fd;
  478. if (!sd->fd)
  479. return 0;
  480. fd = sd->fd;
  481. WFIFOHEAD(fd, packet_len(0x73));
  482. WFIFOW(fd, 0) = 0x73;
  483. WFIFOL(fd, 2) = gettick();
  484. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  485. WFIFOB(fd, 9) = 5; // ignored
  486. WFIFOB(fd,10) = 5; // ignored
  487. WFIFOSET(fd,packet_len(0x73));
  488. return 0;
  489. }
  490. /*==========================================
  491. * Authentication failed/disconnect client.
  492. *------------------------------------------
  493. * The client closes it's socket and displays a message according to type:
  494. * 1 - server closed -> MsgStringTable[4]
  495. * 2 - ID already logged in -> MsgStringTable[5]
  496. * 3 - timeout/too much lag -> MsgStringTable[241]
  497. * 4 - server full -> MsgStringTable[264]
  498. * 5 - underaged -> MsgStringTable[305]
  499. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  500. * 9 - too many connections from this ip -> MsgStringTable[529]
  501. * 10 - out of available time paid for -> MsgStringTable[530]
  502. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  503. * other - disconnected -> MsgStringTable[3]
  504. */
  505. int clif_authfail_fd(int fd, int type)
  506. {
  507. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  508. return 0;
  509. WFIFOHEAD(fd, packet_len(0x81));
  510. WFIFOW(fd,0) = 0x81;
  511. WFIFOB(fd,2) = type;
  512. WFIFOSET(fd,packet_len(0x81));
  513. set_eof(fd);
  514. return 0;
  515. }
  516. /*==========================================
  517. *
  518. *------------------------------------------*/
  519. int clif_charselectok(int id)
  520. {
  521. struct map_session_data* sd;
  522. int fd;
  523. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  524. return 1;
  525. fd = sd->fd;
  526. WFIFOHEAD(fd,packet_len(0xb3));
  527. WFIFOW(fd,0) = 0xb3;
  528. WFIFOB(fd,2) = 1;
  529. WFIFOSET(fd,packet_len(0xb3));
  530. return 0;
  531. }
  532. /*==========================================
  533. * Makes an item appear on the ground
  534. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  535. *------------------------------------------*/
  536. int clif_dropflooritem(struct flooritem_data* fitem)
  537. {
  538. uint8 buf[17];
  539. int view;
  540. nullpo_ret(fitem);
  541. if (fitem->item_data.nameid <= 0)
  542. return 0;
  543. WBUFW(buf, 0) = 0x9e;
  544. WBUFL(buf, 2) = fitem->bl.id;
  545. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  546. WBUFB(buf, 8) = fitem->item_data.identify;
  547. WBUFW(buf, 9) = fitem->bl.x;
  548. WBUFW(buf,11) = fitem->bl.y;
  549. WBUFB(buf,13) = fitem->subx;
  550. WBUFB(buf,14) = fitem->suby;
  551. WBUFW(buf,15) = fitem->item_data.amount;
  552. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  553. return 0;
  554. }
  555. /*==========================================
  556. *
  557. *------------------------------------------*/
  558. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  559. {
  560. unsigned char buf[16];
  561. nullpo_ret(fitem);
  562. WBUFW(buf,0) = 0xa1;
  563. WBUFL(buf,2) = fitem->bl.id;
  564. if (fd == 0) {
  565. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  566. } else {
  567. WFIFOHEAD(fd,packet_len(0xa1));
  568. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  569. WFIFOSET(fd,packet_len(0xa1));
  570. }
  571. return 0;
  572. }
  573. /*==========================================
  574. * make a unit (char, npc, mob, homun) disappear to one client
  575. * id : the id of the unit
  576. * type: 0 - moved out of sight
  577. * 1 - died
  578. * 2 - respawned
  579. * 3 - teleported / logged out
  580. * fd : the target client
  581. *------------------------------------------*/
  582. int clif_clearunit_single(int id, clr_type type, int fd)
  583. {
  584. WFIFOHEAD(fd, packet_len(0x80));
  585. WFIFOW(fd,0) = 0x80;
  586. WFIFOL(fd,2) = id;
  587. WFIFOB(fd,6) = type;
  588. WFIFOSET(fd, packet_len(0x80));
  589. return 0;
  590. }
  591. /*==========================================
  592. * make a unit (char, npc, mob, homun) disappear to all clients in area
  593. * type: 0 - moved out of sight
  594. * 1 - died
  595. * 2 - respawned
  596. * 3 - teleported / logged out
  597. *------------------------------------------*/
  598. int clif_clearunit_area(struct block_list* bl, clr_type type)
  599. {
  600. unsigned char buf[16];
  601. nullpo_ret(bl);
  602. WBUFW(buf,0) = 0x80;
  603. WBUFL(buf,2) = bl->id;
  604. WBUFB(buf,6) = type;
  605. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  606. if(disguised(bl)) {
  607. WBUFL(buf,2) = -bl->id;
  608. clif_send(buf, packet_len(0x80), bl, SELF);
  609. }
  610. return 0;
  611. }
  612. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  613. {
  614. struct block_list *bl = (struct block_list *)data;
  615. clif_clearunit_area(bl, CLR_OUTSIGHT);
  616. aFree(bl);
  617. return 0;
  618. }
  619. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  620. {
  621. struct block_list *tbl;
  622. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  623. memcpy (tbl, bl, sizeof (struct block_list));
  624. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  625. return 0;
  626. }
  627. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  628. {
  629. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  630. {
  631. *rhand = *lhand = 0;
  632. return;
  633. }
  634. #if PACKETVER < 4
  635. *rhand = sd->status.weapon;
  636. *lhand = sd->status.shield;
  637. #else
  638. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  639. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  640. {
  641. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  642. if (id->view_id > 0)
  643. *rhand = id->view_id;
  644. else
  645. *rhand = id->nameid;
  646. } else
  647. *rhand = 0;
  648. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  649. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  650. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  651. {
  652. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  653. if (id->view_id > 0)
  654. *lhand = id->view_id;
  655. else
  656. *lhand = id->nameid;
  657. } else
  658. *lhand = 0;
  659. #endif
  660. }
  661. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  662. static int clif_setlevel(int lv)
  663. {
  664. if( lv < battle_config.max_lv )
  665. return lv;
  666. if( lv < battle_config.aura_lv )
  667. return battle_config.max_lv - 1;
  668. return battle_config.max_lv;
  669. }
  670. /*==========================================
  671. * Prepares 'unit standing/spawning' packet
  672. *------------------------------------------*/
  673. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  674. {
  675. struct map_session_data* sd;
  676. struct status_change* sc = status_get_sc(bl);
  677. struct view_data* vd = status_get_viewdata(bl);
  678. unsigned char *buf = WBUFP(buffer,0);
  679. #if PACKETVER < 20091103
  680. bool type = !pcdb_checkid(vd->class_);
  681. #endif
  682. #if PACKETVER >= 7
  683. unsigned short offset = 0;
  684. #endif
  685. #if PACKETVER >= 20091103
  686. const char *name;
  687. #endif
  688. sd = BL_CAST(BL_PC, bl);
  689. #if PACKETVER < 20091103
  690. if(type)
  691. WBUFW(buf,0) = spawn?0x7c:0x78;
  692. else
  693. #endif
  694. #if PACKETVER < 4
  695. WBUFW(buf,0) = spawn?0x79:0x78;
  696. #elif PACKETVER < 7
  697. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  698. #elif PACKETVER < 20080102
  699. WBUFW(buf,0) = spawn?0x22b:0x22a;
  700. #elif PACKETVER < 20091103
  701. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  702. #else
  703. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  704. #endif
  705. #if PACKETVER >= 20091103
  706. name = status_get_name(bl);
  707. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  708. WBUFB(buf,4) = clif_bl_type(bl);
  709. offset+=3;
  710. buf = WBUFP(buffer,offset);
  711. #elif PACKETVER >= 20071106
  712. if (type) { //Non-player packets
  713. WBUFB(buf,2) = clif_bl_type(bl);
  714. offset++;
  715. buf = WBUFP(buffer,offset);
  716. }
  717. #endif
  718. WBUFL(buf, 2) = bl->id;
  719. WBUFW(buf, 6) = status_get_speed(bl);
  720. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  721. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  722. #if PACKETVER < 20091103
  723. if (type&&spawn) { //uses an older and different packet structure
  724. WBUFW(buf,12) = (sc)? sc->option : 0;
  725. WBUFW(buf,14) = vd->hair_style;
  726. WBUFW(buf,16) = vd->weapon;
  727. WBUFW(buf,18) = vd->head_bottom;
  728. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  729. WBUFW(buf,22) = vd->shield;
  730. } else {
  731. #endif
  732. #if PACKETVER >= 20091103
  733. WBUFL(buf,12) = (sc)? sc->option : 0;
  734. offset+=2;
  735. buf = WBUFP(buffer,offset);
  736. #elif PACKETVER >= 7
  737. if (!type) {
  738. WBUFL(buf,12) = (sc)? sc->option : 0;
  739. offset+=2;
  740. buf = WBUFP(buffer,offset);
  741. } else
  742. WBUFW(buf,12) = (sc)? sc->option : 0;
  743. #else
  744. WBUFW(buf,12) = (sc)? sc->option : 0;
  745. #endif
  746. WBUFW(buf,14) = vd->class_;
  747. WBUFW(buf,16) = vd->hair_style;
  748. WBUFW(buf,18) = vd->weapon;
  749. #if PACKETVER < 4
  750. WBUFW(buf,20) = vd->head_bottom;
  751. WBUFW(buf,22) = vd->shield;
  752. #else
  753. WBUFW(buf,20) = vd->shield;
  754. WBUFW(buf,22) = vd->head_bottom;
  755. #endif
  756. #if PACKETVER < 20091103
  757. }
  758. #endif
  759. WBUFW(buf,24) = vd->head_top;
  760. WBUFW(buf,26) = vd->head_mid;
  761. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  762. { //The hell, why flags work like this?
  763. WBUFL(buf,22) = status_get_emblem_id(bl);
  764. WBUFL(buf,26) = status_get_guild_id(bl);
  765. }
  766. WBUFW(buf,28) = vd->hair_color;
  767. WBUFW(buf,30) = vd->cloth_color;
  768. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  769. #if PACKETVER < 20091103
  770. if (type&&spawn) { //End of packet 0x7c
  771. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  772. WBUFB(buf,35) = vd->sex;
  773. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  774. WBUFB(buf,39) = 0;
  775. WBUFB(buf,40) = 0;
  776. return packet_len(0x7c);
  777. }
  778. #endif
  779. WBUFL(buf,34) = status_get_guild_id(bl);
  780. WBUFW(buf,38) = status_get_emblem_id(bl);
  781. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  782. #if PACKETVER >= 20091103
  783. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  784. offset+=2;
  785. buf = WBUFP(buffer,offset);
  786. #elif PACKETVER >= 7
  787. if (!type) {
  788. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  789. offset+=2;
  790. buf = WBUFP(buffer,offset);
  791. } else
  792. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  793. #else
  794. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  795. #endif
  796. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  797. WBUFB(buf,45) = vd->sex;
  798. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  799. WBUFB(buf,49) = (sd)? 5 : 0;
  800. WBUFB(buf,50) = (sd)? 5 : 0;
  801. if (!spawn) {
  802. WBUFB(buf,51) = vd->dead_sit;
  803. offset++;
  804. buf = WBUFP(buffer,offset);
  805. }
  806. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  807. #if PACKETVER < 20091103
  808. if (type) //End for non-player packet
  809. return packet_len(WBUFW(buffer,0));
  810. #endif
  811. #if PACKETVER >= 20080102
  812. WBUFW(buf,53) = sd?sd->state.user_font:0;
  813. #endif
  814. #if PACKETVER >= 20091103
  815. strcpy((char*)WBUFP(buf,55), name);
  816. return WBUFW(buffer,2);
  817. #else
  818. return packet_len(WBUFW(buffer,0));
  819. #endif
  820. }
  821. /*==========================================
  822. * Prepares 'unit walking' packet
  823. *------------------------------------------*/
  824. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  825. {
  826. struct map_session_data* sd;
  827. struct status_change* sc = status_get_sc(bl);
  828. struct view_data* vd = status_get_viewdata(bl);
  829. unsigned char* buf = WBUFP(buffer,0);
  830. #if PACKETVER >= 7
  831. unsigned short offset = 0;
  832. #endif
  833. #if PACKETVER >= 20091103
  834. const char *name;
  835. #endif
  836. sd = BL_CAST(BL_PC, bl);
  837. #if PACKETVER < 4
  838. WBUFW(buf, 0) = 0x7b;
  839. #elif PACKETVER < 7
  840. WBUFW(buf, 0) = 0x1da;
  841. #elif PACKETVER < 20080102
  842. WBUFW(buf, 0) = 0x22c;
  843. #elif PACKETVER < 20091103
  844. WBUFW(buf, 0) = 0x2ec;
  845. #else
  846. WBUFW(buf, 0) = 0x7f7;
  847. #endif
  848. #if PACKETVER >= 20091103
  849. name = status_get_name(bl);
  850. WBUFW(buf, 2) = 69+strlen(name);
  851. offset+=2;
  852. buf = WBUFP(buffer,offset);
  853. #endif
  854. #if PACKETVER >= 20071106
  855. WBUFB(buf, 2) = clif_bl_type(bl);
  856. offset++;
  857. buf = WBUFP(buffer,offset);
  858. #endif
  859. WBUFL(buf, 2) = bl->id;
  860. WBUFW(buf, 6) = status_get_speed(bl);
  861. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  862. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  863. #if PACKETVER < 7
  864. WBUFW(buf,12) = (sc)? sc->option : 0;
  865. #else
  866. WBUFL(buf,12) = (sc)? sc->option : 0;
  867. offset+=2; //Shift the rest of elements by 2 bytes.
  868. buf = WBUFP(buffer,offset);
  869. #endif
  870. WBUFW(buf,14) = vd->class_;
  871. WBUFW(buf,16) = vd->hair_style;
  872. WBUFW(buf,18) = vd->weapon;
  873. #if PACKETVER < 4
  874. WBUFW(buf,20) = vd->head_bottom;
  875. WBUFL(buf,22) = gettick();
  876. WBUFW(buf,26) = vd->shield;
  877. #else
  878. WBUFW(buf,20) = vd->shield;
  879. WBUFW(buf,22) = vd->head_bottom;
  880. WBUFL(buf,24) = gettick();
  881. #endif
  882. WBUFW(buf,28) = vd->head_top;
  883. WBUFW(buf,30) = vd->head_mid;
  884. WBUFW(buf,32) = vd->hair_color;
  885. WBUFW(buf,34) = vd->cloth_color;
  886. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  887. WBUFL(buf,38) = status_get_guild_id(bl);
  888. WBUFW(buf,42) = status_get_emblem_id(bl);
  889. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  890. #if PACKETVER < 7
  891. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  892. #else
  893. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  894. offset+=2; //Shift the rest of elements by 2 bytes.
  895. buf = WBUFP(buffer,offset);
  896. #endif
  897. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  898. WBUFB(buf,49) = vd->sex;
  899. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  900. WBUFB(buf,56) = (sd)? 5 : 0;
  901. WBUFB(buf,57) = (sd)? 5 : 0;
  902. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  903. #if PACKETVER >= 20080102
  904. WBUFW(buf,60) = sd?sd->state.user_font:0;
  905. #endif
  906. #if PACKETVER >= 20091103
  907. strcpy((char*)WBUFP(buf,62), name);
  908. return WBUFW(buffer,2);
  909. #else
  910. return packet_len(WBUFW(buffer,0));
  911. #endif
  912. }
  913. //Modifies the buffer for disguise characters and sends it to self.
  914. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  915. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  916. {
  917. #if PACKETVER >= 20091103
  918. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  919. WBUFL(buf,5)=-bl->id;
  920. #elif PACKETVER >= 20071106
  921. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  922. WBUFL(buf,3)=-bl->id;
  923. #else
  924. WBUFL(buf,2)=-bl->id;
  925. #endif
  926. clif_send(buf, len, bl, SELF);
  927. }
  928. /*==========================================
  929. * クラスチェンジ typeはMobの場合は1で他は0?
  930. *------------------------------------------*/
  931. int clif_class_change(struct block_list *bl,int class_,int type)
  932. {
  933. unsigned char buf[16];
  934. nullpo_ret(bl);
  935. if(!pcdb_checkid(class_)) {
  936. WBUFW(buf,0)=0x1b0;
  937. WBUFL(buf,2)=bl->id;
  938. WBUFB(buf,6)=type;
  939. WBUFL(buf,7)=class_;
  940. clif_send(buf,packet_len(0x1b0),bl,AREA);
  941. }
  942. return 0;
  943. }
  944. /*==========================================
  945. *
  946. *------------------------------------------*/
  947. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  948. {
  949. WFIFOHEAD(fd, packet_len(0x1e1));
  950. WFIFOW(fd,0)=0x1e1;
  951. WFIFOL(fd,2)=sd->bl.id;
  952. WFIFOW(fd,6)=sd->spiritball;
  953. WFIFOSET(fd, packet_len(0x1e1));
  954. }
  955. /*==========================================
  956. *
  957. *------------------------------------------*/
  958. static void clif_weather_check(struct map_session_data *sd)
  959. {
  960. int m = sd->bl.m, fd = sd->fd;
  961. if (map[m].flag.snow
  962. || map[m].flag.clouds
  963. || map[m].flag.fog
  964. || map[m].flag.fireworks
  965. || map[m].flag.sakura
  966. || map[m].flag.leaves
  967. || map[m].flag.rain
  968. || map[m].flag.clouds2)
  969. {
  970. if (map[m].flag.snow)
  971. clif_specialeffect_single(&sd->bl, 162, fd);
  972. if (map[m].flag.clouds)
  973. clif_specialeffect_single(&sd->bl, 233, fd);
  974. if (map[m].flag.clouds2)
  975. clif_specialeffect_single(&sd->bl, 516, fd);
  976. if (map[m].flag.fog)
  977. clif_specialeffect_single(&sd->bl, 515, fd);
  978. if (map[m].flag.fireworks) {
  979. clif_specialeffect_single(&sd->bl, 297, fd);
  980. clif_specialeffect_single(&sd->bl, 299, fd);
  981. clif_specialeffect_single(&sd->bl, 301, fd);
  982. }
  983. if (map[m].flag.sakura)
  984. clif_specialeffect_single(&sd->bl, 163, fd);
  985. if (map[m].flag.leaves)
  986. clif_specialeffect_single(&sd->bl, 333, fd);
  987. if (map[m].flag.rain)
  988. clif_specialeffect_single(&sd->bl, 161, fd);
  989. }
  990. }
  991. void clif_weather(int m)
  992. {
  993. struct s_mapiterator* iter;
  994. struct map_session_data *sd=NULL;
  995. iter = mapit_getallusers();
  996. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  997. {
  998. if( sd->bl.m == m )
  999. clif_weather_check(sd);
  1000. }
  1001. mapit_free(iter);
  1002. }
  1003. int clif_spawn(struct block_list *bl)
  1004. {
  1005. unsigned char buf[128];
  1006. struct view_data *vd;
  1007. int len;
  1008. vd = status_get_viewdata(bl);
  1009. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1010. return 0;
  1011. len = clif_set_unit_idle(bl, buf,true);
  1012. clif_send(buf, len, bl, AREA_WOS);
  1013. if (disguised(bl))
  1014. clif_setdisguise(bl, buf, len);
  1015. if (vd->cloth_color)
  1016. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1017. switch (bl->type)
  1018. {
  1019. case BL_PC:
  1020. {
  1021. TBL_PC *sd = ((TBL_PC*)bl);
  1022. if (sd->spiritball > 0)
  1023. clif_spiritball(sd);
  1024. if(sd->state.size==2) // tiny/big players [Valaris]
  1025. clif_specialeffect(bl,423,AREA);
  1026. else if(sd->state.size==1)
  1027. clif_specialeffect(bl,421,AREA);
  1028. if( sd->state.bg_id && map[sd->bl.m].flag.battleground )
  1029. clif_sendbgemblem_area(sd);
  1030. }
  1031. break;
  1032. case BL_MOB:
  1033. {
  1034. TBL_MOB *md = ((TBL_MOB*)bl);
  1035. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1036. clif_specialeffect(&md->bl,423,AREA);
  1037. else if(md->special_state.size==1)
  1038. clif_specialeffect(&md->bl,421,AREA);
  1039. }
  1040. break;
  1041. case BL_NPC:
  1042. {
  1043. TBL_NPC *nd = ((TBL_NPC*)bl);
  1044. if( nd->size == 2 )
  1045. clif_specialeffect(&nd->bl,423,AREA);
  1046. else if( nd->size == 1 )
  1047. clif_specialeffect(&nd->bl,421,AREA);
  1048. }
  1049. break;
  1050. case BL_PET:
  1051. if (vd->head_bottom)
  1052. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1053. break;
  1054. }
  1055. return 0;
  1056. }
  1057. //[orn]
  1058. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1059. {
  1060. struct status_data *status;
  1061. unsigned char buf[128];
  1062. nullpo_ret(hd);
  1063. status = &hd->battle_status;
  1064. memset(buf,0,packet_len(0x22e));
  1065. WBUFW(buf,0)=0x22e;
  1066. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1067. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1068. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1069. WBUFW(buf,27)=hd->homunculus.level;
  1070. WBUFW(buf,29)=hd->homunculus.hunger;
  1071. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1072. WBUFW(buf,33)=0; // equip id
  1073. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1074. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1075. WBUFW(buf,39)=status->hit;
  1076. if (battle_config.hom_setting&0x10)
  1077. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1078. else
  1079. WBUFW(buf,41)=status->cri/10;
  1080. WBUFW(buf,43)=status->def + status->vit ;
  1081. WBUFW(buf,45)=status->mdef;
  1082. WBUFW(buf,47)=status->flee;
  1083. WBUFW(buf,49)=(flag)?0:status->amotion;
  1084. if (status->max_hp > SHRT_MAX) {
  1085. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1086. WBUFW(buf,53) = 100;
  1087. } else {
  1088. WBUFW(buf,51)=status->hp;
  1089. WBUFW(buf,53)=status->max_hp;
  1090. }
  1091. if (status->max_sp > SHRT_MAX) {
  1092. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1093. WBUFW(buf,57) = 100;
  1094. } else {
  1095. WBUFW(buf,55)=status->sp;
  1096. WBUFW(buf,57)=status->max_sp;
  1097. }
  1098. WBUFL(buf,59)=hd->homunculus.exp;
  1099. WBUFL(buf,63)=hd->exp_next;
  1100. WBUFW(buf,67)=hd->homunculus.skillpts;
  1101. WBUFW(buf,69)=status_get_range(&hd->bl);
  1102. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1103. return 0;
  1104. }
  1105. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1106. { //[orn]
  1107. int fd = sd->fd;
  1108. WFIFOHEAD(fd, packet_len(0x230));
  1109. nullpo_retv(sd->hd);
  1110. WFIFOW(fd,0)=0x230;
  1111. WFIFOW(fd,2)=type; // FIXME: This is actually <type>.B <state>.B
  1112. WFIFOL(fd,4)=sd->hd->bl.id;
  1113. WFIFOL(fd,8)=param;
  1114. WFIFOSET(fd,packet_len(0x230));
  1115. return;
  1116. }
  1117. int clif_homskillinfoblock(struct map_session_data *sd)
  1118. { //[orn]
  1119. struct homun_data *hd;
  1120. int fd = sd->fd;
  1121. int i,j,len=4,id;
  1122. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1123. hd = sd->hd;
  1124. if ( !hd )
  1125. return 0 ;
  1126. WFIFOW(fd,0)=0x235;
  1127. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1128. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1129. j = id - HM_SKILLBASE;
  1130. WFIFOW(fd,len ) = id;
  1131. WFIFOW(fd,len+2) = skill_get_inf(id);
  1132. WFIFOW(fd,len+4) = 0;
  1133. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1134. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1135. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1136. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1137. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1138. len+=37;
  1139. }
  1140. }
  1141. WFIFOW(fd,2)=len;
  1142. WFIFOSET(fd,len);
  1143. return 0;
  1144. }
  1145. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1146. { //[orn]
  1147. struct homun_data *hd;
  1148. int fd, skillid;
  1149. nullpo_retv(sd);
  1150. skillid = skill_num - HM_SKILLBASE;
  1151. fd=sd->fd;
  1152. hd=sd->hd;
  1153. WFIFOHEAD(fd, packet_len(0x239));
  1154. WFIFOW(fd,0) = 0x239;
  1155. WFIFOW(fd,2) = skill_num;
  1156. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1157. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1158. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1159. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1160. WFIFOSET(fd,packet_len(0x239));
  1161. return;
  1162. }
  1163. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1164. {
  1165. int fd=sd->fd;
  1166. WFIFOHEAD(fd,packet_len(0x22f));
  1167. WFIFOW(fd,0)=0x22f;
  1168. WFIFOB(fd,2)=fail;
  1169. WFIFOW(fd,3)=foodid;
  1170. WFIFOSET(fd,packet_len(0x22f));
  1171. return 0;
  1172. }
  1173. /*==========================================
  1174. *
  1175. *------------------------------------------*/
  1176. int clif_walkok(struct map_session_data *sd)
  1177. {
  1178. int fd=sd->fd;
  1179. WFIFOHEAD(fd, packet_len(0x87));
  1180. WFIFOW(fd,0)=0x87;
  1181. WFIFOL(fd,2)=gettick();
  1182. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1183. WFIFOSET(fd,packet_len(0x87));
  1184. return 0;
  1185. }
  1186. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1187. {
  1188. uint8 buf[128];
  1189. int len;
  1190. len = clif_set_unit_walking(bl,ud,buf);
  1191. clif_send(buf,len,bl,AREA_WOS);
  1192. if (disguised(bl))
  1193. clif_setdisguise(bl, buf, len);
  1194. if(vd->cloth_color)
  1195. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1196. switch(bl->type)
  1197. {
  1198. case BL_PC:
  1199. {
  1200. TBL_PC *sd = ((TBL_PC*)bl);
  1201. // clif_movepc(sd);
  1202. if(sd->state.size==2) // tiny/big players [Valaris]
  1203. clif_specialeffect(&sd->bl,423,AREA);
  1204. else if(sd->state.size==1)
  1205. clif_specialeffect(&sd->bl,421,AREA);
  1206. }
  1207. break;
  1208. case BL_MOB:
  1209. {
  1210. TBL_MOB *md = ((TBL_MOB*)bl);
  1211. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1212. clif_specialeffect(&md->bl,423,AREA);
  1213. else if(md->special_state.size==1)
  1214. clif_specialeffect(&md->bl,421,AREA);
  1215. }
  1216. break;
  1217. }
  1218. return;
  1219. }
  1220. /// Move the unit (does nothing if the client has no info about the unit)
  1221. /// Note: unit must not be self
  1222. void clif_move(struct unit_data *ud)
  1223. {
  1224. unsigned char buf[16];
  1225. struct view_data* vd;
  1226. struct block_list* bl = ud->bl;
  1227. vd = status_get_viewdata(bl);
  1228. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1229. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1230. if (ud->state.speed_changed) {
  1231. // Since we don't know how to update the speed of other objects,
  1232. // use the old walk packet to update the data.
  1233. ud->state.speed_changed = 0;
  1234. clif_move2(bl, vd, ud);
  1235. return;
  1236. }
  1237. WBUFW(buf,0)=0x86;
  1238. WBUFL(buf,2)=bl->id;
  1239. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1240. WBUFL(buf,12)=gettick();
  1241. clif_send(buf, 16, bl, AREA_WOS);
  1242. if (disguised(bl))
  1243. {
  1244. WBUFL(buf,2)=-bl->id;
  1245. clif_send(buf, 16, bl, SELF);
  1246. }
  1247. }
  1248. /*==========================================
  1249. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1250. *------------------------------------------*/
  1251. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1252. {
  1253. struct map_session_data *sd = NULL;
  1254. //Remove player from map server
  1255. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1256. map_quit(sd);
  1257. return 0;
  1258. }
  1259. /*==========================================
  1260. *
  1261. *------------------------------------------*/
  1262. void clif_quitsave(int fd,struct map_session_data *sd)
  1263. {
  1264. if (!battle_config.prevent_logout ||
  1265. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1266. map_quit(sd);
  1267. else if (sd->fd)
  1268. { //Disassociate session from player (session is deleted after this function was called)
  1269. //And set a timer to make him quit later.
  1270. session[sd->fd]->session_data = NULL;
  1271. sd->fd = 0;
  1272. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1273. }
  1274. }
  1275. /*==========================================
  1276. *
  1277. *------------------------------------------*/
  1278. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1279. {
  1280. int fd;
  1281. nullpo_retv(sd);
  1282. fd = sd->fd;
  1283. WFIFOHEAD(fd,packet_len(0x91));
  1284. WFIFOW(fd,0) = 0x91;
  1285. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1286. WFIFOW(fd,18) = x;
  1287. WFIFOW(fd,20) = y;
  1288. WFIFOSET(fd,packet_len(0x91));
  1289. }
  1290. /*==========================================
  1291. * Tells the client to connect to another map-server
  1292. *------------------------------------------*/
  1293. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1294. {
  1295. int fd;
  1296. nullpo_retv(sd);
  1297. fd = sd->fd;
  1298. WFIFOHEAD(fd,packet_len(0x92));
  1299. WFIFOW(fd,0) = 0x92;
  1300. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1301. WFIFOW(fd,18) = x;
  1302. WFIFOW(fd,20) = y;
  1303. WFIFOL(fd,22) = htonl(ip);
  1304. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1305. WFIFOSET(fd,packet_len(0x92));
  1306. }
  1307. void clif_blown(struct block_list *bl)
  1308. {
  1309. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1310. // clif_fixpos(bl);
  1311. clif_slide(bl, bl->x, bl->y);
  1312. }
  1313. /// Visually moves(slides) a character to x,y. If the target cell
  1314. /// isn't walkable, the char doesn't move at all. If the char is
  1315. /// sitting it will stand up.
  1316. /// S 0088 <gid>.L <x>.W <y>.W
  1317. void clif_fixpos(struct block_list *bl)
  1318. {
  1319. unsigned char buf[10];
  1320. nullpo_retv(bl);
  1321. WBUFW(buf,0) = 0x88;
  1322. WBUFL(buf,2) = bl->id;
  1323. WBUFW(buf,6) = bl->x;
  1324. WBUFW(buf,8) = bl->y;
  1325. clif_send(buf, packet_len(0x88), bl, AREA);
  1326. if( disguised(bl) )
  1327. {
  1328. WBUFL(buf,2) = -bl->id;
  1329. clif_send(buf, packet_len(0x88), bl, SELF);
  1330. }
  1331. }
  1332. /*==========================================
  1333. *
  1334. *------------------------------------------*/
  1335. int clif_npcbuysell(struct map_session_data* sd, int id)
  1336. {
  1337. int fd;
  1338. nullpo_ret(sd);
  1339. fd=sd->fd;
  1340. WFIFOHEAD(fd, packet_len(0xc4));
  1341. WFIFOW(fd,0)=0xc4;
  1342. WFIFOL(fd,2)=id;
  1343. WFIFOSET(fd,packet_len(0xc4));
  1344. return 0;
  1345. }
  1346. /*==========================================
  1347. *
  1348. *------------------------------------------*/
  1349. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1350. {
  1351. int fd,i,c;
  1352. nullpo_ret(sd);
  1353. nullpo_ret(nd);
  1354. fd = sd->fd;
  1355. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1356. WFIFOW(fd,0) = 0xc6;
  1357. c = 0;
  1358. for( i = 0; i < nd->u.shop.count; i++ )
  1359. {
  1360. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1361. int val = nd->u.shop.shop_item[i].value;
  1362. if( id == NULL )
  1363. continue;
  1364. WFIFOL(fd, 4+c*11) = val;
  1365. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1366. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1367. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1368. c++;
  1369. }
  1370. WFIFOW(fd,2) = 4 + c*11;
  1371. WFIFOSET(fd,WFIFOW(fd,2));
  1372. return 0;
  1373. }
  1374. /*==========================================
  1375. *
  1376. *------------------------------------------*/
  1377. int clif_selllist(struct map_session_data *sd)
  1378. {
  1379. int fd,i,c=0,val;
  1380. nullpo_ret(sd);
  1381. fd=sd->fd;
  1382. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1383. WFIFOW(fd,0)=0xc7;
  1384. for( i = 0; i < MAX_INVENTORY; i++ )
  1385. {
  1386. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1387. {
  1388. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1389. continue;
  1390. if( sd->status.inventory[i].expire_time )
  1391. continue; // Cannot Sell Rental Items
  1392. val=sd->inventory_data[i]->value_sell;
  1393. if( val < 0 )
  1394. continue;
  1395. WFIFOW(fd,4+c*10)=i+2;
  1396. WFIFOL(fd,6+c*10)=val;
  1397. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1398. c++;
  1399. }
  1400. }
  1401. WFIFOW(fd,2)=c*10+4;
  1402. WFIFOSET(fd,WFIFOW(fd,2));
  1403. return 0;
  1404. }
  1405. /// Client behavior (dialog window):
  1406. /// - disable mouse targeting
  1407. /// - open the dialog window
  1408. /// - set npcid of dialog window (0 by default)
  1409. /// - if set to clear on next mes, clear contents
  1410. /// - append this text
  1411. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1412. {
  1413. int fd = sd->fd;
  1414. int slen = strlen(mes) + 9;
  1415. WFIFOHEAD(fd, slen);
  1416. WFIFOW(fd,0)=0xb4;
  1417. WFIFOW(fd,2)=slen;
  1418. WFIFOL(fd,4)=npcid;
  1419. strcpy((char*)WFIFOP(fd,8),mes);
  1420. WFIFOSET(fd,WFIFOW(fd,2));
  1421. return 0;
  1422. }
  1423. /// Client behavior (dialog window):
  1424. /// - disable mouse targeting
  1425. /// - open the dialog window
  1426. /// - add 'next' button
  1427. /// When 'next' is pressed:
  1428. /// - S 00B9 <npcid of dialog window>.L
  1429. /// - set to clear on next mes
  1430. /// - remove 'next' button
  1431. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1432. {
  1433. int fd;
  1434. nullpo_ret(sd);
  1435. fd=sd->fd;
  1436. WFIFOHEAD(fd, packet_len(0xb5));
  1437. WFIFOW(fd,0)=0xb5;
  1438. WFIFOL(fd,2)=npcid;
  1439. WFIFOSET(fd,packet_len(0xb5));
  1440. return 0;
  1441. }
  1442. /// Client behavior:
  1443. /// - if dialog window is open:
  1444. /// - remove 'next' button
  1445. /// - add 'close' button
  1446. /// - else:
  1447. /// - enable mouse targeting
  1448. /// - close the dialog window
  1449. /// - close the menu window
  1450. /// When 'close' is pressed:
  1451. /// - enable mouse targeting
  1452. /// - close the dialog window
  1453. /// - close the menu window
  1454. /// - S 0146 <npcid of dialog window>.L
  1455. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1456. {
  1457. int fd;
  1458. nullpo_ret(sd);
  1459. fd=sd->fd;
  1460. WFIFOHEAD(fd, packet_len(0xb6));
  1461. WFIFOW(fd,0)=0xb6;
  1462. WFIFOL(fd,2)=npcid;
  1463. WFIFOSET(fd,packet_len(0xb6));
  1464. return 0;
  1465. }
  1466. /*==========================================
  1467. *
  1468. *------------------------------------------*/
  1469. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1470. {
  1471. unsigned char *buf;
  1472. int fd = sd->fd;
  1473. sd->state.using_fake_npc = 1;
  1474. WFIFOHEAD(fd, packet_len(0x78));
  1475. buf = WFIFOP(fd,0);
  1476. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1477. WBUFW(buf,0)=0x78;
  1478. #if PACKETVER >= 20071106
  1479. WBUFB(buf,2) = 0; //Unknown bit
  1480. buf = WFIFOP(fd,1);
  1481. #endif
  1482. WBUFL(buf,2)=npcid;
  1483. WBUFW(buf,14)=111;
  1484. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1485. WBUFB(buf,49)=5;
  1486. WBUFB(buf,50)=5;
  1487. WFIFOSET(fd, packet_len(0x78));
  1488. return;
  1489. }
  1490. /// Client behavior:
  1491. /// - disable mouse targeting
  1492. /// - close the menu window
  1493. /// - open the menu window
  1494. /// - add options to the menu (separated in the text by ":")
  1495. /// - set npcid of menu window
  1496. /// - if dialog window is open:
  1497. /// - remove 'next' button
  1498. /// When 'ok' is pressed:
  1499. /// - S 00B8 <npcid of menu window>.L <selected option>.B
  1500. /// - close the menu window
  1501. /// When 'cancel' is pressed:
  1502. /// - S 00B8 <npcid of menu window>.L <-1>.B
  1503. /// - enable mouse targeting
  1504. /// - close a bunch of windows...
  1505. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1506. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1507. /// TODO investigate behavior of other windows [FlavioJS]
  1508. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1509. {
  1510. int fd = sd->fd;
  1511. int slen = strlen(mes) + 8;
  1512. struct block_list *bl = NULL;
  1513. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1514. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1515. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1516. clif_sendfakenpc(sd, npcid);
  1517. WFIFOHEAD(fd, slen);
  1518. WFIFOW(fd,0)=0xb7;
  1519. WFIFOW(fd,2)=slen;
  1520. WFIFOL(fd,4)=npcid;
  1521. strcpy((char*)WFIFOP(fd,8),mes);
  1522. WFIFOSET(fd,WFIFOW(fd,2));
  1523. return 0;
  1524. }
  1525. /// Client behavior (inputnum window):
  1526. /// - if npcid exists in the client:
  1527. /// - open the inputnum window
  1528. /// - set npcid of inputnum window
  1529. /// When 'ok' is pressed:
  1530. /// - if inputnum window has text:
  1531. /// - if npcid exists in the client:
  1532. /// - S 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1533. /// - close inputnum window
  1534. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1535. {
  1536. int fd;
  1537. struct block_list *bl = NULL;
  1538. nullpo_ret(sd);
  1539. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1540. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1541. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1542. clif_sendfakenpc(sd, npcid);
  1543. fd=sd->fd;
  1544. WFIFOHEAD(fd, packet_len(0x142));
  1545. WFIFOW(fd,0)=0x142;
  1546. WFIFOL(fd,2)=npcid;
  1547. WFIFOSET(fd,packet_len(0x142));
  1548. return 0;
  1549. }
  1550. /// Client behavior (inputstr window):
  1551. /// - if npcid is 0 or npcid exists in the client:
  1552. /// - open the inputstr window
  1553. /// - set npcid of inputstr window
  1554. /// When 'ok' is pressed:
  1555. /// - if inputstr window has text and isn't an insult(manner.txt):
  1556. /// - if npcid is 0 or npcid exists in the client:
  1557. /// - S 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1558. /// - close inputstr window
  1559. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1560. {
  1561. int fd;
  1562. struct block_list *bl = NULL;
  1563. nullpo_ret(sd);
  1564. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1565. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1566. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1567. clif_sendfakenpc(sd, npcid);
  1568. fd=sd->fd;
  1569. WFIFOHEAD(fd, packet_len(0x1d4));
  1570. WFIFOW(fd,0)=0x1d4;
  1571. WFIFOL(fd,2)=npcid;
  1572. WFIFOSET(fd,packet_len(0x1d4));
  1573. return 0;
  1574. }
  1575. /// npc_id is ignored in the client
  1576. /// type=2 : Remove viewpoint
  1577. /// type=other : Show viewpoint
  1578. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1579. {
  1580. int fd;
  1581. nullpo_ret(sd);
  1582. fd=sd->fd;
  1583. WFIFOHEAD(fd, packet_len(0x144));
  1584. WFIFOW(fd,0)=0x144;
  1585. WFIFOL(fd,2)=npc_id;
  1586. WFIFOL(fd,6)=type;
  1587. WFIFOL(fd,10)=x;
  1588. WFIFOL(fd,14)=y;
  1589. WFIFOB(fd,18)=id;
  1590. WFIFOL(fd,19)=color;
  1591. WFIFOSET(fd,packet_len(0x144));
  1592. return 0;
  1593. }
  1594. /*==========================================
  1595. *
  1596. *------------------------------------------*/
  1597. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1598. {
  1599. int fd;
  1600. nullpo_ret(sd);
  1601. fd=sd->fd;
  1602. WFIFOHEAD(fd, packet_len(0x1b3));
  1603. WFIFOW(fd,0)=0x1b3;
  1604. strncpy((char*)WFIFOP(fd,2),image,64);
  1605. WFIFOB(fd,66)=type;
  1606. WFIFOSET(fd,packet_len(0x1b3));
  1607. return 0;
  1608. }
  1609. /*==========================================
  1610. * Fills in card data from the given item and into the buffer. [Skotlex]
  1611. *------------------------------------------*/
  1612. static void clif_addcards(unsigned char* buf, struct item* item)
  1613. {
  1614. int i=0,j;
  1615. if( item == NULL ) { //Blank data
  1616. WBUFW(buf,0) = 0;
  1617. WBUFW(buf,2) = 0;
  1618. WBUFW(buf,4) = 0;
  1619. WBUFW(buf,6) = 0;
  1620. return;
  1621. }
  1622. if( item->card[0] == CARD0_PET ) { //pet eggs
  1623. WBUFW(buf,0) = 0;
  1624. WBUFW(buf,2) = 0;
  1625. WBUFW(buf,4) = 0;
  1626. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1627. return;
  1628. }
  1629. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1630. WBUFW(buf,0) = item->card[0];
  1631. WBUFW(buf,2) = item->card[1];
  1632. WBUFW(buf,4) = item->card[2];
  1633. WBUFW(buf,6) = item->card[3];
  1634. return;
  1635. }
  1636. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1637. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1638. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1639. //Normal items.
  1640. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1641. WBUFW(buf,0) = j;
  1642. else
  1643. WBUFW(buf,0) = item->card[i];
  1644. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1645. WBUFW(buf,2) = j;
  1646. else
  1647. WBUFW(buf,2) = item->card[i];
  1648. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1649. WBUFW(buf,4) = j;
  1650. else
  1651. WBUFW(buf,4) = item->card[i];
  1652. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1653. WBUFW(buf,6) = j;
  1654. else
  1655. WBUFW(buf,6) = item->card[i];
  1656. }
  1657. /*==========================================
  1658. *
  1659. *------------------------------------------*/
  1660. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1661. {
  1662. int fd;
  1663. #if PACKETVER < 20071002
  1664. const int cmd = 0xa0;
  1665. #else
  1666. const int cmd = 0x2d4;
  1667. #endif
  1668. nullpo_ret(sd);
  1669. fd = sd->fd;
  1670. if( !session_isActive(fd) ) //Sasuke-
  1671. return 0;
  1672. WFIFOHEAD(fd,packet_len(cmd));
  1673. if( fail )
  1674. {
  1675. WFIFOW(fd,0)=cmd;
  1676. WFIFOW(fd,2)=n+2;
  1677. WFIFOW(fd,4)=amount;
  1678. WFIFOW(fd,6)=0;
  1679. WFIFOB(fd,8)=0;
  1680. WFIFOB(fd,9)=0;
  1681. WFIFOB(fd,10)=0;
  1682. WFIFOW(fd,11)=0;
  1683. WFIFOW(fd,13)=0;
  1684. WFIFOW(fd,15)=0;
  1685. WFIFOW(fd,17)=0;
  1686. WFIFOW(fd,19)=0;
  1687. WFIFOB(fd,21)=0;
  1688. WFIFOB(fd,22)=fail;
  1689. #if PACKETVER >= 20071002
  1690. WFIFOW(fd,23)=0;
  1691. WFIFOW(fd,25)=0;
  1692. WFIFOW(fd,27)=0;
  1693. #endif
  1694. }
  1695. else
  1696. {
  1697. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1698. return 1;
  1699. WFIFOW(fd,0)=cmd;
  1700. WFIFOW(fd,2)=n+2;
  1701. WFIFOW(fd,4)=amount;
  1702. if (sd->inventory_data[n]->view_id > 0)
  1703. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1704. else
  1705. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1706. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1707. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1708. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1709. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1710. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1711. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1712. WFIFOB(fd,22)=fail;
  1713. #if PACKETVER >= 20071002
  1714. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1715. WFIFOW(fd,27)=0;
  1716. #endif
  1717. }
  1718. WFIFOSET(fd,packet_len(cmd));
  1719. return 0;
  1720. }
  1721. /*==========================================
  1722. *
  1723. *------------------------------------------*/
  1724. int clif_dropitem(struct map_session_data *sd,int n,int amount)
  1725. {
  1726. int fd;
  1727. nullpo_ret(sd);
  1728. fd=sd->fd;
  1729. WFIFOHEAD(fd, packet_len(0xaf));
  1730. WFIFOW(fd,0)=0xaf;
  1731. WFIFOW(fd,2)=n+2;
  1732. WFIFOW(fd,4)=amount;
  1733. WFIFOSET(fd,packet_len(0xaf));
  1734. return 0;
  1735. }
  1736. /*==========================================
  1737. * Deletes an item from your inventory.
  1738. * Reason values:
  1739. * 0 - Normal
  1740. * 1 - Item used for a skill
  1741. * 2 - Refine failed
  1742. * 3 - Material changed
  1743. * 4 - Moved to storage
  1744. * 5 - Moved to cart
  1745. * 6 - Item sold
  1746. * 7 - Item dropped
  1747. *------------------------------------------*/
  1748. int clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1749. {
  1750. #if PACKETVER < 20091117
  1751. return clif_dropitem(sd,n,amount);
  1752. #else
  1753. int fd;
  1754. nullpo_ret(sd);
  1755. if (reason == 7)
  1756. return clif_dropitem(sd,n,amount);
  1757. fd=sd->fd;
  1758. WFIFOHEAD(fd, packet_len(0x7fa));
  1759. WFIFOW(fd,0)=0x7fa;
  1760. WFIFOW(fd,2)=reason;
  1761. WFIFOW(fd,4)=n+2;
  1762. WFIFOW(fd,6)=amount;
  1763. WFIFOSET(fd,packet_len(0x7fa));
  1764. return 0;
  1765. #endif
  1766. }
  1767. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1768. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1769. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1770. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1771. {
  1772. if (id->view_id > 0)
  1773. WBUFW(buf,n)=id->view_id;
  1774. else
  1775. WBUFW(buf,n)=i->nameid;
  1776. WBUFB(buf,n+2)=itemtype(id->type);
  1777. WBUFB(buf,n+3)=i->identify;
  1778. if (equip >= 0) { //Equippable item
  1779. WBUFW(buf,n+4)=equip;
  1780. WBUFW(buf,n+6)=i->equip;
  1781. WBUFB(buf,n+8)=i->attribute;
  1782. WBUFB(buf,n+9)=i->refine;
  1783. } else { //Stackable item.
  1784. WBUFW(buf,n+4)=i->amount;
  1785. if (equip == -2 && id->equip == EQP_AMMO)
  1786. WBUFW(buf,n+6)=EQP_AMMO;
  1787. else
  1788. WBUFW(buf,n+6)=0;
  1789. }
  1790. }
  1791. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1792. void clif_inventorylist(struct map_session_data *sd)
  1793. {
  1794. int i,n,ne,arrow=-1;
  1795. unsigned char *buf;
  1796. unsigned char *bufe;
  1797. #if PACKETVER < 5
  1798. const int s = 10; //Entry size.
  1799. #elif PACKETVER < 20080102
  1800. const int s = 18;
  1801. #else
  1802. const int s = 22;
  1803. #endif
  1804. #if PACKETVER < 20071002
  1805. const int se = 20;
  1806. #elif PACKETVER < 20100629
  1807. const int se = 26;
  1808. #else
  1809. const int se = 28;
  1810. #endif
  1811. buf = (unsigned char*)aMallocA(MAX_INVENTORY * s + 4);
  1812. bufe = (unsigned char*)aMallocA(MAX_INVENTORY * se + 4);
  1813. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  1814. {
  1815. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  1816. continue;
  1817. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  1818. { //Non-stackable (Equippable)
  1819. WBUFW(bufe,ne*se+4)=i+2;
  1820. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1821. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  1822. #if PACKETVER >= 20071002
  1823. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  1824. WBUFW(bufe,ne*se+28)=0; //Unknown
  1825. #endif
  1826. #if PACKETVER >= 20100629
  1827. if (sd->inventory_data[i]->equip&EQP_HELM)
  1828. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  1829. else
  1830. WBUFW(bufe,ne*se+30)=0;
  1831. #endif
  1832. ne++;
  1833. }
  1834. else
  1835. { //Stackable.
  1836. WBUFW(buf,n*s+4)=i+2;
  1837. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1838. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  1839. arrow=i;
  1840. #if PACKETVER >= 5
  1841. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1842. #endif
  1843. #if PACKETVER >= 20080102
  1844. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  1845. #endif
  1846. n++;
  1847. }
  1848. }
  1849. if( n )
  1850. {
  1851. #if PACKETVER < 5
  1852. WBUFW(buf,0)=0xa3;
  1853. #elif PACKETVER < 20080102
  1854. WBUFW(buf,0)=0x1ee;
  1855. #else
  1856. WBUFW(buf,0)=0x2e8;
  1857. #endif
  1858. WBUFW(buf,2)=4+n*s;
  1859. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1860. }
  1861. if( arrow >= 0 )
  1862. clif_arrowequip(sd,arrow);
  1863. if( ne )
  1864. {
  1865. #if PACKETVER < 20071002
  1866. WBUFW(bufe,0)=0xa4;
  1867. #else
  1868. WBUFW(bufe,0)=0x2d0;
  1869. #endif
  1870. WBUFW(bufe,2)=4+ne*se;
  1871. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1872. }
  1873. if( buf ) aFree(buf);
  1874. if( bufe ) aFree(bufe);
  1875. }
  1876. //Required when items break/get-repaired. Only sends equippable item list.
  1877. void clif_equiplist(struct map_session_data *sd)
  1878. {
  1879. int i,n,fd = sd->fd;
  1880. unsigned char *buf;
  1881. #if PACKETVER < 20071002
  1882. const int cmd = 20;
  1883. #elif PACKETVER < 20100629
  1884. const int cmd = 26;
  1885. #else
  1886. const int cmd = 28;
  1887. #endif
  1888. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  1889. buf = WFIFOP(fd,0);
  1890. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1891. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1892. continue;
  1893. if(itemdb_isstackable2(sd->inventory_data[i]))
  1894. continue;
  1895. //Equippable
  1896. WBUFW(buf,n*cmd+4)=i+2;
  1897. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1898. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  1899. #if PACKETVER >= 20071002
  1900. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  1901. WBUFW(buf,n*cmd+28)=0; //Unknown
  1902. #endif
  1903. #if PACKETVER >= 20100629
  1904. if (sd->inventory_data[i]->equip&EQP_HELM)
  1905. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  1906. else
  1907. WBUFW(buf,n*cmd+30)=0;
  1908. #endif
  1909. n++;
  1910. }
  1911. if (n) {
  1912. #if PACKETVER < 20071002
  1913. WBUFW(buf,0)=0xa4;
  1914. #else
  1915. WBUFW(buf,0)=0x2d0;
  1916. #endif
  1917. WBUFW(buf,2)=4+n*cmd;
  1918. WFIFOSET(fd,WFIFOW(fd,2));
  1919. }
  1920. }
  1921. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  1922. {
  1923. struct item_data *id;
  1924. int i,n,ne;
  1925. unsigned char *buf;
  1926. unsigned char *bufe;
  1927. #if PACKETVER < 5
  1928. const int s = 10; //Entry size.
  1929. #elif PACKETVER < 20080102
  1930. const int s = 18;
  1931. #else
  1932. const int s = 22;
  1933. #endif
  1934. #if PACKETVER < 20071002
  1935. const int cmd = 20;
  1936. #elif PACKETVER < 20100629
  1937. const int cmd = 26;
  1938. #else
  1939. const int cmd = 28;
  1940. #endif
  1941. buf = (unsigned char*)aMallocA(items_length * s + 4);
  1942. bufe = (unsigned char*)aMallocA(items_length * cmd + 4);
  1943. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  1944. {
  1945. if( items[i].nameid <= 0 )
  1946. continue;
  1947. id = itemdb_search(items[i].nameid);
  1948. if( !itemdb_isstackable2(id) )
  1949. { //Equippable
  1950. WBUFW(bufe,ne*cmd+4)=i+1;
  1951. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  1952. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  1953. #if PACKETVER >= 20071002
  1954. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  1955. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  1956. #endif
  1957. ne++;
  1958. }
  1959. else
  1960. { //Stackable
  1961. WBUFW(buf,n*s+4)=i+1;
  1962. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  1963. #if PACKETVER >= 5
  1964. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  1965. #endif
  1966. #if PACKETVER >= 20080102
  1967. WBUFL(buf,n*s+22)=items[i].expire_time;
  1968. #endif
  1969. n++;
  1970. }
  1971. }
  1972. if( n )
  1973. {
  1974. #if PACKETVER < 5
  1975. WBUFW(buf,0)=0xa5;
  1976. #elif PACKETVER < 20080102
  1977. WBUFW(buf,0)=0x1f0;
  1978. #else
  1979. WBUFW(buf,0)=0x2ea;
  1980. #endif
  1981. WBUFW(buf,2)=4+n*s;
  1982. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1983. }
  1984. if( ne )
  1985. {
  1986. #if PACKETVER < 20071002
  1987. WBUFW(bufe,0)=0xa6;
  1988. #else
  1989. WBUFW(bufe,0)=0x2d1;
  1990. #endif
  1991. WBUFW(bufe,2)=4+ne*cmd;
  1992. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1993. }
  1994. if( buf ) aFree(buf);
  1995. if( bufe ) aFree(bufe);
  1996. }
  1997. void clif_cartlist(struct map_session_data *sd)
  1998. {
  1999. struct item_data *id;
  2000. int i,n,ne;
  2001. unsigned char *buf;
  2002. unsigned char *bufe;
  2003. #if PACKETVER < 5
  2004. const int s = 10; //Entry size.
  2005. #elif PACKETVER < 20080102
  2006. const int s = 18;
  2007. #else
  2008. const int s = 22;
  2009. #endif
  2010. #if PACKETVER < 20071002
  2011. const int cmd = 20;
  2012. #elif PACKETVER < 20100629
  2013. const int cmd = 26;
  2014. #else
  2015. const int cmd = 28;
  2016. #endif
  2017. buf = (unsigned char*)aMallocA(MAX_CART * s + 4);
  2018. bufe = (unsigned char*)aMallocA(MAX_CART * cmd + 4);
  2019. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2020. {
  2021. if( sd->status.cart[i].nameid <= 0 )
  2022. continue;
  2023. id = itemdb_search(sd->status.cart[i].nameid);
  2024. if( !itemdb_isstackable2(id) )
  2025. { //Equippable
  2026. WBUFW(bufe,ne*cmd+4)=i+2;
  2027. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2028. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2029. #if PACKETVER >= 20071002
  2030. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2031. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2032. #endif
  2033. ne++;
  2034. }
  2035. else
  2036. { //Stackable
  2037. WBUFW(buf,n*s+4)=i+2;
  2038. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2039. #if PACKETVER >= 5
  2040. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2041. #endif
  2042. #if PACKETVER >= 20080102
  2043. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2044. #endif
  2045. n++;
  2046. }
  2047. }
  2048. if( n )
  2049. {
  2050. #if PACKETVER < 5
  2051. WBUFW(buf,0)=0x123;
  2052. #elif PACKETVER < 20080102
  2053. WBUFW(buf,0)=0x1ef;
  2054. #else
  2055. WBUFW(buf,0)=0x2e9;
  2056. #endif
  2057. WBUFW(buf,2)=4+n*s;
  2058. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2059. }
  2060. if( ne )
  2061. {
  2062. #if PACKETVER < 20071002
  2063. WBUFW(bufe,0)=0x122;
  2064. #else
  2065. WBUFW(bufe,0)=0x2d2;
  2066. #endif
  2067. WBUFW(bufe,2)=4+ne*cmd;
  2068. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2069. }
  2070. if( buf ) aFree(buf);
  2071. if( bufe ) aFree(bufe);
  2072. }
  2073. /// Client behaviour:
  2074. /// Closes the cart storage and removes all it's items from memory.
  2075. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2076. void clif_clearcart(int fd)
  2077. {
  2078. WFIFOHEAD(fd, packet_len(0x12b));
  2079. WFIFOW(fd,0) = 0x12b;
  2080. WFIFOSET(fd, packet_len(0x12b));
  2081. }
  2082. // Guild XY locators [Valaris]
  2083. int clif_guild_xy(struct map_session_data *sd)
  2084. {
  2085. unsigned char buf[10];
  2086. nullpo_ret(sd);
  2087. WBUFW(buf,0)=0x1eb;
  2088. WBUFL(buf,2)=sd->status.account_id;
  2089. WBUFW(buf,6)=sd->bl.x;
  2090. WBUFW(buf,8)=sd->bl.y;
  2091. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2092. return 0;
  2093. }
  2094. /*==========================================
  2095. * Sends x/y dot to a single fd. [Skotlex]
  2096. *------------------------------------------*/
  2097. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2098. {
  2099. if( sd->state.bg_id )
  2100. return 0;
  2101. WFIFOHEAD(fd,packet_len(0x1eb));
  2102. WFIFOW(fd,0)=0x1eb;
  2103. WFIFOL(fd,2)=sd->status.account_id;
  2104. WFIFOW(fd,6)=sd->bl.x;
  2105. WFIFOW(fd,8)=sd->bl.y;
  2106. WFIFOSET(fd,packet_len(0x1eb));
  2107. return 0;
  2108. }
  2109. // Guild XY locators [Valaris]
  2110. int clif_guild_xy_remove(struct map_session_data *sd)
  2111. {
  2112. unsigned char buf[10];
  2113. nullpo_ret(sd);
  2114. WBUFW(buf,0)=0x1eb;
  2115. WBUFL(buf,2)=sd->status.account_id;
  2116. WBUFW(buf,6)=-1;
  2117. WBUFW(buf,8)=-1;
  2118. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2119. return 0;
  2120. }
  2121. /*==========================================
  2122. * ステータスを送りつける
  2123. * 表示専用数字はこの中で計算して送る
  2124. *------------------------------------------*/
  2125. int clif_updatestatus(struct map_session_data *sd,int type)
  2126. {
  2127. int fd,len=8;
  2128. nullpo_ret(sd);
  2129. fd=sd->fd;
  2130. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2131. return 0;
  2132. WFIFOHEAD(fd, 14);
  2133. WFIFOW(fd,0)=0xb0;
  2134. WFIFOW(fd,2)=type;
  2135. switch(type){
  2136. // 00b0
  2137. case SP_WEIGHT:
  2138. pc_updateweightstatus(sd);
  2139. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2140. WFIFOW(fd,2)=type;
  2141. WFIFOL(fd,4)=sd->weight;
  2142. break;
  2143. case SP_MAXWEIGHT:
  2144. WFIFOL(fd,4)=sd->max_weight;
  2145. break;
  2146. case SP_SPEED:
  2147. WFIFOL(fd,4)=sd->battle_status.speed;
  2148. break;
  2149. case SP_BASELEVEL:
  2150. WFIFOL(fd,4)=sd->status.base_level;
  2151. break;
  2152. case SP_JOBLEVEL:
  2153. WFIFOL(fd,4)=sd->status.job_level;
  2154. break;
  2155. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2156. WFIFOL(fd,4)=sd->status.karma;
  2157. break;
  2158. case SP_MANNER:
  2159. WFIFOL(fd,4)=sd->status.manner;
  2160. break;
  2161. case SP_STATUSPOINT:
  2162. WFIFOL(fd,4)=sd->status.status_point;
  2163. break;
  2164. case SP_SKILLPOINT:
  2165. WFIFOL(fd,4)=sd->status.skill_point;
  2166. break;
  2167. case SP_HIT:
  2168. WFIFOL(fd,4)=sd->battle_status.hit;
  2169. break;
  2170. case SP_FLEE1:
  2171. WFIFOL(fd,4)=sd->battle_status.flee;
  2172. break;
  2173. case SP_FLEE2:
  2174. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2175. break;
  2176. case SP_MAXHP:
  2177. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2178. break;
  2179. case SP_MAXSP:
  2180. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2181. break;
  2182. case SP_HP:
  2183. WFIFOL(fd,4)=sd->battle_status.hp;
  2184. if( battle_config.disp_hpmeter )
  2185. clif_hpmeter(sd);
  2186. if( !battle_config.party_hp_mode && sd->status.party_id )
  2187. clif_party_hp(sd);
  2188. if( sd->state.bg_id )
  2189. clif_bg_hp(sd);
  2190. break;
  2191. case SP_SP:
  2192. WFIFOL(fd,4)=sd->battle_status.sp;
  2193. break;
  2194. case SP_ASPD:
  2195. WFIFOL(fd,4)=sd->battle_status.amotion;
  2196. break;
  2197. case SP_ATK1:
  2198. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  2199. break;
  2200. case SP_DEF1:
  2201. WFIFOL(fd,4)=sd->battle_status.def;
  2202. break;
  2203. case SP_MDEF1:
  2204. WFIFOL(fd,4)=sd->battle_status.mdef;
  2205. break;
  2206. case SP_ATK2:
  2207. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  2208. break;
  2209. case SP_DEF2:
  2210. WFIFOL(fd,4)=sd->battle_status.def2;
  2211. break;
  2212. case SP_MDEF2:
  2213. //negative check (in case you have something like Berserk active)
  2214. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2215. if (len < 0) len = 0;
  2216. WFIFOL(fd,4)= len;
  2217. len = 8;
  2218. break;
  2219. case SP_CRITICAL:
  2220. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2221. break;
  2222. case SP_MATK1:
  2223. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2224. break;
  2225. case SP_MATK2:
  2226. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2227. break;
  2228. case SP_ZENY:
  2229. WFIFOW(fd,0)=0xb1;
  2230. WFIFOL(fd,4)=sd->status.zeny;
  2231. break;
  2232. case SP_BASEEXP:
  2233. WFIFOW(fd,0)=0xb1;
  2234. WFIFOL(fd,4)=sd->status.base_exp;
  2235. break;
  2236. case SP_JOBEXP:
  2237. WFIFOW(fd,0)=0xb1;
  2238. WFIFOL(fd,4)=sd->status.job_exp;
  2239. break;
  2240. case SP_NEXTBASEEXP:
  2241. WFIFOW(fd,0)=0xb1;
  2242. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2243. break;
  2244. case SP_NEXTJOBEXP:
  2245. WFIFOW(fd,0)=0xb1;
  2246. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2247. break;
  2248. // 00be 終了
  2249. case SP_USTR:
  2250. case SP_UAGI:
  2251. case SP_UVIT:
  2252. case SP_UINT:
  2253. case SP_UDEX:
  2254. case SP_ULUK:
  2255. WFIFOW(fd,0)=0xbe;
  2256. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2257. len=5;
  2258. break;
  2259. // 013a 終了
  2260. case SP_ATTACKRANGE:
  2261. WFIFOW(fd,0)=0x13a;
  2262. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2263. len=4;
  2264. break;
  2265. // 0141 終了
  2266. case SP_STR:
  2267. WFIFOW(fd,0)=0x141;
  2268. WFIFOL(fd,2)=type;
  2269. WFIFOL(fd,6)=sd->status.str;
  2270. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2271. len=14;
  2272. break;
  2273. case SP_AGI:
  2274. WFIFOW(fd,0)=0x141;
  2275. WFIFOL(fd,2)=type;
  2276. WFIFOL(fd,6)=sd->status.agi;
  2277. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2278. len=14;
  2279. break;
  2280. case SP_VIT:
  2281. WFIFOW(fd,0)=0x141;
  2282. WFIFOL(fd,2)=type;
  2283. WFIFOL(fd,6)=sd->status.vit;
  2284. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2285. len=14;
  2286. break;
  2287. case SP_INT:
  2288. WFIFOW(fd,0)=0x141;
  2289. WFIFOL(fd,2)=type;
  2290. WFIFOL(fd,6)=sd->status.int_;
  2291. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2292. len=14;
  2293. break;
  2294. case SP_DEX:
  2295. WFIFOW(fd,0)=0x141;
  2296. WFIFOL(fd,2)=type;
  2297. WFIFOL(fd,6)=sd->status.dex;
  2298. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2299. len=14;
  2300. break;
  2301. case SP_LUK:
  2302. WFIFOW(fd,0)=0x141;
  2303. WFIFOL(fd,2)=type;
  2304. WFIFOL(fd,6)=sd->status.luk;
  2305. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2306. len=14;
  2307. break;
  2308. case SP_CARTINFO:
  2309. WFIFOW(fd,0)=0x121;
  2310. WFIFOW(fd,2)=sd->cart_num;
  2311. WFIFOW(fd,4)=MAX_CART;
  2312. WFIFOL(fd,6)=sd->cart_weight;
  2313. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2314. len=14;
  2315. break;
  2316. default:
  2317. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2318. return 1;
  2319. }
  2320. WFIFOSET(fd,len);
  2321. return 0;
  2322. }
  2323. int clif_changestatus(struct block_list *bl,int type,int val)
  2324. {
  2325. unsigned char buf[12];
  2326. struct map_session_data *sd = NULL;
  2327. nullpo_ret(bl);
  2328. if(bl->type == BL_PC)
  2329. sd = (struct map_session_data *)bl;
  2330. if(sd){
  2331. WBUFW(buf,0)=0x1ab;
  2332. WBUFL(buf,2)=bl->id;
  2333. WBUFW(buf,6)=type;
  2334. switch(type){
  2335. case SP_MANNER:
  2336. WBUFL(buf,8)=val;
  2337. break;
  2338. default:
  2339. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2340. return 1;
  2341. }
  2342. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2343. }
  2344. return 0;
  2345. }
  2346. /*==========================================
  2347. *
  2348. *------------------------------------------*/
  2349. void clif_changelook(struct block_list *bl,int type,int val)
  2350. {
  2351. unsigned char buf[16];
  2352. struct map_session_data* sd = NULL;
  2353. struct status_change* sc;
  2354. struct view_data* vd;
  2355. enum send_target target = AREA;
  2356. nullpo_retv(bl);
  2357. sd = BL_CAST(BL_PC, bl);
  2358. sc = status_get_sc(bl);
  2359. vd = status_get_viewdata(bl);
  2360. //nullpo_ret(vd);
  2361. if( vd ) //temp hack to let Warp Portal change appearance
  2362. switch(type)
  2363. {
  2364. case LOOK_WEAPON:
  2365. if (sd)
  2366. {
  2367. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2368. val = vd->weapon;
  2369. }
  2370. else vd->weapon = val;
  2371. break;
  2372. case LOOK_SHIELD:
  2373. if (sd)
  2374. {
  2375. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2376. val = vd->shield;
  2377. }
  2378. else vd->shield = val;
  2379. break;
  2380. case LOOK_BASE:
  2381. vd->class_ = val;
  2382. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2383. vd->weapon = vd->shield = 0;
  2384. if (vd->cloth_color && (
  2385. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2386. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2387. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2388. ))
  2389. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2390. break;
  2391. case LOOK_HAIR:
  2392. vd->hair_style = val;
  2393. break;
  2394. case LOOK_HEAD_BOTTOM:
  2395. vd->head_bottom = val;
  2396. break;
  2397. case LOOK_HEAD_TOP:
  2398. vd->head_top = val;
  2399. break;
  2400. case LOOK_HEAD_MID:
  2401. vd->head_mid = val;
  2402. break;
  2403. case LOOK_HAIR_COLOR:
  2404. vd->hair_color = val;
  2405. break;
  2406. case LOOK_CLOTHES_COLOR:
  2407. if (val && (
  2408. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2409. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2410. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2411. ))
  2412. val = 0;
  2413. vd->cloth_color = val;
  2414. break;
  2415. case LOOK_SHOES:
  2416. #if PACKETVER > 3
  2417. if (sd) {
  2418. int n;
  2419. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2420. if(sd->inventory_data[n]->view_id > 0)
  2421. val = sd->inventory_data[n]->view_id;
  2422. else
  2423. val = sd->status.inventory[n].nameid;
  2424. }
  2425. val = 0;
  2426. }
  2427. #endif
  2428. //Shoes? No packet uses this....
  2429. break;
  2430. }
  2431. // prevent leaking the presence of GM-hidden objects
  2432. if( sc && sc->option&OPTION_INVISIBLE )
  2433. target = SELF;
  2434. #if PACKETVER < 4
  2435. WBUFW(buf,0)=0xc3;
  2436. WBUFL(buf,2)=bl->id;
  2437. WBUFB(buf,6)=type;
  2438. WBUFB(buf,7)=val;
  2439. clif_send(buf,packet_len(0xc3),bl,target);
  2440. #else
  2441. WBUFW(buf,0)=0x1d7;
  2442. WBUFL(buf,2)=bl->id;
  2443. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2444. WBUFB(buf,6)=LOOK_WEAPON;
  2445. WBUFW(buf,7)=vd->weapon;
  2446. WBUFW(buf,9)=vd->shield;
  2447. } else {
  2448. WBUFB(buf,6)=type;
  2449. WBUFW(buf,7)=val;
  2450. WBUFW(buf,9)=0;
  2451. }
  2452. clif_send(buf,packet_len(0x1d7),bl,target);
  2453. #endif
  2454. }
  2455. //Sends a change-base-look packet required for traps as they are triggered.
  2456. void clif_changetraplook(struct block_list *bl,int val)
  2457. {
  2458. unsigned char buf[32];
  2459. #if PACKETVER < 4
  2460. WBUFW(buf,0)=0xc3;
  2461. WBUFL(buf,2)=bl->id;
  2462. WBUFB(buf,6)=LOOK_BASE;
  2463. WBUFB(buf,7)=val;
  2464. clif_send(buf,packet_len(0xc3),bl,AREA);
  2465. #else
  2466. WBUFW(buf,0)=0x1d7;
  2467. WBUFL(buf,2)=bl->id;
  2468. WBUFB(buf,6)=LOOK_BASE;
  2469. WBUFW(buf,7)=val;
  2470. WBUFW(buf,9)=0;
  2471. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2472. #endif
  2473. }
  2474. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2475. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2476. {
  2477. unsigned char buf[32];
  2478. #if PACKETVER < 4
  2479. WBUFW(buf,0)=0xc3;
  2480. WBUFL(buf,2)=id;
  2481. WBUFB(buf,6)=type;
  2482. WBUFB(buf,7)=val;
  2483. clif_send(buf,packet_len(0xc3),bl,target);
  2484. #else
  2485. WBUFW(buf,0)=0x1d7;
  2486. WBUFL(buf,2)=id;
  2487. WBUFB(buf,6)=type;
  2488. WBUFW(buf,7)=val;
  2489. WBUFW(buf,9)=0;
  2490. clif_send(buf,packet_len(0x1d7),bl,target);
  2491. #endif
  2492. return;
  2493. }
  2494. /*==========================================
  2495. *
  2496. *------------------------------------------*/
  2497. int clif_initialstatus(struct map_session_data *sd)
  2498. {
  2499. int fd;
  2500. unsigned char *buf;
  2501. nullpo_ret(sd);
  2502. fd=sd->fd;
  2503. WFIFOHEAD(fd,packet_len(0xbd));
  2504. buf=WFIFOP(fd,0);
  2505. WBUFW(buf,0)=0xbd;
  2506. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2507. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2508. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2509. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2510. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2511. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2512. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2513. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2514. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2515. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2516. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2517. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2518. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2519. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2520. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2521. WBUFW(buf,20) = sd->battle_status.matk_max;
  2522. WBUFW(buf,22) = sd->battle_status.matk_min;
  2523. WBUFW(buf,24) = sd->battle_status.def; // def
  2524. WBUFW(buf,26) = sd->battle_status.def2;
  2525. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2526. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2527. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2528. WBUFW(buf,30) = fd;
  2529. fd = sd->fd;
  2530. WBUFW(buf,32) = sd->battle_status.hit;
  2531. WBUFW(buf,34) = sd->battle_status.flee;
  2532. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2533. WBUFW(buf,38) = sd->battle_status.cri/10;
  2534. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2535. WBUFW(buf,42) = sd->status.manner; // FIXME: This is 'plusASPD', but what is it supposed to be?
  2536. WFIFOSET(fd,packet_len(0xbd));
  2537. clif_updatestatus(sd,SP_STR);
  2538. clif_updatestatus(sd,SP_AGI);
  2539. clif_updatestatus(sd,SP_VIT);
  2540. clif_updatestatus(sd,SP_INT);
  2541. clif_updatestatus(sd,SP_DEX);
  2542. clif_updatestatus(sd,SP_LUK);
  2543. clif_updatestatus(sd,SP_ATTACKRANGE);
  2544. clif_updatestatus(sd,SP_ASPD);
  2545. return 0;
  2546. }
  2547. /*==========================================
  2548. *矢装備
  2549. *------------------------------------------*/
  2550. int clif_arrowequip(struct map_session_data *sd,int val)
  2551. {
  2552. int fd;
  2553. nullpo_ret(sd);
  2554. pc_stop_attack(sd); // [Valaris]
  2555. fd=sd->fd;
  2556. WFIFOHEAD(fd, packet_len(0x013c));
  2557. WFIFOW(fd,0)=0x013c;
  2558. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2559. WFIFOSET(fd,packet_len(0x013c));
  2560. return 0;
  2561. }
  2562. /// Ammunition action message.
  2563. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2564. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2565. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2566. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2567. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2568. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2569. int clif_arrow_fail(struct map_session_data *sd,int type)
  2570. {
  2571. int fd;
  2572. nullpo_ret(sd);
  2573. fd=sd->fd;
  2574. WFIFOHEAD(fd, packet_len(0x013b));
  2575. WFIFOW(fd,0)=0x013b;
  2576. WFIFOW(fd,2)=type;
  2577. WFIFOSET(fd,packet_len(0x013b));
  2578. return 0;
  2579. }
  2580. /*==========================================
  2581. * 作成可能 矢リスト送信
  2582. *------------------------------------------*/
  2583. int clif_arrow_create_list(struct map_session_data *sd)
  2584. {
  2585. int i, c, j;
  2586. int fd;
  2587. nullpo_ret(sd);
  2588. fd = sd->fd;
  2589. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2590. WFIFOW(fd,0) = 0x1ad;
  2591. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2592. if (skill_arrow_db[i].nameid > 0 &&
  2593. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2594. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2595. {
  2596. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2597. WFIFOW(fd,c*2+4) = j;
  2598. else
  2599. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2600. c++;
  2601. }
  2602. }
  2603. WFIFOW(fd,2) = c*2+4;
  2604. WFIFOSET(fd, WFIFOW(fd,2));
  2605. if (c > 0) {
  2606. sd->menuskill_id = AC_MAKINGARROW;
  2607. sd->menuskill_val = c;
  2608. }
  2609. return 0;
  2610. }
  2611. /*==========================================
  2612. *
  2613. *------------------------------------------*/
  2614. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2615. {
  2616. int fd;
  2617. nullpo_ret(sd);
  2618. fd=sd->fd;
  2619. WFIFOHEAD(fd,packet_len(0xbc));
  2620. WFIFOW(fd,0)=0xbc;
  2621. WFIFOW(fd,2)=type;
  2622. WFIFOB(fd,4)=ok;
  2623. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2624. WFIFOSET(fd,packet_len(0xbc));
  2625. return 0;
  2626. }
  2627. /*==========================================
  2628. *
  2629. *------------------------------------------*/
  2630. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2631. {
  2632. int fd;
  2633. nullpo_ret(sd);
  2634. fd=sd->fd;
  2635. WFIFOHEAD(fd,packet_len(0xaa));
  2636. WFIFOW(fd,0)=0xaa;
  2637. WFIFOW(fd,2)=n+2;
  2638. WFIFOW(fd,4)=pos;
  2639. #if PACKETVER < 20100629
  2640. WFIFOB(fd,6)=ok;
  2641. #else
  2642. if (ok && sd->inventory_data[n]->equip&EQP_HELM)
  2643. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2644. else
  2645. WFIFOW(fd,6)=0;
  2646. WFIFOB(fd,8)=ok;
  2647. #endif
  2648. WFIFOSET(fd,packet_len(0xaa));
  2649. return 0;
  2650. }
  2651. /*==========================================
  2652. *
  2653. *------------------------------------------*/
  2654. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2655. {
  2656. int fd;
  2657. nullpo_ret(sd);
  2658. fd=sd->fd;
  2659. WFIFOHEAD(fd,packet_len(0xac));
  2660. WFIFOW(fd,0)=0xac;
  2661. WFIFOW(fd,2)=n+2;
  2662. WFIFOW(fd,4)=pos;
  2663. WFIFOB(fd,6)=ok;
  2664. WFIFOSET(fd,packet_len(0xac));
  2665. return 0;
  2666. }
  2667. /*==========================================
  2668. *
  2669. *------------------------------------------*/
  2670. int clif_misceffect(struct block_list* bl,int type)
  2671. {
  2672. unsigned char buf[32];
  2673. nullpo_ret(bl);
  2674. WBUFW(buf,0) = 0x19b;
  2675. WBUFL(buf,2) = bl->id;
  2676. WBUFL(buf,6) = type;
  2677. clif_send(buf,packet_len(0x19b),bl,AREA);
  2678. return 0;
  2679. }
  2680. /*==========================================
  2681. * 表示オプション変更
  2682. *------------------------------------------*/
  2683. int clif_changeoption(struct block_list* bl)
  2684. {
  2685. unsigned char buf[32];
  2686. struct status_change *sc;
  2687. struct map_session_data* sd;
  2688. nullpo_ret(bl);
  2689. sc = status_get_sc(bl);
  2690. if (!sc) return 0; //How can an option change if there's no sc?
  2691. sd = BL_CAST(BL_PC, bl);
  2692. #if PACKETVER >= 7
  2693. WBUFW(buf,0) = 0x229;
  2694. WBUFL(buf,2) = bl->id;
  2695. WBUFW(buf,6) = sc->opt1;
  2696. WBUFW(buf,8) = sc->opt2;
  2697. WBUFL(buf,10) = sc->option;
  2698. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2699. if(disguised(bl)) {
  2700. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2701. WBUFL(buf,2) = -bl->id;
  2702. clif_send(buf,packet_len(0x229),bl,SELF);
  2703. WBUFL(buf,2) = bl->id;
  2704. WBUFL(buf,10) = OPTION_INVISIBLE;
  2705. clif_send(buf,packet_len(0x229),bl,SELF);
  2706. } else
  2707. clif_send(buf,packet_len(0x229),bl,AREA);
  2708. #else
  2709. WBUFW(buf,0) = 0x119;
  2710. WBUFL(buf,2) = bl->id;
  2711. WBUFW(buf,6) = sc->opt1;
  2712. WBUFW(buf,8) = sc->opt2;
  2713. WBUFW(buf,10) = sc->option;
  2714. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  2715. if(disguised(bl)) {
  2716. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2717. WBUFL(buf,2) = -bl->id;
  2718. clif_send(buf,packet_len(0x119),bl,SELF);
  2719. WBUFL(buf,2) = bl->id;
  2720. WBUFW(buf,10) = OPTION_INVISIBLE;
  2721. clif_send(buf,packet_len(0x119),bl,SELF);
  2722. } else
  2723. clif_send(buf,packet_len(0x119),bl,AREA);
  2724. #endif
  2725. return 0;
  2726. }
  2727. int clif_changeoption2(struct block_list* bl)
  2728. {
  2729. unsigned char buf[20];
  2730. struct status_change *sc;
  2731. sc = status_get_sc(bl);
  2732. if (!sc) return 0; //How can an option change if there's no sc?
  2733. WBUFW(buf,0) = 0x28a;
  2734. WBUFL(buf,2) = bl->id;
  2735. WBUFL(buf,6) = sc->option;
  2736. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2737. WBUFL(buf,14) = sc->opt3;
  2738. if(disguised(bl)) {
  2739. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2740. WBUFL(buf,2) = -bl->id;
  2741. clif_send(buf,packet_len(0x28a),bl,SELF);
  2742. WBUFL(buf,2) = bl->id;
  2743. WBUFL(buf,6) = OPTION_INVISIBLE;
  2744. clif_send(buf,packet_len(0x28a),bl,SELF);
  2745. } else
  2746. clif_send(buf,packet_len(0x28a),bl,AREA);
  2747. return 0;
  2748. }
  2749. /*==========================================
  2750. *
  2751. *------------------------------------------*/
  2752. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2753. {
  2754. nullpo_ret(sd);
  2755. if(!ok) {
  2756. int fd=sd->fd;
  2757. WFIFOHEAD(fd,packet_len(0xa8));
  2758. WFIFOW(fd,0)=0xa8;
  2759. WFIFOW(fd,2)=index+2;
  2760. WFIFOW(fd,4)=amount;
  2761. WFIFOB(fd,6)=ok;
  2762. WFIFOSET(fd,packet_len(0xa8));
  2763. }
  2764. else {
  2765. #if PACKETVER < 3
  2766. int fd=sd->fd;
  2767. WFIFOHEAD(fd,packet_len(0xa8));
  2768. WFIFOW(fd,0)=0xa8;
  2769. WFIFOW(fd,2)=index+2;
  2770. WFIFOW(fd,4)=amount;
  2771. WFIFOB(fd,6)=ok;
  2772. WFIFOSET(fd,packet_len(0xa8));
  2773. #else
  2774. unsigned char buf[32];
  2775. WBUFW(buf,0)=0x1c8;
  2776. WBUFW(buf,2)=index+2;
  2777. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2778. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2779. else
  2780. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2781. WBUFL(buf,6)=sd->bl.id;
  2782. WBUFW(buf,10)=amount;
  2783. WBUFB(buf,12)=ok;
  2784. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2785. #endif
  2786. }
  2787. return 0;
  2788. }
  2789. /// Inform client whether chatroom creation was successful or not
  2790. /// R 00d6 <flag>.B
  2791. /// flag:
  2792. /// 0 = Room has been successfully created (opens chat room)
  2793. /// 1 = Room limit exceeded
  2794. /// 2 = Same room already exists
  2795. void clif_createchat(struct map_session_data* sd, int flag)
  2796. {
  2797. int fd;
  2798. nullpo_retv(sd);
  2799. fd = sd->fd;
  2800. WFIFOHEAD(fd,packet_len(0xd6));
  2801. WFIFOW(fd,0) = 0xd6;
  2802. WFIFOB(fd,2) = flag;
  2803. WFIFOSET(fd,packet_len(0xd6));
  2804. }
  2805. /*==========================================
  2806. * Display a chat above the owner
  2807. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2808. *------------------------------------------*/
  2809. int clif_dispchat(struct chat_data* cd, int fd)
  2810. {
  2811. unsigned char buf[128];
  2812. uint8 type;
  2813. if( cd == NULL || cd->owner == NULL )
  2814. return 1;
  2815. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2816. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2817. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2818. : 1;
  2819. WBUFW(buf, 0) = 0xd7;
  2820. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2821. WBUFL(buf, 4) = cd->owner->id;
  2822. WBUFL(buf, 8) = cd->bl.id;
  2823. WBUFW(buf,12) = cd->limit;
  2824. WBUFW(buf,14) = cd->users;
  2825. WBUFB(buf,16) = type;
  2826. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2827. if( fd ) {
  2828. WFIFOHEAD(fd,WBUFW(buf,2));
  2829. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2830. WFIFOSET(fd,WBUFW(buf,2));
  2831. } else {
  2832. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2833. }
  2834. return 0;
  2835. }
  2836. /*==========================================
  2837. * Chatroom properties adjustment
  2838. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2839. *------------------------------------------*/
  2840. int clif_changechatstatus(struct chat_data* cd)
  2841. {
  2842. unsigned char buf[128];
  2843. if( cd == NULL || cd->usersd[0] == NULL )
  2844. return 1;
  2845. WBUFW(buf, 0) = 0xdf;
  2846. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2847. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2848. WBUFL(buf, 8) = cd->bl.id;
  2849. WBUFW(buf,12) = cd->limit;
  2850. WBUFW(buf,14) = cd->users;
  2851. WBUFB(buf,16) = cd->pub;
  2852. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2853. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2854. return 0;
  2855. }
  2856. /*==========================================
  2857. *
  2858. *------------------------------------------*/
  2859. int clif_clearchat(struct chat_data *cd,int fd)
  2860. {
  2861. unsigned char buf[32];
  2862. nullpo_ret(cd);
  2863. WBUFW(buf,0) = 0xd8;
  2864. WBUFL(buf,2) = cd->bl.id;
  2865. if( fd ) {
  2866. WFIFOHEAD(fd,packet_len(0xd8));
  2867. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2868. WFIFOSET(fd,packet_len(0xd8));
  2869. } else {
  2870. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2871. }
  2872. return 0;
  2873. }
  2874. /// Displays message (mostly) regarding join chat
  2875. /// failures
  2876. /// R 0x00da <flag>.B
  2877. /// flag:
  2878. /// 0 = The room is already full.
  2879. /// 1 = Incorrect password, please try again.
  2880. /// 2 = You have been kicked out of the room.
  2881. /// 4 = You don't have enough money.
  2882. /// 5 = You are not the required level.
  2883. /// 6 = Too high level for this job.
  2884. /// 7 = Not the suitable job for this type of work.
  2885. int clif_joinchatfail(struct map_session_data *sd,int flag)
  2886. {
  2887. int fd;
  2888. nullpo_ret(sd);
  2889. fd = sd->fd;
  2890. WFIFOHEAD(fd,packet_len(0xda));
  2891. WFIFOW(fd,0) = 0xda;
  2892. WFIFOB(fd,2) = flag;
  2893. WFIFOSET(fd,packet_len(0xda));
  2894. return 0;
  2895. }
  2896. /*==========================================
  2897. *
  2898. *------------------------------------------*/
  2899. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2900. {
  2901. int fd;
  2902. int i;
  2903. nullpo_ret(sd);
  2904. nullpo_ret(cd);
  2905. fd = sd->fd;
  2906. if (!session_isActive(fd))
  2907. return 0;
  2908. WFIFOHEAD(fd, 8 + (28*cd->users));
  2909. WFIFOW(fd, 0) = 0xdb;
  2910. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2911. WFIFOL(fd, 4) = cd->bl.id;
  2912. for (i = 0; i < cd->users; i++) {
  2913. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2914. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2915. }
  2916. WFIFOSET(fd, WFIFOW(fd, 2));
  2917. return 0;
  2918. }
  2919. /*==========================================
  2920. *
  2921. *------------------------------------------*/
  2922. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2923. {
  2924. unsigned char buf[32];
  2925. nullpo_ret(sd);
  2926. nullpo_ret(cd);
  2927. WBUFW(buf, 0) = 0x0dc;
  2928. WBUFW(buf, 2) = cd->users;
  2929. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2930. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2931. return 0;
  2932. }
  2933. /*==========================================
  2934. * Announce the new owner
  2935. * R 00e1 <owner flag>.l <nick>.24B
  2936. *------------------------------------------*/
  2937. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2938. {
  2939. unsigned char buf[64];
  2940. nullpo_retv(sd);
  2941. nullpo_retv(cd);
  2942. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2943. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2944. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2945. // It's not position, but operator flag, everyone set to 1 gets chat
  2946. // operator menu (yes, that means a chat may host multiple operators) [Ai4rei]
  2947. WBUFW(buf, 0) = 0xe1;
  2948. WBUFL(buf, 2) = 1;
  2949. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2950. WBUFW(buf,30) = 0xe1;
  2951. WBUFL(buf,32) = 0;
  2952. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2953. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2954. }
  2955. /*==========================================
  2956. * Notify about user leaving the chatroom
  2957. * R 00dd <index>.w <nick>.24B <flag>.B
  2958. *------------------------------------------*/
  2959. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2960. {
  2961. unsigned char buf[32];
  2962. nullpo_retv(sd);
  2963. nullpo_retv(cd);
  2964. WBUFW(buf, 0) = 0xdd;
  2965. WBUFW(buf, 2) = cd->users-1;
  2966. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2967. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2968. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2969. }
  2970. /*==========================================
  2971. * Opens a trade request window from char 'name'
  2972. * R 00e5 <nick>.24B
  2973. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2974. *------------------------------------------*/
  2975. void clif_traderequest(struct map_session_data* sd, const char* name)
  2976. {
  2977. int fd = sd->fd;
  2978. #if PACKETVER < 6
  2979. WFIFOHEAD(fd,packet_len(0xe5));
  2980. WFIFOW(fd,0) = 0xe5;
  2981. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2982. WFIFOSET(fd,packet_len(0xe5));
  2983. #else
  2984. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2985. if( !tsd ) return;
  2986. WFIFOHEAD(fd,packet_len(0x1f4));
  2987. WFIFOW(fd,0) = 0x1f4;
  2988. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2989. WFIFOL(fd,26) = tsd->status.char_id;
  2990. WFIFOW(fd,30) = tsd->status.base_level;
  2991. WFIFOSET(fd,packet_len(0x1f4));
  2992. #endif
  2993. }
  2994. /*==========================================
  2995. * Reply to a trade-request.
  2996. * R 00e7 <type>.B
  2997. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2998. * Type:
  2999. * 0: Char is too far
  3000. * 1: Character does not exist
  3001. * 2: Trade failed
  3002. * 3: Accept
  3003. * 4: Cancel
  3004. *------------------------------------------*/
  3005. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3006. {
  3007. int fd = sd->fd;
  3008. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3009. if( PACKETVER < 6 || !tsd ) {
  3010. WFIFOHEAD(fd,packet_len(0xe7));
  3011. WFIFOW(fd,0) = 0xe7;
  3012. WFIFOB(fd,2) = type;
  3013. WFIFOSET(fd,packet_len(0xe7));
  3014. } else {
  3015. WFIFOHEAD(fd,packet_len(0x1f5));
  3016. WFIFOW(fd,0) = 0x1f5;
  3017. WFIFOB(fd,2) = type;
  3018. WFIFOL(fd,3) = tsd->status.char_id;
  3019. WFIFOW(fd,7) = tsd->status.base_level;
  3020. WFIFOSET(fd,packet_len(0x1f5));
  3021. }
  3022. }
  3023. /*==========================================
  3024. * 相手方からのアイテム追加
  3025. *------------------------------------------*/
  3026. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3027. {
  3028. int fd;
  3029. unsigned char *buf;
  3030. #if PACKETVER < 20100223
  3031. const int cmd = 0xe9;
  3032. #else
  3033. const int cmd = 0x80f;
  3034. #endif
  3035. nullpo_retv(sd);
  3036. nullpo_retv(tsd);
  3037. fd = tsd->fd;
  3038. buf = WFIFOP(fd,0);
  3039. WFIFOHEAD(fd,packet_len(cmd));
  3040. WBUFW(buf,0) = cmd;
  3041. if( index == 0 )
  3042. {
  3043. #if PACKETVER < 20100223
  3044. WBUFL(buf,2) = amount; //amount
  3045. WBUFW(buf,6) = 0; // type id
  3046. #else
  3047. WBUFW(buf,2) = 0; // type id
  3048. WBUFB(buf,4) = 0; // item type
  3049. WBUFL(buf,5) = amount; // amount
  3050. buf = WBUFP(buf,1); //Advance 1B
  3051. #endif
  3052. WBUFB(buf,8) = 0; //identify flag
  3053. WBUFB(buf,9) = 0; // attribute
  3054. WBUFB(buf,10)= 0; //refine
  3055. WBUFW(buf,11)= 0; //card (4w)
  3056. WBUFW(buf,13)= 0; //card (4w)
  3057. WBUFW(buf,15)= 0; //card (4w)
  3058. WBUFW(buf,17)= 0; //card (4w)
  3059. }
  3060. else
  3061. {
  3062. index -= 2; //index fix
  3063. #if PACKETVER < 20100223
  3064. WBUFL(buf,2) = amount; //amount
  3065. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3066. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3067. else
  3068. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3069. #else
  3070. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3071. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3072. else
  3073. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3074. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3075. WBUFL(buf,5) = amount; // amount
  3076. buf = WBUFP(buf,1); //Advance 1B
  3077. #endif
  3078. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3079. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3080. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3081. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3082. }
  3083. WFIFOSET(fd,packet_len(cmd));
  3084. }
  3085. /*==========================================
  3086. * アイテム追加成功/失敗
  3087. *------------------------------------------*/
  3088. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3089. {
  3090. int fd;
  3091. nullpo_retv(sd);
  3092. fd = sd->fd;
  3093. WFIFOHEAD(fd,packet_len(0xea));
  3094. WFIFOW(fd,0) = 0xea;
  3095. WFIFOW(fd,2) = index;
  3096. WFIFOB(fd,4) = fail;
  3097. WFIFOSET(fd,packet_len(0xea));
  3098. }
  3099. /*==========================================
  3100. * 取り引きok押し
  3101. *------------------------------------------*/
  3102. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3103. {
  3104. int fd;
  3105. nullpo_retv(sd);
  3106. fd = sd->fd;
  3107. WFIFOHEAD(fd,packet_len(0xec));
  3108. WFIFOW(fd,0) = 0xec;
  3109. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3110. WFIFOSET(fd,packet_len(0xec));
  3111. }
  3112. /*==========================================
  3113. * 取り引きがキャンセルされました
  3114. *------------------------------------------*/
  3115. void clif_tradecancelled(struct map_session_data* sd)
  3116. {
  3117. int fd;
  3118. nullpo_retv(sd);
  3119. fd = sd->fd;
  3120. WFIFOHEAD(fd,packet_len(0xee));
  3121. WFIFOW(fd,0) = 0xee;
  3122. WFIFOSET(fd,packet_len(0xee));
  3123. }
  3124. /*==========================================
  3125. * 取り引き完了
  3126. *------------------------------------------*/
  3127. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3128. {
  3129. int fd;
  3130. nullpo_retv(sd);
  3131. fd = sd->fd;
  3132. WFIFOHEAD(fd,packet_len(0xf0));
  3133. WFIFOW(fd,0) = 0xf0;
  3134. WFIFOB(fd,2) = fail;
  3135. WFIFOSET(fd,packet_len(0xf0));
  3136. }
  3137. /*==========================================
  3138. * カプラ倉庫のアイテム数を更新
  3139. *------------------------------------------*/
  3140. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  3141. {
  3142. int fd;
  3143. nullpo_retv(sd);
  3144. fd=sd->fd;
  3145. WFIFOHEAD(fd,packet_len(0xf2));
  3146. WFIFOW(fd,0) = 0xf2; // update storage amount
  3147. WFIFOW(fd,2) = amount; //items
  3148. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3149. WFIFOSET(fd,packet_len(0xf2));
  3150. }
  3151. /*==========================================
  3152. * カプラ倉庫にアイテムを追加する
  3153. *------------------------------------------*/
  3154. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3155. {
  3156. int view,fd;
  3157. nullpo_retv(sd);
  3158. nullpo_retv(i);
  3159. fd=sd->fd;
  3160. view = itemdb_viewid(i->nameid);
  3161. #if PACKETVER < 5
  3162. WFIFOHEAD(fd,packet_len(0xf4));
  3163. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3164. WFIFOW(fd, 2) = index+1; // index
  3165. WFIFOL(fd, 4) = amount; // amount
  3166. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3167. WFIFOB(fd,10) = i->identify; //identify flag
  3168. WFIFOB(fd,11) = i->attribute; // attribute
  3169. WFIFOB(fd,12) = i->refine; //refine
  3170. clif_addcards(WFIFOP(fd,13), i);
  3171. WFIFOSET(fd,packet_len(0xf4));
  3172. #else
  3173. WFIFOHEAD(fd,packet_len(0x1c4));
  3174. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3175. WFIFOW(fd, 2) = index+1; // index
  3176. WFIFOL(fd, 4) = amount; // amount
  3177. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3178. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3179. WFIFOB(fd,11) = i->identify; //identify flag
  3180. WFIFOB(fd,12) = i->attribute; // attribute
  3181. WFIFOB(fd,13) = i->refine; //refine
  3182. clif_addcards(WFIFOP(fd,14), i);
  3183. WFIFOSET(fd,packet_len(0x1c4));
  3184. #endif
  3185. }
  3186. /*==========================================
  3187. *
  3188. *------------------------------------------*/
  3189. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  3190. {
  3191. int fd;
  3192. nullpo_retv(sd);
  3193. fd=sd->fd;
  3194. WFIFOHEAD(fd,packet_len(0xf2));
  3195. WFIFOW(fd,0) = 0xf2; // update storage amount
  3196. WFIFOW(fd,2) = amount; //items
  3197. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3198. WFIFOSET(fd,packet_len(0xf2));
  3199. }
  3200. /*==========================================
  3201. * カプラ倉庫からアイテムを取り去る
  3202. *------------------------------------------*/
  3203. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3204. {
  3205. int fd;
  3206. nullpo_retv(sd);
  3207. fd=sd->fd;
  3208. WFIFOHEAD(fd,packet_len(0xf6));
  3209. WFIFOW(fd,0)=0xf6; // Storage item removed
  3210. WFIFOW(fd,2)=index+1;
  3211. WFIFOL(fd,4)=amount;
  3212. WFIFOSET(fd,packet_len(0xf6));
  3213. }
  3214. /*==========================================
  3215. * カプラ倉庫を閉じる
  3216. *------------------------------------------*/
  3217. void clif_storageclose(struct map_session_data* sd)
  3218. {
  3219. int fd;
  3220. nullpo_retv(sd);
  3221. fd=sd->fd;
  3222. WFIFOHEAD(fd,packet_len(0xf8));
  3223. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3224. WFIFOSET(fd,packet_len(0xf8));
  3225. }
  3226. /*==========================================
  3227. * PC表示
  3228. *------------------------------------------*/
  3229. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3230. {
  3231. int gmlvl;
  3232. struct block_list *d_bl;
  3233. int i;
  3234. if(dstsd->chatID)
  3235. {
  3236. struct chat_data *cd;
  3237. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3238. if(cd && cd->usersd[0]==dstsd)
  3239. clif_dispchat(cd,sd->fd);
  3240. }
  3241. if(dstsd->vender_id)
  3242. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3243. if( dstsd->state.buyingstore )
  3244. clif_buyingstore_entry_single(sd, dstsd);
  3245. if(dstsd->spiritball > 0)
  3246. clif_spiritball_single(sd->fd, dstsd);
  3247. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3248. (sd->state.bg_id && sd->state.bg_id == dstsd->state.bg_id) || //BattleGround
  3249. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd)) )
  3250. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3251. // display link (sd - dstsd) to sd
  3252. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3253. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3254. // display links (dstsd - devotees) to sd
  3255. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3256. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3257. // display link (dstsd - crusader) to sd
  3258. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3259. clif_devotion(d_bl, sd);
  3260. }
  3261. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3262. {
  3263. uint8 buf[128];
  3264. struct unit_data *ud;
  3265. struct view_data *vd;
  3266. int len;
  3267. vd = status_get_viewdata(bl);
  3268. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3269. return;
  3270. ud = unit_bl2ud(bl);
  3271. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3272. clif_send(buf,len,&sd->bl,SELF);
  3273. if (vd->cloth_color)
  3274. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3275. switch (bl->type)
  3276. {
  3277. case BL_PC:
  3278. {
  3279. TBL_PC* tsd = (TBL_PC*)bl;
  3280. clif_getareachar_pc(sd, tsd);
  3281. if(tsd->state.size==2) // tiny/big players [Valaris]
  3282. clif_specialeffect_single(bl,423,sd->fd);
  3283. else if(tsd->state.size==1)
  3284. clif_specialeffect_single(bl,421,sd->fd);
  3285. if( tsd->state.bg_id && map[tsd->bl.m].flag.battleground )
  3286. clif_sendbgemblem_single(sd->fd,tsd);
  3287. }
  3288. break;
  3289. case BL_MER: // Devotion Effects
  3290. if( ((TBL_MER*)bl)->devotion_flag )
  3291. clif_devotion(bl, sd);
  3292. break;
  3293. case BL_NPC:
  3294. {
  3295. TBL_NPC* nd = (TBL_NPC*)bl;
  3296. if( nd->chat_id )
  3297. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3298. if( nd->size == 2 )
  3299. clif_specialeffect_single(bl,423,sd->fd);
  3300. else if( nd->size == 1 )
  3301. clif_specialeffect_single(bl,421,sd->fd);
  3302. }
  3303. break;
  3304. case BL_MOB:
  3305. {
  3306. TBL_MOB* md = (TBL_MOB*)bl;
  3307. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3308. clif_specialeffect_single(bl,423,sd->fd);
  3309. else if(md->special_state.size==1)
  3310. clif_specialeffect_single(bl,421,sd->fd);
  3311. }
  3312. break;
  3313. case BL_PET:
  3314. if (vd->head_bottom)
  3315. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3316. break;
  3317. }
  3318. }
  3319. //Modifies the type of damage according to status changes [Skotlex]
  3320. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3321. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3322. /*==========================================
  3323. * Estimates walk delay based on the damage criteria. [Skotlex]
  3324. *------------------------------------------*/
  3325. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3326. {
  3327. if (type == 4 || type == 9 || damage <=0)
  3328. return 0;
  3329. if (bl->type == BL_PC) {
  3330. if (battle_config.pc_walk_delay_rate != 100)
  3331. delay = delay*battle_config.pc_walk_delay_rate/100;
  3332. } else
  3333. if (battle_config.walk_delay_rate != 100)
  3334. delay = delay*battle_config.walk_delay_rate/100;
  3335. if (div_ > 1) //Multi-hit skills mean higher delays.
  3336. delay += battle_config.multihit_delay*(div_-1);
  3337. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3338. }
  3339. /*==========================================
  3340. * Sends a 'damage' packet (src performs action on dst)
  3341. * 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
  3342. * 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
  3343. *
  3344. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3345. * type=01 pick up item
  3346. * type=02 sit down
  3347. * type=03 stand up
  3348. * type=04 reflected/absorbed damage?
  3349. * type=08 double attack
  3350. * type=09 don't display flinch animation (endure)
  3351. * type=0a critical hit
  3352. * type=0b lucky dodge
  3353. *------------------------------------------*/
  3354. 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)
  3355. {
  3356. unsigned char buf[256];
  3357. struct status_change *sc;
  3358. nullpo_ret(src);
  3359. nullpo_ret(dst);
  3360. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3361. sc = status_get_sc(dst);
  3362. if(sc && sc->count) {
  3363. if(sc->data[SC_HALLUCINATION]) {
  3364. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3365. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3366. }
  3367. }
  3368. WBUFW(buf,0)=0x8a;
  3369. WBUFL(buf,2)=src->id;
  3370. WBUFL(buf,6)=dst->id;
  3371. WBUFL(buf,10)=tick;
  3372. WBUFL(buf,14)=sdelay;
  3373. WBUFL(buf,18)=ddelay;
  3374. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3375. WBUFW(buf,22)=damage?div:0;
  3376. WBUFW(buf,27)=damage2?div:0;
  3377. } else {
  3378. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3379. WBUFW(buf,27)=damage2;
  3380. }
  3381. WBUFW(buf,24)=div;
  3382. WBUFB(buf,26)=type;
  3383. if(disguised(dst)) {
  3384. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3385. WBUFL(buf,6) = -dst->id;
  3386. clif_send(buf,packet_len(0x8a),dst,SELF);
  3387. } else
  3388. clif_send(buf,packet_len(0x8a),dst,AREA);
  3389. if(disguised(src)) {
  3390. WBUFL(buf,2) = -src->id;
  3391. if (disguised(dst))
  3392. WBUFL(buf,6) = dst->id;
  3393. if(damage > 0) WBUFW(buf,22) = -1;
  3394. if(damage2 > 0) WBUFW(buf,27) = -1;
  3395. clif_send(buf,packet_len(0x8a),src,SELF);
  3396. }
  3397. //Return adjusted can't walk delay for further processing.
  3398. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3399. }
  3400. /*==========================================
  3401. * src picks up dst
  3402. *------------------------------------------*/
  3403. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3404. {
  3405. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3406. unsigned char buf[32];
  3407. nullpo_retv(src);
  3408. nullpo_retv(dst);
  3409. WBUFW(buf, 0) = 0x8a;
  3410. WBUFL(buf, 2) = src->id;
  3411. WBUFL(buf, 6) = dst->id;
  3412. WBUFB(buf,26) = 1;
  3413. clif_send(buf, packet_len(0x8a), src, AREA);
  3414. }
  3415. /*==========================================
  3416. * inform clients in area that `bl` is sitting
  3417. *------------------------------------------*/
  3418. void clif_sitting(struct block_list* bl)
  3419. {
  3420. unsigned char buf[32];
  3421. nullpo_retv(bl);
  3422. WBUFW(buf, 0) = 0x8a;
  3423. WBUFL(buf, 2) = bl->id;
  3424. WBUFB(buf,26) = 2;
  3425. clif_send(buf, packet_len(0x8a), bl, AREA);
  3426. if(disguised(bl)) {
  3427. WBUFL(buf, 2) = - bl->id;
  3428. clif_send(buf, packet_len(0x8a), bl, SELF);
  3429. }
  3430. }
  3431. /*==========================================
  3432. * inform clients in area that `bl` is standing
  3433. *------------------------------------------*/
  3434. void clif_standing(struct block_list* bl)
  3435. {
  3436. unsigned char buf[32];
  3437. nullpo_retv(bl);
  3438. WBUFW(buf, 0) = 0x8a;
  3439. WBUFL(buf, 2) = bl->id;
  3440. WBUFB(buf,26) = 3;
  3441. clif_send(buf, packet_len(0x8a), bl, AREA);
  3442. if(disguised(bl)) {
  3443. WBUFL(buf, 2) = - bl->id;
  3444. clif_send(buf, packet_len(0x8a), bl, SELF);
  3445. }
  3446. }
  3447. /*==========================================
  3448. * Inform client(s) about a map-cell change
  3449. *------------------------------------------*/
  3450. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3451. {
  3452. unsigned char buf[32];
  3453. WBUFW(buf,0) = 0x192;
  3454. WBUFW(buf,2) = x;
  3455. WBUFW(buf,4) = y;
  3456. WBUFW(buf,6) = type;
  3457. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3458. if( fd )
  3459. {
  3460. WFIFOHEAD(fd,packet_len(0x192));
  3461. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3462. WFIFOSET(fd,packet_len(0x192));
  3463. }
  3464. else
  3465. {
  3466. struct block_list dummy_bl;
  3467. dummy_bl.type = BL_NUL;
  3468. dummy_bl.x = x;
  3469. dummy_bl.y = y;
  3470. dummy_bl.m = m;
  3471. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3472. }
  3473. }
  3474. /*==========================================
  3475. *
  3476. *------------------------------------------*/
  3477. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3478. {
  3479. int view,fd;
  3480. fd=sd->fd;
  3481. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3482. WFIFOHEAD(fd,packet_len(0x9d));
  3483. WFIFOW(fd,0)=0x9d;
  3484. WFIFOL(fd,2)=fitem->bl.id;
  3485. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3486. WFIFOW(fd,6)=view;
  3487. else
  3488. WFIFOW(fd,6)=fitem->item_data.nameid;
  3489. WFIFOB(fd,8)=fitem->item_data.identify;
  3490. WFIFOW(fd,9)=fitem->bl.x;
  3491. WFIFOW(fd,11)=fitem->bl.y;
  3492. WFIFOW(fd,13)=fitem->item_data.amount;
  3493. WFIFOB(fd,15)=fitem->subx;
  3494. WFIFOB(fd,16)=fitem->suby;
  3495. WFIFOSET(fd,packet_len(0x9d));
  3496. }
  3497. /*==========================================
  3498. * 場所スキルエフェクトが視界に入る
  3499. *------------------------------------------*/
  3500. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3501. {
  3502. int fd = sd->fd;
  3503. #if PACKETVER >= 3
  3504. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3505. WFIFOHEAD(fd,packet_len(0x1c9));
  3506. WFIFOW(fd, 0)=0x1c9;
  3507. WFIFOL(fd, 2)=unit->bl.id;
  3508. WFIFOL(fd, 6)=unit->group->src_id;
  3509. WFIFOW(fd,10)=unit->bl.x;
  3510. WFIFOW(fd,12)=unit->bl.y;
  3511. WFIFOB(fd,14)=unit->group->unit_id;
  3512. WFIFOB(fd,15)=1;
  3513. WFIFOB(fd,16)=1;
  3514. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3515. WFIFOSET(fd,packet_len(0x1c9));
  3516. return;
  3517. }
  3518. #endif
  3519. WFIFOHEAD(fd,packet_len(0x11f));
  3520. WFIFOW(fd, 0)=0x11f;
  3521. WFIFOL(fd, 2)=unit->bl.id;
  3522. WFIFOL(fd, 6)=unit->group->src_id;
  3523. WFIFOW(fd,10)=unit->bl.x;
  3524. WFIFOW(fd,12)=unit->bl.y;
  3525. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3526. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3527. else
  3528. WFIFOB(fd,14)=unit->group->unit_id;
  3529. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3530. WFIFOSET(fd,packet_len(0x11f));
  3531. if(unit->group->skill_id == WZ_ICEWALL)
  3532. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3533. }
  3534. /*==========================================
  3535. * 場所スキルエフェクトが視界から消える
  3536. *------------------------------------------*/
  3537. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3538. {
  3539. nullpo_retv(unit);
  3540. WFIFOHEAD(fd,packet_len(0x120));
  3541. WFIFOW(fd, 0)=0x120;
  3542. WFIFOL(fd, 2)=unit->bl.id;
  3543. WFIFOSET(fd,packet_len(0x120));
  3544. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3545. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3546. }
  3547. /*==========================================
  3548. * 場所スキルエフェクト削除
  3549. *------------------------------------------*/
  3550. void clif_skill_delunit(struct skill_unit *unit)
  3551. {
  3552. unsigned char buf[16];
  3553. nullpo_retv(unit);
  3554. WBUFW(buf, 0)=0x120;
  3555. WBUFL(buf, 2)=unit->bl.id;
  3556. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3557. }
  3558. /*==========================================
  3559. * Sent when an object gets ankle-snared (ZC_SKILL_UPDATE)
  3560. * Only affects units with class [139,153] client-side
  3561. * R 01ac <object id>.l
  3562. *------------------------------------------*/
  3563. void clif_skillunit_update(struct block_list* bl)
  3564. {
  3565. unsigned char buf[6];
  3566. nullpo_retv(bl);
  3567. WBUFW(buf,0) = 0x1ac;
  3568. WBUFL(buf,2) = bl->id;
  3569. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3570. }
  3571. /*==========================================
  3572. *
  3573. *------------------------------------------*/
  3574. int clif_getareachar(struct block_list* bl,va_list ap)
  3575. {
  3576. struct map_session_data *sd;
  3577. nullpo_ret(bl);
  3578. sd=va_arg(ap,struct map_session_data*);
  3579. if (sd == NULL || !sd->fd)
  3580. return 0;
  3581. switch(bl->type){
  3582. case BL_ITEM:
  3583. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3584. break;
  3585. case BL_SKILL:
  3586. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3587. break;
  3588. default:
  3589. if(&sd->bl == bl)
  3590. break;
  3591. clif_getareachar_unit(sd,bl);
  3592. break;
  3593. }
  3594. return 0;
  3595. }
  3596. /*==========================================
  3597. * tbl has gone out of view-size of bl
  3598. *------------------------------------------*/
  3599. int clif_outsight(struct block_list *bl,va_list ap)
  3600. {
  3601. struct block_list *tbl;
  3602. struct view_data *vd;
  3603. TBL_PC *sd, *tsd;
  3604. tbl=va_arg(ap,struct block_list*);
  3605. if(bl == tbl) return 0;
  3606. sd = BL_CAST(BL_PC, bl);
  3607. tsd = BL_CAST(BL_PC, tbl);
  3608. if (tsd && tsd->fd)
  3609. { //tsd has lost sight of the bl object.
  3610. switch(bl->type){
  3611. case BL_PC:
  3612. if (sd->vd.class_ != INVISIBLE_CLASS)
  3613. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3614. if(sd->chatID){
  3615. struct chat_data *cd;
  3616. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3617. if(cd->usersd[0]==sd)
  3618. clif_dispchat(cd,tsd->fd);
  3619. }
  3620. if(sd->vender_id)
  3621. clif_closevendingboard(bl,tsd->fd);
  3622. if( sd->state.buyingstore )
  3623. clif_buyingstore_disappear_entry_single(tsd, sd);
  3624. break;
  3625. case BL_ITEM:
  3626. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3627. break;
  3628. case BL_SKILL:
  3629. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3630. break;
  3631. default:
  3632. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3633. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3634. break;
  3635. }
  3636. }
  3637. if (sd && sd->fd)
  3638. { //sd is watching tbl go out of view.
  3639. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3640. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3641. }
  3642. return 0;
  3643. }
  3644. /*==========================================
  3645. * tbl has come into view of bl
  3646. *------------------------------------------*/
  3647. int clif_insight(struct block_list *bl,va_list ap)
  3648. {
  3649. struct block_list *tbl;
  3650. TBL_PC *sd, *tsd;
  3651. tbl=va_arg(ap,struct block_list*);
  3652. if (bl == tbl) return 0;
  3653. sd = BL_CAST(BL_PC, bl);
  3654. tsd = BL_CAST(BL_PC, tbl);
  3655. if (tsd && tsd->fd)
  3656. { //Tell tsd that bl entered into his view
  3657. switch(bl->type){
  3658. case BL_ITEM:
  3659. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3660. break;
  3661. case BL_SKILL:
  3662. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3663. break;
  3664. default:
  3665. clif_getareachar_unit(tsd,bl);
  3666. break;
  3667. }
  3668. }
  3669. if (sd && sd->fd)
  3670. { //Tell sd that tbl walked into his view
  3671. clif_getareachar_unit(sd,tbl);
  3672. }
  3673. return 0;
  3674. }
  3675. /*==========================================
  3676. * スキルリストを送信する
  3677. *------------------------------------------*/
  3678. int clif_skillinfoblock(struct map_session_data *sd)
  3679. {
  3680. int fd;
  3681. int i,len,id;
  3682. nullpo_ret(sd);
  3683. fd=sd->fd;
  3684. if (!fd) return 0;
  3685. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3686. WFIFOW(fd,0) = 0x10f;
  3687. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  3688. {
  3689. if( (id = sd->status.skill[i].id) != 0 )
  3690. {
  3691. WFIFOW(fd,len) = id;
  3692. if( (id == MO_EXTREMITYFIST && sd->state.combo&1) || (id == TK_JUMPKICK && sd->state.combo&2) )
  3693. WFIFOW(fd,len+2) = INF_SELF_SKILL;
  3694. else
  3695. WFIFOW(fd,len+2) = skill_get_inf(id);
  3696. WFIFOW(fd,len+4) = 0;
  3697. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3698. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3699. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3700. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3701. if(sd->status.skill[i].flag == 0)
  3702. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3703. else
  3704. WFIFOB(fd,len+36) = 0;
  3705. len += 37;
  3706. }
  3707. }
  3708. WFIFOW(fd,2)=len;
  3709. WFIFOSET(fd,len);
  3710. return 1;
  3711. }
  3712. int clif_addskill(struct map_session_data *sd, int id )
  3713. {
  3714. int fd;
  3715. nullpo_ret(sd);
  3716. fd = sd->fd;
  3717. if (!fd) return 0;
  3718. if( sd->status.skill[id].id <= 0 )
  3719. return 0;
  3720. WFIFOHEAD(fd, packet_len(0x111));
  3721. WFIFOW(fd,0) = 0x111;
  3722. WFIFOW(fd,2) = id;
  3723. if( (id == MO_EXTREMITYFIST && sd->state.combo&1) || (id == TK_JUMPKICK && sd->state.combo&2) )
  3724. WFIFOW(fd,4) = INF_SELF_SKILL;
  3725. else
  3726. WFIFOW(fd,4) = skill_get_inf(id);
  3727. WFIFOW(fd,6) = 0;
  3728. WFIFOW(fd,8) = sd->status.skill[id].lv;
  3729. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  3730. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  3731. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3732. if( sd->status.skill[id].flag == 0 )
  3733. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3734. else
  3735. WFIFOB(fd,38) = 0;
  3736. WFIFOSET(fd,packet_len(0x111));
  3737. return 1;
  3738. }
  3739. int clif_deleteskill(struct map_session_data *sd, int id)
  3740. {
  3741. #if PACKETVER >= 20081217
  3742. int fd;
  3743. nullpo_ret(sd);
  3744. fd = sd->fd;
  3745. if( !fd ) return 0;
  3746. WFIFOHEAD(fd,packet_len(0x441));
  3747. WFIFOW(fd,0) = 0x441;
  3748. WFIFOW(fd,2) = id;
  3749. WFIFOSET(fd,packet_len(0x441));
  3750. return 1;
  3751. #else
  3752. return clif_skillinfoblock(sd);
  3753. #endif
  3754. }
  3755. /*==========================================
  3756. * スキル割り振り通知
  3757. *------------------------------------------*/
  3758. int clif_skillup(struct map_session_data *sd,int skill_num)
  3759. {
  3760. int fd;
  3761. nullpo_ret(sd);
  3762. fd=sd->fd;
  3763. WFIFOHEAD(fd,packet_len(0x10e));
  3764. WFIFOW(fd,0) = 0x10e;
  3765. WFIFOW(fd,2) = skill_num;
  3766. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3767. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3768. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3769. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3770. WFIFOSET(fd,packet_len(0x10e));
  3771. return 0;
  3772. }
  3773. /*==========================================
  3774. * スキル詠唱エフェクトを送信する
  3775. * pl:
  3776. * 0 = Yellow cast aura
  3777. * 1 = Water elemental cast aura
  3778. * 2 = Earth elemental cast aura
  3779. * 3 = Fire elemental cast aura
  3780. * 4 = Wind elemental cast aura
  3781. * 5 = Poison elemental cast aura
  3782. * 6 = White cast aura
  3783. * ? = like 0
  3784. *------------------------------------------*/
  3785. int clif_skillcasting(struct block_list* bl,
  3786. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3787. {
  3788. unsigned char buf[32];
  3789. WBUFW(buf,0) = 0x13e;
  3790. WBUFL(buf,2) = src_id;
  3791. WBUFL(buf,6) = dst_id;
  3792. WBUFW(buf,10) = dst_x;
  3793. WBUFW(buf,12) = dst_y;
  3794. WBUFW(buf,14) = skill_num;
  3795. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3796. WBUFL(buf,20) = casttime;
  3797. if (disguised(bl)) {
  3798. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3799. WBUFL(buf,2) = -src_id;
  3800. clif_send(buf,packet_len(0x13e), bl, SELF);
  3801. } else
  3802. clif_send(buf,packet_len(0x13e), bl, AREA);
  3803. return 0;
  3804. }
  3805. /*==========================================
  3806. *
  3807. *------------------------------------------*/
  3808. int clif_skillcastcancel(struct block_list* bl)
  3809. {
  3810. unsigned char buf[16];
  3811. nullpo_ret(bl);
  3812. WBUFW(buf,0) = 0x1b9;
  3813. WBUFL(buf,2) = bl->id;
  3814. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3815. return 0;
  3816. }
  3817. /// only when type==0:
  3818. /// if(skill_id==NV_BASIC)
  3819. /// btype==0 "skill failed" MsgStringTable[159]
  3820. /// btype==1 "no emotions" MsgStringTable[160]
  3821. /// btype==2 "no sit" MsgStringTable[161]
  3822. /// btype==3 "no chat" MsgStringTable[162]
  3823. /// btype==4 "no party" MsgStringTable[163]
  3824. /// btype==5 "no shout" MsgStringTable[164]
  3825. /// btype==6 "no PKing" MsgStringTable[165]
  3826. /// btype==7 "no alligning" MsgStringTable[383]
  3827. /// btype>=8: ignored
  3828. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3829. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3830. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3831. /// otherwise "skill failed" MsgStringTable[204]
  3832. /// btype irrelevant
  3833. /// type==1 "insufficient SP" MsgStringTable[202]
  3834. /// type==2 "insufficient HP" MsgStringTable[203]
  3835. /// type==3 "insufficient materials" MsgStringTable[808]
  3836. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3837. /// type==5 "insufficient zeny" MsgStringTable[233]
  3838. /// type==6 "wrong weapon" MsgStringTable[239]
  3839. /// type==7 "red gemstone needed" MsgStringTable[246]
  3840. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3841. /// type==9 "overweight" MsgStringTable[580]
  3842. /// type==10 "skill failed" MsgStringTable[285]
  3843. /// type>=11 ignored
  3844. ///
  3845. /// if(success!=0) doesn't display any of the previous messages
  3846. /// Note: when this packet is received an unknown flag is always set to 0,
  3847. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3848. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3849. {
  3850. int fd;
  3851. if (!sd) { //Since this is the most common nullpo....
  3852. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3853. return 0;
  3854. }
  3855. fd=sd->fd;
  3856. if (!fd) return 0;
  3857. if(battle_config.display_skill_fail&1)
  3858. return 0; //Disable all skill failed messages
  3859. if(type==0x4 && !sd->state.showdelay)
  3860. return 0; //Disable delay failed messages
  3861. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3862. return 0;
  3863. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3864. return 0;
  3865. WFIFOHEAD(fd,packet_len(0x110));
  3866. WFIFOW(fd,0) = 0x110;
  3867. WFIFOW(fd,2) = skill_id;
  3868. WFIFOL(fd,4) = btype;
  3869. WFIFOB(fd,8) = 0;// success
  3870. WFIFOB(fd,9) = type;
  3871. WFIFOSET(fd,packet_len(0x110));
  3872. return 1;
  3873. }
  3874. /*==========================================
  3875. * skill cooldown display icon
  3876. * R 043d <skill ID>.w <tick>.l
  3877. *------------------------------------------*/
  3878. int clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  3879. {
  3880. #if PACKETVER>=20081112
  3881. int fd;
  3882. nullpo_ret(sd);
  3883. fd=sd->fd;
  3884. WFIFOHEAD(fd,packet_len(0x043d));
  3885. WFIFOW(fd,0) = 0x043d;
  3886. WFIFOW(fd,2) = skillid;
  3887. WFIFOL(fd,4) = tick;
  3888. WFIFOSET(fd,packet_len(0x043d));
  3889. #endif
  3890. return 0;
  3891. }
  3892. /*==========================================
  3893. * skill attack effect and damage
  3894. * 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
  3895. *------------------------------------------*/
  3896. 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)
  3897. {
  3898. unsigned char buf[64];
  3899. struct status_change *sc;
  3900. nullpo_ret(src);
  3901. nullpo_ret(dst);
  3902. type = clif_calc_delay(type,div,damage,ddelay);
  3903. sc = status_get_sc(dst);
  3904. if(sc && sc->count) {
  3905. if(sc->data[SC_HALLUCINATION] && damage)
  3906. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3907. }
  3908. #if PACKETVER < 3
  3909. WBUFW(buf,0)=0x114;
  3910. WBUFW(buf,2)=skill_id;
  3911. WBUFL(buf,4)=src->id;
  3912. WBUFL(buf,8)=dst->id;
  3913. WBUFL(buf,12)=tick;
  3914. WBUFL(buf,16)=sdelay;
  3915. WBUFL(buf,20)=ddelay;
  3916. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3917. WBUFW(buf,24)=damage?div:0;
  3918. } else {
  3919. WBUFW(buf,24)=damage;
  3920. }
  3921. WBUFW(buf,26)=skill_lv;
  3922. WBUFW(buf,28)=div;
  3923. WBUFB(buf,30)=type;
  3924. if (disguised(dst)) {
  3925. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3926. WBUFL(buf,8)=-dst->id;
  3927. clif_send(buf,packet_len(0x114),dst,SELF);
  3928. } else
  3929. clif_send(buf,packet_len(0x114),dst,AREA);
  3930. if(disguised(src)) {
  3931. WBUFL(buf,4)=-src->id;
  3932. if (disguised(dst))
  3933. WBUFL(buf,8)=dst->id;
  3934. if(damage > 0)
  3935. WBUFW(buf,24)=-1;
  3936. clif_send(buf,packet_len(0x114),src,SELF);
  3937. }
  3938. #else
  3939. WBUFW(buf,0)=0x1de;
  3940. WBUFW(buf,2)=skill_id;
  3941. WBUFL(buf,4)=src->id;
  3942. WBUFL(buf,8)=dst->id;
  3943. WBUFL(buf,12)=tick;
  3944. WBUFL(buf,16)=sdelay;
  3945. WBUFL(buf,20)=ddelay;
  3946. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3947. WBUFL(buf,24)=damage?div:0;
  3948. } else {
  3949. WBUFL(buf,24)=damage;
  3950. }
  3951. WBUFW(buf,28)=skill_lv;
  3952. WBUFW(buf,30)=div;
  3953. WBUFB(buf,32)=type;
  3954. if (disguised(dst)) {
  3955. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3956. WBUFL(buf,8)=-dst->id;
  3957. clif_send(buf,packet_len(0x1de),dst,SELF);
  3958. } else
  3959. clif_send(buf,packet_len(0x1de),dst,AREA);
  3960. if(disguised(src)) {
  3961. WBUFL(buf,4)=-src->id;
  3962. if (disguised(dst))
  3963. WBUFL(buf,8)=dst->id;
  3964. if(damage > 0)
  3965. WBUFL(buf,24)=-1;
  3966. clif_send(buf,packet_len(0x1de),src,SELF);
  3967. }
  3968. #endif
  3969. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3970. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3971. }
  3972. /*==========================================
  3973. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3974. *------------------------------------------*/
  3975. /*
  3976. 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)
  3977. {
  3978. unsigned char buf[64];
  3979. struct status_change *sc;
  3980. nullpo_ret(src);
  3981. nullpo_ret(dst);
  3982. type = (type>0)?type:skill_get_hit(skill_id);
  3983. type = clif_calc_delay(type,div,damage,ddelay);
  3984. sc = status_get_sc(dst);
  3985. if(sc && sc->count) {
  3986. if(sc->data[SC_HALLUCINATION] && damage)
  3987. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3988. }
  3989. WBUFW(buf,0)=0x115;
  3990. WBUFW(buf,2)=skill_id;
  3991. WBUFL(buf,4)=src->id;
  3992. WBUFL(buf,8)=dst->id;
  3993. WBUFL(buf,12)=tick;
  3994. WBUFL(buf,16)=sdelay;
  3995. WBUFL(buf,20)=ddelay;
  3996. WBUFW(buf,24)=dst->x;
  3997. WBUFW(buf,26)=dst->y;
  3998. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3999. WBUFW(buf,28)=damage?div:0;
  4000. } else {
  4001. WBUFW(buf,28)=damage;
  4002. }
  4003. WBUFW(buf,30)=skill_lv;
  4004. WBUFW(buf,32)=div;
  4005. WBUFB(buf,34)=type;
  4006. clif_send(buf,packet_len(0x115),src,AREA);
  4007. if(disguised(src)) {
  4008. WBUFL(buf,4)=-src->id;
  4009. if(damage > 0)
  4010. WBUFW(buf,28)=-1;
  4011. clif_send(buf,packet_len(0x115),src,SELF);
  4012. }
  4013. if (disguised(dst)) {
  4014. WBUFL(buf,8)=-dst->id;
  4015. if (disguised(src))
  4016. WBUFL(buf,4)=src->id;
  4017. else if(damage > 0)
  4018. WBUFW(buf,28)=-1;
  4019. clif_send(buf,packet_len(0x115),dst,SELF);
  4020. }
  4021. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4022. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4023. }
  4024. */
  4025. /*==========================================
  4026. * 支援/回復スキルエフェクト
  4027. *------------------------------------------*/
  4028. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  4029. {
  4030. unsigned char buf[32];
  4031. nullpo_ret(dst);
  4032. WBUFW(buf,0)=0x11a;
  4033. WBUFW(buf,2)=skill_id;
  4034. WBUFW(buf,4)=min(heal, SHRT_MAX);
  4035. WBUFL(buf,6)=dst->id;
  4036. WBUFL(buf,10)=src?src->id:0;
  4037. WBUFB(buf,14)=fail;
  4038. if (disguised(dst)) {
  4039. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4040. WBUFL(buf,6)=-dst->id;
  4041. clif_send(buf,packet_len(0x11a),dst,SELF);
  4042. } else
  4043. clif_send(buf,packet_len(0x11a),dst,AREA);
  4044. if(src && disguised(src)) {
  4045. WBUFL(buf,10)=-src->id;
  4046. if (disguised(dst))
  4047. WBUFL(buf,6)=dst->id;
  4048. clif_send(buf,packet_len(0x11a),src,SELF);
  4049. }
  4050. return fail;
  4051. }
  4052. /*==========================================
  4053. * 場所スキルエフェクト
  4054. *------------------------------------------*/
  4055. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4056. {
  4057. unsigned char buf[32];
  4058. nullpo_ret(src);
  4059. WBUFW(buf,0)=0x117;
  4060. WBUFW(buf,2)=skill_id;
  4061. WBUFL(buf,4)=src->id;
  4062. WBUFW(buf,8)=val;
  4063. WBUFW(buf,10)=x;
  4064. WBUFW(buf,12)=y;
  4065. WBUFL(buf,14)=tick;
  4066. if(disguised(src)) {
  4067. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4068. WBUFL(buf,4)=-src->id;
  4069. clif_send(buf,packet_len(0x117),src,SELF);
  4070. } else
  4071. clif_send(buf,packet_len(0x117),src,AREA);
  4072. return 0;
  4073. }
  4074. /*==========================================
  4075. * 場所スキルエフェクト表示
  4076. *------------------------------------------*/
  4077. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4078. void clif_skill_setunit(struct skill_unit *unit)
  4079. {
  4080. unsigned char buf[128];
  4081. nullpo_retv(unit);
  4082. #if PACKETVER >= 3
  4083. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4084. WBUFW(buf, 0)=0x1c9;
  4085. WBUFL(buf, 2)=unit->bl.id;
  4086. WBUFL(buf, 6)=unit->group->src_id;
  4087. WBUFW(buf,10)=unit->bl.x;
  4088. WBUFW(buf,12)=unit->bl.y;
  4089. WBUFB(buf,14)=unit->group->unit_id;
  4090. WBUFB(buf,15)=1;
  4091. WBUFB(buf,16)=1;
  4092. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4093. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4094. return;
  4095. }
  4096. #endif
  4097. WBUFW(buf, 0)=0x11f;
  4098. WBUFL(buf, 2)=unit->bl.id;
  4099. WBUFL(buf, 6)=unit->group->src_id;
  4100. WBUFW(buf,10)=unit->bl.x;
  4101. WBUFW(buf,12)=unit->bl.y;
  4102. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4103. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4104. else
  4105. WBUFB(buf,14)=unit->group->unit_id;
  4106. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4107. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4108. }
  4109. /*==========================================
  4110. * ワープ場所選択
  4111. *------------------------------------------*/
  4112. 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)
  4113. {
  4114. int fd;
  4115. nullpo_retv(sd);
  4116. fd = sd->fd;
  4117. WFIFOHEAD(fd,packet_len(0x11c));
  4118. WFIFOW(fd,0) = 0x11c;
  4119. WFIFOW(fd,2) = skill_num;
  4120. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4121. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4122. else // normal map name
  4123. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4124. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4125. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4126. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4127. WFIFOSET(fd,packet_len(0x11c));
  4128. sd->menuskill_id = skill_num;
  4129. if (skill_num == AL_WARP)
  4130. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4131. else
  4132. sd->menuskill_val = skill_lv;
  4133. }
  4134. /// Memo message.
  4135. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4136. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  4137. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  4138. ///
  4139. /// @param sd Who receives the message
  4140. /// @param type What message
  4141. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4142. {
  4143. int fd;
  4144. nullpo_retv(sd);
  4145. fd=sd->fd;
  4146. WFIFOHEAD(fd,packet_len(0x11e));
  4147. WFIFOW(fd,0)=0x11e;
  4148. WFIFOB(fd,2)=type;
  4149. WFIFOSET(fd,packet_len(0x11e));
  4150. }
  4151. /// Teleport message.
  4152. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4153. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  4154. ///
  4155. /// @param sd Who receives the message
  4156. /// @param type What message
  4157. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4158. {
  4159. int fd;
  4160. nullpo_retv(sd);
  4161. fd=sd->fd;
  4162. WFIFOHEAD(fd,packet_len(0x189));
  4163. WFIFOW(fd,0)=0x189;
  4164. WFIFOW(fd,2)=type;
  4165. WFIFOSET(fd,packet_len(0x189));
  4166. }
  4167. /*==========================================
  4168. * モンスター情報
  4169. *------------------------------------------*/
  4170. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4171. {
  4172. struct status_data *status;
  4173. unsigned char buf[64];
  4174. int i;//, fix;
  4175. nullpo_ret(sd);
  4176. nullpo_ret(dst);
  4177. if( dst->type != BL_MOB )
  4178. return 0;
  4179. status = status_get_status_data(dst);
  4180. WBUFW(buf, 0)=0x18c;
  4181. WBUFW(buf, 2)=status_get_class(dst);
  4182. WBUFW(buf, 4)=status_get_lv(dst);
  4183. WBUFW(buf, 6)=status->size;
  4184. WBUFL(buf, 8)=status->hp;
  4185. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4186. +(battle_config.estimation_type&2?status->def2:0);
  4187. WBUFW(buf,14)=status->race;
  4188. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4189. +(battle_config.estimation_type&2?status->mdef2:0);
  4190. WBUFW(buf,18)= status->def_ele;
  4191. for(i=0;i<9;i++)
  4192. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4193. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4194. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4195. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4196. return 0;
  4197. }
  4198. /*==========================================
  4199. * アイテム合成可能リスト
  4200. *------------------------------------------*/
  4201. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4202. {
  4203. int i,c,view,fd;
  4204. nullpo_ret(sd);
  4205. if(sd->menuskill_id == AM_PHARMACY)
  4206. return 0; //Avoid resending the menu twice or more times...
  4207. fd=sd->fd;
  4208. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4209. WFIFOW(fd, 0)=0x18d;
  4210. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4211. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4212. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4213. WFIFOW(fd,c*8+ 4)= view;
  4214. else
  4215. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4216. WFIFOW(fd,c*8+ 6)= 0x0012;
  4217. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4218. c++;
  4219. }
  4220. }
  4221. WFIFOW(fd, 2)=c*8+8;
  4222. WFIFOSET(fd,WFIFOW(fd,2));
  4223. if(c > 0) {
  4224. sd->menuskill_id = AM_PHARMACY;
  4225. sd->menuskill_val = trigger;
  4226. return 1;
  4227. }
  4228. return 0;
  4229. }
  4230. /*==========================================
  4231. *
  4232. *------------------------------------------*/
  4233. void clif_cooking_list(struct map_session_data *sd, int trigger)
  4234. {
  4235. int fd;
  4236. int i, c;
  4237. int view;
  4238. nullpo_retv(sd);
  4239. fd = sd->fd;
  4240. WFIFOHEAD(fd, 6 + 2*MAX_SKILL_PRODUCE_DB);
  4241. WFIFOW(fd,0) = 0x25a;
  4242. WFIFOW(fd,4) = 1; // list type
  4243. c = 0;
  4244. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ )
  4245. {
  4246. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) )
  4247. continue;
  4248. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4249. WFIFOW(fd, 6+2*c)= view;
  4250. else
  4251. WFIFOW(fd, 6+2*c)= skill_produce_db[i].nameid;
  4252. c++;
  4253. }
  4254. WFIFOW(fd,2) = 6 + 2*c;
  4255. WFIFOSET(fd,WFIFOW(fd,2));
  4256. //TODO: replace with proper solution
  4257. if( c > 0 )
  4258. {
  4259. sd->menuskill_id = AM_PHARMACY;
  4260. sd->menuskill_val = trigger;
  4261. }
  4262. }
  4263. /*==========================================
  4264. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4265. *------------------------------------------*/
  4266. int clif_status_load(struct block_list *bl,int type, int flag)
  4267. {
  4268. int fd;
  4269. if (type == SI_BLANK) //It shows nothing on the client...
  4270. return 0;
  4271. if (bl->type != BL_PC)
  4272. return 0;
  4273. fd = ((struct map_session_data*)bl)->fd;
  4274. WFIFOHEAD(fd,packet_len(0x196));
  4275. WFIFOW(fd,0)=0x0196;
  4276. WFIFOW(fd,2)=type;
  4277. WFIFOL(fd,4)=bl->id;
  4278. WFIFOB(fd,8)=flag; //Status start
  4279. WFIFOSET(fd, packet_len(0x196));
  4280. return 0;
  4281. }
  4282. /*==========================================
  4283. * 状態異常アイコン/メッセージ表示
  4284. *------------------------------------------*/
  4285. int clif_status_change(struct block_list *bl,int type,int flag,unsigned int tick)
  4286. {
  4287. unsigned char buf[32];
  4288. if (type == SI_BLANK) //It shows nothing on the client...
  4289. return 0;
  4290. nullpo_ret(bl);
  4291. if (type == SI_BLANK || type == SI_MAXIMIZEPOWER || type == SI_RIDING ||
  4292. type == SI_FALCON || type == SI_TRICKDEAD || type == SI_BROKENARMOR ||
  4293. type == SI_BROKENWEAPON || type == SI_WEIGHT50 || type == SI_WEIGHT90 ||
  4294. type == SI_TENSIONRELAX || type == SI_LANDENDOW || type == SI_AUTOBERSERK ||
  4295. type == SI_BUMP || type == SI_READYSTORM || type == SI_READYDOWN ||
  4296. type == SI_READYTURN || type == SI_READYCOUNTER || type == SI_DODGE ||
  4297. type == SI_DEVIL || type == SI_NIGHT || type == SI_INTRAVISION)
  4298. tick=0;
  4299. if( battle_config.display_status_timers && tick>0 )
  4300. WBUFW(buf,0)=0x043f;
  4301. else
  4302. WBUFW(buf,0)=0x0196;
  4303. WBUFW(buf,2)=type;
  4304. WBUFL(buf,4)=bl->id;
  4305. WBUFB(buf,8)=flag;
  4306. if( battle_config.display_status_timers && tick>0 )
  4307. {
  4308. WBUFL(buf,9)=tick;
  4309. WBUFL(buf,13)=0;
  4310. WBUFL(buf,17)=0;
  4311. WBUFL(buf,21)=0;
  4312. }
  4313. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  4314. return 0;
  4315. }
  4316. /*==========================================
  4317. * Send message (modified by [Yor])
  4318. *------------------------------------------*/
  4319. int clif_displaymessage(const int fd, const char* mes)
  4320. {
  4321. // invalid pointer?
  4322. nullpo_retr(-1, mes);
  4323. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4324. if (fd == 0)
  4325. return 0;
  4326. else {
  4327. int len_mes = strlen(mes);
  4328. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4329. WFIFOHEAD(fd, 5 + len_mes);
  4330. WFIFOW(fd,0) = 0x8e;
  4331. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4332. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4333. WFIFOSET(fd, 5 + len_mes);
  4334. }
  4335. }
  4336. return 0;
  4337. }
  4338. /*==========================================
  4339. * 天の声を送信する
  4340. * Send broadcast message in yellow or blue (without font formatting).
  4341. * S 009A <len>.W <message>.?B
  4342. *------------------------------------------*/
  4343. int clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4344. {
  4345. int lp = type ? 4 : 0;
  4346. unsigned char *buf = (unsigned char*)aMallocA((4 + lp + len)*sizeof(unsigned char));
  4347. WBUFW(buf,0) = 0x9a;
  4348. WBUFW(buf,2) = 4 + lp + len;
  4349. if (type == 0x10) // bc_blue
  4350. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4351. else if (type == 0x20) // bc_woe
  4352. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4353. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4354. clif_send(buf, WBUFW(buf,2), bl, target);
  4355. if (buf)
  4356. aFree(buf);
  4357. return 0;
  4358. }
  4359. /*==========================================
  4360. * グローバルメッセージ
  4361. *------------------------------------------*/
  4362. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4363. {
  4364. char buf[100];
  4365. int len;
  4366. nullpo_retv(bl);
  4367. if(!message)
  4368. return;
  4369. len = strlen(message)+1;
  4370. if( len > sizeof(buf)-8 )
  4371. {
  4372. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4373. len = sizeof(buf)-8;
  4374. }
  4375. WBUFW(buf,0)=0x8d;
  4376. WBUFW(buf,2)=len+8;
  4377. WBUFL(buf,4)=bl->id;
  4378. strncpy((char *) WBUFP(buf,8),message,len);
  4379. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4380. }
  4381. /*==========================================
  4382. * Send main chat message [LuzZza]
  4383. *------------------------------------------*/
  4384. void clif_MainChatMessage(const char* message)
  4385. {
  4386. char buf[200];
  4387. int len;
  4388. if(!message)
  4389. return;
  4390. len = strlen(message)+1;
  4391. if (len+8 > sizeof(buf)) {
  4392. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4393. len = sizeof(buf)-8;
  4394. }
  4395. WBUFW(buf,0)=0x8d;
  4396. WBUFW(buf,2)=len+8;
  4397. WBUFL(buf,4)=0;
  4398. strncpy((char *) WBUFP(buf,8),message,len);
  4399. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4400. }
  4401. /*==========================================
  4402. * Send broadcast message with font formatting.
  4403. * S 01C3 <len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4404. * S 040C <len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4405. *------------------------------------------*/
  4406. 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)
  4407. {
  4408. unsigned char *buf = (unsigned char*)aMallocA((16 + len)*sizeof(unsigned char));
  4409. #if PACKETVER < 20080820
  4410. WBUFW(buf,0) = 0x1c3;
  4411. #else
  4412. WBUFW(buf,0) = 0x40c;
  4413. #endif
  4414. WBUFW(buf,2) = len + 16;
  4415. WBUFL(buf,4) = fontColor;
  4416. WBUFW(buf,8) = fontType;
  4417. WBUFW(buf,10) = fontSize;
  4418. WBUFW(buf,12) = fontAlign;
  4419. WBUFW(buf,14) = fontY;
  4420. memcpy(WBUFP(buf,16), mes, len);
  4421. clif_send(buf, WBUFW(buf,2), bl, target);
  4422. if (buf)
  4423. aFree(buf);
  4424. return 0;
  4425. }
  4426. /*==========================================
  4427. * HPSP回復エフェクトを送信する
  4428. *------------------------------------------*/
  4429. int clif_heal(int fd,int type,int val)
  4430. {
  4431. WFIFOHEAD(fd,packet_len(0x13d));
  4432. WFIFOW(fd,0)=0x13d;
  4433. WFIFOW(fd,2)=type;
  4434. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4435. WFIFOSET(fd,packet_len(0x13d));
  4436. return 0;
  4437. }
  4438. /*==========================================
  4439. * 復活する
  4440. *------------------------------------------*/
  4441. int clif_resurrection(struct block_list *bl,int type)
  4442. {
  4443. unsigned char buf[16];
  4444. nullpo_ret(bl);
  4445. WBUFW(buf,0)=0x148;
  4446. WBUFL(buf,2)=bl->id;
  4447. WBUFW(buf,6)=type;
  4448. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4449. if (disguised(bl))
  4450. clif_spawn(bl);
  4451. return 0;
  4452. }
  4453. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4454. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4455. {
  4456. int fd;
  4457. nullpo_retv(sd);
  4458. fd=sd->fd;
  4459. WFIFOHEAD(fd,packet_len(0x199));
  4460. WFIFOW(fd,0)=0x199;
  4461. WFIFOW(fd,2)=property;
  4462. WFIFOSET(fd,packet_len(0x199));
  4463. }
  4464. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2)
  4465. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4466. {
  4467. int fd;
  4468. nullpo_retv(sd);
  4469. fd=sd->fd;
  4470. WFIFOHEAD(fd,packet_len(0x1D6));
  4471. WFIFOW(fd,0)=0x1D6;
  4472. WFIFOW(fd,2)=type;
  4473. WFIFOSET(fd,packet_len(0x1D6));
  4474. }
  4475. /*==========================================
  4476. * PVP実装?(仮)
  4477. *------------------------------------------*/
  4478. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4479. {
  4480. if(type == 2) {
  4481. int fd = sd->fd;
  4482. WFIFOHEAD(fd,packet_len(0x19a));
  4483. WFIFOW(fd,0) = 0x19a;
  4484. WFIFOL(fd,2) = sd->bl.id;
  4485. WFIFOL(fd,6) = pvprank;
  4486. WFIFOL(fd,10) = pvpnum;
  4487. WFIFOSET(fd,packet_len(0x19a));
  4488. } else {
  4489. unsigned char buf[32];
  4490. WBUFW(buf,0) = 0x19a;
  4491. WBUFL(buf,2) = sd->bl.id;
  4492. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4493. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4494. else
  4495. WBUFL(buf,6) = pvprank;
  4496. WBUFL(buf,10) = pvpnum;
  4497. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4498. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4499. else if(!type)
  4500. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4501. else
  4502. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4503. }
  4504. return 0;
  4505. }
  4506. /*==========================================
  4507. *
  4508. *------------------------------------------*/
  4509. void clif_map_property_mapall(int map, enum map_property property)
  4510. {
  4511. struct block_list bl;
  4512. unsigned char buf[16];
  4513. bl.id = 0;
  4514. bl.type = BL_NUL;
  4515. bl.m = map;
  4516. WBUFW(buf,0)=0x199;
  4517. WBUFW(buf,2)=property;
  4518. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4519. }
  4520. /*==========================================
  4521. * 精錬エフェクトを送信する
  4522. *------------------------------------------*/
  4523. void clif_refine(int fd, int fail, int index, int val)
  4524. {
  4525. WFIFOHEAD(fd,packet_len(0x188));
  4526. WFIFOW(fd,0)=0x188;
  4527. WFIFOW(fd,2)=fail;
  4528. WFIFOW(fd,4)=index+2;
  4529. WFIFOW(fd,6)=val;
  4530. WFIFOSET(fd,packet_len(0x188));
  4531. }
  4532. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4533. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4534. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4535. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4536. void clif_upgrademessage(int fd, int result, int item_id)
  4537. {
  4538. WFIFOHEAD(fd,packet_len(0x223));
  4539. WFIFOW(fd,0)=0x223;
  4540. WFIFOL(fd,2)=result;
  4541. WFIFOW(fd,6)=item_id;
  4542. WFIFOSET(fd,packet_len(0x223));
  4543. }
  4544. /*==========================================
  4545. * Wisp/page is transmitted to the destination player
  4546. * R 0097 <len>.w <nick>.24B <message>.?B
  4547. * R 0097 <len>.w <nick>.24B <???>.L <message>.?B
  4548. *------------------------------------------*/
  4549. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4550. {
  4551. #if PACKETVER < 20091104
  4552. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4553. WFIFOW(fd,0) = 0x97;
  4554. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4555. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4556. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4557. WFIFOSET(fd,WFIFOW(fd,2));
  4558. #else
  4559. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4560. WFIFOW(fd,0) = 0x97;
  4561. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4562. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4563. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4564. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4565. WFIFOSET(fd,WFIFOW(fd,2));
  4566. #endif
  4567. return 0;
  4568. }
  4569. /*==========================================
  4570. * Inform the player about the result of his whisper action
  4571. * R 0098 <type>.B
  4572. * 0: success to send wisper
  4573. * 1: target character is not loged in
  4574. * 2: ignored by target
  4575. * 3: everyone ignored by target
  4576. *------------------------------------------*/
  4577. int clif_wis_end(int fd, int flag)
  4578. {
  4579. WFIFOHEAD(fd,packet_len(0x98));
  4580. WFIFOW(fd,0) = 0x98;
  4581. WFIFOW(fd,2) = flag;
  4582. WFIFOSET(fd,packet_len(0x98));
  4583. return 0;
  4584. }
  4585. /*==========================================
  4586. * キャラID名前引き結果を送信する
  4587. *------------------------------------------*/
  4588. int clif_solved_charname(int fd, int charid, const char* name)
  4589. {
  4590. WFIFOHEAD(fd,packet_len(0x194));
  4591. WFIFOW(fd,0)=0x194;
  4592. WFIFOL(fd,2)=charid;
  4593. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4594. WFIFOSET(fd,packet_len(0x194));
  4595. return 0;
  4596. }
  4597. /*==========================================
  4598. * カードの挿入可能リストを返す
  4599. *------------------------------------------*/
  4600. int clif_use_card(struct map_session_data *sd,int idx)
  4601. {
  4602. int i,c,ep;
  4603. int fd=sd->fd;
  4604. nullpo_ret(sd);
  4605. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4606. return 0;
  4607. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4608. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4609. ep=sd->inventory_data[idx]->equip;
  4610. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4611. WFIFOW(fd,0)=0x017b;
  4612. for(i=c=0;i<MAX_INVENTORY;i++){
  4613. int j;
  4614. if(sd->inventory_data[i] == NULL)
  4615. continue;
  4616. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4617. continue;
  4618. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4619. continue;
  4620. if(sd->status.inventory[i].identify==0 ) //Not identified
  4621. continue;
  4622. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4623. continue;
  4624. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4625. continue;
  4626. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4627. if( j == sd->inventory_data[i]->slot ) // No room
  4628. continue;
  4629. WFIFOW(fd,4+c*2)=i+2;
  4630. c++;
  4631. }
  4632. WFIFOW(fd,2)=4+c*2;
  4633. WFIFOSET(fd,WFIFOW(fd,2));
  4634. return 0;
  4635. }
  4636. /*==========================================
  4637. * カードの挿入終了
  4638. *------------------------------------------*/
  4639. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4640. {
  4641. int fd;
  4642. nullpo_ret(sd);
  4643. fd=sd->fd;
  4644. WFIFOHEAD(fd,packet_len(0x17d));
  4645. WFIFOW(fd,0)=0x17d;
  4646. WFIFOW(fd,2)=idx_equip+2;
  4647. WFIFOW(fd,4)=idx_card+2;
  4648. WFIFOB(fd,6)=flag;
  4649. WFIFOSET(fd,packet_len(0x17d));
  4650. return 0;
  4651. }
  4652. /*==========================================
  4653. * 鑑定可能アイテムリスト送信
  4654. *------------------------------------------*/
  4655. int clif_item_identify_list(struct map_session_data *sd)
  4656. {
  4657. int i,c;
  4658. int fd;
  4659. nullpo_ret(sd);
  4660. fd=sd->fd;
  4661. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4662. WFIFOW(fd,0)=0x177;
  4663. for(i=c=0;i<MAX_INVENTORY;i++){
  4664. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4665. WFIFOW(fd,c*2+4)=i+2;
  4666. c++;
  4667. }
  4668. }
  4669. if(c > 0) {
  4670. WFIFOW(fd,2)=c*2+4;
  4671. WFIFOSET(fd,WFIFOW(fd,2));
  4672. sd->menuskill_id = MC_IDENTIFY;
  4673. sd->menuskill_val = c;
  4674. }
  4675. return 0;
  4676. }
  4677. /*==========================================
  4678. * 鑑定結果
  4679. *------------------------------------------*/
  4680. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4681. {
  4682. int fd;
  4683. nullpo_ret(sd);
  4684. fd=sd->fd;
  4685. WFIFOHEAD(fd,packet_len(0x179));
  4686. WFIFOW(fd, 0)=0x179;
  4687. WFIFOW(fd, 2)=idx+2;
  4688. WFIFOB(fd, 4)=flag;
  4689. WFIFOSET(fd,packet_len(0x179));
  4690. return 0;
  4691. }
  4692. /*==========================================
  4693. * 修理可能アイテムリスト送信
  4694. *------------------------------------------*/
  4695. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4696. {
  4697. int i,c;
  4698. int fd;
  4699. int nameid;
  4700. nullpo_ret(sd);
  4701. nullpo_ret(dstsd);
  4702. fd=sd->fd;
  4703. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4704. WFIFOW(fd,0)=0x1fc;
  4705. for(i=c=0;i<MAX_INVENTORY;i++){
  4706. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4707. WFIFOW(fd,c*13+4) = i;
  4708. WFIFOW(fd,c*13+6) = nameid;
  4709. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4710. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4711. WFIFOB(fd,c*13+16)= c;
  4712. c++;
  4713. }
  4714. }
  4715. if(c > 0) {
  4716. WFIFOW(fd,2)=c*13+4;
  4717. WFIFOSET(fd,WFIFOW(fd,2));
  4718. sd->menuskill_id = BS_REPAIRWEAPON;
  4719. sd->menuskill_val = dstsd->bl.id;
  4720. }else
  4721. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4722. return 0;
  4723. }
  4724. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4725. {
  4726. int view,fd;
  4727. nullpo_ret(sd);
  4728. fd=sd->fd;
  4729. WFIFOHEAD(fd,packet_len(0x1fe));
  4730. WFIFOW(fd, 0)=0x1fe;
  4731. if((view = itemdb_viewid(nameid)) > 0)
  4732. WFIFOW(fd, 2)=view;
  4733. else
  4734. WFIFOW(fd, 2)=nameid;
  4735. WFIFOB(fd, 4)=flag;
  4736. WFIFOSET(fd,packet_len(0x1fe));
  4737. return 0;
  4738. }
  4739. /*==========================================
  4740. * Weapon Refining - Taken from jAthena
  4741. *------------------------------------------*/
  4742. int clif_item_refine_list(struct map_session_data *sd)
  4743. {
  4744. int i,c;
  4745. int fd;
  4746. int skilllv;
  4747. int wlv;
  4748. int refine_item[5];
  4749. nullpo_ret(sd);
  4750. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4751. fd=sd->fd;
  4752. refine_item[0] = -1;
  4753. refine_item[1] = pc_search_inventory(sd,1010);
  4754. refine_item[2] = pc_search_inventory(sd,1011);
  4755. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4756. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4757. WFIFOW(fd,0)=0x221;
  4758. for(i=c=0;i<MAX_INVENTORY;i++){
  4759. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4760. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4761. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4762. WFIFOW(fd,c*13+ 4)=i+2;
  4763. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4764. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4765. WFIFOW(fd,c*13+10)=0;
  4766. WFIFOB(fd,c*13+12)=c;
  4767. c++;
  4768. }
  4769. }
  4770. WFIFOW(fd,2)=c*13+4;
  4771. WFIFOSET(fd,WFIFOW(fd,2));
  4772. if (c > 0) {
  4773. sd->menuskill_id = WS_WEAPONREFINE;
  4774. sd->menuskill_val = skilllv;
  4775. }
  4776. return 0;
  4777. }
  4778. /*==========================================
  4779. * アイテムによる一時的なスキル効果
  4780. *------------------------------------------*/
  4781. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4782. {
  4783. int fd;
  4784. nullpo_ret(sd);
  4785. fd=sd->fd;
  4786. WFIFOHEAD(fd,packet_len(0x147));
  4787. WFIFOW(fd, 0)=0x147;
  4788. WFIFOW(fd, 2)=skillid;
  4789. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4790. WFIFOW(fd, 6)=0;
  4791. WFIFOW(fd, 8)=skilllv;
  4792. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4793. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4794. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4795. WFIFOB(fd,38)=0;
  4796. WFIFOSET(fd,packet_len(0x147));
  4797. return 0;
  4798. }
  4799. /*==========================================
  4800. * カートにアイテム追加
  4801. *------------------------------------------*/
  4802. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4803. {
  4804. int view,fd;
  4805. unsigned char *buf;
  4806. nullpo_ret(sd);
  4807. fd=sd->fd;
  4808. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4809. return 1;
  4810. #if PACKETVER < 5
  4811. WFIFOHEAD(fd,packet_len(0x124));
  4812. buf=WFIFOP(fd,0);
  4813. WBUFW(buf,0)=0x124;
  4814. WBUFW(buf,2)=n+2;
  4815. WBUFL(buf,4)=amount;
  4816. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4817. WBUFW(buf,8)=view;
  4818. else
  4819. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4820. WBUFB(buf,10)=sd->status.cart[n].identify;
  4821. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4822. WBUFB(buf,12)=sd->status.cart[n].refine;
  4823. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4824. WFIFOSET(fd,packet_len(0x124));
  4825. #else
  4826. WFIFOHEAD(fd,packet_len(0x1c5));
  4827. buf=WFIFOP(fd,0);
  4828. WBUFW(buf,0)=0x1c5;
  4829. WBUFW(buf,2)=n+2;
  4830. WBUFL(buf,4)=amount;
  4831. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4832. WBUFW(buf,8)=view;
  4833. else
  4834. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4835. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4836. WBUFB(buf,11)=sd->status.cart[n].identify;
  4837. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4838. WBUFB(buf,13)=sd->status.cart[n].refine;
  4839. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4840. WFIFOSET(fd,packet_len(0x1c5));
  4841. #endif
  4842. return 0;
  4843. }
  4844. /*==========================================
  4845. * カートからアイテム削除
  4846. *------------------------------------------*/
  4847. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4848. {
  4849. int fd;
  4850. nullpo_ret(sd);
  4851. fd=sd->fd;
  4852. WFIFOHEAD(fd,packet_len(0x125));
  4853. WFIFOW(fd,0)=0x125;
  4854. WFIFOW(fd,2)=n+2;
  4855. WFIFOL(fd,4)=amount;
  4856. WFIFOSET(fd,packet_len(0x125));
  4857. return 0;
  4858. }
  4859. /*==========================================
  4860. * Opens the shop creation menu.
  4861. * R 012d <num>.w
  4862. * 'num' is the number of allowed item slots
  4863. *------------------------------------------*/
  4864. void clif_openvendingreq(struct map_session_data* sd, int num)
  4865. {
  4866. int fd;
  4867. nullpo_retv(sd);
  4868. fd = sd->fd;
  4869. WFIFOHEAD(fd,packet_len(0x12d));
  4870. WFIFOW(fd,0) = 0x12d;
  4871. WFIFOW(fd,2) = num;
  4872. WFIFOSET(fd,packet_len(0x12d));
  4873. }
  4874. /*==========================================
  4875. * Displays a vending board to target/area
  4876. * R 0131 <ID>.l <message>.80B
  4877. *------------------------------------------*/
  4878. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4879. {
  4880. unsigned char buf[128];
  4881. nullpo_retv(bl);
  4882. WBUFW(buf,0) = 0x131;
  4883. WBUFL(buf,2) = bl->id;
  4884. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4885. if( fd ) {
  4886. WFIFOHEAD(fd,packet_len(0x131));
  4887. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4888. WFIFOSET(fd,packet_len(0x131));
  4889. } else {
  4890. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4891. }
  4892. }
  4893. /*==========================================
  4894. * Removes a vending board from screen
  4895. *------------------------------------------*/
  4896. void clif_closevendingboard(struct block_list* bl, int fd)
  4897. {
  4898. unsigned char buf[16];
  4899. nullpo_retv(bl);
  4900. WBUFW(buf,0) = 0x132;
  4901. WBUFL(buf,2) = bl->id;
  4902. if( fd ) {
  4903. WFIFOHEAD(fd,packet_len(0x132));
  4904. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4905. WFIFOSET(fd,packet_len(0x132));
  4906. } else {
  4907. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4908. }
  4909. }
  4910. /*==========================================
  4911. * Sends a list of items in a shop (ZC_PC_PURCHASE_ITEMLIST_FROMMC/ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  4912. * 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
  4913. * 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
  4914. *------------------------------------------*/
  4915. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4916. {
  4917. int i,fd;
  4918. int count;
  4919. struct map_session_data* vsd;
  4920. #if PACKETVER < 20100105
  4921. const int cmd = 0x133;
  4922. const int offset = 8;
  4923. #else
  4924. const int cmd = 0x800;
  4925. const int offset = 12;
  4926. #endif
  4927. nullpo_retv(sd);
  4928. nullpo_retv(vending);
  4929. nullpo_retv(vsd=map_id2sd(id));
  4930. fd = sd->fd;
  4931. count = vsd->vend_num;
  4932. WFIFOHEAD(fd, offset+count*22);
  4933. WFIFOW(fd,0) = cmd;
  4934. WFIFOW(fd,2) = offset+count*22;
  4935. WFIFOL(fd,4) = id;
  4936. #if PACKETVER >= 20100105
  4937. WFIFOL(fd,8) = vsd->vender_id;
  4938. #endif
  4939. for( i = 0; i < count; i++ )
  4940. {
  4941. int index = vending[i].index;
  4942. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4943. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  4944. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  4945. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  4946. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  4947. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4948. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  4949. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  4950. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  4951. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  4952. }
  4953. WFIFOSET(fd,WFIFOW(fd,2));
  4954. }
  4955. /*==========================================
  4956. * Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC)
  4957. * R 0135 <index>.w <amount>.w <fail>.B
  4958. * fail=1 - not enough zeny
  4959. * fail=2 - overweight
  4960. * fail=4 - out of stock
  4961. * fail=5 - "cannot use an npc shop while in a trade"
  4962. * fail=6 - Because the store information was incorrect the item was not purchased.
  4963. * fail=7 - No sales information.
  4964. *------------------------------------------*/
  4965. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4966. {
  4967. int fd;
  4968. nullpo_retv(sd);
  4969. fd = sd->fd;
  4970. WFIFOHEAD(fd,packet_len(0x135));
  4971. WFIFOW(fd,0) = 0x135;
  4972. WFIFOW(fd,2) = index+2;
  4973. WFIFOW(fd,4) = amount;
  4974. WFIFOB(fd,6) = fail;
  4975. WFIFOSET(fd,packet_len(0x135));
  4976. }
  4977. /*==========================================
  4978. * Shop creation success
  4979. * 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*
  4980. *------------------------------------------*/
  4981. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4982. {
  4983. int i,fd;
  4984. int count;
  4985. nullpo_retv(sd);
  4986. fd = sd->fd;
  4987. count = sd->vend_num;
  4988. WFIFOHEAD(fd, 8+count*22);
  4989. WFIFOW(fd,0) = 0x136;
  4990. WFIFOW(fd,2) = 8+count*22;
  4991. WFIFOL(fd,4) = id;
  4992. for( i = 0; i < count; i++ )
  4993. {
  4994. int index = vending[i].index;
  4995. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4996. WFIFOL(fd, 8+i*22) = vending[i].value;
  4997. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4998. WFIFOW(fd,14+i*22) = vending[i].amount;
  4999. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5000. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5001. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5002. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5003. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5004. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5005. }
  5006. WFIFOSET(fd,WFIFOW(fd,2));
  5007. }
  5008. /*==========================================
  5009. * Inform merchant that someone has bought an item.
  5010. * R 0137 <index>.w <amount>.w
  5011. *------------------------------------------*/
  5012. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5013. {
  5014. int fd;
  5015. nullpo_retv(sd);
  5016. fd = sd->fd;
  5017. WFIFOHEAD(fd,packet_len(0x137));
  5018. WFIFOW(fd,0) = 0x137;
  5019. WFIFOW(fd,2) = index+2;
  5020. WFIFOW(fd,4) = amount;
  5021. WFIFOSET(fd,packet_len(0x137));
  5022. }
  5023. /// Result of organizing a party.
  5024. /// R 00FA <result>.B
  5025. ///
  5026. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  5027. /// result=1 : MsgStringTable[78]="party name already exists"
  5028. /// result=2 : MsgStringTable[79]="already in a party"
  5029. /// result=other : nothing
  5030. int clif_party_created(struct map_session_data *sd,int result)
  5031. {
  5032. int fd;
  5033. nullpo_ret(sd);
  5034. fd=sd->fd;
  5035. WFIFOHEAD(fd,packet_len(0xfa));
  5036. WFIFOW(fd,0)=0xfa;
  5037. WFIFOB(fd,2)=result;
  5038. WFIFOSET(fd,packet_len(0xfa));
  5039. return 0;
  5040. }
  5041. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5042. {
  5043. unsigned char buf[96];
  5044. int i;
  5045. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5046. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5047. } else {
  5048. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5049. }
  5050. if (i >= MAX_PARTY) return 0; //Should never happen...
  5051. sd = p->data[i].sd;
  5052. WBUFW(buf, 0) = 0x1e9;
  5053. WBUFL(buf, 2) = sd->status.account_id;
  5054. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5055. WBUFW(buf,10) = sd->bl.x;
  5056. WBUFW(buf,12) = sd->bl.y;
  5057. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5058. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5059. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5060. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  5061. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5062. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5063. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5064. return 1;
  5065. }
  5066. /*==========================================
  5067. * Sends party information
  5068. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  5069. *------------------------------------------*/
  5070. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  5071. {
  5072. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5073. struct map_session_data* party_sd = NULL;
  5074. int i, c;
  5075. nullpo_ret(p);
  5076. WBUFW(buf,0) = 0xfb;
  5077. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5078. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5079. {
  5080. struct party_member* m = &p->party.member[i];
  5081. if(!m->account_id) continue;
  5082. if(party_sd == NULL) party_sd = p->data[i].sd;
  5083. WBUFL(buf,28+c*46) = m->account_id;
  5084. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5085. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5086. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5087. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5088. c++;
  5089. }
  5090. WBUFW(buf,2) = 28+c*46;
  5091. if(sd) { // send only to self
  5092. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5093. } else if (party_sd) { // send to whole party
  5094. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5095. }
  5096. return 0;
  5097. }
  5098. /*==========================================
  5099. * The player's 'party invite' state, sent during login
  5100. * R 02c9 <flag>.B
  5101. *------------------------------------------*/
  5102. void clif_partyinvitationstate(struct map_session_data* sd)
  5103. {
  5104. int fd;
  5105. nullpo_retv(sd);
  5106. fd = sd->fd;
  5107. WFIFOHEAD(fd, packet_len(0x2c9));
  5108. WFIFOW(fd, 0) = 0x2c9;
  5109. WFIFOB(fd, 2) = 0; // not implemented
  5110. WFIFOSET(fd, packet_len(0x2c9));
  5111. }
  5112. /*==========================================
  5113. * パーティ勧誘
  5114. *------------------------------------------*/
  5115. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5116. {
  5117. int fd;
  5118. struct party_data *p;
  5119. nullpo_ret(sd);
  5120. nullpo_ret(tsd);
  5121. fd=tsd->fd;
  5122. if( (p=party_search(sd->status.party_id))==NULL )
  5123. return 0;
  5124. WFIFOHEAD(fd,packet_len(0xfe));
  5125. WFIFOW(fd,0)=0xfe;
  5126. WFIFOL(fd,2)=sd->status.account_id; // FIXME: This is party_id
  5127. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5128. WFIFOSET(fd,packet_len(0xfe));
  5129. return 0;
  5130. }
  5131. /*==========================================
  5132. * Party invitation result.
  5133. * R 00fd <nick>.24S <flag>.B
  5134. * R 02c5 <nick>.24S <flag>.L
  5135. * Flag values are:
  5136. * 0 -> char is already in a party
  5137. * 1 -> party invite was rejected
  5138. * 2 -> party invite was accepted
  5139. * 3 -> party is full
  5140. * 4 -> char of the same account already joined the party
  5141. *------------------------------------------*/
  5142. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  5143. {
  5144. int fd;
  5145. nullpo_retv(sd);
  5146. fd=sd->fd;
  5147. #if PACKETVER < 20070821
  5148. WFIFOHEAD(fd,packet_len(0xfd));
  5149. WFIFOW(fd,0) = 0xfd;
  5150. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5151. WFIFOB(fd,26) = flag;
  5152. WFIFOSET(fd,packet_len(0xfd));
  5153. #else
  5154. WFIFOHEAD(fd,packet_len(0x2c5));
  5155. WFIFOW(fd,0) = 0x2c5;
  5156. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5157. WFIFOL(fd,26) = flag;
  5158. WFIFOSET(fd,packet_len(0x2c5));
  5159. #endif
  5160. }
  5161. /*==========================================
  5162. * パーティ設定送信
  5163. * flag & 0x001=exp変更ミス
  5164. * 0x010=item変更ミス
  5165. * 0x100=一人にのみ送信
  5166. *------------------------------------------*/
  5167. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5168. {
  5169. unsigned char buf[16];
  5170. #if PACKETVER<20090603
  5171. const int cmd = 0x101;
  5172. #else
  5173. const int cmd = 0x7d8;
  5174. #endif
  5175. nullpo_ret(p);
  5176. if(!sd && flag==0){
  5177. int i;
  5178. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5179. if (i < MAX_PARTY)
  5180. sd = p->data[i].sd;
  5181. }
  5182. if(!sd) return 0;
  5183. WBUFW(buf,0)=cmd;
  5184. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5185. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5186. WBUFW(buf,4)=0;
  5187. #if PACKETVER>=20090603
  5188. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5189. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5190. #endif
  5191. if(flag==0)
  5192. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5193. else
  5194. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5195. return 0;
  5196. }
  5197. /*==========================================
  5198. * パーティ脱退(脱退前に呼ぶこと)
  5199. *------------------------------------------*/
  5200. int clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5201. {
  5202. unsigned char buf[64];
  5203. int i;
  5204. nullpo_ret(p);
  5205. if(!sd && (flag&0xf0)==0)
  5206. {
  5207. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5208. if (i < MAX_PARTY)
  5209. sd = p->data[i].sd;
  5210. }
  5211. if(!sd) return 0;
  5212. WBUFW(buf,0)=0x105;
  5213. WBUFL(buf,2)=account_id;
  5214. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5215. WBUFB(buf,30)=flag&0x0f;
  5216. if((flag&0xf0)==0)
  5217. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5218. else
  5219. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5220. return 0;
  5221. }
  5222. /*==========================================
  5223. * パーティメッセージ送信
  5224. *------------------------------------------*/
  5225. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5226. {
  5227. struct map_session_data *sd;
  5228. int i;
  5229. nullpo_ret(p);
  5230. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5231. if(i < MAX_PARTY){
  5232. unsigned char buf[1024];
  5233. sd = p->data[i].sd;
  5234. WBUFW(buf,0)=0x109;
  5235. WBUFW(buf,2)=len+8;
  5236. WBUFL(buf,4)=account_id;
  5237. memcpy(WBUFP(buf,8),mes,len);
  5238. clif_send(buf,len+8,&sd->bl,PARTY);
  5239. }
  5240. return 0;
  5241. }
  5242. /*==========================================
  5243. * パーティ座標通知
  5244. *------------------------------------------*/
  5245. int clif_party_xy(struct map_session_data *sd)
  5246. {
  5247. unsigned char buf[16];
  5248. nullpo_ret(sd);
  5249. WBUFW(buf,0)=0x107;
  5250. WBUFL(buf,2)=sd->status.account_id;
  5251. WBUFW(buf,6)=sd->bl.x;
  5252. WBUFW(buf,8)=sd->bl.y;
  5253. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5254. return 0;
  5255. }
  5256. /*==========================================
  5257. * Sends x/y dot to a single fd. [Skotlex]
  5258. *------------------------------------------*/
  5259. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5260. {
  5261. WFIFOHEAD(fd,packet_len(0x107));
  5262. WFIFOW(fd,0)=0x107;
  5263. WFIFOL(fd,2)=sd->status.account_id;
  5264. WFIFOW(fd,6)=sd->bl.x;
  5265. WFIFOW(fd,8)=sd->bl.y;
  5266. WFIFOSET(fd,packet_len(0x107));
  5267. return 0;
  5268. }
  5269. /*==========================================
  5270. * パーティHP通知
  5271. *------------------------------------------*/
  5272. int clif_party_hp(struct map_session_data *sd)
  5273. {
  5274. unsigned char buf[16];
  5275. #if PACKETVER < 20100126
  5276. const int cmd = 0x106;
  5277. #else
  5278. const int cmd = 0x80e;
  5279. #endif
  5280. nullpo_ret(sd);
  5281. WBUFW(buf,0)=cmd;
  5282. WBUFL(buf,2)=sd->status.account_id;
  5283. #if PACKETVER < 20100126
  5284. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5285. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5286. WBUFW(buf,8) = 100;
  5287. } else {
  5288. WBUFW(buf,6) = sd->battle_status.hp;
  5289. WBUFW(buf,8) = sd->battle_status.max_hp;
  5290. }
  5291. #else
  5292. WBUFL(buf,6) = sd->battle_status.hp;
  5293. WBUFL(buf,10) = sd->battle_status.max_hp;
  5294. #endif
  5295. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5296. return 0;
  5297. }
  5298. /*==========================================
  5299. * Sends HP bar to a single fd. [Skotlex]
  5300. *------------------------------------------*/
  5301. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5302. {
  5303. #if PACKETVER < 20100126
  5304. const int cmd = 0x106;
  5305. #else
  5306. const int cmd = 0x80e;
  5307. #endif
  5308. WFIFOHEAD(fd,packet_len(cmd));
  5309. WFIFOW(fd,0) = cmd;
  5310. WFIFOL(fd,2) = id;
  5311. #if PACKETVER < 20100126
  5312. if( maxhp > SHRT_MAX )
  5313. {// To correctly display the %hp bar. [Skotlex]
  5314. WFIFOW(fd,6) = hp/(maxhp/100);
  5315. WFIFOW(fd,8) = 100;
  5316. } else {
  5317. WFIFOW(fd,6) = hp;
  5318. WFIFOW(fd,8) = maxhp;
  5319. }
  5320. #else
  5321. WFIFOL(fd,6) = hp;
  5322. WFIFOL(fd,10) = maxhp;
  5323. #endif
  5324. WFIFOSET(fd, packet_len(cmd));
  5325. }
  5326. /*==========================================
  5327. *
  5328. *------------------------------------------*/
  5329. int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  5330. {
  5331. struct map_session_data *sd, *tsd;
  5332. int level;
  5333. #if PACKETVER < 20100126
  5334. const int cmd = 0x106;
  5335. #else
  5336. const int cmd = 0x80e;
  5337. #endif
  5338. sd = va_arg(ap, struct map_session_data *);
  5339. tsd = (TBL_PC *)bl;
  5340. nullpo_ret(sd);
  5341. nullpo_ret(tsd);
  5342. if( !tsd->fd || tsd == sd )
  5343. return 0;
  5344. if( (level = pc_isGM(tsd)) < battle_config.disp_hpmeter || level < pc_isGM(sd) )
  5345. return 0;
  5346. WFIFOHEAD(tsd->fd,packet_len(cmd));
  5347. WFIFOW(tsd->fd,0) = cmd;
  5348. WFIFOL(tsd->fd,2) = sd->status.account_id;
  5349. #if PACKETVER < 20100126
  5350. if( sd->battle_status.max_hp > SHRT_MAX )
  5351. { //To correctly display the %hp bar. [Skotlex]
  5352. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5353. WFIFOW(tsd->fd,8) = 100;
  5354. } else {
  5355. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  5356. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  5357. }
  5358. #else
  5359. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  5360. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  5361. #endif
  5362. WFIFOSET(tsd->fd,packet_len(cmd));
  5363. return 0;
  5364. }
  5365. /*==========================================
  5366. * GMへ場所とHP通知
  5367. *------------------------------------------*/
  5368. int clif_hpmeter(struct map_session_data *sd)
  5369. {
  5370. nullpo_ret(sd);
  5371. if( battle_config.disp_hpmeter )
  5372. 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);
  5373. return 0;
  5374. }
  5375. /*==========================================
  5376. * パーティ場所移動(未使用)
  5377. *------------------------------------------*/
  5378. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5379. {
  5380. unsigned char buf[128];
  5381. nullpo_retv(sd);
  5382. nullpo_retv(p);
  5383. WBUFW(buf, 0) = 0x104;
  5384. WBUFL(buf, 2) = sd->status.account_id;
  5385. WBUFL(buf, 6) = 0;
  5386. WBUFW(buf,10) = sd->bl.x;
  5387. WBUFW(buf,12) = sd->bl.y;
  5388. WBUFB(buf,14) = !online;
  5389. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5390. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5391. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5392. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5393. }
  5394. /*==========================================
  5395. * 攻撃するために移動が必要
  5396. *------------------------------------------*/
  5397. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5398. {
  5399. int fd;
  5400. nullpo_ret(sd);
  5401. nullpo_ret(bl);
  5402. fd=sd->fd;
  5403. WFIFOHEAD(fd,packet_len(0x139));
  5404. WFIFOW(fd, 0)=0x139;
  5405. WFIFOL(fd, 2)=bl->id;
  5406. WFIFOW(fd, 6)=bl->x;
  5407. WFIFOW(fd, 8)=bl->y;
  5408. WFIFOW(fd,10)=sd->bl.x;
  5409. WFIFOW(fd,12)=sd->bl.y;
  5410. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5411. WFIFOSET(fd,packet_len(0x139));
  5412. return 0;
  5413. }
  5414. /*==========================================
  5415. * 製造エフェクト
  5416. *------------------------------------------*/
  5417. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5418. {
  5419. int view,fd;
  5420. nullpo_ret(sd);
  5421. fd = sd->fd;
  5422. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5423. WFIFOHEAD(fd,packet_len(0x18f));
  5424. WFIFOW(fd, 0)=0x18f;
  5425. WFIFOW(fd, 2)=flag;
  5426. if((view = itemdb_viewid(nameid)) > 0)
  5427. WFIFOW(fd, 4)=view;
  5428. else
  5429. WFIFOW(fd, 4)=nameid;
  5430. WFIFOSET(fd,packet_len(0x18f));
  5431. return 0;
  5432. }
  5433. // pet
  5434. int clif_catch_process(struct map_session_data *sd)
  5435. {
  5436. int fd;
  5437. nullpo_ret(sd);
  5438. fd=sd->fd;
  5439. WFIFOHEAD(fd,packet_len(0x19e));
  5440. WFIFOW(fd,0)=0x19e;
  5441. WFIFOSET(fd,packet_len(0x19e));
  5442. return 0;
  5443. }
  5444. int clif_pet_roulette(struct map_session_data *sd,int data)
  5445. {
  5446. int fd;
  5447. nullpo_ret(sd);
  5448. fd=sd->fd;
  5449. WFIFOHEAD(fd,packet_len(0x1a0));
  5450. WFIFOW(fd,0)=0x1a0;
  5451. WFIFOB(fd,2)=data;
  5452. WFIFOSET(fd,packet_len(0x1a0));
  5453. return 0;
  5454. }
  5455. /*==========================================
  5456. * pet卵リスト作成
  5457. *------------------------------------------*/
  5458. int clif_sendegg(struct map_session_data *sd)
  5459. {
  5460. //R 01a6 <len>.w <index>.w*
  5461. int i,n=0,fd;
  5462. nullpo_ret(sd);
  5463. fd=sd->fd;
  5464. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5465. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5466. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5467. return 0;
  5468. }
  5469. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5470. WFIFOW(fd,0)=0x1a6;
  5471. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5472. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5473. sd->inventory_data[i]->type!=IT_PETEGG ||
  5474. sd->status.inventory[i].amount<=0)
  5475. continue;
  5476. WFIFOW(fd,n*2+4)=i+2;
  5477. n++;
  5478. }
  5479. WFIFOW(fd,2)=4+n*2;
  5480. WFIFOSET(fd,WFIFOW(fd,2));
  5481. sd->menuskill_id = SA_TAMINGMONSTER;
  5482. sd->menuskill_val = -1;
  5483. return 0;
  5484. }
  5485. /*==========================================
  5486. * Sends a specific pet data update.
  5487. * type = 0 -> param = 0 (initial data)
  5488. * type = 1 -> param = intimacy value
  5489. * type = 2 -> param = hungry value
  5490. * type = 3 -> param = accessory id
  5491. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5492. * type = 5 -> param = hairstyle number
  5493. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5494. *------------------------------------------*/
  5495. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5496. {
  5497. uint8 buf[16];
  5498. nullpo_ret(pd);
  5499. WBUFW(buf,0) = 0x1a4;
  5500. WBUFB(buf,2) = type;
  5501. WBUFL(buf,3) = pd->bl.id;
  5502. WBUFL(buf,7) = param;
  5503. if (sd)
  5504. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5505. else
  5506. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5507. return 0;
  5508. }
  5509. int clif_send_petstatus(struct map_session_data *sd)
  5510. {
  5511. int fd;
  5512. struct s_pet *pet;
  5513. nullpo_ret(sd);
  5514. nullpo_ret(sd->pd);
  5515. fd=sd->fd;
  5516. pet = &sd->pd->pet;
  5517. WFIFOHEAD(fd,packet_len(0x1a2));
  5518. WFIFOW(fd,0)=0x1a2;
  5519. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5520. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5521. WFIFOW(fd,27)=pet->level;
  5522. WFIFOW(fd,29)=pet->hungry;
  5523. WFIFOW(fd,31)=pet->intimate;
  5524. WFIFOW(fd,33)=pet->equip;
  5525. #if PACKETVER >= 20081126
  5526. WFIFOW(fd,35)=pet->class_;
  5527. #endif
  5528. WFIFOSET(fd,packet_len(0x1a2));
  5529. return 0;
  5530. }
  5531. /*==========================================
  5532. *
  5533. *------------------------------------------*/
  5534. int clif_pet_emotion(struct pet_data *pd,int param)
  5535. {
  5536. unsigned char buf[16];
  5537. nullpo_ret(pd);
  5538. memset(buf,0,packet_len(0x1aa));
  5539. WBUFW(buf,0)=0x1aa;
  5540. WBUFL(buf,2)=pd->bl.id;
  5541. if(param >= 100 && pd->petDB->talk_convert_class) {
  5542. if(pd->petDB->talk_convert_class < 0)
  5543. return 0;
  5544. else if(pd->petDB->talk_convert_class > 0) {
  5545. param -= (pd->pet.class_ - 100)*100;
  5546. param += (pd->petDB->talk_convert_class - 100)*100;
  5547. }
  5548. }
  5549. WBUFL(buf,6)=param;
  5550. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5551. return 0;
  5552. }
  5553. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5554. {
  5555. int fd;
  5556. nullpo_ret(sd);
  5557. fd=sd->fd;
  5558. WFIFOHEAD(fd,packet_len(0x1a3));
  5559. WFIFOW(fd,0)=0x1a3;
  5560. WFIFOB(fd,2)=fail;
  5561. WFIFOW(fd,3)=foodid;
  5562. WFIFOSET(fd,packet_len(0x1a3));
  5563. return 0;
  5564. }
  5565. /*==========================================
  5566. * オートスペル リスト送信
  5567. *------------------------------------------*/
  5568. int clif_autospell(struct map_session_data *sd,int skilllv)
  5569. {
  5570. int fd;
  5571. nullpo_ret(sd);
  5572. fd=sd->fd;
  5573. WFIFOHEAD(fd,packet_len(0x1cd));
  5574. WFIFOW(fd, 0)=0x1cd;
  5575. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5576. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5577. else
  5578. WFIFOL(fd,2)= 0x00000000;
  5579. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5580. WFIFOL(fd,6)= MG_COLDBOLT;
  5581. else
  5582. WFIFOL(fd,6)= 0x00000000;
  5583. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5584. WFIFOL(fd,10)= MG_FIREBOLT;
  5585. else
  5586. WFIFOL(fd,10)= 0x00000000;
  5587. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5588. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5589. else
  5590. WFIFOL(fd,14)= 0x00000000;
  5591. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5592. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5593. else
  5594. WFIFOL(fd,18)= 0x00000000;
  5595. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5596. WFIFOL(fd,22)= MG_FIREBALL;
  5597. else
  5598. WFIFOL(fd,22)= 0x00000000;
  5599. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5600. WFIFOL(fd,26)= MG_FROSTDIVER;
  5601. else
  5602. WFIFOL(fd,26)= 0x00000000;
  5603. WFIFOSET(fd,packet_len(0x1cd));
  5604. sd->menuskill_id = SA_AUTOSPELL;
  5605. sd->menuskill_val = skilllv;
  5606. return 0;
  5607. }
  5608. /*==========================================
  5609. * Devotion's visual effect
  5610. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5611. *------------------------------------------*/
  5612. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5613. {
  5614. unsigned char buf[56];
  5615. int i;
  5616. nullpo_retv(src);
  5617. memset(buf,0,packet_len(0x1cf));
  5618. WBUFW(buf,0) = 0x1cf;
  5619. WBUFL(buf,2) = src->id;
  5620. if( src->type == BL_MER )
  5621. {
  5622. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5623. if( md && md->master && md->devotion_flag )
  5624. WBUFL(buf,6) = md->master->bl.id;
  5625. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5626. }
  5627. else
  5628. {
  5629. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5630. if( sd == NULL )
  5631. return;
  5632. for( i = 0; i < 5; i++ )
  5633. WBUFL(buf,6+4*i) = sd->devotion[i];
  5634. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5635. }
  5636. if( tsd )
  5637. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5638. else
  5639. clif_send(buf, packet_len(0x1cf), src, AREA);
  5640. }
  5641. /*==========================================
  5642. * 氣球
  5643. *------------------------------------------*/
  5644. int clif_spiritball(struct map_session_data *sd)
  5645. {
  5646. unsigned char buf[16];
  5647. nullpo_ret(sd);
  5648. WBUFW(buf,0)=0x1d0;
  5649. WBUFL(buf,2)=sd->bl.id;
  5650. WBUFW(buf,6)=sd->spiritball;
  5651. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5652. return 0;
  5653. }
  5654. /*==========================================
  5655. *
  5656. *------------------------------------------*/
  5657. int clif_combo_delay(struct block_list *bl,int wait)
  5658. {
  5659. unsigned char buf[32];
  5660. nullpo_ret(bl);
  5661. WBUFW(buf,0)=0x1d2;
  5662. WBUFL(buf,2)=bl->id;
  5663. WBUFL(buf,6)=wait;
  5664. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5665. return 0;
  5666. }
  5667. /*==========================================
  5668. *白刃取り
  5669. *------------------------------------------*/
  5670. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5671. {
  5672. unsigned char buf[32];
  5673. nullpo_retv(src);
  5674. WBUFW(buf,0)=0x1d1;
  5675. WBUFL(buf,2)=src->id;
  5676. WBUFL(buf,6)=dst_id;
  5677. WBUFL(buf,10)=active;
  5678. clif_send(buf,packet_len(0x1d1),src,AREA);
  5679. }
  5680. /*==========================================
  5681. * MVPエフェクト
  5682. *------------------------------------------*/
  5683. int clif_mvp_effect(struct map_session_data *sd)
  5684. {
  5685. unsigned char buf[16];
  5686. nullpo_ret(sd);
  5687. WBUFW(buf,0)=0x10c;
  5688. WBUFL(buf,2)=sd->bl.id;
  5689. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5690. return 0;
  5691. }
  5692. /*==========================================
  5693. * MVPアイテム所得
  5694. *------------------------------------------*/
  5695. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5696. {
  5697. int view,fd;
  5698. nullpo_ret(sd);
  5699. fd=sd->fd;
  5700. WFIFOHEAD(fd,packet_len(0x10a));
  5701. WFIFOW(fd,0)=0x10a;
  5702. if((view = itemdb_viewid(nameid)) > 0)
  5703. WFIFOW(fd,2)=view;
  5704. else
  5705. WFIFOW(fd,2)=nameid;
  5706. WFIFOSET(fd,packet_len(0x10a));
  5707. return 0;
  5708. }
  5709. /*==========================================
  5710. * MVP経験値所得
  5711. *------------------------------------------*/
  5712. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5713. {
  5714. int fd;
  5715. nullpo_ret(sd);
  5716. fd=sd->fd;
  5717. WFIFOHEAD(fd,packet_len(0x10b));
  5718. WFIFOW(fd,0)=0x10b;
  5719. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5720. WFIFOSET(fd,packet_len(0x10b));
  5721. return 0;
  5722. }
  5723. /*==========================================
  5724. * Guild creation result
  5725. * R 0167 <flag>.B
  5726. * flag = 0 -> "Guild has been created."
  5727. * flag = 1 -> "You are already in a Guild."
  5728. * flag = 2 -> "That Guild Name already exists."
  5729. * flag = 3 -> "You need the neccessary item to create a Guild."
  5730. *------------------------------------------*/
  5731. int clif_guild_created(struct map_session_data *sd,int flag)
  5732. {
  5733. int fd;
  5734. nullpo_ret(sd);
  5735. fd=sd->fd;
  5736. WFIFOHEAD(fd,packet_len(0x167));
  5737. WFIFOW(fd,0)=0x167;
  5738. WFIFOB(fd,2)=flag;
  5739. WFIFOSET(fd,packet_len(0x167));
  5740. return 0;
  5741. }
  5742. /*==========================================
  5743. * ギルド所属通知
  5744. *------------------------------------------*/
  5745. int clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5746. {
  5747. int ps,fd;
  5748. nullpo_ret(sd);
  5749. nullpo_ret(g);
  5750. fd=sd->fd;
  5751. ps=guild_getposition(g,sd);
  5752. WFIFOHEAD(fd,packet_len(0x16c));
  5753. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5754. WFIFOW(fd,0)=0x16c;
  5755. WFIFOL(fd,2)=g->guild_id;
  5756. WFIFOL(fd,6)=g->emblem_id;
  5757. WFIFOL(fd,10)=g->position[ps].mode;
  5758. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5759. WFIFOSET(fd,packet_len(0x16c));
  5760. return 0;
  5761. }
  5762. /*==========================================
  5763. * ギルドメンバログイン通知
  5764. *------------------------------------------*/
  5765. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5766. {
  5767. unsigned char buf[64];
  5768. nullpo_ret(g);
  5769. WBUFW(buf, 0)=0x16d;
  5770. WBUFL(buf, 2)=g->member[idx].account_id;
  5771. WBUFL(buf, 6)=g->member[idx].char_id;
  5772. WBUFL(buf,10)=flag;
  5773. if(g->member[idx].sd==NULL){
  5774. struct map_session_data *sd=guild_getavailablesd(g);
  5775. if(sd!=NULL)
  5776. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5777. }else
  5778. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5779. return 0;
  5780. }
  5781. // Function `clif_guild_memberlogin_notice` sends info about
  5782. // logins and logouts of a guild member to the rest members.
  5783. // But at the 1st time (after a player login or map changing)
  5784. // the client won't show the message.
  5785. // So I suggest use this function for sending "first-time-info"
  5786. // to some player on entering the game or changing location.
  5787. // At next time the client would always show the message.
  5788. // The function sends all the statuses in the single packet
  5789. // to economize traffic. [LuzZza]
  5790. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5791. {
  5792. struct guild *g;
  5793. unsigned char buf[14*128];
  5794. int i, count=0, p_len;
  5795. nullpo_ret(sd);
  5796. p_len = packet_len(0x16d);
  5797. if(!(g = guild_search(sd->status.guild_id)))
  5798. return 0;
  5799. for(i=0; i<g->max_member; i++) {
  5800. if(g->member[i].account_id > 0 &&
  5801. g->member[i].account_id != sd->status.account_id) {
  5802. WBUFW(buf,count*p_len) = 0x16d;
  5803. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5804. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5805. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5806. count++;
  5807. }
  5808. }
  5809. clif_send(buf, p_len*count, &sd->bl, SELF);
  5810. return 0;
  5811. }
  5812. /*==========================================
  5813. * ギルドマスター通知(14dへの応答)
  5814. *------------------------------------------*/
  5815. int clif_guild_masterormember(struct map_session_data *sd)
  5816. {
  5817. int fd;
  5818. nullpo_ret(sd);
  5819. fd=sd->fd;
  5820. WFIFOHEAD(fd,packet_len(0x14e));
  5821. WFIFOW(fd,0) = 0x14e;
  5822. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5823. WFIFOSET(fd,packet_len(0x14e));
  5824. return 0;
  5825. }
  5826. /*==========================================
  5827. * Basic Info (Territories [Valaris])
  5828. *------------------------------------------*/
  5829. int clif_guild_basicinfo(struct map_session_data *sd)
  5830. {
  5831. int fd,i,t;
  5832. struct guild *g;
  5833. struct guild_castle *gc = NULL;
  5834. nullpo_ret(sd);
  5835. fd = sd->fd;
  5836. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5837. return 0;
  5838. WFIFOHEAD(fd,packet_len(0x1b6));
  5839. WFIFOW(fd, 0)=0x1b6;//0x150;
  5840. WFIFOL(fd, 2)=g->guild_id;
  5841. WFIFOL(fd, 6)=g->guild_lv;
  5842. WFIFOL(fd,10)=g->connect_member;
  5843. WFIFOL(fd,14)=g->max_member;
  5844. WFIFOL(fd,18)=g->average_lv;
  5845. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT_MAX);
  5846. WFIFOL(fd,26)=g->next_exp;
  5847. WFIFOL(fd,30)=0; // Tax Points
  5848. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5849. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5850. WFIFOL(fd,42)=g->emblem_id;
  5851. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5852. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5853. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5854. {
  5855. gc = guild_castle_search(i);
  5856. if(gc && g->guild_id == gc->guild_id)
  5857. t++;
  5858. }
  5859. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5860. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5861. return 0;
  5862. }
  5863. /*==========================================
  5864. * ギルド同盟/敵対情報
  5865. *------------------------------------------*/
  5866. int clif_guild_allianceinfo(struct map_session_data *sd)
  5867. {
  5868. int fd,i,c;
  5869. struct guild *g;
  5870. nullpo_ret(sd);
  5871. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5872. return 0;
  5873. fd = sd->fd;
  5874. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5875. WFIFOW(fd, 0)=0x14c;
  5876. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5877. struct guild_alliance *a=&g->alliance[i];
  5878. if(a->guild_id>0){
  5879. WFIFOL(fd,c*32+4)=a->opposition;
  5880. WFIFOL(fd,c*32+8)=a->guild_id;
  5881. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5882. c++;
  5883. }
  5884. }
  5885. WFIFOW(fd, 2)=c*32+4;
  5886. WFIFOSET(fd,WFIFOW(fd,2));
  5887. return 0;
  5888. }
  5889. /*==========================================
  5890. * ギルドメンバーリスト
  5891. *------------------------------------------*/
  5892. int clif_guild_memberlist(struct map_session_data *sd)
  5893. {
  5894. int fd;
  5895. int i,c;
  5896. struct guild *g;
  5897. nullpo_ret(sd);
  5898. if( (fd = sd->fd) == 0 )
  5899. return 0;
  5900. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5901. return 0;
  5902. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5903. WFIFOW(fd, 0)=0x154;
  5904. for(i=0,c=0;i<g->max_member;i++){
  5905. struct guild_member *m=&g->member[i];
  5906. if(m->account_id==0)
  5907. continue;
  5908. WFIFOL(fd,c*104+ 4)=m->account_id;
  5909. WFIFOL(fd,c*104+ 8)=m->char_id;
  5910. WFIFOW(fd,c*104+12)=m->hair;
  5911. WFIFOW(fd,c*104+14)=m->hair_color;
  5912. WFIFOW(fd,c*104+16)=m->gender;
  5913. WFIFOW(fd,c*104+18)=m->class_;
  5914. WFIFOW(fd,c*104+20)=m->lv;
  5915. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT_MAX);
  5916. WFIFOL(fd,c*104+26)=m->online;
  5917. WFIFOL(fd,c*104+30)=m->position;
  5918. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5919. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5920. c++;
  5921. }
  5922. WFIFOW(fd, 2)=c*104+4;
  5923. WFIFOSET(fd,WFIFOW(fd,2));
  5924. return 0;
  5925. }
  5926. /*==========================================
  5927. * ギルド役職名リスト
  5928. *------------------------------------------*/
  5929. int clif_guild_positionnamelist(struct map_session_data *sd)
  5930. {
  5931. int i,fd;
  5932. struct guild *g;
  5933. nullpo_ret(sd);
  5934. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5935. return 0;
  5936. fd = sd->fd;
  5937. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5938. WFIFOW(fd, 0)=0x166;
  5939. for(i=0;i<MAX_GUILDPOSITION;i++){
  5940. WFIFOL(fd,i*28+4)=i;
  5941. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5942. }
  5943. WFIFOW(fd,2)=i*28+4;
  5944. WFIFOSET(fd,WFIFOW(fd,2));
  5945. return 0;
  5946. }
  5947. /*==========================================
  5948. * ギルド役職情報リスト
  5949. *------------------------------------------*/
  5950. int clif_guild_positioninfolist(struct map_session_data *sd)
  5951. {
  5952. int i,fd;
  5953. struct guild *g;
  5954. nullpo_ret(sd);
  5955. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5956. return 0;
  5957. fd = sd->fd;
  5958. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5959. WFIFOW(fd, 0)=0x160;
  5960. for(i=0;i<MAX_GUILDPOSITION;i++){
  5961. struct guild_position *p=&g->position[i];
  5962. WFIFOL(fd,i*16+ 4)=i;
  5963. WFIFOL(fd,i*16+ 8)=p->mode;
  5964. WFIFOL(fd,i*16+12)=i;
  5965. WFIFOL(fd,i*16+16)=p->exp_mode;
  5966. }
  5967. WFIFOW(fd, 2)=i*16+4;
  5968. WFIFOSET(fd,WFIFOW(fd,2));
  5969. return 0;
  5970. }
  5971. /*==========================================
  5972. * ギルド役職変更通知
  5973. *------------------------------------------*/
  5974. int clif_guild_positionchanged(struct guild *g,int idx)
  5975. {
  5976. struct map_session_data *sd;
  5977. unsigned char buf[128];
  5978. nullpo_ret(g);
  5979. WBUFW(buf, 0)=0x174;
  5980. WBUFW(buf, 2)=44;
  5981. WBUFL(buf, 4)=idx;
  5982. WBUFL(buf, 8)=g->position[idx].mode;
  5983. WBUFL(buf,12)=idx;
  5984. WBUFL(buf,16)=g->position[idx].exp_mode;
  5985. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5986. if( (sd=guild_getavailablesd(g))!=NULL )
  5987. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5988. return 0;
  5989. }
  5990. /*==========================================
  5991. * ギルドメンバ変更通知
  5992. *------------------------------------------*/
  5993. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5994. {
  5995. struct map_session_data *sd;
  5996. unsigned char buf[64];
  5997. nullpo_ret(g);
  5998. WBUFW(buf, 0)=0x156;
  5999. WBUFW(buf, 2)=16;
  6000. WBUFL(buf, 4)=g->member[idx].account_id;
  6001. WBUFL(buf, 8)=g->member[idx].char_id;
  6002. WBUFL(buf,12)=g->member[idx].position;
  6003. if( (sd=guild_getavailablesd(g))!=NULL )
  6004. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6005. return 0;
  6006. }
  6007. /*==========================================
  6008. * ギルドエンブレム送信
  6009. *------------------------------------------*/
  6010. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6011. {
  6012. int fd;
  6013. nullpo_ret(sd);
  6014. nullpo_ret(g);
  6015. fd = sd->fd;
  6016. if( g->emblem_len <= 0 )
  6017. return 0;
  6018. WFIFOHEAD(fd,g->emblem_len+12);
  6019. WFIFOW(fd,0)=0x152;
  6020. WFIFOW(fd,2)=g->emblem_len+12;
  6021. WFIFOL(fd,4)=g->guild_id;
  6022. WFIFOL(fd,8)=g->emblem_id;
  6023. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6024. WFIFOSET(fd,WFIFOW(fd,2));
  6025. return 0;
  6026. }
  6027. /// Sends update of the guild id/emblem id to everyone in the area.
  6028. void clif_guild_emblem_area(struct block_list* bl)
  6029. {
  6030. uint8 buf[12];
  6031. nullpo_retv(bl);
  6032. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6033. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6034. WBUFW(buf,0) = 0x1B4;
  6035. WBUFL(buf,2) = bl->id;
  6036. WBUFL(buf,6) = status_get_guild_id(bl);
  6037. WBUFW(buf,10) = status_get_emblem_id(bl);
  6038. clif_send(buf, 12, bl, AREA_WOS);
  6039. }
  6040. /*==========================================
  6041. * Send guild skills
  6042. *------------------------------------------*/
  6043. int clif_guild_skillinfo(struct map_session_data* sd)
  6044. {
  6045. int fd;
  6046. struct guild* g;
  6047. int i,c;
  6048. nullpo_ret(sd);
  6049. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6050. return 0;
  6051. fd = sd->fd;
  6052. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6053. WFIFOW(fd,0) = 0x0162;
  6054. WFIFOW(fd,4) = g->skill_point;
  6055. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6056. {
  6057. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6058. {
  6059. int id = g->skill[i].id;
  6060. int p = 6 + c*37;
  6061. WFIFOW(fd,p+0) = id;
  6062. WFIFOW(fd,p+2) = skill_get_inf(id);
  6063. WFIFOW(fd,p+4) = 0;
  6064. WFIFOW(fd,p+6) = g->skill[i].lv;
  6065. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6066. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6067. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6068. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6069. c++;
  6070. }
  6071. }
  6072. WFIFOW(fd,2) = 6 + c*37;
  6073. WFIFOSET(fd,WFIFOW(fd,2));
  6074. return 0;
  6075. }
  6076. /*==========================================
  6077. * Sends guild notice to client
  6078. * R 016f <str1z>.60B <str2z>.120B
  6079. *------------------------------------------*/
  6080. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6081. {
  6082. int fd;
  6083. nullpo_ret(sd);
  6084. nullpo_ret(g);
  6085. fd = sd->fd;
  6086. if ( !session_isActive(fd) )
  6087. return 0;
  6088. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6089. return 0;
  6090. WFIFOHEAD(fd,packet_len(0x16f));
  6091. WFIFOW(fd,0) = 0x16f;
  6092. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6093. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6094. WFIFOSET(fd,packet_len(0x16f));
  6095. return 0;
  6096. }
  6097. /*==========================================
  6098. * ギルドメンバ勧誘
  6099. *------------------------------------------*/
  6100. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6101. {
  6102. int fd;
  6103. nullpo_ret(sd);
  6104. nullpo_ret(g);
  6105. fd=sd->fd;
  6106. WFIFOHEAD(fd,packet_len(0x16a));
  6107. WFIFOW(fd,0)=0x16a;
  6108. WFIFOL(fd,2)=g->guild_id;
  6109. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6110. WFIFOSET(fd,packet_len(0x16a));
  6111. return 0;
  6112. }
  6113. /*==========================================
  6114. * Reply to invite request
  6115. * Flag:
  6116. * 0 = Already in guild.
  6117. * 1 = Offer rejected.
  6118. * 2 = Offer accepted.
  6119. * 3 = Guild full.
  6120. *------------------------------------------*/
  6121. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6122. {
  6123. int fd;
  6124. nullpo_ret(sd);
  6125. fd=sd->fd;
  6126. WFIFOHEAD(fd,packet_len(0x169));
  6127. WFIFOW(fd,0)=0x169;
  6128. WFIFOB(fd,2)=flag;
  6129. WFIFOSET(fd,packet_len(0x169));
  6130. return 0;
  6131. }
  6132. /*==========================================
  6133. * ギルドメンバ脱退通知
  6134. *------------------------------------------*/
  6135. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6136. {
  6137. unsigned char buf[128];
  6138. nullpo_ret(sd);
  6139. WBUFW(buf, 0)=0x15a;
  6140. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6141. memcpy(WBUFP(buf,26),mes,40);
  6142. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6143. return 0;
  6144. }
  6145. /*==========================================
  6146. * ギルドメンバ追放通知
  6147. *------------------------------------------*/
  6148. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  6149. {
  6150. unsigned char buf[128];
  6151. #if PACKETVER < 20100803
  6152. const unsigned short cmd = 0x15c;
  6153. #else
  6154. const unsigned short cmd = 0x839;
  6155. #endif
  6156. nullpo_ret(sd);
  6157. WBUFW(buf,0) = cmd;
  6158. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  6159. safestrncpy((char*)WBUFP(buf,26),mes,40);
  6160. #if PACKETVER < 20100803
  6161. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  6162. #endif
  6163. clif_send(buf,packet_len(cmd),&sd->bl,GUILD_NOBG);
  6164. return 0;
  6165. }
  6166. /*==========================================
  6167. * ギルド追放メンバリスト
  6168. *------------------------------------------*/
  6169. int clif_guild_expulsionlist(struct map_session_data *sd)
  6170. {
  6171. int fd;
  6172. int i,c;
  6173. struct guild *g;
  6174. nullpo_ret(sd);
  6175. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6176. return 0;
  6177. fd = sd->fd;
  6178. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  6179. WFIFOW(fd,0)=0x163;
  6180. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6181. struct guild_expulsion *e=&g->expulsion[i];
  6182. if(e->account_id>0){
  6183. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  6184. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  6185. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  6186. c++;
  6187. }
  6188. }
  6189. WFIFOW(fd,2) = 4 + c*88;
  6190. WFIFOSET(fd,WFIFOW(fd,2));
  6191. return 0;
  6192. }
  6193. /*==========================================
  6194. * ギルド会話
  6195. *------------------------------------------*/
  6196. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6197. {
  6198. struct map_session_data *sd;
  6199. unsigned char *buf;
  6200. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6201. WBUFW(buf, 0) = 0x17f;
  6202. WBUFW(buf, 2) = len + 4;
  6203. memcpy(WBUFP(buf,4), mes, len);
  6204. if ((sd = guild_getavailablesd(g)) != NULL)
  6205. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6206. if(buf) aFree(buf);
  6207. return 0;
  6208. }
  6209. /*==========================================
  6210. * ギルドスキル割り振り通知
  6211. *------------------------------------------*/
  6212. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6213. {
  6214. int fd;
  6215. nullpo_ret(sd);
  6216. fd=sd->fd;
  6217. WFIFOHEAD(fd,11);
  6218. WFIFOW(fd,0) = 0x10e;
  6219. WFIFOW(fd,2) = skill_num;
  6220. WFIFOW(fd,4) = lv;
  6221. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6222. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6223. WFIFOB(fd,10) = 1;
  6224. WFIFOSET(fd,11);
  6225. return 0;
  6226. }
  6227. /*==========================================
  6228. * ギルド同盟要請
  6229. *------------------------------------------*/
  6230. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6231. {
  6232. int fd;
  6233. nullpo_ret(sd);
  6234. fd=sd->fd;
  6235. WFIFOHEAD(fd,packet_len(0x171));
  6236. WFIFOW(fd,0)=0x171;
  6237. WFIFOL(fd,2)=account_id;
  6238. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6239. WFIFOSET(fd,packet_len(0x171));
  6240. return 0;
  6241. }
  6242. /*==========================================
  6243. * Reply to alliance request.
  6244. * Flag values are:
  6245. * 0: Already allied.
  6246. * 1: You rejected the offer.
  6247. * 2: You accepted the offer.
  6248. * 3: They have too any alliances
  6249. * 4: You have too many alliances.
  6250. *------------------------------------------*/
  6251. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6252. {
  6253. int fd;
  6254. nullpo_ret(sd);
  6255. fd=sd->fd;
  6256. WFIFOHEAD(fd,packet_len(0x173));
  6257. WFIFOW(fd,0)=0x173;
  6258. WFIFOL(fd,2)=flag;
  6259. WFIFOSET(fd,packet_len(0x173));
  6260. return 0;
  6261. }
  6262. /*==========================================
  6263. * ギルド関係解消通知
  6264. *------------------------------------------*/
  6265. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6266. {
  6267. int fd;
  6268. nullpo_ret(sd);
  6269. fd = sd->fd;
  6270. if (fd <= 0)
  6271. return 0;
  6272. WFIFOHEAD(fd,packet_len(0x184));
  6273. WFIFOW(fd,0)=0x184;
  6274. WFIFOL(fd,2)=guild_id;
  6275. WFIFOL(fd,6)=flag;
  6276. WFIFOSET(fd,packet_len(0x184));
  6277. return 0;
  6278. }
  6279. /*==========================================
  6280. * Reply to opposition request
  6281. * Flag:
  6282. * 0 = Antagonist has been set.
  6283. * 1 = Guild has too many Antagonists.
  6284. * 2 = Already set as an Antagonist.
  6285. *------------------------------------------*/
  6286. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6287. {
  6288. int fd;
  6289. nullpo_ret(sd);
  6290. fd=sd->fd;
  6291. WFIFOHEAD(fd,packet_len(0x181));
  6292. WFIFOW(fd,0)=0x181;
  6293. WFIFOB(fd,2)=flag;
  6294. WFIFOSET(fd,packet_len(0x181));
  6295. return 0;
  6296. }
  6297. /*==========================================
  6298. * ギルド関係追加
  6299. *------------------------------------------*/
  6300. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6301. {
  6302. unsigned char buf[64];
  6303. WBUFW(fd,0)=0x185;
  6304. WBUFL(fd,2)=g->alliance[idx].opposition;
  6305. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6306. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6307. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6308. return 0;
  6309. }*/
  6310. /*==========================================
  6311. * ギルド解散通知
  6312. *------------------------------------------*/
  6313. int clif_guild_broken(struct map_session_data *sd,int flag)
  6314. {
  6315. int fd;
  6316. nullpo_ret(sd);
  6317. fd=sd->fd;
  6318. WFIFOHEAD(fd,packet_len(0x15e));
  6319. WFIFOW(fd,0)=0x15e;
  6320. WFIFOL(fd,2)=flag;
  6321. WFIFOSET(fd,packet_len(0x15e));
  6322. return 0;
  6323. }
  6324. /*==========================================
  6325. * エモーション
  6326. *------------------------------------------*/
  6327. void clif_emotion(struct block_list *bl,int type)
  6328. {
  6329. unsigned char buf[8];
  6330. nullpo_retv(bl);
  6331. WBUFW(buf,0)=0xc0;
  6332. WBUFL(buf,2)=bl->id;
  6333. WBUFB(buf,6)=type;
  6334. clif_send(buf,packet_len(0xc0),bl,AREA);
  6335. }
  6336. /*==========================================
  6337. * トーキーボックス
  6338. *------------------------------------------*/
  6339. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6340. {
  6341. unsigned char buf[86];
  6342. nullpo_retv(bl);
  6343. WBUFW(buf,0) = 0x191;
  6344. WBUFL(buf,2) = bl->id;
  6345. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6346. clif_send(buf,packet_len(0x191),bl,AREA);
  6347. }
  6348. /*==========================================
  6349. * 結婚エフェクト
  6350. *------------------------------------------*/
  6351. void clif_wedding_effect(struct block_list *bl)
  6352. {
  6353. unsigned char buf[6];
  6354. nullpo_retv(bl);
  6355. WBUFW(buf,0) = 0x1ea;
  6356. WBUFL(buf,2) = bl->id;
  6357. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6358. }
  6359. /*==========================================
  6360. * ?なたに逢いたい使用時名前叫び
  6361. *------------------------------------------*/
  6362. void clif_callpartner(struct map_session_data *sd)
  6363. {
  6364. unsigned char buf[26];
  6365. const char *p;
  6366. nullpo_retv(sd);
  6367. if(sd->status.partner_id){
  6368. WBUFW(buf,0)=0x1e6;
  6369. p = map_charid2nick(sd->status.partner_id);
  6370. if(p){
  6371. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6372. }else{
  6373. WBUFB(buf,2) = 0;
  6374. }
  6375. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6376. }
  6377. }
  6378. /*==========================================
  6379. * Marry [DracoRPG]
  6380. *------------------------------------------
  6381. void clif_marriage_process(struct map_session_data *sd)
  6382. {
  6383. int fd;
  6384. nullpo_retv(sd);
  6385. fd=sd->fd;
  6386. WFIFOHEAD(fd,packet_len(0x1e4));
  6387. WFIFOW(fd,0)=0x1e4;
  6388. WFIFOSET(fd,packet_len(0x1e4));
  6389. }
  6390. */
  6391. /*==========================================
  6392. * Notice of divorce
  6393. *------------------------------------------*/
  6394. void clif_divorced(struct map_session_data* sd, const char* name)
  6395. {
  6396. int fd;
  6397. nullpo_retv(sd);
  6398. fd=sd->fd;
  6399. WFIFOHEAD(fd,packet_len(0x205));
  6400. WFIFOW(fd,0)=0x205;
  6401. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6402. WFIFOSET(fd, packet_len(0x205));
  6403. }
  6404. /*==========================================
  6405. *
  6406. *------------------------------------------*/
  6407. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6408. {
  6409. nullpo_retv(sd);
  6410. WFIFOHEAD(fd,packet_len(0x1e2));
  6411. WFIFOW(fd,0)=0x1e2;
  6412. WFIFOSET(fd, packet_len(0x1e2));
  6413. }
  6414. /*==========================================
  6415. *
  6416. *------------------------------------------*/
  6417. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6418. {
  6419. int fd;
  6420. nullpo_ret(sd);
  6421. fd = sd->fd;
  6422. if (!fd || !len) return 0; //Disconnected player.
  6423. WFIFOHEAD(fd, len+5);
  6424. WFIFOW(fd, 0) = 0x17f;
  6425. WFIFOW(fd, 2) = len + 5;
  6426. memcpy(WFIFOP(fd,4), mes, len);
  6427. WFIFOSET(fd, WFIFOW(fd,2));
  6428. return 1;
  6429. }
  6430. /*==========================================
  6431. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6432. *------------------------------------------*/
  6433. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6434. {
  6435. unsigned char buf[1024];
  6436. if (!len) return;
  6437. WBUFW(buf, 0) = 0x17f;
  6438. WBUFW(buf, 2) = len + 5;
  6439. memcpy(WBUFP(buf,4), mes, len);
  6440. clif_send(buf, WBUFW(buf,2), src, target);
  6441. return;
  6442. }
  6443. /*==========================================
  6444. *
  6445. *------------------------------------------*/
  6446. int clif_GM_kickack(struct map_session_data *sd, int id)
  6447. {
  6448. int fd;
  6449. nullpo_ret(sd);
  6450. fd = sd->fd;
  6451. WFIFOHEAD(fd,packet_len(0xcd));
  6452. WFIFOW(fd,0) = 0xcd;
  6453. WFIFOL(fd,2) = id;
  6454. WFIFOSET(fd, packet_len(0xcd));
  6455. return 0;
  6456. }
  6457. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6458. {
  6459. int fd = tsd->fd;
  6460. if( fd > 0 )
  6461. clif_authfail_fd(fd, 15);
  6462. else
  6463. map_quit(tsd);
  6464. if( sd )
  6465. clif_GM_kickack(sd,tsd->status.account_id);
  6466. }
  6467. /// Displays various manner-related status messages
  6468. /// R 014a <type>.L
  6469. /// type: 0 - "A manner point has been successfully aligned."
  6470. /// 1 - ?
  6471. /// 2 - ?
  6472. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6473. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6474. /// 5 - "You got a good point from %s."
  6475. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6476. {
  6477. int fd;
  6478. nullpo_retv(sd);
  6479. fd = sd->fd;
  6480. WFIFOHEAD(fd,packet_len(0x14a));
  6481. WFIFOW(fd,0) = 0x14a;
  6482. WFIFOL(fd,2) = type;
  6483. WFIFOSET(fd, packet_len(0x14a));
  6484. }
  6485. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6486. /// R 014b <type>.B <GM name>.24B
  6487. /// type: 0 - positive (unmute)
  6488. /// 1 - negative (mute)
  6489. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6490. {
  6491. int fd;
  6492. nullpo_retv(sd);
  6493. nullpo_retv(tsd);
  6494. fd = tsd->fd;
  6495. WFIFOHEAD(fd,packet_len(0x14b));
  6496. WFIFOW(fd,0) = 0x14b;
  6497. WFIFOB(fd,2) = type;
  6498. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6499. WFIFOSET(fd, packet_len(0x14b));
  6500. }
  6501. /*==========================================
  6502. * Wis拒否許可応答
  6503. *------------------------------------------*/
  6504. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6505. {
  6506. int fd;
  6507. nullpo_ret(sd);
  6508. fd=sd->fd;
  6509. WFIFOHEAD(fd,packet_len(0xd1));
  6510. WFIFOW(fd,0)=0xd1;
  6511. WFIFOB(fd,2)=type;
  6512. WFIFOB(fd,3)=flag;
  6513. WFIFOSET(fd,packet_len(0xd1));
  6514. return 0;
  6515. }
  6516. /*==========================================
  6517. * Wis全拒否許可応答
  6518. *------------------------------------------*/
  6519. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6520. {
  6521. int fd;
  6522. nullpo_ret(sd);
  6523. fd=sd->fd;
  6524. WFIFOHEAD(fd,packet_len(0xd2));
  6525. WFIFOW(fd,0)=0xd2;
  6526. WFIFOB(fd,2)=type;
  6527. WFIFOB(fd,3)=flag;
  6528. WFIFOSET(fd,packet_len(0xd2));
  6529. return 0;
  6530. }
  6531. /*==========================================
  6532. * Play a BGM! [Rikter/Yommy]
  6533. *------------------------------------------*/
  6534. void clif_playBGM(struct map_session_data* sd, const char* name)
  6535. {
  6536. int fd;
  6537. nullpo_retv(sd);
  6538. fd = sd->fd;
  6539. WFIFOHEAD(fd,packet_len(0x7fe));
  6540. WFIFOW(fd,0) = 0x7fe;
  6541. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6542. WFIFOSET(fd,packet_len(0x7fe));
  6543. }
  6544. /*==========================================
  6545. * サウンドエフェクト
  6546. *------------------------------------------*/
  6547. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6548. {
  6549. int fd;
  6550. nullpo_retv(sd);
  6551. nullpo_retv(bl);
  6552. fd = sd->fd;
  6553. WFIFOHEAD(fd,packet_len(0x1d3));
  6554. WFIFOW(fd,0) = 0x1d3;
  6555. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6556. WFIFOB(fd,26) = type;
  6557. WFIFOL(fd,27) = 0;
  6558. WFIFOL(fd,31) = bl->id;
  6559. WFIFOSET(fd,packet_len(0x1d3));
  6560. return;
  6561. }
  6562. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6563. {
  6564. unsigned char buf[40];
  6565. nullpo_ret(bl);
  6566. WBUFW(buf,0) = 0x1d3;
  6567. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6568. WBUFB(buf,26) = type;
  6569. WBUFL(buf,27) = 0;
  6570. WBUFL(buf,31) = bl->id;
  6571. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6572. return 0;
  6573. }
  6574. // displaying special effects (npcs, weather, etc) [Valaris]
  6575. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6576. {
  6577. unsigned char buf[24];
  6578. nullpo_ret(bl);
  6579. memset(buf, 0, packet_len(0x1f3));
  6580. WBUFW(buf,0) = 0x1f3;
  6581. WBUFL(buf,2) = bl->id;
  6582. WBUFL(buf,6) = type;
  6583. clif_send(buf, packet_len(0x1f3), bl, target);
  6584. if (disguised(bl)) {
  6585. WBUFL(buf,2) = -bl->id;
  6586. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6587. }
  6588. return 0;
  6589. }
  6590. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6591. {
  6592. WFIFOHEAD(fd,10);
  6593. WFIFOW(fd,0) = 0x1f3;
  6594. WFIFOL(fd,2) = bl->id;
  6595. WFIFOL(fd,6) = type;
  6596. WFIFOSET(fd,10);
  6597. }
  6598. /******************************************************
  6599. * W.<packet> W.<LENGTH> L.<ID> L.<COLOR> S.<TEXT>
  6600. * Mob/NPC Color Talk [SnakeDrak]
  6601. ******************************************************/
  6602. int clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg)
  6603. {
  6604. unsigned short msg_len = strlen(msg) + 1;
  6605. uint8 buf[256];
  6606. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6607. nullpo_ret(bl);
  6608. if( msg_len > sizeof(buf)-12 )
  6609. {
  6610. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6611. msg_len = sizeof(buf)-12;
  6612. }
  6613. WBUFW(buf,0) = 0x2C1;
  6614. WBUFW(buf,2) = msg_len + 12;
  6615. WBUFL(buf,4) = bl->id;
  6616. WBUFL(buf,8) = color;
  6617. memcpy(WBUFP(buf,12), msg, msg_len);
  6618. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6619. return 0;
  6620. }
  6621. // messages (from mobs/npcs) [Valaris]
  6622. int clif_message(struct block_list* bl, const char* msg)
  6623. {
  6624. unsigned short msg_len = strlen(msg) + 1;
  6625. uint8 buf[256];
  6626. nullpo_ret(bl);
  6627. if( msg_len > sizeof(buf)-8 )
  6628. {
  6629. ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  6630. msg_len = sizeof(buf)-8;
  6631. }
  6632. WBUFW(buf,0) = 0x8d;
  6633. WBUFW(buf,2) = msg_len + 8;
  6634. WBUFL(buf,4) = bl->id;
  6635. memcpy(WBUFP(buf,8), msg, msg_len);
  6636. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6637. return 0;
  6638. }
  6639. // refresh the client's screen, getting rid of any effects
  6640. int clif_refresh(struct map_session_data *sd)
  6641. {
  6642. nullpo_retr(-1, sd);
  6643. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6644. clif_inventorylist(sd);
  6645. if(pc_iscarton(sd)) {
  6646. clif_cartlist(sd);
  6647. clif_updatestatus(sd,SP_CARTINFO);
  6648. }
  6649. clif_updatestatus(sd,SP_WEIGHT);
  6650. clif_updatestatus(sd,SP_MAXWEIGHT);
  6651. clif_updatestatus(sd,SP_STR);
  6652. clif_updatestatus(sd,SP_AGI);
  6653. clif_updatestatus(sd,SP_VIT);
  6654. clif_updatestatus(sd,SP_INT);
  6655. clif_updatestatus(sd,SP_DEX);
  6656. clif_updatestatus(sd,SP_LUK);
  6657. if (sd->spiritball)
  6658. clif_spiritball_single(sd->fd, sd);
  6659. if (sd->vd.cloth_color)
  6660. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6661. if(merc_is_hom_active(sd->hd))
  6662. clif_send_homdata(sd,0,0);
  6663. if( sd->md )
  6664. {
  6665. clif_mercenary_info(sd);
  6666. clif_mercenary_skillblock(sd);
  6667. }
  6668. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6669. clif_weather_check(sd);
  6670. if( sd->chatID )
  6671. chat_leavechat(sd,0);
  6672. if( pc_issit(sd) )
  6673. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6674. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6675. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  6676. else
  6677. clif_changed_dir(&sd->bl, SELF);
  6678. #ifndef TXT_ONLY
  6679. mail_clear(sd);
  6680. #endif
  6681. return 0;
  6682. }
  6683. /// Updates the object's (bl) name on client (ZC_ACK_REQNAME/ZC_ACK_REQNAMEALL)
  6684. /// 0095 <unit id>.L <char name>.24B
  6685. /// 0195 <unit id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B
  6686. int clif_charnameack (int fd, struct block_list *bl)
  6687. {
  6688. unsigned char buf[103];
  6689. int cmd = 0x95, i, ps = -1;
  6690. nullpo_ret(bl);
  6691. WBUFW(buf,0) = cmd;
  6692. WBUFL(buf,2) = bl->id;
  6693. switch( bl->type )
  6694. {
  6695. case BL_PC:
  6696. {
  6697. struct map_session_data *ssd = (struct map_session_data *)bl;
  6698. struct party_data *p = NULL;
  6699. struct guild *g = NULL;
  6700. //Requesting your own "shadow" name. [Skotlex]
  6701. if (ssd->fd == fd && ssd->disguise)
  6702. WBUFL(buf,2) = -bl->id;
  6703. if( ssd->fakename[0] )
  6704. {
  6705. WBUFW(buf, 0) = cmd = 0x195;
  6706. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6707. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  6708. break;
  6709. }
  6710. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6711. if( ssd->status.party_id )
  6712. {
  6713. p = party_search(ssd->status.party_id);
  6714. }
  6715. if( ssd->status.guild_id )
  6716. {
  6717. if( ( g = guild_search(ssd->status.guild_id) ) != NULL )
  6718. {
  6719. 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);
  6720. if( i < g->max_member ) ps = g->member[i].position;
  6721. }
  6722. }
  6723. if( !battle_config.display_party_name && g == NULL )
  6724. {// do not display party unless the player is also in a guild
  6725. p = NULL;
  6726. }
  6727. if (p == NULL && g == NULL)
  6728. break;
  6729. WBUFW(buf, 0) = cmd = 0x195;
  6730. if (p)
  6731. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6732. else
  6733. WBUFB(buf,30) = 0;
  6734. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6735. {
  6736. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6737. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6738. } else { //Assume no guild.
  6739. WBUFB(buf,54) = 0;
  6740. WBUFB(buf,78) = 0;
  6741. }
  6742. }
  6743. break;
  6744. //[blackhole89]
  6745. case BL_HOM:
  6746. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6747. break;
  6748. case BL_MER:
  6749. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6750. break;
  6751. case BL_PET:
  6752. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6753. break;
  6754. case BL_NPC:
  6755. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6756. break;
  6757. case BL_MOB:
  6758. {
  6759. struct mob_data *md = (struct mob_data *)bl;
  6760. nullpo_ret(md);
  6761. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6762. if( md->guardian_data && md->guardian_data->guild_id )
  6763. {
  6764. WBUFW(buf, 0) = cmd = 0x195;
  6765. WBUFB(buf,30) = 0;
  6766. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6767. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6768. }
  6769. else if( battle_config.show_mob_info )
  6770. {
  6771. char mobhp[50], *str_p = mobhp;
  6772. WBUFW(buf, 0) = cmd = 0x195;
  6773. if( battle_config.show_mob_info&4 )
  6774. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6775. if( battle_config.show_mob_info&1 )
  6776. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6777. if( battle_config.show_mob_info&2 )
  6778. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6779. //Even thought mobhp ain't a name, we send it as one so the client
  6780. //can parse it. [Skotlex]
  6781. if( str_p != mobhp )
  6782. {
  6783. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6784. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6785. WBUFB(buf,54) = 0;
  6786. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6787. }
  6788. }
  6789. }
  6790. break;
  6791. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6792. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6793. // break;
  6794. return 0;
  6795. default:
  6796. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6797. return 0;
  6798. }
  6799. // if no receipient specified just update nearby clients
  6800. if (fd == 0)
  6801. clif_send(buf, packet_len(cmd), bl, AREA);
  6802. else {
  6803. WFIFOHEAD(fd, packet_len(cmd));
  6804. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6805. WFIFOSET(fd, packet_len(cmd));
  6806. }
  6807. return 0;
  6808. }
  6809. //Used to update when a char leaves a party/guild. [Skotlex]
  6810. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6811. int clif_charnameupdate (struct map_session_data *ssd)
  6812. {
  6813. unsigned char buf[103];
  6814. int cmd = 0x195, ps = -1, i;
  6815. struct party_data *p = NULL;
  6816. struct guild *g = NULL;
  6817. nullpo_ret(ssd);
  6818. if( ssd->fakename[0] )
  6819. return 0; //No need to update as the party/guild was not displayed anyway.
  6820. WBUFW(buf,0) = cmd;
  6821. WBUFL(buf,2) = ssd->bl.id;
  6822. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6823. if (!battle_config.display_party_name) {
  6824. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL)
  6825. p = party_search(ssd->status.party_id);
  6826. }else{
  6827. if (ssd->status.party_id > 0)
  6828. p = party_search(ssd->status.party_id);
  6829. }
  6830. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6831. {
  6832. 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);
  6833. if( i < g->max_member ) ps = g->member[i].position;
  6834. }
  6835. if( p )
  6836. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6837. else
  6838. WBUFB(buf,30) = 0;
  6839. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  6840. {
  6841. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6842. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6843. }
  6844. else
  6845. {
  6846. WBUFB(buf,54) = 0;
  6847. WBUFB(buf,78) = 0;
  6848. }
  6849. // Update nearby clients
  6850. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6851. return 0;
  6852. }
  6853. /// Visually moves(instant) a character to x,y. The char moves even
  6854. /// when the target cell isn't walkable. If the char is sitting it
  6855. /// stays that way.
  6856. void clif_slide(struct block_list *bl, int x, int y)
  6857. {
  6858. unsigned char buf[10];
  6859. nullpo_retv(bl);
  6860. WBUFW(buf, 0) = 0x01ff;
  6861. WBUFL(buf, 2) = bl->id;
  6862. WBUFW(buf, 6) = x;
  6863. WBUFW(buf, 8) = y;
  6864. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6865. if( disguised(bl) )
  6866. {
  6867. WBUFL(buf,2) = -bl->id;
  6868. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6869. }
  6870. }
  6871. /*------------------------------------------
  6872. * @me command by lordalfa, rewritten implementation by Skotlex
  6873. *------------------------------------------*/
  6874. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6875. {
  6876. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6877. int len_mes = strlen(mes)+1; //Account for \0
  6878. if (len_mes + 8 >= 256) {
  6879. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6880. len_mes = 247; //Trunk it to avoid problems.
  6881. }
  6882. // send message to others
  6883. WBUFW(buf,0) = 0x8d;
  6884. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6885. WBUFL(buf,4) = sd->bl.id;
  6886. memcpy(WBUFP(buf,8), mes, len_mes);
  6887. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6888. // send back message to the speaker
  6889. WBUFW(buf,0) = 0x8e;
  6890. WBUFW(buf, 2) = len_mes + 4;
  6891. memcpy(WBUFP(buf,4), mes, len_mes);
  6892. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6893. return 0;
  6894. }
  6895. /*==========================
  6896. * Minimap fix [Kevin]
  6897. * Remove dot from minimap
  6898. *--------------------------*/
  6899. int clif_party_xy_remove(struct map_session_data *sd)
  6900. {
  6901. unsigned char buf[16];
  6902. nullpo_ret(sd);
  6903. WBUFW(buf,0)=0x107;
  6904. WBUFL(buf,2)=sd->status.account_id;
  6905. WBUFW(buf,6)=-1;
  6906. WBUFW(buf,8)=-1;
  6907. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6908. return 0;
  6909. }
  6910. //Displays gospel-buff information (thanks to Rayce):
  6911. //Type determines message based on this table:
  6912. /*
  6913. 0x15 End all negative status
  6914. 0x16 Immunity to all status
  6915. 0x17 MaxHP +100%
  6916. 0x18 MaxSP +100%
  6917. 0x19 All stats +20
  6918. 0x1c Enchant weapon with Holy element
  6919. 0x1d Enchant armor with Holy element
  6920. 0x1e DEF +25%
  6921. 0x1f ATK +100%
  6922. 0x20 HIT/Flee +50
  6923. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6924. */
  6925. void clif_gospel_info(struct map_session_data *sd, int type)
  6926. {
  6927. int fd=sd->fd;
  6928. WFIFOHEAD(fd,packet_len(0x215));
  6929. WFIFOW(fd,0)=0x215;
  6930. WFIFOL(fd,2)=type;
  6931. WFIFOSET(fd, packet_len(0x215));
  6932. }
  6933. /// Multi purpose mission information packet (ZC_STARSKILL).
  6934. /// 0x20e <mapname>.24B <monster_id>.L <star>.B <result>.B
  6935. /// result:
  6936. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  6937. /// star:
  6938. /// 0 = Place of the Sun
  6939. /// 1 = Place of the Moon
  6940. /// 2 = Place of the Stars
  6941. /// 1 = Star Gladiator %s's %s: <mapname>
  6942. /// star:
  6943. /// 0 = Place of the Sun
  6944. /// 1 = Place of the Moon
  6945. /// 2 = Place of the Stars
  6946. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  6947. /// star:
  6948. /// 0 = Target of the Sun
  6949. /// 1 = Target of the Moon
  6950. /// 2 = Target of the Stars
  6951. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  6952. /// star:
  6953. /// 0 = Monster of the Sun
  6954. /// 1 = Monster of the Moon
  6955. /// 2 = Monster of the Stars
  6956. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  6957. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  6958. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  6959. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  6960. /// 40 = Target HP : <monster_id used as HP>
  6961. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  6962. {
  6963. int fd = sd->fd;
  6964. WFIFOHEAD(fd,packet_len(0x20e));
  6965. WFIFOW(fd,0) = 0x20e;
  6966. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  6967. WFIFOL(fd,26) = monster_id;
  6968. WFIFOB(fd,30) = star;
  6969. WFIFOB(fd,31) = result;
  6970. WFIFOSET(fd,packet_len(0x20e));
  6971. }
  6972. /*==========================================
  6973. * Info about Star Glaldiator save map [Komurka]
  6974. * type: 1: Information, 0: Map registered
  6975. *------------------------------------------*/
  6976. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6977. {
  6978. char mapname[MAP_NAME_LENGTH_EXT];
  6979. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  6980. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  6981. }
  6982. /*==========================================
  6983. * Info about Star Glaldiator hate mob [Komurka]
  6984. * type: 1: Register mob, 0: Information.
  6985. *------------------------------------------*/
  6986. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6987. {
  6988. if( pcdb_checkid(class_) )
  6989. {
  6990. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  6991. }
  6992. else if( mobdb_checkid(class_) )
  6993. {
  6994. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  6995. }
  6996. else
  6997. {
  6998. 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);
  6999. }
  7000. }
  7001. /*==========================================
  7002. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7003. *------------------------------------------*/
  7004. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7005. {
  7006. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7007. }
  7008. /*==========================================
  7009. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7010. *------------------------------------------*/
  7011. void clif_feel_hate_reset(struct map_session_data *sd)
  7012. {
  7013. clif_starskill(sd, "", 0, 0, 30);
  7014. }
  7015. /*==========================================
  7016. * Equip window (un)tick ack
  7017. * R 02d9 <zero>.L <flag>.L
  7018. *------------------------------------------*/
  7019. void clif_equiptickack(struct map_session_data* sd, int flag)
  7020. {
  7021. int fd;
  7022. nullpo_retv(sd);
  7023. fd = sd->fd;
  7024. WFIFOHEAD(fd, packet_len(0x2d9));
  7025. WFIFOW(fd, 0) = 0x2d9;
  7026. WFIFOL(fd, 2) = 0;
  7027. WFIFOL(fd, 6) = flag;
  7028. WFIFOSET(fd, packet_len(0x2d9));
  7029. }
  7030. /*==========================================
  7031. * The player's 'view equip' state, sent during login
  7032. * R 02da <flag>.B
  7033. *------------------------------------------*/
  7034. void clif_equipcheckbox(struct map_session_data* sd)
  7035. {
  7036. int fd;
  7037. nullpo_retv(sd);
  7038. fd = sd->fd;
  7039. WFIFOHEAD(fd, packet_len(0x2da));
  7040. WFIFOW(fd, 0) = 0x2da;
  7041. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7042. WFIFOSET(fd, packet_len(0x2da));
  7043. }
  7044. /*==========================================
  7045. * Sends info about a player's equipped items
  7046. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <up-viewid>.w <mid-viewid>.w <low-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.26B*
  7047. * for PACKETVER >= 20100629
  7048. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <bottom-viewid>.w <mid-viewid>.w <up-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.28B*
  7049. *------------------------------------------*/
  7050. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7051. {
  7052. int i, n, fd;
  7053. #if PACKETVER < 20100629
  7054. const int s = 26;
  7055. #else
  7056. const int s = 28;
  7057. #endif
  7058. nullpo_retv(sd);
  7059. nullpo_retv(tsd);
  7060. fd = sd->fd;
  7061. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7062. WFIFOW(fd, 0) = 0x2d7;
  7063. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  7064. WFIFOW(fd,28) = tsd->status.class_;
  7065. WFIFOW(fd,30) = tsd->vd.hair_style;
  7066. WFIFOW(fd,32) = tsd->vd.head_bottom;
  7067. WFIFOW(fd,34) = tsd->vd.head_mid;
  7068. WFIFOW(fd,36) = tsd->vd.head_top;
  7069. WFIFOW(fd,38) = tsd->vd.hair_color;
  7070. WFIFOW(fd,40) = tsd->vd.cloth_color;
  7071. WFIFOB(fd,42) = tsd->vd.sex;
  7072. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7073. {
  7074. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7075. continue;
  7076. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7077. continue;
  7078. // Inventory position
  7079. WFIFOW(fd, n*s+43) = i + 2;
  7080. // Add refine, identify flag, element, etc.
  7081. clif_item_sub(WFIFOP(fd,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7082. // Add cards
  7083. clif_addcards(WFIFOP(fd, n*s+55), &tsd->status.inventory[i]);
  7084. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7085. WFIFOL(fd, n*s+63) = tsd->status.inventory[i].expire_time;
  7086. WFIFOW(fd, n*s+67) = 0;
  7087. #if PACKETVER >= 20100629
  7088. if (tsd->inventory_data[i]->equip&EQP_HELM)
  7089. WFIFOW(fd, n*s+69) = tsd->inventory_data[i]->look;
  7090. else
  7091. WFIFOW(fd, n*s+69) = 0;
  7092. #endif
  7093. n++;
  7094. }
  7095. WFIFOW(fd, 2) = 43 + n*s; // Set length
  7096. WFIFOSET(fd, WFIFOW(fd, 2));
  7097. }
  7098. /// Display msgstringtable.txt string (ZC_MSG)
  7099. /// R 0291 <message>.W
  7100. void clif_msg(struct map_session_data* sd, unsigned short id)
  7101. {
  7102. int fd;
  7103. nullpo_retv(sd);
  7104. fd = sd->fd;
  7105. WFIFOHEAD(fd, packet_len(0x291));
  7106. WFIFOW(fd, 0) = 0x291;
  7107. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7108. WFIFOSET(fd, packet_len(0x291));
  7109. }
  7110. /// View player equip request denied
  7111. void clif_viewequip_fail(struct map_session_data* sd)
  7112. {
  7113. clif_msg(sd, 0x54d);
  7114. }
  7115. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7116. /// Returns true if the packet was parsed successfully.
  7117. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7118. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7119. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7120. {
  7121. char *text, *name, *message;
  7122. unsigned int packetlen, textlen, namelen, messagelen;
  7123. int fd = sd->fd;
  7124. *name_ = NULL;
  7125. *namelen_ = 0;
  7126. *message_ = NULL;
  7127. *messagelen_ = 0;
  7128. packetlen = RFIFOW(fd,2);
  7129. // basic structure checks
  7130. if( packetlen > RFIFOREST(fd) )
  7131. { // there has to be enough data to read
  7132. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7133. return false;
  7134. }
  7135. if( packetlen < 4 + 1 )
  7136. { // 4-byte header and at least an empty string is expected
  7137. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7138. return false;
  7139. }
  7140. text = (char*)RFIFOP(fd,4);
  7141. textlen = packetlen - 4;
  7142. // process <name> part of the packet
  7143. if( format == 0 )
  7144. {// name and message are separated by ' : '
  7145. // validate name
  7146. name = text;
  7147. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7148. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7149. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7150. {
  7151. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7152. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7153. set_eof(fd); // Just kick them out to correct it.
  7154. return false;
  7155. }
  7156. message = name + namelen + 3;
  7157. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7158. }
  7159. else
  7160. {// name has fixed width
  7161. if( textlen < NAME_LENGTH + 1 )
  7162. {
  7163. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7164. return false;
  7165. }
  7166. // validate name
  7167. name = text;
  7168. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7169. if( name[namelen] != '\0' )
  7170. { // only restriction is that the name must be zero-terminated
  7171. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7172. return false;
  7173. }
  7174. message = name + NAME_LENGTH;
  7175. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7176. }
  7177. if( messagelen != strnlen(message, messagelen)+1 )
  7178. { // the declared length must match real length
  7179. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7180. return false;
  7181. }
  7182. // verify <message> part of the packet
  7183. if( message[messagelen-1] != '\0' )
  7184. { // message must be zero-terminated
  7185. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7186. return false;
  7187. }
  7188. if( messagelen > CHAT_SIZE_MAX-1 )
  7189. { // messages mustn't be too long
  7190. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7191. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7192. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7193. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7194. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7195. return false;
  7196. }
  7197. *name_ = name;
  7198. *namelen_ = namelen;
  7199. *message_ = message;
  7200. *messagelen_ = messagelen;
  7201. return true;
  7202. }
  7203. // ---------------------
  7204. // clif_guess_PacketVer
  7205. // ---------------------
  7206. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7207. // error codes:
  7208. // 0 - Success
  7209. // 1 - Unknown packet_ver
  7210. // 2 - Invalid account_id
  7211. // 3 - Invalid char_id
  7212. // 4 - Invalid login_id1 (reserved)
  7213. // 5 - Invalid client_tick (reserved)
  7214. // 6 - Invalid sex
  7215. // Only the first 'invalid' error that appears is used.
  7216. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7217. {
  7218. static int err = 1;
  7219. static int packet_ver = -1;
  7220. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7221. if (get_previous)
  7222. {//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]
  7223. if( error )
  7224. *error = err;
  7225. return packet_ver;
  7226. }
  7227. //By default, start searching on the default one.
  7228. err = 1;
  7229. packet_ver = clif_config.packet_db_ver;
  7230. cmd = RFIFOW(fd,0);
  7231. packet_len = RFIFOREST(fd);
  7232. #define SET_ERROR(n) \
  7233. if( err == 1 )\
  7234. err = n;\
  7235. //define SET_ERROR
  7236. // FIXME: If the packet is not received at once, this will FAIL.
  7237. // Figure out, when it happens, that only part of the packet is
  7238. // received, or fix the function to be able to deal with that
  7239. // case.
  7240. #define CHECK_PACKET_VER() \
  7241. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7242. ;/* not wanttoconnection or wrong length */\
  7243. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7244. { SET_ERROR(2); }/* invalid account_id */\
  7245. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7246. { SET_ERROR(3); }/* invalid char_id */\
  7247. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7248. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7249. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7250. { SET_ERROR(6); }/* invalid sex */\
  7251. else\
  7252. {\
  7253. err = 0;\
  7254. if( error )\
  7255. *error = 0;\
  7256. return packet_ver;\
  7257. }\
  7258. //define CHECK_PACKET_VER
  7259. CHECK_PACKET_VER();//Default packet version found.
  7260. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7261. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7262. CHECK_PACKET_VER();
  7263. }
  7264. if( error )
  7265. *error = err;
  7266. packet_ver = -1;
  7267. return -1;
  7268. #undef SET_ERROR
  7269. #undef CHECK_PACKET_VER
  7270. }
  7271. // ------------
  7272. // clif_parse_*
  7273. // ------------
  7274. // パケット読み取って色々操作
  7275. /*==========================================
  7276. *
  7277. *------------------------------------------*/
  7278. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7279. {
  7280. struct block_list* bl;
  7281. struct auth_node* node;
  7282. int cmd, account_id, char_id, login_id1, sex;
  7283. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7284. 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])
  7285. if (sd) {
  7286. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7287. return;
  7288. }
  7289. // Only valid packet version get here
  7290. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7291. cmd = RFIFOW(fd,0);
  7292. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7293. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7294. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7295. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7296. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7297. if( packet_ver < 5 || // reject really old client versions
  7298. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7299. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7300. {// packet version rejected
  7301. 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));
  7302. WFIFOHEAD(fd,packet_len(0x6a));
  7303. WFIFOW(fd,0) = 0x6a;
  7304. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7305. WFIFOSET(fd,packet_len(0x6a));
  7306. set_eof(fd);
  7307. return;
  7308. }
  7309. //Check for double login.
  7310. bl = map_id2bl(account_id);
  7311. if(bl && bl->type != BL_PC) {
  7312. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7313. WFIFOHEAD(fd,packet_len(0x6a));
  7314. WFIFOW(fd,0) = 0x6a;
  7315. WFIFOB(fd,2) = 3; // Rejected by server
  7316. WFIFOSET(fd,packet_len(0x6a));
  7317. set_eof(fd);
  7318. return;
  7319. }
  7320. if (bl ||
  7321. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7322. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7323. {
  7324. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7325. return;
  7326. }
  7327. CREATE(sd, TBL_PC, 1);
  7328. sd->fd = fd;
  7329. sd->packet_ver = packet_ver;
  7330. session[fd]->session_data = sd;
  7331. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7332. #if PACKETVER < 20070521
  7333. WFIFOHEAD(fd,4);
  7334. WFIFOL(fd,0) = sd->bl.id;
  7335. WFIFOSET(fd,4);
  7336. #else
  7337. WFIFOHEAD(fd,packet_len(0x283));
  7338. WFIFOW(fd,0) = 0x283;
  7339. WFIFOL(fd,2) = sd->bl.id;
  7340. WFIFOSET(fd,packet_len(0x283));
  7341. #endif
  7342. chrif_authreq(sd);
  7343. return;
  7344. }
  7345. /*==========================================
  7346. * 007d クライアント側マップ読み込み完了
  7347. * map侵入時に必要なデータを全て送りつける
  7348. *------------------------------------------*/
  7349. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7350. {
  7351. if(sd->bl.prev != NULL)
  7352. return;
  7353. if (!sd->state.active)
  7354. { //Character loading is not complete yet!
  7355. //Let pc_reg_received reinvoke this when ready.
  7356. sd->state.connect_new = 0;
  7357. return;
  7358. }
  7359. if (sd->state.rewarp)
  7360. { //Rewarp player.
  7361. sd->state.rewarp = 0;
  7362. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7363. return;
  7364. }
  7365. // look
  7366. #if PACKETVER < 4
  7367. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7368. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7369. #else
  7370. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7371. #endif
  7372. if(sd->vd.cloth_color)
  7373. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7374. // item
  7375. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7376. pc_checkitem(sd);
  7377. // cart
  7378. if(pc_iscarton(sd)) {
  7379. clif_cartlist(sd);
  7380. clif_updatestatus(sd,SP_CARTINFO);
  7381. }
  7382. // weight
  7383. clif_updatestatus(sd,SP_WEIGHT);
  7384. clif_updatestatus(sd,SP_MAXWEIGHT);
  7385. // guild
  7386. // (needs to go before clif_spawn() to show guild emblems correctly)
  7387. if(sd->status.guild_id)
  7388. guild_send_memberinfoshort(sd,1);
  7389. if(battle_config.pc_invincible_time > 0) {
  7390. if(map_flag_gvg(sd->bl.m))
  7391. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7392. else
  7393. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7394. }
  7395. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7396. map_spawnmobs(sd->bl.m);
  7397. if( map[sd->bl.m].instance_id )
  7398. {
  7399. instance[map[sd->bl.m].instance_id].users++;
  7400. instance_check_idle(map[sd->bl.m].instance_id);
  7401. }
  7402. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7403. map_addblock(&sd->bl);
  7404. clif_spawn(&sd->bl);
  7405. // Party
  7406. // (needs to go after clif_spawn() to show hp bars correctly)
  7407. if(sd->status.party_id) {
  7408. party_send_movemap(sd);
  7409. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7410. }
  7411. if( sd->state.bg_id ) clif_bg_hp(sd); // BattleGround System
  7412. if( sd->state.changemap && map[sd->bl.m].flag.battleground )
  7413. {
  7414. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  7415. if( map[sd->bl.m].flag.battleground == 2 )
  7416. clif_bg_updatescore_single(sd);
  7417. }
  7418. if(map[sd->bl.m].flag.pvp) {
  7419. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7420. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7421. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7422. sd->pvp_rank = 0;
  7423. sd->pvp_lastusers = 0;
  7424. sd->pvp_point = 5;
  7425. sd->pvp_won = 0;
  7426. sd->pvp_lost = 0;
  7427. }
  7428. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7429. } else
  7430. // set flag, if it's a duel [LuzZza]
  7431. if(sd->duel_group)
  7432. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7433. if (map[sd->bl.m].flag.gvg_dungeon)
  7434. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7435. if( map_flag_gvg(sd->bl.m) )
  7436. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7437. // info about nearby objects
  7438. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7439. 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);
  7440. // pet
  7441. if( sd->pd )
  7442. {
  7443. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7444. { //Return the pet to egg. [Skotlex]
  7445. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7446. pet_menu(sd, 3); //Option 3 is return to egg.
  7447. }
  7448. else
  7449. {
  7450. map_addblock(&sd->pd->bl);
  7451. clif_spawn(&sd->pd->bl);
  7452. clif_send_petdata(sd,sd->pd,0,0);
  7453. clif_send_petstatus(sd);
  7454. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7455. }
  7456. }
  7457. //homunculus [blackhole89]
  7458. if( merc_is_hom_active(sd->hd) )
  7459. {
  7460. map_addblock(&sd->hd->bl);
  7461. clif_spawn(&sd->hd->bl);
  7462. clif_send_homdata(sd,0,0);
  7463. clif_hominfo(sd,sd->hd,1);
  7464. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7465. clif_homskillinfoblock(sd);
  7466. if( battle_config.hom_setting&0x8 )
  7467. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7468. if( !(battle_config.hom_setting&0x2) )
  7469. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7470. }
  7471. if( sd->md )
  7472. {
  7473. map_addblock(&sd->md->bl);
  7474. clif_spawn(&sd->md->bl);
  7475. clif_mercenary_info(sd);
  7476. clif_mercenary_skillblock(sd);
  7477. }
  7478. if(sd->state.connect_new) {
  7479. int lv;
  7480. sd->state.connect_new = 0;
  7481. clif_skillinfoblock(sd);
  7482. clif_hotkeys_send(sd);
  7483. clif_updatestatus(sd,SP_BASEEXP);
  7484. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7485. clif_updatestatus(sd,SP_JOBEXP);
  7486. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7487. clif_updatestatus(sd,SP_SKILLPOINT);
  7488. clif_initialstatus(sd);
  7489. if (sd->sc.option&OPTION_FALCON)
  7490. clif_status_load(&sd->bl, SI_FALCON, 1);
  7491. if (sd->sc.option&OPTION_RIDING)
  7492. clif_status_load(&sd->bl, SI_RIDING, 1);
  7493. if(sd->status.manner < 0)
  7494. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7495. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7496. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7497. if(sd->bl.m == sd->feel_map[0].m
  7498. || sd->bl.m == sd->feel_map[1].m
  7499. || sd->bl.m == sd->feel_map[2].m)
  7500. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7501. }
  7502. if(sd->pd && sd->pd->pet.intimate > 900)
  7503. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7504. if(merc_is_hom_active(sd->hd))
  7505. merc_hom_init_timers(sd->hd);
  7506. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7507. {
  7508. sd->state.night = 1;
  7509. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7510. }
  7511. // Notify everyone that this char logged in [Skotlex].
  7512. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7513. //Login Event
  7514. npc_script_event(sd, NPCE_LOGIN);
  7515. } else {
  7516. //For some reason the client "loses" these on warp/map-change.
  7517. clif_updatestatus(sd,SP_STR);
  7518. clif_updatestatus(sd,SP_AGI);
  7519. clif_updatestatus(sd,SP_VIT);
  7520. clif_updatestatus(sd,SP_INT);
  7521. clif_updatestatus(sd,SP_DEX);
  7522. clif_updatestatus(sd,SP_LUK);
  7523. // abort currently running script
  7524. sd->state.using_fake_npc = 0;
  7525. sd->state.menu_or_input = 0;
  7526. sd->npc_menu = 0;
  7527. if(sd->npc_id)
  7528. npc_event_dequeue(sd);
  7529. }
  7530. if( sd->state.changemap )
  7531. {// restore information that gets lost on map-change
  7532. #if PACKETVER >= 20070918
  7533. clif_partyinvitationstate(sd);
  7534. clif_equipcheckbox(sd);
  7535. #endif
  7536. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7537. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7538. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7539. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7540. { //Display night.
  7541. if( !sd->state.night )
  7542. {
  7543. sd->state.night = 1;
  7544. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7545. }
  7546. }
  7547. else if( sd->state.night )
  7548. { //Clear night display.
  7549. sd->state.night = 0;
  7550. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7551. }
  7552. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7553. {
  7554. char output[128];
  7555. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7556. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7557. }
  7558. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7559. sd->state.changemap = false;
  7560. }
  7561. #ifndef TXT_ONLY
  7562. mail_clear(sd);
  7563. #endif
  7564. if(map[sd->bl.m].flag.loadevent) // Lance
  7565. npc_script_event(sd, NPCE_LOADMAP);
  7566. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7567. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7568. if (sd->sc.opt2) //Client loses these on warp.
  7569. clif_changeoption(&sd->bl);
  7570. clif_weather_check(sd);
  7571. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7572. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7573. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7574. else
  7575. sd->areanpc_id = 0;
  7576. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7577. if(pc_isdead(sd))
  7578. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7579. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7580. // else
  7581. // clif_changed_dir(&sd->bl, SELF);
  7582. // Trigger skill effects if you appear standing on them
  7583. if(!battle_config.pc_invincible_time)
  7584. skill_unit_move(&sd->bl,gettick(),1);
  7585. }
  7586. /*==========================================
  7587. *
  7588. *------------------------------------------*/
  7589. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7590. {
  7591. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7592. WFIFOHEAD(fd, packet_len(0x7f));
  7593. WFIFOW(fd,0)=0x7f;
  7594. WFIFOL(fd,2)=gettick();
  7595. WFIFOSET(fd,packet_len(0x7f));
  7596. // removed until the socket problems are fixed. [FlavioJS]
  7597. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7598. return;
  7599. }
  7600. void clif_hotkeys_send(struct map_session_data *sd) {
  7601. #ifdef HOTKEY_SAVING
  7602. const int fd = sd->fd;
  7603. int i;
  7604. #if PACKETVER<20090603
  7605. const int cmd = 0x02b9;
  7606. #else
  7607. const int cmd = 0x07d9;
  7608. #endif
  7609. if (!fd) return;
  7610. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7611. WFIFOW(fd, 0) = cmd;
  7612. for(i = 0; i < MAX_HOTKEYS; i++) {
  7613. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7614. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7615. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7616. }
  7617. WFIFOSET(fd, packet_len(cmd));
  7618. #endif
  7619. }
  7620. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7621. #ifdef HOTKEY_SAVING
  7622. unsigned short idx;
  7623. int cmd;
  7624. cmd = RFIFOW(fd, 0);
  7625. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7626. if (idx >= MAX_HOTKEYS) return;
  7627. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7628. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7629. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7630. return;
  7631. #endif
  7632. }
  7633. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  7634. {
  7635. int fd = sd->fd;
  7636. WFIFOHEAD(fd,packet_len(0x2f0));
  7637. WFIFOW(fd,0) = 0x2f0;
  7638. WFIFOL(fd,2) = color;
  7639. WFIFOL(fd,6) = second;
  7640. WFIFOSET(fd,packet_len(0x2f0));
  7641. }
  7642. void clif_progressbar_abort(struct map_session_data * sd)
  7643. {
  7644. int fd = sd->fd;
  7645. WFIFOHEAD(fd,packet_len(0x2f2));
  7646. WFIFOW(fd,0) = 0x2f2;
  7647. WFIFOSET(fd,packet_len(0x2f2));
  7648. }
  7649. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  7650. {
  7651. int npc_id = sd->progressbar.npc_id;
  7652. if( gettick() < sd->progressbar.timeout && sd->st )
  7653. sd->st->state = END;
  7654. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  7655. npc_scriptcont(sd, npc_id);
  7656. }
  7657. /*==========================================
  7658. *
  7659. *------------------------------------------*/
  7660. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7661. {
  7662. short x, y;
  7663. int cmd;
  7664. if (pc_isdead(sd)) {
  7665. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7666. return;
  7667. }
  7668. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7669. ; //You CAN walk on this OPT1 value.
  7670. else if( sd->progressbar.npc_id )
  7671. clif_progressbar_abort(sd);
  7672. else if (pc_cant_act(sd))
  7673. return;
  7674. if(sd->sc.data[SC_RUN])
  7675. return;
  7676. pc_delinvincibletimer(sd);
  7677. cmd = RFIFOW(fd,0);
  7678. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7679. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7680. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7681. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7682. //Set last idle time... [Skotlex]
  7683. sd->idletime = last_tick;
  7684. unit_walktoxy(&sd->bl, x, y, 4);
  7685. }
  7686. /*==========================================
  7687. *
  7688. *------------------------------------------*/
  7689. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7690. {
  7691. WFIFOHEAD(fd,packet_len(0x18b));
  7692. WFIFOW(fd,0) = 0x18b;
  7693. /* Rovert's prevent logout option fixed [Valaris] */
  7694. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  7695. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7696. {
  7697. set_eof(fd);
  7698. WFIFOW(fd,2)=0;
  7699. } else {
  7700. WFIFOW(fd,2)=1;
  7701. }
  7702. WFIFOSET(fd,packet_len(0x18b));
  7703. }
  7704. /// Requesting unit's name
  7705. /// S 0094 <object id>.l
  7706. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7707. {
  7708. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7709. struct block_list* bl;
  7710. //struct status_change *sc;
  7711. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7712. id = sd->bl.id;
  7713. bl = map_id2bl(id);
  7714. if( bl == NULL )
  7715. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7716. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  7717. return; // Block namerequests past view range
  7718. // 'see people in GM hide' cheat detection
  7719. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7720. sc = status_get_sc(bl);
  7721. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7722. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7723. pc_isGM(sd) < battle_config.hack_info_GM_level
  7724. ) {
  7725. char gm_msg[256];
  7726. 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);
  7727. ShowWarning(gm_msg);
  7728. // information is sent to all online GMs
  7729. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7730. return;
  7731. }
  7732. */
  7733. clif_charnameack(fd, bl);
  7734. }
  7735. /*==========================================
  7736. * Validates and processes global messages
  7737. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7738. *------------------------------------------*/
  7739. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7740. {
  7741. const char* text = (char*)RFIFOP(fd,4);
  7742. int textlen = RFIFOW(fd,2) - 4;
  7743. char *name, *message;
  7744. int namelen, messagelen;
  7745. // validate packet and retrieve name and message
  7746. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7747. return;
  7748. if( is_atcommand(fd, sd, message, 1) )
  7749. return;
  7750. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7751. return;
  7752. if( battle_config.min_chat_delay )
  7753. { //[Skotlex]
  7754. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7755. return;
  7756. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7757. }
  7758. // send message to others (using the send buffer for temp. storage)
  7759. WFIFOHEAD(fd, 8 + textlen);
  7760. WFIFOW(fd,0) = 0x8d;
  7761. WFIFOW(fd,2) = 8 + textlen;
  7762. WFIFOL(fd,4) = sd->bl.id;
  7763. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7764. //FIXME: chat has range of 9 only
  7765. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7766. // send back message to the speaker
  7767. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7768. WFIFOW(fd,0) = 0x8e;
  7769. WFIFOSET(fd, WFIFOW(fd,2));
  7770. #ifdef PCRE_SUPPORT
  7771. // trigger listening npcs
  7772. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7773. #endif
  7774. // Chat logging type 'O' / Global Chat
  7775. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7776. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7777. return;
  7778. }
  7779. /*==========================================
  7780. * /mm /mapmove (as @rura GM command)
  7781. *------------------------------------------*/
  7782. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7783. {
  7784. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7785. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7786. char* map_name;
  7787. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7788. return;
  7789. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7790. return;
  7791. map_name = (char*)RFIFOP(fd,2);
  7792. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7793. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7794. atcommand_mapmove(fd, sd, "@mapmove", output);
  7795. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7796. {
  7797. sprintf(message, "/mm %s", output);
  7798. log_atcommand(sd, message);
  7799. }
  7800. return;
  7801. }
  7802. /*==========================================
  7803. *
  7804. *------------------------------------------*/
  7805. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7806. {
  7807. unsigned char buf[64];
  7808. WBUFW(buf,0) = 0x9c;
  7809. WBUFL(buf,2) = bl->id;
  7810. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7811. WBUFB(buf,8) = unit_getdir(bl);
  7812. clif_send(buf, packet_len(0x9c), bl, target);
  7813. if (disguised(bl)) {
  7814. WBUFL(buf,2) = -bl->id;
  7815. WBUFW(buf,6) = 0;
  7816. clif_send(buf, packet_len(0x9c), bl, SELF);
  7817. }
  7818. return;
  7819. }
  7820. /*==========================================
  7821. *
  7822. *------------------------------------------*/
  7823. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7824. {
  7825. unsigned char headdir, dir;
  7826. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7827. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7828. pc_setdir(sd, dir, headdir);
  7829. clif_changed_dir(&sd->bl, AREA_WOS);
  7830. return;
  7831. }
  7832. /*==========================================
  7833. *
  7834. *------------------------------------------*/
  7835. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7836. {
  7837. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7838. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7839. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  7840. clif_skill_fail(sd, 1, 0, 1);
  7841. return;
  7842. }
  7843. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7844. if (sd->emotionlasttime >= time(NULL)) {
  7845. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7846. clif_skill_fail(sd, 1, 0, 1);
  7847. return;
  7848. }
  7849. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7850. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  7851. {// re-roll dice
  7852. emoticon = rand()%6+E_DICE1;
  7853. }
  7854. clif_emotion(&sd->bl, emoticon);
  7855. } else
  7856. clif_skill_fail(sd, 1, 0, 1);
  7857. }
  7858. /*==========================================
  7859. *
  7860. *------------------------------------------*/
  7861. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7862. {
  7863. WFIFOHEAD(fd,packet_len(0xc2));
  7864. WFIFOW(fd,0) = 0xc2;
  7865. WFIFOL(fd,2) = map_getusers();
  7866. WFIFOSET(fd,packet_len(0xc2));
  7867. }
  7868. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7869. {
  7870. if (pc_isdead(sd)) {
  7871. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7872. return;
  7873. }
  7874. if (sd->sc.count &&
  7875. (sd->sc.data[SC_TRICKDEAD] ||
  7876. sd->sc.data[SC_AUTOCOUNTER] ||
  7877. sd->sc.data[SC_BLADESTOP]))
  7878. return;
  7879. pc_stop_walking(sd, 1);
  7880. pc_stop_attack(sd);
  7881. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7882. target_id = sd->bl.id;
  7883. switch(action_type)
  7884. {
  7885. case 0x00: // once attack
  7886. case 0x07: // continuous attack
  7887. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7888. return;
  7889. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7890. return;
  7891. if( sd->sc.data[SC_BASILICA] )
  7892. return;
  7893. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7894. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7895. clif_skill_fail(sd, 1, 4, 0);
  7896. return;
  7897. }
  7898. }
  7899. pc_delinvincibletimer(sd);
  7900. sd->idletime = last_tick;
  7901. unit_attack(&sd->bl, target_id, action_type != 0);
  7902. break;
  7903. case 0x02: // sitdown
  7904. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7905. clif_skill_fail(sd, 1, 0, 2);
  7906. break;
  7907. }
  7908. if(pc_issit(sd)) {
  7909. //Bugged client? Just refresh them.
  7910. clif_sitting(&sd->bl);
  7911. return;
  7912. }
  7913. if (sd->ud.skilltimer != INVALID_TIMER || sd->sc.opt1)
  7914. break;
  7915. if (sd->sc.count && (
  7916. sd->sc.data[SC_DANCING] ||
  7917. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7918. )) //No sitting during these states either.
  7919. break;
  7920. pc_setsit(sd);
  7921. skill_sit(sd,1);
  7922. clif_sitting(&sd->bl);
  7923. break;
  7924. case 0x03: // standup
  7925. if (!pc_issit(sd)) {
  7926. //Bugged client? Just refresh them.
  7927. clif_standing(&sd->bl);
  7928. return;
  7929. }
  7930. pc_setstand(sd);
  7931. skill_sit(sd,0);
  7932. clif_standing(&sd->bl);
  7933. break;
  7934. }
  7935. }
  7936. /*==========================================
  7937. *
  7938. *------------------------------------------*/
  7939. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7940. {
  7941. clif_parse_ActionRequest_sub(sd,
  7942. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7943. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7944. gettick()
  7945. );
  7946. }
  7947. /*==========================================
  7948. *
  7949. *------------------------------------------*/
  7950. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7951. {
  7952. switch(RFIFOB(fd,2)) {
  7953. case 0x00:
  7954. pc_respawn(sd,CLR_RESPAWN);
  7955. break;
  7956. case 0x01:
  7957. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7958. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  7959. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7960. { //Send to char-server for character selection.
  7961. chrif_charselectreq(sd, session[fd]->client_addr);
  7962. } else {
  7963. WFIFOHEAD(fd,packet_len(0x18b));
  7964. WFIFOW(fd,0)=0x18b;
  7965. WFIFOW(fd,2)=1;
  7966. WFIFOSET(fd,packet_len(0x018b));
  7967. }
  7968. break;
  7969. }
  7970. }
  7971. /*==========================================
  7972. * Validates and processes whispered messages
  7973. * S 0096 <packet len>.w <nick>.24B <message>.?B
  7974. *------------------------------------------*/
  7975. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7976. {
  7977. struct map_session_data* dstsd;
  7978. int i;
  7979. char *target, *message;
  7980. int namelen, messagelen;
  7981. // validate packet and retrieve name and message
  7982. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7983. return;
  7984. if (is_atcommand(fd, sd, message, 1) )
  7985. return;
  7986. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7987. return;
  7988. if (battle_config.min_chat_delay)
  7989. { //[Skotlex]
  7990. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7991. return;
  7992. }
  7993. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7994. }
  7995. // Chat logging type 'W' / Whisper
  7996. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7997. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7998. //-------------------------------------------------------//
  7999. // Lordalfa - Paperboy - To whisper NPC commands //
  8000. //-------------------------------------------------------//
  8001. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8002. {
  8003. char* str = target+4; //Skip the NPC: string part.
  8004. struct npc_data* npc;
  8005. if ((npc = npc_name2id(str)))
  8006. {
  8007. char split_data[10][50];
  8008. char *split;
  8009. char output[256];
  8010. str = message;
  8011. // skip codepage indicator, if detected
  8012. if( str[0] == '|' && strlen(str) >= 4 )
  8013. str += 3;
  8014. for( i = 0; i < 10; ++i )
  8015. {// Splits the message using '#' as separators
  8016. split = strchr(str,'#');
  8017. if( split == NULL )
  8018. { // use the remaining string
  8019. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8020. for( ++i; i < 10; ++i )
  8021. split_data[i][0] = '\0';
  8022. break;
  8023. }
  8024. *split = '\0';
  8025. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8026. str = split+1;
  8027. }
  8028. for( i = 0; i < 10; ++i )
  8029. {
  8030. sprintf(output, "@whispervar%d$", i);
  8031. set_var(sd,output,(char *) split_data[i]);
  8032. }
  8033. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8034. npc_event(sd,output,0); // Calls the NPC label
  8035. return;
  8036. }
  8037. }
  8038. // Main chat [LuzZza]
  8039. if(strcmpi(target, main_chat_nick) == 0)
  8040. {
  8041. if(!sd->state.mainchat)
  8042. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8043. else {
  8044. char output[256];
  8045. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  8046. intif_broadcast2(output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0);
  8047. }
  8048. // Chat logging type 'M' / Main Chat
  8049. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8050. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8051. return;
  8052. }
  8053. // searching destination character
  8054. dstsd = map_nick2sd(target);
  8055. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8056. {
  8057. // player is not on this map-server
  8058. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8059. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8060. // and if we ask for 'Test', we must not contact 'test' player
  8061. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8062. intif_wis_message(sd, target, message, messagelen);
  8063. return;
  8064. }
  8065. // if player ignores everyone
  8066. if (dstsd->state.ignoreAll)
  8067. {
  8068. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8069. clif_wis_end(fd, 1); // 1: target character is not loged in
  8070. else
  8071. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8072. return;
  8073. }
  8074. // if player ignores the source character
  8075. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8076. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8077. { // source char present in ignore list
  8078. clif_wis_end(fd, 2); // 2: ignored by target
  8079. return;
  8080. }
  8081. // if player is autotrading
  8082. if( dstsd->state.autotrade == 1 )
  8083. {
  8084. char output[256];
  8085. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8086. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8087. return;
  8088. }
  8089. // notify sender of success
  8090. clif_wis_end(fd, 0); // 0: success to send wisper
  8091. // Normal message
  8092. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8093. return;
  8094. }
  8095. /*==========================================
  8096. * /b /nb
  8097. * S 0099 <packet len>.w <text>.?B 00
  8098. *------------------------------------------*/
  8099. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8100. {
  8101. char* msg = (char*)RFIFOP(fd,4);
  8102. unsigned int len = RFIFOW(fd,2)-4;
  8103. int lv;
  8104. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8105. return;
  8106. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  8107. return;
  8108. // as the length varies depending on the command used, just block unreasonably long strings
  8109. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8110. intif_broadcast(msg, len, 0);
  8111. if(log_config.gm && lv >= log_config.gm) {
  8112. char logmsg[CHAT_SIZE_MAX+4];
  8113. sprintf(logmsg, "/b %s", msg);
  8114. log_atcommand(sd, logmsg);
  8115. }
  8116. }
  8117. /*==========================================
  8118. *
  8119. *------------------------------------------*/
  8120. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8121. {
  8122. struct flooritem_data *fitem;
  8123. int map_object_id;
  8124. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8125. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8126. do {
  8127. if (pc_isdead(sd)) {
  8128. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8129. break;
  8130. }
  8131. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8132. break;
  8133. if (pc_cant_act(sd))
  8134. break;
  8135. if(sd->sc.count && (
  8136. sd->sc.data[SC_HIDING] ||
  8137. sd->sc.data[SC_CLOAKING] ||
  8138. sd->sc.data[SC_TRICKDEAD] ||
  8139. sd->sc.data[SC_BLADESTOP] ||
  8140. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8141. )
  8142. break;
  8143. if (!pc_takeitem(sd, fitem))
  8144. break;
  8145. return;
  8146. } while (0);
  8147. // Client REQUIRES a fail packet or you can no longer pick items.
  8148. clif_additem(sd,0,0,6);
  8149. }
  8150. /*==========================================
  8151. *
  8152. *------------------------------------------*/
  8153. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8154. {
  8155. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8156. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8157. for(;;) {
  8158. if (pc_isdead(sd))
  8159. break;
  8160. if (pc_cant_act(sd))
  8161. break;
  8162. if (sd->sc.count && (
  8163. sd->sc.data[SC_AUTOCOUNTER] ||
  8164. sd->sc.data[SC_BLADESTOP] ||
  8165. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8166. ))
  8167. break;
  8168. if (!pc_dropitem(sd, item_index, item_amount))
  8169. break;
  8170. return;
  8171. }
  8172. //Because the client does not like being ignored.
  8173. clif_dropitem(sd, item_index,0);
  8174. }
  8175. /*==========================================
  8176. *
  8177. *------------------------------------------*/
  8178. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8179. {
  8180. int n;
  8181. if (pc_isdead(sd)) {
  8182. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8183. return;
  8184. }
  8185. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8186. return;
  8187. //This flag enables you to use items while in an NPC. [Skotlex]
  8188. if (sd->npc_id) {
  8189. if (sd->npc_id != sd->npc_item_flag)
  8190. return;
  8191. } else
  8192. if (pc_istrading(sd))
  8193. return;
  8194. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8195. sd->idletime = last_tick;
  8196. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8197. if(n <0 || n >= MAX_INVENTORY)
  8198. return;
  8199. if (!pc_useitem(sd,n))
  8200. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8201. }
  8202. /*==========================================
  8203. *
  8204. *------------------------------------------*/
  8205. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8206. {
  8207. int index;
  8208. if(pc_isdead(sd)) {
  8209. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8210. return;
  8211. }
  8212. index = RFIFOW(fd,2)-2;
  8213. if (index < 0 || index >= MAX_INVENTORY)
  8214. return; //Out of bounds check.
  8215. if(sd->npc_id) {
  8216. if (sd->npc_id != sd->npc_item_flag)
  8217. return;
  8218. } else if (sd->state.storage_flag || sd->sc.opt1)
  8219. ; //You can equip/unequip stuff while storage is open/under status changes
  8220. else if (pc_cant_act(sd))
  8221. return;
  8222. if(!sd->status.inventory[index].identify) {
  8223. clif_equipitemack(sd,index,0,0); // fail
  8224. return;
  8225. }
  8226. if(!sd->inventory_data[index])
  8227. return;
  8228. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8229. pet_equipitem(sd,index);
  8230. return;
  8231. }
  8232. //Client doesn't send the position for ammo.
  8233. if(sd->inventory_data[index]->type == IT_AMMO)
  8234. pc_equipitem(sd,index,EQP_AMMO);
  8235. else
  8236. pc_equipitem(sd,index,RFIFOW(fd,4));
  8237. }
  8238. /*==========================================
  8239. *
  8240. *------------------------------------------*/
  8241. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8242. {
  8243. int index;
  8244. if(pc_isdead(sd)) {
  8245. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8246. return;
  8247. }
  8248. if (sd->state.storage_flag)
  8249. ; //You can equip/unequip stuff while storage is open.
  8250. else if (pc_cant_act(sd))
  8251. return;
  8252. index = RFIFOW(fd,2)-2;
  8253. pc_unequipitem(sd,index,1);
  8254. }
  8255. /*==========================================
  8256. *
  8257. *------------------------------------------*/
  8258. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8259. {
  8260. struct block_list *bl;
  8261. if(pc_isdead(sd)) {
  8262. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8263. return;
  8264. }
  8265. if (pc_cant_act(sd))
  8266. return;
  8267. bl = map_id2bl(RFIFOL(fd,2));
  8268. if (!bl) return;
  8269. switch (bl->type) {
  8270. case BL_MOB:
  8271. case BL_PC:
  8272. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8273. break;
  8274. case BL_NPC:
  8275. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8276. npc_click(sd,(TBL_NPC*)bl);
  8277. break;
  8278. }
  8279. return;
  8280. }
  8281. /*==========================================
  8282. *
  8283. *------------------------------------------*/
  8284. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8285. {
  8286. if (sd->state.trading)
  8287. return;
  8288. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8289. }
  8290. /// Request to buy chosen items from npc shop
  8291. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  8292. /// R 00ca <result>.b
  8293. /// result = 00 -> "The deal has successfully completed."
  8294. /// result = 01 -> "You do not have enough zeny."
  8295. /// result = 02 -> "You are over your Weight Limit."
  8296. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8297. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8298. {
  8299. int n = (RFIFOW(fd,2)-4) /4;
  8300. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8301. int result;
  8302. if( sd->state.trading || !sd->npc_shopid )
  8303. result = 1;
  8304. else
  8305. result = npc_buylist(sd,n,item_list);
  8306. sd->npc_shopid = 0; //Clear shop data.
  8307. WFIFOHEAD(fd,packet_len(0xca));
  8308. WFIFOW(fd,0) = 0xca;
  8309. WFIFOB(fd,2) = result;
  8310. WFIFOSET(fd,packet_len(0xca));
  8311. }
  8312. /// Request to sell chosen items to npc shop
  8313. /// R 00c9 <packet len>.W {<index>.W <amount>.W}.4B*
  8314. /// S 00cb <result>.B
  8315. /// result = 00 -> "The deal has successfully completed."
  8316. /// result = 01 -> "The deal has failed."
  8317. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8318. {
  8319. int fail=0,n;
  8320. unsigned short *item_list;
  8321. n = (RFIFOW(fd,2)-4) /4;
  8322. item_list = (unsigned short*)RFIFOP(fd,4);
  8323. if (sd->state.trading || !sd->npc_shopid)
  8324. fail = 1;
  8325. else
  8326. fail = npc_selllist(sd,n,item_list);
  8327. sd->npc_shopid = 0; //Clear shop data.
  8328. WFIFOHEAD(fd,packet_len(0xcb));
  8329. WFIFOW(fd,0)=0xcb;
  8330. WFIFOB(fd,2)=fail;
  8331. WFIFOSET(fd,packet_len(0xcb));
  8332. }
  8333. /*==========================================
  8334. * Chatroom creation request
  8335. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8336. *------------------------------------------*/
  8337. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8338. {
  8339. int len = RFIFOW(fd,2)-15;
  8340. int limit = RFIFOW(fd,4);
  8341. bool pub = (RFIFOB(fd,6) != 0);
  8342. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8343. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8344. char s_password[CHATROOM_PASS_SIZE];
  8345. char s_title[CHATROOM_TITLE_SIZE];
  8346. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8347. return;
  8348. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8349. clif_skill_fail(sd,1,0,3);
  8350. return;
  8351. }
  8352. if( len <= 0 )
  8353. return; // invalid input
  8354. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8355. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8356. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8357. }
  8358. /*==========================================
  8359. * Chatroom join request
  8360. * S 00d9 <chat ID>.l <passwd>.8B
  8361. *------------------------------------------*/
  8362. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8363. {
  8364. int chatid = RFIFOL(fd,2);
  8365. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8366. chat_joinchat(sd,chatid,password);
  8367. }
  8368. /*==========================================
  8369. * Chatroom properties adjustment request
  8370. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8371. *------------------------------------------*/
  8372. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8373. {
  8374. int len = RFIFOW(fd,2)-15;
  8375. int limit = RFIFOW(fd,4);
  8376. bool pub = (RFIFOB(fd,6) != 0);
  8377. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8378. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8379. char s_password[CHATROOM_PASS_SIZE];
  8380. char s_title[CHATROOM_TITLE_SIZE];
  8381. if( len <= 0 )
  8382. return; // invalid input
  8383. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8384. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8385. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8386. }
  8387. /*==========================================
  8388. * S 00e0 ?.l <nick>.24B
  8389. *------------------------------------------*/
  8390. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8391. {
  8392. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  8393. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8394. }
  8395. /*==========================================
  8396. *
  8397. *------------------------------------------*/
  8398. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8399. {
  8400. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8401. }
  8402. /*==========================================
  8403. * Request to leave the current chatroom
  8404. * S 00e3
  8405. *------------------------------------------*/
  8406. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8407. {
  8408. chat_leavechat(sd,0);
  8409. }
  8410. //Handles notifying asker and rejecter of what has just ocurred.
  8411. //Type is used to determine the correct msg_txt to use:
  8412. //0:
  8413. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8414. {
  8415. char *msg, output[256];
  8416. // Your request has been rejected by autoreject option.
  8417. msg = msg_txt(392);
  8418. clif_disp_onlyself(src, msg, strlen(msg));
  8419. //Notice that a request was rejected.
  8420. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8421. clif_disp_onlyself(target, output, strlen(output));
  8422. }
  8423. /*==========================================
  8424. * 取引要請を相手に送る
  8425. *------------------------------------------*/
  8426. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8427. {
  8428. struct map_session_data *t_sd;
  8429. t_sd = map_id2sd(RFIFOL(fd,2));
  8430. if(!sd->chatID && pc_cant_act(sd))
  8431. return; //You can trade while in a chatroom.
  8432. // @noask [LuzZza]
  8433. if(t_sd && t_sd->state.noask) {
  8434. clif_noask_sub(sd, t_sd, 0);
  8435. return;
  8436. }
  8437. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8438. {
  8439. clif_skill_fail(sd,1,0,0);
  8440. return;
  8441. }
  8442. trade_traderequest(sd,t_sd);
  8443. }
  8444. /*==========================================
  8445. * 取引要請
  8446. *------------------------------------------*/
  8447. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8448. {
  8449. trade_tradeack(sd,RFIFOB(fd,2));
  8450. }
  8451. /*==========================================
  8452. * アイテム追加
  8453. *------------------------------------------*/
  8454. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8455. {
  8456. short index = RFIFOW(fd,2);
  8457. int amount = RFIFOL(fd,4);
  8458. if( index == 0 )
  8459. trade_tradeaddzeny(sd, amount);
  8460. else
  8461. trade_tradeadditem(sd, index, (short)amount);
  8462. }
  8463. /*==========================================
  8464. * アイテム追加完了(ok押し)
  8465. *------------------------------------------*/
  8466. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8467. {
  8468. trade_tradeok(sd);
  8469. }
  8470. /*==========================================
  8471. * 取引キャンセル
  8472. *------------------------------------------*/
  8473. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8474. {
  8475. trade_tradecancel(sd);
  8476. }
  8477. /*==========================================
  8478. * 取引許諾(trade押し)
  8479. *------------------------------------------*/
  8480. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8481. {
  8482. trade_tradecommit(sd);
  8483. }
  8484. /*==========================================
  8485. *
  8486. *------------------------------------------*/
  8487. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8488. {
  8489. pc_stop_attack(sd);
  8490. }
  8491. /*==========================================
  8492. * カートへアイテムを移す
  8493. *------------------------------------------*/
  8494. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8495. {
  8496. if (pc_istrading(sd))
  8497. return;
  8498. if (!pc_iscarton(sd))
  8499. return;
  8500. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8501. }
  8502. /*==========================================
  8503. * カートからアイテムを出す
  8504. *------------------------------------------*/
  8505. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8506. {
  8507. if (!pc_iscarton(sd))
  8508. return;
  8509. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8510. }
  8511. /*==========================================
  8512. * 付属品(鷹,ペコ,カート)をはずす
  8513. *------------------------------------------*/
  8514. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8515. {
  8516. //Can only remove Cart/Riding/Falcon.
  8517. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8518. }
  8519. /*==========================================
  8520. * チェンジカート
  8521. *------------------------------------------*/
  8522. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8523. {
  8524. int type;
  8525. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8526. return;
  8527. type = (int)RFIFOW(fd,2);
  8528. if( (type == 5 && sd->status.base_level > 90) ||
  8529. (type == 4 && sd->status.base_level > 80) ||
  8530. (type == 3 && sd->status.base_level > 65) ||
  8531. (type == 2 && sd->status.base_level > 40) ||
  8532. (type == 1))
  8533. pc_setcart(sd,type);
  8534. }
  8535. /*==========================================
  8536. * ステータスアップ
  8537. *------------------------------------------*/
  8538. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8539. {
  8540. pc_statusup(sd,RFIFOW(fd,2));
  8541. }
  8542. /*==========================================
  8543. * スキルレベルアップ
  8544. *------------------------------------------*/
  8545. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8546. {
  8547. pc_skillup(sd,RFIFOW(fd,2));
  8548. }
  8549. 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)
  8550. {
  8551. int lv;
  8552. if( !hd )
  8553. return;
  8554. if( skillnotok_hom(skillnum, hd) )
  8555. return;
  8556. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8557. target_id = hd->bl.id;
  8558. if( hd->ud.skilltimer != INVALID_TIMER )
  8559. {
  8560. if( skillnum != SA_CASTCANCEL ) return;
  8561. }
  8562. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8563. return;
  8564. lv = merc_hom_checkskill(hd, skillnum);
  8565. if( skilllv > lv )
  8566. skilllv = lv;
  8567. if( skilllv )
  8568. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8569. }
  8570. 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)
  8571. {
  8572. int lv;
  8573. if( !md )
  8574. return;
  8575. if( skillnotok_mercenary(skillnum, md) )
  8576. return;
  8577. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8578. target_id = md->bl.id;
  8579. if( md->ud.skilltimer != INVALID_TIMER )
  8580. {
  8581. if( skillnum != SA_CASTCANCEL ) return;
  8582. }
  8583. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8584. return;
  8585. lv = mercenary_checkskill(md, skillnum);
  8586. if( skilllv > lv )
  8587. skilllv = lv;
  8588. if( skilllv )
  8589. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8590. }
  8591. 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)
  8592. {
  8593. int lv;
  8594. if( !md )
  8595. return;
  8596. if( skillnotok_mercenary(skillnum, md) )
  8597. return;
  8598. if( md->ud.skilltimer != INVALID_TIMER )
  8599. return;
  8600. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8601. {
  8602. clif_skill_fail(md->master, skillnum, 4, 0);
  8603. return;
  8604. }
  8605. if( md->sc.data[SC_BASILICA] )
  8606. return;
  8607. lv = mercenary_checkskill(md, skillnum);
  8608. if( skilllv > lv )
  8609. skilllv = lv;
  8610. if( skilllv )
  8611. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8612. }
  8613. /*==========================================
  8614. * スキル使用(ID指定)
  8615. *------------------------------------------*/
  8616. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8617. {
  8618. short skillnum, skilllv;
  8619. int tmp, target_id;
  8620. unsigned int tick = gettick();
  8621. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8622. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8623. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8624. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8625. tmp = skill_get_inf(skillnum);
  8626. if (tmp&INF_GROUND_SKILL || !tmp)
  8627. return; //Using a ground/passive skill on a target? WRONG.
  8628. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8629. {
  8630. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8631. return;
  8632. }
  8633. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8634. {
  8635. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8636. return;
  8637. }
  8638. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8639. sd->idletime = last_tick;
  8640. if( pc_cant_act(sd) )
  8641. return;
  8642. if( pc_issit(sd) )
  8643. return;
  8644. if( skillnotok(skillnum, sd) )
  8645. return;
  8646. if( sd->bl.id != target_id && (tmp&INF_SELF_SKILL || sd->state.combo) )
  8647. target_id = sd->bl.id; // never trust the client
  8648. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8649. target_id = sd->bl.id;
  8650. if( sd->ud.skilltimer != INVALID_TIMER )
  8651. {
  8652. if( skillnum != SA_CASTCANCEL )
  8653. return;
  8654. }
  8655. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8656. {
  8657. if( sd->skillitem != skillnum )
  8658. {
  8659. clif_skill_fail(sd, skillnum, 4, 0);
  8660. return;
  8661. }
  8662. }
  8663. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8664. return;
  8665. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8666. return; // On basilica only caster can use Basilica again to stop it.
  8667. if( sd->menuskill_id )
  8668. {
  8669. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8670. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8671. else if( sd->menuskill_id != SA_AUTOSPELL )
  8672. return; //Can't use skills while a menu is open.
  8673. }
  8674. if( sd->skillitem == skillnum )
  8675. {
  8676. if( skilllv != sd->skillitemlv )
  8677. skilllv = sd->skillitemlv;
  8678. if( !(tmp&INF_SELF_SKILL) )
  8679. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  8680. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8681. return;
  8682. }
  8683. sd->skillitem = sd->skillitemlv = 0;
  8684. if( skillnum >= GD_SKILLBASE )
  8685. {
  8686. if( sd->state.gmaster_flag )
  8687. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8688. else
  8689. skilllv = 0;
  8690. }
  8691. else
  8692. {
  8693. tmp = pc_checkskill(sd, skillnum);
  8694. if( skilllv > tmp )
  8695. skilllv = tmp;
  8696. }
  8697. pc_delinvincibletimer(sd);
  8698. if( skilllv )
  8699. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8700. }
  8701. /*==========================================
  8702. * スキル使用(場所指定)
  8703. *------------------------------------------*/
  8704. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8705. {
  8706. int lv;
  8707. unsigned int tick = gettick();
  8708. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8709. return; //Using a target skill on the ground? WRONG.
  8710. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8711. {
  8712. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8713. return;
  8714. }
  8715. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8716. sd->idletime = last_tick;
  8717. if( skillnotok(skillnum, sd) )
  8718. return;
  8719. if( skillmoreinfo != -1 )
  8720. {
  8721. if( pc_issit(sd) )
  8722. {
  8723. clif_skill_fail(sd, skillnum, 0, 0);
  8724. return;
  8725. }
  8726. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8727. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8728. }
  8729. if( sd->ud.skilltimer != INVALID_TIMER )
  8730. return;
  8731. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8732. {
  8733. if( sd->skillitem != skillnum )
  8734. {
  8735. clif_skill_fail(sd, skillnum, 4, 0);
  8736. return;
  8737. }
  8738. }
  8739. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8740. return;
  8741. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8742. return; // On basilica only caster can use Basilica again to stop it.
  8743. if( sd->menuskill_id )
  8744. {
  8745. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8746. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8747. else if( sd->menuskill_id != SA_AUTOSPELL )
  8748. return; //Can't use skills while a menu is open.
  8749. }
  8750. pc_delinvincibletimer(sd);
  8751. if( sd->skillitem == skillnum )
  8752. {
  8753. if( skilllv != sd->skillitemlv )
  8754. skilllv = sd->skillitemlv;
  8755. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8756. }
  8757. else
  8758. {
  8759. sd->skillitem = sd->skillitemlv = 0;
  8760. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8761. {
  8762. if( skilllv > lv )
  8763. skilllv = lv;
  8764. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8765. }
  8766. }
  8767. }
  8768. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8769. {
  8770. if (pc_cant_act(sd))
  8771. return;
  8772. if (pc_issit(sd))
  8773. return;
  8774. clif_parse_UseSkillToPosSub(fd, sd,
  8775. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8776. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8777. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8778. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8779. -1 //Skill more info.
  8780. );
  8781. }
  8782. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8783. {
  8784. if (pc_cant_act(sd))
  8785. return;
  8786. if (pc_issit(sd))
  8787. return;
  8788. clif_parse_UseSkillToPosSub(fd, sd,
  8789. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8790. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8791. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8792. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8793. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8794. );
  8795. }
  8796. /*==========================================
  8797. * スキル使用(map指定)
  8798. *------------------------------------------*/
  8799. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8800. {
  8801. short skill_num = RFIFOW(fd,2);
  8802. char map_name[MAP_NAME_LENGTH];
  8803. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8804. if(skill_num != sd->menuskill_id)
  8805. return;
  8806. if( pc_cant_act(sd) )
  8807. {
  8808. sd->menuskill_id = sd->menuskill_val = 0;
  8809. return;
  8810. }
  8811. pc_delinvincibletimer(sd);
  8812. skill_castend_map(sd,skill_num,map_name);
  8813. }
  8814. /*==========================================
  8815. * メモ要求
  8816. *------------------------------------------*/
  8817. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8818. {
  8819. if (!pc_isdead(sd))
  8820. pc_memo(sd,-1);
  8821. }
  8822. /*==========================================
  8823. * アイテム合成
  8824. *------------------------------------------*/
  8825. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8826. {
  8827. if (sd->menuskill_id != AM_PHARMACY)
  8828. return;
  8829. if (pc_istrading(sd)) {
  8830. //Make it fail to avoid shop exploits where you sell something different than you see.
  8831. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8832. sd->menuskill_val = sd->menuskill_id = 0;
  8833. return;
  8834. }
  8835. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8836. sd->menuskill_val = sd->menuskill_id = 0;
  8837. }
  8838. /*==========================================
  8839. *
  8840. *------------------------------------------*/
  8841. void clif_parse_Cooking(int fd,struct map_session_data *sd)
  8842. {
  8843. //int type = RFIFOW(fd,2); // '1' for cooking, but what do other values mean?
  8844. int nameid = RFIFOW(fd,4);
  8845. if( sd->menuskill_id != AM_PHARMACY )
  8846. {
  8847. return;
  8848. }
  8849. if (pc_istrading(sd)) {
  8850. //Make it fail to avoid shop exploits where you sell something different than you see.
  8851. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8852. sd->menuskill_val = sd->menuskill_id = 0;
  8853. return;
  8854. }
  8855. skill_produce_mix(sd,0,nameid,0,0,0,1);
  8856. sd->menuskill_val = sd->menuskill_id = 0;
  8857. }
  8858. /*==========================================
  8859. * 武器修理
  8860. *------------------------------------------*/
  8861. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8862. {
  8863. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8864. return;
  8865. if (pc_istrading(sd)) {
  8866. //Make it fail to avoid shop exploits where you sell something different than you see.
  8867. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8868. sd->menuskill_val = sd->menuskill_id = 0;
  8869. return;
  8870. }
  8871. skill_repairweapon(sd,RFIFOW(fd,2));
  8872. sd->menuskill_val = sd->menuskill_id = 0;
  8873. }
  8874. /*==========================================
  8875. *
  8876. *------------------------------------------*/
  8877. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8878. {
  8879. int idx;
  8880. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8881. return;
  8882. if (pc_istrading(sd)) {
  8883. //Make it fail to avoid shop exploits where you sell something different than you see.
  8884. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8885. sd->menuskill_val = sd->menuskill_id = 0;
  8886. return;
  8887. }
  8888. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8889. skill_weaponrefine(sd, idx-2);
  8890. sd->menuskill_val = sd->menuskill_id = 0;
  8891. }
  8892. /*==========================================
  8893. *
  8894. *------------------------------------------*/
  8895. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8896. {
  8897. int npc_id = RFIFOL(fd,2);
  8898. uint8 select = RFIFOB(fd,6);
  8899. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  8900. {
  8901. TBL_NPC* nd = map_id2nd(npc_id);
  8902. 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);
  8903. clif_GM_kick(NULL,sd);
  8904. return;
  8905. }
  8906. sd->npc_menu = select;
  8907. npc_scriptcont(sd,npc_id);
  8908. }
  8909. /*==========================================
  8910. *
  8911. *------------------------------------------*/
  8912. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8913. {
  8914. npc_scriptcont(sd,RFIFOL(fd,2));
  8915. }
  8916. /*==========================================
  8917. * Value entered into a NPC input box.
  8918. * S 0143 <npcID>.l <amount>.l
  8919. *------------------------------------------*/
  8920. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8921. {
  8922. int npcid = RFIFOL(fd,2);
  8923. int amount = (int)RFIFOL(fd,6);
  8924. sd->npc_amount = amount;
  8925. npc_scriptcont(sd, npcid);
  8926. }
  8927. /*==========================================
  8928. * Text entered into a NPC input box.
  8929. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8930. *------------------------------------------*/
  8931. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8932. {
  8933. int message_len = RFIFOW(fd,2)-8;
  8934. int npcid = RFIFOL(fd,4);
  8935. const char* message = (char*)RFIFOP(fd,8);
  8936. if( message_len <= 0 )
  8937. return; // invalid input
  8938. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8939. npc_scriptcont(sd, npcid);
  8940. }
  8941. /*==========================================
  8942. *
  8943. *------------------------------------------*/
  8944. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8945. {
  8946. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8947. return;
  8948. npc_scriptcont(sd,RFIFOL(fd,2));
  8949. }
  8950. /*==========================================
  8951. * アイテム鑑定
  8952. *------------------------------------------*/
  8953. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8954. {
  8955. short idx = RFIFOW(fd,2);
  8956. if (sd->menuskill_id != MC_IDENTIFY)
  8957. return;
  8958. if( idx == -1 )
  8959. {// cancel pressed
  8960. sd->menuskill_val = sd->menuskill_id = 0;
  8961. return;
  8962. }
  8963. skill_identify(sd,idx-2);
  8964. sd->menuskill_val = sd->menuskill_id = 0;
  8965. }
  8966. /*==========================================
  8967. * 矢作成
  8968. *------------------------------------------*/
  8969. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8970. {
  8971. if (sd->menuskill_id != AC_MAKINGARROW)
  8972. return;
  8973. if (pc_istrading(sd)) {
  8974. //Make it fail to avoid shop exploits where you sell something different than you see.
  8975. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8976. sd->menuskill_val = sd->menuskill_id = 0;
  8977. return;
  8978. }
  8979. skill_arrow_create(sd,RFIFOW(fd,2));
  8980. sd->menuskill_val = sd->menuskill_id = 0;
  8981. }
  8982. /*==========================================
  8983. * オートスペル受信
  8984. *------------------------------------------*/
  8985. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8986. {
  8987. if (sd->menuskill_id != SA_AUTOSPELL)
  8988. return;
  8989. skill_autospell(sd,RFIFOW(fd,2));
  8990. sd->menuskill_val = sd->menuskill_id = 0;
  8991. }
  8992. /*==========================================
  8993. * カード使用
  8994. *------------------------------------------*/
  8995. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8996. {
  8997. if (sd->state.trading != 0)
  8998. return;
  8999. clif_use_card(sd,RFIFOW(fd,2)-2);
  9000. }
  9001. /*==========================================
  9002. * カード挿入装備選択
  9003. *------------------------------------------*/
  9004. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9005. {
  9006. if (sd->state.trading != 0)
  9007. return;
  9008. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9009. }
  9010. /*==========================================
  9011. * 0193 キャラID名前引き
  9012. *------------------------------------------*/
  9013. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9014. {
  9015. int charid;
  9016. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9017. map_reqnickdb(sd, charid);
  9018. }
  9019. /*==========================================
  9020. * 0197 /resetskill /resetstate
  9021. *------------------------------------------*/
  9022. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  9023. {
  9024. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9025. return;
  9026. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  9027. return;
  9028. if( RFIFOW(fd,2) )
  9029. pc_resetskill(sd,1);
  9030. else
  9031. pc_resetstate(sd);
  9032. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  9033. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  9034. }
  9035. /*==========================================
  9036. * /lb /nlb
  9037. * S 019c <packet len>.w <text>.?B 00
  9038. *------------------------------------------*/
  9039. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9040. {
  9041. char* msg = (char*)RFIFOP(fd,4);
  9042. unsigned int len = RFIFOW(fd,2)-4;
  9043. int lv;
  9044. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9045. return;
  9046. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  9047. return;
  9048. // as the length varies depending on the command used, just block unreasonably long strings
  9049. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9050. clif_broadcast(&sd->bl, msg, len, 0, ALL_SAMEMAP);
  9051. if( log_config.gm && lv >= log_config.gm ) {
  9052. char logmsg[CHAT_SIZE_MAX+5];
  9053. sprintf(logmsg, "/lb %s", msg);
  9054. log_atcommand(sd, logmsg);
  9055. }
  9056. }
  9057. /*==========================================
  9058. * カプラ倉庫へ入れる
  9059. *------------------------------------------*/
  9060. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9061. {
  9062. int item_index, item_amount;
  9063. if (pc_istrading(sd))
  9064. return;
  9065. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9066. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9067. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9068. return;
  9069. if (sd->state.storage_flag == 1)
  9070. storage_storageadd(sd, item_index, item_amount);
  9071. else
  9072. if (sd->state.storage_flag == 2)
  9073. storage_guild_storageadd(sd, item_index, item_amount);
  9074. }
  9075. /*==========================================
  9076. * カプラ倉庫から出す
  9077. *------------------------------------------*/
  9078. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9079. {
  9080. int item_index, item_amount;
  9081. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9082. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9083. if (sd->state.storage_flag == 1)
  9084. storage_storageget(sd, item_index, item_amount);
  9085. else
  9086. if(sd->state.storage_flag == 2)
  9087. storage_guild_storageget(sd, item_index, item_amount);
  9088. }
  9089. /*==========================================
  9090. * カプラ倉庫へカートから入れる
  9091. *------------------------------------------*/
  9092. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9093. {
  9094. if(sd->vender_id)
  9095. return;
  9096. if (!pc_iscarton(sd))
  9097. return;
  9098. if (sd->state.storage_flag == 1)
  9099. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9100. else
  9101. if (sd->state.storage_flag == 2)
  9102. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9103. }
  9104. /*==========================================
  9105. * カプラ倉庫から出す
  9106. *------------------------------------------*/
  9107. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9108. {
  9109. if (sd->vender_id)
  9110. return;
  9111. if (!pc_iscarton(sd))
  9112. return;
  9113. if (sd->state.storage_flag == 1)
  9114. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9115. else
  9116. if (sd->state.storage_flag == 2)
  9117. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9118. }
  9119. /*==========================================
  9120. * カプラ倉庫を閉じる
  9121. *------------------------------------------*/
  9122. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9123. {
  9124. if( sd->state.storage_flag == 1 )
  9125. storage_storageclose(sd);
  9126. else
  9127. if( sd->state.storage_flag == 2 )
  9128. storage_guild_storageclose(sd);
  9129. }
  9130. /*==========================================
  9131. * Kafra storage protection password system
  9132. *------------------------------------------*/
  9133. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9134. {
  9135. //TODO
  9136. }
  9137. /*==========================================
  9138. * Party creation request
  9139. * S 00f9 <party name>.24S
  9140. * S 01e8 <party name>.24S <share flag>.B <share type>.B
  9141. *------------------------------------------*/
  9142. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9143. {
  9144. char* name = (char*)RFIFOP(fd,2);
  9145. name[NAME_LENGTH-1] = '\0';
  9146. if( map[sd->bl.m].flag.partylock )
  9147. {// Party locked.
  9148. clif_displaymessage(fd, msg_txt(227));
  9149. return;
  9150. }
  9151. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9152. {
  9153. clif_skill_fail(sd,1,0,4);
  9154. return;
  9155. }
  9156. party_create(sd,name,0,0);
  9157. }
  9158. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9159. {
  9160. char* name = (char*)RFIFOP(fd,2);
  9161. int item1 = RFIFOB(fd,26);
  9162. int item2 = RFIFOB(fd,27);
  9163. name[NAME_LENGTH-1] = '\0';
  9164. if( map[sd->bl.m].flag.partylock )
  9165. {// Party locked.
  9166. clif_displaymessage(fd, msg_txt(227));
  9167. return;
  9168. }
  9169. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9170. {
  9171. clif_skill_fail(sd,1,0,4);
  9172. return;
  9173. }
  9174. party_create(sd,name,item1,item2);
  9175. }
  9176. /*==========================================
  9177. * Party invitation request
  9178. * S 00fc <account ID>.L
  9179. * S 02c4 <char name>.24S
  9180. *------------------------------------------*/
  9181. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9182. {
  9183. struct map_session_data *t_sd;
  9184. if(map[sd->bl.m].flag.partylock)
  9185. {// Party locked.
  9186. clif_displaymessage(fd, msg_txt(227));
  9187. return;
  9188. }
  9189. t_sd = map_id2sd(RFIFOL(fd,2));
  9190. if(t_sd && t_sd->state.noask)
  9191. {// @noask [LuzZza]
  9192. clif_noask_sub(sd, t_sd, 1);
  9193. return;
  9194. }
  9195. party_invite(sd, t_sd);
  9196. }
  9197. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9198. {
  9199. struct map_session_data *t_sd;
  9200. char *name = (char*)RFIFOP(fd,2);
  9201. name[NAME_LENGTH-1] = '\0';
  9202. if(map[sd->bl.m].flag.partylock)
  9203. {// Party locked.
  9204. clif_displaymessage(fd, msg_txt(227));
  9205. return;
  9206. }
  9207. t_sd = map_nick2sd(name);
  9208. if(t_sd && t_sd->state.noask)
  9209. {// @noask [LuzZza]
  9210. clif_noask_sub(sd, t_sd, 1);
  9211. return;
  9212. }
  9213. party_invite(sd, t_sd);
  9214. }
  9215. /*==========================================
  9216. * Party invitation reply
  9217. * S 00ff <account ID>.L <flag>.L
  9218. * S 02c7 <account ID>.L <flag>.B
  9219. * flag: 0-reject, 1-accept
  9220. *------------------------------------------*/
  9221. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9222. {
  9223. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9224. }
  9225. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9226. {
  9227. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9228. }
  9229. /*==========================================
  9230. * パーティ脱退要求
  9231. *------------------------------------------*/
  9232. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9233. {
  9234. if(map[sd->bl.m].flag.partylock)
  9235. { //Guild locked.
  9236. clif_displaymessage(fd, msg_txt(227));
  9237. return;
  9238. }
  9239. party_leave(sd);
  9240. }
  9241. /*==========================================
  9242. * パーティ除名要求
  9243. *------------------------------------------*/
  9244. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9245. {
  9246. if(map[sd->bl.m].flag.partylock)
  9247. { //Guild locked.
  9248. clif_displaymessage(fd, msg_txt(227));
  9249. return;
  9250. }
  9251. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9252. }
  9253. /*==========================================
  9254. * パーティ設定変更要求
  9255. *------------------------------------------*/
  9256. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9257. {
  9258. struct party_data *p;
  9259. int i;
  9260. if( !sd->status.party_id )
  9261. return;
  9262. p = party_search(sd->status.party_id);
  9263. if( p == NULL )
  9264. return;
  9265. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9266. if( i == MAX_PARTY )
  9267. return; //Shouldn't happen
  9268. if( !p->party.member[i].leader )
  9269. return;
  9270. #if PACKETVER < 20090603
  9271. //Client can't change the item-field
  9272. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9273. #else
  9274. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)+(RFIFOB(fd,7)?2:0)));
  9275. #endif
  9276. }
  9277. /*==========================================
  9278. * Validates and processes party messages
  9279. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  9280. *------------------------------------------*/
  9281. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9282. {
  9283. const char* text = (char*)RFIFOP(fd,4);
  9284. int textlen = RFIFOW(fd,2) - 4;
  9285. char *name, *message;
  9286. int namelen, messagelen;
  9287. // validate packet and retrieve name and message
  9288. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9289. return;
  9290. if( is_atcommand(fd, sd, message, 1) )
  9291. return;
  9292. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9293. return;
  9294. if( battle_config.min_chat_delay )
  9295. { //[Skotlex]
  9296. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9297. return;
  9298. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9299. }
  9300. party_send_message(sd, text, textlen);
  9301. }
  9302. /*==========================================
  9303. * Changes Party Leader
  9304. * S 07da <account ID>.L
  9305. *------------------------------------------*/
  9306. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9307. {
  9308. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9309. }
  9310. /*==========================================
  9311. * Party Booking in KRO [Spiria]
  9312. *------------------------------------------*/
  9313. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9314. {
  9315. short level = RFIFOW(fd,2);
  9316. short mapid = RFIFOW(fd,4);
  9317. short job[PARTY_BOOKING_JOBS];
  9318. int i;
  9319. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9320. job[i] = RFIFOB(fd,6+i*2);
  9321. party_booking_register(sd, level, mapid, job);
  9322. }
  9323. /*==========================================
  9324. * flag: 0 - success, 1 - failed
  9325. *------------------------------------------*/
  9326. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9327. {
  9328. int fd = sd->fd;
  9329. WFIFOHEAD(fd,packet_len(0x803));
  9330. WFIFOW(fd,0) = 0x803;
  9331. WFIFOW(fd,2) = flag;
  9332. WFIFOSET(fd,packet_len(0x803));
  9333. }
  9334. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9335. {
  9336. short level = RFIFOW(fd,2);
  9337. short mapid = RFIFOW(fd,4);
  9338. short job = RFIFOW(fd,6);
  9339. unsigned long lastindex = RFIFOL(fd,8);
  9340. short resultcount = RFIFOB(fd,12);
  9341. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9342. }
  9343. /*==========================================
  9344. * more_result: 0 - no more, 1 - more
  9345. *------------------------------------------*/
  9346. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9347. {
  9348. int i, j;
  9349. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9350. struct party_booking_ad_info *pb_ad;
  9351. WFIFOHEAD(fd,size*count + 5);
  9352. WFIFOW(fd,0) = 0x805;
  9353. WFIFOW(fd,2) = size*count + 5;
  9354. WFIFOB(fd,4) = more_result;
  9355. for(i=0; i<count; i++)
  9356. {
  9357. pb_ad = results[i];
  9358. WFIFOL(fd,i*size+5) = pb_ad->index;
  9359. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9360. WFIFOL(fd,i*size+33) = pb_ad->starttime;
  9361. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9362. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9363. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9364. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9365. }
  9366. WFIFOSET(fd,WFIFOW(fd,2));
  9367. }
  9368. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9369. {
  9370. if(party_booking_delete(sd))
  9371. clif_PartyBookingDeleteAck(sd, 0);
  9372. }
  9373. /*==========================================
  9374. * flag: 0 - success, other - failed
  9375. *------------------------------------------*/
  9376. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9377. {
  9378. int fd = sd->fd;
  9379. WFIFOHEAD(fd,packet_len(0x807));
  9380. WFIFOW(fd,0) = 0x807;
  9381. WFIFOW(fd,2) = flag;
  9382. WFIFOSET(fd,packet_len(0x807));
  9383. }
  9384. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9385. {
  9386. short job[PARTY_BOOKING_JOBS];
  9387. int i;
  9388. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9389. job[i] = RFIFOW(fd,2+i*2);
  9390. party_booking_update(sd, job);
  9391. }
  9392. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9393. {
  9394. int i;
  9395. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9396. if(pb_ad == NULL) return;
  9397. WBUFW(buf,0) = 0x809;
  9398. WBUFL(buf,2) = pb_ad->index;
  9399. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9400. WBUFL(buf,30) = pb_ad->starttime;
  9401. WBUFW(buf,34) = pb_ad->p_detail.level;
  9402. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9403. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9404. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9405. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9406. }
  9407. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9408. {
  9409. int i;
  9410. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9411. if(pb_ad == NULL) return;
  9412. WBUFW(buf,0) = 0x80a;
  9413. WBUFL(buf,2) = pb_ad->index;
  9414. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9415. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9416. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9417. }
  9418. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9419. {
  9420. uint8 buf[6];
  9421. WBUFW(buf,0) = 0x80b;
  9422. WBUFL(buf,2) = index;
  9423. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9424. }
  9425. /*==========================================
  9426. * 露店閉鎖
  9427. *------------------------------------------*/
  9428. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9429. {
  9430. vending_closevending(sd);
  9431. }
  9432. /*==========================================
  9433. * 露店アイテムリスト要求
  9434. *------------------------------------------*/
  9435. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9436. {
  9437. if( sd->npc_id )
  9438. {// using an NPC
  9439. return;
  9440. }
  9441. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9442. }
  9443. /*==========================================
  9444. * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC)
  9445. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  9446. *------------------------------------------*/
  9447. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9448. {
  9449. int len = (int)RFIFOW(fd,2) - 8;
  9450. int id = (int)RFIFOL(fd,4);
  9451. const uint8* data = (uint8*)RFIFOP(fd,8);
  9452. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  9453. // whether it fails or not, the buy window is closed
  9454. sd->vended_id = 0;
  9455. }
  9456. /*==========================================
  9457. * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2)
  9458. * S 0801 <len>.w <AID>.l <UniqueID>.l {<amount>.w <index>.w}.4B*
  9459. *------------------------------------------*/
  9460. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9461. {
  9462. int len = (int)RFIFOW(fd,2) - 12;
  9463. int aid = (int)RFIFOL(fd,4);
  9464. int uid = (int)RFIFOL(fd,8);
  9465. const uint8* data = (uint8*)RFIFOP(fd,12);
  9466. vending_purchasereq(sd, aid, uid, data, len/4);
  9467. // whether it fails or not, the buy window is closed
  9468. sd->vended_id = 0;
  9469. }
  9470. /*==========================================
  9471. * Confirm or cancel the shop preparation window
  9472. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  9473. * flag: 0=cancel, 1=confirm
  9474. *------------------------------------------*/
  9475. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9476. {
  9477. short len = (short)RFIFOW(fd,2) - 85;
  9478. const char* message = (char*)RFIFOP(fd,4);
  9479. bool flag = (bool)RFIFOB(fd,84);
  9480. const uint8* data = (uint8*)RFIFOP(fd,85);
  9481. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9482. return;
  9483. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9484. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9485. return;
  9486. }
  9487. if( message[0] == '\0' ) // invalid input
  9488. return;
  9489. vending_openvending(sd, message, flag, data, len/8);
  9490. }
  9491. /*==========================================
  9492. * Guild creation request
  9493. * S 0165 <account id>.L <guild name>.24S
  9494. *------------------------------------------*/
  9495. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9496. {
  9497. char* name = (char*)RFIFOP(fd,6);
  9498. name[NAME_LENGTH-1] = '\0';
  9499. if(map[sd->bl.m].flag.guildlock)
  9500. { //Guild locked.
  9501. clif_displaymessage(fd, msg_txt(228));
  9502. return;
  9503. }
  9504. guild_create(sd, name);
  9505. }
  9506. /*==========================================
  9507. * ギルドマスターかどうか確認
  9508. *------------------------------------------*/
  9509. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9510. {
  9511. clif_guild_masterormember(sd);
  9512. }
  9513. /*==========================================
  9514. * ギルド情報要求
  9515. *------------------------------------------*/
  9516. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  9517. {
  9518. if( !sd->status.guild_id && !sd->state.bg_id )
  9519. return;
  9520. switch( RFIFOL(fd,2) )
  9521. {
  9522. case 0: // ギルド基本情報、同盟敵対情報
  9523. clif_guild_basicinfo(sd);
  9524. clif_guild_allianceinfo(sd);
  9525. break;
  9526. case 1: // メンバーリスト、役職名リスト
  9527. clif_guild_positionnamelist(sd);
  9528. clif_guild_memberlist(sd);
  9529. break;
  9530. case 2: // 役職名リスト、役職情報リスト
  9531. clif_guild_positionnamelist(sd);
  9532. clif_guild_positioninfolist(sd);
  9533. break;
  9534. case 3: // スキルリスト
  9535. clif_guild_skillinfo(sd);
  9536. break;
  9537. case 4: // 追放リスト
  9538. clif_guild_expulsionlist(sd);
  9539. break;
  9540. default:
  9541. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9542. break;
  9543. }
  9544. }
  9545. /*==========================================
  9546. * ギルド役職変更
  9547. *------------------------------------------*/
  9548. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  9549. {
  9550. int i;
  9551. if(!sd->state.gmaster_flag)
  9552. return;
  9553. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9554. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9555. }
  9556. }
  9557. /*==========================================
  9558. * ギルドメンバ役職変更
  9559. * S 0155 <packet len>.W {<account id>.L <char id>.L <idx>.L}
  9560. *------------------------------------------*/
  9561. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  9562. {
  9563. int i;
  9564. if(!sd->state.gmaster_flag)
  9565. return;
  9566. for(i=4;i<RFIFOW(fd,2);i+=12){
  9567. guild_change_memberposition(sd->status.guild_id,
  9568. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9569. }
  9570. }
  9571. /*==========================================
  9572. * ギルドエンブレム要求
  9573. *------------------------------------------*/
  9574. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  9575. {
  9576. struct guild* g;
  9577. int guild_id = RFIFOL(fd,2);
  9578. if( (g = guild_search(guild_id)) != NULL )
  9579. clif_guild_emblem(sd,g);
  9580. }
  9581. /*==========================================
  9582. * ギルドエンブレム変更
  9583. * S 0153 <packet len>.W <emblem data>.?B
  9584. *------------------------------------------*/
  9585. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  9586. {
  9587. if(!sd->state.gmaster_flag)
  9588. return;
  9589. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9590. }
  9591. /*==========================================
  9592. * Guild notice update request
  9593. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  9594. *------------------------------------------*/
  9595. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  9596. {
  9597. int guild_id = RFIFOL(fd,2);
  9598. char* msg1 = (char*)RFIFOP(fd,6);
  9599. char* msg2 = (char*)RFIFOP(fd,66);
  9600. if(!sd->state.gmaster_flag)
  9601. return;
  9602. // compensate for some client defects when using multilanguage mode
  9603. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  9604. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  9605. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  9606. guild_change_notice(sd, guild_id, msg1, msg2);
  9607. }
  9608. /*==========================================
  9609. * ギルド勧誘
  9610. *------------------------------------------*/
  9611. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  9612. {
  9613. struct map_session_data *t_sd;
  9614. if(map[sd->bl.m].flag.guildlock)
  9615. { //Guild locked.
  9616. clif_displaymessage(fd, msg_txt(228));
  9617. return;
  9618. }
  9619. t_sd = map_id2sd(RFIFOL(fd,2));
  9620. // @noask [LuzZza]
  9621. if(t_sd && t_sd->state.noask) {
  9622. clif_noask_sub(sd, t_sd, 2);
  9623. return;
  9624. }
  9625. guild_invite(sd,t_sd);
  9626. }
  9627. /*==========================================
  9628. * ギルド勧誘返信
  9629. *------------------------------------------*/
  9630. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  9631. {
  9632. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9633. }
  9634. /*==========================================
  9635. * ギルド脱退
  9636. *------------------------------------------*/
  9637. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9638. {
  9639. if(map[sd->bl.m].flag.guildlock)
  9640. { //Guild locked.
  9641. clif_displaymessage(fd, msg_txt(228));
  9642. return;
  9643. }
  9644. if( sd->state.bg_id )
  9645. {
  9646. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9647. return;
  9648. }
  9649. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9650. }
  9651. /*==========================================
  9652. * Request to expel a member of a guild
  9653. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.40B
  9654. *------------------------------------------*/
  9655. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9656. {
  9657. if( map[sd->bl.m].flag.guildlock || sd->state.bg_id )
  9658. { // Guild locked.
  9659. clif_displaymessage(fd, msg_txt(228));
  9660. return;
  9661. }
  9662. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9663. }
  9664. /*==========================================
  9665. * Validates and processes guild messages
  9666. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  9667. *------------------------------------------*/
  9668. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9669. {
  9670. const char* text = (char*)RFIFOP(fd,4);
  9671. int textlen = RFIFOW(fd,2) - 4;
  9672. char *name, *message;
  9673. int namelen, messagelen;
  9674. // validate packet and retrieve name and message
  9675. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9676. return;
  9677. if( is_atcommand(fd, sd, message, 1) )
  9678. return;
  9679. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9680. return;
  9681. if( battle_config.min_chat_delay )
  9682. { //[Skotlex]
  9683. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9684. return;
  9685. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9686. }
  9687. if( sd->state.bg_id )
  9688. bg_send_message(sd, text, textlen);
  9689. else
  9690. guild_send_message(sd, text, textlen);
  9691. }
  9692. /*==========================================
  9693. * ギルド同盟要求
  9694. *------------------------------------------*/
  9695. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9696. {
  9697. struct map_session_data *t_sd;
  9698. if(!sd->state.gmaster_flag)
  9699. return;
  9700. if(map[sd->bl.m].flag.guildlock)
  9701. { //Guild locked.
  9702. clif_displaymessage(fd, msg_txt(228));
  9703. return;
  9704. }
  9705. t_sd = map_id2sd(RFIFOL(fd,2));
  9706. // @noask [LuzZza]
  9707. if(t_sd && t_sd->state.noask) {
  9708. clif_noask_sub(sd, t_sd, 3);
  9709. return;
  9710. }
  9711. guild_reqalliance(sd,t_sd);
  9712. }
  9713. /*==========================================
  9714. * ギルド同盟要求返信
  9715. *------------------------------------------*/
  9716. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9717. {
  9718. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9719. }
  9720. /*==========================================
  9721. * ギルド関係解消
  9722. *------------------------------------------*/
  9723. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9724. {
  9725. if(!sd->state.gmaster_flag)
  9726. return;
  9727. if(map[sd->bl.m].flag.guildlock)
  9728. { //Guild locked.
  9729. clif_displaymessage(fd, msg_txt(228));
  9730. return;
  9731. }
  9732. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9733. }
  9734. /*==========================================
  9735. * ギルド敵対
  9736. *------------------------------------------*/
  9737. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9738. {
  9739. struct map_session_data *t_sd;
  9740. if(!sd->state.gmaster_flag)
  9741. return;
  9742. if(map[sd->bl.m].flag.guildlock)
  9743. { //Guild locked.
  9744. clif_displaymessage(fd, msg_txt(228));
  9745. return;
  9746. }
  9747. t_sd = map_id2sd(RFIFOL(fd,2));
  9748. // @noask [LuzZza]
  9749. if(t_sd && t_sd->state.noask) {
  9750. clif_noask_sub(sd, t_sd, 4);
  9751. return;
  9752. }
  9753. guild_opposition(sd,t_sd);
  9754. }
  9755. /*==========================================
  9756. * ギルド解散
  9757. *------------------------------------------*/
  9758. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9759. {
  9760. if( map[sd->bl.m].flag.guildlock )
  9761. { //Guild locked.
  9762. clif_displaymessage(fd, msg_txt(228));
  9763. return;
  9764. }
  9765. guild_break(sd,(char*)RFIFOP(fd,2));
  9766. }
  9767. // pet
  9768. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9769. {
  9770. pet_menu(sd,RFIFOB(fd,2));
  9771. }
  9772. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9773. {
  9774. pet_catch_process2(sd,RFIFOL(fd,2));
  9775. }
  9776. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9777. {
  9778. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9779. {
  9780. //Forged packet, disconnect them [Kevin]
  9781. clif_authfail_fd(fd, 0);
  9782. return;
  9783. }
  9784. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9785. sd->menuskill_val = sd->menuskill_id = 0;
  9786. }
  9787. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9788. {
  9789. if(sd->pd)
  9790. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9791. }
  9792. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9793. {
  9794. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9795. }
  9796. /*==========================================
  9797. * /kill <???>
  9798. * (or right click menu for GM "(name) force to quit")
  9799. * S 00cc <id>.L
  9800. *------------------------------------------*/
  9801. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9802. {
  9803. struct block_list *target;
  9804. int tid,lv;
  9805. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9806. return;
  9807. tid = RFIFOL(fd,2);
  9808. target = map_id2bl(tid);
  9809. if (!target) {
  9810. clif_GM_kickack(sd, 0);
  9811. return;
  9812. }
  9813. switch (target->type) {
  9814. case BL_PC:
  9815. {
  9816. struct map_session_data *tsd = (struct map_session_data *)target;
  9817. if (pc_isGM(sd) <= pc_isGM(tsd))
  9818. {
  9819. clif_GM_kickack(sd, 0);
  9820. return;
  9821. }
  9822. lv = get_atcommand_level(atcommand_kick);
  9823. if( pc_isGM(sd) < lv )
  9824. {
  9825. clif_GM_kickack(sd, 0);
  9826. return;
  9827. }
  9828. if(log_config.gm && lv >= log_config.gm) {
  9829. char message[256];
  9830. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9831. log_atcommand(sd, message);
  9832. }
  9833. clif_GM_kick(sd, tsd);
  9834. }
  9835. break;
  9836. case BL_MOB:
  9837. {
  9838. lv = get_atcommand_level(atcommand_killmonster);
  9839. if( pc_isGM(sd) < lv )
  9840. {
  9841. clif_GM_kickack(sd, 0);
  9842. return;
  9843. }
  9844. if(log_config.gm && lv >= log_config.gm) {
  9845. char message[256];
  9846. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9847. log_atcommand(sd, message);
  9848. }
  9849. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  9850. }
  9851. break;
  9852. case BL_NPC:
  9853. {
  9854. struct npc_data* nd = (struct npc_data *)target;
  9855. lv = get_atcommand_level(atcommand_unloadnpc);
  9856. if( pc_isGM(sd) < lv )
  9857. {
  9858. clif_GM_kickack(sd, 0);
  9859. return;
  9860. }
  9861. if( log_config.gm && lv >= log_config.gm ) {
  9862. char message[256];
  9863. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9864. log_atcommand(sd, message);
  9865. }
  9866. // copy-pasted from atcommand_unloadnpc
  9867. npc_unload_duplicates(nd);
  9868. npc_unload(nd); // invalidates 'target'
  9869. npc_read_event_script();
  9870. }
  9871. break;
  9872. default:
  9873. clif_GM_kickack(sd, 0);
  9874. }
  9875. }
  9876. /*==========================================
  9877. * /killall
  9878. *------------------------------------------*/
  9879. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9880. {
  9881. is_atcommand(fd, sd, "@kickall", 1);
  9882. }
  9883. /*==========================================
  9884. * /remove <account name>
  9885. * /shift <char name>
  9886. *------------------------------------------*/
  9887. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9888. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  9889. char *player_name;
  9890. int lv;
  9891. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9892. return;
  9893. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9894. return;
  9895. player_name = (char*)RFIFOP(fd,2);
  9896. player_name[NAME_LENGTH-1] = '\0';
  9897. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9898. if( log_config.gm && lv >= log_config.gm ) {
  9899. char message[NAME_LENGTH+7];
  9900. sprintf(message, "/shift %s", player_name);
  9901. log_atcommand(sd, message);
  9902. }
  9903. }
  9904. /// Warps oneself to the location of the character given by account id ( /remove <account id> ).
  9905. /// R 0843 <account id>.L
  9906. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  9907. {
  9908. int account_id, lv;
  9909. struct map_session_data* pl_sd;
  9910. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9911. {
  9912. return;
  9913. }
  9914. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_jumpto) ) )
  9915. {
  9916. return;
  9917. }
  9918. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9919. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  9920. {
  9921. pc_warpto(sd, pl_sd);
  9922. }
  9923. if( log_config.gm && lv >= log_config.gm )
  9924. {
  9925. char message[32];
  9926. sprintf(message, "/remove %d", account_id);
  9927. log_atcommand(sd, message);
  9928. }
  9929. }
  9930. /*==========================================
  9931. * /recall <account name>
  9932. * /summon <char name>
  9933. *------------------------------------------*/
  9934. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9935. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  9936. char *player_name;
  9937. int lv;
  9938. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9939. return;
  9940. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9941. return;
  9942. player_name = (char*)RFIFOP(fd,2);
  9943. player_name[NAME_LENGTH-1] = '\0';
  9944. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9945. if( log_config.gm && lv >= log_config.gm ) {
  9946. char message[NAME_LENGTH+8];
  9947. sprintf(message, "/recall %s", player_name);
  9948. log_atcommand(sd, message);
  9949. }
  9950. }
  9951. /// Summons a character given by account id to one's own position ( /recall <account id> )
  9952. /// R 0842 <account id>.L
  9953. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  9954. {
  9955. int account_id, lv;
  9956. struct map_session_data* pl_sd;
  9957. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9958. {
  9959. return;
  9960. }
  9961. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_recall) ) )
  9962. {
  9963. return;
  9964. }
  9965. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9966. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  9967. {
  9968. pc_recall(sd, pl_sd);
  9969. }
  9970. if( log_config.gm && lv >= log_config.gm )
  9971. {
  9972. char message[32];
  9973. sprintf(message, "/recall %d", account_id);
  9974. log_atcommand(sd, message);
  9975. }
  9976. }
  9977. /*==========================================
  9978. * /monster /item
  9979. * R 01F3 <name>.24B
  9980. *------------------------------------------*/
  9981. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9982. {
  9983. char *monster_item_name;
  9984. char message[NAME_LENGTH+10]; //For logging.
  9985. int level;
  9986. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9987. return;
  9988. monster_item_name = (char*)RFIFOP(fd,2);
  9989. monster_item_name[NAME_LENGTH-1] = '\0';
  9990. if( mobdb_searchname(monster_item_name) ) {
  9991. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9992. return;
  9993. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9994. if( log_config.gm && level >= log_config.gm )
  9995. { //Log action. [Skotlex]
  9996. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9997. log_atcommand(sd, message);
  9998. }
  9999. return;
  10000. }
  10001. if( itemdb_searchname(monster_item_name) == NULL )
  10002. return;
  10003. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  10004. return;
  10005. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  10006. if( log_config.gm && level >= log_config.gm )
  10007. { //Log action. [Skotlex]
  10008. sprintf(message, "@item %s", monster_item_name);
  10009. log_atcommand(sd, message);
  10010. }
  10011. }
  10012. /*==========================================
  10013. * /hide
  10014. *------------------------------------------*/
  10015. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  10016. {
  10017. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10018. return;
  10019. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  10020. return;
  10021. if( sd->sc.option & OPTION_INVISIBLE ) {
  10022. sd->sc.option &= ~OPTION_INVISIBLE;
  10023. if (sd->disguise)
  10024. status_set_viewdata(&sd->bl, sd->disguise);
  10025. else
  10026. status_set_viewdata(&sd->bl, sd->status.class_);
  10027. clif_displaymessage(fd, "Invisible: Off.");
  10028. } else {
  10029. sd->sc.option |= OPTION_INVISIBLE;
  10030. sd->vd.class_ = INVISIBLE_CLASS;
  10031. clif_displaymessage(fd, "Invisible: On.");
  10032. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  10033. log_atcommand(sd, "/hide");
  10034. }
  10035. clif_changeoption(&sd->bl);
  10036. }
  10037. /*==========================================
  10038. * GM adjustment of a player's manner value (right-click GM menu)
  10039. * S 0149 <id>.L <type>.B <value>.W
  10040. * type: 0 - positive points
  10041. * 1 - negative points
  10042. * 2 - self mute (+10 minutes)
  10043. *------------------------------------------*/
  10044. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10045. {
  10046. int id, type, value, level;
  10047. struct map_session_data *dstsd;
  10048. id = RFIFOL(fd,2);
  10049. type = RFIFOB(fd,6);
  10050. value = RFIFOW(fd,7);
  10051. if( type == 0 )
  10052. value = 0 - value;
  10053. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10054. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10055. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  10056. return;
  10057. dstsd = map_id2sd(id);
  10058. if( dstsd == NULL )
  10059. return;
  10060. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  10061. {
  10062. clif_manner_message(sd, 0);
  10063. clif_manner_message(dstsd, 5);
  10064. if( dstsd->status.manner < value ) {
  10065. dstsd->status.manner -= value;
  10066. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10067. } else {
  10068. dstsd->status.manner = 0;
  10069. status_change_end(&dstsd->bl, SC_NOCHAT, INVALID_TIMER);
  10070. }
  10071. if( type != 2 )
  10072. clif_GM_silence(sd, dstsd, type);
  10073. }
  10074. }
  10075. /*==========================================
  10076. * GM adjustment of a player's manner value by -60 (using name)
  10077. * /rc <name>
  10078. * S 0212 <name>.24B
  10079. *------------------------------------------*/
  10080. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10081. {
  10082. char* name = (char*)RFIFOP(fd,2);
  10083. struct map_session_data* dstsd;
  10084. name[23] = '\0';
  10085. dstsd = map_nick2sd(name);
  10086. if( dstsd == NULL )
  10087. return;
  10088. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  10089. {
  10090. clif_manner_message(sd, 0);
  10091. clif_manner_message(dstsd, 3);
  10092. dstsd->status.manner -= 60;
  10093. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10094. clif_GM_silence(sd, dstsd, 1);
  10095. }
  10096. }
  10097. /*==========================================
  10098. * GM requesting account name (for right-click gm menu)
  10099. * S 01df <id>.L
  10100. * R 01e0 <id>.L <name>.24B
  10101. *------------------------------------------*/
  10102. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10103. {
  10104. int tid;
  10105. tid = RFIFOL(fd,2);
  10106. //TODO: find out if this works for any player or only for authorized GMs
  10107. WFIFOHEAD(fd,packet_len(0x1e0));
  10108. WFIFOW(fd,0) = 0x1e0;
  10109. WFIFOL(fd,2) = tid;
  10110. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10111. WFIFOSET(fd, packet_len(0x1e0));
  10112. }
  10113. /*==========================================
  10114. * GM single cell type change request
  10115. * /changemaptype <x> <y> <type:0-1>
  10116. * S 0198 <x>.W <y>.W <gat>.W
  10117. *------------------------------------------*/
  10118. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10119. {
  10120. int x,y,type;
  10121. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10122. return;
  10123. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  10124. return;
  10125. x = RFIFOW(fd,2);
  10126. y = RFIFOW(fd,4);
  10127. type = RFIFOW(fd,6);
  10128. map_setgatcell(sd->bl.m,x,y,type);
  10129. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10130. //FIXME: once players leave the map, the client 'forgets' this information.
  10131. }
  10132. /// S 00cf <nick>.24B <type>.B
  10133. /// type: 0 (/ex nick) deny speech from nick
  10134. /// 1 (/in nick) allow speech from nick
  10135. ///
  10136. /// R 00d1 <type>.B <result>.B
  10137. /// type: 0: deny, 1: allow
  10138. /// result: 0: success, 1: fail 2: list full
  10139. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10140. {
  10141. char output[512];
  10142. char* nick;
  10143. uint8 type;
  10144. int i;
  10145. nick = (char*)RFIFOP(fd,2); // speed up
  10146. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10147. type = RFIFOB(fd,26);
  10148. WFIFOHEAD(fd,packet_len(0xd1));
  10149. WFIFOW(fd,0) = 0x0d1;
  10150. WFIFOB(fd,2) = type;
  10151. if( type == 0 )
  10152. { // Add name to ignore list (block)
  10153. // Bot-check...
  10154. if (strcmp(wisp_server_name, nick) == 0)
  10155. { // to find possible bot users who automaticaly ignore people
  10156. 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);
  10157. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  10158. WFIFOB(fd,3) = 1; // fail
  10159. WFIFOSET(fd, packet_len(0x0d1));
  10160. return;
  10161. }
  10162. // try to find a free spot, while checking for duplicates at the same time
  10163. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10164. if( i == MAX_IGNORE_LIST )
  10165. {// no space for new entry
  10166. WFIFOB(fd,3) = 2; // fail
  10167. WFIFOSET(fd, packet_len(0x0d1));
  10168. return;
  10169. }
  10170. if( sd->ignore[i].name[0] != '\0' )
  10171. {// name already exists
  10172. WFIFOB(fd,3) = 0; // Aegis reports success.
  10173. WFIFOSET(fd, packet_len(0x0d1));
  10174. return;
  10175. }
  10176. //Insert in position i
  10177. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10178. WFIFOB(fd,3) = 0; // success
  10179. WFIFOSET(fd, packet_len(0x0d1));
  10180. }
  10181. else
  10182. { // Remove name from ignore list (unblock)
  10183. // find entry
  10184. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10185. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10186. { //Not found
  10187. WFIFOB(fd,3) = 1; // fail
  10188. WFIFOSET(fd, packet_len(0x0d1));
  10189. return;
  10190. }
  10191. // move everything one place down to overwrite removed entry
  10192. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10193. // wipe last entry
  10194. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10195. WFIFOB(fd,3) = 0; // success
  10196. WFIFOSET(fd, packet_len(0x0d1));
  10197. }
  10198. return;
  10199. }
  10200. /// S 00d0 <type>.B
  10201. /// type: 0 (/exall) deny all speech
  10202. /// 1 (/inall) allow all speech
  10203. ///
  10204. /// R 00d2 <type>.B <fail>.B
  10205. /// type: 0: deny, 1: allow
  10206. /// fail: 0: success, 1: fail
  10207. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10208. {
  10209. WFIFOHEAD(fd,packet_len(0xd2));
  10210. WFIFOW(fd,0) = 0x0d2;
  10211. WFIFOB(fd,2) = RFIFOB(fd,2);
  10212. if( RFIFOB(fd,2) == 0 )
  10213. {// Deny all
  10214. if( sd->state.ignoreAll ) {
  10215. WFIFOB(fd,3) = 1; // fail
  10216. } else {
  10217. sd->state.ignoreAll = 1;
  10218. WFIFOB(fd,3) = 0; // success
  10219. }
  10220. }
  10221. else
  10222. {//Unblock everyone
  10223. if( sd->state.ignoreAll ) {
  10224. sd->state.ignoreAll = 0;
  10225. WFIFOB(fd,3) = 0; // success
  10226. } else {
  10227. if (sd->ignore[0].name[0] != '\0')
  10228. { //Wipe the ignore list.
  10229. memset(sd->ignore, 0, sizeof(sd->ignore));
  10230. WFIFOB(fd,3) = 0; // success
  10231. } else {
  10232. WFIFOB(fd,3) = 1; // fail
  10233. }
  10234. }
  10235. }
  10236. WFIFOSET(fd, packet_len(0x0d2));
  10237. return;
  10238. }
  10239. /*==========================================
  10240. * Wis拒否リスト
  10241. *------------------------------------------*/
  10242. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10243. {
  10244. int i;
  10245. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10246. WFIFOW(fd,0) = 0xd4;
  10247. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10248. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10249. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10250. WFIFOSET(fd, WFIFOW(fd,2));
  10251. return;
  10252. }
  10253. /*==========================================
  10254. * スパノビの/doridoriによるSPR2倍
  10255. *------------------------------------------*/
  10256. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10257. {
  10258. if (sd->state.doridori) return;
  10259. switch (sd->class_&MAPID_UPPERMASK)
  10260. {
  10261. case MAPID_SOUL_LINKER:
  10262. case MAPID_STAR_GLADIATOR:
  10263. case MAPID_TAEKWON:
  10264. if (!sd->state.rest)
  10265. break;
  10266. case MAPID_SUPER_NOVICE:
  10267. sd->state.doridori=1;
  10268. break;
  10269. }
  10270. return;
  10271. }
  10272. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI)
  10273. /// 01ed
  10274. /// Note: This packet is caused by 7 lines of any text, followed by
  10275. /// the prayer and an another line of any text. The prayer is
  10276. /// defined by lines 791~794 in data\msgstringtable.txt
  10277. /// "Dear angel, can you hear my voice?"
  10278. /// "I am" (space separated player name) "Super Novice~"
  10279. /// "Help me out~ Please~ T_T"
  10280. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10281. {
  10282. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE )
  10283. {
  10284. unsigned int next = pc_nextbaseexp(sd);
  10285. if( next )
  10286. {
  10287. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10288. if( percent && ( percent%100 ) == 0 )
  10289. {// 10.0%, 20.0%, ..., 90.0%
  10290. sc_start(&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  10291. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10292. }
  10293. }
  10294. }
  10295. }
  10296. /*==========================================
  10297. * Friends List
  10298. *------------------------------------------*/
  10299. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10300. { //Toggles a single friend online/offline [Skotlex]
  10301. int i, fd = sd->fd;
  10302. //Seek friend.
  10303. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10304. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10305. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10306. return; //Not found
  10307. WFIFOHEAD(fd,packet_len(0x206));
  10308. WFIFOW(fd, 0) = 0x206;
  10309. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10310. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10311. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10312. WFIFOSET(fd, packet_len(0x206));
  10313. }
  10314. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10315. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10316. {
  10317. int account_id, char_id, online;
  10318. account_id = va_arg(ap, int);
  10319. char_id = va_arg(ap, int);
  10320. online = va_arg(ap, int);
  10321. clif_friendslist_toggle(sd, account_id, char_id, online);
  10322. return 0;
  10323. }
  10324. //For sending the whole friends list.
  10325. void clif_friendslist_send(struct map_session_data *sd)
  10326. {
  10327. int i = 0, n, fd = sd->fd;
  10328. // Send friends list
  10329. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10330. WFIFOW(fd, 0) = 0x201;
  10331. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10332. {
  10333. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10334. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10335. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10336. }
  10337. if (i) {
  10338. WFIFOW(fd,2) = 4 + 32 * i;
  10339. WFIFOSET(fd, WFIFOW(fd,2));
  10340. }
  10341. for (n = 0; n < i; n++)
  10342. { //Sending the online players
  10343. if (map_charid2sd(sd->status.friends[n].char_id))
  10344. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10345. }
  10346. }
  10347. /// Reply for add friend request: (success => type 0)
  10348. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  10349. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  10350. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  10351. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  10352. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10353. {
  10354. int fd;
  10355. nullpo_retv(sd);
  10356. fd = sd->fd;
  10357. WFIFOHEAD(fd,packet_len(0x209));
  10358. WFIFOW(fd,0) = 0x209;
  10359. WFIFOW(fd,2) = type;
  10360. if (f_sd)
  10361. {
  10362. WFIFOL(fd,4) = f_sd->status.account_id;
  10363. WFIFOL(fd,8) = f_sd->status.char_id;
  10364. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10365. }
  10366. WFIFOSET(fd, packet_len(0x209));
  10367. }
  10368. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10369. {
  10370. struct map_session_data *f_sd;
  10371. int i, f_fd;
  10372. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10373. // Friend doesn't exist (no player with this name)
  10374. if (f_sd == NULL) {
  10375. clif_displaymessage(fd, msg_txt(3));
  10376. return;
  10377. }
  10378. // @noask [LuzZza]
  10379. if(f_sd->state.noask) {
  10380. clif_noask_sub(sd, f_sd, 5);
  10381. return;
  10382. }
  10383. // Friend already exists
  10384. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10385. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10386. clif_displaymessage(fd, "Friend already exists.");
  10387. return;
  10388. }
  10389. }
  10390. if (i == MAX_FRIENDS) {
  10391. //No space, list full.
  10392. clif_friendslist_reqack(sd, f_sd, 2);
  10393. return;
  10394. }
  10395. f_fd = f_sd->fd;
  10396. WFIFOHEAD(f_fd,packet_len(0x207));
  10397. WFIFOW(f_fd,0) = 0x207;
  10398. WFIFOL(f_fd,2) = sd->status.account_id;
  10399. WFIFOL(f_fd,6) = sd->status.char_id;
  10400. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10401. WFIFOSET(f_fd, packet_len(0x207));
  10402. return;
  10403. }
  10404. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10405. {
  10406. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  10407. struct map_session_data *f_sd;
  10408. int char_id, account_id;
  10409. char reply;
  10410. account_id = RFIFOL(fd,2);
  10411. char_id = RFIFOL(fd,6);
  10412. reply = RFIFOB(fd,10);
  10413. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10414. if (f_sd == NULL)
  10415. return;
  10416. if (reply == 0)
  10417. clif_friendslist_reqack(f_sd, sd, 1);
  10418. else {
  10419. int i;
  10420. // Find an empty slot
  10421. for (i = 0; i < MAX_FRIENDS; i++)
  10422. if (f_sd->status.friends[i].char_id == 0)
  10423. break;
  10424. if (i == MAX_FRIENDS) {
  10425. clif_friendslist_reqack(f_sd, sd, 2);
  10426. return;
  10427. }
  10428. f_sd->status.friends[i].account_id = sd->status.account_id;
  10429. f_sd->status.friends[i].char_id = sd->status.char_id;
  10430. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10431. clif_friendslist_reqack(f_sd, sd, 0);
  10432. if (battle_config.friend_auto_add) {
  10433. // Also add f_sd to sd's friendlist.
  10434. for (i = 0; i < MAX_FRIENDS; i++) {
  10435. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10436. return; //No need to add anything.
  10437. if (sd->status.friends[i].char_id == 0)
  10438. break;
  10439. }
  10440. if (i == MAX_FRIENDS) {
  10441. clif_friendslist_reqack(sd, f_sd, 2);
  10442. return;
  10443. }
  10444. sd->status.friends[i].account_id = f_sd->status.account_id;
  10445. sd->status.friends[i].char_id = f_sd->status.char_id;
  10446. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10447. clif_friendslist_reqack(sd, f_sd, 0);
  10448. }
  10449. }
  10450. return;
  10451. }
  10452. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10453. {
  10454. // 0x203 </o> <ID to be removed W 4B>
  10455. int account_id, char_id;
  10456. int i, j;
  10457. account_id = RFIFOL(fd,2);
  10458. char_id = RFIFOL(fd,6);
  10459. // Search friend
  10460. for (i = 0; i < MAX_FRIENDS &&
  10461. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10462. if (i == MAX_FRIENDS) {
  10463. clif_displaymessage(fd, "Name not found in list.");
  10464. return;
  10465. }
  10466. // move all chars down
  10467. for(j = i + 1; j < MAX_FRIENDS; j++)
  10468. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10469. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10470. clif_displaymessage(fd, "Friend removed");
  10471. WFIFOHEAD(fd,packet_len(0x20a));
  10472. WFIFOW(fd,0) = 0x20a;
  10473. WFIFOL(fd,2) = account_id;
  10474. WFIFOL(fd,6) = char_id;
  10475. WFIFOSET(fd, packet_len(0x20a));
  10476. // clif_friendslist_send(sd); //This is not needed anymore.
  10477. return;
  10478. }
  10479. /*==========================================
  10480. * /pvpinfo (CZ_REQ_PVPPOINT & ZC_ACK_PVPPOINT)
  10481. * R 020f <char id>.L <account id>.L
  10482. * S 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  10483. *------------------------------------------*/
  10484. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10485. {
  10486. WFIFOHEAD(fd,packet_len(0x210));
  10487. WFIFOW(fd,0) = 0x210;
  10488. WFIFOL(fd,2) = sd->status.char_id;
  10489. WFIFOL(fd,6) = sd->status.account_id;
  10490. WFIFOL(fd,10) = sd->pvp_won; // times won
  10491. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10492. WFIFOL(fd,18) = sd->pvp_point;
  10493. WFIFOSET(fd, packet_len(0x210));
  10494. }
  10495. /*==========================================
  10496. * /blacksmith
  10497. * S 0217
  10498. *------------------------------------------*/
  10499. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10500. {
  10501. int i;
  10502. const char* name;
  10503. WFIFOHEAD(fd,packet_len(0x219));
  10504. WFIFOW(fd,0) = 0x219;
  10505. //Packet size limits this list to 10 elements. [Skotlex]
  10506. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10507. if (smith_fame_list[i].id > 0) {
  10508. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10509. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10510. {
  10511. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10512. } else
  10513. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10514. } else
  10515. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10516. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10517. }
  10518. for(;i < 10; i++) { //In case the MAX is less than 10.
  10519. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10520. WFIFOL(fd, 242 + i * 4) = 0;
  10521. }
  10522. WFIFOSET(fd, packet_len(0x219));
  10523. }
  10524. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10525. {
  10526. int fd = sd->fd;
  10527. WFIFOHEAD(fd,packet_len(0x21b));
  10528. WFIFOW(fd,0) = 0x21b;
  10529. WFIFOL(fd,2) = points;
  10530. WFIFOL(fd,6) = sd->status.fame;
  10531. WFIFOSET(fd, packet_len(0x21b));
  10532. return 0;
  10533. }
  10534. /*==========================================
  10535. * /alchemist
  10536. * S 0218
  10537. *------------------------------------------*/
  10538. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10539. {
  10540. int i;
  10541. const char* name;
  10542. WFIFOHEAD(fd,packet_len(0x21a));
  10543. WFIFOW(fd,0) = 0x21a;
  10544. //Packet size limits this list to 10 elements. [Skotlex]
  10545. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10546. if (chemist_fame_list[i].id > 0) {
  10547. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10548. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10549. {
  10550. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10551. } else
  10552. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10553. } else
  10554. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10555. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10556. }
  10557. for(;i < 10; i++) { //In case the MAX is less than 10.
  10558. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10559. WFIFOL(fd, 242 + i * 4) = 0;
  10560. }
  10561. WFIFOSET(fd, packet_len(0x21a));
  10562. }
  10563. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10564. {
  10565. int fd = sd->fd;
  10566. WFIFOHEAD(fd,packet_len(0x21c));
  10567. WFIFOW(fd,0) = 0x21c;
  10568. WFIFOL(fd,2) = points;
  10569. WFIFOL(fd,6) = sd->status.fame;
  10570. WFIFOSET(fd, packet_len(0x21c));
  10571. return 0;
  10572. }
  10573. /*==========================================
  10574. * /taekwon
  10575. * S 0225
  10576. *------------------------------------------*/
  10577. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10578. {
  10579. int i;
  10580. const char* name;
  10581. WFIFOHEAD(fd,packet_len(0x226));
  10582. WFIFOW(fd,0) = 0x226;
  10583. //Packet size limits this list to 10 elements. [Skotlex]
  10584. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10585. if (taekwon_fame_list[i].id > 0) {
  10586. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10587. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10588. {
  10589. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10590. } else
  10591. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10592. } else
  10593. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10594. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10595. }
  10596. for(;i < 10; i++) { //In case the MAX is less than 10.
  10597. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10598. WFIFOL(fd, 242 + i * 4) = 0;
  10599. }
  10600. WFIFOSET(fd, packet_len(0x226));
  10601. }
  10602. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10603. {
  10604. int fd = sd->fd;
  10605. WFIFOHEAD(fd,packet_len(0x224));
  10606. WFIFOW(fd,0) = 0x224;
  10607. WFIFOL(fd,2) = points;
  10608. WFIFOL(fd,6) = sd->status.fame;
  10609. WFIFOSET(fd, packet_len(0x224));
  10610. return 0;
  10611. }
  10612. /*==========================================
  10613. * /pk
  10614. * S 0237
  10615. *------------------------------------------*/
  10616. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10617. {
  10618. int i;
  10619. WFIFOHEAD(fd,packet_len(0x238));
  10620. WFIFOW(fd,0) = 0x238;
  10621. for(i=0;i<10;i++){
  10622. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10623. WFIFOL(fd,i*4+242) = 0;
  10624. }
  10625. WFIFOSET(fd, packet_len(0x238));
  10626. return;
  10627. }
  10628. /*==========================================
  10629. * SG Feel save OK [Komurka]
  10630. *------------------------------------------*/
  10631. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10632. {
  10633. int i;
  10634. if (sd->menuskill_id != SG_FEEL)
  10635. return;
  10636. i = sd->menuskill_val-1;
  10637. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  10638. sd->feel_map[i].index = map_id2index(sd->bl.m);
  10639. sd->feel_map[i].m = sd->bl.m;
  10640. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  10641. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10642. // clif_misceffect2(&sd->bl, 0x1b0);
  10643. // clif_misceffect2(&sd->bl, 0x21f);
  10644. clif_feel_info(sd, i, 0);
  10645. sd->menuskill_val = sd->menuskill_id = 0;
  10646. }
  10647. /*==========================================
  10648. * Question about Star Glaldiator save map [Komurka]
  10649. *------------------------------------------*/
  10650. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  10651. {
  10652. WFIFOHEAD(fd,packet_len(0x253));
  10653. WFIFOW(fd,0)=0x253;
  10654. WFIFOSET(fd, packet_len(0x253));
  10655. sd->menuskill_id = SG_FEEL;
  10656. sd->menuskill_val = skilllv;
  10657. }
  10658. /*==========================================
  10659. * Homunculus packets
  10660. *------------------------------------------*/
  10661. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  10662. {
  10663. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  10664. }
  10665. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  10666. {
  10667. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10668. struct block_list *bl = NULL;
  10669. struct unit_data *ud = NULL;
  10670. if( sd->md && sd->md->bl.id == id )
  10671. bl = &sd->md->bl;
  10672. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10673. bl = &sd->hd->bl; // Moving Homunculus
  10674. else return;
  10675. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  10676. ud = unit_bl2ud(bl);
  10677. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  10678. }
  10679. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  10680. {
  10681. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10682. struct block_list *bl = NULL;
  10683. short x, y, cmd;
  10684. cmd = RFIFOW(fd,0);
  10685. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10686. 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);
  10687. if( sd->md && sd->md->bl.id == id )
  10688. bl = &sd->md->bl; // Moving Mercenary
  10689. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10690. bl = &sd->hd->bl; // Moving Homunculus
  10691. else return;
  10692. unit_walktoxy(bl, x, y, 4);
  10693. }
  10694. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  10695. {
  10696. struct block_list *bl = NULL;
  10697. int id = RFIFOL(fd,2),
  10698. target_id = RFIFOL(fd,6),
  10699. action_type = RFIFOB(fd,10);
  10700. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10701. bl = &sd->hd->bl;
  10702. else if( sd->md && sd->md->bl.id == id )
  10703. bl = &sd->md->bl;
  10704. else return;
  10705. unit_stop_attack(bl);
  10706. unit_attack(bl, target_id, action_type != 0);
  10707. }
  10708. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  10709. { //[orn]
  10710. int cmd;
  10711. cmd = RFIFOW(fd,0);
  10712. if(!merc_is_hom_active(sd->hd))
  10713. return;
  10714. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10715. }
  10716. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  10717. {
  10718. int item_position = pc_search_inventory(sd, 7621);
  10719. if (item_position < 0)
  10720. return;
  10721. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  10722. return;
  10723. if (!status_revive(&sd->bl, 100, 100))
  10724. return;
  10725. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  10726. pc_delitem(sd, item_position, 1, 0, 1);
  10727. }
  10728. /// Information about character's status values (ZC_ACK_STATUS_GM)
  10729. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  10730. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  10731. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  10732. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  10733. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  10734. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  10735. void clif_check(int fd, struct map_session_data* pl_sd)
  10736. {
  10737. WFIFOHEAD(fd,packet_len(0x214));
  10738. WFIFOW(fd, 0) = 0x214;
  10739. WFIFOB(fd, 2) = min(pl_sd->status.str, UCHAR_MAX);
  10740. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR);
  10741. WFIFOB(fd, 4) = min(pl_sd->status.agi, UCHAR_MAX);
  10742. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI);
  10743. WFIFOB(fd, 6) = min(pl_sd->status.vit, UCHAR_MAX);
  10744. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT);
  10745. WFIFOB(fd, 8) = min(pl_sd->status.int_, UCHAR_MAX);
  10746. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT);
  10747. WFIFOB(fd,10) = min(pl_sd->status.dex, UCHAR_MAX);
  10748. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX);
  10749. WFIFOB(fd,12) = min(pl_sd->status.luk, UCHAR_MAX);
  10750. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK);
  10751. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  10752. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  10753. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  10754. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  10755. WFIFOW(fd,22) = pl_sd->battle_status.def;
  10756. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  10757. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  10758. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  10759. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  10760. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  10761. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  10762. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  10763. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  10764. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be?
  10765. WFIFOSET(fd,packet_len(0x214));
  10766. }
  10767. /// Request character's status values (CZ_REQ_STATUS_GM)
  10768. /// /check <char name>
  10769. /// 0213 <char name>.24B
  10770. void clif_parse_Check(int fd, struct map_session_data *sd)
  10771. {
  10772. char charname[NAME_LENGTH];
  10773. struct map_session_data* pl_sd;
  10774. if( pc_isGM(sd) < battle_config.gm_check_minlevel )
  10775. {
  10776. return;
  10777. }
  10778. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  10779. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_isGM(sd) < pc_isGM(pl_sd) )
  10780. {
  10781. return;
  10782. }
  10783. clif_check(fd, pl_sd);
  10784. }
  10785. #ifndef TXT_ONLY
  10786. /*==========================================
  10787. * MAIL SYSTEM
  10788. * By Zephyrus
  10789. *==========================================*/
  10790. /*------------------------------------------
  10791. * Reply to Set Attachment operation
  10792. * 0 : Successfully attached item to mail
  10793. * 1 : Fail to set the attachment
  10794. *------------------------------------------*/
  10795. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  10796. {
  10797. WFIFOHEAD(fd,packet_len(0x255));
  10798. WFIFOW(fd,0) = 0x255;
  10799. WFIFOW(fd,2) = index;
  10800. WFIFOB(fd,4) = flag;
  10801. WFIFOSET(fd,packet_len(0x255));
  10802. }
  10803. /*------------------------------------------
  10804. * Reply to Get Attachment operation
  10805. * 0 : Successfully added attachment to Inventory
  10806. * 1 : Fail to set the item to inventory
  10807. * 2 : Weight problems
  10808. *------------------------------------------*/
  10809. void clif_Mail_getattachment(int fd, uint8 flag)
  10810. {
  10811. WFIFOHEAD(fd,packet_len(0x245));
  10812. WFIFOW(fd,0) = 0x245;
  10813. WFIFOB(fd,2) = flag;
  10814. WFIFOSET(fd,packet_len(0x245));
  10815. }
  10816. /*------------------------------------------
  10817. * Send Mail ack
  10818. * 0 : Message Send Ok
  10819. * 1 : Recipient does not exist
  10820. *------------------------------------------*/
  10821. void clif_Mail_send(int fd, bool fail)
  10822. {
  10823. WFIFOHEAD(fd,packet_len(0x249));
  10824. WFIFOW(fd,0) = 0x249;
  10825. WFIFOB(fd,2) = fail;
  10826. WFIFOSET(fd,packet_len(0x249));
  10827. }
  10828. /*------------------------------------------
  10829. * Delete Mail ack
  10830. * 0 : Delete ok
  10831. * 1 : Delete failed
  10832. *------------------------------------------*/
  10833. void clif_Mail_delete(int fd, int mail_id, short fail)
  10834. {
  10835. WFIFOHEAD(fd, packet_len(0x257));
  10836. WFIFOW(fd,0) = 0x257;
  10837. WFIFOL(fd,2) = mail_id;
  10838. WFIFOW(fd,6) = fail;
  10839. WFIFOSET(fd, packet_len(0x257));
  10840. }
  10841. /*------------------------------------------
  10842. * Return Mail ack
  10843. * 0 : Mail returned to the sender
  10844. * 1 : The mail does not exist
  10845. *------------------------------------------*/
  10846. void clif_Mail_return(int fd, int mail_id, short fail)
  10847. {
  10848. WFIFOHEAD(fd,packet_len(0x274));
  10849. WFIFOW(fd,0) = 0x274;
  10850. WFIFOL(fd,2) = mail_id;
  10851. WFIFOW(fd,6) = fail;
  10852. WFIFOSET(fd,packet_len(0x274));
  10853. }
  10854. /*------------------------------------------
  10855. * You have New Mail
  10856. *------------------------------------------*/
  10857. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10858. {
  10859. WFIFOHEAD(fd,packet_len(0x24a));
  10860. WFIFOW(fd,0) = 0x24a;
  10861. WFIFOL(fd,2) = mail_id;
  10862. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10863. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10864. WFIFOSET(fd,packet_len(0x24a));
  10865. }
  10866. /*------------------------------------------
  10867. * Handles Mail Window on Client
  10868. * flag : 0 open | 1 close
  10869. *------------------------------------------*/
  10870. void clif_Mail_window(int fd, int flag)
  10871. {
  10872. WFIFOHEAD(fd,packet_len(0x260));
  10873. WFIFOW(fd,0) = 0x260;
  10874. WFIFOL(fd,2) = flag;
  10875. WFIFOSET(fd,packet_len(0x260));
  10876. }
  10877. /*------------------------------------------
  10878. * Send Inbox Data to Client
  10879. *------------------------------------------*/
  10880. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10881. {
  10882. int fd = sd->fd;
  10883. struct mail_data *md = &sd->mail.inbox;
  10884. struct mail_message *msg;
  10885. int len, i, j;
  10886. len = 8 + (73 * md->amount);
  10887. WFIFOHEAD(fd,len);
  10888. WFIFOW(fd,0) = 0x240;
  10889. WFIFOW(fd,2) = len;
  10890. WFIFOL(fd,4) = md->amount;
  10891. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10892. {
  10893. msg = &md->msg[i];
  10894. if (msg->id < 1)
  10895. continue;
  10896. WFIFOL(fd,8+73*j) = msg->id;
  10897. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10898. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10899. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10900. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10901. j++;
  10902. }
  10903. WFIFOSET(fd,len);
  10904. if( md->full )
  10905. {
  10906. char output[100];
  10907. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10908. clif_disp_onlyself(sd, output, strlen(output));
  10909. }
  10910. }
  10911. /*------------------------------------------
  10912. * Client Request Inbox List
  10913. *------------------------------------------*/
  10914. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10915. {
  10916. struct mail_data* md = &sd->mail.inbox;
  10917. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10918. intif_Mail_requestinbox(sd->status.char_id, 1);
  10919. else
  10920. clif_Mail_refreshinbox(sd);
  10921. mail_removeitem(sd, 0);
  10922. mail_removezeny(sd, 0);
  10923. }
  10924. /*------------------------------------------
  10925. * Read Message
  10926. *------------------------------------------*/
  10927. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10928. {
  10929. int i, fd = sd->fd;
  10930. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10931. if( i == MAIL_MAX_INBOX )
  10932. {
  10933. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10934. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10935. return;
  10936. }
  10937. else
  10938. {
  10939. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10940. struct item *item = &msg->item;
  10941. struct item_data *data;
  10942. int msg_len = strlen(msg->body), len;
  10943. if( msg_len == 0 ) {
  10944. strcpy(msg->body, "(no message)");
  10945. msg_len = strlen(msg->body);
  10946. }
  10947. len = 101 + msg_len;
  10948. WFIFOHEAD(fd,len);
  10949. WFIFOW(fd,0) = 0x242;
  10950. WFIFOW(fd,2) = len;
  10951. WFIFOL(fd,4) = msg->id;
  10952. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10953. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10954. WFIFOL(fd,72) = 0;
  10955. WFIFOL(fd,76) = msg->zeny;
  10956. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
  10957. {
  10958. WFIFOL(fd,80) = item->amount;
  10959. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10960. WFIFOW(fd,86) = data->type;
  10961. WFIFOB(fd,88) = item->identify;
  10962. WFIFOB(fd,89) = item->attribute;
  10963. WFIFOB(fd,90) = item->refine;
  10964. WFIFOW(fd,91) = item->card[0];
  10965. WFIFOW(fd,93) = item->card[1];
  10966. WFIFOW(fd,95) = item->card[2];
  10967. WFIFOW(fd,97) = item->card[3];
  10968. }
  10969. else // no item, set all to zero
  10970. memset(WFIFOP(fd,80), 0x00, 19);
  10971. WFIFOB(fd,99) = (unsigned char)msg_len;
  10972. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10973. WFIFOSET(fd,len);
  10974. if (msg->status == MAIL_UNREAD) {
  10975. msg->status = MAIL_READ;
  10976. intif_Mail_read(mail_id);
  10977. clif_parse_Mail_refreshinbox(fd, sd);
  10978. }
  10979. }
  10980. }
  10981. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10982. {
  10983. int mail_id = RFIFOL(fd,2);
  10984. if( mail_id <= 0 )
  10985. return;
  10986. if( mail_invalid_operation(sd) )
  10987. return;
  10988. clif_Mail_read(sd, RFIFOL(fd,2));
  10989. }
  10990. /*------------------------------------------
  10991. * Get Attachment from Message
  10992. *------------------------------------------*/
  10993. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10994. {
  10995. int mail_id = RFIFOL(fd,2);
  10996. int i;
  10997. bool fail = false;
  10998. if( mail_id <= 0 )
  10999. return;
  11000. if( mail_invalid_operation(sd) )
  11001. return;
  11002. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11003. if( i == MAIL_MAX_INBOX )
  11004. return;
  11005. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11006. return;
  11007. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  11008. {
  11009. struct item_data *data;
  11010. unsigned int weight;
  11011. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11012. return;
  11013. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  11014. {
  11015. case ADDITEM_NEW:
  11016. fail = ( pc_inventoryblank(sd) == 0 );
  11017. break;
  11018. case ADDITEM_OVERAMOUNT:
  11019. fail = true;
  11020. }
  11021. if( fail )
  11022. {
  11023. clif_Mail_getattachment(fd, 1);
  11024. return;
  11025. }
  11026. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11027. if( sd->weight + weight > sd->max_weight )
  11028. {
  11029. clif_Mail_getattachment(fd, 2);
  11030. return;
  11031. }
  11032. }
  11033. sd->mail.inbox.msg[i].zeny = 0;
  11034. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11035. clif_Mail_read(sd, mail_id);
  11036. intif_Mail_getattach(sd->status.char_id, mail_id);
  11037. }
  11038. /*------------------------------------------
  11039. * Delete Message
  11040. *------------------------------------------*/
  11041. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11042. {
  11043. int mail_id = RFIFOL(fd,2);
  11044. int i;
  11045. if( mail_id <= 0 )
  11046. return;
  11047. if( mail_invalid_operation(sd) )
  11048. return;
  11049. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11050. if (i < MAIL_MAX_INBOX)
  11051. {
  11052. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11053. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11054. {// can't delete mail without removing attachment first
  11055. clif_Mail_delete(sd->fd, mail_id, 1);
  11056. return;
  11057. }
  11058. intif_Mail_delete(sd->status.char_id, mail_id);
  11059. }
  11060. }
  11061. /*------------------------------------------
  11062. * Return Mail Message
  11063. *------------------------------------------*/
  11064. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11065. {
  11066. int mail_id = RFIFOL(fd,2);
  11067. int i;
  11068. if( mail_id <= 0 )
  11069. return;
  11070. if( mail_invalid_operation(sd) )
  11071. return;
  11072. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11073. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11074. intif_Mail_return(sd->status.char_id, mail_id);
  11075. else
  11076. clif_Mail_return(sd->fd, mail_id, 1);
  11077. }
  11078. /*------------------------------------------
  11079. * Set Attachment
  11080. *------------------------------------------*/
  11081. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11082. {
  11083. int idx = RFIFOW(fd,2);
  11084. int amount = RFIFOL(fd,4);
  11085. unsigned char flag;
  11086. if (idx < 0 || amount < 0)
  11087. return;
  11088. flag = mail_setitem(sd, idx, amount);
  11089. clif_Mail_setattachment(fd,idx,flag);
  11090. }
  11091. /*------------------------------------------
  11092. * Mail Window Operation
  11093. * S 0246 <flag>.W
  11094. * 0 : Switch to 'new mail' window, or Close mailbox
  11095. * 1 : ???
  11096. * 2 : Zeny entering start
  11097. *------------------------------------------*/
  11098. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11099. {
  11100. int flag = RFIFOW(fd,2);
  11101. if (flag == 0 || flag == 1)
  11102. mail_removeitem(sd, 0);
  11103. if (flag == 0 || flag == 2)
  11104. mail_removezeny(sd, 0);
  11105. }
  11106. /*------------------------------------------
  11107. * Send Mail
  11108. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  11109. *------------------------------------------*/
  11110. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11111. {
  11112. struct mail_message msg;
  11113. int body_len;
  11114. if( sd->state.trading )
  11115. return;
  11116. if( RFIFOW(fd,2) < 69 ) {
  11117. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11118. return;
  11119. }
  11120. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11121. {
  11122. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11123. clif_Mail_send(fd, true); // fail
  11124. return;
  11125. }
  11126. body_len = RFIFOB(fd,68);
  11127. if (body_len > MAIL_BODY_LENGTH)
  11128. body_len = MAIL_BODY_LENGTH;
  11129. if( !mail_setattachment(sd, &msg) )
  11130. { // Invalid Append condition
  11131. clif_Mail_send(sd->fd, true); // fail
  11132. mail_removeitem(sd,0);
  11133. mail_removezeny(sd,0);
  11134. return;
  11135. }
  11136. msg.id = 0; // id will be assigned by charserver
  11137. msg.send_id = sd->status.char_id;
  11138. msg.dest_id = 0; // will attempt to resolve name
  11139. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11140. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11141. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11142. if (body_len)
  11143. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11144. else
  11145. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11146. msg.timestamp = time(NULL);
  11147. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11148. mail_deliveryfail(sd, &msg);
  11149. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11150. }
  11151. /*==========================================
  11152. * AUCTION SYSTEM
  11153. * By Zephyrus
  11154. *==========================================*/
  11155. void clif_Auction_openwindow(struct map_session_data *sd)
  11156. {
  11157. int fd = sd->fd;
  11158. if( sd->state.storage_flag || sd->vender_id || sd->state.buyingstore || sd->state.trading )
  11159. return;
  11160. WFIFOHEAD(fd,12);
  11161. WFIFOW(fd,0) = 0x25f;
  11162. WFIFOL(fd,2) = 0;
  11163. WFIFOB(fd,6) = 0xb6;
  11164. WFIFOB(fd,7) = 0x00;
  11165. WFIFOB(fd,8) = 0xa6;
  11166. WFIFOB(fd,9) = 0xde;
  11167. WFIFOW(fd,10) = 0;
  11168. WFIFOSET(fd,12);
  11169. }
  11170. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11171. {
  11172. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11173. struct auction_data auction;
  11174. struct item_data *item;
  11175. int k;
  11176. WFIFOHEAD(fd,20);
  11177. WFIFOW(fd,0) = 0x252;
  11178. WFIFOW(fd,2) = 12 + (count * 83);
  11179. WFIFOL(fd,4) = pages;
  11180. WFIFOL(fd,8) = count;
  11181. for( i = 0; i < count; i++ )
  11182. {
  11183. memcpy(&auction, RBUFP(buf,i * len), len);
  11184. k = 12 + (i * 83);
  11185. WFIFOL(fd,k) = auction.auction_id;
  11186. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11187. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11188. WFIFOW(fd,28+k) = item->view_id;
  11189. else
  11190. WFIFOW(fd,28+k) = auction.item.nameid;
  11191. WFIFOW(fd,30+k) = auction.type;
  11192. WFIFOW(fd,32+k) = 0; // ??
  11193. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  11194. WFIFOB(fd,36+k) = auction.item.identify;
  11195. WFIFOB(fd,37+k) = auction.item.attribute;
  11196. WFIFOB(fd,38+k) = auction.item.refine;
  11197. WFIFOW(fd,39+k) = auction.item.card[0];
  11198. WFIFOW(fd,41+k) = auction.item.card[1];
  11199. WFIFOW(fd,43+k) = auction.item.card[2];
  11200. WFIFOW(fd,45+k) = auction.item.card[3];
  11201. WFIFOL(fd,47+k) = auction.price;
  11202. WFIFOL(fd,51+k) = auction.buynow;
  11203. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11204. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11205. }
  11206. WFIFOSET(fd, 12 + (count * 83));
  11207. }
  11208. static void clif_Auction_setitem(int fd, int index, bool fail)
  11209. {
  11210. WFIFOHEAD(fd,packet_len(0x256));
  11211. WFIFOW(fd,0) = 0x256;
  11212. WFIFOW(fd,2) = index;
  11213. WFIFOB(fd,4) = fail;
  11214. WFIFOSET(fd,packet_len(0x256));
  11215. }
  11216. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11217. {
  11218. if( sd->auction.amount > 0 )
  11219. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11220. sd->auction.amount = 0;
  11221. }
  11222. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11223. {
  11224. int idx = RFIFOW(fd,2) - 2;
  11225. int amount = RFIFOL(fd,4); // Allways 1
  11226. struct item_data *item;
  11227. if( sd->auction.amount > 0 )
  11228. sd->auction.amount = 0;
  11229. if( idx < 0 || idx >= MAX_INVENTORY )
  11230. {
  11231. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11232. return;
  11233. }
  11234. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  11235. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  11236. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11237. return;
  11238. }
  11239. 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) )
  11240. { // Consumible or pets are not allowed
  11241. clif_Auction_setitem(sd->fd, idx, true);
  11242. return;
  11243. }
  11244. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
  11245. { // Quest Item or something else
  11246. clif_Auction_setitem(sd->fd, idx, true);
  11247. return;
  11248. }
  11249. sd->auction.index = idx;
  11250. sd->auction.amount = amount;
  11251. clif_Auction_setitem(fd, idx + 2, false);
  11252. }
  11253. // 0 = You have failed to bid into the auction
  11254. // 1 = You have successfully bid in the auction
  11255. // 2 = The auction has been canceled
  11256. // 3 = An auction with at least one bidder cannot be canceled
  11257. // 4 = You cannot register more than 5 items in an auction at a time
  11258. // 5 = You do not have enough Zeny to pay the Auction Fee
  11259. // 6 = You have won the auction
  11260. // 7 = You have failed to win the auction
  11261. // 8 = You do not have enough Zeny
  11262. // 9 = You cannot place more than 5 bids at a time
  11263. void clif_Auction_message(int fd, unsigned char flag)
  11264. {
  11265. WFIFOHEAD(fd,3);
  11266. WFIFOW(fd,0) = 0x250;
  11267. WFIFOB(fd,2) = flag;
  11268. WFIFOSET(fd,3);
  11269. }
  11270. // 0 = You have ended the auction
  11271. // 1 = You cannot end the auction
  11272. // 2 = Bid number is incorrect
  11273. void clif_Auction_close(int fd, unsigned char flag)
  11274. {
  11275. WFIFOHEAD(fd,6);
  11276. WFIFOW(fd,0) = 0x25d;
  11277. WFIFOL(fd,2) = flag;
  11278. WFIFOSET(fd,6);
  11279. }
  11280. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11281. {
  11282. struct auction_data auction;
  11283. struct item_data *item;
  11284. auction.price = RFIFOL(fd,2);
  11285. auction.buynow = RFIFOL(fd,6);
  11286. auction.hours = RFIFOW(fd,10);
  11287. // Invalid Situations...
  11288. if( sd->auction.amount < 1 )
  11289. {
  11290. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11291. return;
  11292. }
  11293. if( auction.price >= auction.buynow )
  11294. {
  11295. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11296. return;
  11297. }
  11298. if( auction.hours < 1 || auction.hours > 48 )
  11299. {
  11300. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11301. return;
  11302. }
  11303. // Auction checks...
  11304. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11305. {
  11306. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11307. return;
  11308. }
  11309. if( auction.buynow > battle_config.auction_maximumprice )
  11310. { // Zeny Limits
  11311. auction.buynow = battle_config.auction_maximumprice;
  11312. if( auction.price >= auction.buynow )
  11313. auction.price = auction.buynow - 1;
  11314. }
  11315. auction.auction_id = 0;
  11316. auction.seller_id = sd->status.char_id;
  11317. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  11318. auction.buyer_id = 0;
  11319. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  11320. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11321. {
  11322. clif_Auction_message(fd, 2); // The auction has been canceled
  11323. return;
  11324. }
  11325. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11326. { // Just in case
  11327. clif_Auction_message(fd, 2); // The auction has been canceled
  11328. return;
  11329. }
  11330. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  11331. auction.type = item->type;
  11332. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11333. auction.item.amount = 1;
  11334. auction.timestamp = 0;
  11335. if( !intif_Auction_register(&auction) )
  11336. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11337. else
  11338. {
  11339. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6);
  11340. sd->auction.amount = 0;
  11341. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  11342. }
  11343. }
  11344. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11345. {
  11346. unsigned int auction_id = RFIFOL(fd,2);
  11347. intif_Auction_cancel(sd->status.char_id, auction_id);
  11348. }
  11349. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11350. {
  11351. unsigned int auction_id = RFIFOL(fd,2);
  11352. intif_Auction_close(sd->status.char_id, auction_id);
  11353. }
  11354. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11355. {
  11356. unsigned int auction_id = RFIFOL(fd,2);
  11357. int bid = RFIFOL(fd,6);
  11358. if( !pc_can_give_items(pc_isGM(sd)) )
  11359. { //They aren't supposed to give zeny [Inkfish]
  11360. clif_displaymessage(sd->fd, msg_txt(246));
  11361. return;
  11362. }
  11363. if( bid <= 0 )
  11364. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11365. else if( bid > sd->status.zeny )
  11366. clif_Auction_message(fd, 8); // You do not have enough zeny
  11367. else
  11368. {
  11369. pc_payzeny(sd, bid);
  11370. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11371. }
  11372. }
  11373. /*------------------------------------------
  11374. * Auction Search
  11375. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  11376. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  11377. *------------------------------------------*/
  11378. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11379. {
  11380. char search_text[NAME_LENGTH];
  11381. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11382. int price = RFIFOL(fd,4);
  11383. clif_parse_Auction_cancelreg(fd, sd);
  11384. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  11385. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11386. }
  11387. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11388. {
  11389. short type = RFIFOW(fd,2) + 6;
  11390. clif_parse_Auction_cancelreg(fd, sd);
  11391. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11392. }
  11393. #endif
  11394. /*==========================================
  11395. * CASH/POINT SHOP
  11396. *==========================================*/
  11397. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11398. {
  11399. int fd,i;
  11400. nullpo_retv(sd);
  11401. nullpo_retv(nd);
  11402. fd = sd->fd;
  11403. sd->npc_shopid = nd->bl.id;
  11404. WFIFOHEAD(fd, 200 * 11 + 12);
  11405. WFIFOW(fd,0) = 0x287;
  11406. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  11407. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11408. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11409. for( i = 0; i < nd->u.shop.count; i++ )
  11410. {
  11411. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11412. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  11413. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  11414. WFIFOB(fd,20+i*11) = itemtype(id->type);
  11415. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11416. }
  11417. WFIFOSET(fd,WFIFOW(fd,2));
  11418. }
  11419. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE)
  11420. /// S 0289 <cash point>.L <kafra point>.L <error>.W
  11421. ///
  11422. /// @param error
  11423. /// 0: The deal has successfully completed. (ERROR_TYPE_NONE)
  11424. /// 1: The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11425. /// 2: The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11426. /// 3: You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11427. /// 4: You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11428. /// 5: The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11429. /// 6: You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11430. /// 7: You can purchase up to 10 items.
  11431. /// 8: Some items could not be purchased.
  11432. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11433. {
  11434. int fd = sd->fd;
  11435. WFIFOHEAD(fd, packet_len(0x289));
  11436. WFIFOW(fd,0) = 0x289;
  11437. WFIFOL(fd,2) = sd->cashPoints;
  11438. WFIFOL(fd,6) = sd->kafraPoints;
  11439. WFIFOW(fd,10) = TOW(error);
  11440. WFIFOSET(fd, packet_len(0x289));
  11441. }
  11442. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11443. {
  11444. int fail = 0, amount, points;
  11445. short nameid;
  11446. nullpo_retv(sd);
  11447. nameid = RFIFOW(fd,2);
  11448. amount = RFIFOW(fd,4);
  11449. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  11450. if( sd->state.trading || !sd->npc_shopid )
  11451. fail = 1;
  11452. else
  11453. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11454. clif_cashshop_ack(sd, fail);
  11455. }
  11456. /*==========================================
  11457. * Adoption System
  11458. *==========================================*/
  11459. // 0 : "You cannot adopt more than 1 child."
  11460. // 1 : "You must be at least character level 70 in order to adopt someone."
  11461. // 2 : "You cannot adopt a married person."
  11462. void clif_Adopt_reply(struct map_session_data *sd, int type)
  11463. {
  11464. int fd = sd->fd;
  11465. WFIFOHEAD(fd,6);
  11466. WFIFOW(fd,0) = 0x0216;
  11467. WFIFOL(fd,2) = type;
  11468. WFIFOSET(fd,6);
  11469. }
  11470. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  11471. {
  11472. int fd = sd->fd;
  11473. WFIFOHEAD(fd,34);
  11474. WFIFOW(fd,0) = 0x01f6;
  11475. WFIFOL(fd,2) = src->status.account_id;
  11476. WFIFOL(fd,6) = p_id;
  11477. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  11478. WFIFOSET(fd,34);
  11479. }
  11480. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  11481. {
  11482. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  11483. if( pc_can_Adopt(sd, p_sd, tsd) )
  11484. {
  11485. tsd->adopt_invite = sd->status.account_id;
  11486. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  11487. }
  11488. }
  11489. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  11490. {
  11491. int p1_id = RFIFOL(fd,2);
  11492. int p2_id = RFIFOL(fd,6);
  11493. int result = RFIFOL(fd,10);
  11494. struct map_session_data* p1_sd = map_id2sd(p1_id);
  11495. struct map_session_data* p2_sd = map_id2sd(p2_id);
  11496. int pid = sd->adopt_invite;
  11497. sd->adopt_invite = 0;
  11498. if( p1_sd == NULL || p2_sd == NULL )
  11499. return; // Both players need to be online
  11500. if( pid != p1_sd->status.account_id )
  11501. return; // Incorrect values
  11502. if( result == 0 )
  11503. return; // Rejected
  11504. pc_adoption(p1_sd, p2_sd, sd);
  11505. }
  11506. /*==========================================
  11507. * Convex Mirror (ZC_BOSS_INFO)
  11508. * S 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  11509. * infoType:
  11510. * 0 = No boss on this map (BOSS_INFO_NOT).
  11511. * 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  11512. * 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  11513. * 3 = Boss is dead (BOSS_INFO_DEAD).
  11514. *==========================================*/
  11515. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  11516. {
  11517. WFIFOHEAD(fd,70);
  11518. memset(WFIFOP(fd,0),0,70);
  11519. WFIFOW(fd,0) = 0x0293;
  11520. if( md != NULL )
  11521. {
  11522. if( md->bl.prev != NULL )
  11523. { // Boss on This Map
  11524. if( flag )
  11525. {
  11526. WFIFOB(fd,2) = 1;
  11527. WFIFOL(fd,3) = md->bl.x;
  11528. WFIFOL(fd,7) = md->bl.y;
  11529. }
  11530. else
  11531. WFIFOB(fd,2) = 2; // First Time
  11532. }
  11533. else if (md->spawn_timer != INVALID_TIMER)
  11534. { // Boss is Dead
  11535. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  11536. unsigned int seconds;
  11537. int hours, minutes;
  11538. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  11539. hours = seconds / (60 * 60);
  11540. seconds = seconds - (60 * 60 * hours);
  11541. minutes = seconds / 60;
  11542. WFIFOB(fd,2) = 3;
  11543. WFIFOW(fd,11) = hours; // Hours
  11544. WFIFOW(fd,13) = minutes; // Minutes
  11545. }
  11546. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  11547. }
  11548. WFIFOSET(fd,70);
  11549. }
  11550. /*==========================================
  11551. * Requesting equip of a player
  11552. *------------------------------------------*/
  11553. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  11554. {
  11555. int charid = RFIFOL(fd, 2);
  11556. struct map_session_data* tsd = map_id2sd(charid);
  11557. if (!tsd)
  11558. return;
  11559. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  11560. clif_viewequip_ack(sd, tsd);
  11561. else
  11562. clif_viewequip_fail(sd);
  11563. }
  11564. /*==========================================
  11565. * Equip window (un)tick
  11566. * S 02d8 <zero?>.L <flag>.L
  11567. *------------------------------------------*/
  11568. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  11569. {
  11570. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  11571. sd->status.show_equip = flag;
  11572. clif_equiptickack(sd, flag);
  11573. }
  11574. /*==========================================
  11575. * Questlog System [Kevin] [Inkfish]
  11576. *------------------------------------------*/
  11577. //* 02B1 <packet_len>.W <quest_num>.L { <quest_id>.L <state>.B }.5B*
  11578. void clif_quest_send_list(struct map_session_data * sd)
  11579. {
  11580. int fd = sd->fd;
  11581. int i;
  11582. int len = sd->avail_quests*5+8;
  11583. WFIFOHEAD(fd,len);
  11584. WFIFOW(fd, 0) = 0x02B1;
  11585. WFIFOW(fd, 2) = len;
  11586. WFIFOL(fd, 4) = sd->avail_quests;
  11587. for( i = 0; i < sd->avail_quests; i++ )
  11588. {
  11589. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  11590. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  11591. }
  11592. WFIFOSET(fd, len);
  11593. }
  11594. //* 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*
  11595. void clif_quest_send_mission(struct map_session_data * sd)
  11596. {
  11597. int fd = sd->fd;
  11598. int i, j;
  11599. int len = sd->avail_quests*104+8;
  11600. struct mob_db *mob;
  11601. WFIFOHEAD(fd, len);
  11602. WFIFOW(fd, 0) = 0x02B2;
  11603. WFIFOW(fd, 2) = len;
  11604. WFIFOL(fd, 4) = sd->avail_quests;
  11605. for( i = 0; i < sd->avail_quests; i++ )
  11606. {
  11607. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  11608. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  11609. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  11610. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  11611. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  11612. {
  11613. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  11614. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  11615. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  11616. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  11617. }
  11618. }
  11619. WFIFOSET(fd, len);
  11620. }
  11621. //* 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]
  11622. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  11623. {
  11624. int fd = sd->fd;
  11625. int i;
  11626. struct mob_db *mob;
  11627. WFIFOHEAD(fd, packet_len(0x02B3));
  11628. WFIFOW(fd, 0) = 0x02B3;
  11629. WFIFOL(fd, 2) = qd->quest_id;
  11630. WFIFOB(fd, 6) = qd->state;
  11631. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  11632. WFIFOL(fd, 11) = qd->time;
  11633. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  11634. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11635. {
  11636. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  11637. WFIFOW(fd, i*30+21) = qd->count[i];
  11638. mob = mob_db(quest_db[index].mob[i]);
  11639. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  11640. }
  11641. WFIFOSET(fd, packet_len(0x02B3));
  11642. }
  11643. //* 02B4 <quest_id>.L
  11644. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  11645. {
  11646. int fd = sd->fd;
  11647. WFIFOHEAD(fd, packet_len(0x02B4));
  11648. WFIFOW(fd, 0) = 0x02B4;
  11649. WFIFOL(fd, 2) = quest_id;
  11650. WFIFOSET(fd, packet_len(0x02B4));
  11651. }
  11652. //* 02b5 <packet_len>.w <mob_num>.w { <quest_id>.d <mob_id>.d <count_total>.w <count_partial>.w }.mob_num
  11653. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  11654. {
  11655. int fd = sd->fd;
  11656. int i;
  11657. int len = quest_db[index].num_objectives*12+6;
  11658. WFIFOHEAD(fd, len);
  11659. WFIFOW(fd, 0) = 0x02B5;
  11660. WFIFOW(fd, 2) = len;
  11661. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  11662. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11663. {
  11664. WFIFOL(fd, i*12+6) = qd->quest_id;
  11665. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  11666. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  11667. WFIFOW(fd, i*12+16) = qd->count[i];
  11668. }
  11669. WFIFOSET(fd, len);
  11670. }
  11671. //* 02B6 <quest_id>.L <state>.B
  11672. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  11673. {
  11674. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  11675. }
  11676. //* 02B7 <quest_id>.L <state_to>.B
  11677. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  11678. {
  11679. int fd = sd->fd;
  11680. WFIFOHEAD(fd, packet_len(0x02B7));
  11681. WFIFOW(fd, 0) = 0x02B7;
  11682. WFIFOL(fd, 2) = quest_id;
  11683. WFIFOB(fd, 6) = active;
  11684. WFIFOSET(fd, packet_len(0x02B7));
  11685. }
  11686. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  11687. {
  11688. #if PACKETVER >= 20090218
  11689. int fd = sd->fd;
  11690. WFIFOHEAD(fd, packet_len(0x446));
  11691. WFIFOW(fd, 0) = 0x446;
  11692. WFIFOL(fd, 2) = bl->id;
  11693. WFIFOW(fd, 6) = bl->x;
  11694. WFIFOW(fd, 8) = bl->y;
  11695. WFIFOW(fd, 10) = state;
  11696. WFIFOW(fd, 12) = color;
  11697. WFIFOSET(fd, packet_len(0x446));
  11698. #endif
  11699. }
  11700. /*==========================================
  11701. * Mercenary System
  11702. *==========================================*/
  11703. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  11704. {
  11705. struct mercenary_data *md;
  11706. struct status_data *status;
  11707. int fd;
  11708. if( sd == NULL || (md = sd->md) == NULL )
  11709. return;
  11710. fd = sd->fd;
  11711. status = &md->battle_status;
  11712. WFIFOHEAD(fd,8);
  11713. WFIFOW(fd,0) = 0x02a2;
  11714. WFIFOW(fd,2) = type;
  11715. switch( type )
  11716. {
  11717. case SP_ATK1:
  11718. {
  11719. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11720. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  11721. }
  11722. break;
  11723. case SP_MATK1:
  11724. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  11725. break;
  11726. case SP_HIT:
  11727. WFIFOL(fd,4) = status->hit;
  11728. break;
  11729. case SP_CRITICAL:
  11730. WFIFOL(fd,4) = status->cri/10;
  11731. break;
  11732. case SP_DEF1:
  11733. WFIFOL(fd,4) = status->def;
  11734. break;
  11735. case SP_MDEF1:
  11736. WFIFOL(fd,4) = status->mdef;
  11737. break;
  11738. case SP_MERCFLEE:
  11739. WFIFOL(fd,4) = status->flee;
  11740. break;
  11741. case SP_ASPD:
  11742. WFIFOL(fd,4) = status->amotion;
  11743. break;
  11744. case SP_HP:
  11745. WFIFOL(fd,4) = status->hp;
  11746. break;
  11747. case SP_MAXHP:
  11748. WFIFOL(fd,4) = status->max_hp;
  11749. break;
  11750. case SP_SP:
  11751. WFIFOL(fd,4) = status->sp;
  11752. break;
  11753. case SP_MAXSP:
  11754. WFIFOL(fd,4) = status->max_sp;
  11755. break;
  11756. case SP_MERCKILLS:
  11757. WFIFOL(fd,4) = md->mercenary.kill_count;
  11758. break;
  11759. case SP_MERCFAITH:
  11760. WFIFOL(fd,4) = mercenary_get_faith(md);
  11761. break;
  11762. }
  11763. WFIFOSET(fd,8);
  11764. }
  11765. void clif_mercenary_info(struct map_session_data *sd)
  11766. {
  11767. int fd;
  11768. struct mercenary_data *md;
  11769. struct status_data *status;
  11770. int atk;
  11771. if( sd == NULL || (md = sd->md) == NULL )
  11772. return;
  11773. fd = sd->fd;
  11774. status = &md->battle_status;
  11775. WFIFOHEAD(fd,80);
  11776. WFIFOW(fd,0) = 0x029b;
  11777. WFIFOL(fd,2) = md->bl.id;
  11778. // Mercenary shows ATK as a random value between ATK ~ ATK2
  11779. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11780. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  11781. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  11782. WFIFOW(fd,10) = status->hit;
  11783. WFIFOW(fd,12) = status->cri/10;
  11784. WFIFOW(fd,14) = status->def;
  11785. WFIFOW(fd,16) = status->mdef;
  11786. WFIFOW(fd,18) = status->flee;
  11787. WFIFOW(fd,20) = status->amotion;
  11788. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  11789. WFIFOW(fd,46) = md->db->lv;
  11790. WFIFOL(fd,48) = status->hp;
  11791. WFIFOL(fd,52) = status->max_hp;
  11792. WFIFOL(fd,56) = status->sp;
  11793. WFIFOL(fd,60) = status->max_sp;
  11794. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  11795. WFIFOW(fd,68) = mercenary_get_faith(md);
  11796. WFIFOL(fd,70) = mercenary_get_calls(md);
  11797. WFIFOL(fd,74) = md->mercenary.kill_count;
  11798. WFIFOW(fd,78) = md->battle_status.rhw.range;
  11799. WFIFOSET(fd,80);
  11800. }
  11801. void clif_mercenary_skillblock(struct map_session_data *sd)
  11802. {
  11803. struct mercenary_data *md;
  11804. int fd, i, len = 4, id, j;
  11805. if( sd == NULL || (md = sd->md) == NULL )
  11806. return;
  11807. fd = sd->fd;
  11808. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  11809. WFIFOW(fd,0) = 0x029d;
  11810. for( i = 0; i < MAX_MERCSKILL; i++ )
  11811. {
  11812. if( (id = md->db->skill[i].id) == 0 )
  11813. continue;
  11814. j = id - MC_SKILLBASE;
  11815. WFIFOW(fd,len) = id;
  11816. WFIFOW(fd,len+2) = skill_get_inf(id);
  11817. WFIFOW(fd,len+4) = 0;
  11818. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  11819. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  11820. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  11821. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  11822. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  11823. len += 37;
  11824. }
  11825. WFIFOW(fd,2) = len;
  11826. WFIFOSET(fd,len);
  11827. }
  11828. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  11829. {
  11830. int option = RFIFOB(fd,2);
  11831. if( sd->md == NULL )
  11832. return;
  11833. if( option == 2 ) merc_delete(sd->md, 2);
  11834. }
  11835. /*------------------------------------------
  11836. * Mercenary Message
  11837. * 0 = Mercenary soldier's duty hour is over.
  11838. * 1 = Your mercenary soldier has been killed.
  11839. * 2 = Your mercenary soldier has been fired.
  11840. * 3 = Your mercenary soldier has ran away.
  11841. *------------------------------------------*/
  11842. void clif_mercenary_message(struct map_session_data* sd, int message)
  11843. {
  11844. clif_msg(sd, 1266 + message);
  11845. }
  11846. /*------------------------------------------
  11847. * Rental System Messages
  11848. *------------------------------------------*/
  11849. void clif_rental_time(int fd, int nameid, int seconds)
  11850. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  11851. WFIFOHEAD(fd,8);
  11852. WFIFOW(fd,0) = 0x0298;
  11853. WFIFOW(fd,2) = nameid;
  11854. WFIFOL(fd,4) = seconds;
  11855. WFIFOSET(fd,8);
  11856. }
  11857. void clif_rental_expired(int fd, int nameid)
  11858. { // '<ItemName>' item has been deleted from the Inventory
  11859. WFIFOHEAD(fd,6);
  11860. WFIFOW(fd,0) = 0x0299;
  11861. WFIFOW(fd,2) = 0;
  11862. WFIFOW(fd,4) = nameid;
  11863. WFIFOSET(fd,6);
  11864. }
  11865. /*------------------------------------------
  11866. * Book Reading
  11867. *------------------------------------------*/
  11868. void clif_readbook(int fd, int book_id, int page)
  11869. {
  11870. WFIFOHEAD(fd,10);
  11871. WFIFOW(fd,0) = 0x0294;
  11872. WFIFOL(fd,2) = book_id;
  11873. WFIFOL(fd,6) = page;
  11874. WFIFOSET(fd,10);
  11875. }
  11876. /*------------------------------------------
  11877. * BattleGround Packets
  11878. *------------------------------------------*/
  11879. int clif_bg_hp(struct map_session_data *sd)
  11880. {
  11881. unsigned char buf[16];
  11882. #if PACKETVER < 20100126
  11883. const int cmd = 0x106;
  11884. #else
  11885. const int cmd = 0x80e;
  11886. #endif
  11887. nullpo_ret(sd);
  11888. WBUFW(buf,0)=cmd;
  11889. WBUFL(buf,2) = sd->status.account_id;
  11890. #if PACKETVER < 20100126
  11891. if( sd->battle_status.max_hp > SHRT_MAX )
  11892. { // To correctly display the %hp bar. [Skotlex]
  11893. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  11894. WBUFW(buf,8) = 100;
  11895. }
  11896. else
  11897. {
  11898. WBUFW(buf,6) = sd->battle_status.hp;
  11899. WBUFW(buf,8) = sd->battle_status.max_hp;
  11900. }
  11901. #else
  11902. WBUFL(buf,6) = sd->battle_status.hp;
  11903. WBUFL(buf,10) = sd->battle_status.max_hp;
  11904. #endif
  11905. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  11906. return 0;
  11907. }
  11908. int clif_bg_xy(struct map_session_data *sd)
  11909. {
  11910. unsigned char buf[10];
  11911. nullpo_ret(sd);
  11912. WBUFW(buf,0)=0x1eb;
  11913. WBUFL(buf,2)=sd->status.account_id;
  11914. WBUFW(buf,6)=sd->bl.x;
  11915. WBUFW(buf,8)=sd->bl.y;
  11916. clif_send(buf, packet_len(0x1eb), &sd->bl, BG_SAMEMAP_WOS);
  11917. return 0;
  11918. }
  11919. int clif_bg_xy_remove(struct map_session_data *sd)
  11920. {
  11921. unsigned char buf[10];
  11922. nullpo_ret(sd);
  11923. WBUFW(buf,0)=0x1eb;
  11924. WBUFL(buf,2)=sd->status.account_id;
  11925. WBUFW(buf,6)=-1;
  11926. WBUFW(buf,8)=-1;
  11927. clif_send(buf,packet_len(0x1eb),&sd->bl,BG_SAMEMAP_WOS);
  11928. return 0;
  11929. }
  11930. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT)
  11931. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  11932. int clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  11933. {
  11934. struct map_session_data *sd;
  11935. unsigned char *buf;
  11936. if( (sd = bg_getavailablesd(bg)) == NULL )
  11937. return 0;
  11938. buf = (unsigned char*)aMallocA((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  11939. WBUFW(buf,0) = 0x2dc;
  11940. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  11941. WBUFL(buf,4) = src_id;
  11942. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  11943. memcpy(WBUFP(buf,32), mes, len);
  11944. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  11945. if( buf ) aFree(buf);
  11946. return 0;
  11947. }
  11948. /*==========================================
  11949. * Validates and processes battlechat messages [pakpil]
  11950. * S 0x2db <packet len>.w <text>.?B (<name> : <message>) 00
  11951. *------------------------------------------*/
  11952. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  11953. {
  11954. const char* text = (char*)RFIFOP(fd,4);
  11955. int textlen = RFIFOW(fd,2) - 4;
  11956. char *name, *message;
  11957. int namelen, messagelen;
  11958. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11959. return;
  11960. if( is_atcommand(fd, sd, message, 1) )
  11961. return;
  11962. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  11963. return;
  11964. if( battle_config.min_chat_delay )
  11965. {
  11966. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  11967. return;
  11968. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11969. }
  11970. bg_send_message(sd, text, textlen);
  11971. }
  11972. int clif_bg_updatescore(int m)
  11973. {
  11974. struct block_list bl;
  11975. unsigned char buf[6];
  11976. bl.id = 0;
  11977. bl.type = BL_NUL;
  11978. bl.m = m;
  11979. WBUFW(buf,0) = 0x2de;
  11980. WBUFW(buf,2) = map[m].bgscore_lion;
  11981. WBUFW(buf,4) = map[m].bgscore_eagle;
  11982. clif_send(buf,6,&bl,ALL_SAMEMAP);
  11983. return 0;
  11984. }
  11985. int clif_bg_updatescore_single(struct map_session_data *sd)
  11986. {
  11987. int fd;
  11988. nullpo_ret(sd);
  11989. fd = sd->fd;
  11990. WFIFOHEAD(fd,6);
  11991. WFIFOW(fd,0) = 0x2de;
  11992. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  11993. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  11994. WFIFOSET(fd,6);
  11995. return 0;
  11996. }
  11997. int clif_sendbgemblem_area(struct map_session_data *sd)
  11998. {
  11999. unsigned char buf[33];
  12000. nullpo_ret(sd);
  12001. WBUFW(buf, 0) = 0x2dd;
  12002. WBUFL(buf,2) = sd->bl.id;
  12003. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12004. WBUFW(buf,30) = sd->state.bg_id;
  12005. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12006. return 0;
  12007. }
  12008. int clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12009. {
  12010. nullpo_ret(sd);
  12011. WFIFOHEAD(fd,32);
  12012. WFIFOW(fd,0) = 0x2dd;
  12013. WFIFOL(fd,2) = sd->bl.id;
  12014. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12015. WFIFOW(fd,30) = sd->state.bg_id;
  12016. WFIFOSET(fd,packet_len(0x2dd));
  12017. return 0;
  12018. }
  12019. /*==========================================
  12020. * Custom Fonts
  12021. * S 0x2ef <account_id>.l <font id>.w
  12022. *------------------------------------------*/
  12023. int clif_font(struct map_session_data *sd)
  12024. {
  12025. unsigned char buf[8];
  12026. nullpo_ret(sd);
  12027. WBUFW(buf,0) = 0x2ef;
  12028. WBUFL(buf,2) = sd->bl.id;
  12029. WBUFW(buf,6) = sd->state.user_font;
  12030. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12031. return 1;
  12032. }
  12033. /*==========================================
  12034. * Instancing Window
  12035. *------------------------------------------*/
  12036. int clif_instance(int instance_id, int type, int flag)
  12037. {
  12038. struct map_session_data *sd;
  12039. struct party_data *p;
  12040. unsigned char buf[255];
  12041. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12042. return 0;
  12043. switch( type )
  12044. {
  12045. case 1:
  12046. // S 0x2cb <Instance name>.63B <Standby Position>.W
  12047. // Required to start the instancing information window on Client
  12048. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12049. WBUFW(buf,0) = 0x02CB;
  12050. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12051. WBUFW(buf,63) = flag;
  12052. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12053. break;
  12054. case 2:
  12055. // S 0x2cc <Standby Position>.W
  12056. // To announce Instancing queue creation if no maps available
  12057. WBUFW(buf,0) = 0x02CC;
  12058. WBUFW(buf,2) = flag;
  12059. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12060. break;
  12061. case 3:
  12062. case 4:
  12063. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12064. WBUFW(buf,0) = 0x02CD;
  12065. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12066. if( type == 3 )
  12067. {
  12068. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12069. WBUFL(buf,67) = 0;
  12070. }
  12071. else
  12072. {
  12073. WBUFL(buf,63) = 0;
  12074. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12075. }
  12076. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12077. break;
  12078. case 5: // R 02CE <message ID>.L
  12079. // S 0x2ce <Message ID>.L
  12080. // 1 = The Memorial Dungeon expired; it has been destroyed
  12081. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12082. // 3 = The Memorial Dungeon has been removed.
  12083. // 4 = Just remove the window, maybe party/guild leave
  12084. WBUFW(buf,0) = 0x02CE;
  12085. WBUFL(buf,2) = flag;
  12086. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12087. break;
  12088. }
  12089. return 0;
  12090. }
  12091. void clif_instance_join(int fd, int instance_id)
  12092. {
  12093. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12094. {
  12095. WFIFOHEAD(fd,packet_len(0x02CD));
  12096. WFIFOW(fd,0) = 0x02CD;
  12097. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12098. WFIFOL(fd,63) = 0;
  12099. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12100. WFIFOSET(fd,packet_len(0x02CD));
  12101. }
  12102. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12103. {
  12104. WFIFOHEAD(fd,packet_len(0x02CD));
  12105. WFIFOW(fd,0) = 0x02CD;
  12106. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12107. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12108. WFIFOL(fd,67) = 0;
  12109. WFIFOSET(fd,packet_len(0x02CD));
  12110. }
  12111. else
  12112. {
  12113. WFIFOHEAD(fd,packet_len(0x02CB));
  12114. WFIFOW(fd,0) = 0x02CB;
  12115. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12116. WFIFOW(fd,63) = 0;
  12117. WFIFOSET(fd,packet_len(0x02CB));
  12118. }
  12119. }
  12120. void clif_instance_leave(int fd)
  12121. {
  12122. WFIFOHEAD(fd,packet_len(0x02CE));
  12123. WFIFOW(fd,0) = 0x02ce;
  12124. WFIFOL(fd,2) = 4;
  12125. WFIFOSET(fd,packet_len(0x02CE));
  12126. }
  12127. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12128. {
  12129. #if PACKETVER >= 20071002
  12130. unsigned char buf[22];
  12131. WBUFW(buf,0)=0x2b8;
  12132. WBUFL(buf,2) = sd->status.account_id;
  12133. WBUFW(buf,6) = item_data->nameid;
  12134. WBUFB(buf,8) = item_data->identify;
  12135. WBUFB(buf,9) = item_data->attribute;
  12136. WBUFB(buf,10) = item_data->refine;
  12137. WBUFW(buf,11) = item_data->card[0];
  12138. WBUFW(buf,13) = item_data->card[1];
  12139. WBUFW(buf,15) = item_data->card[2];
  12140. WBUFW(buf,17) = item_data->card[3];
  12141. //WBUFW(buf,19) = 0; // equip location? 32+2 for left/right hand, 0x8000 for 'throw' (verify this)
  12142. //WBUFB(buf,21) = 0; // item type
  12143. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12144. #endif
  12145. }
  12146. // Display gain exp
  12147. // type = 1 -> base_exp
  12148. // type = 2 -> job_exp
  12149. // flag = 0 -> normal exp gain/lost
  12150. // flag = 1 -> quest exp gain/lost
  12151. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12152. {
  12153. int fd;
  12154. nullpo_retv(sd);
  12155. fd = sd->fd;
  12156. WFIFOHEAD(fd, packet_len(0x7f6));
  12157. WFIFOW(fd,0) = 0x7f6;
  12158. WFIFOL(fd,2) = sd->bl.id;
  12159. WFIFOL(fd,6) = exp;
  12160. WFIFOW(fd,10) = type;
  12161. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12162. WFIFOSET(fd,packet_len(0x7f6));
  12163. return;
  12164. }
  12165. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12166. /// type:
  12167. /// 0: Displays 'value' for 5 seconds.
  12168. /// 1: Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12169. /// 2: Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12170. /// 3: Decremental counter (2 ticks/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12171. /// value:
  12172. /// 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).
  12173. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12174. {
  12175. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12176. WFIFOW(sd->fd,0) = 0x1b1;
  12177. WFIFOB(sd->fd,0) = type;
  12178. WFIFOL(sd->fd,0) = value;
  12179. WFIFOSET(sd->fd, packet_len(0x1b1));
  12180. }
  12181. /// Buying Store System
  12182. ///
  12183. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE)
  12184. /// 0810 <slots>.B
  12185. void clif_buyingstore_open(struct map_session_data* sd)
  12186. {
  12187. int fd = sd->fd;
  12188. WFIFOHEAD(fd,packet_len(0x810));
  12189. WFIFOW(fd,0) = 0x810;
  12190. WFIFOB(fd,2) = sd->buyingstore.slots;
  12191. WFIFOSET(fd,packet_len(0x810));
  12192. }
  12193. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE)
  12194. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12195. /// result:
  12196. /// 0 = cancel
  12197. /// 1 = open
  12198. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12199. {
  12200. const unsigned int blocksize = 8;
  12201. uint8* itemlist;
  12202. char storename[MESSAGE_SIZE];
  12203. unsigned char result;
  12204. int zenylimit;
  12205. unsigned int count, packet_len;
  12206. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12207. packet_len = RFIFOW(fd,info->pos[0]);
  12208. // TODO: Make this check global for all variable length packets.
  12209. if( packet_len < 89 )
  12210. {// minimum packet length
  12211. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12212. return;
  12213. }
  12214. zenylimit = RFIFOL(fd,info->pos[1]);
  12215. result = RFIFOL(fd,info->pos[2]);
  12216. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  12217. itemlist = RFIFOP(fd,info->pos[4]);
  12218. // so that buyingstore_create knows, how many elements it has access to
  12219. packet_len-= info->pos[4];
  12220. if( packet_len%blocksize )
  12221. {
  12222. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12223. return;
  12224. }
  12225. count = packet_len/blocksize;
  12226. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  12227. }
  12228. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER)
  12229. /// 0812 <result>.W <total weight>.L
  12230. /// result:
  12231. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  12232. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  12233. /// 8 = "No sale (purchase) information available." (0x705)
  12234. /// other = nothing
  12235. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  12236. {
  12237. int fd = sd->fd;
  12238. WFIFOHEAD(fd,packet_len(0x812));
  12239. WFIFOW(fd,0) = 0x812;
  12240. WFIFOW(fd,2) = result;
  12241. WFIFOL(fd,4) = weight;
  12242. WFIFOSET(fd,packet_len(0x812));
  12243. }
  12244. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE)
  12245. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  12246. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  12247. {
  12248. int fd = sd->fd;
  12249. unsigned int i;
  12250. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  12251. WFIFOW(fd,0) = 0x813;
  12252. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  12253. WFIFOL(fd,4) = sd->bl.id;
  12254. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  12255. for( i = 0; i < sd->buyingstore.slots; i++ )
  12256. {
  12257. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  12258. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  12259. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  12260. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  12261. }
  12262. WFIFOSET(fd,WFIFOW(fd,2));
  12263. }
  12264. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY)
  12265. /// 0814 <account id>.L <store name>.80B
  12266. void clif_buyingstore_entry(struct map_session_data* sd)
  12267. {
  12268. uint8 buf[86];
  12269. WBUFW(buf,0) = 0x814;
  12270. WBUFL(buf,2) = sd->bl.id;
  12271. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  12272. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  12273. }
  12274. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12275. {
  12276. int fd = sd->fd;
  12277. WFIFOHEAD(fd,packet_len(0x814));
  12278. WFIFOW(fd,0) = 0x814;
  12279. WFIFOL(fd,2) = pl_sd->bl.id;
  12280. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  12281. WFIFOSET(fd,packet_len(0x814));
  12282. }
  12283. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE)
  12284. /// 0815
  12285. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  12286. {
  12287. buyingstore_close(sd);
  12288. }
  12289. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY)
  12290. /// 0816 <account id>.L
  12291. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  12292. {
  12293. uint8 buf[6];
  12294. WBUFW(buf,0) = 0x816;
  12295. WBUFL(buf,2) = sd->bl.id;
  12296. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  12297. }
  12298. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  12299. {
  12300. int fd = sd->fd;
  12301. WFIFOHEAD(fd,packet_len(0x816));
  12302. WFIFOW(fd,0) = 0x816;
  12303. WFIFOL(fd,2) = pl_sd->bl.id;
  12304. WFIFOSET(fd,packet_len(0x816));
  12305. }
  12306. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE)
  12307. /// 0817 <account id>.L
  12308. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  12309. {
  12310. int account_id;
  12311. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12312. buyingstore_open(sd, account_id);
  12313. }
  12314. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE)
  12315. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  12316. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  12317. {
  12318. int fd = sd->fd;
  12319. unsigned int i;
  12320. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  12321. WFIFOW(fd,0) = 0x818;
  12322. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  12323. WFIFOL(fd,4) = pl_sd->bl.id;
  12324. WFIFOL(fd,8) = pl_sd->buyer_id;
  12325. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  12326. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  12327. {
  12328. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  12329. 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.
  12330. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  12331. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  12332. }
  12333. WFIFOSET(fd,WFIFOW(fd,2));
  12334. }
  12335. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE)
  12336. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  12337. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  12338. {
  12339. const unsigned int blocksize = 6;
  12340. uint8* itemlist;
  12341. int account_id;
  12342. unsigned int count, packet_len, buyer_id;
  12343. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12344. packet_len = RFIFOW(fd,info->pos[0]);
  12345. if( packet_len < 12 )
  12346. {// minimum packet length
  12347. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  12348. return;
  12349. }
  12350. account_id = RFIFOL(fd,info->pos[1]);
  12351. buyer_id = RFIFOL(fd,info->pos[2]);
  12352. itemlist = RFIFOP(fd,info->pos[3]);
  12353. // so that buyingstore_trade knows, how many elements it has access to
  12354. packet_len-= info->pos[3];
  12355. if( packet_len%blocksize )
  12356. {
  12357. 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);
  12358. return;
  12359. }
  12360. count = packet_len/blocksize;
  12361. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  12362. }
  12363. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER)
  12364. /// 081a <result>.W
  12365. /// result:
  12366. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  12367. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  12368. /// other = nothing
  12369. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  12370. {
  12371. int fd = sd->fd;
  12372. WFIFOHEAD(fd,packet_len(0x81a));
  12373. WFIFOW(fd,0) = 0x81a;
  12374. WFIFOW(fd,2) = result;
  12375. WFIFOSET(fd,packet_len(0x81a));
  12376. }
  12377. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  12378. /// 081b <name id>.W <amount>.W <limit zeny>.L
  12379. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  12380. {
  12381. int fd = sd->fd;
  12382. WFIFOHEAD(fd,packet_len(0x81b));
  12383. WFIFOW(fd,0) = 0x81b;
  12384. WFIFOW(fd,2) = nameid;
  12385. WFIFOW(fd,4) = amount; // amount of nameid received
  12386. WFIFOW(fd,6) = sd->buyingstore.zenylimit;
  12387. WFIFOSET(fd,packet_len(0x81b));
  12388. }
  12389. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE)
  12390. /// 081c <index>.W <amount>.W <price>.L
  12391. /// message:
  12392. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  12393. ///
  12394. /// @note This function has to be called _instead_ of clif_delitem/clif_dropitem.
  12395. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  12396. {
  12397. int fd = sd->fd;
  12398. WFIFOHEAD(fd,packet_len(0x81c));
  12399. WFIFOW(fd,0) = 0x81c;
  12400. WFIFOW(fd,2) = index+2;
  12401. WFIFOW(fd,4) = amount;
  12402. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  12403. WFIFOSET(fd,packet_len(0x81c));
  12404. }
  12405. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER)
  12406. /// 0824 <result>.W <name id>.W
  12407. /// result:
  12408. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  12409. /// 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)
  12410. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  12411. /// other = nothing
  12412. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  12413. {
  12414. int fd = sd->fd;
  12415. WFIFOHEAD(fd,packet_len(0x824));
  12416. WFIFOW(fd,0) = 0x824;
  12417. WFIFOW(fd,2) = result;
  12418. WFIFOW(fd,4) = nameid;
  12419. WFIFOSET(fd,packet_len(0x824));
  12420. }
  12421. /// Search Store Info System
  12422. ///
  12423. /// Request to search for stores (CZ_SEARCH_STORE_INFO)
  12424. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  12425. /// type:
  12426. /// 0 = Vending
  12427. /// 1 = Buying Store
  12428. ///
  12429. /// @note The client determines the item ids by specifying a name and optionally,
  12430. /// amount of card slots. If the client does not know about the item it
  12431. /// cannot be searched.
  12432. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  12433. {
  12434. const unsigned int blocksize = 2;
  12435. const uint8* itemlist;
  12436. const uint8* cardlist;
  12437. unsigned char type;
  12438. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  12439. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12440. packet_len = RFIFOW(fd,info->pos[0]);
  12441. if( packet_len < 15 )
  12442. {// minimum packet length
  12443. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  12444. return;
  12445. }
  12446. type = RFIFOB(fd,info->pos[1]);
  12447. max_price = RFIFOL(fd,info->pos[2]);
  12448. min_price = RFIFOL(fd,info->pos[3]);
  12449. item_count = RFIFOB(fd,info->pos[4]);
  12450. card_count = RFIFOB(fd,info->pos[5]);
  12451. itemlist = RFIFOP(fd,info->pos[6]);
  12452. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  12453. // check, if there is enough data for the claimed count of items
  12454. packet_len-= info->pos[6];
  12455. if( packet_len%blocksize )
  12456. {
  12457. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  12458. return;
  12459. }
  12460. count = packet_len/blocksize;
  12461. if( count < item_count+card_count )
  12462. {
  12463. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  12464. return;
  12465. }
  12466. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  12467. }
  12468. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK)
  12469. /// 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 }*
  12470. /// is first page:
  12471. /// 0 = appends to existing results
  12472. /// 1 = clears previous results before displaying this result set
  12473. /// is next page:
  12474. /// 0 = no "next" label
  12475. /// 1 = "next" label to retrieve more results
  12476. void clif_search_store_info_ack(struct map_session_data* sd)
  12477. {
  12478. const unsigned int blocksize = MESSAGE_SIZE+26;
  12479. int fd = sd->fd;
  12480. unsigned int i, start, end;
  12481. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  12482. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  12483. WFIFOHEAD(fd,7+(end-start)*blocksize);
  12484. WFIFOW(fd,0) = 0x836;
  12485. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  12486. WFIFOB(fd,4) = !sd->searchstore.pages;
  12487. WFIFOB(fd,5) = searchstore_querynext(sd);
  12488. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UCHAR_MAX);
  12489. for( i = start; i < end; i++ )
  12490. {
  12491. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  12492. struct item it;
  12493. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  12494. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  12495. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  12496. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  12497. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  12498. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  12499. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  12500. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  12501. // make-up an item for clif_addcards
  12502. memset(&it, 0, sizeof(it));
  12503. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  12504. it.nameid = ssitem->nameid;
  12505. it.amount = ssitem->amount;
  12506. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  12507. }
  12508. WFIFOSET(fd,WFIFOW(fd,2));
  12509. }
  12510. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED)
  12511. /// 0837 <reason>.B
  12512. /// reason:
  12513. /// 0 = "No matching stores were found." (0x70b)
  12514. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  12515. /// 2 = "You cannot search anymore." (0x706)
  12516. /// 3 = "You cannot search yet." (0x708)
  12517. /// 4 = "No sale (purchase) information available." (0x705)
  12518. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  12519. {
  12520. int fd = sd->fd;
  12521. WFIFOHEAD(fd,packet_len(0x837));
  12522. WFIFOW(fd,0) = 0x837;
  12523. WFIFOB(fd,2) = reason;
  12524. WFIFOSET(fd,packet_len(0x837));
  12525. }
  12526. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE)
  12527. /// 0838
  12528. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  12529. {
  12530. searchstore_next(sd);
  12531. }
  12532. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO)
  12533. /// 083a <type>.W <remaining uses>.B
  12534. /// type:
  12535. /// 0 = Search Stores
  12536. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  12537. void clif_open_search_store_info(struct map_session_data* sd)
  12538. {
  12539. int fd = sd->fd;
  12540. WFIFOHEAD(fd,packet_len(0x83a));
  12541. WFIFOW(fd,0) = 0x83a;
  12542. WFIFOW(fd,2) = sd->searchstore.effect;
  12543. #if PACKETVER > 20100701
  12544. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UCHAR_MAX);
  12545. #endif
  12546. WFIFOSET(fd,packet_len(0x83a));
  12547. }
  12548. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO)
  12549. /// 083b
  12550. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  12551. {
  12552. searchstore_close(sd);
  12553. }
  12554. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK)
  12555. /// 083c <account id>.L <store id>.L <nameid>.W
  12556. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  12557. {
  12558. unsigned short nameid;
  12559. int account_id, store_id;
  12560. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12561. account_id = RFIFOL(fd,info->pos[0]);
  12562. store_id = RFIFOL(fd,info->pos[1]);
  12563. nameid = RFIFOW(fd,info->pos[2]);
  12564. searchstore_click(sd, account_id, store_id, nameid);
  12565. }
  12566. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK)
  12567. /// 083d <xPos>.W <yPos>.W
  12568. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  12569. {
  12570. int fd = sd->fd;
  12571. WFIFOHEAD(fd,packet_len(0x83d));
  12572. WFIFOW(fd,0) = 0x83d;
  12573. WFIFOW(fd,2) = x;
  12574. WFIFOW(fd,4) = y;
  12575. WFIFOSET(fd,packet_len(0x83d));
  12576. }
  12577. /// Parse function for packet debugging
  12578. void clif_parse_debug(int fd,struct map_session_data *sd)
  12579. {
  12580. int cmd, packet_len;
  12581. // clif_parse ensures, that there is at least 2 bytes of data
  12582. cmd = RFIFOW(fd,0);
  12583. if( sd )
  12584. {
  12585. packet_len = packet_db[sd->packet_ver][cmd].len;
  12586. if( packet_len == 0 )
  12587. {// unknown
  12588. packet_len = RFIFOREST(fd);
  12589. }
  12590. else if( packet_len == -1 )
  12591. {// variable length
  12592. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  12593. }
  12594. 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);
  12595. }
  12596. else
  12597. {
  12598. packet_len = RFIFOREST(fd);
  12599. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  12600. }
  12601. ShowDump(RFIFOP(fd,0), packet_len);
  12602. }
  12603. /*==========================================
  12604. * Main client packet processing function
  12605. *------------------------------------------*/
  12606. int clif_parse(int fd)
  12607. {
  12608. int cmd, packet_ver, packet_len, err;
  12609. TBL_PC* sd;
  12610. int pnum;
  12611. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  12612. // Note: "click masters" can do 80+ clicks in 10 seconds
  12613. 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]
  12614. { // begin main client packet processing loop
  12615. sd = (TBL_PC *)session[fd]->session_data;
  12616. if (session[fd]->flag.eof) {
  12617. if (sd) {
  12618. if (sd->state.autotrade) {
  12619. //Disassociate character from the socket connection.
  12620. session[fd]->session_data = NULL;
  12621. sd->fd = 0;
  12622. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  12623. } else
  12624. if (sd->state.active) {
  12625. // Player logout display [Valaris]
  12626. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  12627. clif_quitsave(fd, sd);
  12628. } else {
  12629. //Unusual logout (during log on/off/map-changer procedure)
  12630. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  12631. map_quit(sd);
  12632. }
  12633. } else {
  12634. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  12635. }
  12636. do_close(fd);
  12637. return 0;
  12638. }
  12639. if (RFIFOREST(fd) < 2)
  12640. return 0;
  12641. cmd = RFIFOW(fd,0);
  12642. // identify client's packet version
  12643. if (sd) {
  12644. packet_ver = sd->packet_ver;
  12645. } else {
  12646. // check authentification packet to know packet version
  12647. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  12648. if( err )
  12649. {// failed to identify packet version
  12650. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  12651. err == 1 ? "" :
  12652. err == 2 ? ", possibly for having an invalid account_id" :
  12653. err == 3 ? ", possibly for having an invalid char_id." :
  12654. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  12655. err == 4 ? ", possibly for having an invalid login_id1." :
  12656. err == 5 ? ", possibly for having an invalid client_tick." :
  12657. */
  12658. err == 6 ? ", possibly for having an invalid sex." :
  12659. ". ERROR invalid error code"));
  12660. WFIFOHEAD(fd,packet_len(0x6a));
  12661. WFIFOW(fd,0) = 0x6a;
  12662. WFIFOB(fd,2) = 3; // Rejected from Server
  12663. WFIFOSET(fd,packet_len(0x6a));
  12664. #ifdef DUMP_INVALID_PACKET
  12665. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  12666. #endif
  12667. RFIFOSKIP(fd, RFIFOREST(fd));
  12668. set_eof(fd);
  12669. return 0;
  12670. }
  12671. }
  12672. // filter out invalid / unsupported packets
  12673. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  12674. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  12675. #ifdef DUMP_INVALID_PACKET
  12676. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  12677. #endif
  12678. set_eof(fd);
  12679. return 0;
  12680. }
  12681. // determine real packet length
  12682. packet_len = packet_db[packet_ver][cmd].len;
  12683. if (packet_len == -1) { // variable-length packet
  12684. if (RFIFOREST(fd) < 4)
  12685. return 0;
  12686. packet_len = RFIFOW(fd,2);
  12687. if (packet_len < 4 || packet_len > 32768) {
  12688. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  12689. #ifdef DUMP_INVALID_PACKET
  12690. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  12691. #endif
  12692. set_eof(fd);
  12693. return 0;
  12694. }
  12695. }
  12696. if ((int)RFIFOREST(fd) < packet_len)
  12697. return 0; // not enough data received to form the packet
  12698. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  12699. packet_db[packet_ver][cmd].func(fd, sd);
  12700. else
  12701. if( packet_db[packet_ver][cmd].func != NULL )
  12702. {
  12703. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  12704. ; //Only valid packet when there is no session
  12705. else
  12706. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  12707. ; //Only valid packet when player is not on a map
  12708. else
  12709. if( sd && session[sd->fd]->flag.eof )
  12710. ; //No more packets accepted
  12711. else
  12712. packet_db[packet_ver][cmd].func(fd, sd);
  12713. }
  12714. #ifdef DUMP_UNKNOWN_PACKET
  12715. else
  12716. {
  12717. const char* packet_txt = "save/packet.txt";
  12718. FILE* fp;
  12719. if((fp = fopen(packet_txt, "a"))!=NULL)
  12720. {
  12721. if( sd )
  12722. {
  12723. 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);
  12724. }
  12725. else
  12726. {
  12727. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  12728. }
  12729. WriteDump(fp, RFIFOP(fd,0), packet_len);
  12730. fprintf(fp, "\n");
  12731. fclose(fp);
  12732. }
  12733. else
  12734. {
  12735. ShowError("Failed to write '%s'.\n", packet_txt);
  12736. // Dump on console instead
  12737. if( sd )
  12738. {
  12739. 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);
  12740. }
  12741. else
  12742. {
  12743. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  12744. }
  12745. ShowDump(RFIFOP(fd,0), packet_len);
  12746. }
  12747. }
  12748. #endif
  12749. RFIFOSKIP(fd, packet_len);
  12750. }; // main loop end
  12751. return 0;
  12752. }
  12753. /*==========================================
  12754. * パケットデータベース読み込み
  12755. *------------------------------------------*/
  12756. static int packetdb_readdb(void)
  12757. {
  12758. FILE *fp;
  12759. char line[1024];
  12760. int ln=0;
  12761. int cmd,i,j,packet_ver;
  12762. int max_cmd=-1;
  12763. int skip_ver = 0;
  12764. int warned = 0;
  12765. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  12766. int packet_len_table[MAX_PACKET_DB] = {
  12767. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12771. //#0x0040
  12772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12774. #if PACKETVER <= 20081217
  12775. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  12776. #else
  12777. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  12778. #endif
  12779. #if PACKETVER < 2
  12780. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  12781. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  12782. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  12783. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  12784. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  12785. #else
  12786. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  12787. #endif
  12788. //#0x0080
  12789. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  12790. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  12791. #if PACKETVER <= 20100622
  12792. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  12793. #else
  12794. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  12795. #endif
  12796. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  12797. //#0x00C0
  12798. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  12799. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  12800. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  12801. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  12802. //#0x0100
  12803. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  12804. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  12805. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  12806. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  12807. //#0x0140
  12808. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  12809. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  12810. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  12811. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  12812. //#0x0180
  12813. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  12814. #if PACKETVER < 1
  12815. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  12816. #else // 196 comodo以降 状態表示アイコン用
  12817. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  12818. #endif
  12819. #if PACKETVER < 20081126
  12820. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  12821. #else // 0x1a2 changed (35->37)
  12822. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  12823. #endif
  12824. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  12825. //#0x01C0, Set 0x1d5=-1
  12826. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  12827. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  12828. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  12829. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  12830. //#0x0200
  12831. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  12832. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  12833. #if PACKETVER < 20071106
  12834. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  12835. #else // 0x22c changed
  12836. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  12837. #endif
  12838. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, -1, -1, 4, 2,
  12839. //#0x0240
  12840. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  12841. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, -1, 4, 0,
  12842. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12843. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12844. //#0x0280
  12845. 0, 0, 0, 6, 0, 0, 0, 0, 0, 12, 18, 0, 0, 0, 0, 0,
  12846. 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12848. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
  12849. //#0x02C0
  12850. 0, 0, 0, 0, 0, 30, 0, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  12851. 0, 0, 0, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 0,
  12852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 59, 60, 8,
  12853. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12854. //#0x0300
  12855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12859. //#0x0340
  12860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12864. //#0x0380
  12865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12869. //#0x03C0
  12870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12874. //#0x0400
  12875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  12879. //#0x0440
  12880. 0, 4, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12884. //#0x0480
  12885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12889. //#0x04C0
  12890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12894. //#0x0500
  12895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12899. //#0x0540
  12900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12904. //#0x0580
  12905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12909. //#0x05C0
  12910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12914. //#0x0600
  12915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12919. //#0x0640
  12920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12924. //#0x0680
  12925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12929. //#0x06C0
  12930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12934. //#0x0700
  12935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12939. //#0x0740
  12940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12944. //#0x0780
  12945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12949. //#0x07C0
  12950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12951. #if PACKETVER < 20090617
  12952. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  12953. #else // 0x7d9 changed
  12954. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  12955. #endif
  12956. 0, 0, 0, 0, 0, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  12957. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 0, 0, 0, 26, 0,
  12958. //#0x0800
  12959. #if PACKETVER < 20091229
  12960. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  12961. #else // for Party booking ( PACKETVER >= 20091229 )
  12962. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  12963. #endif
  12964. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  12965. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12966. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  12967. };
  12968. struct {
  12969. void (*func)(int, struct map_session_data *);
  12970. char *name;
  12971. } clif_parse_func[]={
  12972. {clif_parse_WantToConnection,"wanttoconnection"},
  12973. {clif_parse_LoadEndAck,"loadendack"},
  12974. {clif_parse_TickSend,"ticksend"},
  12975. {clif_parse_WalkToXY,"walktoxy"},
  12976. {clif_parse_QuitGame,"quitgame"},
  12977. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  12978. {clif_parse_GlobalMessage,"globalmessage"},
  12979. {clif_parse_MapMove,"mapmove"},
  12980. {clif_parse_ChangeDir,"changedir"},
  12981. {clif_parse_Emotion,"emotion"},
  12982. {clif_parse_HowManyConnections,"howmanyconnections"},
  12983. {clif_parse_ActionRequest,"actionrequest"},
  12984. {clif_parse_Restart,"restart"},
  12985. {clif_parse_WisMessage,"wis"},
  12986. {clif_parse_Broadcast,"broadcast"},
  12987. {clif_parse_TakeItem,"takeitem"},
  12988. {clif_parse_DropItem,"dropitem"},
  12989. {clif_parse_UseItem,"useitem"},
  12990. {clif_parse_EquipItem,"equipitem"},
  12991. {clif_parse_UnequipItem,"unequipitem"},
  12992. {clif_parse_NpcClicked,"npcclicked"},
  12993. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  12994. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  12995. {clif_parse_NpcSellListSend,"npcselllistsend"},
  12996. {clif_parse_CreateChatRoom,"createchatroom"},
  12997. {clif_parse_ChatAddMember,"chataddmember"},
  12998. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  12999. {clif_parse_ChangeChatOwner,"changechatowner"},
  13000. {clif_parse_KickFromChat,"kickfromchat"},
  13001. {clif_parse_ChatLeave,"chatleave"},
  13002. {clif_parse_TradeRequest,"traderequest"},
  13003. {clif_parse_TradeAck,"tradeack"},
  13004. {clif_parse_TradeAddItem,"tradeadditem"},
  13005. {clif_parse_TradeOk,"tradeok"},
  13006. {clif_parse_TradeCancel,"tradecancel"},
  13007. {clif_parse_TradeCommit,"tradecommit"},
  13008. {clif_parse_StopAttack,"stopattack"},
  13009. {clif_parse_PutItemToCart,"putitemtocart"},
  13010. {clif_parse_GetItemFromCart,"getitemfromcart"},
  13011. {clif_parse_RemoveOption,"removeoption"},
  13012. {clif_parse_ChangeCart,"changecart"},
  13013. {clif_parse_StatusUp,"statusup"},
  13014. {clif_parse_SkillUp,"skillup"},
  13015. {clif_parse_UseSkillToId,"useskilltoid"},
  13016. {clif_parse_UseSkillToPos,"useskilltopos"},
  13017. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  13018. {clif_parse_UseSkillMap,"useskillmap"},
  13019. {clif_parse_RequestMemo,"requestmemo"},
  13020. {clif_parse_ProduceMix,"producemix"},
  13021. {clif_parse_Cooking,"cooking"},
  13022. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  13023. {clif_parse_NpcNextClicked,"npcnextclicked"},
  13024. {clif_parse_NpcAmountInput,"npcamountinput"},
  13025. {clif_parse_NpcStringInput,"npcstringinput"},
  13026. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  13027. {clif_parse_ItemIdentify,"itemidentify"},
  13028. {clif_parse_SelectArrow,"selectarrow"},
  13029. {clif_parse_AutoSpell,"autospell"},
  13030. {clif_parse_UseCard,"usecard"},
  13031. {clif_parse_InsertCard,"insertcard"},
  13032. {clif_parse_RepairItem,"repairitem"},
  13033. {clif_parse_WeaponRefine,"weaponrefine"},
  13034. {clif_parse_SolveCharName,"solvecharname"},
  13035. {clif_parse_ResetChar,"resetchar"},
  13036. {clif_parse_LocalBroadcast,"localbroadcast"},
  13037. {clif_parse_MoveToKafra,"movetokafra"},
  13038. {clif_parse_MoveFromKafra,"movefromkafra"},
  13039. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  13040. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  13041. {clif_parse_CloseKafra,"closekafra"},
  13042. {clif_parse_CreateParty,"createparty"},
  13043. {clif_parse_CreateParty2,"createparty2"},
  13044. {clif_parse_PartyInvite,"partyinvite"},
  13045. {clif_parse_PartyInvite2,"partyinvite2"},
  13046. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  13047. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  13048. {clif_parse_LeaveParty,"leaveparty"},
  13049. {clif_parse_RemovePartyMember,"removepartymember"},
  13050. {clif_parse_PartyChangeOption,"partychangeoption"},
  13051. {clif_parse_PartyMessage,"partymessage"},
  13052. {clif_parse_PartyChangeLeader,"partychangeleader"},
  13053. {clif_parse_CloseVending,"closevending"},
  13054. {clif_parse_VendingListReq,"vendinglistreq"},
  13055. {clif_parse_PurchaseReq,"purchasereq"},
  13056. {clif_parse_PurchaseReq2,"purchasereq2"},
  13057. {clif_parse_OpenVending,"openvending"},
  13058. {clif_parse_CreateGuild,"createguild"},
  13059. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  13060. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  13061. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  13062. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  13063. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  13064. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  13065. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  13066. {clif_parse_GuildInvite,"guildinvite"},
  13067. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  13068. {clif_parse_GuildLeave,"guildleave"},
  13069. {clif_parse_GuildExpulsion,"guildexpulsion"},
  13070. {clif_parse_GuildMessage,"guildmessage"},
  13071. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  13072. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  13073. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  13074. {clif_parse_GuildOpposition,"guildopposition"},
  13075. {clif_parse_GuildBreak,"guildbreak"},
  13076. {clif_parse_PetMenu,"petmenu"},
  13077. {clif_parse_CatchPet,"catchpet"},
  13078. {clif_parse_SelectEgg,"selectegg"},
  13079. {clif_parse_SendEmotion,"sendemotion"},
  13080. {clif_parse_ChangePetName,"changepetname"},
  13081. {clif_parse_GMKick,"gmkick"},
  13082. {clif_parse_GMHide,"gmhide"},
  13083. {clif_parse_GMReqNoChat,"gmreqnochat"},
  13084. {clif_parse_GMReqAccountName,"gmreqaccname"},
  13085. {clif_parse_GMKickAll,"killall"},
  13086. {clif_parse_GMRecall,"recall"},
  13087. {clif_parse_GMRecall,"summon"},
  13088. {clif_parse_GM_Monster_Item,"itemmonster"},
  13089. {clif_parse_GMShift,"remove"},
  13090. {clif_parse_GMShift,"shift"},
  13091. {clif_parse_GMChangeMapType,"changemaptype"},
  13092. {clif_parse_GMRc,"rc"},
  13093. {clif_parse_GMRecall2,"recall2"},
  13094. {clif_parse_GMRemove2,"remove2"},
  13095. {clif_parse_NoviceDoriDori,"sndoridori"},
  13096. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  13097. {clif_parse_PMIgnore,"wisexin"},
  13098. {clif_parse_PMIgnoreList,"wisexlist"},
  13099. {clif_parse_PMIgnoreAll,"wisall"},
  13100. {clif_parse_FriendsListAdd,"friendslistadd"},
  13101. {clif_parse_FriendsListRemove,"friendslistremove"},
  13102. {clif_parse_FriendsListReply,"friendslistreply"},
  13103. {clif_parse_Blacksmith,"blacksmith"},
  13104. {clif_parse_Alchemist,"alchemist"},
  13105. {clif_parse_Taekwon,"taekwon"},
  13106. {clif_parse_RankingPk,"rankingpk"},
  13107. {clif_parse_FeelSaveOk,"feelsaveok"},
  13108. {clif_parse_debug,"debug"},
  13109. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  13110. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  13111. {clif_parse_HomMoveTo,"hommoveto"},
  13112. {clif_parse_HomAttack,"homattack"},
  13113. {clif_parse_HomMenu,"hommenu"},
  13114. {clif_parse_StoragePassword,"storagepassword"},
  13115. {clif_parse_Hotkey,"hotkey"},
  13116. {clif_parse_AutoRevive,"autorevive"},
  13117. {clif_parse_Check,"check"},
  13118. {clif_parse_Adopt_request,"adoptrequest"},
  13119. {clif_parse_Adopt_reply,"adoptreply"},
  13120. #ifndef TXT_ONLY
  13121. // MAIL SYSTEM
  13122. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  13123. {clif_parse_Mail_read,"mailread"},
  13124. {clif_parse_Mail_getattach,"mailgetattach"},
  13125. {clif_parse_Mail_delete,"maildelete"},
  13126. {clif_parse_Mail_return,"mailreturn"},
  13127. {clif_parse_Mail_setattach,"mailsetattach"},
  13128. {clif_parse_Mail_winopen,"mailwinopen"},
  13129. {clif_parse_Mail_send,"mailsend"},
  13130. // AUCTION SYSTEM
  13131. {clif_parse_Auction_search,"auctionsearch"},
  13132. {clif_parse_Auction_buysell,"auctionbuysell"},
  13133. {clif_parse_Auction_setitem,"auctionsetitem"},
  13134. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  13135. {clif_parse_Auction_register,"auctionregister"},
  13136. {clif_parse_Auction_cancel,"auctioncancel"},
  13137. {clif_parse_Auction_close,"auctionclose"},
  13138. {clif_parse_Auction_bid,"auctionbid"},
  13139. // Quest Log System
  13140. {clif_parse_questStateAck,"queststate"},
  13141. #endif
  13142. {clif_parse_cashshop_buy,"cashshopbuy"},
  13143. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  13144. {clif_parse_EquipTick,"equiptickbox"},
  13145. {clif_parse_BattleChat,"battlechat"},
  13146. {clif_parse_mercenary_action,"mermenu"},
  13147. {clif_parse_progressbar,"progressbar"},
  13148. #if PACKETVER >= 20091229
  13149. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  13150. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  13151. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  13152. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  13153. #endif
  13154. {clif_parse_PVPInfo,"pvpinfo"},
  13155. // Buying Store
  13156. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  13157. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  13158. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  13159. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  13160. // Store Search
  13161. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  13162. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  13163. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  13164. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  13165. {NULL,NULL}
  13166. };
  13167. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  13168. memset(packet_db,0,sizeof(packet_db));
  13169. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  13170. packet_len(i) = packet_len_table[i];
  13171. sprintf(line, "%s/packet_db.txt", db_path);
  13172. if( (fp=fopen(line,"r"))==NULL ){
  13173. ShowFatalError("can't read %s\n", line);
  13174. exit(EXIT_FAILURE);
  13175. }
  13176. clif_config.packet_db_ver = MAX_PACKET_VER;
  13177. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  13178. while( fgets(line, sizeof(line), fp) )
  13179. {
  13180. ln++;
  13181. if(line[0]=='/' && line[1]=='/')
  13182. continue;
  13183. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  13184. {
  13185. if(strcmpi(w1,"packet_ver")==0) {
  13186. int prev_ver = packet_ver;
  13187. skip_ver = 0;
  13188. packet_ver = atoi(w2);
  13189. if ( packet_ver > MAX_PACKET_VER )
  13190. { //Check to avoid overflowing. [Skotlex]
  13191. if( (warned&1) == 0 )
  13192. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  13193. warned &= 1;
  13194. skip_ver = 1;
  13195. }
  13196. else if( packet_ver < 0 )
  13197. {
  13198. if( (warned&2) == 0 )
  13199. ShowWarning("Negative packet versions are not supported.\n");
  13200. warned &= 2;
  13201. skip_ver = 1;
  13202. }
  13203. else if( packet_ver == SERVER )
  13204. {
  13205. if( (warned&4) == 0 )
  13206. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  13207. warned &= 4;
  13208. skip_ver = 1;
  13209. }
  13210. if( skip_ver )
  13211. {
  13212. ShowWarning("Skipping packet version %d.\n", packet_ver);
  13213. packet_ver = prev_ver;
  13214. continue;
  13215. }
  13216. // copy from previous version into new version and continue
  13217. // - indicating all following packets should be read into the newer version
  13218. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  13219. continue;
  13220. } else if(strcmpi(w1,"packet_db_ver")==0) {
  13221. if(strcmpi(w2,"default")==0) //This is the preferred version.
  13222. clif_config.packet_db_ver = MAX_PACKET_VER;
  13223. else // to manually set the packet DB version
  13224. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  13225. continue;
  13226. }
  13227. }
  13228. if( skip_ver != 0 )
  13229. continue; // Skipping current packet version
  13230. memset(str,0,sizeof(str));
  13231. for(j=0,p=line;j<4 && p; ++j)
  13232. {
  13233. str[j]=p;
  13234. p=strchr(p,',');
  13235. if(p) *p++=0;
  13236. }
  13237. if(str[0]==NULL)
  13238. continue;
  13239. cmd=strtol(str[0],(char **)NULL,0);
  13240. if(max_cmd < cmd)
  13241. max_cmd = cmd;
  13242. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  13243. continue;
  13244. if(str[1]==NULL){
  13245. ShowError("packet_db: packet len error\n");
  13246. continue;
  13247. }
  13248. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  13249. if(str[2]==NULL){
  13250. packet_db[packet_ver][cmd].func = NULL;
  13251. ln++;
  13252. continue;
  13253. }
  13254. // look up processing function by name
  13255. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  13256. if( j < ARRAYLENGTH(clif_parse_func) )
  13257. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  13258. // set the identifying cmd for the packet_db version
  13259. if (strcmp(str[2],"wanttoconnection")==0)
  13260. clif_config.connect_cmd[packet_ver] = cmd;
  13261. if(str[3]==NULL){
  13262. ShowError("packet_db: packet error\n");
  13263. exit(EXIT_FAILURE);
  13264. }
  13265. for(j=0,p2=str[3];p2;j++){
  13266. short k;
  13267. str2[j]=p2;
  13268. p2=strchr(p2,':');
  13269. if(p2) *p2++=0;
  13270. k = atoi(str2[j]);
  13271. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  13272. packet_db[packet_ver][cmd].pos[j] = k;
  13273. }
  13274. }
  13275. fclose(fp);
  13276. if(max_cmd > MAX_PACKET_DB)
  13277. {
  13278. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  13279. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  13280. }
  13281. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  13282. { //Locate the nearest version that we still support. [Skotlex]
  13283. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  13284. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  13285. }
  13286. 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);
  13287. return 0;
  13288. }
  13289. /*==========================================
  13290. *
  13291. *------------------------------------------*/
  13292. int do_init_clif(void)
  13293. {
  13294. clif_config.packet_db_ver = -1; // the main packet version of the DB
  13295. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  13296. memset(packet_db,0,sizeof(packet_db));
  13297. //Using the packet_db file is the only way to set up packets now [Skotlex]
  13298. packetdb_readdb();
  13299. set_defaultparse(clif_parse);
  13300. if( make_listen_bind(bind_ip,map_port) == -1 )
  13301. {
  13302. ShowFatalError("can't bind game port\n");
  13303. exit(EXIT_FAILURE);
  13304. }
  13305. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  13306. add_timer_func_list(clif_delayquit, "clif_delayquit");
  13307. return 0;
  13308. }