clif.c 352 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280
  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 "mob.h"
  27. #include "party.h"
  28. #include "unit.h"
  29. #include "guild.h"
  30. #include "vending.h"
  31. #include "pet.h"
  32. #include "homunculus.h"
  33. #include "mercenary.h"
  34. #include "log.h"
  35. #include "clif.h"
  36. #include "mail.h"
  37. #include "quest.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To idenfity disguised characters.
  74. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  75. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  76. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  77. static char map_ip_str[128];
  78. static uint32 map_ip;
  79. static uint32 bind_ip = INADDR_ANY;
  80. static uint16 map_port = 5121;
  81. int map_fd;
  82. int clif_parse (int fd);
  83. /*==========================================
  84. * map鯖のip設定
  85. *------------------------------------------*/
  86. int clif_setip(const char* ip)
  87. {
  88. char ip_str[16];
  89. map_ip = host2ip(ip);
  90. if (!map_ip) {
  91. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  92. return 0;
  93. }
  94. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  95. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  96. return 1;
  97. }
  98. void clif_setbindip(const char* ip)
  99. {
  100. char ip_str[16];
  101. bind_ip = host2ip(ip);
  102. if (bind_ip) {
  103. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  104. } else {
  105. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  106. }
  107. }
  108. /*==========================================
  109. * map鯖のport設定
  110. *------------------------------------------*/
  111. void clif_setport(uint16 port)
  112. {
  113. map_port = port;
  114. }
  115. /*==========================================
  116. * map鯖のip読み出し
  117. *------------------------------------------*/
  118. uint32 clif_getip(void)
  119. {
  120. return map_ip;
  121. }
  122. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  123. uint32 clif_refresh_ip(void)
  124. {
  125. uint32 new_ip;
  126. new_ip = host2ip(map_ip_str);
  127. if (new_ip && new_ip != map_ip) {
  128. map_ip = new_ip;
  129. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  130. return map_ip;
  131. }
  132. return 0;
  133. }
  134. /*==========================================
  135. * map鯖のport読み出し
  136. *------------------------------------------*/
  137. uint16 clif_getport(void)
  138. {
  139. return map_port;
  140. }
  141. /*==========================================
  142. * clif_sendでAREA*指定時用
  143. *------------------------------------------*/
  144. int clif_send_sub(struct block_list *bl, va_list ap)
  145. {
  146. struct block_list *src_bl;
  147. struct map_session_data *sd;
  148. unsigned char *buf;
  149. int len, type, fd;
  150. nullpo_retr(0, bl);
  151. nullpo_retr(0, sd = (struct map_session_data *)bl);
  152. fd = sd->fd;
  153. if (!fd) //Don't send to disconnected clients.
  154. return 0;
  155. buf = va_arg(ap,unsigned char*);
  156. len = va_arg(ap,int);
  157. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  158. type = va_arg(ap,int);
  159. switch(type)
  160. {
  161. case AREA_WOS:
  162. if (bl == src_bl)
  163. return 0;
  164. break;
  165. case AREA_WOC:
  166. if (sd->chatID || bl == src_bl)
  167. return 0;
  168. break;
  169. case AREA_WOSC:
  170. {
  171. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  172. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  173. return 0;
  174. }
  175. break;
  176. }
  177. if (session[fd] == NULL)
  178. return 0;
  179. WFIFOHEAD(fd, len);
  180. if (WFIFOP(fd,0) == buf) {
  181. ShowError("WARNING: Invalid use of clif_send function\n");
  182. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  183. ShowError(" Please correct your code.\n");
  184. // don't send to not move the pointer of the packet for next sessions in the loop
  185. //WFIFOSET(fd,0);//## TODO is this ok?
  186. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  187. return 0;
  188. }
  189. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  190. memcpy(WFIFOP(fd,0), buf, len);
  191. WFIFOSET(fd,len);
  192. }
  193. return 0;
  194. }
  195. /*==========================================
  196. *
  197. *------------------------------------------*/
  198. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  199. {
  200. int i;
  201. struct map_session_data *sd;
  202. struct party_data *p = NULL;
  203. struct guild *g = NULL;
  204. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  205. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  206. nullpo_retr(0, bl);
  207. sd = BL_CAST(BL_PC, bl);
  208. switch(type) {
  209. case ALL_CLIENT: //All player clients.
  210. for (i = 0; i < fd_max; i++) {
  211. if (session[i] && session[i]->func_parse == clif_parse &&
  212. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  213. sd->state.active &&
  214. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  215. { // packet must exist for the client version
  216. WFIFOHEAD(i, len);
  217. memcpy(WFIFOP(i,0), buf, len);
  218. WFIFOSET(i,len);
  219. }
  220. }
  221. break;
  222. case ALL_SAMEMAP: //All players on the same map
  223. for(i = 0; i < fd_max; i++) {
  224. if (session[i] && session[i]->func_parse == clif_parse &&
  225. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  226. sd->state.active && sd->bl.m == bl->m &&
  227. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  228. { // packet must exist for the client version
  229. WFIFOHEAD(i,len);
  230. memcpy(WFIFOP(i,0), buf, len);
  231. WFIFOSET(i,len);
  232. }
  233. }
  234. break;
  235. case AREA:
  236. case AREA_WOSC:
  237. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  238. clif_send (buf, len, bl, SELF);
  239. case AREA_WOC:
  240. case AREA_WOS:
  241. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  242. BL_PC, buf, len, bl, type);
  243. break;
  244. case AREA_CHAT_WOC:
  245. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  246. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  247. break;
  248. case CHAT:
  249. case CHAT_WOS:
  250. {
  251. struct chat_data *cd;
  252. if (sd) {
  253. cd = (struct chat_data*)map_id2bl(sd->chatID);
  254. } else if (bl->type == BL_CHAT) {
  255. cd = (struct chat_data*)bl;
  256. } else break;
  257. if (cd == NULL)
  258. break;
  259. for(i = 0; i < cd->users; i++) {
  260. if (type == CHAT_WOS && cd->usersd[i] == sd)
  261. continue;
  262. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  263. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  264. {
  265. WFIFOHEAD(fd,len);
  266. memcpy(WFIFOP(fd,0), buf, len);
  267. WFIFOSET(fd,len);
  268. }
  269. }
  270. }
  271. }
  272. break;
  273. case CHAT_MAINCHAT: //[LuzZza]
  274. for(i=1; i<fd_max; i++) {
  275. if (session[i] && session[i]->func_parse == clif_parse &&
  276. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  277. sd->state.active && sd->state.mainchat && !sd->chatID)
  278. {
  279. WFIFOHEAD(i,len);
  280. memcpy(WFIFOP(i,0), buf, len);
  281. WFIFOSET(i, len);
  282. }
  283. }
  284. break;
  285. case PARTY_AREA:
  286. case PARTY_AREA_WOS:
  287. x0 = bl->x - AREA_SIZE;
  288. y0 = bl->y - AREA_SIZE;
  289. x1 = bl->x + AREA_SIZE;
  290. y1 = bl->y + AREA_SIZE;
  291. case PARTY:
  292. case PARTY_WOS:
  293. case PARTY_SAMEMAP:
  294. case PARTY_SAMEMAP_WOS:
  295. if (sd && sd->status.party_id)
  296. p = party_search(sd->status.party_id);
  297. if (p) {
  298. for(i=0;i<MAX_PARTY;i++){
  299. if( (sd = p->data[i].sd) == NULL )
  300. continue;
  301. if( !(fd=sd->fd) )
  302. continue;
  303. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  304. continue;
  305. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  306. continue;
  307. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  308. continue;
  309. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  310. { // packet must exist for the client version
  311. WFIFOHEAD(fd,len);
  312. memcpy(WFIFOP(fd,0), buf, len);
  313. WFIFOSET(fd,len);
  314. }
  315. }
  316. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  317. break;
  318. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  319. if (session[i] && session[i]->func_parse == clif_parse &&
  320. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  321. sd->state.active && sd->partyspy == p->party.party_id &&
  322. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  323. { // packet must exist for the client version
  324. WFIFOHEAD(i,len);
  325. memcpy(WFIFOP(i,0), buf, len);
  326. WFIFOSET(i,len);
  327. }
  328. }
  329. }
  330. break;
  331. case DUEL:
  332. case DUEL_WOS:
  333. if (!sd || !sd->duel_group) break; //Invalid usage.
  334. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  335. for (i = 0; i < fd_max; i++) {
  336. if (session[i] && session[i]->func_parse == clif_parse &&
  337. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  338. sd->state.active && sd->duel_group == x0) {
  339. if (type == DUEL_WOS && bl->id == sd->bl.id)
  340. continue;
  341. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  342. WFIFOHEAD(i, len);
  343. memcpy(WFIFOP(i,0), buf, len);
  344. WFIFOSET(i,len);
  345. }
  346. }
  347. }
  348. break;
  349. case SELF:
  350. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  351. WFIFOHEAD(fd,len);
  352. memcpy(WFIFOP(fd,0), buf, len);
  353. WFIFOSET(fd,len);
  354. }
  355. break;
  356. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  357. case GUILD_AREA:
  358. case GUILD_AREA_WOS:
  359. x0 = bl->x - AREA_SIZE;
  360. y0 = bl->y - AREA_SIZE;
  361. x1 = bl->x + AREA_SIZE;
  362. y1 = bl->y + AREA_SIZE;
  363. case GUILD_SAMEMAP:
  364. case GUILD_SAMEMAP_WOS:
  365. case GUILD:
  366. case GUILD_WOS:
  367. if (sd && sd->status.guild_id)
  368. g = guild_search(sd->status.guild_id);
  369. if (g) {
  370. for(i = 0; i < g->max_member; i++) {
  371. if( (sd = g->member[i].sd) != NULL )
  372. {
  373. if( !(fd=sd->fd) )
  374. continue;
  375. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  376. continue;
  377. if( type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m )
  378. continue;
  379. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  380. continue;
  381. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  382. { // packet must exist for the client version
  383. WFIFOHEAD(fd,len);
  384. memcpy(WFIFOP(fd,0), buf, len);
  385. WFIFOSET(fd,len);
  386. }
  387. }
  388. }
  389. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  390. break;
  391. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  392. if (session[i] && session[i]->func_parse == clif_parse &&
  393. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  394. sd->state.active && sd->guildspy == g->guild_id &&
  395. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  396. { // packet must exist for the client version
  397. WFIFOHEAD(i,len);
  398. memcpy(WFIFOP(i,0), buf, len);
  399. WFIFOSET(i,len);
  400. }
  401. }
  402. }
  403. break;
  404. default:
  405. ShowError("clif_send: Unrecognized type %d\n",type);
  406. return -1;
  407. }
  408. return 0;
  409. }
  410. //
  411. // パケット作って送信
  412. //
  413. /*==========================================
  414. *
  415. *------------------------------------------*/
  416. int clif_authok(struct map_session_data *sd)
  417. {
  418. int fd;
  419. if (!sd->fd)
  420. return 0;
  421. fd = sd->fd;
  422. WFIFOHEAD(fd, packet_len(0x73));
  423. WFIFOW(fd, 0) = 0x73;
  424. WFIFOL(fd, 2) = gettick();
  425. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  426. WFIFOB(fd, 9) = 5; // ignored
  427. WFIFOB(fd,10) = 5; // ignored
  428. WFIFOSET(fd,packet_len(0x73));
  429. return 0;
  430. }
  431. /*==========================================
  432. * Authentication failed/disconnect client.
  433. *------------------------------------------
  434. * The client closes it's socket and displays a message according to type:
  435. * 1 - server closed -> MsgStringTable[4]
  436. * 2 - ID already logged in -> MsgStringTable[5]
  437. * 3 - timeout/too much lag -> MsgStringTable[241]
  438. * 4 - server full -> MsgStringTable[264]
  439. * 5 - underaged -> MsgStringTable[305]
  440. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  441. * 9 - too many connections from this ip -> MsgStringTable[529]
  442. * 10 - out of available time paid for -> MsgStringTable[530]
  443. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  444. * other - disconnected -> MsgStringTable[3]
  445. */
  446. int clif_authfail_fd(int fd, int type)
  447. {
  448. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  449. return 0;
  450. WFIFOHEAD(fd, packet_len(0x81));
  451. WFIFOW(fd,0) = 0x81;
  452. WFIFOB(fd,2) = type;
  453. WFIFOSET(fd,packet_len(0x81));
  454. set_eof(fd);
  455. return 0;
  456. }
  457. /*==========================================
  458. *
  459. *------------------------------------------*/
  460. int clif_charselectok(int id)
  461. {
  462. struct map_session_data* sd;
  463. int fd;
  464. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  465. return 1;
  466. fd = sd->fd;
  467. WFIFOHEAD(fd,packet_len(0xb3));
  468. WFIFOW(fd,0) = 0xb3;
  469. WFIFOB(fd,2) = 1;
  470. WFIFOSET(fd,packet_len(0xb3));
  471. return 0;
  472. }
  473. /*==========================================
  474. * Makes an item appear on the ground
  475. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  476. *------------------------------------------*/
  477. int clif_dropflooritem(struct flooritem_data* fitem)
  478. {
  479. uint8 buf[17];
  480. int view;
  481. nullpo_retr(0, fitem);
  482. if (fitem->item_data.nameid <= 0)
  483. return 0;
  484. WBUFW(buf, 0) = 0x9e;
  485. WBUFL(buf, 2) = fitem->bl.id;
  486. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  487. WBUFB(buf, 8) = fitem->item_data.identify;
  488. WBUFW(buf, 9) = fitem->bl.x;
  489. WBUFW(buf,11) = fitem->bl.y;
  490. WBUFB(buf,13) = fitem->subx;
  491. WBUFB(buf,14) = fitem->suby;
  492. WBUFW(buf,15) = fitem->item_data.amount;
  493. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  494. return 0;
  495. }
  496. /*==========================================
  497. *
  498. *------------------------------------------*/
  499. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  500. {
  501. unsigned char buf[16];
  502. nullpo_retr(0, fitem);
  503. WBUFW(buf,0) = 0xa1;
  504. WBUFL(buf,2) = fitem->bl.id;
  505. if (fd == 0) {
  506. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  507. } else {
  508. WFIFOHEAD(fd,packet_len(0xa1));
  509. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  510. WFIFOSET(fd,packet_len(0xa1));
  511. }
  512. return 0;
  513. }
  514. /*==========================================
  515. * make a unit (char, npc, mob, homun) disappear to one client
  516. * id : the id of the unit
  517. * type: 0 - moved out of sight
  518. * 1 - died
  519. * 2 - respawned
  520. * 3 - teleported / logged out
  521. * fd : the target client
  522. *------------------------------------------*/
  523. int clif_clearunit_single(int id, uint8 type, int fd)
  524. {
  525. WFIFOHEAD(fd, packet_len(0x80));
  526. WFIFOW(fd,0) = 0x80;
  527. WFIFOL(fd,2) = id;
  528. WFIFOB(fd,6) = type;
  529. WFIFOSET(fd, packet_len(0x80));
  530. return 0;
  531. }
  532. /*==========================================
  533. * make a unit (char, npc, mob, homun) disappear to all clients in area
  534. * type: 0 - moved out of sight
  535. * 1 - died
  536. * 2 - respawned
  537. * 3 - teleported / logged out
  538. *------------------------------------------*/
  539. int clif_clearunit_area(struct block_list* bl, uint8 type)
  540. {
  541. unsigned char buf[16];
  542. nullpo_retr(0, bl);
  543. WBUFW(buf,0) = 0x80;
  544. WBUFL(buf,2) = bl->id;
  545. WBUFB(buf,6) = type;
  546. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  547. if(disguised(bl)) {
  548. WBUFL(buf,2) = -bl->id;
  549. clif_send(buf, packet_len(0x80), bl, SELF);
  550. }
  551. return 0;
  552. }
  553. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  554. {
  555. struct block_list *bl = (struct block_list *)data;
  556. clif_clearunit_area(bl, 0);
  557. aFree(bl);
  558. return 0;
  559. }
  560. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  561. {
  562. struct block_list *tbl;
  563. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  564. memcpy (tbl, bl, sizeof (struct block_list));
  565. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  566. return 0;
  567. }
  568. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  569. {
  570. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  571. {
  572. *rhand = *lhand = 0;
  573. return;
  574. }
  575. #if PACKETVER < 4
  576. *rhand = sd->status.weapon;
  577. *lhand = sd->status.shield;
  578. #else
  579. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  580. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  581. {
  582. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  583. if (id->view_id > 0)
  584. *rhand = id->view_id;
  585. else
  586. *rhand = id->nameid;
  587. } else
  588. *rhand = 0;
  589. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  590. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  591. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  592. {
  593. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  594. if (id->view_id > 0)
  595. *lhand = id->view_id;
  596. else
  597. *lhand = id->nameid;
  598. } else
  599. *lhand = 0;
  600. #endif
  601. }
  602. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  603. static int clif_setlevel(int lv)
  604. {
  605. if( lv < battle_config.max_lv )
  606. return lv;
  607. if( lv < battle_config.aura_lv )
  608. return battle_config.max_lv - 1;
  609. return battle_config.max_lv;
  610. }
  611. /*==========================================
  612. * Prepares 'unit standing/spawning' packet
  613. *------------------------------------------*/
  614. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  615. {
  616. struct map_session_data* sd;
  617. struct status_change* sc = status_get_sc(bl);
  618. struct view_data* vd = status_get_viewdata(bl);
  619. unsigned char *buf = WBUFP(buffer,0);
  620. bool type = !pcdb_checkid(vd->class_);
  621. #if PACKETVER >= 7
  622. unsigned short offset = 0;
  623. #endif
  624. sd = BL_CAST(BL_PC, bl);
  625. if(type)
  626. WBUFW(buf,0) = spawn?0x7c:0x78;
  627. else
  628. #if PACKETVER < 4
  629. WBUFW(buf,0) = spawn?0x79:0x78;
  630. #elif PACKETVER < 7
  631. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  632. #else
  633. WBUFW(buf,0) = spawn?0x22b:0x22a;
  634. #endif
  635. #if PACKETVER >= 20071106
  636. if (type) {
  637. // shift payload 1 byte to the right for mob packets
  638. WBUFB(buf,2) = 0; // padding?
  639. offset++;
  640. buf = WBUFP(buffer,offset);
  641. }
  642. #endif
  643. WBUFL(buf, 2) = bl->id;
  644. WBUFW(buf, 6) = status_get_speed(bl);
  645. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  646. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  647. if (type&&spawn) { //uses an older and different packet structure
  648. WBUFW(buf,12) = (sc)? sc->option : 0;
  649. WBUFW(buf,14) = vd->hair_style;
  650. WBUFW(buf,16) = vd->weapon;
  651. WBUFW(buf,18) = vd->head_bottom;
  652. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  653. WBUFW(buf,22) = vd->shield;
  654. } else {
  655. #if PACKETVER >= 7
  656. if (!type) {
  657. WBUFL(buf,12) = (sc)? sc->option : 0;
  658. offset+=2;
  659. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  660. } else
  661. #endif
  662. WBUFW(buf,12) = (sc)? sc->option : 0;
  663. WBUFW(buf,14) = vd->class_;
  664. WBUFW(buf,16) = vd->hair_style;
  665. WBUFW(buf,18) = vd->weapon;
  666. #if PACKETVER < 4
  667. WBUFW(buf,20) = vd->head_bottom;
  668. WBUFW(buf,22) = vd->shield;
  669. #else
  670. WBUFW(buf,20) = vd->shield;
  671. WBUFW(buf,22) = vd->head_bottom;
  672. #endif
  673. }
  674. WBUFW(buf,24) = vd->head_top;
  675. WBUFW(buf,26) = vd->head_mid;
  676. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  677. { //The hell, why flags work like this?
  678. WBUFL(buf,22) = status_get_emblem_id(bl);
  679. WBUFL(buf,26) = status_get_guild_id(bl);
  680. }
  681. WBUFW(buf,28) = vd->hair_color;
  682. WBUFW(buf,30) = vd->cloth_color;
  683. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  684. if (type&&spawn) { //End of packet 0x7c
  685. WBUFB(buf,34) = 0; // karma
  686. WBUFB(buf,35) = vd->sex;
  687. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  688. WBUFB(buf,39) = 0;
  689. WBUFB(buf,40) = 0;
  690. return packet_len(0x7c);
  691. }
  692. WBUFL(buf,34) = status_get_guild_id(bl);
  693. WBUFW(buf,38) = status_get_emblem_id(bl);
  694. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  695. #if PACKETVER >= 7
  696. if (!type) {
  697. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  698. offset+=2;
  699. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  700. } else
  701. #endif
  702. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  703. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  704. WBUFB(buf,45) = vd->sex;
  705. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  706. WBUFB(buf,49) = (sd)? 5 : 0;
  707. WBUFB(buf,50) = (sd)? 5 : 0;
  708. if (spawn) {
  709. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  710. } else {
  711. WBUFB(buf,51) = vd->dead_sit;
  712. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  713. }
  714. return packet_len(WBUFW(buffer,0));
  715. }
  716. /*==========================================
  717. * Prepares 'unit walking' packet
  718. *------------------------------------------*/
  719. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  720. {
  721. struct map_session_data* sd;
  722. struct status_change* sc = status_get_sc(bl);
  723. struct view_data* vd = status_get_viewdata(bl);
  724. unsigned char* buf = WBUFP(buffer,0);
  725. #if PACKETVER >= 7
  726. unsigned short offset = 0;
  727. #endif
  728. sd = BL_CAST(BL_PC, bl);
  729. #if PACKETVER < 4
  730. WBUFW(buf, 0) = 0x7b;
  731. #elif PACKETVER < 7
  732. WBUFW(buf, 0) = 0x1da;
  733. #else
  734. WBUFW(buf, 0) = 0x22c;
  735. #endif
  736. #if PACKETVER >= 20071106
  737. WBUFB(buf, 2) = 0; // padding?
  738. offset++;
  739. buf = WBUFP(buf,offset);
  740. #endif
  741. WBUFL(buf, 2) = bl->id;
  742. WBUFW(buf, 6) = status_get_speed(bl);
  743. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  744. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  745. #if PACKETVER < 7
  746. WBUFW(buf,12) = (sc)? sc->option : 0;
  747. #else
  748. WBUFL(buf,12) = (sc)? sc->option : 0;
  749. offset+=2; //Shift the rest of elements by 2 bytes.
  750. buf = WBUFP(buffer,offset);
  751. #endif
  752. WBUFW(buf,14) = vd->class_;
  753. WBUFW(buf,16) = vd->hair_style;
  754. WBUFW(buf,18) = vd->weapon;
  755. #if PACKETVER < 4
  756. WBUFW(buf,20) = vd->head_bottom;
  757. WBUFL(buf,22) = gettick();
  758. WBUFW(buf,26) = vd->shield;
  759. #else
  760. WBUFW(buf,20) = vd->shield;
  761. WBUFW(buf,22) = vd->head_bottom;
  762. WBUFL(buf,24) = gettick();
  763. #endif
  764. WBUFW(buf,28) = vd->head_top;
  765. WBUFW(buf,30) = vd->head_mid;
  766. WBUFW(buf,32) = vd->hair_color;
  767. WBUFW(buf,34) = vd->cloth_color;
  768. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  769. WBUFL(buf,38) = status_get_guild_id(bl);
  770. WBUFW(buf,42) = status_get_emblem_id(bl);
  771. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  772. #if PACKETVER < 7
  773. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  774. #else
  775. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  776. offset+=2; //Shift the rest of elements by 2 bytes.
  777. buf = WBUFP(buffer,offset);
  778. #endif
  779. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  780. WBUFB(buf,49) = vd->sex;
  781. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  782. WBUFB(buf,56) = (sd)? 5 : 0;
  783. WBUFB(buf,57) = (sd)? 5 : 0;
  784. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  785. return packet_len(WBUFW(buffer,0));
  786. }
  787. //Modifies the buffer for disguise characters and sends it to self.
  788. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  789. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  790. {
  791. #if PACKETVER >= 20071106
  792. WBUFL(buf,3)=-bl->id;
  793. #else
  794. WBUFL(buf,2)=-bl->id;
  795. #endif
  796. clif_send(buf, len, bl, SELF);
  797. }
  798. /*==========================================
  799. * クラスチェンジ typeはMobの場合は1で他は0?
  800. *------------------------------------------*/
  801. int clif_class_change(struct block_list *bl,int class_,int type)
  802. {
  803. unsigned char buf[16];
  804. nullpo_retr(0, bl);
  805. if(!pcdb_checkid(class_)) {
  806. WBUFW(buf,0)=0x1b0;
  807. WBUFL(buf,2)=bl->id;
  808. WBUFB(buf,6)=type;
  809. WBUFL(buf,7)=class_;
  810. clif_send(buf,packet_len(0x1b0),bl,AREA);
  811. }
  812. return 0;
  813. }
  814. /*==========================================
  815. *
  816. *------------------------------------------*/
  817. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  818. {
  819. WFIFOHEAD(fd, packet_len(0x1e1));
  820. WFIFOW(fd,0)=0x1e1;
  821. WFIFOL(fd,2)=sd->bl.id;
  822. WFIFOW(fd,6)=sd->spiritball;
  823. WFIFOSET(fd, packet_len(0x1e1));
  824. }
  825. // new and improved weather display [Valaris]
  826. static void clif_weather_sub(int fd, int id, int type)
  827. {
  828. WFIFOHEAD(fd,packet_len(0x1f3));
  829. WFIFOW(fd,0) = 0x1f3;
  830. WFIFOL(fd,2) = id;
  831. WFIFOL(fd,6) = type;
  832. WFIFOSET(fd,packet_len(0x1f3));
  833. }
  834. /*==========================================
  835. *
  836. *------------------------------------------*/
  837. static void clif_weather_check(struct map_session_data *sd)
  838. {
  839. int m = sd->bl.m, fd = sd->fd;
  840. if (map[m].flag.snow
  841. || map[m].flag.clouds
  842. || map[m].flag.fog
  843. || map[m].flag.fireworks
  844. || map[m].flag.sakura
  845. || map[m].flag.leaves
  846. || map[m].flag.rain
  847. || map[m].flag.clouds2)
  848. {
  849. if (map[m].flag.snow)
  850. clif_weather_sub(fd, sd->bl.id, 162);
  851. if (map[m].flag.clouds)
  852. clif_weather_sub(fd, sd->bl.id, 233);
  853. if (map[m].flag.clouds2)
  854. clif_weather_sub(fd, sd->bl.id, 516);
  855. if (map[m].flag.fog)
  856. clif_weather_sub(fd, sd->bl.id, 515);
  857. if (map[m].flag.fireworks) {
  858. clif_weather_sub(fd, sd->bl.id, 297);
  859. clif_weather_sub(fd, sd->bl.id, 299);
  860. clif_weather_sub(fd, sd->bl.id, 301);
  861. }
  862. if (map[m].flag.sakura)
  863. clif_weather_sub(fd, sd->bl.id, 163);
  864. if (map[m].flag.leaves)
  865. clif_weather_sub(fd, sd->bl.id, 333);
  866. if (map[m].flag.rain)
  867. clif_weather_sub(fd, sd->bl.id, 161);
  868. }
  869. }
  870. void clif_weather(int m)
  871. {
  872. struct s_mapiterator* iter;
  873. struct map_session_data *sd=NULL;
  874. iter = mapit_getallusers();
  875. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  876. {
  877. if( sd->bl.m == m )
  878. clif_weather_check(sd);
  879. }
  880. mapit_free(iter);
  881. }
  882. int clif_spawn(struct block_list *bl)
  883. {
  884. unsigned char buf[128];
  885. struct view_data *vd;
  886. int len;
  887. vd = status_get_viewdata(bl);
  888. if( !vd || vd->class_ == INVISIBLE_CLASS )
  889. return 0;
  890. len = clif_set_unit_idle(bl, buf,true);
  891. clif_send(buf, len, bl, AREA_WOS);
  892. if (disguised(bl))
  893. clif_setdisguise(bl, buf, len);
  894. if (vd->cloth_color)
  895. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  896. switch (bl->type)
  897. {
  898. case BL_PC:
  899. {
  900. TBL_PC *sd = ((TBL_PC*)bl);
  901. if (sd->spiritball > 0)
  902. clif_spiritball(sd);
  903. if(sd->state.size==2) // tiny/big players [Valaris]
  904. clif_specialeffect(bl,423,AREA);
  905. else if(sd->state.size==1)
  906. clif_specialeffect(bl,421,AREA);
  907. }
  908. break;
  909. case BL_MOB:
  910. {
  911. TBL_MOB *md = ((TBL_MOB*)bl);
  912. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  913. clif_specialeffect(&md->bl,423,AREA);
  914. else if(md->special_state.size==1)
  915. clif_specialeffect(&md->bl,421,AREA);
  916. }
  917. break;
  918. case BL_NPC:
  919. {
  920. TBL_NPC *nd = ((TBL_NPC*)bl);
  921. if( nd->size == 2 )
  922. clif_specialeffect(&nd->bl,423,AREA);
  923. else if( nd->size == 1 )
  924. clif_specialeffect(&nd->bl,421,AREA);
  925. }
  926. break;
  927. case BL_PET:
  928. if (vd->head_bottom)
  929. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  930. break;
  931. }
  932. return 0;
  933. }
  934. //[orn]
  935. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  936. {
  937. struct status_data *status;
  938. unsigned char buf[128];
  939. nullpo_retr(0, hd);
  940. status = &hd->battle_status;
  941. memset(buf,0,packet_len(0x22e));
  942. WBUFW(buf,0)=0x22e;
  943. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  944. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  945. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  946. WBUFW(buf,27)=hd->homunculus.level;
  947. WBUFW(buf,29)=hd->homunculus.hunger;
  948. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  949. WBUFW(buf,33)=0; // equip id
  950. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  951. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  952. WBUFW(buf,39)=status->hit;
  953. if (battle_config.hom_setting&0x10)
  954. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  955. else
  956. WBUFW(buf,41)=status->cri/10;
  957. WBUFW(buf,43)=status->def + status->vit ;
  958. WBUFW(buf,45)=status->mdef;
  959. WBUFW(buf,47)=status->flee;
  960. WBUFW(buf,49)=(flag)?0:status->amotion;
  961. if (status->max_hp > SHRT_MAX) {
  962. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  963. WBUFW(buf,53) = 100;
  964. } else {
  965. WBUFW(buf,51)=status->hp;
  966. WBUFW(buf,53)=status->max_hp;
  967. }
  968. if (status->max_sp > SHRT_MAX) {
  969. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  970. WBUFW(buf,57) = 100;
  971. } else {
  972. WBUFW(buf,55)=status->sp;
  973. WBUFW(buf,57)=status->max_sp;
  974. }
  975. WBUFL(buf,59)=hd->homunculus.exp;
  976. WBUFL(buf,63)=hd->exp_next;
  977. WBUFW(buf,67)=hd->homunculus.skillpts;
  978. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  979. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  980. return 0;
  981. }
  982. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  983. { //[orn]
  984. int fd = sd->fd;
  985. WFIFOHEAD(fd, packet_len(0x230));
  986. nullpo_retv(sd->hd);
  987. WFIFOW(fd,0)=0x230;
  988. WFIFOW(fd,2)=type;
  989. WFIFOL(fd,4)=sd->hd->bl.id;
  990. WFIFOL(fd,8)=param;
  991. WFIFOSET(fd,packet_len(0x230));
  992. return;
  993. }
  994. int clif_homskillinfoblock(struct map_session_data *sd)
  995. { //[orn]
  996. struct homun_data *hd;
  997. int fd = sd->fd;
  998. int i,j,len=4,id;
  999. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1000. hd = sd->hd;
  1001. if ( !hd )
  1002. return 0 ;
  1003. WFIFOW(fd,0)=0x235;
  1004. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1005. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1006. j = id - HM_SKILLBASE;
  1007. WFIFOW(fd,len ) = id;
  1008. WFIFOW(fd,len+2) = skill_get_inf(id);
  1009. WFIFOW(fd,len+4) = 0;
  1010. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1011. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1012. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1013. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1014. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1015. len+=37;
  1016. }
  1017. }
  1018. WFIFOW(fd,2)=len;
  1019. WFIFOSET(fd,len);
  1020. return 0;
  1021. }
  1022. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1023. { //[orn]
  1024. struct homun_data *hd;
  1025. int fd=sd->fd, skillid;
  1026. WFIFOHEAD(fd, packet_len(0x239));
  1027. nullpo_retv(sd);
  1028. skillid = skill_num - HM_SKILLBASE;
  1029. hd=sd->hd;
  1030. WFIFOW(fd,0) = 0x239;
  1031. WFIFOW(fd,2) = skill_num;
  1032. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1033. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1034. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1035. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1036. WFIFOSET(fd,packet_len(0x239));
  1037. return;
  1038. }
  1039. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1040. {
  1041. int fd=sd->fd;
  1042. WFIFOHEAD(fd,packet_len(0x22f));
  1043. WFIFOW(fd,0)=0x22f;
  1044. WFIFOB(fd,2)=fail;
  1045. WFIFOW(fd,3)=foodid;
  1046. WFIFOSET(fd,packet_len(0x22f));
  1047. return 0;
  1048. }
  1049. /*==========================================
  1050. *
  1051. *------------------------------------------*/
  1052. int clif_walkok(struct map_session_data *sd)
  1053. {
  1054. int fd=sd->fd;
  1055. WFIFOHEAD(fd, packet_len(0x87));
  1056. WFIFOW(fd,0)=0x87;
  1057. WFIFOL(fd,2)=gettick();
  1058. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1059. WFIFOSET(fd,packet_len(0x87));
  1060. return 0;
  1061. }
  1062. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1063. {
  1064. uint8 buf[128];
  1065. int len;
  1066. len = clif_set_unit_walking(bl,ud,buf);
  1067. clif_send(buf,len,bl,AREA_WOS);
  1068. if (disguised(bl))
  1069. clif_setdisguise(bl, buf, len);
  1070. if(vd->cloth_color)
  1071. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1072. switch(bl->type)
  1073. {
  1074. case BL_PC:
  1075. {
  1076. TBL_PC *sd = ((TBL_PC*)bl);
  1077. // clif_movepc(sd);
  1078. if(sd->state.size==2) // tiny/big players [Valaris]
  1079. clif_specialeffect(&sd->bl,423,AREA);
  1080. else if(sd->state.size==1)
  1081. clif_specialeffect(&sd->bl,421,AREA);
  1082. }
  1083. break;
  1084. case BL_MOB:
  1085. {
  1086. TBL_MOB *md = ((TBL_MOB*)bl);
  1087. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1088. clif_specialeffect(&md->bl,423,AREA);
  1089. else if(md->special_state.size==1)
  1090. clif_specialeffect(&md->bl,421,AREA);
  1091. }
  1092. break;
  1093. }
  1094. return;
  1095. }
  1096. /// Move the unit (does nothing if the client has no info about the unit)
  1097. /// Note: unit must not be self
  1098. void clif_move(struct unit_data *ud)
  1099. {
  1100. unsigned char buf[16];
  1101. struct view_data* vd;
  1102. struct block_list* bl = ud->bl;
  1103. vd = status_get_viewdata(bl);
  1104. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1105. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1106. if (ud->state.speed_changed) {
  1107. // Since we don't know how to update the speed of other objects,
  1108. // use the old walk packet to update the data.
  1109. ud->state.speed_changed = 0;
  1110. clif_move2(bl, vd, ud);
  1111. return;
  1112. }
  1113. WBUFW(buf,0)=0x86;
  1114. WBUFL(buf,2)=bl->id;
  1115. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1116. WBUFL(buf,12)=gettick();
  1117. clif_send(buf, 16, bl, AREA_WOS);
  1118. if (disguised(bl))
  1119. {
  1120. WBUFL(buf,2)=-bl->id;
  1121. clif_send(buf, 16, bl, SELF);
  1122. }
  1123. }
  1124. /*==========================================
  1125. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1126. *------------------------------------------*/
  1127. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1128. {
  1129. struct map_session_data *sd = NULL;
  1130. //Remove player from map server
  1131. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1132. map_quit(sd);
  1133. return 0;
  1134. }
  1135. /*==========================================
  1136. *
  1137. *------------------------------------------*/
  1138. void clif_quitsave(int fd,struct map_session_data *sd)
  1139. {
  1140. if (!battle_config.prevent_logout ||
  1141. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1142. map_quit(sd);
  1143. else if (sd->fd)
  1144. { //Disassociate session from player (session is deleted after this function was called)
  1145. //And set a timer to make him quit later.
  1146. session[sd->fd]->session_data = NULL;
  1147. sd->fd = 0;
  1148. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1149. }
  1150. }
  1151. /*==========================================
  1152. *
  1153. *------------------------------------------*/
  1154. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1155. {
  1156. int fd;
  1157. nullpo_retv(sd);
  1158. fd = sd->fd;
  1159. WFIFOHEAD(fd,packet_len(0x91));
  1160. WFIFOW(fd,0) = 0x91;
  1161. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1162. WFIFOW(fd,18) = x;
  1163. WFIFOW(fd,20) = y;
  1164. WFIFOSET(fd,packet_len(0x91));
  1165. }
  1166. /*==========================================
  1167. * Tells the client to connect to another map-server
  1168. *------------------------------------------*/
  1169. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1170. {
  1171. int fd;
  1172. nullpo_retv(sd);
  1173. fd = sd->fd;
  1174. WFIFOHEAD(fd,packet_len(0x92));
  1175. WFIFOW(fd,0) = 0x92;
  1176. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1177. WFIFOW(fd,18) = x;
  1178. WFIFOW(fd,20) = y;
  1179. WFIFOL(fd,22) = htonl(ip);
  1180. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1181. WFIFOSET(fd,packet_len(0x92));
  1182. }
  1183. void clif_blown(struct block_list *bl)
  1184. {
  1185. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1186. // clif_fixpos(bl);
  1187. clif_slide(bl, bl->x, bl->y);
  1188. }
  1189. /*==========================================
  1190. *
  1191. *------------------------------------------*/
  1192. void clif_fixpos(struct block_list *bl)
  1193. {
  1194. unsigned char buf[10];
  1195. nullpo_retv(bl);
  1196. WBUFW(buf,0) = 0x88;
  1197. WBUFL(buf,2) = bl->id;
  1198. WBUFW(buf,6) = bl->x;
  1199. WBUFW(buf,8) = bl->y;
  1200. clif_send(buf, packet_len(0x88), bl, AREA);
  1201. if( disguised(bl) )
  1202. {
  1203. WBUFL(buf,2) = -bl->id;
  1204. clif_send(buf, packet_len(0x88), bl, SELF);
  1205. }
  1206. }
  1207. /*==========================================
  1208. *
  1209. *------------------------------------------*/
  1210. int clif_npcbuysell(struct map_session_data* sd, int id)
  1211. {
  1212. int fd;
  1213. nullpo_retr(0, sd);
  1214. fd=sd->fd;
  1215. WFIFOHEAD(fd, packet_len(0xc4));
  1216. WFIFOW(fd,0)=0xc4;
  1217. WFIFOL(fd,2)=id;
  1218. WFIFOSET(fd,packet_len(0xc4));
  1219. return 0;
  1220. }
  1221. /*==========================================
  1222. *
  1223. *------------------------------------------*/
  1224. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1225. {
  1226. int fd,i,c;
  1227. nullpo_retr(0, sd);
  1228. nullpo_retr(0, nd);
  1229. fd = sd->fd;
  1230. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1231. WFIFOW(fd,0) = 0xc6;
  1232. c = 0;
  1233. for( i = 0; i < nd->u.shop.count; i++ )
  1234. {
  1235. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1236. int val = nd->u.shop.shop_item[i].value;
  1237. if( id == NULL )
  1238. continue;
  1239. WFIFOL(fd, 4+c*11) = val;
  1240. if (!id->flag.value_notdc)
  1241. val = pc_modifybuyvalue(sd,val);
  1242. WFIFOL(fd, 8+c*11) = val;
  1243. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1244. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1245. c++;
  1246. }
  1247. WFIFOW(fd,2) = 4 + c*11;
  1248. WFIFOSET(fd,WFIFOW(fd,2));
  1249. return 0;
  1250. }
  1251. /*==========================================
  1252. *
  1253. *------------------------------------------*/
  1254. int clif_selllist(struct map_session_data *sd)
  1255. {
  1256. int fd,i,c=0,val;
  1257. nullpo_retr(0, sd);
  1258. fd=sd->fd;
  1259. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1260. WFIFOW(fd,0)=0xc7;
  1261. for( i = 0; i < MAX_INVENTORY; i++ )
  1262. {
  1263. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1264. {
  1265. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1266. continue;
  1267. if( sd->status.inventory[i].expire_time )
  1268. continue; // Cannot Sell Rental Items
  1269. val=sd->inventory_data[i]->value_sell;
  1270. if( val < 0 )
  1271. continue;
  1272. WFIFOW(fd,4+c*10)=i+2;
  1273. WFIFOL(fd,6+c*10)=val;
  1274. if( !sd->inventory_data[i]->flag.value_notoc )
  1275. val=pc_modifysellvalue(sd,val);
  1276. WFIFOL(fd,10+c*10)=val;
  1277. c++;
  1278. }
  1279. }
  1280. WFIFOW(fd,2)=c*10+4;
  1281. WFIFOSET(fd,WFIFOW(fd,2));
  1282. return 0;
  1283. }
  1284. /*==========================================
  1285. *
  1286. *------------------------------------------*/
  1287. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1288. {
  1289. int fd = sd->fd;
  1290. int slen = strlen(mes) + 9;
  1291. WFIFOHEAD(fd, slen);
  1292. WFIFOW(fd,0)=0xb4;
  1293. WFIFOW(fd,2)=slen;
  1294. WFIFOL(fd,4)=npcid;
  1295. strcpy((char*)WFIFOP(fd,8),mes);
  1296. WFIFOSET(fd,WFIFOW(fd,2));
  1297. return 0;
  1298. }
  1299. /*==========================================
  1300. *
  1301. *------------------------------------------*/
  1302. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1303. {
  1304. int fd;
  1305. nullpo_retr(0, sd);
  1306. fd=sd->fd;
  1307. WFIFOHEAD(fd, packet_len(0xb5));
  1308. WFIFOW(fd,0)=0xb5;
  1309. WFIFOL(fd,2)=npcid;
  1310. WFIFOSET(fd,packet_len(0xb5));
  1311. return 0;
  1312. }
  1313. /*==========================================
  1314. *
  1315. *------------------------------------------*/
  1316. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1317. {
  1318. int fd;
  1319. nullpo_retr(0, sd);
  1320. fd=sd->fd;
  1321. WFIFOHEAD(fd, packet_len(0xb6));
  1322. WFIFOW(fd,0)=0xb6;
  1323. WFIFOL(fd,2)=npcid;
  1324. WFIFOSET(fd,packet_len(0xb6));
  1325. return 0;
  1326. }
  1327. /*==========================================
  1328. *
  1329. *------------------------------------------*/
  1330. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1331. {
  1332. unsigned char *buf;
  1333. int fd = sd->fd;
  1334. sd->state.using_fake_npc = 1;
  1335. WFIFOHEAD(fd, packet_len(0x78));
  1336. buf = WFIFOP(fd,0);
  1337. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1338. WBUFW(buf,0)=0x78;
  1339. #if PACKETVER >= 20071106
  1340. WBUFB(buf,2) = 0; //Unknown bit
  1341. buf = WFIFOP(fd,1);
  1342. #endif
  1343. WBUFL(buf,2)=npcid;
  1344. WBUFW(buf,14)=111;
  1345. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1346. WBUFB(buf,49)=5;
  1347. WBUFB(buf,50)=5;
  1348. WFIFOSET(fd, packet_len(0x78));
  1349. return;
  1350. }
  1351. /*==========================================
  1352. *
  1353. *------------------------------------------*/
  1354. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1355. {
  1356. int fd = sd->fd;
  1357. int slen = strlen(mes) + 8;
  1358. struct block_list *bl = NULL;
  1359. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1360. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1361. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1362. clif_sendfakenpc(sd, npcid);
  1363. WFIFOHEAD(fd, slen);
  1364. WFIFOW(fd,0)=0xb7;
  1365. WFIFOW(fd,2)=slen;
  1366. WFIFOL(fd,4)=npcid;
  1367. strcpy((char*)WFIFOP(fd,8),mes);
  1368. WFIFOSET(fd,WFIFOW(fd,2));
  1369. return 0;
  1370. }
  1371. /*==========================================
  1372. *
  1373. *------------------------------------------*/
  1374. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1375. {
  1376. int fd;
  1377. struct block_list *bl = NULL;
  1378. nullpo_retr(0, sd);
  1379. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1380. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1381. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1382. clif_sendfakenpc(sd, npcid);
  1383. fd=sd->fd;
  1384. WFIFOHEAD(fd, packet_len(0x142));
  1385. WFIFOW(fd,0)=0x142;
  1386. WFIFOL(fd,2)=npcid;
  1387. WFIFOSET(fd,packet_len(0x142));
  1388. return 0;
  1389. }
  1390. /*==========================================
  1391. *
  1392. *------------------------------------------*/
  1393. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1394. {
  1395. int fd;
  1396. struct block_list *bl = NULL;
  1397. nullpo_retr(0, sd);
  1398. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1399. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1400. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1401. clif_sendfakenpc(sd, npcid);
  1402. fd=sd->fd;
  1403. WFIFOHEAD(fd, packet_len(0x1d4));
  1404. WFIFOW(fd,0)=0x1d4;
  1405. WFIFOL(fd,2)=npcid;
  1406. WFIFOSET(fd,packet_len(0x1d4));
  1407. return 0;
  1408. }
  1409. /// npc_id is ignored in the client
  1410. /// type=2 : Remove viewpoint
  1411. /// type=other : Show viewpoint
  1412. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1413. {
  1414. int fd;
  1415. nullpo_retr(0, sd);
  1416. fd=sd->fd;
  1417. WFIFOHEAD(fd, packet_len(0x144));
  1418. WFIFOW(fd,0)=0x144;
  1419. WFIFOL(fd,2)=npc_id;
  1420. WFIFOL(fd,6)=type;
  1421. WFIFOL(fd,10)=x;
  1422. WFIFOL(fd,14)=y;
  1423. WFIFOB(fd,18)=id;
  1424. WFIFOL(fd,19)=color;
  1425. WFIFOSET(fd,packet_len(0x144));
  1426. return 0;
  1427. }
  1428. /*==========================================
  1429. *
  1430. *------------------------------------------*/
  1431. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1432. {
  1433. int fd;
  1434. nullpo_retr(0, sd);
  1435. fd=sd->fd;
  1436. WFIFOHEAD(fd, packet_len(0x1b3));
  1437. WFIFOW(fd,0)=0x1b3;
  1438. strncpy((char*)WFIFOP(fd,2),image,64);
  1439. WFIFOB(fd,66)=type;
  1440. WFIFOSET(fd,packet_len(0x1b3));
  1441. return 0;
  1442. }
  1443. /*==========================================
  1444. * Fills in card data from the given item and into the buffer. [Skotlex]
  1445. *------------------------------------------*/
  1446. static void clif_addcards(unsigned char* buf, struct item* item)
  1447. {
  1448. int i=0,j;
  1449. if( item == NULL ) { //Blank data
  1450. WBUFW(buf,0) = 0;
  1451. WBUFW(buf,2) = 0;
  1452. WBUFW(buf,4) = 0;
  1453. WBUFW(buf,6) = 0;
  1454. return;
  1455. }
  1456. if( item->card[0] == CARD0_PET ) { //pet eggs
  1457. WBUFW(buf,0) = 0;
  1458. WBUFW(buf,2) = 0;
  1459. WBUFW(buf,4) = 0;
  1460. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1461. return;
  1462. }
  1463. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1464. WBUFW(buf,0) = item->card[0];
  1465. WBUFW(buf,2) = item->card[1];
  1466. WBUFW(buf,4) = item->card[2];
  1467. WBUFW(buf,6) = item->card[3];
  1468. return;
  1469. }
  1470. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1471. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1472. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1473. //Normal items.
  1474. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1475. WBUFW(buf,0) = j;
  1476. else
  1477. WBUFW(buf,0) = item->card[i];
  1478. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1479. WBUFW(buf,2) = j;
  1480. else
  1481. WBUFW(buf,2) = item->card[i];
  1482. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1483. WBUFW(buf,4) = j;
  1484. else
  1485. WBUFW(buf,4) = item->card[i];
  1486. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1487. WBUFW(buf,6) = j;
  1488. else
  1489. WBUFW(buf,6) = item->card[i];
  1490. }
  1491. /*==========================================
  1492. *
  1493. *------------------------------------------*/
  1494. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1495. {
  1496. int fd;
  1497. nullpo_retr(0, sd);
  1498. fd = sd->fd;
  1499. if (!session_isActive(fd)) //Sasuke-
  1500. return 0;
  1501. WFIFOHEAD(fd,packet_len(0xa0));
  1502. if(fail) {
  1503. WFIFOW(fd,0)=0xa0;
  1504. WFIFOW(fd,2)=n+2;
  1505. WFIFOW(fd,4)=amount;
  1506. WFIFOW(fd,6)=0;
  1507. WFIFOB(fd,8)=0;
  1508. WFIFOB(fd,9)=0;
  1509. WFIFOB(fd,10)=0;
  1510. WFIFOW(fd,11)=0;
  1511. WFIFOW(fd,13)=0;
  1512. WFIFOW(fd,15)=0;
  1513. WFIFOW(fd,17)=0;
  1514. WFIFOW(fd,19)=0;
  1515. WFIFOB(fd,21)=0;
  1516. WFIFOB(fd,22)=fail;
  1517. } else {
  1518. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1519. return 1;
  1520. WFIFOW(fd,0)=0xa0;
  1521. WFIFOW(fd,2)=n+2;
  1522. WFIFOW(fd,4)=amount;
  1523. if (sd->inventory_data[n]->view_id > 0)
  1524. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1525. else
  1526. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1527. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1528. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1529. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1530. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1531. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1532. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1533. WFIFOB(fd,22)=fail;
  1534. }
  1535. WFIFOSET(fd,packet_len(0xa0));
  1536. return 0;
  1537. }
  1538. /*==========================================
  1539. *
  1540. *------------------------------------------*/
  1541. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1542. {
  1543. int fd;
  1544. nullpo_retr(0, sd);
  1545. fd=sd->fd;
  1546. WFIFOHEAD(fd, packet_len(0xaf));
  1547. WFIFOW(fd,0)=0xaf;
  1548. WFIFOW(fd,2)=n+2;
  1549. WFIFOW(fd,4)=amount;
  1550. WFIFOSET(fd,packet_len(0xaf));
  1551. return 0;
  1552. }
  1553. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1554. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1555. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1556. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1557. {
  1558. if (id->view_id > 0)
  1559. WBUFW(buf,n)=id->view_id;
  1560. else
  1561. WBUFW(buf,n)=i->nameid;
  1562. WBUFB(buf,n+2)=itemtype(id->type);
  1563. WBUFB(buf,n+3)=i->identify;
  1564. if (equip >= 0) { //Equippable item
  1565. WBUFW(buf,n+4)=equip;
  1566. WBUFW(buf,n+6)=i->equip;
  1567. WBUFB(buf,n+8)=i->attribute;
  1568. WBUFB(buf,n+9)=i->refine;
  1569. } else { //Stackable item.
  1570. WBUFW(buf,n+4)=i->amount;
  1571. if (equip == -2 && id->equip == EQP_AMMO)
  1572. WBUFW(buf,n+6)=EQP_AMMO;
  1573. else
  1574. WBUFW(buf,n+6)=0;
  1575. }
  1576. }
  1577. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1578. void clif_inventorylist(struct map_session_data *sd)
  1579. {
  1580. int i,n,ne,fd = sd->fd,arrow=-1;
  1581. unsigned char *buf;
  1582. unsigned char bufe[MAX_INVENTORY*20+4];
  1583. #if PACKETVER < 5
  1584. const int s = 10; //Entry size.
  1585. #else
  1586. const int s = 18;
  1587. #endif
  1588. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1589. buf = WFIFOP(fd,0);
  1590. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1591. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1592. continue;
  1593. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1594. { //Non-stackable (Equippable)
  1595. WBUFW(bufe,ne*20+4)=i+2;
  1596. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1597. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1598. ne++;
  1599. } else { //Stackable.
  1600. WBUFW(buf,n*s+4)=i+2;
  1601. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1602. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1603. sd->status.inventory[i].equip)
  1604. arrow=i;
  1605. #if PACKETVER >= 5
  1606. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1607. #endif
  1608. n++;
  1609. }
  1610. }
  1611. if (n) {
  1612. #if PACKETVER < 5
  1613. WBUFW(buf,0)=0xa3;
  1614. #else
  1615. WBUFW(buf,0)=0x1ee;
  1616. #endif
  1617. WBUFW(buf,2)=4+n*s;
  1618. WFIFOSET(fd,WFIFOW(fd,2));
  1619. }
  1620. if(arrow >= 0)
  1621. clif_arrowequip(sd,arrow);
  1622. if(ne){
  1623. WBUFW(bufe,0)=0xa4;
  1624. WBUFW(bufe,2)=4+ne*20;
  1625. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1626. }
  1627. }
  1628. //Required when items break/get-repaired. Only sends equippable item list.
  1629. void clif_equiplist(struct map_session_data *sd)
  1630. {
  1631. int i,n,fd = sd->fd;
  1632. unsigned char *buf;
  1633. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1634. buf = WFIFOP(fd,0);
  1635. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1636. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1637. continue;
  1638. if(itemdb_isstackable2(sd->inventory_data[i]))
  1639. continue;
  1640. //Equippable
  1641. WBUFW(buf,n*20+4)=i+2;
  1642. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1643. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1644. n++;
  1645. }
  1646. if (n) {
  1647. WBUFW(buf,0)=0xa4;
  1648. WBUFW(buf,2)=4+n*20;
  1649. WFIFOSET(fd,WFIFOW(fd,2));
  1650. }
  1651. }
  1652. void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
  1653. {
  1654. struct item_data *id;
  1655. int i,n,ne,fd=sd->fd;
  1656. unsigned char *buf;
  1657. unsigned char bufe[MAX_STORAGE*20+4];
  1658. #if PACKETVER < 5
  1659. const int s = 10; //Entry size.
  1660. #else
  1661. const int s = 18;
  1662. #endif
  1663. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1664. buf = WFIFOP(fd,0);
  1665. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1666. if(stor->items[i].nameid<=0)
  1667. continue;
  1668. id = itemdb_search(stor->items[i].nameid);
  1669. if(!itemdb_isstackable2(id))
  1670. { //Equippable
  1671. WBUFW(bufe,ne*20+4)=i+1;
  1672. clif_item_sub(bufe, ne*20+6, &stor->items[i], id, id->equip);
  1673. clif_addcards(WBUFP(bufe, ne*20+16), &stor->items[i]);
  1674. ne++;
  1675. } else { //Stackable
  1676. WBUFW(buf,n*s+4)=i+1;
  1677. clif_item_sub(buf, n*s+6, &stor->items[i], id,-1);
  1678. #if PACKETVER >= 5
  1679. clif_addcards(WBUFP(buf,n*s+14), &stor->items[i]);
  1680. #endif
  1681. n++;
  1682. }
  1683. }
  1684. if(n){
  1685. #if PACKETVER < 5
  1686. WBUFW(buf,0)=0xa5;
  1687. #else
  1688. WBUFW(buf,0)=0x1f0;
  1689. #endif
  1690. WBUFW(buf,2)=4+n*s;
  1691. WFIFOSET(fd,WFIFOW(fd,2));
  1692. }
  1693. if(ne){
  1694. WBUFW(bufe,0)=0xa6;
  1695. WBUFW(bufe,2)=4+ne*20;
  1696. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1697. }
  1698. }
  1699. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1700. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1701. {
  1702. struct item_data *id;
  1703. int i,n,ne,fd=sd->fd;
  1704. unsigned char *buf;
  1705. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1706. #if PACKETVER < 5
  1707. const int s = 10; //Entry size.
  1708. #else
  1709. const int s = 18;
  1710. #endif
  1711. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1712. buf = WFIFOP(fd,0);
  1713. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1714. if(stor->storage_[i].nameid<=0)
  1715. continue;
  1716. id = itemdb_search(stor->storage_[i].nameid);
  1717. if(!itemdb_isstackable2(id))
  1718. { //Equippable
  1719. WBUFW(bufe,ne*20+4)=i+1;
  1720. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1721. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1722. ne++;
  1723. } else { //Stackable
  1724. WBUFW(buf,n*s+4)=i+1;
  1725. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1726. #if PACKETVER >= 5
  1727. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1728. #endif
  1729. n++;
  1730. }
  1731. }
  1732. if(n){
  1733. #if PACKETVER < 5
  1734. WBUFW(buf,0)=0xa5;
  1735. #else
  1736. WBUFW(buf,0)=0x1f0;
  1737. #endif
  1738. WBUFW(buf,2)=4+n*s;
  1739. WFIFOSET(fd,WFIFOW(fd,2));
  1740. }
  1741. if(ne){
  1742. WBUFW(bufe,0)=0xa6;
  1743. WBUFW(bufe,2)=4+ne*20;
  1744. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1745. }
  1746. }
  1747. void clif_cartlist(struct map_session_data *sd)
  1748. {
  1749. struct item_data *id;
  1750. int i,n,ne,fd=sd->fd;
  1751. unsigned char *buf;
  1752. unsigned char bufe[MAX_CART*20+4];
  1753. #if PACKETVER < 5
  1754. const int s = 10; //Entry size.
  1755. #else
  1756. const int s = 18;
  1757. #endif
  1758. WFIFOHEAD(fd, MAX_CART * s + 4);
  1759. buf = WFIFOP(fd,0);
  1760. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1761. if(sd->status.cart[i].nameid<=0)
  1762. continue;
  1763. id = itemdb_search(sd->status.cart[i].nameid);
  1764. if(!itemdb_isstackable2(id))
  1765. { //Equippable
  1766. WBUFW(bufe,ne*20+4)=i+2;
  1767. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1768. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1769. ne++;
  1770. } else { //Stackable
  1771. WBUFW(buf,n*s+4)=i+2;
  1772. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1773. #if PACKETVER >= 5
  1774. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1775. #endif
  1776. n++;
  1777. }
  1778. }
  1779. if(n){
  1780. #if PACKETVER < 5
  1781. WBUFW(buf,0)=0x123;
  1782. #else
  1783. WBUFW(buf,0)=0x1ef;
  1784. #endif
  1785. WBUFW(buf,2)=4+n*s;
  1786. WFIFOSET(fd,WFIFOW(fd,2));
  1787. }
  1788. if(ne){
  1789. WBUFW(bufe,0)=0x122;
  1790. WBUFW(bufe,2)=4+ne*20;
  1791. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1792. }
  1793. return;
  1794. }
  1795. /// Client behaviour:
  1796. /// Closes the cart storage and removes all it's items from memory.
  1797. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1798. void clif_clearcart(int fd)
  1799. {
  1800. WFIFOHEAD(fd, packet_len(0x12b));
  1801. WFIFOW(fd,0) = 0x12b;
  1802. }
  1803. // Guild XY locators [Valaris]
  1804. int clif_guild_xy(struct map_session_data *sd)
  1805. {
  1806. unsigned char buf[10];
  1807. nullpo_retr(0, sd);
  1808. WBUFW(buf,0)=0x1eb;
  1809. WBUFL(buf,2)=sd->status.account_id;
  1810. WBUFW(buf,6)=sd->bl.x;
  1811. WBUFW(buf,8)=sd->bl.y;
  1812. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1813. return 0;
  1814. }
  1815. /*==========================================
  1816. * Sends x/y dot to a single fd. [Skotlex]
  1817. *------------------------------------------*/
  1818. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1819. {
  1820. WFIFOHEAD(fd,packet_len(0x1eb));
  1821. WFIFOW(fd,0)=0x1eb;
  1822. WFIFOL(fd,2)=sd->status.account_id;
  1823. WFIFOW(fd,6)=sd->bl.x;
  1824. WFIFOW(fd,8)=sd->bl.y;
  1825. WFIFOSET(fd,packet_len(0x1eb));
  1826. return 0;
  1827. }
  1828. // Guild XY locators [Valaris]
  1829. int clif_guild_xy_remove(struct map_session_data *sd)
  1830. {
  1831. unsigned char buf[10];
  1832. nullpo_retr(0, sd);
  1833. WBUFW(buf,0)=0x1eb;
  1834. WBUFL(buf,2)=sd->status.account_id;
  1835. WBUFW(buf,6)=-1;
  1836. WBUFW(buf,8)=-1;
  1837. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1838. return 0;
  1839. }
  1840. /*==========================================
  1841. * ステータスを送りつける
  1842. * 表示専用数字はこの中で計算して送る
  1843. *------------------------------------------*/
  1844. int clif_updatestatus(struct map_session_data *sd,int type)
  1845. {
  1846. int fd,len=8;
  1847. nullpo_retr(0, sd);
  1848. fd=sd->fd;
  1849. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1850. return 0;
  1851. WFIFOHEAD(fd, 14);
  1852. WFIFOW(fd,0)=0xb0;
  1853. WFIFOW(fd,2)=type;
  1854. switch(type){
  1855. // 00b0
  1856. case SP_WEIGHT:
  1857. pc_updateweightstatus(sd);
  1858. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1859. WFIFOW(fd,2)=type;
  1860. WFIFOL(fd,4)=sd->weight;
  1861. break;
  1862. case SP_MAXWEIGHT:
  1863. WFIFOL(fd,4)=sd->max_weight;
  1864. break;
  1865. case SP_SPEED:
  1866. WFIFOL(fd,4)=sd->battle_status.speed;
  1867. break;
  1868. case SP_BASELEVEL:
  1869. WFIFOL(fd,4)=sd->status.base_level;
  1870. break;
  1871. case SP_JOBLEVEL:
  1872. WFIFOL(fd,4)=sd->status.job_level;
  1873. break;
  1874. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1875. WFIFOL(fd,4)=sd->status.karma;
  1876. break;
  1877. case SP_MANNER:
  1878. WFIFOL(fd,4)=sd->status.manner;
  1879. break;
  1880. case SP_STATUSPOINT:
  1881. WFIFOL(fd,4)=sd->status.status_point;
  1882. break;
  1883. case SP_SKILLPOINT:
  1884. WFIFOL(fd,4)=sd->status.skill_point;
  1885. break;
  1886. case SP_HIT:
  1887. WFIFOL(fd,4)=sd->battle_status.hit;
  1888. break;
  1889. case SP_FLEE1:
  1890. WFIFOL(fd,4)=sd->battle_status.flee;
  1891. break;
  1892. case SP_FLEE2:
  1893. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1894. break;
  1895. case SP_MAXHP:
  1896. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1897. break;
  1898. case SP_MAXSP:
  1899. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1900. break;
  1901. case SP_HP:
  1902. WFIFOL(fd,4)=sd->battle_status.hp;
  1903. if (battle_config.disp_hpmeter)
  1904. clif_hpmeter(sd);
  1905. if (!battle_config.party_hp_mode && sd->status.party_id)
  1906. clif_party_hp(sd);
  1907. break;
  1908. case SP_SP:
  1909. WFIFOL(fd,4)=sd->battle_status.sp;
  1910. break;
  1911. case SP_ASPD:
  1912. WFIFOL(fd,4)=sd->battle_status.amotion;
  1913. break;
  1914. case SP_ATK1:
  1915. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1916. break;
  1917. case SP_DEF1:
  1918. WFIFOL(fd,4)=sd->battle_status.def;
  1919. break;
  1920. case SP_MDEF1:
  1921. WFIFOL(fd,4)=sd->battle_status.mdef;
  1922. break;
  1923. case SP_ATK2:
  1924. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1925. break;
  1926. case SP_DEF2:
  1927. WFIFOL(fd,4)=sd->battle_status.def2;
  1928. break;
  1929. case SP_MDEF2:
  1930. //negative check (in case you have something like Berserk active)
  1931. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1932. if (len < 0) len = 0;
  1933. WFIFOL(fd,4)= len;
  1934. len = 8;
  1935. break;
  1936. case SP_CRITICAL:
  1937. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1938. break;
  1939. case SP_MATK1:
  1940. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1941. break;
  1942. case SP_MATK2:
  1943. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1944. break;
  1945. case SP_ZENY:
  1946. WFIFOW(fd,0)=0xb1;
  1947. WFIFOL(fd,4)=sd->status.zeny;
  1948. break;
  1949. case SP_BASEEXP:
  1950. WFIFOW(fd,0)=0xb1;
  1951. WFIFOL(fd,4)=sd->status.base_exp;
  1952. break;
  1953. case SP_JOBEXP:
  1954. WFIFOW(fd,0)=0xb1;
  1955. WFIFOL(fd,4)=sd->status.job_exp;
  1956. break;
  1957. case SP_NEXTBASEEXP:
  1958. WFIFOW(fd,0)=0xb1;
  1959. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  1960. break;
  1961. case SP_NEXTJOBEXP:
  1962. WFIFOW(fd,0)=0xb1;
  1963. WFIFOL(fd,4)=pc_nextjobexp(sd);
  1964. break;
  1965. // 00be 終了
  1966. case SP_USTR:
  1967. case SP_UAGI:
  1968. case SP_UVIT:
  1969. case SP_UINT:
  1970. case SP_UDEX:
  1971. case SP_ULUK:
  1972. WFIFOW(fd,0)=0xbe;
  1973. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  1974. len=5;
  1975. break;
  1976. // 013a 終了
  1977. case SP_ATTACKRANGE:
  1978. WFIFOW(fd,0)=0x13a;
  1979. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  1980. len=4;
  1981. break;
  1982. // 0141 終了
  1983. case SP_STR:
  1984. WFIFOW(fd,0)=0x141;
  1985. WFIFOL(fd,2)=type;
  1986. WFIFOL(fd,6)=sd->status.str;
  1987. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  1988. len=14;
  1989. break;
  1990. case SP_AGI:
  1991. WFIFOW(fd,0)=0x141;
  1992. WFIFOL(fd,2)=type;
  1993. WFIFOL(fd,6)=sd->status.agi;
  1994. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  1995. len=14;
  1996. break;
  1997. case SP_VIT:
  1998. WFIFOW(fd,0)=0x141;
  1999. WFIFOL(fd,2)=type;
  2000. WFIFOL(fd,6)=sd->status.vit;
  2001. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2002. len=14;
  2003. break;
  2004. case SP_INT:
  2005. WFIFOW(fd,0)=0x141;
  2006. WFIFOL(fd,2)=type;
  2007. WFIFOL(fd,6)=sd->status.int_;
  2008. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2009. len=14;
  2010. break;
  2011. case SP_DEX:
  2012. WFIFOW(fd,0)=0x141;
  2013. WFIFOL(fd,2)=type;
  2014. WFIFOL(fd,6)=sd->status.dex;
  2015. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2016. len=14;
  2017. break;
  2018. case SP_LUK:
  2019. WFIFOW(fd,0)=0x141;
  2020. WFIFOL(fd,2)=type;
  2021. WFIFOL(fd,6)=sd->status.luk;
  2022. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2023. len=14;
  2024. break;
  2025. case SP_CARTINFO:
  2026. WFIFOW(fd,0)=0x121;
  2027. WFIFOW(fd,2)=sd->cart_num;
  2028. WFIFOW(fd,4)=MAX_CART;
  2029. WFIFOL(fd,6)=sd->cart_weight;
  2030. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2031. len=14;
  2032. break;
  2033. default:
  2034. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2035. return 1;
  2036. }
  2037. WFIFOSET(fd,len);
  2038. return 0;
  2039. }
  2040. int clif_changestatus(struct block_list *bl,int type,int val)
  2041. {
  2042. unsigned char buf[12];
  2043. struct map_session_data *sd = NULL;
  2044. nullpo_retr(0, bl);
  2045. if(bl->type == BL_PC)
  2046. sd = (struct map_session_data *)bl;
  2047. if(sd){
  2048. WBUFW(buf,0)=0x1ab;
  2049. WBUFL(buf,2)=bl->id;
  2050. WBUFW(buf,6)=type;
  2051. switch(type){
  2052. case SP_MANNER:
  2053. WBUFL(buf,8)=val;
  2054. break;
  2055. default:
  2056. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2057. return 1;
  2058. }
  2059. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2060. }
  2061. return 0;
  2062. }
  2063. /*==========================================
  2064. *
  2065. *------------------------------------------*/
  2066. void clif_changelook(struct block_list *bl,int type,int val)
  2067. {
  2068. unsigned char buf[16];
  2069. struct map_session_data* sd = NULL;
  2070. struct status_change* sc;
  2071. struct view_data* vd;
  2072. enum send_target target = AREA;
  2073. nullpo_retv(bl);
  2074. sd = BL_CAST(BL_PC, bl);
  2075. sc = status_get_sc(bl);
  2076. vd = status_get_viewdata(bl);
  2077. //nullpo_ret(vd);
  2078. if( vd ) //temp hack to let Warp Portal change appearance
  2079. switch(type)
  2080. {
  2081. case LOOK_WEAPON:
  2082. if (sd)
  2083. {
  2084. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2085. val = vd->weapon;
  2086. }
  2087. else vd->weapon = val;
  2088. break;
  2089. case LOOK_SHIELD:
  2090. if (sd)
  2091. {
  2092. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2093. val = vd->shield;
  2094. }
  2095. else vd->shield = val;
  2096. break;
  2097. case LOOK_BASE:
  2098. vd->class_ = val;
  2099. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2100. vd->weapon = vd->shield = 0;
  2101. if (vd->cloth_color && (
  2102. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2103. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2104. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2105. ))
  2106. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2107. break;
  2108. case LOOK_HAIR:
  2109. vd->hair_style = val;
  2110. break;
  2111. case LOOK_HEAD_BOTTOM:
  2112. vd->head_bottom = val;
  2113. break;
  2114. case LOOK_HEAD_TOP:
  2115. vd->head_top = val;
  2116. break;
  2117. case LOOK_HEAD_MID:
  2118. vd->head_mid = val;
  2119. break;
  2120. case LOOK_HAIR_COLOR:
  2121. vd->hair_color = val;
  2122. break;
  2123. case LOOK_CLOTHES_COLOR:
  2124. if (val && (
  2125. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2126. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2127. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2128. ))
  2129. val = 0;
  2130. vd->cloth_color = val;
  2131. break;
  2132. case LOOK_SHOES:
  2133. #if PACKETVER > 3
  2134. if (sd) {
  2135. int n;
  2136. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2137. if(sd->inventory_data[n]->view_id > 0)
  2138. val = sd->inventory_data[n]->view_id;
  2139. else
  2140. val = sd->status.inventory[n].nameid;
  2141. }
  2142. val = 0;
  2143. }
  2144. #endif
  2145. //Shoes? No packet uses this....
  2146. break;
  2147. }
  2148. // prevent leaking the presence of GM-hidden objects
  2149. if( sc && sc->option&OPTION_INVISIBLE )
  2150. target = SELF;
  2151. #if PACKETVER < 4
  2152. WBUFW(buf,0)=0xc3;
  2153. WBUFL(buf,2)=bl->id;
  2154. WBUFB(buf,6)=type;
  2155. WBUFB(buf,7)=val;
  2156. clif_send(buf,packet_len(0xc3),bl,target);
  2157. #else
  2158. WBUFW(buf,0)=0x1d7;
  2159. WBUFL(buf,2)=bl->id;
  2160. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2161. WBUFB(buf,6)=LOOK_WEAPON;
  2162. WBUFW(buf,7)=vd->weapon;
  2163. WBUFW(buf,9)=vd->shield;
  2164. } else {
  2165. WBUFB(buf,6)=type;
  2166. WBUFW(buf,7)=val;
  2167. WBUFW(buf,9)=0;
  2168. }
  2169. clif_send(buf,packet_len(0x1d7),bl,target);
  2170. #endif
  2171. }
  2172. //Sends a change-base-look packet required for traps as they are triggered.
  2173. void clif_changetraplook(struct block_list *bl,int val)
  2174. {
  2175. unsigned char buf[32];
  2176. #if PACKETVER < 4
  2177. WBUFW(buf,0)=0xc3;
  2178. WBUFL(buf,2)=bl->id;
  2179. WBUFB(buf,6)=LOOK_BASE;
  2180. WBUFB(buf,7)=val;
  2181. clif_send(buf,packet_len(0xc3),bl,AREA);
  2182. #else
  2183. WBUFW(buf,0)=0x1d7;
  2184. WBUFL(buf,2)=bl->id;
  2185. WBUFB(buf,6)=LOOK_BASE;
  2186. WBUFW(buf,7)=val;
  2187. WBUFW(buf,9)=0;
  2188. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2189. #endif
  2190. }
  2191. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2192. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2193. {
  2194. unsigned char buf[32];
  2195. #if PACKETVER < 4
  2196. WBUFW(buf,0)=0xc3;
  2197. WBUFL(buf,2)=id;
  2198. WBUFB(buf,6)=type;
  2199. WBUFB(buf,7)=val;
  2200. clif_send(buf,packet_len(0xc3),bl,target);
  2201. #else
  2202. WBUFW(buf,0)=0x1d7;
  2203. WBUFL(buf,2)=id;
  2204. WBUFB(buf,6)=type;
  2205. WBUFW(buf,7)=val;
  2206. WBUFW(buf,9)=0;
  2207. clif_send(buf,packet_len(0x1d7),bl,target);
  2208. #endif
  2209. return;
  2210. }
  2211. /*==========================================
  2212. *
  2213. *------------------------------------------*/
  2214. int clif_initialstatus(struct map_session_data *sd)
  2215. {
  2216. int fd;
  2217. unsigned char *buf;
  2218. nullpo_retr(0, sd);
  2219. fd=sd->fd;
  2220. WFIFOHEAD(fd,packet_len(0xbd));
  2221. buf=WFIFOP(fd,0);
  2222. WBUFW(buf,0)=0xbd;
  2223. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2224. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2225. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2226. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2227. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2228. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2229. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2230. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2231. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2232. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2233. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2234. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2235. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2236. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2237. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2238. WBUFW(buf,20) = sd->battle_status.matk_max;
  2239. WBUFW(buf,22) = sd->battle_status.matk_min;
  2240. WBUFW(buf,24) = sd->battle_status.def; // def
  2241. WBUFW(buf,26) = sd->battle_status.def2;
  2242. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2243. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2244. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2245. WBUFW(buf,30) = fd;
  2246. fd = sd->fd;
  2247. WBUFW(buf,32) = sd->battle_status.hit;
  2248. WBUFW(buf,34) = sd->battle_status.flee;
  2249. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2250. WBUFW(buf,38) = sd->battle_status.cri/10;
  2251. WBUFW(buf,40) = sd->status.karma;
  2252. WBUFW(buf,42) = sd->status.manner;
  2253. WFIFOSET(fd,packet_len(0xbd));
  2254. clif_updatestatus(sd,SP_STR);
  2255. clif_updatestatus(sd,SP_AGI);
  2256. clif_updatestatus(sd,SP_VIT);
  2257. clif_updatestatus(sd,SP_INT);
  2258. clif_updatestatus(sd,SP_DEX);
  2259. clif_updatestatus(sd,SP_LUK);
  2260. clif_updatestatus(sd,SP_ATTACKRANGE);
  2261. clif_updatestatus(sd,SP_ASPD);
  2262. return 0;
  2263. }
  2264. /*==========================================
  2265. *矢装備
  2266. *------------------------------------------*/
  2267. int clif_arrowequip(struct map_session_data *sd,int val)
  2268. {
  2269. int fd;
  2270. nullpo_retr(0, sd);
  2271. pc_stop_attack(sd); // [Valaris]
  2272. fd=sd->fd;
  2273. WFIFOHEAD(fd, packet_len(0x013c));
  2274. WFIFOW(fd,0)=0x013c;
  2275. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2276. WFIFOSET(fd,packet_len(0x013c));
  2277. return 0;
  2278. }
  2279. /// Ammunition action message.
  2280. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2281. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2282. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2283. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2284. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2285. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2286. int clif_arrow_fail(struct map_session_data *sd,int type)
  2287. {
  2288. int fd;
  2289. nullpo_retr(0, sd);
  2290. fd=sd->fd;
  2291. WFIFOHEAD(fd, packet_len(0x013b));
  2292. WFIFOW(fd,0)=0x013b;
  2293. WFIFOW(fd,2)=type;
  2294. WFIFOSET(fd,packet_len(0x013b));
  2295. return 0;
  2296. }
  2297. /*==========================================
  2298. * 作成可能 矢リスト送信
  2299. *------------------------------------------*/
  2300. int clif_arrow_create_list(struct map_session_data *sd)
  2301. {
  2302. int i, c, j;
  2303. int fd;
  2304. nullpo_retr(0, sd);
  2305. fd = sd->fd;
  2306. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2307. WFIFOW(fd,0) = 0x1ad;
  2308. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2309. if (skill_arrow_db[i].nameid > 0 &&
  2310. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2311. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2312. {
  2313. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2314. WFIFOW(fd,c*2+4) = j;
  2315. else
  2316. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2317. c++;
  2318. }
  2319. }
  2320. WFIFOW(fd,2) = c*2+4;
  2321. WFIFOSET(fd, WFIFOW(fd,2));
  2322. if (c > 0) {
  2323. sd->menuskill_id = AC_MAKINGARROW;
  2324. sd->menuskill_val = c;
  2325. }
  2326. return 0;
  2327. }
  2328. /*==========================================
  2329. *
  2330. *------------------------------------------*/
  2331. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2332. {
  2333. int fd;
  2334. nullpo_retr(0, sd);
  2335. fd=sd->fd;
  2336. WFIFOHEAD(fd,packet_len(0xbc));
  2337. WFIFOW(fd,0)=0xbc;
  2338. WFIFOW(fd,2)=type;
  2339. WFIFOB(fd,4)=ok;
  2340. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2341. WFIFOSET(fd,packet_len(0xbc));
  2342. return 0;
  2343. }
  2344. /*==========================================
  2345. *
  2346. *------------------------------------------*/
  2347. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2348. {
  2349. int fd;
  2350. nullpo_retr(0, sd);
  2351. fd=sd->fd;
  2352. WFIFOHEAD(fd,packet_len(0xaa));
  2353. WFIFOW(fd,0)=0xaa;
  2354. WFIFOW(fd,2)=n+2;
  2355. WFIFOW(fd,4)=pos;
  2356. WFIFOB(fd,6)=ok;
  2357. WFIFOSET(fd,packet_len(0xaa));
  2358. return 0;
  2359. }
  2360. /*==========================================
  2361. *
  2362. *------------------------------------------*/
  2363. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2364. {
  2365. int fd;
  2366. nullpo_retr(0, sd);
  2367. fd=sd->fd;
  2368. WFIFOHEAD(fd,packet_len(0xac));
  2369. WFIFOW(fd,0)=0xac;
  2370. WFIFOW(fd,2)=n+2;
  2371. WFIFOW(fd,4)=pos;
  2372. WFIFOB(fd,6)=ok;
  2373. WFIFOSET(fd,packet_len(0xac));
  2374. return 0;
  2375. }
  2376. /*==========================================
  2377. *
  2378. *------------------------------------------*/
  2379. int clif_misceffect(struct block_list* bl,int type)
  2380. {
  2381. unsigned char buf[32];
  2382. nullpo_retr(0, bl);
  2383. WBUFW(buf,0) = 0x19b;
  2384. WBUFL(buf,2) = bl->id;
  2385. WBUFL(buf,6) = type;
  2386. clif_send(buf,packet_len(0x19b),bl,AREA);
  2387. return 0;
  2388. }
  2389. int clif_misceffect2(struct block_list *bl, int type)
  2390. {
  2391. unsigned char buf[24];
  2392. nullpo_retr(0, bl);
  2393. memset(buf, 0, packet_len(0x1f3));
  2394. WBUFW(buf,0) = 0x1f3;
  2395. WBUFL(buf,2) = bl->id;
  2396. WBUFL(buf,6) = type;
  2397. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2398. return 0;
  2399. }
  2400. /*==========================================
  2401. * 表示オプション変更
  2402. *------------------------------------------*/
  2403. int clif_changeoption(struct block_list* bl)
  2404. {
  2405. unsigned char buf[32];
  2406. struct status_change *sc;
  2407. nullpo_retr(0, bl);
  2408. sc = status_get_sc(bl);
  2409. if (!sc) return 0; //How can an option change if there's no sc?
  2410. #if PACKETVER >= 7
  2411. WBUFW(buf,0) = 0x229;
  2412. WBUFL(buf,2) = bl->id;
  2413. WBUFW(buf,6) = sc->opt1;
  2414. WBUFW(buf,8) = sc->opt2;
  2415. WBUFL(buf,10) = sc->option;
  2416. WBUFB(buf,14) = 0; // PK???
  2417. if(disguised(bl)) {
  2418. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2419. WBUFL(buf,2) = -bl->id;
  2420. clif_send(buf,packet_len(0x229),bl,SELF);
  2421. WBUFL(buf,2) = bl->id;
  2422. WBUFL(buf,10) = OPTION_INVISIBLE;
  2423. clif_send(buf,packet_len(0x229),bl,SELF);
  2424. } else
  2425. clif_send(buf,packet_len(0x229),bl,AREA);
  2426. #else
  2427. WBUFW(buf,0) = 0x119;
  2428. WBUFL(buf,2) = bl->id;
  2429. WBUFW(buf,6) = sc->opt1;
  2430. WBUFW(buf,8) = sc->opt2;
  2431. WBUFW(buf,10) = sc->option;
  2432. WBUFB(buf,12) = 0; // ??
  2433. if(disguised(bl)) {
  2434. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2435. WBUFL(buf,2) = -bl->id;
  2436. clif_send(buf,packet_len(0x119),bl,SELF);
  2437. WBUFL(buf,2) = bl->id;
  2438. WBUFW(buf,10) = OPTION_INVISIBLE;
  2439. clif_send(buf,packet_len(0x119),bl,SELF);
  2440. } else
  2441. clif_send(buf,packet_len(0x119),bl,AREA);
  2442. #endif
  2443. return 0;
  2444. }
  2445. int clif_changeoption2(struct block_list* bl)
  2446. {
  2447. unsigned char buf[20];
  2448. struct status_change *sc;
  2449. sc = status_get_sc(bl);
  2450. if (!sc) return 0; //How can an option change if there's no sc?
  2451. WBUFW(buf,0) = 0x28a;
  2452. WBUFL(buf,2) = bl->id;
  2453. WBUFL(buf,6) = sc->option;
  2454. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2455. WBUFL(buf,14) = sc->opt3;
  2456. if(disguised(bl)) {
  2457. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2458. WBUFL(buf,2) = -bl->id;
  2459. clif_send(buf,packet_len(0x28a),bl,SELF);
  2460. WBUFL(buf,2) = bl->id;
  2461. WBUFL(buf,6) = OPTION_INVISIBLE;
  2462. clif_send(buf,packet_len(0x28a),bl,SELF);
  2463. } else
  2464. clif_send(buf,packet_len(0x28a),bl,AREA);
  2465. return 0;
  2466. }
  2467. /*==========================================
  2468. *
  2469. *------------------------------------------*/
  2470. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2471. {
  2472. nullpo_retr(0, sd);
  2473. if(!ok) {
  2474. int fd=sd->fd;
  2475. WFIFOHEAD(fd,packet_len(0xa8));
  2476. WFIFOW(fd,0)=0xa8;
  2477. WFIFOW(fd,2)=index+2;
  2478. WFIFOW(fd,4)=amount;
  2479. WFIFOB(fd,6)=ok;
  2480. WFIFOSET(fd,packet_len(0xa8));
  2481. }
  2482. else {
  2483. #if PACKETVER < 3
  2484. int fd=sd->fd;
  2485. WFIFOHEAD(fd,packet_len(0xa8));
  2486. WFIFOW(fd,0)=0xa8;
  2487. WFIFOW(fd,2)=index+2;
  2488. WFIFOW(fd,4)=amount;
  2489. WFIFOB(fd,6)=ok;
  2490. WFIFOSET(fd,packet_len(0xa8));
  2491. #else
  2492. unsigned char buf[32];
  2493. WBUFW(buf,0)=0x1c8;
  2494. WBUFW(buf,2)=index+2;
  2495. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2496. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2497. else
  2498. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2499. WBUFL(buf,6)=sd->bl.id;
  2500. WBUFW(buf,10)=amount;
  2501. WBUFB(buf,12)=ok;
  2502. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2503. #endif
  2504. }
  2505. return 0;
  2506. }
  2507. /*==========================================
  2508. * Inform client whether chatroom creation was successful or not
  2509. * R 00d6 <fail>.B
  2510. *------------------------------------------*/
  2511. void clif_createchat(struct map_session_data* sd, int fail)
  2512. {
  2513. int fd;
  2514. nullpo_retv(sd);
  2515. fd = sd->fd;
  2516. WFIFOHEAD(fd,packet_len(0xd6));
  2517. WFIFOW(fd,0) = 0xd6;
  2518. WFIFOB(fd,2) = fail;
  2519. WFIFOSET(fd,packet_len(0xd6));
  2520. }
  2521. /*==========================================
  2522. * Display a chat above the owner
  2523. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2524. *------------------------------------------*/
  2525. int clif_dispchat(struct chat_data* cd, int fd)
  2526. {
  2527. unsigned char buf[128];
  2528. uint8 type;
  2529. if( cd == NULL || cd->owner == NULL )
  2530. return 1;
  2531. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2532. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2533. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2534. : 1;
  2535. WBUFW(buf, 0) = 0xd7;
  2536. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2537. WBUFL(buf, 4) = cd->owner->id;
  2538. WBUFL(buf, 8) = cd->bl.id;
  2539. WBUFW(buf,12) = cd->limit;
  2540. WBUFW(buf,14) = cd->users;
  2541. WBUFB(buf,16) = type;
  2542. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2543. if( fd ) {
  2544. WFIFOHEAD(fd,WBUFW(buf,2));
  2545. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2546. WFIFOSET(fd,WBUFW(buf,2));
  2547. } else {
  2548. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2549. }
  2550. return 0;
  2551. }
  2552. /*==========================================
  2553. * Chatroom properties adjustment
  2554. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2555. *------------------------------------------*/
  2556. int clif_changechatstatus(struct chat_data* cd)
  2557. {
  2558. unsigned char buf[128];
  2559. if( cd == NULL || cd->usersd[0] == NULL )
  2560. return 1;
  2561. WBUFW(buf, 0) = 0xdf;
  2562. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2563. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2564. WBUFL(buf, 8) = cd->bl.id;
  2565. WBUFW(buf,12) = cd->limit;
  2566. WBUFW(buf,14) = cd->users;
  2567. WBUFB(buf,16) = cd->pub;
  2568. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2569. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2570. return 0;
  2571. }
  2572. /*==========================================
  2573. *
  2574. *------------------------------------------*/
  2575. int clif_clearchat(struct chat_data *cd,int fd)
  2576. {
  2577. unsigned char buf[32];
  2578. nullpo_retr(0, cd);
  2579. WBUFW(buf,0) = 0xd8;
  2580. WBUFL(buf,2) = cd->bl.id;
  2581. if( fd ) {
  2582. WFIFOHEAD(fd,packet_len(0xd8));
  2583. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2584. WFIFOSET(fd,packet_len(0xd8));
  2585. } else {
  2586. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2587. }
  2588. return 0;
  2589. }
  2590. /*==========================================
  2591. *
  2592. *------------------------------------------*/
  2593. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2594. {
  2595. int fd;
  2596. nullpo_retr(0, sd);
  2597. fd = sd->fd;
  2598. WFIFOHEAD(fd,packet_len(0xda));
  2599. WFIFOW(fd,0) = 0xda;
  2600. WFIFOB(fd,2) = fail;
  2601. WFIFOSET(fd,packet_len(0xda));
  2602. return 0;
  2603. }
  2604. /*==========================================
  2605. *
  2606. *------------------------------------------*/
  2607. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2608. {
  2609. int fd;
  2610. int i;
  2611. nullpo_retr(0, sd);
  2612. nullpo_retr(0, cd);
  2613. fd = sd->fd;
  2614. if (!session_isActive(fd))
  2615. return 0;
  2616. WFIFOHEAD(fd, 8 + (28*cd->users));
  2617. WFIFOW(fd, 0) = 0xdb;
  2618. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2619. WFIFOL(fd, 4) = cd->bl.id;
  2620. for (i = 0; i < cd->users; i++) {
  2621. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2622. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2623. }
  2624. WFIFOSET(fd, WFIFOW(fd, 2));
  2625. return 0;
  2626. }
  2627. /*==========================================
  2628. *
  2629. *------------------------------------------*/
  2630. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2631. {
  2632. unsigned char buf[32];
  2633. nullpo_retr(0, sd);
  2634. nullpo_retr(0, cd);
  2635. WBUFW(buf, 0) = 0x0dc;
  2636. WBUFW(buf, 2) = cd->users;
  2637. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2638. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2639. return 0;
  2640. }
  2641. /*==========================================
  2642. * Announce the new owner
  2643. * R 00e1 <index>.l <nick>.24B
  2644. *------------------------------------------*/
  2645. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2646. {
  2647. unsigned char buf[64];
  2648. nullpo_retv(sd);
  2649. nullpo_retv(cd);
  2650. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2651. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2652. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2653. WBUFW(buf, 0) = 0xe1;
  2654. WBUFL(buf, 2) = 1;
  2655. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2656. WBUFW(buf,30) = 0xe1;
  2657. WBUFL(buf,32) = 0;
  2658. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2659. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2660. }
  2661. /*==========================================
  2662. * Notify about user leaving the chatroom
  2663. * R 00dd <index>.w <nick>.24B <flag>.B
  2664. *------------------------------------------*/
  2665. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2666. {
  2667. unsigned char buf[32];
  2668. nullpo_retv(sd);
  2669. nullpo_retv(cd);
  2670. WBUFW(buf, 0) = 0xdd;
  2671. WBUFW(buf, 2) = cd->users-1;
  2672. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2673. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2674. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2675. }
  2676. /*==========================================
  2677. * Opens a trade request window from char 'name'
  2678. * R 00e5 <nick>.24B
  2679. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2680. *------------------------------------------*/
  2681. void clif_traderequest(struct map_session_data* sd, const char* name)
  2682. {
  2683. int fd = sd->fd;
  2684. #if PACKETVER < 6
  2685. WFIFOHEAD(fd,packet_len(0xe5));
  2686. WFIFOW(fd,0) = 0xe5;
  2687. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2688. WFIFOSET(fd,packet_len(0xe5));
  2689. #else
  2690. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2691. if( !tsd ) return;
  2692. WFIFOHEAD(fd,packet_len(0x1f4));
  2693. WFIFOW(fd,0) = 0x1f4;
  2694. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2695. WFIFOL(fd,26) = tsd->status.char_id;
  2696. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2697. WFIFOSET(fd,packet_len(0x1f4));
  2698. #endif
  2699. }
  2700. /*==========================================
  2701. * Reply to a trade-request.
  2702. * R 00e7 <type>.B
  2703. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2704. * Type:
  2705. * 0: Char is too far
  2706. * 1: Character does not exist
  2707. * 2: Trade failed
  2708. * 3: Accept
  2709. * 4: Cancel
  2710. *------------------------------------------*/
  2711. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2712. {
  2713. int fd = sd->fd;
  2714. #if PACKETVER < 6
  2715. WFIFOHEAD(fd,packet_len(0xe7));
  2716. WFIFOW(fd,0) = 0xe7;
  2717. WFIFOB(fd,2) = type;
  2718. WFIFOSET(fd,packet_len(0xe7));
  2719. #else
  2720. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2721. if( !tsd ) return;
  2722. WFIFOHEAD(fd,packet_len(0x1f5));
  2723. WFIFOW(fd,0) = 0x1f5;
  2724. WFIFOB(fd,2) = type;
  2725. WFIFOL(fd,3) = tsd->status.char_id;
  2726. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2727. WFIFOSET(fd,packet_len(0x1f5));
  2728. #endif
  2729. }
  2730. /*==========================================
  2731. * 相手方からのアイテム追加
  2732. *------------------------------------------*/
  2733. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2734. {
  2735. int fd;
  2736. nullpo_retv(sd);
  2737. nullpo_retv(tsd);
  2738. fd = tsd->fd;
  2739. WFIFOHEAD(fd,packet_len(0xe9));
  2740. WFIFOW(fd,0) = 0xe9;
  2741. WFIFOL(fd,2) = amount;
  2742. if( index == 0 )
  2743. {
  2744. WFIFOW(fd,6) = 0; // type id
  2745. WFIFOB(fd,8) = 0; //identify flag
  2746. WFIFOB(fd,9) = 0; // attribute
  2747. WFIFOB(fd,10)= 0; //refine
  2748. WFIFOW(fd,11)= 0; //card (4w)
  2749. WFIFOW(fd,13)= 0; //card (4w)
  2750. WFIFOW(fd,15)= 0; //card (4w)
  2751. WFIFOW(fd,17)= 0; //card (4w)
  2752. }
  2753. else
  2754. {
  2755. index -= 2; //index fix
  2756. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2757. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2758. else
  2759. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2760. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2761. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2762. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2763. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2764. }
  2765. WFIFOSET(fd,packet_len(0xe9));
  2766. }
  2767. /*==========================================
  2768. * アイテム追加成功/失敗
  2769. *------------------------------------------*/
  2770. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2771. {
  2772. int fd;
  2773. nullpo_retv(sd);
  2774. fd = sd->fd;
  2775. WFIFOHEAD(fd,packet_len(0xea));
  2776. WFIFOW(fd,0) = 0xea;
  2777. WFIFOW(fd,2) = index;
  2778. WFIFOB(fd,4) = fail;
  2779. WFIFOSET(fd,packet_len(0xea));
  2780. }
  2781. /*==========================================
  2782. * 取り引きok押し
  2783. *------------------------------------------*/
  2784. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2785. {
  2786. int fd;
  2787. nullpo_retv(sd);
  2788. fd = sd->fd;
  2789. WFIFOHEAD(fd,packet_len(0xec));
  2790. WFIFOW(fd,0) = 0xec;
  2791. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2792. WFIFOSET(fd,packet_len(0xec));
  2793. }
  2794. /*==========================================
  2795. * 取り引きがキャンセルされました
  2796. *------------------------------------------*/
  2797. void clif_tradecancelled(struct map_session_data* sd)
  2798. {
  2799. int fd;
  2800. nullpo_retv(sd);
  2801. fd = sd->fd;
  2802. WFIFOHEAD(fd,packet_len(0xee));
  2803. WFIFOW(fd,0) = 0xee;
  2804. WFIFOSET(fd,packet_len(0xee));
  2805. }
  2806. /*==========================================
  2807. * 取り引き完了
  2808. *------------------------------------------*/
  2809. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2810. {
  2811. int fd;
  2812. nullpo_retv(sd);
  2813. fd = sd->fd;
  2814. WFIFOHEAD(fd,packet_len(0xf0));
  2815. WFIFOW(fd,0) = 0xf0;
  2816. WFIFOB(fd,2) = fail;
  2817. WFIFOSET(fd,packet_len(0xf0));
  2818. }
  2819. /*==========================================
  2820. * カプラ倉庫のアイテム数を更新
  2821. *------------------------------------------*/
  2822. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  2823. {
  2824. int fd;
  2825. nullpo_retv(sd);
  2826. fd=sd->fd;
  2827. WFIFOHEAD(fd,packet_len(0xf2));
  2828. WFIFOW(fd,0) = 0xf2; // update storage amount
  2829. WFIFOW(fd,2) = amount; //items
  2830. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2831. WFIFOSET(fd,packet_len(0xf2));
  2832. }
  2833. /*==========================================
  2834. * カプラ倉庫にアイテムを追加する
  2835. *------------------------------------------*/
  2836. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2837. {
  2838. int view,fd;
  2839. nullpo_retv(sd);
  2840. nullpo_retv(i);
  2841. fd=sd->fd;
  2842. view = itemdb_viewid(i->nameid);
  2843. #if PACKETVER < 5
  2844. WFIFOHEAD(fd,packet_len(0xf4));
  2845. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2846. WFIFOW(fd, 2) = index+1; // index
  2847. WFIFOL(fd, 4) = amount; // amount
  2848. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2849. WFIFOB(fd,10) = i->identify; //identify flag
  2850. WFIFOB(fd,11) = i->attribute; // attribute
  2851. WFIFOB(fd,12) = i->refine; //refine
  2852. clif_addcards(WFIFOP(fd,13), i);
  2853. WFIFOSET(fd,packet_len(0xf4));
  2854. #else
  2855. WFIFOHEAD(fd,packet_len(0x1c4));
  2856. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  2857. WFIFOW(fd, 2) = index+1; // index
  2858. WFIFOL(fd, 4) = amount; // amount
  2859. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2860. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  2861. WFIFOB(fd,11) = i->identify; //identify flag
  2862. WFIFOB(fd,12) = i->attribute; // attribute
  2863. WFIFOB(fd,13) = i->refine; //refine
  2864. clif_addcards(WFIFOP(fd,14), i);
  2865. WFIFOSET(fd,packet_len(0x1c4));
  2866. #endif
  2867. }
  2868. /*==========================================
  2869. *
  2870. *------------------------------------------*/
  2871. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  2872. {
  2873. int fd;
  2874. nullpo_retv(sd);
  2875. fd=sd->fd;
  2876. WFIFOHEAD(fd,packet_len(0xf2));
  2877. WFIFOW(fd,0) = 0xf2; // update storage amount
  2878. WFIFOW(fd,2) = amount; //items
  2879. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2880. WFIFOSET(fd,packet_len(0xf2));
  2881. }
  2882. /*==========================================
  2883. *
  2884. *------------------------------------------*/
  2885. void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2886. {
  2887. int view,fd;
  2888. nullpo_retv(sd);
  2889. nullpo_retv(i);
  2890. fd=sd->fd;
  2891. view = itemdb_viewid(i->nameid);
  2892. WFIFOHEAD(fd,packet_len(0xf4));
  2893. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2894. WFIFOW(fd, 2) = index+1; // index
  2895. WFIFOL(fd, 4) = amount; // amount
  2896. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2897. WFIFOB(fd,10) = i->identify; //identify flag
  2898. WFIFOB(fd,11) = i->attribute; // attribute
  2899. WFIFOB(fd,12) = i->refine; //refine
  2900. clif_addcards(WFIFOP(fd,13), i);
  2901. WFIFOSET(fd,packet_len(0xf4));
  2902. }
  2903. /*==========================================
  2904. * カプラ倉庫からアイテムを取り去る
  2905. *------------------------------------------*/
  2906. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  2907. {
  2908. int fd;
  2909. nullpo_retv(sd);
  2910. fd=sd->fd;
  2911. WFIFOHEAD(fd,packet_len(0xf6));
  2912. WFIFOW(fd,0)=0xf6; // Storage item removed
  2913. WFIFOW(fd,2)=index+1;
  2914. WFIFOL(fd,4)=amount;
  2915. WFIFOSET(fd,packet_len(0xf6));
  2916. }
  2917. /*==========================================
  2918. * カプラ倉庫を閉じる
  2919. *------------------------------------------*/
  2920. void clif_storageclose(struct map_session_data* sd)
  2921. {
  2922. int fd;
  2923. nullpo_retv(sd);
  2924. fd=sd->fd;
  2925. WFIFOHEAD(fd,packet_len(0xf8));
  2926. WFIFOW(fd,0) = 0xf8; // Storage Closed
  2927. WFIFOSET(fd,packet_len(0xf8));
  2928. }
  2929. /*==========================================
  2930. * PC表示
  2931. *------------------------------------------*/
  2932. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2933. {
  2934. int gmlvl;
  2935. struct block_list *d_bl;
  2936. int i;
  2937. if(dstsd->chatID)
  2938. {
  2939. struct chat_data *cd;
  2940. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2941. if(cd && cd->usersd[0]==dstsd)
  2942. clif_dispchat(cd,sd->fd);
  2943. }
  2944. if(dstsd->vender_id)
  2945. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2946. if(dstsd->spiritball > 0)
  2947. clif_spiritball_single(sd->fd, dstsd);
  2948. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2949. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd))
  2950. )
  2951. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2952. // display link (sd - dstsd) to sd
  2953. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2954. if( i < 5 ) clif_devotion(&sd->bl, sd);
  2955. // display links (dstsd - devotees) to sd
  2956. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  2957. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  2958. // display link (dstsd - crusader) to sd
  2959. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  2960. clif_devotion(d_bl, sd);
  2961. }
  2962. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  2963. {
  2964. uint8 buf[128];
  2965. struct unit_data *ud;
  2966. struct view_data *vd;
  2967. int len;
  2968. vd = status_get_viewdata(bl);
  2969. if (!vd || vd->class_ == INVISIBLE_CLASS)
  2970. return;
  2971. ud = unit_bl2ud(bl);
  2972. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  2973. clif_send(buf,len,&sd->bl,SELF);
  2974. if (vd->cloth_color)
  2975. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  2976. switch (bl->type)
  2977. {
  2978. case BL_PC:
  2979. {
  2980. TBL_PC* tsd = (TBL_PC*)bl;
  2981. clif_getareachar_pc(sd, tsd);
  2982. if(tsd->state.size==2) // tiny/big players [Valaris]
  2983. clif_specialeffect_single(bl,423,sd->fd);
  2984. else if(tsd->state.size==1)
  2985. clif_specialeffect_single(bl,421,sd->fd);
  2986. }
  2987. break;
  2988. case BL_MER: // Devotion Effects
  2989. if( ((TBL_MER*)bl)->devotion_flag )
  2990. clif_devotion(bl, sd);
  2991. break;
  2992. case BL_NPC:
  2993. {
  2994. TBL_NPC* nd = (TBL_NPC*)bl;
  2995. if( nd->chat_id )
  2996. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  2997. if( nd->size == 2 )
  2998. clif_specialeffect_single(bl,423,sd->fd);
  2999. else if( nd->size == 1 )
  3000. clif_specialeffect_single(bl,421,sd->fd);
  3001. }
  3002. break;
  3003. case BL_MOB:
  3004. {
  3005. TBL_MOB* md = (TBL_MOB*)bl;
  3006. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3007. clif_specialeffect_single(bl,423,sd->fd);
  3008. else if(md->special_state.size==1)
  3009. clif_specialeffect_single(bl,421,sd->fd);
  3010. }
  3011. break;
  3012. case BL_PET:
  3013. if (vd->head_bottom)
  3014. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3015. break;
  3016. }
  3017. }
  3018. //Modifies the type of damage according to status changes [Skotlex]
  3019. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3020. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3021. /*==========================================
  3022. * Estimates walk delay based on the damage criteria. [Skotlex]
  3023. *------------------------------------------*/
  3024. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3025. {
  3026. if (type == 4 || type == 9 || damage <=0)
  3027. return 0;
  3028. if (bl->type == BL_PC) {
  3029. if (battle_config.pc_walk_delay_rate != 100)
  3030. delay = delay*battle_config.pc_walk_delay_rate/100;
  3031. } else
  3032. if (battle_config.walk_delay_rate != 100)
  3033. delay = delay*battle_config.walk_delay_rate/100;
  3034. if (div_ > 1) //Multi-hit skills mean higher delays.
  3035. delay += battle_config.multihit_delay*(div_-1);
  3036. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3037. }
  3038. /*==========================================
  3039. * Sends a 'damage' packet (src performs action on dst)
  3040. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3041. *
  3042. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3043. * type=01 pick up item
  3044. * type=02 sit down
  3045. * type=03 stand up
  3046. * type=04 reflected/absorbed damage?
  3047. * type=08 double attack
  3048. * type=09 don't display flinch animation (endure)
  3049. * type=0a critical hit
  3050. * type=0b lucky dodge
  3051. *------------------------------------------*/
  3052. 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)
  3053. {
  3054. unsigned char buf[256];
  3055. struct status_change *sc;
  3056. nullpo_retr(0, src);
  3057. nullpo_retr(0, dst);
  3058. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3059. sc = status_get_sc(dst);
  3060. if(sc && sc->count) {
  3061. if(sc->data[SC_HALLUCINATION]) {
  3062. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3063. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3064. }
  3065. }
  3066. WBUFW(buf,0)=0x8a;
  3067. WBUFL(buf,2)=src->id;
  3068. WBUFL(buf,6)=dst->id;
  3069. WBUFL(buf,10)=tick;
  3070. WBUFL(buf,14)=sdelay;
  3071. WBUFL(buf,18)=ddelay;
  3072. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3073. WBUFW(buf,22)=damage?div:0;
  3074. WBUFW(buf,27)=damage2?div:0;
  3075. } else {
  3076. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3077. WBUFW(buf,27)=damage2;
  3078. }
  3079. WBUFW(buf,24)=div;
  3080. WBUFB(buf,26)=type;
  3081. if(disguised(dst)) {
  3082. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3083. WBUFL(buf,6) = -dst->id;
  3084. clif_send(buf,packet_len(0x8a),dst,SELF);
  3085. } else
  3086. clif_send(buf,packet_len(0x8a),dst,AREA);
  3087. if(disguised(src)) {
  3088. WBUFL(buf,2) = -src->id;
  3089. if (disguised(dst))
  3090. WBUFL(buf,6) = dst->id;
  3091. if(damage > 0) WBUFW(buf,22) = -1;
  3092. if(damage2 > 0) WBUFW(buf,27) = -1;
  3093. clif_send(buf,packet_len(0x8a),src,SELF);
  3094. }
  3095. //Return adjusted can't walk delay for further processing.
  3096. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3097. }
  3098. /*==========================================
  3099. * src picks up dst
  3100. *------------------------------------------*/
  3101. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3102. {
  3103. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3104. unsigned char buf[32];
  3105. nullpo_retv(src);
  3106. nullpo_retv(dst);
  3107. WBUFW(buf, 0) = 0x8a;
  3108. WBUFL(buf, 2) = src->id;
  3109. WBUFL(buf, 6) = dst->id;
  3110. WBUFB(buf,26) = 1;
  3111. clif_send(buf, packet_len(0x8a), src, AREA);
  3112. }
  3113. /*==========================================
  3114. * inform clients in area that `bl` is sitting
  3115. *------------------------------------------*/
  3116. void clif_sitting(struct block_list* bl)
  3117. {
  3118. unsigned char buf[32];
  3119. nullpo_retv(bl);
  3120. WBUFW(buf, 0) = 0x8a;
  3121. WBUFL(buf, 2) = bl->id;
  3122. WBUFB(buf,26) = 2;
  3123. clif_send(buf, packet_len(0x8a), bl, AREA);
  3124. if(disguised(bl)) {
  3125. WBUFL(buf, 2) = - bl->id;
  3126. clif_send(buf, packet_len(0x8a), bl, SELF);
  3127. }
  3128. }
  3129. /*==========================================
  3130. * inform clients in area that `bl` is standing
  3131. *------------------------------------------*/
  3132. void clif_standing(struct block_list* bl)
  3133. {
  3134. unsigned char buf[32];
  3135. nullpo_retv(bl);
  3136. WBUFW(buf, 0) = 0x8a;
  3137. WBUFL(buf, 2) = bl->id;
  3138. WBUFB(buf,26) = 3;
  3139. clif_send(buf, packet_len(0x8a), bl, AREA);
  3140. if(disguised(bl)) {
  3141. WBUFL(buf, 2) = - bl->id;
  3142. clif_send(buf, packet_len(0x8a), bl, SELF);
  3143. }
  3144. }
  3145. /*==========================================
  3146. * Inform client(s) about a map-cell change
  3147. *------------------------------------------*/
  3148. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3149. {
  3150. unsigned char buf[32];
  3151. WBUFW(buf,0) = 0x192;
  3152. WBUFW(buf,2) = x;
  3153. WBUFW(buf,4) = y;
  3154. WBUFW(buf,6) = type;
  3155. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3156. if( fd )
  3157. {
  3158. WFIFOHEAD(fd,packet_len(0x192));
  3159. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3160. WFIFOSET(fd,packet_len(0x192));
  3161. }
  3162. else
  3163. {
  3164. struct block_list dummy_bl;
  3165. dummy_bl.type = BL_NUL;
  3166. dummy_bl.x = x;
  3167. dummy_bl.y = y;
  3168. dummy_bl.m = m;
  3169. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3170. }
  3171. }
  3172. /*==========================================
  3173. *
  3174. *------------------------------------------*/
  3175. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3176. {
  3177. int view,fd;
  3178. fd=sd->fd;
  3179. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3180. WFIFOHEAD(fd,packet_len(0x9d));
  3181. WFIFOW(fd,0)=0x9d;
  3182. WFIFOL(fd,2)=fitem->bl.id;
  3183. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3184. WFIFOW(fd,6)=view;
  3185. else
  3186. WFIFOW(fd,6)=fitem->item_data.nameid;
  3187. WFIFOB(fd,8)=fitem->item_data.identify;
  3188. WFIFOW(fd,9)=fitem->bl.x;
  3189. WFIFOW(fd,11)=fitem->bl.y;
  3190. WFIFOW(fd,13)=fitem->item_data.amount;
  3191. WFIFOB(fd,15)=fitem->subx;
  3192. WFIFOB(fd,16)=fitem->suby;
  3193. WFIFOSET(fd,packet_len(0x9d));
  3194. }
  3195. /*==========================================
  3196. * 場所スキルエフェクトが視界に入る
  3197. *------------------------------------------*/
  3198. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3199. {
  3200. int fd = sd->fd;
  3201. #if PACKETVER >= 3
  3202. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3203. WFIFOHEAD(fd,packet_len(0x1c9));
  3204. WFIFOW(fd, 0)=0x1c9;
  3205. WFIFOL(fd, 2)=unit->bl.id;
  3206. WFIFOL(fd, 6)=unit->group->src_id;
  3207. WFIFOW(fd,10)=unit->bl.x;
  3208. WFIFOW(fd,12)=unit->bl.y;
  3209. WFIFOB(fd,14)=unit->group->unit_id;
  3210. WFIFOB(fd,15)=1;
  3211. WFIFOB(fd,16)=1;
  3212. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3213. WFIFOSET(fd,packet_len(0x1c9));
  3214. return;
  3215. }
  3216. #endif
  3217. WFIFOHEAD(fd,packet_len(0x11f));
  3218. WFIFOW(fd, 0)=0x11f;
  3219. WFIFOL(fd, 2)=unit->bl.id;
  3220. WFIFOL(fd, 6)=unit->group->src_id;
  3221. WFIFOW(fd,10)=unit->bl.x;
  3222. WFIFOW(fd,12)=unit->bl.y;
  3223. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3224. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3225. else
  3226. WFIFOB(fd,14)=unit->group->unit_id;
  3227. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3228. WFIFOSET(fd,packet_len(0x11f));
  3229. if(unit->group->skill_id == WZ_ICEWALL)
  3230. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3231. }
  3232. /*==========================================
  3233. * 場所スキルエフェクトが視界から消える
  3234. *------------------------------------------*/
  3235. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3236. {
  3237. nullpo_retv(unit);
  3238. WFIFOHEAD(fd,packet_len(0x120));
  3239. WFIFOW(fd, 0)=0x120;
  3240. WFIFOL(fd, 2)=unit->bl.id;
  3241. WFIFOSET(fd,packet_len(0x120));
  3242. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3243. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3244. }
  3245. /*==========================================
  3246. * 場所スキルエフェクト削除
  3247. *------------------------------------------*/
  3248. void clif_skill_delunit(struct skill_unit *unit)
  3249. {
  3250. unsigned char buf[16];
  3251. nullpo_retv(unit);
  3252. WBUFW(buf, 0)=0x120;
  3253. WBUFL(buf, 2)=unit->bl.id;
  3254. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3255. }
  3256. /*==========================================
  3257. * Unknown... trap related?
  3258. * Sent when an object gets ankle-snared
  3259. * Only affects units with class [139,153] client-side
  3260. * R 01ac <object id>.l
  3261. *------------------------------------------*/
  3262. void clif_01ac(struct block_list* bl)
  3263. {
  3264. unsigned char buf[6];
  3265. nullpo_retv(bl);
  3266. WBUFW(buf,0) = 0x1ac;
  3267. WBUFL(buf,2) = bl->id;
  3268. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3269. }
  3270. /*==========================================
  3271. *
  3272. *------------------------------------------*/
  3273. int clif_getareachar(struct block_list* bl,va_list ap)
  3274. {
  3275. struct map_session_data *sd;
  3276. nullpo_retr(0, bl);
  3277. sd=va_arg(ap,struct map_session_data*);
  3278. if (sd == NULL || !sd->fd)
  3279. return 0;
  3280. switch(bl->type){
  3281. case BL_ITEM:
  3282. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3283. break;
  3284. case BL_SKILL:
  3285. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3286. break;
  3287. default:
  3288. if(&sd->bl == bl)
  3289. break;
  3290. clif_getareachar_unit(sd,bl);
  3291. break;
  3292. }
  3293. return 0;
  3294. }
  3295. /*==========================================
  3296. * tbl has gone out of view-size of bl
  3297. *------------------------------------------*/
  3298. int clif_outsight(struct block_list *bl,va_list ap)
  3299. {
  3300. struct block_list *tbl;
  3301. struct view_data *vd;
  3302. TBL_PC *sd, *tsd;
  3303. tbl=va_arg(ap,struct block_list*);
  3304. if(bl == tbl) return 0;
  3305. sd = BL_CAST(BL_PC, bl);
  3306. tsd = BL_CAST(BL_PC, tbl);
  3307. if (tsd && tsd->fd)
  3308. { //tsd has lost sight of the bl object.
  3309. switch(bl->type){
  3310. case BL_PC:
  3311. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3312. clif_clearunit_single(bl->id,0,tsd->fd);
  3313. if(sd->chatID){
  3314. struct chat_data *cd;
  3315. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3316. if(cd->usersd[0]==sd)
  3317. clif_dispchat(cd,tsd->fd);
  3318. }
  3319. if(sd->vender_id)
  3320. clif_closevendingboard(bl,tsd->fd);
  3321. break;
  3322. case BL_ITEM:
  3323. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3324. break;
  3325. case BL_SKILL:
  3326. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3327. break;
  3328. default:
  3329. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3330. clif_clearunit_single(bl->id,0,tsd->fd);
  3331. break;
  3332. }
  3333. }
  3334. if (sd && sd->fd)
  3335. { //sd is watching tbl go out of view.
  3336. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3337. clif_clearunit_single(tbl->id,0,sd->fd);
  3338. }
  3339. return 0;
  3340. }
  3341. /*==========================================
  3342. * tbl has come into view of bl
  3343. *------------------------------------------*/
  3344. int clif_insight(struct block_list *bl,va_list ap)
  3345. {
  3346. struct block_list *tbl;
  3347. TBL_PC *sd, *tsd;
  3348. tbl=va_arg(ap,struct block_list*);
  3349. if (bl == tbl) return 0;
  3350. sd = BL_CAST(BL_PC, bl);
  3351. tsd = BL_CAST(BL_PC, tbl);
  3352. if (tsd && tsd->fd)
  3353. { //Tell tsd that bl entered into his view
  3354. switch(bl->type){
  3355. case BL_ITEM:
  3356. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3357. break;
  3358. case BL_SKILL:
  3359. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3360. break;
  3361. default:
  3362. clif_getareachar_unit(tsd,bl);
  3363. break;
  3364. }
  3365. }
  3366. if (sd && sd->fd)
  3367. { //Tell sd that tbl walked into his view
  3368. clif_getareachar_unit(sd,tbl);
  3369. }
  3370. return 0;
  3371. }
  3372. /*==========================================
  3373. *
  3374. *------------------------------------------*/
  3375. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3376. {
  3377. int fd,id;
  3378. nullpo_retr(0, sd);
  3379. fd=sd->fd;
  3380. if( (id=sd->status.skill[skillid].id) <= 0 )
  3381. return 0;
  3382. WFIFOHEAD(fd,packet_len(0x147));
  3383. WFIFOW(fd,0)=0x147;
  3384. WFIFOW(fd,2) = id;
  3385. if(type < 0)
  3386. WFIFOW(fd,4) = skill_get_inf(id);
  3387. else
  3388. WFIFOW(fd,4) = type;
  3389. WFIFOW(fd,6) = 0;
  3390. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3391. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3392. if(range < 0)
  3393. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3394. WFIFOW(fd,12)= range;
  3395. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3396. if(sd->status.skill[skillid].flag ==0)
  3397. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3398. else
  3399. WFIFOB(fd,38) = 0;
  3400. WFIFOSET(fd,packet_len(0x147));
  3401. return 0;
  3402. }
  3403. /*==========================================
  3404. * スキルリストを送信する
  3405. *------------------------------------------*/
  3406. int clif_skillinfoblock(struct map_session_data *sd)
  3407. {
  3408. int fd;
  3409. int i,c,len,id;
  3410. nullpo_retr(0, sd);
  3411. fd=sd->fd;
  3412. if (!fd) return 0;
  3413. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3414. WFIFOW(fd,0) = 0x10f;
  3415. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3416. {
  3417. if( (id = sd->status.skill[i].id) != 0 )
  3418. {
  3419. WFIFOW(fd,len) = id;
  3420. WFIFOW(fd,len+2) = skill_get_inf(id);
  3421. WFIFOW(fd,len+4) = 0;
  3422. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3423. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3424. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3425. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3426. if(sd->status.skill[i].flag == 0)
  3427. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3428. else
  3429. WFIFOB(fd,len+36) = 0;
  3430. len += 37;
  3431. c++;
  3432. }
  3433. }
  3434. WFIFOW(fd,2)=len;
  3435. WFIFOSET(fd,len);
  3436. return 1;
  3437. }
  3438. /*==========================================
  3439. * スキル割り振り通知
  3440. *------------------------------------------*/
  3441. int clif_skillup(struct map_session_data *sd,int skill_num)
  3442. {
  3443. int fd;
  3444. nullpo_retr(0, sd);
  3445. fd=sd->fd;
  3446. WFIFOHEAD(fd,packet_len(0x10e));
  3447. WFIFOW(fd,0) = 0x10e;
  3448. WFIFOW(fd,2) = skill_num;
  3449. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3450. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3451. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3452. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3453. WFIFOSET(fd,packet_len(0x10e));
  3454. return 0;
  3455. }
  3456. /*==========================================
  3457. * スキル詠唱エフェクトを送信する
  3458. *------------------------------------------*/
  3459. int clif_skillcasting(struct block_list* bl,
  3460. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3461. {
  3462. unsigned char buf[32];
  3463. WBUFW(buf,0) = 0x13e;
  3464. WBUFL(buf,2) = src_id;
  3465. WBUFL(buf,6) = dst_id;
  3466. WBUFW(buf,10) = dst_x;
  3467. WBUFW(buf,12) = dst_y;
  3468. WBUFW(buf,14) = skill_num;
  3469. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3470. WBUFL(buf,20) = casttime;
  3471. if (disguised(bl)) {
  3472. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3473. WBUFL(buf,2) = -src_id;
  3474. clif_send(buf,packet_len(0x13e), bl, SELF);
  3475. } else
  3476. clif_send(buf,packet_len(0x13e), bl, AREA);
  3477. return 0;
  3478. }
  3479. /*==========================================
  3480. *
  3481. *------------------------------------------*/
  3482. int clif_skillcastcancel(struct block_list* bl)
  3483. {
  3484. unsigned char buf[16];
  3485. nullpo_retr(0, bl);
  3486. WBUFW(buf,0) = 0x1b9;
  3487. WBUFL(buf,2) = bl->id;
  3488. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3489. return 0;
  3490. }
  3491. /// only when type==0:
  3492. /// if(skill_id==NV_BASIC)
  3493. /// btype==0 "skill failed" MsgStringTable[159]
  3494. /// btype==1 "no emotions" MsgStringTable[160]
  3495. /// btype==2 "no sit" MsgStringTable[161]
  3496. /// btype==3 "no chat" MsgStringTable[162]
  3497. /// btype==4 "no party" MsgStringTable[163]
  3498. /// btype==5 "no shout" MsgStringTable[164]
  3499. /// btype==6 "no PKing" MsgStringTable[165]
  3500. /// btype==7 "no alligning" MsgStringTable[383]
  3501. /// btype>=8: ignored
  3502. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3503. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3504. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3505. /// otherwise "skill failed" MsgStringTable[204]
  3506. /// btype irrelevant
  3507. /// type==1 "insufficient SP" MsgStringTable[202]
  3508. /// type==2 "insufficient HP" MsgStringTable[203]
  3509. /// type==3 "insufficient materials" MsgStringTable[808]
  3510. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3511. /// type==5 "insufficient zeny" MsgStringTable[233]
  3512. /// type==6 "wrong weapon" MsgStringTable[239]
  3513. /// type==7 "red gemstone needed" MsgStringTable[246]
  3514. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3515. /// type==9 "overweight" MsgStringTable[580]
  3516. /// type==10 "skill failed" MsgStringTable[285]
  3517. /// type>=11 ignored
  3518. ///
  3519. /// if(success!=0) doesn't display any of the previous messages
  3520. /// Note: when this packet is received an unknown flag is always set to 0,
  3521. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3522. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3523. {
  3524. int fd;
  3525. if (!sd) { //Since this is the most common nullpo....
  3526. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3527. return 0;
  3528. }
  3529. fd=sd->fd;
  3530. if (!fd) return 0;
  3531. if(battle_config.display_skill_fail&1)
  3532. return 0; //Disable all skill failed messages
  3533. if(type==0x4 && !sd->state.showdelay)
  3534. return 0; //Disable delay failed messages
  3535. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3536. return 0;
  3537. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3538. return 0;
  3539. WFIFOHEAD(fd,packet_len(0x110));
  3540. WFIFOW(fd,0) = 0x110;
  3541. WFIFOW(fd,2) = skill_id;
  3542. WFIFOL(fd,4) = btype;
  3543. WFIFOB(fd,8) = 0;// success?
  3544. WFIFOB(fd,9) = type;
  3545. WFIFOSET(fd,packet_len(0x110));
  3546. return 1;
  3547. }
  3548. /*==========================================
  3549. * skill attack effect and damage
  3550. * 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
  3551. *------------------------------------------*/
  3552. 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)
  3553. {
  3554. unsigned char buf[64];
  3555. struct status_change *sc;
  3556. nullpo_retr(0, src);
  3557. nullpo_retr(0, dst);
  3558. type = clif_calc_delay(type,div,damage,ddelay);
  3559. sc = status_get_sc(dst);
  3560. if(sc && sc->count) {
  3561. if(sc->data[SC_HALLUCINATION] && damage)
  3562. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3563. }
  3564. #if PACKETVER < 3
  3565. WBUFW(buf,0)=0x114;
  3566. WBUFW(buf,2)=skill_id;
  3567. WBUFL(buf,4)=src->id;
  3568. WBUFL(buf,8)=dst->id;
  3569. WBUFL(buf,12)=tick;
  3570. WBUFL(buf,16)=sdelay;
  3571. WBUFL(buf,20)=ddelay;
  3572. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3573. WBUFW(buf,24)=damage?div:0;
  3574. } else {
  3575. WBUFW(buf,24)=damage;
  3576. }
  3577. WBUFW(buf,26)=skill_lv;
  3578. WBUFW(buf,28)=div;
  3579. WBUFB(buf,30)=type;
  3580. if (disguised(dst)) {
  3581. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3582. WBUFL(buf,8)=-dst->id;
  3583. clif_send(buf,packet_len(0x114),dst,SELF);
  3584. } else
  3585. clif_send(buf,packet_len(0x114),dst,AREA);
  3586. if(disguised(src)) {
  3587. WBUFL(buf,4)=-src->id;
  3588. if (disguised(dst))
  3589. WBUFL(buf,8)=dst->id;
  3590. if(damage > 0)
  3591. WBUFW(buf,24)=-1;
  3592. clif_send(buf,packet_len(0x114),src,SELF);
  3593. }
  3594. #else
  3595. WBUFW(buf,0)=0x1de;
  3596. WBUFW(buf,2)=skill_id;
  3597. WBUFL(buf,4)=src->id;
  3598. WBUFL(buf,8)=dst->id;
  3599. WBUFL(buf,12)=tick;
  3600. WBUFL(buf,16)=sdelay;
  3601. WBUFL(buf,20)=ddelay;
  3602. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3603. WBUFL(buf,24)=damage?div:0;
  3604. } else {
  3605. WBUFL(buf,24)=damage;
  3606. }
  3607. WBUFW(buf,28)=skill_lv;
  3608. WBUFW(buf,30)=div;
  3609. WBUFB(buf,32)=type;
  3610. if (disguised(dst)) {
  3611. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3612. WBUFL(buf,8)=-dst->id;
  3613. clif_send(buf,packet_len(0x1de),dst,SELF);
  3614. } else
  3615. clif_send(buf,packet_len(0x1de),dst,AREA);
  3616. if(disguised(src)) {
  3617. WBUFL(buf,4)=-src->id;
  3618. if (disguised(dst))
  3619. WBUFL(buf,8)=dst->id;
  3620. if(damage > 0)
  3621. WBUFL(buf,24)=-1;
  3622. clif_send(buf,packet_len(0x1de),src,SELF);
  3623. }
  3624. #endif
  3625. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3626. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3627. }
  3628. /*==========================================
  3629. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3630. *------------------------------------------*/
  3631. /*
  3632. 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)
  3633. {
  3634. unsigned char buf[64];
  3635. struct status_change *sc;
  3636. nullpo_retr(0, src);
  3637. nullpo_retr(0, dst);
  3638. type = (type>0)?type:skill_get_hit(skill_id);
  3639. type = clif_calc_delay(type,div,damage,ddelay);
  3640. sc = status_get_sc(dst);
  3641. if(sc && sc->count) {
  3642. if(sc->data[SC_HALLUCINATION] && damage)
  3643. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3644. }
  3645. WBUFW(buf,0)=0x115;
  3646. WBUFW(buf,2)=skill_id;
  3647. WBUFL(buf,4)=src->id;
  3648. WBUFL(buf,8)=dst->id;
  3649. WBUFL(buf,12)=tick;
  3650. WBUFL(buf,16)=sdelay;
  3651. WBUFL(buf,20)=ddelay;
  3652. WBUFW(buf,24)=dst->x;
  3653. WBUFW(buf,26)=dst->y;
  3654. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3655. WBUFW(buf,28)=damage?div:0;
  3656. } else {
  3657. WBUFW(buf,28)=damage;
  3658. }
  3659. WBUFW(buf,30)=skill_lv;
  3660. WBUFW(buf,32)=div;
  3661. WBUFB(buf,34)=type;
  3662. clif_send(buf,packet_len(0x115),src,AREA);
  3663. if(disguised(src)) {
  3664. WBUFL(buf,4)=-src->id;
  3665. if(damage > 0)
  3666. WBUFW(buf,28)=-1;
  3667. clif_send(buf,packet_len(0x115),src,SELF);
  3668. }
  3669. if (disguised(dst)) {
  3670. WBUFL(buf,8)=-dst->id;
  3671. if (disguised(src))
  3672. WBUFL(buf,4)=src->id;
  3673. else if(damage > 0)
  3674. WBUFW(buf,28)=-1;
  3675. clif_send(buf,packet_len(0x115),dst,SELF);
  3676. }
  3677. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3678. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3679. }
  3680. */
  3681. /*==========================================
  3682. * 支援/回復スキルエフェクト
  3683. *------------------------------------------*/
  3684. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3685. {
  3686. unsigned char buf[32];
  3687. nullpo_retr(0, dst);
  3688. WBUFW(buf,0)=0x11a;
  3689. WBUFW(buf,2)=skill_id;
  3690. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3691. WBUFL(buf,6)=dst->id;
  3692. WBUFL(buf,10)=src?src->id:0;
  3693. WBUFB(buf,14)=fail;
  3694. if (disguised(dst)) {
  3695. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3696. WBUFL(buf,6)=-dst->id;
  3697. clif_send(buf,packet_len(0x11a),dst,SELF);
  3698. } else
  3699. clif_send(buf,packet_len(0x11a),dst,AREA);
  3700. if(src && disguised(src)) {
  3701. WBUFL(buf,10)=-src->id;
  3702. if (disguised(dst))
  3703. WBUFL(buf,6)=dst->id;
  3704. clif_send(buf,packet_len(0x11a),src,SELF);
  3705. }
  3706. return fail;
  3707. }
  3708. /*==========================================
  3709. * 場所スキルエフェクト
  3710. *------------------------------------------*/
  3711. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3712. {
  3713. unsigned char buf[32];
  3714. nullpo_retr(0, src);
  3715. WBUFW(buf,0)=0x117;
  3716. WBUFW(buf,2)=skill_id;
  3717. WBUFL(buf,4)=src->id;
  3718. WBUFW(buf,8)=val;
  3719. WBUFW(buf,10)=x;
  3720. WBUFW(buf,12)=y;
  3721. WBUFL(buf,14)=tick;
  3722. if(disguised(src)) {
  3723. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3724. WBUFL(buf,4)=-src->id;
  3725. clif_send(buf,packet_len(0x117),src,SELF);
  3726. } else
  3727. clif_send(buf,packet_len(0x117),src,AREA);
  3728. return 0;
  3729. }
  3730. /*==========================================
  3731. * 場所スキルエフェクト表示
  3732. *------------------------------------------*/
  3733. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3734. void clif_skill_setunit(struct skill_unit *unit)
  3735. {
  3736. unsigned char buf[128];
  3737. nullpo_retv(unit);
  3738. #if PACKETVER >= 3
  3739. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3740. WBUFW(buf, 0)=0x1c9;
  3741. WBUFL(buf, 2)=unit->bl.id;
  3742. WBUFL(buf, 6)=unit->group->src_id;
  3743. WBUFW(buf,10)=unit->bl.x;
  3744. WBUFW(buf,12)=unit->bl.y;
  3745. WBUFB(buf,14)=unit->group->unit_id;
  3746. WBUFB(buf,15)=1;
  3747. WBUFB(buf,16)=1;
  3748. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3749. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3750. return;
  3751. }
  3752. #endif
  3753. WBUFW(buf, 0)=0x11f;
  3754. WBUFL(buf, 2)=unit->bl.id;
  3755. WBUFL(buf, 6)=unit->group->src_id;
  3756. WBUFW(buf,10)=unit->bl.x;
  3757. WBUFW(buf,12)=unit->bl.y;
  3758. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3759. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3760. else
  3761. WBUFB(buf,14)=unit->group->unit_id;
  3762. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3763. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3764. }
  3765. /*==========================================
  3766. * ワープ場所選択
  3767. *------------------------------------------*/
  3768. 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)
  3769. {
  3770. int fd;
  3771. nullpo_retv(sd);
  3772. fd = sd->fd;
  3773. WFIFOHEAD(fd,packet_len(0x11c));
  3774. WFIFOW(fd,0) = 0x11c;
  3775. WFIFOW(fd,2) = skill_num;
  3776. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3777. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3778. else // normal map name
  3779. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3780. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3781. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3782. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3783. WFIFOSET(fd,packet_len(0x11c));
  3784. sd->menuskill_id = skill_num;
  3785. if (skill_num == AL_WARP)
  3786. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3787. else
  3788. sd->menuskill_val = skill_lv;
  3789. }
  3790. /// Memo message.
  3791. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3792. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3793. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3794. ///
  3795. /// @param sd Who receives the message
  3796. /// @param type What message
  3797. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3798. {
  3799. int fd;
  3800. nullpo_retv(sd);
  3801. fd=sd->fd;
  3802. WFIFOHEAD(fd,packet_len(0x11e));
  3803. WFIFOW(fd,0)=0x11e;
  3804. WFIFOB(fd,2)=type;
  3805. WFIFOSET(fd,packet_len(0x11e));
  3806. }
  3807. /// Teleport message.
  3808. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3809. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3810. ///
  3811. /// @param sd Who receives the message
  3812. /// @param type What message
  3813. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3814. {
  3815. int fd;
  3816. nullpo_retv(sd);
  3817. fd=sd->fd;
  3818. WFIFOHEAD(fd,packet_len(0x189));
  3819. WFIFOW(fd,0)=0x189;
  3820. WFIFOW(fd,2)=type;
  3821. WFIFOSET(fd,packet_len(0x189));
  3822. }
  3823. /*==========================================
  3824. * モンスター情報
  3825. *------------------------------------------*/
  3826. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3827. {
  3828. struct status_data *status;
  3829. unsigned char buf[64];
  3830. int i;//, fix;
  3831. nullpo_retr(0, sd);
  3832. nullpo_retr(0, dst);
  3833. if( dst->type != BL_MOB )
  3834. return 0;
  3835. status = status_get_status_data(dst);
  3836. WBUFW(buf, 0)=0x18c;
  3837. WBUFW(buf, 2)=status_get_class(dst);
  3838. WBUFW(buf, 4)=status_get_lv(dst);
  3839. WBUFW(buf, 6)=status->size;
  3840. WBUFL(buf, 8)=status->hp;
  3841. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3842. +(battle_config.estimation_type&2?status->def2:0);
  3843. WBUFW(buf,14)=status->race;
  3844. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3845. +(battle_config.estimation_type&2?status->mdef2:0);
  3846. WBUFW(buf,18)= status->def_ele;
  3847. for(i=0;i<9;i++)
  3848. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  3849. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3850. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3851. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3852. return 0;
  3853. }
  3854. /*==========================================
  3855. * アイテム合成可能リスト
  3856. *------------------------------------------*/
  3857. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3858. {
  3859. int i,c,view,fd;
  3860. nullpo_retr(0, sd);
  3861. if(sd->menuskill_id == AM_PHARMACY)
  3862. return 0; //Avoid resending the menu twice or more times...
  3863. fd=sd->fd;
  3864. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3865. WFIFOW(fd, 0)=0x18d;
  3866. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3867. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3868. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3869. WFIFOW(fd,c*8+ 4)= view;
  3870. else
  3871. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3872. WFIFOW(fd,c*8+ 6)= 0x0012;
  3873. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3874. c++;
  3875. }
  3876. }
  3877. WFIFOW(fd, 2)=c*8+8;
  3878. WFIFOSET(fd,WFIFOW(fd,2));
  3879. if(c > 0) {
  3880. sd->menuskill_id = AM_PHARMACY;
  3881. sd->menuskill_val = trigger;
  3882. return 1;
  3883. }
  3884. return 0;
  3885. }
  3886. /*==========================================
  3887. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3888. *------------------------------------------*/
  3889. int clif_status_load(struct block_list *bl,int type, int flag)
  3890. {
  3891. int fd;
  3892. if (type == SI_BLANK) //It shows nothing on the client...
  3893. return 0;
  3894. if (bl->type != BL_PC)
  3895. return 0;
  3896. fd = ((struct map_session_data*)bl)->fd;
  3897. WFIFOHEAD(fd,packet_len(0x196));
  3898. WFIFOW(fd,0)=0x0196;
  3899. WFIFOW(fd,2)=type;
  3900. WFIFOL(fd,4)=bl->id;
  3901. WFIFOB(fd,8)=flag; //Status start
  3902. WFIFOSET(fd, packet_len(0x196));
  3903. return 0;
  3904. }
  3905. /*==========================================
  3906. * 状態異常アイコン/メッセージ表示
  3907. *------------------------------------------*/
  3908. int clif_status_change(struct block_list *bl,int type,int flag)
  3909. {
  3910. unsigned char buf[16];
  3911. if (type == SI_BLANK) //It shows nothing on the client...
  3912. return 0;
  3913. nullpo_retr(0, bl);
  3914. WBUFW(buf,0)=0x0196;
  3915. WBUFW(buf,2)=type;
  3916. WBUFL(buf,4)=bl->id;
  3917. WBUFB(buf,8)=flag;
  3918. clif_send(buf,packet_len(0x196),bl,AREA);
  3919. return 0;
  3920. }
  3921. /*==========================================
  3922. * Send message (modified by [Yor])
  3923. *------------------------------------------*/
  3924. int clif_displaymessage(const int fd, const char* mes)
  3925. {
  3926. // invalid pointer?
  3927. nullpo_retr(-1, mes);
  3928. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3929. if (fd == 0)
  3930. return 0;
  3931. else {
  3932. int len_mes = strlen(mes);
  3933. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3934. WFIFOHEAD(fd, 5 + len_mes);
  3935. WFIFOW(fd,0) = 0x8e;
  3936. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3937. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3938. WFIFOSET(fd, 5 + len_mes);
  3939. }
  3940. }
  3941. return 0;
  3942. }
  3943. /*==========================================
  3944. * 天の声を送信する
  3945. *------------------------------------------*/
  3946. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3947. {
  3948. unsigned char *buf;
  3949. int lp;
  3950. lp = (flag & 0x10) ? 8 : 4;
  3951. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3952. WBUFW(buf,0) = 0x9a;
  3953. WBUFW(buf,2) = len + lp;
  3954. WBUFL(buf,4) = 0x65756c62; //"blue":
  3955. memcpy(WBUFP(buf,lp), mes, len);
  3956. flag &= 0x07;
  3957. clif_send(buf, WBUFW(buf,2), bl,
  3958. (flag == 1) ? ALL_SAMEMAP :
  3959. (flag == 2) ? AREA :
  3960. (flag == 3) ? SELF :
  3961. ALL_CLIENT);
  3962. if(buf) aFree(buf);
  3963. return 0;
  3964. }
  3965. /*==========================================
  3966. * グローバルメッセージ
  3967. *------------------------------------------*/
  3968. void clif_GlobalMessage(struct block_list* bl, const char* message)
  3969. {
  3970. char buf[100];
  3971. int len;
  3972. nullpo_retv(bl);
  3973. if(!message)
  3974. return;
  3975. len = strlen(message)+1;
  3976. WBUFW(buf,0)=0x8d;
  3977. WBUFW(buf,2)=len+8;
  3978. WBUFL(buf,4)=bl->id;
  3979. strncpy((char *) WBUFP(buf,8),message,len);
  3980. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  3981. }
  3982. /*==========================================
  3983. * Send main chat message [LuzZza]
  3984. *------------------------------------------*/
  3985. void clif_MainChatMessage(const char* message)
  3986. {
  3987. char buf[200];
  3988. int len;
  3989. if(!message)
  3990. return;
  3991. len = strlen(message)+1;
  3992. if (len+8 > sizeof(buf)) {
  3993. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  3994. len = sizeof(buf)-8;
  3995. }
  3996. WBUFW(buf,0)=0x8d;
  3997. WBUFW(buf,2)=len+8;
  3998. WBUFL(buf,4)=0;
  3999. strncpy((char *) WBUFP(buf,8),message,len);
  4000. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4001. }
  4002. /*==========================================
  4003. * Does an announce message in the given color.
  4004. *------------------------------------------*/
  4005. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4006. {
  4007. return clif_announce_ex(bl, mes, len, color, flag, 12);
  4008. }
  4009. int clif_announce_ex(struct block_list* bl, const char* mes, int len, unsigned long color, int flag, int size)
  4010. {
  4011. unsigned char *buf;
  4012. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4013. WBUFW(buf,0) = 0x1c3;
  4014. WBUFW(buf,2) = len + 16;
  4015. WBUFL(buf,4) = color;
  4016. WBUFW(buf,8) = 0x190; //Font style? Type?
  4017. WBUFW(buf,10) = size; // Font size
  4018. WBUFL(buf,12) = 0; //Unknown!
  4019. memcpy(WBUFP(buf,16), mes, len);
  4020. flag &= 0x07;
  4021. clif_send(buf, WBUFW(buf,2), bl,
  4022. (flag == 1) ? ALL_SAMEMAP :
  4023. (flag == 2) ? AREA :
  4024. (flag == 3) ? SELF :
  4025. ALL_CLIENT);
  4026. if(buf) aFree(buf);
  4027. return 0;
  4028. }
  4029. /*==========================================
  4030. * HPSP回復エフェクトを送信する
  4031. *------------------------------------------*/
  4032. int clif_heal(int fd,int type,int val)
  4033. {
  4034. WFIFOHEAD(fd,packet_len(0x13d));
  4035. WFIFOW(fd,0)=0x13d;
  4036. WFIFOW(fd,2)=type;
  4037. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4038. WFIFOSET(fd,packet_len(0x13d));
  4039. return 0;
  4040. }
  4041. /*==========================================
  4042. * 復活する
  4043. *------------------------------------------*/
  4044. int clif_resurrection(struct block_list *bl,int type)
  4045. {
  4046. unsigned char buf[16];
  4047. nullpo_retr(0, bl);
  4048. WBUFW(buf,0)=0x148;
  4049. WBUFL(buf,2)=bl->id;
  4050. WBUFW(buf,6)=type;
  4051. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4052. if (disguised(bl))
  4053. clif_spawn(bl);
  4054. return 0;
  4055. }
  4056. /// Sets the map mode.
  4057. ///
  4058. /// mode=1 : pvp mode
  4059. /// mode=2 : unknown mode (pk?)
  4060. /// mode=3 : gvg mode
  4061. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4062. /// mode=5 : pvp mode
  4063. /// mode=other : ?
  4064. void clif_set0199(struct map_session_data* sd, int mode)
  4065. {
  4066. int fd;
  4067. nullpo_retv(sd);
  4068. fd=sd->fd;
  4069. WFIFOHEAD(fd,packet_len(0x199));
  4070. WFIFOW(fd,0)=0x199;
  4071. WFIFOW(fd,2)=mode;
  4072. WFIFOSET(fd,packet_len(0x199));
  4073. }
  4074. #if 0
  4075. /// Set the map mode?
  4076. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4077. void clif_set01D6(struct map_session_data* sd, int mode)
  4078. {
  4079. int fd;
  4080. nullpo_retv(sd);
  4081. fd=sd->fd;
  4082. WFIFOHEAD(fd,packet_len(0x1D6));
  4083. WFIFOW(fd,0)=0x1D6;
  4084. WFIFOW(fd,2)=mode;
  4085. WFIFOSET(fd,packet_len(0x1D6));
  4086. }
  4087. #endif
  4088. /*==========================================
  4089. * PVP実装?(仮)
  4090. *------------------------------------------*/
  4091. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4092. {
  4093. if(type == 2) {
  4094. int fd = sd->fd;
  4095. WFIFOHEAD(fd,packet_len(0x19a));
  4096. WFIFOW(fd,0) = 0x19a;
  4097. WFIFOL(fd,2) = sd->bl.id;
  4098. WFIFOL(fd,6) = pvprank;
  4099. WFIFOL(fd,10) = pvpnum;
  4100. WFIFOSET(fd,packet_len(0x19a));
  4101. } else {
  4102. unsigned char buf[32];
  4103. WBUFW(buf,0) = 0x19a;
  4104. WBUFL(buf,2) = sd->bl.id;
  4105. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4106. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4107. else
  4108. WBUFL(buf,6) = pvprank;
  4109. WBUFL(buf,10) = pvpnum;
  4110. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4111. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4112. else if(!type)
  4113. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4114. else
  4115. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4116. }
  4117. return 0;
  4118. }
  4119. /*==========================================
  4120. *
  4121. *------------------------------------------*/
  4122. int clif_send0199(int map,int type)
  4123. {
  4124. struct block_list bl;
  4125. unsigned char buf[16];
  4126. bl.id = 0;
  4127. bl.type = BL_NUL;
  4128. bl.m = map;
  4129. WBUFW(buf,0)=0x199;
  4130. WBUFW(buf,2)=type;
  4131. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4132. return 0;
  4133. }
  4134. /*==========================================
  4135. * 精錬エフェクトを送信する
  4136. *------------------------------------------*/
  4137. void clif_refine(int fd, int fail, int index, int val)
  4138. {
  4139. WFIFOHEAD(fd,packet_len(0x188));
  4140. WFIFOW(fd,0)=0x188;
  4141. WFIFOW(fd,2)=fail;
  4142. WFIFOW(fd,4)=index+2;
  4143. WFIFOW(fd,6)=val;
  4144. WFIFOSET(fd,packet_len(0x188));
  4145. }
  4146. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4147. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4148. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4149. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4150. void clif_upgrademessage(int fd, int result, int item_id)
  4151. {
  4152. WFIFOHEAD(fd,packet_len(0x223));
  4153. WFIFOW(fd,0)=0x223;
  4154. WFIFOL(fd,2)=result;
  4155. WFIFOW(fd,6)=item_id;
  4156. WFIFOSET(fd,packet_len(0x223));
  4157. }
  4158. /*==========================================
  4159. * Wisp/page is transmitted to the destination player
  4160. * R 0097 <len>.w <nick>.24B <message>.?B
  4161. *------------------------------------------*/
  4162. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4163. {
  4164. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4165. WFIFOW(fd,0) = 0x97;
  4166. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4167. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4168. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4169. WFIFOSET(fd,WFIFOW(fd,2));
  4170. return 0;
  4171. }
  4172. /*==========================================
  4173. * Inform the player about the result of his whisper action
  4174. * R 0098 <type>.B
  4175. * 0: success to send wisper
  4176. * 1: target character is not loged in
  4177. * 2: ignored by target
  4178. * 3: everyone ignored by target
  4179. *------------------------------------------*/
  4180. int clif_wis_end(int fd, int flag)
  4181. {
  4182. WFIFOHEAD(fd,packet_len(0x98));
  4183. WFIFOW(fd,0) = 0x98;
  4184. WFIFOW(fd,2) = flag;
  4185. WFIFOSET(fd,packet_len(0x98));
  4186. return 0;
  4187. }
  4188. /*==========================================
  4189. * キャラID名前引き結果を送信する
  4190. *------------------------------------------*/
  4191. int clif_solved_charname(int fd, int charid, const char* name)
  4192. {
  4193. WFIFOHEAD(fd,packet_len(0x194));
  4194. WFIFOW(fd,0)=0x194;
  4195. WFIFOL(fd,2)=charid;
  4196. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4197. WFIFOSET(fd,packet_len(0x194));
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. * カードの挿入可能リストを返す
  4202. *------------------------------------------*/
  4203. int clif_use_card(struct map_session_data *sd,int idx)
  4204. {
  4205. int i,c,ep;
  4206. int fd=sd->fd;
  4207. nullpo_retr(0, sd);
  4208. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4209. return 0;
  4210. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4211. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4212. ep=sd->inventory_data[idx]->equip;
  4213. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4214. WFIFOW(fd,0)=0x017b;
  4215. for(i=c=0;i<MAX_INVENTORY;i++){
  4216. int j;
  4217. if(sd->inventory_data[i] == NULL)
  4218. continue;
  4219. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4220. continue;
  4221. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4222. continue;
  4223. if(sd->status.inventory[i].identify==0 ) //Not identified
  4224. continue;
  4225. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4226. continue;
  4227. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4228. continue;
  4229. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4230. if( j == sd->inventory_data[i]->slot ) // No room
  4231. continue;
  4232. WFIFOW(fd,4+c*2)=i+2;
  4233. c++;
  4234. }
  4235. WFIFOW(fd,2)=4+c*2;
  4236. WFIFOSET(fd,WFIFOW(fd,2));
  4237. return 0;
  4238. }
  4239. /*==========================================
  4240. * カードの挿入終了
  4241. *------------------------------------------*/
  4242. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4243. {
  4244. int fd;
  4245. nullpo_retr(0, sd);
  4246. fd=sd->fd;
  4247. WFIFOHEAD(fd,packet_len(0x17d));
  4248. WFIFOW(fd,0)=0x17d;
  4249. WFIFOW(fd,2)=idx_equip+2;
  4250. WFIFOW(fd,4)=idx_card+2;
  4251. WFIFOB(fd,6)=flag;
  4252. WFIFOSET(fd,packet_len(0x17d));
  4253. return 0;
  4254. }
  4255. /*==========================================
  4256. * 鑑定可能アイテムリスト送信
  4257. *------------------------------------------*/
  4258. int clif_item_identify_list(struct map_session_data *sd)
  4259. {
  4260. int i,c;
  4261. int fd;
  4262. nullpo_retr(0, sd);
  4263. fd=sd->fd;
  4264. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4265. WFIFOW(fd,0)=0x177;
  4266. for(i=c=0;i<MAX_INVENTORY;i++){
  4267. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4268. WFIFOW(fd,c*2+4)=i+2;
  4269. c++;
  4270. }
  4271. }
  4272. if(c > 0) {
  4273. WFIFOW(fd,2)=c*2+4;
  4274. WFIFOSET(fd,WFIFOW(fd,2));
  4275. sd->menuskill_id = MC_IDENTIFY;
  4276. sd->menuskill_val = c;
  4277. }
  4278. return 0;
  4279. }
  4280. /*==========================================
  4281. * 鑑定結果
  4282. *------------------------------------------*/
  4283. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4284. {
  4285. int fd;
  4286. nullpo_retr(0, sd);
  4287. fd=sd->fd;
  4288. WFIFOHEAD(fd,packet_len(0x179));
  4289. WFIFOW(fd, 0)=0x179;
  4290. WFIFOW(fd, 2)=idx+2;
  4291. WFIFOB(fd, 4)=flag;
  4292. WFIFOSET(fd,packet_len(0x179));
  4293. return 0;
  4294. }
  4295. /*==========================================
  4296. * 修理可能アイテムリスト送信
  4297. *------------------------------------------*/
  4298. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4299. {
  4300. int i,c;
  4301. int fd;
  4302. int nameid;
  4303. nullpo_retr(0, sd);
  4304. nullpo_retr(0, dstsd);
  4305. fd=sd->fd;
  4306. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4307. WFIFOW(fd,0)=0x1fc;
  4308. for(i=c=0;i<MAX_INVENTORY;i++){
  4309. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4310. WFIFOW(fd,c*13+4) = i;
  4311. WFIFOW(fd,c*13+6) = nameid;
  4312. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4313. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4314. WFIFOB(fd,c*13+16)= c;
  4315. c++;
  4316. }
  4317. }
  4318. if(c > 0) {
  4319. WFIFOW(fd,2)=c*13+4;
  4320. WFIFOSET(fd,WFIFOW(fd,2));
  4321. sd->menuskill_id = BS_REPAIRWEAPON;
  4322. sd->menuskill_val = dstsd->bl.id;
  4323. }else
  4324. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4325. return 0;
  4326. }
  4327. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4328. {
  4329. int view,fd;
  4330. nullpo_retr(0, sd);
  4331. fd=sd->fd;
  4332. WFIFOHEAD(fd,packet_len(0x1fe));
  4333. WFIFOW(fd, 0)=0x1fe;
  4334. if((view = itemdb_viewid(nameid)) > 0)
  4335. WFIFOW(fd, 2)=view;
  4336. else
  4337. WFIFOW(fd, 2)=nameid;
  4338. WFIFOB(fd, 4)=flag;
  4339. WFIFOSET(fd,packet_len(0x1fe));
  4340. return 0;
  4341. }
  4342. /*==========================================
  4343. * Weapon Refining - Taken from jAthena
  4344. *------------------------------------------*/
  4345. int clif_item_refine_list(struct map_session_data *sd)
  4346. {
  4347. int i,c;
  4348. int fd;
  4349. int skilllv;
  4350. int wlv;
  4351. int refine_item[5];
  4352. nullpo_retr(0, sd);
  4353. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4354. fd=sd->fd;
  4355. refine_item[0] = -1;
  4356. refine_item[1] = pc_search_inventory(sd,1010);
  4357. refine_item[2] = pc_search_inventory(sd,1011);
  4358. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4359. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4360. WFIFOW(fd,0)=0x221;
  4361. for(i=c=0;i<MAX_INVENTORY;i++){
  4362. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4363. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4364. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4365. WFIFOW(fd,c*13+ 4)=i+2;
  4366. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4367. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4368. WFIFOW(fd,c*13+10)=0;
  4369. WFIFOB(fd,c*13+12)=c;
  4370. c++;
  4371. }
  4372. }
  4373. WFIFOW(fd,2)=c*13+4;
  4374. WFIFOSET(fd,WFIFOW(fd,2));
  4375. if (c > 0) {
  4376. sd->menuskill_id = WS_WEAPONREFINE;
  4377. sd->menuskill_val = skilllv;
  4378. }
  4379. return 0;
  4380. }
  4381. /*==========================================
  4382. * アイテムによる一時的なスキル効果
  4383. *------------------------------------------*/
  4384. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4385. {
  4386. int fd;
  4387. nullpo_retr(0, sd);
  4388. fd=sd->fd;
  4389. WFIFOHEAD(fd,packet_len(0x147));
  4390. WFIFOW(fd, 0)=0x147;
  4391. WFIFOW(fd, 2)=skillid;
  4392. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4393. WFIFOW(fd, 6)=0;
  4394. WFIFOW(fd, 8)=skilllv;
  4395. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4396. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4397. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4398. WFIFOB(fd,38)=0;
  4399. WFIFOSET(fd,packet_len(0x147));
  4400. return 0;
  4401. }
  4402. /*==========================================
  4403. * カートにアイテム追加
  4404. *------------------------------------------*/
  4405. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4406. {
  4407. int view,fd;
  4408. unsigned char *buf;
  4409. nullpo_retr(0, sd);
  4410. fd=sd->fd;
  4411. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4412. return 1;
  4413. #if PACKETVER < 5
  4414. WFIFOHEAD(fd,packet_len(0x124));
  4415. buf=WFIFOP(fd,0);
  4416. WBUFW(buf,0)=0x124;
  4417. WBUFW(buf,2)=n+2;
  4418. WBUFL(buf,4)=amount;
  4419. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4420. WBUFW(buf,8)=view;
  4421. else
  4422. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4423. WBUFB(buf,10)=sd->status.cart[n].identify;
  4424. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4425. WBUFB(buf,12)=sd->status.cart[n].refine;
  4426. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4427. WFIFOSET(fd,packet_len(0x124));
  4428. #else
  4429. WFIFOHEAD(fd,packet_len(0x1c5));
  4430. buf=WFIFOP(fd,0);
  4431. WBUFW(buf,0)=0x1c5;
  4432. WBUFW(buf,2)=n+2;
  4433. WBUFL(buf,4)=amount;
  4434. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4435. WBUFW(buf,8)=view;
  4436. else
  4437. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4438. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4439. WBUFB(buf,11)=sd->status.cart[n].identify;
  4440. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4441. WBUFB(buf,13)=sd->status.cart[n].refine;
  4442. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4443. WFIFOSET(fd,packet_len(0x1c5));
  4444. #endif
  4445. return 0;
  4446. }
  4447. /*==========================================
  4448. * カートからアイテム削除
  4449. *------------------------------------------*/
  4450. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4451. {
  4452. int fd;
  4453. nullpo_retr(0, sd);
  4454. fd=sd->fd;
  4455. WFIFOHEAD(fd,packet_len(0x125));
  4456. WFIFOW(fd,0)=0x125;
  4457. WFIFOW(fd,2)=n+2;
  4458. WFIFOL(fd,4)=amount;
  4459. WFIFOSET(fd,packet_len(0x125));
  4460. return 0;
  4461. }
  4462. /*==========================================
  4463. * Opens the shop creation menu.
  4464. * R 012d <num>.w
  4465. * 'num' is the number of allowed item slots
  4466. *------------------------------------------*/
  4467. void clif_openvendingreq(struct map_session_data* sd, int num)
  4468. {
  4469. int fd;
  4470. nullpo_retv(sd);
  4471. fd = sd->fd;
  4472. WFIFOHEAD(fd,packet_len(0x12d));
  4473. WFIFOW(fd,0) = 0x12d;
  4474. WFIFOW(fd,2) = num;
  4475. WFIFOSET(fd,packet_len(0x12d));
  4476. }
  4477. /*==========================================
  4478. * Displays a vending board to target/area
  4479. * R 0131 <ID>.l <message>.80B
  4480. *------------------------------------------*/
  4481. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4482. {
  4483. unsigned char buf[128];
  4484. nullpo_retv(bl);
  4485. WBUFW(buf,0) = 0x131;
  4486. WBUFL(buf,2) = bl->id;
  4487. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4488. if( fd ) {
  4489. WFIFOHEAD(fd,packet_len(0x131));
  4490. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4491. WFIFOSET(fd,packet_len(0x131));
  4492. } else {
  4493. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4494. }
  4495. }
  4496. /*==========================================
  4497. * Removes a vending board from screen
  4498. *------------------------------------------*/
  4499. void clif_closevendingboard(struct block_list* bl, int fd)
  4500. {
  4501. unsigned char buf[16];
  4502. nullpo_retv(bl);
  4503. WBUFW(buf,0) = 0x132;
  4504. WBUFL(buf,2) = bl->id;
  4505. if( fd ) {
  4506. WFIFOHEAD(fd,packet_len(0x132));
  4507. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4508. WFIFOSET(fd,packet_len(0x132));
  4509. } else {
  4510. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4511. }
  4512. }
  4513. /*==========================================
  4514. * Sends a list of items in a shop
  4515. * 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
  4516. *------------------------------------------*/
  4517. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4518. {
  4519. int i,fd;
  4520. int count;
  4521. struct map_session_data* vsd;
  4522. nullpo_retv(sd);
  4523. nullpo_retv(vending);
  4524. nullpo_retv(vsd=map_id2sd(id));
  4525. fd = sd->fd;
  4526. count = vsd->vend_num;
  4527. WFIFOHEAD(fd, 8+count*22);
  4528. WFIFOW(fd,0) = 0x133;
  4529. WFIFOW(fd,2) = 8+count*22;
  4530. WFIFOL(fd,4) = id;
  4531. for( i = 0; i < count; i++ )
  4532. {
  4533. int index = vending[i].index;
  4534. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4535. WFIFOL(fd, 8+i*22) = vending[i].value;
  4536. WFIFOW(fd,12+i*22) = vending[i].amount;
  4537. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4538. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4539. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4540. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4541. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4542. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4543. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4544. }
  4545. WFIFOSET(fd,WFIFOW(fd,2));
  4546. }
  4547. /*==========================================
  4548. * Shop purchase failure
  4549. * R 0135 <index>.w <amount>.w <fail>.B
  4550. * fail=1 - not enough zeny
  4551. * fail=2 - overweight
  4552. * fail=4 - out of stock
  4553. * fail=5 - "cannot use an npc shop while in a trade"
  4554. *------------------------------------------*/
  4555. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4556. {
  4557. int fd;
  4558. nullpo_retv(sd);
  4559. fd = sd->fd;
  4560. WFIFOHEAD(fd,packet_len(0x135));
  4561. WFIFOW(fd,0) = 0x135;
  4562. WFIFOW(fd,2) = index+2;
  4563. WFIFOW(fd,4) = amount;
  4564. WFIFOB(fd,6) = fail;
  4565. WFIFOSET(fd,packet_len(0x135));
  4566. }
  4567. /*==========================================
  4568. * Shop creation success
  4569. * 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*
  4570. *------------------------------------------*/
  4571. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4572. {
  4573. int i,fd;
  4574. int count;
  4575. nullpo_retv(sd);
  4576. fd = sd->fd;
  4577. count = sd->vend_num;
  4578. WFIFOHEAD(fd, 8+count*22);
  4579. WFIFOW(fd,0) = 0x136;
  4580. WFIFOW(fd,2) = 8+count*22;
  4581. WFIFOL(fd,4) = id;
  4582. for( i = 0; i < count; i++ )
  4583. {
  4584. int index = vending[i].index;
  4585. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4586. WFIFOL(fd, 8+i*22) = vending[i].value;
  4587. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4588. WFIFOW(fd,14+i*22) = vending[i].amount;
  4589. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4590. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4591. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4592. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4593. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4594. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4595. }
  4596. WFIFOSET(fd,WFIFOW(fd,2));
  4597. }
  4598. /*==========================================
  4599. * Inform merchant that someone has bought an item.
  4600. * R 0137 <index>.w <amount>.w
  4601. *------------------------------------------*/
  4602. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4603. {
  4604. int fd;
  4605. nullpo_retv(sd);
  4606. fd = sd->fd;
  4607. WFIFOHEAD(fd,packet_len(0x137));
  4608. WFIFOW(fd,0) = 0x137;
  4609. WFIFOW(fd,2) = index+2;
  4610. WFIFOW(fd,4) = amount;
  4611. WFIFOSET(fd,packet_len(0x137));
  4612. }
  4613. /// Result of organizing a party.
  4614. /// R 00FA <result>.B
  4615. ///
  4616. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4617. /// result=1 : MsgStringTable[78]="party name already exists"
  4618. /// result=2 : MsgStringTable[79]="already in a party"
  4619. /// result=other : nothing
  4620. int clif_party_created(struct map_session_data *sd,int result)
  4621. {
  4622. int fd;
  4623. nullpo_retr(0, sd);
  4624. fd=sd->fd;
  4625. WFIFOHEAD(fd,packet_len(0xfa));
  4626. WFIFOW(fd,0)=0xfa;
  4627. WFIFOB(fd,2)=result;
  4628. WFIFOSET(fd,packet_len(0xfa));
  4629. return 0;
  4630. }
  4631. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4632. {
  4633. unsigned char buf[96];
  4634. int i;
  4635. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4636. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4637. } else {
  4638. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4639. }
  4640. if (i >= MAX_PARTY) return 0; //Should never happen...
  4641. sd = p->data[i].sd;
  4642. WBUFW(buf, 0) = 0x1e9;
  4643. WBUFL(buf, 2) = sd->status.account_id;
  4644. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4645. WBUFW(buf,10) = sd->bl.x;
  4646. WBUFW(buf,12) = sd->bl.y;
  4647. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4648. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4649. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4650. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4651. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4652. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4653. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4654. return 1;
  4655. }
  4656. /*==========================================
  4657. * Sends party information
  4658. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4659. *------------------------------------------*/
  4660. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4661. {
  4662. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4663. struct map_session_data* party_sd = NULL;
  4664. int i, c;
  4665. nullpo_retr(0, p);
  4666. WBUFW(buf,0) = 0xfb;
  4667. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4668. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4669. {
  4670. struct party_member* m = &p->party.member[i];
  4671. if(!m->account_id) continue;
  4672. if(party_sd == NULL) party_sd = p->data[i].sd;
  4673. WBUFL(buf,28+c*46) = m->account_id;
  4674. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4675. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4676. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4677. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4678. c++;
  4679. }
  4680. WBUFW(buf,2) = 28+c*46;
  4681. if(sd) { // send only to self
  4682. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4683. } else if (party_sd) { // send to whole party
  4684. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4685. }
  4686. return 0;
  4687. }
  4688. /*==========================================
  4689. * パーティ勧誘
  4690. *------------------------------------------*/
  4691. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4692. {
  4693. int fd;
  4694. struct party_data *p;
  4695. nullpo_retr(0, sd);
  4696. nullpo_retr(0, tsd);
  4697. fd=tsd->fd;
  4698. if( (p=party_search(sd->status.party_id))==NULL )
  4699. return 0;
  4700. WFIFOHEAD(fd,packet_len(0xfe));
  4701. WFIFOW(fd,0)=0xfe;
  4702. WFIFOL(fd,2)=sd->status.account_id;
  4703. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4704. WFIFOSET(fd,packet_len(0xfe));
  4705. return 0;
  4706. }
  4707. /*==========================================
  4708. * Party invitation result.
  4709. * R 00fd <nick>.24S <flag>.B
  4710. * R 02c5 <nick>.24S <flag>.L
  4711. * Flag values are:
  4712. * 0 -> char is already in a party
  4713. * 1 -> party invite was rejected
  4714. * 2 -> party invite was accepted
  4715. * 3 -> party is full
  4716. * 4 -> char of the same account already joined the party
  4717. *------------------------------------------*/
  4718. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4719. {
  4720. int fd;
  4721. nullpo_retv(sd);
  4722. fd=sd->fd;
  4723. #if PACKETVER < 20070821
  4724. WFIFOHEAD(fd,packet_len(0xfd));
  4725. WFIFOW(fd,0) = 0xfd;
  4726. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4727. WFIFOB(fd,26) = flag;
  4728. WFIFOSET(fd,packet_len(0xfd));
  4729. #else
  4730. WFIFOHEAD(fd,packet_len(0x2c5));
  4731. WFIFOW(fd,0) = 0x2c5;
  4732. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4733. WFIFOL(fd,26) = flag;
  4734. WFIFOSET(fd,packet_len(0x2c5));
  4735. #endif
  4736. }
  4737. /*==========================================
  4738. * パーティ設定送信
  4739. * flag & 0x001=exp変更ミス
  4740. * 0x010=item変更ミス
  4741. * 0x100=一人にのみ送信
  4742. *------------------------------------------*/
  4743. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4744. {
  4745. unsigned char buf[16];
  4746. nullpo_retr(0, p);
  4747. if(!sd && flag==0){
  4748. int i;
  4749. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4750. if (i < MAX_PARTY)
  4751. sd = p->data[i].sd;
  4752. }
  4753. if(!sd) return 0;
  4754. WBUFW(buf,0)=0x101;
  4755. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4756. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4757. WBUFW(buf,4)=0;
  4758. if(flag==0)
  4759. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4760. else
  4761. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4762. return 0;
  4763. }
  4764. /*==========================================
  4765. * パーティ脱退(脱退前に呼ぶこと)
  4766. *------------------------------------------*/
  4767. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4768. {
  4769. unsigned char buf[64];
  4770. int i;
  4771. nullpo_retr(0, p);
  4772. if(!sd && (flag&0xf0)==0)
  4773. {
  4774. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4775. if (i < MAX_PARTY)
  4776. sd = p->data[i].sd;
  4777. }
  4778. if(!sd) return 0;
  4779. WBUFW(buf,0)=0x105;
  4780. WBUFL(buf,2)=account_id;
  4781. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4782. WBUFB(buf,30)=flag&0x0f;
  4783. if((flag&0xf0)==0)
  4784. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4785. else
  4786. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4787. return 0;
  4788. }
  4789. /*==========================================
  4790. * パーティメッセージ送信
  4791. *------------------------------------------*/
  4792. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4793. {
  4794. struct map_session_data *sd;
  4795. int i;
  4796. nullpo_retr(0, p);
  4797. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4798. if(i < MAX_PARTY){
  4799. unsigned char buf[1024];
  4800. sd = p->data[i].sd;
  4801. WBUFW(buf,0)=0x109;
  4802. WBUFW(buf,2)=len+8;
  4803. WBUFL(buf,4)=account_id;
  4804. memcpy(WBUFP(buf,8),mes,len);
  4805. clif_send(buf,len+8,&sd->bl,PARTY);
  4806. }
  4807. return 0;
  4808. }
  4809. /*==========================================
  4810. * パーティ座標通知
  4811. *------------------------------------------*/
  4812. int clif_party_xy(struct map_session_data *sd)
  4813. {
  4814. unsigned char buf[16];
  4815. nullpo_retr(0, sd);
  4816. WBUFW(buf,0)=0x107;
  4817. WBUFL(buf,2)=sd->status.account_id;
  4818. WBUFW(buf,6)=sd->bl.x;
  4819. WBUFW(buf,8)=sd->bl.y;
  4820. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4821. return 0;
  4822. }
  4823. /*==========================================
  4824. * Sends x/y dot to a single fd. [Skotlex]
  4825. *------------------------------------------*/
  4826. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4827. {
  4828. WFIFOHEAD(fd,packet_len(0x107));
  4829. WFIFOW(fd,0)=0x107;
  4830. WFIFOL(fd,2)=sd->status.account_id;
  4831. WFIFOW(fd,6)=sd->bl.x;
  4832. WFIFOW(fd,8)=sd->bl.y;
  4833. WFIFOSET(fd,packet_len(0x107));
  4834. return 0;
  4835. }
  4836. /*==========================================
  4837. * パーティHP通知
  4838. *------------------------------------------*/
  4839. int clif_party_hp(struct map_session_data *sd)
  4840. {
  4841. unsigned char buf[16];
  4842. nullpo_retr(0, sd);
  4843. WBUFW(buf,0)=0x106;
  4844. WBUFL(buf,2)=sd->status.account_id;
  4845. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4846. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4847. WBUFW(buf,8) = 100;
  4848. } else {
  4849. WBUFW(buf,6) = sd->battle_status.hp;
  4850. WBUFW(buf,8) = sd->battle_status.max_hp;
  4851. }
  4852. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4853. return 0;
  4854. }
  4855. /*==========================================
  4856. * Sends HP bar to a single fd. [Skotlex]
  4857. *------------------------------------------*/
  4858. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4859. {
  4860. WFIFOHEAD(fd,packet_len(0x106));
  4861. WFIFOW(fd,0) = 0x106;
  4862. WFIFOL(fd,2) = id;
  4863. if( maxhp > SHRT_MAX )
  4864. {// To correctly display the %hp bar. [Skotlex]
  4865. WFIFOW(fd,6) = hp/(maxhp/100);
  4866. WFIFOW(fd,8) = 100;
  4867. } else {
  4868. WFIFOW(fd,6) = hp;
  4869. WFIFOW(fd,8) = maxhp;
  4870. }
  4871. WFIFOSET(fd, packet_len(0x106));
  4872. }
  4873. /*==========================================
  4874. * GMへ場所とHP通知
  4875. *------------------------------------------*/
  4876. int clif_hpmeter(struct map_session_data *sd)
  4877. {
  4878. struct map_session_data *sd2;
  4879. unsigned char buf[16];
  4880. int i, x0, y0, x1, y1;
  4881. int level;
  4882. nullpo_retr(0, sd);
  4883. x0 = sd->bl.x - AREA_SIZE;
  4884. y0 = sd->bl.y - AREA_SIZE;
  4885. x1 = sd->bl.x + AREA_SIZE;
  4886. y1 = sd->bl.y + AREA_SIZE;
  4887. WBUFW(buf,0) = 0x106;
  4888. WBUFL(buf,2) = sd->status.account_id;
  4889. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4890. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4891. WBUFW(buf,8) = 100;
  4892. } else {
  4893. WBUFW(buf,6) = sd->battle_status.hp;
  4894. WBUFW(buf,8) = sd->battle_status.max_hp;
  4895. }
  4896. for (i = 0; i < fd_max; i++) {
  4897. if (session[i] && session[i]->func_parse == clif_parse &&
  4898. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4899. sd != sd2 && sd2->state.active) {
  4900. if (sd2->bl.m != sd->bl.m ||
  4901. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4902. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4903. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4904. level < pc_isGM(sd))
  4905. continue;
  4906. WFIFOHEAD (i, packet_len(0x106));
  4907. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4908. WFIFOSET (i, packet_len(0x106));
  4909. }
  4910. }
  4911. return 0;
  4912. }
  4913. /*==========================================
  4914. * パーティ場所移動(未使用)
  4915. *------------------------------------------*/
  4916. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4917. {
  4918. unsigned char buf[128];
  4919. nullpo_retv(sd);
  4920. nullpo_retv(p);
  4921. WBUFW(buf, 0) = 0x104;
  4922. WBUFL(buf, 2) = sd->status.account_id;
  4923. WBUFL(buf, 6) = 0;
  4924. WBUFW(buf,10) = sd->bl.x;
  4925. WBUFW(buf,12) = sd->bl.y;
  4926. WBUFB(buf,14) = !online;
  4927. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4928. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4929. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4930. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4931. }
  4932. /*==========================================
  4933. * 攻撃するために移動が必要
  4934. *------------------------------------------*/
  4935. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4936. {
  4937. int fd;
  4938. nullpo_retr(0, sd);
  4939. nullpo_retr(0, bl);
  4940. fd=sd->fd;
  4941. WFIFOHEAD(fd,packet_len(0x139));
  4942. WFIFOW(fd, 0)=0x139;
  4943. WFIFOL(fd, 2)=bl->id;
  4944. WFIFOW(fd, 6)=bl->x;
  4945. WFIFOW(fd, 8)=bl->y;
  4946. WFIFOW(fd,10)=sd->bl.x;
  4947. WFIFOW(fd,12)=sd->bl.y;
  4948. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4949. WFIFOSET(fd,packet_len(0x139));
  4950. return 0;
  4951. }
  4952. /*==========================================
  4953. * 製造エフェクト
  4954. *------------------------------------------*/
  4955. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4956. {
  4957. int view,fd;
  4958. nullpo_retr(0, sd);
  4959. fd = sd->fd;
  4960. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4961. WFIFOHEAD(fd,packet_len(0x18f));
  4962. WFIFOW(fd, 0)=0x18f;
  4963. WFIFOW(fd, 2)=flag;
  4964. if((view = itemdb_viewid(nameid)) > 0)
  4965. WFIFOW(fd, 4)=view;
  4966. else
  4967. WFIFOW(fd, 4)=nameid;
  4968. WFIFOSET(fd,packet_len(0x18f));
  4969. return 0;
  4970. }
  4971. // pet
  4972. int clif_catch_process(struct map_session_data *sd)
  4973. {
  4974. int fd;
  4975. nullpo_retr(0, sd);
  4976. fd=sd->fd;
  4977. WFIFOHEAD(fd,packet_len(0x19e));
  4978. WFIFOW(fd,0)=0x19e;
  4979. WFIFOSET(fd,packet_len(0x19e));
  4980. return 0;
  4981. }
  4982. int clif_pet_roulette(struct map_session_data *sd,int data)
  4983. {
  4984. int fd;
  4985. nullpo_retr(0, sd);
  4986. fd=sd->fd;
  4987. WFIFOHEAD(fd,packet_len(0x1a0));
  4988. WFIFOW(fd,0)=0x1a0;
  4989. WFIFOB(fd,2)=data;
  4990. WFIFOSET(fd,packet_len(0x1a0));
  4991. return 0;
  4992. }
  4993. /*==========================================
  4994. * pet卵リスト作成
  4995. *------------------------------------------*/
  4996. int clif_sendegg(struct map_session_data *sd)
  4997. {
  4998. //R 01a6 <len>.w <index>.w*
  4999. int i,n=0,fd;
  5000. nullpo_retr(0, sd);
  5001. fd=sd->fd;
  5002. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5003. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5004. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5005. return 0;
  5006. }
  5007. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5008. WFIFOW(fd,0)=0x1a6;
  5009. if(sd->status.pet_id <= 0) {
  5010. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5011. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5012. sd->inventory_data[i]->type!=IT_PETEGG ||
  5013. sd->status.inventory[i].amount<=0)
  5014. continue;
  5015. WFIFOW(fd,n*2+4)=i+2;
  5016. n++;
  5017. }
  5018. }
  5019. WFIFOW(fd,2)=4+n*2;
  5020. WFIFOSET(fd,WFIFOW(fd,2));
  5021. sd->menuskill_id = SA_TAMINGMONSTER;
  5022. sd->menuskill_val = -1;
  5023. return 0;
  5024. }
  5025. /*==========================================
  5026. * Sends a specific pet data update.
  5027. * type = 0 -> param = 0 (initial data)
  5028. * type = 1 -> param = intimacy value
  5029. * type = 2 -> param = hungry value
  5030. * type = 3 -> param = accessory id
  5031. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5032. * type = 5 -> param = hairstyle number
  5033. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5034. *------------------------------------------*/
  5035. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5036. {
  5037. uint8 buf[16];
  5038. nullpo_retr(0, pd);
  5039. WBUFW(buf,0) = 0x1a4;
  5040. WBUFB(buf,2) = type;
  5041. WBUFL(buf,3) = pd->bl.id;
  5042. WBUFL(buf,7) = param;
  5043. if (sd)
  5044. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5045. else
  5046. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5047. return 0;
  5048. }
  5049. int clif_send_petstatus(struct map_session_data *sd)
  5050. {
  5051. int fd;
  5052. struct s_pet *pet;
  5053. nullpo_retr(0, sd);
  5054. nullpo_retr(0, sd->pd);
  5055. fd=sd->fd;
  5056. pet = &sd->pd->pet;
  5057. WFIFOHEAD(fd,packet_len(0x1a2));
  5058. WFIFOW(fd,0)=0x1a2;
  5059. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5060. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5061. WFIFOW(fd,27)=pet->level;
  5062. WFIFOW(fd,29)=pet->hungry;
  5063. WFIFOW(fd,31)=pet->intimate;
  5064. WFIFOW(fd,33)=pet->equip;
  5065. WFIFOSET(fd,packet_len(0x1a2));
  5066. return 0;
  5067. }
  5068. /*==========================================
  5069. *
  5070. *------------------------------------------*/
  5071. int clif_pet_emotion(struct pet_data *pd,int param)
  5072. {
  5073. unsigned char buf[16];
  5074. nullpo_retr(0, pd);
  5075. memset(buf,0,packet_len(0x1aa));
  5076. WBUFW(buf,0)=0x1aa;
  5077. WBUFL(buf,2)=pd->bl.id;
  5078. if(param >= 100 && pd->petDB->talk_convert_class) {
  5079. if(pd->petDB->talk_convert_class < 0)
  5080. return 0;
  5081. else if(pd->petDB->talk_convert_class > 0) {
  5082. param -= (pd->pet.class_ - 100)*100;
  5083. param += (pd->petDB->talk_convert_class - 100)*100;
  5084. }
  5085. }
  5086. WBUFL(buf,6)=param;
  5087. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5088. return 0;
  5089. }
  5090. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5091. {
  5092. int fd;
  5093. nullpo_retr(0, sd);
  5094. fd=sd->fd;
  5095. WFIFOHEAD(fd,packet_len(0x1a3));
  5096. WFIFOW(fd,0)=0x1a3;
  5097. WFIFOB(fd,2)=fail;
  5098. WFIFOW(fd,3)=foodid;
  5099. WFIFOSET(fd,packet_len(0x1a3));
  5100. return 0;
  5101. }
  5102. /*==========================================
  5103. * オートスペル リスト送信
  5104. *------------------------------------------*/
  5105. int clif_autospell(struct map_session_data *sd,int skilllv)
  5106. {
  5107. int fd;
  5108. nullpo_retr(0, sd);
  5109. fd=sd->fd;
  5110. WFIFOHEAD(fd,packet_len(0x1cd));
  5111. WFIFOW(fd, 0)=0x1cd;
  5112. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5113. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5114. else
  5115. WFIFOL(fd,2)= 0x00000000;
  5116. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5117. WFIFOL(fd,6)= MG_COLDBOLT;
  5118. else
  5119. WFIFOL(fd,6)= 0x00000000;
  5120. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5121. WFIFOL(fd,10)= MG_FIREBOLT;
  5122. else
  5123. WFIFOL(fd,10)= 0x00000000;
  5124. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5125. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5126. else
  5127. WFIFOL(fd,14)= 0x00000000;
  5128. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5129. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5130. else
  5131. WFIFOL(fd,18)= 0x00000000;
  5132. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5133. WFIFOL(fd,22)= MG_FIREBALL;
  5134. else
  5135. WFIFOL(fd,22)= 0x00000000;
  5136. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5137. WFIFOL(fd,26)= MG_FROSTDIVER;
  5138. else
  5139. WFIFOL(fd,26)= 0x00000000;
  5140. WFIFOSET(fd,packet_len(0x1cd));
  5141. sd->menuskill_id = SA_AUTOSPELL;
  5142. sd->menuskill_val = skilllv;
  5143. return 0;
  5144. }
  5145. /*==========================================
  5146. * Devotion's visual effect
  5147. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5148. *------------------------------------------*/
  5149. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5150. {
  5151. unsigned char buf[56];
  5152. int i;
  5153. nullpo_retv(src);
  5154. memset(buf,0,packet_len(0x1cf));
  5155. WBUFW(buf,0) = 0x1cf;
  5156. WBUFL(buf,2) = src->id;
  5157. if( src->type == BL_MER )
  5158. {
  5159. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5160. if( md && md->master && md->devotion_flag )
  5161. WBUFL(buf,6) = md->master->bl.id;
  5162. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5163. }
  5164. else
  5165. {
  5166. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5167. if( sd == NULL )
  5168. return;
  5169. for( i = 0; i < 5; i++ )
  5170. WBUFL(buf,6+4*i) = sd->devotion[i];
  5171. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5172. }
  5173. if( tsd )
  5174. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5175. else
  5176. clif_send(buf, packet_len(0x1cf), src, AREA);
  5177. }
  5178. /*==========================================
  5179. * 氣球
  5180. *------------------------------------------*/
  5181. int clif_spiritball(struct map_session_data *sd)
  5182. {
  5183. unsigned char buf[16];
  5184. nullpo_retr(0, sd);
  5185. WBUFW(buf,0)=0x1d0;
  5186. WBUFL(buf,2)=sd->bl.id;
  5187. WBUFW(buf,6)=sd->spiritball;
  5188. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5189. return 0;
  5190. }
  5191. /*==========================================
  5192. *
  5193. *------------------------------------------*/
  5194. int clif_combo_delay(struct block_list *bl,int wait)
  5195. {
  5196. unsigned char buf[32];
  5197. nullpo_retr(0, bl);
  5198. WBUFW(buf,0)=0x1d2;
  5199. WBUFL(buf,2)=bl->id;
  5200. WBUFL(buf,6)=wait;
  5201. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5202. return 0;
  5203. }
  5204. /*==========================================
  5205. *白刃取り
  5206. *------------------------------------------*/
  5207. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5208. int _bool)
  5209. {
  5210. unsigned char buf[32];
  5211. nullpo_retr(0, src);
  5212. nullpo_retr(0, dst);
  5213. WBUFW(buf,0)=0x1d1;
  5214. WBUFL(buf,2)=src->id;
  5215. WBUFL(buf,6)=dst->id;
  5216. WBUFL(buf,10)=_bool;
  5217. clif_send(buf,packet_len(0x1d1),src,AREA);
  5218. return 0;
  5219. }
  5220. /*==========================================
  5221. * MVPエフェクト
  5222. *------------------------------------------*/
  5223. int clif_mvp_effect(struct map_session_data *sd)
  5224. {
  5225. unsigned char buf[16];
  5226. nullpo_retr(0, sd);
  5227. WBUFW(buf,0)=0x10c;
  5228. WBUFL(buf,2)=sd->bl.id;
  5229. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5230. return 0;
  5231. }
  5232. /*==========================================
  5233. * MVPアイテム所得
  5234. *------------------------------------------*/
  5235. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5236. {
  5237. int view,fd;
  5238. nullpo_retr(0, sd);
  5239. fd=sd->fd;
  5240. WFIFOHEAD(fd,packet_len(0x10a));
  5241. WFIFOW(fd,0)=0x10a;
  5242. if((view = itemdb_viewid(nameid)) > 0)
  5243. WFIFOW(fd,2)=view;
  5244. else
  5245. WFIFOW(fd,2)=nameid;
  5246. WFIFOSET(fd,packet_len(0x10a));
  5247. return 0;
  5248. }
  5249. /*==========================================
  5250. * MVP経験値所得
  5251. *------------------------------------------*/
  5252. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5253. {
  5254. int fd;
  5255. nullpo_retr(0, sd);
  5256. fd=sd->fd;
  5257. WFIFOHEAD(fd,packet_len(0x10b));
  5258. WFIFOW(fd,0)=0x10b;
  5259. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5260. WFIFOSET(fd,packet_len(0x10b));
  5261. return 0;
  5262. }
  5263. /*==========================================
  5264. * Guild creation result
  5265. * R 0167 <flag>.B
  5266. * flag = 0 -> "Guild has been created."
  5267. * flag = 1 -> "You are already in a Guild."
  5268. * flag = 2 -> "That Guild Name already exists."
  5269. * flag = 3 -> "You need the neccessary item to create a Guild."
  5270. *------------------------------------------*/
  5271. int clif_guild_created(struct map_session_data *sd,int flag)
  5272. {
  5273. int fd;
  5274. nullpo_retr(0, sd);
  5275. fd=sd->fd;
  5276. WFIFOHEAD(fd,packet_len(0x167));
  5277. WFIFOW(fd,0)=0x167;
  5278. WFIFOB(fd,2)=flag;
  5279. WFIFOSET(fd,packet_len(0x167));
  5280. return 0;
  5281. }
  5282. /*==========================================
  5283. * ギルド所属通知
  5284. *------------------------------------------*/
  5285. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5286. {
  5287. int ps,fd;
  5288. nullpo_retr(0, sd);
  5289. nullpo_retr(0, g);
  5290. fd=sd->fd;
  5291. ps=guild_getposition(g,sd);
  5292. WFIFOHEAD(fd,packet_len(0x16c));
  5293. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5294. WFIFOW(fd,0)=0x16c;
  5295. WFIFOL(fd,2)=g->guild_id;
  5296. WFIFOL(fd,6)=g->emblem_id;
  5297. WFIFOL(fd,10)=g->position[ps].mode;
  5298. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5299. WFIFOSET(fd,packet_len(0x16c));
  5300. return 0;
  5301. }
  5302. /*==========================================
  5303. * ギルドメンバログイン通知
  5304. *------------------------------------------*/
  5305. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5306. {
  5307. unsigned char buf[64];
  5308. nullpo_retr(0, g);
  5309. WBUFW(buf, 0)=0x16d;
  5310. WBUFL(buf, 2)=g->member[idx].account_id;
  5311. WBUFL(buf, 6)=g->member[idx].char_id;
  5312. WBUFL(buf,10)=flag;
  5313. if(g->member[idx].sd==NULL){
  5314. struct map_session_data *sd=guild_getavailablesd(g);
  5315. if(sd!=NULL)
  5316. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5317. }else
  5318. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5319. return 0;
  5320. }
  5321. // Function `clif_guild_memberlogin_notice` sends info about
  5322. // logins and logouts of a guild member to the rest members.
  5323. // But at the 1st time (after a player login or map changing)
  5324. // the client won't show the message.
  5325. // So I suggest use this function for sending "first-time-info"
  5326. // to some player on entering the game or changing location.
  5327. // At next time the client would always show the message.
  5328. // The function sends all the statuses in the single packet
  5329. // to economize traffic. [LuzZza]
  5330. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5331. {
  5332. struct guild *g;
  5333. unsigned char buf[14*128];
  5334. int i, count=0, p_len;
  5335. nullpo_retr(0, sd);
  5336. p_len = packet_len(0x16d);
  5337. if(!(g = guild_search(sd->status.guild_id)))
  5338. return 0;
  5339. for(i=0; i<g->max_member; i++) {
  5340. if(g->member[i].account_id > 0 &&
  5341. g->member[i].account_id != sd->status.account_id) {
  5342. WBUFW(buf,count*p_len) = 0x16d;
  5343. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5344. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5345. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5346. count++;
  5347. }
  5348. }
  5349. clif_send(buf, p_len*count, &sd->bl, SELF);
  5350. return 0;
  5351. }
  5352. /*==========================================
  5353. * ギルドマスター通知(14dへの応答)
  5354. *------------------------------------------*/
  5355. int clif_guild_masterormember(struct map_session_data *sd)
  5356. {
  5357. int fd;
  5358. nullpo_retr(0, sd);
  5359. fd=sd->fd;
  5360. WFIFOHEAD(fd,packet_len(0x14e));
  5361. WFIFOW(fd,0) = 0x14e;
  5362. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5363. WFIFOSET(fd,packet_len(0x14e));
  5364. return 0;
  5365. }
  5366. /*==========================================
  5367. * Basic Info (Territories [Valaris])
  5368. *------------------------------------------*/
  5369. int clif_guild_basicinfo(struct map_session_data *sd)
  5370. {
  5371. int fd,i,t;
  5372. struct guild *g;
  5373. struct guild_castle *gc=NULL;
  5374. nullpo_retr(0, sd);
  5375. fd=sd->fd;
  5376. g=guild_search(sd->status.guild_id);
  5377. if(g==NULL)
  5378. return 0;
  5379. WFIFOHEAD(fd,packet_len(0x1b6));
  5380. WFIFOW(fd, 0)=0x1b6;//0x150;
  5381. WFIFOL(fd, 2)=g->guild_id;
  5382. WFIFOL(fd, 6)=g->guild_lv;
  5383. WFIFOL(fd,10)=g->connect_member;
  5384. WFIFOL(fd,14)=g->max_member;
  5385. WFIFOL(fd,18)=g->average_lv;
  5386. WFIFOL(fd,22)=g->exp;
  5387. WFIFOL(fd,26)=g->next_exp;
  5388. WFIFOL(fd,30)=0; // Tax Points
  5389. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5390. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5391. WFIFOL(fd,42)=g->emblem_id;
  5392. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5393. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5394. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5395. {
  5396. gc = guild_castle_search(i);
  5397. if(gc && g->guild_id == gc->guild_id)
  5398. t++;
  5399. }
  5400. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5401. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5402. return 0;
  5403. }
  5404. /*==========================================
  5405. * ギルド同盟/敵対情報
  5406. *------------------------------------------*/
  5407. int clif_guild_allianceinfo(struct map_session_data *sd)
  5408. {
  5409. int fd,i,c;
  5410. struct guild *g;
  5411. nullpo_retr(0, sd);
  5412. fd=sd->fd;
  5413. g=guild_search(sd->status.guild_id);
  5414. if(g==NULL)
  5415. return 0;
  5416. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5417. WFIFOW(fd, 0)=0x14c;
  5418. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5419. struct guild_alliance *a=&g->alliance[i];
  5420. if(a->guild_id>0){
  5421. WFIFOL(fd,c*32+4)=a->opposition;
  5422. WFIFOL(fd,c*32+8)=a->guild_id;
  5423. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5424. c++;
  5425. }
  5426. }
  5427. WFIFOW(fd, 2)=c*32+4;
  5428. WFIFOSET(fd,WFIFOW(fd,2));
  5429. return 0;
  5430. }
  5431. /*==========================================
  5432. * ギルドメンバーリスト
  5433. *------------------------------------------*/
  5434. int clif_guild_memberlist(struct map_session_data *sd)
  5435. {
  5436. int fd;
  5437. int i,c;
  5438. struct guild *g;
  5439. nullpo_retr(0, sd);
  5440. fd=sd->fd;
  5441. if (!fd)
  5442. return 0;
  5443. g=guild_search(sd->status.guild_id);
  5444. if(g==NULL)
  5445. return 0;
  5446. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5447. WFIFOW(fd, 0)=0x154;
  5448. for(i=0,c=0;i<g->max_member;i++){
  5449. struct guild_member *m=&g->member[i];
  5450. if(m->account_id==0)
  5451. continue;
  5452. WFIFOL(fd,c*104+ 4)=m->account_id;
  5453. WFIFOL(fd,c*104+ 8)=m->char_id;
  5454. WFIFOW(fd,c*104+12)=m->hair;
  5455. WFIFOW(fd,c*104+14)=m->hair_color;
  5456. WFIFOW(fd,c*104+16)=m->gender;
  5457. WFIFOW(fd,c*104+18)=m->class_;
  5458. WFIFOW(fd,c*104+20)=m->lv;
  5459. WFIFOL(fd,c*104+22)=m->exp;
  5460. WFIFOL(fd,c*104+26)=m->online;
  5461. WFIFOL(fd,c*104+30)=m->position;
  5462. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5463. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5464. c++;
  5465. }
  5466. WFIFOW(fd, 2)=c*104+4;
  5467. WFIFOSET(fd,WFIFOW(fd,2));
  5468. return 0;
  5469. }
  5470. /*==========================================
  5471. * ギルド役職名リスト
  5472. *------------------------------------------*/
  5473. int clif_guild_positionnamelist(struct map_session_data *sd)
  5474. {
  5475. int i,fd;
  5476. struct guild *g;
  5477. nullpo_retr(0, sd);
  5478. fd=sd->fd;
  5479. g=guild_search(sd->status.guild_id);
  5480. if(g==NULL)
  5481. return 0;
  5482. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5483. WFIFOW(fd, 0)=0x166;
  5484. for(i=0;i<MAX_GUILDPOSITION;i++){
  5485. WFIFOL(fd,i*28+4)=i;
  5486. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5487. }
  5488. WFIFOW(fd,2)=i*28+4;
  5489. WFIFOSET(fd,WFIFOW(fd,2));
  5490. return 0;
  5491. }
  5492. /*==========================================
  5493. * ギルド役職情報リスト
  5494. *------------------------------------------*/
  5495. int clif_guild_positioninfolist(struct map_session_data *sd)
  5496. {
  5497. int i,fd;
  5498. struct guild *g;
  5499. nullpo_retr(0, sd);
  5500. fd=sd->fd;
  5501. g=guild_search(sd->status.guild_id);
  5502. if(g==NULL)
  5503. return 0;
  5504. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5505. WFIFOW(fd, 0)=0x160;
  5506. for(i=0;i<MAX_GUILDPOSITION;i++){
  5507. struct guild_position *p=&g->position[i];
  5508. WFIFOL(fd,i*16+ 4)=i;
  5509. WFIFOL(fd,i*16+ 8)=p->mode;
  5510. WFIFOL(fd,i*16+12)=i;
  5511. WFIFOL(fd,i*16+16)=p->exp_mode;
  5512. }
  5513. WFIFOW(fd, 2)=i*16+4;
  5514. WFIFOSET(fd,WFIFOW(fd,2));
  5515. return 0;
  5516. }
  5517. /*==========================================
  5518. * ギルド役職変更通知
  5519. *------------------------------------------*/
  5520. int clif_guild_positionchanged(struct guild *g,int idx)
  5521. {
  5522. struct map_session_data *sd;
  5523. unsigned char buf[128];
  5524. nullpo_retr(0, g);
  5525. WBUFW(buf, 0)=0x174;
  5526. WBUFW(buf, 2)=44;
  5527. WBUFL(buf, 4)=idx;
  5528. WBUFL(buf, 8)=g->position[idx].mode;
  5529. WBUFL(buf,12)=idx;
  5530. WBUFL(buf,16)=g->position[idx].exp_mode;
  5531. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5532. if( (sd=guild_getavailablesd(g))!=NULL )
  5533. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5534. return 0;
  5535. }
  5536. /*==========================================
  5537. * ギルドメンバ変更通知
  5538. *------------------------------------------*/
  5539. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5540. {
  5541. struct map_session_data *sd;
  5542. unsigned char buf[64];
  5543. nullpo_retr(0, g);
  5544. WBUFW(buf, 0)=0x156;
  5545. WBUFW(buf, 2)=16;
  5546. WBUFL(buf, 4)=g->member[idx].account_id;
  5547. WBUFL(buf, 8)=g->member[idx].char_id;
  5548. WBUFL(buf,12)=g->member[idx].position;
  5549. if( (sd=guild_getavailablesd(g))!=NULL )
  5550. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5551. return 0;
  5552. }
  5553. /*==========================================
  5554. * ギルドエンブレム送信
  5555. *------------------------------------------*/
  5556. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5557. {
  5558. int fd;
  5559. nullpo_retr(0, sd);
  5560. nullpo_retr(0, g);
  5561. fd=sd->fd;
  5562. if(g->emblem_len<=0)
  5563. return 0;
  5564. WFIFOHEAD(fd,g->emblem_len+12);
  5565. WFIFOW(fd,0)=0x152;
  5566. WFIFOW(fd,2)=g->emblem_len+12;
  5567. WFIFOL(fd,4)=g->guild_id;
  5568. WFIFOL(fd,8)=g->emblem_id;
  5569. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5570. WFIFOSET(fd,WFIFOW(fd,2));
  5571. return 0;
  5572. }
  5573. /// Sends update of the guild id/emblem id to everyone in the area.
  5574. void clif_guild_emblem_area(struct block_list* bl)
  5575. {
  5576. uint8 buf[12];
  5577. nullpo_retv(bl);
  5578. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5579. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5580. WBUFW(buf,0) = 0x1B4;
  5581. WBUFL(buf,2) = bl->id;
  5582. WBUFL(buf,6) = status_get_guild_id(bl);
  5583. WBUFW(buf,10) = status_get_emblem_id(bl);
  5584. clif_send(buf, 12, bl, AREA_WOS);
  5585. }
  5586. /*==========================================
  5587. * Send guild skills
  5588. *------------------------------------------*/
  5589. int clif_guild_skillinfo(struct map_session_data* sd)
  5590. {
  5591. int fd;
  5592. struct guild* g;
  5593. int i,c;
  5594. nullpo_retr(0, sd);
  5595. fd = sd->fd;
  5596. g = guild_search(sd->status.guild_id);
  5597. if(g == NULL)
  5598. return 0;
  5599. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5600. WFIFOW(fd,0) = 0x0162;
  5601. WFIFOW(fd,4) = g->skill_point;
  5602. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5603. {
  5604. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5605. {
  5606. int id = g->skill[i].id;
  5607. int p = 6 + c*37;
  5608. WFIFOW(fd,p+0) = id;
  5609. WFIFOW(fd,p+2) = skill_get_inf(id);
  5610. WFIFOW(fd,p+4) = 0;
  5611. WFIFOW(fd,p+6) = g->skill[i].lv;
  5612. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5613. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5614. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5615. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5616. c++;
  5617. }
  5618. }
  5619. WFIFOW(fd,2) = 6 + c*37;
  5620. WFIFOSET(fd,WFIFOW(fd,2));
  5621. return 0;
  5622. }
  5623. /*==========================================
  5624. * Sends guild notice to client
  5625. * R 016f <str1z>.60B <str2z>.120B
  5626. *------------------------------------------*/
  5627. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5628. {
  5629. int fd;
  5630. nullpo_retr(0, sd);
  5631. nullpo_retr(0, g);
  5632. fd = sd->fd;
  5633. if ( !session_isActive(fd) )
  5634. return 0;
  5635. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5636. return 0;
  5637. WFIFOHEAD(fd,packet_len(0x16f));
  5638. WFIFOW(fd,0) = 0x16f;
  5639. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5640. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5641. WFIFOSET(fd,packet_len(0x16f));
  5642. return 0;
  5643. }
  5644. /*==========================================
  5645. * ギルドメンバ勧誘
  5646. *------------------------------------------*/
  5647. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5648. {
  5649. int fd;
  5650. nullpo_retr(0, sd);
  5651. nullpo_retr(0, g);
  5652. fd=sd->fd;
  5653. WFIFOHEAD(fd,packet_len(0x16a));
  5654. WFIFOW(fd,0)=0x16a;
  5655. WFIFOL(fd,2)=g->guild_id;
  5656. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5657. WFIFOSET(fd,packet_len(0x16a));
  5658. return 0;
  5659. }
  5660. /*==========================================
  5661. * ギルドメンバ勧誘結果
  5662. *------------------------------------------*/
  5663. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5664. {
  5665. int fd;
  5666. nullpo_retr(0, sd);
  5667. fd=sd->fd;
  5668. WFIFOHEAD(fd,packet_len(0x169));
  5669. WFIFOW(fd,0)=0x169;
  5670. WFIFOB(fd,2)=flag;
  5671. WFIFOSET(fd,packet_len(0x169));
  5672. return 0;
  5673. }
  5674. /*==========================================
  5675. * ギルドメンバ脱退通知
  5676. *------------------------------------------*/
  5677. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5678. {
  5679. unsigned char buf[128];
  5680. nullpo_retr(0, sd);
  5681. WBUFW(buf, 0)=0x15a;
  5682. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5683. memcpy(WBUFP(buf,26),mes,40);
  5684. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5685. return 0;
  5686. }
  5687. /*==========================================
  5688. * ギルドメンバ追放通知
  5689. *------------------------------------------*/
  5690. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5691. {
  5692. unsigned char buf[128];
  5693. nullpo_retr(0, sd);
  5694. WBUFW(buf, 0)=0x15c;
  5695. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  5696. safestrncpy((char*)WBUFP(buf,26),mes,40);
  5697. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5698. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5699. return 0;
  5700. }
  5701. /*==========================================
  5702. * ギルド追放メンバリスト
  5703. *------------------------------------------*/
  5704. int clif_guild_expulsionlist(struct map_session_data *sd)
  5705. {
  5706. int fd;
  5707. int i,c;
  5708. struct guild *g;
  5709. nullpo_retr(0, sd);
  5710. fd=sd->fd;
  5711. g=guild_search(sd->status.guild_id);
  5712. if(g==NULL)
  5713. return 0;
  5714. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5715. WFIFOW(fd,0)=0x163;
  5716. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5717. struct guild_expulsion *e=&g->expulsion[i];
  5718. if(e->account_id>0){
  5719. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5720. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5721. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  5722. c++;
  5723. }
  5724. }
  5725. WFIFOW(fd,2) = 4 + c*88;
  5726. WFIFOSET(fd,WFIFOW(fd,2));
  5727. return 0;
  5728. }
  5729. /*==========================================
  5730. * ギルド会話
  5731. *------------------------------------------*/
  5732. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5733. {
  5734. struct map_session_data *sd;
  5735. unsigned char *buf;
  5736. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5737. WBUFW(buf, 0) = 0x17f;
  5738. WBUFW(buf, 2) = len + 4;
  5739. memcpy(WBUFP(buf,4), mes, len);
  5740. if ((sd = guild_getavailablesd(g)) != NULL)
  5741. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5742. if(buf) aFree(buf);
  5743. return 0;
  5744. }
  5745. /*==========================================
  5746. * ギルドスキル割り振り通知
  5747. *------------------------------------------*/
  5748. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5749. {
  5750. int fd;
  5751. nullpo_retr(0, sd);
  5752. fd=sd->fd;
  5753. WFIFOHEAD(fd,11);
  5754. WFIFOW(fd,0) = 0x10e;
  5755. WFIFOW(fd,2) = skill_num;
  5756. WFIFOW(fd,4) = lv;
  5757. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5758. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5759. WFIFOB(fd,10) = 1;
  5760. WFIFOSET(fd,11);
  5761. return 0;
  5762. }
  5763. /*==========================================
  5764. * ギルド同盟要請
  5765. *------------------------------------------*/
  5766. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5767. {
  5768. int fd;
  5769. nullpo_retr(0, sd);
  5770. fd=sd->fd;
  5771. WFIFOHEAD(fd,packet_len(0x171));
  5772. WFIFOW(fd,0)=0x171;
  5773. WFIFOL(fd,2)=account_id;
  5774. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5775. WFIFOSET(fd,packet_len(0x171));
  5776. return 0;
  5777. }
  5778. /*==========================================
  5779. * Reply to alliance request.
  5780. * Flag values are:
  5781. * 0: Already allied.
  5782. * 1: You rejected the offer.
  5783. * 2: You accepted the offer.
  5784. * 3: They have too any alliances
  5785. * 4: You have too many alliances.
  5786. *------------------------------------------*/
  5787. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5788. {
  5789. int fd;
  5790. nullpo_retr(0, sd);
  5791. fd=sd->fd;
  5792. WFIFOHEAD(fd,packet_len(0x173));
  5793. WFIFOW(fd,0)=0x173;
  5794. WFIFOL(fd,2)=flag;
  5795. WFIFOSET(fd,packet_len(0x173));
  5796. return 0;
  5797. }
  5798. /*==========================================
  5799. * ギルド関係解消通知
  5800. *------------------------------------------*/
  5801. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5802. {
  5803. int fd;
  5804. nullpo_retr(0, sd);
  5805. fd = sd->fd;
  5806. if (fd <= 0)
  5807. return 0;
  5808. WFIFOHEAD(fd,packet_len(0x184));
  5809. WFIFOW(fd,0)=0x184;
  5810. WFIFOL(fd,2)=guild_id;
  5811. WFIFOL(fd,6)=flag;
  5812. WFIFOSET(fd,packet_len(0x184));
  5813. return 0;
  5814. }
  5815. /*==========================================
  5816. * ギルド敵対結果
  5817. *------------------------------------------*/
  5818. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5819. {
  5820. int fd;
  5821. nullpo_retr(0, sd);
  5822. fd=sd->fd;
  5823. WFIFOHEAD(fd,packet_len(0x181));
  5824. WFIFOW(fd,0)=0x181;
  5825. WFIFOB(fd,2)=flag;
  5826. WFIFOSET(fd,packet_len(0x181));
  5827. return 0;
  5828. }
  5829. /*==========================================
  5830. * ギルド関係追加
  5831. *------------------------------------------*/
  5832. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5833. {
  5834. unsigned char buf[64];
  5835. WBUFW(fd,0)=0x185;
  5836. WBUFL(fd,2)=g->alliance[idx].opposition;
  5837. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5838. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5839. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5840. return 0;
  5841. }*/
  5842. /*==========================================
  5843. * ギルド解散通知
  5844. *------------------------------------------*/
  5845. int clif_guild_broken(struct map_session_data *sd,int flag)
  5846. {
  5847. int fd;
  5848. nullpo_retr(0, sd);
  5849. fd=sd->fd;
  5850. WFIFOHEAD(fd,packet_len(0x15e));
  5851. WFIFOW(fd,0)=0x15e;
  5852. WFIFOL(fd,2)=flag;
  5853. WFIFOSET(fd,packet_len(0x15e));
  5854. return 0;
  5855. }
  5856. /*==========================================
  5857. * エモーション
  5858. *------------------------------------------*/
  5859. void clif_emotion(struct block_list *bl,int type)
  5860. {
  5861. unsigned char buf[8];
  5862. nullpo_retv(bl);
  5863. WBUFW(buf,0)=0xc0;
  5864. WBUFL(buf,2)=bl->id;
  5865. WBUFB(buf,6)=type;
  5866. clif_send(buf,packet_len(0xc0),bl,AREA);
  5867. }
  5868. /*==========================================
  5869. * トーキーボックス
  5870. *------------------------------------------*/
  5871. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5872. {
  5873. unsigned char buf[86];
  5874. nullpo_retv(bl);
  5875. WBUFW(buf,0) = 0x191;
  5876. WBUFL(buf,2) = bl->id;
  5877. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5878. clif_send(buf,packet_len(0x191),bl,AREA);
  5879. }
  5880. /*==========================================
  5881. * 結婚エフェクト
  5882. *------------------------------------------*/
  5883. void clif_wedding_effect(struct block_list *bl)
  5884. {
  5885. unsigned char buf[6];
  5886. nullpo_retv(bl);
  5887. WBUFW(buf,0) = 0x1ea;
  5888. WBUFL(buf,2) = bl->id;
  5889. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5890. }
  5891. /*==========================================
  5892. * � なたに逢いたい使用時名前叫び
  5893. *------------------------------------------
  5894. void clif_callpartner(struct map_session_data *sd)
  5895. {
  5896. unsigned char buf[26];
  5897. char *p;
  5898. nullpo_retv(sd);
  5899. if(sd->status.partner_id){
  5900. WBUFW(buf,0)=0x1e6;
  5901. p = map_charid2nick(sd->status.partner_id);
  5902. if(p){
  5903. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5904. }else{
  5905. map_reqchariddb(sd,sd->status.partner_id);
  5906. chrif_searchcharid(sd->status.partner_id);
  5907. WBUFB(buf,2) = 0;
  5908. }
  5909. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5910. }
  5911. return;
  5912. }
  5913. */
  5914. /*==========================================
  5915. * Marry [DracoRPG]
  5916. *------------------------------------------
  5917. void clif_marriage_process(struct map_session_data *sd)
  5918. {
  5919. int fd;
  5920. nullpo_retv(sd);
  5921. fd=sd->fd;
  5922. WFIFOHEAD(fd,packet_len(0x1e4));
  5923. WFIFOW(fd,0)=0x1e4;
  5924. WFIFOSET(fd,packet_len(0x1e4));
  5925. }
  5926. */
  5927. /*==========================================
  5928. * Notice of divorce
  5929. *------------------------------------------*/
  5930. void clif_divorced(struct map_session_data* sd, const char* name)
  5931. {
  5932. int fd;
  5933. nullpo_retv(sd);
  5934. fd=sd->fd;
  5935. WFIFOHEAD(fd,packet_len(0x205));
  5936. WFIFOW(fd,0)=0x205;
  5937. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5938. WFIFOSET(fd, packet_len(0x205));
  5939. }
  5940. /*==========================================
  5941. *
  5942. *------------------------------------------*/
  5943. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5944. {
  5945. nullpo_retv(sd);
  5946. WFIFOHEAD(fd,packet_len(0x1e2));
  5947. WFIFOW(fd,0)=0x1e2;
  5948. WFIFOSET(fd, packet_len(0x1e2));
  5949. }
  5950. /*==========================================
  5951. *
  5952. *------------------------------------------*/
  5953. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5954. {
  5955. int fd;
  5956. nullpo_retr(0, sd);
  5957. fd = sd->fd;
  5958. if (!fd || !len) return 0; //Disconnected player.
  5959. WFIFOHEAD(fd, len+5);
  5960. WFIFOW(fd, 0) = 0x17f;
  5961. WFIFOW(fd, 2) = len + 5;
  5962. memcpy(WFIFOP(fd,4), mes, len);
  5963. WFIFOSET(fd, WFIFOW(fd,2));
  5964. return 1;
  5965. }
  5966. /*==========================================
  5967. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5968. *------------------------------------------*/
  5969. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5970. {
  5971. unsigned char buf[1024];
  5972. if (!len) return;
  5973. WBUFW(buf, 0) = 0x17f;
  5974. WBUFW(buf, 2) = len + 5;
  5975. memcpy(WBUFP(buf,4), mes, len);
  5976. clif_send(buf, WBUFW(buf,2), src, target);
  5977. return;
  5978. }
  5979. /*==========================================
  5980. *
  5981. *------------------------------------------*/
  5982. int clif_GM_kickack(struct map_session_data *sd, int id)
  5983. {
  5984. int fd;
  5985. nullpo_retr(0, sd);
  5986. fd = sd->fd;
  5987. WFIFOHEAD(fd,packet_len(0xcd));
  5988. WFIFOW(fd,0) = 0xcd;
  5989. WFIFOL(fd,2) = id;
  5990. WFIFOSET(fd, packet_len(0xcd));
  5991. return 0;
  5992. }
  5993. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  5994. {
  5995. int fd = tsd->fd;
  5996. if( fd > 0 )
  5997. clif_authfail_fd(fd, 15);
  5998. else
  5999. map_quit(tsd);
  6000. if( sd )
  6001. clif_GM_kickack(sd,tsd->status.account_id);
  6002. }
  6003. /// Displays various manner-related status messages
  6004. /// R 014a <type>.L
  6005. /// type: 0 - "A manner point has been successfully aligned."
  6006. /// 1 - ?
  6007. /// 2 - ?
  6008. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6009. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6010. /// 5 - "You got a good point from %s."
  6011. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6012. {
  6013. int fd;
  6014. nullpo_retv(sd);
  6015. fd = sd->fd;
  6016. WFIFOHEAD(fd,packet_len(0x14a));
  6017. WFIFOW(fd,0) = 0x14a;
  6018. WFIFOL(fd,2) = type;
  6019. WFIFOSET(fd, packet_len(0x14a));
  6020. }
  6021. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6022. /// R 014b <type>.B <GM name>.24B
  6023. /// type: 0 - positive (unmute)
  6024. /// 1 - negative (mute)
  6025. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6026. {
  6027. int fd;
  6028. nullpo_retv(sd);
  6029. nullpo_retv(tsd);
  6030. fd = tsd->fd;
  6031. WFIFOHEAD(fd,packet_len(0x14b));
  6032. WFIFOW(fd,0) = 0x14b;
  6033. WFIFOB(fd,2) = type;
  6034. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6035. WFIFOSET(fd, packet_len(0x14b));
  6036. }
  6037. /*==========================================
  6038. * Wis拒否許可応答
  6039. *------------------------------------------*/
  6040. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6041. {
  6042. int fd;
  6043. nullpo_retr(0, sd);
  6044. fd=sd->fd;
  6045. WFIFOHEAD(fd,packet_len(0xd1));
  6046. WFIFOW(fd,0)=0xd1;
  6047. WFIFOB(fd,2)=type;
  6048. WFIFOB(fd,3)=flag;
  6049. WFIFOSET(fd,packet_len(0xd1));
  6050. return 0;
  6051. }
  6052. /*==========================================
  6053. * Wis全拒否許可応答
  6054. *------------------------------------------*/
  6055. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6056. {
  6057. int fd;
  6058. nullpo_retr(0, sd);
  6059. fd=sd->fd;
  6060. WFIFOHEAD(fd,packet_len(0xd2));
  6061. WFIFOW(fd,0)=0xd2;
  6062. WFIFOB(fd,2)=type;
  6063. WFIFOB(fd,3)=flag;
  6064. WFIFOSET(fd,packet_len(0xd2));
  6065. return 0;
  6066. }
  6067. /*==========================================
  6068. * サウンドエフェクト
  6069. *------------------------------------------*/
  6070. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6071. {
  6072. int fd;
  6073. nullpo_retv(sd);
  6074. nullpo_retv(bl);
  6075. fd = sd->fd;
  6076. WFIFOHEAD(fd,packet_len(0x1d3));
  6077. WFIFOW(fd,0) = 0x1d3;
  6078. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6079. WFIFOB(fd,26) = type;
  6080. WFIFOL(fd,27) = 0;
  6081. WFIFOL(fd,31) = bl->id;
  6082. WFIFOSET(fd,packet_len(0x1d3));
  6083. return;
  6084. }
  6085. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6086. {
  6087. unsigned char buf[40];
  6088. nullpo_retr(0, bl);
  6089. WBUFW(buf,0) = 0x1d3;
  6090. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6091. WBUFB(buf,26) = type;
  6092. WBUFL(buf,27) = 0;
  6093. WBUFL(buf,31) = bl->id;
  6094. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6095. return 0;
  6096. }
  6097. // displaying special effects (npcs, weather, etc) [Valaris]
  6098. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6099. {
  6100. unsigned char buf[24];
  6101. nullpo_retr(0, bl);
  6102. memset(buf, 0, packet_len(0x1f3));
  6103. WBUFW(buf,0) = 0x1f3;
  6104. WBUFL(buf,2) = bl->id;
  6105. WBUFL(buf,6) = type;
  6106. clif_send(buf, packet_len(0x1f3), bl, target);
  6107. if (disguised(bl)) {
  6108. WBUFL(buf,2) = -bl->id;
  6109. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6110. }
  6111. return 0;
  6112. }
  6113. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6114. {
  6115. WFIFOHEAD(fd,10);
  6116. WFIFOW(fd,0) = 0x1f3;
  6117. WFIFOL(fd,2) = bl->id;
  6118. WFIFOL(fd,6) = type;
  6119. WFIFOSET(fd,10);
  6120. }
  6121. // messages (from mobs/npcs) [Valaris]
  6122. int clif_message(struct block_list* bl, const char* msg)
  6123. {
  6124. unsigned short msg_len = strlen(msg) + 1;
  6125. uint8 buf[256];
  6126. nullpo_retr(0, bl);
  6127. WBUFW(buf,0) = 0x8d;
  6128. WBUFW(buf,2) = msg_len + 8;
  6129. WBUFL(buf,4) = bl->id;
  6130. memcpy(WBUFP(buf,8), msg, msg_len);
  6131. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6132. return 0;
  6133. }
  6134. // refresh the client's screen, getting rid of any effects
  6135. int clif_refresh(struct map_session_data *sd)
  6136. {
  6137. nullpo_retr(-1, sd);
  6138. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6139. clif_inventorylist(sd);
  6140. if(pc_iscarton(sd)) {
  6141. clif_cartlist(sd);
  6142. clif_updatestatus(sd,SP_CARTINFO);
  6143. }
  6144. clif_updatestatus(sd,SP_WEIGHT);
  6145. clif_updatestatus(sd,SP_MAXWEIGHT);
  6146. clif_updatestatus(sd,SP_STR);
  6147. clif_updatestatus(sd,SP_AGI);
  6148. clif_updatestatus(sd,SP_VIT);
  6149. clif_updatestatus(sd,SP_INT);
  6150. clif_updatestatus(sd,SP_DEX);
  6151. clif_updatestatus(sd,SP_LUK);
  6152. if (sd->spiritball)
  6153. clif_spiritball_single(sd->fd, sd);
  6154. if (sd->vd.cloth_color)
  6155. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6156. if(merc_is_hom_active(sd->hd))
  6157. clif_send_homdata(sd,0,0);
  6158. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6159. clif_weather_check(sd);
  6160. if( pc_issit(sd) )
  6161. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6162. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6163. clif_clearunit_single(sd->bl.id,1,sd->fd);
  6164. #ifndef TXT_ONLY
  6165. mail_clear(sd);
  6166. #endif
  6167. return 0;
  6168. }
  6169. // updates the object's (bl) name on client
  6170. int clif_charnameack (int fd, struct block_list *bl)
  6171. {
  6172. unsigned char buf[103];
  6173. int cmd = 0x95;
  6174. nullpo_retr(0, bl);
  6175. WBUFW(buf,0) = cmd;
  6176. WBUFL(buf,2) = bl->id;
  6177. switch( bl->type )
  6178. {
  6179. case BL_PC:
  6180. {
  6181. struct map_session_data *ssd = (struct map_session_data *)bl;
  6182. struct party_data *p = NULL;
  6183. struct guild *g = NULL;
  6184. //Requesting your own "shadow" name. [Skotlex]
  6185. if (ssd->fd == fd && ssd->disguise)
  6186. WBUFL(buf,2) = -bl->id;
  6187. if (strlen(ssd->fakename)>1) {
  6188. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6189. break;
  6190. }
  6191. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6192. if (ssd->status.party_id > 0)
  6193. p = party_search(ssd->status.party_id);
  6194. if (ssd->status.guild_id > 0)
  6195. g = guild_search(ssd->status.guild_id);
  6196. if (p == NULL && g == NULL)
  6197. break;
  6198. WBUFW(buf, 0) = cmd = 0x195;
  6199. if (p)
  6200. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6201. else
  6202. WBUFB(buf,30) = 0;
  6203. if (g)
  6204. {
  6205. int i, ps = -1;
  6206. for(i = 0; i < g->max_member; i++) {
  6207. if (g->member[i].account_id == ssd->status.account_id &&
  6208. g->member[i].char_id == ssd->status.char_id )
  6209. {
  6210. ps = g->member[i].position;
  6211. break;
  6212. }
  6213. }
  6214. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6215. {
  6216. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6217. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6218. } else { //Assume no guild.
  6219. WBUFB(buf,54) = 0;
  6220. WBUFB(buf,78) = 0;
  6221. }
  6222. } else {
  6223. WBUFB(buf,54) = 0;
  6224. WBUFB(buf,78) = 0;
  6225. }
  6226. }
  6227. break;
  6228. //[blackhole89]
  6229. case BL_HOM:
  6230. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6231. break;
  6232. case BL_MER:
  6233. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6234. break;
  6235. case BL_PET:
  6236. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6237. break;
  6238. case BL_NPC:
  6239. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6240. break;
  6241. case BL_MOB:
  6242. {
  6243. struct mob_data *md = (struct mob_data *)bl;
  6244. nullpo_retr(0, md);
  6245. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6246. if (md->guardian_data && md->guardian_data->guild_id) {
  6247. WBUFW(buf, 0) = cmd = 0x195;
  6248. WBUFB(buf,30) = 0;
  6249. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6250. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6251. } else if (battle_config.show_mob_info) {
  6252. char mobhp[50], *str_p = mobhp;
  6253. WBUFW(buf, 0) = cmd = 0x195;
  6254. if (battle_config.show_mob_info&4)
  6255. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6256. if (battle_config.show_mob_info&1)
  6257. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6258. if (battle_config.show_mob_info&2)
  6259. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6260. //Even thought mobhp ain't a name, we send it as one so the client
  6261. //can parse it. [Skotlex]
  6262. if (str_p != mobhp) {
  6263. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6264. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6265. WBUFB(buf,54) = 0;
  6266. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6267. }
  6268. }
  6269. }
  6270. break;
  6271. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6272. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6273. // break;
  6274. return 0;
  6275. default:
  6276. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6277. return 0;
  6278. }
  6279. // if no receipient specified just update nearby clients
  6280. if (fd == 0)
  6281. clif_send(buf, packet_len(cmd), bl, AREA);
  6282. else {
  6283. WFIFOHEAD(fd, packet_len(cmd));
  6284. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6285. WFIFOSET(fd, packet_len(cmd));
  6286. }
  6287. return 0;
  6288. }
  6289. //Used to update when a char leaves a party/guild. [Skotlex]
  6290. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6291. int clif_charnameupdate (struct map_session_data *ssd)
  6292. {
  6293. unsigned char buf[103];
  6294. int cmd = 0x195;
  6295. struct party_data *p = NULL;
  6296. struct guild *g = NULL;
  6297. nullpo_retr(0, ssd);
  6298. if (strlen(ssd->fakename)>1)
  6299. return 0; //No need to update as the party/guild was not displayed anyway.
  6300. WBUFW(buf,0) = cmd;
  6301. WBUFL(buf,2) = ssd->bl.id;
  6302. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6303. if (ssd->status.party_id > 0)
  6304. p = party_search(ssd->status.party_id);
  6305. if (ssd->status.guild_id > 0)
  6306. g = guild_search(ssd->status.guild_id);
  6307. if (p)
  6308. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6309. else
  6310. WBUFB(buf,30) = 0;
  6311. if (g)
  6312. {
  6313. int i, ps = -1;
  6314. for(i = 0; i < g->max_member; i++) {
  6315. if (g->member[i].account_id == ssd->status.account_id &&
  6316. g->member[i].char_id == ssd->status.char_id )
  6317. {
  6318. ps = g->member[i].position;
  6319. break;
  6320. }
  6321. }
  6322. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6323. {
  6324. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6325. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6326. } else { //Assume no guild.
  6327. WBUFB(buf,54) = 0;
  6328. WBUFB(buf,78) = 0;
  6329. }
  6330. } else {
  6331. WBUFB(buf,54) = 0;
  6332. WBUFB(buf,78) = 0;
  6333. }
  6334. // Update nearby clients
  6335. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6336. return 0;
  6337. }
  6338. void clif_slide(struct block_list *bl, int x, int y)
  6339. {
  6340. unsigned char buf[10];
  6341. nullpo_retv(bl);
  6342. WBUFW(buf, 0) = 0x01ff;
  6343. WBUFL(buf, 2) = bl->id;
  6344. WBUFW(buf, 6) = x;
  6345. WBUFW(buf, 8) = y;
  6346. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6347. if( disguised(bl) )
  6348. {
  6349. WBUFL(buf,2) = -bl->id;
  6350. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6351. }
  6352. }
  6353. /*------------------------------------------
  6354. * @me command by lordalfa, rewritten implementation by Skotlex
  6355. *------------------------------------------*/
  6356. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6357. {
  6358. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6359. int len_mes = strlen(mes)+1; //Account for \0
  6360. if (len_mes + 8 >= 256) {
  6361. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6362. len_mes = 247; //Trunk it to avoid problems.
  6363. }
  6364. // send message to others
  6365. WBUFW(buf,0) = 0x8d;
  6366. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6367. WBUFL(buf,4) = sd->bl.id;
  6368. memcpy(WBUFP(buf,8), mes, len_mes);
  6369. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6370. // send back message to the speaker
  6371. WBUFW(buf,0) = 0x8e;
  6372. WBUFW(buf, 2) = len_mes + 4;
  6373. memcpy(WBUFP(buf,4), mes, len_mes);
  6374. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6375. return 0;
  6376. }
  6377. /*==========================
  6378. * Minimap fix [Kevin]
  6379. * Remove dot from minimap
  6380. *--------------------------*/
  6381. int clif_party_xy_remove(struct map_session_data *sd)
  6382. {
  6383. unsigned char buf[16];
  6384. nullpo_retr(0, sd);
  6385. WBUFW(buf,0)=0x107;
  6386. WBUFL(buf,2)=sd->status.account_id;
  6387. WBUFW(buf,6)=-1;
  6388. WBUFW(buf,8)=-1;
  6389. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6390. return 0;
  6391. }
  6392. //Displays gospel-buff information (thanks to Rayce):
  6393. //Type determines message based on this table:
  6394. /*
  6395. 0x15 End all negative status
  6396. 0x16 Immunity to all status
  6397. 0x17 MaxHP +100%
  6398. 0x18 MaxSP +100%
  6399. 0x19 All stats +20
  6400. 0x1c Enchant weapon with Holy element
  6401. 0x1d Enchant armor with Holy element
  6402. 0x1e DEF +25%
  6403. 0x1f ATK +100%
  6404. 0x20 HIT/Flee +50
  6405. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6406. */
  6407. void clif_gospel_info(struct map_session_data *sd, int type)
  6408. {
  6409. int fd=sd->fd;
  6410. WFIFOHEAD(fd,packet_len(0x215));
  6411. WFIFOW(fd,0)=0x215;
  6412. WFIFOL(fd,2)=type;
  6413. WFIFOSET(fd, packet_len(0x215));
  6414. }
  6415. /*==========================================
  6416. * Info about Star Glaldiator save map [Komurka]
  6417. * type: 1: Information, 0: Map registered
  6418. *------------------------------------------*/
  6419. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6420. {
  6421. int fd=sd->fd;
  6422. WFIFOHEAD(fd,packet_len(0x20e));
  6423. WFIFOW(fd,0) = 0x20e;
  6424. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6425. WFIFOL(fd,26) = sd->bl.id;
  6426. WFIFOB(fd,30) = feel_level;
  6427. WFIFOB(fd,31) = type?1:0;
  6428. WFIFOSET(fd,packet_len(0x20e));
  6429. }
  6430. /*==========================================
  6431. * Info about Star Glaldiator hate mob [Komurka]
  6432. * type: 1: Register mob, 0: Information.
  6433. *------------------------------------------*/
  6434. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6435. {
  6436. int fd=sd->fd;
  6437. WFIFOHEAD(fd,packet_len(0x20e));
  6438. WFIFOW(fd,0)=0x20e;
  6439. if (pcdb_checkid(class_))
  6440. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6441. else if (mobdb_checkid(class_))
  6442. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6443. else //Really shouldn't happen...
  6444. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6445. WFIFOL(fd,26)=sd->bl.id;
  6446. WFIFOB(fd,30)=hate_level;
  6447. WFIFOB(fd,31)=type?10:11; //Register/Info
  6448. WFIFOSET(fd, packet_len(0x20e));
  6449. }
  6450. /*==========================================
  6451. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6452. *------------------------------------------*/
  6453. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6454. {
  6455. int fd=sd->fd;
  6456. WFIFOHEAD(fd,packet_len(0x20e));
  6457. WFIFOW(fd,0)=0x20e;
  6458. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6459. WFIFOL(fd,26)=mob_id;
  6460. WFIFOB(fd,30)=progress; //Message to display
  6461. WFIFOB(fd,31)=20;
  6462. WFIFOSET(fd, packet_len(0x20e));
  6463. }
  6464. /*==========================================
  6465. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6466. *------------------------------------------*/
  6467. void clif_feel_hate_reset(struct map_session_data *sd)
  6468. {
  6469. int fd=sd->fd;
  6470. WFIFOHEAD(fd,packet_len(0x20e));
  6471. WFIFOW(fd,0)=0x20e;
  6472. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6473. WFIFOL(fd,26)=sd->bl.id;
  6474. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6475. WFIFOB(fd,31)=30;
  6476. WFIFOSET(fd, packet_len(0x20e));
  6477. }
  6478. /*==========================================
  6479. * Equip window (un)tick ack
  6480. * R 02d9 <zero>.L <flag>.L
  6481. *------------------------------------------*/
  6482. void clif_equiptickack(struct map_session_data* sd, int flag)
  6483. {
  6484. int fd;
  6485. nullpo_retv(sd);
  6486. fd = sd->fd;
  6487. WFIFOHEAD(fd, packet_len(0x2d9));
  6488. WFIFOW(fd, 0) = 0x2d9;
  6489. WFIFOL(fd, 2) = 0;
  6490. WFIFOL(fd, 6) = flag;
  6491. WFIFOSET(fd, packet_len(0x2d9));
  6492. }
  6493. /*==========================================
  6494. * The player's 'view equip' state, sent during login
  6495. * R 02da <flag>.B
  6496. *------------------------------------------*/
  6497. void clif_equipcheckbox(struct map_session_data* sd)
  6498. {
  6499. int fd;
  6500. nullpo_retv(sd);
  6501. fd = sd->fd;
  6502. WFIFOHEAD(fd, packet_len(0x2da));
  6503. WFIFOW(fd, 0) = 0x2da;
  6504. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6505. WFIFOSET(fd, packet_len(0x2da));
  6506. }
  6507. /*==========================================
  6508. * Sends info about a player's equipped items
  6509. * 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*
  6510. *------------------------------------------*/
  6511. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6512. {
  6513. int i, n, fd;
  6514. nullpo_retv(sd);
  6515. nullpo_retv(tsd);
  6516. fd = sd->fd;
  6517. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6518. WFIFOW(fd, 0) = 0x2d7;
  6519. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6520. WFIFOW(fd,28) = tsd->status.class_;
  6521. WFIFOW(fd,30) = tsd->vd.hair_style;
  6522. WFIFOW(fd,32) = tsd->vd.head_top;
  6523. WFIFOW(fd,34) = tsd->vd.head_mid;
  6524. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6525. WFIFOW(fd,38) = tsd->vd.hair_color;
  6526. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6527. WFIFOB(fd,42) = tsd->vd.sex;
  6528. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6529. {
  6530. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6531. continue;
  6532. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6533. continue;
  6534. // Inventory position
  6535. WFIFOW(fd, n*26+43) = i + 2;
  6536. // Add refine, identify flag, element, etc.
  6537. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6538. // Add cards
  6539. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6540. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6541. memset(WFIFOP(fd, n*26+63), 0, 6);
  6542. n++;
  6543. }
  6544. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6545. WFIFOSET(fd, WFIFOW(fd, 2));
  6546. }
  6547. /*==========================================
  6548. * View player equip request denied
  6549. * R 0291 <message>.W
  6550. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6551. *------------------------------------------*/
  6552. void clif_viewequip_fail(struct map_session_data* sd)
  6553. {
  6554. int fd;
  6555. nullpo_retv(sd);
  6556. fd = sd->fd;
  6557. WFIFOHEAD(fd, packet_len(0x291));
  6558. WFIFOW(fd, 0) = 0x291;
  6559. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6560. WFIFOSET(fd, packet_len(0x291));
  6561. }
  6562. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6563. /// Returns true if the packet was parsed successfully.
  6564. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6565. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6566. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6567. {
  6568. char *text, *name, *message;
  6569. unsigned int packetlen, textlen, namelen, messagelen;
  6570. int fd = sd->fd;
  6571. *name_ = NULL;
  6572. *namelen_ = 0;
  6573. *message_ = NULL;
  6574. *messagelen_ = 0;
  6575. packetlen = RFIFOW(fd,2);
  6576. // basic structure checks
  6577. if( packetlen > RFIFOREST(fd) )
  6578. { // there has to be enough data to read
  6579. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6580. return false;
  6581. }
  6582. if( packetlen < 4 + 1 )
  6583. { // 4-byte header and at least an empty string is expected
  6584. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6585. return false;
  6586. }
  6587. text = (char*)RFIFOP(fd,4);
  6588. textlen = packetlen - 4;
  6589. // process <name> part of the packet
  6590. if( format == 0 )
  6591. {// name and message are separated by ' : '
  6592. // validate name
  6593. name = text;
  6594. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6595. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6596. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6597. {
  6598. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6599. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6600. set_eof(fd); // Just kick them out to correct it.
  6601. return false;
  6602. }
  6603. message = name + namelen + 3;
  6604. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6605. }
  6606. else
  6607. {// name has fixed width
  6608. if( textlen < NAME_LENGTH + 1 )
  6609. {
  6610. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6611. return false;
  6612. }
  6613. // validate name
  6614. name = text;
  6615. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6616. if( name[namelen] != '\0' )
  6617. { // only restriction is that the name must be zero-terminated
  6618. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6619. return false;
  6620. }
  6621. message = name + NAME_LENGTH;
  6622. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6623. }
  6624. if( messagelen != strnlen(message, messagelen)+1 )
  6625. { // the declared length must match real length
  6626. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6627. return false;
  6628. }
  6629. // verify <message> part of the packet
  6630. if( message[messagelen-1] != '\0' )
  6631. { // message must be zero-terminated
  6632. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6633. return false;
  6634. }
  6635. if( messagelen > CHAT_SIZE_MAX-1 )
  6636. { // messages mustn't be too long
  6637. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  6638. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  6639. // Neither the official client nor server place any restriction on the length of the data in the packet,
  6640. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  6641. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  6642. return false;
  6643. }
  6644. *name_ = name;
  6645. *namelen_ = namelen;
  6646. *message_ = message;
  6647. *messagelen_ = messagelen;
  6648. return true;
  6649. }
  6650. // ---------------------
  6651. // clif_guess_PacketVer
  6652. // ---------------------
  6653. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6654. // error codes:
  6655. // 0 - Success
  6656. // 1 - Unknown packet_ver
  6657. // 2 - Invalid account_id
  6658. // 3 - Invalid char_id
  6659. // 4 - Invalid login_id1 (reserved)
  6660. // 5 - Invalid client_tick (reserved)
  6661. // 6 - Invalid sex
  6662. // Only the first 'invalid' error that appears is used.
  6663. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6664. {
  6665. static int err = 1;
  6666. static int packet_ver = -1;
  6667. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6668. if (get_previous)
  6669. {//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]
  6670. if( error )
  6671. *error = err;
  6672. return packet_ver;
  6673. }
  6674. //By default, start searching on the default one.
  6675. err = 1;
  6676. packet_ver = clif_config.packet_db_ver;
  6677. cmd = RFIFOW(fd,0);
  6678. packet_len = RFIFOREST(fd);
  6679. #define SET_ERROR(n) \
  6680. if( err == 1 )\
  6681. err = n;\
  6682. //define SET_ERROR
  6683. #define CHECK_PACKET_VER() \
  6684. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6685. ;/* not wanttoconnection or wrong length */\
  6686. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  6687. { SET_ERROR(2); }/* invalid account_id */\
  6688. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  6689. { SET_ERROR(3); }/* invalid char_id */\
  6690. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6691. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6692. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6693. { SET_ERROR(6); }/* invalid sex */\
  6694. else\
  6695. {\
  6696. err = 0;\
  6697. if( error )\
  6698. *error = 0;\
  6699. return packet_ver;\
  6700. }\
  6701. //define CHECK_PACKET_VER
  6702. CHECK_PACKET_VER();//Default packet version found.
  6703. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6704. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6705. CHECK_PACKET_VER();
  6706. }
  6707. if( error )
  6708. *error = err;
  6709. packet_ver = -1;
  6710. return -1;
  6711. #undef SET_ERROR
  6712. #undef CHECK_PACKET_VER
  6713. }
  6714. // ------------
  6715. // clif_parse_*
  6716. // ------------
  6717. // パケット読み取って色々操作
  6718. /*==========================================
  6719. *
  6720. *------------------------------------------*/
  6721. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6722. {
  6723. struct block_list* bl;
  6724. struct auth_node* node;
  6725. int cmd, account_id, char_id, login_id1, sex;
  6726. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6727. 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])
  6728. if (sd) {
  6729. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6730. return;
  6731. }
  6732. // Only valid packet version get here
  6733. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6734. cmd = RFIFOW(fd,0);
  6735. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6736. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6737. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6738. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6739. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6740. if( packet_ver < 5 || // reject really old client versions
  6741. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6742. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6743. {// packet version rejected
  6744. 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));
  6745. WFIFOHEAD(fd,packet_len(0x6a));
  6746. WFIFOW(fd,0) = 0x6a;
  6747. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6748. WFIFOSET(fd,packet_len(0x6a));
  6749. set_eof(fd);
  6750. return;
  6751. }
  6752. //Check for double login.
  6753. bl = map_id2bl(account_id);
  6754. if(bl && bl->type != BL_PC) {
  6755. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6756. WFIFOHEAD(fd,packet_len(0x6a));
  6757. WFIFOW(fd,0) = 0x6a;
  6758. WFIFOB(fd,2) = 3; // Rejected by server
  6759. WFIFOSET(fd,packet_len(0x6a));
  6760. set_eof(fd);
  6761. return;
  6762. }
  6763. if (bl ||
  6764. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6765. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6766. sd = BL_CAST(BL_PC, bl);
  6767. if (!sd)
  6768. ; //We have another char with the same account logging in/out.
  6769. else //Already connected player.
  6770. if (sd->fd)
  6771. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6772. else
  6773. if(sd->state.autotrade)
  6774. map_quit(sd);// kick autotrading character
  6775. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6776. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6777. return;
  6778. }
  6779. CREATE(sd, TBL_PC, 1);
  6780. sd->fd = fd;
  6781. sd->packet_ver = packet_ver;
  6782. session[fd]->session_data = sd;
  6783. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6784. #if PACKETVER < 20070521
  6785. WFIFOHEAD(fd,4);
  6786. WFIFOL(fd,0) = sd->bl.id;
  6787. WFIFOSET(fd,4);
  6788. #else
  6789. WFIFOHEAD(fd,packet_len(0x283));
  6790. WFIFOW(fd,0) = 0x283;
  6791. WFIFOL(fd,2) = sd->bl.id;
  6792. WFIFOSET(fd,packet_len(0x283));
  6793. #endif
  6794. chrif_authreq(sd);
  6795. return;
  6796. }
  6797. /*==========================================
  6798. * 007d クライアント側マップ読み込み完了
  6799. * map侵入時に必要なデータを全て送りつける
  6800. *------------------------------------------*/
  6801. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6802. {
  6803. if(sd->bl.prev != NULL)
  6804. return;
  6805. if (!sd->state.active)
  6806. { //Character loading is not complete yet!
  6807. //Let pc_reg_received reinvoke this when ready.
  6808. sd->state.connect_new = 0;
  6809. return;
  6810. }
  6811. if (sd->state.rewarp)
  6812. { //Rewarp player.
  6813. sd->state.rewarp = 0;
  6814. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6815. return;
  6816. }
  6817. // look
  6818. #if PACKETVER < 4
  6819. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6820. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6821. #else
  6822. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6823. #endif
  6824. if(sd->vd.cloth_color)
  6825. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6826. // item
  6827. pc_checkitem(sd);
  6828. clif_inventorylist(sd);
  6829. // cart
  6830. if(pc_iscarton(sd)) {
  6831. clif_cartlist(sd);
  6832. clif_updatestatus(sd,SP_CARTINFO);
  6833. }
  6834. // weight
  6835. clif_updatestatus(sd,SP_WEIGHT);
  6836. clif_updatestatus(sd,SP_MAXWEIGHT);
  6837. // guild
  6838. // (needs to go before clif_spawn() to show guild emblems correctly)
  6839. if(sd->status.guild_id)
  6840. guild_send_memberinfoshort(sd,1);
  6841. if(battle_config.pc_invincible_time > 0) {
  6842. if(map_flag_gvg(sd->bl.m))
  6843. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6844. else
  6845. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6846. }
  6847. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6848. map_spawnmobs(sd->bl.m);
  6849. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  6850. map_addblock(&sd->bl);
  6851. clif_spawn(&sd->bl);
  6852. // Party
  6853. // (needs to go after clif_spawn() to show hp bars correctly)
  6854. if(sd->status.party_id) {
  6855. party_send_movemap(sd);
  6856. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6857. }
  6858. if(map[sd->bl.m].flag.pvp) {
  6859. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6860. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6861. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6862. sd->pvp_rank = 0;
  6863. sd->pvp_lastusers = 0;
  6864. sd->pvp_point = 5;
  6865. sd->pvp_won = 0;
  6866. sd->pvp_lost = 0;
  6867. }
  6868. clif_set0199(sd,1);
  6869. } else
  6870. // set flag, if it's a duel [LuzZza]
  6871. if(sd->duel_group)
  6872. clif_set0199(sd,1);
  6873. if (map[sd->bl.m].flag.gvg_dungeon)
  6874. {
  6875. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6876. if (!sd->pvp_point)
  6877. {
  6878. sd->pvp_point = 5; //Need to die twice to be warped out.
  6879. sd->pvp_won = 0;
  6880. sd->pvp_lost = 0;
  6881. }
  6882. }
  6883. if(map_flag_gvg(sd->bl.m))
  6884. {
  6885. clif_set0199(sd,3);
  6886. if (battle_config.gvg_flee_penalty != 100)
  6887. status_calc_bl(&sd->bl, SCB_FLEE); //Apply flee penalty
  6888. }
  6889. // info about nearby objects
  6890. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6891. 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);
  6892. //TODO: merge it with the code below
  6893. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6894. { //Return the pet to egg. [Skotlex]
  6895. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6896. pet_menu(sd, 3); //Option 3 is return to egg.
  6897. }
  6898. // pet
  6899. if(sd->pd) {
  6900. map_addblock(&sd->pd->bl);
  6901. clif_spawn(&sd->pd->bl);
  6902. clif_send_petdata(sd,sd->pd,0,0);
  6903. clif_send_petstatus(sd);
  6904. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6905. }
  6906. //homunculus [blackhole89]
  6907. if( merc_is_hom_active(sd->hd) )
  6908. {
  6909. map_addblock(&sd->hd->bl);
  6910. clif_spawn(&sd->hd->bl);
  6911. clif_send_homdata(sd,0,0);
  6912. clif_hominfo(sd,sd->hd,1);
  6913. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6914. clif_homskillinfoblock(sd);
  6915. if( battle_config.hom_setting&0x8 )
  6916. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6917. if( !(battle_config.hom_setting&0x2) )
  6918. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6919. }
  6920. if( sd->md )
  6921. {
  6922. map_addblock(&sd->md->bl);
  6923. clif_spawn(&sd->md->bl);
  6924. clif_mercenary_info(sd);
  6925. clif_mercenary_skillblock(sd);
  6926. }
  6927. if(sd->state.connect_new) {
  6928. int lv;
  6929. sd->state.connect_new = 0;
  6930. clif_skillinfoblock(sd);
  6931. clif_hotkeys_send(sd);
  6932. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6933. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6934. clif_updatestatus(sd,SP_SKILLPOINT);
  6935. clif_initialstatus(sd);
  6936. if (sd->sc.option&OPTION_FALCON)
  6937. clif_status_load(&sd->bl, SI_FALCON, 1);
  6938. if (sd->sc.option&OPTION_RIDING)
  6939. clif_status_load(&sd->bl, SI_RIDING, 1);
  6940. if(sd->status.manner < 0)
  6941. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6942. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6943. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6944. if(sd->bl.m == sd->feel_map[0].m
  6945. || sd->bl.m == sd->feel_map[1].m
  6946. || sd->bl.m == sd->feel_map[2].m)
  6947. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6948. }
  6949. if(sd->pd && sd->pd->pet.intimate > 900)
  6950. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6951. if(merc_is_hom_active(sd->hd))
  6952. merc_hom_init_timers(sd->hd);
  6953. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6954. {
  6955. sd->state.night = 1;
  6956. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6957. }
  6958. #if PACKETVER >= 20070918
  6959. clif_equipcheckbox(sd);
  6960. #endif
  6961. // Notify everyone that this char logged in [Skotlex].
  6962. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6963. //Login Event
  6964. npc_script_event(sd, NPCE_LOGIN);
  6965. } else {
  6966. //For some reason the client "loses" these on warp/map-change.
  6967. clif_updatestatus(sd,SP_STR);
  6968. clif_updatestatus(sd,SP_AGI);
  6969. clif_updatestatus(sd,SP_VIT);
  6970. clif_updatestatus(sd,SP_INT);
  6971. clif_updatestatus(sd,SP_DEX);
  6972. clif_updatestatus(sd,SP_LUK);
  6973. // abort currently running script
  6974. sd->state.using_fake_npc = 0;
  6975. sd->state.menu_or_input = 0;
  6976. sd->npc_menu = 0;
  6977. if(sd->npc_id)
  6978. npc_event_dequeue(sd);
  6979. }
  6980. if( sd->state.changemap )
  6981. {// restore information that gets lost on map-change
  6982. if( night_flag && map[sd->bl.m].flag.nightenabled )
  6983. { //Display night.
  6984. if( !sd->state.night )
  6985. {
  6986. sd->state.night = 1;
  6987. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6988. }
  6989. }
  6990. else if( sd->state.night )
  6991. { //Clear night display.
  6992. sd->state.night = 0;
  6993. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6994. }
  6995. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  6996. {
  6997. char output[128];
  6998. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  6999. clif_announce(&sd->bl, output, strlen(output) + 1, 0x00CC66, 3);
  7000. }
  7001. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7002. sd->state.changemap = false;
  7003. }
  7004. #ifndef TXT_ONLY
  7005. mail_clear(sd);
  7006. #endif
  7007. quest_pc_login(sd);
  7008. if(map[sd->bl.m].flag.loadevent) // Lance
  7009. npc_script_event(sd, NPCE_LOADMAP);
  7010. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7011. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7012. if (sd->sc.opt2) //Client loses these on warp.
  7013. clif_changeoption(&sd->bl);
  7014. clif_weather_check(sd);
  7015. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7016. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7017. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7018. else
  7019. sd->areanpc_id = 0;
  7020. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7021. if(pc_isdead(sd))
  7022. clif_clearunit_area(&sd->bl, 1);
  7023. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7024. // else
  7025. // clif_changed_dir(&sd->bl, SELF);
  7026. // Trigger skill effects if you appear standing on them
  7027. if(!battle_config.pc_invincible_time)
  7028. skill_unit_move(&sd->bl,gettick(),1);
  7029. }
  7030. /*==========================================
  7031. *
  7032. *------------------------------------------*/
  7033. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7034. {
  7035. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7036. WFIFOHEAD(fd, packet_len(0x7f));
  7037. WFIFOW(fd,0)=0x7f;
  7038. WFIFOL(fd,2)=gettick();
  7039. WFIFOSET(fd,packet_len(0x7f));
  7040. // removed until the socket problems are fixed. [FlavioJS]
  7041. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7042. return;
  7043. }
  7044. void clif_hotkeys_send(struct map_session_data *sd) {
  7045. #ifdef HOTKEY_SAVING
  7046. const int fd = sd->fd;
  7047. int i;
  7048. if (!fd) return;
  7049. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7050. WFIFOW(fd, 0) = 0x02b9;
  7051. for(i = 0; i < MAX_HOTKEYS; i++) {
  7052. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7053. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7054. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7055. }
  7056. WFIFOSET(fd, packet_len(0x02b9));
  7057. #endif
  7058. }
  7059. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7060. #ifdef HOTKEY_SAVING
  7061. unsigned short idx;
  7062. int cmd;
  7063. cmd = RFIFOW(fd, 0);
  7064. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7065. if (idx >= MAX_HOTKEYS) return;
  7066. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7067. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7068. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7069. return;
  7070. #endif
  7071. }
  7072. /*==========================================
  7073. *
  7074. *------------------------------------------*/
  7075. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7076. {
  7077. short x, y;
  7078. int cmd;
  7079. if (pc_isdead(sd)) {
  7080. clif_clearunit_area(&sd->bl, 1);
  7081. return;
  7082. }
  7083. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7084. ; //You CAN walk on this OPT1 value.
  7085. else if (pc_cant_act(sd))
  7086. return;
  7087. if(sd->sc.data[SC_RUN])
  7088. return;
  7089. pc_delinvincibletimer(sd);
  7090. cmd = RFIFOW(fd,0);
  7091. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7092. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7093. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7094. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7095. //Set last idle time... [Skotlex]
  7096. sd->idletime = last_tick;
  7097. unit_walktoxy(&sd->bl, x, y, 4);
  7098. }
  7099. /*==========================================
  7100. *
  7101. *------------------------------------------*/
  7102. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7103. {
  7104. WFIFOHEAD(fd,packet_len(0x18b));
  7105. WFIFOW(fd,0) = 0x18b;
  7106. /* Rovert's prevent logout option fixed [Valaris] */
  7107. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7108. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7109. ) {
  7110. set_eof(fd);
  7111. WFIFOW(fd,2)=0;
  7112. } else {
  7113. WFIFOW(fd,2)=1;
  7114. }
  7115. WFIFOSET(fd,packet_len(0x18b));
  7116. }
  7117. /// Requesting unit's name
  7118. /// S 0094 <object id>.l
  7119. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7120. {
  7121. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7122. struct block_list* bl;
  7123. //struct status_change *sc;
  7124. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7125. id = sd->bl.id;
  7126. bl = map_id2bl(id);
  7127. if( bl == NULL )
  7128. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7129. // 'see people in GM hide' cheat detection
  7130. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7131. sc = status_get_sc(bl);
  7132. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7133. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7134. pc_isGM(sd) < battle_config.hack_info_GM_level
  7135. ) {
  7136. char gm_msg[256];
  7137. 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);
  7138. ShowWarning(gm_msg);
  7139. // information is sent to all online GMs
  7140. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7141. return;
  7142. }
  7143. */
  7144. clif_charnameack(fd, bl);
  7145. }
  7146. /*==========================================
  7147. * Validates and processes global messages
  7148. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7149. *------------------------------------------*/
  7150. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7151. {
  7152. const char* text = (char*)RFIFOP(fd,4);
  7153. int textlen = RFIFOW(fd,2) - 4;
  7154. char *name, *message;
  7155. int namelen, messagelen;
  7156. // validate packet and retrieve name and message
  7157. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7158. return;
  7159. if( is_atcommand(fd, sd, message) )
  7160. return;
  7161. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7162. return;
  7163. if( battle_config.min_chat_delay )
  7164. { //[Skotlex]
  7165. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7166. return;
  7167. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7168. }
  7169. // send message to others (using the send buffer for temp. storage)
  7170. WFIFOHEAD(fd, 8 + textlen);
  7171. WFIFOW(fd,0) = 0x8d;
  7172. WFIFOW(fd,2) = 8 + textlen;
  7173. WFIFOL(fd,4) = sd->bl.id;
  7174. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7175. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7176. // send back message to the speaker
  7177. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7178. WFIFOW(fd,0) = 0x8e;
  7179. WFIFOSET(fd, WFIFOW(fd,2));
  7180. #ifdef PCRE_SUPPORT
  7181. // trigger listening npcs
  7182. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7183. #endif
  7184. // check for special supernovice phrase
  7185. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7186. {
  7187. unsigned int next = pc_nextbaseexp(sd);
  7188. if( next == 0 ) next = pc_thisbaseexp(sd);
  7189. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7190. {
  7191. switch (sd->state.snovice_call_flag) {
  7192. case 0:
  7193. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7194. sd->state.snovice_call_flag++;
  7195. break;
  7196. case 1: {
  7197. char buf[256];
  7198. sprintf(buf, msg_txt(505), sd->status.name);
  7199. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7200. sd->state.snovice_call_flag++;
  7201. }
  7202. break;
  7203. case 2:
  7204. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7205. sd->state.snovice_call_flag++;
  7206. break;
  7207. case 3:
  7208. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7209. break; //Do not override the noskill mapflag. [Skotlex]
  7210. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7211. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7212. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7213. sd->state.snovice_call_flag = 0;
  7214. break;
  7215. }
  7216. }
  7217. }
  7218. // Chat logging type 'O' / Global Chat
  7219. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7220. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7221. return;
  7222. }
  7223. /*==========================================
  7224. * /mm /mapmove (as @rura GM command)
  7225. *------------------------------------------*/
  7226. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7227. {
  7228. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7229. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7230. char* map_name;
  7231. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7232. return;
  7233. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7234. return;
  7235. map_name = (char*)RFIFOP(fd,2);
  7236. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7237. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7238. atcommand_mapmove(fd, sd, "@mapmove", output);
  7239. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7240. {
  7241. sprintf(message, "/mm %s", output);
  7242. log_atcommand(sd, message);
  7243. }
  7244. return;
  7245. }
  7246. /*==========================================
  7247. *
  7248. *------------------------------------------*/
  7249. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7250. {
  7251. unsigned char buf[64];
  7252. WBUFW(buf,0) = 0x9c;
  7253. WBUFL(buf,2) = bl->id;
  7254. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7255. WBUFB(buf,8) = unit_getdir(bl);
  7256. clif_send(buf, packet_len(0x9c), bl, target);
  7257. if (disguised(bl)) {
  7258. WBUFL(buf,2) = -bl->id;
  7259. WBUFW(buf,6) = 0;
  7260. clif_send(buf, packet_len(0x9c), bl, SELF);
  7261. }
  7262. return;
  7263. }
  7264. /*==========================================
  7265. *
  7266. *------------------------------------------*/
  7267. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7268. {
  7269. unsigned char headdir, dir;
  7270. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7271. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7272. pc_setdir(sd, dir, headdir);
  7273. clif_changed_dir(&sd->bl, AREA_WOS);
  7274. return;
  7275. }
  7276. /*==========================================
  7277. *
  7278. *------------------------------------------*/
  7279. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7280. {
  7281. unsigned char buf[64];
  7282. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7283. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7284. clif_skill_fail(sd, 1, 0, 1);
  7285. return;
  7286. }
  7287. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7288. if (sd->emotionlasttime >= time(NULL)) {
  7289. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7290. clif_skill_fail(sd, 1, 0, 1);
  7291. return;
  7292. }
  7293. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7294. WBUFW(buf,0) = 0xc0;
  7295. WBUFL(buf,2) = sd->bl.id;
  7296. WBUFB(buf,6) = RFIFOB(fd,2);
  7297. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7298. } else
  7299. clif_skill_fail(sd, 1, 0, 1);
  7300. }
  7301. /*==========================================
  7302. *
  7303. *------------------------------------------*/
  7304. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7305. {
  7306. WFIFOHEAD(fd,packet_len(0xc2));
  7307. WFIFOW(fd,0) = 0xc2;
  7308. WFIFOL(fd,2) = map_getusers();
  7309. WFIFOSET(fd,packet_len(0xc2));
  7310. }
  7311. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7312. {
  7313. if (pc_isdead(sd)) {
  7314. clif_clearunit_area(&sd->bl, 1);
  7315. return;
  7316. }
  7317. if (sd->sc.count &&
  7318. (sd->sc.data[SC_TRICKDEAD] ||
  7319. sd->sc.data[SC_AUTOCOUNTER] ||
  7320. sd->sc.data[SC_BLADESTOP]))
  7321. return;
  7322. pc_stop_walking(sd, 1);
  7323. pc_stop_attack(sd);
  7324. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7325. target_id = sd->bl.id;
  7326. switch(action_type)
  7327. {
  7328. case 0x00: // once attack
  7329. case 0x07: // continuous attack
  7330. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7331. return;
  7332. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7333. return;
  7334. if( sd->sc.data[SC_BASILICA] )
  7335. return;
  7336. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7337. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7338. clif_skill_fail(sd, 1, 4, 0);
  7339. return;
  7340. }
  7341. }
  7342. pc_delinvincibletimer(sd);
  7343. sd->idletime = last_tick;
  7344. unit_attack(&sd->bl, target_id, action_type != 0);
  7345. break;
  7346. case 0x02: // sitdown
  7347. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7348. clif_skill_fail(sd, 1, 0, 2);
  7349. break;
  7350. }
  7351. if(pc_issit(sd)) {
  7352. //Bugged client? Just refresh them.
  7353. clif_sitting(&sd->bl);
  7354. return;
  7355. }
  7356. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7357. break;
  7358. if (sd->sc.count && (
  7359. sd->sc.data[SC_DANCING] ||
  7360. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7361. )) //No sitting during these states either.
  7362. break;
  7363. pc_setsit(sd);
  7364. skill_sit(sd,1);
  7365. clif_sitting(&sd->bl);
  7366. break;
  7367. case 0x03: // standup
  7368. if (!pc_issit(sd)) {
  7369. //Bugged client? Just refresh them.
  7370. clif_standing(&sd->bl);
  7371. return;
  7372. }
  7373. pc_setstand(sd);
  7374. skill_sit(sd,0);
  7375. clif_standing(&sd->bl);
  7376. break;
  7377. }
  7378. }
  7379. /*==========================================
  7380. *
  7381. *------------------------------------------*/
  7382. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7383. {
  7384. clif_parse_ActionRequest_sub(sd,
  7385. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7386. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7387. gettick()
  7388. );
  7389. }
  7390. /*==========================================
  7391. *
  7392. *------------------------------------------*/
  7393. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7394. {
  7395. switch(RFIFOB(fd,2)) {
  7396. case 0x00:
  7397. pc_respawn(sd,2);
  7398. break;
  7399. case 0x01:
  7400. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7401. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7402. { //Send to char-server for character selection.
  7403. chrif_charselectreq(sd, session[fd]->client_addr);
  7404. } else {
  7405. WFIFOHEAD(fd,packet_len(0x18b));
  7406. WFIFOW(fd,0)=0x18b;
  7407. WFIFOW(fd,2)=1;
  7408. WFIFOSET(fd,packet_len(0x018b));
  7409. }
  7410. break;
  7411. }
  7412. }
  7413. /*==========================================
  7414. * Validates and processes whispered messages
  7415. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7416. *------------------------------------------*/
  7417. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7418. {
  7419. struct map_session_data* dstsd;
  7420. int i;
  7421. char *target, *message;
  7422. int namelen, messagelen;
  7423. // validate packet and retrieve name and message
  7424. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7425. return;
  7426. if (is_atcommand(fd, sd, message) )
  7427. return;
  7428. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7429. return;
  7430. if (battle_config.min_chat_delay)
  7431. { //[Skotlex]
  7432. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7433. return;
  7434. }
  7435. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7436. }
  7437. // Chat logging type 'W' / Whisper
  7438. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7439. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7440. //-------------------------------------------------------//
  7441. // Lordalfa - Paperboy - To whisper NPC commands //
  7442. //-------------------------------------------------------//
  7443. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7444. {
  7445. char* str = target+4; //Skip the NPC: string part.
  7446. struct npc_data* npc;
  7447. if ((npc = npc_name2id(str)))
  7448. {
  7449. char split_data[10][50];
  7450. char *split;
  7451. char output[256];
  7452. str = message;
  7453. for( i = 0; i < 10; ++i )
  7454. {// Splits the message using '#' as separators
  7455. split = strchr(str,'#');
  7456. if( split == NULL )
  7457. { // use the remaining string
  7458. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7459. for( ++i; i < 10; ++i )
  7460. split_data[i][0] = '\0';
  7461. break;
  7462. }
  7463. *split = '\0';
  7464. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7465. str = split+1;
  7466. }
  7467. for( i = 0; i < 10; ++i )
  7468. {
  7469. sprintf(output, "@whispervar%d$", i);
  7470. set_var(sd,output,(char *) split_data[i]);
  7471. }
  7472. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7473. npc_event(sd,output,0); // Calls the NPC label
  7474. return;
  7475. }
  7476. }
  7477. // Main chat [LuzZza]
  7478. if(strcmpi(target, main_chat_nick) == 0)
  7479. {
  7480. if(!sd->state.mainchat)
  7481. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7482. else {
  7483. char output[256];
  7484. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7485. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7486. }
  7487. // Chat logging type 'M' / Main Chat
  7488. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7489. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7490. return;
  7491. }
  7492. // searching destination character
  7493. dstsd = map_nick2sd(target);
  7494. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7495. {
  7496. // player is not on this map-server
  7497. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7498. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7499. // and if we ask for 'Test', we must not contact 'test' player
  7500. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7501. intif_wis_message(sd, target, message, messagelen);
  7502. return;
  7503. }
  7504. // if player ignores everyone
  7505. if (dstsd->state.ignoreAll)
  7506. {
  7507. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7508. clif_wis_end(fd, 1); // 1: target character is not loged in
  7509. else
  7510. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7511. return;
  7512. }
  7513. // if player ignores the source character
  7514. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7515. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7516. { // source char present in ignore list
  7517. clif_wis_end(fd, 2); // 2: ignored by target
  7518. return;
  7519. }
  7520. // if player is autotrading
  7521. if( dstsd->state.autotrade == 1 )
  7522. {
  7523. char output[256];
  7524. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  7525. clif_wis_message(fd, sd->status.name, output, strlen(output) + 1);
  7526. return;
  7527. }
  7528. // notify sender of success
  7529. clif_wis_end(fd, 0); // 0: success to send wisper
  7530. // if player has an auto-away message
  7531. if(dstsd->away_message[0] != '\0')
  7532. {
  7533. char output[256];
  7534. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7535. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7536. if(dstsd->state.autotrade)
  7537. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7538. else
  7539. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7540. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7541. return;
  7542. }
  7543. // Normal message
  7544. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7545. return;
  7546. }
  7547. /*==========================================
  7548. * /b /nb
  7549. * S 0099 <packet len>.w <text>.?B 00
  7550. *------------------------------------------*/
  7551. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7552. {
  7553. char* msg = (char*)RFIFOP(fd,4);
  7554. unsigned int len = RFIFOW(fd,2)-4;
  7555. int lv;
  7556. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7557. return;
  7558. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7559. return;
  7560. // as the length varies depending on the command used, just block unreasonably long strings
  7561. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7562. intif_GMmessage(msg, len, 0);
  7563. if(log_config.gm && lv >= log_config.gm) {
  7564. char logmsg[CHAT_SIZE_MAX+4];
  7565. sprintf(logmsg, "/b %s", msg);
  7566. log_atcommand(sd, logmsg);
  7567. }
  7568. }
  7569. /*==========================================
  7570. *
  7571. *------------------------------------------*/
  7572. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7573. {
  7574. struct flooritem_data *fitem;
  7575. int map_object_id;
  7576. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7577. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7578. do {
  7579. if (pc_isdead(sd)) {
  7580. clif_clearunit_area(&sd->bl, 1);
  7581. break;
  7582. }
  7583. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7584. break;
  7585. if (pc_cant_act(sd))
  7586. break;
  7587. if(sd->sc.count && (
  7588. sd->sc.data[SC_HIDING] ||
  7589. sd->sc.data[SC_CLOAKING] ||
  7590. sd->sc.data[SC_TRICKDEAD] ||
  7591. sd->sc.data[SC_BLADESTOP] ||
  7592. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7593. )
  7594. break;
  7595. if (!pc_takeitem(sd, fitem))
  7596. break;
  7597. return;
  7598. } while (0);
  7599. // Client REQUIRES a fail packet or you can no longer pick items.
  7600. clif_additem(sd,0,0,6);
  7601. }
  7602. /*==========================================
  7603. *
  7604. *------------------------------------------*/
  7605. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7606. {
  7607. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7608. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7609. do {
  7610. if (pc_isdead(sd))
  7611. break;
  7612. if (pc_cant_act(sd))
  7613. break;
  7614. if (sd->sc.count && (
  7615. sd->sc.data[SC_HIDING] ||
  7616. sd->sc.data[SC_AUTOCOUNTER] ||
  7617. sd->sc.data[SC_BLADESTOP] ||
  7618. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7619. ))
  7620. break;
  7621. if (!pc_dropitem(sd, item_index, item_amount))
  7622. break;
  7623. return;
  7624. } while (0);
  7625. //Because the client does not like being ignored.
  7626. clif_delitem(sd, item_index,0);
  7627. }
  7628. /*==========================================
  7629. *
  7630. *------------------------------------------*/
  7631. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7632. {
  7633. int n;
  7634. if (pc_isdead(sd)) {
  7635. clif_clearunit_area(&sd->bl, 1);
  7636. return;
  7637. }
  7638. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7639. return;
  7640. //This flag enables you to use items while in an NPC. [Skotlex]
  7641. if (sd->npc_id) {
  7642. if (sd->npc_id != sd->npc_item_flag)
  7643. return;
  7644. } else
  7645. if (pc_istrading(sd))
  7646. return;
  7647. pc_delinvincibletimer(sd);
  7648. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7649. sd->idletime = last_tick;
  7650. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7651. if(n <0 || n >= MAX_INVENTORY)
  7652. return;
  7653. if (!pc_useitem(sd,n))
  7654. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7655. }
  7656. /*==========================================
  7657. *
  7658. *------------------------------------------*/
  7659. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7660. {
  7661. int index;
  7662. if(pc_isdead(sd)) {
  7663. clif_clearunit_area(&sd->bl,1);
  7664. return;
  7665. }
  7666. index = RFIFOW(fd,2)-2;
  7667. if (index < 0 || index >= MAX_INVENTORY)
  7668. return; //Out of bounds check.
  7669. if(sd->npc_id) {
  7670. if (sd->npc_id != sd->npc_item_flag)
  7671. return;
  7672. } else if (sd->state.storage_flag || sd->sc.opt1)
  7673. ; //You can equip/unequip stuff while storage is open/under status changes
  7674. else if (pc_cant_act(sd))
  7675. return;
  7676. if(!sd->status.inventory[index].identify) {
  7677. clif_equipitemack(sd,index,0,0); // fail
  7678. return;
  7679. }
  7680. if(!sd->inventory_data[index])
  7681. return;
  7682. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7683. pet_equipitem(sd,index);
  7684. return;
  7685. }
  7686. //Client doesn't send the position for ammo.
  7687. if(sd->inventory_data[index]->type == IT_AMMO)
  7688. pc_equipitem(sd,index,EQP_AMMO);
  7689. else
  7690. pc_equipitem(sd,index,RFIFOW(fd,4));
  7691. }
  7692. /*==========================================
  7693. *
  7694. *------------------------------------------*/
  7695. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7696. {
  7697. int index;
  7698. if(pc_isdead(sd)) {
  7699. clif_clearunit_area(&sd->bl,1);
  7700. return;
  7701. }
  7702. if (sd->state.storage_flag)
  7703. ; //You can equip/unequip stuff while storage is open.
  7704. else if (pc_cant_act(sd))
  7705. return;
  7706. index = RFIFOW(fd,2)-2;
  7707. pc_unequipitem(sd,index,1);
  7708. }
  7709. /*==========================================
  7710. *
  7711. *------------------------------------------*/
  7712. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7713. {
  7714. struct block_list *bl;
  7715. if(pc_isdead(sd)) {
  7716. clif_clearunit_area(&sd->bl,1);
  7717. return;
  7718. }
  7719. if (pc_cant_act(sd))
  7720. return;
  7721. bl = map_id2bl(RFIFOL(fd,2));
  7722. if (!bl) return;
  7723. switch (bl->type) {
  7724. case BL_MOB:
  7725. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7726. break;
  7727. case BL_PC:
  7728. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7729. break;
  7730. case BL_NPC:
  7731. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  7732. npc_click(sd,(TBL_NPC*)bl);
  7733. break;
  7734. }
  7735. return;
  7736. }
  7737. /*==========================================
  7738. *
  7739. *------------------------------------------*/
  7740. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7741. {
  7742. if (sd->state.trading)
  7743. return;
  7744. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7745. }
  7746. /// Request to buy chosen items from npc shop
  7747. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  7748. /// R 00ca <result>.b
  7749. /// result = 00 -> "The deal has successfully completed."
  7750. /// result = 01 -> "You do not have enough zeny."
  7751. /// result = 02 -> "You are over your Weight Limit."
  7752. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  7753. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  7754. {
  7755. int n = (RFIFOW(fd,2)-4) /4;
  7756. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  7757. int result;
  7758. if( sd->state.trading || !sd->npc_shopid )
  7759. result = 1;
  7760. else
  7761. result = npc_buylist(sd,n,item_list);
  7762. sd->npc_shopid = 0; //Clear shop data.
  7763. WFIFOHEAD(fd,packet_len(0xca));
  7764. WFIFOW(fd,0) = 0xca;
  7765. WFIFOB(fd,2) = result;
  7766. WFIFOSET(fd,packet_len(0xca));
  7767. }
  7768. /*==========================================
  7769. *
  7770. *------------------------------------------*/
  7771. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7772. {
  7773. int fail=0,n;
  7774. unsigned short *item_list;
  7775. n = (RFIFOW(fd,2)-4) /4;
  7776. item_list = (unsigned short*)RFIFOP(fd,4);
  7777. if (sd->state.trading || !sd->npc_shopid)
  7778. fail = 1;
  7779. else
  7780. fail = npc_selllist(sd,n,item_list);
  7781. sd->npc_shopid = 0; //Clear shop data.
  7782. WFIFOHEAD(fd,packet_len(0xcb));
  7783. WFIFOW(fd,0)=0xcb;
  7784. WFIFOB(fd,2)=fail;
  7785. WFIFOSET(fd,packet_len(0xcb));
  7786. }
  7787. /*==========================================
  7788. * Chatroom creation request
  7789. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7790. *------------------------------------------*/
  7791. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7792. {
  7793. int len = RFIFOW(fd,2)-15;
  7794. int limit = RFIFOW(fd,4);
  7795. bool pub = (RFIFOB(fd,6) != 0);
  7796. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7797. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7798. char s_title[CHATROOM_TITLE_SIZE];
  7799. char s_password[CHATROOM_PASS_SIZE];
  7800. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7801. return;
  7802. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7803. clif_skill_fail(sd,1,0,3);
  7804. return;
  7805. }
  7806. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7807. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7808. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7809. }
  7810. /*==========================================
  7811. * Chatroom join request
  7812. * S 00d9 <chat ID>.l <passwd>.8B
  7813. *------------------------------------------*/
  7814. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7815. {
  7816. int chatid = RFIFOL(fd,2);
  7817. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7818. chat_joinchat(sd,chatid,password);
  7819. }
  7820. /*==========================================
  7821. * Chatroom properties adjustment request
  7822. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7823. *------------------------------------------*/
  7824. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7825. {
  7826. int len = RFIFOW(fd,2)-15;
  7827. int limit = RFIFOW(fd,4);
  7828. bool pub = (RFIFOB(fd,6) != 0);
  7829. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7830. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7831. char s_title[CHATROOM_TITLE_SIZE];
  7832. char s_password[CHATROOM_PASS_SIZE];
  7833. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7834. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7835. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7836. }
  7837. /*==========================================
  7838. * S 00e0 ?.l <nick>.24B
  7839. *------------------------------------------*/
  7840. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7841. {
  7842. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7843. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7844. }
  7845. /*==========================================
  7846. *
  7847. *------------------------------------------*/
  7848. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7849. {
  7850. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7851. }
  7852. /*==========================================
  7853. * Request to leave the current chatroom
  7854. * S 00e3
  7855. *------------------------------------------*/
  7856. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7857. {
  7858. chat_leavechat(sd,0);
  7859. }
  7860. //Handles notifying asker and rejecter of what has just ocurred.
  7861. //Type is used to determine the correct msg_txt to use:
  7862. //0:
  7863. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7864. {
  7865. char *msg, output[256];
  7866. // Your request has been rejected by autoreject option.
  7867. msg = msg_txt(392);
  7868. clif_disp_onlyself(src, msg, strlen(msg));
  7869. //Notice that a request was rejected.
  7870. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7871. clif_disp_onlyself(target, output, strlen(output));
  7872. }
  7873. /*==========================================
  7874. * 取引要請を相手に送る
  7875. *------------------------------------------*/
  7876. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7877. {
  7878. struct map_session_data *t_sd;
  7879. t_sd = map_id2sd(RFIFOL(fd,2));
  7880. if(!sd->chatID && pc_cant_act(sd))
  7881. return; //You can trade while in a chatroom.
  7882. // @noask [LuzZza]
  7883. if(t_sd && t_sd->state.noask) {
  7884. clif_noask_sub(sd, t_sd, 0);
  7885. return;
  7886. }
  7887. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  7888. {
  7889. clif_skill_fail(sd,1,0,0);
  7890. return;
  7891. }
  7892. trade_traderequest(sd,t_sd);
  7893. }
  7894. /*==========================================
  7895. * 取引要請
  7896. *------------------------------------------*/
  7897. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7898. {
  7899. trade_tradeack(sd,RFIFOB(fd,2));
  7900. }
  7901. /*==========================================
  7902. * アイテム追加
  7903. *------------------------------------------*/
  7904. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7905. {
  7906. short index = RFIFOW(fd,2);
  7907. int amount = RFIFOL(fd,4);
  7908. if( index == 0 )
  7909. trade_tradeaddzeny(sd, amount);
  7910. else
  7911. trade_tradeadditem(sd, index, (short)amount);
  7912. }
  7913. /*==========================================
  7914. * アイテム追加完了(ok押し)
  7915. *------------------------------------------*/
  7916. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7917. {
  7918. trade_tradeok(sd);
  7919. }
  7920. /*==========================================
  7921. * 取引キャンセル
  7922. *------------------------------------------*/
  7923. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7924. {
  7925. trade_tradecancel(sd);
  7926. }
  7927. /*==========================================
  7928. * 取引許諾(trade押し)
  7929. *------------------------------------------*/
  7930. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7931. {
  7932. trade_tradecommit(sd);
  7933. }
  7934. /*==========================================
  7935. *
  7936. *------------------------------------------*/
  7937. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7938. {
  7939. pc_stop_attack(sd);
  7940. }
  7941. /*==========================================
  7942. * カートへアイテムを移す
  7943. *------------------------------------------*/
  7944. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7945. {
  7946. if (pc_istrading(sd))
  7947. return;
  7948. if (!pc_iscarton(sd))
  7949. return;
  7950. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7951. }
  7952. /*==========================================
  7953. * カートからアイテムを出す
  7954. *------------------------------------------*/
  7955. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7956. {
  7957. if (!pc_iscarton(sd))
  7958. return;
  7959. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7960. }
  7961. /*==========================================
  7962. * 付属品(鷹,ペコ,カート)をはずす
  7963. *------------------------------------------*/
  7964. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7965. {
  7966. //Can only remove Cart/Riding/Falcon.
  7967. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7968. }
  7969. /*==========================================
  7970. * チェンジカート
  7971. *------------------------------------------*/
  7972. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7973. {
  7974. int type;
  7975. type = (int)RFIFOW(fd,2);
  7976. if( (type == 5 && sd->status.base_level > 90) ||
  7977. (type == 4 && sd->status.base_level > 80) ||
  7978. (type == 3 && sd->status.base_level > 65) ||
  7979. (type == 2 && sd->status.base_level > 40) ||
  7980. (type == 1))
  7981. pc_setcart(sd,type);
  7982. }
  7983. /*==========================================
  7984. * ステータスアップ
  7985. *------------------------------------------*/
  7986. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7987. {
  7988. pc_statusup(sd,RFIFOW(fd,2));
  7989. }
  7990. /*==========================================
  7991. * スキルレベルアップ
  7992. *------------------------------------------*/
  7993. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7994. {
  7995. pc_skillup(sd,RFIFOW(fd,2));
  7996. }
  7997. 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)
  7998. {
  7999. int lv;
  8000. if( !hd )
  8001. return;
  8002. if( skillnotok_hom(skillnum, hd) )
  8003. return;
  8004. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8005. target_id = hd->bl.id;
  8006. if( hd->ud.skilltimer != -1 )
  8007. {
  8008. if( skillnum != SA_CASTCANCEL ) return;
  8009. }
  8010. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8011. return;
  8012. lv = merc_hom_checkskill(hd, skillnum);
  8013. if( skilllv > lv )
  8014. skilllv = lv;
  8015. if( skilllv )
  8016. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8017. }
  8018. 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)
  8019. {
  8020. int lv;
  8021. if( !md )
  8022. return;
  8023. if( skillnotok_mercenary(skillnum, md) )
  8024. return;
  8025. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8026. target_id = md->bl.id;
  8027. if( md->ud.skilltimer != INVALID_TIMER )
  8028. {
  8029. if( skillnum != SA_CASTCANCEL ) return;
  8030. }
  8031. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8032. return;
  8033. lv = mercenary_checkskill(md, skillnum);
  8034. if( skilllv > lv )
  8035. skilllv = lv;
  8036. if( skilllv )
  8037. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8038. }
  8039. 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)
  8040. {
  8041. int lv;
  8042. if( !md )
  8043. return;
  8044. if( skillnotok_mercenary(skillnum, md) )
  8045. return;
  8046. if( md->ud.skilltimer != INVALID_TIMER )
  8047. return;
  8048. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8049. {
  8050. clif_skill_fail(md->master, skillnum, 4, 0);
  8051. return;
  8052. }
  8053. if( md->sc.data[SC_BASILICA] )
  8054. return;
  8055. lv = mercenary_checkskill(md, skillnum);
  8056. if( skilllv > lv )
  8057. skilllv = lv;
  8058. if( skilllv )
  8059. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8060. }
  8061. /*==========================================
  8062. * スキル使用(ID指定)
  8063. *------------------------------------------*/
  8064. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8065. {
  8066. short skillnum, skilllv;
  8067. int tmp, target_id;
  8068. unsigned int tick = gettick();
  8069. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8070. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8071. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8072. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8073. tmp = skill_get_inf(skillnum);
  8074. if (tmp&INF_GROUND_SKILL || !tmp)
  8075. return; //Using a ground/passive skill on a target? WRONG.
  8076. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8077. {
  8078. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8079. return;
  8080. }
  8081. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8082. {
  8083. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8084. return;
  8085. }
  8086. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8087. sd->idletime = last_tick;
  8088. if( pc_cant_act(sd) )
  8089. return;
  8090. if( pc_issit(sd) )
  8091. return;
  8092. if( skillnotok(skillnum, sd) )
  8093. return;
  8094. if( sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL )
  8095. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8096. if( sd->ud.skilltimer != -1 )
  8097. {
  8098. if( skillnum != SA_CASTCANCEL )
  8099. return;
  8100. }
  8101. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8102. {
  8103. clif_skill_fail(sd, skillnum, 4, 0);
  8104. return;
  8105. }
  8106. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8107. return;
  8108. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8109. return; // On basilica only caster can use Basilica again to stop it.
  8110. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8111. target_id = sd->bl.id;
  8112. if( sd->menuskill_id )
  8113. {
  8114. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8115. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8116. else if( sd->menuskill_id != SA_AUTOSPELL )
  8117. return; //Can't use skills while a menu is open.
  8118. }
  8119. if( sd->skillitem == skillnum )
  8120. {
  8121. if( skilllv != sd->skillitemlv )
  8122. skilllv = sd->skillitemlv;
  8123. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8124. return;
  8125. }
  8126. sd->skillitem = sd->skillitemlv = 0;
  8127. if( skillnum == MO_EXTREMITYFIST )
  8128. {
  8129. if( (!sd->sc.data[SC_COMBO] ||
  8130. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8131. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8132. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8133. if( !sd->state.skill_flag )
  8134. {
  8135. sd->state.skill_flag = 1;
  8136. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8137. return;
  8138. } else if( sd->bl.id == target_id )
  8139. {
  8140. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8141. return;
  8142. }
  8143. }
  8144. }
  8145. if( skillnum == TK_JUMPKICK )
  8146. {
  8147. if( !sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK )
  8148. {
  8149. if( !sd->state.skill_flag )
  8150. {
  8151. sd->state.skill_flag = 1;
  8152. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8153. return;
  8154. }
  8155. else if( sd->bl.id == target_id )
  8156. {
  8157. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8158. return;
  8159. }
  8160. }
  8161. }
  8162. if( skillnum >= GD_SKILLBASE )
  8163. {
  8164. if( sd->state.gmaster_flag )
  8165. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8166. else
  8167. skilllv = 0;
  8168. }
  8169. else
  8170. {
  8171. tmp = pc_checkskill(sd, skillnum);
  8172. if( skilllv > tmp )
  8173. skilllv = tmp;
  8174. }
  8175. pc_delinvincibletimer(sd);
  8176. if( skilllv )
  8177. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8178. if( sd->state.skill_flag )
  8179. sd->state.skill_flag = 0;
  8180. }
  8181. /*==========================================
  8182. * スキル使用(場所指定)
  8183. *------------------------------------------*/
  8184. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8185. {
  8186. int lv;
  8187. unsigned int tick = gettick();
  8188. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8189. return; //Using a target skill on the ground? WRONG.
  8190. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8191. {
  8192. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8193. return;
  8194. }
  8195. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8196. sd->idletime = last_tick;
  8197. if( skillnotok(skillnum, sd) )
  8198. return;
  8199. if( skillmoreinfo != -1 )
  8200. {
  8201. if( pc_issit(sd) )
  8202. {
  8203. clif_skill_fail(sd, skillnum, 0, 0);
  8204. return;
  8205. }
  8206. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8207. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8208. }
  8209. if( sd->ud.skilltimer != -1 )
  8210. return;
  8211. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8212. {
  8213. clif_skill_fail(sd, skillnum, 4, 0);
  8214. return;
  8215. }
  8216. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8217. return;
  8218. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8219. return; // On basilica only caster can use Basilica again to stop it.
  8220. if( sd->menuskill_id )
  8221. {
  8222. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8223. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8224. else if( sd->menuskill_id != SA_AUTOSPELL )
  8225. return; //Can't use skills while a menu is open.
  8226. }
  8227. pc_delinvincibletimer(sd);
  8228. if( sd->skillitem == skillnum )
  8229. {
  8230. if( skilllv != sd->skillitemlv )
  8231. skilllv = sd->skillitemlv;
  8232. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8233. }
  8234. else
  8235. {
  8236. sd->skillitem = sd->skillitemlv = 0;
  8237. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8238. {
  8239. if( skilllv > lv )
  8240. skilllv = lv;
  8241. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8242. }
  8243. }
  8244. }
  8245. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8246. {
  8247. if (pc_cant_act(sd))
  8248. return;
  8249. if (pc_issit(sd))
  8250. return;
  8251. clif_parse_UseSkillToPosSub(fd, sd,
  8252. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8253. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8254. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8255. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8256. -1 //Skill more info.
  8257. );
  8258. }
  8259. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8260. {
  8261. if (pc_cant_act(sd))
  8262. return;
  8263. if (pc_issit(sd))
  8264. return;
  8265. clif_parse_UseSkillToPosSub(fd, sd,
  8266. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8267. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8268. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8269. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8270. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8271. );
  8272. }
  8273. /*==========================================
  8274. * スキル使用(map指定)
  8275. *------------------------------------------*/
  8276. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8277. {
  8278. short skill_num = RFIFOW(fd,2);
  8279. char map_name[MAP_NAME_LENGTH];
  8280. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8281. if(skill_num != sd->menuskill_id)
  8282. return;
  8283. if( pc_cant_act(sd) )
  8284. {
  8285. sd->menuskill_id = sd->menuskill_val = 0;
  8286. return;
  8287. }
  8288. pc_delinvincibletimer(sd);
  8289. skill_castend_map(sd,skill_num,map_name);
  8290. }
  8291. /*==========================================
  8292. * メモ要求
  8293. *------------------------------------------*/
  8294. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8295. {
  8296. if (!pc_isdead(sd))
  8297. pc_memo(sd,-1);
  8298. }
  8299. /*==========================================
  8300. * アイテム合成
  8301. *------------------------------------------*/
  8302. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8303. {
  8304. if (sd->menuskill_id != AM_PHARMACY)
  8305. return;
  8306. if (pc_istrading(sd)) {
  8307. //Make it fail to avoid shop exploits where you sell something different than you see.
  8308. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8309. sd->menuskill_val = sd->menuskill_id = 0;
  8310. return;
  8311. }
  8312. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8313. sd->menuskill_val = sd->menuskill_id = 0;
  8314. }
  8315. /*==========================================
  8316. * 武器修理
  8317. *------------------------------------------*/
  8318. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8319. {
  8320. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8321. return;
  8322. if (pc_istrading(sd)) {
  8323. //Make it fail to avoid shop exploits where you sell something different than you see.
  8324. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8325. sd->menuskill_val = sd->menuskill_id = 0;
  8326. return;
  8327. }
  8328. skill_repairweapon(sd,RFIFOW(fd,2));
  8329. sd->menuskill_val = sd->menuskill_id = 0;
  8330. }
  8331. /*==========================================
  8332. *
  8333. *------------------------------------------*/
  8334. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8335. {
  8336. int idx;
  8337. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8338. return;
  8339. if (pc_istrading(sd)) {
  8340. //Make it fail to avoid shop exploits where you sell something different than you see.
  8341. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8342. sd->menuskill_val = sd->menuskill_id = 0;
  8343. return;
  8344. }
  8345. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8346. skill_weaponrefine(sd, idx-2);
  8347. sd->menuskill_val = sd->menuskill_id = 0;
  8348. }
  8349. /*==========================================
  8350. *
  8351. *------------------------------------------*/
  8352. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8353. {
  8354. uint8 select;
  8355. select = RFIFOB(fd,6);
  8356. if((select > sd->npc_menu && select != 0xff) || !select){
  8357. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8358. clif_GM_kick(NULL,sd);
  8359. } else {
  8360. sd->npc_menu=select;
  8361. npc_scriptcont(sd,RFIFOL(fd,2));
  8362. }
  8363. }
  8364. /*==========================================
  8365. *
  8366. *------------------------------------------*/
  8367. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8368. {
  8369. npc_scriptcont(sd,RFIFOL(fd,2));
  8370. }
  8371. /*==========================================
  8372. * Value entered into a NPC input box.
  8373. * S 0143 <npcID>.l <amount>.l
  8374. *------------------------------------------*/
  8375. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8376. {
  8377. int npcid = RFIFOL(fd,2);
  8378. int amount = (int)RFIFOL(fd,6);
  8379. sd->npc_amount = amount;
  8380. npc_scriptcont(sd, npcid);
  8381. }
  8382. /*==========================================
  8383. * Text entered into a NPC input box.
  8384. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8385. *------------------------------------------*/
  8386. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8387. {
  8388. int message_len = RFIFOW(fd,2)-8;
  8389. int npcid = RFIFOL(fd,4);
  8390. const char* message = (char*)RFIFOP(fd,8);
  8391. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8392. npc_scriptcont(sd, npcid);
  8393. }
  8394. /*==========================================
  8395. *
  8396. *------------------------------------------*/
  8397. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8398. {
  8399. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8400. return;
  8401. npc_scriptcont(sd,RFIFOL(fd,2));
  8402. }
  8403. /*==========================================
  8404. * アイテム鑑定
  8405. *------------------------------------------*/
  8406. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8407. {
  8408. if (sd->menuskill_id != MC_IDENTIFY)
  8409. return;
  8410. skill_identify(sd,RFIFOW(fd,2)-2);
  8411. sd->menuskill_val = sd->menuskill_id = 0;
  8412. }
  8413. /*==========================================
  8414. * 矢作成
  8415. *------------------------------------------*/
  8416. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8417. {
  8418. if (sd->menuskill_id != AC_MAKINGARROW)
  8419. return;
  8420. if (pc_istrading(sd)) {
  8421. //Make it fail to avoid shop exploits where you sell something different than you see.
  8422. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8423. sd->menuskill_val = sd->menuskill_id = 0;
  8424. return;
  8425. }
  8426. skill_arrow_create(sd,RFIFOW(fd,2));
  8427. sd->menuskill_val = sd->menuskill_id = 0;
  8428. }
  8429. /*==========================================
  8430. * オートスペル受信
  8431. *------------------------------------------*/
  8432. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8433. {
  8434. if (sd->menuskill_id != SA_AUTOSPELL)
  8435. return;
  8436. skill_autospell(sd,RFIFOW(fd,2));
  8437. sd->menuskill_val = sd->menuskill_id = 0;
  8438. }
  8439. /*==========================================
  8440. * カード使用
  8441. *------------------------------------------*/
  8442. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8443. {
  8444. if (sd->state.trading != 0)
  8445. return;
  8446. clif_use_card(sd,RFIFOW(fd,2)-2);
  8447. }
  8448. /*==========================================
  8449. * カード挿入装備選択
  8450. *------------------------------------------*/
  8451. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8452. {
  8453. if (sd->state.trading != 0)
  8454. return;
  8455. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8456. }
  8457. /*==========================================
  8458. * 0193 キャラID名前引き
  8459. *------------------------------------------*/
  8460. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8461. {
  8462. int charid;
  8463. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8464. map_reqnickdb(sd, charid);
  8465. }
  8466. /*==========================================
  8467. * 0197 /resetskill /resetstate
  8468. *------------------------------------------*/
  8469. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8470. {
  8471. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8472. return;
  8473. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8474. return;
  8475. if( RFIFOW(fd,2) )
  8476. pc_resetskill(sd,1);
  8477. else
  8478. pc_resetstate(sd);
  8479. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8480. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8481. }
  8482. /*==========================================
  8483. * /lb /nlb
  8484. * S 019c <packet len>.w <text>.?B 00
  8485. *------------------------------------------*/
  8486. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8487. {
  8488. char* msg = (char*)RFIFOP(fd,4);
  8489. unsigned int len = RFIFOW(fd,2)-4;
  8490. int lv;
  8491. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8492. return;
  8493. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8494. return;
  8495. // as the length varies depending on the command used, just block unreasonably long strings
  8496. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8497. clif_GMmessage(&sd->bl, msg, len, 1);
  8498. if( log_config.gm && lv >= log_config.gm ) {
  8499. char logmsg[CHAT_SIZE_MAX+5];
  8500. sprintf(logmsg, "/lb %s", msg);
  8501. log_atcommand(sd, logmsg);
  8502. }
  8503. }
  8504. /*==========================================
  8505. * カプラ倉庫へ入れる
  8506. *------------------------------------------*/
  8507. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8508. {
  8509. int item_index, item_amount;
  8510. if (pc_istrading(sd))
  8511. return;
  8512. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8513. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8514. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8515. return;
  8516. if (sd->state.storage_flag == 1)
  8517. storage_storageadd(sd, item_index, item_amount);
  8518. else
  8519. if (sd->state.storage_flag == 2)
  8520. storage_guild_storageadd(sd, item_index, item_amount);
  8521. }
  8522. /*==========================================
  8523. * カプラ倉庫から出す
  8524. *------------------------------------------*/
  8525. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8526. {
  8527. int item_index, item_amount;
  8528. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8529. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8530. if (sd->state.storage_flag == 1)
  8531. storage_storageget(sd, item_index, item_amount);
  8532. else
  8533. if(sd->state.storage_flag == 2)
  8534. storage_guild_storageget(sd, item_index, item_amount);
  8535. }
  8536. /*==========================================
  8537. * カプラ倉庫へカートから入れる
  8538. *------------------------------------------*/
  8539. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8540. {
  8541. if(sd->vender_id)
  8542. return;
  8543. if (!pc_iscarton(sd))
  8544. return;
  8545. if (sd->state.storage_flag == 1)
  8546. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8547. else
  8548. if (sd->state.storage_flag == 2)
  8549. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8550. }
  8551. /*==========================================
  8552. * カプラ倉庫から出す
  8553. *------------------------------------------*/
  8554. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8555. {
  8556. if (sd->vender_id)
  8557. return;
  8558. if (!pc_iscarton(sd))
  8559. return;
  8560. if (sd->state.storage_flag == 1)
  8561. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8562. else
  8563. if (sd->state.storage_flag == 2)
  8564. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8565. }
  8566. /*==========================================
  8567. * カプラ倉庫を閉じる
  8568. *------------------------------------------*/
  8569. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8570. {
  8571. if( sd->state.storage_flag == 1 )
  8572. storage_storageclose(sd);
  8573. else
  8574. if( sd->state.storage_flag == 2 )
  8575. storage_guild_storageclose(sd);
  8576. }
  8577. /*==========================================
  8578. * Kafra storage protection password system
  8579. *------------------------------------------*/
  8580. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8581. {
  8582. //TODO
  8583. }
  8584. /*==========================================
  8585. * Party creation request
  8586. * S 00f9 <party name>.24S
  8587. * S 01e8 <party name>.24S <item1>.B <item2>.B
  8588. *------------------------------------------*/
  8589. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8590. {
  8591. char* name = (char*)RFIFOP(fd,2);
  8592. name[NAME_LENGTH-1] = '\0';
  8593. if( map[sd->bl.m].flag.partylock )
  8594. {// Party locked.
  8595. clif_displaymessage(fd, msg_txt(227));
  8596. return;
  8597. }
  8598. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8599. {
  8600. clif_skill_fail(sd,1,0,4);
  8601. return;
  8602. }
  8603. party_create(sd,name,0,0);
  8604. }
  8605. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8606. {
  8607. char* name = (char*)RFIFOP(fd,2);
  8608. int item1 = RFIFOB(fd,26);
  8609. int item2 = RFIFOB(fd,27);
  8610. name[NAME_LENGTH-1] = '\0';
  8611. if( map[sd->bl.m].flag.partylock )
  8612. {// Party locked.
  8613. clif_displaymessage(fd, msg_txt(227));
  8614. return;
  8615. }
  8616. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8617. {
  8618. clif_skill_fail(sd,1,0,4);
  8619. return;
  8620. }
  8621. party_create(sd,name,item1,item2);
  8622. }
  8623. /*==========================================
  8624. * Party invitation request
  8625. * S 00fc <account ID>.L
  8626. * S 02c4 <char name>.24S
  8627. *------------------------------------------*/
  8628. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8629. {
  8630. struct map_session_data *t_sd;
  8631. if(map[sd->bl.m].flag.partylock)
  8632. {// Party locked.
  8633. clif_displaymessage(fd, msg_txt(227));
  8634. return;
  8635. }
  8636. t_sd = map_id2sd(RFIFOL(fd,2));
  8637. if(t_sd && t_sd->state.noask)
  8638. {// @noask [LuzZza]
  8639. clif_noask_sub(sd, t_sd, 1);
  8640. return;
  8641. }
  8642. party_invite(sd, t_sd);
  8643. }
  8644. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8645. {
  8646. struct map_session_data *t_sd;
  8647. char *name = (char*)RFIFOP(fd,2);
  8648. name[NAME_LENGTH-1] = '\0';
  8649. if(map[sd->bl.m].flag.partylock)
  8650. {// Party locked.
  8651. clif_displaymessage(fd, msg_txt(227));
  8652. return;
  8653. }
  8654. t_sd = map_nick2sd(name);
  8655. if(t_sd && t_sd->state.noask)
  8656. {// @noask [LuzZza]
  8657. clif_noask_sub(sd, t_sd, 1);
  8658. return;
  8659. }
  8660. party_invite(sd, t_sd);
  8661. }
  8662. /*==========================================
  8663. * Party invitation reply
  8664. * S 00ff <account ID>.L <flag>.L
  8665. * S 02c7 <account ID>.L <flag>.B
  8666. * flag: 0-reject, 1-accept
  8667. *------------------------------------------*/
  8668. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8669. {
  8670. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8671. }
  8672. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8673. {
  8674. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8675. }
  8676. /*==========================================
  8677. * パーティ脱退要求
  8678. *------------------------------------------*/
  8679. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8680. {
  8681. if(map[sd->bl.m].flag.partylock)
  8682. { //Guild locked.
  8683. clif_displaymessage(fd, msg_txt(227));
  8684. return;
  8685. }
  8686. party_leave(sd);
  8687. }
  8688. /*==========================================
  8689. * パーティ除名要求
  8690. *------------------------------------------*/
  8691. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8692. {
  8693. if(map[sd->bl.m].flag.partylock)
  8694. { //Guild locked.
  8695. clif_displaymessage(fd, msg_txt(227));
  8696. return;
  8697. }
  8698. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8699. }
  8700. /*==========================================
  8701. * パーティ設定変更要求
  8702. *------------------------------------------*/
  8703. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8704. {
  8705. struct party_data *p;
  8706. int i;
  8707. if( !sd->status.party_id )
  8708. return;
  8709. p = party_search(sd->status.party_id);
  8710. if( p == NULL )
  8711. return;
  8712. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8713. if( i == MAX_PARTY )
  8714. return; //Shouldn't happen
  8715. if( !p->party.member[i].leader )
  8716. return;
  8717. //The client no longer can change the item-field, therefore it always
  8718. //comes as zero. Here, resend the item data as it is.
  8719. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8720. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8721. }
  8722. /*==========================================
  8723. * Validates and processes party messages
  8724. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8725. *------------------------------------------*/
  8726. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8727. {
  8728. const char* text = (char*)RFIFOP(fd,4);
  8729. int textlen = RFIFOW(fd,2) - 4;
  8730. char *name, *message;
  8731. int namelen, messagelen;
  8732. // validate packet and retrieve name and message
  8733. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8734. return;
  8735. if( is_atcommand(fd, sd, message) )
  8736. return;
  8737. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8738. return;
  8739. if( battle_config.min_chat_delay )
  8740. { //[Skotlex]
  8741. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8742. return;
  8743. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8744. }
  8745. party_send_message(sd, text, textlen);
  8746. }
  8747. /*==========================================
  8748. * 露店閉鎖
  8749. *------------------------------------------*/
  8750. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8751. {
  8752. vending_closevending(sd);
  8753. }
  8754. /*==========================================
  8755. * 露店アイテムリスト要求
  8756. *------------------------------------------*/
  8757. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8758. {
  8759. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8760. if( sd->npc_id )
  8761. npc_event_dequeue(sd);
  8762. }
  8763. /*==========================================
  8764. * Shop item(s) purchase request
  8765. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8766. *------------------------------------------*/
  8767. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8768. {
  8769. int len = (int)RFIFOW(fd,2) - 8;
  8770. int id = (int)RFIFOL(fd,4);
  8771. const uint8* data = (uint8*)RFIFOP(fd,8);
  8772. vending_purchasereq(sd, id, data, len/4);
  8773. }
  8774. /*==========================================
  8775. * Confirm or cancel the shop preparation window
  8776. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8777. * flag: 0=cancel, 1=confirm
  8778. *------------------------------------------*/
  8779. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8780. {
  8781. short len = (short)RFIFOW(fd,2) - 85;
  8782. const char* message = (char*)RFIFOP(fd,4);
  8783. bool flag = (bool)RFIFOB(fd,84);
  8784. const uint8* data = (uint8*)RFIFOP(fd,85);
  8785. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8786. return;
  8787. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8788. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  8789. return;
  8790. }
  8791. if( message[0] == '\0' ) // invalid input
  8792. return;
  8793. vending_openvending(sd, message, flag, data, len/8);
  8794. }
  8795. /*==========================================
  8796. * Guild creation request
  8797. * S 0165 <account id>.L <guild name>.24S
  8798. *------------------------------------------*/
  8799. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8800. {
  8801. char* name = (char*)RFIFOP(fd,6);
  8802. name[NAME_LENGTH-1] = '\0';
  8803. if(map[sd->bl.m].flag.guildlock)
  8804. { //Guild locked.
  8805. clif_displaymessage(fd, msg_txt(228));
  8806. return;
  8807. }
  8808. guild_create(sd, name);
  8809. }
  8810. /*==========================================
  8811. * ギルドマスターかどうか確認
  8812. *------------------------------------------*/
  8813. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8814. {
  8815. clif_guild_masterormember(sd);
  8816. }
  8817. /*==========================================
  8818. * ギルド情報要求
  8819. *------------------------------------------*/
  8820. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8821. {
  8822. if (!sd->status.guild_id)
  8823. return;
  8824. switch(RFIFOL(fd,2)){
  8825. case 0: // ギルド基本情報、同盟敵対情報
  8826. clif_guild_basicinfo(sd);
  8827. clif_guild_allianceinfo(sd);
  8828. break;
  8829. case 1: // メンバーリスト、役職名リスト
  8830. clif_guild_positionnamelist(sd);
  8831. clif_guild_memberlist(sd);
  8832. break;
  8833. case 2: // 役職名リスト、役職情報リスト
  8834. clif_guild_positionnamelist(sd);
  8835. clif_guild_positioninfolist(sd);
  8836. break;
  8837. case 3: // スキルリスト
  8838. clif_guild_skillinfo(sd);
  8839. break;
  8840. case 4: // 追放リスト
  8841. clif_guild_expulsionlist(sd);
  8842. break;
  8843. default:
  8844. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8845. break;
  8846. }
  8847. }
  8848. /*==========================================
  8849. * ギルド役職変更
  8850. *------------------------------------------*/
  8851. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8852. {
  8853. int i;
  8854. if(!sd->state.gmaster_flag)
  8855. return;
  8856. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8857. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8858. }
  8859. }
  8860. /*==========================================
  8861. * ギルドメンバ役職変更
  8862. *------------------------------------------*/
  8863. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8864. {
  8865. int i;
  8866. if(!sd->state.gmaster_flag)
  8867. return;
  8868. for(i=4;i<RFIFOW(fd,2);i+=12){
  8869. guild_change_memberposition(sd->status.guild_id,
  8870. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8871. }
  8872. }
  8873. /*==========================================
  8874. * ギルドエンブレム要求
  8875. *------------------------------------------*/
  8876. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8877. {
  8878. struct guild* g = guild_search(RFIFOL(fd,2));
  8879. if(g!=NULL)
  8880. clif_guild_emblem(sd,g);
  8881. }
  8882. /*==========================================
  8883. * ギルドエンブレム変更
  8884. *------------------------------------------*/
  8885. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8886. {
  8887. if(!sd->state.gmaster_flag)
  8888. return;
  8889. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8890. }
  8891. /*==========================================
  8892. * Guild notice update request
  8893. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8894. *------------------------------------------*/
  8895. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8896. {
  8897. int guild_id = RFIFOL(fd,2);
  8898. char* msg1 = (char*)RFIFOP(fd,6);
  8899. char* msg2 = (char*)RFIFOP(fd,66);
  8900. if(!sd->state.gmaster_flag)
  8901. return;
  8902. // compensate for some client defects when using multilanguage mode
  8903. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8904. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8905. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8906. guild_change_notice(sd, guild_id, msg1, msg2);
  8907. }
  8908. /*==========================================
  8909. * ギルド勧誘
  8910. *------------------------------------------*/
  8911. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8912. {
  8913. struct map_session_data *t_sd;
  8914. if(map[sd->bl.m].flag.guildlock)
  8915. { //Guild locked.
  8916. clif_displaymessage(fd, msg_txt(228));
  8917. return;
  8918. }
  8919. t_sd = map_id2sd(RFIFOL(fd,2));
  8920. // @noask [LuzZza]
  8921. if(t_sd && t_sd->state.noask) {
  8922. clif_noask_sub(sd, t_sd, 2);
  8923. return;
  8924. }
  8925. guild_invite(sd,t_sd);
  8926. }
  8927. /*==========================================
  8928. * ギルド勧誘返信
  8929. *------------------------------------------*/
  8930. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8931. {
  8932. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8933. }
  8934. /*==========================================
  8935. * ギルド脱退
  8936. *------------------------------------------*/
  8937. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8938. {
  8939. if(map[sd->bl.m].flag.guildlock)
  8940. { //Guild locked.
  8941. clif_displaymessage(fd, msg_txt(228));
  8942. return;
  8943. }
  8944. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8945. }
  8946. /*==========================================
  8947. * Request to expel a member of a guild
  8948. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8949. *------------------------------------------*/
  8950. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8951. {
  8952. if(map[sd->bl.m].flag.guildlock)
  8953. { //Guild locked.
  8954. clif_displaymessage(fd, msg_txt(228));
  8955. return;
  8956. }
  8957. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8958. }
  8959. /*==========================================
  8960. * Validates and processes guild messages
  8961. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8962. *------------------------------------------*/
  8963. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8964. {
  8965. const char* text = (char*)RFIFOP(fd,4);
  8966. int textlen = RFIFOW(fd,2) - 4;
  8967. char *name, *message;
  8968. int namelen, messagelen;
  8969. // validate packet and retrieve name and message
  8970. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8971. return;
  8972. if( is_atcommand(fd, sd, message) )
  8973. return;
  8974. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8975. return;
  8976. if( battle_config.min_chat_delay )
  8977. { //[Skotlex]
  8978. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8979. return;
  8980. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8981. }
  8982. guild_send_message(sd, text, textlen);
  8983. }
  8984. /*==========================================
  8985. * ギルド同盟要求
  8986. *------------------------------------------*/
  8987. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8988. {
  8989. struct map_session_data *t_sd;
  8990. if(!sd->state.gmaster_flag)
  8991. return;
  8992. if(map[sd->bl.m].flag.guildlock)
  8993. { //Guild locked.
  8994. clif_displaymessage(fd, msg_txt(228));
  8995. return;
  8996. }
  8997. t_sd = map_id2sd(RFIFOL(fd,2));
  8998. // @noask [LuzZza]
  8999. if(t_sd && t_sd->state.noask) {
  9000. clif_noask_sub(sd, t_sd, 3);
  9001. return;
  9002. }
  9003. guild_reqalliance(sd,t_sd);
  9004. }
  9005. /*==========================================
  9006. * ギルド同盟要求返信
  9007. *------------------------------------------*/
  9008. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9009. {
  9010. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9011. }
  9012. /*==========================================
  9013. * ギルド関係解消
  9014. *------------------------------------------*/
  9015. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9016. {
  9017. if(!sd->state.gmaster_flag)
  9018. return;
  9019. if(map[sd->bl.m].flag.guildlock)
  9020. { //Guild locked.
  9021. clif_displaymessage(fd, msg_txt(228));
  9022. return;
  9023. }
  9024. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9025. }
  9026. /*==========================================
  9027. * ギルド敵対
  9028. *------------------------------------------*/
  9029. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9030. {
  9031. struct map_session_data *t_sd;
  9032. if(!sd->state.gmaster_flag)
  9033. return;
  9034. if(map[sd->bl.m].flag.guildlock)
  9035. { //Guild locked.
  9036. clif_displaymessage(fd, msg_txt(228));
  9037. return;
  9038. }
  9039. t_sd = map_id2sd(RFIFOL(fd,2));
  9040. // @noask [LuzZza]
  9041. if(t_sd && t_sd->state.noask) {
  9042. clif_noask_sub(sd, t_sd, 4);
  9043. return;
  9044. }
  9045. guild_opposition(sd,t_sd);
  9046. }
  9047. /*==========================================
  9048. * ギルド解散
  9049. *------------------------------------------*/
  9050. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9051. {
  9052. if(map[sd->bl.m].flag.guildlock)
  9053. { //Guild locked.
  9054. clif_displaymessage(fd, msg_txt(228));
  9055. return;
  9056. }
  9057. guild_break(sd,(char*)RFIFOP(fd,2));
  9058. }
  9059. // pet
  9060. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9061. {
  9062. pet_menu(sd,RFIFOB(fd,2));
  9063. }
  9064. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9065. {
  9066. pet_catch_process2(sd,RFIFOL(fd,2));
  9067. }
  9068. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9069. {
  9070. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9071. {
  9072. //Forged packet, disconnect them [Kevin]
  9073. clif_authfail_fd(fd, 0);
  9074. return;
  9075. }
  9076. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9077. sd->menuskill_val = sd->menuskill_id = 0;
  9078. }
  9079. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9080. {
  9081. if(sd->pd)
  9082. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9083. }
  9084. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9085. {
  9086. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9087. }
  9088. /*==========================================
  9089. * /kill <???>
  9090. * (or right click menu for GM "(name) force to quit")
  9091. * S 00cc <id>.L
  9092. *------------------------------------------*/
  9093. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9094. {
  9095. struct block_list *target;
  9096. int tid,lv;
  9097. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9098. return;
  9099. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  9100. return;
  9101. tid = RFIFOL(fd,2);
  9102. target = map_id2bl(tid);
  9103. if (!target) {
  9104. clif_GM_kickack(sd, 0);
  9105. return;
  9106. }
  9107. switch (target->type) {
  9108. case BL_PC:
  9109. {
  9110. struct map_session_data *tsd = (struct map_session_data *)target;
  9111. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9112. clif_GM_kickack(sd, 0);
  9113. return;
  9114. }
  9115. clif_GM_kick(sd, tsd);
  9116. if(log_config.gm && lv >= log_config.gm) {
  9117. char message[256];
  9118. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9119. log_atcommand(sd, message);
  9120. }
  9121. }
  9122. break;
  9123. case BL_MOB:
  9124. status_percent_damage(&sd->bl, target, 100, 0, true);
  9125. if(log_config.gm && lv >= log_config.gm) {
  9126. char message[256];
  9127. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9128. log_atcommand(sd, message);
  9129. }
  9130. break;
  9131. case BL_NPC:
  9132. {
  9133. struct npc_data* nd = (struct npc_data *)target;
  9134. lv = get_atcommand_level(atcommand_unloadnpc);
  9135. if( pc_isGM(sd) < lv )
  9136. return;
  9137. // copy-pasted from atcommand_unloadnpc
  9138. npc_unload_duplicates(nd);
  9139. npc_unload(nd);
  9140. npc_read_event_script();
  9141. if( log_config.gm && lv >= log_config.gm ) {
  9142. char message[256];
  9143. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9144. log_atcommand(sd, message);
  9145. }
  9146. }
  9147. break;
  9148. default:
  9149. clif_GM_kickack(sd, 0);
  9150. }
  9151. }
  9152. /*==========================================
  9153. * /killall
  9154. *------------------------------------------*/
  9155. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9156. {
  9157. is_atcommand(fd, sd, "@kickall");
  9158. }
  9159. /*==========================================
  9160. * /shift <name>
  9161. *------------------------------------------*/
  9162. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9163. {
  9164. char *player_name;
  9165. int lv;
  9166. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9167. return;
  9168. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9169. return;
  9170. player_name = (char*)RFIFOP(fd,2);
  9171. player_name[NAME_LENGTH-1] = '\0';
  9172. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9173. if( log_config.gm && lv >= log_config.gm ) {
  9174. char message[NAME_LENGTH+7];
  9175. sprintf(message, "/shift %s", player_name);
  9176. log_atcommand(sd, message);
  9177. }
  9178. }
  9179. /*==========================================
  9180. * /recall <name>
  9181. *------------------------------------------*/
  9182. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9183. {
  9184. char *player_name;
  9185. int lv;
  9186. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9187. return;
  9188. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9189. return;
  9190. player_name = (char*)RFIFOP(fd,2);
  9191. player_name[NAME_LENGTH-1] = '\0';
  9192. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9193. if( log_config.gm && lv >= log_config.gm ) {
  9194. char message[NAME_LENGTH+8];
  9195. sprintf(message, "/recall %s", player_name);
  9196. log_atcommand(sd, message);
  9197. }
  9198. }
  9199. /*==========================================
  9200. * /monster /item
  9201. *------------------------------------------*/
  9202. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9203. {
  9204. char *monster_item_name;
  9205. char message[NAME_LENGTH+10]; //For logging.
  9206. int level;
  9207. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9208. return;
  9209. monster_item_name = (char*)RFIFOP(fd,2);
  9210. monster_item_name[NAME_LENGTH-1] = '\0';
  9211. if( mobdb_searchname(monster_item_name) ) {
  9212. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9213. return;
  9214. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9215. if( log_config.gm && level >= log_config.gm )
  9216. { //Log action. [Skotlex]
  9217. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9218. log_atcommand(sd, message);
  9219. }
  9220. return;
  9221. }
  9222. if( itemdb_searchname(monster_item_name) == NULL )
  9223. return;
  9224. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9225. return;
  9226. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9227. if( log_config.gm && level >= log_config.gm )
  9228. { //Log action. [Skotlex]
  9229. sprintf(message, "@item %s", monster_item_name);
  9230. log_atcommand(sd, message);
  9231. }
  9232. }
  9233. /*==========================================
  9234. * /hide
  9235. *------------------------------------------*/
  9236. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9237. {
  9238. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9239. return;
  9240. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9241. return;
  9242. if( sd->sc.option & OPTION_INVISIBLE ) {
  9243. sd->sc.option &= ~OPTION_INVISIBLE;
  9244. if (sd->disguise)
  9245. status_set_viewdata(&sd->bl, sd->disguise);
  9246. else
  9247. status_set_viewdata(&sd->bl, sd->status.class_);
  9248. clif_displaymessage(fd, "Invisible: Off.");
  9249. } else {
  9250. sd->sc.option |= OPTION_INVISIBLE;
  9251. sd->vd.class_ = INVISIBLE_CLASS;
  9252. clif_displaymessage(fd, "Invisible: On.");
  9253. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9254. log_atcommand(sd, "/hide");
  9255. }
  9256. clif_changeoption(&sd->bl);
  9257. }
  9258. /*==========================================
  9259. * GM adjustment of a player's manner value (right-click GM menu)
  9260. * S 0149 <id>.L <type>.B <value>.W
  9261. * type: 0 - positive points
  9262. * 1 - negative points
  9263. * 2 - self mute (+10 minutes)
  9264. *------------------------------------------*/
  9265. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9266. {
  9267. int id, type, value, level;
  9268. struct map_session_data *dstsd;
  9269. id = RFIFOL(fd,2);
  9270. type = RFIFOB(fd,6);
  9271. value = RFIFOW(fd,7);
  9272. if( type == 0 )
  9273. value = 0 - value;
  9274. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9275. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9276. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9277. return;
  9278. dstsd = map_id2sd(id);
  9279. if( dstsd == NULL )
  9280. return;
  9281. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9282. {
  9283. clif_manner_message(sd, 0);
  9284. clif_manner_message(dstsd, 5);
  9285. if( dstsd->status.manner < value ) {
  9286. dstsd->status.manner -= value;
  9287. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9288. } else {
  9289. dstsd->status.manner = 0;
  9290. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9291. }
  9292. if( type != 2 )
  9293. clif_GM_silence(sd, dstsd, type);
  9294. }
  9295. }
  9296. /*==========================================
  9297. * GM adjustment of a player's manner value by -60 (using name)
  9298. * /rc <name>
  9299. * S 0212 <name>.24B
  9300. *------------------------------------------*/
  9301. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9302. {
  9303. char* name = (char*)RFIFOP(fd,2);
  9304. struct map_session_data* dstsd;
  9305. name[23] = '\0';
  9306. dstsd = map_nick2sd(name);
  9307. if( dstsd == NULL )
  9308. return;
  9309. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9310. {
  9311. clif_manner_message(sd, 0);
  9312. clif_manner_message(dstsd, 3);
  9313. dstsd->status.manner -= 60;
  9314. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9315. clif_GM_silence(sd, dstsd, 1);
  9316. }
  9317. }
  9318. /*==========================================
  9319. * GM requesting account name (for right-click gm menu)
  9320. * S 01df <id>.L
  9321. * R 01e0 <id>.L <name>.24B
  9322. *------------------------------------------*/
  9323. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9324. {
  9325. int tid;
  9326. tid = RFIFOL(fd,2);
  9327. //TODO: find out if this works for any player or only for authorized GMs
  9328. WFIFOHEAD(fd,packet_len(0x1e0));
  9329. WFIFOW(fd,0) = 0x1e0;
  9330. WFIFOL(fd,2) = tid;
  9331. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9332. WFIFOSET(fd, packet_len(0x1e0));
  9333. }
  9334. /*==========================================
  9335. * GM single cell type change request
  9336. * /changemaptype <x> <y> <type>
  9337. * S 0198 <x>.W <y>.W <gat>.W
  9338. *------------------------------------------*/
  9339. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9340. {
  9341. int x,y,type;
  9342. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9343. return;
  9344. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9345. return;
  9346. x = RFIFOW(fd,2);
  9347. y = RFIFOW(fd,4);
  9348. type = RFIFOW(fd,6);
  9349. map_setgatcell(sd->bl.m,x,y,type);
  9350. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9351. //FIXME: once players leave the map, the client 'forgets' this information.
  9352. }
  9353. /// S 00cf <nick>.24B <type>.B
  9354. /// type: 0 (/ex nick) deny speech from nick
  9355. /// 1 (/in nick) allow speech from nick
  9356. ///
  9357. /// R 00d1 <type>.B <result>.B
  9358. /// type: 0: deny, 1: allow
  9359. /// result: 0: success, 1: fail 2: list full
  9360. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9361. {
  9362. char output[512];
  9363. char* nick;
  9364. uint8 type;
  9365. int i;
  9366. nick = (char*)RFIFOP(fd,2); // speed up
  9367. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9368. type = RFIFOB(fd,26);
  9369. WFIFOHEAD(fd,packet_len(0xd1));
  9370. WFIFOW(fd,0) = 0x0d1;
  9371. WFIFOB(fd,2) = type;
  9372. if( type == 0 )
  9373. { // Add name to ignore list (block)
  9374. // Bot-check...
  9375. if (strcmp(wisp_server_name, nick) == 0)
  9376. { // to find possible bot users who automaticaly ignore people
  9377. 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);
  9378. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9379. WFIFOB(fd,3) = 1; // fail
  9380. WFIFOSET(fd, packet_len(0x0d1));
  9381. return;
  9382. }
  9383. // try to find a free spot, while checking for duplicates at the same time
  9384. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9385. if( i == MAX_IGNORE_LIST )
  9386. {// no space for new entry
  9387. WFIFOB(fd,3) = 2; // fail
  9388. WFIFOSET(fd, packet_len(0x0d1));
  9389. return;
  9390. }
  9391. if( sd->ignore[i].name[0] != '\0' )
  9392. {// name already exists
  9393. WFIFOB(fd,3) = 0; // Aegis reports success.
  9394. WFIFOSET(fd, packet_len(0x0d1));
  9395. return;
  9396. }
  9397. //Insert in position i
  9398. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9399. WFIFOB(fd,3) = 0; // success
  9400. WFIFOSET(fd, packet_len(0x0d1));
  9401. }
  9402. else
  9403. { // Remove name from ignore list (unblock)
  9404. // find entry
  9405. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9406. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9407. { //Not found
  9408. WFIFOB(fd,3) = 1; // fail
  9409. WFIFOSET(fd, packet_len(0x0d1));
  9410. return;
  9411. }
  9412. // move everything one place down to overwrite removed entry
  9413. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9414. // wipe last entry
  9415. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9416. WFIFOB(fd,3) = 0; // success
  9417. WFIFOSET(fd, packet_len(0x0d1));
  9418. }
  9419. return;
  9420. }
  9421. /// S 00d0 <type>.B
  9422. /// type: 0 (/exall) deny all speech
  9423. /// 1 (/inall) allow all speech
  9424. ///
  9425. /// R 00d2 <type>.B <fail>.B
  9426. /// type: 0: deny, 1: allow
  9427. /// fail: 0: success, 1: fail
  9428. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9429. {
  9430. WFIFOHEAD(fd,packet_len(0xd2));
  9431. WFIFOW(fd,0) = 0x0d2;
  9432. WFIFOB(fd,2) = RFIFOB(fd,2);
  9433. if( RFIFOB(fd,2) == 0 )
  9434. {// Deny all
  9435. if( sd->state.ignoreAll ) {
  9436. WFIFOB(fd,3) = 1; // fail
  9437. } else {
  9438. sd->state.ignoreAll = 1;
  9439. WFIFOB(fd,3) = 0; // success
  9440. }
  9441. }
  9442. else
  9443. {//Unblock everyone
  9444. if( sd->state.ignoreAll ) {
  9445. sd->state.ignoreAll = 0;
  9446. WFIFOB(fd,3) = 0; // success
  9447. } else {
  9448. if (sd->ignore[0].name[0] != '\0')
  9449. { //Wipe the ignore list.
  9450. memset(sd->ignore, 0, sizeof(sd->ignore));
  9451. WFIFOB(fd,3) = 0; // success
  9452. } else {
  9453. WFIFOB(fd,3) = 1; // fail
  9454. }
  9455. }
  9456. }
  9457. WFIFOSET(fd, packet_len(0x0d2));
  9458. return;
  9459. }
  9460. /*==========================================
  9461. * Wis拒否リスト
  9462. *------------------------------------------*/
  9463. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9464. {
  9465. int i;
  9466. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9467. WFIFOW(fd,0) = 0xd4;
  9468. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9469. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9470. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9471. WFIFOSET(fd, WFIFOW(fd,2));
  9472. return;
  9473. }
  9474. /*==========================================
  9475. * スパノビの/doridoriによるSPR2倍
  9476. *------------------------------------------*/
  9477. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9478. {
  9479. if (sd->state.doridori) return;
  9480. switch (sd->class_&MAPID_UPPERMASK)
  9481. {
  9482. case MAPID_SOUL_LINKER:
  9483. case MAPID_STAR_GLADIATOR:
  9484. case MAPID_TAEKWON:
  9485. if (!sd->state.rest)
  9486. break;
  9487. case MAPID_SUPER_NOVICE:
  9488. sd->state.doridori=1;
  9489. break;
  9490. }
  9491. return;
  9492. }
  9493. /*==========================================
  9494. * スパノビの爆裂波動
  9495. *------------------------------------------*/
  9496. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9497. {
  9498. if(sd){
  9499. int nextbaseexp=pc_nextbaseexp(sd);
  9500. if (battle_config.etc_log){
  9501. if(nextbaseexp != 0)
  9502. ShowInfo("SuperNovice explosionspirits!! %d %d %d %d\n",sd->bl.id,sd->status.class_,sd->status.base_exp,(int)((double)1000*sd->status.base_exp/nextbaseexp));
  9503. else
  9504. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9505. }
  9506. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_exp > 0 && nextbaseexp > 0 && (int)((double)1000*sd->status.base_exp/nextbaseexp)%100==0){
  9507. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9508. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  9509. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9510. }
  9511. }
  9512. return;
  9513. }
  9514. // random notes:
  9515. // 0x214: monster/player info ?
  9516. /*==========================================
  9517. * Friends List
  9518. *------------------------------------------*/
  9519. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9520. { //Toggles a single friend online/offline [Skotlex]
  9521. int i, fd = sd->fd;
  9522. //Seek friend.
  9523. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9524. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9525. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9526. return; //Not found
  9527. WFIFOHEAD(fd,packet_len(0x206));
  9528. WFIFOW(fd, 0) = 0x206;
  9529. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9530. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9531. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9532. WFIFOSET(fd, packet_len(0x206));
  9533. }
  9534. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9535. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9536. {
  9537. int account_id, char_id, online;
  9538. account_id = va_arg(ap, int);
  9539. char_id = va_arg(ap, int);
  9540. online = va_arg(ap, int);
  9541. clif_friendslist_toggle(sd, account_id, char_id, online);
  9542. return 0;
  9543. }
  9544. //For sending the whole friends list.
  9545. void clif_friendslist_send(struct map_session_data *sd)
  9546. {
  9547. int i = 0, n, fd = sd->fd;
  9548. // Send friends list
  9549. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9550. WFIFOW(fd, 0) = 0x201;
  9551. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9552. {
  9553. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9554. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9555. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9556. }
  9557. if (i) {
  9558. WFIFOW(fd,2) = 4 + 32 * i;
  9559. WFIFOSET(fd, WFIFOW(fd,2));
  9560. }
  9561. for (n = 0; n < i; n++)
  9562. { //Sending the online players
  9563. if (map_charid2sd(sd->status.friends[n].char_id))
  9564. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9565. }
  9566. }
  9567. /// Reply for add friend request: (success => type 0)
  9568. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9569. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9570. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9571. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9572. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9573. {
  9574. int fd;
  9575. nullpo_retv(sd);
  9576. fd = sd->fd;
  9577. WFIFOHEAD(fd,packet_len(0x209));
  9578. WFIFOW(fd,0) = 0x209;
  9579. WFIFOW(fd,2) = type;
  9580. if (f_sd)
  9581. {
  9582. WFIFOL(fd,4) = f_sd->status.account_id;
  9583. WFIFOL(fd,8) = f_sd->status.char_id;
  9584. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9585. }
  9586. WFIFOSET(fd, packet_len(0x209));
  9587. }
  9588. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9589. {
  9590. struct map_session_data *f_sd;
  9591. int i, f_fd;
  9592. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9593. // Friend doesn't exist (no player with this name)
  9594. if (f_sd == NULL) {
  9595. clif_displaymessage(fd, msg_txt(3));
  9596. return;
  9597. }
  9598. // @noask [LuzZza]
  9599. if(f_sd->state.noask) {
  9600. clif_noask_sub(sd, f_sd, 5);
  9601. return;
  9602. }
  9603. // Friend already exists
  9604. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9605. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9606. clif_displaymessage(fd, "Friend already exists.");
  9607. return;
  9608. }
  9609. }
  9610. if (i == MAX_FRIENDS) {
  9611. //No space, list full.
  9612. clif_friendslist_reqack(sd, f_sd, 2);
  9613. return;
  9614. }
  9615. f_fd = f_sd->fd;
  9616. WFIFOHEAD(f_fd,packet_len(0x207));
  9617. WFIFOW(f_fd,0) = 0x207;
  9618. WFIFOL(f_fd,2) = sd->status.account_id;
  9619. WFIFOL(f_fd,6) = sd->status.char_id;
  9620. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9621. WFIFOSET(f_fd, packet_len(0x207));
  9622. return;
  9623. }
  9624. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9625. {
  9626. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9627. struct map_session_data *f_sd;
  9628. int char_id, account_id;
  9629. char reply;
  9630. account_id = RFIFOL(fd,2);
  9631. char_id = RFIFOL(fd,6);
  9632. reply = RFIFOB(fd,10);
  9633. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9634. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9635. if (f_sd == NULL)
  9636. return;
  9637. if (reply == 0)
  9638. clif_friendslist_reqack(f_sd, sd, 1);
  9639. else {
  9640. int i;
  9641. // Find an empty slot
  9642. for (i = 0; i < MAX_FRIENDS; i++)
  9643. if (f_sd->status.friends[i].char_id == 0)
  9644. break;
  9645. if (i == MAX_FRIENDS) {
  9646. clif_friendslist_reqack(f_sd, sd, 2);
  9647. return;
  9648. }
  9649. f_sd->status.friends[i].account_id = sd->status.account_id;
  9650. f_sd->status.friends[i].char_id = sd->status.char_id;
  9651. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9652. clif_friendslist_reqack(f_sd, sd, 0);
  9653. if (battle_config.friend_auto_add) {
  9654. // Also add f_sd to sd's friendlist.
  9655. for (i = 0; i < MAX_FRIENDS; i++) {
  9656. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9657. return; //No need to add anything.
  9658. if (sd->status.friends[i].char_id == 0)
  9659. break;
  9660. }
  9661. if (i == MAX_FRIENDS) {
  9662. clif_friendslist_reqack(sd, f_sd, 2);
  9663. return;
  9664. }
  9665. sd->status.friends[i].account_id = f_sd->status.account_id;
  9666. sd->status.friends[i].char_id = f_sd->status.char_id;
  9667. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9668. clif_friendslist_reqack(sd, f_sd, 0);
  9669. }
  9670. }
  9671. return;
  9672. }
  9673. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9674. {
  9675. // 0x203 </o> <ID to be removed W 4B>
  9676. int account_id, char_id;
  9677. int i, j;
  9678. account_id = RFIFOL(fd,2);
  9679. char_id = RFIFOL(fd,6);
  9680. // Search friend
  9681. for (i = 0; i < MAX_FRIENDS &&
  9682. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9683. if (i == MAX_FRIENDS) {
  9684. clif_displaymessage(fd, "Name not found in list.");
  9685. return;
  9686. }
  9687. // move all chars down
  9688. for(j = i + 1; j < MAX_FRIENDS; j++)
  9689. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9690. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9691. clif_displaymessage(fd, "Friend removed");
  9692. WFIFOHEAD(fd,packet_len(0x20a));
  9693. WFIFOW(fd,0) = 0x20a;
  9694. WFIFOL(fd,2) = account_id;
  9695. WFIFOL(fd,6) = char_id;
  9696. WFIFOSET(fd, packet_len(0x20a));
  9697. // clif_friendslist_send(sd); //This is not needed anymore.
  9698. return;
  9699. }
  9700. /*==========================================
  9701. * /pvpinfo
  9702. *------------------------------------------*/
  9703. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9704. {
  9705. WFIFOHEAD(fd,packet_len(0x210));
  9706. WFIFOW(fd,0) = 0x210;
  9707. //WFIFOL(fd,2) = 0; // not sure what for yet
  9708. //WFIFOL(fd,6) = 0;
  9709. WFIFOL(fd,10) = sd->pvp_won; // times won
  9710. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9711. WFIFOL(fd,18) = sd->pvp_point;
  9712. WFIFOSET(fd, packet_len(0x210));
  9713. return;
  9714. }
  9715. /*==========================================
  9716. * /blacksmith
  9717. *------------------------------------------*/
  9718. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9719. {
  9720. int i;
  9721. const char* name;
  9722. WFIFOHEAD(fd,packet_len(0x219));
  9723. WFIFOW(fd,0) = 0x219;
  9724. //Packet size limits this list to 10 elements. [Skotlex]
  9725. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9726. if (smith_fame_list[i].id > 0) {
  9727. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9728. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9729. {
  9730. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9731. } else
  9732. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9733. } else
  9734. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9735. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9736. }
  9737. for(;i < 10; i++) { //In case the MAX is less than 10.
  9738. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9739. WFIFOL(fd, 242 + i * 4) = 0;
  9740. }
  9741. WFIFOSET(fd, packet_len(0x219));
  9742. }
  9743. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9744. {
  9745. int fd = sd->fd;
  9746. WFIFOHEAD(fd,packet_len(0x21b));
  9747. WFIFOW(fd,0) = 0x21b;
  9748. WFIFOL(fd,2) = points;
  9749. WFIFOL(fd,6) = sd->status.fame;
  9750. WFIFOSET(fd, packet_len(0x21b));
  9751. return 0;
  9752. }
  9753. /*==========================================
  9754. * /alchemist
  9755. *------------------------------------------*/
  9756. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9757. {
  9758. int i;
  9759. const char* name;
  9760. WFIFOHEAD(fd,packet_len(0x21a));
  9761. WFIFOW(fd,0) = 0x21a;
  9762. //Packet size limits this list to 10 elements. [Skotlex]
  9763. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9764. if (chemist_fame_list[i].id > 0) {
  9765. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9766. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9767. {
  9768. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9769. } else
  9770. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9771. } else
  9772. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9773. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9774. }
  9775. for(;i < 10; i++) { //In case the MAX is less than 10.
  9776. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9777. WFIFOL(fd, 242 + i * 4) = 0;
  9778. }
  9779. WFIFOSET(fd, packet_len(0x21a));
  9780. }
  9781. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9782. {
  9783. int fd = sd->fd;
  9784. WFIFOHEAD(fd,packet_len(0x21c));
  9785. WFIFOW(fd,0) = 0x21c;
  9786. WFIFOL(fd,2) = points;
  9787. WFIFOL(fd,6) = sd->status.fame;
  9788. WFIFOSET(fd, packet_len(0x21c));
  9789. return 0;
  9790. }
  9791. /*==========================================
  9792. * /taekwon
  9793. *------------------------------------------*/
  9794. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9795. {
  9796. int i;
  9797. const char* name;
  9798. WFIFOHEAD(fd,packet_len(0x226));
  9799. WFIFOW(fd,0) = 0x226;
  9800. //Packet size limits this list to 10 elements. [Skotlex]
  9801. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9802. if (taekwon_fame_list[i].id > 0) {
  9803. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9804. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9805. {
  9806. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9807. } else
  9808. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9809. } else
  9810. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9811. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9812. }
  9813. for(;i < 10; i++) { //In case the MAX is less than 10.
  9814. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9815. WFIFOL(fd, 242 + i * 4) = 0;
  9816. }
  9817. WFIFOSET(fd, packet_len(0x226));
  9818. }
  9819. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9820. {
  9821. int fd = sd->fd;
  9822. WFIFOHEAD(fd,packet_len(0x224));
  9823. WFIFOW(fd,0) = 0x224;
  9824. WFIFOL(fd,2) = points;
  9825. WFIFOL(fd,6) = sd->status.fame;
  9826. WFIFOSET(fd, packet_len(0x224));
  9827. return 0;
  9828. }
  9829. /*==========================================
  9830. * PK Ranking table?
  9831. *------------------------------------------*/
  9832. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9833. {
  9834. int i;
  9835. WFIFOHEAD(fd,packet_len(0x238));
  9836. WFIFOW(fd,0) = 0x238;
  9837. for(i=0;i<10;i++){
  9838. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9839. WFIFOL(fd,i*4+242) = 0;
  9840. }
  9841. WFIFOSET(fd, packet_len(0x238));
  9842. return;
  9843. }
  9844. /*==========================================
  9845. * SG Feel save OK [Komurka]
  9846. *------------------------------------------*/
  9847. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9848. {
  9849. int i;
  9850. if (sd->menuskill_id != SG_FEEL)
  9851. return;
  9852. i = sd->menuskill_val-1;
  9853. if (i<0 || i > 2) return; //Bug?
  9854. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9855. sd->feel_map[i].m = sd->bl.m;
  9856. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9857. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9858. // clif_misceffect2(&sd->bl, 0x1b0);
  9859. // clif_misceffect2(&sd->bl, 0x21f);
  9860. clif_feel_info(sd, i, 0);
  9861. sd->menuskill_val = sd->menuskill_id = 0;
  9862. }
  9863. /*==========================================
  9864. * Question about Star Glaldiator save map [Komurka]
  9865. *------------------------------------------*/
  9866. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9867. {
  9868. WFIFOHEAD(fd,packet_len(0x253));
  9869. WFIFOW(fd,0)=0x253;
  9870. WFIFOSET(fd, packet_len(0x253));
  9871. sd->menuskill_id = SG_FEEL;
  9872. sd->menuskill_val = skilllv;
  9873. }
  9874. /*==========================================
  9875. * Homunculus packets
  9876. *------------------------------------------*/
  9877. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9878. {
  9879. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9880. }
  9881. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9882. {
  9883. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9884. struct block_list *bl = NULL;
  9885. struct unit_data *ud = NULL;
  9886. if( sd->md && sd->md->bl.id == id )
  9887. bl = &sd->md->bl;
  9888. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9889. bl = &sd->hd->bl; // Moving Homunculus
  9890. else return;
  9891. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  9892. ud = unit_bl2ud(bl);
  9893. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  9894. }
  9895. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  9896. {
  9897. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9898. struct block_list *bl = NULL;
  9899. short x, y, cmd;
  9900. cmd = RFIFOW(fd,0);
  9901. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9902. 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);
  9903. if( sd->md && sd->md->bl.id == id )
  9904. bl = &sd->md->bl; // Moving Mercenary
  9905. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9906. bl = &sd->hd->bl; // Moving Homunculus
  9907. else return;
  9908. unit_walktoxy(bl, x, y, 4);
  9909. }
  9910. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9911. {
  9912. struct block_list *bl = NULL;
  9913. int id = RFIFOL(fd,2),
  9914. target_id = RFIFOL(fd,6),
  9915. action_type = RFIFOB(fd,10);
  9916. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9917. bl = &sd->hd->bl;
  9918. else if( sd->md && sd->md->bl.id == id )
  9919. bl = &sd->md->bl;
  9920. else return;
  9921. unit_stop_walking(bl, 1);
  9922. unit_stop_attack(bl);
  9923. unit_attack(bl, target_id, action_type != 0);
  9924. }
  9925. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9926. { //[orn]
  9927. int cmd;
  9928. cmd = RFIFOW(fd,0);
  9929. if(!merc_is_hom_active(sd->hd))
  9930. return;
  9931. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9932. }
  9933. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9934. {
  9935. int item_position = pc_search_inventory(sd, 7621);
  9936. if (item_position < 0)
  9937. return;
  9938. if (!status_revive(&sd->bl, 100, 100))
  9939. return;
  9940. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9941. pc_delitem(sd, item_position, 1, 0);
  9942. }
  9943. /// /check <string>
  9944. /// S 0213 <string>.24B
  9945. void clif_parse_Check(int fd, struct map_session_data *sd)
  9946. {
  9947. // no info
  9948. }
  9949. #ifndef TXT_ONLY
  9950. /*==========================================
  9951. * MAIL SYSTEM
  9952. * By Zephyrus
  9953. *==========================================*/
  9954. /*------------------------------------------
  9955. * Reply to Set Attachment operation
  9956. * 0 : Successfully attached item to mail
  9957. * 1 : Fail to set the attachment
  9958. *------------------------------------------*/
  9959. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9960. {
  9961. WFIFOHEAD(fd,packet_len(0x255));
  9962. WFIFOW(fd,0) = 0x255;
  9963. WFIFOW(fd,2) = index;
  9964. WFIFOB(fd,4) = flag;
  9965. WFIFOSET(fd,packet_len(0x255));
  9966. }
  9967. /*------------------------------------------
  9968. * Reply to Get Attachment operation
  9969. * 0 : Successfully added attachment to Inventory
  9970. * 1 : Fail to set the item to inventory
  9971. * 2 : Weight problems
  9972. *------------------------------------------*/
  9973. void clif_Mail_getattachment(int fd, uint8 flag)
  9974. {
  9975. WFIFOHEAD(fd,packet_len(0x245));
  9976. WFIFOW(fd,0) = 0x245;
  9977. WFIFOB(fd,2) = flag;
  9978. WFIFOSET(fd,packet_len(0x245));
  9979. }
  9980. /*------------------------------------------
  9981. * Send Mail ack
  9982. * 0 : Message Send Ok
  9983. * 1 : Recipient does not exist
  9984. *------------------------------------------*/
  9985. void clif_Mail_send(int fd, bool fail)
  9986. {
  9987. WFIFOHEAD(fd,packet_len(0x249));
  9988. WFIFOW(fd,0) = 0x249;
  9989. WFIFOB(fd,2) = fail;
  9990. WFIFOSET(fd,packet_len(0x249));
  9991. }
  9992. /*------------------------------------------
  9993. * Delete Mail ack
  9994. * 0 : Delete ok
  9995. * 1 : Delete failed
  9996. *------------------------------------------*/
  9997. void clif_Mail_delete(int fd, int mail_id, short fail)
  9998. {
  9999. WFIFOHEAD(fd, packet_len(0x257));
  10000. WFIFOW(fd,0) = 0x257;
  10001. WFIFOL(fd,2) = mail_id;
  10002. WFIFOW(fd,6) = fail;
  10003. WFIFOSET(fd, packet_len(0x257));
  10004. }
  10005. /*------------------------------------------
  10006. * Return Mail ack
  10007. * 0 : Mail returned to the sender
  10008. * 1 : The mail does not exist
  10009. *------------------------------------------*/
  10010. void clif_Mail_return(int fd, int mail_id, short fail)
  10011. {
  10012. WFIFOHEAD(fd,packet_len(0x274));
  10013. WFIFOW(fd,0) = 0x274;
  10014. WFIFOL(fd,2) = mail_id;
  10015. WFIFOW(fd,6) = fail;
  10016. WFIFOSET(fd,packet_len(0x274));
  10017. }
  10018. /*------------------------------------------
  10019. * You have New Mail
  10020. *------------------------------------------*/
  10021. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10022. {
  10023. WFIFOHEAD(fd,packet_len(0x24a));
  10024. WFIFOW(fd,0) = 0x24a;
  10025. WFIFOL(fd,2) = mail_id;
  10026. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10027. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10028. WFIFOSET(fd,packet_len(0x24a));
  10029. }
  10030. /*------------------------------------------
  10031. * Handles Mail Window on Client
  10032. * flag : 0 open | 1 close
  10033. *------------------------------------------*/
  10034. void clif_Mail_window(int fd, int flag)
  10035. {
  10036. WFIFOHEAD(fd,packet_len(0x260));
  10037. WFIFOW(fd,0) = 0x260;
  10038. WFIFOL(fd,2) = flag;
  10039. WFIFOSET(fd,packet_len(0x260));
  10040. }
  10041. /*------------------------------------------
  10042. * Send Inbox Data to Client
  10043. *------------------------------------------*/
  10044. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10045. {
  10046. int fd = sd->fd;
  10047. struct mail_data *md = &sd->mail.inbox;
  10048. struct mail_message *msg;
  10049. int len, i, j;
  10050. len = 8 + (73 * md->amount);
  10051. WFIFOHEAD(fd,len);
  10052. WFIFOW(fd,0) = 0x240;
  10053. WFIFOW(fd,2) = len;
  10054. WFIFOL(fd,4) = md->amount;
  10055. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10056. {
  10057. msg = &md->msg[i];
  10058. if (msg->id < 1)
  10059. continue;
  10060. WFIFOL(fd,8+73*j) = msg->id;
  10061. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10062. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10063. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10064. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10065. j++;
  10066. }
  10067. WFIFOSET(fd,len);
  10068. if( md->full )
  10069. {
  10070. char output[100];
  10071. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10072. clif_disp_onlyself(sd, output, strlen(output));
  10073. }
  10074. }
  10075. /*------------------------------------------
  10076. * Client Request Inbox List
  10077. *------------------------------------------*/
  10078. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10079. {
  10080. struct mail_data* md = &sd->mail.inbox;
  10081. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10082. intif_Mail_requestinbox(sd->status.char_id, 1);
  10083. else
  10084. clif_Mail_refreshinbox(sd);
  10085. mail_removeitem(sd, 0);
  10086. mail_removezeny(sd, 0);
  10087. }
  10088. /*------------------------------------------
  10089. * Read Message
  10090. *------------------------------------------*/
  10091. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10092. {
  10093. int i, fd = sd->fd;
  10094. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10095. if( i == MAIL_MAX_INBOX )
  10096. {
  10097. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10098. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10099. return;
  10100. }
  10101. else
  10102. {
  10103. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10104. struct item *item = &msg->item;
  10105. struct item_data *data;
  10106. int msg_len = strlen(msg->body), len;
  10107. if( msg_len == 0 ) {
  10108. strcpy(msg->body, "(no message)");
  10109. msg_len = strlen(msg->body);
  10110. }
  10111. len = 101 + msg_len;
  10112. WFIFOHEAD(fd,len);
  10113. WFIFOW(fd,0) = 0x242;
  10114. WFIFOW(fd,2) = len;
  10115. WFIFOL(fd,4) = msg->id;
  10116. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10117. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10118. WFIFOL(fd,72) = 0;
  10119. WFIFOL(fd,76) = msg->zeny;
  10120. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  10121. {
  10122. WFIFOL(fd,80) = item->amount;
  10123. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10124. WFIFOW(fd,86) = data->type;
  10125. WFIFOB(fd,88) = item->identify;
  10126. WFIFOB(fd,89) = item->attribute;
  10127. WFIFOB(fd,90) = item->refine;
  10128. WFIFOW(fd,91) = item->card[0];
  10129. WFIFOW(fd,93) = item->card[1];
  10130. WFIFOW(fd,95) = item->card[2];
  10131. WFIFOW(fd,97) = item->card[3];
  10132. }
  10133. else // no item, set all to zero
  10134. memset(WFIFOP(fd,80), 0x00, 19);
  10135. WFIFOB(fd,99) = (unsigned char)msg_len;
  10136. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10137. WFIFOSET(fd,len);
  10138. if (msg->status == MAIL_UNREAD) {
  10139. msg->status = MAIL_READ;
  10140. intif_Mail_read(mail_id);
  10141. clif_parse_Mail_refreshinbox(fd, sd);
  10142. }
  10143. }
  10144. }
  10145. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10146. {
  10147. if( mail_invalid_operation(sd) )
  10148. return;
  10149. clif_Mail_read(sd, RFIFOL(fd,2));
  10150. }
  10151. /*------------------------------------------
  10152. * Get Attachment from Message
  10153. *------------------------------------------*/
  10154. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10155. {
  10156. int i, mail_id = RFIFOL(fd,2);
  10157. bool fail = false;
  10158. if( mail_invalid_operation(sd) )
  10159. return;
  10160. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10161. if( i == MAIL_MAX_INBOX )
  10162. return;
  10163. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10164. return;
  10165. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10166. {
  10167. struct item_data *data;
  10168. unsigned int weight;
  10169. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10170. return;
  10171. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10172. {
  10173. case ADDITEM_NEW:
  10174. fail = ( pc_inventoryblank(sd) == 0 );
  10175. break;
  10176. case ADDITEM_OVERAMOUNT:
  10177. fail = true;
  10178. }
  10179. if( fail )
  10180. {
  10181. clif_Mail_getattachment(fd, 1);
  10182. return;
  10183. }
  10184. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10185. if( weight > sd->max_weight - sd->weight )
  10186. {
  10187. clif_Mail_getattachment(fd, 2);
  10188. return;
  10189. }
  10190. }
  10191. sd->mail.inbox.msg[i].zeny = 0;
  10192. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10193. clif_Mail_read(sd, mail_id);
  10194. intif_Mail_getattach(sd->status.char_id, mail_id);
  10195. }
  10196. /*------------------------------------------
  10197. * Delete Message
  10198. *------------------------------------------*/
  10199. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10200. {
  10201. int i, mail_id = RFIFOL(fd,2);
  10202. if( mail_invalid_operation(sd) )
  10203. return;
  10204. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10205. if (i < MAIL_MAX_INBOX)
  10206. {
  10207. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10208. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10209. {// can't delete mail without removing attachment first
  10210. clif_Mail_delete(sd->fd, mail_id, 1);
  10211. return;
  10212. }
  10213. intif_Mail_delete(sd->status.char_id, mail_id);
  10214. }
  10215. }
  10216. /*------------------------------------------
  10217. * Return Mail Message
  10218. *------------------------------------------*/
  10219. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10220. {
  10221. int i, mail_id = RFIFOL(fd,2);
  10222. if( mail_invalid_operation(sd) )
  10223. return;
  10224. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10225. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10226. intif_Mail_return(sd->status.char_id, mail_id);
  10227. else
  10228. clif_Mail_return(sd->fd, mail_id, 1);
  10229. }
  10230. /*------------------------------------------
  10231. * Set Attachment
  10232. *------------------------------------------*/
  10233. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10234. {
  10235. int idx = RFIFOW(fd,2);
  10236. int amount = RFIFOL(fd,4);
  10237. unsigned char flag;
  10238. if (idx < 0 || amount < 0)
  10239. return;
  10240. flag = mail_setitem(sd, idx, amount);
  10241. clif_Mail_setattachment(fd,idx,flag);
  10242. }
  10243. /*------------------------------------------
  10244. * Mail Window Operation
  10245. * 0 : Switch to 'new mail' window, or Close mailbox
  10246. * 1 : ???
  10247. * 2 : ???
  10248. *------------------------------------------*/
  10249. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10250. {
  10251. int flag = RFIFOW(fd,2);
  10252. if (flag == 0 || flag == 1)
  10253. mail_removeitem(sd, 0);
  10254. if (flag == 0 || flag == 2)
  10255. mail_removezeny(sd, 0);
  10256. }
  10257. /*------------------------------------------
  10258. * Send Mail
  10259. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10260. *------------------------------------------*/
  10261. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10262. {
  10263. struct mail_message msg;
  10264. int body_len;
  10265. if( sd->state.trading )
  10266. return;
  10267. if( RFIFOW(fd,2) < 69 ) {
  10268. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10269. return;
  10270. }
  10271. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10272. {
  10273. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10274. clif_Mail_send(fd, true); // fail
  10275. return;
  10276. }
  10277. body_len = RFIFOB(fd,68);
  10278. if (body_len > MAIL_BODY_LENGTH)
  10279. body_len = MAIL_BODY_LENGTH;
  10280. if( !mail_setattachment(sd, &msg) )
  10281. { // Invalid Append condition
  10282. clif_Mail_send(sd->fd, true); // fail
  10283. mail_removeitem(sd,0);
  10284. mail_removezeny(sd,0);
  10285. return;
  10286. }
  10287. msg.id = 0; // id will be assigned by charserver
  10288. msg.send_id = sd->status.char_id;
  10289. msg.dest_id = 0; // will attempt to resolve name
  10290. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10291. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10292. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10293. if (body_len)
  10294. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10295. else
  10296. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10297. msg.timestamp = time(NULL);
  10298. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10299. mail_deliveryfail(sd, &msg);
  10300. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10301. }
  10302. /*==========================================
  10303. * AUCTION SYSTEM
  10304. * By Zephyrus
  10305. *==========================================*/
  10306. void clif_Auction_openwindow(struct map_session_data *sd)
  10307. {
  10308. int fd = sd->fd;
  10309. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10310. return;
  10311. WFIFOHEAD(fd,12);
  10312. WFIFOW(fd,0) = 0x25f;
  10313. WFIFOL(fd,2) = 0;
  10314. WFIFOB(fd,6) = 0xb6;
  10315. WFIFOB(fd,7) = 0x00;
  10316. WFIFOB(fd,8) = 0xa6;
  10317. WFIFOB(fd,9) = 0xde;
  10318. WFIFOW(fd,10) = 0;
  10319. WFIFOSET(fd,12);
  10320. }
  10321. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  10322. {
  10323. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10324. struct auction_data auction;
  10325. struct item_data *item;
  10326. int k;
  10327. WFIFOHEAD(fd,20);
  10328. WFIFOW(fd,0) = 0x252;
  10329. WFIFOW(fd,2) = 12 + (count * 83);
  10330. WFIFOL(fd,4) = pages;
  10331. WFIFOL(fd,8) = count;
  10332. for( i = 0; i < count; i++ )
  10333. {
  10334. memcpy(&auction, RBUFP(buf,i * len), len);
  10335. k = 12 + (i * 83);
  10336. WFIFOL(fd,k) = auction.auction_id;
  10337. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10338. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10339. WFIFOW(fd,28+k) = item->view_id;
  10340. else
  10341. WFIFOW(fd,28+k) = auction.item.nameid;
  10342. WFIFOW(fd,30+k) = auction.type;
  10343. WFIFOW(fd,32+k) = 0; // ??
  10344. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10345. WFIFOB(fd,36+k) = auction.item.identify;
  10346. WFIFOB(fd,37+k) = auction.item.attribute;
  10347. WFIFOB(fd,38+k) = auction.item.refine;
  10348. WFIFOW(fd,39+k) = auction.item.card[0];
  10349. WFIFOW(fd,41+k) = auction.item.card[1];
  10350. WFIFOW(fd,43+k) = auction.item.card[2];
  10351. WFIFOW(fd,45+k) = auction.item.card[3];
  10352. WFIFOL(fd,47+k) = auction.price;
  10353. WFIFOL(fd,51+k) = auction.buynow;
  10354. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10355. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  10356. }
  10357. WFIFOSET(fd, 12 + (count * 83));
  10358. }
  10359. static void clif_Auction_setitem(int fd, int index, bool fail)
  10360. {
  10361. WFIFOHEAD(fd,packet_len(0x256));
  10362. WFIFOW(fd,0) = 0x256;
  10363. WFIFOW(fd,2) = index;
  10364. WFIFOB(fd,4) = fail;
  10365. WFIFOSET(fd,packet_len(0x256));
  10366. }
  10367. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10368. {
  10369. if( sd->auction.amount > 0 )
  10370. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10371. sd->auction.amount = 0;
  10372. }
  10373. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10374. {
  10375. int idx = RFIFOW(fd,2) - 2;
  10376. int amount = RFIFOL(fd,4); // Allways 1
  10377. struct item_data *item;
  10378. if( sd->auction.amount > 0 )
  10379. sd->auction.amount = 0;
  10380. if( idx < 0 || idx >= MAX_INVENTORY )
  10381. {
  10382. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10383. return;
  10384. }
  10385. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10386. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10387. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10388. return;
  10389. }
  10390. if( (item = itemdb_search(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) )
  10391. { // Consumible or pets are not allowed
  10392. clif_Auction_setitem(sd->fd, idx, true);
  10393. return;
  10394. }
  10395. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify || sd->status.inventory[idx].expire_time )
  10396. { // Quest Item or something else
  10397. clif_Auction_setitem(sd->fd, idx, true);
  10398. return;
  10399. }
  10400. sd->auction.index = idx;
  10401. sd->auction.amount = amount;
  10402. clif_Auction_setitem(fd, idx + 2, false);
  10403. }
  10404. // 0 = You have failed to bid into the auction
  10405. // 1 = You have successfully bid in the auction
  10406. // 2 = The auction has been canceled
  10407. // 3 = An auction with at least one bidder cannot be canceled
  10408. // 4 = You cannot register more than 5 items in an auction at a time
  10409. // 5 = You do not have enough Zeny to pay the Auction Fee
  10410. // 6 = You have won the auction
  10411. // 7 = You have failed to win the auction
  10412. // 8 = You do not have enough Zeny
  10413. // 9 = You cannot place more than 5 bids at a time
  10414. void clif_Auction_message(int fd, unsigned char flag)
  10415. {
  10416. WFIFOHEAD(fd,3);
  10417. WFIFOW(fd,0) = 0x250;
  10418. WFIFOB(fd,2) = flag;
  10419. WFIFOSET(fd,3);
  10420. }
  10421. // 0 = You have ended the auction
  10422. // 1 = You cannot end the auction
  10423. // 2 = Bid number is incorrect
  10424. void clif_Auction_close(int fd, unsigned char flag)
  10425. {
  10426. WFIFOHEAD(fd,6);
  10427. WFIFOW(fd,0) = 0x25d;
  10428. WFIFOL(fd,2) = flag;
  10429. WFIFOSET(fd,6);
  10430. }
  10431. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10432. {
  10433. struct auction_data auction;
  10434. struct item_data *item;
  10435. auction.price = RFIFOL(fd,2);
  10436. auction.buynow = RFIFOL(fd,6);
  10437. auction.hours = RFIFOW(fd,10);
  10438. // Invalid Situations...
  10439. if( sd->auction.amount < 1 )
  10440. {
  10441. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10442. return;
  10443. }
  10444. if( auction.price >= auction.buynow )
  10445. {
  10446. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10447. return;
  10448. }
  10449. if( auction.hours < 1 || auction.hours > 48 )
  10450. {
  10451. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10452. return;
  10453. }
  10454. // Auction checks...
  10455. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10456. {
  10457. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10458. return;
  10459. }
  10460. if( auction.buynow > battle_config.auction_maximumprice )
  10461. { // Zeny Limits
  10462. auction.buynow = battle_config.auction_maximumprice;
  10463. if( auction.price >= auction.buynow )
  10464. auction.price = auction.buynow - 1;
  10465. }
  10466. auction.auction_id = 0;
  10467. auction.seller_id = sd->status.char_id;
  10468. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10469. auction.buyer_id = 0;
  10470. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10471. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10472. {
  10473. clif_Auction_message(fd, 2); // The auction has been canceled
  10474. return;
  10475. }
  10476. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10477. { // Just in case
  10478. clif_Auction_message(fd, 2); // The auction has been canceled
  10479. return;
  10480. }
  10481. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10482. auction.type = item->type;
  10483. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10484. auction.item.amount = 1;
  10485. auction.timestamp = 0;
  10486. if( !intif_Auction_register(&auction) )
  10487. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10488. else
  10489. {
  10490. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10491. sd->auction.amount = 0;
  10492. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10493. }
  10494. }
  10495. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10496. {
  10497. unsigned int auction_id = RFIFOL(fd,2);
  10498. intif_Auction_cancel(sd->status.char_id, auction_id);
  10499. }
  10500. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10501. {
  10502. unsigned int auction_id = RFIFOL(fd,2);
  10503. intif_Auction_close(sd->status.char_id, auction_id);
  10504. }
  10505. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10506. {
  10507. unsigned int auction_id = RFIFOL(fd,2);
  10508. int bid = RFIFOL(fd,6);
  10509. if( bid <= 0 )
  10510. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10511. else if( bid > sd->status.zeny )
  10512. clif_Auction_message(fd, 8); // You do not have enough zeny
  10513. else
  10514. {
  10515. pc_payzeny(sd, bid);
  10516. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10517. }
  10518. }
  10519. /*------------------------------------------
  10520. * Auction Search
  10521. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10522. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10523. *------------------------------------------*/
  10524. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10525. {
  10526. char search_text[NAME_LENGTH];
  10527. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10528. int price = RFIFOL(fd,4);
  10529. clif_parse_Auction_cancelreg(fd, sd);
  10530. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10531. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10532. }
  10533. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10534. {
  10535. short type = RFIFOW(fd,2) + 6;
  10536. clif_parse_Auction_cancelreg(fd, sd);
  10537. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10538. }
  10539. #endif
  10540. /*==========================================
  10541. * CASH/POINT SHOP
  10542. *==========================================*/
  10543. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10544. {
  10545. int fd,i;
  10546. nullpo_retv(sd);
  10547. nullpo_retv(nd);
  10548. fd = sd->fd;
  10549. sd->npc_shopid = nd->bl.id;
  10550. WFIFOHEAD(fd, 200 * 11 + 12);
  10551. WFIFOW(fd,0) = 0x287;
  10552. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10553. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10554. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10555. for( i = 0; i < nd->u.shop.count; i++ )
  10556. {
  10557. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10558. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10559. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10560. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10561. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10562. }
  10563. WFIFOSET(fd,WFIFOW(fd,2));
  10564. }
  10565. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10566. {
  10567. int fail = 0, amount, points;
  10568. short nameid;
  10569. struct npc_data *nd;
  10570. nullpo_retv(sd);
  10571. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10572. nameid = RFIFOW(fd,2);
  10573. amount = RFIFOW(fd,4);
  10574. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10575. if( sd->state.trading || !sd->npc_shopid )
  10576. fail = 1;
  10577. else
  10578. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10579. WFIFOHEAD(fd,12);
  10580. WFIFOW(fd,0) = 0x289;
  10581. WFIFOL(fd,2) = sd->cashPoints;
  10582. WFIFOL(fd,6) = sd->kafraPoints;
  10583. WFIFOW(fd,10) = fail;
  10584. WFIFOSET(fd,12);
  10585. }
  10586. /*==========================================
  10587. * Adoption System
  10588. *==========================================*/
  10589. // 0 : "You cannot adopt more than 1 child."
  10590. // 1 : "You must be at least character level 70 in order to adopt someone."
  10591. // 2 : "You cannot adopt a married person."
  10592. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10593. {
  10594. int fd = sd->fd;
  10595. WFIFOHEAD(fd,6);
  10596. WFIFOW(fd,0) = 0x0216;
  10597. WFIFOL(fd,2) = type;
  10598. WFIFOSET(fd,6);
  10599. }
  10600. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10601. {
  10602. int fd = sd->fd;
  10603. WFIFOHEAD(fd,34);
  10604. WFIFOW(fd,0) = 0x01f6;
  10605. WFIFOL(fd,2) = src->status.account_id;
  10606. WFIFOL(fd,6) = p_id;
  10607. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10608. WFIFOSET(fd,34);
  10609. }
  10610. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10611. {
  10612. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10613. if( pc_can_Adopt(sd, p_sd, tsd) )
  10614. {
  10615. tsd->adopt_invite = sd->status.account_id;
  10616. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10617. }
  10618. }
  10619. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10620. {
  10621. int p1_id = RFIFOL(fd,2);
  10622. int p2_id = RFIFOL(fd,6);
  10623. int result = RFIFOL(fd,10);
  10624. struct map_session_data* p1_sd = map_id2sd(p1_id);
  10625. struct map_session_data* p2_sd = map_id2sd(p2_id);
  10626. int pid = sd->adopt_invite;
  10627. sd->adopt_invite = 0;
  10628. if( p1_sd == NULL || p2_sd == NULL )
  10629. return; // Both players need to be online
  10630. if( pid != p1_sd->status.account_id )
  10631. return; // Incorrect values
  10632. if( result == 0 )
  10633. return; // Rejected
  10634. pc_adoption(p1_sd, p2_sd, sd);
  10635. }
  10636. /*==========================================
  10637. * Convex Mirror
  10638. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  10639. *==========================================*/
  10640. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  10641. {
  10642. WFIFOHEAD(fd,70);
  10643. memset(WFIFOP(fd,0),0,70);
  10644. WFIFOW(fd,0) = 0x0293;
  10645. if( md != NULL )
  10646. {
  10647. if( md->bl.prev != NULL )
  10648. { // Boss on This Map
  10649. if( flag )
  10650. {
  10651. WFIFOB(fd,2) = 1;
  10652. WFIFOL(fd,3) = md->bl.x;
  10653. WFIFOL(fd,7) = md->bl.y;
  10654. }
  10655. else
  10656. WFIFOB(fd,2) = 2; // First Time
  10657. }
  10658. else
  10659. { // Boss is Dead
  10660. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  10661. unsigned int seconds;
  10662. int hours, minutes;
  10663. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000;
  10664. hours = seconds / (60 * 60);
  10665. seconds = seconds - (60 * 60 * hours);
  10666. minutes = seconds / 60;
  10667. WFIFOB(fd,2) = 3;
  10668. WFIFOW(fd,11) = hours; // Hours
  10669. WFIFOW(fd,13) = minutes; // Minutes
  10670. }
  10671. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  10672. }
  10673. WFIFOSET(fd,70);
  10674. }
  10675. /*==========================================
  10676. * Requesting equip of a player
  10677. *------------------------------------------*/
  10678. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10679. {
  10680. int charid = RFIFOL(fd, 2);
  10681. struct map_session_data* tsd = map_id2sd(charid);
  10682. if (!tsd)
  10683. return;
  10684. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  10685. clif_viewequip_ack(sd, tsd);
  10686. else
  10687. clif_viewequip_fail(sd);
  10688. }
  10689. /*==========================================
  10690. * Equip window (un)tick
  10691. * S 02d8 <zero?>.L <flag>.L
  10692. *------------------------------------------*/
  10693. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10694. {
  10695. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10696. sd->status.show_equip = flag;
  10697. clif_equiptickack(sd, flag);
  10698. }
  10699. /*==========================================
  10700. * Questlog System [Kevin]
  10701. * 02B5 <packet_len>.W <ignored>.L { }.10B* <-- UNKOWN PACKET
  10702. * 02B6 <quest_id>.L <state>.B
  10703. *------------------------------------------*/
  10704. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  10705. {
  10706. }
  10707. //Send simple list of quests upon login
  10708. //* 02B1 <packet_len>.W <ignored>.L { <quest_id>.L <state>.B }.5B*
  10709. void clif_send_questlog(struct map_session_data * sd)
  10710. {
  10711. int fd = sd->fd;
  10712. int i;
  10713. WFIFOHEAD(fd,sd->num_quests*5+8);
  10714. WFIFOW(fd, 0) = 0x02B1;
  10715. WFIFOW(fd, 2) = sd->num_quests*5+8;
  10716. for(i=0; i<MAX_QUEST; i++)
  10717. {
  10718. if(!sd->quest_log[i].quest_id)
  10719. continue;
  10720. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  10721. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  10722. }
  10723. WFIFOSET(fd, WFIFOW(fd, 2));
  10724. }
  10725. //Send objective info on login
  10726. //* 02B2 <packet_len>.W <ignored>.L { <quest_id>.L <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  10727. void clif_send_questlog_info(struct map_session_data * sd)
  10728. {
  10729. int fd = sd->fd;
  10730. int i, j;
  10731. WFIFOHEAD(fd,sd->num_quests*104+8);
  10732. WFIFOW(fd, 0) = 0x02B2;
  10733. WFIFOW(fd, 2) = sd->num_quests*104+8;
  10734. for(i=0; i<MAX_QUEST; i++)
  10735. {
  10736. if(!sd->quest_log[i].quest_id)
  10737. continue;
  10738. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  10739. // I have no idea what the time field does [Kevin]
  10740. WFIFOL(fd, i*104+16) = 0;
  10741. WFIFOW(fd, i*104+20) = sd->quest_log[i].num_objectives;
  10742. for(j=0; j<sd->quest_log[i].num_objectives; j++)
  10743. {
  10744. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].objectives[j].count;
  10745. memcpy(WFIFOP(fd, i*104+28+j*30), sd->quest_log[i].objectives[j].name, NAME_LENGTH);
  10746. }
  10747. }
  10748. WFIFOSET(fd, WFIFOW(fd, 2));
  10749. }
  10750. //Send info when objective info needs an update
  10751. //* 02B3 <quest_id>.L <state>.B <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3]
  10752. void clif_send_quest_info(struct map_session_data * sd, struct quest * qd)
  10753. {
  10754. int fd = sd->fd;
  10755. int i;
  10756. WFIFOHEAD(fd,qd->num_objectives*30+17);
  10757. WFIFOW(fd, 0) = 0x02B3;
  10758. WFIFOL(fd, 2) = qd->quest_id;
  10759. WFIFOB(fd, 6) = qd->state;
  10760. //Same time value thing
  10761. WFIFOW(fd, 11) = 0;
  10762. WFIFOW(fd, 15) = qd->num_objectives;
  10763. for(i=0; i<qd->num_objectives; i++)
  10764. {
  10765. WFIFOW(fd, i*30+21) = qd->objectives[i].count;
  10766. memcpy(WFIFOP(fd, i*30+23), qd->objectives[i].name, NAME_LENGTH);
  10767. }
  10768. WFIFOSET(fd, qd->num_objectives*30+17);
  10769. }
  10770. //Send delete msg
  10771. //* 02B4 <quest_id>.L
  10772. void clif_send_quest_delete(struct map_session_data * sd, int quest_id)
  10773. {
  10774. int fd = sd->fd;
  10775. WFIFOHEAD(fd, 6);
  10776. WFIFOW(fd, 0) = 0x02B4;
  10777. WFIFOL(fd, 2) = quest_id;
  10778. WFIFOSET(fd, 6);
  10779. }
  10780. //Change active state of the quest
  10781. //* 02B7 <quest_id>.L <state_to>.B
  10782. void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active)
  10783. {
  10784. int fd = sd->fd;
  10785. WFIFOHEAD(fd, 7);
  10786. WFIFOW(fd, 0) = 0x02B7;
  10787. WFIFOL(fd, 2) = quest_id;
  10788. WFIFOB(fd, 6) = active?1:0;
  10789. WFIFOSET(fd, 7);
  10790. }
  10791. /*==========================================
  10792. * Mercenary System
  10793. *==========================================*/
  10794. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  10795. {
  10796. struct mercenary_data *md;
  10797. struct status_data *status;
  10798. int fd;
  10799. if( sd == NULL || (md = sd->md) == NULL )
  10800. return;
  10801. fd = sd->fd;
  10802. status = &md->battle_status;
  10803. WFIFOHEAD(fd,8);
  10804. WFIFOW(fd,0) = 0x02a2;
  10805. WFIFOW(fd,2) = type;
  10806. switch( type )
  10807. {
  10808. case SP_ATK1:
  10809. {
  10810. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10811. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  10812. }
  10813. break;
  10814. case SP_MATK1:
  10815. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  10816. break;
  10817. case SP_HIT:
  10818. WFIFOL(fd,4) = status->hit;
  10819. break;
  10820. case SP_CRITICAL:
  10821. WFIFOL(fd,4) = status->cri/10;
  10822. break;
  10823. case SP_DEF1:
  10824. WFIFOL(fd,4) = status->def;
  10825. break;
  10826. case SP_MDEF1:
  10827. WFIFOL(fd,4) = status->mdef;
  10828. break;
  10829. case SP_MERCFLEE:
  10830. WFIFOL(fd,4) = status->flee;
  10831. break;
  10832. case SP_ASPD:
  10833. WFIFOL(fd,4) = status->amotion;
  10834. break;
  10835. case SP_HP:
  10836. WFIFOL(fd,4) = status->hp;
  10837. break;
  10838. case SP_MAXHP:
  10839. WFIFOL(fd,4) = status->max_hp;
  10840. break;
  10841. case SP_SP:
  10842. WFIFOL(fd,4) = status->sp;
  10843. break;
  10844. case SP_MAXSP:
  10845. WFIFOL(fd,4) = status->max_sp;
  10846. break;
  10847. case SP_MERCKILLS:
  10848. WFIFOL(fd,4) = md->mercenary.kill_count;
  10849. break;
  10850. case SP_MERCFAITH:
  10851. WFIFOL(fd,4) = mercenary_get_faith(md);
  10852. break;
  10853. }
  10854. WFIFOSET(fd,8);
  10855. }
  10856. void clif_mercenary_info(struct map_session_data *sd)
  10857. {
  10858. int fd;
  10859. struct mercenary_data *md;
  10860. struct status_data *status;
  10861. int atk;
  10862. if( sd == NULL || (md = sd->md) == NULL )
  10863. return;
  10864. fd = sd->fd;
  10865. status = &md->battle_status;
  10866. WFIFOHEAD(fd,80);
  10867. WFIFOW(fd,0) = 0x029b;
  10868. WFIFOL(fd,2) = md->bl.id;
  10869. // Mercenary shows ATK as a random value between ATK ~ ATK2
  10870. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10871. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  10872. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  10873. WFIFOW(fd,10) = status->hit;
  10874. WFIFOW(fd,12) = status->cri/10;
  10875. WFIFOW(fd,14) = status->def;
  10876. WFIFOW(fd,16) = status->mdef;
  10877. WFIFOW(fd,18) = status->flee;
  10878. WFIFOW(fd,20) = status->amotion;
  10879. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  10880. WFIFOW(fd,46) = md->db->lv;
  10881. WFIFOL(fd,48) = status->hp;
  10882. WFIFOL(fd,52) = status->max_hp;
  10883. WFIFOL(fd,56) = status->sp;
  10884. WFIFOL(fd,60) = status->max_sp;
  10885. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  10886. WFIFOW(fd,68) = mercenary_get_faith(md);
  10887. WFIFOL(fd,70) = mercenary_get_calls(md);
  10888. WFIFOL(fd,74) = md->mercenary.kill_count;
  10889. WFIFOW(fd,78) = md->battle_status.rhw.range;
  10890. WFIFOSET(fd,80);
  10891. }
  10892. void clif_mercenary_skillblock(struct map_session_data *sd)
  10893. {
  10894. struct mercenary_data *md;
  10895. int fd, i, len = 4, id, j;
  10896. if( sd == NULL || (md = sd->md) == NULL )
  10897. return;
  10898. fd = sd->fd;
  10899. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  10900. WFIFOW(fd,0) = 0x029d;
  10901. for( i = 0; i < MAX_MERCSKILL; i++ )
  10902. {
  10903. if( (id = md->db->skill[i].id) == 0 )
  10904. continue;
  10905. j = id - MC_SKILLBASE;
  10906. WFIFOW(fd,len) = id;
  10907. WFIFOW(fd,len+2) = skill_get_inf(id);
  10908. WFIFOW(fd,len+4) = 0;
  10909. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  10910. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  10911. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  10912. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  10913. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  10914. len += 37;
  10915. }
  10916. WFIFOW(fd,2) = len;
  10917. WFIFOSET(fd,len);
  10918. }
  10919. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  10920. {
  10921. int option = RFIFOB(fd,2);
  10922. if( sd->md == NULL )
  10923. return;
  10924. if( option == 2 ) merc_delete(sd->md, 2);
  10925. }
  10926. /*------------------------------------------
  10927. * Mercenary Message
  10928. * 0 = Mercenary soldier's duty hour is over.
  10929. * 1 = Your mercenary soldier has been killed.
  10930. * 2 = Your mercenary soldier has been fired.
  10931. * 3 = Your mercenary soldier has ran away.
  10932. *------------------------------------------*/
  10933. void clif_mercenary_message(int fd, int message)
  10934. {
  10935. WFIFOHEAD(fd,4);
  10936. WFIFOW(fd,0) = 0x0291;
  10937. WFIFOW(fd,2) = 1266 + message;
  10938. WFIFOSET(fd,4);
  10939. }
  10940. /*------------------------------------------
  10941. * Rental System Messages
  10942. *------------------------------------------*/
  10943. void clif_rental_time(int fd, int nameid, int seconds)
  10944. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  10945. WFIFOHEAD(fd,8);
  10946. WFIFOW(fd,0) = 0x0298;
  10947. WFIFOW(fd,2) = nameid;
  10948. WFIFOL(fd,4) = seconds;
  10949. WFIFOSET(fd,8);
  10950. }
  10951. void clif_rental_expired(int fd, int nameid)
  10952. { // '<ItemName>' item has been deleted from the Inventory
  10953. WFIFOHEAD(fd,6);
  10954. WFIFOW(fd,0) = 0x0299;
  10955. WFIFOW(fd,2) = 0;
  10956. WFIFOW(fd,4) = nameid;
  10957. WFIFOSET(fd,6);
  10958. }
  10959. /*------------------------------------------
  10960. * Book Reading
  10961. *------------------------------------------*/
  10962. void clif_readbook(int fd, int book_id, int page)
  10963. {
  10964. WFIFOHEAD(fd,10);
  10965. WFIFOW(fd,0) = 0x0294;
  10966. WFIFOL(fd,2) = book_id;
  10967. WFIFOL(fd,6) = page;
  10968. WFIFOSET(fd,10);
  10969. }
  10970. /*==========================================
  10971. * パケットデバッグ
  10972. *------------------------------------------*/
  10973. void clif_parse_debug(int fd,struct map_session_data *sd)
  10974. {
  10975. int i, cmd, len;
  10976. cmd = RFIFOW(fd,0);
  10977. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10978. ShowDebug("packet debug 0x%4X\n",cmd);
  10979. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10980. for(i=0;i<len;i++){
  10981. if((i&15)==0)
  10982. ShowMessage("\n%04X ",i);
  10983. ShowMessage("%02X ",RFIFOB(fd,i));
  10984. }
  10985. ShowMessage("\n");
  10986. }
  10987. /*==========================================
  10988. * Main client packet processing function
  10989. *------------------------------------------*/
  10990. int clif_parse(int fd)
  10991. {
  10992. int cmd, packet_ver, packet_len, err;
  10993. TBL_PC* sd;
  10994. int pnum;
  10995. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10996. // Note: "click masters" can do 80+ clicks in 10 seconds
  10997. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10998. { // begin main client packet processing loop
  10999. sd = (TBL_PC *)session[fd]->session_data;
  11000. if (session[fd]->flag.eof) {
  11001. if (sd) {
  11002. if (sd->state.autotrade) {
  11003. //Disassociate character from the socket connection.
  11004. session[fd]->session_data = NULL;
  11005. sd->fd = 0;
  11006. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11007. } else
  11008. if (sd->state.active) {
  11009. // Player logout display [Valaris]
  11010. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11011. clif_quitsave(fd, sd);
  11012. } else {
  11013. //Unusual logout (during log on/off/map-changer procedure)
  11014. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  11015. map_quit(sd);
  11016. }
  11017. } else {
  11018. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  11019. }
  11020. do_close(fd);
  11021. return 0;
  11022. }
  11023. if (RFIFOREST(fd) < 2)
  11024. return 0;
  11025. cmd = RFIFOW(fd,0);
  11026. // identify client's packet version
  11027. if (sd) {
  11028. packet_ver = sd->packet_ver;
  11029. } else {
  11030. // check authentification packet to know packet version
  11031. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  11032. if( err )
  11033. {// failed to identify packet version
  11034. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  11035. err == 1 ? "" :
  11036. err == 2 ? ", possibly for having an invalid account_id" :
  11037. err == 3 ? ", possibly for having an invalid char_id." :
  11038. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  11039. err == 4 ? ", possibly for having an invalid login_id1." :
  11040. err == 5 ? ", possibly for having an invalid client_tick." :
  11041. */
  11042. err == 6 ? ", possibly for having an invalid sex." :
  11043. ". ERROR invalid error code"));
  11044. WFIFOHEAD(fd,packet_len(0x6a));
  11045. WFIFOW(fd,0) = 0x6a;
  11046. WFIFOB(fd,2) = 3; // Rejected from Server
  11047. WFIFOSET(fd,packet_len(0x6a));
  11048. RFIFOSKIP(fd, RFIFOREST(fd));
  11049. set_eof(fd);
  11050. return 0;
  11051. }
  11052. }
  11053. // filter out invalid / unsupported packets
  11054. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  11055. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  11056. set_eof(fd);
  11057. return 0;
  11058. }
  11059. // determine real packet length
  11060. packet_len = packet_db[packet_ver][cmd].len;
  11061. if (packet_len == -1) { // variable-length packet
  11062. if (RFIFOREST(fd) < 4)
  11063. return 0;
  11064. packet_len = RFIFOW(fd,2);
  11065. if (packet_len < 4 || packet_len > 32768) {
  11066. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  11067. set_eof(fd);
  11068. return 0;
  11069. }
  11070. }
  11071. if ((int)RFIFOREST(fd) < packet_len)
  11072. return 0; // not enough data received to form the packet
  11073. if (packet_db[packet_ver][cmd].func) {
  11074. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  11075. ; //Only valid packet when player is not on a map is the finish-loading packet.
  11076. else
  11077. if ((sd && sd->state.active)
  11078. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  11079. || packet_db[packet_ver][cmd].func == clif_parse_debug
  11080. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  11081. packet_db[packet_ver][cmd].func(fd, sd);
  11082. }
  11083. #if DUMP_UNKNOWN_PACKET
  11084. else if (battle_config.error_log)
  11085. {
  11086. int i;
  11087. FILE *fp;
  11088. char packet_txt[256] = "save/packet.txt";
  11089. time_t now;
  11090. dump = 1;
  11091. if ((fp = fopen(packet_txt, "a")) == NULL) {
  11092. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  11093. return 1;
  11094. } else {
  11095. time(&now);
  11096. if (sd && sd->state.active) {
  11097. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  11098. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  11099. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11100. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  11101. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11102. for(i = 0; i < packet_len; i++) {
  11103. if ((i & 15) == 0)
  11104. fprintf(fp, "\n\t%04X ", i);
  11105. fprintf(fp, "%02X ", RFIFOB(fd,i));
  11106. }
  11107. fprintf(fp, "\n\n");
  11108. fclose(fp);
  11109. }
  11110. }
  11111. #endif
  11112. /* TODO: use utils.c :: dump()
  11113. if (dump) {
  11114. int i;
  11115. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  11116. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11117. for(i = 0; i < packet_len; i++) {
  11118. if ((i & 15) == 0)
  11119. ShowMessage("\n%04X ",i);
  11120. ShowMessage("%02X ", RFIFOB(fd,i));
  11121. }
  11122. ShowMessage("\n");
  11123. if (sd && sd->state.active) {
  11124. if (sd->status.name != NULL)
  11125. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  11126. sd->status.account_id, sd->status.char_id, sd->status.name);
  11127. else
  11128. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11129. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11130. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11131. }*/
  11132. RFIFOSKIP(fd, packet_len);
  11133. }; // main loop end
  11134. return 0;
  11135. }
  11136. /*==========================================
  11137. * パケットデータベース読み込み
  11138. *------------------------------------------*/
  11139. static int packetdb_readdb(void)
  11140. {
  11141. FILE *fp;
  11142. char line[1024];
  11143. int ln=0;
  11144. int cmd,i,j,packet_ver;
  11145. int max_cmd=-1;
  11146. int skip_ver = 0;
  11147. int warned = 0;
  11148. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  11149. int packet_len_table[MAX_PACKET_DB] = {
  11150. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11154. //#0x0040
  11155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11157. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  11158. #if PACKETVER < 2
  11159. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  11160. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  11161. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  11162. #else // change in 0x78 and 0x7c
  11163. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  11164. #endif
  11165. //#0x0080
  11166. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  11167. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  11168. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  11169. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  11170. //#0x00C0
  11171. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  11172. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  11173. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  11174. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  11175. //#0x0100
  11176. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  11177. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  11178. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  11179. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  11180. //#0x0140
  11181. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  11182. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  11183. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  11184. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  11185. //#0x0180
  11186. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  11187. #if PACKETVER < 1
  11188. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11189. #else // 196 comodo以降 状態表示アイコン用
  11190. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11191. #endif
  11192. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  11193. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  11194. //#0x01C0, Set 0x1d5=-1
  11195. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  11196. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  11197. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  11198. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  11199. //#0x0200
  11200. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  11201. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  11202. #if PACKETVER < 20071106
  11203. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  11204. #else // 0x22c changed
  11205. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  11206. #endif
  11207. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  11208. //#0x0240
  11209. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  11210. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  11211. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11212. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11213. //#0x0280
  11214. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  11215. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11217. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  11218. //#0x02C0
  11219. 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11220. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  11221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11223. };
  11224. struct {
  11225. void (*func)(int, struct map_session_data *);
  11226. char *name;
  11227. } clif_parse_func[]={
  11228. {clif_parse_WantToConnection,"wanttoconnection"},
  11229. {clif_parse_LoadEndAck,"loadendack"},
  11230. {clif_parse_TickSend,"ticksend"},
  11231. {clif_parse_WalkToXY,"walktoxy"},
  11232. {clif_parse_QuitGame,"quitgame"},
  11233. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  11234. {clif_parse_GlobalMessage,"globalmessage"},
  11235. {clif_parse_MapMove,"mapmove"},
  11236. {clif_parse_ChangeDir,"changedir"},
  11237. {clif_parse_Emotion,"emotion"},
  11238. {clif_parse_HowManyConnections,"howmanyconnections"},
  11239. {clif_parse_ActionRequest,"actionrequest"},
  11240. {clif_parse_Restart,"restart"},
  11241. {clif_parse_WisMessage,"wis"},
  11242. {clif_parse_GMmessage,"gmmessage"},
  11243. {clif_parse_TakeItem,"takeitem"},
  11244. {clif_parse_DropItem,"dropitem"},
  11245. {clif_parse_UseItem,"useitem"},
  11246. {clif_parse_EquipItem,"equipitem"},
  11247. {clif_parse_UnequipItem,"unequipitem"},
  11248. {clif_parse_NpcClicked,"npcclicked"},
  11249. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  11250. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  11251. {clif_parse_NpcSellListSend,"npcselllistsend"},
  11252. {clif_parse_CreateChatRoom,"createchatroom"},
  11253. {clif_parse_ChatAddMember,"chataddmember"},
  11254. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  11255. {clif_parse_ChangeChatOwner,"changechatowner"},
  11256. {clif_parse_KickFromChat,"kickfromchat"},
  11257. {clif_parse_ChatLeave,"chatleave"},
  11258. {clif_parse_TradeRequest,"traderequest"},
  11259. {clif_parse_TradeAck,"tradeack"},
  11260. {clif_parse_TradeAddItem,"tradeadditem"},
  11261. {clif_parse_TradeOk,"tradeok"},
  11262. {clif_parse_TradeCancel,"tradecancel"},
  11263. {clif_parse_TradeCommit,"tradecommit"},
  11264. {clif_parse_StopAttack,"stopattack"},
  11265. {clif_parse_PutItemToCart,"putitemtocart"},
  11266. {clif_parse_GetItemFromCart,"getitemfromcart"},
  11267. {clif_parse_RemoveOption,"removeoption"},
  11268. {clif_parse_ChangeCart,"changecart"},
  11269. {clif_parse_StatusUp,"statusup"},
  11270. {clif_parse_SkillUp,"skillup"},
  11271. {clif_parse_UseSkillToId,"useskilltoid"},
  11272. {clif_parse_UseSkillToPos,"useskilltopos"},
  11273. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  11274. {clif_parse_UseSkillMap,"useskillmap"},
  11275. {clif_parse_RequestMemo,"requestmemo"},
  11276. {clif_parse_ProduceMix,"producemix"},
  11277. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  11278. {clif_parse_NpcNextClicked,"npcnextclicked"},
  11279. {clif_parse_NpcAmountInput,"npcamountinput"},
  11280. {clif_parse_NpcStringInput,"npcstringinput"},
  11281. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  11282. {clif_parse_ItemIdentify,"itemidentify"},
  11283. {clif_parse_SelectArrow,"selectarrow"},
  11284. {clif_parse_AutoSpell,"autospell"},
  11285. {clif_parse_UseCard,"usecard"},
  11286. {clif_parse_InsertCard,"insertcard"},
  11287. {clif_parse_RepairItem,"repairitem"},
  11288. {clif_parse_WeaponRefine,"weaponrefine"},
  11289. {clif_parse_SolveCharName,"solvecharname"},
  11290. {clif_parse_ResetChar,"resetchar"},
  11291. {clif_parse_LGMmessage,"lgmmessage"},
  11292. {clif_parse_MoveToKafra,"movetokafra"},
  11293. {clif_parse_MoveFromKafra,"movefromkafra"},
  11294. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  11295. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  11296. {clif_parse_CloseKafra,"closekafra"},
  11297. {clif_parse_CreateParty,"createparty"},
  11298. {clif_parse_CreateParty2,"createparty2"},
  11299. {clif_parse_PartyInvite,"partyinvite"},
  11300. {clif_parse_PartyInvite2,"partyinvite2"},
  11301. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  11302. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  11303. {clif_parse_LeaveParty,"leaveparty"},
  11304. {clif_parse_RemovePartyMember,"removepartymember"},
  11305. {clif_parse_PartyChangeOption,"partychangeoption"},
  11306. {clif_parse_PartyMessage,"partymessage"},
  11307. {clif_parse_CloseVending,"closevending"},
  11308. {clif_parse_VendingListReq,"vendinglistreq"},
  11309. {clif_parse_PurchaseReq,"purchasereq"},
  11310. {clif_parse_OpenVending,"openvending"},
  11311. {clif_parse_CreateGuild,"createguild"},
  11312. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  11313. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  11314. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  11315. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  11316. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  11317. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  11318. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  11319. {clif_parse_GuildInvite,"guildinvite"},
  11320. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  11321. {clif_parse_GuildLeave,"guildleave"},
  11322. {clif_parse_GuildExpulsion,"guildexpulsion"},
  11323. {clif_parse_GuildMessage,"guildmessage"},
  11324. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  11325. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  11326. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  11327. {clif_parse_GuildOpposition,"guildopposition"},
  11328. {clif_parse_GuildBreak,"guildbreak"},
  11329. {clif_parse_PetMenu,"petmenu"},
  11330. {clif_parse_CatchPet,"catchpet"},
  11331. {clif_parse_SelectEgg,"selectegg"},
  11332. {clif_parse_SendEmotion,"sendemotion"},
  11333. {clif_parse_ChangePetName,"changepetname"},
  11334. {clif_parse_GMKick,"gmkick"},
  11335. {clif_parse_GMHide,"gmhide"},
  11336. {clif_parse_GMReqNoChat,"gmreqnochat"},
  11337. {clif_parse_GMReqAccountName,"gmreqaccname"},
  11338. {clif_parse_GMKickAll,"killall"},
  11339. {clif_parse_GMRecall,"recall"},
  11340. {clif_parse_GMRecall,"summon"},
  11341. {clif_parse_GM_Monster_Item,"itemmonster"},
  11342. {clif_parse_GMShift,"remove"},
  11343. {clif_parse_GMShift,"shift"},
  11344. {clif_parse_GMChangeMapType,"changemaptype"},
  11345. {clif_parse_GMRc,"rc"},
  11346. {clif_parse_NoviceDoriDori,"sndoridori"},
  11347. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  11348. {clif_parse_PMIgnore,"wisexin"},
  11349. {clif_parse_PMIgnoreList,"wisexlist"},
  11350. {clif_parse_PMIgnoreAll,"wisall"},
  11351. {clif_parse_FriendsListAdd,"friendslistadd"},
  11352. {clif_parse_FriendsListRemove,"friendslistremove"},
  11353. {clif_parse_FriendsListReply,"friendslistreply"},
  11354. {clif_parse_Blacksmith,"blacksmith"},
  11355. {clif_parse_Alchemist,"alchemist"},
  11356. {clif_parse_Taekwon,"taekwon"},
  11357. {clif_parse_RankingPk,"rankingpk"},
  11358. {clif_parse_FeelSaveOk,"feelsaveok"},
  11359. {clif_parse_debug,"debug"},
  11360. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  11361. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  11362. {clif_parse_HomMoveTo,"hommoveto"},
  11363. {clif_parse_HomAttack,"homattack"},
  11364. {clif_parse_HomMenu,"hommenu"},
  11365. {clif_parse_StoragePassword,"storagepassword"},
  11366. {clif_parse_Hotkey,"hotkey"},
  11367. {clif_parse_AutoRevive,"autorevive"},
  11368. {clif_parse_Check,"check"},
  11369. {clif_parse_Adopt_request,"adoptrequest"},
  11370. {clif_parse_Adopt_reply,"adoptreply"},
  11371. #ifndef TXT_ONLY
  11372. // MAIL SYSTEM
  11373. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  11374. {clif_parse_Mail_read,"mailread"},
  11375. {clif_parse_Mail_getattach,"mailgetattach"},
  11376. {clif_parse_Mail_delete,"maildelete"},
  11377. {clif_parse_Mail_return,"mailreturn"},
  11378. {clif_parse_Mail_setattach,"mailsetattach"},
  11379. {clif_parse_Mail_winopen,"mailwinopen"},
  11380. {clif_parse_Mail_send,"mailsend"},
  11381. // AUCTION SYSTEM
  11382. {clif_parse_Auction_search,"auctionsearch"},
  11383. {clif_parse_Auction_buysell,"auctionbuysell"},
  11384. {clif_parse_Auction_setitem,"auctionsetitem"},
  11385. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  11386. {clif_parse_Auction_register,"auctionregister"},
  11387. {clif_parse_Auction_cancel,"auctioncancel"},
  11388. {clif_parse_Auction_close,"auctionclose"},
  11389. {clif_parse_Auction_bid,"auctionbid"},
  11390. #endif
  11391. {clif_parse_cashshop_buy,"cashshopbuy"},
  11392. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  11393. {clif_parse_EquipTick,"equiptickbox"},
  11394. {clif_parse_mercenary_action,"mermenu"},
  11395. {NULL,NULL}
  11396. };
  11397. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  11398. memset(packet_db,0,sizeof(packet_db));
  11399. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  11400. packet_len(i) = packet_len_table[i];
  11401. sprintf(line, "%s/packet_db.txt", db_path);
  11402. if( (fp=fopen(line,"r"))==NULL ){
  11403. ShowFatalError("can't read %s\n", line);
  11404. exit(EXIT_FAILURE);
  11405. }
  11406. clif_config.packet_db_ver = MAX_PACKET_VER;
  11407. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  11408. while( fgets(line, sizeof(line), fp) )
  11409. {
  11410. ln++;
  11411. if(line[0]=='/' && line[1]=='/')
  11412. continue;
  11413. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  11414. {
  11415. if(strcmpi(w1,"packet_ver")==0) {
  11416. int prev_ver = packet_ver;
  11417. skip_ver = 0;
  11418. packet_ver = atoi(w2);
  11419. if ( packet_ver > MAX_PACKET_VER )
  11420. { //Check to avoid overflowing. [Skotlex]
  11421. if( (warned&1) == 0 )
  11422. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  11423. warned &= 1;
  11424. skip_ver = 1;
  11425. }
  11426. else if( packet_ver < 0 )
  11427. {
  11428. if( (warned&2) == 0 )
  11429. ShowWarning("Negative packet versions are not supported.\n");
  11430. warned &= 2;
  11431. skip_ver = 1;
  11432. }
  11433. else if( packet_ver == SERVER )
  11434. {
  11435. if( (warned&4) == 0 )
  11436. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  11437. warned &= 4;
  11438. skip_ver = 1;
  11439. }
  11440. if( skip_ver )
  11441. {
  11442. ShowWarning("Skipping packet version %d.\n", packet_ver);
  11443. packet_ver = prev_ver;
  11444. continue;
  11445. }
  11446. // copy from previous version into new version and continue
  11447. // - indicating all following packets should be read into the newer version
  11448. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  11449. continue;
  11450. } else if(strcmpi(w1,"packet_db_ver")==0) {
  11451. if(strcmpi(w2,"default")==0) //This is the preferred version.
  11452. clif_config.packet_db_ver = MAX_PACKET_VER;
  11453. else // to manually set the packet DB version
  11454. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  11455. continue;
  11456. }
  11457. }
  11458. if( skip_ver != 0 )
  11459. continue; // Skipping current packet version
  11460. memset(str,0,sizeof(str));
  11461. for(j=0,p=line;j<4 && p; ++j)
  11462. {
  11463. str[j]=p;
  11464. p=strchr(p,',');
  11465. if(p) *p++=0;
  11466. }
  11467. if(str[0]==NULL)
  11468. continue;
  11469. cmd=strtol(str[0],(char **)NULL,0);
  11470. if(max_cmd < cmd)
  11471. max_cmd = cmd;
  11472. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  11473. continue;
  11474. if(str[1]==NULL){
  11475. ShowError("packet_db: packet len error\n");
  11476. continue;
  11477. }
  11478. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  11479. if(str[2]==NULL){
  11480. packet_db[packet_ver][cmd].func = NULL;
  11481. ln++;
  11482. continue;
  11483. }
  11484. // look up processing function by name
  11485. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  11486. if( j < ARRAYLENGTH(clif_parse_func) )
  11487. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  11488. // set the identifying cmd for the packet_db version
  11489. if (strcmp(str[2],"wanttoconnection")==0)
  11490. clif_config.connect_cmd[packet_ver] = cmd;
  11491. if(str[3]==NULL){
  11492. ShowError("packet_db: packet error\n");
  11493. exit(EXIT_FAILURE);
  11494. }
  11495. for(j=0,p2=str[3];p2;j++){
  11496. short k;
  11497. str2[j]=p2;
  11498. p2=strchr(p2,':');
  11499. if(p2) *p2++=0;
  11500. k = atoi(str2[j]);
  11501. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  11502. packet_db[packet_ver][cmd].pos[j] = k;
  11503. }
  11504. }
  11505. fclose(fp);
  11506. if(max_cmd > MAX_PACKET_DB)
  11507. {
  11508. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11509. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11510. }
  11511. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11512. { //Locate the nearest version that we still support. [Skotlex]
  11513. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11514. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11515. }
  11516. 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);
  11517. return 0;
  11518. }
  11519. /*==========================================
  11520. *
  11521. *------------------------------------------*/
  11522. int do_init_clif(void)
  11523. {
  11524. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11525. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11526. memset(packet_db,0,sizeof(packet_db));
  11527. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11528. packetdb_readdb();
  11529. set_defaultparse(clif_parse);
  11530. if( make_listen_bind(bind_ip,map_port) == -1 )
  11531. {
  11532. ShowFatalError("can't bind game port\n");
  11533. exit(EXIT_FAILURE);
  11534. }
  11535. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11536. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11537. return 0;
  11538. }