atcommand.cpp 351 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "atcommand.hpp"
  4. #include <cmath>
  5. #include <cstdlib>
  6. #include <set>
  7. #include <unordered_map>
  8. #include <common/cbasetypes.hpp>
  9. #include <common/database.hpp>
  10. #include <common/cli.hpp>
  11. #include <common/malloc.hpp>
  12. #include <common/mmo.hpp>
  13. #include <common/nullpo.hpp>
  14. #include <common/random.hpp>
  15. #include <common/showmsg.hpp>
  16. #include <common/socket.hpp>
  17. #include <common/strlib.hpp>
  18. #include <common/timer.hpp>
  19. #include <common/utilities.hpp>
  20. #include <common/utils.hpp>
  21. #include "achievement.hpp"
  22. #include "battle.hpp"
  23. #include "buyingstore.hpp"
  24. #include "channel.hpp"
  25. #include "chat.hpp"
  26. #include "chrif.hpp"
  27. #include "clan.hpp"
  28. #include "clif.hpp"
  29. #include "duel.hpp"
  30. #include "elemental.hpp"
  31. #include "guild.hpp"
  32. #include "homunculus.hpp"
  33. #include "instance.hpp"
  34. #include "intif.hpp"
  35. #include "itemdb.hpp" // MAX_ITEMGROUP
  36. #include "cashshop.hpp"
  37. #include "log.hpp"
  38. #include "mail.hpp"
  39. #include "map.hpp"
  40. #include "mapreg.hpp"
  41. #include "mercenary.hpp"
  42. #include "mob.hpp"
  43. #include "npc.hpp"
  44. #include "party.hpp"
  45. #include "pc.hpp"
  46. #include "pc_groups.hpp"
  47. #include "pet.hpp"
  48. #include "quest.hpp"
  49. #include "script.hpp"
  50. #include "storage.hpp"
  51. #include "trade.hpp"
  52. #include "vending.hpp"
  53. using namespace rathena;
  54. #define ATCOMMAND_LENGTH 50
  55. #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, map_session_data* sd, const char* command, const char* message)
  56. typedef struct AtCommandInfo AtCommandInfo;
  57. int atcmd_binding_count = 0;
  58. /// Atcommand restriction usage
  59. enum e_atcmd_restict {
  60. ATCMD_NOCONSOLE = 0x1, /// Cannot be used via console (is_atcommand type 2)
  61. ATCMD_NOSCRIPT = 0x2, /// Cannot be used via script command 'atcommand' or 'useatcmd' (is_atcommand type 0 and 3)
  62. ATCMD_NOAUTOTRADE = 0x4, /// Like ATCMD_NOSCRIPT, but if the player is autotrader. Example: atcommand "@kick "+strcharinfo(0);
  63. };
  64. struct AtCommandInfo {
  65. char command[ATCOMMAND_LENGTH];
  66. AtCommandFunc func;
  67. char* at_groups; /// Quick @commands "can-use" lookup
  68. char* char_groups; /// Quick @charcommands "can-use" lookup
  69. uint8 restriction; /// Restrictions see enum e_restict
  70. };
  71. struct s_atcommand_alias_info{
  72. AtCommandInfo *command;
  73. std::set<std::string> aliases;
  74. std::string help;
  75. };
  76. char atcommand_symbol = '@'; // first char of the commands
  77. char charcommand_symbol = '#';
  78. static DBMap* atcommand_db = nullptr; //name -> AtCommandInfo
  79. static AtCommandInfo* get_atcommandinfo_byname( const char* name );
  80. class AtcommandAliasDatabase : public TypesafeYamlDatabase<std::string, s_atcommand_alias_info>{
  81. private:
  82. std::unordered_map<std::string, std::string> aliases;
  83. public:
  84. AtcommandAliasDatabase() : TypesafeYamlDatabase( "ATCOMMAND_DB", 1 ){
  85. }
  86. void clear() override;
  87. const std::string getDefaultLocation() override;
  88. uint64 parseBodyNode( const ryml::NodeRef& node ) override;
  89. // Additional
  90. const char* checkAlias( const char* alias );
  91. };
  92. void AtcommandAliasDatabase::clear(){
  93. TypesafeYamlDatabase::clear();
  94. this->aliases.clear();
  95. }
  96. const std::string AtcommandAliasDatabase::getDefaultLocation(){
  97. return std::string(conf_path) + "/atcommands.yml";
  98. }
  99. uint64 AtcommandAliasDatabase::parseBodyNode( const ryml::NodeRef& node ){
  100. std::string command;
  101. if( !this->asString( node, "Command", command ) ){
  102. return 0;
  103. }
  104. AtCommandInfo* commandinfo = get_atcommandinfo_byname( command.c_str() );
  105. if( commandinfo == nullptr ){
  106. this->invalidWarning( node["Command"], "Command %s does not exist.\n", command.c_str() );
  107. return 0;
  108. }
  109. std::shared_ptr<s_atcommand_alias_info> info = this->find( command );
  110. bool exists = info != nullptr;
  111. if( !exists ){
  112. info = std::make_shared<s_atcommand_alias_info>();
  113. info->command = commandinfo;
  114. }
  115. if( this->nodeExists( node, "Help" ) ){
  116. std::string help;
  117. if( !this->asString( node, "Help", help ) ){
  118. return 0;
  119. }
  120. info->help = help;
  121. }
  122. if( this->nodeExists( node, "Aliases" ) ){
  123. const auto& aliasesNode = node["Aliases"];
  124. if( !aliasesNode.is_seq() ){
  125. this->invalidWarning( aliasesNode, "Aliases should be a sequence.\n" );
  126. return 0;
  127. }
  128. for( const auto& subNode : aliasesNode ){
  129. std::string alias;
  130. subNode >> alias;
  131. info->aliases.insert( alias );
  132. this->aliases[alias] = command;
  133. }
  134. }
  135. if( !exists ){
  136. this->put( command, info );
  137. }
  138. return 1;
  139. }
  140. const char* AtcommandAliasDatabase::checkAlias( const char* alias ){
  141. std::string alias_str( alias );
  142. std::string* command = util::umap_find( this->aliases, alias_str );
  143. if( command == nullptr ){
  144. return alias;
  145. }else{
  146. return command->c_str();
  147. }
  148. }
  149. AtcommandAliasDatabase atcommand_alias_db;
  150. static char atcmd_output[CHAT_SIZE_MAX];
  151. static char atcmd_player_name[NAME_LENGTH];
  152. const char *parent_cmd;
  153. struct atcmd_binding_data** atcmd_binding;
  154. static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help
  155. static void atcommand_get_suggestions(map_session_data* sd, const char *name, bool atcommand); // @help
  156. static void warp_get_suggestions(map_session_data* sd, const char *name); // @rura, @warp, @mapmove
  157. // @commands (script-based)
  158. struct atcmd_binding_data* get_atcommandbind_byname(const char* name) {
  159. int i = 0;
  160. if( *name == atcommand_symbol || *name == charcommand_symbol )
  161. name++; // for backwards compatibility
  162. ARR_FIND( 0, atcmd_binding_count, i, strcmpi(atcmd_binding[i]->command, name) == 0 );
  163. return ( i < atcmd_binding_count ) ? atcmd_binding[i] : nullptr;
  164. }
  165. /**
  166. * retrieves the help string associated with a given command.
  167. *
  168. * @param name the name of the command to retrieve help information for
  169. * @return the string associated with the command, or nullptr
  170. */
  171. static const char* atcommand_help_string( const char* command ){
  172. // remove the prefix symbol for the raw name of the command
  173. if( *command == atcommand_symbol || *command == charcommand_symbol ){
  174. command++;
  175. }
  176. // convert alias to the real command name
  177. command = atcommand_alias_db.checkAlias( command );
  178. // attempt to find the first default help command
  179. std::shared_ptr<s_atcommand_alias_info> info = atcommand_alias_db.find( command );
  180. // failed to find the help property in the configuration file
  181. if( info == nullptr ){
  182. return nullptr;
  183. }
  184. // push the result from the method
  185. return info->help.c_str();
  186. }
  187. /*==========================================
  188. * @send (used for testing packet sends from the client)
  189. *------------------------------------------*/
  190. ACMD_FUNC(send)
  191. {
  192. int len=0,type;
  193. // read message type as hex number (without the 0x)
  194. if(!message || !*message ||
  195. !((sscanf(message, "len %8x", &type)==1 && (len=1))
  196. || sscanf(message, "%8x", &type)==1) )
  197. {
  198. int i;
  199. for (i = 900; i <= 903; ++i)
  200. clif_displaymessage(fd, msg_txt(sd,i));
  201. return -1;
  202. }
  203. #define PARSE_ERROR(error,p) \
  204. {\
  205. clif_displaymessage(fd, (error));\
  206. sprintf(atcmd_output, ">%s", (p));\
  207. clif_displaymessage(fd, atcmd_output);\
  208. }
  209. //define PARSE_ERROR
  210. #define CHECK_EOS(p) \
  211. if(*(p) == 0){\
  212. clif_displaymessage(fd, "Unexpected end of string");\
  213. return -1;\
  214. }
  215. //define CHECK_EOS
  216. #define SKIP_VALUE(p) \
  217. {\
  218. while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
  219. while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
  220. }
  221. //define SKIP_VALUE
  222. #define GET_VALUE(p,num) \
  223. {\
  224. if(sscanf((p), "x%16lx", &(num)) < 1 && sscanf((p), "%20ld ", &(num)) < 1){\
  225. PARSE_ERROR("Invalid number in:",(p));\
  226. return -1;\
  227. }\
  228. }
  229. //define GET_VALUE
  230. if (type > 0 && type < MAX_PACKET_DB) {
  231. int off,end;
  232. long num;
  233. if(len)
  234. {// show packet length
  235. sprintf(atcmd_output, msg_txt(sd,904), type, packet_db[type].len); // Packet 0x%x length: %d
  236. clif_displaymessage(fd, atcmd_output);
  237. return 0;
  238. }
  239. len=packet_db[type].len;
  240. off=2;
  241. if(len == 0)
  242. {// unknown packet - ERROR
  243. sprintf(atcmd_output, msg_txt(sd,905), type); // Unknown packet: 0x%x
  244. clif_displaymessage(fd, atcmd_output);
  245. return -1;
  246. } else if(len == -1)
  247. {// dynamic packet
  248. len=SHRT_MAX-4; // maximum length
  249. off=4;
  250. }
  251. WFIFOHEAD(fd, len);
  252. WFIFOW(fd,0)=TOW(type);
  253. // parse packet contents
  254. SKIP_VALUE(message);
  255. while(*message != 0 && off < len){
  256. if(ISDIGIT(*message) || *message == '-' || *message == '+')
  257. {// default (byte)
  258. GET_VALUE(message,num);
  259. WFIFOB(fd,off)=TOB(num);
  260. ++off;
  261. } else if(TOUPPER(*message) == 'B')
  262. {// byte
  263. ++message;
  264. GET_VALUE(message,num);
  265. WFIFOB(fd,off)=TOB(num);
  266. ++off;
  267. } else if(TOUPPER(*message) == 'W')
  268. {// word (2 bytes)
  269. ++message;
  270. GET_VALUE(message,num);
  271. WFIFOW(fd,off)=TOW(num);
  272. off+=2;
  273. } else if(TOUPPER(*message) == 'L')
  274. {// long word (4 bytes)
  275. ++message;
  276. GET_VALUE(message,num);
  277. WFIFOL(fd,off)=TOL(num);
  278. off+=4;
  279. } else if(TOUPPER(*message) == 'S')
  280. {// string - escapes are valid
  281. // get string length - num <= 0 means not fixed length (default)
  282. ++message;
  283. if(*message == '"'){
  284. num=0;
  285. } else {
  286. GET_VALUE(message,num);
  287. while(*message != '"')
  288. {// find start of string
  289. if(*message == 0 || ISSPACE(*message)){
  290. PARSE_ERROR(msg_txt(sd,906),message); // Not a string:
  291. return -1;
  292. }
  293. ++message;
  294. }
  295. }
  296. // parse string
  297. ++message;
  298. CHECK_EOS(message);
  299. end=(num<=0? 0: min(off+((int)num),len));
  300. for(; *message != '"' && (off < end || end == 0); ++off){
  301. if(*message == '\\'){
  302. ++message;
  303. CHECK_EOS(message);
  304. switch(*message){
  305. case 'a': num=0x07; break; // Bell
  306. case 'b': num=0x08; break; // Backspace
  307. case 't': num=0x09; break; // Horizontal tab
  308. case 'n': num=0x0A; break; // Line feed
  309. case 'v': num=0x0B; break; // Vertical tab
  310. case 'f': num=0x0C; break; // Form feed
  311. case 'r': num=0x0D; break; // Carriage return
  312. case 'e': num=0x1B; break; // Escape
  313. default: num=*message; break;
  314. case 'x': // Hexadecimal
  315. {
  316. ++message;
  317. CHECK_EOS(message);
  318. if(!ISXDIGIT(*message)){
  319. PARSE_ERROR(msg_txt(sd,907),message); // Not a hexadecimal digit:
  320. return -1;
  321. }
  322. num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  323. if(ISXDIGIT(*message)){
  324. ++message;
  325. CHECK_EOS(message);
  326. num<<=8;
  327. num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  328. }
  329. WFIFOB(fd,off)=TOB(num);
  330. ++message;
  331. CHECK_EOS(message);
  332. continue;
  333. }
  334. case '0':
  335. case '1':
  336. case '2':
  337. case '3':
  338. case '4':
  339. case '5':
  340. case '6':
  341. case '7': // Octal
  342. {
  343. num=*message-'0'; // 1st octal digit
  344. ++message;
  345. CHECK_EOS(message);
  346. if(ISDIGIT(*message) && *message < '8'){
  347. num<<=3;
  348. num+=*message-'0'; // 2nd octal digit
  349. ++message;
  350. CHECK_EOS(message);
  351. if(ISDIGIT(*message) && *message < '8'){
  352. num<<=3;
  353. num+=*message-'0'; // 3rd octal digit
  354. ++message;
  355. CHECK_EOS(message);
  356. }
  357. }
  358. WFIFOB(fd,off)=TOB(num);
  359. continue;
  360. }
  361. }
  362. } else
  363. num=*message;
  364. WFIFOB(fd,off)=TOB(num);
  365. ++message;
  366. CHECK_EOS(message);
  367. }//for
  368. while(*message != '"')
  369. {// ignore extra characters
  370. ++message;
  371. CHECK_EOS(message);
  372. }
  373. // terminate the string
  374. if(off < end)
  375. {// fill the rest with 0's
  376. memset(WFIFOP(fd,off),0,end-off);
  377. off=end;
  378. }
  379. } else
  380. {// unknown
  381. PARSE_ERROR(msg_txt(sd,908),message); // Unknown type of value in:
  382. return -1;
  383. }
  384. SKIP_VALUE(message);
  385. }
  386. if(packet_db[type].len == -1)
  387. {// send dynamic packet
  388. WFIFOW(fd,2)=TOW(off);
  389. WFIFOSET(fd,off);
  390. } else
  391. {// send static packet
  392. if(off < len)
  393. memset(WFIFOP(fd,off),0,len-off);
  394. WFIFOSET(fd,len);
  395. }
  396. } else {
  397. clif_displaymessage(fd, msg_txt(sd,259)); // Invalid packet
  398. return -1;
  399. }
  400. sprintf (atcmd_output, msg_txt(sd,258), type, type); // Sent packet 0x%x (%d)
  401. clif_displaymessage(fd, atcmd_output);
  402. return 0;
  403. #undef PARSE_ERROR
  404. #undef CHECK_EOS
  405. #undef SKIP_VALUE
  406. #undef GET_VALUE
  407. }
  408. /**
  409. * Retrieves map name suggestions for a given string.
  410. * This will first check if any map names contain the given string, and will
  411. * print out MAX_SUGGESTIONS results if any maps are found.
  412. * Otherwise, suggestions will be calculated through Levenshtein distance,
  413. * and up to 5 of the closest matches will be printed.
  414. *
  415. * @author Euphy
  416. */
  417. static void warp_get_suggestions(map_session_data* sd, const char *name) {
  418. // Minimum length for suggestions is 2 characters
  419. if( strlen( name ) < 2 ){
  420. return;
  421. }
  422. std::vector<const char*> suggestions;
  423. suggestions.reserve( MAX_SUGGESTIONS );
  424. // check for maps that contain string
  425. for (int i = 0; i < map_num; i++) {
  426. struct map_data *mapdata = map_getmapdata(i);
  427. // Prevent suggestion of instance mapnames
  428. if( mapdata->instance_id != 0 ){
  429. continue;
  430. }
  431. if( strstr( mapdata->name, name ) != nullptr ){
  432. suggestions.push_back( mapdata->name );
  433. if( suggestions.size() == MAX_SUGGESTIONS ){
  434. break;
  435. }
  436. }
  437. }
  438. // if no maps found, search by edit distance
  439. if( suggestions.empty() ){
  440. // Levenshtein > 4 is bad
  441. const int LEVENSHTEIN_MAX = 4;
  442. std::unordered_map<int, std::vector<const char*>> maps;
  443. for (int i = 0; i < map_num; i++) {
  444. struct map_data *mapdata = map_getmapdata(i);
  445. // Prevent suggestion of instance mapnames
  446. if(mapdata->instance_id != 0 ){
  447. continue;
  448. }
  449. // Calculate the levenshtein distance of the two strings
  450. int distance = levenshtein(mapdata->name, name);
  451. // Check if it is above the maximum defined distance
  452. if( distance > LEVENSHTEIN_MAX ){
  453. continue;
  454. }
  455. std::vector<const char*>& vector = maps[distance];
  456. // Do not add more entries than required
  457. if( vector.size() == MAX_SUGGESTIONS ){
  458. continue;
  459. }
  460. vector.push_back(mapdata->name);
  461. }
  462. for( int distance = 0; distance <= LEVENSHTEIN_MAX; distance++ ){
  463. std::vector<const char*>& vector = maps[distance];
  464. for( const char* found_map : vector ){
  465. suggestions.push_back( found_map );
  466. if( suggestions.size() == MAX_SUGGESTIONS ){
  467. break;
  468. }
  469. }
  470. if( suggestions.size() == MAX_SUGGESTIONS ){
  471. break;
  472. }
  473. }
  474. }
  475. // If no suggestion could be made, do not output anything at all
  476. if( suggestions.empty() ){
  477. return;
  478. }
  479. char buffer[CHAT_SIZE_MAX];
  480. // build the suggestion string
  481. strcpy(buffer, msg_txt(sd, 205)); // Maybe you meant:
  482. strcat(buffer, "\n");
  483. for( const char* suggestion : suggestions ){
  484. strcat(buffer, suggestion);
  485. strcat(buffer, " ");
  486. }
  487. clif_displaymessage(sd->fd, buffer);
  488. }
  489. /*==========================================
  490. * @rura, @warp, @mapmove
  491. *------------------------------------------*/
  492. ACMD_FUNC(mapmove)
  493. {
  494. char map_name[MAP_NAME_LENGTH_EXT];
  495. unsigned short mapindex;
  496. short x = 0, y = 0;
  497. int16 m = -1;
  498. nullpo_retr(-1, sd);
  499. memset(map_name, '\0', sizeof(map_name));
  500. if (!message || !*message ||
  501. (sscanf(message, "%15s %6hd %6hd", map_name, &x, &y) < 3 &&
  502. sscanf(message, "%15[^,],%6hd,%6hd", map_name, &x, &y) < 1)) {
  503. clif_displaymessage(fd, msg_txt(sd,909)); // Please enter a map (usage: @warp/@rura/@mapmove <mapname> <x> <y>).
  504. return -1;
  505. }
  506. mapindex = mapindex_name2idx(map_name, nullptr);
  507. if (mapindex)
  508. m = map_mapindex2mapid(mapindex);
  509. if (m < 0) { // m < 0 means on different server! [Kevin]
  510. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  511. if (battle_config.warp_suggestions_enabled)
  512. warp_get_suggestions(sd, map_name);
  513. return -1;
  514. }
  515. if ((x || y) && map_getcell(m, x, y, CELL_CHKNOPASS))
  516. { //This is to prevent the pc_setpos call from printing an error.
  517. clif_displaymessage(fd, msg_txt(sd,2)); // Invalid coordinates, using random target cell.
  518. if (!map_search_freecell(nullptr, m, &x, &y, 10, 10, 1))
  519. x = y = 0; //Invalid cell, use random spot.
  520. }
  521. if ((map_getmapflag(m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) || !pc_job_can_entermap((enum e_job)sd->status.class_, m, pc_get_group_level(sd))) {
  522. clif_displaymessage(fd, msg_txt(sd,247)); // You are not authorized to warp to this map.
  523. return -1;
  524. }
  525. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  526. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  527. return -1;
  528. }
  529. if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != SETPOS_OK) {
  530. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  531. return -1;
  532. }
  533. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  534. return 0;
  535. }
  536. /*==========================================
  537. * Displays where a character is. Corrected version by Silent. [Skotlex]
  538. *------------------------------------------*/
  539. ACMD_FUNC(where)
  540. {
  541. map_session_data* pl_sd;
  542. nullpo_retr(-1, sd);
  543. memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  544. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  545. clif_displaymessage(fd, msg_txt(sd,910)); // Please enter a player name (usage: @where <char name>).
  546. return -1;
  547. }
  548. pl_sd = map_nick2sd(atcmd_player_name,true);
  549. if (pl_sd == nullptr ||
  550. strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 ||
  551. (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > pc_get_group_level(sd) && !pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  552. ) {
  553. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  554. return -1;
  555. }
  556. snprintf(atcmd_output, sizeof atcmd_output, "%s %s %d %d", pl_sd->status.name, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  557. clif_displaymessage(fd, atcmd_output);
  558. return 0;
  559. }
  560. /*==========================================
  561. *
  562. *------------------------------------------*/
  563. ACMD_FUNC(jumpto)
  564. {
  565. map_session_data* pl_sd = nullptr;;
  566. nullpo_retr(-1, sd);
  567. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  568. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  569. clif_displaymessage(fd, msg_txt(sd,911)); // Please enter a player name (usage: @jumpto/@warpto/@goto <char name/ID>).
  570. return -1;
  571. }
  572. if((pl_sd=map_nick2sd(atcmd_player_name,true)) == nullptr && (pl_sd=map_charid2sd(atoi(atcmd_player_name))) == nullptr)
  573. {
  574. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  575. return -1;
  576. }
  577. if (pl_sd->bl.m >= 0 && map_getmapflag(pl_sd->bl.m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  578. {
  579. clif_displaymessage(fd, msg_txt(sd,247)); // You are not authorized to warp to this map.
  580. return -1;
  581. }
  582. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  583. {
  584. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  585. return -1;
  586. }
  587. if( pc_isdead(sd) )
  588. {
  589. clif_displaymessage(fd, msg_txt(sd,664)); // You cannot use this command when dead.
  590. return -1;
  591. }
  592. pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  593. sprintf(atcmd_output, msg_txt(sd,4), pl_sd->status.name); // Jumped to %s
  594. clif_displaymessage(fd, atcmd_output);
  595. return 0;
  596. }
  597. /*==========================================
  598. *
  599. *------------------------------------------*/
  600. ACMD_FUNC(jump)
  601. {
  602. short x = 0, y = 0;
  603. nullpo_retr(-1, sd);
  604. memset(atcmd_output, '\0', sizeof(atcmd_output));
  605. sscanf(message, "%6hd %6hd", &x, &y);
  606. if (map_getmapflag(sd->bl.m, MF_NOTELEPORT) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  607. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  608. return -1;
  609. }
  610. if( pc_isdead(sd) )
  611. {
  612. clif_displaymessage(fd, msg_txt(sd,664)); // You cannot use this command when dead.
  613. return -1;
  614. }
  615. if ((x || y) && map_getcell(sd->bl.m, x, y, CELL_CHKNOPASS))
  616. { //This is to prevent the pc_setpos call from printing an error.
  617. clif_displaymessage(fd, msg_txt(sd,2)); // Invalid coordinates, using random target cell.
  618. if (!map_search_freecell(nullptr, sd->bl.m, &x, &y, 10, 10, 1))
  619. x = y = 0; //Invalid cell, use random spot.
  620. }
  621. pc_setpos(sd, sd->mapindex, x, y, CLR_TELEPORT);
  622. sprintf(atcmd_output, msg_txt(sd,5), sd->bl.x, sd->bl.y); // Jumped to %d %d
  623. clif_displaymessage(fd, atcmd_output);
  624. return 0;
  625. }
  626. /*==========================================
  627. * Display list of online characters with
  628. * various info.
  629. *------------------------------------------*/
  630. ACMD_FUNC(who) {
  631. map_session_data* pl_sd = nullptr;;
  632. struct s_mapiterator *iter = nullptr;
  633. char player_name[NAME_LENGTH] = "";
  634. int count = 0;
  635. int level = 0;
  636. StringBuf buf;
  637. /**
  638. * 1 = @who : Player name, [Title], [Party name], [Guild name]
  639. * 2 = @who2 : Player name, [Title], BLvl, JLvl, Job
  640. * 3 = @who3 : [CID/AID] Player name [Title], Map, X, Y
  641. */
  642. int display_type = 1;
  643. int map_id = -1;
  644. nullpo_retr(-1, sd);
  645. if (strstr(command, "map") != nullptr) {
  646. char map_name[MAP_NAME_LENGTH_EXT] = "";
  647. if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map_mapname2mapid(map_name)) < 0)
  648. map_id = sd->bl.m;
  649. } else {
  650. sscanf(message, "%23s", player_name);
  651. }
  652. if (strstr(command, "2") != nullptr)
  653. display_type = 2;
  654. else if (strstr(command, "3") != nullptr)
  655. display_type = 3;
  656. level = pc_get_group_level(sd);
  657. StringBuf_Init(&buf);
  658. iter = mapit_getallusers();
  659. for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) {
  660. if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || pc_isinvisible(pl_sd)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level
  661. if (stristr(pl_sd->status.name, player_name) == nullptr // search with no case sensitive
  662. || (map_id >= 0 && pl_sd->bl.m != map_id))
  663. continue;
  664. switch (display_type) {
  665. case 2: {
  666. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  667. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  668. StringBuf_Printf(&buf, msg_txt(sd,344),pl_sd->group->name.c_str()); // "(%s) "
  669. StringBuf_Printf(&buf, msg_txt(sd,347), pl_sd->status.base_level, pl_sd->status.job_level,
  670. job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s"
  671. break;
  672. }
  673. case 3: {
  674. if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  675. StringBuf_Printf(&buf, msg_txt(sd,912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) "
  676. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  677. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  678. StringBuf_Printf(&buf, msg_txt(sd,344), pl_sd->group->name.c_str()); // "(%s) "
  679. StringBuf_Printf(&buf, msg_txt(sd,348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
  680. break;
  681. }
  682. default: {
  683. struct party_data *p = party_search(pl_sd->status.party_id);
  684. auto &g = pl_sd->guild;
  685. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  686. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  687. StringBuf_Printf(&buf, msg_txt(sd,344), pl_sd->group->name.c_str()); // "(%s) "
  688. if (p != nullptr)
  689. StringBuf_Printf(&buf, msg_txt(sd,345), p->party.name); // " | Party: '%s'"
  690. if (g != nullptr)
  691. StringBuf_Printf(&buf, msg_txt(sd,346), g->guild.name); // " | Guild: '%s'"
  692. break;
  693. }
  694. }
  695. clif_displaymessage(fd, StringBuf_Value(&buf));
  696. StringBuf_Clear(&buf);
  697. count++;
  698. }
  699. }
  700. mapit_free(iter);
  701. if (map_id < 0) {
  702. if (count == 0)
  703. StringBuf_Printf(&buf, msg_txt(sd,28)); // No player found.
  704. else if (count == 1)
  705. StringBuf_Printf(&buf, msg_txt(sd,29)); // 1 player found.
  706. else
  707. StringBuf_Printf(&buf, msg_txt(sd,30), count); // %d players found.
  708. } else {
  709. struct map_data *mapdata = map_getmapdata(map_id);
  710. if (count == 0)
  711. StringBuf_Printf(&buf, msg_txt(sd,54), mapdata->name); // No player found in map '%s'.
  712. else if (count == 1)
  713. StringBuf_Printf(&buf, msg_txt(sd,55), mapdata->name); // 1 player found in map '%s'.
  714. else
  715. StringBuf_Printf(&buf, msg_txt(sd,56), count, mapdata->name); // %d players found in map '%s'.
  716. }
  717. clif_displaymessage(fd, StringBuf_Value(&buf));
  718. StringBuf_Destroy(&buf);
  719. return 0;
  720. }
  721. /*==========================================
  722. *
  723. *------------------------------------------*/
  724. ACMD_FUNC(whogm)
  725. {
  726. map_session_data* pl_sd;
  727. struct s_mapiterator* iter;
  728. int j, count;
  729. int level;
  730. char match_text[CHAT_SIZE_MAX];
  731. char player_name[NAME_LENGTH];
  732. struct party_data *p;
  733. nullpo_retr(-1, sd);
  734. memset(atcmd_output, '\0', sizeof(atcmd_output));
  735. memset(match_text, '\0', sizeof(match_text));
  736. memset(player_name, '\0', sizeof(player_name));
  737. if (sscanf(message, "%255[^\n]", match_text) < 1)
  738. strcpy(match_text, "");
  739. for (j = 0; match_text[j]; j++)
  740. match_text[j] = TOLOWER(match_text[j]);
  741. count = 0;
  742. level = pc_get_group_level(sd);
  743. iter = mapit_getallusers();
  744. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  745. {
  746. int pl_level = pc_get_group_level(pl_sd);
  747. if (!pl_level)
  748. continue;
  749. if (match_text[0])
  750. {
  751. memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
  752. for (j = 0; player_name[j]; j++)
  753. player_name[j] = TOLOWER(player_name[j]);
  754. // search with no case sensitive
  755. if (strstr(player_name, match_text) == nullptr)
  756. continue;
  757. }
  758. if (pl_level > level) {
  759. if (pc_isinvisible(pl_sd))
  760. continue;
  761. sprintf(atcmd_output, msg_txt(sd,913), pl_sd->status.name); // Name: %s (GM)
  762. clif_displaymessage(fd, atcmd_output);
  763. count++;
  764. continue;
  765. }
  766. sprintf(atcmd_output, msg_txt(sd,914), // Name: %s (GM:%d) | Location: %s %d %d
  767. pl_sd->status.name, pl_level,
  768. mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  769. clif_displaymessage(fd, atcmd_output);
  770. sprintf(atcmd_output, msg_txt(sd,915), // BLvl: %d | Job: %s (Lvl: %d)
  771. pl_sd->status.base_level,
  772. job_name(pl_sd->status.class_), pl_sd->status.job_level);
  773. clif_displaymessage(fd, atcmd_output);
  774. p = party_search(pl_sd->status.party_id);
  775. auto &g = pl_sd->guild;
  776. sprintf(atcmd_output,msg_txt(sd,916), // Party: '%s' | Guild: '%s'
  777. p?p->party.name:msg_txt(sd,917), g?g->guild.name:msg_txt(sd,917)); // None.
  778. clif_displaymessage(fd, atcmd_output);
  779. count++;
  780. }
  781. mapit_free(iter);
  782. if (count == 0)
  783. clif_displaymessage(fd, msg_txt(sd,150)); // No GM found.
  784. else if (count == 1)
  785. clif_displaymessage(fd, msg_txt(sd,151)); // 1 GM found.
  786. else {
  787. sprintf(atcmd_output, msg_txt(sd,152), count); // %d GMs found.
  788. clif_displaymessage(fd, atcmd_output);
  789. }
  790. return 0;
  791. }
  792. /*==========================================
  793. *
  794. *------------------------------------------*/
  795. ACMD_FUNC(save)
  796. {
  797. nullpo_retr(-1, sd);
  798. if( map_getmapdata(sd->bl.m)->instance_id ) {
  799. clif_displaymessage(fd, msg_txt(sd,383)); // You cannot create a savepoint in an instance.
  800. return 1;
  801. }
  802. pc_setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  803. if (sd->status.pet_id > 0 && sd->pd)
  804. intif_save_petdata(sd->status.account_id, &sd->pd->pet);
  805. chrif_save(sd, CSAVE_NORMAL);
  806. clif_displaymessage(fd, msg_txt(sd,6)); // Your save point has been changed.
  807. return 0;
  808. }
  809. /*==========================================
  810. *
  811. *------------------------------------------*/
  812. ACMD_FUNC(load){
  813. nullpo_retr(-1, sd);
  814. uint16 mapindex = mapindex_name2id( sd->status.save_point.map );
  815. int16 m = map_mapindex2mapid( mapindex );
  816. if (m >= 0 && map_getmapflag(m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  817. clif_displaymessage(fd, msg_txt(sd,249)); // You are not authorized to warp to your save map.
  818. return -1;
  819. }
  820. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  821. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  822. return -1;
  823. }
  824. pc_setpos( sd, mapindex, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT );
  825. clif_displaymessage(fd, msg_txt(sd,7)); // Warping to save point..
  826. return 0;
  827. }
  828. /*==========================================
  829. *
  830. *------------------------------------------*/
  831. ACMD_FUNC(speed)
  832. {
  833. short speed;
  834. nullpo_retr(-1, sd);
  835. memset(atcmd_output, '\0', sizeof(atcmd_output));
  836. if (!message || !*message || sscanf(message, "%6hd", &speed) < 1) {
  837. sprintf(atcmd_output, msg_txt(sd,918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>).
  838. clif_displaymessage(fd, atcmd_output);
  839. return -1;
  840. }
  841. sd->state.permanent_speed = 0; // Remove lock when set back to default speed.
  842. if (speed < 0)
  843. sd->base_status.speed = DEFAULT_WALK_SPEED;
  844. else
  845. sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
  846. if (sd->base_status.speed != DEFAULT_WALK_SPEED) {
  847. sd->state.permanent_speed = 1; // Set lock when set to non-default speed.
  848. clif_displaymessage(fd, msg_txt(sd,8)); // Speed changed.
  849. } else
  850. clif_displaymessage(fd, msg_txt(sd,389)); // Speed returned to normal.
  851. status_calc_bl(&sd->bl, { SCB_SPEED });
  852. return 0;
  853. }
  854. /*==========================================
  855. *
  856. *------------------------------------------*/
  857. ACMD_FUNC(storage)
  858. {
  859. nullpo_retr(-1, sd);
  860. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
  861. return -1;
  862. if (storage_storageopen(sd) == 1)
  863. { //Already open.
  864. clif_displaymessage(fd, msg_txt(sd,250)); // You have already opened your storage. Close it first.
  865. return -1;
  866. }
  867. clif_displaymessage(fd, msg_txt(sd,919)); // Storage opened.
  868. return 0;
  869. }
  870. /*==========================================
  871. *
  872. *------------------------------------------*/
  873. ACMD_FUNC(guildstorage)
  874. {
  875. nullpo_retr(-1, sd);
  876. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  877. return -1;
  878. switch (storage_guild_storageopen(sd)) {
  879. case GSTORAGE_OPEN:
  880. clif_displaymessage(fd, msg_txt(sd, 920)); // Guild storage opened.
  881. break;
  882. case GSTORAGE_STORAGE_ALREADY_OPEN:
  883. clif_displaymessage(fd, msg_txt(sd, 250)); // You have already opened your storage. Close it first.
  884. return -1;
  885. case GSTORAGE_ALREADY_OPEN:
  886. clif_displaymessage(fd, msg_txt(sd, 251)); // You have already opened your guild storage. Close it first.
  887. return -1;
  888. case GSTORAGE_NO_GUILD:
  889. clif_displaymessage(fd, msg_txt(sd, 252)); // You are not in a guild.
  890. return -1;
  891. case GSTORAGE_NO_STORAGE:
  892. clif_displaymessage(fd, msg_txt(sd, 786)); // The guild does not have a guild storage.
  893. return -1;
  894. case GSTORAGE_NO_PERMISSION:
  895. clif_displaymessage(fd, msg_txt(sd, 787)); // You do not have permission to use the guild storage.
  896. return -1;
  897. }
  898. return 0;
  899. }
  900. /*==========================================
  901. *
  902. *------------------------------------------*/
  903. ACMD_FUNC(option)
  904. {
  905. int param1 = 0, param2 = 0, param3 = 0;
  906. nullpo_retr(-1, sd);
  907. if (!message || !*message || sscanf(message, "%11d %11d %11d", &param1, &param2, &param3) < 1 || param1 < 0 || param2 < 0 || param3 < 0)
  908. {// failed to match the parameters so inform the user of the options
  909. const char* text;
  910. // attempt to find the setting information for this command
  911. text = atcommand_help_string( command );
  912. // notify the user of the requirement to enter an option
  913. clif_displaymessage(fd, msg_txt(sd,921)); // Please enter at least one option.
  914. if( text )
  915. {// send the help text associated with this command
  916. clif_displaymessage( fd, text );
  917. }
  918. return -1;
  919. }
  920. sd->sc.opt1 = param1;
  921. sd->sc.opt2 = param2;
  922. pc_setoption(sd, param3);
  923. clif_displaymessage(fd, msg_txt(sd,9)); // Options changed.
  924. return 0;
  925. }
  926. /*==========================================
  927. *
  928. *------------------------------------------*/
  929. ACMD_FUNC(hide)
  930. {
  931. nullpo_retr(-1, sd);
  932. if (pc_isinvisible(sd)) {
  933. sd->sc.option &= ~OPTION_INVISIBLE;
  934. if (sd->disguise)
  935. status_set_viewdata(&sd->bl, sd->disguise);
  936. else
  937. status_set_viewdata(&sd->bl, sd->status.class_);
  938. clif_displaymessage(fd, msg_txt(sd,10)); // Invisible: Off
  939. // increment the number of pvp players on the map
  940. map_getmapdata(sd->bl.m)->users_pvp++;
  941. if( !battle_config.pk_mode && map_getmapflag(sd->bl.m, MF_PVP) && !map_getmapflag(sd->bl.m, MF_PVP_NOCALCRANK) )
  942. {// register the player for ranking calculations
  943. sd->pvp_timer = add_timer( gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0 );
  944. }
  945. //bugreport:2266
  946. map_foreachinmovearea(clif_insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  947. } else {
  948. sd->sc.option |= OPTION_INVISIBLE;
  949. sd->vd.class_ = JT_INVISIBLE;
  950. clif_displaymessage(fd, msg_txt(sd,11)); // Invisible: On
  951. // decrement the number of pvp players on the map
  952. map_getmapdata(sd->bl.m)->users_pvp--;
  953. if( map_getmapflag(sd->bl.m, MF_PVP) && !map_getmapflag(sd->bl.m, MF_PVP_NOCALCRANK) && sd->pvp_timer != INVALID_TIMER )
  954. {// unregister the player for ranking
  955. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  956. sd->pvp_timer = INVALID_TIMER;
  957. }
  958. }
  959. clif_changeoption(&sd->bl);
  960. return 0;
  961. }
  962. /*==========================================
  963. * Changes a character's class
  964. *------------------------------------------*/
  965. ACMD_FUNC(jobchange)
  966. {
  967. int job = 0, upper = 0;
  968. const char* text;
  969. nullpo_retr(-1, sd);
  970. if (!message || !*message || sscanf(message, "%11d %11d", &job, &upper) < 1) {
  971. int i;
  972. bool found = false;
  973. upper = 0;
  974. // Normal Jobs
  975. for( i = JOB_NOVICE; i < JOB_MAX_BASIC && !found; i++ ) {
  976. if (strncmpi(message, job_name(i), 16) == 0) {
  977. job = i;
  978. found = true;
  979. }
  980. }
  981. // High Jobs, Babys, Third, and Fourth
  982. for( i = JOB_NOVICE_HIGH; i < JOB_MAX && !found; i++ ) {
  983. if (strncmpi(message, job_name(i), 16) == 0) {
  984. job = i;
  985. found = true;
  986. }
  987. }
  988. if (!found) {
  989. text = atcommand_help_string(command);
  990. if (text)
  991. clif_displaymessage(fd, text);
  992. return -1;
  993. }
  994. }
  995. if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2 || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER || job == JOB_HANBOK || job == JOB_OKTOBERFEST
  996. || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2 || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2 || job == JOB_STAR_GLADIATOR2
  997. || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE_KNIGHT2 && job <= JOB_BABY_MECHANIC2) || job == JOB_BABY_STAR_GLADIATOR2
  998. || job == JOB_STAR_EMPEROR2 || job == JOB_BABY_STAR_EMPEROR2 || job == JOB_SUMMER2
  999. || (job >= JOB_WINDHAWK2 && job <= JOB_IMPERIAL_GUARD2) || job == JOB_SKY_EMPEROR2)
  1000. { // Deny direct transformation into dummy jobs
  1001. clif_displaymessage(fd, msg_txt(sd,923)); //"You can not change to this job by command."
  1002. return 0;
  1003. }
  1004. if (pcdb_checkid(job))
  1005. {
  1006. if (pc_jobchange(sd, job, upper))
  1007. clif_displaymessage(fd, msg_txt(sd,12)); // Your job has been changed.
  1008. else {
  1009. clif_displaymessage(fd, msg_txt(sd,155)); // You are unable to change your job.
  1010. return -1;
  1011. }
  1012. } else {
  1013. text = atcommand_help_string(command);
  1014. if (text)
  1015. clif_displaymessage(fd, text);
  1016. return -1;
  1017. }
  1018. return 0;
  1019. }
  1020. /*==========================================
  1021. *
  1022. *------------------------------------------*/
  1023. ACMD_FUNC(kill)
  1024. {
  1025. nullpo_retr(-1, sd);
  1026. status_kill(&sd->bl);
  1027. clif_displaymessage(sd->fd, msg_txt(sd,13)); // A pity! You've died.
  1028. if (fd != sd->fd)
  1029. clif_displaymessage(fd, msg_txt(sd,14)); // Character killed.
  1030. return 0;
  1031. }
  1032. /*==========================================
  1033. *
  1034. *------------------------------------------*/
  1035. ACMD_FUNC(alive)
  1036. {
  1037. nullpo_retr(-1, sd);
  1038. if (!status_revive(&sd->bl, 100, 100))
  1039. {
  1040. clif_displaymessage(fd, msg_txt(sd,667)); // You're not dead.
  1041. return -1;
  1042. }
  1043. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  1044. clif_displaymessage(fd, msg_txt(sd,16)); // You've been revived! It's a miracle!
  1045. return 0;
  1046. }
  1047. /*==========================================
  1048. * +kamic [LuzZza]
  1049. *------------------------------------------*/
  1050. ACMD_FUNC(kami)
  1051. {
  1052. unsigned long color=0;
  1053. nullpo_retr(-1, sd);
  1054. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1055. if(*(command + 5) != 'c' && *(command + 5) != 'C') {
  1056. if (!message || !*message) {
  1057. clif_displaymessage(fd, msg_txt(sd,980)); // Please enter a message (usage: @kami <message>).
  1058. return -1;
  1059. }
  1060. sscanf(message, "%255[^\n]", atcmd_output);
  1061. if (strstr(command, "l") != nullptr)
  1062. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP);
  1063. else
  1064. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(command + 5) == 'b' || *(command + 5) == 'B') ? BC_BLUE : BC_DEFAULT);
  1065. } else {
  1066. if(!message || !*message || (sscanf(message, "%20lx %199[^\n]", &color, atcmd_output) < 2)) {
  1067. clif_displaymessage(fd, msg_txt(sd,981)); // Please enter color and message (usage: @kamic <color> <message>).
  1068. return -1;
  1069. }
  1070. if(color > 0xFFFFFF) {
  1071. clif_displaymessage(fd, msg_txt(sd,982)); // Invalid color.
  1072. return -1;
  1073. }
  1074. intif_broadcast2(atcmd_output, strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0);
  1075. }
  1076. return 0;
  1077. }
  1078. /*==========================================
  1079. *
  1080. *------------------------------------------*/
  1081. ACMD_FUNC(heal)
  1082. {
  1083. int hp = 0, sp = 0; // [Valaris] thanks to fov
  1084. nullpo_retr(-1, sd);
  1085. sscanf(message, "%11d %11d", &hp, &sp);
  1086. // some overflow checks
  1087. if( hp == INT_MIN ) hp++;
  1088. if( sp == INT_MIN ) sp++;
  1089. if ( hp == 0 && sp == 0 ) {
  1090. if (!status_percent_heal(&sd->bl, 100, 100))
  1091. clif_displaymessage(fd, msg_txt(sd,157)); // HP and SP have already been recovered.
  1092. else
  1093. clif_displaymessage(fd, msg_txt(sd,17)); // HP, SP recovered.
  1094. return 0;
  1095. }
  1096. if ( hp > 0 && sp >= 0 ) {
  1097. if(!status_heal(&sd->bl, hp, sp, 0))
  1098. clif_displaymessage(fd, msg_txt(sd,157)); // HP and SP are already with the good value.
  1099. else
  1100. clif_displaymessage(fd, msg_txt(sd,17)); // HP, SP recovered.
  1101. return 0;
  1102. }
  1103. if ( hp < 0 && sp <= 0 ) {
  1104. status_damage(nullptr, &sd->bl, -hp, -sp, 0, 0, 0);
  1105. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, DMG_ENDURE, 0, false);
  1106. clif_displaymessage(fd, msg_txt(sd,156)); // HP or/and SP modified.
  1107. return 0;
  1108. }
  1109. //Opposing signs.
  1110. if ( hp ) {
  1111. if (hp > 0)
  1112. status_heal(&sd->bl, hp, 0, 0);
  1113. else {
  1114. status_damage(nullptr, &sd->bl, -hp, 0, 0, 0, 0);
  1115. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, DMG_ENDURE, 0, false);
  1116. }
  1117. }
  1118. if ( sp ) {
  1119. if (sp > 0)
  1120. status_heal(&sd->bl, 0, sp, 0);
  1121. else
  1122. status_damage(nullptr, &sd->bl, 0, -sp, 0, 0, 0);
  1123. }
  1124. clif_displaymessage(fd, msg_txt(sd,156)); // HP or/and SP modified.
  1125. return 0;
  1126. }
  1127. /*==========================================
  1128. * Recover's AP and allows exact adjustments. [Rytech]
  1129. *------------------------------------------*/
  1130. ACMD_FUNC(healap)
  1131. {
  1132. int ap = 0;
  1133. nullpo_retr(-1, sd);
  1134. sscanf(message, "%11d", &ap);
  1135. // Overflow check.
  1136. if (ap == INT_MIN) ap++;
  1137. if (ap == 0) {
  1138. if (!status_percent_heal(&sd->bl, 0, 0, 100))
  1139. clif_displaymessage(fd, msg_txt(sd, 823));// AP have already been recovered.
  1140. else
  1141. clif_displaymessage(fd, msg_txt(sd, 821));// AP recovered.
  1142. return 0;
  1143. }else if (ap > 0) {
  1144. if (!status_heal(&sd->bl, 0, 0, ap, 0))
  1145. clif_displaymessage(fd, msg_txt(sd, 823));// AP have already been recovered.
  1146. else
  1147. clif_displaymessage(fd, msg_txt(sd, 821));// AP recovered.
  1148. return 0;
  1149. }else{
  1150. status_damage(nullptr, &sd->bl, 0, 0, -ap, 0, 0, 0);
  1151. clif_displaymessage(fd, msg_txt(sd, 822));// AP modified.
  1152. return 0;
  1153. }
  1154. }
  1155. /*==========================================
  1156. * @item command (usage: @item <itemdid1:itemid2:itemname:..> <quantity>) (modified by [Yor] for pet_egg)
  1157. * @itembound command (usage: @itembound <name/id_of_item> <quantity> <bound_type>)
  1158. *------------------------------------------*/
  1159. ACMD_FUNC(item)
  1160. {
  1161. char item_name[100];
  1162. int number = 0, bound = BOUND_NONE;
  1163. char flag = 0;
  1164. char *itemlist;
  1165. nullpo_retr(-1, sd);
  1166. memset(item_name, '\0', sizeof(item_name));
  1167. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  1168. if (!strcmpi(parent_cmd,"itembound")) {
  1169. if (!message || !*message || (
  1170. sscanf(message, "\"%99[^\"]\" %11d %11d", item_name, &number, &bound) < 3 &&
  1171. sscanf(message, "%99s %11d %11d", item_name, &number, &bound) < 3))
  1172. {
  1173. clif_displaymessage(fd, msg_txt(sd,295)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity> <bound_type>).
  1174. clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
  1175. return -1;
  1176. }
  1177. if( bound <= BOUND_NONE || bound >= BOUND_MAX ) {
  1178. clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
  1179. return -1;
  1180. }
  1181. } else if (!message || !*message || (
  1182. sscanf(message, "\"%99[^\"]\" %11d", item_name, &number) < 1 &&
  1183. sscanf(message, "%99s %11d", item_name, &number) < 1
  1184. )) {
  1185. clif_displaymessage(fd, msg_txt(sd,983)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity>).
  1186. return -1;
  1187. }
  1188. std::vector<std::shared_ptr<item_data>> items;
  1189. itemlist = strtok(item_name, ":");
  1190. while( itemlist != nullptr ){
  1191. std::shared_ptr<item_data> item = item_db.searchname( itemlist );
  1192. if( item == nullptr ){
  1193. item = item_db.find( strtoul( itemlist, nullptr, 10 ) );
  1194. }
  1195. if( item == nullptr ){
  1196. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  1197. return -1;
  1198. }
  1199. items.push_back( item );
  1200. itemlist = strtok(nullptr, ":"); //next itemline
  1201. }
  1202. if (number <= 0)
  1203. number = 1;
  1204. int get_count = number;
  1205. // Produce items in list
  1206. for( const auto& item : items ){
  1207. t_itemid item_id = item->nameid;
  1208. //Check if it's stackable.
  1209. if( !itemdb_isstackable2( item.get() ) ){
  1210. get_count = 1;
  1211. }
  1212. for( int i = 0; i < number; i += get_count ){
  1213. // if not pet egg
  1214. if (!pet_create_egg(sd, item_id)) {
  1215. struct item item_tmp = {};
  1216. item_tmp.nameid = item_id;
  1217. item_tmp.identify = 1;
  1218. item_tmp.bound = bound;
  1219. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1220. clif_additem(sd, 0, 0, flag);
  1221. }
  1222. }
  1223. }
  1224. if (flag == 0)
  1225. clif_displaymessage(fd, msg_txt(sd,18)); // Item created.
  1226. return 0;
  1227. }
  1228. /*==========================================
  1229. *
  1230. *------------------------------------------*/
  1231. ACMD_FUNC(item2)
  1232. {
  1233. char item_name[100];
  1234. int number = 0, bound = BOUND_NONE;
  1235. int identify = 0, refine = 0, attr = 0;
  1236. int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  1237. nullpo_retr(-1, sd);
  1238. memset(item_name, '\0', sizeof(item_name));
  1239. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  1240. if (!strcmpi(parent_cmd+1,"itembound2")) {
  1241. if (!message || !*message || (
  1242. sscanf(message, "\"%99[^\"]\" %11d %11d %11d %11d %11d %11d %11d %11d %11d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 &&
  1243. sscanf(message, "%99s %11d %11d %11d %11d %11d %11d %11d %11d %11d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))
  1244. {
  1245. clif_displaymessage(fd, msg_txt(sd,296)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity>
  1246. clif_displaymessage(fd, msg_txt(sd,297)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4> <bound_type>).
  1247. clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
  1248. return -1;
  1249. }
  1250. if( bound <= BOUND_NONE || bound >= BOUND_MAX ) {
  1251. clif_displaymessage(fd, msg_txt(sd,298)); // Invalid bound type
  1252. return -1;
  1253. }
  1254. } else if ( !message || !*message || (
  1255. sscanf(message, "\"%99[^\"]\" %11d %11d %11d %11d %11d %11d %11d %11d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
  1256. sscanf(message, "%99s %11d %11d %11d %11d %11d %11d %11d %11d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
  1257. )) {
  1258. clif_displaymessage(fd, msg_txt(sd,984)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity>
  1259. clif_displaymessage(fd, msg_txt(sd,985)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4>).
  1260. return -1;
  1261. }
  1262. if (number <= 0)
  1263. number = 1;
  1264. std::shared_ptr<item_data> item_data = item_db.searchname( item_name );
  1265. if( item_data == nullptr ){
  1266. item_data = item_db.find( strtoul( item_name, nullptr, 10 ) );
  1267. }
  1268. if( item_data != nullptr ){
  1269. int loop, get_count, i;
  1270. char flag = 0;
  1271. //Check if it's stackable.
  1272. if( !itemdb_isstackable2( item_data.get() ) ){
  1273. loop = number;
  1274. get_count = 1;
  1275. }else{
  1276. loop = 1;
  1277. get_count = number;
  1278. }
  1279. if( itemdb_isequip2( item_data.get() ) ){
  1280. refine = cap_value( refine, 0, MAX_REFINE );
  1281. }else{
  1282. // All other items cannot be refined and are always identified
  1283. identify = 1;
  1284. refine = attr = 0;
  1285. }
  1286. for (i = 0; i < loop; i++) {
  1287. // if not pet egg
  1288. if (!pet_create_egg(sd, item_data->nameid)) {
  1289. struct item item_tmp = {};
  1290. item_tmp.nameid = item_data->nameid;
  1291. item_tmp.identify = identify;
  1292. item_tmp.refine = refine;
  1293. item_tmp.attribute = attr;
  1294. item_tmp.card[0] = c1;
  1295. item_tmp.card[1] = c2;
  1296. item_tmp.card[2] = c3;
  1297. item_tmp.card[3] = c4;
  1298. item_tmp.bound = bound;
  1299. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1300. clif_additem(sd, 0, 0, flag);
  1301. }
  1302. }
  1303. if (flag == 0)
  1304. clif_displaymessage(fd, msg_txt(sd,18)); // Item created.
  1305. } else {
  1306. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  1307. return -1;
  1308. }
  1309. return 0;
  1310. }
  1311. /*==========================================
  1312. *
  1313. *------------------------------------------*/
  1314. ACMD_FUNC(itemreset)
  1315. {
  1316. int i;
  1317. nullpo_retr(-1, sd);
  1318. for (i = 0; i < MAX_INVENTORY; i++) {
  1319. if (sd->inventory.u.items_inventory[i].amount && sd->inventory.u.items_inventory[i].equip == 0 && !itemdb_ishatched_egg(&sd->inventory.u.items_inventory[i])) {
  1320. pc_delitem(sd, i, sd->inventory.u.items_inventory[i].amount, 0, 0, LOG_TYPE_COMMAND);
  1321. }
  1322. }
  1323. clif_displaymessage(fd, msg_txt(sd,20)); // All of your items have been removed.
  1324. return 0;
  1325. }
  1326. /*==========================================
  1327. * Atcommand @lvlup
  1328. *------------------------------------------*/
  1329. ACMD_FUNC(baselevelup)
  1330. {
  1331. int level=0, i=0, status_point=0, trait_point=0;
  1332. nullpo_retr(-1, sd);
  1333. level = atoi(message);
  1334. if (!message || !*message || !level) {
  1335. clif_displaymessage(fd, msg_txt(sd,986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).
  1336. return -1;
  1337. }
  1338. if (level > 0) {
  1339. if (sd->status.base_level >= pc_maxbaselv(sd)) { // check for max level by Valaris
  1340. clif_displaymessage(fd, msg_txt(sd,47)); // Base level can't go any higher.
  1341. return -1;
  1342. } // End Addition
  1343. if ((unsigned int)level > pc_maxbaselv(sd) || (unsigned int)level > pc_maxbaselv(sd) - sd->status.base_level) // fix positive overflow
  1344. level = pc_maxbaselv(sd) - sd->status.base_level;
  1345. for (i = 0; i < level; i++)
  1346. {
  1347. status_point += statpoint_db.pc_gets_status_point(sd->status.base_level + i);
  1348. trait_point += statpoint_db.pc_gets_trait_point(sd->status.base_level + i);
  1349. }
  1350. sd->status.status_point += status_point;
  1351. sd->status.trait_point += trait_point;
  1352. sd->status.base_level += (unsigned int)level;
  1353. status_calc_pc(sd, SCO_FORCE);
  1354. status_percent_heal(&sd->bl, 100, 100);
  1355. clif_misceffect(&sd->bl, 0);
  1356. for (uint32 j = sd->status.base_level - level; j <= sd->status.base_level; j++) {
  1357. achievement_update_objective(sd, AG_GOAL_LEVEL, 1, j);
  1358. achievement_update_objective(sd, AG_GOAL_STATUS, 2, j, sd->status.class_);
  1359. }
  1360. clif_displaymessage(fd, msg_txt(sd,21)); // Base level raised.
  1361. } else {
  1362. if (sd->status.base_level == 1) {
  1363. clif_displaymessage(fd, msg_txt(sd,158)); // Base level can't go any lower.
  1364. return -1;
  1365. }
  1366. level*=-1;
  1367. if ((unsigned int)level >= sd->status.base_level)
  1368. level = sd->status.base_level-1;
  1369. for (i = 0; i > -level; i--)
  1370. {
  1371. status_point += statpoint_db.pc_gets_status_point(sd->status.base_level + i - 1);
  1372. trait_point += statpoint_db.pc_gets_trait_point(sd->status.base_level + i - 1);
  1373. }
  1374. if (sd->status.status_point < status_point || sd->status.trait_point < trait_point)
  1375. pc_resetstate(sd);
  1376. if (sd->status.status_point < status_point)
  1377. sd->status.status_point = 0;
  1378. else
  1379. sd->status.status_point -= status_point;
  1380. if (sd->status.trait_point < trait_point)
  1381. sd->status.trait_point = 0;
  1382. else
  1383. sd->status.trait_point -= trait_point;
  1384. sd->status.base_level -= (unsigned int)level;
  1385. clif_displaymessage(fd, msg_txt(sd,22)); // Base level lowered.
  1386. status_calc_pc(sd, SCO_FORCE);
  1387. level*=-1;
  1388. }
  1389. sd->status.base_exp = 0;
  1390. clif_updatestatus(*sd, SP_STATUSPOINT);
  1391. clif_updatestatus(*sd, SP_TRAITPOINT);
  1392. clif_updatestatus(*sd, SP_BASELEVEL);
  1393. clif_updatestatus(*sd, SP_BASEEXP);
  1394. clif_updatestatus(*sd, SP_NEXTBASEEXP);
  1395. pc_baselevelchanged(sd);
  1396. if(sd->status.party_id)
  1397. party_send_levelup(sd);
  1398. if( level > 0 && battle_config.atcommand_levelup_events )
  1399. npc_script_event(sd,NPCE_BASELVUP);
  1400. return 0;
  1401. }
  1402. /*==========================================
  1403. *
  1404. *------------------------------------------*/
  1405. ACMD_FUNC(joblevelup)
  1406. {
  1407. int level=0;
  1408. nullpo_retr(-1, sd);
  1409. level = atoi(message);
  1410. if (!message || !*message || !level) {
  1411. clif_displaymessage(fd, msg_txt(sd,987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).
  1412. return -1;
  1413. }
  1414. if (level > 0) {
  1415. if (sd->status.job_level >= pc_maxjoblv(sd)) {
  1416. clif_displaymessage(fd, msg_txt(sd,23)); // Job level can't go any higher.
  1417. return -1;
  1418. }
  1419. if ((unsigned int)level > pc_maxjoblv(sd) || (unsigned int)level > pc_maxjoblv(sd) - sd->status.job_level) // fix positive overflow
  1420. level = pc_maxjoblv(sd) - sd->status.job_level;
  1421. sd->status.job_level += (unsigned int)level;
  1422. sd->status.skill_point += level;
  1423. clif_misceffect(&sd->bl, 1);
  1424. for (uint32 i = sd->status.job_level - level; i <= sd->status.job_level; i++)
  1425. achievement_update_objective(sd, AG_GOAL_LEVEL, 1, i);
  1426. clif_displaymessage(fd, msg_txt(sd,24)); // Job level raised.
  1427. } else {
  1428. if (sd->status.job_level == 1) {
  1429. clif_displaymessage(fd, msg_txt(sd,159)); // Job level can't go any lower.
  1430. return -1;
  1431. }
  1432. level *=-1;
  1433. if ((unsigned int)level >= sd->status.job_level) // fix negative overflow
  1434. level = sd->status.job_level-1;
  1435. sd->status.job_level -= (unsigned int)level;
  1436. if (sd->status.skill_point < level)
  1437. pc_resetskill(sd,0); //Reset skills since we need to subtract more points.
  1438. if (sd->status.skill_point < level)
  1439. sd->status.skill_point = 0;
  1440. else
  1441. sd->status.skill_point -= level;
  1442. clif_displaymessage(fd, msg_txt(sd,25)); // Job level lowered.
  1443. level *=-1;
  1444. }
  1445. sd->status.job_exp = 0;
  1446. clif_updatestatus(*sd, SP_JOBLEVEL);
  1447. clif_updatestatus(*sd, SP_JOBEXP);
  1448. clif_updatestatus(*sd, SP_NEXTJOBEXP);
  1449. clif_updatestatus(*sd, SP_SKILLPOINT);
  1450. status_calc_pc(sd, SCO_FORCE);
  1451. if( level > 0 && battle_config.atcommand_levelup_events )
  1452. npc_script_event(sd,NPCE_JOBLVUP);
  1453. return 0;
  1454. }
  1455. /*==========================================
  1456. * @help
  1457. *------------------------------------------*/
  1458. ACMD_FUNC(help){
  1459. const char *command_name = nullptr;
  1460. nullpo_retr(-1, sd);
  1461. if (!message || !*message) {
  1462. command_name = "help"; // If no command_name specified, display help for @help.
  1463. } else {
  1464. if (*message == atcommand_symbol || *message == charcommand_symbol)
  1465. ++message;
  1466. command_name = atcommand_alias_db.checkAlias(message);
  1467. }
  1468. if (!pc_can_use_command(sd, command_name, COMMAND_ATCOMMAND)) {
  1469. sprintf(atcmd_output, msg_txt(sd,153), message); // "%s is Unknown Command"
  1470. clif_displaymessage(fd, atcmd_output);
  1471. atcommand_get_suggestions(sd, command_name, true);
  1472. return -1;
  1473. }
  1474. // attempt to find the first default help command
  1475. std::shared_ptr<s_atcommand_alias_info> info = atcommand_alias_db.find( command_name );
  1476. const char* text = info != nullptr ? info->help.c_str() : nullptr;
  1477. if( text == nullptr ){
  1478. sprintf(atcmd_output, msg_txt(sd,988), atcommand_symbol, command_name); // There is no help for %c%s.
  1479. clif_displaymessage(fd, atcmd_output);
  1480. atcommand_get_suggestions(sd, command_name, true);
  1481. return -1;
  1482. }
  1483. sprintf(atcmd_output, msg_txt(sd,989), atcommand_symbol, command_name); // Help for command %c%s:
  1484. clif_displaymessage(fd, atcmd_output);
  1485. { // Display aliases
  1486. StringBuf buf;
  1487. bool has_aliases = false;
  1488. StringBuf_Init(&buf);
  1489. StringBuf_AppendStr(&buf, msg_txt(sd,990)); // Available aliases:
  1490. for( const std::string& alias : info->aliases ){
  1491. StringBuf_Printf( &buf, " %s", alias.c_str() );
  1492. has_aliases = true;
  1493. }
  1494. if (has_aliases)
  1495. clif_displaymessage(fd, StringBuf_Value(&buf));
  1496. StringBuf_Destroy(&buf);
  1497. }
  1498. // Display help contents
  1499. clif_displaymessage(fd, text);
  1500. return 0;
  1501. }
  1502. /*==========================================
  1503. *
  1504. *------------------------------------------*/
  1505. ACMD_FUNC(pvpoff)
  1506. {
  1507. nullpo_retr(-1, sd);
  1508. if (!map_getmapflag(sd->bl.m, MF_PVP)) {
  1509. clif_displaymessage(fd, msg_txt(sd,160)); // PvP is already Off.
  1510. return -1;
  1511. }
  1512. map_setmapflag(sd->bl.m, MF_PVP, false);
  1513. clif_displaymessage(fd, msg_txt(sd,31)); // PvP: Off.
  1514. return 0;
  1515. }
  1516. /*==========================================
  1517. *
  1518. *------------------------------------------*/
  1519. ACMD_FUNC(pvpon)
  1520. {
  1521. nullpo_retr(-1, sd);
  1522. if (map_getmapflag(sd->bl.m, MF_PVP)) {
  1523. clif_displaymessage(fd, msg_txt(sd,161)); // PvP is already On.
  1524. return -1;
  1525. }
  1526. map_setmapflag(sd->bl.m, MF_PVP, true);
  1527. clif_displaymessage(fd, msg_txt(sd,32)); // PvP: On.
  1528. return 0;
  1529. }
  1530. /*==========================================
  1531. *
  1532. *------------------------------------------*/
  1533. ACMD_FUNC(gvgoff)
  1534. {
  1535. nullpo_retr(-1, sd);
  1536. if (!map_getmapflag(sd->bl.m, MF_GVG)) {
  1537. clif_displaymessage(fd, msg_txt(sd,162)); // GvG is already Off.
  1538. return -1;
  1539. }
  1540. map_setmapflag(sd->bl.m, MF_GVG, false);
  1541. clif_displaymessage(fd, msg_txt(sd,33)); // GvG: Off.
  1542. return 0;
  1543. }
  1544. /*==========================================
  1545. *
  1546. *------------------------------------------*/
  1547. ACMD_FUNC(gvgon)
  1548. {
  1549. nullpo_retr(-1, sd);
  1550. if (map_getmapflag(sd->bl.m, MF_GVG)) {
  1551. clif_displaymessage(fd, msg_txt(sd,163)); // GvG is already On.
  1552. return -1;
  1553. }
  1554. map_setmapflag(sd->bl.m, MF_GVG, true);
  1555. clif_displaymessage(fd, msg_txt(sd,34)); // GvG: On.
  1556. return 0;
  1557. }
  1558. /*==========================================
  1559. *
  1560. *------------------------------------------*/
  1561. ACMD_FUNC(model)
  1562. {
  1563. int hair_style = 0, hair_color = 0, cloth_color = 0;
  1564. nullpo_retr(-1, sd);
  1565. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1566. if (!message || !*message || sscanf(message, "%11d %11d %11d", &hair_style, &hair_color, &cloth_color) < 1) {
  1567. sprintf(atcmd_output, msg_txt(sd,991), // Please enter at least one value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).
  1568. MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1569. clif_displaymessage(fd, atcmd_output);
  1570. return -1;
  1571. }
  1572. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
  1573. hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
  1574. cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1575. pc_changelook(sd, LOOK_HAIR, hair_style);
  1576. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1577. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1578. clif_displaymessage(fd, msg_txt(sd,36)); // Appearance changed.
  1579. } else {
  1580. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1581. return -1;
  1582. }
  1583. return 0;
  1584. }
  1585. /*==========================================
  1586. * @bodystyle [Rytech]
  1587. *------------------------------------------*/
  1588. ACMD_FUNC(bodystyle)
  1589. {
  1590. int body_style = 0;
  1591. nullpo_retr(-1, sd);
  1592. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1593. if ( (sd->class_ & JOBL_FOURTH) || !(sd->class_ & JOBL_THIRD) || (sd->class_ & MAPID_THIRDMASK) == MAPID_SUPER_NOVICE_E || (sd->class_ & MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || (sd->class_ & MAPID_THIRDMASK) == MAPID_SOUL_REAPER) {
  1594. clif_displaymessage(fd, msg_txt(sd,740)); // This job has no alternate body styles.
  1595. return -1;
  1596. }
  1597. if (!message || !*message || sscanf(message, "%d", &body_style) < 1) {
  1598. sprintf(atcmd_output, msg_txt(sd,739), MIN_BODY_STYLE, MAX_BODY_STYLE); // Please enter a body style (usage: @bodystyle <body ID: %d-%d>).
  1599. clif_displaymessage(fd, atcmd_output);
  1600. return -1;
  1601. }
  1602. if (body_style >= MIN_BODY_STYLE && body_style <= MAX_BODY_STYLE) {
  1603. pc_changelook(sd, LOOK_BODY2, body_style);
  1604. clif_displaymessage(fd, msg_txt(sd,36)); // Appearence changed.
  1605. } else {
  1606. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1607. return -1;
  1608. }
  1609. return 0;
  1610. }
  1611. /*==========================================
  1612. * @dye && @ccolor
  1613. *------------------------------------------*/
  1614. ACMD_FUNC(dye)
  1615. {
  1616. int cloth_color = 0;
  1617. nullpo_retr(-1, sd);
  1618. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1619. if (!message || !*message || sscanf(message, "%11d", &cloth_color) < 1) {
  1620. sprintf(atcmd_output, msg_txt(sd,992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).
  1621. clif_displaymessage(fd, atcmd_output);
  1622. return -1;
  1623. }
  1624. if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1625. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1626. clif_displaymessage(fd, msg_txt(sd,36)); // Appearance changed.
  1627. } else {
  1628. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1629. return -1;
  1630. }
  1631. return 0;
  1632. }
  1633. /*==========================================
  1634. * @hairstyle && @hstyle
  1635. *------------------------------------------*/
  1636. ACMD_FUNC(hair_style)
  1637. {
  1638. int hair_style = 0;
  1639. nullpo_retr(-1, sd);
  1640. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1641. if (!message || !*message || sscanf(message, "%11d", &hair_style) < 1) {
  1642. sprintf(atcmd_output, msg_txt(sd,993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).
  1643. clif_displaymessage(fd, atcmd_output);
  1644. return -1;
  1645. }
  1646. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) {
  1647. pc_changelook(sd, LOOK_HAIR, hair_style);
  1648. clif_displaymessage(fd, msg_txt(sd,36)); // Appearance changed.
  1649. } else {
  1650. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1651. return -1;
  1652. }
  1653. return 0;
  1654. }
  1655. /*==========================================
  1656. * @haircolor && @hcolor
  1657. *------------------------------------------*/
  1658. ACMD_FUNC(hair_color)
  1659. {
  1660. int hair_color = 0;
  1661. nullpo_retr(-1, sd);
  1662. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1663. if (!message || !*message || sscanf(message, "%11d", &hair_color) < 1) {
  1664. sprintf(atcmd_output, msg_txt(sd,994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).
  1665. clif_displaymessage(fd, atcmd_output);
  1666. return -1;
  1667. }
  1668. if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) {
  1669. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1670. clif_displaymessage(fd, msg_txt(sd,36)); // Appearance changed.
  1671. } else {
  1672. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1673. return -1;
  1674. }
  1675. return 0;
  1676. }
  1677. /*==========================================
  1678. * @go [city_number or city_name] - Updated by Harbin
  1679. *------------------------------------------*/
  1680. ACMD_FUNC(go)
  1681. {
  1682. int i;
  1683. int town;
  1684. char map_name[MAP_NAME_LENGTH];
  1685. const struct {
  1686. char map[MAP_NAME_LENGTH];
  1687. int x, y;
  1688. } data[] = {
  1689. { MAP_PRONTERA, 156, 191 }, // 0=Prontera
  1690. { MAP_MORROC, 156, 93 }, // 1=Morroc
  1691. { MAP_GEFFEN, 119, 59 }, // 2=Geffen
  1692. { MAP_PAYON, 162, 233 }, // 3=Payon
  1693. { MAP_ALBERTA, 192, 147 }, // 4=Alberta
  1694. #ifdef RENEWAL
  1695. { MAP_IZLUDE, 128, 146 }, // 5=Izlude (Renewal)
  1696. #else
  1697. { MAP_IZLUDE, 128, 114 }, // 5=Izlude
  1698. #endif
  1699. { MAP_ALDEBARAN, 140, 131 }, // 6=Al de Baran
  1700. { MAP_LUTIE, 147, 134 }, // 7=Lutie
  1701. { MAP_COMODO, 209, 143 }, // 8=Comodo
  1702. { MAP_YUNO, 157, 51 }, // 9=Yuno
  1703. { MAP_AMATSU, 198, 84 }, // 10=Amatsu
  1704. { MAP_GONRYUN, 160, 120 }, // 11=Gonryun
  1705. { MAP_UMBALA, 89, 157 }, // 12=Umbala
  1706. { MAP_NIFLHEIM, 21, 153 }, // 13=Niflheim
  1707. { MAP_LOUYANG, 217, 40 }, // 14=Louyang
  1708. #ifdef RENEWAL
  1709. { MAP_NOVICE, 18, 26 }, // 15=Training Grounds (Renewal)
  1710. #else
  1711. { MAP_NOVICE, 53, 111 }, // 15=Training Grounds
  1712. #endif
  1713. { MAP_JAIL, 23, 61 }, // 16=Prison
  1714. { MAP_JAWAII, 249, 127 }, // 17=Jawaii
  1715. { MAP_AYOTHAYA, 151, 117 }, // 18=Ayothaya
  1716. { MAP_EINBROCH, 64, 200 }, // 19=Einbroch
  1717. { MAP_LIGHTHALZEN, 158, 92 }, // 20=Lighthalzen
  1718. { MAP_EINBECH, 70, 95 }, // 21=Einbech
  1719. { MAP_HUGEL, 96, 145 }, // 22=Hugel
  1720. { MAP_RACHEL, 130, 110 }, // 23=Rachel
  1721. { MAP_VEINS, 216, 123 }, // 24=Veins
  1722. { MAP_MOSCOVIA, 223, 184 }, // 25=Moscovia
  1723. { MAP_MIDCAMP, 180, 240 }, // 26=Midgard Camp
  1724. { MAP_MANUK, 282, 138 }, // 27=Manuk
  1725. { MAP_SPLENDIDE, 201, 147 }, // 28=Splendide
  1726. { MAP_BRASILIS, 182, 239 }, // 29=Brasilis
  1727. { MAP_DICASTES, 198, 187 }, // 30=El Dicastes
  1728. { MAP_MORA, 44, 151 }, // 31=Mora
  1729. { MAP_DEWATA, 200, 180 }, // 32=Dewata
  1730. { MAP_MALANGDO, 140, 114 }, // 33=Malangdo Island
  1731. { MAP_MALAYA, 242, 211 }, // 34=Malaya Port
  1732. { MAP_ECLAGE, 110, 39 }, // 35=Eclage
  1733. { MAP_LASAGNA, 193, 182 }, // 36=Lasagna
  1734. };
  1735. nullpo_retr(-1, sd);
  1736. if( map_getmapflag(sd->bl.m, MF_NOGO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  1737. clif_displaymessage(sd->fd,msg_txt(sd,995)); // You cannot use @go on this map.
  1738. return 0;
  1739. }
  1740. memset(map_name, '\0', sizeof(map_name));
  1741. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1742. // get the number
  1743. town = atoi(message);
  1744. if (!message || !*message || sscanf(message, "%11s", map_name) < 1 || town < 0 || town >= ARRAYLENGTH(data))
  1745. {// no value matched so send the list of locations
  1746. const char* text;
  1747. // attempt to find the text help string
  1748. text = atcommand_help_string( command );
  1749. clif_displaymessage(fd, msg_txt(sd,38)); // Invalid location number, or name.
  1750. if( text )
  1751. {// send the text to the client
  1752. clif_displaymessage( fd, text );
  1753. }
  1754. return -1;
  1755. }
  1756. // get possible name of the city
  1757. map_name[MAP_NAME_LENGTH-1] = '\0';
  1758. for (i = 0; map_name[i]; i++)
  1759. map_name[i] = TOLOWER(map_name[i]);
  1760. // try to identify the map name
  1761. if (strncmp(map_name, "prontera", 3) == 0) {
  1762. town = 0;
  1763. } else if (strncmp(map_name, "morocc", 4) == 0 ||
  1764. strncmp(map_name, "morroc", 4) == 0) {
  1765. town = 1;
  1766. } else if (strncmp(map_name, "geffen", 3) == 0) {
  1767. town = 2;
  1768. } else if (strncmp(map_name, "payon", 3) == 0) {
  1769. town = 3;
  1770. } else if (strncmp(map_name, "alberta", 3) == 0) {
  1771. town = 4;
  1772. } else if (strncmp(map_name, "izlude", 3) == 0) {
  1773. town = 5;
  1774. } else if (strncmp(map_name, "aldebaran", 3) == 0) {
  1775. town = 6;
  1776. } else if (strncmp(map_name, "lutie", 3) == 0 ||
  1777. strcmp(map_name, "christmas") == 0 ||
  1778. strncmp(map_name, "xmas", 3) == 0 ||
  1779. strncmp(map_name, "x-mas", 3) == 0) {
  1780. town = 7;
  1781. } else if (strncmp(map_name, "comodo", 3) == 0) {
  1782. town = 8;
  1783. } else if (strncmp(map_name, "juno", 3) == 0 ||
  1784. strncmp(map_name, "yuno", 3) == 0) {
  1785. town = 9;
  1786. } else if (strncmp(map_name, "amatsu", 3) == 0) {
  1787. town = 10;
  1788. } else if (strncmp(map_name, "kunlun", 3) == 0 ||
  1789. strncmp(map_name, "gonryun", 3) == 0) {
  1790. town = 11;
  1791. } else if (strncmp(map_name, "umbala", 3) == 0) {
  1792. town = 12;
  1793. } else if (strncmp(map_name, "niflheim", 3) == 0) {
  1794. town = 13;
  1795. } else if (strncmp(map_name, "louyang", 3) == 0) {
  1796. town = 14;
  1797. } else if (strncmp(map_name, "new_1-1", 3) == 0 ||
  1798. strncmp(map_name, "startpoint", 3) == 0 ||
  1799. strncmp(map_name, "beginning", 3) == 0) {
  1800. town = 15;
  1801. } else if (strncmp(map_name, "sec_pri", 3) == 0 ||
  1802. strncmp(map_name, "prison", 3) == 0 ||
  1803. strncmp(map_name, "jail", 3) == 0) {
  1804. town = 16;
  1805. } else if (strncmp(map_name, "jawaii", 3) == 0) {
  1806. town = 17;
  1807. } else if (strncmp(map_name, "ayothaya", 3) == 0) {
  1808. town = 18;
  1809. } else if (strncmp(map_name, "einbroch", 5) == 0) {
  1810. town = 19;
  1811. } else if (strncmp(map_name, "lighthalzen", 3) == 0) {
  1812. town = 20;
  1813. } else if (strncmp(map_name, "einbech", 5) == 0) {
  1814. town = 21;
  1815. } else if (strncmp(map_name, "hugel", 3) == 0) {
  1816. town = 22;
  1817. } else if (strncmp(map_name, "rachel", 3) == 0) {
  1818. town = 23;
  1819. } else if (strncmp(map_name, "veins", 3) == 0) {
  1820. town = 24;
  1821. } else if (strncmp(map_name, "moscovia", 3) == 0) {
  1822. town = 25;
  1823. } else if (strncmp(map_name, "mid_camp", 3) == 0) {
  1824. town = 26;
  1825. } else if (strncmp(map_name, "manuk", 3) == 0) {
  1826. town = 27;
  1827. } else if (strncmp(map_name, "splendide", 3) == 0) {
  1828. town = 28;
  1829. } else if (strncmp(map_name, "brasilis", 3) == 0) {
  1830. town = 29;
  1831. } else if (strncmp(map_name, "dicastes01", 3) == 0) {
  1832. town = 30;
  1833. } else if (strcmp(map_name, "mora") == 0) {
  1834. town = 31;
  1835. } else if (strncmp(map_name, "dewata", 3) == 0) {
  1836. town = 32;
  1837. } else if (strncmp(map_name, "malangdo", 5) == 0) {
  1838. town = 33;
  1839. } else if (strncmp(map_name, "malaya", 5) == 0) {
  1840. town = 34;
  1841. } else if (strncmp(map_name, "eclage", 3) == 0) {
  1842. town = 35;
  1843. } else if (strncmp(map_name, "lasagna", 2) == 0) {
  1844. town = 36;
  1845. }
  1846. if (town >= 0 && town < ARRAYLENGTH(data))
  1847. {
  1848. int16 m = map_mapname2mapid(data[town].map);
  1849. if (m >= 0 && map_getmapflag(m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1850. clif_displaymessage(fd, msg_txt(sd,247)); // You are not authorized to warp to this map.
  1851. return -1;
  1852. }
  1853. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1854. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  1855. return -1;
  1856. }
  1857. if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == SETPOS_OK) {
  1858. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  1859. } else {
  1860. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  1861. return -1;
  1862. }
  1863. } else { // if you arrive here, you have an error in town variable when reading of names
  1864. clif_displaymessage(fd, msg_txt(sd,38)); // Invalid location number or name.
  1865. return -1;
  1866. }
  1867. return 0;
  1868. }
  1869. /*==========================================
  1870. *
  1871. *------------------------------------------*/
  1872. ACMD_FUNC(monster)
  1873. {
  1874. char name[NAME_LENGTH];
  1875. char monster[NAME_LENGTH];
  1876. char eventname[EVENT_NAME_LENGTH] = "";
  1877. int mob_id;
  1878. int number = 0;
  1879. int count;
  1880. int i, range;
  1881. short mx, my;
  1882. unsigned int size;
  1883. nullpo_retr(-1, sd);
  1884. memset(name, '\0', sizeof(name));
  1885. memset(monster, '\0', sizeof(monster));
  1886. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1887. if (!message || !*message) {
  1888. clif_displaymessage(fd, msg_txt(sd,80)); // Give the display name or monster name/id please.
  1889. return -1;
  1890. }
  1891. if (sscanf(message, "\"%23[^\"]\" %23s %11d", name, monster, &number) > 1 ||
  1892. sscanf(message, "%23s \"%23[^\"]\" %11d", monster, name, &number) > 1) {
  1893. //All data can be left as it is.
  1894. } else if ((count=sscanf(message, "%23s %11d %23s", monster, &number, name)) > 1) {
  1895. //Here, it is possible name was not given and we are using monster for it.
  1896. if (count < 3) //Blank mob's name.
  1897. name[0] = '\0';
  1898. } else if (sscanf(message, "%23s %23s %11d", name, monster, &number) > 1) {
  1899. //All data can be left as it is.
  1900. } else if (sscanf(message, "%23s", monster) > 0) {
  1901. //As before, name may be already filled.
  1902. name[0] = '\0';
  1903. } else {
  1904. clif_displaymessage(fd, msg_txt(sd,80)); // Give a display name and monster name/id please.
  1905. return -1;
  1906. }
  1907. if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
  1908. mob_id = mobdb_checkid(atoi(monster));
  1909. if (mob_id == 0) {
  1910. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  1911. return -1;
  1912. }
  1913. if (mob_id == MOBID_EMPERIUM) {
  1914. clif_displaymessage(fd, msg_txt(sd,83)); // Monster 'Emperium' cannot be spawned.
  1915. return -1;
  1916. }
  1917. if (number <= 0)
  1918. number = 1;
  1919. if( !name[0] )
  1920. strcpy(name, "--ja--");
  1921. // If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
  1922. if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit)
  1923. number = battle_config.atc_spawn_quantity_limit;
  1924. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  1925. if (strcmp(parent_cmd, "monstersmall") == 0)
  1926. size = SZ_MEDIUM; // This is just gorgeous [mkbu95]
  1927. else if (strcmp(parent_cmd, "monsterbig") == 0)
  1928. size = SZ_BIG;
  1929. else
  1930. size = SZ_SMALL;
  1931. if (battle_config.etc_log)
  1932. ShowInfo("%s monster='%s' name='%s' id=%d count=%d (%d,%d)\n", command, monster, name, mob_id, number, sd->bl.x, sd->bl.y);
  1933. count = 0;
  1934. range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
  1935. for (i = 0; i < number; i++) {
  1936. int k;
  1937. map_search_freecell(&sd->bl, 0, &mx, &my, range, range, 0);
  1938. k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE);
  1939. if(k) {
  1940. //mapreg_setreg(reference_uid(add_str("$@mobid"), i),k); //retain created mobid in array uncomment if needed
  1941. count ++;
  1942. }
  1943. }
  1944. if (count != 0)
  1945. if (number == count)
  1946. clif_displaymessage(fd, msg_txt(sd,39)); // All monster summoned!
  1947. else {
  1948. sprintf(atcmd_output, msg_txt(sd,240), count); // %d monster(s) summoned!
  1949. clif_displaymessage(fd, atcmd_output);
  1950. }
  1951. else {
  1952. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  1953. return -1;
  1954. }
  1955. return 0;
  1956. }
  1957. /*==========================================
  1958. *
  1959. *------------------------------------------*/
  1960. static int atkillmonster_sub(struct block_list *bl, va_list ap)
  1961. {
  1962. struct mob_data *md;
  1963. int flag;
  1964. nullpo_ret(md=(struct mob_data *)bl);
  1965. flag = va_arg(ap, int);
  1966. if (md->guardian_data)
  1967. return 0; //Do not touch WoE mobs!
  1968. if (flag)
  1969. status_zap(bl,md->status.hp, 0);
  1970. else
  1971. status_kill(bl);
  1972. return 1;
  1973. }
  1974. ACMD_FUNC(killmonster)
  1975. {
  1976. int map_id, drop_flag;
  1977. char map_name[MAP_NAME_LENGTH_EXT];
  1978. nullpo_retr(-1, sd);
  1979. memset(map_name, '\0', sizeof(map_name));
  1980. if (!message || !*message || sscanf(message, "%15s", map_name) < 1)
  1981. map_id = sd->bl.m;
  1982. else {
  1983. if ((map_id = map_mapname2mapid(map_name)) < 0)
  1984. map_id = sd->bl.m;
  1985. }
  1986. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  1987. drop_flag = strcmpi(parent_cmd, "killmonster2");
  1988. map_foreachinmap(atkillmonster_sub, map_id, BL_MOB, -drop_flag);
  1989. clif_displaymessage(fd, msg_txt(sd,165)); // All monsters killed!
  1990. return 0;
  1991. }
  1992. /*==========================================
  1993. *
  1994. *------------------------------------------*/
  1995. ACMD_FUNC(refine)
  1996. {
  1997. int j, position = 0, refine = 0, current_position, final_refine;
  1998. int count;
  1999. nullpo_retr(-1, sd);
  2000. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2001. if (!message || !*message || sscanf(message, "%11d %11d", &position, &refine) < 2) {
  2002. clif_displaymessage(fd, msg_txt(sd,996)); // Please enter a position and an amount (usage: @refine <equip position> <+/- amount>).
  2003. sprintf(atcmd_output, msg_txt(sd,997), EQP_HEAD_LOW); // %d: Lower Headgear
  2004. clif_displaymessage(fd, atcmd_output);
  2005. sprintf(atcmd_output, msg_txt(sd,998), EQP_HAND_R); // %d: Right Hand
  2006. clif_displaymessage(fd, atcmd_output);
  2007. sprintf(atcmd_output, msg_txt(sd,999), EQP_GARMENT); // %d: Garment
  2008. clif_displaymessage(fd, atcmd_output);
  2009. sprintf(atcmd_output, msg_txt(sd,1000), EQP_ACC_L); // %d: Left Accessory
  2010. clif_displaymessage(fd, atcmd_output);
  2011. sprintf(atcmd_output, msg_txt(sd,1001), EQP_ARMOR); // %d: Body Armor
  2012. clif_displaymessage(fd, atcmd_output);
  2013. sprintf(atcmd_output, msg_txt(sd,1002), EQP_HAND_L); // %d: Left Hand
  2014. clif_displaymessage(fd, atcmd_output);
  2015. sprintf(atcmd_output, msg_txt(sd,1003), EQP_SHOES); // %d: Shoes
  2016. clif_displaymessage(fd, atcmd_output);
  2017. sprintf(atcmd_output, msg_txt(sd,1004), EQP_ACC_R); // %d: Right Accessory
  2018. clif_displaymessage(fd, atcmd_output);
  2019. sprintf(atcmd_output, msg_txt(sd,1005), EQP_HEAD_TOP); // %d: Top Headgear
  2020. clif_displaymessage(fd, atcmd_output);
  2021. sprintf(atcmd_output, msg_txt(sd,1006), EQP_HEAD_MID); // %d: Mid Headgear
  2022. clif_displaymessage(fd, atcmd_output);
  2023. sprintf(atcmd_output, msg_txt(sd,1521), EQP_SHADOW_ARMOR); // %d: Shadow Armor
  2024. clif_displaymessage(fd, atcmd_output);
  2025. sprintf(atcmd_output, msg_txt(sd,1522), EQP_SHADOW_WEAPON); // %d: Shadow Weapon
  2026. clif_displaymessage(fd, atcmd_output);
  2027. sprintf(atcmd_output, msg_txt(sd,1523), EQP_SHADOW_SHIELD); // %d: Shadow Shield
  2028. clif_displaymessage(fd, atcmd_output);
  2029. sprintf(atcmd_output, msg_txt(sd,1524), EQP_SHADOW_SHOES); // %d: Shadow Shoes
  2030. clif_displaymessage(fd, atcmd_output);
  2031. sprintf(atcmd_output, msg_txt(sd,1525), EQP_SHADOW_ACC_R); // %d: Shadow Right Accessory
  2032. clif_displaymessage(fd, atcmd_output);
  2033. sprintf(atcmd_output, msg_txt(sd,1526), EQP_SHADOW_ACC_L); // %d: Shadow Left Accessory
  2034. clif_displaymessage(fd, atcmd_output);
  2035. return -1;
  2036. }
  2037. refine = cap_value(refine, -MAX_REFINE, MAX_REFINE);
  2038. count = 0;
  2039. for (j = 0; j < EQI_MAX; j++) {
  2040. int i;
  2041. if ((i = sd->equip_index[j]) < 0)
  2042. continue;
  2043. if(j == EQI_AMMO)
  2044. continue;
  2045. if (pc_is_same_equip_index((enum equip_index)j, sd->equip_index, i))
  2046. continue;
  2047. if(position && !(sd->inventory.u.items_inventory[i].equip & position))
  2048. continue;
  2049. final_refine = cap_value(sd->inventory.u.items_inventory[i].refine + refine, 0, MAX_REFINE);
  2050. if (sd->inventory.u.items_inventory[i].refine != final_refine) {
  2051. sd->inventory.u.items_inventory[i].refine = final_refine;
  2052. current_position = sd->inventory.u.items_inventory[i].equip;
  2053. pc_unequipitem(sd, i, 3);
  2054. clif_refine( *sd, i, ITEMREFINING_SUCCESS );
  2055. clif_delitem( *sd, i, 1, 3 );
  2056. clif_additem(sd, i, 1, 0);
  2057. pc_equipitem(sd, i, current_position);
  2058. clif_misceffect(&sd->bl, 3);
  2059. if( sd->inventory_data[i]->type == IT_WEAPON ){
  2060. achievement_update_objective(sd, AG_ENCHANT_SUCCESS, 2, sd->inventory_data[i]->weapon_level, sd->inventory.u.items_inventory[i].refine);
  2061. }
  2062. count++;
  2063. }
  2064. }
  2065. if (count == 0)
  2066. clif_displaymessage(fd, msg_txt(sd,166)); // No item has been refined.
  2067. else if (count == 1)
  2068. clif_displaymessage(fd, msg_txt(sd,167)); // 1 item has been refined.
  2069. else {
  2070. sprintf(atcmd_output, msg_txt(sd,168), count); // %d items have been refined.
  2071. clif_displaymessage(fd, atcmd_output);
  2072. }
  2073. return 0;
  2074. }
  2075. /*==========================================
  2076. *
  2077. *------------------------------------------*/
  2078. ACMD_FUNC(grade)
  2079. {
  2080. int j, position = 0, grade = 0, current_position, final_grade;
  2081. int count;
  2082. nullpo_retr(-1, sd);
  2083. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2084. if (!message || !*message || sscanf(message, "%11d %11d", &position, &grade) < 2) {
  2085. clif_displaymessage(fd, msg_txt(sd,1519)); // Please enter a position and an amount (usage: @grade <equip position> <+/- amount>).
  2086. sprintf(atcmd_output, msg_txt(sd,997), EQP_HEAD_LOW); // %d: Lower Headgear
  2087. clif_displaymessage(fd, atcmd_output);
  2088. sprintf(atcmd_output, msg_txt(sd,998), EQP_HAND_R); // %d: Right Hand
  2089. clif_displaymessage(fd, atcmd_output);
  2090. sprintf(atcmd_output, msg_txt(sd,999), EQP_GARMENT); // %d: Garment
  2091. clif_displaymessage(fd, atcmd_output);
  2092. sprintf(atcmd_output, msg_txt(sd,1000), EQP_ACC_L); // %d: Left Accessory
  2093. clif_displaymessage(fd, atcmd_output);
  2094. sprintf(atcmd_output, msg_txt(sd,1001), EQP_ARMOR); // %d: Body Armor
  2095. clif_displaymessage(fd, atcmd_output);
  2096. sprintf(atcmd_output, msg_txt(sd,1002), EQP_HAND_L); // %d: Left Hand
  2097. clif_displaymessage(fd, atcmd_output);
  2098. sprintf(atcmd_output, msg_txt(sd,1003), EQP_SHOES); // %d: Shoes
  2099. clif_displaymessage(fd, atcmd_output);
  2100. sprintf(atcmd_output, msg_txt(sd,1004), EQP_ACC_R); // %d: Right Accessory
  2101. clif_displaymessage(fd, atcmd_output);
  2102. sprintf(atcmd_output, msg_txt(sd,1005), EQP_HEAD_TOP); // %d: Top Headgear
  2103. clif_displaymessage(fd, atcmd_output);
  2104. sprintf(atcmd_output, msg_txt(sd,1006), EQP_HEAD_MID); // %d: Mid Headgear
  2105. clif_displaymessage(fd, atcmd_output);
  2106. return -1;
  2107. }
  2108. grade = cap_value(grade, -MAX_ENCHANTGRADE, MAX_ENCHANTGRADE);
  2109. count = 0;
  2110. for (j = 0; j < EQI_MAX; j++) {
  2111. int i;
  2112. if ((i = sd->equip_index[j]) < 0)
  2113. continue;
  2114. if(j == EQI_AMMO)
  2115. continue;
  2116. if (pc_is_same_equip_index((enum equip_index)j, sd->equip_index, i))
  2117. continue;
  2118. if(position && !(sd->inventory.u.items_inventory[i].equip & position))
  2119. continue;
  2120. final_grade = cap_value(sd->inventory.u.items_inventory[i].enchantgrade + grade, 0, MAX_ENCHANTGRADE);
  2121. if (sd->inventory.u.items_inventory[i].enchantgrade != final_grade) {
  2122. sd->inventory.u.items_inventory[i].enchantgrade = final_grade;
  2123. current_position = sd->inventory.u.items_inventory[i].equip;
  2124. pc_unequipitem(sd, i, 3);
  2125. clif_delitem( *sd, i, 1, 3 );
  2126. clif_additem(sd, i, 1, 0);
  2127. pc_equipitem(sd, i, current_position);
  2128. clif_misceffect(&sd->bl, 3);
  2129. count++;
  2130. }
  2131. }
  2132. sprintf(atcmd_output, msg_txt(sd,1520), count); // %d items have been graded.
  2133. clif_displaymessage(fd, atcmd_output);
  2134. return 0;
  2135. }
  2136. /*==========================================
  2137. *
  2138. *------------------------------------------*/
  2139. ACMD_FUNC(produce)
  2140. {
  2141. char item_name[100];
  2142. t_itemid item_id;
  2143. int attribute = 0, star = 0;
  2144. nullpo_retr(-1, sd);
  2145. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2146. memset(item_name, '\0', sizeof(item_name));
  2147. if (!message || !*message || (
  2148. sscanf(message, "\"%99[^\"]\" %11d %11d", item_name, &attribute, &star) < 1 &&
  2149. sscanf(message, "%99s %11d %11d", item_name, &attribute, &star) < 1
  2150. )) {
  2151. clif_displaymessage(fd, msg_txt(sd,1007)); // Please enter at least one item name/ID (usage: @produce <equip name/ID> <element> <# of very's>).
  2152. return -1;
  2153. }
  2154. std::shared_ptr<item_data> item_data = item_db.searchname( item_name );
  2155. if( item_data == nullptr ){
  2156. item_data = item_db.find( strtoul( item_name, nullptr, 10 ) );
  2157. }
  2158. if( item_data == nullptr ){
  2159. clif_displaymessage(fd, msg_txt(sd,170)); //This item is not an equipment.
  2160. return -1;
  2161. }
  2162. item_id = item_data->nameid;
  2163. if( itemdb_isequip2( item_data.get() ) ){
  2164. char flag = 0;
  2165. if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
  2166. attribute = ATTRIBUTE_NORMAL;
  2167. if (star < MIN_STAR || star > MAX_STAR)
  2168. star = 0;
  2169. struct item tmp_item = {};
  2170. tmp_item.nameid = item_id;
  2171. tmp_item.amount = 1;
  2172. tmp_item.identify = 1;
  2173. tmp_item.card[0] = CARD0_FORGE;
  2174. tmp_item.card[1] = item_data->type==IT_WEAPON?
  2175. ((star*5) << 8) + attribute:0;
  2176. tmp_item.card[2] = GetWord(sd->status.char_id, 0);
  2177. tmp_item.card[3] = GetWord(sd->status.char_id, 1);
  2178. clif_produceeffect(sd, 0, item_id);
  2179. clif_misceffect(&sd->bl, 3);
  2180. if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  2181. clif_additem(sd, 0, 0, flag);
  2182. } else {
  2183. sprintf(atcmd_output, msg_txt(sd,169), item_id, item_data->name.c_str()); // The item (%u: '%s') is not equipable.
  2184. clif_displaymessage(fd, atcmd_output);
  2185. return -1;
  2186. }
  2187. return 0;
  2188. }
  2189. /*==========================================
  2190. *
  2191. *------------------------------------------*/
  2192. ACMD_FUNC(memo)
  2193. {
  2194. int position = 0;
  2195. nullpo_retr(-1, sd);
  2196. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2197. if( !message || !*message || sscanf(message, "%11d", &position) < 1 )
  2198. {
  2199. int i;
  2200. clif_displaymessage(sd->fd, msg_txt(sd,668)); // Your actual memo positions are:
  2201. for( i = 0; i < MAX_MEMOPOINTS; i++ )
  2202. {
  2203. if( strcmp( "", sd->status.memo_point[i].map ) != 0 )
  2204. sprintf( atcmd_output, "%d - %s (%d,%d)", i, sd->status.memo_point[i].map, sd->status.memo_point[i].x, sd->status.memo_point[i].y );
  2205. else
  2206. sprintf(atcmd_output, msg_txt(sd,171), i); // %d - void
  2207. clif_displaymessage(sd->fd, atcmd_output);
  2208. }
  2209. return 0;
  2210. }
  2211. if( position < 0 || position >= MAX_MEMOPOINTS )
  2212. {
  2213. sprintf(atcmd_output, msg_txt(sd,1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo <memo_position:%d-%d>).
  2214. clif_displaymessage(fd, atcmd_output);
  2215. return -1;
  2216. }
  2217. return !pc_memo( sd, position );
  2218. }
  2219. /*==========================================
  2220. *
  2221. *------------------------------------------*/
  2222. ACMD_FUNC(gat)
  2223. {
  2224. int y;
  2225. nullpo_retr(-1, sd);
  2226. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2227. for (y = 2; y >= -2; y--) {
  2228. sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
  2229. map_getmapdata(sd->bl.m)->name, sd->bl.x - 2, sd->bl.y + y,
  2230. map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE),
  2231. map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE),
  2232. map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y, CELL_GETTYPE),
  2233. map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE),
  2234. map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE));
  2235. clif_displaymessage(fd, atcmd_output);
  2236. }
  2237. return 0;
  2238. }
  2239. /*==========================================
  2240. *
  2241. *------------------------------------------*/
  2242. ACMD_FUNC(displaystatus)
  2243. {
  2244. int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0;
  2245. nullpo_retr(-1, sd);
  2246. if (!message || !*message || (i = sscanf(message, "%11d %11d %11d %11d %11d %11d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) {
  2247. clif_displaymessage(fd, msg_txt(sd,1009)); // Please enter a status type/flag (usage: @displaystatus <status type> <flag> <tick> {<val1> {<val2> {<val3>}}}).
  2248. return -1;
  2249. }
  2250. if (i < 2) flag = 1;
  2251. if (i < 3) tick = 0;
  2252. clif_status_change(&sd->bl, type, flag, tick, val1, val2, val3);
  2253. return 0;
  2254. }
  2255. /*==========================================
  2256. * @stpoint (Rewritten by [Yor])
  2257. *------------------------------------------*/
  2258. ACMD_FUNC(statuspoint)
  2259. {
  2260. int point;
  2261. unsigned int new_status_point;
  2262. if (!message || !*message || (point = atoi(message)) == 0) {
  2263. clif_displaymessage(fd, msg_txt(sd,1010)); // Please enter a number (usage: @stpoint <number of points>).
  2264. return -1;
  2265. }
  2266. if(point < 0)
  2267. {
  2268. if(sd->status.status_point < (unsigned int)(-point))
  2269. {
  2270. new_status_point = 0;
  2271. }
  2272. else
  2273. {
  2274. new_status_point = sd->status.status_point + point;
  2275. }
  2276. }
  2277. else if(UINT_MAX - sd->status.status_point < (unsigned int)point)
  2278. {
  2279. new_status_point = UINT_MAX;
  2280. }
  2281. else
  2282. {
  2283. new_status_point = sd->status.status_point + point;
  2284. }
  2285. if (new_status_point != sd->status.status_point) {
  2286. sd->status.status_point = new_status_point;
  2287. clif_updatestatus(*sd, SP_STATUSPOINT);
  2288. clif_displaymessage(fd, msg_txt(sd,174)); // Number of status points changed.
  2289. } else {
  2290. if (point < 0)
  2291. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2292. else
  2293. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2294. return -1;
  2295. }
  2296. return 0;
  2297. }
  2298. /*==========================================
  2299. * @trpoint
  2300. *------------------------------------------*/
  2301. ACMD_FUNC(traitpoint)
  2302. {
  2303. int point;
  2304. unsigned int new_trait_point;
  2305. if (!message || !*message || (point = atoi(message)) == 0) {
  2306. clif_displaymessage(fd, msg_txt(sd, 820)); // Please enter a number (usage: @trpoint <number of points>).
  2307. return -1;
  2308. }
  2309. if (point < 0)
  2310. {
  2311. if (sd->status.trait_point < (unsigned int)(-point))
  2312. {
  2313. new_trait_point = 0;
  2314. }
  2315. else
  2316. {
  2317. new_trait_point = sd->status.trait_point + point;
  2318. }
  2319. }
  2320. else if (UINT_MAX - sd->status.trait_point < (unsigned int)point)
  2321. {
  2322. new_trait_point = UINT_MAX;
  2323. }
  2324. else
  2325. {
  2326. new_trait_point = sd->status.trait_point + point;
  2327. }
  2328. if (new_trait_point != sd->status.trait_point) {
  2329. sd->status.trait_point = new_trait_point;
  2330. clif_updatestatus(*sd, SP_TRAITPOINT);
  2331. clif_displaymessage(fd, msg_txt(sd, 174)); // Number of status points changed.
  2332. }
  2333. else {
  2334. if (point < 0)
  2335. clif_displaymessage(fd, msg_txt(sd, 41)); // Unable to decrease the number/value.
  2336. else
  2337. clif_displaymessage(fd, msg_txt(sd, 149)); // Unable to increase the number/value.
  2338. return -1;
  2339. }
  2340. return 0;
  2341. }
  2342. /*==========================================
  2343. * @skpoint (Rewritten by [Yor])
  2344. *------------------------------------------*/
  2345. ACMD_FUNC(skillpoint)
  2346. {
  2347. int point;
  2348. unsigned int new_skill_point;
  2349. nullpo_retr(-1, sd);
  2350. if (!message || !*message || (point = atoi(message)) == 0) {
  2351. clif_displaymessage(fd, msg_txt(sd,1011)); // Please enter a number (usage: @skpoint <number of points>).
  2352. return -1;
  2353. }
  2354. if(point < 0)
  2355. {
  2356. if(sd->status.skill_point < (unsigned int)(-point))
  2357. {
  2358. new_skill_point = 0;
  2359. }
  2360. else
  2361. {
  2362. new_skill_point = sd->status.skill_point + point;
  2363. }
  2364. }
  2365. else if(UINT_MAX - sd->status.skill_point < (unsigned int)point)
  2366. {
  2367. new_skill_point = UINT_MAX;
  2368. }
  2369. else
  2370. {
  2371. new_skill_point = sd->status.skill_point + point;
  2372. }
  2373. if (new_skill_point != sd->status.skill_point) {
  2374. sd->status.skill_point = new_skill_point;
  2375. clif_updatestatus(*sd, SP_SKILLPOINT);
  2376. clif_displaymessage(fd, msg_txt(sd,175)); // Number of skill points changed.
  2377. } else {
  2378. if (point < 0)
  2379. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2380. else
  2381. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2382. return -1;
  2383. }
  2384. return 0;
  2385. }
  2386. /*==========================================
  2387. * @zeny
  2388. *------------------------------------------*/
  2389. ACMD_FUNC(zeny)
  2390. {
  2391. int zeny=0, ret=-1;
  2392. nullpo_retr(-1, sd);
  2393. if (!message || !*message || (zeny = atoi(message)) == 0) {
  2394. clif_displaymessage(fd, msg_txt(sd,1012)); // Please enter an amount (usage: @zeny <amount>).
  2395. return -1;
  2396. }
  2397. if(zeny > 0){
  2398. if((ret=pc_getzeny(sd,zeny,LOG_TYPE_COMMAND)) == 1)
  2399. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2400. }
  2401. else {
  2402. if( sd->status.zeny < -zeny ) zeny = -sd->status.zeny;
  2403. if((ret=pc_payzeny(sd,-zeny,LOG_TYPE_COMMAND)) == 1)
  2404. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2405. }
  2406. if(!ret) clif_displaymessage(fd, msg_txt(sd,176)); //ret=0 mean cmd success
  2407. return 0;
  2408. }
  2409. /*==========================================
  2410. *
  2411. *------------------------------------------*/
  2412. ACMD_FUNC(param)
  2413. {
  2414. nullpo_retr(-1, sd);
  2415. uint8 stat;
  2416. int value = 0;
  2417. uint16 new_value, status, max_status;
  2418. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2419. if (!message || !*message || sscanf(message, "%11d", &value) < 1 || value == 0) {
  2420. clif_displaymessage(fd, msg_txt(sd,1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2421. return -1;
  2422. }
  2423. ARR_FIND( 0, ARRAYLENGTH(parameter_names), stat, strcmpi(command + 1, parameter_names[stat]) == 0 );
  2424. if( stat == ARRAYLENGTH(parameter_names)) { // normally impossible...
  2425. clif_displaymessage(fd, msg_txt(sd,1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2426. return -1;
  2427. }
  2428. if( stat < PARAM_POW ){
  2429. status = pc_getstat( sd, SP_STR + stat - PARAM_STR );
  2430. }else{
  2431. if( !( sd->class_ & JOBL_FOURTH ) ){
  2432. clif_displaymessage(fd, msg_txt(sd, 797)); // This command is unavailable to non - 4th class.
  2433. return -1;
  2434. }
  2435. status = pc_getstat( sd, SP_POW + stat - PARAM_POW );
  2436. }
  2437. if( pc_has_permission( sd, PC_PERM_BYPASS_MAX_STAT ) ){
  2438. max_status = SHRT_MAX;
  2439. }else{
  2440. max_status = pc_maxparameter( sd, static_cast<e_params>( stat ) );
  2441. }
  2442. if( value > 0 && status + value >= max_status ){
  2443. new_value = max_status;
  2444. }else if( value < 0 && abs( value ) >= status ){
  2445. if( stat < PARAM_POW ){
  2446. new_value = 1;
  2447. }else{
  2448. new_value = 0;
  2449. }
  2450. }else{
  2451. new_value = status + value;
  2452. }
  2453. if( new_value != status ){
  2454. if (stat < PARAM_POW) {
  2455. pc_setstat( sd, SP_STR + stat - PARAM_STR, new_value );
  2456. clif_updatestatus(*sd, static_cast<_sp>( SP_STR + stat ) );
  2457. clif_updatestatus(*sd, static_cast<_sp>( SP_USTR + stat ) );
  2458. } else {
  2459. pc_setstat( sd, SP_POW + stat - PARAM_POW, new_value );
  2460. clif_updatestatus(*sd, static_cast<_sp>( SP_POW + stat - PARAM_POW ) );
  2461. clif_updatestatus(*sd, static_cast<_sp>( SP_UPOW + stat - PARAM_POW ) );
  2462. }
  2463. status_calc_pc(sd, SCO_FORCE);
  2464. clif_displaymessage(fd, msg_txt(sd,42)); // Stat changed.
  2465. achievement_update_objective(sd, AG_GOAL_STATUS, 0);
  2466. } else {
  2467. if (value < 0)
  2468. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2469. else
  2470. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2471. return -1;
  2472. }
  2473. return 0;
  2474. }
  2475. /*==========================================
  2476. * Stat all by fritz (rewritten by [Yor])
  2477. *------------------------------------------*/
  2478. ACMD_FUNC(stat_all)
  2479. {
  2480. nullpo_retr(-1, sd);
  2481. int value = 0;
  2482. uint8 count, i;
  2483. uint16 status[PARAM_MAX] = {}, max_status[PARAM_MAX] = {};
  2484. for (i = PARAM_STR; i < PARAM_POW; i++)
  2485. status[i] = pc_getstat(sd, SP_STR + i);
  2486. if (!message || !*message || sscanf(message, "%11d", &value) < 1 || value == 0) {
  2487. for (i = PARAM_STR; i < PARAM_POW; i++)
  2488. max_status[i] = pc_maxparameter(sd, static_cast<e_params>(i));
  2489. value = SHRT_MAX;
  2490. } else {
  2491. if (pc_has_permission(sd, PC_PERM_BYPASS_MAX_STAT)) {
  2492. for (i = PARAM_STR; i < PARAM_POW; i++)
  2493. max_status[i] = SHRT_MAX;
  2494. } else {
  2495. for (i = PARAM_STR; i < PARAM_POW; i++)
  2496. max_status[i] = pc_maxparameter(sd, static_cast<e_params>(i));
  2497. }
  2498. }
  2499. count = 0;
  2500. for (i = PARAM_STR; i < PARAM_POW; i++) {
  2501. short new_value;
  2502. if (value > 0 && status[i] + value >= max_status[i])
  2503. new_value = max_status[i];
  2504. else if (value < 0 && abs(value) >= status[i])
  2505. new_value = 1;
  2506. else
  2507. new_value = status[i] + value;
  2508. if (new_value != status[i]) {
  2509. pc_setstat( sd, SP_STR + i, new_value );
  2510. clif_updatestatus(*sd, static_cast<_sp>( SP_STR + i ) );
  2511. clif_updatestatus(*sd, static_cast<_sp>( SP_USTR + i ) );
  2512. count++;
  2513. }
  2514. }
  2515. if (count > 0) { // if at least 1 stat modified
  2516. status_calc_pc(sd, SCO_FORCE);
  2517. clif_displaymessage(fd, msg_txt(sd,84)); // All stats changed!
  2518. achievement_update_objective(sd, AG_GOAL_STATUS, 0);
  2519. } else {
  2520. if (value < 0)
  2521. clif_displaymessage(fd, msg_txt(sd,177)); // You cannot decrease that stat anymore.
  2522. else
  2523. clif_displaymessage(fd, msg_txt(sd,178)); // You cannot increase that stat anymore.
  2524. return -1;
  2525. }
  2526. return 0;
  2527. }
  2528. /*==========================================
  2529. * Traits
  2530. *------------------------------------------*/
  2531. ACMD_FUNC(trait_all) {
  2532. nullpo_retr(-1, sd);
  2533. #ifndef RENEWAL
  2534. sprintf(atcmd_output, msg_txt(sd, 154), command); // %s failed.
  2535. clif_displaymessage(fd, atcmd_output);
  2536. return -1;
  2537. #endif
  2538. if( !( sd->class_ & JOBL_FOURTH ) ){
  2539. clif_displaymessage(fd, msg_txt(sd, 797)); // This command is unavailable to non - 4th class.
  2540. return -1;
  2541. }
  2542. int value = 0;
  2543. uint8 i;
  2544. uint16 status[PARAM_MAX] = {}, max_status[PARAM_MAX] = {};
  2545. for (i = PARAM_POW; i < PARAM_MAX; i++)
  2546. status[i] = pc_getstat(sd, SP_POW + i - PARAM_POW);
  2547. if (!message || !*message || sscanf(message, "%11d", &value) < 1 || value == 0) {
  2548. for (i = PARAM_POW; i < PARAM_MAX; i++)
  2549. max_status[i] = pc_maxparameter(sd, static_cast<e_params>(i));
  2550. value = SHRT_MAX;
  2551. } else {
  2552. if (pc_has_permission(sd, PC_PERM_BYPASS_MAX_STAT)) {
  2553. for (i = PARAM_POW; i < PARAM_MAX; i++)
  2554. max_status[i] = SHRT_MAX;
  2555. } else {
  2556. for (i = PARAM_POW; i < PARAM_MAX; i++)
  2557. max_status[i] = pc_maxparameter(sd, static_cast<e_params>(i));
  2558. }
  2559. }
  2560. uint8 count = 0;
  2561. for (i = PARAM_POW; i < PARAM_MAX; i++) {
  2562. short new_value;
  2563. if (value > 0 && status[i] + value >= max_status[i])
  2564. new_value = max_status[i];
  2565. else if (value < 0 && abs(value) >= status[i])
  2566. new_value = 0;
  2567. else
  2568. new_value = status[i] + value;
  2569. if (new_value != status[i]) {
  2570. pc_setstat( sd, SP_POW + i - PARAM_POW, new_value );
  2571. clif_updatestatus(*sd, static_cast<_sp>( SP_POW + i - PARAM_POW ) );
  2572. clif_updatestatus(*sd, static_cast<_sp>( SP_UPOW + i - PARAM_POW ) );
  2573. count++;
  2574. }
  2575. }
  2576. if (count > 0) { // if at least 1 stat modified
  2577. status_calc_pc(sd, SCO_FORCE);
  2578. clif_displaymessage(fd, msg_txt(sd, 84)); // All stats changed!
  2579. achievement_update_objective(sd, AG_GOAL_STATUS, 0);
  2580. } else {
  2581. if (value < 0)
  2582. clif_displaymessage(fd, msg_txt(sd, 177)); // You cannot decrease that stat anymore.
  2583. else
  2584. clif_displaymessage(fd, msg_txt(sd, 178)); // You cannot increase that stat anymore.
  2585. return -1;
  2586. }
  2587. return 0;
  2588. }
  2589. /*==========================================
  2590. *
  2591. *------------------------------------------*/
  2592. ACMD_FUNC(guildlevelup) {
  2593. int level = 0;
  2594. short added_level;
  2595. nullpo_retr(-1, sd);
  2596. if (!message || !*message || sscanf(message, "%11d", &level) < 1 || level == 0) {
  2597. clif_displaymessage(fd, msg_txt(sd,1014)); // Please enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>).
  2598. return -1;
  2599. }
  2600. auto &guild_info = sd->guild;
  2601. if (sd->status.guild_id <= 0 || guild_info == nullptr) {
  2602. clif_displaymessage(fd, msg_txt(sd,43)); // You're not in a guild.
  2603. return -1;
  2604. }
  2605. //if (strcmp(sd->status.name, guild_info->master) != 0) {
  2606. // clif_displaymessage(fd, msg_txt(sd,44)); // You're not the master of your guild.
  2607. // return -1;
  2608. //}
  2609. added_level = (short)level;
  2610. if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild.guild_lv))) // fix positive overflow
  2611. added_level = (short)MAX_GUILDLEVEL - guild_info->guild.guild_lv;
  2612. else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild.guild_lv))) // fix negative overflow
  2613. added_level = 1 - guild_info->guild.guild_lv;
  2614. if (added_level != 0) {
  2615. intif_guild_change_basicinfo(guild_info->guild.guild_id, GBI_GUILDLV, &added_level, sizeof(added_level));
  2616. clif_displaymessage(fd, msg_txt(sd,179)); // Guild level changed.
  2617. } else {
  2618. clif_displaymessage(fd, msg_txt(sd,45)); // Guild level change failed.
  2619. return -1;
  2620. }
  2621. return 0;
  2622. }
  2623. /*==========================================
  2624. *
  2625. *------------------------------------------*/
  2626. ACMD_FUNC(makeegg) {
  2627. int id;
  2628. nullpo_retr(-1, sd);
  2629. if (!message || !*message) {
  2630. clif_displaymessage(fd, msg_txt(sd,1015)); // Please enter a monster/egg name/ID (usage: @makeegg <pet>).
  2631. return -1;
  2632. }
  2633. // for monster name
  2634. if ((id = mobdb_searchname(message)) != 0)
  2635. ;
  2636. else
  2637. id = atoi(message);
  2638. std::shared_ptr<s_pet_db> pet = pet_db.find(id);
  2639. if( pet == nullptr ){
  2640. t_itemid nameid;
  2641. // for egg name
  2642. std::shared_ptr<item_data> item_data = item_db.searchname( message );
  2643. if( item_data != nullptr ){
  2644. nameid = item_data->nameid;
  2645. }else{
  2646. nameid = strtoul( message, nullptr, 10 );
  2647. }
  2648. pet = pet_db_search( nameid, PET_EGG );
  2649. }
  2650. int res(-1);
  2651. if (pet != nullptr) {
  2652. std::shared_ptr<s_mob_db> mdb = mob_db.find(pet->class_);
  2653. if(mdb){
  2654. sd->catch_target_class = pet->class_;
  2655. if(intif_create_pet(sd->status.account_id, sd->status.char_id, pet->class_, mdb->lv, pet->EggID, 0, pet->intimate, 100, 0, 1, mdb->jname.c_str())){
  2656. res = 0;
  2657. } else {
  2658. res = -2; //char server down
  2659. }
  2660. }
  2661. }
  2662. switch(res){
  2663. case -1:
  2664. clif_displaymessage(fd, msg_txt(sd,180)); // The monster/egg name/id doesn't exist.
  2665. break;
  2666. case -2:
  2667. clif_displaymessage(fd, msg_txt(sd,407)); //charserver link broken
  2668. break;
  2669. }
  2670. return res;
  2671. }
  2672. /*==========================================
  2673. *
  2674. *------------------------------------------*/
  2675. ACMD_FUNC(hatch) {
  2676. nullpo_retr(-1, sd);
  2677. if (sd->status.pet_id <= 0)
  2678. clif_sendegg(sd);
  2679. else {
  2680. clif_displaymessage(fd, msg_txt(sd,181)); // You already have a pet.
  2681. return -1;
  2682. }
  2683. return 0;
  2684. }
  2685. /*==========================================
  2686. *
  2687. *------------------------------------------*/
  2688. ACMD_FUNC(petfriendly) {
  2689. int friendly;
  2690. struct pet_data *pd;
  2691. nullpo_retr(-1, sd);
  2692. if (!message || !*message || (friendly = atoi(message)) < 0) {
  2693. clif_displaymessage(fd, msg_txt(sd,1016)); // Please enter a valid value (usage: @petfriendly <0-1000>).
  2694. return -1;
  2695. }
  2696. pd = sd->pd;
  2697. if (!pd) {
  2698. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2699. return -1;
  2700. }
  2701. if (friendly < 0 || friendly > 1000)
  2702. {
  2703. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  2704. return -1;
  2705. }
  2706. if (friendly == pd->pet.intimate) {
  2707. clif_displaymessage(fd, msg_txt(sd,183)); // Pet intimacy is already at maximum.
  2708. return -1;
  2709. }
  2710. pet_set_intimate(pd, friendly);
  2711. clif_send_petstatus(sd);
  2712. clif_displaymessage(fd, msg_txt(sd,182)); // Pet intimacy changed.
  2713. return 0;
  2714. }
  2715. /*==========================================
  2716. *
  2717. *------------------------------------------*/
  2718. ACMD_FUNC(pethungry)
  2719. {
  2720. int hungry;
  2721. struct pet_data *pd;
  2722. nullpo_retr(-1, sd);
  2723. if (!message || !*message || (hungry = atoi(message)) < 0) {
  2724. clif_displaymessage(fd, msg_txt(sd,1017)); // Please enter a valid number (usage: @pethungry <0-100>).
  2725. return -1;
  2726. }
  2727. pd = sd->pd;
  2728. if (!sd->status.pet_id || !pd) {
  2729. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2730. return -1;
  2731. }
  2732. if (hungry < 0 || hungry > 100) {
  2733. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  2734. return -1;
  2735. }
  2736. if (hungry == pd->pet.hungry) {
  2737. clif_displaymessage(fd, msg_txt(sd,186)); // Pet hunger is already at maximum.
  2738. return -1;
  2739. }
  2740. pd->pet.hungry = hungry;
  2741. clif_send_petstatus(sd);
  2742. clif_displaymessage(fd, msg_txt(sd,185)); // Pet hunger changed.
  2743. return 0;
  2744. }
  2745. /*==========================================
  2746. *
  2747. *------------------------------------------*/
  2748. ACMD_FUNC(petrename)
  2749. {
  2750. struct pet_data *pd;
  2751. nullpo_retr(-1, sd);
  2752. if (!sd->status.pet_id || !sd->pd) {
  2753. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2754. return -1;
  2755. }
  2756. pd = sd->pd;
  2757. if (!pd->pet.rename_flag) {
  2758. clif_displaymessage(fd, msg_txt(sd,188)); // You can already rename your pet.
  2759. return -1;
  2760. }
  2761. pd->pet.rename_flag = 0;
  2762. intif_save_petdata(sd->status.account_id, &pd->pet);
  2763. clif_send_petstatus(sd);
  2764. clif_displaymessage(fd, msg_txt(sd,187)); // You can now rename your pet.
  2765. return 0;
  2766. }
  2767. /*==========================================
  2768. *
  2769. *------------------------------------------*/
  2770. ACMD_FUNC(recall) {
  2771. map_session_data* pl_sd = nullptr;;
  2772. nullpo_retr(-1, sd);
  2773. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2774. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2775. clif_displaymessage(fd, msg_txt(sd,1018)); // Please enter a player name (usage: @recall <char name/ID>).
  2776. return -1;
  2777. }
  2778. if((pl_sd=map_nick2sd(atcmd_player_name,true)) == nullptr && (pl_sd=map_charid2sd(atoi(atcmd_player_name))) == nullptr)
  2779. {
  2780. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  2781. return -1;
  2782. }
  2783. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  2784. {
  2785. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level doesn't authorize you to perform this action on the specified player.
  2786. return -1;
  2787. }
  2788. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2789. clif_displaymessage(fd, msg_txt(sd,1019)); // You are not authorized to warp someone to this map.
  2790. return -1;
  2791. }
  2792. if (pl_sd->bl.m >= 0 && map_getmapflag(pl_sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2793. clif_displaymessage(fd, msg_txt(sd,1020)); // You are not authorized to warp this player from their map.
  2794. return -1;
  2795. }
  2796. if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y) {
  2797. return -1;
  2798. }
  2799. if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
  2800. clif_displaymessage(fd, msg_txt(sd,1025)); // The player is currently autotrading and cannot be recalled.
  2801. return -1;
  2802. }
  2803. sprintf(atcmd_output, msg_txt(sd,46), pl_sd->status.name); // %s recalled!
  2804. clif_displaymessage(fd, atcmd_output);
  2805. return 0;
  2806. }
  2807. /*==========================================
  2808. * charblock command (usage: charblock <player_name>)
  2809. * This command do a definitiv ban on a player
  2810. *------------------------------------------*/
  2811. ACMD_FUNC(char_block)
  2812. {
  2813. nullpo_retr(-1, sd);
  2814. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2815. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2816. sprintf(atcmd_output, msg_txt(sd, 1021), command); // Please enter a player name (usage: %s <char name>).
  2817. clif_displaymessage(fd, atcmd_output);
  2818. return -1;
  2819. }
  2820. chrif_req_login_operation(sd->status.account_id, atcmd_player_name, CHRIF_OP_LOGIN_BLOCK, 0, 0, 0);
  2821. sprintf(atcmd_output, msg_txt(sd,88), "login"); // Sending request to %s server...
  2822. clif_displaymessage(fd, atcmd_output);
  2823. return 0;
  2824. }
  2825. /*==========================================
  2826. * accountban command (usage: ban <%time> <player_name>)
  2827. * charban command (usage: charban <%time> <player_name>)
  2828. * %time see common/timer.cpp::solve_time()
  2829. *------------------------------------------*/
  2830. ACMD_FUNC(char_ban)
  2831. {
  2832. char *modif_p, output[CHAT_SIZE_MAX];
  2833. int32 timediff = 0; //don't set this as uint as we may want to decrease banned time
  2834. enum chrif_req_op bantype;
  2835. nullpo_retr(-1, sd);
  2836. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2837. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2838. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  2839. if (strcmpi(parent_cmd,"charban") == 0)
  2840. bantype = CHRIF_OP_BAN;
  2841. else if (strcmpi(parent_cmd,"ban") == 0)
  2842. bantype = CHRIF_OP_LOGIN_BAN;
  2843. else
  2844. return -1;
  2845. if (!message || !*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) {
  2846. sprintf(output, msg_txt(sd,1022), command); // Please enter ban time and a player name (usage: %s <time> <char name>).
  2847. clif_displaymessage(fd, output);
  2848. return -1;
  2849. }
  2850. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  2851. modif_p = atcmd_output;
  2852. timediff = (int32)solve_time(modif_p); //discard seconds
  2853. if (timediff == 0) { //allow negative ?
  2854. safesnprintf(output, sizeof(output), msg_txt(sd,85), command, timediff); // Invalid time for %s command (time=%d)
  2855. clif_displaymessage(fd, output);
  2856. clif_displaymessage(fd, msg_txt(sd,702)); // Time parameter format is +/-<value> to alter. y/a = Year, m = Month, d/j = Day, h = Hour, n/mn = Minute, s = Second.
  2857. return -1;
  2858. }
  2859. if( timediff < 0 && (
  2860. (bantype == CHRIF_OP_LOGIN_BAN && !pc_can_use_command(sd, "unban", COMMAND_ATCOMMAND))
  2861. || (bantype == CHRIF_OP_BAN && !pc_can_use_command(sd, "charunban", COMMAND_ATCOMMAND))
  2862. ))
  2863. {
  2864. clif_displaymessage(fd,msg_txt(sd,1023)); // You are not allowed to alter the time of a ban.
  2865. return -1;
  2866. }
  2867. if (bantype == CHRIF_OP_BAN)
  2868. chrif_req_charban(sd->status.account_id, atcmd_player_name,timediff);
  2869. else
  2870. chrif_req_login_operation(sd->status.account_id, atcmd_player_name, bantype, timediff, 0, 0);
  2871. safesnprintf(output, sizeof(output), msg_txt(sd,88), bantype == CHRIF_OP_BAN ? "char" : "login"); // Sending request to %s server...
  2872. clif_displaymessage(fd, output);
  2873. return 0;
  2874. }
  2875. /*==========================================
  2876. * charunblock command (usage: charunblock <player_name>)
  2877. *------------------------------------------*/
  2878. ACMD_FUNC(char_unblock)
  2879. {
  2880. nullpo_retr(-1, sd);
  2881. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2882. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2883. sprintf(atcmd_output, msg_txt(sd, 1021), command); // Please enter a player name (usage: %s <char name>).
  2884. clif_displaymessage(fd, atcmd_output);
  2885. return -1;
  2886. }
  2887. // send answer to login server via char-server
  2888. chrif_req_login_operation(sd->status.account_id, atcmd_player_name, CHRIF_OP_LOGIN_UNBLOCK, 0, 0, 0);
  2889. sprintf(atcmd_output, msg_txt(sd,88), "login"); // Sending request to %s server...
  2890. clif_displaymessage(fd, atcmd_output);
  2891. return 0;
  2892. }
  2893. /*==========================================
  2894. * acc unban command (usage: unban <player_name>)
  2895. * char unban command (usage: charunban <player_name>)
  2896. *------------------------------------------*/
  2897. ACMD_FUNC(char_unban){
  2898. enum chrif_req_op unbantype;
  2899. nullpo_retr(-1, sd);
  2900. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2901. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2902. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  2903. if (strcmpi(parent_cmd,"charunban") == 0)
  2904. unbantype = CHRIF_OP_UNBAN;
  2905. else if (strcmpi(parent_cmd,"unban") == 0)
  2906. unbantype = CHRIF_OP_LOGIN_UNBAN;
  2907. else
  2908. return -1;
  2909. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2910. sprintf(atcmd_output, msg_txt(sd,435), command); // Please enter a player name (usage: %s <char name>).
  2911. clif_displaymessage(fd, atcmd_output);
  2912. return -1;
  2913. }
  2914. if (unbantype == CHRIF_OP_UNBAN)
  2915. chrif_req_charunban(sd->status.account_id,atcmd_player_name);
  2916. else
  2917. chrif_req_login_operation(sd->status.account_id, atcmd_player_name, unbantype, 0, 0, 0);
  2918. sprintf(atcmd_output, msg_txt(sd,88), unbantype == CHRIF_OP_UNBAN ? "char":"login"); // Sending request to %s server...
  2919. clif_displaymessage(fd, atcmd_output);
  2920. return 0;
  2921. }
  2922. /*==========================================
  2923. *
  2924. *------------------------------------------*/
  2925. ACMD_FUNC(night)
  2926. {
  2927. nullpo_retr(-1, sd);
  2928. if (night_flag != 1) {
  2929. map_night_timer(night_timer_tid, 0, 0, 1);
  2930. } else {
  2931. clif_displaymessage(fd, msg_txt(sd,89)); // Night mode is already enabled.
  2932. return -1;
  2933. }
  2934. return 0;
  2935. }
  2936. /*==========================================
  2937. *
  2938. *------------------------------------------*/
  2939. ACMD_FUNC(day)
  2940. {
  2941. nullpo_retr(-1, sd);
  2942. if (night_flag != 0) {
  2943. map_day_timer(day_timer_tid, 0, 0, 1);
  2944. } else {
  2945. clif_displaymessage(fd, msg_txt(sd,90)); // Day mode is already enabled.
  2946. return -1;
  2947. }
  2948. return 0;
  2949. }
  2950. /*==========================================
  2951. *
  2952. *------------------------------------------*/
  2953. ACMD_FUNC(doom)
  2954. {
  2955. map_session_data* pl_sd;
  2956. struct s_mapiterator* iter;
  2957. nullpo_retr(-1, sd);
  2958. iter = mapit_getallusers();
  2959. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2960. {
  2961. if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2962. {
  2963. status_kill(&pl_sd->bl);
  2964. clif_specialeffect(&pl_sd->bl,EF_GRANDCROSS2,AREA);
  2965. clif_displaymessage(pl_sd->fd, msg_txt(sd,61)); // The holy messenger has given judgement.
  2966. }
  2967. }
  2968. mapit_free(iter);
  2969. clif_displaymessage(fd, msg_txt(sd,62)); // Judgement was made.
  2970. return 0;
  2971. }
  2972. /*==========================================
  2973. *
  2974. *------------------------------------------*/
  2975. ACMD_FUNC(doommap)
  2976. {
  2977. map_session_data* pl_sd;
  2978. struct s_mapiterator* iter;
  2979. nullpo_retr(-1, sd);
  2980. iter = mapit_getallusers();
  2981. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2982. {
  2983. if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2984. {
  2985. status_kill(&pl_sd->bl);
  2986. clif_specialeffect(&pl_sd->bl,EF_GRANDCROSS2,AREA);
  2987. clif_displaymessage(pl_sd->fd, msg_txt(sd,61)); // The holy messenger has given judgement.
  2988. }
  2989. }
  2990. mapit_free(iter);
  2991. clif_displaymessage(fd, msg_txt(sd,62)); // Judgement was made.
  2992. return 0;
  2993. }
  2994. /*==========================================
  2995. *
  2996. *------------------------------------------*/
  2997. static void atcommand_raise_sub(map_session_data* sd) {
  2998. status_revive(&sd->bl, 100, 100);
  2999. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  3000. clif_displaymessage(sd->fd, msg_txt(sd,63)); // Mercy has been shown.
  3001. }
  3002. /*==========================================
  3003. *
  3004. *------------------------------------------*/
  3005. ACMD_FUNC(raise)
  3006. {
  3007. map_session_data* pl_sd;
  3008. struct s_mapiterator* iter;
  3009. nullpo_retr(-1, sd);
  3010. iter = mapit_getallusers();
  3011. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3012. if( pc_isdead(pl_sd) )
  3013. atcommand_raise_sub(pl_sd);
  3014. mapit_free(iter);
  3015. clif_displaymessage(fd, msg_txt(sd,64)); // Mercy has been granted.
  3016. return 0;
  3017. }
  3018. /*==========================================
  3019. *
  3020. *------------------------------------------*/
  3021. ACMD_FUNC(raisemap)
  3022. {
  3023. map_session_data* pl_sd;
  3024. struct s_mapiterator* iter;
  3025. nullpo_retr(-1, sd);
  3026. iter = mapit_getallusers();
  3027. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3028. if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) )
  3029. atcommand_raise_sub(pl_sd);
  3030. mapit_free(iter);
  3031. clif_displaymessage(fd, msg_txt(sd,64)); // Mercy has been granted.
  3032. return 0;
  3033. }
  3034. /*==========================================
  3035. *
  3036. *------------------------------------------*/
  3037. ACMD_FUNC(kick)
  3038. {
  3039. map_session_data *pl_sd;
  3040. nullpo_retr(-1, sd);
  3041. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3042. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3043. clif_displaymessage(fd, msg_txt(sd,1026)); // Please enter a player name (usage: @kick <char name/ID>).
  3044. return -1;
  3045. }
  3046. if((pl_sd=map_nick2sd(atcmd_player_name,false)) == nullptr && (pl_sd=map_charid2sd(atoi(atcmd_player_name))) == nullptr)
  3047. {
  3048. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  3049. return -1;
  3050. }
  3051. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  3052. {
  3053. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  3054. return -1;
  3055. }
  3056. clif_GM_kick(sd, pl_sd);
  3057. return 0;
  3058. }
  3059. /*==========================================
  3060. *
  3061. *------------------------------------------*/
  3062. ACMD_FUNC(kickall)
  3063. {
  3064. map_session_data* pl_sd;
  3065. struct s_mapiterator* iter;
  3066. nullpo_retr(-1, sd);
  3067. iter = mapit_getallusers();
  3068. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3069. {
  3070. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level
  3071. if (sd->status.account_id != pl_sd->status.account_id)
  3072. clif_GM_kick(nullptr, pl_sd);
  3073. }
  3074. }
  3075. mapit_free(iter);
  3076. clif_displaymessage(fd, msg_txt(sd,195)); // All players have been kicked!
  3077. return 0;
  3078. }
  3079. /*==========================================
  3080. *
  3081. *------------------------------------------*/
  3082. ACMD_FUNC(allskill)
  3083. {
  3084. nullpo_retr(-1, sd);
  3085. pc_allskillup(sd); // all skills
  3086. sd->status.skill_point = 0; // 0 skill points
  3087. clif_updatestatus(*sd, SP_SKILLPOINT); // update
  3088. clif_displaymessage(fd, msg_txt(sd,76)); // All skills have been added to your skill tree.
  3089. return 0;
  3090. }
  3091. /*==========================================
  3092. *
  3093. *------------------------------------------*/
  3094. ACMD_FUNC(questskill)
  3095. {
  3096. uint16 skill_id;
  3097. nullpo_retr(-1, sd);
  3098. if (!message || !*message || (skill_id = atoi(message)) <= 0)
  3099. {// also send a list of skills applicable to this command
  3100. const char* text;
  3101. // attempt to find the text corresponding to this command
  3102. text = atcommand_help_string( command );
  3103. // send the error message as always
  3104. clif_displaymessage(fd, msg_txt(sd,1027)); // Please enter a quest skill number.
  3105. if( text )
  3106. {// send the skill ID list associated with this command
  3107. clif_displaymessage( fd, text );
  3108. }
  3109. return -1;
  3110. }
  3111. if (skill_id >= MAX_SKILL_ID) {
  3112. clif_displaymessage(fd, msg_txt(sd,198)); // This skill number doesn't exist.
  3113. return -1;
  3114. }
  3115. if (!skill_get_inf2(skill_id, INF2_ISQUEST)) {
  3116. clif_displaymessage(fd, msg_txt(sd,197)); // This skill number doesn't exist or isn't a quest skill.
  3117. return -1;
  3118. }
  3119. if (pc_checkskill(sd, skill_id) > 0) {
  3120. clif_displaymessage(fd, msg_txt(sd,196)); // You already have this quest skill.
  3121. return -1;
  3122. }
  3123. pc_skill(sd, skill_id, 1, ADDSKILL_PERMANENT);
  3124. clif_displaymessage(fd, msg_txt(sd,70)); // You have learned the skill.
  3125. return 0;
  3126. }
  3127. /*==========================================
  3128. *
  3129. *------------------------------------------*/
  3130. ACMD_FUNC(lostskill)
  3131. {
  3132. uint16 skill_id = 0, sk_idx = 0;
  3133. nullpo_retr(-1, sd);
  3134. if (!message || !*message || (skill_id = atoi(message)) <= 0)
  3135. {// also send a list of skills applicable to this command
  3136. const char* text;
  3137. // attempt to find the text corresponding to this command
  3138. text = atcommand_help_string( command );
  3139. // send the error message as always
  3140. clif_displaymessage(fd, msg_txt(sd,1027)); // Please enter a quest skill number.
  3141. if( text )
  3142. {// send the skill ID list associated with this command
  3143. clif_displaymessage( fd, text );
  3144. }
  3145. return -1;
  3146. }
  3147. if (!(sk_idx = skill_get_index(skill_id))) {
  3148. clif_displaymessage(fd, msg_txt(sd,198)); // This skill number doesn't exist.
  3149. return -1;
  3150. }
  3151. if (!skill_get_inf2(skill_id, INF2_ISQUEST)) {
  3152. clif_displaymessage(fd, msg_txt(sd,197)); // This skill number doesn't exist or isn't a quest skill.
  3153. return -1;
  3154. }
  3155. if (pc_checkskill(sd, skill_id) == 0) {
  3156. clif_displaymessage(fd, msg_txt(sd,201)); // You don't have this quest skill.
  3157. return -1;
  3158. }
  3159. sd->status.skill[sk_idx].lv = 0;
  3160. sd->status.skill[sk_idx].flag = SKILL_FLAG_PERMANENT;
  3161. clif_deleteskill(sd,skill_id);
  3162. clif_displaymessage(fd, msg_txt(sd,71)); // You have forgotten the skill.
  3163. return 0;
  3164. }
  3165. /*==========================================
  3166. *
  3167. *------------------------------------------*/
  3168. ACMD_FUNC(spiritball)
  3169. {
  3170. uint32 max_spiritballs;
  3171. int number;
  3172. nullpo_retr(-1, sd);
  3173. max_spiritballs = zmin(ARRAYLENGTH(sd->spirit_timer), 0x7FFF);
  3174. if( !message || !*message || (number = atoi(message)) < 0 || number > max_spiritballs )
  3175. {
  3176. char msg[CHAT_SIZE_MAX];
  3177. safesnprintf(msg, sizeof(msg), msg_txt(sd,1028), max_spiritballs); // Please enter a party name (usage: @party <party_name>).
  3178. clif_displaymessage(fd, msg);
  3179. return -1;
  3180. }
  3181. if( sd->spiritball > 0 )
  3182. pc_delspiritball(sd, sd->spiritball, 1);
  3183. sd->spiritball = number;
  3184. clif_spiritball(&sd->bl);
  3185. // no message, player can look the difference
  3186. return 0;
  3187. }
  3188. ACMD_FUNC(soulball)
  3189. {
  3190. int number;
  3191. nullpo_retr(-1, sd);
  3192. if (!message || !*message || (number = atoi(message)) < 0 || number > MAX_SOUL_BALL) {
  3193. char msg[CHAT_SIZE_MAX];
  3194. safesnprintf(msg, sizeof(msg), "Usage: @soulball <number: 0-%d>", MAX_SOUL_BALL);
  3195. clif_displaymessage(fd, msg);
  3196. return -1;
  3197. }
  3198. if (sd->soulball > 0)
  3199. pc_delsoulball(sd, sd->soulball, true);
  3200. sd->soulball = number;
  3201. clif_soulball(sd);
  3202. return 0;
  3203. }
  3204. /*==========================================
  3205. *
  3206. *------------------------------------------*/
  3207. ACMD_FUNC(party)
  3208. {
  3209. char party[NAME_LENGTH];
  3210. nullpo_retr(-1, sd);
  3211. memset(party, '\0', sizeof(party));
  3212. if (!message || !*message || sscanf(message, "%23[^\n]", party) < 1) {
  3213. clif_displaymessage(fd, msg_txt(sd,1029)); // Please enter a party name (usage: @party <party_name>).
  3214. return -1;
  3215. }
  3216. party_create(sd, party, 0, 0);
  3217. return 0;
  3218. }
  3219. /*==========================================
  3220. *
  3221. *------------------------------------------*/
  3222. ACMD_FUNC(guild)
  3223. {
  3224. char guild[NAME_LENGTH];
  3225. int prev;
  3226. nullpo_retr(-1, sd);
  3227. memset(guild, '\0', sizeof(guild));
  3228. if (sd->clan) {
  3229. clif_displaymessage(fd, msg_txt(sd, 1498)); // You cannot create a guild because you are in a clan.
  3230. return -1;
  3231. }
  3232. if (!message || !*message || sscanf(message, "%23[^\n]", guild) < 1) {
  3233. clif_displaymessage(fd, msg_txt(sd,1030)); // Please enter a guild name (usage: @guild <guild_name>).
  3234. return -1;
  3235. }
  3236. prev = battle_config.guild_emperium_check;
  3237. battle_config.guild_emperium_check = 0;
  3238. guild_create(sd, guild);
  3239. battle_config.guild_emperium_check = prev;
  3240. return 0;
  3241. }
  3242. ACMD_FUNC(breakguild)
  3243. {
  3244. nullpo_retr(-1, sd);
  3245. if (sd->status.guild_id) { // Check if the player has a guild
  3246. if (sd->guild) { // Check if guild was found
  3247. if (sd->state.gmaster_flag) { // Check if player is guild master
  3248. int ret = 0;
  3249. ret = guild_break(sd, sd->guild->guild.name); // Break guild
  3250. if (ret) { // Check if anything went wrong
  3251. return 0; // Guild was broken
  3252. } else {
  3253. return -1; // Something went wrong
  3254. }
  3255. } else { // Not guild master
  3256. clif_displaymessage(fd, msg_txt(sd,1181)); // You need to be a Guild Master to use this command.
  3257. return -1;
  3258. }
  3259. } else { // Guild was not found. HOW?
  3260. clif_displaymessage(fd, msg_txt(sd,252)); // You are not in a guild.
  3261. return -1;
  3262. }
  3263. } else { // Player does not have a guild
  3264. clif_displaymessage(fd, msg_txt(sd,252)); // You are not in a guild.
  3265. return -1;
  3266. }
  3267. }
  3268. /**
  3269. * Start WoE:FE
  3270. */
  3271. ACMD_FUNC(agitstart)
  3272. {
  3273. nullpo_retr(-1, sd);
  3274. if( guild_agit_start() ){
  3275. clif_displaymessage(fd, msg_txt(sd,72)); // War of Emperium has been initiated.
  3276. return 0;
  3277. }else{
  3278. clif_displaymessage(fd, msg_txt(sd,73)); // War of Emperium is currently in progress.
  3279. return -1;
  3280. }
  3281. }
  3282. /**
  3283. * Start WoE:SE
  3284. */
  3285. ACMD_FUNC(agitstart2)
  3286. {
  3287. nullpo_retr(-1, sd);
  3288. if( guild_agit2_start() ){
  3289. clif_displaymessage(fd, msg_txt(sd,403)); // "War of Emperium SE has been initiated."
  3290. return 0;
  3291. }else{
  3292. clif_displaymessage(fd, msg_txt(sd,404)); // "War of Emperium SE is currently in progress."
  3293. return -1;
  3294. }
  3295. }
  3296. /**
  3297. * Start WoE:TE
  3298. */
  3299. ACMD_FUNC(agitstart3)
  3300. {
  3301. nullpo_retr(-1, sd);
  3302. if( guild_agit3_start() ){
  3303. clif_displaymessage(fd, msg_txt(sd,749)); // "War of Emperium TE has been initiated."
  3304. return 0;
  3305. }else{
  3306. clif_displaymessage(fd, msg_txt(sd,750)); // "War of Emperium TE is currently in progress."
  3307. return -1;
  3308. }
  3309. }
  3310. /**
  3311. * End WoE:FE
  3312. */
  3313. ACMD_FUNC(agitend)
  3314. {
  3315. nullpo_retr(-1, sd);
  3316. if( guild_agit_end() ){
  3317. clif_displaymessage(fd, msg_txt(sd,74)); // War of Emperium has been ended.
  3318. return 0;
  3319. }else{
  3320. clif_displaymessage(fd, msg_txt(sd,75)); // War of Emperium is currently not in progress.
  3321. return -1;
  3322. }
  3323. }
  3324. /**
  3325. * End WoE:SE
  3326. */
  3327. ACMD_FUNC(agitend2)
  3328. {
  3329. nullpo_retr(-1, sd);
  3330. if( guild_agit2_end() ){
  3331. clif_displaymessage(fd, msg_txt(sd,405)); // "War of Emperium SE has been ended."
  3332. return 0;
  3333. }else{
  3334. clif_displaymessage(fd, msg_txt(sd,406)); // "War of Emperium SE is currently not in progress."
  3335. return -1;
  3336. }
  3337. }
  3338. /**
  3339. * End WoE:TE
  3340. */
  3341. ACMD_FUNC(agitend3)
  3342. {
  3343. nullpo_retr(-1, sd);
  3344. if( guild_agit3_end() ){
  3345. clif_displaymessage(fd, msg_txt(sd,751));// War of Emperium TE has been ended.
  3346. return 0;
  3347. }else{
  3348. clif_displaymessage(fd, msg_txt(sd,752));// War of Emperium TE is currently not in progress.
  3349. return -1;
  3350. }
  3351. }
  3352. /*==========================================
  3353. * @mapexit - shuts down the map server
  3354. *------------------------------------------*/
  3355. ACMD_FUNC(mapexit)
  3356. {
  3357. nullpo_retr(-1, sd);
  3358. global_core->signal_shutdown();
  3359. return 0;
  3360. }
  3361. /*==========================================
  3362. * idsearch <part_of_name>: revrited by [Yor]
  3363. *------------------------------------------*/
  3364. ACMD_FUNC(idsearch)
  3365. {
  3366. nullpo_retr(-1, sd);
  3367. char item_name[100];
  3368. memset(item_name, '\0', sizeof(item_name));
  3369. if (!message || !*message || sscanf(message, "%99s", item_name) < 0) {
  3370. clif_displaymessage(fd, msg_txt(sd,1031)); // Please enter part of an item name (usage: @idsearch <part_of_item_name>).
  3371. return -1;
  3372. }
  3373. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3374. sprintf(atcmd_output, msg_txt(sd,77), item_name); // The reference result of '%s' (name: id):
  3375. clif_displaymessage(fd, atcmd_output);
  3376. std::map<t_itemid, std::shared_ptr<item_data>> item_array = {};
  3377. uint16 match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
  3378. if (match == MAX_SEARCH) {
  3379. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH); // Displaying first %d matches
  3380. clif_displaymessage(fd, atcmd_output);
  3381. }
  3382. for(const auto &result : item_array) {
  3383. std::shared_ptr<item_data> id = result.second;
  3384. sprintf(atcmd_output, msg_txt(sd,78), item_db.create_item_link( id ).c_str(), id->nameid); // %s: %u
  3385. clif_displaymessage(fd, atcmd_output);
  3386. }
  3387. sprintf(atcmd_output, msg_txt(sd,79), match); // It is %d affair above.
  3388. clif_displaymessage(fd, atcmd_output);
  3389. return 0;
  3390. }
  3391. /*==========================================
  3392. * Recall All Characters Online To Your Location
  3393. *------------------------------------------*/
  3394. ACMD_FUNC(recallall)
  3395. {
  3396. map_session_data* pl_sd;
  3397. struct s_mapiterator* iter;
  3398. int count;
  3399. nullpo_retr(-1, sd);
  3400. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3401. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3402. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp someone to your current map.
  3403. return -1;
  3404. }
  3405. count = 0;
  3406. iter = mapit_getallusers();
  3407. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3408. {
  3409. if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3410. {
  3411. if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y)
  3412. continue; // Don't waste time warping the character to the same place.
  3413. if (pl_sd->bl.m >= 0 && map_getmapflag(pl_sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3414. count++;
  3415. else {
  3416. if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
  3417. count++;
  3418. }
  3419. }
  3420. }
  3421. }
  3422. mapit_free(iter);
  3423. clif_displaymessage(fd, msg_txt(sd,92)); // All characters recalled!
  3424. if (count) {
  3425. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3426. clif_displaymessage(fd, atcmd_output);
  3427. }
  3428. return 0;
  3429. }
  3430. /*==========================================
  3431. * Recall online characters of a guild to your location
  3432. *------------------------------------------*/
  3433. ACMD_FUNC(guildrecall)
  3434. {
  3435. map_session_data* pl_sd;
  3436. struct s_mapiterator* iter;
  3437. int count;
  3438. char guild_name[NAME_LENGTH];
  3439. nullpo_retr(-1, sd);
  3440. memset(guild_name, '\0', sizeof(guild_name));
  3441. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3442. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3443. clif_displaymessage(fd, msg_txt(sd,1034)); // Please enter a guild name/ID (usage: @guildrecall <guild_name/ID>).
  3444. return -1;
  3445. }
  3446. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3447. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp someone to your current map.
  3448. return -1;
  3449. }
  3450. auto g = guild_searchnameid(guild_name);
  3451. if (!g) {
  3452. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  3453. return -1;
  3454. }
  3455. count = 0;
  3456. iter = mapit_getallusers();
  3457. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3458. {
  3459. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild.guild_id)
  3460. {
  3461. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y))
  3462. continue; // Skip GMs greater than you... or chars already on the cell
  3463. if (pl_sd->bl.m >= 0 && map_getmapflag(pl_sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3464. count++;
  3465. else{
  3466. if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
  3467. count++;
  3468. }
  3469. }
  3470. }
  3471. }
  3472. mapit_free(iter);
  3473. sprintf(atcmd_output, msg_txt(sd,93), g->guild.name); // All online characters of the %s guild have been recalled to your position.
  3474. clif_displaymessage(fd, atcmd_output);
  3475. if (count) {
  3476. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3477. clif_displaymessage(fd, atcmd_output);
  3478. }
  3479. return 0;
  3480. }
  3481. /*==========================================
  3482. * Recall online characters of a party to your location
  3483. *------------------------------------------*/
  3484. ACMD_FUNC(partyrecall)
  3485. {
  3486. map_session_data* pl_sd;
  3487. struct s_mapiterator* iter;
  3488. char party_name[NAME_LENGTH];
  3489. struct party_data *p;
  3490. int count;
  3491. nullpo_retr(-1, sd);
  3492. memset(party_name, '\0', sizeof(party_name));
  3493. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3494. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3495. clif_displaymessage(fd, msg_txt(sd,1035)); // Please enter a party name/ID (usage: @partyrecall <party_name/ID>).
  3496. return -1;
  3497. }
  3498. if (sd->bl.m >= 0 && map_getmapflag(sd->bl.m, MF_NOWARPTO) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3499. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp someone to your current map.
  3500. return -1;
  3501. }
  3502. if ((p = party_searchname(party_name)) == nullptr && // name first to avoid error when name begin with a number
  3503. (p = party_search(atoi(message))) == nullptr)
  3504. {
  3505. clif_displaymessage(fd, msg_txt(sd,96)); // Incorrect name or ID, or no one from the party is online.
  3506. return -1;
  3507. }
  3508. count = 0;
  3509. iter = mapit_getallusers();
  3510. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3511. {
  3512. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id)
  3513. {
  3514. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y))
  3515. continue; // Skip GMs greater than you... or chars already on the cell
  3516. if (pl_sd->bl.m >= 0 && map_getmapflag(pl_sd->bl.m, MF_NOWARP) && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3517. count++;
  3518. else{
  3519. if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
  3520. count++;
  3521. }
  3522. }
  3523. }
  3524. }
  3525. mapit_free(iter);
  3526. sprintf(atcmd_output, msg_txt(sd,95), p->party.name); // All online characters of the %s party have been recalled to your position.
  3527. clif_displaymessage(fd, atcmd_output);
  3528. if (count) {
  3529. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3530. clif_displaymessage(fd, atcmd_output);
  3531. }
  3532. return 0;
  3533. }
  3534. /*==========================================
  3535. *
  3536. *------------------------------------------*/
  3537. void atcommand_doload();
  3538. ACMD_FUNC(reload) {
  3539. nullpo_retr(-1, sd);
  3540. if ((strlen(command) < 8 ) && (!message || !*message)) {
  3541. const char* text;
  3542. text = atcommand_help_string( command );
  3543. if(text)
  3544. clif_displaymessage( fd, text );
  3545. return -1;
  3546. }
  3547. if (strstr(command, "itemdb") || strncmp(message, "itemdb", 4) == 0) {
  3548. itemdb_reload();
  3549. clif_displaymessage(fd, msg_txt(sd,97)); // Item database has been reloaded.
  3550. } else if (strstr(command, "cashdb") || strncmp(message, "cashdb", 4) == 0) {
  3551. cashshop_reloaddb();
  3552. clif_displaymessage( fd, msg_txt( sd, 832 ) ); // Cash shop database has been reloaded.
  3553. } else if (strstr(command, "mobdb") || strncmp(message, "mobdb", 3) == 0) {
  3554. mob_reload();
  3555. pet_db.reload();
  3556. hom_reload();
  3557. mercenary_db.reload();
  3558. elemental_db.reload();
  3559. clif_displaymessage(fd, msg_txt(sd,98)); // Monster database has been reloaded.
  3560. } else if (strstr(command, "skilldb") || strncmp(message, "skilldb", 4) == 0) {
  3561. skill_reload();
  3562. homunculus_db.reload();
  3563. clif_displaymessage(fd, msg_txt(sd,99)); // Skill database has been reloaded.
  3564. } else if (strstr(command, "atcommand") || strncmp(message, "atcommand", 4) == 0) {
  3565. atcommand_doload();
  3566. pc_groups_reload();
  3567. clif_displaymessage(fd, msg_txt(sd,254)); // GM command configuration has been reloaded.
  3568. } else if (strstr(command, "battleconf") || strncmp(message, "battleconf", 3) == 0) {
  3569. struct Battle_Config prev_config;
  3570. memcpy(&prev_config, &battle_config, sizeof(prev_config));
  3571. battle_config_read(BATTLE_CONF_FILENAME);
  3572. if( prev_config.item_rate_mvp != battle_config.item_rate_mvp
  3573. || prev_config.item_rate_common != battle_config.item_rate_common
  3574. || prev_config.item_rate_common_boss != battle_config.item_rate_common_boss
  3575. || prev_config.item_rate_common_mvp != battle_config.item_rate_common_mvp
  3576. || prev_config.item_rate_card != battle_config.item_rate_card
  3577. || prev_config.item_rate_card_boss != battle_config.item_rate_card_boss
  3578. || prev_config.item_rate_card_mvp != battle_config.item_rate_card_mvp
  3579. || prev_config.item_rate_equip != battle_config.item_rate_equip
  3580. || prev_config.item_rate_equip_boss != battle_config.item_rate_equip_boss
  3581. || prev_config.item_rate_equip_mvp != battle_config.item_rate_equip_mvp
  3582. || prev_config.item_rate_heal != battle_config.item_rate_heal
  3583. || prev_config.item_rate_heal_boss != battle_config.item_rate_heal_boss
  3584. || prev_config.item_rate_heal_mvp != battle_config.item_rate_heal_mvp
  3585. || prev_config.item_rate_use != battle_config.item_rate_use
  3586. || prev_config.item_rate_use_boss != battle_config.item_rate_use_boss
  3587. || prev_config.item_rate_use_mvp != battle_config.item_rate_use_mvp
  3588. || prev_config.item_rate_treasure != battle_config.item_rate_treasure
  3589. || prev_config.item_rate_adddrop != battle_config.item_rate_adddrop
  3590. || prev_config.logarithmic_drops != battle_config.logarithmic_drops
  3591. || prev_config.item_drop_common_min != battle_config.item_drop_common_min
  3592. || prev_config.item_drop_common_max != battle_config.item_drop_common_max
  3593. || prev_config.item_drop_card_min != battle_config.item_drop_card_min
  3594. || prev_config.item_drop_card_max != battle_config.item_drop_card_max
  3595. || prev_config.item_drop_equip_min != battle_config.item_drop_equip_min
  3596. || prev_config.item_drop_equip_max != battle_config.item_drop_equip_max
  3597. || prev_config.item_drop_mvp_min != battle_config.item_drop_mvp_min
  3598. || prev_config.item_drop_mvp_max != battle_config.item_drop_mvp_max
  3599. || prev_config.item_drop_heal_min != battle_config.item_drop_heal_min
  3600. || prev_config.item_drop_heal_max != battle_config.item_drop_heal_max
  3601. || prev_config.item_drop_use_min != battle_config.item_drop_use_min
  3602. || prev_config.item_drop_use_max != battle_config.item_drop_use_max
  3603. || prev_config.item_drop_treasure_min != battle_config.item_drop_treasure_min
  3604. || prev_config.item_drop_treasure_max != battle_config.item_drop_treasure_max
  3605. || prev_config.base_exp_rate != battle_config.base_exp_rate
  3606. || prev_config.job_exp_rate != battle_config.job_exp_rate
  3607. )
  3608. { // Exp or Drop rates changed.
  3609. mob_reload(); //Needed as well so rate changes take effect.
  3610. }
  3611. clif_displaymessage(fd, msg_txt(sd,255)); // Battle configuration has been reloaded.
  3612. } else if (strstr(command, "statusdb") || strncmp(message, "statusdb", 3) == 0) {
  3613. status_readdb( true );
  3614. clif_displaymessage(fd, msg_txt(sd,256)); // Status database has been reloaded.
  3615. } else if (strstr(command, "pcdb") || strncmp(message, "pcdb", 2) == 0) {
  3616. pc_readdb();
  3617. clif_displaymessage(fd, msg_txt(sd,257)); // Player database has been reloaded.
  3618. } else if (strstr(command, "motd") || strncmp(message, "motd", 4) == 0) {
  3619. pc_read_motd();
  3620. clif_displaymessage(fd, msg_txt(sd,268)); // Reloaded the Message of the Day.
  3621. } else if (strstr(command, "script") || strncmp(message, "script", 3) == 0) {
  3622. struct s_mapiterator* iter;
  3623. map_session_data* pl_sd;
  3624. //atcommand_broadcast( fd, sd, "@broadcast", "Server is reloading scripts..." );
  3625. //atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
  3626. iter = mapit_getallusers();
  3627. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ){
  3628. pc_close_npc(pl_sd,1);
  3629. clif_cutin( *pl_sd, "", 255 );
  3630. pl_sd->state.block_action &= ~(PCBLOCK_ALL ^ PCBLOCK_IMMUNE);
  3631. bg_queue_leave(pl_sd);
  3632. }
  3633. mapit_free(iter);
  3634. for (auto &bg : bg_queues) {
  3635. for (auto &bg_sd : bg->teama_members)
  3636. bg_team_leave(bg_sd, false, false); // Kick Team A from battlegrounds
  3637. for (auto &bg_sd : bg->teamb_members)
  3638. bg_team_leave(bg_sd, false, false); // Kick Team B from battlegrounds
  3639. bg_queue_clear(bg, true);
  3640. }
  3641. flush_fifos();
  3642. map_reloadnpc(true); // reload config files seeking for npcs
  3643. script_reload();
  3644. npc_reload();
  3645. clif_displaymessage(fd, msg_txt(sd,100)); // Scripts have been reloaded.
  3646. } else if (strstr(command, "msgconf") || strncmp(message, "msgconf", 3) == 0) {
  3647. map_msg_reload();
  3648. clif_displaymessage(fd, msg_txt(sd,463)); // Message configuration has been reloaded.
  3649. } else if (strstr(command, "questdb") || strncmp(message, "questdb", 3) == 0) {
  3650. if (quest_db.reload())
  3651. clif_displaymessage(fd, msg_txt(sd,1377)); // Quest database has been reloaded.
  3652. } else if (strstr(command, "instancedb") || strncmp(message, "instancedb", 4) == 0) {
  3653. if (instance_db.reload())
  3654. clif_displaymessage(fd, msg_txt(sd,516)); // Instance database has been reloaded.
  3655. } else if (strstr(command, "achievementdb") || strncmp(message, "achievementdb", 4) == 0) {
  3656. achievement_db_reload();
  3657. clif_displaymessage(fd, msg_txt(sd,771)); // Achievement database has been reloaded.
  3658. } else if (strstr(command, "attendancedb") || strncmp(message, "attendancedb", 4) == 0) {
  3659. attendance_db.reload();
  3660. clif_displaymessage(fd, msg_txt(sd, 795)); // Attendance database has been reloaded.
  3661. }else if( strstr( command, "barterdb" ) || strncmp( message, "barterdb", 4 ) == 0 ){
  3662. barter_db.reload();
  3663. clif_displaymessage(fd, msg_txt(sd, 830)); // Barter database has been reloaded.
  3664. }
  3665. return 0;
  3666. }
  3667. /*==========================================
  3668. * @partysharelvl <share_range> [Akinari]
  3669. * Updates char server party share level range in runtime
  3670. * Temporary - Permanent update in inter_athena.conf
  3671. *------------------------------------------*/
  3672. ACMD_FUNC(partysharelvl) {
  3673. unsigned int share_lvl;
  3674. nullpo_retr(-1, sd);
  3675. if(!message || !*message) {
  3676. clif_displaymessage(fd, msg_txt(sd,1322)); // Please enter an amount.
  3677. return -1;
  3678. } else {
  3679. share_lvl = min(abs(atoi(message)),MAX_LEVEL);
  3680. }
  3681. if(intif_party_sharelvlupdate(share_lvl)) //Successfully updated
  3682. clif_displaymessage(fd, msg_txt(sd,1478)); // Party share level range has been changed successfully.
  3683. else //Char server offline
  3684. clif_displaymessage(fd, msg_txt(sd,1479)); // Failed to update configuration. Character server is offline.
  3685. return 0;
  3686. }
  3687. /*==========================================
  3688. * @mapinfo [0-3] <map name> by MC_Cameri
  3689. * => Shows information about the map [map name]
  3690. * 0 = no additional information
  3691. * 1 = Show users in that map and their location
  3692. * 2 = Shows NPCs in that map
  3693. * 3 = Shows the chats in that map
  3694. *------------------------------------------*/
  3695. ACMD_FUNC(mapinfo) {
  3696. map_session_data* pl_sd;
  3697. struct s_mapiterator* iter;
  3698. struct chat_data *cd = nullptr;
  3699. char direction[12];
  3700. int i, m_id, chat_num = 0, list = 0, vend_num = 0;
  3701. unsigned short m_index;
  3702. char mapname[MAP_NAME_LENGTH];
  3703. nullpo_retr(-1, sd);
  3704. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3705. memset(mapname, '\0', sizeof(mapname));
  3706. memset(direction, '\0', sizeof(direction));
  3707. sscanf(message, "%11d %11[^\n]", &list, mapname);
  3708. if (list < 0 || list > 3) {
  3709. clif_displaymessage(fd, msg_txt(sd,1038)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3710. return -1;
  3711. }
  3712. if (mapname[0] == '\0') {
  3713. safestrncpy(mapname, mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  3714. m_id = map_mapindex2mapid(sd->mapindex);
  3715. } else {
  3716. m_id = map_mapname2mapid(mapname);
  3717. }
  3718. if (m_id < 0) {
  3719. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  3720. return -1;
  3721. }
  3722. m_index = mapindex_name2id(mapname); //This one shouldn't fail since the previous seek did not.
  3723. clif_displaymessage(fd, msg_txt(sd,1039)); // ------ Map Info ------
  3724. // count chats (for initial message)
  3725. chat_num = 0;
  3726. iter = mapit_getallusers();
  3727. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) {
  3728. if( pl_sd->mapindex == m_index ) {
  3729. if( pl_sd->state.vending )
  3730. vend_num++;
  3731. else if( (cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != nullptr && cd->usersd[0] == pl_sd )
  3732. chat_num++;
  3733. }
  3734. }
  3735. mapit_free(iter);
  3736. struct map_data *mapdata = map_getmapdata(m_id);
  3737. sprintf(atcmd_output, msg_txt(sd,1040), mapname, mapdata->users, mapdata->npc_num, chat_num, vend_num); // Map: %s | Players: %d | NPCs: %d | Chats: %d | Vendings: %d
  3738. clif_displaymessage(fd, atcmd_output);
  3739. clif_displaymessage(fd, msg_txt(sd,1041)); // ------ Map Flags ------
  3740. if (map_getmapflag(m_id, MF_TOWN))
  3741. clif_displaymessage(fd, msg_txt(sd,1042)); // Town Map
  3742. if (map_getmapflag(m_id, MF_RESTRICTED)){
  3743. sprintf(atcmd_output, " Restricted (zone %d)",mapdata->zone);
  3744. clif_displaymessage(fd, atcmd_output);
  3745. }
  3746. if (battle_config.autotrade_mapflag == map_getmapflag(m_id, MF_AUTOTRADE))
  3747. clif_displaymessage(fd, msg_txt(sd,1043)); // Autotrade Enabled
  3748. else
  3749. clif_displaymessage(fd, msg_txt(sd,1044)); // Autotrade Disabled
  3750. if (map_getmapflag(m_id, MF_BATTLEGROUND)){
  3751. sprintf(atcmd_output, msg_txt(sd,1045),map_getmapflag(m_id, MF_BATTLEGROUND)); // Battlegrounds ON (type %d)
  3752. clif_displaymessage(fd, atcmd_output);
  3753. }
  3754. /* Skill damage adjustment info [Cydh] */
  3755. if (mapdata->getMapFlag(MF_SKILL_DAMAGE)) {
  3756. clif_displaymessage(fd,msg_txt(sd,1052)); // Skill Damage Adjustments:
  3757. sprintf(atcmd_output, msg_txt(sd, 1053), // > [Map] %d%%, %d%%, %d%%, %d%% | Caster:%d
  3758. mapdata->damage_adjust.rate[SKILLDMG_PC],
  3759. mapdata->damage_adjust.rate[SKILLDMG_MOB],
  3760. mapdata->damage_adjust.rate[SKILLDMG_BOSS],
  3761. mapdata->damage_adjust.rate[SKILLDMG_OTHER],
  3762. mapdata->damage_adjust.caster);
  3763. clif_displaymessage(fd, atcmd_output);
  3764. if (!mapdata->skill_damage.empty()) {
  3765. clif_displaymessage(fd, msg_txt(sd, 1054)); // > [Map Skill] Name : Player, Monster, Boss Monster, Other | Caster
  3766. for (const auto& skilldmg : mapdata->skill_damage) {
  3767. sprintf(atcmd_output," %s : %d%%, %d%%, %d%%, %d%% | %d",
  3768. skill_get_name(skilldmg.first),
  3769. skilldmg.second.rate[SKILLDMG_PC],
  3770. skilldmg.second.rate[SKILLDMG_MOB],
  3771. skilldmg.second.rate[SKILLDMG_BOSS],
  3772. skilldmg.second.rate[SKILLDMG_OTHER],
  3773. skilldmg.second.caster);
  3774. clif_displaymessage(fd,atcmd_output);
  3775. }
  3776. }
  3777. }
  3778. if (map_getmapflag(m_id, MF_SKILL_DURATION)) {
  3779. clif_displaymessage(fd, msg_txt(sd, 1055)); // Skill Duration Adjustments:
  3780. for (const auto &it : mapdata->skill_duration) {
  3781. sprintf(atcmd_output, " > %s : %d%%", skill_get_name(it.first), it.second);
  3782. clif_displaymessage(fd, atcmd_output);
  3783. }
  3784. }
  3785. strcpy(atcmd_output,msg_txt(sd,1046)); // PvP Flags:
  3786. if (map_getmapflag(m_id, MF_PVP))
  3787. strcat(atcmd_output, " Pvp ON |");
  3788. if (map_getmapflag(m_id, MF_PVP_NOGUILD))
  3789. strcat(atcmd_output, " NoGuild |");
  3790. if (map_getmapflag(m_id, MF_PVP_NOPARTY))
  3791. strcat(atcmd_output, " NoParty |");
  3792. if (map_getmapflag(m_id, MF_PVP_NIGHTMAREDROP))
  3793. strcat(atcmd_output, " NightmareDrop |");
  3794. if (map_getmapflag(m_id, MF_PVP_NOCALCRANK))
  3795. strcat(atcmd_output, " NoCalcRank |");
  3796. clif_displaymessage(fd, atcmd_output);
  3797. strcpy(atcmd_output,msg_txt(sd,1047)); // GvG Flags:
  3798. if (map_getmapflag(m_id, MF_GVG))
  3799. strcat(atcmd_output, " GvG ON |");
  3800. if (map_getmapflag(m_id, MF_GVG_DUNGEON))
  3801. strcat(atcmd_output, " GvG Dungeon |");
  3802. if (map_getmapflag(m_id, MF_GVG_CASTLE))
  3803. strcat(atcmd_output, " GvG Castle |");
  3804. if (map_getmapflag(m_id, MF_GVG_TE))
  3805. strcat(atcmd_output, " GvG TE |");
  3806. if (map_getmapflag(m_id, MF_GVG_TE_CASTLE))
  3807. strcat(atcmd_output, " GvG TE Castle |");
  3808. if (map_getmapflag(m_id, MF_GVG_NOPARTY))
  3809. strcat(atcmd_output, " NoParty |");
  3810. clif_displaymessage(fd, atcmd_output);
  3811. strcpy(atcmd_output,msg_txt(sd,1048)); // Teleport Flags:
  3812. if (map_getmapflag(m_id, MF_NOTELEPORT))
  3813. strcat(atcmd_output, " NoTeleport |");
  3814. if (map_getmapflag(m_id, MF_MONSTER_NOTELEPORT))
  3815. strcat(atcmd_output, " Monster NoTeleport |");
  3816. if (map_getmapflag(m_id, MF_NOWARP))
  3817. strcat(atcmd_output, " NoWarp |");
  3818. if (map_getmapflag(m_id, MF_NOWARPTO))
  3819. strcat(atcmd_output, " NoWarpTo |");
  3820. if (map_getmapflag(m_id, MF_NORETURN))
  3821. strcat(atcmd_output, " NoReturn |");
  3822. if (map_getmapflag(m_id, MF_NOGO))
  3823. strcat(atcmd_output, " NoGo |"); //
  3824. if (map_getmapflag(m_id, MF_NOMEMO))
  3825. strcat(atcmd_output, " NoMemo |");
  3826. if (map_getmapflag(m_id, MF_PRIVATEAIRSHIP_SOURCE))
  3827. strcat(atcmd_output, " PrivateAirship_Source |");
  3828. if (map_getmapflag(m_id, MF_PRIVATEAIRSHIP_DESTINATION))
  3829. strcat(atcmd_output, " PrivateAirship_Destination |");
  3830. clif_displaymessage(fd, atcmd_output);
  3831. sprintf(atcmd_output, msg_txt(sd,1065), // No Exp Penalty: %s | No Zeny Penalty: %s
  3832. (map_getmapflag(m_id, MF_NOEXPPENALTY)) ? msg_txt(sd,1066) : msg_txt(sd,1067), (map_getmapflag(m_id, MF_NOZENYPENALTY)) ? msg_txt(sd,1066) : msg_txt(sd,1067)); // On / Off
  3833. clif_displaymessage(fd, atcmd_output);
  3834. if (map_getmapflag(m_id, MF_NOSAVE)) {
  3835. if (!mapdata->save.map)
  3836. clif_displaymessage(fd, msg_txt(sd,1068)); // No Save (Return to last Save Point)
  3837. else if (mapdata->save.x == -1 || mapdata->save.y == -1 ) {
  3838. sprintf(atcmd_output, msg_txt(sd,1069), mapindex_id2name(mapdata->save.map)); // No Save, Save Point: %s,Random
  3839. clif_displaymessage(fd, atcmd_output);
  3840. }
  3841. else {
  3842. sprintf(atcmd_output, msg_txt(sd,1070), // No Save, Save Point: %s,%d,%d
  3843. mapindex_id2name(mapdata->save.map),mapdata->save.x,mapdata->save.y);
  3844. clif_displaymessage(fd, atcmd_output);
  3845. }
  3846. }
  3847. strcpy(atcmd_output,msg_txt(sd,1049)); // Weather Flags:
  3848. if (map_getmapflag(m_id, MF_SNOW))
  3849. strcat(atcmd_output, " Snow |");
  3850. if (map_getmapflag(m_id, MF_FOG))
  3851. strcat(atcmd_output, " Fog |");
  3852. if (map_getmapflag(m_id, MF_SAKURA))
  3853. strcat(atcmd_output, " Sakura |");
  3854. if (map_getmapflag(m_id, MF_CLOUDS))
  3855. strcat(atcmd_output, " Clouds |");
  3856. if (map_getmapflag(m_id, MF_CLOUDS2))
  3857. strcat(atcmd_output, " Clouds2 |");
  3858. if (map_getmapflag(m_id, MF_FIREWORKS))
  3859. strcat(atcmd_output, " Fireworks |");
  3860. if (map_getmapflag(m_id, MF_LEAVES))
  3861. strcat(atcmd_output, " Leaves |");
  3862. if (map_getmapflag(m_id, MF_NIGHTENABLED))
  3863. strcat(atcmd_output, " Displays Night |");
  3864. clif_displaymessage(fd, atcmd_output);
  3865. strcpy(atcmd_output,msg_txt(sd,1050)); // Other Flags:
  3866. if (map_getmapflag(m_id, MF_NOBRANCH))
  3867. strcat(atcmd_output, " NoBranch |");
  3868. if (map_getmapflag(m_id, MF_NOTRADE))
  3869. strcat(atcmd_output, " NoTrade |");
  3870. if (map_getmapflag(m_id, MF_NOVENDING))
  3871. strcat(atcmd_output, " NoVending |");
  3872. if (map_getmapflag(m_id, MF_NOBUYINGSTORE))
  3873. strcat(atcmd_output, " NoBuyingstore |");
  3874. if (map_getmapflag(m_id, MF_NODROP))
  3875. strcat(atcmd_output, " NoDrop |");
  3876. if (map_getmapflag(m_id, MF_NOSKILL))
  3877. strcat(atcmd_output, " NoSkill |");
  3878. if (map_getmapflag(m_id, MF_NOICEWALL))
  3879. strcat(atcmd_output, " NoIcewall |");
  3880. if (map_getmapflag(m_id, MF_ALLOWKS))
  3881. strcat(atcmd_output, " AllowKS |");
  3882. if (map_getmapflag(m_id, MF_RESET))
  3883. strcat(atcmd_output, " Reset |");
  3884. if (map_getmapflag(m_id, MF_HIDEMOBHPBAR))
  3885. strcat(atcmd_output, " HideMobHPBar |");
  3886. if (map_getmapflag(m_id, MF_NOCOMMAND))
  3887. strcat(atcmd_output, " NoCommand |");
  3888. if (map_getmapflag(m_id, MF_NOBASEEXP))
  3889. strcat(atcmd_output, " NoBaseEXP |");
  3890. if (map_getmapflag(m_id, MF_NOJOBEXP))
  3891. strcat(atcmd_output, " NoJobEXP |");
  3892. if (map_getmapflag(m_id, MF_NOMOBLOOT))
  3893. strcat(atcmd_output, " NoMobLoot |");
  3894. if (map_getmapflag(m_id, MF_NOMVPLOOT))
  3895. strcat(atcmd_output, " NoMVPLoot |");
  3896. if (map_getmapflag(m_id, MF_NORENEWALEXPPENALTY))
  3897. strcat(atcmd_output, " NoRenewalExpPenalty |");
  3898. if (map_getmapflag(m_id, MF_NORENEWALDROPPENALTY))
  3899. strcat(atcmd_output, " NoRenewalDropPenalty |");
  3900. if (map_getmapflag(m_id, MF_PARTYLOCK))
  3901. strcat(atcmd_output, " PartyLock |");
  3902. if (map_getmapflag(m_id, MF_GUILDLOCK))
  3903. strcat(atcmd_output, " GuildLock |");
  3904. if (map_getmapflag(m_id, MF_LOADEVENT))
  3905. strcat(atcmd_output, " Loadevent |");
  3906. if (map_getmapflag(m_id, MF_NODYNAMICNPC))
  3907. strcat(atcmd_output, " NoDynamicNPC |");
  3908. if (map_getmapflag(m_id, MF_NOMAPCHANNELAUTOJOIN))
  3909. strcat(atcmd_output, " NoMapChannelAutoJoin |");
  3910. if (map_getmapflag(m_id, MF_NOUSECART))
  3911. strcat(atcmd_output, " NoUsecart |");
  3912. if (map_getmapflag(m_id, MF_NOITEMCONSUMPTION))
  3913. strcat(atcmd_output, " NoItemConsumption |");
  3914. if (map_getmapflag(m_id, MF_NOSUNMOONSTARMIRACLE))
  3915. strcat(atcmd_output, " NoSunMoonStarMiracle |");
  3916. if (map_getmapflag(m_id, MF_FORCEMINEFFECT))
  3917. strcat(atcmd_output, " ForceMinEffect |");
  3918. if (map_getmapflag(m_id, MF_NOLOCKON))
  3919. strcat(atcmd_output, " NoLockOn |");
  3920. if (map_getmapflag(m_id, MF_NOTOMB))
  3921. strcat(atcmd_output, " NoTomb |");
  3922. if (map_getmapflag(m_id, MF_NOCOSTUME))
  3923. strcat(atcmd_output, " NoCostume |");
  3924. if (map_getmapflag(m_id, MF_NOBANK))
  3925. strcat(atcmd_output, " NoBank |");
  3926. if (map_getmapflag(m_id, MF_NOCASHSHOP))
  3927. strcat(atcmd_output, " NoCashShop |");
  3928. if (map_getmapflag(m_id, MF_NORODEX))
  3929. strcat(atcmd_output, " NoRODex |");
  3930. if (map_getmapflag(m_id, MF_NOPETCAPTURE))
  3931. strcat(atcmd_output, " NoPetCapture |");
  3932. clif_displaymessage(fd, atcmd_output);
  3933. switch (list) {
  3934. case 0:
  3935. // Do nothing. It's list 0, no additional display.
  3936. break;
  3937. case 1:
  3938. clif_displaymessage(fd, msg_txt(sd,480)); // ----- Players in Map -----
  3939. iter = mapit_getallusers();
  3940. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3941. {
  3942. if (pl_sd->mapindex == m_index) {
  3943. sprintf(atcmd_output, msg_txt(sd,481), // Player '%s' (session #%d) | Location: %d,%d
  3944. pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y);
  3945. clif_displaymessage(fd, atcmd_output);
  3946. }
  3947. }
  3948. mapit_free(iter);
  3949. break;
  3950. case 2:
  3951. clif_displaymessage(fd, msg_txt(sd,482)); // ----- NPCs in Map -----
  3952. for (i = 0; i < mapdata->npc_num;)
  3953. {
  3954. struct npc_data *nd = mapdata->npc[i];
  3955. switch(nd->ud.dir) {
  3956. case DIR_NORTH: strcpy(direction, msg_txt(sd,491)); break; // North
  3957. case DIR_NORTHWEST: strcpy(direction, msg_txt(sd,492)); break; // North West
  3958. case DIR_WEST: strcpy(direction, msg_txt(sd,493)); break; // West
  3959. case DIR_SOUTHWEST: strcpy(direction, msg_txt(sd,494)); break; // South West
  3960. case DIR_SOUTH: strcpy(direction, msg_txt(sd,495)); break; // South
  3961. case DIR_SOUTHEAST: strcpy(direction, msg_txt(sd,496)); break; // South East
  3962. case DIR_EAST: strcpy(direction, msg_txt(sd,497)); break; // East
  3963. case DIR_NORTHEAST: strcpy(direction, msg_txt(sd,498)); break; // North East
  3964. default: strcpy(direction, msg_txt(sd,499)); break; // Unknown
  3965. }
  3966. if(strcmp(nd->name,nd->exname) == 0)
  3967. sprintf(atcmd_output, msg_txt(sd,490), // NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d
  3968. ++i, nd->name, direction, nd->class_, nd->bl.x, nd->bl.y);
  3969. else
  3970. sprintf(atcmd_output, msg_txt(sd,489), // NPC %d: %s::%s | Direction: %s | Sprite: %d | Location: %d %d
  3971. ++i, nd->name, nd->exname, direction, nd->class_, nd->bl.x, nd->bl.y);
  3972. clif_displaymessage(fd, atcmd_output);
  3973. }
  3974. break;
  3975. case 3:
  3976. clif_displaymessage(fd, msg_txt(sd,483)); // ----- Chats in Map -----
  3977. iter = mapit_getallusers();
  3978. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3979. {
  3980. if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != nullptr &&
  3981. pl_sd->mapindex == m_index &&
  3982. cd->usersd[0] == pl_sd)
  3983. {
  3984. sprintf(atcmd_output, msg_txt(sd,484), // Chat: %s | Player: %s | Location: %d %d
  3985. cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y);
  3986. clif_displaymessage(fd, atcmd_output);
  3987. sprintf(atcmd_output, msg_txt(sd,485), // Users: %d/%d | Password: %s | Public: %s
  3988. cd->users, cd->limit, cd->pass, (cd->pub) ? msg_txt(sd,486) : msg_txt(sd,487)); // Yes / No
  3989. clif_displaymessage(fd, atcmd_output);
  3990. }
  3991. }
  3992. mapit_free(iter);
  3993. break;
  3994. default: // normally impossible to arrive here
  3995. clif_displaymessage(fd, msg_txt(sd,488)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3996. return -1;
  3997. break;
  3998. }
  3999. return 0;
  4000. }
  4001. /*==========================================
  4002. *
  4003. *------------------------------------------*/
  4004. ACMD_FUNC(mount_peco)
  4005. {
  4006. nullpo_retr(-1, sd);
  4007. if (sd->disguise) {
  4008. clif_displaymessage(fd, msg_txt(sd,212)); // Cannot mount while in disguise.
  4009. return -1;
  4010. }
  4011. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT && pc_checkskill(sd,RK_DRAGONTRAINING) > 0 ) {
  4012. if( !(sd->sc.option&OPTION_DRAGON) ) {
  4013. unsigned int option = OPTION_DRAGON1;
  4014. if( message[0] ) {
  4015. int color = atoi(message);
  4016. option = ( color == 2 ? OPTION_DRAGON2 :
  4017. color == 3 ? OPTION_DRAGON3 :
  4018. color == 4 ? OPTION_DRAGON4 :
  4019. color == 5 ? OPTION_DRAGON5 :
  4020. OPTION_DRAGON1 );
  4021. }
  4022. clif_displaymessage(sd->fd,msg_txt(sd,1119)); // You have mounted your Dragon.
  4023. pc_setoption(sd, sd->sc.option|option);
  4024. } else {
  4025. clif_displaymessage(sd->fd,msg_txt(sd,1120)); // You have released your Dragon.
  4026. pc_setoption(sd, sd->sc.option&~OPTION_DRAGON);
  4027. }
  4028. return 0;
  4029. }
  4030. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER && pc_checkskill(sd,RA_WUGRIDER) > 0 && (!pc_isfalcon(sd) || (pc_checkskill(sd, WH_HAWK_M) || battle_config.warg_can_falcon)) ) {
  4031. if( !pc_isridingwug(sd) ) {
  4032. clif_displaymessage(sd->fd,msg_txt(sd,1121)); // You have mounted your Warg.
  4033. pc_setoption(sd, sd->sc.option|OPTION_WUGRIDER);
  4034. } else {
  4035. clif_displaymessage(sd->fd,msg_txt(sd,1122)); // You have released your Warg.
  4036. pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
  4037. }
  4038. return 0;
  4039. }
  4040. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  4041. if( !pc_ismadogear(sd) ) {
  4042. e_mado_type type = MADO_ROBOT;
  4043. if (message[0]) {
  4044. int tmp = strtol(message, nullptr, 10);
  4045. switch (tmp) {
  4046. case MADO_ROBOT:
  4047. case MADO_SUIT:
  4048. type = static_cast<e_mado_type>(tmp);
  4049. break;
  4050. default:
  4051. type = MADO_ROBOT;
  4052. break;
  4053. }
  4054. }
  4055. clif_displaymessage(sd->fd,msg_txt(sd,1123)); // You have mounted your Mado Gear.
  4056. pc_setmadogear(sd, true, type);
  4057. } else {
  4058. clif_displaymessage(sd->fd,msg_txt(sd,1124)); // You have released your Mado Gear.
  4059. pc_setmadogear(sd, false);
  4060. }
  4061. return 0;
  4062. }
  4063. if (!pc_isriding(sd)) { // if actually no peco
  4064. if (!pc_checkskill(sd, KN_RIDING)) {
  4065. clif_displaymessage(fd, msg_txt(sd,213)); // You can not mount a Peco Peco with your current job.
  4066. return -1;
  4067. }
  4068. pc_setoption(sd, sd->sc.option | OPTION_RIDING);
  4069. clif_displaymessage(fd, msg_txt(sd,102)); // You have mounted a Peco Peco.
  4070. } else {//Dismount
  4071. pc_setoption(sd, sd->sc.option & ~OPTION_RIDING);
  4072. clif_displaymessage(fd, msg_txt(sd,214)); // You have released your Peco Peco.
  4073. }
  4074. return 0;
  4075. }
  4076. /*==========================================
  4077. *Spy Commands by Syrus22
  4078. *------------------------------------------*/
  4079. ACMD_FUNC(guildspy)
  4080. {
  4081. char guild_name[NAME_LENGTH];
  4082. nullpo_retr(-1, sd);
  4083. memset(guild_name, '\0', sizeof(guild_name));
  4084. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4085. if (!enable_spy)
  4086. {
  4087. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
  4088. return -1;
  4089. }
  4090. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4091. clif_displaymessage(fd, msg_txt(sd,1126)); // Please enter a guild name/ID (usage: @guildspy <guild_name/ID>).
  4092. return -1;
  4093. }
  4094. auto g = guild_searchnameid(guild_name);
  4095. if (!g) {
  4096. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the specified guild is online.
  4097. return -1;
  4098. }
  4099. if (sd->guildspy == g->guild.guild_id) {
  4100. sd->guildspy = 0;
  4101. sprintf(atcmd_output, msg_txt(sd,103), g->guild.name); // No longer spying on the %s guild.
  4102. clif_displaymessage(fd, atcmd_output);
  4103. } else {
  4104. sd->guildspy = g->guild.guild_id;
  4105. sprintf(atcmd_output, msg_txt(sd,104), g->guild.name); // Spying on the %s guild.
  4106. clif_displaymessage(fd, atcmd_output);
  4107. }
  4108. return 0;
  4109. }
  4110. /*==========================================
  4111. *
  4112. *------------------------------------------*/
  4113. ACMD_FUNC(partyspy)
  4114. {
  4115. char party_name[NAME_LENGTH];
  4116. struct party_data *p;
  4117. nullpo_retr(-1, sd);
  4118. memset(party_name, '\0', sizeof(party_name));
  4119. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4120. if (!enable_spy)
  4121. {
  4122. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
  4123. return -1;
  4124. }
  4125. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  4126. clif_displaymessage(fd, msg_txt(sd,1127)); // Please enter a party name/ID (usage: @partyspy <party_name/ID>).
  4127. return -1;
  4128. }
  4129. if ((p = party_searchname(party_name)) != nullptr || // name first to avoid error when name begin with a number
  4130. (p = party_search(atoi(message))) != nullptr) {
  4131. if (sd->partyspy == p->party.party_id) {
  4132. sd->partyspy = 0;
  4133. sprintf(atcmd_output, msg_txt(sd,105), p->party.name); // No longer spying on the %s party.
  4134. clif_displaymessage(fd, atcmd_output);
  4135. } else {
  4136. sd->partyspy = p->party.party_id;
  4137. sprintf(atcmd_output, msg_txt(sd,106), p->party.name); // Spying on the %s party.
  4138. clif_displaymessage(fd, atcmd_output);
  4139. }
  4140. } else {
  4141. clif_displaymessage(fd, msg_txt(sd,96)); // Incorrect name/ID, or no one from the specified party is online.
  4142. return -1;
  4143. }
  4144. return 0;
  4145. }
  4146. ACMD_FUNC(clanspy){
  4147. char clan_name[NAME_LENGTH];
  4148. struct clan* c;
  4149. nullpo_retr(-1, sd);
  4150. memset(clan_name, '\0', sizeof(clan_name));
  4151. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4152. if( !enable_spy ){
  4153. clif_displaymessage(fd, msg_txt(sd, 1125)); // The mapserver has spy command support disabled.
  4154. return -1;
  4155. }
  4156. if( !message || !*message || sscanf( message, "%23[^\n]", clan_name ) < 1 ){
  4157. clif_displaymessage(fd, msg_txt(sd, 1499)); // Please enter a clan name/ID (usage: @clanspy <clan_name/ID>).
  4158. return -1;
  4159. }
  4160. if ((c = clan_searchname(clan_name)) != nullptr || // name first to avoid error when name begin with a number
  4161. (c = clan_search(atoi(message))) != nullptr) {
  4162. if (sd->clanspy == c->id) {
  4163. sd->clanspy = 0;
  4164. sprintf(atcmd_output, msg_txt(sd, 1500), c->name); // No longer spying on the %s clan.
  4165. clif_displaymessage(fd, atcmd_output);
  4166. }
  4167. else {
  4168. sd->clanspy = c->id;
  4169. sprintf(atcmd_output, msg_txt(sd, 1501), c->name); // Spying on the %s clan.
  4170. clif_displaymessage(fd, atcmd_output);
  4171. }
  4172. }
  4173. else {
  4174. clif_displaymessage(fd, msg_txt(sd, 1502)); // Incorrect clan name/ID.
  4175. return -1;
  4176. }
  4177. return 0;
  4178. }
  4179. /*==========================================
  4180. * @repairall [Valaris]
  4181. *------------------------------------------*/
  4182. ACMD_FUNC(repairall)
  4183. {
  4184. int count, i;
  4185. nullpo_retr(-1, sd);
  4186. count = 0;
  4187. for (i = 0; i < MAX_INVENTORY; i++) {
  4188. if (sd->inventory.u.items_inventory[i].nameid && sd->inventory.u.items_inventory[i].attribute == 1 && !itemdb_ishatched_egg(&sd->inventory.u.items_inventory[i])) {
  4189. sd->inventory.u.items_inventory[i].attribute = 0;
  4190. clif_produceeffect(sd, 0, sd->inventory.u.items_inventory[i].nameid);
  4191. count++;
  4192. }
  4193. }
  4194. if (count > 0) {
  4195. clif_misceffect(&sd->bl, 3);
  4196. clif_equiplist(sd);
  4197. clif_displaymessage(fd, msg_txt(sd,107)); // All items have been repaired.
  4198. } else {
  4199. clif_displaymessage(fd, msg_txt(sd,108)); // No item need to be repaired.
  4200. return -1;
  4201. }
  4202. return 0;
  4203. }
  4204. /*==========================================
  4205. * @nuke [Valaris]
  4206. *------------------------------------------*/
  4207. ACMD_FUNC(nuke)
  4208. {
  4209. map_session_data *pl_sd;
  4210. nullpo_retr(-1, sd);
  4211. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4212. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4213. clif_displaymessage(fd, msg_txt(sd,1128)); // Please enter a player name (usage: @nuke <char name>).
  4214. return -1;
  4215. }
  4216. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) != nullptr) {
  4217. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level
  4218. skill_castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, gettick(), 0);
  4219. clif_displaymessage(fd, msg_txt(sd,109)); // Player has been nuked!
  4220. } else {
  4221. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  4222. return -1;
  4223. }
  4224. } else {
  4225. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4226. return -1;
  4227. }
  4228. return 0;
  4229. }
  4230. /*==========================================
  4231. * @tonpc
  4232. *------------------------------------------*/
  4233. ACMD_FUNC(tonpc)
  4234. {
  4235. char npcname[NPC_NAME_LENGTH];
  4236. struct npc_data *nd;
  4237. nullpo_retr(-1, sd);
  4238. memset(npcname, 0, sizeof(npcname));
  4239. if (!message || !*message || sscanf(message, "%49[^\n]", npcname) < 1) {
  4240. clif_displaymessage(fd, msg_txt(sd,1129)); // Please enter a NPC name (usage: @tonpc <NPC_name>).
  4241. return -1;
  4242. }
  4243. if ((nd = npc_name2id(npcname)) != nullptr) {
  4244. if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == SETPOS_OK)
  4245. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  4246. else
  4247. return -1;
  4248. } else {
  4249. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4250. return -1;
  4251. }
  4252. return 0;
  4253. }
  4254. /*==========================================
  4255. *
  4256. *------------------------------------------*/
  4257. ACMD_FUNC(shownpc)
  4258. {
  4259. char NPCname[NPC_NAME_LENGTH];
  4260. nullpo_retr(-1, sd);
  4261. memset(NPCname, '\0', sizeof(NPCname));
  4262. if (!message || !*message || sscanf(message, "%49[^\n]", NPCname) < 1) {
  4263. clif_displaymessage(fd, msg_txt(sd,1130)); // Please enter a NPC name (usage: @enablenpc <NPC_name>).
  4264. return -1;
  4265. }
  4266. npc_data* nd = npc_name2id(NPCname);
  4267. if (nd) {
  4268. npc_enable(*nd, NPCVIEW_ENABLE);
  4269. clif_displaymessage(fd, msg_txt(sd,110)); // Npc Enabled.
  4270. } else {
  4271. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4272. return -1;
  4273. }
  4274. return 0;
  4275. }
  4276. /*==========================================
  4277. *
  4278. *------------------------------------------*/
  4279. ACMD_FUNC(hidenpc)
  4280. {
  4281. char NPCname[NPC_NAME_LENGTH];
  4282. nullpo_retr(-1, sd);
  4283. memset(NPCname, '\0', sizeof(NPCname));
  4284. if (!message || !*message || sscanf(message, "%49[^\n]", NPCname) < 1) {
  4285. clif_displaymessage(fd, msg_txt(sd,1131)); // Please enter a NPC name (usage: @hidenpc <NPC_name>).
  4286. return -1;
  4287. }
  4288. npc_data* nd = npc_name2id(NPCname);
  4289. if (!nd) {
  4290. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4291. return -1;
  4292. }
  4293. npc_enable(*nd, NPCVIEW_DISABLE);
  4294. clif_displaymessage(fd, msg_txt(sd,112)); // Npc Disabled.
  4295. return 0;
  4296. }
  4297. ACMD_FUNC(loadnpc)
  4298. {
  4299. if (!message || !*message) {
  4300. clif_displaymessage(fd, msg_txt(sd,1132)); // Please enter a script file name (usage: @loadnpc <file name>).
  4301. return -1;
  4302. }
  4303. if (!npc_addsrcfile(message, true)) {
  4304. clif_displaymessage(fd, msg_txt(sd,261)); // Script could not be loaded.
  4305. return -1;
  4306. }
  4307. npc_read_event_script();
  4308. ShowStatus( "NPC file '" CL_WHITE "%s" CL_RESET "' was loaded.\n", message );
  4309. npc_event_doall_path( script_config.init_event_name, message );
  4310. clif_displaymessage(fd, msg_txt(sd,262)); // Script loaded.
  4311. return 0;
  4312. }
  4313. ACMD_FUNC(unloadnpc)
  4314. {
  4315. struct npc_data *nd;
  4316. char NPCname[NPC_NAME_LENGTH];
  4317. nullpo_retr(-1, sd);
  4318. memset(NPCname, '\0', sizeof(NPCname));
  4319. if (!message || !*message || sscanf(message, "%49[^\n]", NPCname) < 1) {
  4320. clif_displaymessage(fd, msg_txt(sd,1133)); // Please enter a NPC name (usage: @unloadnpc <NPC_name>).
  4321. return -1;
  4322. }
  4323. if ((nd = npc_name2id(NPCname)) == nullptr) {
  4324. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4325. return -1;
  4326. }
  4327. npc_unload_duplicates(nd);
  4328. npc_unload(nd,true);
  4329. npc_read_event_script();
  4330. clif_displaymessage(fd, msg_txt(sd,112)); // Npc Disabled.
  4331. return 0;
  4332. }
  4333. ACMD_FUNC(reloadnpcfile) {
  4334. if (!message || !*message) {
  4335. clif_displaymessage(fd, msg_txt(sd,733)); // Please enter a NPC file name (usage: @reloadnpcfile <file name>).
  4336. return -1;
  4337. }
  4338. if (npc_unloadfile(message))
  4339. clif_displaymessage(fd, msg_txt(sd,1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
  4340. if (!npc_addsrcfile(message, true)) {
  4341. clif_displaymessage(fd, msg_txt(sd,261)); // Script could not be loaded.
  4342. return -1;
  4343. }
  4344. npc_read_event_script();
  4345. ShowStatus( "NPC file '" CL_WHITE "%s" CL_RESET "' was reloaded.\n", message );
  4346. npc_event_doall_path( script_config.init_event_name, message );
  4347. clif_displaymessage(fd, msg_txt(sd,262)); // Script loaded.
  4348. return 0;
  4349. }
  4350. /*==========================================
  4351. * time in txt for time command (by [Yor])
  4352. *------------------------------------------*/
  4353. char* txt_time(t_tick duration_)
  4354. {
  4355. int days, hours, minutes, seconds;
  4356. char temp[CHAT_SIZE_MAX];
  4357. static char temp1[CHAT_SIZE_MAX];
  4358. memset(temp, '\0', sizeof(temp));
  4359. memset(temp1, '\0', sizeof(temp1));
  4360. // Cap it
  4361. int duration = (int)duration_;
  4362. days = duration / (60 * 60 * 24);
  4363. duration = duration - (60 * 60 * 24 * days);
  4364. hours = duration / (60 * 60);
  4365. duration = duration - (60 * 60 * hours);
  4366. minutes = duration / 60;
  4367. seconds = duration - (60 * minutes);
  4368. if (days == 1)
  4369. sprintf(temp, msg_txt(nullptr,219), days); // %d day
  4370. else if (days > 1)
  4371. sprintf(temp, msg_txt(nullptr,220), days); // %d days
  4372. if (hours == 1)
  4373. sprintf(temp1, msg_txt(nullptr,221), temp, hours); // %s %d hour
  4374. else if (hours > 1)
  4375. sprintf(temp1, msg_txt(nullptr,222), temp, hours); // %s %d hours
  4376. if (minutes < 2)
  4377. sprintf(temp, msg_txt(nullptr,223), temp1, minutes); // %s %d minute
  4378. else
  4379. sprintf(temp, msg_txt(nullptr,224), temp1, minutes); // %s %d minutes
  4380. if (seconds == 1)
  4381. sprintf(temp1, msg_txt(nullptr,225), temp, seconds); // %s and %d second
  4382. else if (seconds > 1)
  4383. sprintf(temp1, msg_txt(nullptr,226), temp, seconds); // %s and %d seconds
  4384. return temp1;
  4385. }
  4386. /*==========================================
  4387. * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor]
  4388. * Calculation management of GM modification (@day/@night GM commands) is done
  4389. *------------------------------------------*/
  4390. ACMD_FUNC(servertime)
  4391. {
  4392. const struct TimerData * timer_data;
  4393. time_t time_server; // variable for number of seconds (used with time() function)
  4394. struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
  4395. char temp[CHAT_SIZE_MAX];
  4396. nullpo_retr(-1, sd);
  4397. memset(temp, '\0', sizeof(temp));
  4398. time(&time_server); // get time in seconds since 1/1/1970
  4399. datetime = localtime(&time_server); // convert seconds in structure
  4400. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  4401. strftime(temp, sizeof(temp)-1, msg_txt(sd,230), datetime); // Server time (normal time): %A, %B %d %Y %X.
  4402. clif_displaymessage(fd, temp);
  4403. if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
  4404. if (night_flag == 0)
  4405. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
  4406. else
  4407. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  4408. } else if (battle_config.night_duration == 0)
  4409. if (night_flag == 1) { // we start with night
  4410. if ((timer_data = get_timer(day_timer_tid)) != nullptr) {
  4411. sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in night for %s.
  4412. clif_displaymessage(fd, temp);
  4413. clif_displaymessage(fd, msg_txt(sd,234)); // Game time: After, the game will be in permanent daylight.
  4414. } else
  4415. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  4416. } else
  4417. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
  4418. else if (battle_config.day_duration == 0)
  4419. if (night_flag == 0) { // we start with day
  4420. if ((timer_data = get_timer(night_timer_tid)) != nullptr) {
  4421. sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s.
  4422. clif_displaymessage(fd, temp);
  4423. clif_displaymessage(fd, msg_txt(sd,236)); // Game time: After, the game will be in permanent night.
  4424. } else
  4425. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
  4426. } else
  4427. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  4428. else {
  4429. const struct TimerData * timer_data2;
  4430. if (night_flag == 0) {
  4431. if ((timer_data = get_timer(night_timer_tid)) != nullptr && (timer_data2 = get_timer(day_timer_tid)) != nullptr) {
  4432. sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s.
  4433. clif_displaymessage(fd, temp);
  4434. if (DIFF_TICK(timer_data->tick, timer_data2->tick) > 0)
  4435. sprintf(temp, msg_txt(sd,237), txt_time(DIFF_TICK(timer_data->interval,DIFF_TICK(timer_data->tick,timer_data2->tick)) / 1000)); // Game time: After, the game will be in night for %s.
  4436. else
  4437. sprintf(temp, msg_txt(sd,237), txt_time(DIFF_TICK(timer_data2->tick,timer_data->tick)/1000)); // Game time: After, the game will be in night for %s.
  4438. clif_displaymessage(fd, temp);
  4439. sprintf(temp, msg_txt(sd,238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4440. clif_displaymessage(fd, temp);
  4441. } else
  4442. clif_displaymessage(fd, msg_txt(sd, 231)); // Game time: The game is in permanent daylight.
  4443. } else {
  4444. if ((timer_data = get_timer(day_timer_tid)) != nullptr && (timer_data2 = get_timer(night_timer_tid)) != nullptr) {
  4445. sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick()) / 1000)); // Game time: The game is in night for %s.
  4446. clif_displaymessage(fd, temp);
  4447. if (DIFF_TICK(timer_data->tick,timer_data2->tick) > 0)
  4448. sprintf(temp, msg_txt(sd,239), txt_time((timer_data->interval - DIFF_TICK(timer_data->tick, timer_data2->tick)) / 1000)); // Game time: After, the game will be in daylight for %s.
  4449. else
  4450. sprintf(temp, msg_txt(sd,239), txt_time(DIFF_TICK(timer_data2->tick, timer_data->tick) / 1000)); // Game time: After, the game will be in daylight for %s.
  4451. clif_displaymessage(fd, temp);
  4452. sprintf(temp, msg_txt(sd,238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  4453. clif_displaymessage(fd, temp);
  4454. } else
  4455. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  4456. }
  4457. }
  4458. return 0;
  4459. }
  4460. /*==========================================
  4461. * @jail <char_name> by [Yor]
  4462. * Special warp! No check with nowarp and nowarpto flag
  4463. *------------------------------------------*/
  4464. ACMD_FUNC(jail)
  4465. {
  4466. map_session_data *pl_sd;
  4467. nullpo_retr(-1, sd);
  4468. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4469. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4470. clif_displaymessage(fd, msg_txt(sd,1134)); // Please enter a player name (usage: @jail <char_name>).
  4471. return -1;
  4472. }
  4473. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  4474. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4475. return -1;
  4476. }
  4477. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  4478. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  4479. return -1;
  4480. }
  4481. if (pl_sd->sc.getSCE(SC_JAILED)) {
  4482. clif_displaymessage(fd, msg_txt(sd,118)); // Player warped in jails.
  4483. return -1;
  4484. }
  4485. pc_jail(*pl_sd);
  4486. clif_displaymessage(pl_sd->fd, msg_txt(sd,117)); // GM has send you in jails.
  4487. clif_displaymessage(fd, msg_txt(sd,118)); // Player warped in jails.
  4488. return 0;
  4489. }
  4490. /*==========================================
  4491. * @unjail/@discharge <char_name> by [Yor]
  4492. * Special warp! No check with nowarp and nowarpto flag
  4493. *------------------------------------------*/
  4494. ACMD_FUNC(unjail)
  4495. {
  4496. map_session_data *pl_sd;
  4497. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4498. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4499. clif_displaymessage(fd, msg_txt(sd,1135)); // Please enter a player name (usage: @unjail/@discharge <char_name>).
  4500. return -1;
  4501. }
  4502. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  4503. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4504. return -1;
  4505. }
  4506. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  4507. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  4508. return -1;
  4509. }
  4510. if (!pl_sd->sc.getSCE(SC_JAILED)) {
  4511. clif_displaymessage(fd, msg_txt(sd,119)); // This player is not in jails.
  4512. return -1;
  4513. }
  4514. //Reset jail time to 1 sec.
  4515. pc_jail(*pl_sd, 0);
  4516. clif_displaymessage(pl_sd->fd, msg_txt(sd,120)); // A GM has discharged you from jail.
  4517. clif_displaymessage(fd, msg_txt(sd,121)); // Player unjailed.
  4518. return 0;
  4519. }
  4520. ACMD_FUNC(jailfor) {
  4521. map_session_data* pl_sd = nullptr;;
  4522. char * modif_p;
  4523. int jailtime = 0;
  4524. nullpo_retr(-1, sd);
  4525. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4526. if (!message || !*message || sscanf(message, "%255s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  4527. clif_displaymessage(fd, msg_txt(sd,400)); //Usage: @jailfor <time> <character name>
  4528. return -1;
  4529. }
  4530. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  4531. modif_p = atcmd_output;
  4532. jailtime = (int)solve_time(modif_p)/60; // Change to minutes
  4533. if (jailtime == 0) {
  4534. clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
  4535. clif_displaymessage(fd, msg_txt(sd,702)); // Time parameter format is +/-<value> to alter. y/a = Year, m = Month, d/j = Day, h = Hour, n/mn = Minute, s = Second.
  4536. return -1;
  4537. }
  4538. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  4539. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4540. return -1;
  4541. }
  4542. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  4543. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  4544. return -1;
  4545. }
  4546. // Added by Coltaro
  4547. if(pl_sd->sc.getSCE(SC_JAILED) && pl_sd->sc.getSCE(SC_JAILED)->val1 != INT_MAX) { // Update the player's jail time
  4548. jailtime += pl_sd->sc.getSCE(SC_JAILED)->val1;
  4549. if (jailtime <= 0) {
  4550. jailtime = 0;
  4551. clif_displaymessage(pl_sd->fd, msg_txt(sd,120)); // GM has discharge you.
  4552. clif_displaymessage(fd, msg_txt(sd,121)); // Player unjailed
  4553. } else {
  4554. int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
  4555. char timestr[21];
  4556. time_t now=time(nullptr);
  4557. split_time(jailtime*60,&year,&month,&day,&hour,&minute,&second);
  4558. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1137),year,month,day,hour,minute); // %s in jail for %d years, %d months, %d days, %d hours and %d minutes
  4559. clif_displaymessage(pl_sd->fd, atcmd_output);
  4560. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1138),year,month,day,hour,minute); // This player is now in jail for %d years, %d months, %d days, %d hours and %d minutes
  4561. clif_displaymessage(fd, atcmd_output);
  4562. timestamp2string(timestr,20,now+jailtime*60,"%Y-%m-%d %H:%M");
  4563. sprintf(atcmd_output,"Release date is: %s",timestr);
  4564. clif_displaymessage(pl_sd->fd, atcmd_output);
  4565. clif_displaymessage(fd, atcmd_output);
  4566. }
  4567. } else if (jailtime < 0) {
  4568. clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
  4569. return -1;
  4570. }
  4571. pc_jail(*pl_sd, jailtime);
  4572. return 0;
  4573. }
  4574. //By Coltaro
  4575. ACMD_FUNC(jailtime){
  4576. int year, month, day, hour, minute, second;
  4577. char timestr[21];
  4578. time_t now = time(nullptr);
  4579. nullpo_retr(-1, sd);
  4580. if (!sd->sc.getSCE(SC_JAILED)) {
  4581. clif_displaymessage(fd, msg_txt(sd,1139)); // You are not in jail.
  4582. return -1;
  4583. }
  4584. if (sd->sc.getSCE(SC_JAILED)->val1 == INT_MAX) {
  4585. clif_displaymessage(fd, msg_txt(sd,1140)); // You have been jailed indefinitely.
  4586. return 0;
  4587. }
  4588. if (sd->sc.getSCE(SC_JAILED)->val1 <= 0) { // Was not jailed with @jailfor (maybe @jail? or warped there? or got recalled?)
  4589. clif_displaymessage(fd, msg_txt(sd,1141)); // You have been jailed for an unknown amount of time.
  4590. return -1;
  4591. }
  4592. // Get remaining jail time
  4593. split_time(sd->sc.getSCE(SC_JAILED)->val1*60,&year,&month,&day,&hour,&minute,&second);
  4594. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1142),year,month,day,hour,minute); // You will remain in jail for %d years, %d months, %d days, %d hours and %d minutes
  4595. clif_displaymessage(fd, atcmd_output);
  4596. timestamp2string(timestr,20,now+sd->sc.getSCE(SC_JAILED)->val1*60,"%Y-%m-%d %H:%M");
  4597. sprintf(atcmd_output,"Release date is: %s",timestr);
  4598. clif_displaymessage(fd, atcmd_output);
  4599. return 0;
  4600. }
  4601. /*==========================================
  4602. * @disguise <mob_id> by [Valaris] (simplified by [Yor])
  4603. *------------------------------------------*/
  4604. ACMD_FUNC(disguise)
  4605. {
  4606. int id = 0;
  4607. nullpo_retr(-1, sd);
  4608. if (!message || !*message) {
  4609. clif_displaymessage(fd, msg_txt(sd,1143)); // Please enter a Monster/NPC name/ID (usage: @disguise <name/ID>).
  4610. return -1;
  4611. }
  4612. if ((id = atoi(message)) > 0)
  4613. { //Acquired an ID
  4614. if (!mobdb_checkid(id) && !npcdb_checkid(id))
  4615. id = 0; //Invalid id for either mobs or npcs.
  4616. } else { //Acquired a Name
  4617. if ((id = mobdb_searchname(message)) == 0)
  4618. {
  4619. struct npc_data* nd = npc_name2id(message);
  4620. if (nd != nullptr)
  4621. id = nd->class_;
  4622. }
  4623. }
  4624. if (id == 0)
  4625. {
  4626. clif_displaymessage(fd, msg_txt(sd,123)); // Invalid Monster/NPC name/ID specified.
  4627. return -1;
  4628. }
  4629. if(pc_isriding(sd))
  4630. {
  4631. clif_displaymessage(fd, msg_txt(sd,1144)); // Character cannot be disguised while mounted.
  4632. return -1;
  4633. }
  4634. if (sd->sc.getSCE(SC_MONSTER_TRANSFORM) || sd->sc.getSCE(SC_ACTIVE_MONSTER_TRANSFORM)) {
  4635. clif_displaymessage(fd, msg_txt(sd,730)); // Character cannot be disguised while in monster transform.
  4636. return -1;
  4637. }
  4638. pc_disguise(sd, id);
  4639. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4640. return 0;
  4641. }
  4642. /*==========================================
  4643. * DisguiseAll
  4644. *------------------------------------------*/
  4645. ACMD_FUNC(disguiseall)
  4646. {
  4647. int mob_id=0;
  4648. map_session_data *pl_sd;
  4649. struct s_mapiterator* iter;
  4650. nullpo_retr(-1, sd);
  4651. if (!message || !*message) {
  4652. clif_displaymessage(fd, msg_txt(sd,1145)); // Please enter a Monster/NPC name/ID (usage: @disguiseall <name/ID>).
  4653. return -1;
  4654. }
  4655. if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name beginning by a number)
  4656. mob_id = atoi(message);
  4657. if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
  4658. clif_displaymessage(fd, msg_txt(sd,123)); // Monster/NPC name/id not found.
  4659. return -1;
  4660. }
  4661. iter = mapit_getallusers();
  4662. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4663. pc_disguise(pl_sd, mob_id);
  4664. mapit_free(iter);
  4665. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4666. return 0;
  4667. }
  4668. /*==========================================
  4669. * DisguiseGuild
  4670. *------------------------------------------*/
  4671. ACMD_FUNC(disguiseguild)
  4672. {
  4673. int id = 0, i;
  4674. char monster[NAME_LENGTH], guild[NAME_LENGTH];
  4675. memset(monster, '\0', sizeof(monster));
  4676. memset(guild, '\0', sizeof(guild));
  4677. if( !message || !*message || sscanf(message, "%23[^,], %23[^\r\n]", monster, guild) < 2 ) {
  4678. clif_displaymessage(fd, msg_txt(sd,1146)); // Please enter a mob name/ID and guild name/ID (usage: @disguiseguild <mob name/ID>, <guild name/ID>).
  4679. return -1;
  4680. }
  4681. if( (id = atoi(monster)) > 0 ) {
  4682. if( !mobdb_checkid(id) && !npcdb_checkid(id) )
  4683. id = 0;
  4684. } else {
  4685. if( (id = mobdb_searchname(monster)) == 0 ) {
  4686. struct npc_data* nd = npc_name2id(monster);
  4687. if( nd != nullptr )
  4688. id = nd->class_;
  4689. }
  4690. }
  4691. if( id == 0 ) {
  4692. clif_displaymessage(fd, msg_txt(sd,123)); // Monster/NPC name/id hasn't been found.
  4693. return -1;
  4694. }
  4695. auto g = guild_searchnameid(guild);
  4696. if (!g) {
  4697. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  4698. return -1;
  4699. }
  4700. for( i = 0; i < g->guild.max_member; i++ ){
  4701. map_session_data *pl_sd;
  4702. if( (pl_sd = g->guild.member[i].sd) && !pc_isriding(pl_sd) )
  4703. pc_disguise(pl_sd, id);
  4704. }
  4705. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4706. return 0;
  4707. }
  4708. /*==========================================
  4709. * @undisguise by [Yor]
  4710. *------------------------------------------*/
  4711. ACMD_FUNC(undisguise)
  4712. {
  4713. nullpo_retr(-1, sd);
  4714. if (sd->disguise) {
  4715. pc_disguise(sd, 0);
  4716. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4717. } else {
  4718. clif_displaymessage(fd, msg_txt(sd,125)); // You're not disguised.
  4719. return -1;
  4720. }
  4721. return 0;
  4722. }
  4723. /*==========================================
  4724. * UndisguiseAll
  4725. *------------------------------------------*/
  4726. ACMD_FUNC(undisguiseall)
  4727. {
  4728. map_session_data *pl_sd;
  4729. struct s_mapiterator* iter;
  4730. nullpo_retr(-1, sd);
  4731. iter = mapit_getallusers();
  4732. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4733. if( pl_sd->disguise )
  4734. pc_disguise(pl_sd, 0);
  4735. mapit_free(iter);
  4736. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4737. return 0;
  4738. }
  4739. /*==========================================
  4740. * UndisguiseGuild
  4741. *------------------------------------------*/
  4742. ACMD_FUNC(undisguiseguild)
  4743. {
  4744. char guild_name[NAME_LENGTH];
  4745. int i;
  4746. nullpo_retr(-1, sd);
  4747. memset(guild_name, '\0', sizeof(guild_name));
  4748. if(!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4749. clif_displaymessage(fd, msg_txt(sd,1147)); // Please enter guild name/ID (usage: @undisguiseguild <guild name/ID>).
  4750. return -1;
  4751. }
  4752. auto g = guild_searchnameid(guild_name);
  4753. if (!g) {
  4754. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  4755. return -1;
  4756. }
  4757. for(i = 0; i < g->guild.max_member; i++){
  4758. map_session_data *pl_sd;
  4759. if( (pl_sd = g->guild.member[i].sd) && pl_sd->disguise )
  4760. pc_disguise(pl_sd, 0);
  4761. }
  4762. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4763. return 0;
  4764. }
  4765. /*==========================================
  4766. * @exp by [Skotlex]
  4767. *------------------------------------------*/
  4768. ACMD_FUNC(exp)
  4769. {
  4770. char output[CHAT_SIZE_MAX];
  4771. double nextb, nextj;
  4772. nullpo_retr(-1, sd);
  4773. memset(output, '\0', sizeof(output));
  4774. nextb = (double)pc_nextbaseexp(sd);
  4775. if (nextb)
  4776. nextb = sd->status.base_exp*100.0/nextb;
  4777. nextj = (double)pc_nextjobexp(sd);
  4778. if (nextj)
  4779. nextj = sd->status.job_exp*100.0/nextj;
  4780. sprintf(output, msg_txt(sd,1148), sd->status.base_level, nextb, sd->status.job_level, nextj); // Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%)
  4781. clif_displaymessage(fd, output);
  4782. return 0;
  4783. }
  4784. /*==========================================
  4785. * @broadcast by [Valaris]
  4786. *------------------------------------------*/
  4787. ACMD_FUNC(broadcast)
  4788. {
  4789. nullpo_retr(-1, sd);
  4790. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4791. if (!message || !*message) {
  4792. clif_displaymessage(fd, msg_txt(sd,1149)); // Please enter a message (usage: @broadcast <message>).
  4793. return -1;
  4794. }
  4795. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4796. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT);
  4797. return 0;
  4798. }
  4799. /*==========================================
  4800. * @localbroadcast by [Valaris]
  4801. *------------------------------------------*/
  4802. ACMD_FUNC(localbroadcast)
  4803. {
  4804. nullpo_retr(-1, sd);
  4805. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4806. if (!message || !*message) {
  4807. clif_displaymessage(fd, msg_txt(sd,1150)); // Please enter a message (usage: @localbroadcast <message>).
  4808. return -1;
  4809. }
  4810. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4811. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, BC_DEFAULT, ALL_SAMEMAP);
  4812. return 0;
  4813. }
  4814. /*==========================================
  4815. * @email <actual@email> <new@email> by [Yor]
  4816. *------------------------------------------*/
  4817. ACMD_FUNC(email)
  4818. {
  4819. char actual_email[100];
  4820. char new_email[100];
  4821. nullpo_retr(-1, sd);
  4822. memset(actual_email, '\0', sizeof(actual_email));
  4823. memset(new_email, '\0', sizeof(new_email));
  4824. if (!message || !*message || sscanf(message, "%99s %99s", actual_email, new_email) < 2) {
  4825. clif_displaymessage(fd, msg_txt(sd,1151)); // Please enter 2 emails (usage: @email <actual@email> <new@email>).
  4826. return -1;
  4827. }
  4828. if (e_mail_check(actual_email) == 0) {
  4829. clif_displaymessage(fd, msg_txt(sd,144)); // Invalid actual email. If you have default e-mail, give a@a.com.
  4830. return -1;
  4831. } else if (e_mail_check(new_email) == 0) {
  4832. clif_displaymessage(fd, msg_txt(sd,145)); // Invalid new email. Please enter a real e-mail.
  4833. return -1;
  4834. } else if (strcmpi(new_email, "a@a.com") == 0) {
  4835. clif_displaymessage(fd, msg_txt(sd,146)); // New email must be a real e-mail.
  4836. return -1;
  4837. } else if (strcmpi(actual_email, new_email) == 0) {
  4838. clif_displaymessage(fd, msg_txt(sd,147)); // New email must be different of the actual e-mail.
  4839. return -1;
  4840. }
  4841. chrif_changeemail(sd->status.account_id, actual_email, new_email);
  4842. clif_displaymessage(fd, msg_txt(sd,148)); // Information sent to login-server via char-server.
  4843. return 0;
  4844. }
  4845. /*==========================================
  4846. *@effect
  4847. *------------------------------------------*/
  4848. ACMD_FUNC(effect)
  4849. {
  4850. int type = EF_NONE;
  4851. nullpo_retr(-1, sd);
  4852. if (!message || !*message || sscanf(message, "%11d", &type) < 1) {
  4853. clif_displaymessage(fd, msg_txt(sd,1152)); // Please enter an effect number (usage: @effect <effect number>).
  4854. return -1;
  4855. }
  4856. if( type <= EF_NONE || type >= EF_MAX ){
  4857. sprintf(atcmd_output, msg_txt(sd,1152),EF_NONE+1,EF_MAX-1); // Please enter a valid effect id in the range from %d to %d.
  4858. clif_displaymessage(fd, atcmd_output);
  4859. return -1;
  4860. }
  4861. clif_specialeffect(&sd->bl, type, ALL_CLIENT);
  4862. clif_displaymessage(fd, msg_txt(sd,229)); // Your effect has changed.
  4863. return 0;
  4864. }
  4865. /*==========================================
  4866. * @killer by MouseJstr
  4867. * enable killing players even when not in pvp
  4868. *------------------------------------------*/
  4869. ACMD_FUNC(killer)
  4870. {
  4871. nullpo_retr(-1, sd);
  4872. sd->state.killer = !sd->state.killer;
  4873. if(sd->state.killer)
  4874. clif_displaymessage(fd, msg_txt(sd,241)); // You can now attack and kill players freely.
  4875. else {
  4876. clif_displaymessage(fd, msg_txt(sd,292)); // Killer state reset.
  4877. pc_stop_attack(sd);
  4878. }
  4879. return 0;
  4880. }
  4881. /*==========================================
  4882. * @killable by MouseJstr
  4883. * enable other people killing you
  4884. *------------------------------------------*/
  4885. ACMD_FUNC(killable)
  4886. {
  4887. nullpo_retr(-1, sd);
  4888. sd->state.killable = !sd->state.killable;
  4889. if(sd->state.killable)
  4890. clif_displaymessage(fd, msg_txt(sd,242)); // You can now be attacked and killed by players.
  4891. else {
  4892. clif_displaymessage(fd, msg_txt(sd,288)); // You are no longer killable.
  4893. map_foreachinallrange(unit_stopattack,&sd->bl, AREA_SIZE, BL_CHAR, sd->bl.id);
  4894. }
  4895. return 0;
  4896. }
  4897. /*==========================================
  4898. * @skillon by MouseJstr
  4899. * turn skills on for the map
  4900. *------------------------------------------*/
  4901. ACMD_FUNC(skillon)
  4902. {
  4903. nullpo_retr(-1, sd);
  4904. map_setmapflag(sd->bl.m, MF_NOSKILL, false);
  4905. clif_displaymessage(fd, msg_txt(sd,244)); // Skills have been enabled on this map.
  4906. return 0;
  4907. }
  4908. /*==========================================
  4909. * @skilloff by MouseJstr
  4910. * Turn skills off on the map
  4911. *------------------------------------------*/
  4912. ACMD_FUNC(skilloff)
  4913. {
  4914. nullpo_retr(-1, sd);
  4915. map_setmapflag(sd->bl.m, MF_NOSKILL, true);
  4916. clif_displaymessage(fd, msg_txt(sd,243)); // Skills have been disabled on this map.
  4917. return 0;
  4918. }
  4919. /*==========================================
  4920. * @npcmove by MouseJstr
  4921. * move a npc
  4922. *------------------------------------------*/
  4923. ACMD_FUNC(npcmove)
  4924. {
  4925. short x = 0, y = 0;
  4926. struct npc_data *nd = 0;
  4927. char npc_name[NPC_NAME_LENGTH];
  4928. nullpo_retr(-1, sd);
  4929. memset(npc_name, '\0', sizeof npc_name);
  4930. if (!message || !*message || sscanf(message, "%6hd %6hd %49[^\n]", &x, &y, npc_name) < 3) {
  4931. clif_displaymessage(fd, msg_txt(sd,1153)); // Usage: @npcmove <X> <Y> <npc_name>
  4932. return -1;
  4933. }
  4934. if ((nd = npc_name2id(npc_name)) == nullptr)
  4935. {
  4936. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4937. return -1;
  4938. }
  4939. if ( npc_movenpc( nd, x, y ) )
  4940. { //actually failed to move
  4941. clif_displaymessage(fd, msg_txt(sd,1154)); // NPC is not on this map.
  4942. return -1; //Not on a map.
  4943. } else
  4944. clif_displaymessage(fd, msg_txt(sd,1155)); // NPC moved
  4945. return 0;
  4946. }
  4947. /*==========================================
  4948. * @addwarp by MouseJstr
  4949. * Create a new static warp point.
  4950. *------------------------------------------*/
  4951. ACMD_FUNC(addwarp)
  4952. {
  4953. char mapname[MAP_NAME_LENGTH_EXT], warpname[NPC_NAME_LENGTH];
  4954. short x,y;
  4955. unsigned short m;
  4956. struct npc_data* nd;
  4957. nullpo_retr(-1, sd);
  4958. memset(warpname, '\0', sizeof(warpname));
  4959. if (!message || !*message || sscanf(message, "%15s %6hd %6hd %49[^\n]", mapname, &x, &y, warpname) < 4) {
  4960. clif_displaymessage(fd, msg_txt(sd,1156)); // Usage: @addwarp <mapname> <X> <Y> <npc name>
  4961. return -1;
  4962. }
  4963. m = mapindex_name2id(mapname);
  4964. if( m == 0 )
  4965. {
  4966. sprintf(atcmd_output, msg_txt(sd,1157), mapname); // Unknown map '%s'.
  4967. clif_displaymessage(fd, atcmd_output);
  4968. return -1;
  4969. }
  4970. nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
  4971. if( nd == nullptr )
  4972. return -1;
  4973. sprintf(atcmd_output, msg_txt(sd,1158), nd->exname); // New warp NPC '%s' created.
  4974. clif_displaymessage(fd, atcmd_output);
  4975. return 0;
  4976. }
  4977. /*==========================================
  4978. * @follow by [MouseJstr]
  4979. * Follow a player .. staying no more then 5 spaces away
  4980. *------------------------------------------*/
  4981. ACMD_FUNC(follow)
  4982. {
  4983. map_session_data* pl_sd = nullptr;;
  4984. nullpo_retr(-1, sd);
  4985. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4986. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4987. if (sd->followtarget == -1)
  4988. return -1;
  4989. pc_stop_following (sd);
  4990. clif_displaymessage(fd, msg_txt(sd,1159)); // Follow mode OFF.
  4991. return 0;
  4992. }
  4993. if ( (pl_sd = map_nick2sd(atcmd_player_name,true)) == nullptr )
  4994. {
  4995. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4996. return -1;
  4997. }
  4998. if (sd->followtarget == pl_sd->bl.id) {
  4999. pc_stop_following (sd);
  5000. clif_displaymessage(fd, msg_txt(sd,1159)); // Follow mode OFF.
  5001. } else {
  5002. pc_follow(sd, pl_sd->bl.id);
  5003. clif_displaymessage(fd, msg_txt(sd,1160)); // Follow mode ON.
  5004. }
  5005. return 0;
  5006. }
  5007. /*==========================================
  5008. * @dropall by [MouseJstr] and [Xantara]
  5009. * Drops all your possession on the ground based on item type
  5010. *------------------------------------------*/
  5011. ACMD_FUNC(dropall)
  5012. {
  5013. int8 type = -1;
  5014. uint16 i, count = 0, count2 = 0;
  5015. nullpo_retr(-1, sd);
  5016. if( message[0] ) {
  5017. type = atoi(message);
  5018. if( type != -1 && type != IT_HEALING && type != IT_USABLE && type != IT_ETC && type != IT_WEAPON &&
  5019. type != IT_ARMOR && type != IT_CARD && type != IT_PETEGG && type != IT_PETARMOR && type != IT_AMMO )
  5020. {
  5021. clif_displaymessage(fd, msg_txt(sd,1492)); // Usage: @dropall {<type>}
  5022. clif_displaymessage(fd, msg_txt(sd,1493)); // Type List: (default) all = -1, healing = 0, usable = 2, etc = 3, armor = 4, weapon = 5, card = 6, petegg = 7, petarmor = 8, ammo = 10
  5023. return -1;
  5024. }
  5025. }
  5026. for( i = 0; i < MAX_INVENTORY; i++ ) {
  5027. if( sd->inventory.u.items_inventory[i].amount ) {
  5028. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[i].nameid);
  5029. if( id == nullptr ) {
  5030. ShowDebug("Non-existant item %d on dropall list (account_id: %d, char_id: %d)\n", sd->inventory.u.items_inventory[i].nameid, sd->status.account_id, sd->status.char_id);
  5031. continue;
  5032. }
  5033. if( !pc_candrop(sd,&sd->inventory.u.items_inventory[i]) )
  5034. continue;
  5035. if( type == -1 || type == (uint8)id->type ) {
  5036. if( sd->inventory.u.items_inventory[i].equip != 0 )
  5037. pc_unequipitem(sd, i, 3);
  5038. if( itemdb_ishatched_egg( &sd->inventory.u.items_inventory[i] ) ){
  5039. pet_return_egg( sd, sd->pd );
  5040. }
  5041. pc_equipswitch_remove(sd, i);
  5042. int amount = sd->inventory.u.items_inventory[i].amount;
  5043. if(pc_dropitem(sd, i, amount))
  5044. count += amount;
  5045. else count2 += amount;
  5046. }
  5047. }
  5048. }
  5049. sprintf(atcmd_output, msg_txt(sd,1494), count,count2); // %d items are dropped (%d skipped)!
  5050. clif_displaymessage(fd, atcmd_output);
  5051. return 0;
  5052. }
  5053. /*==========================================
  5054. * @stockall by [Hanashi]
  5055. * transfer items from cart to inventory
  5056. *------------------------------------------*/
  5057. ACMD_FUNC(stockall)
  5058. {
  5059. nullpo_retr(-1, sd);
  5060. if (!pc_iscarton(sd)) {
  5061. clif_displaymessage(fd, msg_txt(sd,1533)); // You do not have a cart.
  5062. return -1;
  5063. }
  5064. int8 type = -1;
  5065. if ( message[0] ) {
  5066. type = atoi(message);
  5067. switch (type) {
  5068. case -1:
  5069. case IT_HEALING:
  5070. case IT_USABLE:
  5071. case IT_ETC:
  5072. case IT_WEAPON:
  5073. case IT_ARMOR:
  5074. case IT_CARD:
  5075. case IT_PETEGG:
  5076. case IT_PETARMOR:
  5077. case IT_AMMO:
  5078. break;
  5079. default:
  5080. clif_displaymessage(fd, msg_txt(sd, 1534)); // Usage: @stockall {<type>}
  5081. clif_displaymessage(fd, msg_txt(sd, 1493)); // Type List: (default) all = -1, healing = 0, usable = 2, etc = 3, armor = 4, weapon = 5, card = 6, petegg = 7, petarmor = 8, ammo = 10
  5082. return -1;
  5083. }
  5084. }
  5085. uint16 count = 0, count2 = 0;
  5086. for ( uint16 i = 0; i < MAX_CART; i++ ) {
  5087. if ( sd->cart.u.items_cart[i].amount > 0 ) {
  5088. std::shared_ptr<item_data> id = item_db.find(sd->cart.u.items_cart[i].nameid);
  5089. if ( id == nullptr ) {
  5090. ShowDebug("Non-existent item %u on stockall list (account_id: %d, char_id: %d)\n", sd->cart.u.items_cart[i].nameid, sd->status.account_id, sd->status.char_id);
  5091. continue;
  5092. }
  5093. if ( type == -1 || static_cast<item_types>(type) == id->type ) {
  5094. if (pc_getitemfromcart(sd, i, sd->cart.u.items_cart[i].amount))
  5095. count += sd->cart.u.items_cart[i].amount;
  5096. else
  5097. count2 += sd->cart.u.items_cart[i].amount;
  5098. }
  5099. }
  5100. }
  5101. sprintf(atcmd_output, msg_txt(sd,1535), count,count2); // %d items are transferred (%d skipped)!
  5102. clif_displaymessage(fd, atcmd_output);
  5103. return 0;
  5104. }
  5105. /*==========================================
  5106. * @storeall by [MouseJstr]
  5107. * Put everything into storage
  5108. *------------------------------------------*/
  5109. ACMD_FUNC(storeall)
  5110. {
  5111. int i;
  5112. nullpo_retr(-1, sd);
  5113. if (sd->state.storage_flag != 1)
  5114. { //Open storage.
  5115. if( storage_storageopen(sd) == 1 ) {
  5116. clif_displaymessage(fd, msg_txt(sd,1161)); // You currently cannot open your storage.
  5117. return -1;
  5118. }
  5119. }
  5120. for (i = 0; i < MAX_INVENTORY; i++) {
  5121. if (sd->inventory.u.items_inventory[i].amount) {
  5122. if(sd->inventory.u.items_inventory[i].equip != 0)
  5123. pc_unequipitem(sd, i, 3);
  5124. if( itemdb_ishatched_egg( &sd->inventory.u.items_inventory[i] ) ){
  5125. pet_return_egg( sd, sd->pd );
  5126. }
  5127. pc_equipswitch_remove(sd, i);
  5128. storage_storageadd(sd, &sd->storage, i, sd->inventory.u.items_inventory[i].amount);
  5129. }
  5130. }
  5131. storage_storageclose(sd);
  5132. clif_displaymessage(fd, msg_txt(sd,1162)); // All items stored.
  5133. return 0;
  5134. }
  5135. ACMD_FUNC(clearstorage)
  5136. {
  5137. int i, j;
  5138. nullpo_retr(-1, sd);
  5139. if (sd->state.storage_flag == 1) {
  5140. clif_displaymessage(fd, msg_txt(sd,250)); // You have already opened your storage. Close it first.
  5141. return -1;
  5142. }
  5143. if (sd->state.storage_flag == 3) {
  5144. clif_displaymessage(fd, msg_txt(sd,250)); // You have already opened your storage. Close it first.
  5145. return -1;
  5146. }
  5147. j = sd->storage.amount;
  5148. for (i = 0; i < j; ++i) {
  5149. storage_delitem(sd, &sd->storage, i, sd->storage.u.items_storage[i].amount);
  5150. }
  5151. sd->state.storage_flag = 1;
  5152. storage_storageclose(sd);
  5153. clif_displaymessage(fd, msg_txt(sd,1394)); // Your storage was cleaned.
  5154. return 0;
  5155. }
  5156. ACMD_FUNC(cleargstorage)
  5157. {
  5158. int i, j;
  5159. struct s_storage *gstorage;
  5160. nullpo_retr(-1, sd);
  5161. if (!sd->guild) {
  5162. clif_displaymessage(fd, msg_txt(sd,43)); // You're not in a guild.
  5163. return -1;
  5164. }
  5165. if (sd->state.storage_flag == 1) {
  5166. clif_displaymessage(fd, msg_txt(sd,250)); // You have already opened your storage. Close it first.
  5167. return -1;
  5168. }
  5169. if (sd->state.storage_flag == 2) {
  5170. clif_displaymessage(fd, msg_txt(sd,251)); // You have already opened your guild storage. Close it first.
  5171. return -1;
  5172. }
  5173. if (sd->state.storage_flag == 3) {
  5174. clif_displaymessage(fd, msg_txt(sd,250)); // You have already opened your storage. Close it first.
  5175. return -1;
  5176. }
  5177. gstorage = guild2storage2(sd->status.guild_id);
  5178. if (gstorage == nullptr) { // Doesn't have opened @gstorage yet, so we skip the deletion since *shouldn't* have any item there.
  5179. return -1;
  5180. }
  5181. j = gstorage->amount;
  5182. gstorage->lock = true; // Lock @gstorage: do not allow any item to be retrieved or stored from any guild member
  5183. for (i = 0; i < j; ++i) {
  5184. storage_guild_delitem(sd, gstorage, i, gstorage->u.items_guild[i].amount);
  5185. }
  5186. storage_guild_storageclose(sd);
  5187. gstorage->lock = false; // Cleaning done, release lock
  5188. clif_displaymessage(fd, msg_txt(sd,1395)); // Your guild storage was cleaned.
  5189. return 0;
  5190. }
  5191. ACMD_FUNC(clearcart)
  5192. {
  5193. int i;
  5194. nullpo_retr(-1, sd);
  5195. if (pc_iscarton(sd) == 0) {
  5196. clif_displaymessage(fd, msg_txt(sd,1396)); // You do not have a cart to be cleaned.
  5197. return -1;
  5198. }
  5199. if (sd->state.vending == 1) { //Somehow...
  5200. return -1;
  5201. }
  5202. for (i = 0; i < MAX_CART; i++) {
  5203. if (sd->cart.u.items_cart[i].nameid > 0)
  5204. pc_cart_delitem(sd, i, sd->cart.u.items_cart[i].amount, 1, LOG_TYPE_OTHER);
  5205. }
  5206. clif_clearcart(fd);
  5207. clif_updatestatus(*sd,SP_CARTINFO);
  5208. clif_displaymessage(fd, msg_txt(sd,1397)); // Your cart was cleaned.
  5209. return 0;
  5210. }
  5211. /*==========================================
  5212. * @skillid by [MouseJstr]
  5213. * lookup a skill by name
  5214. *------------------------------------------*/
  5215. #define MAX_SKILLID_PARTIAL_RESULTS 5
  5216. #define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 // "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33)
  5217. ACMD_FUNC(skillid) {
  5218. int skillen, i, found = 0;
  5219. char partials[MAX_SKILLID_PARTIAL_RESULTS][MAX_SKILLID_PARTIAL_RESULTS_LEN];
  5220. nullpo_retr(-1, sd);
  5221. if (!message || !*message) {
  5222. clif_displaymessage(fd, msg_txt(sd,1163)); // Please enter a skill name to look up (usage: @skillid <skill name>).
  5223. return -1;
  5224. }
  5225. skillen = strlen(message);
  5226. for(const auto & skill : skill_db) {
  5227. uint16 skill_id = skill.second->nameid;
  5228. uint16 idx = skill_get_index(skill_id);
  5229. const char *name = skill.second->name;
  5230. const char *desc = skill.second->desc;
  5231. if (strnicmp(name, message, skillen) == 0 || strnicmp(desc, message, skillen) == 0) {
  5232. sprintf(atcmd_output, msg_txt(sd,1164), skill_id, desc, name); // skill %d: %s (%s)
  5233. clif_displaymessage(fd, atcmd_output);
  5234. } else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(name,message) || stristr(desc,message) ) ) {
  5235. snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(sd,1164), skill_id, desc, name); // // skill %d: %s (%s)
  5236. }
  5237. }
  5238. if( found ) {
  5239. sprintf(atcmd_output, msg_txt(sd,1398), found); // -- Displaying first %d partial matches
  5240. clif_displaymessage(fd, atcmd_output);
  5241. }
  5242. for(i = 0; i < found; i++) { /* partials */
  5243. clif_displaymessage(fd, partials[i]);
  5244. }
  5245. return 0;
  5246. }
  5247. /*==========================================
  5248. * @useskill by [MouseJstr]
  5249. * A way of using skills without having to find them in the skills menu
  5250. *------------------------------------------*/
  5251. ACMD_FUNC(useskill)
  5252. {
  5253. map_session_data* pl_sd = nullptr;;
  5254. struct block_list *bl;
  5255. uint16 skill_id;
  5256. uint16 skill_lv;
  5257. nullpo_retr(-1, sd);
  5258. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  5259. if(!message || !*message || sscanf(message, "%6hu %6hu %23[^\n]", &skill_id, &skill_lv, atcmd_player_name) != 3) {
  5260. clif_displaymessage(fd, msg_txt(sd,1165)); // Usage: @useskill <skill ID> <skill level> <char name>
  5261. return -1;
  5262. }
  5263. if (!skill_id || !skill_db.find(skill_id)) {
  5264. clif_displaymessage(fd, msg_txt(sd, 198)); // This skill number doesn't exist.
  5265. return -1;
  5266. }
  5267. if (!skill_lv)
  5268. skill_lv = 1;
  5269. if(!strcmp(atcmd_player_name,"self"))
  5270. pl_sd = sd; //quick keyword
  5271. else if ( (pl_sd = map_nick2sd(atcmd_player_name,true)) == nullptr ){
  5272. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5273. return -1;
  5274. }
  5275. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  5276. {
  5277. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  5278. return -1;
  5279. }
  5280. if (SKILL_CHK_HOMUN(skill_id) && hom_is_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
  5281. bl = &sd->hd->bl;
  5282. else
  5283. bl = &sd->bl;
  5284. if (skill_get_inf(skill_id)&INF_GROUND_SKILL)
  5285. unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skill_id, skill_lv);
  5286. else
  5287. unit_skilluse_id(bl, pl_sd->bl.id, skill_id, skill_lv);
  5288. return 0;
  5289. }
  5290. /*==========================================
  5291. * @displayskill by [Skotlex]
  5292. * Debug command to locate new skill IDs. It sends the
  5293. * three possible skill-effect packets to the area.
  5294. *------------------------------------------*/
  5295. ACMD_FUNC(displayskill)
  5296. {
  5297. struct status_data * status;
  5298. t_tick tick;
  5299. uint16 skill_id;
  5300. uint16 skill_lv = 1;
  5301. uint16 type = 0;
  5302. nullpo_retr(-1, sd);
  5303. if (!message || !*message || sscanf(message, "%6hu %6hu %6hu", &skill_id, &skill_lv, &type) < 1)
  5304. {
  5305. clif_displaymessage(fd, msg_txt(sd,1166));// Usage: @displayskill <skill ID> {<skill level> <type>}
  5306. clif_displaymessage(fd, msg_txt(sd,825));// Effect Types: 0: All, 1: Damage, 2: Splash Dmg, 3: No Damage, 4: Ground
  5307. return -1;
  5308. }
  5309. status = status_get_status_data(&sd->bl);
  5310. tick = gettick();
  5311. if (type == 0 || type == 1)
  5312. clif_skill_damage(&sd->bl, &sd->bl, tick, status->amotion, status->dmotion, 1, 1, skill_id, skill_lv, DMG_SINGLE);
  5313. if (type == 0 || type == 2)
  5314. clif_skill_damage(&sd->bl, &sd->bl, tick, status->amotion, status->dmotion, 1, 1, skill_id, skill_lv, DMG_SPLASH);
  5315. if (type == 0 || type == 3)
  5316. clif_skill_nodamage(&sd->bl, &sd->bl, skill_id, skill_lv, 1);
  5317. if (type == 0 || type == 4)
  5318. clif_skill_poseffect(&sd->bl, skill_id, skill_lv, sd->bl.x, sd->bl.y, tick);
  5319. return 0;
  5320. }
  5321. /*==========================================
  5322. * @displayskillcast by [Rytech]
  5323. * Debug command to view casting animations for skills.
  5324. * Can target self or the ground. Ground target can be
  5325. * useful for seeing casting circle size.
  5326. *------------------------------------------*/
  5327. ACMD_FUNC(displayskillcast)
  5328. {
  5329. uint16 skill_id;
  5330. uint16 skill_lv = 1;
  5331. uint16 cast_time = 5000;
  5332. uint16 target_type = 0;
  5333. nullpo_retr(-1, sd);
  5334. if (!message || !*message || sscanf(message, "%6hu %6hu %6hu %6hu", &skill_id, &skill_lv, &target_type, &cast_time) < 1)
  5335. {
  5336. clif_displaymessage(fd, msg_txt(sd, 824));// Usage: @displayskillcast <skill ID> {<skill level> <ground target flag> <cast time>}
  5337. return -1;
  5338. }
  5339. if ( target_type == 1)
  5340. clif_skillcasting(&sd->bl, sd->bl.id, 0, sd->bl.x, sd->bl.y, skill_id, skill_lv, 0, cast_time);
  5341. else
  5342. clif_skillcasting(&sd->bl, sd->bl.id, sd->bl.id, 0, 0, skill_id, skill_lv, 0, cast_time);
  5343. return 0;
  5344. }
  5345. /*==========================================
  5346. * @displayskillunit by [Rytech]
  5347. * Debug command to view unit animations for skills.
  5348. *------------------------------------------*/
  5349. ACMD_FUNC(displayskillunit)
  5350. {
  5351. uint16 unit_id;
  5352. uint16 range = 0;
  5353. uint16 skill_lv = 1;
  5354. nullpo_retr(-1, sd);
  5355. if (!message || !*message || sscanf(message, "%6hu %6hu %6hu", &unit_id, &skill_lv, &range) < 1)
  5356. {
  5357. clif_displaymessage(fd, msg_txt(sd, 826));// Usage: @displayskillunit <unit ID> {<skill level> <range>}
  5358. return -1;
  5359. }
  5360. clif_skill_unit_test(&sd->bl, sd->bl.x, sd->bl.y, unit_id, range, skill_lv);
  5361. return 0;
  5362. }
  5363. /*==========================================
  5364. * @skilltree by [MouseJstr]
  5365. * prints the skill tree for a player required to get to a skill
  5366. *------------------------------------------*/
  5367. ACMD_FUNC(skilltree)
  5368. {
  5369. map_session_data* pl_sd = nullptr;;
  5370. uint16 skill_id;
  5371. nullpo_retr(-1, sd);
  5372. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  5373. if(!message || !*message || sscanf(message, "%6hu %23[^\n]", &skill_id, atcmd_player_name) != 2) {
  5374. clif_displaymessage(fd, msg_txt(sd,1167)); // Usage: @skilltree <skill ID> <char name>
  5375. return -1;
  5376. }
  5377. if ( (pl_sd = map_nick2sd(atcmd_player_name,true)) == nullptr )
  5378. {
  5379. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5380. return -1;
  5381. }
  5382. int c = pc_mapid2jobid( pc_calc_skilltree_normalize_job( pl_sd ), pl_sd->status.sex );
  5383. sprintf(atcmd_output, msg_txt(sd,1168), job_name(c), pc_checkskill(pl_sd, NV_BASIC)); // Player is using %s skill tree (%d basic points).
  5384. clif_displaymessage(fd, atcmd_output);
  5385. auto entry = skill_tree_db.get_skill_data(c, skill_id);
  5386. if (entry == nullptr) {
  5387. clif_displaymessage(fd, msg_txt(sd,1169)); // The player cannot use that skill.
  5388. return 0;
  5389. }
  5390. bool meets = true;
  5391. for (const auto &it : entry->need) {
  5392. if (pc_checkskill(sd, it.first) < it.second) {
  5393. sprintf(atcmd_output, msg_txt(sd,1170), it.second, skill_get_desc(it.first)); // Player requires level %d of skill %s.
  5394. clif_displaymessage(fd, atcmd_output);
  5395. meets = false;
  5396. }
  5397. }
  5398. if (meets) {
  5399. clif_displaymessage(fd, msg_txt(sd,1171)); // The player meets all the requirements for that skill.
  5400. }
  5401. return 0;
  5402. }
  5403. // Hand a ring with partners name on it to this char
  5404. void getring (map_session_data* sd)
  5405. {
  5406. char flag = 0;
  5407. t_itemid item_id;
  5408. struct item item_tmp;
  5409. item_id = (sd->status.sex) ? WEDDING_RING_M : WEDDING_RING_F;
  5410. memset(&item_tmp, 0, sizeof(item_tmp));
  5411. item_tmp.nameid = item_id;
  5412. item_tmp.identify = 1;
  5413. item_tmp.card[0] = CARD0_FORGE;
  5414. item_tmp.card[2] = GetWord(sd->status.partner_id,0);
  5415. item_tmp.card[3] = GetWord(sd->status.partner_id,1);
  5416. if((flag = pc_additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
  5417. clif_additem(sd,0,0,flag);
  5418. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,4,0);
  5419. }
  5420. }
  5421. /*==========================================
  5422. * @marry by [MouseJstr], fixed by Lupus
  5423. * Marry two players
  5424. *------------------------------------------*/
  5425. ACMD_FUNC(marry)
  5426. {
  5427. map_session_data* pl_sd = nullptr;;
  5428. nullpo_retr(-1, sd);
  5429. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  5430. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  5431. clif_displaymessage(fd, msg_txt(sd,1172)); // Usage: @marry <char name>
  5432. return -1;
  5433. }
  5434. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  5435. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5436. return -1;
  5437. }
  5438. if (pc_marriage(sd, pl_sd)) {
  5439. clif_displaymessage(fd, msg_txt(sd,1173)); // They are married... wish them well.
  5440. clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus]
  5441. if( pl_sd->bl.m != sd->bl.m )
  5442. clif_wedding_effect(&sd->bl);
  5443. getring(sd); // Auto-give named rings (Aru)
  5444. getring(pl_sd);
  5445. return 0;
  5446. }
  5447. clif_displaymessage(fd, msg_txt(sd,1174)); // The two cannot wed because one is either a baby or already married.
  5448. return -1;
  5449. }
  5450. /*==========================================
  5451. * @divorce by [MouseJstr], fixed by [Lupus]
  5452. * divorce two players
  5453. *------------------------------------------*/
  5454. ACMD_FUNC(divorce)
  5455. {
  5456. nullpo_retr(-1, sd);
  5457. if (!pc_divorce(sd)) {
  5458. sprintf(atcmd_output, msg_txt(sd,1175), sd->status.name); // '%s' is not married.
  5459. clif_displaymessage(fd, atcmd_output);
  5460. return -1;
  5461. }
  5462. sprintf(atcmd_output, msg_txt(sd,1176), sd->status.name); // '%s' and his/her partner are now divorced.
  5463. clif_displaymessage(fd, atcmd_output);
  5464. return 0;
  5465. }
  5466. /*==========================================
  5467. * @changelook by [Celest]
  5468. *------------------------------------------*/
  5469. ACMD_FUNC(changelook)
  5470. {
  5471. int i, j = 0, k = 0;
  5472. int pos[8] = { LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HEAD_BOTTOM,LOOK_WEAPON,LOOK_SHIELD,LOOK_SHOES,LOOK_ROBE, LOOK_BODY2 };
  5473. if((i = sscanf(message, "%11d %11d", &j, &k)) < 1) {
  5474. clif_displaymessage(fd, msg_txt(sd,1177)); // Usage: @changelook {<position>} <view id>
  5475. clif_displaymessage(fd, msg_txt(sd,1178)); // Position: 1-Top 2-Middle 3-Bottom 4-Weapon 5-Shield 6-Shoes 7-Robe 8-Body
  5476. return -1;
  5477. } else if ( i == 2 ) {
  5478. if (j < 1 || j > 8)
  5479. j = 1;
  5480. j = pos[j - 1];
  5481. } else if( i == 1 ) { // position not defined, use HEAD_TOP as default
  5482. k = j; // swap
  5483. j = LOOK_HEAD_TOP;
  5484. }
  5485. clif_changelook(&sd->bl,j,k);
  5486. return 0;
  5487. }
  5488. /*==========================================
  5489. * @autotrade by durf [Lupus] [Paradox924X]
  5490. * Turns on/off Autotrade for a specific player
  5491. *------------------------------------------*/
  5492. ACMD_FUNC(autotrade) {
  5493. nullpo_retr(-1, sd);
  5494. if( map_getmapflag(sd->bl.m, MF_AUTOTRADE) != battle_config.autotrade_mapflag ) {
  5495. clif_displaymessage(fd, msg_txt(sd,1179)); // Autotrade is not allowed on this map.
  5496. return -1;
  5497. }
  5498. if( pc_isdead(sd) ) {
  5499. clif_displaymessage(fd, msg_txt(sd,1180)); // You cannot autotrade when dead.
  5500. return -1;
  5501. }
  5502. if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
  5503. clif_displaymessage(fd, msg_txt(sd,549)); // "You should have a shop open to use @autotrade."
  5504. return -1;
  5505. }
  5506. sd->state.autotrade = 1;
  5507. if (battle_config.autotrade_monsterignore)
  5508. sd->state.block_action |= PCBLOCK_IMMUNE;
  5509. if( sd->state.vending ){
  5510. vending_update(*sd);
  5511. }else if( sd->state.buyingstore ){
  5512. buyingstore_update(*sd);
  5513. }
  5514. if( battle_config.at_timeout ) {
  5515. int timeout = atoi(message);
  5516. status_change_start(nullptr,&sd->bl, SC_AUTOTRADE, 10000, 0, 0, 0, 0, ((timeout > 0) ? min(timeout,battle_config.at_timeout) : battle_config.at_timeout) * 60000, SCSTART_NONE);
  5517. }
  5518. if (battle_config.at_logout_event)
  5519. npc_script_event(sd, NPCE_LOGOUT); //Logout Event
  5520. channel_pcquit(sd,0xF); //leave all chan
  5521. clif_authfail_fd(sd->fd, 15);
  5522. chrif_save(sd, CSAVE_AUTOTRADE);
  5523. return 0;
  5524. }
  5525. /*==========================================
  5526. * @changegm by durf (changed by Lupus)
  5527. * Changes Master of your Guild to a specified guild member
  5528. *------------------------------------------*/
  5529. ACMD_FUNC(changegm)
  5530. {
  5531. map_session_data *pl_sd;
  5532. nullpo_retr(-1, sd);
  5533. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  5534. if (sd->status.guild_id == 0 || sd->guild == nullptr || strcmp(sd->guild->guild.master,sd->status.name)) {
  5535. clif_displaymessage(fd, msg_txt(sd,1181)); // You need to be a Guild Master to use this command.
  5536. return -1;
  5537. }
  5538. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || map_getmapflag(sd->bl.m, MF_GVG_CASTLE) ) {
  5539. clif_displaymessage(fd, msg_txt(sd,1182)); // You cannot change guild leaders on this map.
  5540. return -1;
  5541. }
  5542. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  5543. clif_displaymessage(fd, msg_txt(sd,1183)); // Usage: @changegm <guild_member_name>
  5544. return -1;
  5545. }
  5546. if((pl_sd=map_nick2sd(atcmd_player_name,false)) == nullptr || pl_sd->status.guild_id != sd->status.guild_id) {
  5547. clif_displaymessage(fd, msg_txt(sd,1184)); // Target character must be online and be a guild member.
  5548. return -1;
  5549. }
  5550. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  5551. #if PACKETVER >= 20151001
  5552. clif_msg(sd, GUILD_MASTER_WOE);
  5553. #else
  5554. clif_displaymessage(fd, msg_txt(sd,1513)); // Currently in WoE hours, unable to delegate Guild leader
  5555. #endif
  5556. return -1;
  5557. }
  5558. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(nullptr),sd->guild->guild.last_leader_change) < battle_config.guild_leaderchange_delay ){
  5559. #if PACKETVER >= 20151001
  5560. clif_msg(sd, GUILD_MASTER_DELAY);
  5561. #else
  5562. clif_displaymessage(fd, msg_txt(sd,1514)); // You have to wait for a while before delegating a new Guild leader
  5563. #endif
  5564. return -1;
  5565. }
  5566. guild_gm_change(sd->status.guild_id, pl_sd->status.char_id);
  5567. return 0;
  5568. }
  5569. /*==========================================
  5570. * @changeleader by Skotlex
  5571. * Changes the leader of a party.
  5572. *------------------------------------------*/
  5573. ACMD_FUNC(changeleader)
  5574. {
  5575. nullpo_retr(-1, sd);
  5576. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  5577. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  5578. clif_displaymessage(fd, msg_txt(sd,1185)); // Usage: @changeleader <party_member_name>
  5579. return -1;
  5580. }
  5581. party_changeleader(sd, map_nick2sd(atcmd_player_name,false),nullptr);
  5582. return 0;
  5583. }
  5584. /*==========================================
  5585. * @partyoption by Skotlex
  5586. * Used to change the item share setting of a party.
  5587. *------------------------------------------*/
  5588. ACMD_FUNC(partyoption)
  5589. {
  5590. struct party_data *p;
  5591. int mi, option;
  5592. char w1[16], w2[16];
  5593. nullpo_retr(-1, sd);
  5594. if (sd->status.party_id == 0 || (p = party_search(sd->status.party_id)) == nullptr)
  5595. {
  5596. clif_displaymessage(fd, msg_txt(sd,282)); // You need to be a party leader to use this command.
  5597. return -1;
  5598. }
  5599. ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd );
  5600. if (mi == MAX_PARTY)
  5601. return -1; //Shouldn't happen
  5602. if (!p->party.member[mi].leader)
  5603. {
  5604. clif_displaymessage(fd, msg_txt(sd,282)); // You need to be a party leader to use this command.
  5605. return -1;
  5606. }
  5607. if(!message || !*message || sscanf(message, "%15s %15s", w1, w2) < 2)
  5608. {
  5609. clif_displaymessage(fd, msg_txt(sd,1186)); // Usage: @partyoption <pickup share: yes/no> <item distribution: yes/no>
  5610. return -1;
  5611. }
  5612. option = (config_switch(w1)?1:0)|(config_switch(w2)?2:0);
  5613. //Change item share type.
  5614. if (option != p->party.item)
  5615. party_changeoption(sd, p->party.exp, option);
  5616. else
  5617. clif_displaymessage(fd, msg_txt(sd,286)); // There's been no change in the setting.
  5618. return 0;
  5619. }
  5620. /*==========================================
  5621. * @autoloot by Upa-Kun
  5622. * Turns on/off AutoLoot for a specific player
  5623. *------------------------------------------*/
  5624. ACMD_FUNC(autoloot)
  5625. {
  5626. int rate;
  5627. nullpo_retr(-1, sd);
  5628. // autoloot command without value
  5629. if(!message || !*message)
  5630. {
  5631. if (sd->state.autoloot)
  5632. rate = 0;
  5633. else
  5634. rate = 10000;
  5635. } else {
  5636. double drate;
  5637. drate = atof(message);
  5638. rate = (int)(drate*100);
  5639. }
  5640. if (rate < 0) rate = 0;
  5641. if (rate > 10000) rate = 10000;
  5642. sd->state.autoloot = rate;
  5643. if (sd->state.autoloot) {
  5644. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1187),((double)sd->state.autoloot)/100.); // Autolooting items with drop rates of %0.02f%% and below.
  5645. clif_displaymessage(fd, atcmd_output);
  5646. }else
  5647. clif_displaymessage(fd, msg_txt(sd,1188)); // Autoloot is now off.
  5648. return 0;
  5649. }
  5650. /*==========================================
  5651. * @alootid
  5652. *------------------------------------------*/
  5653. ACMD_FUNC(autolootitem)
  5654. {
  5655. std::shared_ptr<item_data> item_data;
  5656. int i;
  5657. int action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  5658. nullpo_retr(-1, sd);
  5659. if (message && *message) {
  5660. if (message[0] == '+') {
  5661. message++;
  5662. action = 1;
  5663. }
  5664. else if (message[0] == '-') {
  5665. message++;
  5666. action = 2;
  5667. }
  5668. else if (!strcmp(message,"reset"))
  5669. action = 4;
  5670. }
  5671. if (action < 3) // add or remove
  5672. {
  5673. item_data = item_db.find( strtoul( message, nullptr, 10 ) );
  5674. if( item_data == nullptr ){
  5675. item_data = item_db.searchname( message );
  5676. }
  5677. if( item_data == nullptr ){
  5678. // No items founds in the DB with Id or Name
  5679. clif_displaymessage(fd, msg_txt(sd,1189)); // Item not found.
  5680. return -1;
  5681. }
  5682. }
  5683. switch(action) {
  5684. case 1:
  5685. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5686. if (i != AUTOLOOTITEM_SIZE) {
  5687. clif_displaymessage(fd, msg_txt(sd,1190)); // You're already autolooting this item.
  5688. return -1;
  5689. }
  5690. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == 0);
  5691. if (i == AUTOLOOTITEM_SIZE) {
  5692. clif_displaymessage(fd, msg_txt(sd,1191)); // Your autolootitem list is full. Remove some items first with @autolootid -<item name or ID>.
  5693. return -1;
  5694. }
  5695. sd->state.autolootid[i] = item_data->nameid; // Autoloot Activated
  5696. sprintf(atcmd_output, msg_txt(sd,1192), item_data->name.c_str(), item_db.create_item_link( item_data ).c_str(), item_data->nameid); // Autolooting item: '%s'/'%s' {%u}
  5697. clif_displaymessage(fd, atcmd_output);
  5698. sd->state.autolooting = 1;
  5699. break;
  5700. case 2:
  5701. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5702. if (i == AUTOLOOTITEM_SIZE) {
  5703. clif_displaymessage(fd, msg_txt(sd,1193)); // You're currently not autolooting this item.
  5704. return -1;
  5705. }
  5706. sd->state.autolootid[i] = 0;
  5707. sprintf(atcmd_output, msg_txt(sd,1194), item_data->name.c_str(), item_db.create_item_link( item_data ).c_str(), item_data->nameid); // Removed item: '%s'/'%s' {%u} from your autolootitem list.
  5708. clif_displaymessage(fd, atcmd_output);
  5709. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5710. if (i == AUTOLOOTITEM_SIZE) {
  5711. sd->state.autolooting = 0;
  5712. }
  5713. break;
  5714. case 3:
  5715. sprintf(atcmd_output, msg_txt(sd,1195), AUTOLOOTITEM_SIZE); // You can have %d items on your autolootitem list.
  5716. clif_displaymessage(fd, atcmd_output);
  5717. clif_displaymessage(fd, msg_txt(sd,1196)); // To add an item to the list, use "@alootid +<item name or ID>". To remove an item, use "@alootid -<item name or ID>".
  5718. clif_displaymessage(fd, msg_txt(sd,1197)); // "@alootid reset" will clear your autolootitem list.
  5719. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5720. if (i == AUTOLOOTITEM_SIZE) {
  5721. clif_displaymessage(fd, msg_txt(sd,1198)); // Your autolootitem list is empty.
  5722. } else {
  5723. clif_displaymessage(fd, msg_txt(sd,1199)); // Items on your autolootitem list:
  5724. for(i = 0; i < AUTOLOOTITEM_SIZE; i++)
  5725. {
  5726. if (sd->state.autolootid[i] == 0)
  5727. continue;
  5728. item_data = item_db.find( sd->state.autolootid[i] );
  5729. if( item_data == nullptr ){
  5730. ShowDebug("Non-existant item %d on autolootitem list (account_id: %d, char_id: %d)", sd->state.autolootid[i], sd->status.account_id, sd->status.char_id);
  5731. continue;
  5732. }
  5733. sprintf(atcmd_output, "'%s'/'%s' {%u}", item_data->name.c_str(), item_db.create_item_link( item_data ).c_str(), item_data->nameid);
  5734. clif_displaymessage(fd, atcmd_output);
  5735. }
  5736. }
  5737. break;
  5738. case 4:
  5739. memset(sd->state.autolootid, 0, sizeof(sd->state.autolootid));
  5740. clif_displaymessage(fd, msg_txt(sd,1200)); // Your autolootitem list has been reset.
  5741. sd->state.autolooting = 0;
  5742. break;
  5743. }
  5744. return 0;
  5745. }
  5746. /*==========================================
  5747. * @autoloottype
  5748. * Flags:
  5749. * 1: IT_HEALING, 2: IT_UNKNOWN, 4: IT_USABLE, 8: IT_ETC,
  5750. * 16: IT_ARMOR, 32: IT_WEAPON, 64: IT_CARD, 128: IT_PETEGG,
  5751. * 256: IT_PETARMOR, 512: IT_UNKNOWN2, 1024: IT_AMMO, 2048: IT_DELAYCONSUME
  5752. * 262144: IT_CASH
  5753. *------------------------------------------
  5754. * Credits:
  5755. * chriser
  5756. * Aleos
  5757. *------------------------------------------*/
  5758. ACMD_FUNC(autoloottype)
  5759. {
  5760. uint8 action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  5761. enum item_types type= IT_UNKNOWN;
  5762. int ITEM_MAX = 1533;
  5763. nullpo_retr(-1, sd);
  5764. if (message && *message) {
  5765. if (message[0] == '+') {
  5766. message++;
  5767. action = 1;
  5768. }
  5769. else if (message[0] == '-') {
  5770. message++;
  5771. action = 2;
  5772. }
  5773. else if (!strcmp(message,"reset"))
  5774. action = 4;
  5775. }
  5776. if (action < 3) { // add or remove
  5777. if ((strncmp(message, "healing", 3) == 0) || (atoi(message) == 0))
  5778. type = IT_HEALING;
  5779. else if ((strncmp(message, "usable", 3) == 0) || (atoi(message) == 2))
  5780. type = IT_USABLE;
  5781. else if ((strncmp(message, "etc", 3) == 0) || (atoi(message) == 3))
  5782. type = IT_ETC;
  5783. else if ((strncmp(message, "armor", 3) == 0) || (atoi(message) == 4))
  5784. type = IT_ARMOR;
  5785. else if ((strncmp(message, "weapon", 3) == 0) || (atoi(message) == 5))
  5786. type = IT_WEAPON;
  5787. else if ((strncmp(message, "card", 3) == 0) || (atoi(message) == 6))
  5788. type = IT_CARD;
  5789. else if ((strncmp(message, "petegg", 4) == 0) || (atoi(message) == 7))
  5790. type = IT_PETEGG;
  5791. else if ((strncmp(message, "petarmor", 4) == 0) || (atoi(message) == 8))
  5792. type = IT_PETARMOR;
  5793. else if ((strncmp(message, "ammo", 3) == 0) || (atoi(message) == 10))
  5794. type = IT_AMMO;
  5795. else {
  5796. clif_displaymessage(fd, msg_txt(sd,1480)); // Item type not found.
  5797. return -1;
  5798. }
  5799. }
  5800. switch (action) {
  5801. case 1:
  5802. if (sd->state.autoloottype&(1<<type)) {
  5803. clif_displaymessage(fd, msg_txt(sd,1481)); // You're already autolooting this item type.
  5804. return -1;
  5805. }
  5806. if (sd->state.autoloottype == ITEM_MAX) {
  5807. clif_displaymessage(fd, msg_txt(sd,1482)); // Your autoloottype list has all item types. You can remove some items with @autoloottype -<type name or ID>.
  5808. return -1;
  5809. }
  5810. sd->state.autoloottype |= (1<<type); // Stores the type
  5811. sprintf(atcmd_output, msg_txt(sd,1483), itemdb_typename(type), type); // Autolooting item type: '%s' {%u}
  5812. clif_displaymessage(fd, atcmd_output);
  5813. break;
  5814. case 2:
  5815. if (!(sd->state.autoloottype&(1<<type))) {
  5816. clif_displaymessage(fd, msg_txt(sd,1484)); // You're currently not autolooting this item type.
  5817. return -1;
  5818. }
  5819. sd->state.autoloottype &= ~(1<<type);
  5820. sprintf(atcmd_output, msg_txt(sd,1485), itemdb_typename(type), type); // Removed item type: '%s' {%u} from your autoloottype list.
  5821. clif_displaymessage(fd, atcmd_output);
  5822. break;
  5823. case 3:
  5824. clif_displaymessage(fd, msg_txt(sd,1486)); // To add an item type to the list, use "@aloottype +<type name or ID>". To remove an item type, use "@aloottype -<type name or ID>".
  5825. clif_displaymessage(fd, msg_txt(sd,1487)); // Type List: healing = 0, usable = 2, etc = 3, armor = 4, weapon = 5, card = 6, petegg = 7, petarmor = 8, ammo = 10
  5826. clif_displaymessage(fd, msg_txt(sd,1488)); // "@aloottype reset" will clear your autoloottype list.
  5827. if (sd->state.autoloottype == 0)
  5828. clif_displaymessage(fd, msg_txt(sd,1489)); // Your autoloottype list is empty.
  5829. else {
  5830. uint8 i = 0;
  5831. clif_displaymessage(fd, msg_txt(sd,1490)); // Item types on your autoloottype list:
  5832. while (i < IT_MAX) {
  5833. if (sd->state.autoloottype&(1<<i)) {
  5834. sprintf(atcmd_output, " '%s' {%d}", itemdb_typename(static_cast<item_types>(i)), i);
  5835. clif_displaymessage(fd, atcmd_output);
  5836. }
  5837. i++;
  5838. }
  5839. }
  5840. break;
  5841. case 4:
  5842. sd->state.autoloottype = 0;
  5843. clif_displaymessage(fd, msg_txt(sd,1491)); // Your autoloottype list has been reset.
  5844. break;
  5845. }
  5846. return 0;
  5847. }
  5848. /*==========================================
  5849. * It is made to rain.
  5850. * No longer available, keeping here just in case it's back someday. [Ind]
  5851. *------------------------------------------*/
  5852. //ACMD_FUNC(rain)
  5853. //{
  5854. // nullpo_retr(-1, sd);
  5855. // if (map_getmapflag(sd->bl.m, MF_RAIN)) {
  5856. // map_setmapflag(sd->bl.m, MF_RAIN, false);
  5857. // clif_weather(sd->bl.m);
  5858. // clif_displaymessage(fd, msg_txt(sd,1201)); // The rain has stopped.
  5859. // } else {
  5860. // map_setmapflag(sd->bl.m, MF_RAIN, true);
  5861. // clif_weather(sd->bl.m);
  5862. // clif_displaymessage(fd, msg_txt(sd,1202)); // It has started to rain.
  5863. // }
  5864. // return 0;
  5865. //}
  5866. /*==========================================
  5867. * It is made to snow.
  5868. *------------------------------------------*/
  5869. ACMD_FUNC(snow)
  5870. {
  5871. nullpo_retr(-1, sd);
  5872. if (map_getmapflag(sd->bl.m, MF_SNOW)) {
  5873. map_setmapflag(sd->bl.m, MF_SNOW, false);
  5874. clif_weather(sd->bl.m);
  5875. clif_displaymessage(fd, msg_txt(sd,1203)); // Snow has stopped falling.
  5876. } else {
  5877. map_setmapflag(sd->bl.m, MF_SNOW, true);
  5878. clif_weather(sd->bl.m);
  5879. clif_displaymessage(fd, msg_txt(sd,1204)); // It has started to snow.
  5880. }
  5881. return 0;
  5882. }
  5883. /*==========================================
  5884. * Cherry tree snowstorm is made to fall. (Sakura)
  5885. *------------------------------------------*/
  5886. ACMD_FUNC(sakura)
  5887. {
  5888. nullpo_retr(-1, sd);
  5889. if (map_getmapflag(sd->bl.m, MF_SAKURA)) {
  5890. map_setmapflag(sd->bl.m, MF_SAKURA, false);
  5891. clif_weather(sd->bl.m);
  5892. clif_displaymessage(fd, msg_txt(sd,1205)); // Cherry tree leaves no longer fall.
  5893. } else {
  5894. map_setmapflag(sd->bl.m, MF_SAKURA, true);
  5895. clif_weather(sd->bl.m);
  5896. clif_displaymessage(fd, msg_txt(sd,1206)); // Cherry tree leaves have begun to fall.
  5897. }
  5898. return 0;
  5899. }
  5900. /*==========================================
  5901. * Clouds appear.
  5902. *------------------------------------------*/
  5903. ACMD_FUNC(clouds)
  5904. {
  5905. nullpo_retr(-1, sd);
  5906. if (map_getmapflag(sd->bl.m, MF_CLOUDS)) {
  5907. map_setmapflag(sd->bl.m, MF_CLOUDS, false);
  5908. clif_weather(sd->bl.m);
  5909. clif_displaymessage(fd, msg_txt(sd,1207)); // The clouds has disappear.
  5910. } else {
  5911. map_setmapflag(sd->bl.m, MF_CLOUDS, true);
  5912. clif_weather(sd->bl.m);
  5913. clif_displaymessage(fd, msg_txt(sd,1208)); // Clouds appear.
  5914. }
  5915. return 0;
  5916. }
  5917. /*==========================================
  5918. * Different type of clouds using effect 516
  5919. *------------------------------------------*/
  5920. ACMD_FUNC(clouds2)
  5921. {
  5922. nullpo_retr(-1, sd);
  5923. if (map_getmapflag(sd->bl.m, MF_CLOUDS2)) {
  5924. map_setmapflag(sd->bl.m, MF_CLOUDS2, false);
  5925. clif_weather(sd->bl.m);
  5926. clif_displaymessage(fd, msg_txt(sd,1209)); // The alternative clouds disappear.
  5927. } else {
  5928. map_setmapflag(sd->bl.m, MF_CLOUDS2, true);
  5929. clif_weather(sd->bl.m);
  5930. clif_displaymessage(fd, msg_txt(sd,1210)); // Alternative clouds appear.
  5931. }
  5932. return 0;
  5933. }
  5934. /*==========================================
  5935. * Fog hangs over.
  5936. *------------------------------------------*/
  5937. ACMD_FUNC(fog)
  5938. {
  5939. nullpo_retr(-1, sd);
  5940. if (map_getmapflag(sd->bl.m, MF_FOG)) {
  5941. map_setmapflag(sd->bl.m, MF_FOG, false);
  5942. clif_weather(sd->bl.m);
  5943. clif_displaymessage(fd, msg_txt(sd,1211)); // The fog has gone.
  5944. } else {
  5945. map_setmapflag(sd->bl.m, MF_FOG, true);
  5946. clif_weather(sd->bl.m);
  5947. clif_displaymessage(fd, msg_txt(sd,1212)); // Fog hangs over.
  5948. }
  5949. return 0;
  5950. }
  5951. /*==========================================
  5952. * Fallen leaves fall.
  5953. *------------------------------------------*/
  5954. ACMD_FUNC(leaves)
  5955. {
  5956. nullpo_retr(-1, sd);
  5957. if (map_getmapflag(sd->bl.m, MF_LEAVES)) {
  5958. map_setmapflag(sd->bl.m, MF_LEAVES, false);
  5959. clif_weather(sd->bl.m);
  5960. clif_displaymessage(fd, msg_txt(sd,1213)); // Leaves no longer fall.
  5961. } else {
  5962. map_setmapflag(sd->bl.m, MF_LEAVES, true);
  5963. clif_weather(sd->bl.m);
  5964. clif_displaymessage(fd, msg_txt(sd,1214)); // Fallen leaves fall.
  5965. }
  5966. return 0;
  5967. }
  5968. /*==========================================
  5969. * Fireworks appear.
  5970. *------------------------------------------*/
  5971. ACMD_FUNC(fireworks)
  5972. {
  5973. nullpo_retr(-1, sd);
  5974. if (map_getmapflag(sd->bl.m, MF_FIREWORKS)) {
  5975. map_setmapflag(sd->bl.m, MF_FIREWORKS, false);
  5976. clif_weather(sd->bl.m);
  5977. clif_displaymessage(fd, msg_txt(sd,1215)); // Fireworks have ended.
  5978. } else {
  5979. map_setmapflag(sd->bl.m, MF_FIREWORKS, true);
  5980. clif_weather(sd->bl.m);
  5981. clif_displaymessage(fd, msg_txt(sd,1216)); // Fireworks have launched.
  5982. }
  5983. return 0;
  5984. }
  5985. /*==========================================
  5986. * Clearing Weather Effects by Dexity
  5987. *------------------------------------------*/
  5988. ACMD_FUNC(clearweather)
  5989. {
  5990. nullpo_retr(-1, sd);
  5991. //map_setmapflag(sd->bl.m, MF_RAIN, false); // No longer available, keeping here just in case it's back someday. [Ind]
  5992. map_setmapflag(sd->bl.m, MF_SNOW, false);
  5993. map_setmapflag(sd->bl.m, MF_SAKURA, false);
  5994. map_setmapflag(sd->bl.m, MF_CLOUDS, false);
  5995. map_setmapflag(sd->bl.m, MF_CLOUDS2, false);
  5996. map_setmapflag(sd->bl.m, MF_FOG, false);
  5997. map_setmapflag(sd->bl.m, MF_FIREWORKS, false);
  5998. map_setmapflag(sd->bl.m, MF_LEAVES, false);
  5999. clif_weather(sd->bl.m);
  6000. clif_displaymessage(fd, msg_txt(sd,291)); // Weather effects will dispell on warp/refresh
  6001. return 0;
  6002. }
  6003. /*===============================================================
  6004. * Sound Command - plays a sound for everyone around! [Codemaster]
  6005. *---------------------------------------------------------------*/
  6006. ACMD_FUNC(sound)
  6007. {
  6008. char sound_file[100];
  6009. memset(sound_file, '\0', sizeof(sound_file));
  6010. if(!message || !*message || sscanf(message, "%99[^\n]", sound_file) < 1) {
  6011. clif_displaymessage(fd, msg_txt(sd,1217)); // Please enter a sound filename (usage: @sound <filename>).
  6012. return -1;
  6013. }
  6014. if(strstr(sound_file, ".wav") == nullptr)
  6015. strcat(sound_file, ".wav");
  6016. clif_soundeffect( sd->bl, sound_file, 0, AREA );
  6017. return 0;
  6018. }
  6019. /*==========================================
  6020. * MOB Search
  6021. *------------------------------------------*/
  6022. ACMD_FUNC(mobsearch)
  6023. {
  6024. nullpo_retr(-1, sd);
  6025. char mob_name[100]={0};
  6026. if (!message || !*message || sscanf(message, "%99[^\n]", mob_name) < 1) {
  6027. clif_displaymessage(fd, msg_txt(sd,1218)); // Please enter a monster name (usage: @mobsearch <monster name>).
  6028. return -1;
  6029. }
  6030. int mob_id = strtol(mob_name, nullptr, 10);
  6031. if (mob_id == 0)
  6032. mob_id = mobdb_searchname(mob_name);
  6033. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  6034. if (mob == nullptr || mobdb_checkid(mob_id) == 0) {
  6035. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1219),mob_name); // Invalid mob ID %s!
  6036. clif_displaymessage(fd, atcmd_output);
  6037. return -1;
  6038. }
  6039. strcpy(mob_name, mob->jname.c_str()); // --ja--
  6040. // strcpy(mob_name, mob->name.c_str()); // --en--
  6041. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s
  6042. clif_displaymessage(fd, atcmd_output);
  6043. s_mapiterator* it = mapit_geteachmob();
  6044. int number = 0;
  6045. for(;;)
  6046. {
  6047. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6048. if( md == nullptr )
  6049. break;// no more mobs
  6050. if( md->bl.m != sd->bl.m )
  6051. continue;
  6052. if( md->mob_id != mob_id )
  6053. continue;
  6054. ++number;
  6055. if( md->spawn_timer == INVALID_TIMER )
  6056. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%3d:%3d] %s", number, md->bl.x, md->bl.y, md->name);
  6057. else
  6058. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name);
  6059. clif_displaymessage(fd, atcmd_output);
  6060. }
  6061. mapit_free(it);
  6062. return 0;
  6063. }
  6064. /*==========================================
  6065. * @cleanmap - cleans items on the ground
  6066. * @cleanarea - cleans items on the ground within an specified area
  6067. *------------------------------------------*/
  6068. static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap)
  6069. {
  6070. nullpo_ret(bl);
  6071. map_clearflooritem(bl);
  6072. return 0;
  6073. }
  6074. ACMD_FUNC(cleanmap)
  6075. {
  6076. map_foreachinmap(atcommand_cleanfloor_sub, sd->bl.m, BL_ITEM);
  6077. clif_displaymessage(fd, msg_txt(sd,1221)); // All dropped items have been cleaned up.
  6078. return 0;
  6079. }
  6080. ACMD_FUNC(cleanarea)
  6081. {
  6082. short x0 = 0, y0 = 0, x1 = 0, y1 = 0;
  6083. if (!message || !*message || sscanf(message, "%6hd %6hd %6hd %6hd", &x0, &y0, &x1, &y1) < 1) {
  6084. map_foreachinallarea(atcommand_cleanfloor_sub, sd->bl.m, sd->bl.x - (AREA_SIZE * 2), sd->bl.y - (AREA_SIZE * 2), sd->bl.x + (AREA_SIZE * 2), sd->bl.y + (AREA_SIZE * 2), BL_ITEM);
  6085. }
  6086. else if (sscanf(message, "%6hd %6hd %6hd %6hd", &x0, &y0, &x1, &y1) == 1) {
  6087. map_foreachinallarea(atcommand_cleanfloor_sub, sd->bl.m, sd->bl.x - x0, sd->bl.y - x0, sd->bl.x + x0, sd->bl.y + x0, BL_ITEM);
  6088. }
  6089. else if (sscanf(message, "%6hd %6hd %6hd %6hd", &x0, &y0, &x1, &y1) == 4) {
  6090. map_foreachinallarea(atcommand_cleanfloor_sub, sd->bl.m, x0, y0, x1, y1, BL_ITEM);
  6091. }
  6092. clif_displaymessage(fd, msg_txt(sd,1221)); // All dropped items have been cleaned up.
  6093. return 0;
  6094. }
  6095. /*==========================================
  6096. * make a NPC/PET talk
  6097. * @npctalkc [SnakeDrak]
  6098. *------------------------------------------*/
  6099. ACMD_FUNC(npctalk)
  6100. {
  6101. char name[NPC_NAME_LENGTH],mes[100],temp[CHAT_SIZE_MAX];
  6102. struct npc_data *nd;
  6103. bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
  6104. unsigned long color=0;
  6105. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  6106. return -1; //no "chatting" while muted.
  6107. if(!ifcolor) {
  6108. if (!message || !*message || sscanf(message, "%49[^,], %99[^\n]", name, mes) < 2) {
  6109. clif_displaymessage(fd, msg_txt(sd,1222)); // Please enter the correct parameters (usage: @npctalk <npc name>, <message>).
  6110. return -1;
  6111. }
  6112. }
  6113. else {
  6114. if (!message || !*message || sscanf(message, "%16lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
  6115. clif_displaymessage(fd, msg_txt(sd,1223)); // Please enter the correct parameters (usage: @npctalkc <color> <npc name>, <message>).
  6116. return -1;
  6117. }
  6118. }
  6119. if (!(nd = npc_name2id(name))) {
  6120. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist
  6121. return -1;
  6122. }
  6123. strtok(name, "#"); // discard extra name identifier if present
  6124. snprintf(temp, sizeof(temp), "%s : %s", name, mes);
  6125. if(ifcolor) clif_messagecolor(&nd->bl,color,temp,true,AREA_CHAT_WOC);
  6126. else clif_disp_overhead(&nd->bl, temp);
  6127. return 0;
  6128. }
  6129. ACMD_FUNC(pettalk)
  6130. {
  6131. char mes[100],temp[CHAT_SIZE_MAX];
  6132. struct pet_data *pd;
  6133. nullpo_retr(-1, sd);
  6134. if ( battle_config.min_chat_delay ) {
  6135. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  6136. return 0;
  6137. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  6138. }
  6139. if(!sd->status.pet_id || !(pd=sd->pd))
  6140. {
  6141. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  6142. return -1;
  6143. }
  6144. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  6145. return -1; //no "chatting" while muted.
  6146. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6147. clif_displaymessage(fd, msg_txt(sd,1224)); // Please enter a message (usage: @pettalk <message>).
  6148. return -1;
  6149. }
  6150. if (message[0] == '/')
  6151. {// pet emotion processing
  6152. const char* emo[] = {
  6153. "/!", "/?", "/ho", "/lv", "/swt", "/ic", "/an", "/ag", "/$", "/...",
  6154. "/scissors", "/rock", "/paper", "/korea", "/lv2", "/thx", "/wah", "/sry", "/heh", "/swt2",
  6155. "/hmm", "/no1", "/??", "/omg", "/O", "/X", "/hlp", "/go", "/sob", "/gg",
  6156. "/kis", "/kis2", "/pif", "/ok", "-?-", "/indonesia", "/bzz", "/rice", "/awsm", "/meh",
  6157. "/shy", "/pat", "/mp", "/slur", "/com", "/yawn", "/grat", "/hp", "/philippines", "/malaysia",
  6158. "/singapore", "/brazil", "/fsh", "/spin", "/sigh", "/dum", "/crwd", "/desp", "/dice", "-dice2",
  6159. "-dice3", "-dice4", "-dice5", "-dice6", "/india", "/love", "/russia", "-?-", "/mobile", "/mail",
  6160. "/chinese", "/antenna1", "/antenna2", "/antenna3", "/hum", "/abs", "/oops", "/spit", "/ene", "/panic",
  6161. "/whisp"
  6162. };
  6163. int i;
  6164. ARR_FIND( 0, ARRAYLENGTH(emo), i, stricmp(message, emo[i]) == 0 );
  6165. if( i == ET_DICE1 ) i = rnd_value<int>(ET_DICE1, ET_DICE6); // randomize /dice
  6166. if( i < ARRAYLENGTH(emo) )
  6167. {
  6168. if (sd->emotionlasttime + 1 >= time(nullptr)) { // not more than 1 per second
  6169. sd->emotionlasttime = time(nullptr);
  6170. return 0;
  6171. }
  6172. sd->emotionlasttime = time(nullptr);
  6173. clif_emotion(&pd->bl, i);
  6174. return 0;
  6175. }
  6176. }
  6177. snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes);
  6178. clif_disp_overhead(&pd->bl, temp);
  6179. return 0;
  6180. }
  6181. /// @users - displays the number of players present on each map (and percentage)
  6182. /// #users displays on the target user instead of self
  6183. ACMD_FUNC(users)
  6184. {
  6185. char buf[CHAT_SIZE_MAX];
  6186. int i;
  6187. int users[MAX_MAPINDEX];
  6188. int users_all;
  6189. struct s_mapiterator* iter;
  6190. memset(users, 0, sizeof(users));
  6191. users_all = 0;
  6192. // count users on each map
  6193. iter = mapit_getallusers();
  6194. for(;;)
  6195. {
  6196. map_session_data* sd2 = (map_session_data*)mapit_next(iter);
  6197. if( sd2 == nullptr )
  6198. break;// no more users
  6199. if( sd2->mapindex >= MAX_MAPINDEX )
  6200. continue;// invalid mapindex
  6201. if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
  6202. if( users_all < INT_MAX ) ++users_all;
  6203. }
  6204. mapit_free(iter);
  6205. // display results for each map
  6206. for( i = 0; i < MAX_MAPINDEX; ++i )
  6207. {
  6208. if( users[i] == 0 )
  6209. continue;// empty
  6210. safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
  6211. clif_displaymessage(sd->fd, buf);
  6212. }
  6213. // display overall count
  6214. safesnprintf(buf, sizeof(buf), "all: %d", users_all);
  6215. clif_displaymessage(sd->fd, buf);
  6216. return 0;
  6217. }
  6218. /*==========================================
  6219. *
  6220. *------------------------------------------*/
  6221. ACMD_FUNC(reset)
  6222. {
  6223. pc_resetstate(sd);
  6224. pc_resetskill(sd,1);
  6225. sprintf(atcmd_output, msg_txt(sd,208), sd->status.name); // '%s' skill and stats points reseted!
  6226. clif_displaymessage(fd, atcmd_output);
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. *
  6231. *------------------------------------------*/
  6232. ACMD_FUNC(summon)
  6233. {
  6234. char name[NAME_LENGTH];
  6235. int mob_id = 0;
  6236. int duration = 0;
  6237. struct mob_data *md;
  6238. t_tick tick=gettick();
  6239. nullpo_retr(-1, sd);
  6240. if (!message || !*message || sscanf(message, "%23s %11d", name, &duration) < 1)
  6241. {
  6242. clif_displaymessage(fd, msg_txt(sd,1225)); // Please enter a monster name (usage: @summon <monster name> {duration}).
  6243. return -1;
  6244. }
  6245. if (duration < 1)
  6246. duration =1;
  6247. else if (duration > 60)
  6248. duration =60;
  6249. if ((mob_id = atoi(name)) == 0)
  6250. mob_id = mobdb_searchname(name);
  6251. if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
  6252. {
  6253. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  6254. return -1;
  6255. }
  6256. md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE);
  6257. if(!md)
  6258. return -1;
  6259. md->master_id=sd->bl.id;
  6260. md->special_state.ai=AI_ATTACK;
  6261. md->deletetimer=add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
  6262. clif_specialeffect(&md->bl,EF_ENTRY2,AREA);
  6263. mob_spawn(md);
  6264. sc_start4(nullptr,&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  6265. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
  6266. clif_displaymessage(fd, msg_txt(sd,39)); // All monster summoned!
  6267. return 0;
  6268. }
  6269. /*==========================================
  6270. * @adjgroup
  6271. * Temporarily move player to another group
  6272. * Useful during beta testing to allow players to use GM commands for short periods of time
  6273. *------------------------------------------*/
  6274. ACMD_FUNC(adjgroup)
  6275. {
  6276. int new_group = 0;
  6277. nullpo_retr(-1, sd);
  6278. if (!message || !*message || sscanf(message, "%11d", &new_group) != 1) {
  6279. clif_displaymessage(fd, msg_txt(sd,1226)); // Usage: @adjgroup <group_id>
  6280. return -1;
  6281. }
  6282. if (!player_group_db.exists(new_group)) {
  6283. clif_displaymessage(fd, msg_txt(sd,1227)); // Specified group does not exist.
  6284. return -1;
  6285. }
  6286. sd->group_id = new_group;
  6287. pc_group_pc_load(sd);/* update cache */
  6288. clif_displaymessage(fd, msg_txt(sd,1228)); // Group changed successfully.
  6289. clif_displaymessage(sd->fd, msg_txt(sd,1229)); // Your group has changed.
  6290. return 0;
  6291. }
  6292. /*==========================================
  6293. * @trade by [MouseJstr]
  6294. * Open a trade window with a remote player
  6295. *------------------------------------------*/
  6296. ACMD_FUNC(trade)
  6297. {
  6298. map_session_data* pl_sd = nullptr;;
  6299. nullpo_retr(-1, sd);
  6300. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  6301. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  6302. clif_displaymessage(fd, msg_txt(sd,1230)); // Please enter a player name (usage: @trade <char name>).
  6303. return -1;
  6304. }
  6305. if ( (pl_sd = map_nick2sd(atcmd_player_name,true)) == nullptr )
  6306. {
  6307. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  6308. return -1;
  6309. }
  6310. trade_traderequest(sd, pl_sd);
  6311. return 0;
  6312. }
  6313. /*==========================================
  6314. * @setbattleflag by [MouseJstr]
  6315. * set a battle_config flag without having to reboot
  6316. *------------------------------------------*/
  6317. ACMD_FUNC(setbattleflag)
  6318. {
  6319. char flag[128], value[128];
  6320. int reload = 0;
  6321. nullpo_retr(-1, sd);
  6322. if (!message || !*message || sscanf(message, "%127s %127s %11d", flag, value, &reload) < 2) {
  6323. clif_displaymessage(fd, msg_txt(sd,1231)); // Usage: @setbattleflag <flag> <value> {<reload>}
  6324. return -1;
  6325. }
  6326. if (battle_set_value(flag, value) == 0)
  6327. {
  6328. clif_displaymessage(fd, msg_txt(sd,1232)); // Unknown battle_config flag.
  6329. return -1;
  6330. }
  6331. clif_displaymessage(fd, msg_txt(sd,1233)); // Set battle_config as requested.
  6332. if (reload)
  6333. mob_reload();
  6334. return 0;
  6335. }
  6336. /*==========================================
  6337. * @unmute [Valaris]
  6338. *------------------------------------------*/
  6339. ACMD_FUNC(unmute)
  6340. {
  6341. map_session_data* pl_sd = nullptr;;
  6342. nullpo_retr(-1, sd);
  6343. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  6344. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  6345. clif_displaymessage(fd, msg_txt(sd,1234)); // Please enter a player name (usage: @unmute <char name>).
  6346. return -1;
  6347. }
  6348. if ( (pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr )
  6349. {
  6350. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  6351. return -1;
  6352. }
  6353. if(!pl_sd->sc.getSCE(SC_NOCHAT)) {
  6354. clif_displaymessage(sd->fd,msg_txt(sd,1235)); // Player is not muted.
  6355. return -1;
  6356. }
  6357. pl_sd->status.manner = 0;
  6358. status_change_end(&pl_sd->bl, SC_NOCHAT);
  6359. clif_displaymessage(sd->fd,msg_txt(sd,1236)); // Player unmuted.
  6360. return 0;
  6361. }
  6362. /*==========================================
  6363. * @uptime by MC Cameri
  6364. *------------------------------------------*/
  6365. ACMD_FUNC(uptime)
  6366. {
  6367. unsigned long seconds = 0, day = 24*60*60, hour = 60*60,
  6368. minute = 60, days = 0, hours = 0, minutes = 0;
  6369. nullpo_retr(-1, sd);
  6370. seconds = get_uptime();
  6371. days = seconds/day;
  6372. seconds -= (seconds/day>0)?(seconds/day)*day:0;
  6373. hours = seconds/hour;
  6374. seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
  6375. minutes = seconds/minute;
  6376. seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
  6377. snprintf(atcmd_output, sizeof(atcmd_output), msg_txt(sd,245), days, hours, minutes, seconds); // Server Uptime: %ld days, %ld hours, %ld minutes, %ld seconds.
  6378. clif_displaymessage(fd, atcmd_output);
  6379. return 0;
  6380. }
  6381. /*==========================================
  6382. * @changesex
  6383. * => Changes one's account sex. Switch from male to female or visversa
  6384. *------------------------------------------*/
  6385. ACMD_FUNC(changesex)
  6386. {
  6387. int i;
  6388. nullpo_retr(-1, sd);
  6389. pc_resetskill(sd,4);
  6390. // to avoid any problem with equipment and invalid sex, equipment is unequiped.
  6391. for (i = 0; i < EQI_MAX; i++) {
  6392. if (sd->equip_index[i] >= 0)
  6393. pc_unequipitem(sd, sd->equip_index[i], 3);
  6394. }
  6395. chrif_changesex(sd, true);
  6396. return 0;
  6397. }
  6398. /*==========================================
  6399. * @changecharsex
  6400. * => Changes one's character sex. Switch from male to female or visversa.
  6401. *------------------------------------------*/
  6402. ACMD_FUNC(changecharsex)
  6403. {
  6404. int i;
  6405. nullpo_retr(-1, sd);
  6406. pc_resetskill(sd,4);
  6407. // to avoid any problem with equipment and invalid sex, equipment is unequiped.
  6408. for (i = 0; i < EQI_MAX; i++) {
  6409. if (sd->equip_index[i] >= 0)
  6410. pc_unequipitem(sd, sd->equip_index[i], 3);
  6411. }
  6412. chrif_changesex(sd, false);
  6413. return 0;
  6414. }
  6415. /*================================================
  6416. * @mute - Mutes a player for a set amount of time
  6417. *------------------------------------------------*/
  6418. ACMD_FUNC(mute)
  6419. {
  6420. map_session_data* pl_sd = nullptr;;
  6421. int manner;
  6422. nullpo_retr(-1, sd);
  6423. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  6424. if (!message || !*message || sscanf(message, "%11d %23[^\n]", &manner, atcmd_player_name) < 1) {
  6425. clif_displaymessage(fd, msg_txt(sd,1237)); // Usage: @mute <time> <char name>
  6426. return -1;
  6427. }
  6428. if ( (pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr )
  6429. {
  6430. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  6431. return -1;
  6432. }
  6433. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  6434. {
  6435. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  6436. return -1;
  6437. }
  6438. clif_manner_message(sd, 0);
  6439. clif_manner_message(pl_sd, 5);
  6440. if( pl_sd->status.manner < manner ) {
  6441. pl_sd->status.manner -= manner;
  6442. sc_start(nullptr,&pl_sd->bl,SC_NOCHAT,100,0,0);
  6443. } else {
  6444. pl_sd->status.manner = 0;
  6445. status_change_end(&pl_sd->bl, SC_NOCHAT);
  6446. }
  6447. clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
  6448. return 0;
  6449. }
  6450. /*==========================================
  6451. * @refresh (like @jumpto <<yourself>>)
  6452. *------------------------------------------*/
  6453. ACMD_FUNC(refresh)
  6454. {
  6455. nullpo_retr(-1, sd);
  6456. clif_refresh(sd);
  6457. return 0;
  6458. }
  6459. ACMD_FUNC(refreshall)
  6460. {
  6461. map_session_data* iter_sd;
  6462. struct s_mapiterator* iter;
  6463. nullpo_retr(-1, sd);
  6464. iter = mapit_getallusers();
  6465. for (iter_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); iter_sd = (TBL_PC*)mapit_next(iter))
  6466. clif_refresh(iter_sd);
  6467. mapit_free(iter);
  6468. return 0;
  6469. }
  6470. /*==========================================
  6471. * @identify
  6472. * => GM's magnifier.
  6473. *------------------------------------------*/
  6474. ACMD_FUNC(identify)
  6475. {
  6476. int i,num;
  6477. nullpo_retr(-1, sd);
  6478. for(i=num=0;i<MAX_INVENTORY;i++){
  6479. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].identify != 1) {
  6480. num++;
  6481. }
  6482. }
  6483. if (num > 0) {
  6484. clif_item_identify_list(sd);
  6485. } else {
  6486. clif_displaymessage(fd,msg_txt(sd,1238)); // There are no items to appraise.
  6487. }
  6488. return 0;
  6489. }
  6490. /*===============================================
  6491. * @identifyall
  6492. * => Indentify all items in inventory - Akinari
  6493. *-----------------------------------------------*/
  6494. ACMD_FUNC(identifyall)
  6495. {
  6496. nullpo_retr(-1, sd);
  6497. pc_identifyall(sd, true);
  6498. return 0;
  6499. }
  6500. /*==========================================
  6501. * @gmotd (Global MOTD)
  6502. * by davidsiaw :P
  6503. *------------------------------------------*/
  6504. ACMD_FUNC(gmotd)
  6505. {
  6506. FILE* fp;
  6507. if( ( fp = fopen(motd_txt, "r") ) != nullptr )
  6508. {
  6509. char buf[CHAT_SIZE_MAX];
  6510. size_t len;
  6511. while( fgets(buf, sizeof(buf), fp) )
  6512. {
  6513. if( buf[0] == '/' && buf[1] == '/' )
  6514. {
  6515. continue;
  6516. }
  6517. len = strlen(buf);
  6518. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) )
  6519. {// strip trailing EOL characters
  6520. len--;
  6521. }
  6522. if( len )
  6523. {
  6524. buf[len] = 0;
  6525. intif_broadcast(buf, len+1, 0);
  6526. }
  6527. }
  6528. fclose(fp);
  6529. }
  6530. return 0;
  6531. }
  6532. ACMD_FUNC(misceffect)
  6533. {
  6534. int effect = 0;
  6535. nullpo_retr(-1, sd);
  6536. if (!message || !*message)
  6537. return -1;
  6538. if (sscanf(message, "%11d", &effect) < 1)
  6539. return -1;
  6540. clif_misceffect(&sd->bl,effect);
  6541. return 0;
  6542. }
  6543. /*==========================================
  6544. * MAIL SYSTEM
  6545. *------------------------------------------*/
  6546. ACMD_FUNC(mail)
  6547. {
  6548. nullpo_ret(sd);
  6549. mail_openmail(sd);
  6550. return 0;
  6551. }
  6552. /*==========================================
  6553. * Show Monster DB Info v 1.0
  6554. * originally by [Lupus]
  6555. *------------------------------------------*/
  6556. ACMD_FUNC(mobinfo)
  6557. {
  6558. unsigned char msize[SZ_ALL][7] = { "Small", "Medium", "Large" };
  6559. unsigned char mrace[RC_ALL][11] = { "Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Player" };
  6560. unsigned char melement[ELE_ALL][8] = { "Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead" };
  6561. char atcmd_output2[CHAT_SIZE_MAX];
  6562. uint16 mob_ids[MAX_SEARCH], count;
  6563. uint16 i;
  6564. memset(atcmd_output, '\0', sizeof(atcmd_output));
  6565. memset(atcmd_output2, '\0', sizeof(atcmd_output2));
  6566. if (!message || !*message) {
  6567. clif_displaymessage(fd, msg_txt(sd,1239)); // Please enter a monster name/ID (usage: @mobinfo <monster_name_or_monster_ID>).
  6568. return -1;
  6569. }
  6570. // If monster identifier/name argument is a name
  6571. if ((i = mobdb_checkid(strtoul(message, nullptr, 10))))
  6572. {
  6573. mob_ids[0] = i;
  6574. count = 1;
  6575. } else
  6576. count = mobdb_searchname_array(message, mob_ids, MAX_SEARCH);
  6577. if (!count) {
  6578. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  6579. return -1;
  6580. }
  6581. if (count >= MAX_SEARCH) {
  6582. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH); // Displaying first %d matches
  6583. clif_displaymessage(fd, atcmd_output);
  6584. count = MAX_SEARCH;
  6585. }
  6586. for (uint16 k = 0; k < count; k++) {
  6587. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_ids[k]);
  6588. if (mob == nullptr)
  6589. continue;
  6590. t_exp base_exp = mob->base_exp;
  6591. t_exp job_exp = mob->job_exp;
  6592. if (pc_isvip(sd)) { // Display EXP rate increase for VIP
  6593. base_exp += (base_exp * battle_config.vip_base_exp_increase) / 100;
  6594. job_exp += (job_exp * battle_config.vip_job_exp_increase) / 100;
  6595. }
  6596. #ifdef RENEWAL_EXP
  6597. if( battle_config.atcommand_mobinfo_type ) {
  6598. int penalty = pc_level_penalty_mod( sd, PENALTY_EXP, mob );
  6599. base_exp = base_exp * penalty / 100;
  6600. job_exp = job_exp * penalty / 100;
  6601. }
  6602. #endif
  6603. // stats
  6604. if( mob->get_bosstype() == BOSSTYPE_MVP )
  6605. sprintf(atcmd_output, msg_txt(sd,1240), mob->name.c_str(), mob->jname.c_str(), mob->sprite.c_str(), mob->id); // MVP Monster: '%s'/'%s'/'%s' (%d)
  6606. else
  6607. sprintf(atcmd_output, msg_txt(sd,1241), mob->name.c_str(), mob->jname.c_str(), mob->sprite.c_str(), mob->id); // Monster: '%s'/'%s'/'%s' (%d)
  6608. clif_displaymessage(fd, atcmd_output);
  6609. sprintf(atcmd_output, msg_txt(sd,1242), mob->lv, mob->status.max_hp, base_exp, job_exp, MOB_HIT(mob), MOB_FLEE(mob)); // Lv:%d HP:%d Base EXP:%llu Job EXP:%llu HIT:%d FLEE:%d
  6610. clif_displaymessage(fd, atcmd_output);
  6611. sprintf(atcmd_output, msg_txt(sd,1243), // DEF:%d MDEF:%d STR:%d AGI:%d VIT:%d INT:%d DEX:%d LUK:%d
  6612. mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
  6613. mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
  6614. clif_displaymessage(fd, atcmd_output);
  6615. sprintf(atcmd_output, msg_txt(sd,1244), // ATK:%d~%d Range:%d~%d~%d Size:%s Race: %s Element: %s (Lv:%d)
  6616. mob->status.batk + mob->status.rhw.atk, mob->status.batk + mob->status.rhw.atk2, mob->status.rhw.range,
  6617. mob->range2 , mob->range3, msize[mob->status.size],
  6618. mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
  6619. clif_displaymessage(fd, atcmd_output);
  6620. #ifdef RENEWAL
  6621. sprintf(atcmd_output, msg_txt(sd, 827), mob->status.res, mob->status.mres);// MDEF:%d RES:%d MRES:%d
  6622. clif_displaymessage(fd, atcmd_output);
  6623. #endif
  6624. // drops
  6625. clif_displaymessage(fd, msg_txt(sd,1245)); // Drops:
  6626. strcpy(atcmd_output, " ");
  6627. unsigned int j = 0;
  6628. int drop_modifier = 100;
  6629. #ifdef RENEWAL_DROP
  6630. if( battle_config.atcommand_mobinfo_type ){
  6631. drop_modifier = pc_level_penalty_mod( sd, PENALTY_DROP, mob );
  6632. }
  6633. #endif
  6634. for (i = 0; i < MAX_MOB_DROP_TOTAL; i++) {
  6635. if (mob->dropitem[i].nameid == 0 || mob->dropitem[i].rate < 1)
  6636. continue;
  6637. std::shared_ptr<item_data> id = item_db.find(mob->dropitem[i].nameid);
  6638. if (id == nullptr)
  6639. continue;
  6640. int droprate = mob_getdroprate( &sd->bl, mob, mob->dropitem[i].rate, drop_modifier );
  6641. sprintf(atcmd_output2, " - %s %02.02f%%", item_db.create_item_link( id ).c_str(), (float)droprate / 100);
  6642. strcat(atcmd_output, atcmd_output2);
  6643. if (++j % 3 == 0) {
  6644. clif_displaymessage(fd, atcmd_output);
  6645. strcpy(atcmd_output, " ");
  6646. }
  6647. }
  6648. if (j == 0)
  6649. clif_displaymessage(fd, msg_txt(sd,1246)); // This monster has no drops.
  6650. else if (j % 3 != 0)
  6651. clif_displaymessage(fd, atcmd_output);
  6652. // mvp
  6653. if( mob->get_bosstype() == BOSSTYPE_MVP ){
  6654. float mvppercent, mvpremain;
  6655. sprintf(atcmd_output, msg_txt(sd,1247), mob->mexp); // MVP Bonus EXP:%llu
  6656. clif_displaymessage(fd, atcmd_output);
  6657. strcpy(atcmd_output, msg_txt(sd,1248)); // MVP Items:
  6658. mvpremain = 100.0; //Remaining drop chance for official mvp drop mode
  6659. j = 0;
  6660. for (i = 0; i < MAX_MVP_DROP_TOTAL; i++) {
  6661. if (mob->mvpitem[i].nameid == 0)
  6662. continue;
  6663. std::shared_ptr<item_data> id = item_db.find(mob->mvpitem[i].nameid);
  6664. if (id == nullptr)
  6665. continue;
  6666. //Because if there are 3 MVP drops at 50%, the first has a chance of 50%, the second 25% and the third 12.5%
  6667. mvppercent = (float)mob->mvpitem[i].rate * mvpremain / 10000.0f;
  6668. if(battle_config.item_drop_mvp_mode == 0) {
  6669. mvpremain -= mvppercent;
  6670. }
  6671. if (mvppercent > 0) {
  6672. j++;
  6673. if (j == 1) {
  6674. sprintf(atcmd_output2, " %s %02.02f%%", item_db.create_item_link( id ).c_str(), mvppercent);
  6675. } else {
  6676. sprintf(atcmd_output2, " - %s %02.02f%%", item_db.create_item_link( id ).c_str(), mvppercent);
  6677. }
  6678. strcat(atcmd_output, atcmd_output2);
  6679. }
  6680. }
  6681. if (j == 0)
  6682. clif_displaymessage(fd, msg_txt(sd,1249)); // This monster has no MVP prizes.
  6683. else
  6684. clif_displaymessage(fd, atcmd_output);
  6685. }
  6686. }
  6687. return 0;
  6688. }
  6689. /*=========================================
  6690. * @showmobs by KarLaeda
  6691. * => For 15 sec displays the mobs on minimap
  6692. *------------------------------------------*/
  6693. ACMD_FUNC(showmobs)
  6694. {
  6695. char mob_name[100];
  6696. int mob_id;
  6697. int number = 0;
  6698. struct s_mapiterator* it;
  6699. nullpo_retr(-1, sd);
  6700. if(sscanf(message, "%99[^\n]", mob_name) < 0)
  6701. return -1;
  6702. if((mob_id = strtol(mob_name, nullptr, 10)) == 0)
  6703. mob_id = mobdb_searchname(mob_name);
  6704. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  6705. if (mob == nullptr || mobdb_checkid(mob_id) == 0) {
  6706. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1250),mob_name); // Invalid mob id %s!
  6707. clif_displaymessage(fd, atcmd_output);
  6708. return 0;
  6709. }
  6710. if(status_has_mode(&mob->status,MD_STATUSIMMUNE) && !pc_has_permission(sd, PC_PERM_SHOW_BOSS)){ // If player group does not have access to boss mobs.
  6711. clif_displaymessage(fd, msg_txt(sd,1251)); // Can't show boss mobs!
  6712. return 0;
  6713. }
  6714. if(mob_id == strtol(mob_name, nullptr, 10) && !mob->jname.empty())
  6715. strcpy(mob_name, mob->jname.c_str()); // --ja--
  6716. //strcpy(mob_name, mob->name.c_str()); // --en--
  6717. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1252), // Mob Search... %s %s
  6718. mob_name, mapindex_id2name(sd->mapindex));
  6719. clif_displaymessage(fd, atcmd_output);
  6720. it = mapit_geteachmob();
  6721. for(;;)
  6722. {
  6723. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  6724. if( md == nullptr )
  6725. break;// no more mobs
  6726. if( md->bl.m != sd->bl.m )
  6727. continue;
  6728. if( mob_id != -1 && md->mob_id != mob_id )
  6729. continue;
  6730. if( md->special_state.ai || md->master_id )
  6731. continue; // hide slaves and player summoned mobs
  6732. if( md->spawn_timer != INVALID_TIMER )
  6733. continue; // hide mobs waiting for respawn
  6734. ++number;
  6735. clif_viewpoint( *sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF );
  6736. }
  6737. mapit_free(it);
  6738. return 0;
  6739. }
  6740. /*==========================================
  6741. * homunculus level up [orn]
  6742. *------------------------------------------*/
  6743. ACMD_FUNC(homlevel)
  6744. {
  6745. TBL_HOM * hd;
  6746. int level = 0, i = 0;
  6747. nullpo_retr(-1, sd);
  6748. if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
  6749. clif_displaymessage(fd, msg_txt(sd,1253)); // Please enter a level adjustment (usage: @homlevel <number of levels>).
  6750. return -1;
  6751. }
  6752. if ( !hom_is_active(sd->hd) ) {
  6753. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6754. return -1;
  6755. }
  6756. hd = sd->hd;
  6757. for (i = 1; i <= level && hd->exp_next; i++){
  6758. hd->homunculus.exp += hd->exp_next;
  6759. if( !hom_levelup(hd) )
  6760. break;
  6761. }
  6762. status_calc_homunculus(hd, SCO_NONE);
  6763. status_percent_heal(&hd->bl, 100, 100);
  6764. clif_specialeffect(&hd->bl,EF_HO_UP,AREA);
  6765. return 0;
  6766. }
  6767. /*==========================================
  6768. * homunculus evolution H [orn]
  6769. *------------------------------------------*/
  6770. ACMD_FUNC(homevolution)
  6771. {
  6772. nullpo_retr(-1, sd);
  6773. if ( !hom_is_active(sd->hd) ) {
  6774. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6775. return -1;
  6776. }
  6777. if ( !hom_evolution(sd->hd) ) {
  6778. clif_displaymessage(fd, msg_txt(sd,1255)); // Your homunculus doesn't evolve.
  6779. return -1;
  6780. }
  6781. clif_homskillinfoblock( *sd->hd );
  6782. return 0;
  6783. }
  6784. ACMD_FUNC(hommutate)
  6785. {
  6786. int homun_id, m_class = 0, m_id;
  6787. nullpo_retr(-1, sd);
  6788. if (!hom_is_active(sd->hd)) {
  6789. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6790. return -1;
  6791. }
  6792. if (!message || !*message) {
  6793. homun_id = rnd_value<uint16>(MER_EIRA, MER_ELEANOR);
  6794. } else {
  6795. homun_id = atoi(message);
  6796. }
  6797. m_class = hom_class2mapid(sd->hd->homunculus.class_);
  6798. m_id = hom_class2mapid(homun_id);
  6799. if (m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99) {
  6800. hom_mutate(sd->hd, homun_id);
  6801. } else {
  6802. clif_emotion(&sd->hd->bl, ET_SWEAT);
  6803. }
  6804. return 0;
  6805. }
  6806. /*==========================================
  6807. * call choosen homunculus [orn]
  6808. *------------------------------------------*/
  6809. ACMD_FUNC(makehomun)
  6810. {
  6811. int homunid;
  6812. nullpo_retr(-1, sd);
  6813. if ( sd->status.hom_id ) {
  6814. clif_displaymessage(fd, msg_txt(sd,450)); // You already have a homunculus
  6815. return -1;
  6816. }
  6817. if (!message || !*message) {
  6818. clif_displaymessage(fd, msg_txt(sd,1256)); // Please enter a homunculus ID (usage: @makehomun <homunculus id>).
  6819. return -1;
  6820. }
  6821. homunid = atoi(message);
  6822. if( homunid < HM_CLASS_BASE || homunid > HM_CLASS_BASE + MAX_HOMUNCULUS_CLASS - 1 )
  6823. {
  6824. clif_displaymessage(fd, msg_txt(sd,1257)); // Invalid Homunculus ID.
  6825. return -1;
  6826. }
  6827. hom_create_request(sd,homunid);
  6828. return 0;
  6829. }
  6830. /*==========================================
  6831. * modify homunculus intimacy [orn]
  6832. *------------------------------------------*/
  6833. ACMD_FUNC(homfriendly)
  6834. {
  6835. int friendly = 0;
  6836. nullpo_retr(-1, sd);
  6837. if ( !hom_is_active(sd->hd) ) {
  6838. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6839. return -1;
  6840. }
  6841. if (!message || !*message) {
  6842. clif_displaymessage(fd, msg_txt(sd,1258)); // Please enter a friendly value (usage: @homfriendly <friendly value [0-1000]>).
  6843. return -1;
  6844. }
  6845. friendly = atoi(message);
  6846. friendly = cap_value(friendly, 0, 1000);
  6847. sd->hd->homunculus.intimacy = friendly * 100 ;
  6848. clif_send_homdata( *sd->hd, SP_INTIMATE );
  6849. return 0;
  6850. }
  6851. /*==========================================
  6852. * modify homunculus hunger [orn]
  6853. *------------------------------------------*/
  6854. ACMD_FUNC(homhungry)
  6855. {
  6856. int hungry = 0;
  6857. nullpo_retr(-1, sd);
  6858. if ( !hom_is_active(sd->hd) ) {
  6859. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6860. return -1;
  6861. }
  6862. if (!message || !*message) {
  6863. clif_displaymessage(fd, msg_txt(sd,1259)); // Please enter a hunger value (usage: @homhungry <hunger value [0-100]>).
  6864. return -1;
  6865. }
  6866. hungry = atoi(message);
  6867. hungry = cap_value(hungry, 0, 100);
  6868. sd->hd->homunculus.hunger = hungry;
  6869. clif_send_homdata( *sd->hd, SP_HUNGRY );
  6870. return 0;
  6871. }
  6872. /*==========================================
  6873. * make the homunculus speak [orn]
  6874. *------------------------------------------*/
  6875. ACMD_FUNC(homtalk)
  6876. {
  6877. char mes[100],temp[CHAT_SIZE_MAX];
  6878. nullpo_retr(-1, sd);
  6879. if ( battle_config.min_chat_delay ) {
  6880. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  6881. return 0;
  6882. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  6883. }
  6884. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  6885. return -1; //no "chatting" while muted.
  6886. if ( !hom_is_active(sd->hd) ) {
  6887. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6888. return -1;
  6889. }
  6890. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6891. clif_displaymessage(fd, msg_txt(sd,1260)); // Please enter a message (usage: @homtalk <message>).
  6892. return -1;
  6893. }
  6894. snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes);
  6895. clif_disp_overhead(&sd->hd->bl, temp);
  6896. return 0;
  6897. }
  6898. /*==========================================
  6899. * Show homunculus stats
  6900. *------------------------------------------*/
  6901. ACMD_FUNC(hominfo)
  6902. {
  6903. struct homun_data *hd;
  6904. struct status_data *status;
  6905. nullpo_retr(-1, sd);
  6906. if ( !hom_is_active(sd->hd) ) {
  6907. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6908. return -1;
  6909. }
  6910. hd = sd->hd;
  6911. status = status_get_status_data(&hd->bl);
  6912. clif_displaymessage(fd, msg_txt(sd,1261)); // Homunculus stats:
  6913. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1262), // HP: %d/%d - SP: %d/%d
  6914. status->hp, status->max_hp, status->sp, status->max_sp);
  6915. clif_displaymessage(fd, atcmd_output);
  6916. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1263), // ATK: %d - MATK: %d~%d
  6917. status->rhw.atk2 +status->batk, status->matk_min, status->matk_max);
  6918. clif_displaymessage(fd, atcmd_output);
  6919. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1264), // Hungry: %d - Intimacy: %u
  6920. hd->homunculus.hunger, hd->homunculus.intimacy/100);
  6921. clif_displaymessage(fd, atcmd_output);
  6922. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6923. msg_txt(sd,1265), // Stats: Str %d / Agi %d / Vit %d / Int %d / Dex %d / Luk %d
  6924. status->str, status->agi, status->vit,
  6925. status->int_, status->dex, status->luk);
  6926. clif_displaymessage(fd, atcmd_output);
  6927. return 0;
  6928. }
  6929. ACMD_FUNC(homstats)
  6930. {
  6931. struct homun_data *hd;
  6932. std::shared_ptr<s_homunculus_db> db;
  6933. struct s_homunculus *hom;
  6934. int lv, min, max, evo;
  6935. nullpo_retr(-1, sd);
  6936. if ( !hom_is_active(sd->hd) ) {
  6937. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6938. return -1;
  6939. }
  6940. hd = sd->hd;
  6941. hom = &hd->homunculus;
  6942. db = hd->homunculusDB;
  6943. lv = hom->level;
  6944. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6945. msg_txt(sd,1266), lv, db->name); // Homunculus growth stats (Lv %d %s):
  6946. clif_displaymessage(fd, atcmd_output);
  6947. lv--; //Since the first increase is at level 2.
  6948. evo = (hom->class_ == db->evo_class);
  6949. min = db->base.HP +lv*db->gmin.HP +(evo?db->emin.HP:0);
  6950. max = db->base.HP +lv*db->gmax.HP +(evo?db->emax.HP:0);;
  6951. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1267), hom->max_hp, min, max); // Max HP: %d (%d~%d)
  6952. clif_displaymessage(fd, atcmd_output);
  6953. min = db->base.SP +lv*db->gmin.SP +(evo?db->emin.SP:0);
  6954. max = db->base.SP +lv*db->gmax.SP +(evo?db->emax.SP:0);;
  6955. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1268), hom->max_sp, min, max); // Max SP: %d (%d~%d)
  6956. clif_displaymessage(fd, atcmd_output);
  6957. min = db->base.str +lv*(db->gmin.str/10) +(evo?db->emin.str:0);
  6958. max = db->base.str +lv*(db->gmax.str/10) +(evo?db->emax.str:0);;
  6959. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1269), hom->str/10, min, max); // Str: %d (%d~%d)
  6960. clif_displaymessage(fd, atcmd_output);
  6961. min = db->base.agi +lv*(db->gmin.agi/10) +(evo?db->emin.agi:0);
  6962. max = db->base.agi +lv*(db->gmax.agi/10) +(evo?db->emax.agi:0);;
  6963. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1270), hom->agi/10, min, max); // Agi: %d (%d~%d)
  6964. clif_displaymessage(fd, atcmd_output);
  6965. min = db->base.vit +lv*(db->gmin.vit/10) +(evo?db->emin.vit:0);
  6966. max = db->base.vit +lv*(db->gmax.vit/10) +(evo?db->emax.vit:0);;
  6967. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1271), hom->vit/10, min, max); // Vit: %d (%d~%d)
  6968. clif_displaymessage(fd, atcmd_output);
  6969. min = db->base.int_ +lv*(db->gmin.int_/10) +(evo?db->emin.int_:0);
  6970. max = db->base.int_ +lv*(db->gmax.int_/10) +(evo?db->emax.int_:0);;
  6971. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1272), hom->int_/10, min, max); // Int: %d (%d~%d)
  6972. clif_displaymessage(fd, atcmd_output);
  6973. min = db->base.dex +lv*(db->gmin.dex/10) +(evo?db->emin.dex:0);
  6974. max = db->base.dex +lv*(db->gmax.dex/10) +(evo?db->emax.dex:0);;
  6975. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1273), hom->dex/10, min, max); // Dex: %d (%d~%d)
  6976. clif_displaymessage(fd, atcmd_output);
  6977. min = db->base.luk +lv*(db->gmin.luk/10) +(evo?db->emin.luk:0);
  6978. max = db->base.luk +lv*(db->gmax.luk/10) +(evo?db->emax.luk:0);;
  6979. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1274), hom->luk/10, min, max); // Luk: %d (%d~%d)
  6980. clif_displaymessage(fd, atcmd_output);
  6981. return 0;
  6982. }
  6983. ACMD_FUNC(homshuffle)
  6984. {
  6985. nullpo_retr(-1, sd);
  6986. if(!sd->hd)
  6987. return -1; // nothing to do
  6988. if(!hom_shuffle(sd->hd))
  6989. return -1;
  6990. clif_displaymessage(sd->fd, msg_txt(sd,1275)); // Homunculus stats altered.
  6991. atcommand_homstats(fd, sd, command, message); //Print out the new stats
  6992. return 0;
  6993. }
  6994. /*==========================================
  6995. * Show Items DB Info v 1.0
  6996. * originally by [Lupus]
  6997. *------------------------------------------*/
  6998. ACMD_FUNC(iteminfo)
  6999. {
  7000. if (!message || !*message) {
  7001. clif_displaymessage(fd, msg_txt(sd,1276)); // Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>).
  7002. return -1;
  7003. }
  7004. std::map<t_itemid, std::shared_ptr<item_data>> item_array = {};
  7005. uint16 count = 1;
  7006. t_itemid itemid = strtoul(message, nullptr, 10);
  7007. if (itemid == 0) // Entered a string
  7008. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7009. else {
  7010. if ((item_array[0] = item_db.find(itemid)) == nullptr)
  7011. count = 0;
  7012. }
  7013. if (!count) {
  7014. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  7015. return -1;
  7016. }
  7017. if (count == MAX_SEARCH) {
  7018. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH); // Displaying first %d matches
  7019. clif_displaymessage(fd, atcmd_output);
  7020. }
  7021. for (const auto &result : item_array) {
  7022. std::shared_ptr<item_data> item_data = result.second;
  7023. sprintf(atcmd_output, msg_txt(sd,1277), // Item: '%s'/'%s' (%u) Type: %s | Extra Effect: %s
  7024. item_data->name.c_str(), item_db.create_item_link( item_data ).c_str(),item_data->nameid,
  7025. (item_data->type != IT_AMMO) ? itemdb_typename((enum item_types)item_data->type) : itemdb_typename_ammo((e_ammo_type)item_data->subtype),
  7026. (item_data->script==nullptr)? msg_txt(sd,1278) : msg_txt(sd,1279) // None / With script
  7027. );
  7028. clif_displaymessage(fd, atcmd_output);
  7029. sprintf(atcmd_output, msg_txt(sd,1280), item_data->value_buy, item_data->value_sell, item_data->weight/10. ); // NPC Buy:%dz, Sell:%dz | Weight: %.1f
  7030. clif_displaymessage(fd, atcmd_output);
  7031. if (item_data->maxchance == -1) {
  7032. strcpy(atcmd_output, msg_txt(sd,1281)); // - Available in the shops only.
  7033. clif_displaymessage(fd, atcmd_output);
  7034. }
  7035. else if (!battle_config.atcommand_mobinfo_type) {
  7036. if (item_data->maxchance)
  7037. sprintf(atcmd_output, msg_txt(sd,1282), (float)item_data->maxchance / 100 ); // - Maximal monsters drop chance: %02.02f%%
  7038. else
  7039. strcpy(atcmd_output, msg_txt(sd,1283)); // - Monsters don't drop this item.
  7040. clif_displaymessage(fd, atcmd_output);
  7041. }
  7042. }
  7043. return 0;
  7044. }
  7045. /*==========================================
  7046. * Show who drops the item.
  7047. *------------------------------------------*/
  7048. ACMD_FUNC(whodrops)
  7049. {
  7050. if (!message || !*message) {
  7051. clif_displaymessage(fd, msg_txt(sd,1284)); // Please enter item name/ID (usage: @whodrops <item name/ID>).
  7052. return -1;
  7053. }
  7054. std::map<t_itemid, std::shared_ptr<item_data>> item_array = {};
  7055. uint16 count = 1;
  7056. t_itemid itemid = strtoul(message, nullptr, 10);
  7057. if (itemid == 0) // Entered a string
  7058. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  7059. else {
  7060. if ((item_array[0] = item_db.find(itemid)) == nullptr)
  7061. count = 0;
  7062. }
  7063. if (!count) {
  7064. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  7065. return -1;
  7066. }
  7067. if (count == MAX_SEARCH) {
  7068. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH); // Displaying first %d matches
  7069. clif_displaymessage(fd, atcmd_output);
  7070. }
  7071. for (const auto &result : item_array) {
  7072. std::shared_ptr<item_data> id = result.second;
  7073. sprintf(atcmd_output, msg_txt(sd,1285), item_db.create_item_link( id ).c_str(), id->nameid); // Item: '%s' (ID:%u)
  7074. clif_displaymessage(fd, atcmd_output);
  7075. if (id->mob[0].chance == 0) {
  7076. strcpy(atcmd_output, msg_txt(sd,1286)); // - Item is not dropped by mobs.
  7077. clif_displaymessage(fd, atcmd_output);
  7078. } else {
  7079. sprintf(atcmd_output, msg_txt(sd,1287), MAX_SEARCH); // - Common mobs with highest drop chance (only max %d are listed):
  7080. clif_displaymessage(fd, atcmd_output);
  7081. for (uint16 j=0; j < MAX_SEARCH && id->mob[j].chance > 0; j++)
  7082. {
  7083. int dropchance = id->mob[j].chance;
  7084. std::shared_ptr<s_mob_db> mob = mob_db.find(id->mob[j].id);
  7085. if(!mob) continue;
  7086. #ifdef RENEWAL_DROP
  7087. if( battle_config.atcommand_mobinfo_type ) {
  7088. dropchance = dropchance * pc_level_penalty_mod( sd, PENALTY_DROP, mob ) / 100;
  7089. if (dropchance <= 0 && !battle_config.drop_rate0item)
  7090. dropchance = 1;
  7091. }
  7092. #endif
  7093. if (pc_isvip(sd)) // Display item rate increase for VIP
  7094. dropchance += (dropchance * battle_config.vip_drop_increase) / 100;
  7095. sprintf(atcmd_output, "- %s (%d): %02.02f%%", mob->jname.c_str(), id->mob[j].id, dropchance/100.);
  7096. clif_displaymessage(fd, atcmd_output);
  7097. }
  7098. }
  7099. }
  7100. return 0;
  7101. }
  7102. ACMD_FUNC(whereis)
  7103. {
  7104. uint16 mob_ids[MAX_SEARCH] = {0}, count;
  7105. if (!message || !*message) {
  7106. clif_displaymessage(fd, msg_txt(sd,1288)); // Please enter a monster name/ID (usage: @whereis <monster_name_or_monster_ID>).
  7107. return -1;
  7108. }
  7109. int i_message = atoi(message);
  7110. if (mobdb_checkid(i_message)) {
  7111. // ID given
  7112. mob_ids[0] = i_message;
  7113. count = 1;
  7114. } else {
  7115. // Name given, get all monster associated whith this name
  7116. count = mobdb_searchname_array(message, mob_ids, MAX_SEARCH);
  7117. }
  7118. if (count <= 0) {
  7119. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  7120. return -1;
  7121. }
  7122. if (count >= MAX_SEARCH) {
  7123. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH); // Displaying first %d matches
  7124. clif_displaymessage(fd, atcmd_output);
  7125. count = MAX_SEARCH;
  7126. }
  7127. for (int i = 0; i < count; i++) {
  7128. uint16 mob_id = mob_ids[i];
  7129. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  7130. if(!mob) continue;
  7131. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1289), mob->jname.c_str()); // %s spawns in:
  7132. clif_displaymessage(fd, atcmd_output);
  7133. const std::vector<spawn_info> spawns = mob_get_spawns(mob_id);
  7134. if (spawns.size() <= 0) {
  7135. // This monster does not spawn normally.
  7136. clif_displaymessage(fd, msg_txt(sd,1290));
  7137. } else {
  7138. for(auto& spawn : spawns)
  7139. {
  7140. int16 mapid = map_mapindex2mapid(spawn.mapindex);
  7141. if (mapid < 0)
  7142. continue;
  7143. snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map_getmapdata(mapid)->name, spawn.qty);
  7144. clif_displaymessage(fd, atcmd_output);
  7145. }
  7146. }
  7147. }
  7148. return 0;
  7149. }
  7150. ACMD_FUNC(version)
  7151. {
  7152. pc_show_version(sd);
  7153. return 0;
  7154. }
  7155. /*==========================================
  7156. * @mutearea by MouseJstr
  7157. *------------------------------------------*/
  7158. static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
  7159. {
  7160. int time, id;
  7161. map_session_data *pl_sd = (map_session_data *)bl;
  7162. if (pl_sd == nullptr)
  7163. return 0;
  7164. id = va_arg(ap, int);
  7165. time = va_arg(ap, int);
  7166. if (id != bl->id && !pc_get_group_level(pl_sd)) {
  7167. pl_sd->status.manner -= time;
  7168. if (pl_sd->status.manner < 0)
  7169. sc_start(nullptr,&pl_sd->bl,SC_NOCHAT,100,0,0);
  7170. else
  7171. status_change_end(&pl_sd->bl, SC_NOCHAT);
  7172. }
  7173. return 0;
  7174. }
  7175. ACMD_FUNC(mutearea)
  7176. {
  7177. int time;
  7178. nullpo_ret(sd);
  7179. if (!message || !*message) {
  7180. clif_displaymessage(fd, msg_txt(sd,1297)); // Please enter a time in minutes (usage: @mutearea/@stfu <time in minutes>).
  7181. return -1;
  7182. }
  7183. time = atoi(message);
  7184. map_foreachinallarea(atcommand_mutearea_sub,sd->bl.m,
  7185. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE,
  7186. sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time);
  7187. return 0;
  7188. }
  7189. ACMD_FUNC(rates)
  7190. {
  7191. char buf[CHAT_SIZE_MAX];
  7192. nullpo_ret(sd);
  7193. memset(buf, '\0', sizeof(buf));
  7194. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1298), // Experience rates: Base %.2fx / Job %.2fx
  7195. (battle_config.base_exp_rate + (pc_isvip(sd) ? (battle_config.vip_base_exp_increase * battle_config.base_exp_rate) / 100 : 0)) / 100.,
  7196. (battle_config.job_exp_rate + (pc_isvip(sd) ? (battle_config.vip_job_exp_increase * battle_config.job_exp_rate) / 100 : 0)) / 100.);
  7197. clif_displaymessage(fd, buf);
  7198. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1299), // Normal Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  7199. (battle_config.item_rate_common + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100 : 0)) / 100.,
  7200. (battle_config.item_rate_heal + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_heal) / 100 : 0)) / 100.,
  7201. (battle_config.item_rate_use + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_use) / 100 : 0)) / 100.,
  7202. (battle_config.item_rate_equip + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_equip) / 100 : 0)) / 100.,
  7203. (battle_config.item_rate_card + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_card) / 100 : 0)) / 100.);
  7204. clif_displaymessage(fd, buf);
  7205. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1300), // Boss Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  7206. (battle_config.item_rate_common_boss + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_common_boss) / 100 : 0)) / 100.,
  7207. (battle_config.item_rate_heal_boss + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_heal_boss) / 100 : 0)) / 100.,
  7208. (battle_config.item_rate_use_boss + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_use_boss) / 100 : 0)) / 100.,
  7209. (battle_config.item_rate_equip_boss + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_equip_boss) / 100 : 0)) / 100.,
  7210. (battle_config.item_rate_card_boss + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_card_boss) / 100 : 0)) / 100.);
  7211. clif_displaymessage(fd, buf);
  7212. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1024), // MVP Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  7213. (battle_config.item_rate_common_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_common_mvp) / 100 : 0)) / 100.,
  7214. (battle_config.item_rate_heal_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_heal_mvp) / 100 : 0)) / 100.,
  7215. (battle_config.item_rate_use_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_use_mvp) / 100 : 0)) / 100.,
  7216. (battle_config.item_rate_equip_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_equip_mvp) / 100 : 0)) / 100.,
  7217. (battle_config.item_rate_card_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_card_mvp) / 100 : 0)) / 100.);
  7218. clif_displaymessage(fd, buf);
  7219. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1301), // Other Drop Rates: MvP %.2fx / Card-Based %.2fx / Treasure %.2fx
  7220. (battle_config.item_rate_mvp + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_mvp) / 100 : 0)) / 100.,
  7221. (battle_config.item_rate_adddrop + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_adddrop) / 100 : 0)) / 100.,
  7222. (battle_config.item_rate_treasure + (pc_isvip(sd) ? (battle_config.vip_drop_increase * battle_config.item_rate_treasure) / 100 : 0)) / 100.);
  7223. clif_displaymessage(fd, buf);
  7224. return 0;
  7225. }
  7226. /*==========================================
  7227. * @me by lordalfa
  7228. * => Displays the OUTPUT string on top of the Visible players Heads.
  7229. *------------------------------------------*/
  7230. ACMD_FUNC(me)
  7231. {
  7232. char tempmes[CHAT_SIZE_MAX];
  7233. nullpo_retr(-1, sd);
  7234. memset(tempmes, '\0', sizeof(tempmes));
  7235. memset(atcmd_output, '\0', sizeof(atcmd_output));
  7236. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  7237. return -1; //no "chatting" while muted.
  7238. if (!message || !*message || sscanf(message, "%255[^\n]", tempmes) < 0) {
  7239. clif_displaymessage(fd, msg_txt(sd,1302)); // Please enter a message (usage: @me <message>).
  7240. return -1;
  7241. }
  7242. sprintf(atcmd_output, msg_txt(sd,270), sd->status.name, tempmes); // *%s %s*
  7243. clif_disp_overhead(&sd->bl, atcmd_output);
  7244. return 0;
  7245. }
  7246. /*==========================================
  7247. * @size
  7248. * => Resize your character sprite. [Valaris]
  7249. *------------------------------------------*/
  7250. ACMD_FUNC(size)
  7251. {
  7252. int size = SZ_SMALL;
  7253. nullpo_retr(-1, sd);
  7254. size = cap_value(atoi(message),SZ_SMALL,SZ_BIG);
  7255. if(sd->state.size) {
  7256. sd->state.size = SZ_SMALL;
  7257. pc_setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_TELEPORT);
  7258. }
  7259. sd->state.size = size;
  7260. if( size == SZ_MEDIUM )
  7261. clif_specialeffect(&sd->bl,EF_BABYBODY,AREA);
  7262. else if( size == SZ_BIG )
  7263. clif_specialeffect(&sd->bl,EF_GIANTBODY,AREA);
  7264. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  7265. return 0;
  7266. }
  7267. ACMD_FUNC(sizeall)
  7268. {
  7269. int size;
  7270. map_session_data *pl_sd;
  7271. struct s_mapiterator* iter;
  7272. size = atoi(message);
  7273. size = cap_value(size,SZ_SMALL,SZ_BIG);
  7274. iter = mapit_getallusers();
  7275. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) {
  7276. if( pl_sd->state.size != size ) {
  7277. if( pl_sd->state.size ) {
  7278. pl_sd->state.size = SZ_SMALL;
  7279. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  7280. }
  7281. pl_sd->state.size = size;
  7282. if( size == SZ_MEDIUM )
  7283. clif_specialeffect(&pl_sd->bl,EF_BABYBODY,AREA);
  7284. else if( size == SZ_BIG )
  7285. clif_specialeffect(&pl_sd->bl,EF_GIANTBODY,AREA);
  7286. }
  7287. }
  7288. mapit_free(iter);
  7289. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  7290. return 0;
  7291. }
  7292. ACMD_FUNC(sizeguild)
  7293. {
  7294. int size = SZ_SMALL, i;
  7295. char guild[NAME_LENGTH];
  7296. map_session_data *pl_sd;
  7297. nullpo_retr(-1, sd);
  7298. memset(guild, '\0', sizeof(guild));
  7299. if( !message || !*message || sscanf(message, "%11d %23[^\n]", &size, guild) < 2 ) {
  7300. clif_displaymessage(fd, msg_txt(sd,1304)); // Please enter guild name/ID (usage: @sizeguild <size> <guild name/ID>).
  7301. return -1;
  7302. }
  7303. auto g = guild_searchnameid(guild);
  7304. if (!g) {
  7305. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  7306. return -1;
  7307. }
  7308. size = cap_value(size,SZ_SMALL,SZ_BIG);
  7309. for( i = 0; i < g->guild.max_member; i++ ) {
  7310. if( (pl_sd = g->guild.member[i].sd) && pl_sd->state.size != size ) {
  7311. if( pl_sd->state.size ) {
  7312. pl_sd->state.size = SZ_SMALL;
  7313. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  7314. }
  7315. pl_sd->state.size = size;
  7316. if( size == SZ_MEDIUM )
  7317. clif_specialeffect(&pl_sd->bl,EF_BABYBODY,AREA);
  7318. else if( size == SZ_BIG )
  7319. clif_specialeffect(&pl_sd->bl,EF_GIANTBODY,AREA);
  7320. }
  7321. }
  7322. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  7323. return 0;
  7324. }
  7325. /*==========================================
  7326. * @monsterignore
  7327. * => Makes monsters ignore you. [Valaris]
  7328. *------------------------------------------*/
  7329. ACMD_FUNC(monsterignore)
  7330. {
  7331. nullpo_retr(-1, sd);
  7332. if (sd->state.block_action & PCBLOCK_IMMUNE) {
  7333. sd->state.block_action &= ~PCBLOCK_IMMUNE;
  7334. clif_displaymessage(sd->fd, msg_txt(sd,1306)); // Returned to normal state.
  7335. } else {
  7336. sd->state.block_action |= PCBLOCK_IMMUNE;
  7337. clif_displaymessage(sd->fd, msg_txt(sd,1305)); // You are now immune to attacks.
  7338. }
  7339. return 0;
  7340. }
  7341. /*==========================================
  7342. * @fakename
  7343. * => Gives your character a fake name. [Valaris]
  7344. *------------------------------------------*/
  7345. ACMD_FUNC(fakename)
  7346. {
  7347. nullpo_retr(-1, sd);
  7348. if( !message || !*message )
  7349. {
  7350. if( sd->fakename[0] )
  7351. {
  7352. sd->fakename[0] = '\0';
  7353. clif_name_area(&sd->bl);
  7354. if (sd->disguise)
  7355. clif_name_self(&sd->bl);
  7356. clif_displaymessage(sd->fd, msg_txt(sd,1307)); // Returned to real name.
  7357. return 0;
  7358. }
  7359. clif_displaymessage(sd->fd, msg_txt(sd,1308)); // You must enter a name.
  7360. return -1;
  7361. }
  7362. if( strlen(message) < 2 )
  7363. {
  7364. clif_displaymessage(sd->fd, msg_txt(sd,1309)); // Fake name must be at least two characters.
  7365. return -1;
  7366. }
  7367. safestrncpy(sd->fakename, message, sizeof(sd->fakename));
  7368. clif_name_area(&sd->bl);
  7369. if (sd->disguise) // Another packet should be sent so the client updates the name for sd
  7370. clif_name_self(&sd->bl);
  7371. clif_displaymessage(sd->fd, msg_txt(sd,1310)); // Fake name enabled.
  7372. return 0;
  7373. }
  7374. /*==========================================
  7375. * Ragnarok Resources
  7376. *------------------------------------------*/
  7377. ACMD_FUNC(mapflag) {
  7378. char flag_name[50];
  7379. short flag = 0, i, j;
  7380. std::string buf;
  7381. nullpo_retr(-1, sd);
  7382. memset(flag_name, '\0', sizeof(flag_name));
  7383. if (!message || !*message || (sscanf(message, "%49s %6hd", flag_name, &flag) < 1)) {
  7384. clif_displaymessage(sd->fd,msg_txt(sd,1311)); // Enabled Mapflags in this map:
  7385. clif_displaymessage(sd->fd,"----------------------------------");
  7386. for( i = MF_MIN; i < MF_MAX; i++ ){
  7387. union u_mapflag_args args = {};
  7388. if( map_getmapflag_name(static_cast<e_mapflag>(i), flag_name) && map_getmapflag_sub( sd->bl.m, static_cast<e_mapflag>(i), &args ) ){
  7389. clif_displaymessage(sd->fd, flag_name);
  7390. }
  7391. }
  7392. clif_displaymessage(sd->fd," ");
  7393. clif_displaymessage(sd->fd,msg_txt(sd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  7394. clif_displaymessage(sd->fd,msg_txt(sd,1313)); // Type "@mapflag available" to list the available mapflags.
  7395. return 1;
  7396. }
  7397. // Check if the list of mapflags was requested
  7398. if( strcasecmp(flag_name,"available") ){
  7399. for (i = 0; flag_name[i]; i++) flag_name[i] = (char)tolower(flag_name[i]); //lowercase
  7400. enum e_mapflag mapflag = map_getmapflag_by_name(flag_name);
  7401. if( mapflag != MF_INVALID ){
  7402. std::vector<e_mapflag> disabled_mf = { MF_NOSAVE,
  7403. MF_PVP_NIGHTMAREDROP,
  7404. MF_RESTRICTED,
  7405. MF_NOCOMMAND,
  7406. MF_BEXP,
  7407. MF_JEXP,
  7408. MF_BATTLEGROUND,
  7409. MF_SKILL_DAMAGE,
  7410. MF_SKILL_DURATION };
  7411. if (flag > 0 && util::vector_exists(disabled_mf, mapflag)) {
  7412. sprintf(atcmd_output,"[ @mapflag ] %s flag cannot be enabled as it requires unique values.", flag_name);
  7413. clif_displaymessage(sd->fd,atcmd_output);
  7414. } else {
  7415. map_setmapflag(sd->bl.m, mapflag, flag != 0);
  7416. sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s value = %hd",flag_name,flag?"On":"Off",flag);
  7417. clif_displaymessage(sd->fd,atcmd_output);
  7418. }
  7419. return 0;
  7420. }else{
  7421. clif_displaymessage(sd->fd, msg_txt(sd, 1314)); // Invalid flag name or flag.
  7422. clif_displaymessage(sd->fd, msg_txt(sd, 1313)); // Type "@mapflag available" to list the available mapflags.
  7423. return 1;
  7424. }
  7425. }
  7426. clif_displaymessage(sd->fd,msg_txt(sd,1315)); // Available Flags:
  7427. clif_displaymessage(sd->fd,"----------------------------------");
  7428. for( i = MF_MIN, j = 0; i < MF_MAX; i++ ){
  7429. if( map_getmapflag_name( static_cast<e_mapflag>(i), flag_name ) ){
  7430. buf.append(flag_name);
  7431. if( (i + 1) < MF_MAX )
  7432. buf.append(", ");
  7433. j++;
  7434. }
  7435. if( i > MF_MIN && ( j == 6 || ( i + 1 ) == MF_MAX ) ){
  7436. clif_displaymessage(sd->fd, buf.c_str() );
  7437. buf.clear();
  7438. j = 0;
  7439. }
  7440. }
  7441. clif_displaymessage(sd->fd, msg_txt(sd, 1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  7442. return 0;
  7443. }
  7444. /*===================================
  7445. * Remove some messages
  7446. *-----------------------------------*/
  7447. ACMD_FUNC(showexp)
  7448. {
  7449. if (sd->state.showexp) {
  7450. sd->state.showexp = 0;
  7451. clif_displaymessage(fd, msg_txt(sd,1316)); // Gained exp will not be shown.
  7452. return 0;
  7453. }
  7454. sd->state.showexp = 1;
  7455. clif_displaymessage(fd, msg_txt(sd,1317)); // Gained exp is now shown.
  7456. return 0;
  7457. }
  7458. ACMD_FUNC(showzeny)
  7459. {
  7460. if (sd->state.showzeny) {
  7461. sd->state.showzeny = 0;
  7462. clif_displaymessage(fd, msg_txt(sd,1318)); // Gained zeny will not be shown.
  7463. return 0;
  7464. }
  7465. sd->state.showzeny = 1;
  7466. clif_displaymessage(fd, msg_txt(sd,1319)); // Gained zeny is now shown.
  7467. return 0;
  7468. }
  7469. ACMD_FUNC(showdelay)
  7470. {
  7471. if (sd->state.showdelay) {
  7472. sd->state.showdelay = 0;
  7473. clif_displaymessage(fd, msg_txt(sd,1320)); // Skill delay failures will not be shown.
  7474. return 0;
  7475. }
  7476. sd->state.showdelay = 1;
  7477. clif_displaymessage(fd, msg_txt(sd,1321)); // Skill delay failures are now shown.
  7478. return 0;
  7479. }
  7480. /*==========================================
  7481. * Duel organizing functions [LuzZza]
  7482. *
  7483. * @duel [limit|nick] - create a duel
  7484. * @invite <nick> - invite player
  7485. * @accept - accept invitation
  7486. * @reject - reject invitation
  7487. * @leave - leave duel
  7488. *------------------------------------------*/
  7489. ACMD_FUNC(invite)
  7490. {
  7491. unsigned int did = sd->duel_group;
  7492. map_session_data *target_sd = nullptr;
  7493. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  7494. memset(atcmd_output, '\0', sizeof(atcmd_output));
  7495. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  7496. sprintf(atcmd_output, msg_txt(sd, 435), command); // Please enter a player name (usage: %s <char name>).
  7497. clif_displaymessage(fd, atcmd_output);
  7498. return -1;
  7499. }
  7500. if(did == 0 || !duel_exist(did) ) {
  7501. clif_displaymessage(fd, msg_txt(sd,350)); // "Duel: @invite without @duel."
  7502. return 0;
  7503. }
  7504. if( !duel_check_player_limit( duel_get_duelid(did) ) ){
  7505. clif_displaymessage(fd, msg_txt(sd,351)); // "Duel: Limit of players is reached."
  7506. return 0;
  7507. }
  7508. if((target_sd = map_nick2sd(atcmd_player_name, true)) == nullptr) {
  7509. clif_displaymessage(fd, msg_txt(sd,352)); // "Duel: Player not found."
  7510. return 0;
  7511. }
  7512. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  7513. clif_displaymessage(fd, msg_txt(sd,353)); // "Duel: Player already in duel."
  7514. return 0;
  7515. }
  7516. if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
  7517. {
  7518. sprintf(atcmd_output, msg_txt(sd,364), atcmd_player_name); // Duel: You can't invite %s because he/she isn't on the same map.
  7519. clif_displaymessage(fd, atcmd_output);
  7520. return 0;
  7521. }
  7522. duel_invite(did, sd, target_sd);
  7523. clif_displaymessage(fd, msg_txt(sd,354)); // "Duel: Invitation has been sent."
  7524. return 0;
  7525. }
  7526. ACMD_FUNC(duel)
  7527. {
  7528. unsigned int maxpl = 0;
  7529. if(sd->duel_group > 0) {
  7530. duel_showinfo(sd->duel_group, sd);
  7531. return 0;
  7532. }
  7533. if(sd->duel_invite > 0) {
  7534. clif_displaymessage(fd, msg_txt(sd,355)); // "Duel: @duel without @reject."
  7535. return 0;
  7536. }
  7537. if(!duel_checktime(sd)) {
  7538. char output[CHAT_SIZE_MAX];
  7539. sprintf(output, msg_txt(sd,356), battle_config.duel_time_interval); // "Duel: You can take part in duel only one time per %d minutes."
  7540. clif_displaymessage(fd, output);
  7541. return 0;
  7542. }
  7543. if( message[0] ) {
  7544. if(sscanf(message, "%11u", &maxpl) >= 1) {
  7545. if(maxpl < 2 || maxpl > 65535) {
  7546. clif_displaymessage(fd, msg_txt(sd,357)); // "Duel: Invalid value."
  7547. return 0;
  7548. }
  7549. duel_create(sd, maxpl);
  7550. } else {
  7551. map_session_data *target_sd = nullptr;
  7552. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  7553. memset(atcmd_output, '\0', sizeof(atcmd_output));
  7554. if (sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  7555. sprintf(atcmd_output, msg_txt(sd, 435), command); // Please enter a player name (usage: %s <char name>).
  7556. clif_displaymessage(fd, atcmd_output);
  7557. return -1;
  7558. }
  7559. target_sd = map_nick2sd(atcmd_player_name,true);
  7560. if(target_sd != nullptr) {
  7561. unsigned int newduel;
  7562. if((newduel = duel_create(sd, 2)) != -1) {
  7563. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  7564. clif_displaymessage(fd, msg_txt(sd,353)); // "Duel: Player already in duel."
  7565. return 0;
  7566. }
  7567. duel_invite(newduel, sd, target_sd);
  7568. clif_displaymessage(fd, msg_txt(sd,354)); // "Duel: Invitation has been sent."
  7569. }
  7570. } else {
  7571. clif_displaymessage(fd, msg_txt(sd,352)); // "Duel: Player not found."
  7572. return 0;
  7573. }
  7574. }
  7575. } else
  7576. duel_create(sd, 0);
  7577. return 0;
  7578. }
  7579. ACMD_FUNC(leave)
  7580. {
  7581. if(sd->duel_group <= 0) {
  7582. clif_displaymessage(fd, msg_txt(sd,358)); // "Duel: @leave without @duel."
  7583. return 0;
  7584. }
  7585. duel_leave(sd->duel_group, sd);
  7586. clif_displaymessage(fd, msg_txt(sd,359)); // "Duel: You left the duel."
  7587. return 0;
  7588. }
  7589. ACMD_FUNC(accept)
  7590. {
  7591. if(!duel_checktime(sd)) {
  7592. char output[CHAT_SIZE_MAX];
  7593. sprintf(output, msg_txt(sd,356), battle_config.duel_time_interval); // "Duel: You can take part in duel only one time per %d minutes."
  7594. clif_displaymessage(fd, output);
  7595. return 0;
  7596. }
  7597. if(sd->duel_invite <= 0 || !duel_exist(sd->duel_invite) ) {
  7598. clif_displaymessage(fd, msg_txt(sd,360)); // "Duel: @accept without invititation."
  7599. return 0;
  7600. }
  7601. if( !duel_check_player_limit( duel_get_duelid( sd->duel_invite ) ) )
  7602. {
  7603. clif_displaymessage(fd, msg_txt(sd,351)); // "Duel: Limit of players is reached."
  7604. return 0;
  7605. }
  7606. duel_accept(sd->duel_invite, sd);
  7607. clif_displaymessage(fd, msg_txt(sd,361)); // "Duel: Invitation has been accepted."
  7608. return 0;
  7609. }
  7610. ACMD_FUNC(reject)
  7611. {
  7612. if(sd->duel_invite <= 0) {
  7613. clif_displaymessage(fd, msg_txt(sd,362)); // "Duel: @reject without invititation."
  7614. return 0;
  7615. }
  7616. duel_reject(sd->duel_invite, sd);
  7617. clif_displaymessage(fd, msg_txt(sd,363)); // "Duel: Invitation has been rejected."
  7618. return 0;
  7619. }
  7620. /*===================================
  7621. * Cash Points
  7622. *-----------------------------------*/
  7623. ACMD_FUNC(cash)
  7624. {
  7625. char output[128];
  7626. int value;
  7627. int ret=0;
  7628. nullpo_retr(-1, sd);
  7629. // Since there is no cashpoint update packet we need to force updating like this
  7630. if( sd->state.cashshop_open ){
  7631. clif_displaymessage(fd, msg_txt(sd, 1376)); // Please close the cashshop before using this command.
  7632. return -1;
  7633. }
  7634. if( !message || !*message || (value = atoi(message)) == 0 ) {
  7635. clif_displaymessage(fd, msg_txt(sd,1322)); // Please enter an amount.
  7636. return -1;
  7637. }
  7638. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  7639. if( !strcmpi(parent_cmd,"cash") )
  7640. {
  7641. if( value > 0 ) {
  7642. if( (ret=pc_getcash(sd, value, 0, LOG_TYPE_COMMAND)) >= 0){
  7643. // If this option is set, the message is already sent by pc function
  7644. if( !battle_config.cashshop_show_points ){
  7645. sprintf(output, msg_txt(sd,505), ret, sd->cashPoints); // Gained %d cash points. Total %d points.
  7646. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  7647. }
  7648. }
  7649. else clif_displaymessage(fd, msg_txt(sd,149)); // Impossible to increase the number/value.
  7650. } else {
  7651. if (-value > sd->cashPoints) //By command, if cash < value, force it to remove all
  7652. value = -sd->cashPoints;
  7653. if( (ret=pc_paycash(sd, -value, 0, LOG_TYPE_COMMAND)) >= 0){
  7654. // If this option is set, the message is already sent by pc function
  7655. if( !battle_config.cashshop_show_points ){
  7656. sprintf(output, msg_txt(sd,410), ret, sd->cashPoints); // Removed %d cash points. Total %d points.
  7657. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  7658. }
  7659. }
  7660. else clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  7661. }
  7662. }
  7663. else
  7664. { // @points
  7665. if( value > 0 ) {
  7666. if( (ret=pc_getcash(sd, 0, value, LOG_TYPE_COMMAND)) >= 0){
  7667. sprintf(output, msg_txt(sd,506), ret, sd->kafraPoints); // Gained %d kafra points. Total %d points.
  7668. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  7669. }
  7670. else clif_displaymessage(fd, msg_txt(sd,149)); // Impossible to increase the number/value.
  7671. } else {
  7672. if (-value > sd->kafraPoints) //By command, if cash < value, force it to remove all
  7673. value = -sd->kafraPoints;
  7674. if( (ret=pc_paycash(sd, 0, -value, LOG_TYPE_COMMAND)) >= 0){
  7675. sprintf(output, msg_txt(sd,411), ret, sd->kafraPoints); // Removed %d kafra points. Total %d points.
  7676. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  7677. }
  7678. else clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  7679. }
  7680. }
  7681. return 0;
  7682. }
  7683. // @clone/@slaveclone/@evilclone <playername> [Valaris]
  7684. ACMD_FUNC(clone)
  7685. {
  7686. int x=0,y=0,flag=0,master=0,i=0;
  7687. map_session_data *pl_sd=nullptr;
  7688. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  7689. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  7690. clif_displaymessage(sd->fd,msg_txt(sd,1323)); // You must enter a player name or ID.
  7691. return 0;
  7692. }
  7693. if((pl_sd=map_nick2sd(atcmd_player_name,true)) == nullptr && (pl_sd=map_charid2sd(atoi(atcmd_player_name))) == nullptr) {
  7694. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  7695. return 0;
  7696. }
  7697. if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  7698. clif_displaymessage(fd, msg_txt(sd,126)); // Cannot clone a player of higher GM level than yourself.
  7699. return 0;
  7700. }
  7701. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  7702. if (strcmpi(parent_cmd, "clone") == 0)
  7703. flag = 1;
  7704. else if (strcmpi(parent_cmd, "slaveclone") == 0) {
  7705. flag = 2;
  7706. if(pc_isdead(sd)){
  7707. clif_displaymessage(fd, msg_txt(sd,129+flag*2));
  7708. return 0;
  7709. }
  7710. master = sd->bl.id;
  7711. if (battle_config.atc_slave_clone_limit
  7712. && mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
  7713. clif_displaymessage(fd, msg_txt(sd,127)); // You've reached your slave clones limit.
  7714. return 0;
  7715. }
  7716. }
  7717. do {
  7718. x = sd->bl.x + rnd_value(-5, 5);
  7719. y = sd->bl.y + rnd_value(-5, 5);
  7720. } while (map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) && i++ < 10);
  7721. if (i >= 10) {
  7722. x = sd->bl.x;
  7723. y = sd->bl.y;
  7724. }
  7725. if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, MD_NONE, flag?1:0, 0)) > 0) {
  7726. clif_displaymessage(fd, msg_txt(sd,128+flag*2)); // Evil Clone spawned. Clone spawned. Slave clone spawned.
  7727. return 0;
  7728. }
  7729. clif_displaymessage(fd, msg_txt(sd,129+flag*2)); // Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
  7730. return 0;
  7731. }
  7732. /*=====================================
  7733. * Autorejecting Invites/Deals [LuzZza]
  7734. * Usage: @noask
  7735. *-------------------------------------*/
  7736. ACMD_FUNC(noask)
  7737. {
  7738. if(sd->state.noask) {
  7739. clif_displaymessage(fd, msg_txt(sd,391)); // Autorejecting is deactivated.
  7740. sd->state.noask = 0;
  7741. } else {
  7742. clif_displaymessage(fd, msg_txt(sd,390)); // Autorejecting is activated.
  7743. sd->state.noask = 1;
  7744. }
  7745. return 0;
  7746. }
  7747. /*=====================================
  7748. * Send a @request message to all GMs of lowest_gm_level.
  7749. * Usage: @request <petition>
  7750. *-------------------------------------*/
  7751. ACMD_FUNC(request)
  7752. {
  7753. if (!message || !*message) {
  7754. clif_displaymessage(sd->fd,msg_txt(sd,277)); // Usage: @request <petition/message to online GMs>.
  7755. return -1;
  7756. }
  7757. sprintf(atcmd_output, msg_txt(sd,278), message); // (@request): %s
  7758. intif_wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output);
  7759. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], atcmd_output, false, SELF);
  7760. clif_displaymessage(sd->fd,msg_txt(sd,279)); // @request sent.
  7761. return 0;
  7762. }
  7763. /*==========================================
  7764. * Feel (SG designated maps) Reset [HiddenDragon]
  7765. *------------------------------------------*/
  7766. ACMD_FUNC(feelreset)
  7767. {
  7768. if ((sd->class_&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  7769. clif_displaymessage(sd->fd,msg_txt(sd,35)); // You can't use this command with this class.
  7770. return -1;
  7771. }
  7772. pc_resetfeel(sd);
  7773. clif_displaymessage(fd, msg_txt(sd,1324)); // Reset 'Feeling' maps.
  7774. return 0;
  7775. }
  7776. /*==========================================
  7777. * Hate (SG designated monsters) Reset
  7778. *------------------------------------------*/
  7779. ACMD_FUNC(hatereset)
  7780. {
  7781. if ((sd->class_&MAPID_UPPERMASK) != MAPID_STAR_GLADIATOR) {
  7782. clif_displaymessage(sd->fd,msg_txt(sd,35)); // You can't use this command with this class.
  7783. return -1;
  7784. }
  7785. pc_resethate(sd);
  7786. clif_displaymessage(fd, msg_txt(sd,1515)); // Reset 'Hatred' monsters.
  7787. return 0;
  7788. }
  7789. /*==========================================
  7790. * AUCTION SYSTEM
  7791. *------------------------------------------*/
  7792. ACMD_FUNC(auction)
  7793. {
  7794. nullpo_ret(sd);
  7795. if (!battle_config.feature_auction) {
  7796. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 517), false, SELF);
  7797. return 0;
  7798. }
  7799. clif_Auction_openwindow(sd);
  7800. return 0;
  7801. }
  7802. /*==========================================
  7803. * Kill Steal Protection
  7804. *------------------------------------------*/
  7805. ACMD_FUNC(ksprotection)
  7806. {
  7807. nullpo_retr(-1,sd);
  7808. if( sd->state.noks ) {
  7809. sd->state.noks = 0;
  7810. clif_displaymessage(fd, msg_txt(sd,1325)); // [ K.S Protection Inactive ]
  7811. }
  7812. else
  7813. {
  7814. if( !message || !*message || !strcmpi(message, "party") )
  7815. { // Default is Party
  7816. sd->state.noks = 2;
  7817. clif_displaymessage(fd, msg_txt(sd,1326)); // [ K.S Protection Active - Option: Party ]
  7818. }
  7819. else if( !strcmpi(message, "self") )
  7820. {
  7821. sd->state.noks = 1;
  7822. clif_displaymessage(fd, msg_txt(sd,1327)); // [ K.S Protection Active - Option: Self ]
  7823. }
  7824. else if( !strcmpi(message, "guild") )
  7825. {
  7826. sd->state.noks = 3;
  7827. clif_displaymessage(fd, msg_txt(sd,1328)); // [ K.S Protection Active - Option: Guild ]
  7828. }
  7829. else
  7830. clif_displaymessage(fd, msg_txt(sd,1329)); // Usage: @noks <self|party|guild>
  7831. }
  7832. return 0;
  7833. }
  7834. /*==========================================
  7835. * Map Kill Steal Protection Setting
  7836. *------------------------------------------*/
  7837. ACMD_FUNC(allowks)
  7838. {
  7839. nullpo_retr(-1,sd);
  7840. if( map_getmapflag(sd->bl.m, MF_ALLOWKS) ) {
  7841. map_setmapflag(sd->bl.m, MF_ALLOWKS, false);
  7842. clif_displaymessage(fd, msg_txt(sd,1330)); // [ Map K.S Protection Active ]
  7843. } else {
  7844. map_setmapflag(sd->bl.m, MF_ALLOWKS, true);
  7845. clif_displaymessage(fd, msg_txt(sd,1331)); // [ Map K.S Protection Inactive ]
  7846. }
  7847. return 0;
  7848. }
  7849. ACMD_FUNC(resetstat)
  7850. {
  7851. nullpo_retr(-1, sd);
  7852. pc_resetstate(sd);
  7853. sprintf(atcmd_output, msg_txt(sd,207), sd->status.name); // '%s' stats points reset.
  7854. clif_displaymessage(fd, atcmd_output);
  7855. return 0;
  7856. }
  7857. ACMD_FUNC(resetskill)
  7858. {
  7859. nullpo_retr(-1,sd);
  7860. pc_resetskill(sd,1);
  7861. sprintf(atcmd_output, msg_txt(sd,206), sd->status.name); // '%s' skill points reset.
  7862. clif_displaymessage(fd, atcmd_output);
  7863. return 0;
  7864. }
  7865. /*==========================================
  7866. * #storagelist: Displays the items list of a player's storage.
  7867. * #cartlist: Displays contents of target's cart.
  7868. * #itemlist: Displays contents of target's inventory.
  7869. *------------------------------------------*/
  7870. ACMD_FUNC(itemlist)
  7871. {
  7872. int i, j, count, counter;
  7873. const char* location;
  7874. struct item* items;
  7875. int size;
  7876. StringBuf buf;
  7877. nullpo_retr(-1, sd);
  7878. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  7879. if( strcmp(parent_cmd, "storagelist") == 0 ) {
  7880. location = "storage";
  7881. items = sd->storage.u.items_storage;
  7882. size = sd->storage.max_amount;
  7883. } else if( strcmp(parent_cmd, "cartlist") == 0 ) {
  7884. location = "cart";
  7885. items = sd->cart.u.items_cart;
  7886. size = MAX_CART;
  7887. } else if( strcmp(parent_cmd, "itemlist") == 0 ) {
  7888. location = "inventory";
  7889. items = sd->inventory.u.items_inventory;
  7890. size = MAX_INVENTORY;
  7891. } else
  7892. return 1;
  7893. StringBuf_Init(&buf);
  7894. count = 0; // total slots occupied
  7895. counter = 0; // total items found
  7896. for( i = 0; i < size; ++i ) {
  7897. struct item* it = &items[i];
  7898. if( it->nameid == 0 )
  7899. continue;
  7900. std::shared_ptr<item_data> itd = item_db.find(it->nameid);
  7901. if (itd == nullptr)
  7902. continue;
  7903. counter += it->amount;
  7904. count++;
  7905. if( count == 1 ) {
  7906. StringBuf_Printf(&buf, msg_txt(sd,1332), location, sd->status.name); // ------ %s items list of '%s' ------
  7907. clif_displaymessage(fd, StringBuf_Value(&buf));
  7908. StringBuf_Clear(&buf);
  7909. }
  7910. StringBuf_Printf(&buf, "%d %s (%s, id: %u)", it->amount, item_db.create_item_link( *it ).c_str(), itd->name.c_str(), it->nameid);
  7911. if( it->equip ) {
  7912. char equipstr[CHAT_SIZE_MAX];
  7913. strcpy(equipstr, msg_txt(sd,1333)); // | Equipped:
  7914. if( it->equip&EQP_GARMENT )
  7915. strcat(equipstr, msg_txt(sd,1334)); // Robe,
  7916. if( it->equip&EQP_ACC_L )
  7917. strcat(equipstr, msg_txt(sd,1335)); // Left Accessory,
  7918. if( it->equip&EQP_ARMOR )
  7919. strcat(equipstr, msg_txt(sd,1336)); // Body/Armor,
  7920. if( (it->equip&EQP_ARMS) == EQP_HAND_R )
  7921. strcat(equipstr, msg_txt(sd,1337)); // Right Hand,
  7922. if( (it->equip&EQP_ARMS) == EQP_HAND_L )
  7923. strcat(equipstr, msg_txt(sd,1338)); // Left Hand,
  7924. if( (it->equip&EQP_ARMS) == EQP_ARMS )
  7925. strcat(equipstr, msg_txt(sd,1339)); // Both Hands,
  7926. if( it->equip&EQP_SHOES )
  7927. strcat(equipstr, msg_txt(sd,1340)); // Shoes,
  7928. if( it->equip&EQP_ACC_R )
  7929. strcat(equipstr, msg_txt(sd,1341)); // Right Accessory,
  7930. if( (it->equip&EQP_HELM) == EQP_HEAD_LOW )
  7931. strcat(equipstr, msg_txt(sd,1342)); // Lower Head,
  7932. if( (it->equip&EQP_HELM) == EQP_HEAD_TOP )
  7933. strcat(equipstr, msg_txt(sd,1343)); // Top Head,
  7934. if( (it->equip&EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_TOP) )
  7935. strcat(equipstr, msg_txt(sd,1344)); // Top/Lower Head,
  7936. if( (it->equip&EQP_HELM) == EQP_HEAD_MID )
  7937. strcat(equipstr, msg_txt(sd,1345)); // Mid Head,
  7938. if( (it->equip&EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_MID) )
  7939. strcat(equipstr, msg_txt(sd,1346)); // Mid/Lower Head,
  7940. if( (it->equip&EQP_HELM) == EQP_HELM )
  7941. strcat(equipstr, msg_txt(sd,1347)); // Top/Mid/Lower Head,
  7942. if( (it->equip&EQP_COSTUME_HELM) == EQP_COSTUME_HEAD_LOW )
  7943. strcat(equipstr, msg_txt(sd,518)); // Lower Costume Head,
  7944. if( (it->equip&EQP_COSTUME_HELM) == EQP_COSTUME_HEAD_TOP )
  7945. strcat(equipstr, msg_txt(sd,519)); // Top Costume Head,
  7946. if( (it->equip&EQP_COSTUME_HELM) == (EQP_COSTUME_HEAD_LOW|EQP_COSTUME_HEAD_TOP) )
  7947. strcat(equipstr, msg_txt(sd,520)); // Top/Lower Costume Head,
  7948. if( (it->equip&EQP_COSTUME_HELM) == EQP_COSTUME_HEAD_MID )
  7949. strcat(equipstr, msg_txt(sd,521)); // Mid Costume Head,
  7950. if( (it->equip&EQP_COSTUME_HELM) == (EQP_COSTUME_HEAD_LOW|EQP_COSTUME_HEAD_MID) )
  7951. strcat(equipstr, msg_txt(sd,522)); // Mid/Lower Costume Head,
  7952. if( (it->equip&EQP_COSTUME_HELM) == EQP_COSTUME_HELM )
  7953. strcat(equipstr, msg_txt(sd,523)); // Top/Mid/Lower Costume Head,
  7954. if( it->equip&EQP_COSTUME_GARMENT )
  7955. strcat(equipstr, msg_txt(sd,524)); // Costume Robe,
  7956. //if( it->equip&EQP_COSTUME_FLOOR )
  7957. //strcat(equipstr, msg_txt(sd,525)); // Costume Floor,
  7958. if( it->equip&EQP_AMMO )
  7959. strcat(equipstr, msg_txt(sd,526)); // Ammo,
  7960. if( it->equip&EQP_SHADOW_ARMOR )
  7961. strcat(equipstr, msg_txt(sd,527)); // Shadow Body,
  7962. if( (it->equip&EQP_SHADOW_ARMS) == EQP_SHADOW_WEAPON )
  7963. strcat(equipstr, msg_txt(sd,528)); // Shadow Right Hand,
  7964. if( (it->equip&EQP_SHADOW_ARMS) == EQP_SHADOW_SHIELD )
  7965. strcat(equipstr, msg_txt(sd,529)); // Shadow Left Hand,
  7966. if( (it->equip&EQP_SHADOW_ARMS) == EQP_SHADOW_ARMS )
  7967. strcat(equipstr, msg_txt(sd,530)); // Shadow Both Hands,
  7968. if( it->equip&EQP_SHADOW_SHOES )
  7969. strcat(equipstr, msg_txt(sd,531)); // Shadow Shoes,
  7970. if( it->equip&EQP_SHADOW_ACC_R )
  7971. strcat(equipstr, msg_txt(sd,532)); // Shadow Right Accessory,
  7972. if( it->equip&EQP_SHADOW_ACC_L )
  7973. strcat(equipstr, msg_txt(sd,533)); // Shadow Left Accessory,
  7974. // remove final ', '
  7975. equipstr[strlen(equipstr) - 2] = '\0';
  7976. StringBuf_AppendStr(&buf, equipstr);
  7977. }
  7978. clif_displaymessage(fd, StringBuf_Value(&buf));
  7979. StringBuf_Clear(&buf);
  7980. if( it->card[0] == CARD0_PET ) { // pet egg
  7981. if (it->card[3]&1)
  7982. StringBuf_Printf(&buf, msg_txt(sd,1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named)
  7983. else
  7984. StringBuf_Printf(&buf, msg_txt(sd,1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed)
  7985. } else if(it->card[0] == CARD0_FORGE) { // forged item
  7986. StringBuf_Printf(&buf, msg_txt(sd,1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d)
  7987. } else if(it->card[0] == CARD0_CREATE) { // created item
  7988. StringBuf_Printf(&buf, msg_txt(sd,1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u)
  7989. } else { // normal item
  7990. int counter2 = 0;
  7991. for( j = 0; j < itd->slots; ++j ) {
  7992. if( it->card[j] == 0 )
  7993. continue;
  7994. std::shared_ptr<item_data> card = item_db.find(it->card[j]);
  7995. if (card == nullptr)
  7996. continue;
  7997. counter2++;
  7998. if( counter2 == 1 )
  7999. StringBuf_AppendStr(&buf, msg_txt(sd,1352)); // -> (card(s):
  8000. if( counter2 != 1 )
  8001. StringBuf_AppendStr(&buf, ", ");
  8002. StringBuf_Printf(&buf, "#%d %s (id: %u)", counter2, item_db.create_item_link( card ).c_str(), card->nameid);
  8003. }
  8004. if( counter2 > 0 )
  8005. StringBuf_AppendStr(&buf, ")");
  8006. }
  8007. if( StringBuf_Length(&buf) > 0 )
  8008. clif_displaymessage(fd, StringBuf_Value(&buf));
  8009. StringBuf_Clear(&buf);
  8010. }
  8011. if( count == 0 )
  8012. StringBuf_Printf(&buf, msg_txt(sd,1353), location); // No item found in this player's %s.
  8013. else
  8014. StringBuf_Printf(&buf, msg_txt(sd,1354), counter, count, location); // %d item(s) found in %d %s slots.
  8015. clif_displaymessage(fd, StringBuf_Value(&buf));
  8016. StringBuf_Destroy(&buf);
  8017. return 0;
  8018. }
  8019. ACMD_FUNC(stats)
  8020. {
  8021. char job_jobname[100];
  8022. char output[CHAT_SIZE_MAX];
  8023. int i;
  8024. struct {
  8025. const char* format;
  8026. int value;
  8027. } output_table[] = {
  8028. { "Base Level - %d", 0 },
  8029. { nullptr, 0 },
  8030. { "Hp - %d", 0 },
  8031. { "MaxHp - %d", 0 },
  8032. { "Sp - %d", 0 },
  8033. { "MaxSp - %d", 0 },
  8034. { "Ap - %d", 0 },
  8035. { "MaxAp - %d", 0 },
  8036. { "Str - %3d", 0 },
  8037. { "Agi - %3d", 0 },
  8038. { "Vit - %3d", 0 },
  8039. { "Int - %3d", 0 },
  8040. { "Dex - %3d", 0 },
  8041. { "Luk - %3d", 0 },
  8042. { "Pow - %3d", 0 },
  8043. { "Sta - %3d", 0 },
  8044. { "Wis - %3d", 0 },
  8045. { "Spl - %3d", 0 },
  8046. { "Con - %3d", 0 },
  8047. { "Crt - %3d", 0 },
  8048. { "Zeny - %d", 0 },
  8049. { "Free Status Points - %d", 0 },
  8050. { "Free Trait Points - %d", 0 },
  8051. { "Free Skill Points - %d", 0 },
  8052. { "JobChangeLvl (2nd) - %d", 0 },
  8053. { "JobChangeLvl (3rd) - %d", 0 },
  8054. { "JobChangeLvl (4th) - %d", 0 },
  8055. { nullptr, 0 }
  8056. };
  8057. memset(job_jobname, '\0', sizeof(job_jobname));
  8058. memset(output, '\0', sizeof(output));
  8059. //direct array initialization with variables is not standard C compliant.
  8060. output_table[0].value = sd->status.base_level;
  8061. output_table[1].format = job_jobname;
  8062. output_table[1].value = sd->status.job_level;
  8063. output_table[2].value = sd->status.hp;
  8064. output_table[3].value = sd->status.max_hp;
  8065. output_table[4].value = sd->status.sp;
  8066. output_table[5].value = sd->status.max_sp;
  8067. output_table[6].value = sd->status.ap;
  8068. output_table[7].value = sd->status.max_ap;
  8069. output_table[8].value = sd->status.str;
  8070. output_table[9].value = sd->status.agi;
  8071. output_table[10].value = sd->status.vit;
  8072. output_table[11].value = sd->status.int_;
  8073. output_table[12].value = sd->status.dex;
  8074. output_table[13].value = sd->status.luk;
  8075. output_table[14].value = sd->status.pow;
  8076. output_table[15].value = sd->status.sta;
  8077. output_table[16].value = sd->status.wis;
  8078. output_table[17].value = sd->status.spl;
  8079. output_table[18].value = sd->status.con;
  8080. output_table[19].value = sd->status.crt;
  8081. output_table[20].value = sd->status.zeny;
  8082. output_table[21].value = sd->status.status_point;
  8083. output_table[22].value = sd->status.trait_point;
  8084. output_table[23].value = sd->status.skill_point;
  8085. output_table[24].value = sd->change_level_2nd;
  8086. output_table[25].value = sd->change_level_3rd;
  8087. output_table[26].value = sd->change_level_4th;
  8088. sprintf(job_jobname, "Job - %s %s", job_name(sd->status.class_), "(level %d)");
  8089. sprintf(output, msg_txt(sd,53), sd->status.name); // '%s' stats:
  8090. clif_displaymessage(fd, output);
  8091. for (i = 0; output_table[i].format != nullptr; i++) {
  8092. sprintf(output, output_table[i].format, output_table[i].value);
  8093. clif_displaymessage(fd, output);
  8094. }
  8095. return 0;
  8096. }
  8097. ACMD_FUNC(delitem)
  8098. {
  8099. char item_name[100];
  8100. int amount = 0, idx;
  8101. nullpo_retr(-1, sd);
  8102. if( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %11d", item_name, &amount) < 2 && sscanf(message, "%99s %11d", item_name, &amount) < 2 ) || amount < 1 )
  8103. {
  8104. clif_displaymessage(fd, msg_txt(sd,1355)); // Please enter an item name/ID, a quantity, and a player name (usage: #delitem <player> <item_name_or_ID> <quantity>).
  8105. return -1;
  8106. }
  8107. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  8108. if( id == nullptr ){
  8109. id = item_db.find( strtoul( item_name, nullptr, 10 ) );
  8110. }
  8111. if( id == nullptr ){
  8112. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  8113. return -1;
  8114. }
  8115. t_itemid nameid = id->nameid;
  8116. int total = amount;
  8117. // delete items
  8118. while( amount && ( idx = pc_search_inventory(sd, nameid) ) != -1 )
  8119. {
  8120. int delamount = ( amount < sd->inventory.u.items_inventory[idx].amount ) ? amount : sd->inventory.u.items_inventory[idx].amount;
  8121. if( sd->inventory_data[idx]->type == IT_PETEGG && sd->inventory.u.items_inventory[idx].card[0] == CARD0_PET )
  8122. {// delete pet
  8123. intif_delete_petdata(MakeDWord(sd->inventory.u.items_inventory[idx].card[1], sd->inventory.u.items_inventory[idx].card[2]));
  8124. }
  8125. pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_COMMAND);
  8126. amount-= delamount;
  8127. }
  8128. // notify target
  8129. sprintf(atcmd_output, msg_txt(sd,113), total-amount); // %d item(s) removed by a GM.
  8130. clif_displaymessage(sd->fd, atcmd_output);
  8131. // notify source
  8132. if( amount == total )
  8133. {
  8134. clif_displaymessage(fd, msg_txt(sd,116)); // Character does not have the item.
  8135. }
  8136. else if( amount )
  8137. {
  8138. sprintf(atcmd_output, msg_txt(sd,115), total-amount, total-amount, total); // %d item(s) removed. Player had only %d on %d items.
  8139. clif_displaymessage(fd, atcmd_output);
  8140. }
  8141. else
  8142. {
  8143. sprintf(atcmd_output, msg_txt(sd,114), total); // %d item(s) removed from the player.
  8144. clif_displaymessage(fd, atcmd_output);
  8145. }
  8146. return 0;
  8147. }
  8148. /*==========================================
  8149. * Custom Fonts
  8150. *------------------------------------------*/
  8151. ACMD_FUNC(font)
  8152. {
  8153. int font_id;
  8154. nullpo_retr(-1,sd);
  8155. font_id = atoi(message);
  8156. if( font_id == 0 ) {
  8157. if( sd->status.font ) {
  8158. sd->status.font = 0;
  8159. clif_displaymessage(fd, msg_txt(sd,1356)); // Returning to normal font.
  8160. clif_font(sd);
  8161. } else {
  8162. clif_displaymessage(fd, msg_txt(sd,1357)); // Use @font <1-9> to change your message font.
  8163. clif_displaymessage(fd, msg_txt(sd,1358)); // Use 0 or no parameter to return to normal font.
  8164. }
  8165. } else if( font_id < 0 || font_id > 9 )
  8166. clif_displaymessage(fd, msg_txt(sd,1359)); // Invalid font. Use a value from 0 to 9.
  8167. else if( font_id != sd->status.font ) {
  8168. sd->status.font = font_id;
  8169. clif_font(sd);
  8170. clif_displaymessage(fd, msg_txt(sd,1360)); // Font changed.
  8171. } else
  8172. clif_displaymessage(fd, msg_txt(sd,1361)); // Already using this font.
  8173. return 0;
  8174. }
  8175. /*==========================================
  8176. * type: 1 = commands (@), 2 = charcommands (#)
  8177. *------------------------------------------*/
  8178. static void atcommand_commands_sub(map_session_data* sd, const int fd, AtCommandType type)
  8179. {
  8180. char line_buff[CHATBOX_SIZE];
  8181. char* cur = line_buff;
  8182. AtCommandInfo* cmd;
  8183. DBIterator *iter = db_iterator(atcommand_db);
  8184. int count = 0;
  8185. memset(line_buff,' ',CHATBOX_SIZE);
  8186. line_buff[CHATBOX_SIZE-1] = 0;
  8187. clif_displaymessage(fd, msg_txt(sd,273)); // "Commands available:"
  8188. for (cmd = (AtCommandInfo*)dbi_first(iter); dbi_exists(iter); cmd = (AtCommandInfo*)dbi_next(iter)) {
  8189. unsigned int slen = 0;
  8190. switch( type ) {
  8191. case COMMAND_CHARCOMMAND:
  8192. if( cmd->char_groups[sd->group->index] == 0 )
  8193. continue;
  8194. break;
  8195. case COMMAND_ATCOMMAND:
  8196. if( cmd->at_groups[sd->group->index] == 0 )
  8197. continue;
  8198. break;
  8199. default:
  8200. continue;
  8201. }
  8202. slen = strlen(cmd->command);
  8203. // flush the text buffer if this command won't fit into it
  8204. if (slen + cur - line_buff >= CHATBOX_SIZE) {
  8205. clif_displaymessage(fd,line_buff);
  8206. cur = line_buff;
  8207. memset(line_buff,' ',CHATBOX_SIZE);
  8208. line_buff[CHATBOX_SIZE-1] = 0;
  8209. }
  8210. memcpy(cur,cmd->command,slen);
  8211. cur += slen+(10-slen%10);
  8212. count++;
  8213. }
  8214. dbi_destroy(iter);
  8215. clif_displaymessage(fd,line_buff);
  8216. if ( atcmd_binding_count ) {
  8217. int i, count_bind, gm_lvl = pc_get_group_level(sd);
  8218. for( i = count_bind = 0; i < atcmd_binding_count; i++ ) {
  8219. if ( gm_lvl >= ( (type - 1) ? atcmd_binding[i]->level2 : atcmd_binding[i]->level ) ) {
  8220. unsigned int slen = strlen(atcmd_binding[i]->command);
  8221. if ( count_bind == 0 ) {
  8222. cur = line_buff;
  8223. memset(line_buff,' ',CHATBOX_SIZE);
  8224. line_buff[CHATBOX_SIZE-1] = 0;
  8225. clif_displaymessage(fd, "-----------------");
  8226. clif_displaymessage(fd, msg_txt(sd,509)); // Script-bound commands:
  8227. }
  8228. if (slen + cur - line_buff >= CHATBOX_SIZE) {
  8229. clif_displaymessage(fd,line_buff);
  8230. cur = line_buff;
  8231. memset(line_buff,' ',CHATBOX_SIZE);
  8232. line_buff[CHATBOX_SIZE-1] = 0;
  8233. }
  8234. memcpy(cur,atcmd_binding[i]->command,slen);
  8235. cur += slen+(10-slen%10);
  8236. count_bind++;
  8237. }
  8238. }
  8239. if ( count_bind )
  8240. clif_displaymessage(fd,line_buff);// last one
  8241. count += count_bind;
  8242. }
  8243. sprintf(atcmd_output, msg_txt(sd,274), count); // "%d commands found."
  8244. clif_displaymessage(fd, atcmd_output);
  8245. return;
  8246. }
  8247. /*==========================================
  8248. * @commands Lists available @ commands to you
  8249. *------------------------------------------*/
  8250. ACMD_FUNC(commands)
  8251. {
  8252. atcommand_commands_sub(sd, fd, COMMAND_ATCOMMAND);
  8253. return 0;
  8254. }
  8255. /*==========================================
  8256. * @charcommands Lists available # commands to you
  8257. *------------------------------------------*/
  8258. ACMD_FUNC(charcommands) {
  8259. atcommand_commands_sub(sd, fd, COMMAND_CHARCOMMAND);
  8260. return 0;
  8261. }
  8262. /* for new mounts */
  8263. ACMD_FUNC(mount2) {
  8264. clif_displaymessage(sd->fd,msg_txt(sd,1362)); // NOTICE: If you crash with mount your LUA is outdated.
  8265. if (!sd->sc.getSCE(SC_ALL_RIDING)) {
  8266. clif_displaymessage(sd->fd,msg_txt(sd,1363)); // You have mounted.
  8267. sc_start(nullptr, &sd->bl, SC_ALL_RIDING, 10000, 1, INFINITE_TICK);
  8268. } else {
  8269. clif_displaymessage(sd->fd,msg_txt(sd,1364)); // You have released your mount.
  8270. status_change_end(&sd->bl, SC_ALL_RIDING);
  8271. }
  8272. return 0;
  8273. }
  8274. ACMD_FUNC(accinfo) {
  8275. char query[NAME_LENGTH];
  8276. char type = 0; // type = 1, get only account name
  8277. if (!message || !*message || strlen(message) > NAME_LENGTH
  8278. || ( sscanf(message, "%23s %c", query, &type) < 1))
  8279. {
  8280. clif_displaymessage(fd, msg_txt(sd,1365)); // Usage: @accinfo/@accountinfo <account_id/char name>
  8281. clif_displaymessage(fd, msg_txt(sd,1366)); // You may search partial name by making use of '%' in the search, ex. "@accinfo %Mario%" lists all characters whose name contains "Mario".
  8282. return -1;
  8283. } else if (type != 0) {
  8284. type = type-'0'; //make it int
  8285. if (type != 1) {
  8286. clif_displaymessage(fd, "accinfo : Unknow type specified\n");
  8287. return -1;
  8288. }
  8289. }
  8290. intif_request_accinfo( sd->fd, sd->bl.id, pc_get_group_level(sd), query, type);
  8291. return 0;
  8292. }
  8293. /**
  8294. * @set <variable name{[index]}>{ <value>}
  8295. *
  8296. * Gets or sets a value of a non server variable.
  8297. * If a value is specified it is used to set the variable's value,
  8298. * if not the variable's value is read.
  8299. * In any case it reads and displays the variable's value.
  8300. *
  8301. * Original implementation by Ind
  8302. */
  8303. ACMD_FUNC(set) {
  8304. char reg[46], val[128], name[32];
  8305. int toset = 0, len;
  8306. uint32 index;
  8307. bool is_str = false;
  8308. int64 uid;
  8309. if( !message || !*message || (toset = sscanf(message, "%45s %127[^\n]s", reg, val)) < 1 ) {
  8310. clif_displaymessage(fd, msg_txt(sd,1367)); // Usage: @set <variable name> <value>
  8311. clif_displaymessage(fd, msg_txt(sd,1368)); // Usage: ex. "@set PoringCharVar 50"
  8312. clif_displaymessage(fd, msg_txt(sd,1369)); // Usage: ex. "@set PoringCharVarSTR$ Super Duper String"
  8313. clif_displaymessage(fd, msg_txt(sd,1370)); // Usage: ex. "@set PoringCharVarSTR$" outputs its value, Super Duper String.
  8314. return -1;
  8315. }
  8316. /* disabled variable types (they require a proper script state to function, so allowing them would crash the server) */
  8317. if( reg[0] == '.' ) {
  8318. clif_displaymessage(fd, msg_txt(sd,1371)); // NPC variables may not be used with @set.
  8319. return -1;
  8320. } else if( reg[0] == '\'' ) {
  8321. clif_displaymessage(fd, msg_txt(sd,1372)); // Instance variables may not be used with @set.
  8322. return -1;
  8323. }
  8324. // Check if the user wanted to set an array
  8325. if( sscanf( reg, "%31[^[][%" PRIu32 "]", name, &index ) < 2 ){
  8326. // The user did not specify array brackets, so we set the index to zero
  8327. index = 0;
  8328. }
  8329. is_str = is_string_variable(name);
  8330. if( ( len = strlen(val) ) > 1 ) {
  8331. if( val[0] == '"' && val[len-1] == '"') {
  8332. val[len-1] = '\0'; //Strip quotes.
  8333. memmove(val, val+1, len-1);
  8334. }
  8335. }
  8336. // Only set the variable if there is a value for it
  8337. if( toset >= 2 ){
  8338. if( is_str ){
  8339. setd_sub_str( nullptr, sd, name, index, val, nullptr );
  8340. }else{
  8341. setd_sub_num( nullptr, sd, name, index, strtoll( val, nullptr, 10 ), nullptr );
  8342. }
  8343. }
  8344. uid = reference_uid( add_str( name ), index );
  8345. if( is_str ) {// string variable
  8346. char* value;
  8347. switch( reg[0] ) {
  8348. case '@':
  8349. value = pc_readregstr(sd, uid);
  8350. break;
  8351. case '$':
  8352. value = mapreg_readregstr(uid);
  8353. break;
  8354. case '#':
  8355. if( reg[1] == '#' )
  8356. value = pc_readaccountreg2str(sd, uid);// global
  8357. else
  8358. value = pc_readaccountregstr(sd, uid);// local
  8359. break;
  8360. default:
  8361. value = pc_readglobalreg_str(sd, uid);
  8362. break;
  8363. }
  8364. if( value == nullptr || *value == '\0' ){// empty string
  8365. sprintf(atcmd_output,msg_txt(sd,1375),reg); // %s is empty
  8366. }else{
  8367. sprintf(atcmd_output,msg_txt(sd,1374),reg,value); // %s value is now: %s
  8368. }
  8369. } else {// integer variable
  8370. int64 value;
  8371. switch( reg[0] ) {
  8372. case '@':
  8373. value = pc_readreg(sd, uid);
  8374. break;
  8375. case '$':
  8376. value = mapreg_readreg(uid);
  8377. break;
  8378. case '#':
  8379. if( reg[1] == '#' )
  8380. value = pc_readaccountreg2(sd, uid);// global
  8381. else
  8382. value = pc_readaccountreg(sd, uid);// local
  8383. break;
  8384. default:
  8385. value = pc_readglobalreg(sd, uid);
  8386. break;
  8387. }
  8388. sprintf(atcmd_output,msg_txt(sd,1373),reg,value); // %s value is now: %lld
  8389. }
  8390. clif_displaymessage(fd, atcmd_output);
  8391. return 0;
  8392. }
  8393. ACMD_FUNC(addperm) {
  8394. int perm_size = ARRAYLENGTH(pc_g_permission_name);
  8395. bool add;
  8396. int i;
  8397. parent_cmd = atcommand_alias_db.checkAlias(command+1);
  8398. add = (strcmpi(parent_cmd, "addperm") == 0);
  8399. if( !message || !*message ) {
  8400. sprintf(atcmd_output, msg_txt(sd,1378),command); // Usage: %s <permission_name>
  8401. clif_displaymessage(fd, atcmd_output);
  8402. clif_displaymessage(fd, msg_txt(sd,1379)); // -- Permission List
  8403. for( i = 0; i < perm_size; i++ ) {
  8404. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  8405. clif_displaymessage(fd, atcmd_output);
  8406. }
  8407. return -1;
  8408. }
  8409. ARR_FIND(0, perm_size, i, strcmpi(pc_g_permission_name[i].name, message) == 0);
  8410. if( i == perm_size ) {
  8411. sprintf(atcmd_output,msg_txt(sd,1380),message); // '%s' is not a known permission.
  8412. clif_displaymessage(fd, atcmd_output);
  8413. clif_displaymessage(fd, msg_txt(sd,1379)); // -- Permission List
  8414. for( i = 0; i < perm_size; i++ ) {
  8415. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  8416. clif_displaymessage(fd, atcmd_output);
  8417. }
  8418. return -1;
  8419. }
  8420. if( add && pc_has_permission( sd, pc_g_permission_name[i].permission) ){
  8421. sprintf(atcmd_output, msg_txt(sd,1381),sd->status.name,pc_g_permission_name[i].name); // User '%s' already possesses the '%s' permission.
  8422. clif_displaymessage(fd, atcmd_output);
  8423. return -1;
  8424. }else if( !add && !pc_has_permission( sd, pc_g_permission_name[i].permission ) ){
  8425. sprintf(atcmd_output, msg_txt(sd,1382),sd->status.name,pc_g_permission_name[i].name); // User '%s' doesn't possess the '%s' permission.
  8426. clif_displaymessage(fd, atcmd_output);
  8427. sprintf(atcmd_output,msg_txt(sd,1383),sd->status.name); // -- User '%s' Permissions
  8428. clif_displaymessage(fd, atcmd_output);
  8429. for( i = 0; i < perm_size; i++ ) {
  8430. if( pc_has_permission( sd, pc_g_permission_name[i].permission ) ){
  8431. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  8432. clif_displaymessage(fd, atcmd_output);
  8433. }
  8434. }
  8435. return -1;
  8436. }
  8437. if( add ){
  8438. sd->permissions.set( pc_g_permission_name[i].permission );
  8439. }else{
  8440. sd->permissions.reset( pc_g_permission_name[i].permission );
  8441. }
  8442. sprintf(atcmd_output, msg_txt(sd,1384),sd->status.name); // User '%s' permissions updated successfully. The changes are temporary.
  8443. clif_displaymessage(fd, atcmd_output);
  8444. return 0;
  8445. }
  8446. ACMD_FUNC(unloadnpcfile) {
  8447. if( !message || !*message ) {
  8448. clif_displaymessage(fd, msg_txt(sd,1385)); // Usage: @unloadnpcfile <file name>
  8449. return -1;
  8450. }
  8451. if( npc_unloadfile(message) )
  8452. clif_displaymessage(fd, msg_txt(sd,1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
  8453. else {
  8454. clif_displaymessage(fd, msg_txt(sd,1387)); // File not found.
  8455. return -1;
  8456. }
  8457. return 0;
  8458. }
  8459. ACMD_FUNC(cart) {
  8460. #define MC_CART_MDFY(idx, x) \
  8461. sd->status.skill[(idx)].id = (x)?MC_PUSHCART:0; \
  8462. sd->status.skill[(idx)].lv = (x)?1:0; \
  8463. sd->status.skill[(idx)].flag = (x)?SKILL_FLAG_TEMPORARY:SKILL_FLAG_PERMANENT;
  8464. int val = atoi(message);
  8465. bool need_skill = (pc_checkskill(sd, MC_PUSHCART) == 0);
  8466. uint16 sk_idx = 0;
  8467. if( !message || !*message || val < 0 || val > MAX_CARTS ) {
  8468. sprintf(atcmd_output, msg_txt(sd,1390),command,MAX_CARTS); // Unknown Cart (usage: %s <0-%d>).
  8469. clif_displaymessage(fd, atcmd_output);
  8470. return -1;
  8471. }
  8472. if( val == 0 && !pc_iscarton(sd) ) {
  8473. clif_displaymessage(fd, msg_txt(sd,1391)); // You do not possess a cart to be removed
  8474. return -1;
  8475. }
  8476. if (!(sk_idx = skill_get_index(MC_PUSHCART)))
  8477. return -1;
  8478. if( need_skill ) {
  8479. MC_CART_MDFY(sk_idx,1);
  8480. }
  8481. if( !pc_setcart(sd, val) ) {
  8482. if( need_skill ) {
  8483. MC_CART_MDFY(sk_idx,0);
  8484. }
  8485. return -1;/* @cart failed */
  8486. }
  8487. if( need_skill ) {
  8488. MC_CART_MDFY(sk_idx,0);
  8489. }
  8490. clif_displaymessage(fd, msg_txt(sd,1392)); // Cart Added
  8491. return 0;
  8492. #undef MC_CART_MDFY
  8493. }
  8494. /* Channel System [Ind] */
  8495. ACMD_FUNC(join){
  8496. char chname[CHAN_NAME_LENGTH], pass[CHAN_NAME_LENGTH];
  8497. if( !message || !*message || sscanf(message, "%19s %19s", chname, pass) < 1 ) {
  8498. sprintf(atcmd_output, msg_txt(sd,1399),command); // Unknown channel (usage: %s <#channel_name>).
  8499. clif_displaymessage(fd, atcmd_output);
  8500. return -1;
  8501. }
  8502. return channel_pcjoin(sd, chname, pass);
  8503. }
  8504. /*
  8505. * Display available option for @channel command
  8506. * @command : the name of used command (for alias case)
  8507. */
  8508. static inline void atcmd_channel_help(map_session_data *sd, const char *command)
  8509. {
  8510. int fd = sd->fd;
  8511. bool can_delete = pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN);
  8512. bool can_create = (can_delete || channel_config.private_channel.allow);
  8513. clif_displaymessage(fd, msg_txt(sd,1414));// ---- Available options:
  8514. //option create
  8515. if( can_create ) {
  8516. sprintf(atcmd_output, msg_txt(sd,1415),command);// * %s create <#channel_name> <channel_password>
  8517. clif_displaymessage(fd, atcmd_output);
  8518. clif_displaymessage(fd, msg_txt(sd,1416));// -- Creates a new channel.
  8519. }
  8520. //option delete
  8521. if(can_delete){
  8522. sprintf(atcmd_output, msg_txt(sd,1469),command);// * %s delete <#channel_name>
  8523. clif_displaymessage(fd, atcmd_output);
  8524. clif_displaymessage(fd, msg_txt(sd,1470)); // -- Destroys the specified channel.
  8525. }
  8526. //option list
  8527. sprintf(atcmd_output, msg_txt(sd,1417),command);// * %s list
  8528. clif_displaymessage(fd, atcmd_output);
  8529. clif_displaymessage(fd, msg_txt(sd,1418));// -- Lists all public channels.
  8530. sprintf(atcmd_output, msg_txt(sd,1471),command);// * %s list mine
  8531. clif_displaymessage(fd, atcmd_output);
  8532. clif_displaymessage(fd, msg_txt(sd,1472));// -- Lists all channels you have joined.
  8533. if( can_create ) {
  8534. sprintf(atcmd_output, msg_txt(sd,1419),command);// * %s list colors
  8535. clif_displaymessage(fd, atcmd_output);
  8536. clif_displaymessage(fd, msg_txt(sd,1420));// -- Lists all available colors for custom channels.
  8537. }
  8538. //option setcolor
  8539. if(can_create){
  8540. sprintf(atcmd_output, msg_txt(sd,1421),command);// * %s setcolor <#channel_name> <color_name>
  8541. clif_displaymessage(fd, atcmd_output);
  8542. clif_displaymessage(fd, msg_txt(sd,1422));// -- Changes channel text to the specified color (channel owners only).
  8543. }
  8544. //option join
  8545. sprintf(atcmd_output, msg_txt(sd,1473),command);// * %s join <#channel_name> <channel_password>
  8546. clif_displaymessage(fd, atcmd_output);
  8547. clif_displaymessage(fd, msg_txt(sd,1474));// -- Joins the specified channel.
  8548. //option leave
  8549. sprintf(atcmd_output, msg_txt(sd,1423),command);// * %s leave <#channel_name>
  8550. clif_displaymessage(fd, atcmd_output);
  8551. clif_displaymessage(fd, msg_txt(sd,1424));// -- Leaves the specified channel.
  8552. //option bindto
  8553. sprintf(atcmd_output, msg_txt(sd,1427),command);// * %s bindto <#channel_name>
  8554. clif_displaymessage(fd, atcmd_output);
  8555. clif_displaymessage(fd, msg_txt(sd,1428));// -- Binds your global chat to the specified channel, sending all global messages to that channel.
  8556. //option unbind
  8557. sprintf(atcmd_output, msg_txt(sd,1429),command);// * %s unbind
  8558. clif_displaymessage(fd, atcmd_output);
  8559. clif_displaymessage(fd, msg_txt(sd,1430));// -- Unbinds your global chat from the attached channel, if any.
  8560. //option ban/unban/banlist
  8561. if( can_create ) {
  8562. sprintf(atcmd_output, msg_txt(sd,1456),command);// * %s ban <#channel_name> <player>
  8563. clif_displaymessage(fd, atcmd_output);
  8564. clif_displaymessage(fd, msg_txt(sd,1457));// -- Bans the specified player from the channel.
  8565. sprintf(atcmd_output, msg_txt(sd,1458),command);// * %s banlist <#channel_name>
  8566. clif_displaymessage(fd, atcmd_output);
  8567. clif_displaymessage(fd, msg_txt(sd,1459));// -- Lists all players banned from the specified channel.
  8568. sprintf(atcmd_output, msg_txt(sd,1460),command);// * %s unban <#channel_name> <player>
  8569. clif_displaymessage(fd, atcmd_output);
  8570. clif_displaymessage(fd, msg_txt(sd,1461));// -- Unbans the specified player from the channel.
  8571. sprintf(atcmd_output, msg_txt(sd,1467),command);// * %s unbanall <#channel_name>
  8572. clif_displaymessage(fd, atcmd_output);
  8573. clif_displaymessage(fd, msg_txt(sd,1468));// -- Clears all bans from the specified channel.
  8574. }
  8575. //option setopt
  8576. if(can_create){
  8577. sprintf(atcmd_output, msg_txt(sd,1462),command);// * %s setopt <#channel_name> <option> <value>
  8578. clif_displaymessage(fd, atcmd_output);
  8579. clif_displaymessage(fd, msg_txt(sd,1463));// -- Sets an option and value for the specified channel.
  8580. }
  8581. sprintf(atcmd_output, msg_txt(sd,1404),command); // %s failed.
  8582. clif_displaymessage(fd, atcmd_output);
  8583. }
  8584. ACMD_FUNC(channel) {
  8585. char key[NAME_LENGTH], sub1[CHAN_NAME_LENGTH], sub2[64];
  8586. sub1[0] = sub2[0] = '\0';
  8587. if( !message || !*message || sscanf(message, "%23s %19s %63[^\n]", key, sub1, sub2) < 1 ) {
  8588. atcmd_channel_help(sd,command);
  8589. return 0;
  8590. }
  8591. if( strcmpi(key,"delete") == 0 && pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) {
  8592. return channel_pcdelete(sd,sub1);
  8593. } else if ( strcmpi(key,"list") == 0 ) {
  8594. return channel_display_list(sd,sub1);
  8595. } else if ( strcmpi(key,"setcolor") == 0 ) {
  8596. return channel_pccolor(sd, sub1, sub2);
  8597. } else if ( strcmpi(key,"join") == 0 ) {
  8598. return channel_pcjoin(sd, sub1, sub2);
  8599. }else if ( strcmpi(key,"leave") == 0 ) {
  8600. return channel_pcleave(sd, sub1);
  8601. } else if ( strcmpi(key,"bindto") == 0 ) {
  8602. return channel_pcbind(sd, sub1);
  8603. } else if ( strcmpi(key,"unbind") == 0 ) {
  8604. return channel_pcunbind(sd);
  8605. } else if ( strcmpi(key,"ban") == 0 ) {
  8606. return channel_pcban(sd,sub1,sub2,0);
  8607. } else if ( strcmpi(key,"kick") == 0 ) {
  8608. return channel_pckick(sd,sub1,sub2);
  8609. } else if ( strcmpi(key,"banlist") == 0 ) {
  8610. return channel_pcban(sd,sub1,nullptr,3);
  8611. } else if ( strcmpi(key,"unban") == 0 ) {
  8612. return channel_pcban(sd,sub1,sub2,1);
  8613. } else if ( strcmpi(key,"unbanall") == 0 ) {
  8614. return channel_pcban(sd,sub1,nullptr,2);
  8615. } else {
  8616. char sub3[CHAN_NAME_LENGTH], sub4[CHAN_NAME_LENGTH];
  8617. sub3[0] = sub4[0] = '\0';
  8618. sscanf(sub2, "%19s %19s", sub3, sub4);
  8619. if( strcmpi(key,"create") == 0 && ( channel_config.private_channel.allow || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) ) {
  8620. if (sub4[0] != '\0') {
  8621. clif_displaymessage(fd, msg_txt(sd, 1408)); // Channel password may not contain spaces.
  8622. return -1;
  8623. }
  8624. return channel_pccreate(sd,sub1,sub3);
  8625. } else if ( strcmpi(key,"setopt") == 0 ) {
  8626. return channel_pcsetopt(sd,sub1,sub3,sub4);
  8627. }
  8628. atcmd_channel_help(sd,command);
  8629. }
  8630. return 0;
  8631. }
  8632. ACMD_FUNC(fontcolor)
  8633. {
  8634. if( !message || !*message ) {
  8635. channel_display_list(sd,"colors");
  8636. return -1;
  8637. }
  8638. if( strcmpi(message,"Normal") == 0 ) {
  8639. sd->fontcolor = 0;
  8640. } else {
  8641. unsigned char k;
  8642. ARR_FIND(0,channel_config.colors_count,k,( strcmpi(message,channel_config.colors_name[k]) == 0 ));
  8643. if( k == channel_config.colors_count ) {
  8644. sprintf(atcmd_output, msg_txt(sd,1411), message);// Unknown color '%s'.
  8645. clif_displaymessage(fd, atcmd_output);
  8646. return -1;
  8647. }
  8648. sd->fontcolor = k;
  8649. }
  8650. sprintf(atcmd_output, msg_txt(sd,1454), message);// Color set to '%s'.
  8651. clif_displaymessage(fd, atcmd_output);
  8652. return 0;
  8653. }
  8654. ACMD_FUNC(langtype)
  8655. {
  8656. char langstr[8];
  8657. int i=0, fail=0;
  8658. memset(langstr, '\0', sizeof(langstr));
  8659. if(sscanf(message, "%3s", langstr) >= 1){
  8660. int lang=0;
  8661. lang = msg_langstr2langtype(langstr); //Switch langstr to associated langtype
  8662. if( msg_checklangtype(lang,false) == 1 ){ //Verify it's enabled and set it
  8663. char output[100];
  8664. pc_setaccountreg(sd, add_str(LANGTYPE_VAR), lang); //For login/char
  8665. sd->langtype = lang;
  8666. sprintf(output,msg_txt(sd,461),msg_langtype2langstr(lang)); // Language is now set to %s.
  8667. clif_displaymessage(fd,output);
  8668. return 0;
  8669. } else if (lang != -1) { //defined langage but failed check
  8670. clif_displaymessage(fd,msg_txt(sd,462)); // This langage is currently disabled.
  8671. return -1;
  8672. }
  8673. }
  8674. //wrong or no entry
  8675. clif_displaymessage(fd,msg_txt(sd,460)); // Please enter a valid language (usage: @langtype <language>).
  8676. clif_displaymessage(fd,msg_txt(sd,464)); // ---- Available languages:
  8677. while(fail != -1){ //out of range
  8678. fail = msg_checklangtype(i,false);
  8679. if(fail == 1)
  8680. clif_displaymessage(fd,msg_langtype2langstr(i));
  8681. i++;
  8682. }
  8683. return -1;
  8684. }
  8685. #ifdef VIP_ENABLE
  8686. ACMD_FUNC(vip) {
  8687. map_session_data* pl_sd = nullptr;;
  8688. char * modif_p;
  8689. int32 vipdifftime = 0;
  8690. time_t now=time(nullptr);
  8691. nullpo_retr(-1, sd);
  8692. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8693. if (!message || !*message || sscanf(message, "%255s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  8694. clif_displaymessage(fd, msg_txt(sd,700)); //Usage: @vip <timef> <character name>
  8695. return -1;
  8696. }
  8697. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  8698. modif_p = atcmd_output;
  8699. vipdifftime = (int32)solve_time(modif_p);
  8700. if (vipdifftime == 0) {
  8701. clif_displaymessage(fd, msg_txt(sd,701)); // Invalid time for vip command.
  8702. clif_displaymessage(fd, msg_txt(sd,702)); // Time parameter format is +/-<value> to alter. y/a = Year, m = Month, d/j = Day, h = Hour, n/mn = Minute, s = Second.
  8703. return -1;
  8704. }
  8705. if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  8706. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  8707. return -1;
  8708. }
  8709. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  8710. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  8711. return -1;
  8712. }
  8713. if(pl_sd->vip.time==0) pl_sd->vip.time=now;
  8714. pl_sd->vip.time += vipdifftime; //increase or reduce VIP duration
  8715. if (pl_sd->vip.time <= now) {
  8716. clif_displaymessage(pl_sd->fd, msg_txt(pl_sd,703)); // GM has removed your VIP time.
  8717. clif_displaymessage(fd, msg_txt(sd,704)); // Player is no longer VIP.
  8718. } else {
  8719. int year,month,day,hour,minute,second;
  8720. char timestr[21];
  8721. split_time((int)(pl_sd->vip.time-now),&year,&month,&day,&hour,&minute,&second);
  8722. sprintf(atcmd_output,msg_txt(pl_sd,705),year,month,day,hour,minute); // Your VIP status is valid for %d years, %d months, %d days, %d hours and %d minutes.
  8723. clif_displaymessage(pl_sd->fd,atcmd_output);
  8724. timestamp2string(timestr,20,pl_sd->vip.time,"%Y-%m-%d %H:%M");
  8725. sprintf(atcmd_output,msg_txt(pl_sd,707),timestr); // You are VIP until : %s
  8726. clif_displaymessage(pl_sd->fd,atcmd_output);
  8727. if (pl_sd != sd) {
  8728. sprintf(atcmd_output,msg_txt(sd,706),pl_sd->status.name,year,month,day,hour,minute); // Player '%s' is now VIP for %d years, %d months, %d days, %d hours and %d minutes.
  8729. clif_displaymessage(fd,atcmd_output);
  8730. sprintf(atcmd_output,msg_txt(sd,708),timestr); // The player is now VIP until : %s
  8731. clif_displaymessage(fd,atcmd_output);
  8732. }
  8733. }
  8734. chrif_req_login_operation(pl_sd->status.account_id, pl_sd->status.name, CHRIF_OP_LOGIN_VIP, vipdifftime, 7, 0);
  8735. return 0;
  8736. }
  8737. /** Enable/disable rate info */
  8738. ACMD_FUNC(showrate) {
  8739. nullpo_retr(-1,sd);
  8740. if (!sd->vip.disableshowrate) {
  8741. safestrncpy(atcmd_output,msg_txt(sd,718),CHAT_SIZE_MAX); //Personal rate information is not displayed now.
  8742. sd->vip.disableshowrate = 1;
  8743. } else {
  8744. safestrncpy(atcmd_output,msg_txt(sd,719),CHAT_SIZE_MAX); //Personal rate information will be shown.
  8745. sd->vip.disableshowrate = 0;
  8746. }
  8747. clif_displaymessage(fd,atcmd_output);
  8748. return 0;
  8749. }
  8750. #endif
  8751. ACMD_FUNC(fullstrip) {
  8752. int i;
  8753. TBL_PC *tsd;
  8754. nullpo_retr(-1,sd);
  8755. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  8756. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  8757. clif_displaymessage(fd, msg_txt(sd,349)); // Please enter a player name (usage: @fullstrip/@warpto/@goto <char name/ID>).
  8758. return -1;
  8759. }
  8760. if((tsd=map_nick2sd(atcmd_player_name,false)) == nullptr && (tsd=map_id2sd(atoi(atcmd_player_name))) == nullptr){
  8761. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  8762. return -1;
  8763. }
  8764. for( i = 0; i < EQI_MAX; i++ ) {
  8765. if( tsd->equip_index[ i ] >= 0 )
  8766. pc_unequipitem( tsd , tsd->equip_index[ i ] , 2 );
  8767. }
  8768. return 0;
  8769. }
  8770. ACMD_FUNC(changedress){
  8771. sc_type name2id[] = {
  8772. SC_WEDDING,
  8773. SC_XMAS,
  8774. SC_SUMMER,
  8775. SC_DRESSUP,
  8776. SC_HANBOK,
  8777. SC_OKTOBERFEST
  8778. };
  8779. for( sc_type type : name2id ) {
  8780. if( sd->sc.getSCE(type) ) {
  8781. status_change_end( &sd->bl, type );
  8782. // You should only be able to have one - so we cancel here
  8783. break;
  8784. }
  8785. }
  8786. return 0;
  8787. }
  8788. ACMD_FUNC(costume) {
  8789. const char* names[] = {
  8790. "Wedding",
  8791. "Xmas",
  8792. "Summer",
  8793. "Summer2",
  8794. "Hanbok",
  8795. "Oktoberfest"
  8796. };
  8797. const int name2id[] = {
  8798. SC_WEDDING,
  8799. SC_XMAS,
  8800. SC_SUMMER,
  8801. SC_DRESSUP,
  8802. SC_HANBOK,
  8803. SC_OKTOBERFEST
  8804. };
  8805. unsigned short k = 0, len = ARRAYLENGTH(names);
  8806. if( !message || !*message ) {
  8807. for( k = 0; k < len; k++ ) {
  8808. if( sd->sc.getSCE(name2id[k]) ) {
  8809. sprintf(atcmd_output, msg_txt(sd, 727), names[k]); // '%s' Costume removed.
  8810. clif_displaymessage(sd->fd, atcmd_output);
  8811. status_change_end(&sd->bl, (sc_type)name2id[k]);
  8812. return 0;
  8813. }
  8814. }
  8815. clif_displaymessage(sd->fd, msg_txt(sd, 726)); // Available Costumes
  8816. for( k = 0; k < len; k++ ) {
  8817. sprintf(atcmd_output, msg_txt(sd, 725), names[k]); // -- %s
  8818. clif_displaymessage(sd->fd, atcmd_output);
  8819. }
  8820. return -1;
  8821. }
  8822. for( k = 0; k < len; k++ ) {
  8823. if( sd->sc.getSCE(name2id[k]) ) {
  8824. sprintf(atcmd_output, msg_txt(sd, 724), names[k]); // You're already wearing a(n) '%s' costume, type '@costume' to remove it.
  8825. clif_displaymessage(sd->fd, atcmd_output);
  8826. return -1;
  8827. }
  8828. }
  8829. for( k = 0; k < len; k++ )
  8830. if( strcmpi(message, names[k]) == 0 )
  8831. break;
  8832. if( k == len ) {
  8833. sprintf(atcmd_output, msg_txt(sd, 723), message); // '%s' is an unknown costume
  8834. clif_displaymessage(sd->fd, atcmd_output);
  8835. return -1;
  8836. }
  8837. sc_start(&sd->bl, &sd->bl, (sc_type)name2id[k], 100, name2id[k] == SC_DRESSUP ? 1 : 0, INFINITE_TICK);
  8838. return 0;
  8839. }
  8840. /**
  8841. * Clone other player's equipments
  8842. * Usage: @cloneequip <char name/ID>
  8843. * http://rathena.org/board/topic/95076-new-atcommands-suggestion/
  8844. * @author [Cydh], [Antares]
  8845. */
  8846. ACMD_FUNC(cloneequip) {
  8847. map_session_data *pl_sd;
  8848. nullpo_retr(-1, sd);
  8849. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  8850. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8851. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  8852. sprintf(atcmd_output, msg_txt(sd, 735), command); // Usage: %s <char name/ID>
  8853. clif_displaymessage(fd, atcmd_output);
  8854. return -1;
  8855. }
  8856. if (!(pl_sd = map_nick2sd(atcmd_player_name, true)) && !(pl_sd = map_charid2sd(atoi(atcmd_player_name)))) {
  8857. clif_displaymessage(fd, msg_txt(sd, 3));
  8858. return -1;
  8859. }
  8860. if (sd == pl_sd) {
  8861. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8862. sprintf(atcmd_output, msg_txt(sd, 734), "equip"); // Cannot clone your own %.
  8863. clif_displaymessage(fd, atcmd_output);
  8864. return -1;
  8865. }
  8866. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) {
  8867. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8868. sprintf(atcmd_output, msg_txt(sd, 736), "equip"); // Cannot clone %s from this player.
  8869. clif_displaymessage(fd, atcmd_output);
  8870. return -1;
  8871. }
  8872. else {
  8873. int8 i;
  8874. for (i = 0; i < EQI_MAX; i++) {
  8875. short idx;
  8876. char flag = 0;
  8877. struct item tmp_item;
  8878. if ((idx = pl_sd->equip_index[i]) < 0)
  8879. continue;
  8880. if (i == EQI_AMMO)
  8881. continue;
  8882. if (pc_is_same_equip_index((enum equip_index) i, pl_sd->equip_index, idx))
  8883. continue;
  8884. tmp_item = pl_sd->inventory.u.items_inventory[idx];
  8885. if (itemdb_isspecial(tmp_item.card[0]))
  8886. memset(tmp_item.card, 0, sizeof(tmp_item.card));
  8887. tmp_item.bound = 0;
  8888. tmp_item.expire_time = 0;
  8889. tmp_item.unique_id = 0;
  8890. tmp_item.favorite = 0;
  8891. tmp_item.amount = 1;
  8892. if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  8893. clif_additem(sd, 0, 0, flag);
  8894. else
  8895. pc_equipitem(sd, sd->last_addeditem_index, itemdb_equip(tmp_item.nameid));
  8896. }
  8897. }
  8898. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8899. sprintf(atcmd_output, msg_txt(sd, 738), "equip"); // Clone '%s' is done.
  8900. clif_displaymessage(fd, atcmd_output);
  8901. return 0;
  8902. }
  8903. /**
  8904. * Clone other player's statuses/parameters using method same like ACMD_FUNC(param), doesn't use stat point
  8905. * Usage: @clonestat <char name/ID>
  8906. * http://rathena.org/board/topic/95076-new-atcommands-suggestion/
  8907. * @author [Cydh], [Antares]
  8908. */
  8909. ACMD_FUNC(clonestat) {
  8910. map_session_data *pl_sd;
  8911. nullpo_retr(-1, sd);
  8912. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  8913. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8914. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  8915. sprintf(atcmd_output, msg_txt(sd, 735), command); // Usage: %s <char name/ID>
  8916. clif_displaymessage(fd, atcmd_output);
  8917. return -1;
  8918. }
  8919. if (!(pl_sd = map_nick2sd(atcmd_player_name, true)) && !(pl_sd = map_charid2sd(atoi(atcmd_player_name)))) {
  8920. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  8921. return -1;
  8922. }
  8923. if (sd == pl_sd) {
  8924. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8925. sprintf(atcmd_output, msg_txt(sd, 734), "status"); // Cannot clone your own %.
  8926. clif_displaymessage(fd, atcmd_output);
  8927. return -1;
  8928. }
  8929. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) {
  8930. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8931. sprintf(atcmd_output, msg_txt(sd, 736), "status"); // Cannot clone %s from this player.
  8932. clif_displaymessage(fd, atcmd_output);
  8933. return -1;
  8934. }
  8935. else {
  8936. uint8 i;
  8937. short max_status[PARAM_MAX] = {};
  8938. pc_resetstate(sd);
  8939. if (pc_has_permission(sd, PC_PERM_BYPASS_STAT_ONCLONE)) {
  8940. for (i = PARAM_STR; i < PARAM_MAX; i++) {
  8941. if (i >= PARAM_POW && !(sd->class_ & JOBL_FOURTH))
  8942. continue;
  8943. max_status[i] = SHRT_MAX;
  8944. }
  8945. } else {
  8946. for (i = PARAM_STR; i < PARAM_MAX; i++) {
  8947. if (i >= PARAM_POW && sd->class_ & JOBL_FOURTH)
  8948. continue;
  8949. max_status[i] = pc_maxparameter(sd, static_cast<e_params>(i));
  8950. }
  8951. }
  8952. #define clonestat_check(cmd,stat)\
  8953. {\
  8954. memset(atcmd_output, '\0', sizeof(atcmd_output));\
  8955. if (pl_sd->status.cmd > max_status[(stat)]) {\
  8956. sprintf(atcmd_output, msg_txt(sd, 737), #cmd, pl_sd->status.cmd, max_status[(stat)]);\
  8957. clif_displaymessage(fd, atcmd_output);\
  8958. sd->status.cmd = max_status[(stat)];\
  8959. }\
  8960. else\
  8961. sd->status.cmd = pl_sd->status.cmd;\
  8962. }
  8963. clonestat_check(str, PARAM_STR);
  8964. clonestat_check(agi, PARAM_AGI);
  8965. clonestat_check(vit, PARAM_VIT);
  8966. clonestat_check(int_, PARAM_INT);
  8967. clonestat_check(dex, PARAM_DEX);
  8968. clonestat_check(luk, PARAM_LUK);
  8969. for (i = PARAM_STR; i < PARAM_POW; i++) {
  8970. clif_updatestatus(*sd, static_cast<_sp>( SP_STR + i ) );
  8971. clif_updatestatus(*sd, static_cast<_sp>( SP_USTR + i ) );
  8972. }
  8973. if (sd->class_ & JOBL_FOURTH) {
  8974. clonestat_check(pow, PARAM_POW);
  8975. clonestat_check(sta, PARAM_STA);
  8976. clonestat_check(wis, PARAM_WIS);
  8977. clonestat_check(spl, PARAM_SPL);
  8978. clonestat_check(con, PARAM_CON);
  8979. clonestat_check(crt, PARAM_CRT);
  8980. for (i = PARAM_POW; i < PARAM_MAX; i++) {
  8981. clif_updatestatus(*sd, static_cast<_sp>( SP_POW + i - PARAM_POW ) );
  8982. clif_updatestatus(*sd, static_cast<_sp>( SP_UPOW + i - PARAM_POW ) );
  8983. }
  8984. }
  8985. status_calc_pc(sd, SCO_FORCE);
  8986. }
  8987. memset(atcmd_output, '\0', sizeof(atcmd_output));
  8988. sprintf(atcmd_output, msg_txt(sd, 738), "status"); // Clone '%s' is done.
  8989. clif_displaymessage(fd, atcmd_output);
  8990. #undef clonestat_check
  8991. return 0;
  8992. }
  8993. /**
  8994. * Adopt a character.
  8995. * Usage: @adopt <char name>
  8996. * https://rathena.org/board/topic/104014-suggestion-add-adopt-or-etc/
  8997. */
  8998. ACMD_FUNC(adopt)
  8999. {
  9000. TBL_PC *b_sd;
  9001. enum adopt_responses response;
  9002. nullpo_retr(-1, sd);
  9003. memset(atcmd_output, '\0', sizeof(atcmd_output));
  9004. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  9005. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  9006. sprintf(atcmd_output, msg_txt(sd, 435), command); // Please enter a player name (usage: %s <char name>).
  9007. clif_displaymessage(fd, atcmd_output);
  9008. return -1;
  9009. }
  9010. if ((b_sd = map_nick2sd(atcmd_player_name,false)) == nullptr) {
  9011. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  9012. return -1;
  9013. }
  9014. response = pc_try_adopt(sd, map_charid2sd(sd->status.partner_id), b_sd);
  9015. if (response == ADOPT_ALLOWED) {
  9016. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  9017. b_sd->adopt_invite = sd->status.account_id;
  9018. clif_Adopt_request(b_sd, sd, p_sd->status.account_id);
  9019. return 0;
  9020. }
  9021. if (response < ADOPT_MORE_CHILDREN) // No displaymessage for client-type responses
  9022. clif_displaymessage(fd, msg_txt(sd, 744 + response - 1));
  9023. return -1;
  9024. }
  9025. /**
  9026. * Opens the limited sale window.
  9027. * Usage: @limitedsale or client command /limitedsale on supported clients
  9028. */
  9029. ACMD_FUNC(limitedsale){
  9030. nullpo_retr(-1, sd);
  9031. clif_sale_open(sd);
  9032. return 0;
  9033. }
  9034. /**
  9035. * Displays camera information from the client.
  9036. * Usage: @camerainfo or client command /viewpointvalue or /setcamera on supported clients
  9037. */
  9038. ACMD_FUNC(camerainfo){
  9039. nullpo_retr(-1, sd);
  9040. if( message == nullptr || message[0] == '\0' ){
  9041. clif_camerainfo( sd, true );
  9042. return 0;
  9043. }
  9044. float range = 0;
  9045. float rotation = 0;
  9046. float latitude = 0;
  9047. if( sscanf( message, "%f %f %f", &range, &rotation, &latitude ) < 3 ){
  9048. clif_displaymessage( fd, msg_txt( sd, 793 ) ); // Usage @camerainfo range rotation latitude
  9049. return -1;
  9050. }
  9051. clif_camerainfo( sd, false, range, rotation, latitude );
  9052. return 0;
  9053. }
  9054. ACMD_FUNC(resurrect) {
  9055. nullpo_retr(-1, sd);
  9056. if (!pc_revive_item(sd))
  9057. return -1;
  9058. return 0;
  9059. }
  9060. ACMD_FUNC(quest) {
  9061. uint8 i;
  9062. int quest_id = 0;
  9063. nullpo_retr(-1, sd);
  9064. memset(atcmd_output, '\0', sizeof(atcmd_output));
  9065. if (!message || !*message || sscanf(message, "%11d", &quest_id) < 1 || quest_id == 0) {
  9066. sprintf(atcmd_output, msg_txt(sd,1505), command); // Usage: %s <quest ID>
  9067. clif_displaymessage(fd, atcmd_output);
  9068. return -1;
  9069. }
  9070. if (!quest_search(quest_id)) {
  9071. sprintf(atcmd_output, msg_txt(sd,1506), quest_id); // Quest %d not found in DB.
  9072. clif_displaymessage(fd, atcmd_output);
  9073. return -1;
  9074. }
  9075. const char* type[] = { "setquest", "erasequest", "completequest", "checkquest" };
  9076. ARR_FIND( 0, ARRAYLENGTH(type), i, strcmpi(command+1, type[i]) == 0 );
  9077. switch(i) {
  9078. case 0:
  9079. if (quest_check(sd, quest_id, HAVEQUEST) >= 0) {
  9080. sprintf(atcmd_output, msg_txt(sd,1507), quest_id); // Character already has quest %d.
  9081. clif_displaymessage(fd, atcmd_output);
  9082. return -1;
  9083. }
  9084. quest_add(sd, quest_id);
  9085. pc_show_questinfo(sd);
  9086. break;
  9087. case 1:
  9088. if (quest_check(sd, quest_id, HAVEQUEST) < 0) {
  9089. sprintf(atcmd_output, msg_txt(sd,1508), quest_id); // Character doesn't have quest %d.
  9090. clif_displaymessage(fd, atcmd_output);
  9091. return -1;
  9092. }
  9093. quest_delete(sd, quest_id);
  9094. pc_show_questinfo(sd);
  9095. break;
  9096. case 2:
  9097. if (quest_check(sd, quest_id, HAVEQUEST) < 0)
  9098. quest_add(sd, quest_id);
  9099. if (quest_check(sd, quest_id, HAVEQUEST) < 2)
  9100. quest_update_status(sd, quest_id, Q_COMPLETE);
  9101. pc_show_questinfo(sd);
  9102. break;
  9103. case 3:
  9104. sprintf(atcmd_output, msg_txt(sd,1509), quest_id); // Checkquest value for quest %d
  9105. clif_displaymessage(fd, atcmd_output);
  9106. sprintf(atcmd_output, msg_txt(sd,1510), quest_check(sd, quest_id, HAVEQUEST)); // HAVEQUEST : %d
  9107. clif_displaymessage(fd, atcmd_output);
  9108. sprintf(atcmd_output, msg_txt(sd,1511), quest_check(sd, quest_id, HUNTING)); // HUNTING : %d
  9109. clif_displaymessage(fd, atcmd_output);
  9110. sprintf(atcmd_output, msg_txt(sd,1512), quest_check(sd, quest_id, PLAYTIME)); // PLAYTIME : %d
  9111. clif_displaymessage(fd, atcmd_output);
  9112. break;
  9113. }
  9114. return 0;
  9115. }
  9116. /**
  9117. * Opens the refineUI
  9118. * Usage: @refineui
  9119. */
  9120. ACMD_FUNC(refineui)
  9121. {
  9122. nullpo_retr(-1, sd);
  9123. #if PACKETVER < 20161012
  9124. clif_displaymessage(fd, msg_txt(sd, 773)); // This command requires packet version 2016-10-12 or newer.
  9125. return -1;
  9126. #else
  9127. if( !battle_config.feature_refineui ){
  9128. clif_displaymessage(fd, msg_txt(sd, 774)); // This command is disabled via configuration.
  9129. return -1;
  9130. }
  9131. if( sd->state.refineui_open ){
  9132. clif_displaymessage(fd, msg_txt(sd, 775)); // You have already opened the refine UI.
  9133. return -1;
  9134. }
  9135. clif_refineui_open(sd);
  9136. return 0;
  9137. #endif
  9138. }
  9139. ACMD_FUNC( stylist ){
  9140. nullpo_retr(-1, sd);
  9141. #if PACKETVER < 20151104
  9142. clif_displaymessage( fd, msg_txt( sd, 798 ) ); // This command requires packet version 2015-11-04 or newer.
  9143. return -1;
  9144. #else
  9145. if( !battle_config.feature_stylist ){
  9146. clif_displaymessage( fd, msg_txt( sd, 774 ) ); // This command is disabled via configuration.
  9147. return -1;
  9148. }
  9149. if( sd->state.stylist_open ){
  9150. clif_displaymessage( fd, msg_txt( sd, 799 ) ); // You have already opened the stylist UI.
  9151. return -1;
  9152. }
  9153. clif_ui_open( *sd, OUT_UI_STYLIST, 0 );
  9154. return 0;
  9155. #endif
  9156. }
  9157. /**
  9158. * Add fame point(s) to a player
  9159. * Usage: @addfame <amount>
  9160. */
  9161. ACMD_FUNC(addfame)
  9162. {
  9163. nullpo_retr(-1, sd);
  9164. int famepoint = 0;
  9165. memset(atcmd_output, '\0', sizeof(atcmd_output));
  9166. if (!message || !*message || sscanf(message, "%11d", &famepoint) < 1 || famepoint == 0) {
  9167. sprintf(atcmd_output, msg_txt(sd, 1516), command); // Usage: %s <fame points>.
  9168. clif_displaymessage(fd, atcmd_output);
  9169. return -1;
  9170. }
  9171. if (!pc_addfame(*sd, famepoint)) {
  9172. sprintf(atcmd_output, msg_txt(sd, 1517), job_name(sd->status.class_)); // Cannot add fame to class '%s'.
  9173. clif_displaymessage(fd, atcmd_output);
  9174. return -1;
  9175. }
  9176. sprintf(atcmd_output, msg_txt(sd, 1518), famepoint, sd->status.name); // %d points were added to '%s'.
  9177. clif_displaymessage(fd, atcmd_output);
  9178. return 0;
  9179. }
  9180. /**
  9181. * Opens the enchantgrade UI
  9182. * Usage: @enchantgradeui
  9183. */
  9184. ACMD_FUNC( enchantgradeui ){
  9185. nullpo_retr( -1, sd );
  9186. #if !( PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724 )
  9187. sprintf( atcmd_output, msg_txt( sd, 798 ), "2020-07-24" ); // This command requires packet version %s or newer.
  9188. clif_displaymessage( fd, atcmd_output );
  9189. return -1;
  9190. #else
  9191. clif_ui_open( *sd, OUT_UI_ENCHANTGRADE, 0 );
  9192. return 0;
  9193. #endif
  9194. }
  9195. ACMD_FUNC( roulette ){
  9196. nullpo_retr( -1, sd );
  9197. #if PACKETVER < 20141022
  9198. sprintf( atcmd_output, msg_txt( sd, 798 ), "2014-10-22" ); // This command requires packet version %s or newer.
  9199. clif_displaymessage( fd, atcmd_output );
  9200. return -1;
  9201. #else
  9202. if( !battle_config.feature_roulette ){
  9203. clif_displaymessage( fd, msg_txt( sd, 1497 ) ); // Roulette is disabled
  9204. return -1;
  9205. }
  9206. clif_roulette_open( sd );
  9207. return 0;
  9208. #endif
  9209. }
  9210. /**
  9211. * Replaces a card ID in an equip
  9212. * Usage: @setcard <equip position> <slot> <card_id>
  9213. */
  9214. ACMD_FUNC(setcard)
  9215. {
  9216. nullpo_retr(-1, sd);
  9217. int position = 0, slot, card_id;
  9218. if (!message || !*message || sscanf(message, "%11d %11d %11d", &position, &slot, &card_id) < 3) {
  9219. memset(atcmd_output, '\0', sizeof(atcmd_output));
  9220. clif_displaymessage(fd, msg_txt(sd,1527)); // Please enter the position, the slot number and the card ID (usage: @setcard <equip position> <slot> <card_id>).
  9221. sprintf(atcmd_output, msg_txt(sd,997), EQP_HEAD_LOW); // %d: Lower Headgear
  9222. clif_displaymessage(fd, atcmd_output);
  9223. sprintf(atcmd_output, msg_txt(sd,998), EQP_HAND_R); // %d: Right Hand
  9224. clif_displaymessage(fd, atcmd_output);
  9225. sprintf(atcmd_output, msg_txt(sd,999), EQP_GARMENT); // %d: Garment
  9226. clif_displaymessage(fd, atcmd_output);
  9227. sprintf(atcmd_output, msg_txt(sd,1000), EQP_ACC_L); // %d: Left Accessory
  9228. clif_displaymessage(fd, atcmd_output);
  9229. sprintf(atcmd_output, msg_txt(sd,1001), EQP_ARMOR); // %d: Body Armor
  9230. clif_displaymessage(fd, atcmd_output);
  9231. sprintf(atcmd_output, msg_txt(sd,1002), EQP_HAND_L); // %d: Left Hand
  9232. clif_displaymessage(fd, atcmd_output);
  9233. sprintf(atcmd_output, msg_txt(sd,1003), EQP_SHOES); // %d: Shoes
  9234. clif_displaymessage(fd, atcmd_output);
  9235. sprintf(atcmd_output, msg_txt(sd,1004), EQP_ACC_R); // %d: Right Accessory
  9236. clif_displaymessage(fd, atcmd_output);
  9237. sprintf(atcmd_output, msg_txt(sd,1005), EQP_HEAD_TOP); // %d: Top Headgear
  9238. clif_displaymessage(fd, atcmd_output);
  9239. sprintf(atcmd_output, msg_txt(sd,1006), EQP_HEAD_MID); // %d: Mid Headgear
  9240. return -1;
  9241. }
  9242. if (position < EQP_HEAD_LOW || position > EQP_HEAD_MID) {
  9243. clif_displaymessage(fd, msg_txt(sd,1531)); // Invalid position.
  9244. return -1;
  9245. }
  9246. if (slot < 0 || slot >= MAX_SLOTS) {
  9247. clif_displaymessage(fd, msg_txt(sd,1532)); // Invalid slot number.
  9248. return -1;
  9249. }
  9250. if (card_id != 0) {
  9251. std::shared_ptr<item_data> item_data = item_db.find( card_id );
  9252. if (item_data == nullptr) {
  9253. clif_displaymessage(fd, msg_txt(sd,1530)); // Invalid card ID.
  9254. return -1;
  9255. }
  9256. if (item_data->type != IT_CARD) {
  9257. clif_displaymessage(fd, msg_txt(sd,1529)); // The item type must be a card or enchant.
  9258. return -1;
  9259. }
  9260. }
  9261. int16 i = pc_checkequip(sd, position);
  9262. if (i < 0) {
  9263. clif_displaymessage(fd, msg_txt(sd,1528)); // You are not wearing any equipment in this position.
  9264. return -1;
  9265. }
  9266. int current_position = sd->inventory.u.items_inventory[i].equip;
  9267. pc_unequipitem(sd, i, 3);
  9268. log_pick_pc( sd, LOG_TYPE_COMMAND, -1, &sd->inventory.u.items_inventory[i] );
  9269. sd->inventory.u.items_inventory[i].card[slot] = card_id;
  9270. log_pick_pc( sd, LOG_TYPE_COMMAND, 1, &sd->inventory.u.items_inventory[i] );
  9271. clif_delitem( *sd, i, 1, 0 );
  9272. clif_additem(sd, i, 1, 0);
  9273. pc_equipitem(sd, i, current_position);
  9274. return 0;
  9275. }
  9276. #include <custom/atcommand.inc>
  9277. /**
  9278. * Fills the reference of available commands in atcommand DBMap
  9279. **/
  9280. #define ACMD_DEF(x) { #x, atcommand_ ## x, nullptr, nullptr, 0 }
  9281. #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x, nullptr, nullptr, 0 }
  9282. // Define with restriction
  9283. #define ACMD_DEFR(x, r) { #x, atcommand_ ## x, nullptr, nullptr, r }
  9284. #define ACMD_DEF2R(x2, x, r) { x2, atcommand_ ## x, nullptr, nullptr, r }
  9285. void atcommand_basecommands(void) {
  9286. /**
  9287. * Command reference list, place the base of your commands here
  9288. * TODO: List all commands that causing crash
  9289. **/
  9290. AtCommandInfo atcommand_base[] = {
  9291. #include <custom/atcommand_def.inc>
  9292. ACMD_DEF2R("warp", mapmove, ATCMD_NOCONSOLE),
  9293. ACMD_DEF(where),
  9294. ACMD_DEF(jumpto),
  9295. ACMD_DEF(jump),
  9296. ACMD_DEF(who),
  9297. ACMD_DEF2("who2", who),
  9298. ACMD_DEF2("who3", who),
  9299. ACMD_DEF2("whomap", who),
  9300. ACMD_DEF2("whomap2", who),
  9301. ACMD_DEF2("whomap3", who),
  9302. ACMD_DEF(whogm),
  9303. ACMD_DEF(save),
  9304. ACMD_DEF(load),
  9305. ACMD_DEF(speed),
  9306. ACMD_DEF(storage),
  9307. ACMD_DEF(guildstorage),
  9308. ACMD_DEF(option),
  9309. ACMD_DEF(hide), // + /hide
  9310. ACMD_DEFR(jobchange, ATCMD_NOCONSOLE),
  9311. ACMD_DEF(kill),
  9312. ACMD_DEF(alive),
  9313. ACMD_DEF(kami),
  9314. ACMD_DEF2("kamib", kami),
  9315. ACMD_DEF2("kamic", kami),
  9316. ACMD_DEF2("lkami", kami),
  9317. ACMD_DEF(heal),
  9318. ACMD_DEF(healap),
  9319. ACMD_DEF(item),
  9320. ACMD_DEF(item2),
  9321. ACMD_DEF2("itembound",item),
  9322. ACMD_DEF2("itembound2",item2),
  9323. ACMD_DEF(itemreset),
  9324. ACMD_DEF(clearstorage),
  9325. ACMD_DEF(cleargstorage),
  9326. ACMD_DEF(clearcart),
  9327. ACMD_DEF2R("blvl", baselevelup, ATCMD_NOCONSOLE),
  9328. ACMD_DEF2("jlvl", joblevelup),
  9329. ACMD_DEF(help),
  9330. ACMD_DEF(pvpoff),
  9331. ACMD_DEF(pvpon),
  9332. ACMD_DEF(gvgoff),
  9333. ACMD_DEF(gvgon),
  9334. ACMD_DEF(model),
  9335. ACMD_DEFR(go, ATCMD_NOCONSOLE),
  9336. ACMD_DEF(monster),
  9337. ACMD_DEF2("monstersmall", monster),
  9338. ACMD_DEF2("monsterbig", monster),
  9339. ACMD_DEF(killmonster),
  9340. ACMD_DEF2("killmonster2", killmonster),
  9341. ACMD_DEF(refine),
  9342. ACMD_DEF(grade),
  9343. ACMD_DEF(produce),
  9344. ACMD_DEF(memo),
  9345. ACMD_DEF(gat),
  9346. ACMD_DEF(displaystatus),
  9347. ACMD_DEF2("stpoint", statuspoint),
  9348. ACMD_DEF2("trpoint", traitpoint),
  9349. ACMD_DEF2("skpoint", skillpoint),
  9350. ACMD_DEF(zeny),
  9351. ACMD_DEF2("str", param),
  9352. ACMD_DEF2("agi", param),
  9353. ACMD_DEF2("vit", param),
  9354. ACMD_DEF2("int", param),
  9355. ACMD_DEF2("dex", param),
  9356. ACMD_DEF2("luk", param),
  9357. ACMD_DEF2("pow", param),
  9358. ACMD_DEF2("sta", param),
  9359. ACMD_DEF2("wis", param),
  9360. ACMD_DEF2("spl", param),
  9361. ACMD_DEF2("con", param),
  9362. ACMD_DEF2("crt", param),
  9363. ACMD_DEF2("glvl", guildlevelup),
  9364. ACMD_DEF(makeegg),
  9365. ACMD_DEF(hatch),
  9366. ACMD_DEF(petfriendly),
  9367. ACMD_DEF(pethungry),
  9368. ACMD_DEF(petrename),
  9369. ACMD_DEF(recall), // + /recall
  9370. ACMD_DEF(night),
  9371. ACMD_DEF(day),
  9372. ACMD_DEF(doom),
  9373. ACMD_DEF(doommap),
  9374. ACMD_DEF(raise),
  9375. ACMD_DEF(raisemap),
  9376. ACMD_DEFR(kick,ATCMD_NOAUTOTRADE), // + right click menu for GM "(name) force to quit"
  9377. ACMD_DEF(kickall),
  9378. ACMD_DEF(allskill),
  9379. ACMD_DEF(questskill),
  9380. ACMD_DEF(lostskill),
  9381. ACMD_DEF(spiritball),
  9382. ACMD_DEF(soulball),
  9383. ACMD_DEF(party),
  9384. ACMD_DEF(guild),
  9385. ACMD_DEF(breakguild),
  9386. ACMD_DEF(agitstart),
  9387. ACMD_DEF(agitend),
  9388. ACMD_DEF(mapexit),
  9389. ACMD_DEF(idsearch),
  9390. ACMD_DEF(broadcast), // + /b and /nb
  9391. ACMD_DEF(localbroadcast), // + /lb and /nlb
  9392. ACMD_DEF(recallall),
  9393. ACMD_DEFR(reload,ATCMD_NOSCRIPT),
  9394. ACMD_DEF2("reloaditemdb", reload),
  9395. ACMD_DEF2("reloadcashdb", reload),
  9396. ACMD_DEF2("reloadmobdb", reload),
  9397. ACMD_DEF2("reloadskilldb", reload),
  9398. ACMD_DEF2R("reloadscript", reload, ATCMD_NOSCRIPT),
  9399. ACMD_DEF2("reloadatcommand", reload),
  9400. ACMD_DEF2("reloadbattleconf", reload),
  9401. ACMD_DEF2("reloadstatusdb", reload),
  9402. ACMD_DEF2("reloadpcdb", reload),
  9403. ACMD_DEF2("reloadmotd", reload),
  9404. ACMD_DEF2("reloadquestdb", reload),
  9405. ACMD_DEF2("reloadmsgconf", reload),
  9406. ACMD_DEF2("reloadinstancedb", reload),
  9407. ACMD_DEF2("reloadachievementdb",reload),
  9408. ACMD_DEF2("reloadattendancedb",reload),
  9409. ACMD_DEF2("reloadbarterdb",reload),
  9410. ACMD_DEF(partysharelvl),
  9411. ACMD_DEF(mapinfo),
  9412. ACMD_DEF(dye),
  9413. ACMD_DEF2("hairstyle", hair_style),
  9414. ACMD_DEF2("haircolor", hair_color),
  9415. ACMD_DEF2("allstats", stat_all),
  9416. ACMD_DEF2("alltraits", trait_all),
  9417. ACMD_DEF2("block", char_block),
  9418. ACMD_DEF2("ban", char_ban),
  9419. ACMD_DEF2("unblock", char_unblock),
  9420. ACMD_DEF2("unban", char_unban),
  9421. ACMD_DEF2("charban", char_ban),
  9422. ACMD_DEF2("charunban", char_unban),
  9423. ACMD_DEF2("mount", mount_peco),
  9424. ACMD_DEF(guildspy),
  9425. ACMD_DEF(partyspy),
  9426. ACMD_DEF(clanspy),
  9427. ACMD_DEF(repairall),
  9428. ACMD_DEF(guildrecall),
  9429. ACMD_DEF(partyrecall),
  9430. ACMD_DEF(nuke),
  9431. ACMD_DEF(shownpc),
  9432. ACMD_DEF(hidenpc),
  9433. ACMD_DEF(loadnpc),
  9434. ACMD_DEF(unloadnpc),
  9435. ACMD_DEF(reloadnpcfile),
  9436. ACMD_DEF2("time", servertime),
  9437. ACMD_DEF(jail),
  9438. ACMD_DEF(unjail),
  9439. ACMD_DEF(jailfor),
  9440. ACMD_DEF(jailtime),
  9441. ACMD_DEF(disguise),
  9442. ACMD_DEF(undisguise),
  9443. ACMD_DEF(email),
  9444. ACMD_DEF(effect),
  9445. ACMD_DEF(follow),
  9446. ACMD_DEF(addwarp),
  9447. ACMD_DEF(skillon),
  9448. ACMD_DEF(skilloff),
  9449. ACMD_DEF(killer),
  9450. ACMD_DEF(npcmove),
  9451. ACMD_DEF(killable),
  9452. ACMD_DEF(dropall),
  9453. ACMD_DEF(stockall),
  9454. ACMD_DEF(storeall),
  9455. ACMD_DEF(skillid),
  9456. ACMD_DEF(useskill),
  9457. ACMD_DEF(displayskill),
  9458. ACMD_DEF(displayskillcast),
  9459. ACMD_DEF(displayskillunit),
  9460. ACMD_DEF(snow),
  9461. ACMD_DEF(sakura),
  9462. ACMD_DEF(clouds),
  9463. ACMD_DEF(clouds2),
  9464. ACMD_DEF(fog),
  9465. ACMD_DEF(fireworks),
  9466. ACMD_DEF(leaves),
  9467. ACMD_DEF(summon),
  9468. ACMD_DEF(adjgroup),
  9469. ACMD_DEF(trade),
  9470. ACMD_DEF(send),
  9471. ACMD_DEF(setbattleflag),
  9472. ACMD_DEF(unmute),
  9473. ACMD_DEF(clearweather),
  9474. ACMD_DEF(uptime),
  9475. ACMD_DEF(changesex),
  9476. ACMD_DEF(changecharsex),
  9477. ACMD_DEF(mute),
  9478. ACMD_DEF(refresh),
  9479. ACMD_DEF(refreshall),
  9480. ACMD_DEF(identify),
  9481. ACMD_DEF(identifyall),
  9482. ACMD_DEF(gmotd),
  9483. ACMD_DEF(misceffect),
  9484. ACMD_DEF(mobsearch),
  9485. ACMD_DEF(cleanmap),
  9486. ACMD_DEF(cleanarea),
  9487. ACMD_DEF(npctalk),
  9488. ACMD_DEF(pettalk),
  9489. ACMD_DEF(users),
  9490. ACMD_DEF(reset),
  9491. ACMD_DEF(skilltree),
  9492. ACMD_DEF(marry),
  9493. ACMD_DEF(divorce),
  9494. ACMD_DEF(sound),
  9495. ACMD_DEF(undisguiseall),
  9496. ACMD_DEF(disguiseall),
  9497. ACMD_DEF(changelook),
  9498. ACMD_DEF(autoloot),
  9499. ACMD_DEF2("alootid", autolootitem),
  9500. ACMD_DEF(autoloottype),
  9501. ACMD_DEF(mobinfo),
  9502. ACMD_DEF(exp),
  9503. ACMD_DEF(version),
  9504. ACMD_DEF(mutearea),
  9505. ACMD_DEF(rates),
  9506. ACMD_DEF(iteminfo),
  9507. ACMD_DEF(whodrops),
  9508. ACMD_DEF(whereis),
  9509. ACMD_DEF(mapflag),
  9510. ACMD_DEF(me),
  9511. ACMD_DEF(monsterignore),
  9512. ACMD_DEF(fakename),
  9513. ACMD_DEF(size),
  9514. ACMD_DEF(showexp),
  9515. ACMD_DEF(showzeny),
  9516. ACMD_DEF(showdelay),
  9517. ACMD_DEF(autotrade),
  9518. ACMD_DEF(changegm),
  9519. ACMD_DEF(changeleader),
  9520. ACMD_DEF(partyoption),
  9521. ACMD_DEF(invite),
  9522. ACMD_DEF(duel),
  9523. ACMD_DEF(leave),
  9524. ACMD_DEF(accept),
  9525. ACMD_DEF(reject),
  9526. ACMD_DEF(clone),
  9527. ACMD_DEF2("slaveclone", clone),
  9528. ACMD_DEF2("evilclone", clone),
  9529. ACMD_DEF(tonpc),
  9530. ACMD_DEF(commands),
  9531. ACMD_DEF(noask),
  9532. ACMD_DEF(request),
  9533. ACMD_DEF(homlevel),
  9534. ACMD_DEF(homevolution),
  9535. ACMD_DEF(hommutate),
  9536. ACMD_DEF(makehomun),
  9537. ACMD_DEF(homfriendly),
  9538. ACMD_DEF(homhungry),
  9539. ACMD_DEF(homtalk),
  9540. ACMD_DEF(hominfo),
  9541. ACMD_DEF(homstats),
  9542. ACMD_DEF(homshuffle),
  9543. ACMD_DEF(showmobs),
  9544. ACMD_DEF(feelreset),
  9545. ACMD_DEF(hatereset),
  9546. ACMD_DEF(auction),
  9547. ACMD_DEF(mail),
  9548. ACMD_DEF2("noks", ksprotection),
  9549. ACMD_DEF(allowks),
  9550. ACMD_DEF(cash),
  9551. ACMD_DEF2("points", cash),
  9552. ACMD_DEF(agitstart2),
  9553. ACMD_DEF(agitend2),
  9554. ACMD_DEF(resetskill),
  9555. ACMD_DEF(resetstat),
  9556. ACMD_DEF2("storagelist", itemlist),
  9557. ACMD_DEF2("cartlist", itemlist),
  9558. ACMD_DEF2("itemlist", itemlist),
  9559. ACMD_DEF(stats),
  9560. ACMD_DEF(delitem),
  9561. ACMD_DEF(charcommands),
  9562. ACMD_DEF(font),
  9563. ACMD_DEF(accinfo),
  9564. ACMD_DEF(set),
  9565. ACMD_DEF(undisguiseguild),
  9566. ACMD_DEF(disguiseguild),
  9567. ACMD_DEF(sizeall),
  9568. ACMD_DEF(sizeguild),
  9569. ACMD_DEF(addperm),
  9570. ACMD_DEF2("rmvperm", addperm),
  9571. ACMD_DEF(unloadnpcfile),
  9572. ACMD_DEF(cart),
  9573. ACMD_DEF(mount2),
  9574. ACMD_DEF(join),
  9575. ACMD_DEFR(channel,ATCMD_NOSCRIPT),
  9576. ACMD_DEF(fontcolor),
  9577. ACMD_DEF(langtype),
  9578. #ifdef VIP_ENABLE
  9579. ACMD_DEF(vip),
  9580. ACMD_DEF(showrate),
  9581. #endif
  9582. ACMD_DEF(fullstrip),
  9583. ACMD_DEF(costume),
  9584. ACMD_DEF(cloneequip),
  9585. ACMD_DEF(clonestat),
  9586. ACMD_DEF(bodystyle),
  9587. ACMD_DEF(adopt),
  9588. ACMD_DEF(agitstart3),
  9589. ACMD_DEF(agitend3),
  9590. ACMD_DEFR(limitedsale, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9591. ACMD_DEFR(changedress, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9592. ACMD_DEFR(camerainfo, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9593. ACMD_DEFR(resurrect, ATCMD_NOCONSOLE),
  9594. ACMD_DEF2("setquest", quest),
  9595. ACMD_DEF2("erasequest", quest),
  9596. ACMD_DEF2("completequest", quest),
  9597. ACMD_DEF2("checkquest", quest),
  9598. ACMD_DEF(refineui),
  9599. ACMD_DEFR(stylist, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9600. ACMD_DEF(addfame),
  9601. ACMD_DEFR(enchantgradeui, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9602. ACMD_DEFR(roulette, ATCMD_NOCONSOLE|ATCMD_NOAUTOTRADE),
  9603. ACMD_DEF(setcard),
  9604. };
  9605. AtCommandInfo* atcommand;
  9606. int i;
  9607. for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
  9608. if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK
  9609. ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
  9610. continue;
  9611. }
  9612. CREATE(atcommand, AtCommandInfo, 1);
  9613. safestrncpy(atcommand->command, atcommand_base[i].command, sizeof(atcommand->command));
  9614. atcommand->func = atcommand_base[i].func;
  9615. atcommand->restriction = atcommand_base[i].restriction;
  9616. strdb_put(atcommand_db, atcommand->command, atcommand);
  9617. }
  9618. return;
  9619. }
  9620. /*==========================================
  9621. * Command lookup functions
  9622. *------------------------------------------*/
  9623. bool atcommand_exists(const char* name)
  9624. {
  9625. return strdb_exists(atcommand_db, name);
  9626. }
  9627. static AtCommandInfo* get_atcommandinfo_byname(const char *name)
  9628. {
  9629. if (strdb_exists(atcommand_db, name))
  9630. return (AtCommandInfo*)strdb_get(atcommand_db, name);
  9631. return nullptr;
  9632. }
  9633. /// AtCommand suggestion
  9634. static void atcommand_get_suggestions(map_session_data* sd, const char *name, bool atcommand) {
  9635. DBIterator* atcommand_iter;
  9636. AtCommandInfo* command_info = nullptr;
  9637. AtCommandType type = atcommand ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND;
  9638. char* full_match[MAX_SUGGESTIONS];
  9639. char* suggestions[MAX_SUGGESTIONS];
  9640. char* match;
  9641. int prefix_count = 0, full_count = 0;
  9642. bool can_use;
  9643. if (!battle_config.atcommand_suggestions_enabled)
  9644. return;
  9645. atcommand_iter = db_iterator(atcommand_db);
  9646. // Build the matches
  9647. for (command_info = (AtCommandInfo*)dbi_first(atcommand_iter); dbi_exists(atcommand_iter); command_info = (AtCommandInfo*)dbi_next(atcommand_iter)) {
  9648. match = strstr(command_info->command, name);
  9649. can_use = pc_can_use_command(sd, command_info->command, type);
  9650. if ( prefix_count < MAX_SUGGESTIONS && match == command_info->command && can_use ) {
  9651. suggestions[prefix_count] = command_info->command;
  9652. ++prefix_count;
  9653. }
  9654. if ( full_count < MAX_SUGGESTIONS && match != nullptr && match != command_info->command && can_use ) {
  9655. full_match[full_count] = command_info->command;
  9656. ++full_count;
  9657. }
  9658. }
  9659. for( auto& pair : atcommand_alias_db ){
  9660. std::shared_ptr<s_atcommand_alias_info> info = pair.second;
  9661. if( pc_can_use_command( sd, info->command->command, type ) ){
  9662. for( const std::string& alias_str : info->aliases ){
  9663. char* alias = const_cast<char *>(alias_str.c_str());
  9664. match = strstr( alias, name );
  9665. if( prefix_count < MAX_SUGGESTIONS && match == alias ){
  9666. suggestions[prefix_count] = alias;
  9667. ++prefix_count;
  9668. }
  9669. if( full_count < MAX_SUGGESTIONS && match != nullptr && match != alias ){
  9670. full_match[full_count] = alias;
  9671. ++full_count;
  9672. }
  9673. }
  9674. }
  9675. }
  9676. if ((full_count+prefix_count) > 0) {
  9677. char buffer[512];
  9678. int i;
  9679. // Merge full match and prefix match results
  9680. if (prefix_count < MAX_SUGGESTIONS) {
  9681. memmove(&suggestions[prefix_count], full_match, sizeof(char*) * (MAX_SUGGESTIONS-prefix_count));
  9682. prefix_count = min(prefix_count+full_count, MAX_SUGGESTIONS);
  9683. }
  9684. // Build the suggestion string
  9685. strcpy(buffer, msg_txt(sd,205)); // Maybe you meant:
  9686. strcat(buffer,"\n");
  9687. for(i=0; i < prefix_count; ++i) {
  9688. strcat(buffer,suggestions[i]);
  9689. strcat(buffer," ");
  9690. }
  9691. clif_displaymessage(sd->fd, buffer);
  9692. }
  9693. dbi_destroy(atcommand_iter);
  9694. }
  9695. /**
  9696. * Executes an at-command
  9697. * @param fd
  9698. * @param sd
  9699. * @param message
  9700. * @param type
  9701. * 0 : script call (atcommand)
  9702. * 1 : normal player @atcommand
  9703. * 2 : console (admin:@atcommand)
  9704. * 3 : script call (useatcmd)
  9705. */
  9706. bool is_atcommand(const int fd, map_session_data* sd, const char* message, int type)
  9707. {
  9708. char command[CHAT_SIZE_MAX], params[CHAT_SIZE_MAX];
  9709. char output[CHAT_SIZE_MAX];
  9710. //Reconstructed message
  9711. char atcmd_msg[CHAT_SIZE_MAX * 2];
  9712. TBL_PC * ssd = nullptr; //sd for target
  9713. AtCommandInfo * info;
  9714. bool is_atcommand = true; // false if it's a charcommand
  9715. nullpo_retr(false, sd);
  9716. //Shouldn't happen
  9717. if ( !message || !*message )
  9718. return false;
  9719. //If cannot use atcomamnd while talking with NPC [Kichi]
  9720. if (type == 1 && sd->npc_id && sd->state.disable_atcommand_on_npc)
  9721. return false;
  9722. //Block NOCHAT but do not display it as a normal message
  9723. if ( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOCOMMAND )
  9724. return true;
  9725. // skip 10/11-langtype's codepage indicator, if detected
  9726. if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand_symbol || message[3] == charcommand_symbol) )
  9727. message += 3;
  9728. //Should display as a normal message
  9729. if ( *message != atcommand_symbol && *message != charcommand_symbol )
  9730. return false;
  9731. // type value 0|2 = script|console invoked: bypass restrictions
  9732. if ( type == 1 || type == 3) {
  9733. //Commands are disabled on maps flagged as 'nocommand'
  9734. if ( pc_get_group_level(sd) < map_getmapflag(sd->bl.m, MF_NOCOMMAND) ) {
  9735. clif_displaymessage(fd, msg_txt(sd,143)); // Commands are disabled on this map.
  9736. return false;
  9737. }
  9738. }
  9739. if (*message == charcommand_symbol)
  9740. is_atcommand = false;
  9741. if (is_atcommand) { // @command
  9742. sprintf(atcmd_msg, "%s", message);
  9743. ssd = sd;
  9744. } else { // #command
  9745. char charname[NAME_LENGTH];
  9746. int n;
  9747. //Checks to see if #command has a name or a name + parameters.
  9748. if ((n = sscanf(message, "%255s \"%23[^\"]\" %255[^\n]", command, charname, params)) < 2
  9749. && (n = sscanf(message, "%255s %23s %255[^\n]", command, charname, params)) < 2
  9750. ) {
  9751. if (pc_get_group_level(sd) == 0) {
  9752. if (n < 1)
  9753. return false; // No command found. Display as normal message.
  9754. info = get_atcommandinfo_byname(atcommand_alias_db.checkAlias(command + 1));
  9755. if (!info || info->char_groups[sd->group->index] == 0) // If we can't use or doesn't exist: don't even display the command failed message
  9756. return false;
  9757. }
  9758. sprintf(output, msg_txt(sd,1388), charcommand_symbol); // Charcommand failed (usage: %c<command> <char name> <parameters>).
  9759. clif_displaymessage(fd, output);
  9760. return true;
  9761. }
  9762. ssd = map_nick2sd(charname,true);
  9763. if (ssd == nullptr) {
  9764. sprintf(output, msg_txt(sd,1389), command); // %s failed. Player not found.
  9765. clif_displaymessage(fd, output);
  9766. return true;
  9767. }
  9768. if (n > 2)
  9769. sprintf(atcmd_msg, "%s %s", command, params);
  9770. else
  9771. sprintf(atcmd_msg, "%s", command);
  9772. }
  9773. if (battle_config.idletime_option&IDLE_ATCOMMAND)
  9774. sd->idletime = last_tick;
  9775. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATCOMMAND)
  9776. sd->idletime_hom = last_tick;
  9777. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATCOMMAND)
  9778. sd->idletime_mer = last_tick;
  9779. //Clearing these to be used once more.
  9780. memset(command, '\0', sizeof(command));
  9781. memset(params, '\0', sizeof(params));
  9782. //check to see if any params exist within this command
  9783. if( sscanf(atcmd_msg, "%255s %255[^\n]", command, params) < 2 )
  9784. params[0] = '\0';
  9785. if (type == 1 && (sd->state.block_action & PCBLOCK_COMMANDS)) {
  9786. sprintf(output,msg_txt(sd,154), command); // %s failed.
  9787. clif_displaymessage(fd, output);
  9788. return true;
  9789. }
  9790. // @commands (script based)
  9791. if((type == 1 || type == 3) && atcmd_binding_count > 0) {
  9792. struct atcmd_binding_data *binding = get_atcommandbind_byname(command);
  9793. // Check if the binding isn't nullptr and there is a NPC event, level of usage met, et cetera
  9794. if( binding != nullptr && binding->npc_event[0] &&
  9795. ((is_atcommand && pc_get_group_level(sd) >= binding->level) ||
  9796. (!is_atcommand && pc_get_group_level(sd) >= binding->level2)))
  9797. {
  9798. // Check if self or character invoking; if self == character invoked, then self invoke.
  9799. npc_do_atcmd_event(ssd, command, params, binding->npc_event);
  9800. return true;
  9801. }
  9802. }
  9803. //Grab the command information and check for the proper GM level required to use it or if the command exists
  9804. info = get_atcommandinfo_byname(atcommand_alias_db.checkAlias(command + 1));
  9805. if (info == nullptr) {
  9806. if (pc_get_group_level(sd) == 0) // TODO: remove or replace with proper permission
  9807. return false;
  9808. sprintf(output, msg_txt(sd,153), command); // "%s is Unknown Command."
  9809. clif_displaymessage(fd, output);
  9810. atcommand_get_suggestions(sd, command + 1, is_atcommand);
  9811. return true;
  9812. }
  9813. //check restriction
  9814. if (info->restriction) {
  9815. if (info->restriction&ATCMD_NOCONSOLE && type == 2) //console prevent
  9816. return true;
  9817. if (info->restriction&ATCMD_NOSCRIPT && (type == 0 || type == 3)) //scripts prevent
  9818. return true;
  9819. if (info->restriction&ATCMD_NOAUTOTRADE && (type == 0 || type == 3)
  9820. && ((is_atcommand && sd && sd->state.autotrade) || (ssd && ssd->state.autotrade)))
  9821. return true;
  9822. }
  9823. // type == 1 : player invoked
  9824. if (type == 1) {
  9825. if ((is_atcommand && info->at_groups[sd->group->index] == 0) ||
  9826. (!is_atcommand && info->char_groups[sd->group->index] == 0) )
  9827. return false;
  9828. if( pc_isdead(sd) && pc_has_permission(sd,PC_PERM_DISABLE_CMD_DEAD) ) {
  9829. clif_displaymessage(fd, msg_txt(sd,1393)); // You can't use commands while dead
  9830. return true;
  9831. }
  9832. }
  9833. //Attempt to use the command
  9834. if ( (info->func(fd, ssd, command, params) != 0) )
  9835. {
  9836. sprintf(output,msg_txt(sd,154), command); // %s failed.
  9837. clif_displaymessage(fd, output);
  9838. return true;
  9839. }
  9840. //Log only if successful.
  9841. log_atcommand(sd, is_atcommand ? atcmd_msg : message);
  9842. return true;
  9843. }
  9844. void atcommand_db_load_groups(){
  9845. DBIterator *iter = db_iterator(atcommand_db);
  9846. AtCommandInfo* cmd;
  9847. int pc_group_max = player_group_db.size();
  9848. for (cmd = (AtCommandInfo*)dbi_first(iter); dbi_exists(iter); cmd = (AtCommandInfo*)dbi_next(iter)) {
  9849. cmd->at_groups = (char*)aMalloc( pc_group_max * sizeof(char) );
  9850. cmd->char_groups = (char*)aMalloc( pc_group_max * sizeof(char) );
  9851. for( auto& it : player_group_db ){
  9852. cmd->at_groups[it.second->index] = it.second->can_use_command( cmd->command, COMMAND_ATCOMMAND );
  9853. cmd->char_groups[it.second->index] = it.second->can_use_command( cmd->command, COMMAND_CHARCOMMAND );
  9854. }
  9855. }
  9856. dbi_destroy(iter);
  9857. }
  9858. void atcommand_db_clear(void) {
  9859. if (atcommand_db != nullptr) {
  9860. DBIterator *iter = db_iterator(atcommand_db);
  9861. AtCommandInfo* cmd;
  9862. for (cmd = (AtCommandInfo*)dbi_first(iter); dbi_exists(iter); cmd = (AtCommandInfo*)dbi_next(iter)) {
  9863. aFree(cmd->at_groups);
  9864. aFree(cmd->char_groups);
  9865. }
  9866. dbi_destroy(iter);
  9867. db_destroy(atcommand_db);
  9868. }
  9869. atcommand_alias_db.clear();
  9870. }
  9871. void atcommand_doload(void) {
  9872. atcommand_db_clear();
  9873. atcommand_db = stridb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), ATCOMMAND_LENGTH);
  9874. atcommand_basecommands(); //fills initial atcommand_db with known commands
  9875. atcommand_alias_db.load();
  9876. }
  9877. void do_init_atcommand(void) {
  9878. atcommand_doload();
  9879. }
  9880. void do_final_atcommand(void) {
  9881. atcommand_db_clear();
  9882. }