atcommand.c 273 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/mmo.h"
  5. #include "../common/timer.h"
  6. #include "../common/nullpo.h"
  7. #include "../common/core.h"
  8. #include "../common/showmsg.h"
  9. #include "../common/malloc.h"
  10. #include "../common/random.h"
  11. #include "../common/socket.h"
  12. #include "../common/strlib.h"
  13. #include "../common/utils.h"
  14. #include "../common/conf.h"
  15. #include "atcommand.h"
  16. #include "battle.h"
  17. #include "chat.h"
  18. #include "clif.h"
  19. #include "chrif.h"
  20. #include "duel.h"
  21. #include "intif.h"
  22. #include "itemdb.h"
  23. #include "log.h"
  24. #include "map.h"
  25. #include "pc.h"
  26. #include "pc_groups.h" // groupid2name
  27. #include "status.h"
  28. #include "skill.h"
  29. #include "mob.h"
  30. #include "npc.h"
  31. #include "pet.h"
  32. #include "homunculus.h"
  33. #include "mail.h"
  34. #include "mercenary.h"
  35. #include "elemental.h"
  36. #include "party.h"
  37. #include "guild.h"
  38. #include "script.h"
  39. #include "storage.h"
  40. #include "trade.h"
  41. #include "unit.h"
  42. #include "mapreg.h"
  43. #include "quest.h"
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <math.h>
  48. #define ATCOMMAND_LENGTH 50
  49. #define ACMD_FUNC(x) static int atcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
  50. #define MAX_MSG 1400
  51. typedef struct AtCommandInfo AtCommandInfo;
  52. typedef struct AliasInfo AliasInfo;
  53. int atcmd_binding_count = 0;
  54. struct AtCommandInfo {
  55. char command[ATCOMMAND_LENGTH];
  56. AtCommandFunc func;
  57. char* at_groups;/* quick @commands "can-use" lookup */
  58. char* char_groups;/* quick @charcommands "can-use" lookup */
  59. };
  60. struct AliasInfo {
  61. AtCommandInfo *command;
  62. char alias[ATCOMMAND_LENGTH];
  63. };
  64. char atcommand_symbol = '@'; // first char of the commands
  65. char charcommand_symbol = '#';
  66. static char* msg_table[MAX_MSG]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)
  67. static DBMap* atcommand_db = NULL; //name -> AtCommandInfo
  68. static DBMap* atcommand_alias_db = NULL; //alias -> AtCommandInfo
  69. static config_t atcommand_config;
  70. static char atcmd_output[CHAT_SIZE_MAX];
  71. static char atcmd_player_name[NAME_LENGTH];
  72. static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help
  73. static const char* atcommand_checkalias(const char *aliasname); // @help
  74. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help
  75. // @commands (script-based)
  76. struct atcmd_binding_data* get_atcommandbind_byname(const char* name) {
  77. int i = 0;
  78. if( *name == atcommand_symbol || *name == charcommand_symbol )
  79. name++; // for backwards compatibility
  80. ARR_FIND( 0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, name) == 0 );
  81. return ( i < atcmd_binding_count ) ? atcmd_binding[i] : NULL;
  82. }
  83. //-----------------------------------------------------------
  84. // Return the message string of the specified number by [Yor]
  85. //-----------------------------------------------------------
  86. const char* msg_txt(int msg_number)
  87. {
  88. if (msg_number >= 0 && msg_number < MAX_MSG &&
  89. msg_table[msg_number] != NULL && msg_table[msg_number][0] != '\0')
  90. return msg_table[msg_number];
  91. return "??";
  92. }
  93. /*==========================================
  94. * Read Message Data
  95. *------------------------------------------*/
  96. int msg_config_read(const char* cfgName)
  97. {
  98. int msg_number;
  99. char line[1024], w1[1024], w2[1024];
  100. FILE *fp;
  101. static int called = 1;
  102. if ((fp = fopen(cfgName, "r")) == NULL) {
  103. ShowError("Messages file not found: %s\n", cfgName);
  104. return 1;
  105. }
  106. if ((--called) == 0)
  107. memset(msg_table, 0, sizeof(msg_table[0]) * MAX_MSG);
  108. while(fgets(line, sizeof(line), fp))
  109. {
  110. if (line[0] == '/' && line[1] == '/')
  111. continue;
  112. if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
  113. continue;
  114. if (strcmpi(w1, "import") == 0)
  115. msg_config_read(w2);
  116. else
  117. {
  118. msg_number = atoi(w1);
  119. if (msg_number >= 0 && msg_number < MAX_MSG)
  120. {
  121. if (msg_table[msg_number] != NULL)
  122. aFree(msg_table[msg_number]);
  123. msg_table[msg_number] = (char *)aMalloc((strlen(w2) + 1)*sizeof (char));
  124. strcpy(msg_table[msg_number],w2);
  125. }
  126. }
  127. }
  128. fclose(fp);
  129. return 0;
  130. }
  131. /*==========================================
  132. * Cleanup Message Data
  133. *------------------------------------------*/
  134. void do_final_msg(void)
  135. {
  136. int i;
  137. for (i = 0; i < MAX_MSG; i++)
  138. aFree(msg_table[i]);
  139. }
  140. /**
  141. * retrieves the help string associated with a given command.
  142. *
  143. * @param name the name of the command to retrieve help information for
  144. * @return the string associated with the command, or NULL
  145. */
  146. static const char* atcommand_help_string(const char* command)
  147. {
  148. const char* str = NULL;
  149. config_setting_t* info;
  150. if( *command == atcommand_symbol || *command == charcommand_symbol )
  151. {// remove the prefix symbol for the raw name of the command
  152. command ++;
  153. }
  154. // convert alias to the real command name
  155. command = atcommand_checkalias(command);
  156. // attept to find the first default help command
  157. info = config_lookup(&atcommand_config, "help");
  158. if( info == NULL )
  159. {// failed to find the help property in the configuration file
  160. return NULL;
  161. }
  162. if( !config_setting_lookup_string( info, command, &str ) )
  163. {// failed to find the matching help string
  164. return NULL;
  165. }
  166. // push the result from the method
  167. return str;
  168. }
  169. /*==========================================
  170. * @send (used for testing packet sends from the client)
  171. *------------------------------------------*/
  172. ACMD_FUNC(send)
  173. {
  174. int len=0,off,end,type;
  175. long num;
  176. // read message type as hex number (without the 0x)
  177. if(!message || !*message ||
  178. !((sscanf(message, "len %x", &type)==1 && (len=1))
  179. || sscanf(message, "%x", &type)==1) )
  180. {
  181. int i;
  182. for (i = 900; i <= 903; ++i)
  183. clif_displaymessage(fd, msg_txt(i));
  184. return -1;
  185. }
  186. #define PARSE_ERROR(error,p) \
  187. {\
  188. clif_displaymessage(fd, (error));\
  189. sprintf(atcmd_output, ">%s", (p));\
  190. clif_displaymessage(fd, atcmd_output);\
  191. }
  192. //define PARSE_ERROR
  193. #define CHECK_EOS(p) \
  194. if(*(p) == 0){\
  195. clif_displaymessage(fd, "Unexpected end of string");\
  196. return -1;\
  197. }
  198. //define CHECK_EOS
  199. #define SKIP_VALUE(p) \
  200. {\
  201. while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
  202. while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
  203. }
  204. //define SKIP_VALUE
  205. #define GET_VALUE(p,num) \
  206. {\
  207. if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
  208. PARSE_ERROR("Invalid number in:",(p));\
  209. return -1;\
  210. }\
  211. }
  212. //define GET_VALUE
  213. if (type > 0 && type < MAX_PACKET_DB) {
  214. if(len)
  215. {// show packet length
  216. sprintf(atcmd_output, msg_txt(904), type, packet_db[sd->packet_ver][type].len); // Packet 0x%x length: %d
  217. clif_displaymessage(fd, atcmd_output);
  218. return 0;
  219. }
  220. len=packet_db[sd->packet_ver][type].len;
  221. off=2;
  222. if(len == 0)
  223. {// unknown packet - ERROR
  224. sprintf(atcmd_output, msg_txt(905), type); // Unknown packet: 0x%x
  225. clif_displaymessage(fd, atcmd_output);
  226. return -1;
  227. } else if(len == -1)
  228. {// dynamic packet
  229. len=SHRT_MAX-4; // maximum length
  230. off=4;
  231. }
  232. WFIFOHEAD(fd, len);
  233. WFIFOW(fd,0)=TOW(type);
  234. // parse packet contents
  235. SKIP_VALUE(message);
  236. while(*message != 0 && off < len){
  237. if(ISDIGIT(*message) || *message == '-' || *message == '+')
  238. {// default (byte)
  239. GET_VALUE(message,num);
  240. WFIFOB(fd,off)=TOB(num);
  241. ++off;
  242. } else if(TOUPPER(*message) == 'B')
  243. {// byte
  244. ++message;
  245. GET_VALUE(message,num);
  246. WFIFOB(fd,off)=TOB(num);
  247. ++off;
  248. } else if(TOUPPER(*message) == 'W')
  249. {// word (2 bytes)
  250. ++message;
  251. GET_VALUE(message,num);
  252. WFIFOW(fd,off)=TOW(num);
  253. off+=2;
  254. } else if(TOUPPER(*message) == 'L')
  255. {// long word (4 bytes)
  256. ++message;
  257. GET_VALUE(message,num);
  258. WFIFOL(fd,off)=TOL(num);
  259. off+=4;
  260. } else if(TOUPPER(*message) == 'S')
  261. {// string - escapes are valid
  262. // get string length - num <= 0 means not fixed length (default)
  263. ++message;
  264. if(*message == '"'){
  265. num=0;
  266. } else {
  267. GET_VALUE(message,num);
  268. while(*message != '"')
  269. {// find start of string
  270. if(*message == 0 || ISSPACE(*message)){
  271. PARSE_ERROR(msg_txt(906),message); // Not a string:
  272. return -1;
  273. }
  274. ++message;
  275. }
  276. }
  277. // parse string
  278. ++message;
  279. CHECK_EOS(message);
  280. end=(num<=0? 0: min(off+((int)num),len));
  281. for(; *message != '"' && (off < end || end == 0); ++off){
  282. if(*message == '\\'){
  283. ++message;
  284. CHECK_EOS(message);
  285. switch(*message){
  286. case 'a': num=0x07; break; // Bell
  287. case 'b': num=0x08; break; // Backspace
  288. case 't': num=0x09; break; // Horizontal tab
  289. case 'n': num=0x0A; break; // Line feed
  290. case 'v': num=0x0B; break; // Vertical tab
  291. case 'f': num=0x0C; break; // Form feed
  292. case 'r': num=0x0D; break; // Carriage return
  293. case 'e': num=0x1B; break; // Escape
  294. default: num=*message; break;
  295. case 'x': // Hexadecimal
  296. {
  297. ++message;
  298. CHECK_EOS(message);
  299. if(!ISXDIGIT(*message)){
  300. PARSE_ERROR(msg_txt(907),message); // Not a hexadecimal digit:
  301. return -1;
  302. }
  303. num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  304. if(ISXDIGIT(*message)){
  305. ++message;
  306. CHECK_EOS(message);
  307. num<<=8;
  308. num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  309. }
  310. WFIFOB(fd,off)=TOB(num);
  311. ++message;
  312. CHECK_EOS(message);
  313. continue;
  314. }
  315. case '0':
  316. case '1':
  317. case '2':
  318. case '3':
  319. case '4':
  320. case '5':
  321. case '6':
  322. case '7': // Octal
  323. {
  324. num=*message-'0'; // 1st octal digit
  325. ++message;
  326. CHECK_EOS(message);
  327. if(ISDIGIT(*message) && *message < '8'){
  328. num<<=3;
  329. num+=*message-'0'; // 2nd octal digit
  330. ++message;
  331. CHECK_EOS(message);
  332. if(ISDIGIT(*message) && *message < '8'){
  333. num<<=3;
  334. num+=*message-'0'; // 3rd octal digit
  335. ++message;
  336. CHECK_EOS(message);
  337. }
  338. }
  339. WFIFOB(fd,off)=TOB(num);
  340. continue;
  341. }
  342. }
  343. } else
  344. num=*message;
  345. WFIFOB(fd,off)=TOB(num);
  346. ++message;
  347. CHECK_EOS(message);
  348. }//for
  349. while(*message != '"')
  350. {// ignore extra characters
  351. ++message;
  352. CHECK_EOS(message);
  353. }
  354. // terminate the string
  355. if(off < end)
  356. {// fill the rest with 0's
  357. memset(WFIFOP(fd,off),0,end-off);
  358. off=end;
  359. }
  360. } else
  361. {// unknown
  362. PARSE_ERROR(msg_txt(908),message); // Unknown type of value in:
  363. return -1;
  364. }
  365. SKIP_VALUE(message);
  366. }
  367. if(packet_db[sd->packet_ver][type].len == -1)
  368. {// send dynamic packet
  369. WFIFOW(fd,2)=TOW(off);
  370. WFIFOSET(fd,off);
  371. } else
  372. {// send static packet
  373. if(off < len)
  374. memset(WFIFOP(fd,off),0,len-off);
  375. WFIFOSET(fd,len);
  376. }
  377. } else {
  378. clif_displaymessage(fd, msg_txt(259)); // Invalid packet
  379. return -1;
  380. }
  381. sprintf (atcmd_output, msg_txt(258), type, type); // Sent packet 0x%x (%d)
  382. clif_displaymessage(fd, atcmd_output);
  383. return 0;
  384. #undef PARSE_ERROR
  385. #undef CHECK_EOS
  386. #undef SKIP_VALUE
  387. #undef GET_VALUE
  388. }
  389. /*==========================================
  390. * @rura, @warp, @mapmove
  391. *------------------------------------------*/
  392. ACMD_FUNC(mapmove)
  393. {
  394. char map_name[MAP_NAME_LENGTH_EXT];
  395. unsigned short mapindex;
  396. short x = 0, y = 0;
  397. int m = -1;
  398. nullpo_retr(-1, sd);
  399. memset(map_name, '\0', sizeof(map_name));
  400. if (!message || !*message ||
  401. (sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 &&
  402. sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) {
  403. clif_displaymessage(fd, msg_txt(909)); // Please enter a map (usage: @warp/@rura/@mapmove <mapname> <x> <y>).
  404. return -1;
  405. }
  406. mapindex = mapindex_name2id(map_name);
  407. if (mapindex)
  408. m = map_mapindex2mapid(mapindex);
  409. if (!mapindex) { // m < 0 means on different server! [Kevin]
  410. clif_displaymessage(fd, msg_txt(1)); // Map not found.
  411. return -1;
  412. }
  413. if ((x || y) && map_getcell(m, x, y, CELL_CHKNOPASS))
  414. { //This is to prevent the pc_setpos call from printing an error.
  415. clif_displaymessage(fd, msg_txt(2));
  416. if (!map_search_freecell(NULL, m, &x, &y, 10, 10, 1))
  417. x = y = 0; //Invalid cell, use random spot.
  418. }
  419. if (map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  420. clif_displaymessage(fd, msg_txt(247));
  421. return -1;
  422. }
  423. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  424. clif_displaymessage(fd, msg_txt(248));
  425. return -1;
  426. }
  427. if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) {
  428. clif_displaymessage(fd, msg_txt(1)); // Map not found.
  429. return -1;
  430. }
  431. clif_displaymessage(fd, msg_txt(0)); // Warped.
  432. return 0;
  433. }
  434. /*==========================================
  435. * Displays where a character is. Corrected version by Silent. [Skotlex]
  436. *------------------------------------------*/
  437. ACMD_FUNC(where)
  438. {
  439. struct map_session_data* pl_sd;
  440. nullpo_retr(-1, sd);
  441. memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  442. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  443. clif_displaymessage(fd, msg_txt(910)); // Please enter a player name (usage: @where <char name>).
  444. return -1;
  445. }
  446. pl_sd = map_nick2sd(atcmd_player_name);
  447. if (pl_sd == NULL ||
  448. strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 ||
  449. (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))
  450. ) {
  451. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  452. return -1;
  453. }
  454. 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);
  455. clif_displaymessage(fd, atcmd_output);
  456. return 0;
  457. }
  458. /*==========================================
  459. *
  460. *------------------------------------------*/
  461. ACMD_FUNC(jumpto)
  462. {
  463. struct map_session_data *pl_sd = NULL;
  464. nullpo_retr(-1, sd);
  465. if (!message || !*message) {
  466. clif_displaymessage(fd, msg_txt(911)); // Please enter a player name (usage: @jumpto/@warpto/@goto <char name/ID>).
  467. return -1;
  468. }
  469. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  470. {
  471. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  472. return -1;
  473. }
  474. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  475. {
  476. clif_displaymessage(fd, msg_txt(247)); // You are not authorized to warp to this map.
  477. return -1;
  478. }
  479. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  480. {
  481. clif_displaymessage(fd, msg_txt(248)); // You are not authorized to warp from your current map.
  482. return -1;
  483. }
  484. if( pc_isdead(sd) )
  485. {
  486. clif_displaymessage(fd, msg_txt(664));
  487. return -1;
  488. }
  489. pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  490. sprintf(atcmd_output, msg_txt(4), pl_sd->status.name); // Jumped to %s
  491. clif_displaymessage(fd, atcmd_output);
  492. return 0;
  493. }
  494. /*==========================================
  495. *
  496. *------------------------------------------*/
  497. ACMD_FUNC(jump)
  498. {
  499. short x = 0, y = 0;
  500. nullpo_retr(-1, sd);
  501. memset(atcmd_output, '\0', sizeof(atcmd_output));
  502. sscanf(message, "%hd %hd", &x, &y);
  503. if (map[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  504. clif_displaymessage(fd, msg_txt(248)); // You are not authorized to warp from your current map.
  505. return -1;
  506. }
  507. if( pc_isdead(sd) )
  508. {
  509. clif_displaymessage(fd, msg_txt(664));
  510. return -1;
  511. }
  512. if ((x || y) && map_getcell(sd->bl.m, x, y, CELL_CHKNOPASS))
  513. { //This is to prevent the pc_setpos call from printing an error.
  514. clif_displaymessage(fd, msg_txt(2));
  515. if (!map_search_freecell(NULL, sd->bl.m, &x, &y, 10, 10, 1))
  516. x = y = 0; //Invalid cell, use random spot.
  517. }
  518. pc_setpos(sd, sd->mapindex, x, y, CLR_TELEPORT);
  519. sprintf(atcmd_output, msg_txt(5), sd->bl.x, sd->bl.y); // Jumped to %d %d
  520. clif_displaymessage(fd, atcmd_output);
  521. return 0;
  522. }
  523. /*==========================================
  524. * Display list of online characters with
  525. * various info.
  526. *------------------------------------------*/
  527. ACMD_FUNC(who)
  528. {
  529. struct map_session_data *pl_sd = NULL;
  530. struct s_mapiterator *iter = NULL;
  531. char map_name[MAP_NAME_LENGTH_EXT] = "";
  532. char player_name[NAME_LENGTH] = "";
  533. int count = 0;
  534. int level = 0;
  535. StringBuf buf;
  536. /**
  537. * 1 = @who : Player name, [Title], [Party name], [Guild name]
  538. * 2 = @who2 : Player name, [Title], BLvl, JLvl, Job
  539. * 3 = @who3 : [CID/AID] Player name [Title], Map, X, Y
  540. */
  541. int display_type = 1;
  542. int map_id = -1;
  543. nullpo_retr(-1, sd);
  544. if (strstr(command, "map") != NULL) {
  545. if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map_mapname2mapid(map_name)) < 0)
  546. map_id = sd->bl.m;
  547. } else {
  548. sscanf(message, "%23s", player_name);
  549. }
  550. if (strstr(command, "2") != NULL)
  551. display_type = 2;
  552. else if (strstr(command, "3") != NULL)
  553. display_type = 3;
  554. level = pc_get_group_level(sd);
  555. StringBuf_Init(&buf);
  556. iter = mapit_getallusers();
  557. for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) {
  558. if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || (pl_sd->sc.option & OPTION_INVISIBLE)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level
  559. if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive
  560. || (map_id >= 0 && pl_sd->bl.m != map_id))
  561. continue;
  562. switch (display_type) {
  563. case 2: {
  564. StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  565. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  566. StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  567. StringBuf_Printf(&buf, msg_txt(347), pl_sd->status.base_level, pl_sd->status.job_level,
  568. job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s"
  569. break;
  570. }
  571. case 3: {
  572. if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  573. StringBuf_Printf(&buf, msg_txt(912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) "
  574. StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  575. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  576. StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  577. StringBuf_Printf(&buf, msg_txt(348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
  578. break;
  579. }
  580. default: {
  581. struct party_data *p = party_search(pl_sd->status.party_id);
  582. struct guild *g = guild_search(pl_sd->status.guild_id);
  583. StringBuf_Printf(&buf, msg_txt(343), pl_sd->status.name); // "Name: %s "
  584. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  585. StringBuf_Printf(&buf, msg_txt(344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  586. if (p != NULL)
  587. StringBuf_Printf(&buf, msg_txt(345), p->party.name); // " | Party: '%s'"
  588. if (g != NULL)
  589. StringBuf_Printf(&buf, msg_txt(346), g->name); // " | Guild: '%s'"
  590. break;
  591. }
  592. }
  593. clif_displaymessage(fd, StringBuf_Value(&buf));
  594. StringBuf_Clear(&buf);
  595. count++;
  596. }
  597. }
  598. mapit_free(iter);
  599. if (map_id < 0) {
  600. if (count == 0)
  601. StringBuf_Printf(&buf, msg_txt(28)); // No player found.
  602. else if (count == 1)
  603. StringBuf_Printf(&buf, msg_txt(29)); // 1 player found.
  604. else
  605. StringBuf_Printf(&buf, msg_txt(30), count); // %d players found.
  606. } else {
  607. if (count == 0)
  608. StringBuf_Printf(&buf, msg_txt(54), map[map_id].name); // No player found in map '%s'.
  609. else if (count == 1)
  610. StringBuf_Printf(&buf, msg_txt(55), map[map_id].name); // 1 player found in map '%s'.
  611. else
  612. StringBuf_Printf(&buf, msg_txt(56), count, map[map_id].name); // %d players found in map '%s'.
  613. }
  614. clif_displaymessage(fd, StringBuf_Value(&buf));
  615. StringBuf_Destroy(&buf);
  616. return 0;
  617. }
  618. /*==========================================
  619. *
  620. *------------------------------------------*/
  621. ACMD_FUNC(whogm)
  622. {
  623. struct map_session_data* pl_sd;
  624. struct s_mapiterator* iter;
  625. int j, count;
  626. int pl_level, level;
  627. char match_text[CHAT_SIZE_MAX];
  628. char player_name[NAME_LENGTH];
  629. struct guild *g;
  630. struct party_data *p;
  631. nullpo_retr(-1, sd);
  632. memset(atcmd_output, '\0', sizeof(atcmd_output));
  633. memset(match_text, '\0', sizeof(match_text));
  634. memset(player_name, '\0', sizeof(player_name));
  635. if (sscanf(message, "%199[^\n]", match_text) < 1)
  636. strcpy(match_text, "");
  637. for (j = 0; match_text[j]; j++)
  638. match_text[j] = TOLOWER(match_text[j]);
  639. count = 0;
  640. level = pc_get_group_level(sd);
  641. iter = mapit_getallusers();
  642. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  643. {
  644. pl_level = pc_get_group_level(pl_sd);
  645. if (!pl_level)
  646. continue;
  647. if (match_text[0])
  648. {
  649. memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
  650. for (j = 0; player_name[j]; j++)
  651. player_name[j] = TOLOWER(player_name[j]);
  652. // search with no case sensitive
  653. if (strstr(player_name, match_text) == NULL)
  654. continue;
  655. }
  656. if (pl_level > level) {
  657. if (pl_sd->sc.option & OPTION_INVISIBLE)
  658. continue;
  659. sprintf(atcmd_output, msg_txt(913), pl_sd->status.name); // Name: %s (GM)
  660. clif_displaymessage(fd, atcmd_output);
  661. count++;
  662. continue;
  663. }
  664. sprintf(atcmd_output, msg_txt(914), // Name: %s (GM:%d) | Location: %s %d %d
  665. pl_sd->status.name, pl_level,
  666. mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  667. clif_displaymessage(fd, atcmd_output);
  668. sprintf(atcmd_output, msg_txt(915), // BLvl: %d | Job: %s (Lvl: %d)
  669. pl_sd->status.base_level,
  670. job_name(pl_sd->status.class_), pl_sd->status.job_level);
  671. clif_displaymessage(fd, atcmd_output);
  672. p = party_search(pl_sd->status.party_id);
  673. g = guild_search(pl_sd->status.guild_id);
  674. sprintf(atcmd_output,msg_txt(916), // Party: '%s' | Guild: '%s'
  675. p?p->party.name:msg_txt(917), g?g->name:msg_txt(917)); // None.
  676. clif_displaymessage(fd, atcmd_output);
  677. count++;
  678. }
  679. mapit_free(iter);
  680. if (count == 0)
  681. clif_displaymessage(fd, msg_txt(150)); // No GM found.
  682. else if (count == 1)
  683. clif_displaymessage(fd, msg_txt(151)); // 1 GM found.
  684. else {
  685. sprintf(atcmd_output, msg_txt(152), count); // %d GMs found.
  686. clif_displaymessage(fd, atcmd_output);
  687. }
  688. return 0;
  689. }
  690. /*==========================================
  691. *
  692. *------------------------------------------*/
  693. ACMD_FUNC(save)
  694. {
  695. nullpo_retr(-1, sd);
  696. pc_setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  697. if (sd->status.pet_id > 0 && sd->pd)
  698. intif_save_petdata(sd->status.account_id, &sd->pd->pet);
  699. chrif_save(sd,0);
  700. clif_displaymessage(fd, msg_txt(6)); // Your save point has been changed.
  701. return 0;
  702. }
  703. /*==========================================
  704. *
  705. *------------------------------------------*/
  706. ACMD_FUNC(load)
  707. {
  708. int m;
  709. nullpo_retr(-1, sd);
  710. m = map_mapindex2mapid(sd->status.save_point.map);
  711. if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  712. clif_displaymessage(fd, msg_txt(249)); // You are not authorized to warp to your save map.
  713. return -1;
  714. }
  715. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  716. clif_displaymessage(fd, msg_txt(248)); // You are not authorized to warp from your current map.
  717. return -1;
  718. }
  719. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT);
  720. clif_displaymessage(fd, msg_txt(7)); // Warping to save point..
  721. return 0;
  722. }
  723. /*==========================================
  724. *
  725. *------------------------------------------*/
  726. ACMD_FUNC(speed)
  727. {
  728. int speed;
  729. nullpo_retr(-1, sd);
  730. memset(atcmd_output, '\0', sizeof(atcmd_output));
  731. if (!message || !*message || sscanf(message, "%d", &speed) < 1) {
  732. sprintf(atcmd_output, msg_txt(918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>).
  733. clif_displaymessage(fd, atcmd_output);
  734. return -1;
  735. }
  736. sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
  737. status_calc_bl(&sd->bl, SCB_SPEED);
  738. clif_displaymessage(fd, msg_txt(8)); // Speed changed.
  739. return 0;
  740. }
  741. /*==========================================
  742. *
  743. *------------------------------------------*/
  744. ACMD_FUNC(storage)
  745. {
  746. nullpo_retr(-1, sd);
  747. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
  748. return -1;
  749. if (storage_storageopen(sd) == 1)
  750. { //Already open.
  751. clif_displaymessage(fd, msg_txt(250));
  752. return -1;
  753. }
  754. clif_displaymessage(fd, msg_txt(919)); // Storage opened.
  755. return 0;
  756. }
  757. /*==========================================
  758. *
  759. *------------------------------------------*/
  760. ACMD_FUNC(guildstorage)
  761. {
  762. nullpo_retr(-1, sd);
  763. if (!sd->status.guild_id) {
  764. clif_displaymessage(fd, msg_txt(252));
  765. return -1;
  766. }
  767. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  768. return -1;
  769. if (sd->state.storage_flag == 1) {
  770. clif_displaymessage(fd, msg_txt(250));
  771. return -1;
  772. }
  773. if (sd->state.storage_flag == 2) {
  774. clif_displaymessage(fd, msg_txt(251));
  775. return -1;
  776. }
  777. storage_guild_storageopen(sd);
  778. clif_displaymessage(fd, msg_txt(920)); // Guild storage opened.
  779. return 0;
  780. }
  781. /*==========================================
  782. *
  783. *------------------------------------------*/
  784. ACMD_FUNC(option)
  785. {
  786. int param1 = 0, param2 = 0, param3 = 0;
  787. nullpo_retr(-1, sd);
  788. if (!message || !*message || sscanf(message, "%d %d %d", &param1, &param2, &param3) < 1 || param1 < 0 || param2 < 0 || param3 < 0)
  789. {// failed to match the parameters so inform the user of the options
  790. const char* text = NULL;
  791. // attempt to find the setting information for this command
  792. text = atcommand_help_string( command );
  793. // notify the user of the requirement to enter an option
  794. clif_displaymessage(fd, msg_txt(921)); // Please enter at least one option.
  795. if( text )
  796. {// send the help text associated with this command
  797. clif_displaymessage( fd, text );
  798. }
  799. return -1;
  800. }
  801. sd->sc.opt1 = param1;
  802. sd->sc.opt2 = param2;
  803. pc_setoption(sd, param3);
  804. clif_displaymessage(fd, msg_txt(9)); // Options changed.
  805. return 0;
  806. }
  807. /*==========================================
  808. *
  809. *------------------------------------------*/
  810. ACMD_FUNC(hide)
  811. {
  812. nullpo_retr(-1, sd);
  813. if (sd->sc.option & OPTION_INVISIBLE) {
  814. sd->sc.option &= ~OPTION_INVISIBLE;
  815. if (sd->disguise)
  816. status_set_viewdata(&sd->bl, sd->disguise);
  817. else
  818. status_set_viewdata(&sd->bl, sd->status.class_);
  819. clif_displaymessage(fd, msg_txt(10)); // Invisible: Off
  820. // increment the number of pvp players on the map
  821. map[sd->bl.m].users_pvp++;
  822. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank )
  823. {// register the player for ranking calculations
  824. sd->pvp_timer = add_timer( gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0 );
  825. }
  826. //bugreport:2266
  827. map_foreachinmovearea(clif_insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  828. } else {
  829. sd->sc.option |= OPTION_INVISIBLE;
  830. sd->vd.class_ = INVISIBLE_CLASS;
  831. clif_displaymessage(fd, msg_txt(11)); // Invisible: On
  832. // decrement the number of pvp players on the map
  833. map[sd->bl.m].users_pvp--;
  834. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER )
  835. {// unregister the player for ranking
  836. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  837. sd->pvp_timer = INVALID_TIMER;
  838. }
  839. }
  840. clif_changeoption(&sd->bl);
  841. return 0;
  842. }
  843. /*==========================================
  844. * Changes a character's class
  845. *------------------------------------------*/
  846. ACMD_FUNC(jobchange)
  847. {
  848. //FIXME: redundancy, potentially wrong code, should use job_name() or similar instead of hardcoding the table [ultramage]
  849. int job = 0, upper = 0;
  850. const char* text;
  851. nullpo_retr(-1, sd);
  852. if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1)
  853. {
  854. int i, found = 0;
  855. const struct { char name[24]; int id; } jobs[] = {
  856. { "novice", 0 },
  857. { "swordman", 1 },
  858. { "swordsman", 1 },
  859. { "magician", 2 },
  860. { "mage", 2 },
  861. { "archer", 3 },
  862. { "acolyte", 4 },
  863. { "merchant", 5 },
  864. { "thief", 6 },
  865. { "knight", 7 },
  866. { "priest", 8 },
  867. { "priestess", 8 },
  868. { "wizard", 9 },
  869. { "blacksmith", 10 },
  870. { "hunter", 11 },
  871. { "assassin", 12 },
  872. { "crusader", 14 },
  873. { "monk", 15 },
  874. { "sage", 16 },
  875. { "rogue", 17 },
  876. { "alchemist", 18 },
  877. { "bard", 19 },
  878. { "dancer", 20 },
  879. { "super novice", 23 },
  880. { "supernovice", 23 },
  881. { "gunslinger", 24 },
  882. { "gunner", 24 },
  883. { "ninja", 25 },
  884. { "novice high", 4001 },
  885. { "high novice", 4001 },
  886. { "swordman high", 4002 },
  887. { "swordsman high", 4002 },
  888. { "magician high", 4003 },
  889. { "mage high", 4003 },
  890. { "archer high", 4004 },
  891. { "acolyte high", 4005 },
  892. { "merchant high", 4006 },
  893. { "thief high", 4007 },
  894. { "lord knight", 4008 },
  895. { "high priest", 4009 },
  896. { "high priestess", 4009 },
  897. { "high wizard", 4010 },
  898. { "whitesmith", 4011 },
  899. { "sniper", 4012 },
  900. { "assassin cross", 4013 },
  901. { "paladin", 4015 },
  902. { "champion", 4016 },
  903. { "professor", 4017 },
  904. { "stalker", 4018 },
  905. { "creator", 4019 },
  906. { "clown", 4020 },
  907. { "gypsy", 4021 },
  908. { "baby novice", 4023 },
  909. { "baby swordman", 4024 },
  910. { "baby swordsman", 4024 },
  911. { "baby magician", 4025 },
  912. { "baby mage", 4025 },
  913. { "baby archer", 4026 },
  914. { "baby acolyte", 4027 },
  915. { "baby merchant", 4028 },
  916. { "baby thief", 4029 },
  917. { "baby knight", 4030 },
  918. { "baby priest", 4031 },
  919. { "baby priestess", 4031 },
  920. { "baby wizard", 4032 },
  921. { "baby blacksmith",4033 },
  922. { "baby hunter", 4034 },
  923. { "baby assassin", 4035 },
  924. { "baby crusader", 4037 },
  925. { "baby monk", 4038 },
  926. { "baby sage", 4039 },
  927. { "baby rogue", 4040 },
  928. { "baby alchemist", 4041 },
  929. { "baby bard", 4042 },
  930. { "baby dancer", 4043 },
  931. { "super baby", 4045 },
  932. { "taekwon", 4046 },
  933. { "taekwon boy", 4046 },
  934. { "taekwon girl", 4046 },
  935. { "star gladiator", 4047 },
  936. { "soul linker", 4049 },
  937. { "gangsi", 4050 },
  938. { "bongun", 4050 },
  939. { "munak", 4050 },
  940. { "death knight", 4051 },
  941. { "dark collector", 4052 },
  942. { "rune knight", 4054 },
  943. { "warlock", 4055 },
  944. { "ranger", 4056 },
  945. { "arch bishop", 4057 },
  946. { "mechanic", 4058 },
  947. { "guillotine", 4059 },
  948. { "rune knight2", 4060 },
  949. { "warlock2", 4061 },
  950. { "ranger2", 4062 },
  951. { "arch bishop2", 4063 },
  952. { "mechanic2", 4064 },
  953. { "guillotine2", 4065 },
  954. { "royal guard", 4066 },
  955. { "sorcerer", 4067 },
  956. { "minstrel", 4068 },
  957. { "wanderer", 4069 },
  958. { "sura", 4070 },
  959. { "genetic", 4071 },
  960. { "shadow chaser", 4072 },
  961. { "royal guard2", 4073 },
  962. { "sorcerer2", 4074 },
  963. { "minstrel2", 4075 },
  964. { "wanderer2", 4076 },
  965. { "sura2", 4077 },
  966. { "genetic2", 4078 },
  967. { "shadow chaser2", 4079 },
  968. { "baby rune", 4096 },
  969. { "baby warlock", 4097 },
  970. { "baby ranger", 4098 },
  971. { "baby bishop", 4099 },
  972. { "baby mechanic", 4100 },
  973. { "baby cross", 4101 },
  974. { "baby guard", 4102 },
  975. { "baby sorcerer", 4103 },
  976. { "baby minstrel", 4104 },
  977. { "baby wanderer", 4105 },
  978. { "baby sura", 4106 },
  979. { "baby genetic", 4107 },
  980. { "baby chaser", 4108 },
  981. { "super novice e", 4190 },
  982. { "super baby e", 4191 },
  983. { "kagerou", 4211 },
  984. { "oboro", 4212 },
  985. };
  986. for (i=0; i < ARRAYLENGTH(jobs); i++) {
  987. if (strncmpi(message, jobs[i].name, 16) == 0) {
  988. job = jobs[i].id;
  989. upper = 0;
  990. found = 1;
  991. break;
  992. }
  993. }
  994. if (!found) {
  995. text = atcommand_help_string(command);
  996. if (text) clif_displaymessage(fd, text);
  997. return -1;
  998. }
  999. }
  1000. if (job == 13 || job == 21 || job == 22 || job == 26 || job == 27 || job == 4014 || job == 4022 || job == 4036 || job == 4044 || job == 4048
  1001. || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
  1002. ) // Deny direct transformation into dummy jobs
  1003. {clif_displaymessage(fd, msg_txt(923)); //"You can not change to this job by command."
  1004. return 0;}
  1005. if (pcdb_checkid(job))
  1006. {
  1007. if (pc_jobchange(sd, job, upper) == 0)
  1008. clif_displaymessage(fd, msg_txt(12)); // Your job has been changed.
  1009. else {
  1010. clif_displaymessage(fd, msg_txt(155)); // You are unable to change your job.
  1011. return -1;
  1012. }
  1013. } else {
  1014. text = atcommand_help_string(command);
  1015. if (text) 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(13)); // A pity! You've died.
  1028. if (fd != sd->fd)
  1029. clif_displaymessage(fd, msg_txt(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(667));
  1041. return -1;
  1042. }
  1043. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  1044. clif_displaymessage(fd, msg_txt(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(980)); // Please enter a message (usage: @kami <message>).
  1058. return -1;
  1059. }
  1060. sscanf(message, "%199[^\n]", atcmd_output);
  1061. if (strstr(command, "l") != NULL)
  1062. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  1063. else
  1064. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(command + 5) == 'b' || *(command + 5) == 'B') ? 0x10 : 0);
  1065. } else {
  1066. if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) {
  1067. clif_displaymessage(fd, msg_txt(981)); // Please enter color and message (usage: @kamic <color> <message>).
  1068. return -1;
  1069. }
  1070. if(color > 0xFFFFFF) {
  1071. clif_displaymessage(fd, msg_txt(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, "%d %d", &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(157)); // HP and SP have already been recovered.
  1092. else
  1093. clif_displaymessage(fd, msg_txt(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(157)); // HP and SP are already with the good value.
  1099. else
  1100. clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered.
  1101. return 0;
  1102. }
  1103. if ( hp < 0 && sp <= 0 ) {
  1104. status_damage(NULL, &sd->bl, -hp, -sp, 0, 0);
  1105. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1106. clif_displaymessage(fd, msg_txt(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(NULL, &sd->bl, -hp, 0, 0, 0);
  1115. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  1116. }
  1117. }
  1118. if ( sp ) {
  1119. if (sp > 0)
  1120. status_heal(&sd->bl, 0, sp, 0);
  1121. else
  1122. status_damage(NULL, &sd->bl, 0, -sp, 0, 0);
  1123. }
  1124. clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified.
  1125. return 0;
  1126. }
  1127. /*==========================================
  1128. * @item command (usage: @item <name/id_of_item> <quantity>) (modified by [Yor] for pet_egg)
  1129. *------------------------------------------*/
  1130. ACMD_FUNC(item)
  1131. {
  1132. char item_name[100];
  1133. int number = 0, item_id, flag = 0;
  1134. struct item item_tmp;
  1135. struct item_data *item_data;
  1136. int get_count, i;
  1137. nullpo_retr(-1, sd);
  1138. memset(item_name, '\0', sizeof(item_name));
  1139. if (!message || !*message || (
  1140. sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 &&
  1141. sscanf(message, "%99s %d", item_name, &number) < 1
  1142. )) {
  1143. clif_displaymessage(fd, msg_txt(983)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity>).
  1144. return -1;
  1145. }
  1146. if (number <= 0)
  1147. number = 1;
  1148. if ((item_data = itemdb_searchname(item_name)) == NULL &&
  1149. (item_data = itemdb_exists(atoi(item_name))) == NULL)
  1150. {
  1151. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1152. return -1;
  1153. }
  1154. item_id = item_data->nameid;
  1155. get_count = number;
  1156. //Check if it's stackable.
  1157. if (!itemdb_isstackable2(item_data))
  1158. get_count = 1;
  1159. for (i = 0; i < number; i += get_count) {
  1160. // if not pet egg
  1161. if (!pet_create_egg(sd, item_id)) {
  1162. memset(&item_tmp, 0, sizeof(item_tmp));
  1163. item_tmp.nameid = item_id;
  1164. item_tmp.identify = 1;
  1165. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1166. clif_additem(sd, 0, 0, flag);
  1167. }
  1168. }
  1169. if (flag == 0)
  1170. clif_displaymessage(fd, msg_txt(18)); // Item created.
  1171. return 0;
  1172. }
  1173. /*==========================================
  1174. *
  1175. *------------------------------------------*/
  1176. ACMD_FUNC(item2)
  1177. {
  1178. struct item item_tmp;
  1179. struct item_data *item_data;
  1180. char item_name[100];
  1181. int item_id, number = 0;
  1182. int identify = 0, refine = 0, attr = 0;
  1183. int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  1184. int flag = 0;
  1185. int loop, get_count, i;
  1186. nullpo_retr(-1, sd);
  1187. memset(item_name, '\0', sizeof(item_name));
  1188. if (!message || !*message || (
  1189. sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
  1190. sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
  1191. )) {
  1192. clif_displaymessage(fd, msg_txt(984)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity>
  1193. clif_displaymessage(fd, msg_txt(985)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4>).
  1194. return -1;
  1195. }
  1196. if (number <= 0)
  1197. number = 1;
  1198. item_id = 0;
  1199. if ((item_data = itemdb_searchname(item_name)) != NULL ||
  1200. (item_data = itemdb_exists(atoi(item_name))) != NULL)
  1201. item_id = item_data->nameid;
  1202. if (item_id > 500) {
  1203. loop = 1;
  1204. get_count = number;
  1205. if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR ||
  1206. item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) {
  1207. loop = number;
  1208. get_count = 1;
  1209. if (item_data->type == IT_PETEGG) {
  1210. identify = 1;
  1211. refine = 0;
  1212. }
  1213. if (item_data->type == IT_PETARMOR)
  1214. refine = 0;
  1215. if (refine > MAX_REFINE)
  1216. refine = MAX_REFINE;
  1217. } else {
  1218. identify = 1;
  1219. refine = attr = 0;
  1220. }
  1221. for (i = 0; i < loop; i++) {
  1222. memset(&item_tmp, 0, sizeof(item_tmp));
  1223. item_tmp.nameid = item_id;
  1224. item_tmp.identify = identify;
  1225. item_tmp.refine = refine;
  1226. item_tmp.attribute = attr;
  1227. item_tmp.card[0] = c1;
  1228. item_tmp.card[1] = c2;
  1229. item_tmp.card[2] = c3;
  1230. item_tmp.card[3] = c4;
  1231. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1232. clif_additem(sd, 0, 0, flag);
  1233. }
  1234. if (flag == 0)
  1235. clif_displaymessage(fd, msg_txt(18)); // Item created.
  1236. } else {
  1237. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  1238. return -1;
  1239. }
  1240. return 0;
  1241. }
  1242. /*==========================================
  1243. *
  1244. *------------------------------------------*/
  1245. ACMD_FUNC(itemreset)
  1246. {
  1247. int i;
  1248. nullpo_retr(-1, sd);
  1249. for (i = 0; i < MAX_INVENTORY; i++) {
  1250. if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) {
  1251. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_COMMAND);
  1252. }
  1253. }
  1254. clif_displaymessage(fd, msg_txt(20)); // All of your items have been removed.
  1255. return 0;
  1256. }
  1257. /*==========================================
  1258. * Atcommand @lvlup
  1259. *------------------------------------------*/
  1260. ACMD_FUNC(baselevelup)
  1261. {
  1262. int level=0, i=0, status_point=0;
  1263. nullpo_retr(-1, sd);
  1264. level = atoi(message);
  1265. if (!message || !*message || !level) {
  1266. clif_displaymessage(fd, msg_txt(986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).
  1267. return -1;
  1268. }
  1269. if (level > 0) {
  1270. if (sd->status.base_level >= pc_maxbaselv(sd)) { // check for max level by Valaris
  1271. clif_displaymessage(fd, msg_txt(47)); // Base level can't go any higher.
  1272. return -1;
  1273. } // End Addition
  1274. if ((unsigned int)level > pc_maxbaselv(sd) || (unsigned int)level > pc_maxbaselv(sd) - sd->status.base_level) // fix positiv overflow
  1275. level = pc_maxbaselv(sd) - sd->status.base_level;
  1276. for (i = 0; i < level; i++)
  1277. status_point += pc_gets_status_point(sd->status.base_level + i);
  1278. sd->status.status_point += status_point;
  1279. sd->status.base_level += (unsigned int)level;
  1280. status_percent_heal(&sd->bl, 100, 100);
  1281. clif_misceffect(&sd->bl, 0);
  1282. clif_displaymessage(fd, msg_txt(21)); // Base level raised.
  1283. } else {
  1284. if (sd->status.base_level == 1) {
  1285. clif_displaymessage(fd, msg_txt(158)); // Base level can't go any lower.
  1286. return -1;
  1287. }
  1288. level*=-1;
  1289. if ((unsigned int)level >= sd->status.base_level)
  1290. level = sd->status.base_level-1;
  1291. for (i = 0; i > -level; i--)
  1292. status_point += pc_gets_status_point(sd->status.base_level + i - 1);
  1293. if (sd->status.status_point < status_point)
  1294. pc_resetstate(sd);
  1295. if (sd->status.status_point < status_point)
  1296. sd->status.status_point = 0;
  1297. else
  1298. sd->status.status_point -= status_point;
  1299. sd->status.base_level -= (unsigned int)level;
  1300. clif_displaymessage(fd, msg_txt(22)); // Base level lowered.
  1301. }
  1302. sd->status.base_exp = 0;
  1303. clif_updatestatus(sd, SP_STATUSPOINT);
  1304. clif_updatestatus(sd, SP_BASELEVEL);
  1305. clif_updatestatus(sd, SP_BASEEXP);
  1306. clif_updatestatus(sd, SP_NEXTBASEEXP);
  1307. status_calc_pc(sd, 0);
  1308. pc_baselevelchanged(sd);
  1309. if(sd->status.party_id)
  1310. party_send_levelup(sd);
  1311. return 0;
  1312. }
  1313. /*==========================================
  1314. *
  1315. *------------------------------------------*/
  1316. ACMD_FUNC(joblevelup)
  1317. {
  1318. int level=0;
  1319. nullpo_retr(-1, sd);
  1320. level = atoi(message);
  1321. if (!message || !*message || !level) {
  1322. clif_displaymessage(fd, msg_txt(987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).
  1323. return -1;
  1324. }
  1325. if (level > 0) {
  1326. if (sd->status.job_level >= pc_maxjoblv(sd)) {
  1327. clif_displaymessage(fd, msg_txt(23)); // Job level can't go any higher.
  1328. return -1;
  1329. }
  1330. if ((unsigned int)level > pc_maxjoblv(sd) || (unsigned int)level > pc_maxjoblv(sd) - sd->status.job_level) // fix positiv overflow
  1331. level = pc_maxjoblv(sd) - sd->status.job_level;
  1332. sd->status.job_level += (unsigned int)level;
  1333. sd->status.skill_point += level;
  1334. clif_misceffect(&sd->bl, 1);
  1335. clif_displaymessage(fd, msg_txt(24)); // Job level raised.
  1336. } else {
  1337. if (sd->status.job_level == 1) {
  1338. clif_displaymessage(fd, msg_txt(159)); // Job level can't go any lower.
  1339. return -1;
  1340. }
  1341. level *=-1;
  1342. if ((unsigned int)level >= sd->status.job_level) // fix negativ overflow
  1343. level = sd->status.job_level-1;
  1344. sd->status.job_level -= (unsigned int)level;
  1345. if (sd->status.skill_point < level)
  1346. pc_resetskill(sd,0); //Reset skills since we need to substract more points.
  1347. if (sd->status.skill_point < level)
  1348. sd->status.skill_point = 0;
  1349. else
  1350. sd->status.skill_point -= level;
  1351. clif_displaymessage(fd, msg_txt(25)); // Job level lowered.
  1352. }
  1353. sd->status.job_exp = 0;
  1354. clif_updatestatus(sd, SP_JOBLEVEL);
  1355. clif_updatestatus(sd, SP_JOBEXP);
  1356. clif_updatestatus(sd, SP_NEXTJOBEXP);
  1357. clif_updatestatus(sd, SP_SKILLPOINT);
  1358. status_calc_pc(sd, 0);
  1359. return 0;
  1360. }
  1361. /*==========================================
  1362. * @help
  1363. *------------------------------------------*/
  1364. ACMD_FUNC(help)
  1365. {
  1366. config_setting_t *help;
  1367. const char *text = NULL;
  1368. const char *command_name = NULL;
  1369. char *default_command = "help";
  1370. nullpo_retr(-1, sd);
  1371. help = config_lookup(&atcommand_config, "help");
  1372. if (help == NULL) {
  1373. clif_displaymessage(fd, msg_txt(27)); // "Commands help is not available."
  1374. return -1;
  1375. }
  1376. if (!message || !*message) {
  1377. command_name = default_command; // If no command_name specified, display help for @help.
  1378. } else {
  1379. if (*message == atcommand_symbol || *message == charcommand_symbol)
  1380. ++message;
  1381. command_name = atcommand_checkalias(message);
  1382. }
  1383. if (!pc_can_use_command(sd, command_name, COMMAND_ATCOMMAND)) {
  1384. sprintf(atcmd_output, msg_txt(153), message); // "%s is Unknown Command"
  1385. clif_displaymessage(fd, atcmd_output);
  1386. atcommand_get_suggestions(sd, command_name, true);
  1387. return -1;
  1388. }
  1389. if (!config_setting_lookup_string(help, command_name, &text)) {
  1390. sprintf(atcmd_output, msg_txt(988), atcommand_symbol, command_name); // There is no help for %c%s.
  1391. clif_displaymessage(fd, atcmd_output);
  1392. atcommand_get_suggestions(sd, command_name, true);
  1393. return -1;
  1394. }
  1395. sprintf(atcmd_output, msg_txt(989), atcommand_symbol, command_name); // Help for command %c%s:
  1396. clif_displaymessage(fd, atcmd_output);
  1397. { // Display aliases
  1398. DBIterator* iter;
  1399. AtCommandInfo *command_info;
  1400. AliasInfo *alias_info = NULL;
  1401. StringBuf buf;
  1402. bool has_aliases = false;
  1403. StringBuf_Init(&buf);
  1404. StringBuf_AppendStr(&buf, msg_txt(990)); // Available aliases:
  1405. command_info = get_atcommandinfo_byname(command_name);
  1406. iter = db_iterator(atcommand_alias_db);
  1407. for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) {
  1408. if (alias_info->command == command_info) {
  1409. StringBuf_Printf(&buf, " %s", alias_info->alias);
  1410. has_aliases = true;
  1411. }
  1412. }
  1413. dbi_destroy(iter);
  1414. if (has_aliases)
  1415. clif_displaymessage(fd, StringBuf_Value(&buf));
  1416. StringBuf_Destroy(&buf);
  1417. }
  1418. // Display help contents
  1419. clif_displaymessage(fd, text);
  1420. return 0;
  1421. }
  1422. // helper function, used in foreach calls to stop auto-attack timers
  1423. // parameter: '0' - everyone, 'id' - only those attacking someone with that id
  1424. static int atcommand_stopattack(struct block_list *bl,va_list ap)
  1425. {
  1426. struct unit_data *ud = unit_bl2ud(bl);
  1427. int id = va_arg(ap, int);
  1428. if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target))
  1429. {
  1430. unit_stop_attack(bl);
  1431. return 1;
  1432. }
  1433. return 0;
  1434. }
  1435. /*==========================================
  1436. *
  1437. *------------------------------------------*/
  1438. static int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  1439. {
  1440. TBL_PC* sd = (TBL_PC*)bl;
  1441. clif_pvpset(sd, 0, 0, 2);
  1442. if (sd->pvp_timer != INVALID_TIMER) {
  1443. delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
  1444. sd->pvp_timer = INVALID_TIMER;
  1445. }
  1446. return 0;
  1447. }
  1448. ACMD_FUNC(pvpoff)
  1449. {
  1450. nullpo_retr(-1, sd);
  1451. if (!map[sd->bl.m].flag.pvp) {
  1452. clif_displaymessage(fd, msg_txt(160)); // PvP is already Off.
  1453. return -1;
  1454. }
  1455. map[sd->bl.m].flag.pvp = 0;
  1456. if (!battle_config.pk_mode)
  1457. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1458. map_foreachinmap(atcommand_pvpoff_sub,sd->bl.m, BL_PC);
  1459. map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1460. clif_displaymessage(fd, msg_txt(31)); // PvP: Off.
  1461. return 0;
  1462. }
  1463. /*==========================================
  1464. *
  1465. *------------------------------------------*/
  1466. static int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
  1467. {
  1468. TBL_PC* sd = (TBL_PC*)bl;
  1469. if (sd->pvp_timer == INVALID_TIMER) {
  1470. sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
  1471. sd->pvp_rank = 0;
  1472. sd->pvp_lastusers = 0;
  1473. sd->pvp_point = 5;
  1474. sd->pvp_won = 0;
  1475. sd->pvp_lost = 0;
  1476. }
  1477. return 0;
  1478. }
  1479. ACMD_FUNC(pvpon)
  1480. {
  1481. nullpo_retr(-1, sd);
  1482. if (map[sd->bl.m].flag.pvp) {
  1483. clif_displaymessage(fd, msg_txt(161)); // PvP is already On.
  1484. return -1;
  1485. }
  1486. map[sd->bl.m].flag.pvp = 1;
  1487. if (!battle_config.pk_mode)
  1488. {// display pvp circle and rank
  1489. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_FREEPVPZONE);
  1490. map_foreachinmap(atcommand_pvpon_sub,sd->bl.m, BL_PC);
  1491. }
  1492. clif_displaymessage(fd, msg_txt(32)); // PvP: On.
  1493. return 0;
  1494. }
  1495. /*==========================================
  1496. *
  1497. *------------------------------------------*/
  1498. ACMD_FUNC(gvgoff)
  1499. {
  1500. nullpo_retr(-1, sd);
  1501. if (!map[sd->bl.m].flag.gvg) {
  1502. clif_displaymessage(fd, msg_txt(162)); // GvG is already Off.
  1503. return -1;
  1504. }
  1505. map[sd->bl.m].flag.gvg = 0;
  1506. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1507. map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1508. clif_displaymessage(fd, msg_txt(33)); // GvG: Off.
  1509. return 0;
  1510. }
  1511. /*==========================================
  1512. *
  1513. *------------------------------------------*/
  1514. ACMD_FUNC(gvgon)
  1515. {
  1516. nullpo_retr(-1, sd);
  1517. if (map[sd->bl.m].flag.gvg) {
  1518. clif_displaymessage(fd, msg_txt(163)); // GvG is already On.
  1519. return -1;
  1520. }
  1521. map[sd->bl.m].flag.gvg = 1;
  1522. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE);
  1523. clif_displaymessage(fd, msg_txt(34)); // GvG: On.
  1524. return 0;
  1525. }
  1526. /*==========================================
  1527. *
  1528. *------------------------------------------*/
  1529. ACMD_FUNC(model)
  1530. {
  1531. int hair_style = 0, hair_color = 0, cloth_color = 0;
  1532. nullpo_retr(-1, sd);
  1533. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1534. if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) {
  1535. sprintf(atcmd_output, msg_txt(991), // Please enter at least one value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).
  1536. MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1537. clif_displaymessage(fd, atcmd_output);
  1538. return -1;
  1539. }
  1540. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
  1541. hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
  1542. cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1543. pc_changelook(sd, LOOK_HAIR, hair_style);
  1544. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1545. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1546. clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1547. } else {
  1548. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1549. return -1;
  1550. }
  1551. return 0;
  1552. }
  1553. /*==========================================
  1554. * @dye && @ccolor
  1555. *------------------------------------------*/
  1556. ACMD_FUNC(dye)
  1557. {
  1558. int cloth_color = 0;
  1559. nullpo_retr(-1, sd);
  1560. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1561. if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) {
  1562. sprintf(atcmd_output, msg_txt(992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).
  1563. clif_displaymessage(fd, atcmd_output);
  1564. return -1;
  1565. }
  1566. if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1567. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1568. clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1569. } else {
  1570. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1571. return -1;
  1572. }
  1573. return 0;
  1574. }
  1575. /*==========================================
  1576. * @hairstyle && @hstyle
  1577. *------------------------------------------*/
  1578. ACMD_FUNC(hair_style)
  1579. {
  1580. int hair_style = 0;
  1581. nullpo_retr(-1, sd);
  1582. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1583. if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) {
  1584. sprintf(atcmd_output, msg_txt(993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).
  1585. clif_displaymessage(fd, atcmd_output);
  1586. return -1;
  1587. }
  1588. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) {
  1589. pc_changelook(sd, LOOK_HAIR, hair_style);
  1590. clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1591. } else {
  1592. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1593. return -1;
  1594. }
  1595. return 0;
  1596. }
  1597. /*==========================================
  1598. * @haircolor && @hcolor
  1599. *------------------------------------------*/
  1600. ACMD_FUNC(hair_color)
  1601. {
  1602. int hair_color = 0;
  1603. nullpo_retr(-1, sd);
  1604. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1605. if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) {
  1606. sprintf(atcmd_output, msg_txt(994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).
  1607. clif_displaymessage(fd, atcmd_output);
  1608. return -1;
  1609. }
  1610. if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) {
  1611. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1612. clif_displaymessage(fd, msg_txt(36)); // Appearence changed.
  1613. } else {
  1614. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  1615. return -1;
  1616. }
  1617. return 0;
  1618. }
  1619. /*==========================================
  1620. * @go [city_number or city_name] - Updated by Harbin
  1621. *------------------------------------------*/
  1622. ACMD_FUNC(go)
  1623. {
  1624. int i;
  1625. int town;
  1626. char map_name[MAP_NAME_LENGTH];
  1627. int m;
  1628. const struct {
  1629. char map[MAP_NAME_LENGTH];
  1630. int x, y;
  1631. } data[] = {
  1632. { MAP_PRONTERA, 156, 191 }, // 0=Prontera
  1633. { MAP_MORROC, 156, 93 }, // 1=Morroc
  1634. { MAP_GEFFEN, 119, 59 }, // 2=Geffen
  1635. { MAP_PAYON, 162, 233 }, // 3=Payon
  1636. { MAP_ALBERTA, 192, 147 }, // 4=Alberta
  1637. #ifdef RENEWAL
  1638. { MAP_IZLUDE, 128, 146 }, // 5=Izlude (Renewal)
  1639. #else
  1640. { MAP_IZLUDE, 128, 114 }, // 5=Izlude
  1641. #endif
  1642. { MAP_ALDEBARAN, 140, 131 }, // 6=Al de Baran
  1643. { MAP_LUTIE, 147, 134 }, // 7=Lutie
  1644. { MAP_COMODO, 209, 143 }, // 8=Comodo
  1645. { MAP_YUNO, 157, 51 }, // 9=Yuno
  1646. { MAP_AMATSU, 198, 84 }, // 10=Amatsu
  1647. { MAP_GONRYUN, 160, 120 }, // 11=Gonryun
  1648. { MAP_UMBALA, 89, 157 }, // 12=Umbala
  1649. { MAP_NIFLHEIM, 21, 153 }, // 13=Niflheim
  1650. { MAP_LOUYANG, 217, 40 }, // 14=Louyang
  1651. { MAP_NOVICE, 53, 111 }, // 15=Training Grounds
  1652. { MAP_JAIL, 23, 61 }, // 16=Prison
  1653. { MAP_JAWAII, 249, 127 }, // 17=Jawaii
  1654. { MAP_AYOTHAYA, 151, 117 }, // 18=Ayothaya
  1655. { MAP_EINBROCH, 64, 200 }, // 19=Einbroch
  1656. { MAP_LIGHTHALZEN, 158, 92 }, // 20=Lighthalzen
  1657. { MAP_EINBECH, 70, 95 }, // 21=Einbech
  1658. { MAP_HUGEL, 96, 145 }, // 22=Hugel
  1659. { MAP_RACHEL, 130, 110 }, // 23=Rachel
  1660. { MAP_VEINS, 216, 123 }, // 24=Veins
  1661. { MAP_MOSCOVIA, 223, 184 }, // 25=Moscovia
  1662. { MAP_MIDCAMP, 180, 240 }, // 26=Midgard Camp
  1663. { MAP_MANUK, 282, 138 }, // 27=Manuk
  1664. { MAP_SPLENDIDE, 197, 176 }, // 28=Splendide
  1665. { MAP_BRASILIS, 182, 239 }, // 29=Brasilis
  1666. { MAP_DICASTES, 198, 187 }, // 30=El Dicastes
  1667. { MAP_MORA, 44, 151 }, // 31=Mora
  1668. { MAP_DEWATA, 200, 180 }, // 32=Dewata
  1669. { MAP_MALANGDO, 140, 114 }, // 33=Malangdo Island
  1670. { MAP_MALAYA, 242, 211 }, // 34=Malaya Port
  1671. { MAP_ECLAGE, 110, 39 }, // 35=Eclage
  1672. };
  1673. nullpo_retr(-1, sd);
  1674. if( map[sd->bl.m].flag.nogo && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  1675. clif_displaymessage(sd->fd,msg_txt(995)); // You cannot use @go on this map.
  1676. return 0;
  1677. }
  1678. memset(map_name, '\0', sizeof(map_name));
  1679. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1680. // get the number
  1681. town = atoi(message);
  1682. if (!message || !*message || sscanf(message, "%11s", map_name) < 1 || town < 0 || town >= ARRAYLENGTH(data))
  1683. {// no value matched so send the list of locations
  1684. const char* text;
  1685. // attempt to find the text help string
  1686. text = atcommand_help_string( command );
  1687. clif_displaymessage(fd, msg_txt(38)); // Invalid location number, or name.
  1688. if( text )
  1689. {// send the text to the client
  1690. clif_displaymessage( fd, text );
  1691. }
  1692. return -1;
  1693. }
  1694. // get possible name of the city
  1695. map_name[MAP_NAME_LENGTH-1] = '\0';
  1696. for (i = 0; map_name[i]; i++)
  1697. map_name[i] = TOLOWER(map_name[i]);
  1698. // try to identify the map name
  1699. if (strncmp(map_name, "prontera", 3) == 0) {
  1700. town = 0;
  1701. } else if (strncmp(map_name, "morocc", 4) == 0 ||
  1702. strncmp(map_name, "morroc", 4) == 0) {
  1703. town = 1;
  1704. } else if (strncmp(map_name, "geffen", 3) == 0) {
  1705. town = 2;
  1706. } else if (strncmp(map_name, "payon", 3) == 0) {
  1707. town = 3;
  1708. } else if (strncmp(map_name, "alberta", 3) == 0) {
  1709. town = 4;
  1710. } else if (strncmp(map_name, "izlude", 3) == 0) {
  1711. town = 5;
  1712. } else if (strncmp(map_name, "aldebaran", 3) == 0) {
  1713. town = 6;
  1714. } else if (strncmp(map_name, "lutie", 3) == 0 ||
  1715. strcmp(map_name, "christmas") == 0 ||
  1716. strncmp(map_name, "xmas", 3) == 0 ||
  1717. strncmp(map_name, "x-mas", 3) == 0) {
  1718. town = 7;
  1719. } else if (strncmp(map_name, "comodo", 3) == 0) {
  1720. town = 8;
  1721. } else if (strncmp(map_name, "juno", 3) == 0 ||
  1722. strncmp(map_name, "yuno", 3) == 0) {
  1723. town = 9;
  1724. } else if (strncmp(map_name, "amatsu", 3) == 0) {
  1725. town = 10;
  1726. } else if (strncmp(map_name, "kunlun", 3) == 0 ||
  1727. strncmp(map_name, "gonryun", 3) == 0) {
  1728. town = 11;
  1729. } else if (strncmp(map_name, "umbala", 3) == 0) {
  1730. town = 12;
  1731. } else if (strncmp(map_name, "niflheim", 3) == 0) {
  1732. town = 13;
  1733. } else if (strncmp(map_name, "louyang", 3) == 0) {
  1734. town = 14;
  1735. } else if (strncmp(map_name, "new_1-1", 3) == 0 ||
  1736. strncmp(map_name, "startpoint", 3) == 0 ||
  1737. strncmp(map_name, "beginning", 3) == 0) {
  1738. town = 15;
  1739. } else if (strncmp(map_name, "sec_pri", 3) == 0 ||
  1740. strncmp(map_name, "prison", 3) == 0 ||
  1741. strncmp(map_name, "jail", 3) == 0) {
  1742. town = 16;
  1743. } else if (strncmp(map_name, "jawaii", 3) == 0) {
  1744. town = 17;
  1745. } else if (strncmp(map_name, "ayothaya", 3) == 0) {
  1746. town = 18;
  1747. } else if (strncmp(map_name, "einbroch", 5) == 0) {
  1748. town = 19;
  1749. } else if (strncmp(map_name, "lighthalzen", 3) == 0) {
  1750. town = 20;
  1751. } else if (strncmp(map_name, "einbech", 5) == 0) {
  1752. town = 21;
  1753. } else if (strncmp(map_name, "hugel", 3) == 0) {
  1754. town = 22;
  1755. } else if (strncmp(map_name, "rachel", 3) == 0) {
  1756. town = 23;
  1757. } else if (strncmp(map_name, "veins", 3) == 0) {
  1758. town = 24;
  1759. } else if (strncmp(map_name, "moscovia", 3) == 0) {
  1760. town = 25;
  1761. } else if (strncmp(map_name, "mid_camp", 3) == 0) {
  1762. town = 26;
  1763. } else if (strncmp(map_name, "manuk", 3) == 0) {
  1764. town = 27;
  1765. } else if (strncmp(map_name, "splendide", 3) == 0) {
  1766. town = 28;
  1767. } else if (strncmp(map_name, "brasilis", 3) == 0) {
  1768. town = 29;
  1769. } else if (strncmp(map_name, "dicastes01", 3) == 0) {
  1770. town = 30;
  1771. } else if (strcmp(map_name, "mora") == 0) {
  1772. town = 31;
  1773. } else if (strncmp(map_name, "dewata", 3) == 0) {
  1774. town = 32;
  1775. } else if (strncmp(map_name, "malangdo", 5) == 0) {
  1776. town = 33;
  1777. } else if (strncmp(map_name, "malaya", 5) == 0) {
  1778. town = 34;
  1779. } else if (strncmp(map_name, "eclage", 3) == 0) {
  1780. town = 35;
  1781. }
  1782. if (town >= 0 && town < ARRAYLENGTH(data))
  1783. {
  1784. m = map_mapname2mapid(data[town].map);
  1785. if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1786. clif_displaymessage(fd, msg_txt(247));
  1787. return -1;
  1788. }
  1789. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1790. clif_displaymessage(fd, msg_txt(248));
  1791. return -1;
  1792. }
  1793. if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) {
  1794. clif_displaymessage(fd, msg_txt(0)); // Warped.
  1795. } else {
  1796. clif_displaymessage(fd, msg_txt(1)); // Map not found.
  1797. return -1;
  1798. }
  1799. } else { // if you arrive here, you have an error in town variable when reading of names
  1800. clif_displaymessage(fd, msg_txt(38)); // Invalid location number or name.
  1801. return -1;
  1802. }
  1803. return 0;
  1804. }
  1805. /*==========================================
  1806. *
  1807. *------------------------------------------*/
  1808. ACMD_FUNC(monster)
  1809. {
  1810. char name[NAME_LENGTH];
  1811. char monster[NAME_LENGTH];
  1812. char eventname[EVENT_NAME_LENGTH] = "";
  1813. int mob_id;
  1814. int number = 0;
  1815. int count;
  1816. int i, k, range;
  1817. short mx, my;
  1818. unsigned int size;
  1819. nullpo_retr(-1, sd);
  1820. memset(name, '\0', sizeof(name));
  1821. memset(monster, '\0', sizeof(monster));
  1822. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1823. if (!message || !*message) {
  1824. clif_displaymessage(fd, msg_txt(80)); // Give the display name or monster name/id please.
  1825. return -1;
  1826. }
  1827. if (sscanf(message, "\"%23[^\"]\" %23s %d", name, monster, &number) > 1 ||
  1828. sscanf(message, "%23s \"%23[^\"]\" %d", monster, name, &number) > 1) {
  1829. //All data can be left as it is.
  1830. } else if ((count=sscanf(message, "%23s %d %23s", monster, &number, name)) > 1) {
  1831. //Here, it is possible name was not given and we are using monster for it.
  1832. if (count < 3) //Blank mob's name.
  1833. name[0] = '\0';
  1834. } else if (sscanf(message, "%23s %23s %d", name, monster, &number) > 1) {
  1835. //All data can be left as it is.
  1836. } else if (sscanf(message, "%23s", monster) > 0) {
  1837. //As before, name may be already filled.
  1838. name[0] = '\0';
  1839. } else {
  1840. clif_displaymessage(fd, msg_txt(80)); // Give a display name and monster name/id please.
  1841. return -1;
  1842. }
  1843. if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
  1844. mob_id = mobdb_checkid(atoi(monster));
  1845. if (mob_id == 0) {
  1846. clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  1847. return -1;
  1848. }
  1849. if (mob_id == MOBID_EMPERIUM) {
  1850. clif_displaymessage(fd, msg_txt(83)); // Monster 'Emperium' cannot be spawned.
  1851. return -1;
  1852. }
  1853. if (number <= 0)
  1854. number = 1;
  1855. if( !name[0] )
  1856. strcpy(name, "--ja--");
  1857. // 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
  1858. if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit)
  1859. number = battle_config.atc_spawn_quantity_limit;
  1860. if (strcmp(command+1, "monstersmall") == 0)
  1861. size = SZ_MEDIUM; // This is just gorgeous [mkbu95]
  1862. else if (strcmp(command+1, "monsterbig") == 0)
  1863. size = SZ_BIG;
  1864. else
  1865. size = SZ_SMALL;
  1866. if (battle_config.etc_log)
  1867. 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);
  1868. count = 0;
  1869. range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
  1870. for (i = 0; i < number; i++) {
  1871. map_search_freecell(&sd->bl, 0, &mx, &my, range, range, 0);
  1872. k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE);
  1873. count += (k != 0) ? 1 : 0;
  1874. }
  1875. if (count != 0)
  1876. if (number == count)
  1877. clif_displaymessage(fd, msg_txt(39)); // All monster summoned!
  1878. else {
  1879. sprintf(atcmd_output, msg_txt(240), count); // %d monster(s) summoned!
  1880. clif_displaymessage(fd, atcmd_output);
  1881. }
  1882. else {
  1883. clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  1884. return -1;
  1885. }
  1886. return 0;
  1887. }
  1888. /*==========================================
  1889. *
  1890. *------------------------------------------*/
  1891. static int atkillmonster_sub(struct block_list *bl, va_list ap)
  1892. {
  1893. struct mob_data *md;
  1894. int flag;
  1895. nullpo_ret(md=(struct mob_data *)bl);
  1896. flag = va_arg(ap, int);
  1897. if (md->guardian_data)
  1898. return 0; //Do not touch WoE mobs!
  1899. if (flag)
  1900. status_zap(bl,md->status.hp, 0);
  1901. else
  1902. status_kill(bl);
  1903. return 1;
  1904. }
  1905. ACMD_FUNC(killmonster)
  1906. {
  1907. int map_id, drop_flag;
  1908. char map_name[MAP_NAME_LENGTH_EXT];
  1909. nullpo_retr(-1, sd);
  1910. memset(map_name, '\0', sizeof(map_name));
  1911. if (!message || !*message || sscanf(message, "%15s", map_name) < 1)
  1912. map_id = sd->bl.m;
  1913. else {
  1914. if ((map_id = map_mapname2mapid(map_name)) < 0)
  1915. map_id = sd->bl.m;
  1916. }
  1917. drop_flag = strcmp(command+1, "killmonster2");
  1918. map_foreachinmap(atkillmonster_sub, map_id, BL_MOB, -drop_flag);
  1919. clif_displaymessage(fd, msg_txt(165)); // All monsters killed!
  1920. return 0;
  1921. }
  1922. /*==========================================
  1923. *
  1924. *------------------------------------------*/
  1925. ACMD_FUNC(refine)
  1926. {
  1927. int i,j, position = 0, refine = 0, current_position, final_refine;
  1928. int count;
  1929. nullpo_retr(-1, sd);
  1930. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1931. if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) {
  1932. clif_displaymessage(fd, msg_txt(996)); // Please enter a position and an amount (usage: @refine <equip position> <+/- amount>).
  1933. sprintf(atcmd_output, msg_txt(997), EQP_HEAD_LOW); // %d: Lower Headgear
  1934. clif_displaymessage(fd, atcmd_output);
  1935. sprintf(atcmd_output, msg_txt(998), EQP_HAND_R); // %d: Right Hand
  1936. clif_displaymessage(fd, atcmd_output);
  1937. sprintf(atcmd_output, msg_txt(999), EQP_GARMENT); // %d: Garment
  1938. clif_displaymessage(fd, atcmd_output);
  1939. sprintf(atcmd_output, msg_txt(1000), EQP_ACC_L); // %d: Left Accessory
  1940. clif_displaymessage(fd, atcmd_output);
  1941. sprintf(atcmd_output, msg_txt(1001), EQP_ARMOR); // %d: Body Armor
  1942. clif_displaymessage(fd, atcmd_output);
  1943. sprintf(atcmd_output, msg_txt(1002), EQP_HAND_L); // %d: Left Hand
  1944. clif_displaymessage(fd, atcmd_output);
  1945. sprintf(atcmd_output, msg_txt(1003), EQP_SHOES); // %d: Shoes
  1946. clif_displaymessage(fd, atcmd_output);
  1947. sprintf(atcmd_output, msg_txt(1004), EQP_ACC_R); // %d: Right Accessory
  1948. clif_displaymessage(fd, atcmd_output);
  1949. sprintf(atcmd_output, msg_txt(1005), EQP_HEAD_TOP); // %d: Top Headgear
  1950. clif_displaymessage(fd, atcmd_output);
  1951. sprintf(atcmd_output, msg_txt(1006), EQP_HEAD_MID); // %d: Mid Headgear
  1952. clif_displaymessage(fd, atcmd_output);
  1953. return -1;
  1954. }
  1955. refine = cap_value(refine, -MAX_REFINE, MAX_REFINE);
  1956. count = 0;
  1957. for (j = 0; j < EQI_MAX-1; j++) {
  1958. if ((i = sd->equip_index[j]) < 0)
  1959. continue;
  1960. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == i)
  1961. continue;
  1962. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == i)
  1963. continue;
  1964. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i))
  1965. continue;
  1966. if(position && !(sd->status.inventory[i].equip & position))
  1967. continue;
  1968. final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE);
  1969. if (sd->status.inventory[i].refine != final_refine) {
  1970. sd->status.inventory[i].refine = final_refine;
  1971. current_position = sd->status.inventory[i].equip;
  1972. pc_unequipitem(sd, i, 3);
  1973. clif_refine(fd, 0, i, sd->status.inventory[i].refine);
  1974. clif_delitem(sd, i, 1, 3);
  1975. clif_additem(sd, i, 1, 0);
  1976. pc_equipitem(sd, i, current_position);
  1977. clif_misceffect(&sd->bl, 3);
  1978. count++;
  1979. }
  1980. }
  1981. if (count == 0)
  1982. clif_displaymessage(fd, msg_txt(166)); // No item has been refined.
  1983. else if (count == 1)
  1984. clif_displaymessage(fd, msg_txt(167)); // 1 item has been refined.
  1985. else {
  1986. sprintf(atcmd_output, msg_txt(168), count); // %d items have been refined.
  1987. clif_displaymessage(fd, atcmd_output);
  1988. }
  1989. return 0;
  1990. }
  1991. /*==========================================
  1992. *
  1993. *------------------------------------------*/
  1994. ACMD_FUNC(produce)
  1995. {
  1996. char item_name[100];
  1997. int item_id, attribute = 0, star = 0;
  1998. int flag = 0;
  1999. struct item_data *item_data;
  2000. struct item tmp_item;
  2001. nullpo_retr(-1, sd);
  2002. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2003. memset(item_name, '\0', sizeof(item_name));
  2004. if (!message || !*message || (
  2005. sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 &&
  2006. sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1
  2007. )) {
  2008. clif_displaymessage(fd, msg_txt(1007)); // Please enter at least one item name/ID (usage: @produce <equip name/ID> <element> <# of very's>).
  2009. return -1;
  2010. }
  2011. if ( (item_data = itemdb_searchname(item_name)) == NULL &&
  2012. (item_data = itemdb_exists(atoi(item_name))) == NULL ) {
  2013. clif_displaymessage(fd, msg_txt(170)); //This item is not an equipment.
  2014. return -1;
  2015. }
  2016. item_id = item_data->nameid;
  2017. if (itemdb_isequip2(item_data)) {
  2018. if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
  2019. attribute = ATTRIBUTE_NORMAL;
  2020. if (star < MIN_STAR || star > MAX_STAR)
  2021. star = 0;
  2022. memset(&tmp_item, 0, sizeof tmp_item);
  2023. tmp_item.nameid = item_id;
  2024. tmp_item.amount = 1;
  2025. tmp_item.identify = 1;
  2026. tmp_item.card[0] = CARD0_FORGE;
  2027. tmp_item.card[1] = item_data->type==IT_WEAPON?
  2028. ((star*5) << 8) + attribute:0;
  2029. tmp_item.card[2] = GetWord(sd->status.char_id, 0);
  2030. tmp_item.card[3] = GetWord(sd->status.char_id, 1);
  2031. clif_produceeffect(sd, 0, item_id);
  2032. clif_misceffect(&sd->bl, 3);
  2033. if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  2034. clif_additem(sd, 0, 0, flag);
  2035. } else {
  2036. sprintf(atcmd_output, msg_txt(169), item_id, item_data->name); // The item (%d: '%s') is not equipable.
  2037. clif_displaymessage(fd, atcmd_output);
  2038. return -1;
  2039. }
  2040. return 0;
  2041. }
  2042. /*==========================================
  2043. *
  2044. *------------------------------------------*/
  2045. ACMD_FUNC(memo)
  2046. {
  2047. int position = 0;
  2048. nullpo_retr(-1, sd);
  2049. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2050. if( !message || !*message || sscanf(message, "%d", &position) < 1 )
  2051. {
  2052. int i;
  2053. clif_displaymessage(sd->fd, msg_txt(668));
  2054. for( i = 0; i < MAX_MEMOPOINTS; i++ )
  2055. {
  2056. if( sd->status.memo_point[i].map )
  2057. sprintf(atcmd_output, "%d - %s (%d,%d)", i, mapindex_id2name(sd->status.memo_point[i].map), sd->status.memo_point[i].x, sd->status.memo_point[i].y);
  2058. else
  2059. sprintf(atcmd_output, msg_txt(171), i); // %d - void
  2060. clif_displaymessage(sd->fd, atcmd_output);
  2061. }
  2062. return 0;
  2063. }
  2064. if( position < 0 || position >= MAX_MEMOPOINTS )
  2065. {
  2066. sprintf(atcmd_output, msg_txt(1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo <memo_position:%d-%d>).
  2067. clif_displaymessage(fd, atcmd_output);
  2068. return -1;
  2069. }
  2070. pc_memo(sd, position);
  2071. return 0;
  2072. }
  2073. /*==========================================
  2074. *
  2075. *------------------------------------------*/
  2076. ACMD_FUNC(gat)
  2077. {
  2078. int y;
  2079. nullpo_retr(-1, sd);
  2080. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2081. for (y = 2; y >= -2; y--) {
  2082. sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
  2083. map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
  2084. map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE),
  2085. map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE),
  2086. map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y, CELL_GETTYPE),
  2087. map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE),
  2088. map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE));
  2089. clif_displaymessage(fd, atcmd_output);
  2090. }
  2091. return 0;
  2092. }
  2093. /*==========================================
  2094. *
  2095. *------------------------------------------*/
  2096. ACMD_FUNC(displaystatus)
  2097. {
  2098. int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0;
  2099. nullpo_retr(-1, sd);
  2100. if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) {
  2101. clif_displaymessage(fd, msg_txt(1009)); // Please enter a status type/flag (usage: @displaystatus <status type> <flag> <tick> {<val1> {<val2> {<val3>}}}).
  2102. return -1;
  2103. }
  2104. if (i < 2) flag = 1;
  2105. if (i < 3) tick = 0;
  2106. clif_status_change(&sd->bl, type, flag, tick, val1, val2, val3);
  2107. return 0;
  2108. }
  2109. /*==========================================
  2110. * @stpoint (Rewritten by [Yor])
  2111. *------------------------------------------*/
  2112. ACMD_FUNC(statuspoint)
  2113. {
  2114. int point;
  2115. unsigned int new_status_point;
  2116. if (!message || !*message || (point = atoi(message)) == 0) {
  2117. clif_displaymessage(fd, msg_txt(1010)); // Please enter a number (usage: @stpoint <number of points>).
  2118. return -1;
  2119. }
  2120. if(point < 0)
  2121. {
  2122. if(sd->status.status_point < (unsigned int)(-point))
  2123. {
  2124. new_status_point = 0;
  2125. }
  2126. else
  2127. {
  2128. new_status_point = sd->status.status_point + point;
  2129. }
  2130. }
  2131. else if(UINT_MAX - sd->status.status_point < (unsigned int)point)
  2132. {
  2133. new_status_point = UINT_MAX;
  2134. }
  2135. else
  2136. {
  2137. new_status_point = sd->status.status_point + point;
  2138. }
  2139. if (new_status_point != sd->status.status_point) {
  2140. sd->status.status_point = new_status_point;
  2141. clif_updatestatus(sd, SP_STATUSPOINT);
  2142. clif_displaymessage(fd, msg_txt(174)); // Number of status points changed.
  2143. } else {
  2144. if (point < 0)
  2145. clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2146. else
  2147. clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2148. return -1;
  2149. }
  2150. return 0;
  2151. }
  2152. /*==========================================
  2153. * @skpoint (Rewritten by [Yor])
  2154. *------------------------------------------*/
  2155. ACMD_FUNC(skillpoint)
  2156. {
  2157. int point;
  2158. unsigned int new_skill_point;
  2159. nullpo_retr(-1, sd);
  2160. if (!message || !*message || (point = atoi(message)) == 0) {
  2161. clif_displaymessage(fd, msg_txt(1011)); // Please enter a number (usage: @skpoint <number of points>).
  2162. return -1;
  2163. }
  2164. if(point < 0)
  2165. {
  2166. if(sd->status.skill_point < (unsigned int)(-point))
  2167. {
  2168. new_skill_point = 0;
  2169. }
  2170. else
  2171. {
  2172. new_skill_point = sd->status.skill_point + point;
  2173. }
  2174. }
  2175. else if(UINT_MAX - sd->status.skill_point < (unsigned int)point)
  2176. {
  2177. new_skill_point = UINT_MAX;
  2178. }
  2179. else
  2180. {
  2181. new_skill_point = sd->status.skill_point + point;
  2182. }
  2183. if (new_skill_point != sd->status.skill_point) {
  2184. sd->status.skill_point = new_skill_point;
  2185. clif_updatestatus(sd, SP_SKILLPOINT);
  2186. clif_displaymessage(fd, msg_txt(175)); // Number of skill points changed.
  2187. } else {
  2188. if (point < 0)
  2189. clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2190. else
  2191. clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2192. return -1;
  2193. }
  2194. return 0;
  2195. }
  2196. /*==========================================
  2197. * @zeny (Rewritten by [Yor])
  2198. *------------------------------------------*/
  2199. ACMD_FUNC(zeny)
  2200. {
  2201. int zeny;
  2202. nullpo_retr(-1, sd);
  2203. if (!message || !*message || (zeny = atoi(message)) == 0) {
  2204. clif_displaymessage(fd, msg_txt(1012)); // Please enter an amount (usage: @zeny <amount>).
  2205. return -1;
  2206. }
  2207. if(zeny > 0)
  2208. pc_getzeny(sd,zeny,LOG_TYPE_COMMAND,NULL);
  2209. else
  2210. pc_payzeny(sd,zeny,LOG_TYPE_COMMAND,NULL);
  2211. return 0;
  2212. }
  2213. /*==========================================
  2214. *
  2215. *------------------------------------------*/
  2216. ACMD_FUNC(param)
  2217. {
  2218. int i, value = 0, new_value, max;
  2219. const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" };
  2220. short* status[6];
  2221. //we don't use direct initialization because it isn't part of the c standard.
  2222. nullpo_retr(-1, sd);
  2223. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2224. if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2225. clif_displaymessage(fd, msg_txt(1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2226. return -1;
  2227. }
  2228. ARR_FIND( 0, ARRAYLENGTH(param), i, strcmpi(command+1, param[i]) == 0 );
  2229. if( i == ARRAYLENGTH(param) || i > MAX_STATUS_TYPE) { // normally impossible...
  2230. clif_displaymessage(fd, msg_txt(1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2231. return -1;
  2232. }
  2233. status[0] = &sd->status.str;
  2234. status[1] = &sd->status.agi;
  2235. status[2] = &sd->status.vit;
  2236. status[3] = &sd->status.int_;
  2237. status[4] = &sd->status.dex;
  2238. status[5] = &sd->status.luk;
  2239. if( battle_config.atcommand_max_stat_bypass )
  2240. max = SHRT_MAX;
  2241. else
  2242. max = pc_maxparameter(sd);
  2243. if(value < 0 && *status[i] <= -value) {
  2244. new_value = 1;
  2245. } else if(max - *status[i] < value) {
  2246. new_value = max;
  2247. } else {
  2248. new_value = *status[i] + value;
  2249. }
  2250. if (new_value != *status[i]) {
  2251. *status[i] = new_value;
  2252. clif_updatestatus(sd, SP_STR + i);
  2253. clif_updatestatus(sd, SP_USTR + i);
  2254. status_calc_pc(sd, 0);
  2255. clif_displaymessage(fd, msg_txt(42)); // Stat changed.
  2256. } else {
  2257. if (value < 0)
  2258. clif_displaymessage(fd, msg_txt(41)); // Unable to decrease the number/value.
  2259. else
  2260. clif_displaymessage(fd, msg_txt(149)); // Unable to increase the number/value.
  2261. return -1;
  2262. }
  2263. return 0;
  2264. }
  2265. /*==========================================
  2266. * Stat all by fritz (rewritten by [Yor])
  2267. *------------------------------------------*/
  2268. ACMD_FUNC(stat_all)
  2269. {
  2270. int index, count, value, max, new_value;
  2271. short* status[6];
  2272. //we don't use direct initialization because it isn't part of the c standard.
  2273. nullpo_retr(-1, sd);
  2274. status[0] = &sd->status.str;
  2275. status[1] = &sd->status.agi;
  2276. status[2] = &sd->status.vit;
  2277. status[3] = &sd->status.int_;
  2278. status[4] = &sd->status.dex;
  2279. status[5] = &sd->status.luk;
  2280. if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2281. value = pc_maxparameter(sd);
  2282. max = pc_maxparameter(sd);
  2283. } else {
  2284. if( battle_config.atcommand_max_stat_bypass )
  2285. max = SHRT_MAX;
  2286. else
  2287. max = pc_maxparameter(sd);
  2288. }
  2289. count = 0;
  2290. for (index = 0; index < ARRAYLENGTH(status); index++) {
  2291. if (value > 0 && *status[index] > max - value)
  2292. new_value = max;
  2293. else if (value < 0 && *status[index] <= -value)
  2294. new_value = 1;
  2295. else
  2296. new_value = *status[index] +value;
  2297. if (new_value != (int)*status[index]) {
  2298. *status[index] = new_value;
  2299. clif_updatestatus(sd, SP_STR + index);
  2300. clif_updatestatus(sd, SP_USTR + index);
  2301. count++;
  2302. }
  2303. }
  2304. if (count > 0) { // if at least 1 stat modified
  2305. status_calc_pc(sd, 0);
  2306. clif_displaymessage(fd, msg_txt(84)); // All stats changed!
  2307. } else {
  2308. if (value < 0)
  2309. clif_displaymessage(fd, msg_txt(177)); // You cannot decrease that stat anymore.
  2310. else
  2311. clif_displaymessage(fd, msg_txt(178)); // You cannot increase that stat anymore.
  2312. return -1;
  2313. }
  2314. return 0;
  2315. }
  2316. /*==========================================
  2317. *
  2318. *------------------------------------------*/
  2319. ACMD_FUNC(guildlevelup)
  2320. {
  2321. int level = 0;
  2322. short added_level;
  2323. struct guild *guild_info;
  2324. nullpo_retr(-1, sd);
  2325. if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) {
  2326. clif_displaymessage(fd, msg_txt(1014)); // Please enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>).
  2327. return -1;
  2328. }
  2329. if (sd->status.guild_id <= 0 || (guild_info = guild_search(sd->status.guild_id)) == NULL) {
  2330. clif_displaymessage(fd, msg_txt(43)); // You're not in a guild.
  2331. return -1;
  2332. }
  2333. //if (strcmp(sd->status.name, guild_info->master) != 0) {
  2334. // clif_displaymessage(fd, msg_txt(44)); // You're not the master of your guild.
  2335. // return -1;
  2336. //}
  2337. added_level = (short)level;
  2338. if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positiv overflow
  2339. added_level = (short)MAX_GUILDLEVEL - guild_info->guild_lv;
  2340. else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negativ overflow
  2341. added_level = 1 - guild_info->guild_lv;
  2342. if (added_level != 0) {
  2343. intif_guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level));
  2344. clif_displaymessage(fd, msg_txt(179)); // Guild level changed.
  2345. } else {
  2346. clif_displaymessage(fd, msg_txt(45)); // Guild level change failed.
  2347. return -1;
  2348. }
  2349. return 0;
  2350. }
  2351. /*==========================================
  2352. *
  2353. *------------------------------------------*/
  2354. ACMD_FUNC(makeegg)
  2355. {
  2356. struct item_data *item_data;
  2357. int id, pet_id;
  2358. nullpo_retr(-1, sd);
  2359. if (!message || !*message) {
  2360. clif_displaymessage(fd, msg_txt(1015)); // Please enter a monster/egg name/ID (usage: @makeegg <pet>).
  2361. return -1;
  2362. }
  2363. if ((item_data = itemdb_searchname(message)) != NULL) // for egg name
  2364. id = item_data->nameid;
  2365. else
  2366. if ((id = mobdb_searchname(message)) != 0) // for monster name
  2367. ;
  2368. else
  2369. id = atoi(message);
  2370. pet_id = search_petDB_index(id, PET_CLASS);
  2371. if (pet_id < 0)
  2372. pet_id = search_petDB_index(id, PET_EGG);
  2373. if (pet_id >= 0) {
  2374. sd->catch_target_class = pet_db[pet_id].class_;
  2375. intif_create_pet(
  2376. sd->status.account_id, sd->status.char_id,
  2377. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  2378. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  2379. 100, 0, 1, pet_db[pet_id].jname);
  2380. } else {
  2381. clif_displaymessage(fd, msg_txt(180)); // The monster/egg name/id doesn't exist.
  2382. return -1;
  2383. }
  2384. return 0;
  2385. }
  2386. /*==========================================
  2387. *
  2388. *------------------------------------------*/
  2389. ACMD_FUNC(hatch)
  2390. {
  2391. nullpo_retr(-1, sd);
  2392. if (sd->status.pet_id <= 0)
  2393. clif_sendegg(sd);
  2394. else {
  2395. clif_displaymessage(fd, msg_txt(181)); // You already have a pet.
  2396. return -1;
  2397. }
  2398. return 0;
  2399. }
  2400. /*==========================================
  2401. *
  2402. *------------------------------------------*/
  2403. ACMD_FUNC(petfriendly)
  2404. {
  2405. int friendly;
  2406. struct pet_data *pd;
  2407. nullpo_retr(-1, sd);
  2408. if (!message || !*message || (friendly = atoi(message)) < 0) {
  2409. clif_displaymessage(fd, msg_txt(1016)); // Please enter a valid value (usage: @petfriendly <0-1000>).
  2410. return -1;
  2411. }
  2412. pd = sd->pd;
  2413. if (!pd) {
  2414. clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2415. return -1;
  2416. }
  2417. if (friendly < 0 || friendly > 1000)
  2418. {
  2419. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2420. return -1;
  2421. }
  2422. if (friendly == pd->pet.intimate) {
  2423. clif_displaymessage(fd, msg_txt(183)); // Pet intimacy is already at maximum.
  2424. return -1;
  2425. }
  2426. pet_set_intimate(pd, friendly);
  2427. clif_send_petstatus(sd);
  2428. clif_displaymessage(fd, msg_txt(182)); // Pet intimacy changed.
  2429. return 0;
  2430. }
  2431. /*==========================================
  2432. *
  2433. *------------------------------------------*/
  2434. ACMD_FUNC(pethungry)
  2435. {
  2436. int hungry;
  2437. struct pet_data *pd;
  2438. nullpo_retr(-1, sd);
  2439. if (!message || !*message || (hungry = atoi(message)) < 0) {
  2440. clif_displaymessage(fd, msg_txt(1017)); // Please enter a valid number (usage: @pethungry <0-100>).
  2441. return -1;
  2442. }
  2443. pd = sd->pd;
  2444. if (!sd->status.pet_id || !pd) {
  2445. clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2446. return -1;
  2447. }
  2448. if (hungry < 0 || hungry > 100) {
  2449. clif_displaymessage(fd, msg_txt(37)); // An invalid number was specified.
  2450. return -1;
  2451. }
  2452. if (hungry == pd->pet.hungry) {
  2453. clif_displaymessage(fd, msg_txt(186)); // Pet hunger is already at maximum.
  2454. return -1;
  2455. }
  2456. pd->pet.hungry = hungry;
  2457. clif_send_petstatus(sd);
  2458. clif_displaymessage(fd, msg_txt(185)); // Pet hunger changed.
  2459. return 0;
  2460. }
  2461. /*==========================================
  2462. *
  2463. *------------------------------------------*/
  2464. ACMD_FUNC(petrename)
  2465. {
  2466. struct pet_data *pd;
  2467. nullpo_retr(-1, sd);
  2468. if (!sd->status.pet_id || !sd->pd) {
  2469. clif_displaymessage(fd, msg_txt(184)); // Sorry, but you have no pet.
  2470. return -1;
  2471. }
  2472. pd = sd->pd;
  2473. if (!pd->pet.rename_flag) {
  2474. clif_displaymessage(fd, msg_txt(188)); // You can already rename your pet.
  2475. return -1;
  2476. }
  2477. pd->pet.rename_flag = 0;
  2478. intif_save_petdata(sd->status.account_id, &pd->pet);
  2479. clif_send_petstatus(sd);
  2480. clif_displaymessage(fd, msg_txt(187)); // You can now rename your pet.
  2481. return 0;
  2482. }
  2483. /*==========================================
  2484. *
  2485. *------------------------------------------*/
  2486. ACMD_FUNC(recall) {
  2487. struct map_session_data *pl_sd = NULL;
  2488. nullpo_retr(-1, sd);
  2489. if (!message || !*message) {
  2490. clif_displaymessage(fd, msg_txt(1018)); // Please enter a player name (usage: @recall <char name/ID>).
  2491. return -1;
  2492. }
  2493. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2494. {
  2495. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  2496. return -1;
  2497. }
  2498. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  2499. {
  2500. clif_displaymessage(fd, msg_txt(81)); // Your GM level doesn't authorize you to preform this action on the specified player.
  2501. return -1;
  2502. }
  2503. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2504. clif_displaymessage(fd, msg_txt(1019)); // You are not authorized to warp someone to this map.
  2505. return -1;
  2506. }
  2507. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2508. clif_displaymessage(fd, msg_txt(1020)); // You are not authorized to warp this player from their map.
  2509. return -1;
  2510. }
  2511. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  2512. sprintf(atcmd_output, msg_txt(46), pl_sd->status.name); // %s recalled!
  2513. clif_displaymessage(fd, atcmd_output);
  2514. return 0;
  2515. }
  2516. /*==========================================
  2517. * charblock command (usage: charblock <player_name>)
  2518. * This command do a definitiv ban on a player
  2519. *------------------------------------------*/
  2520. ACMD_FUNC(char_block)
  2521. {
  2522. nullpo_retr(-1, sd);
  2523. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2524. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2525. clif_displaymessage(fd, msg_txt(1021)); // Please enter a player name (usage: @charblock/@block <char name>).
  2526. return -1;
  2527. }
  2528. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  2529. clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  2530. return 0;
  2531. }
  2532. /*==========================================
  2533. * charban command (usage: charban <time> <player_name>)
  2534. * This command do a limited ban on a player
  2535. * Time is done as follows:
  2536. * Adjustment value (-1, 1, +1, etc...)
  2537. * Modified element:
  2538. * a or y: year
  2539. * m: month
  2540. * j or d: day
  2541. * h: hour
  2542. * mn: minute
  2543. * s: second
  2544. * <example> @ban +1m-2mn1s-6y test_player
  2545. * this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
  2546. *------------------------------------------*/
  2547. ACMD_FUNC(char_ban)
  2548. {
  2549. char * modif_p;
  2550. int year, month, day, hour, minute, second, value;
  2551. time_t timestamp;
  2552. struct tm *tmtime;
  2553. nullpo_retr(-1, sd);
  2554. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2555. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2556. if (!message || !*message || sscanf(message, "%s %23[^\n]", atcmd_output, atcmd_player_name) < 2) {
  2557. clif_displaymessage(fd, msg_txt(1022)); // Please enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish <time> <char name>).
  2558. return -1;
  2559. }
  2560. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  2561. modif_p = atcmd_output;
  2562. year = month = day = hour = minute = second = 0;
  2563. while (modif_p[0] != '\0') {
  2564. value = atoi(modif_p);
  2565. if (value == 0)
  2566. modif_p++;
  2567. else {
  2568. if (modif_p[0] == '-' || modif_p[0] == '+')
  2569. modif_p++;
  2570. while (modif_p[0] >= '0' && modif_p[0] <= '9')
  2571. modif_p++;
  2572. if (modif_p[0] == 's') {
  2573. second = value;
  2574. modif_p++;
  2575. } else if (modif_p[0] == 'n') {
  2576. minute = value;
  2577. modif_p++;
  2578. } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  2579. minute = value;
  2580. modif_p = modif_p + 2;
  2581. } else if (modif_p[0] == 'h') {
  2582. hour = value;
  2583. modif_p++;
  2584. } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  2585. day = value;
  2586. modif_p++;
  2587. } else if (modif_p[0] == 'm') {
  2588. month = value;
  2589. modif_p++;
  2590. } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  2591. year = value;
  2592. modif_p++;
  2593. } else if (modif_p[0] != '\0') {
  2594. modif_p++;
  2595. }
  2596. }
  2597. }
  2598. if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
  2599. clif_displaymessage(fd, msg_txt(85)); // Invalid time for ban command.
  2600. return -1;
  2601. }
  2602. /**
  2603. * We now check if you can adjust the ban to negative (and if this is the case)
  2604. **/
  2605. timestamp = time(NULL);
  2606. tmtime = localtime(&timestamp);
  2607. tmtime->tm_year = tmtime->tm_year + year;
  2608. tmtime->tm_mon = tmtime->tm_mon + month;
  2609. tmtime->tm_mday = tmtime->tm_mday + day;
  2610. tmtime->tm_hour = tmtime->tm_hour + hour;
  2611. tmtime->tm_min = tmtime->tm_min + minute;
  2612. tmtime->tm_sec = tmtime->tm_sec + second;
  2613. timestamp = mktime(tmtime);
  2614. if( timestamp <= time(NULL) && !pc_can_use_command(sd, "unban", COMMAND_ATCOMMAND) ) {
  2615. clif_displaymessage(fd,msg_txt(1023)); // You are not allowed to reduce the length of a ban.
  2616. return -1;
  2617. }
  2618. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 2, year, month, day, hour, minute, second); // type: 2 - ban
  2619. clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  2620. return 0;
  2621. }
  2622. /*==========================================
  2623. * charunblock command (usage: charunblock <player_name>)
  2624. *------------------------------------------*/
  2625. ACMD_FUNC(char_unblock)
  2626. {
  2627. nullpo_retr(-1, sd);
  2628. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2629. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2630. clif_displaymessage(fd, msg_txt(1024)); // Please enter a player name (usage: @charunblock <char name>).
  2631. return -1;
  2632. }
  2633. // send answer to login server via char-server
  2634. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
  2635. clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  2636. return 0;
  2637. }
  2638. /*==========================================
  2639. * charunban command (usage: charunban <player_name>)
  2640. *------------------------------------------*/
  2641. ACMD_FUNC(char_unban)
  2642. {
  2643. nullpo_retr(-1, sd);
  2644. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2645. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2646. clif_displaymessage(fd, msg_txt(1025)); // Please enter a player name (usage: @charunban <char name>).
  2647. return -1;
  2648. }
  2649. // send answer to login server via char-server
  2650. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
  2651. clif_displaymessage(fd, msg_txt(88)); // Character name sent to char-server to ask it.
  2652. return 0;
  2653. }
  2654. /*==========================================
  2655. *
  2656. *------------------------------------------*/
  2657. ACMD_FUNC(night)
  2658. {
  2659. nullpo_retr(-1, sd);
  2660. if (night_flag != 1) {
  2661. map_night_timer(night_timer_tid, 0, 0, 1);
  2662. } else {
  2663. clif_displaymessage(fd, msg_txt(89)); // Night mode is already enabled.
  2664. return -1;
  2665. }
  2666. return 0;
  2667. }
  2668. /*==========================================
  2669. *
  2670. *------------------------------------------*/
  2671. ACMD_FUNC(day)
  2672. {
  2673. nullpo_retr(-1, sd);
  2674. if (night_flag != 0) {
  2675. map_day_timer(day_timer_tid, 0, 0, 1);
  2676. } else {
  2677. clif_displaymessage(fd, msg_txt(90)); // Day mode is already enabled.
  2678. return -1;
  2679. }
  2680. return 0;
  2681. }
  2682. /*==========================================
  2683. *
  2684. *------------------------------------------*/
  2685. ACMD_FUNC(doom)
  2686. {
  2687. struct map_session_data* pl_sd;
  2688. struct s_mapiterator* iter;
  2689. nullpo_retr(-1, sd);
  2690. iter = mapit_getallusers();
  2691. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2692. {
  2693. if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2694. {
  2695. status_kill(&pl_sd->bl);
  2696. clif_specialeffect(&pl_sd->bl,450,AREA);
  2697. clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  2698. }
  2699. }
  2700. mapit_free(iter);
  2701. clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  2702. return 0;
  2703. }
  2704. /*==========================================
  2705. *
  2706. *------------------------------------------*/
  2707. ACMD_FUNC(doommap)
  2708. {
  2709. struct map_session_data* pl_sd;
  2710. struct s_mapiterator* iter;
  2711. nullpo_retr(-1, sd);
  2712. iter = mapit_getallusers();
  2713. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2714. {
  2715. if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2716. {
  2717. status_kill(&pl_sd->bl);
  2718. clif_specialeffect(&pl_sd->bl,450,AREA);
  2719. clif_displaymessage(pl_sd->fd, msg_txt(61)); // The holy messenger has given judgement.
  2720. }
  2721. }
  2722. mapit_free(iter);
  2723. clif_displaymessage(fd, msg_txt(62)); // Judgement was made.
  2724. return 0;
  2725. }
  2726. /*==========================================
  2727. *
  2728. *------------------------------------------*/
  2729. static void atcommand_raise_sub(struct map_session_data* sd) {
  2730. status_revive(&sd->bl, 100, 100);
  2731. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  2732. clif_displaymessage(sd->fd, msg_txt(63)); // Mercy has been shown.
  2733. }
  2734. /*==========================================
  2735. *
  2736. *------------------------------------------*/
  2737. ACMD_FUNC(raise)
  2738. {
  2739. struct map_session_data* pl_sd;
  2740. struct s_mapiterator* iter;
  2741. nullpo_retr(-1, sd);
  2742. iter = mapit_getallusers();
  2743. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2744. if( pc_isdead(pl_sd) )
  2745. atcommand_raise_sub(pl_sd);
  2746. mapit_free(iter);
  2747. clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  2748. return 0;
  2749. }
  2750. /*==========================================
  2751. *
  2752. *------------------------------------------*/
  2753. ACMD_FUNC(raisemap)
  2754. {
  2755. struct map_session_data* pl_sd;
  2756. struct s_mapiterator* iter;
  2757. nullpo_retr(-1, sd);
  2758. iter = mapit_getallusers();
  2759. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2760. if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) )
  2761. atcommand_raise_sub(pl_sd);
  2762. mapit_free(iter);
  2763. clif_displaymessage(fd, msg_txt(64)); // Mercy has been granted.
  2764. return 0;
  2765. }
  2766. /*==========================================
  2767. *
  2768. *------------------------------------------*/
  2769. ACMD_FUNC(kick)
  2770. {
  2771. struct map_session_data *pl_sd;
  2772. nullpo_retr(-1, sd);
  2773. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2774. if (!message || !*message) {
  2775. clif_displaymessage(fd, msg_txt(1026)); // Please enter a player name (usage: @kick <char name/ID>).
  2776. return -1;
  2777. }
  2778. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2779. {
  2780. clif_displaymessage(fd, msg_txt(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(81)); // Your GM level don't authorise you to do this action on this player.
  2786. return -1;
  2787. }
  2788. clif_GM_kick(sd, pl_sd);
  2789. return 0;
  2790. }
  2791. /*==========================================
  2792. *
  2793. *------------------------------------------*/
  2794. ACMD_FUNC(kickall)
  2795. {
  2796. struct map_session_data* pl_sd;
  2797. struct s_mapiterator* iter;
  2798. nullpo_retr(-1, sd);
  2799. iter = mapit_getallusers();
  2800. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2801. {
  2802. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level
  2803. if (sd->status.account_id != pl_sd->status.account_id)
  2804. clif_GM_kick(NULL, pl_sd);
  2805. }
  2806. }
  2807. mapit_free(iter);
  2808. clif_displaymessage(fd, msg_txt(195)); // All players have been kicked!
  2809. return 0;
  2810. }
  2811. /*==========================================
  2812. *
  2813. *------------------------------------------*/
  2814. ACMD_FUNC(allskill)
  2815. {
  2816. nullpo_retr(-1, sd);
  2817. pc_allskillup(sd); // all skills
  2818. sd->status.skill_point = 0; // 0 skill points
  2819. clif_updatestatus(sd, SP_SKILLPOINT); // update
  2820. clif_displaymessage(fd, msg_txt(76)); // All skills have been added to your skill tree.
  2821. return 0;
  2822. }
  2823. /*==========================================
  2824. *
  2825. *------------------------------------------*/
  2826. ACMD_FUNC(questskill)
  2827. {
  2828. int skill_id;
  2829. nullpo_retr(-1, sd);
  2830. if (!message || !*message || (skill_id = atoi(message)) < 0)
  2831. {// also send a list of skills applicable to this command
  2832. const char* text;
  2833. // attempt to find the text corresponding to this command
  2834. text = atcommand_help_string( command );
  2835. // send the error message as always
  2836. clif_displaymessage(fd, msg_txt(1027)); // Please enter a quest skill number.
  2837. if( text )
  2838. {// send the skill ID list associated with this command
  2839. clif_displaymessage( fd, text );
  2840. }
  2841. return -1;
  2842. }
  2843. if (skill_id < 0 && skill_id >= MAX_SKILL_DB) {
  2844. clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  2845. return -1;
  2846. }
  2847. if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  2848. clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  2849. return -1;
  2850. }
  2851. if (pc_checkskill(sd, skill_id) > 0) {
  2852. clif_displaymessage(fd, msg_txt(196)); // You already have this quest skill.
  2853. return -1;
  2854. }
  2855. pc_skill(sd, skill_id, 1, 0);
  2856. clif_displaymessage(fd, msg_txt(70)); // You have learned the skill.
  2857. return 0;
  2858. }
  2859. /*==========================================
  2860. *
  2861. *------------------------------------------*/
  2862. ACMD_FUNC(lostskill)
  2863. {
  2864. int skill_id;
  2865. nullpo_retr(-1, sd);
  2866. if (!message || !*message || (skill_id = atoi(message)) < 0)
  2867. {// also send a list of skills applicable to this command
  2868. const char* text;
  2869. // attempt to find the text corresponding to this command
  2870. text = atcommand_help_string( command );
  2871. // send the error message as always
  2872. clif_displaymessage(fd, msg_txt(1027)); // Please enter a quest skill number.
  2873. if( text )
  2874. {// send the skill ID list associated with this command
  2875. clif_displaymessage( fd, text );
  2876. }
  2877. return -1;
  2878. }
  2879. if (skill_id < 0 && skill_id >= MAX_SKILL) {
  2880. clif_displaymessage(fd, msg_txt(198)); // This skill number doesn't exist.
  2881. return -1;
  2882. }
  2883. if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  2884. clif_displaymessage(fd, msg_txt(197)); // This skill number doesn't exist or isn't a quest skill.
  2885. return -1;
  2886. }
  2887. if (pc_checkskill(sd, skill_id) == 0) {
  2888. clif_displaymessage(fd, msg_txt(201)); // You don't have this quest skill.
  2889. return -1;
  2890. }
  2891. sd->status.skill[skill_id].lv = 0;
  2892. sd->status.skill[skill_id].flag = 0;
  2893. clif_deleteskill(sd,skill_id);
  2894. clif_displaymessage(fd, msg_txt(71)); // You have forgotten the skill.
  2895. return 0;
  2896. }
  2897. /*==========================================
  2898. *
  2899. *------------------------------------------*/
  2900. ACMD_FUNC(spiritball)
  2901. {
  2902. int max_spiritballs;
  2903. int number;
  2904. nullpo_retr(-1, sd);
  2905. max_spiritballs = min(ARRAYLENGTH(sd->spirit_timer), 0x7FFF);
  2906. if( !message || !*message || (number = atoi(message)) < 0 || number > max_spiritballs )
  2907. {
  2908. char msg[CHAT_SIZE_MAX];
  2909. safesnprintf(msg, sizeof(msg), msg_txt(1028), max_spiritballs); // Please enter a party name (usage: @party <party_name>).
  2910. clif_displaymessage(fd, msg);
  2911. return -1;
  2912. }
  2913. if( sd->spiritball > 0 )
  2914. pc_delspiritball(sd, sd->spiritball, 1);
  2915. sd->spiritball = number;
  2916. clif_spiritball(&sd->bl);
  2917. // no message, player can look the difference
  2918. return 0;
  2919. }
  2920. /*==========================================
  2921. *
  2922. *------------------------------------------*/
  2923. ACMD_FUNC(party)
  2924. {
  2925. char party[NAME_LENGTH];
  2926. nullpo_retr(-1, sd);
  2927. memset(party, '\0', sizeof(party));
  2928. if (!message || !*message || sscanf(message, "%23[^\n]", party) < 1) {
  2929. clif_displaymessage(fd, msg_txt(1029)); // Please enter a party name (usage: @party <party_name>).
  2930. return -1;
  2931. }
  2932. party_create(sd, party, 0, 0);
  2933. return 0;
  2934. }
  2935. /*==========================================
  2936. *
  2937. *------------------------------------------*/
  2938. ACMD_FUNC(guild)
  2939. {
  2940. char guild[NAME_LENGTH];
  2941. int prev;
  2942. nullpo_retr(-1, sd);
  2943. memset(guild, '\0', sizeof(guild));
  2944. if (!message || !*message || sscanf(message, "%23[^\n]", guild) < 1) {
  2945. clif_displaymessage(fd, msg_txt(1030)); // Please enter a guild name (usage: @guild <guild_name>).
  2946. return -1;
  2947. }
  2948. prev = battle_config.guild_emperium_check;
  2949. battle_config.guild_emperium_check = 0;
  2950. guild_create(sd, guild);
  2951. battle_config.guild_emperium_check = prev;
  2952. return 0;
  2953. }
  2954. /*==========================================
  2955. *
  2956. *------------------------------------------*/
  2957. ACMD_FUNC(agitstart)
  2958. {
  2959. nullpo_retr(-1, sd);
  2960. if (agit_flag == 1) {
  2961. clif_displaymessage(fd, msg_txt(73)); // War of Emperium is currently in progress.
  2962. return -1;
  2963. }
  2964. agit_flag = 1;
  2965. guild_agit_start();
  2966. clif_displaymessage(fd, msg_txt(72)); // War of Emperium has been initiated.
  2967. return 0;
  2968. }
  2969. /*==========================================
  2970. *
  2971. *------------------------------------------*/
  2972. ACMD_FUNC(agitstart2)
  2973. {
  2974. nullpo_retr(-1, sd);
  2975. if (agit2_flag == 1) {
  2976. clif_displaymessage(fd, msg_txt(404)); // "War of Emperium SE is currently in progress."
  2977. return -1;
  2978. }
  2979. agit2_flag = 1;
  2980. guild_agit2_start();
  2981. clif_displaymessage(fd, msg_txt(403)); // "War of Emperium SE has been initiated."
  2982. return 0;
  2983. }
  2984. /*==========================================
  2985. *
  2986. *------------------------------------------*/
  2987. ACMD_FUNC(agitend)
  2988. {
  2989. nullpo_retr(-1, sd);
  2990. if (agit_flag == 0) {
  2991. clif_displaymessage(fd, msg_txt(75)); // War of Emperium is currently not in progress.
  2992. return -1;
  2993. }
  2994. agit_flag = 0;
  2995. guild_agit_end();
  2996. clif_displaymessage(fd, msg_txt(74)); // War of Emperium has been ended.
  2997. return 0;
  2998. }
  2999. /*==========================================
  3000. *
  3001. *------------------------------------------*/
  3002. ACMD_FUNC(agitend2)
  3003. {
  3004. nullpo_retr(-1, sd);
  3005. if (agit2_flag == 0) {
  3006. clif_displaymessage(fd, msg_txt(406)); // "War of Emperium SE is currently not in progress."
  3007. return -1;
  3008. }
  3009. agit2_flag = 0;
  3010. guild_agit2_end();
  3011. clif_displaymessage(fd, msg_txt(405)); // "War of Emperium SE has been ended."
  3012. return 0;
  3013. }
  3014. /*==========================================
  3015. * @mapexit - shuts down the map server
  3016. *------------------------------------------*/
  3017. ACMD_FUNC(mapexit)
  3018. {
  3019. nullpo_retr(-1, sd);
  3020. do_shutdown();
  3021. return 0;
  3022. }
  3023. /*==========================================
  3024. * idsearch <part_of_name>: revrited by [Yor]
  3025. *------------------------------------------*/
  3026. ACMD_FUNC(idsearch)
  3027. {
  3028. char item_name[100];
  3029. unsigned int i, match;
  3030. struct item_data *item_array[MAX_SEARCH];
  3031. nullpo_retr(-1, sd);
  3032. memset(item_name, '\0', sizeof(item_name));
  3033. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3034. if (!message || !*message || sscanf(message, "%99s", item_name) < 0) {
  3035. clif_displaymessage(fd, msg_txt(1031)); // Please enter part of an item name (usage: @idsearch <part_of_item_name>).
  3036. return -1;
  3037. }
  3038. sprintf(atcmd_output, msg_txt(77), item_name); // The reference result of '%s' (name: id):
  3039. clif_displaymessage(fd, atcmd_output);
  3040. match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
  3041. if (match > MAX_SEARCH) {
  3042. sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, match);
  3043. clif_displaymessage(fd, atcmd_output);
  3044. match = MAX_SEARCH;
  3045. }
  3046. for(i = 0; i < match; i++) {
  3047. sprintf(atcmd_output, msg_txt(78), item_array[i]->jname, item_array[i]->nameid); // %s: %d
  3048. clif_displaymessage(fd, atcmd_output);
  3049. }
  3050. sprintf(atcmd_output, msg_txt(79), match); // It is %d affair above.
  3051. clif_displaymessage(fd, atcmd_output);
  3052. return 0;
  3053. }
  3054. /*==========================================
  3055. * Recall All Characters Online To Your Location
  3056. *------------------------------------------*/
  3057. ACMD_FUNC(recallall)
  3058. {
  3059. struct map_session_data* pl_sd;
  3060. struct s_mapiterator* iter;
  3061. int count;
  3062. nullpo_retr(-1, sd);
  3063. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3064. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3065. clif_displaymessage(fd, msg_txt(1032)); // You are not authorized to warp somenone to your current map.
  3066. return -1;
  3067. }
  3068. count = 0;
  3069. iter = mapit_getallusers();
  3070. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3071. {
  3072. if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  3073. {
  3074. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3075. count++;
  3076. else {
  3077. if (pc_isdead(pl_sd)) { //Wake them up
  3078. pc_setstand(pl_sd);
  3079. pc_setrestartvalue(pl_sd,1);
  3080. }
  3081. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3082. }
  3083. }
  3084. }
  3085. mapit_free(iter);
  3086. clif_displaymessage(fd, msg_txt(92)); // All characters recalled!
  3087. if (count) {
  3088. sprintf(atcmd_output, msg_txt(1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3089. clif_displaymessage(fd, atcmd_output);
  3090. }
  3091. return 0;
  3092. }
  3093. /*==========================================
  3094. * Recall online characters of a guild to your location
  3095. *------------------------------------------*/
  3096. ACMD_FUNC(guildrecall)
  3097. {
  3098. struct map_session_data* pl_sd;
  3099. struct s_mapiterator* iter;
  3100. int count;
  3101. char guild_name[NAME_LENGTH];
  3102. struct guild *g;
  3103. nullpo_retr(-1, sd);
  3104. memset(guild_name, '\0', sizeof(guild_name));
  3105. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3106. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3107. clif_displaymessage(fd, msg_txt(1034)); // Please enter a guild name/ID (usage: @guildrecall <guild_name/ID>).
  3108. return -1;
  3109. }
  3110. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3111. clif_displaymessage(fd, msg_txt(1032)); // You are not authorized to warp somenone to your current map.
  3112. return -1;
  3113. }
  3114. if ((g = guild_searchname(guild_name)) == NULL && // name first to avoid error when name begin with a number
  3115. (g = guild_search(atoi(message))) == NULL)
  3116. {
  3117. clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  3118. return -1;
  3119. }
  3120. count = 0;
  3121. iter = mapit_getallusers();
  3122. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3123. {
  3124. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id)
  3125. {
  3126. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3127. continue; //Skip GMs greater than you.
  3128. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3129. count++;
  3130. else
  3131. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3132. }
  3133. }
  3134. mapit_free(iter);
  3135. sprintf(atcmd_output, msg_txt(93), g->name); // All online characters of the %s guild have been recalled to your position.
  3136. clif_displaymessage(fd, atcmd_output);
  3137. if (count) {
  3138. sprintf(atcmd_output, msg_txt(1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3139. clif_displaymessage(fd, atcmd_output);
  3140. }
  3141. return 0;
  3142. }
  3143. /*==========================================
  3144. * Recall online characters of a party to your location
  3145. *------------------------------------------*/
  3146. ACMD_FUNC(partyrecall)
  3147. {
  3148. struct map_session_data* pl_sd;
  3149. struct s_mapiterator* iter;
  3150. char party_name[NAME_LENGTH];
  3151. struct party_data *p;
  3152. int count;
  3153. nullpo_retr(-1, sd);
  3154. memset(party_name, '\0', sizeof(party_name));
  3155. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3156. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3157. clif_displaymessage(fd, msg_txt(1035)); // Please enter a party name/ID (usage: @partyrecall <party_name/ID>).
  3158. return -1;
  3159. }
  3160. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3161. clif_displaymessage(fd, msg_txt(1032)); // You are not authorized to warp somenone to your current map.
  3162. return -1;
  3163. }
  3164. if ((p = party_searchname(party_name)) == NULL && // name first to avoid error when name begin with a number
  3165. (p = party_search(atoi(message))) == NULL)
  3166. {
  3167. clif_displaymessage(fd, msg_txt(96)); // Incorrect name or ID, or no one from the party is online.
  3168. return -1;
  3169. }
  3170. count = 0;
  3171. iter = mapit_getallusers();
  3172. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3173. {
  3174. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id)
  3175. {
  3176. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd))
  3177. continue; //Skip GMs greater than you.
  3178. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3179. count++;
  3180. else
  3181. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3182. }
  3183. }
  3184. mapit_free(iter);
  3185. sprintf(atcmd_output, msg_txt(95), p->party.name); // All online characters of the %s party have been recalled to your position.
  3186. clif_displaymessage(fd, atcmd_output);
  3187. if (count) {
  3188. sprintf(atcmd_output, msg_txt(1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3189. clif_displaymessage(fd, atcmd_output);
  3190. }
  3191. return 0;
  3192. }
  3193. /*==========================================
  3194. *
  3195. *------------------------------------------*/
  3196. ACMD_FUNC(reloaditemdb)
  3197. {
  3198. nullpo_retr(-1, sd);
  3199. itemdb_reload();
  3200. clif_displaymessage(fd, msg_txt(97)); // Item database has been reloaded.
  3201. return 0;
  3202. }
  3203. /*==========================================
  3204. *
  3205. *------------------------------------------*/
  3206. ACMD_FUNC(reloadmobdb)
  3207. {
  3208. nullpo_retr(-1, sd);
  3209. mob_reload();
  3210. read_petdb();
  3211. merc_reload();
  3212. read_mercenarydb();
  3213. read_mercenary_skilldb();
  3214. reload_elementaldb();
  3215. clif_displaymessage(fd, msg_txt(98)); // Monster database has been reloaded.
  3216. return 0;
  3217. }
  3218. /*==========================================
  3219. *
  3220. *------------------------------------------*/
  3221. ACMD_FUNC(reloadskilldb)
  3222. {
  3223. nullpo_retr(-1, sd);
  3224. skill_reload();
  3225. merc_skill_reload();
  3226. reload_elemental_skilldb();
  3227. read_mercenary_skilldb();
  3228. clif_displaymessage(fd, msg_txt(99)); // Skill database has been reloaded.
  3229. return 0;
  3230. }
  3231. /*==========================================
  3232. * @reloadatcommand - reloads atcommand_athena.conf groups.conf
  3233. *------------------------------------------*/
  3234. void atcommand_doload();
  3235. ACMD_FUNC(reloadatcommand) {
  3236. config_t run_test;
  3237. if (conf_read_file(&run_test, "conf/groups.conf")) {
  3238. clif_displaymessage(fd, msg_txt(1036)); // Error reading groups.conf, reload failed.
  3239. return -1;
  3240. }
  3241. config_destroy(&run_test);
  3242. if (conf_read_file(&run_test, ATCOMMAND_CONF_FILENAME)) {
  3243. clif_displaymessage(fd, msg_txt(1037)); // Error reading atcommand_athena.conf, reload failed.
  3244. return -1;
  3245. }
  3246. config_destroy(&run_test);
  3247. atcommand_doload();
  3248. pc_groups_reload();
  3249. clif_displaymessage(fd, msg_txt(254));
  3250. return 0;
  3251. }
  3252. /*==========================================
  3253. * @reloadbattleconf - reloads battle_athena.conf
  3254. *------------------------------------------*/
  3255. ACMD_FUNC(reloadbattleconf)
  3256. {
  3257. struct Battle_Config prev_config;
  3258. memcpy(&prev_config, &battle_config, sizeof(prev_config));
  3259. battle_config_read(BATTLE_CONF_FILENAME);
  3260. if( prev_config.item_rate_mvp != battle_config.item_rate_mvp
  3261. || prev_config.item_rate_common != battle_config.item_rate_common
  3262. || prev_config.item_rate_common_boss != battle_config.item_rate_common_boss
  3263. || prev_config.item_rate_card != battle_config.item_rate_card
  3264. || prev_config.item_rate_card_boss != battle_config.item_rate_card_boss
  3265. || prev_config.item_rate_equip != battle_config.item_rate_equip
  3266. || prev_config.item_rate_equip_boss != battle_config.item_rate_equip_boss
  3267. || prev_config.item_rate_heal != battle_config.item_rate_heal
  3268. || prev_config.item_rate_heal_boss != battle_config.item_rate_heal_boss
  3269. || prev_config.item_rate_use != battle_config.item_rate_use
  3270. || prev_config.item_rate_use_boss != battle_config.item_rate_use_boss
  3271. || prev_config.item_rate_treasure != battle_config.item_rate_treasure
  3272. || prev_config.item_rate_adddrop != battle_config.item_rate_adddrop
  3273. || prev_config.logarithmic_drops != battle_config.logarithmic_drops
  3274. || prev_config.item_drop_common_min != battle_config.item_drop_common_min
  3275. || prev_config.item_drop_common_max != battle_config.item_drop_common_max
  3276. || prev_config.item_drop_card_min != battle_config.item_drop_card_min
  3277. || prev_config.item_drop_card_max != battle_config.item_drop_card_max
  3278. || prev_config.item_drop_equip_min != battle_config.item_drop_equip_min
  3279. || prev_config.item_drop_equip_max != battle_config.item_drop_equip_max
  3280. || prev_config.item_drop_mvp_min != battle_config.item_drop_mvp_min
  3281. || prev_config.item_drop_mvp_max != battle_config.item_drop_mvp_max
  3282. || prev_config.item_drop_heal_min != battle_config.item_drop_heal_min
  3283. || prev_config.item_drop_heal_max != battle_config.item_drop_heal_max
  3284. || prev_config.item_drop_use_min != battle_config.item_drop_use_min
  3285. || prev_config.item_drop_use_max != battle_config.item_drop_use_max
  3286. || prev_config.item_drop_treasure_min != battle_config.item_drop_treasure_min
  3287. || prev_config.item_drop_treasure_max != battle_config.item_drop_treasure_max
  3288. || prev_config.base_exp_rate != battle_config.base_exp_rate
  3289. || prev_config.job_exp_rate != battle_config.job_exp_rate
  3290. )
  3291. { // Exp or Drop rates changed.
  3292. mob_reload(); //Needed as well so rate changes take effect.
  3293. chrif_ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
  3294. }
  3295. clif_displaymessage(fd, msg_txt(255));
  3296. return 0;
  3297. }
  3298. /*==========================================
  3299. * @reloadstatusdb - reloads job_db1.txt job_db2.txt job_db2-2.txt refine_db.txt size_fix.txt
  3300. *------------------------------------------*/
  3301. ACMD_FUNC(reloadstatusdb)
  3302. {
  3303. status_readdb();
  3304. clif_displaymessage(fd, msg_txt(256));
  3305. return 0;
  3306. }
  3307. /*==========================================
  3308. * @reloadpcdb - reloads exp.txt skill_tree.txt attr_fix.txt statpoint.txt
  3309. *------------------------------------------*/
  3310. ACMD_FUNC(reloadpcdb)
  3311. {
  3312. pc_readdb();
  3313. clif_displaymessage(fd, msg_txt(257));
  3314. return 0;
  3315. }
  3316. /*==========================================
  3317. * @reloadmotd - reloads motd.txt
  3318. *------------------------------------------*/
  3319. ACMD_FUNC(reloadmotd)
  3320. {
  3321. pc_read_motd();
  3322. clif_displaymessage(fd, msg_txt(268));
  3323. return 0;
  3324. }
  3325. /*==========================================
  3326. * @reloadscript - reloads all scripts (npcs, warps, mob spawns, ...)
  3327. *------------------------------------------*/
  3328. ACMD_FUNC(reloadscript)
  3329. {
  3330. nullpo_retr(-1, sd);
  3331. //atcommand_broadcast( fd, sd, "@broadcast", "Server is reloading scripts..." );
  3332. //atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
  3333. flush_fifos();
  3334. map_reloadnpc(true); // reload config files seeking for npcs
  3335. script_reload();
  3336. npc_reload();
  3337. clif_displaymessage(fd, msg_txt(100)); // Scripts have been reloaded.
  3338. return 0;
  3339. }
  3340. /*==========================================
  3341. * @mapinfo [0-3] <map name> by MC_Cameri
  3342. * => Shows information about the map [map name]
  3343. * 0 = no additional information
  3344. * 1 = Show users in that map and their location
  3345. * 2 = Shows NPCs in that map
  3346. * 3 = Shows the shops/chats in that map (not implemented)
  3347. *------------------------------------------*/
  3348. ACMD_FUNC(mapinfo)
  3349. {
  3350. struct map_session_data* pl_sd;
  3351. struct s_mapiterator* iter;
  3352. struct npc_data *nd = NULL;
  3353. struct chat_data *cd = NULL;
  3354. char direction[12];
  3355. int i, m_id, chat_num, list = 0;
  3356. unsigned short m_index;
  3357. char mapname[24];
  3358. nullpo_retr(-1, sd);
  3359. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3360. memset(mapname, '\0', sizeof(mapname));
  3361. memset(direction, '\0', sizeof(direction));
  3362. sscanf(message, "%d %23[^\n]", &list, mapname);
  3363. if (list < 0 || list > 3) {
  3364. clif_displaymessage(fd, msg_txt(1038)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3365. return -1;
  3366. }
  3367. if (mapname[0] == '\0') {
  3368. safestrncpy(mapname, mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  3369. m_id = map_mapindex2mapid(sd->mapindex);
  3370. } else {
  3371. m_id = map_mapname2mapid(mapname);
  3372. }
  3373. if (m_id < 0) {
  3374. clif_displaymessage(fd, msg_txt(1)); // Map not found.
  3375. return -1;
  3376. }
  3377. m_index = mapindex_name2id(mapname); //This one shouldn't fail since the previous seek did not.
  3378. clif_displaymessage(fd, msg_txt(1039)); // ------ Map Info ------
  3379. // count chats (for initial message)
  3380. chat_num = 0;
  3381. iter = mapit_getallusers();
  3382. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3383. if( (cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd )
  3384. chat_num++;
  3385. mapit_free(iter);
  3386. sprintf(atcmd_output, msg_txt(1040), mapname, map[m_id].users, map[m_id].npc_num, chat_num); // Map Name: %s | Players In Map: %d | NPCs In Map: %d | Chats In Map: %d
  3387. clif_displaymessage(fd, atcmd_output);
  3388. clif_displaymessage(fd, msg_txt(1041)); // ------ Map Flags ------
  3389. if (map[m_id].flag.town)
  3390. clif_displaymessage(fd, msg_txt(1042)); // Town Map
  3391. if (battle_config.autotrade_mapflag == map[m_id].flag.autotrade)
  3392. clif_displaymessage(fd, msg_txt(1043)); // Autotrade Enabled
  3393. else
  3394. clif_displaymessage(fd, msg_txt(1044)); // Autotrade Disabled
  3395. if (map[m_id].flag.battleground)
  3396. clif_displaymessage(fd, msg_txt(1045)); // Battlegrounds ON
  3397. strcpy(atcmd_output,msg_txt(1046)); // PvP Flags:
  3398. if (map[m_id].flag.pvp)
  3399. strcat(atcmd_output, msg_txt(1047)); // Pvp ON |
  3400. if (map[m_id].flag.pvp_noguild)
  3401. strcat(atcmd_output, msg_txt(1048)); // NoGuild |
  3402. if (map[m_id].flag.pvp_noparty)
  3403. strcat(atcmd_output, msg_txt(1049)); // NoParty |
  3404. if (map[m_id].flag.pvp_nightmaredrop)
  3405. strcat(atcmd_output, msg_txt(1050)); // NightmareDrop |
  3406. if (map[m_id].flag.pvp_nocalcrank)
  3407. strcat(atcmd_output, msg_txt(1051)); // NoCalcRank |
  3408. clif_displaymessage(fd, atcmd_output);
  3409. strcpy(atcmd_output,msg_txt(1052)); // GvG Flags:
  3410. if (map[m_id].flag.gvg)
  3411. strcat(atcmd_output, msg_txt(1053)); // GvG ON |
  3412. if (map[m_id].flag.gvg_dungeon)
  3413. strcat(atcmd_output, msg_txt(1054)); // GvG Dungeon |
  3414. if (map[m_id].flag.gvg_castle)
  3415. strcat(atcmd_output, msg_txt(1055)); // GvG Castle |
  3416. if (map[m_id].flag.gvg_noparty)
  3417. strcat(atcmd_output, msg_txt(1056)); // NoParty |
  3418. clif_displaymessage(fd, atcmd_output);
  3419. strcpy(atcmd_output,msg_txt(1057)); // Teleport Flags:
  3420. if (map[m_id].flag.noteleport)
  3421. strcat(atcmd_output, msg_txt(1058)); // NoTeleport |
  3422. if (map[m_id].flag.monster_noteleport)
  3423. strcat(atcmd_output, msg_txt(1059)); // Monster NoTeleport |
  3424. if (map[m_id].flag.nowarp)
  3425. strcat(atcmd_output, msg_txt(1060)); // NoWarp |
  3426. if (map[m_id].flag.nowarpto)
  3427. strcat(atcmd_output, msg_txt(1061)); // NoWarpTo |
  3428. if (map[m_id].flag.noreturn)
  3429. strcat(atcmd_output, msg_txt(1062)); // NoReturn |
  3430. if (map[m_id].flag.nogo)
  3431. strcat(atcmd_output, msg_txt(1063)); // NoGo |
  3432. if (map[m_id].flag.nomemo)
  3433. strcat(atcmd_output, msg_txt(1064)); // NoMemo |
  3434. clif_displaymessage(fd, atcmd_output);
  3435. sprintf(atcmd_output, msg_txt(1065), // No Exp Penalty: %s | No Zeny Penalty: %s
  3436. (map[m_id].flag.noexppenalty) ? msg_txt(1066) : msg_txt(1067), (map[m_id].flag.nozenypenalty) ? msg_txt(1066) : msg_txt(1067)); // On / Off
  3437. clif_displaymessage(fd, atcmd_output);
  3438. if (map[m_id].flag.nosave) {
  3439. if (!map[m_id].save.map)
  3440. clif_displaymessage(fd, msg_txt(1068)); // No Save (Return to last Save Point)
  3441. else if (map[m_id].save.x == -1 || map[m_id].save.y == -1 ) {
  3442. sprintf(atcmd_output, msg_txt(1069), mapindex_id2name(map[m_id].save.map)); // No Save, Save Point: %s,Random
  3443. clif_displaymessage(fd, atcmd_output);
  3444. }
  3445. else {
  3446. sprintf(atcmd_output, msg_txt(1070), // No Save, Save Point: %s,%d,%d
  3447. mapindex_id2name(map[m_id].save.map),map[m_id].save.x,map[m_id].save.y);
  3448. clif_displaymessage(fd, atcmd_output);
  3449. }
  3450. }
  3451. strcpy(atcmd_output,msg_txt(1071)); // Weather Flags:
  3452. if (map[m_id].flag.snow)
  3453. strcat(atcmd_output, msg_txt(1072)); // Snow |
  3454. if (map[m_id].flag.fog)
  3455. strcat(atcmd_output, msg_txt(1073)); // Fog |
  3456. if (map[m_id].flag.sakura)
  3457. strcat(atcmd_output, msg_txt(1074)); // Sakura |
  3458. if (map[m_id].flag.clouds)
  3459. strcat(atcmd_output, msg_txt(1075)); // Clouds |
  3460. if (map[m_id].flag.clouds2)
  3461. strcat(atcmd_output, msg_txt(1076)); // Clouds2 |
  3462. if (map[m_id].flag.fireworks)
  3463. strcat(atcmd_output, msg_txt(1077)); // Fireworks |
  3464. if (map[m_id].flag.leaves)
  3465. strcat(atcmd_output, msg_txt(1078)); // Leaves |
  3466. /**
  3467. * No longer available, keeping here just in case it's back someday. [Ind]
  3468. **/
  3469. //if (map[m_id].flag.rain)
  3470. // strcat(atcmd_output, msg_txt(1079)); // Rain |
  3471. if (map[m_id].flag.nightenabled)
  3472. strcat(atcmd_output, msg_txt(1080)); // Displays Night |
  3473. clif_displaymessage(fd, atcmd_output);
  3474. strcpy(atcmd_output,msg_txt(1081)); // Other Flags:
  3475. if (map[m_id].flag.nobranch)
  3476. strcat(atcmd_output, msg_txt(1082)); // NoBranch |
  3477. if (map[m_id].flag.notrade)
  3478. strcat(atcmd_output, msg_txt(1083)); // NoTrade |
  3479. if (map[m_id].flag.novending)
  3480. strcat(atcmd_output, msg_txt(1084)); // NoVending |
  3481. if (map[m_id].flag.nodrop)
  3482. strcat(atcmd_output, msg_txt(1085)); // NoDrop |
  3483. if (map[m_id].flag.noskill)
  3484. strcat(atcmd_output, msg_txt(1086)); // NoSkill |
  3485. if (map[m_id].flag.noicewall)
  3486. strcat(atcmd_output, msg_txt(1087)); // NoIcewall |
  3487. if (map[m_id].flag.allowks)
  3488. strcat(atcmd_output, msg_txt(1088)); // AllowKS |
  3489. if (map[m_id].flag.reset)
  3490. strcat(atcmd_output, msg_txt(1089)); // Reset |
  3491. clif_displaymessage(fd, atcmd_output);
  3492. strcpy(atcmd_output,msg_txt(1090)); // Other Flags:
  3493. if (map[m_id].nocommand)
  3494. strcat(atcmd_output, msg_txt(1091)); // NoCommand |
  3495. if (map[m_id].flag.nobaseexp)
  3496. strcat(atcmd_output, msg_txt(1092)); // NoBaseEXP |
  3497. if (map[m_id].flag.nojobexp)
  3498. strcat(atcmd_output, msg_txt(1093)); // NoJobEXP |
  3499. if (map[m_id].flag.nomobloot)
  3500. strcat(atcmd_output, msg_txt(1094)); // NoMobLoot |
  3501. if (map[m_id].flag.nomvploot)
  3502. strcat(atcmd_output, msg_txt(1095)); // NoMVPLoot |
  3503. if (map[m_id].flag.partylock)
  3504. strcat(atcmd_output, msg_txt(1096)); // PartyLock |
  3505. if (map[m_id].flag.guildlock)
  3506. strcat(atcmd_output, msg_txt(1097)); // GuildLock |
  3507. clif_displaymessage(fd, atcmd_output);
  3508. switch (list) {
  3509. case 0:
  3510. // Do nothing. It's list 0, no additional display.
  3511. break;
  3512. case 1:
  3513. clif_displaymessage(fd, msg_txt(1098)); // ----- Players in Map -----
  3514. iter = mapit_getallusers();
  3515. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3516. {
  3517. if (pl_sd->mapindex == m_index) {
  3518. sprintf(atcmd_output, msg_txt(1099), // Player '%s' (session #%d) | Location: %d,%d
  3519. pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y);
  3520. clif_displaymessage(fd, atcmd_output);
  3521. }
  3522. }
  3523. mapit_free(iter);
  3524. break;
  3525. case 2:
  3526. clif_displaymessage(fd, msg_txt(1100)); // ----- NPCs in Map -----
  3527. for (i = 0; i < map[m_id].npc_num;)
  3528. {
  3529. nd = map[m_id].npc[i];
  3530. switch(nd->ud.dir) {
  3531. case 0: strcpy(direction, msg_txt(1101)); break; // North
  3532. case 1: strcpy(direction, msg_txt(1102)); break; // North West
  3533. case 2: strcpy(direction, msg_txt(1103)); break; // West
  3534. case 3: strcpy(direction, msg_txt(1104)); break; // South West
  3535. case 4: strcpy(direction, msg_txt(1105)); break; // South
  3536. case 5: strcpy(direction, msg_txt(1106)); break; // South East
  3537. case 6: strcpy(direction, msg_txt(1107)); break; // East
  3538. case 7: strcpy(direction, msg_txt(1108)); break; // North East
  3539. case 9: strcpy(direction, msg_txt(1109)); break; // North
  3540. default: strcpy(direction, msg_txt(1110)); break; // Unknown
  3541. }
  3542. if(strcmp(nd->name,nd->exname) == 0)
  3543. sprintf(atcmd_output, msg_txt(1111), // NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d
  3544. ++i, nd->name, direction, nd->class_, nd->bl.x, nd->bl.y);
  3545. else
  3546. sprintf(atcmd_output, msg_txt(1112), // NPC %d: %s::%s | Direction: %s | Sprite: %d | Location: %d %d
  3547. ++i, nd->name, nd->exname, direction, nd->class_, nd->bl.x, nd->bl.y);
  3548. clif_displaymessage(fd, atcmd_output);
  3549. }
  3550. break;
  3551. case 3:
  3552. clif_displaymessage(fd, msg_txt(1113)); // ----- Chats in Map -----
  3553. iter = mapit_getallusers();
  3554. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3555. {
  3556. if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL &&
  3557. pl_sd->mapindex == m_index &&
  3558. cd->usersd[0] == pl_sd)
  3559. {
  3560. sprintf(atcmd_output, msg_txt(1114), // Chat: %s | Player: %s | Location: %d %d
  3561. cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y);
  3562. clif_displaymessage(fd, atcmd_output);
  3563. sprintf(atcmd_output, msg_txt(1115), // Users: %d/%d | Password: %s | Public: %s
  3564. cd->users, cd->limit, cd->pass, (cd->pub) ? msg_txt(1116) : msg_txt(1117)); // Yes / No
  3565. clif_displaymessage(fd, atcmd_output);
  3566. }
  3567. }
  3568. mapit_free(iter);
  3569. break;
  3570. default: // normally impossible to arrive here
  3571. clif_displaymessage(fd, msg_txt(1118)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3572. return -1;
  3573. break;
  3574. }
  3575. return 0;
  3576. }
  3577. /*==========================================
  3578. *
  3579. *------------------------------------------*/
  3580. ACMD_FUNC(mount_peco)
  3581. {
  3582. nullpo_retr(-1, sd);
  3583. if (sd->disguise) {
  3584. clif_displaymessage(fd, msg_txt(212)); // Cannot mount while in disguise.
  3585. return -1;
  3586. }
  3587. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT && pc_checkskill(sd,RK_DRAGONTRAINING) > 0 ) {
  3588. if( !(sd->sc.option&OPTION_DRAGON1) ) {
  3589. clif_displaymessage(sd->fd,msg_txt(1119)); // You have mounted your Dragon.
  3590. pc_setoption(sd, sd->sc.option|OPTION_DRAGON1);
  3591. } else {
  3592. clif_displaymessage(sd->fd,msg_txt(1120)); // You have released your Dragon.
  3593. pc_setoption(sd, sd->sc.option&~OPTION_DRAGON1);
  3594. }
  3595. return 0;
  3596. }
  3597. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER && pc_checkskill(sd,RA_WUGRIDER) > 0 ) {
  3598. if( !pc_isridingwug(sd) ) {
  3599. clif_displaymessage(sd->fd,msg_txt(1121)); // You have mounted your Warg.
  3600. pc_setoption(sd, sd->sc.option|OPTION_WUGRIDER);
  3601. } else {
  3602. clif_displaymessage(sd->fd,msg_txt(1122)); // You have released your Warg.
  3603. pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
  3604. }
  3605. return 0;
  3606. }
  3607. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  3608. if( !pc_ismadogear(sd) ) {
  3609. clif_displaymessage(sd->fd,msg_txt(1123)); // You have mounted your Mado Gear.
  3610. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  3611. } else {
  3612. clif_displaymessage(sd->fd,msg_txt(1124)); // You have released your Mado Gear.
  3613. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  3614. }
  3615. return 0;
  3616. }
  3617. if (!pc_isriding(sd)) { // if actually no peco
  3618. if (!pc_checkskill(sd, KN_RIDING)) {
  3619. clif_displaymessage(fd, msg_txt(213)); // You can not mount a Peco Peco with your current job.
  3620. return -1;
  3621. }
  3622. pc_setoption(sd, sd->sc.option | OPTION_RIDING);
  3623. clif_displaymessage(fd, msg_txt(102)); // You have mounted a Peco Peco.
  3624. } else {//Dismount
  3625. pc_setoption(sd, sd->sc.option & ~OPTION_RIDING);
  3626. clif_displaymessage(fd, msg_txt(214)); // You have released your Peco Peco.
  3627. }
  3628. return 0;
  3629. }
  3630. /*==========================================
  3631. *Spy Commands by Syrus22
  3632. *------------------------------------------*/
  3633. ACMD_FUNC(guildspy)
  3634. {
  3635. char guild_name[NAME_LENGTH];
  3636. struct guild *g;
  3637. nullpo_retr(-1, sd);
  3638. memset(guild_name, '\0', sizeof(guild_name));
  3639. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3640. if (!enable_spy)
  3641. {
  3642. clif_displaymessage(fd, msg_txt(1125)); // The mapserver has spy command support disabled.
  3643. return -1;
  3644. }
  3645. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3646. clif_displaymessage(fd, msg_txt(1126)); // Please enter a guild name/ID (usage: @guildspy <guild_name/ID>).
  3647. return -1;
  3648. }
  3649. if ((g = guild_searchname(guild_name)) != NULL || // name first to avoid error when name begin with a number
  3650. (g = guild_search(atoi(message))) != NULL) {
  3651. if (sd->guildspy == g->guild_id) {
  3652. sd->guildspy = 0;
  3653. sprintf(atcmd_output, msg_txt(103), g->name); // No longer spying on the %s guild.
  3654. clif_displaymessage(fd, atcmd_output);
  3655. } else {
  3656. sd->guildspy = g->guild_id;
  3657. sprintf(atcmd_output, msg_txt(104), g->name); // Spying on the %s guild.
  3658. clif_displaymessage(fd, atcmd_output);
  3659. }
  3660. } else {
  3661. clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the specified guild is online.
  3662. return -1;
  3663. }
  3664. return 0;
  3665. }
  3666. /*==========================================
  3667. *
  3668. *------------------------------------------*/
  3669. ACMD_FUNC(partyspy)
  3670. {
  3671. char party_name[NAME_LENGTH];
  3672. struct party_data *p;
  3673. nullpo_retr(-1, sd);
  3674. memset(party_name, '\0', sizeof(party_name));
  3675. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3676. if (!enable_spy)
  3677. {
  3678. clif_displaymessage(fd, msg_txt(1125)); // The mapserver has spy command support disabled.
  3679. return -1;
  3680. }
  3681. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3682. clif_displaymessage(fd, msg_txt(1127)); // Please enter a party name/ID (usage: @partyspy <party_name/ID>).
  3683. return -1;
  3684. }
  3685. if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
  3686. (p = party_search(atoi(message))) != NULL) {
  3687. if (sd->partyspy == p->party.party_id) {
  3688. sd->partyspy = 0;
  3689. sprintf(atcmd_output, msg_txt(105), p->party.name); // No longer spying on the %s party.
  3690. clif_displaymessage(fd, atcmd_output);
  3691. } else {
  3692. sd->partyspy = p->party.party_id;
  3693. sprintf(atcmd_output, msg_txt(106), p->party.name); // Spying on the %s party.
  3694. clif_displaymessage(fd, atcmd_output);
  3695. }
  3696. } else {
  3697. clif_displaymessage(fd, msg_txt(96)); // Incorrect name/ID, or no one from the specified party is online.
  3698. return -1;
  3699. }
  3700. return 0;
  3701. }
  3702. /*==========================================
  3703. * @repairall [Valaris]
  3704. *------------------------------------------*/
  3705. ACMD_FUNC(repairall)
  3706. {
  3707. int count, i;
  3708. nullpo_retr(-1, sd);
  3709. count = 0;
  3710. for (i = 0; i < MAX_INVENTORY; i++) {
  3711. if (sd->status.inventory[i].nameid && sd->status.inventory[i].attribute == 1) {
  3712. sd->status.inventory[i].attribute = 0;
  3713. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  3714. count++;
  3715. }
  3716. }
  3717. if (count > 0) {
  3718. clif_misceffect(&sd->bl, 3);
  3719. clif_equiplist(sd);
  3720. clif_displaymessage(fd, msg_txt(107)); // All items have been repaired.
  3721. } else {
  3722. clif_displaymessage(fd, msg_txt(108)); // No item need to be repaired.
  3723. return -1;
  3724. }
  3725. return 0;
  3726. }
  3727. /*==========================================
  3728. * @nuke [Valaris]
  3729. *------------------------------------------*/
  3730. ACMD_FUNC(nuke)
  3731. {
  3732. struct map_session_data *pl_sd;
  3733. nullpo_retr(-1, sd);
  3734. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3735. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3736. clif_displaymessage(fd, msg_txt(1128)); // Please enter a player name (usage: @nuke <char name>).
  3737. return -1;
  3738. }
  3739. if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) {
  3740. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level
  3741. skill_castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, gettick(), 0);
  3742. clif_displaymessage(fd, msg_txt(109)); // Player has been nuked!
  3743. } else {
  3744. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  3745. return -1;
  3746. }
  3747. } else {
  3748. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  3749. return -1;
  3750. }
  3751. return 0;
  3752. }
  3753. /*==========================================
  3754. * @tonpc
  3755. *------------------------------------------*/
  3756. ACMD_FUNC(tonpc)
  3757. {
  3758. char npcname[NAME_LENGTH+1];
  3759. struct npc_data *nd;
  3760. nullpo_retr(-1, sd);
  3761. memset(npcname, 0, sizeof(npcname));
  3762. if (!message || !*message || sscanf(message, "%23[^\n]", npcname) < 1) {
  3763. clif_displaymessage(fd, msg_txt(1129)); // Please enter a NPC name (usage: @tonpc <NPC_name>).
  3764. return -1;
  3765. }
  3766. if ((nd = npc_name2id(npcname)) != NULL) {
  3767. if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
  3768. clif_displaymessage(fd, msg_txt(0)); // Warped.
  3769. else
  3770. return -1;
  3771. } else {
  3772. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  3773. return -1;
  3774. }
  3775. return 0;
  3776. }
  3777. /*==========================================
  3778. *
  3779. *------------------------------------------*/
  3780. ACMD_FUNC(shownpc)
  3781. {
  3782. char NPCname[NAME_LENGTH+1];
  3783. nullpo_retr(-1, sd);
  3784. memset(NPCname, '\0', sizeof(NPCname));
  3785. if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  3786. clif_displaymessage(fd, msg_txt(1130)); // Please enter a NPC name (usage: @enablenpc <NPC_name>).
  3787. return -1;
  3788. }
  3789. if (npc_name2id(NPCname) != NULL) {
  3790. npc_enable(NPCname, 1);
  3791. clif_displaymessage(fd, msg_txt(110)); // Npc Enabled.
  3792. } else {
  3793. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  3794. return -1;
  3795. }
  3796. return 0;
  3797. }
  3798. /*==========================================
  3799. *
  3800. *------------------------------------------*/
  3801. ACMD_FUNC(hidenpc)
  3802. {
  3803. char NPCname[NAME_LENGTH+1];
  3804. nullpo_retr(-1, sd);
  3805. memset(NPCname, '\0', sizeof(NPCname));
  3806. if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  3807. clif_displaymessage(fd, msg_txt(1131)); // Please enter a NPC name (usage: @hidenpc <NPC_name>).
  3808. return -1;
  3809. }
  3810. if (npc_name2id(NPCname) == NULL) {
  3811. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  3812. return -1;
  3813. }
  3814. npc_enable(NPCname, 0);
  3815. clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  3816. return 0;
  3817. }
  3818. ACMD_FUNC(loadnpc)
  3819. {
  3820. FILE *fp;
  3821. if (!message || !*message) {
  3822. clif_displaymessage(fd, msg_txt(1132)); // Please enter a script file name (usage: @loadnpc <file name>).
  3823. return -1;
  3824. }
  3825. // check if script file exists
  3826. if ((fp = fopen(message, "r")) == NULL) {
  3827. clif_displaymessage(fd, msg_txt(261));
  3828. return -1;
  3829. }
  3830. fclose(fp);
  3831. // add to list of script sources and run it
  3832. npc_addsrcfile(message);
  3833. npc_parsesrcfile(message,true);
  3834. npc_read_event_script();
  3835. clif_displaymessage(fd, msg_txt(262));
  3836. return 0;
  3837. }
  3838. ACMD_FUNC(unloadnpc)
  3839. {
  3840. struct npc_data *nd;
  3841. char NPCname[NAME_LENGTH+1];
  3842. nullpo_retr(-1, sd);
  3843. memset(NPCname, '\0', sizeof(NPCname));
  3844. if (!message || !*message || sscanf(message, "%24[^\n]", NPCname) < 1) {
  3845. clif_displaymessage(fd, msg_txt(1133)); // Please enter a NPC name (usage: @npcoff <NPC_name>).
  3846. return -1;
  3847. }
  3848. if ((nd = npc_name2id(NPCname)) == NULL) {
  3849. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  3850. return -1;
  3851. }
  3852. npc_unload_duplicates(nd);
  3853. npc_unload(nd,true);
  3854. npc_read_event_script();
  3855. clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
  3856. return 0;
  3857. }
  3858. /*==========================================
  3859. * time in txt for time command (by [Yor])
  3860. *------------------------------------------*/
  3861. char* txt_time(unsigned int duration)
  3862. {
  3863. int days, hours, minutes, seconds;
  3864. char temp[CHAT_SIZE_MAX];
  3865. static char temp1[CHAT_SIZE_MAX];
  3866. memset(temp, '\0', sizeof(temp));
  3867. memset(temp1, '\0', sizeof(temp1));
  3868. days = duration / (60 * 60 * 24);
  3869. duration = duration - (60 * 60 * 24 * days);
  3870. hours = duration / (60 * 60);
  3871. duration = duration - (60 * 60 * hours);
  3872. minutes = duration / 60;
  3873. seconds = duration - (60 * minutes);
  3874. if (days == 1)
  3875. sprintf(temp, msg_txt(219), days); // %d day
  3876. else if (days > 1)
  3877. sprintf(temp, msg_txt(220), days); // %d days
  3878. if (hours == 1)
  3879. sprintf(temp1, msg_txt(221), temp, hours); // %s %d hour
  3880. else if (hours > 1)
  3881. sprintf(temp1, msg_txt(222), temp, hours); // %s %d hours
  3882. if (minutes < 2)
  3883. sprintf(temp, msg_txt(223), temp1, minutes); // %s %d minute
  3884. else
  3885. sprintf(temp, msg_txt(224), temp1, minutes); // %s %d minutes
  3886. if (seconds == 1)
  3887. sprintf(temp1, msg_txt(225), temp, seconds); // %s and %d second
  3888. else if (seconds > 1)
  3889. sprintf(temp1, msg_txt(226), temp, seconds); // %s and %d seconds
  3890. return temp1;
  3891. }
  3892. /*==========================================
  3893. * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor]
  3894. * Calculation management of GM modification (@day/@night GM commands) is done
  3895. *------------------------------------------*/
  3896. ACMD_FUNC(servertime)
  3897. {
  3898. const struct TimerData * timer_data;
  3899. const struct TimerData * timer_data2;
  3900. time_t time_server; // variable for number of seconds (used with time() function)
  3901. struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
  3902. char temp[CHAT_SIZE_MAX];
  3903. nullpo_retr(-1, sd);
  3904. memset(temp, '\0', sizeof(temp));
  3905. time(&time_server); // get time in seconds since 1/1/1970
  3906. datetime = localtime(&time_server); // convert seconds in structure
  3907. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  3908. strftime(temp, sizeof(temp)-1, msg_txt(230), datetime); // Server time (normal time): %A, %B %d %Y %X.
  3909. clif_displaymessage(fd, temp);
  3910. if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
  3911. if (night_flag == 0)
  3912. clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  3913. else
  3914. clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  3915. } else if (battle_config.night_duration == 0)
  3916. if (night_flag == 1) { // we start with night
  3917. timer_data = get_timer(day_timer_tid);
  3918. sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in night for %s.
  3919. clif_displaymessage(fd, temp);
  3920. clif_displaymessage(fd, msg_txt(234)); // Game time: After, the game will be in permanent daylight.
  3921. } else
  3922. clif_displaymessage(fd, msg_txt(231)); // Game time: The game is in permanent daylight.
  3923. else if (battle_config.day_duration == 0)
  3924. if (night_flag == 0) { // we start with day
  3925. timer_data = get_timer(night_timer_tid);
  3926. sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  3927. clif_displaymessage(fd, temp);
  3928. clif_displaymessage(fd, msg_txt(236)); // Game time: After, the game will be in permanent night.
  3929. } else
  3930. clif_displaymessage(fd, msg_txt(232)); // Game time: The game is in permanent night.
  3931. else {
  3932. if (night_flag == 0) {
  3933. timer_data = get_timer(night_timer_tid);
  3934. timer_data2 = get_timer(day_timer_tid);
  3935. sprintf(temp, msg_txt(235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  3936. clif_displaymessage(fd, temp);
  3937. if (DIFF_TICK(timer_data->tick, timer_data2->tick) > 0)
  3938. sprintf(temp, msg_txt(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.
  3939. else
  3940. sprintf(temp, msg_txt(237), txt_time(DIFF_TICK(timer_data2->tick,timer_data->tick)/1000)); // Game time: After, the game will be in night for %s.
  3941. clif_displaymessage(fd, temp);
  3942. sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  3943. clif_displaymessage(fd, temp);
  3944. } else {
  3945. timer_data = get_timer(day_timer_tid);
  3946. timer_data2 = get_timer(night_timer_tid);
  3947. sprintf(temp, msg_txt(233), txt_time(DIFF_TICK(timer_data->tick,gettick()) / 1000)); // Game time: The game is actualy in night for %s.
  3948. clif_displaymessage(fd, temp);
  3949. if (DIFF_TICK(timer_data->tick,timer_data2->tick) > 0)
  3950. sprintf(temp, msg_txt(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.
  3951. else
  3952. sprintf(temp, msg_txt(239), txt_time(DIFF_TICK(timer_data2->tick, timer_data->tick) / 1000)); // Game time: After, the game will be in daylight for %s.
  3953. clif_displaymessage(fd, temp);
  3954. sprintf(temp, msg_txt(238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  3955. clif_displaymessage(fd, temp);
  3956. }
  3957. }
  3958. return 0;
  3959. }
  3960. //Added by Coltaro
  3961. //We're using this function here instead of using time_t so that it only counts player's jail time when he/she's online (and since the idea is to reduce the amount of minutes one by one in status_change_timer...).
  3962. //Well, using time_t could still work but for some reason that looks like more coding x_x
  3963. static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute)
  3964. {
  3965. const int factor_year = 518400; //12*30*24*60 = 518400
  3966. const int factor_month = 43200; //30*24*60 = 43200
  3967. const int factor_day = 1440; //24*60 = 1440
  3968. const int factor_hour = 60;
  3969. *year = jailtime/factor_year;
  3970. jailtime -= *year*factor_year;
  3971. *month = jailtime/factor_month;
  3972. jailtime -= *month*factor_month;
  3973. *day = jailtime/factor_day;
  3974. jailtime -= *day*factor_day;
  3975. *hour = jailtime/factor_hour;
  3976. jailtime -= *hour*factor_hour;
  3977. *minute = jailtime;
  3978. *year = *year > 0? *year : 0;
  3979. *month = *month > 0? *month : 0;
  3980. *day = *day > 0? *day : 0;
  3981. *hour = *hour > 0? *hour : 0;
  3982. *minute = *minute > 0? *minute : 0;
  3983. return;
  3984. }
  3985. /*==========================================
  3986. * @jail <char_name> by [Yor]
  3987. * Special warp! No check with nowarp and nowarpto flag
  3988. *------------------------------------------*/
  3989. ACMD_FUNC(jail)
  3990. {
  3991. struct map_session_data *pl_sd;
  3992. int x, y;
  3993. unsigned short m_index;
  3994. nullpo_retr(-1, sd);
  3995. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3996. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3997. clif_displaymessage(fd, msg_txt(1134)); // Please enter a player name (usage: @jail <char_name>).
  3998. return -1;
  3999. }
  4000. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4001. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4002. return -1;
  4003. }
  4004. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd))
  4005. { // you can jail only lower or same GM
  4006. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4007. return -1;
  4008. }
  4009. if (pl_sd->sc.data[SC_JAILED])
  4010. {
  4011. clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4012. return -1;
  4013. }
  4014. switch(rnd() % 2) { //Jail Locations
  4015. case 0:
  4016. m_index = mapindex_name2id(MAP_JAIL);
  4017. x = 24;
  4018. y = 75;
  4019. break;
  4020. default:
  4021. m_index = mapindex_name2id(MAP_JAIL);
  4022. x = 49;
  4023. y = 75;
  4024. break;
  4025. }
  4026. //Duration of INT_MAX to specify infinity.
  4027. sc_start4(&pl_sd->bl,SC_JAILED,100,INT_MAX,m_index,x,y,1000);
  4028. clif_displaymessage(pl_sd->fd, msg_txt(117)); // GM has send you in jails.
  4029. clif_displaymessage(fd, msg_txt(118)); // Player warped in jails.
  4030. return 0;
  4031. }
  4032. /*==========================================
  4033. * @unjail/@discharge <char_name> by [Yor]
  4034. * Special warp! No check with nowarp and nowarpto flag
  4035. *------------------------------------------*/
  4036. ACMD_FUNC(unjail)
  4037. {
  4038. struct map_session_data *pl_sd;
  4039. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  4040. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  4041. clif_displaymessage(fd, msg_txt(1135)); // Please enter a player name (usage: @unjail/@discharge <char_name>).
  4042. return -1;
  4043. }
  4044. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4045. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4046. return -1;
  4047. }
  4048. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  4049. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4050. return -1;
  4051. }
  4052. if (!pl_sd->sc.data[SC_JAILED])
  4053. {
  4054. clif_displaymessage(fd, msg_txt(119)); // This player is not in jails.
  4055. return -1;
  4056. }
  4057. //Reset jail time to 1 sec.
  4058. sc_start(&pl_sd->bl,SC_JAILED,100,1,1000);
  4059. clif_displaymessage(pl_sd->fd, msg_txt(120)); // A GM has discharged you from jail.
  4060. clif_displaymessage(fd, msg_txt(121)); // Player unjailed.
  4061. return 0;
  4062. }
  4063. ACMD_FUNC(jailfor)
  4064. {
  4065. struct map_session_data *pl_sd = NULL;
  4066. int year, month, day, hour, minute, value;
  4067. char * modif_p;
  4068. int jailtime = 0,x,y;
  4069. short m_index = 0;
  4070. nullpo_retr(-1, sd);
  4071. if (!message || !*message || sscanf(message, "%s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  4072. clif_displaymessage(fd, msg_txt(400)); //Usage: @jailfor <time> <character name>
  4073. return -1;
  4074. }
  4075. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  4076. modif_p = atcmd_output;
  4077. year = month = day = hour = minute = 0;
  4078. while (modif_p[0] != '\0') {
  4079. value = atoi(modif_p);
  4080. if (value == 0)
  4081. modif_p++;
  4082. else {
  4083. if (modif_p[0] == '-' || modif_p[0] == '+')
  4084. modif_p++;
  4085. while (modif_p[0] >= '0' && modif_p[0] <= '9')
  4086. modif_p++;
  4087. if (modif_p[0] == 'n') {
  4088. minute = value;
  4089. modif_p++;
  4090. } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  4091. minute = value;
  4092. modif_p = modif_p + 2;
  4093. } else if (modif_p[0] == 'h') {
  4094. hour = value;
  4095. modif_p++;
  4096. } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  4097. day = value;
  4098. modif_p++;
  4099. } else if (modif_p[0] == 'm') {
  4100. month = value;
  4101. modif_p++;
  4102. } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  4103. year = value;
  4104. modif_p++;
  4105. } else if (modif_p[0] != '\0') {
  4106. modif_p++;
  4107. }
  4108. }
  4109. }
  4110. if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0) {
  4111. clif_displaymessage(fd, msg_txt(1136)); // Invalid time for jail command.
  4112. return -1;
  4113. }
  4114. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  4115. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4116. return -1;
  4117. }
  4118. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  4119. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4120. return -1;
  4121. }
  4122. jailtime = year*12*30*24*60 + month*30*24*60 + day*24*60 + hour*60 + minute; //In minutes
  4123. if(jailtime==0) {
  4124. clif_displaymessage(fd, msg_txt(1136)); // Invalid time for jail command.
  4125. return -1;
  4126. }
  4127. //Added by Coltaro
  4128. if(pl_sd->sc.data[SC_JAILED] &&
  4129. pl_sd->sc.data[SC_JAILED]->val1 != INT_MAX)
  4130. { //Update the player's jail time
  4131. jailtime += pl_sd->sc.data[SC_JAILED]->val1;
  4132. if (jailtime <= 0) {
  4133. jailtime = 0;
  4134. clif_displaymessage(pl_sd->fd, msg_txt(120)); // GM has discharge you.
  4135. clif_displaymessage(fd, msg_txt(121)); // Player unjailed
  4136. } else {
  4137. get_jail_time(jailtime,&year,&month,&day,&hour,&minute);
  4138. sprintf(atcmd_output,msg_txt(402),msg_txt(1137),year,month,day,hour,minute); //%s in jail for %d years, %d months, %d days, %d hours and %d minutes
  4139. clif_displaymessage(pl_sd->fd, atcmd_output);
  4140. sprintf(atcmd_output,msg_txt(402),msg_txt(1138),year,month,day,hour,minute); //This player is now in jail for %d years, %d months, %d days, %d hours and %d minutes
  4141. clif_displaymessage(fd, atcmd_output);
  4142. }
  4143. } else if (jailtime < 0) {
  4144. clif_displaymessage(fd, msg_txt(1136));
  4145. return -1;
  4146. }
  4147. //Jail locations, add more as you wish.
  4148. switch(rnd()%2)
  4149. {
  4150. case 1: //Jail #1
  4151. m_index = mapindex_name2id(MAP_JAIL);
  4152. x = 49; y = 75;
  4153. break;
  4154. default: //Default Jail
  4155. m_index = mapindex_name2id(MAP_JAIL);
  4156. x = 24; y = 75;
  4157. break;
  4158. }
  4159. sc_start4(&pl_sd->bl,SC_JAILED,100,jailtime,m_index,x,y,jailtime?60000:1000); //jailtime = 0: Time was reset to 0. Wait 1 second to warp player out (since it's done in status_change_timer).
  4160. return 0;
  4161. }
  4162. //By Coltaro
  4163. ACMD_FUNC(jailtime)
  4164. {
  4165. int year, month, day, hour, minute;
  4166. nullpo_retr(-1, sd);
  4167. if (!sd->sc.data[SC_JAILED]) {
  4168. clif_displaymessage(fd, msg_txt(1139)); // You are not in jail.
  4169. return -1;
  4170. }
  4171. if (sd->sc.data[SC_JAILED]->val1 == INT_MAX) {
  4172. clif_displaymessage(fd, msg_txt(1140)); // You have been jailed indefinitely.
  4173. return 0;
  4174. }
  4175. if (sd->sc.data[SC_JAILED]->val1 <= 0) { // Was not jailed with @jailfor (maybe @jail? or warped there? or got recalled?)
  4176. clif_displaymessage(fd, msg_txt(1141)); // You have been jailed for an unknown amount of time.
  4177. return -1;
  4178. }
  4179. //Get remaining jail time
  4180. get_jail_time(sd->sc.data[SC_JAILED]->val1,&year,&month,&day,&hour,&minute);
  4181. sprintf(atcmd_output,msg_txt(402),msg_txt(1142),year,month,day,hour,minute); // You will remain in jail for %d years, %d months, %d days, %d hours and %d minutes
  4182. clif_displaymessage(fd, atcmd_output);
  4183. return 0;
  4184. }
  4185. /*==========================================
  4186. * @disguise <mob_id> by [Valaris] (simplified by [Yor])
  4187. *------------------------------------------*/
  4188. ACMD_FUNC(disguise)
  4189. {
  4190. int id = 0;
  4191. nullpo_retr(-1, sd);
  4192. if (!message || !*message) {
  4193. clif_displaymessage(fd, msg_txt(1143)); // Please enter a Monster/NPC name/ID (usage: @disguise <name/ID>).
  4194. return -1;
  4195. }
  4196. if ((id = atoi(message)) > 0)
  4197. { //Acquired an ID
  4198. if (!mobdb_checkid(id) && !npcdb_checkid(id))
  4199. id = 0; //Invalid id for either mobs or npcs.
  4200. } else { //Acquired a Name
  4201. if ((id = mobdb_searchname(message)) == 0)
  4202. {
  4203. struct npc_data* nd = npc_name2id(message);
  4204. if (nd != NULL)
  4205. id = nd->class_;
  4206. }
  4207. }
  4208. if (id == 0)
  4209. {
  4210. clif_displaymessage(fd, msg_txt(123)); // Invalid Monster/NPC name/ID specified.
  4211. return -1;
  4212. }
  4213. if(pc_isriding(sd))
  4214. {
  4215. clif_displaymessage(fd, msg_txt(1144)); // Character cannot be disguised while mounted.
  4216. return -1;
  4217. }
  4218. pc_disguise(sd, id);
  4219. clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  4220. return 0;
  4221. }
  4222. /*==========================================
  4223. * DisguiseAll
  4224. *------------------------------------------*/
  4225. ACMD_FUNC(disguiseall)
  4226. {
  4227. int mob_id=0;
  4228. struct map_session_data *pl_sd;
  4229. struct s_mapiterator* iter;
  4230. nullpo_retr(-1, sd);
  4231. if (!message || !*message) {
  4232. clif_displaymessage(fd, msg_txt(1145)); // Please enter a Monster/NPC name/ID (usage: @disguiseall <name/ID>).
  4233. return -1;
  4234. }
  4235. if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
  4236. mob_id = atoi(message);
  4237. if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
  4238. clif_displaymessage(fd, msg_txt(123)); // Monster/NPC name/id not found.
  4239. return -1;
  4240. }
  4241. iter = mapit_getallusers();
  4242. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4243. pc_disguise(pl_sd, mob_id);
  4244. mapit_free(iter);
  4245. clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  4246. return 0;
  4247. }
  4248. /*==========================================
  4249. * DisguiseGuild
  4250. *------------------------------------------*/
  4251. ACMD_FUNC(disguiseguild)
  4252. {
  4253. int id = 0, i;
  4254. char monster[NAME_LENGTH], guild[NAME_LENGTH];
  4255. struct map_session_data *pl_sd;
  4256. struct guild *g;
  4257. memset(monster, '\0', sizeof(monster));
  4258. memset(guild, '\0', sizeof(guild));
  4259. if( !message || !*message || sscanf(message, "%23[^,], %23[^\r\n]", monster, guild) < 2 ) {
  4260. clif_displaymessage(fd, msg_txt(1146)); // Please enter a mob name/ID and guild name/ID (usage: @disguiseguild <mob name/ID>, <guild name/ID>).
  4261. return -1;
  4262. }
  4263. if( (id = atoi(monster)) > 0 ) {
  4264. if( !mobdb_checkid(id) && !npcdb_checkid(id) )
  4265. id = 0;
  4266. } else {
  4267. if( (id = mobdb_searchname(monster)) == 0 ) {
  4268. struct npc_data* nd = npc_name2id(monster);
  4269. if( nd != NULL )
  4270. id = nd->class_;
  4271. }
  4272. }
  4273. if( id == 0 ) {
  4274. clif_displaymessage(fd, msg_txt(123)); // Monster/NPC name/id hasn't been found.
  4275. return -1;
  4276. }
  4277. if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) {
  4278. clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  4279. return -1;
  4280. }
  4281. for( i = 0; i < g->max_member; i++ )
  4282. if( (pl_sd = g->member[i].sd) && !pc_isriding(pl_sd) )
  4283. pc_disguise(pl_sd, id);
  4284. clif_displaymessage(fd, msg_txt(122)); // Disguise applied.
  4285. return 0;
  4286. }
  4287. /*==========================================
  4288. * @undisguise by [Yor]
  4289. *------------------------------------------*/
  4290. ACMD_FUNC(undisguise)
  4291. {
  4292. nullpo_retr(-1, sd);
  4293. if (sd->disguise) {
  4294. pc_disguise(sd, 0);
  4295. clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  4296. } else {
  4297. clif_displaymessage(fd, msg_txt(125)); // You're not disguised.
  4298. return -1;
  4299. }
  4300. return 0;
  4301. }
  4302. /*==========================================
  4303. * UndisguiseAll
  4304. *------------------------------------------*/
  4305. ACMD_FUNC(undisguiseall)
  4306. {
  4307. struct map_session_data *pl_sd;
  4308. struct s_mapiterator* iter;
  4309. nullpo_retr(-1, sd);
  4310. iter = mapit_getallusers();
  4311. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4312. if( pl_sd->disguise )
  4313. pc_disguise(pl_sd, 0);
  4314. mapit_free(iter);
  4315. clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  4316. return 0;
  4317. }
  4318. /*==========================================
  4319. * UndisguiseGuild
  4320. *------------------------------------------*/
  4321. ACMD_FUNC(undisguiseguild)
  4322. {
  4323. char guild_name[NAME_LENGTH];
  4324. struct map_session_data *pl_sd;
  4325. struct guild *g;
  4326. int i;
  4327. nullpo_retr(-1, sd);
  4328. memset(guild_name, '\0', sizeof(guild_name));
  4329. if(!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4330. clif_displaymessage(fd, msg_txt(1147)); // Please enter guild name/ID (usage: @undisguiseguild <guild name/ID>).
  4331. return -1;
  4332. }
  4333. if( (g = guild_searchname(guild_name)) == NULL && (g = guild_search(atoi(message))) == NULL ) {
  4334. clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  4335. return -1;
  4336. }
  4337. for(i = 0; i < g->max_member; i++)
  4338. if( (pl_sd = g->member[i].sd) && pl_sd->disguise )
  4339. pc_disguise(pl_sd, 0);
  4340. clif_displaymessage(fd, msg_txt(124)); // Undisguise applied.
  4341. return 0;
  4342. }
  4343. /*==========================================
  4344. * @exp by [Skotlex]
  4345. *------------------------------------------*/
  4346. ACMD_FUNC(exp)
  4347. {
  4348. char output[CHAT_SIZE_MAX];
  4349. double nextb, nextj;
  4350. nullpo_retr(-1, sd);
  4351. memset(output, '\0', sizeof(output));
  4352. nextb = pc_nextbaseexp(sd);
  4353. if (nextb)
  4354. nextb = sd->status.base_exp*100.0/nextb;
  4355. nextj = pc_nextjobexp(sd);
  4356. if (nextj)
  4357. nextj = sd->status.job_exp*100.0/nextj;
  4358. sprintf(output, msg_txt(1148), sd->status.base_level, nextb, sd->status.job_level, nextj); // Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%)
  4359. clif_displaymessage(fd, output);
  4360. return 0;
  4361. }
  4362. /*==========================================
  4363. * @broadcast by [Valaris]
  4364. *------------------------------------------*/
  4365. ACMD_FUNC(broadcast)
  4366. {
  4367. nullpo_retr(-1, sd);
  4368. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4369. if (!message || !*message) {
  4370. clif_displaymessage(fd, msg_txt(1149)); // Please enter a message (usage: @broadcast <message>).
  4371. return -1;
  4372. }
  4373. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4374. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, 0);
  4375. return 0;
  4376. }
  4377. /*==========================================
  4378. * @localbroadcast by [Valaris]
  4379. *------------------------------------------*/
  4380. ACMD_FUNC(localbroadcast)
  4381. {
  4382. nullpo_retr(-1, sd);
  4383. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4384. if (!message || !*message) {
  4385. clif_displaymessage(fd, msg_txt(1150)); // Please enter a message (usage: @localbroadcast <message>).
  4386. return -1;
  4387. }
  4388. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4389. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  4390. return 0;
  4391. }
  4392. /*==========================================
  4393. * @email <actual@email> <new@email> by [Yor]
  4394. *------------------------------------------*/
  4395. ACMD_FUNC(email)
  4396. {
  4397. char actual_email[100];
  4398. char new_email[100];
  4399. nullpo_retr(-1, sd);
  4400. memset(actual_email, '\0', sizeof(actual_email));
  4401. memset(new_email, '\0', sizeof(new_email));
  4402. if (!message || !*message || sscanf(message, "%99s %99s", actual_email, new_email) < 2) {
  4403. clif_displaymessage(fd, msg_txt(1151)); // Please enter 2 emails (usage: @email <actual@email> <new@email>).
  4404. return -1;
  4405. }
  4406. if (e_mail_check(actual_email) == 0) {
  4407. clif_displaymessage(fd, msg_txt(144)); // Invalid actual email. If you have default e-mail, give a@a.com.
  4408. return -1;
  4409. } else if (e_mail_check(new_email) == 0) {
  4410. clif_displaymessage(fd, msg_txt(145)); // Invalid new email. Please enter a real e-mail.
  4411. return -1;
  4412. } else if (strcmpi(new_email, "a@a.com") == 0) {
  4413. clif_displaymessage(fd, msg_txt(146)); // New email must be a real e-mail.
  4414. return -1;
  4415. } else if (strcmpi(actual_email, new_email) == 0) {
  4416. clif_displaymessage(fd, msg_txt(147)); // New email must be different of the actual e-mail.
  4417. return -1;
  4418. }
  4419. chrif_changeemail(sd->status.account_id, actual_email, new_email);
  4420. clif_displaymessage(fd, msg_txt(148)); // Information sended to login-server via char-server.
  4421. return 0;
  4422. }
  4423. /*==========================================
  4424. *@effect
  4425. *------------------------------------------*/
  4426. ACMD_FUNC(effect)
  4427. {
  4428. int type = 0, flag = 0;
  4429. nullpo_retr(-1, sd);
  4430. if (!message || !*message || sscanf(message, "%d", &type) < 1) {
  4431. clif_displaymessage(fd, msg_txt(1152)); // Please enter an effect number (usage: @effect <effect number>).
  4432. return -1;
  4433. }
  4434. clif_specialeffect(&sd->bl, type, (send_target)flag);
  4435. clif_displaymessage(fd, msg_txt(229)); // Your effect has changed.
  4436. return 0;
  4437. }
  4438. /*==========================================
  4439. * @killer by MouseJstr
  4440. * enable killing players even when not in pvp
  4441. *------------------------------------------*/
  4442. ACMD_FUNC(killer)
  4443. {
  4444. nullpo_retr(-1, sd);
  4445. sd->state.killer = !sd->state.killer;
  4446. if(sd->state.killer)
  4447. clif_displaymessage(fd, msg_txt(241));
  4448. else {
  4449. clif_displaymessage(fd, msg_txt(292));
  4450. pc_stop_attack(sd);
  4451. }
  4452. return 0;
  4453. }
  4454. /*==========================================
  4455. * @killable by MouseJstr
  4456. * enable other people killing you
  4457. *------------------------------------------*/
  4458. ACMD_FUNC(killable)
  4459. {
  4460. nullpo_retr(-1, sd);
  4461. sd->state.killable = !sd->state.killable;
  4462. if(sd->state.killable)
  4463. clif_displaymessage(fd, msg_txt(242));
  4464. else {
  4465. clif_displaymessage(fd, msg_txt(288));
  4466. map_foreachinrange(atcommand_stopattack,&sd->bl, AREA_SIZE, BL_CHAR, sd->bl.id);
  4467. }
  4468. return 0;
  4469. }
  4470. /*==========================================
  4471. * @skillon by MouseJstr
  4472. * turn skills on for the map
  4473. *------------------------------------------*/
  4474. ACMD_FUNC(skillon)
  4475. {
  4476. nullpo_retr(-1, sd);
  4477. map[sd->bl.m].flag.noskill = 0;
  4478. clif_displaymessage(fd, msg_txt(244));
  4479. return 0;
  4480. }
  4481. /*==========================================
  4482. * @skilloff by MouseJstr
  4483. * Turn skills off on the map
  4484. *------------------------------------------*/
  4485. ACMD_FUNC(skilloff)
  4486. {
  4487. nullpo_retr(-1, sd);
  4488. map[sd->bl.m].flag.noskill = 1;
  4489. clif_displaymessage(fd, msg_txt(243));
  4490. return 0;
  4491. }
  4492. /*==========================================
  4493. * @npcmove by MouseJstr
  4494. * move a npc
  4495. *------------------------------------------*/
  4496. ACMD_FUNC(npcmove)
  4497. {
  4498. int x = 0, y = 0, m;
  4499. struct npc_data *nd = 0;
  4500. nullpo_retr(-1, sd);
  4501. memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  4502. if (!message || !*message || sscanf(message, "%d %d %23[^\n]", &x, &y, atcmd_player_name) < 3) {
  4503. clif_displaymessage(fd, msg_txt(1153)); // Usage: @npcmove <X> <Y> <npc_name>
  4504. return -1;
  4505. }
  4506. if ((nd = npc_name2id(atcmd_player_name)) == NULL)
  4507. {
  4508. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist.
  4509. return -1;
  4510. }
  4511. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  4512. {
  4513. clif_displaymessage(fd, msg_txt(1154)); // NPC is not on this map.
  4514. return -1; //Not on a map.
  4515. }
  4516. x = cap_value(x, 0, map[m].xs-1);
  4517. y = cap_value(y, 0, map[m].ys-1);
  4518. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  4519. map_moveblock(&nd->bl, x, y, gettick());
  4520. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  4521. clif_displaymessage(fd, msg_txt(1155)); // NPC moved.
  4522. return 0;
  4523. }
  4524. /*==========================================
  4525. * @addwarp by MouseJstr
  4526. * Create a new static warp point.
  4527. *------------------------------------------*/
  4528. ACMD_FUNC(addwarp)
  4529. {
  4530. char mapname[32], warpname[NAME_LENGTH+1];
  4531. int x,y;
  4532. unsigned short m;
  4533. struct npc_data* nd;
  4534. nullpo_retr(-1, sd);
  4535. memset(warpname, '\0', sizeof(warpname));
  4536. if (!message || !*message || sscanf(message, "%31s %d %d %23[^\n]", mapname, &x, &y, warpname) < 4) {
  4537. clif_displaymessage(fd, msg_txt(1156)); // Usage: @addwarp <mapname> <X> <Y> <npc name>
  4538. return -1;
  4539. }
  4540. m = mapindex_name2id(mapname);
  4541. if( m == 0 )
  4542. {
  4543. sprintf(atcmd_output, msg_txt(1157), mapname); // Unknown map '%s'.
  4544. clif_displaymessage(fd, atcmd_output);
  4545. return -1;
  4546. }
  4547. nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
  4548. if( nd == NULL )
  4549. return -1;
  4550. sprintf(atcmd_output, msg_txt(1158), nd->exname); // New warp NPC '%s' created.
  4551. clif_displaymessage(fd, atcmd_output);
  4552. return 0;
  4553. }
  4554. /*==========================================
  4555. * @follow by [MouseJstr]
  4556. * Follow a player .. staying no more then 5 spaces away
  4557. *------------------------------------------*/
  4558. ACMD_FUNC(follow)
  4559. {
  4560. struct map_session_data *pl_sd = NULL;
  4561. nullpo_retr(-1, sd);
  4562. if (!message || !*message) {
  4563. if (sd->followtarget == -1)
  4564. return -1;
  4565. pc_stop_following (sd);
  4566. clif_displaymessage(fd, msg_txt(1159)); // Follow mode OFF.
  4567. return 0;
  4568. }
  4569. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  4570. {
  4571. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4572. return -1;
  4573. }
  4574. if (sd->followtarget == pl_sd->bl.id) {
  4575. pc_stop_following (sd);
  4576. clif_displaymessage(fd, msg_txt(1159)); // Follow mode OFF.
  4577. } else {
  4578. pc_follow(sd, pl_sd->bl.id);
  4579. clif_displaymessage(fd, msg_txt(1160)); // Follow mode ON.
  4580. }
  4581. return 0;
  4582. }
  4583. /*==========================================
  4584. * @dropall by [MouseJstr]
  4585. * Drop all your possession on the ground
  4586. *------------------------------------------*/
  4587. ACMD_FUNC(dropall)
  4588. {
  4589. int i;
  4590. nullpo_retr(-1, sd);
  4591. for (i = 0; i < MAX_INVENTORY; i++) {
  4592. if (sd->status.inventory[i].amount) {
  4593. if(sd->status.inventory[i].equip != 0)
  4594. pc_unequipitem(sd, i, 3);
  4595. pc_dropitem(sd, i, sd->status.inventory[i].amount);
  4596. }
  4597. }
  4598. return 0;
  4599. }
  4600. /*==========================================
  4601. * @storeall by [MouseJstr]
  4602. * Put everything into storage
  4603. *------------------------------------------*/
  4604. ACMD_FUNC(storeall)
  4605. {
  4606. int i;
  4607. nullpo_retr(-1, sd);
  4608. if (sd->state.storage_flag != 1)
  4609. { //Open storage.
  4610. if( storage_storageopen(sd) == 1 ) {
  4611. clif_displaymessage(fd, msg_txt(1161)); // You currently cannot open your storage.
  4612. return -1;
  4613. }
  4614. }
  4615. for (i = 0; i < MAX_INVENTORY; i++) {
  4616. if (sd->status.inventory[i].amount) {
  4617. if(sd->status.inventory[i].equip != 0)
  4618. pc_unequipitem(sd, i, 3);
  4619. storage_storageadd(sd, i, sd->status.inventory[i].amount);
  4620. }
  4621. }
  4622. storage_storageclose(sd);
  4623. clif_displaymessage(fd, msg_txt(1162)); // All items stored.
  4624. return 0;
  4625. }
  4626. /*==========================================
  4627. * @skillid by [MouseJstr]
  4628. * lookup a skill by name
  4629. *------------------------------------------*/
  4630. ACMD_FUNC(skillid)
  4631. {
  4632. int skillen, idx;
  4633. nullpo_retr(-1, sd);
  4634. if (!message || !*message)
  4635. {
  4636. clif_displaymessage(fd, msg_txt(1163)); // Please enter a skill name to look up (usage: @skillid <skill name>).
  4637. return -1;
  4638. }
  4639. skillen = strlen(message);
  4640. for (idx = 0; idx < MAX_SKILL_DB; idx++) {
  4641. if (strnicmp(skill_db[idx].name, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0)
  4642. {
  4643. sprintf(atcmd_output, msg_txt(1164), idx, skill_db[idx].desc); // skill %d: %s
  4644. clif_displaymessage(fd, atcmd_output);
  4645. }
  4646. }
  4647. return 0;
  4648. }
  4649. /*==========================================
  4650. * @useskill by [MouseJstr]
  4651. * A way of using skills without having to find them in the skills menu
  4652. *------------------------------------------*/
  4653. ACMD_FUNC(useskill)
  4654. {
  4655. struct map_session_data *pl_sd = NULL;
  4656. struct block_list *bl;
  4657. int skillnum;
  4658. int skilllv;
  4659. char target[100];
  4660. nullpo_retr(-1, sd);
  4661. if(!message || !*message || sscanf(message, "%d %d %23[^\n]", &skillnum, &skilllv, target) != 3) {
  4662. clif_displaymessage(fd, msg_txt(1165)); // Usage: @useskill <skill ID> <skill level> <target>
  4663. return -1;
  4664. }
  4665. if ( (pl_sd = map_nick2sd(target)) == NULL )
  4666. {
  4667. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4668. return -1;
  4669. }
  4670. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  4671. {
  4672. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  4673. return -1;
  4674. }
  4675. if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL
  4676. && sd->hd && merc_is_hom_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
  4677. bl = &sd->hd->bl;
  4678. else
  4679. bl = &sd->bl;
  4680. if (skill_get_inf(skillnum)&INF_GROUND_SKILL)
  4681. unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skillnum, skilllv);
  4682. else
  4683. unit_skilluse_id(bl, pl_sd->bl.id, skillnum, skilllv);
  4684. return 0;
  4685. }
  4686. /*==========================================
  4687. * @displayskill by [Skotlex]
  4688. * Debug command to locate new skill IDs. It sends the
  4689. * three possible skill-effect packets to the area.
  4690. *------------------------------------------*/
  4691. ACMD_FUNC(displayskill)
  4692. {
  4693. struct status_data * status;
  4694. unsigned int tick;
  4695. int skillnum;
  4696. int skilllv = 1;
  4697. nullpo_retr(-1, sd);
  4698. if (!message || !*message || sscanf(message, "%d %d", &skillnum, &skilllv) < 1)
  4699. {
  4700. clif_displaymessage(fd, msg_txt(1166)); // Usage: @displayskill <skill ID> {<skill level>}
  4701. return -1;
  4702. }
  4703. status = status_get_status_data(&sd->bl);
  4704. tick = gettick();
  4705. clif_skill_damage(&sd->bl,&sd->bl, tick, status->amotion, status->dmotion, 1, 1, skillnum, skilllv, 5);
  4706. clif_skill_nodamage(&sd->bl, &sd->bl, skillnum, skilllv, 1);
  4707. clif_skill_poseffect(&sd->bl, skillnum, skilllv, sd->bl.x, sd->bl.y, tick);
  4708. return 0;
  4709. }
  4710. /*==========================================
  4711. * @skilltree by [MouseJstr]
  4712. * prints the skill tree for a player required to get to a skill
  4713. *------------------------------------------*/
  4714. ACMD_FUNC(skilltree)
  4715. {
  4716. struct map_session_data *pl_sd = NULL;
  4717. int skillnum;
  4718. int meets, j, c=0;
  4719. char target[NAME_LENGTH];
  4720. struct skill_tree_entry *ent;
  4721. nullpo_retr(-1, sd);
  4722. if(!message || !*message || sscanf(message, "%d %23[^\r\n]", &skillnum, target) != 2) {
  4723. clif_displaymessage(fd, msg_txt(1167)); // Usage: @skilltree <skill ID> <target>
  4724. return -1;
  4725. }
  4726. if ( (pl_sd = map_nick2sd(target)) == NULL )
  4727. {
  4728. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  4729. return -1;
  4730. }
  4731. c = pc_calc_skilltree_normalize_job(pl_sd);
  4732. c = pc_mapid2jobid(c, pl_sd->status.sex);
  4733. sprintf(atcmd_output, msg_txt(1168), job_name(c), pc_checkskill(pl_sd, NV_BASIC)); // Player is using %s skill tree (%d basic points).
  4734. clif_displaymessage(fd, atcmd_output);
  4735. ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[c][j].id == 0 || skill_tree[c][j].id == skillnum );
  4736. if( j == MAX_SKILL_TREE || skill_tree[c][j].id == 0 )
  4737. {
  4738. clif_displaymessage(fd, msg_txt(1169)); // The player cannot use that skill.
  4739. return 0;
  4740. }
  4741. ent = &skill_tree[c][j];
  4742. meets = 1;
  4743. for(j=0;j<MAX_PC_SKILL_REQUIRE;j++)
  4744. {
  4745. if( ent->need[j].id && pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv)
  4746. {
  4747. sprintf(atcmd_output, msg_txt(1170), ent->need[j].lv, skill_db[ent->need[j].id].desc); // Player requires level %d of skill %s.
  4748. clif_displaymessage(fd, atcmd_output);
  4749. meets = 0;
  4750. }
  4751. }
  4752. if (meets == 1) {
  4753. clif_displaymessage(fd, msg_txt(1171)); // The player meets all the requirements for that skill.
  4754. }
  4755. return 0;
  4756. }
  4757. // Hand a ring with partners name on it to this char
  4758. void getring (struct map_session_data* sd)
  4759. {
  4760. int flag, item_id;
  4761. struct item item_tmp;
  4762. item_id = (sd->status.sex) ? WEDDING_RING_M : WEDDING_RING_F;
  4763. memset(&item_tmp, 0, sizeof(item_tmp));
  4764. item_tmp.nameid = item_id;
  4765. item_tmp.identify = 1;
  4766. item_tmp.card[0] = 255;
  4767. item_tmp.card[2] = sd->status.partner_id;
  4768. item_tmp.card[3] = sd->status.partner_id >> 16;
  4769. if((flag = pc_additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
  4770. clif_additem(sd,0,0,flag);
  4771. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  4772. }
  4773. }
  4774. /*==========================================
  4775. * @marry by [MouseJstr], fixed by Lupus
  4776. * Marry two players
  4777. *------------------------------------------*/
  4778. ACMD_FUNC(marry)
  4779. {
  4780. struct map_session_data *pl_sd = NULL;
  4781. char player_name[NAME_LENGTH] = "";
  4782. nullpo_retr(-1, sd);
  4783. if (!message || !*message || sscanf(message, "%23s", player_name) != 1) {
  4784. clif_displaymessage(fd, msg_txt(1172)); // Usage: @marry <char name>
  4785. return -1;
  4786. }
  4787. if ((pl_sd = map_nick2sd(player_name)) == NULL) {
  4788. clif_displaymessage(fd, msg_txt(3));
  4789. return -1;
  4790. }
  4791. if (pc_marriage(sd, pl_sd) == 0) {
  4792. clif_displaymessage(fd, msg_txt(1173)); // They are married... wish them well.
  4793. clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus]
  4794. getring(sd); // Auto-give named rings (Aru)
  4795. getring(pl_sd);
  4796. return 0;
  4797. }
  4798. clif_displaymessage(fd, msg_txt(1174)); // The two cannot wed because one is either a baby or already married.
  4799. return -1;
  4800. }
  4801. /*==========================================
  4802. * @divorce by [MouseJstr], fixed by [Lupus]
  4803. * divorce two players
  4804. *------------------------------------------*/
  4805. ACMD_FUNC(divorce)
  4806. {
  4807. nullpo_retr(-1, sd);
  4808. if (pc_divorce(sd) != 0) {
  4809. sprintf(atcmd_output, msg_txt(1175), sd->status.name); // '%s' is not married.
  4810. clif_displaymessage(fd, atcmd_output);
  4811. return -1;
  4812. }
  4813. sprintf(atcmd_output, msg_txt(1176), sd->status.name); // '%s' and his/her partner are now divorced.
  4814. clif_displaymessage(fd, atcmd_output);
  4815. return 0;
  4816. }
  4817. /*==========================================
  4818. * @changelook by [Celest]
  4819. *------------------------------------------*/
  4820. ACMD_FUNC(changelook)
  4821. {
  4822. int i, j = 0, k = 0;
  4823. int pos[7] = { LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HEAD_BOTTOM,LOOK_WEAPON,LOOK_SHIELD,LOOK_SHOES,LOOK_ROBE };
  4824. if((i = sscanf(message, "%d %d", &j, &k)) < 1) {
  4825. clif_displaymessage(fd, msg_txt(1177)); // Usage: @changelook {<position>} <view id>
  4826. clif_displaymessage(fd, msg_txt(1178)); // Position: 1-Top 2-Middle 3-Bottom 4-Weapon 5-Shield 6-Shoes 7-Robe
  4827. return -1;
  4828. } else if ( i == 2 ) {
  4829. if (j < 1 || j > 7)
  4830. j = 1;
  4831. j = pos[j - 1];
  4832. } else if( i == 1 ) { // position not defined, use HEAD_TOP as default
  4833. k = j; // swap
  4834. j = LOOK_HEAD_TOP;
  4835. }
  4836. clif_changelook(&sd->bl,j,k);
  4837. return 0;
  4838. }
  4839. /*==========================================
  4840. * @autotrade by durf [Lupus] [Paradox924X]
  4841. * Turns on/off Autotrade for a specific player
  4842. *------------------------------------------*/
  4843. ACMD_FUNC(autotrade)
  4844. {
  4845. nullpo_retr(-1, sd);
  4846. if( map[sd->bl.m].flag.autotrade != battle_config.autotrade_mapflag ) {
  4847. clif_displaymessage(fd, msg_txt(1179)); // Autotrade is not allowed on this map.
  4848. return -1;
  4849. }
  4850. if( pc_isdead(sd) ) {
  4851. clif_displaymessage(fd, msg_txt(1180)); // You cannot autotrade when dead.
  4852. return -1;
  4853. }
  4854. if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
  4855. clif_displaymessage(fd, msg_txt(549)); // "You should have a shop open to use @autotrade."
  4856. return -1;
  4857. }
  4858. sd->state.autotrade = 1;
  4859. if( battle_config.at_timeout )
  4860. {
  4861. int timeout = atoi(message);
  4862. status_change_start(&sd->bl, SC_AUTOTRADE, 10000, 0, 0, 0, 0, ((timeout > 0) ? min(timeout,battle_config.at_timeout) : battle_config.at_timeout) * 60000, 0);
  4863. }
  4864. clif_authfail_fd(fd, 15);
  4865. return 0;
  4866. }
  4867. /*==========================================
  4868. * @changegm by durf (changed by Lupus)
  4869. * Changes Master of your Guild to a specified guild member
  4870. *------------------------------------------*/
  4871. ACMD_FUNC(changegm)
  4872. {
  4873. struct guild *g;
  4874. struct map_session_data *pl_sd;
  4875. nullpo_retr(-1, sd);
  4876. if (sd->status.guild_id == 0 || (g = guild_search(sd->status.guild_id)) == NULL || strcmp(g->master,sd->status.name)) {
  4877. clif_displaymessage(fd, msg_txt(1181)); // You need to be a Guild Master to use this command.
  4878. return -1;
  4879. }
  4880. if( map[sd->bl.m].flag.guildlock || map[sd->bl.m].flag.gvg_castle ) {
  4881. clif_displaymessage(fd, msg_txt(1182)); // You cannot change guild leaders on this map.
  4882. return -1;
  4883. }
  4884. if( !message[0] ) {
  4885. clif_displaymessage(fd, msg_txt(1183)); // Usage: @changegm <guild_member_name>
  4886. return -1;
  4887. }
  4888. if((pl_sd=map_nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
  4889. clif_displaymessage(fd, msg_txt(1184)); // Target character must be online and be a guild member.
  4890. return -1;
  4891. }
  4892. guild_gm_change(sd->status.guild_id, pl_sd);
  4893. return 0;
  4894. }
  4895. /*==========================================
  4896. * @changeleader by Skotlex
  4897. * Changes the leader of a party.
  4898. *------------------------------------------*/
  4899. ACMD_FUNC(changeleader)
  4900. {
  4901. nullpo_retr(-1, sd);
  4902. if( !message[0] )
  4903. {
  4904. clif_displaymessage(fd, msg_txt(1185)); // Usage: @changeleader <party_member_name>
  4905. return -1;
  4906. }
  4907. if (party_changeleader(sd, map_nick2sd((char *) message)))
  4908. return 0;
  4909. return -1;
  4910. }
  4911. /*==========================================
  4912. * @partyoption by Skotlex
  4913. * Used to change the item share setting of a party.
  4914. *------------------------------------------*/
  4915. ACMD_FUNC(partyoption)
  4916. {
  4917. struct party_data *p;
  4918. int mi, option;
  4919. char w1[16], w2[16];
  4920. nullpo_retr(-1, sd);
  4921. if (sd->status.party_id == 0 || (p = party_search(sd->status.party_id)) == NULL)
  4922. {
  4923. clif_displaymessage(fd, msg_txt(282));
  4924. return -1;
  4925. }
  4926. ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd );
  4927. if (mi == MAX_PARTY)
  4928. return -1; //Shouldn't happen
  4929. if (!p->party.member[mi].leader)
  4930. {
  4931. clif_displaymessage(fd, msg_txt(282));
  4932. return -1;
  4933. }
  4934. if(!message || !*message || sscanf(message, "%15s %15s", w1, w2) < 2)
  4935. {
  4936. clif_displaymessage(fd, msg_txt(1186)); // Usage: @partyoption <pickup share: yes/no> <item distribution: yes/no>
  4937. return -1;
  4938. }
  4939. option = (config_switch(w1)?1:0)|(config_switch(w2)?2:0);
  4940. //Change item share type.
  4941. if (option != p->party.item)
  4942. party_changeoption(sd, p->party.exp, option);
  4943. else
  4944. clif_displaymessage(fd, msg_txt(286));
  4945. return 0;
  4946. }
  4947. /*==========================================
  4948. * @autoloot by Upa-Kun
  4949. * Turns on/off AutoLoot for a specific player
  4950. *------------------------------------------*/
  4951. ACMD_FUNC(autoloot)
  4952. {
  4953. int rate;
  4954. double drate;
  4955. nullpo_retr(-1, sd);
  4956. // autoloot command without value
  4957. if(!message || !*message)
  4958. {
  4959. if (sd->state.autoloot)
  4960. rate = 0;
  4961. else
  4962. rate = 10000;
  4963. } else {
  4964. drate = atof(message);
  4965. rate = (int)(drate*100);
  4966. }
  4967. if (rate < 0) rate = 0;
  4968. if (rate > 10000) rate = 10000;
  4969. sd->state.autoloot = rate;
  4970. if (sd->state.autoloot) {
  4971. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1187),((double)sd->state.autoloot)/100.); // Autolooting items with drop rates of %0.02f%% and below.
  4972. clif_displaymessage(fd, atcmd_output);
  4973. }else
  4974. clif_displaymessage(fd, msg_txt(1188)); // Autoloot is now off.
  4975. return 0;
  4976. }
  4977. /*==========================================
  4978. * @alootid
  4979. *------------------------------------------*/
  4980. ACMD_FUNC(autolootitem)
  4981. {
  4982. struct item_data *item_data = NULL;
  4983. int i;
  4984. int action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  4985. if (message && *message) {
  4986. if (message[0] == '+') {
  4987. message++;
  4988. action = 1;
  4989. }
  4990. else if (message[0] == '-') {
  4991. message++;
  4992. action = 2;
  4993. }
  4994. else if (!strcmp(message,"reset"))
  4995. action = 4;
  4996. }
  4997. if (action < 3) // add or remove
  4998. {
  4999. if ((item_data = itemdb_exists(atoi(message))) == NULL)
  5000. item_data = itemdb_searchname(message);
  5001. if (!item_data) {
  5002. // No items founds in the DB with Id or Name
  5003. clif_displaymessage(fd, msg_txt(1189)); // Item not found.
  5004. return -1;
  5005. }
  5006. }
  5007. switch(action) {
  5008. case 1:
  5009. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5010. if (i != AUTOLOOTITEM_SIZE) {
  5011. clif_displaymessage(fd, msg_txt(1190)); // You're already autolooting this item.
  5012. return -1;
  5013. }
  5014. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == 0);
  5015. if (i == AUTOLOOTITEM_SIZE) {
  5016. clif_displaymessage(fd, msg_txt(1191)); // Your autolootitem list is full. Remove some items first with @autolootid -<item name or ID>.
  5017. return -1;
  5018. }
  5019. sd->state.autolootid[i] = item_data->nameid; // Autoloot Activated
  5020. sprintf(atcmd_output, msg_txt(1192), item_data->name, item_data->jname, item_data->nameid); // Autolooting item: '%s'/'%s' {%d}
  5021. clif_displaymessage(fd, atcmd_output);
  5022. sd->state.autolooting = 1;
  5023. break;
  5024. case 2:
  5025. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  5026. if (i == AUTOLOOTITEM_SIZE) {
  5027. clif_displaymessage(fd, msg_txt(1193)); // You're currently not autolooting this item.
  5028. return -1;
  5029. }
  5030. sd->state.autolootid[i] = 0;
  5031. sprintf(atcmd_output, msg_txt(1194), item_data->name, item_data->jname, item_data->nameid); // Removed item: '%s'/'%s' {%d} from your autolootitem list.
  5032. clif_displaymessage(fd, atcmd_output);
  5033. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5034. if (i == AUTOLOOTITEM_SIZE) {
  5035. sd->state.autolooting = 0;
  5036. }
  5037. break;
  5038. case 3:
  5039. sprintf(atcmd_output, msg_txt(1195), AUTOLOOTITEM_SIZE); // You can have %d items on your autolootitem list.
  5040. clif_displaymessage(fd, atcmd_output);
  5041. clif_displaymessage(fd, msg_txt(1196)); // To add an item to the list, use "@alootid +<item name or ID>". To remove an item, use "@alootid -<item name or ID>".
  5042. clif_displaymessage(fd, msg_txt(1197)); // "@alootid reset" will clear your autolootitem list.
  5043. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5044. if (i == AUTOLOOTITEM_SIZE) {
  5045. clif_displaymessage(fd, msg_txt(1198)); // Your autolootitem list is empty.
  5046. } else {
  5047. clif_displaymessage(fd, msg_txt(1199)); // Items on your autolootitem list:
  5048. for(i = 0; i < AUTOLOOTITEM_SIZE; i++)
  5049. {
  5050. if (sd->state.autolootid[i] == 0)
  5051. continue;
  5052. if (!(item_data = itemdb_exists(sd->state.autolootid[i]))) {
  5053. 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);
  5054. continue;
  5055. }
  5056. sprintf(atcmd_output, "'%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5057. clif_displaymessage(fd, atcmd_output);
  5058. }
  5059. }
  5060. break;
  5061. case 4:
  5062. memset(sd->state.autolootid, 0, sizeof(sd->state.autolootid));
  5063. clif_displaymessage(fd, msg_txt(1200)); // Your autolootitem list has been reset.
  5064. sd->state.autolooting = 0;
  5065. break;
  5066. }
  5067. return 0;
  5068. }
  5069. /**
  5070. * No longer available, keeping here just in case it's back someday. [Ind]
  5071. **/
  5072. /*==========================================
  5073. * It is made to rain.
  5074. *------------------------------------------*/
  5075. //ACMD_FUNC(rain)
  5076. //{
  5077. // nullpo_retr(-1, sd);
  5078. // if (map[sd->bl.m].flag.rain) {
  5079. // map[sd->bl.m].flag.rain=0;
  5080. // clif_weather(sd->bl.m);
  5081. // clif_displaymessage(fd, msg_txt(1201)); // The rain has stopped.
  5082. // } else {
  5083. // map[sd->bl.m].flag.rain=1;
  5084. // clif_weather(sd->bl.m);
  5085. // clif_displaymessage(fd, msg_txt(1202)); // It has started to rain.
  5086. // }
  5087. // return 0;
  5088. //}
  5089. /*==========================================
  5090. * It is made to snow.
  5091. *------------------------------------------*/
  5092. ACMD_FUNC(snow)
  5093. {
  5094. nullpo_retr(-1, sd);
  5095. if (map[sd->bl.m].flag.snow) {
  5096. map[sd->bl.m].flag.snow=0;
  5097. clif_weather(sd->bl.m);
  5098. clif_displaymessage(fd, msg_txt(1203)); // Snow has stopped falling.
  5099. } else {
  5100. map[sd->bl.m].flag.snow=1;
  5101. clif_weather(sd->bl.m);
  5102. clif_displaymessage(fd, msg_txt(1204)); // It has started to snow.
  5103. }
  5104. return 0;
  5105. }
  5106. /*==========================================
  5107. * Cherry tree snowstorm is made to fall. (Sakura)
  5108. *------------------------------------------*/
  5109. ACMD_FUNC(sakura)
  5110. {
  5111. nullpo_retr(-1, sd);
  5112. if (map[sd->bl.m].flag.sakura) {
  5113. map[sd->bl.m].flag.sakura=0;
  5114. clif_weather(sd->bl.m);
  5115. clif_displaymessage(fd, msg_txt(1205)); // Cherry tree leaves no longer fall.
  5116. } else {
  5117. map[sd->bl.m].flag.sakura=1;
  5118. clif_weather(sd->bl.m);
  5119. clif_displaymessage(fd, msg_txt(1206)); // Cherry tree leaves have begun to fall.
  5120. }
  5121. return 0;
  5122. }
  5123. /*==========================================
  5124. * Clouds appear.
  5125. *------------------------------------------*/
  5126. ACMD_FUNC(clouds)
  5127. {
  5128. nullpo_retr(-1, sd);
  5129. if (map[sd->bl.m].flag.clouds) {
  5130. map[sd->bl.m].flag.clouds=0;
  5131. clif_weather(sd->bl.m);
  5132. clif_displaymessage(fd, msg_txt(1207)); // The clouds has disappear.
  5133. } else {
  5134. map[sd->bl.m].flag.clouds=1;
  5135. clif_weather(sd->bl.m);
  5136. clif_displaymessage(fd, msg_txt(1208)); // Clouds appear.
  5137. }
  5138. return 0;
  5139. }
  5140. /*==========================================
  5141. * Different type of clouds using effect 516
  5142. *------------------------------------------*/
  5143. ACMD_FUNC(clouds2)
  5144. {
  5145. nullpo_retr(-1, sd);
  5146. if (map[sd->bl.m].flag.clouds2) {
  5147. map[sd->bl.m].flag.clouds2=0;
  5148. clif_weather(sd->bl.m);
  5149. clif_displaymessage(fd, msg_txt(1209)); // The alternative clouds disappear.
  5150. } else {
  5151. map[sd->bl.m].flag.clouds2=1;
  5152. clif_weather(sd->bl.m);
  5153. clif_displaymessage(fd, msg_txt(1210)); // Alternative clouds appear.
  5154. }
  5155. return 0;
  5156. }
  5157. /*==========================================
  5158. * Fog hangs over.
  5159. *------------------------------------------*/
  5160. ACMD_FUNC(fog)
  5161. {
  5162. nullpo_retr(-1, sd);
  5163. if (map[sd->bl.m].flag.fog) {
  5164. map[sd->bl.m].flag.fog=0;
  5165. clif_weather(sd->bl.m);
  5166. clif_displaymessage(fd, msg_txt(1211)); // The fog has gone.
  5167. } else {
  5168. map[sd->bl.m].flag.fog=1;
  5169. clif_weather(sd->bl.m);
  5170. clif_displaymessage(fd, msg_txt(1212)); // Fog hangs over.
  5171. }
  5172. return 0;
  5173. }
  5174. /*==========================================
  5175. * Fallen leaves fall.
  5176. *------------------------------------------*/
  5177. ACMD_FUNC(leaves)
  5178. {
  5179. nullpo_retr(-1, sd);
  5180. if (map[sd->bl.m].flag.leaves) {
  5181. map[sd->bl.m].flag.leaves=0;
  5182. clif_weather(sd->bl.m);
  5183. clif_displaymessage(fd, msg_txt(1213)); // Leaves no longer fall.
  5184. } else {
  5185. map[sd->bl.m].flag.leaves=1;
  5186. clif_weather(sd->bl.m);
  5187. clif_displaymessage(fd, msg_txt(1214)); // Fallen leaves fall.
  5188. }
  5189. return 0;
  5190. }
  5191. /*==========================================
  5192. * Fireworks appear.
  5193. *------------------------------------------*/
  5194. ACMD_FUNC(fireworks)
  5195. {
  5196. nullpo_retr(-1, sd);
  5197. if (map[sd->bl.m].flag.fireworks) {
  5198. map[sd->bl.m].flag.fireworks=0;
  5199. clif_weather(sd->bl.m);
  5200. clif_displaymessage(fd, msg_txt(1215)); // Fireworks have ended.
  5201. } else {
  5202. map[sd->bl.m].flag.fireworks=1;
  5203. clif_weather(sd->bl.m);
  5204. clif_displaymessage(fd, msg_txt(1216)); // Fireworks have launched.
  5205. }
  5206. return 0;
  5207. }
  5208. /*==========================================
  5209. * Clearing Weather Effects by Dexity
  5210. *------------------------------------------*/
  5211. ACMD_FUNC(clearweather)
  5212. {
  5213. nullpo_retr(-1, sd);
  5214. /**
  5215. * No longer available, keeping here just in case it's back someday. [Ind]
  5216. **/
  5217. //map[sd->bl.m].flag.rain=0;
  5218. map[sd->bl.m].flag.snow=0;
  5219. map[sd->bl.m].flag.sakura=0;
  5220. map[sd->bl.m].flag.clouds=0;
  5221. map[sd->bl.m].flag.clouds2=0;
  5222. map[sd->bl.m].flag.fog=0;
  5223. map[sd->bl.m].flag.fireworks=0;
  5224. map[sd->bl.m].flag.leaves=0;
  5225. clif_weather(sd->bl.m);
  5226. clif_displaymessage(fd, msg_txt(291));
  5227. return 0;
  5228. }
  5229. /*===============================================================
  5230. * Sound Command - plays a sound for everyone around! [Codemaster]
  5231. *---------------------------------------------------------------*/
  5232. ACMD_FUNC(sound)
  5233. {
  5234. char sound_file[100];
  5235. memset(sound_file, '\0', sizeof(sound_file));
  5236. if(!message || !*message || sscanf(message, "%99[^\n]", sound_file) < 1) {
  5237. clif_displaymessage(fd, msg_txt(1217)); // Please enter a sound filename (usage: @sound <filename>).
  5238. return -1;
  5239. }
  5240. if(strstr(sound_file, ".wav") == NULL)
  5241. strcat(sound_file, ".wav");
  5242. clif_soundeffectall(&sd->bl, sound_file, 0, AREA);
  5243. return 0;
  5244. }
  5245. /*==========================================
  5246. * MOB Search
  5247. *------------------------------------------*/
  5248. ACMD_FUNC(mobsearch)
  5249. {
  5250. char mob_name[100];
  5251. int mob_id;
  5252. int number = 0;
  5253. struct s_mapiterator* it;
  5254. nullpo_retr(-1, sd);
  5255. if (!message || !*message || sscanf(message, "%99[^\n]", mob_name) < 1) {
  5256. clif_displaymessage(fd, msg_txt(1218)); // Please enter a monster name (usage: @mobsearch <monster name>).
  5257. return -1;
  5258. }
  5259. if ((mob_id = atoi(mob_name)) == 0)
  5260. mob_id = mobdb_searchname(mob_name);
  5261. if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  5262. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1219),mob_name); // Invalid mob ID %s!
  5263. clif_displaymessage(fd, atcmd_output);
  5264. return -1;
  5265. }
  5266. if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  5267. strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
  5268. // strcpy(mob_name,mob_db(mob_id)->name); // --en--
  5269. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s
  5270. clif_displaymessage(fd, atcmd_output);
  5271. it = mapit_geteachmob();
  5272. for(;;)
  5273. {
  5274. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  5275. if( md == NULL )
  5276. break;// no more mobs
  5277. if( md->bl.m != sd->bl.m )
  5278. continue;
  5279. if( mob_id != -1 && md->class_ != mob_id )
  5280. continue;
  5281. ++number;
  5282. if( md->spawn_timer == INVALID_TIMER )
  5283. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%3d:%3d] %s", number, md->bl.x, md->bl.y, md->name);
  5284. else
  5285. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name);
  5286. clif_displaymessage(fd, atcmd_output);
  5287. }
  5288. mapit_free(it);
  5289. return 0;
  5290. }
  5291. /*==========================================
  5292. * @cleanmap - cleans items on the ground
  5293. *------------------------------------------*/
  5294. static int atcommand_cleanmap_sub(struct block_list *bl, va_list ap)
  5295. {
  5296. nullpo_ret(bl);
  5297. map_clearflooritem(bl);
  5298. return 0;
  5299. }
  5300. ACMD_FUNC(cleanmap)
  5301. {
  5302. map_foreachinarea(atcommand_cleanmap_sub, sd->bl.m,
  5303. sd->bl.x-AREA_SIZE*2, sd->bl.y-AREA_SIZE*2,
  5304. sd->bl.x+AREA_SIZE*2, sd->bl.y+AREA_SIZE*2,
  5305. BL_ITEM);
  5306. clif_displaymessage(fd, msg_txt(1221)); // All dropped items have been cleaned up.
  5307. return 0;
  5308. }
  5309. /*==========================================
  5310. * make a NPC/PET talk
  5311. * @npctalkc [SnakeDrak]
  5312. *------------------------------------------*/
  5313. ACMD_FUNC(npctalk)
  5314. {
  5315. char name[NAME_LENGTH],mes[100],temp[100];
  5316. struct npc_data *nd;
  5317. bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
  5318. unsigned long color=0;
  5319. if (sd->sc.count && //no "chatting" while muted.
  5320. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  5321. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  5322. return -1;
  5323. if(!ifcolor) {
  5324. if (!message || !*message || sscanf(message, "%23[^,], %99[^\n]", name, mes) < 2) {
  5325. clif_displaymessage(fd, msg_txt(1222)); // Please enter the correct parameters (usage: @npctalk <npc name>, <message>).
  5326. return -1;
  5327. }
  5328. }
  5329. else {
  5330. if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
  5331. clif_displaymessage(fd, msg_txt(1223)); // Please enter the correct parameters (usage: @npctalkc <color> <npc name>, <message>).
  5332. return -1;
  5333. }
  5334. }
  5335. if (!(nd = npc_name2id(name))) {
  5336. clif_displaymessage(fd, msg_txt(111)); // This NPC doesn't exist
  5337. return -1;
  5338. }
  5339. strtok(name, "#"); // discard extra name identifier if present
  5340. snprintf(temp, sizeof(temp), "%s : %s", name, mes);
  5341. if(ifcolor) clif_messagecolor(&nd->bl,color,temp);
  5342. else clif_message(&nd->bl, temp);
  5343. return 0;
  5344. }
  5345. ACMD_FUNC(pettalk)
  5346. {
  5347. char mes[100],temp[100];
  5348. struct pet_data *pd;
  5349. nullpo_retr(-1, sd);
  5350. if ( battle_config.min_chat_delay ) {
  5351. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  5352. return 0;
  5353. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  5354. }
  5355. if(!sd->status.pet_id || !(pd=sd->pd))
  5356. {
  5357. clif_displaymessage(fd, msg_txt(184));
  5358. return -1;
  5359. }
  5360. if (sd->sc.count && //no "chatting" while muted.
  5361. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  5362. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  5363. return -1;
  5364. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  5365. clif_displaymessage(fd, msg_txt(1224)); // Please enter a message (usage: @pettalk <message>).
  5366. return -1;
  5367. }
  5368. if (message[0] == '/')
  5369. {// pet emotion processing
  5370. const char* emo[] = {
  5371. "/!", "/?", "/ho", "/lv", "/swt", "/ic", "/an", "/ag", "/$", "/...",
  5372. "/scissors", "/rock", "/paper", "/korea", "/lv2", "/thx", "/wah", "/sry", "/heh", "/swt2",
  5373. "/hmm", "/no1", "/??", "/omg", "/O", "/X", "/hlp", "/go", "/sob", "/gg",
  5374. "/kis", "/kis2", "/pif", "/ok", "-?-", "/indonesia", "/bzz", "/rice", "/awsm", "/meh",
  5375. "/shy", "/pat", "/mp", "/slur", "/com", "/yawn", "/grat", "/hp", "/philippines", "/malaysia",
  5376. "/singapore", "/brazil", "/fsh", "/spin", "/sigh", "/dum", "/crwd", "/desp", "/dice", "-dice2",
  5377. "-dice3", "-dice4", "-dice5", "-dice6", "/india", "/love", "/russia", "-?-", "/mobile", "/mail",
  5378. "/chinese", "/antenna1", "/antenna2", "/antenna3", "/hum", "/abs", "/oops", "/spit", "/ene", "/panic",
  5379. "/whisp"
  5380. };
  5381. int i;
  5382. ARR_FIND( 0, ARRAYLENGTH(emo), i, stricmp(message, emo[i]) == 0 );
  5383. if( i == E_DICE1 ) i = rnd()%6 + E_DICE1; // randomize /dice
  5384. if( i < ARRAYLENGTH(emo) )
  5385. {
  5386. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  5387. sd->emotionlasttime = time(NULL);
  5388. return 0;
  5389. }
  5390. sd->emotionlasttime = time(NULL);
  5391. clif_emotion(&pd->bl, i);
  5392. return 0;
  5393. }
  5394. }
  5395. snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes);
  5396. clif_message(&pd->bl, temp);
  5397. return 0;
  5398. }
  5399. /// @users - displays the number of players present on each map (and percentage)
  5400. /// #users displays on the target user instead of self
  5401. ACMD_FUNC(users)
  5402. {
  5403. char buf[CHAT_SIZE_MAX];
  5404. int i;
  5405. int users[MAX_MAPINDEX];
  5406. int users_all;
  5407. struct s_mapiterator* iter;
  5408. memset(users, 0, sizeof(users));
  5409. users_all = 0;
  5410. // count users on each map
  5411. iter = mapit_getallusers();
  5412. for(;;)
  5413. {
  5414. struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter);
  5415. if( sd2 == NULL )
  5416. break;// no more users
  5417. if( sd2->mapindex >= MAX_MAPINDEX )
  5418. continue;// invalid mapindex
  5419. if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
  5420. if( users_all < INT_MAX ) ++users_all;
  5421. }
  5422. mapit_free(iter);
  5423. // display results for each map
  5424. for( i = 0; i < MAX_MAPINDEX; ++i )
  5425. {
  5426. if( users[i] == 0 )
  5427. continue;// empty
  5428. safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
  5429. clif_displaymessage(sd->fd, buf);
  5430. }
  5431. // display overall count
  5432. safesnprintf(buf, sizeof(buf), "all: %d", users_all);
  5433. clif_displaymessage(sd->fd, buf);
  5434. return 0;
  5435. }
  5436. /*==========================================
  5437. *
  5438. *------------------------------------------*/
  5439. ACMD_FUNC(reset)
  5440. {
  5441. pc_resetstate(sd);
  5442. pc_resetskill(sd,1);
  5443. sprintf(atcmd_output, msg_txt(208), sd->status.name); // '%s' skill and stats points reseted!
  5444. clif_displaymessage(fd, atcmd_output);
  5445. return 0;
  5446. }
  5447. /*==========================================
  5448. *
  5449. *------------------------------------------*/
  5450. ACMD_FUNC(summon)
  5451. {
  5452. char name[NAME_LENGTH];
  5453. int mob_id = 0;
  5454. int duration = 0;
  5455. struct mob_data *md;
  5456. unsigned int tick=gettick();
  5457. nullpo_retr(-1, sd);
  5458. if (!message || !*message || sscanf(message, "%23s %d", name, &duration) < 1)
  5459. {
  5460. clif_displaymessage(fd, msg_txt(1225)); // Please enter a monster name (usage: @summon <monster name> {duration}).
  5461. return -1;
  5462. }
  5463. if (duration < 1)
  5464. duration =1;
  5465. else if (duration > 60)
  5466. duration =60;
  5467. if ((mob_id = atoi(name)) == 0)
  5468. mob_id = mobdb_searchname(name);
  5469. if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
  5470. {
  5471. clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  5472. return -1;
  5473. }
  5474. md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE);
  5475. if(!md)
  5476. return -1;
  5477. md->master_id=sd->bl.id;
  5478. md->special_state.ai=1;
  5479. md->deletetimer=add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
  5480. clif_specialeffect(&md->bl,344,AREA);
  5481. mob_spawn(md);
  5482. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  5483. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
  5484. clif_displaymessage(fd, msg_txt(39)); // All monster summoned!
  5485. return 0;
  5486. }
  5487. /*==========================================
  5488. * @adjgroup
  5489. * Temporarily move player to another group
  5490. * Useful during beta testing to allow players to use GM commands for short periods of time
  5491. *------------------------------------------*/
  5492. ACMD_FUNC(adjgroup)
  5493. {
  5494. int new_group = 0;
  5495. nullpo_retr(-1, sd);
  5496. if (!message || !*message || sscanf(message, "%d", &new_group) != 1) {
  5497. clif_displaymessage(fd, msg_txt(1226)); // Usage: @adjgroup <group_id>
  5498. return -1;
  5499. }
  5500. if (!pc_group_exists(new_group)) {
  5501. clif_displaymessage(fd, msg_txt(1227)); // Specified group does not exist.
  5502. return -1;
  5503. }
  5504. sd->group_id = new_group;
  5505. pc_group_pc_load(sd);/* update cache */
  5506. clif_displaymessage(fd, msg_txt(1228)); // Group changed successfully.
  5507. clif_displaymessage(sd->fd, msg_txt(1229)); // Your group has changed.
  5508. return 0;
  5509. }
  5510. /*==========================================
  5511. * @trade by [MouseJstr]
  5512. * Open a trade window with a remote player
  5513. *------------------------------------------*/
  5514. ACMD_FUNC(trade)
  5515. {
  5516. struct map_session_data *pl_sd = NULL;
  5517. nullpo_retr(-1, sd);
  5518. if (!message || !*message) {
  5519. clif_displaymessage(fd, msg_txt(1230)); // Please enter a player name (usage: @trade <char name>).
  5520. return -1;
  5521. }
  5522. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5523. {
  5524. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5525. return -1;
  5526. }
  5527. trade_traderequest(sd, pl_sd);
  5528. return 0;
  5529. }
  5530. /*==========================================
  5531. * @setbattleflag by [MouseJstr]
  5532. * set a battle_config flag without having to reboot
  5533. *------------------------------------------*/
  5534. ACMD_FUNC(setbattleflag)
  5535. {
  5536. char flag[128], value[128];
  5537. nullpo_retr(-1, sd);
  5538. if (!message || !*message || sscanf(message, "%127s %127s", flag, value) != 2) {
  5539. clif_displaymessage(fd, msg_txt(1231)); // Usage: @setbattleflag <flag> <value>
  5540. return -1;
  5541. }
  5542. if (battle_set_value(flag, value) == 0)
  5543. {
  5544. clif_displaymessage(fd, msg_txt(1232)); // Unknown battle_config flag.
  5545. return -1;
  5546. }
  5547. clif_displaymessage(fd, msg_txt(1233)); // Set battle_config as requested.
  5548. return 0;
  5549. }
  5550. /*==========================================
  5551. * @unmute [Valaris]
  5552. *------------------------------------------*/
  5553. ACMD_FUNC(unmute)
  5554. {
  5555. struct map_session_data *pl_sd = NULL;
  5556. nullpo_retr(-1, sd);
  5557. if (!message || !*message) {
  5558. clif_displaymessage(fd, msg_txt(1234)); // Please enter a player name (usage: @unmute <char name>).
  5559. return -1;
  5560. }
  5561. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5562. {
  5563. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5564. return -1;
  5565. }
  5566. if(!pl_sd->sc.data[SC_NOCHAT]) {
  5567. clif_displaymessage(sd->fd,msg_txt(1235)); // Player is not muted.
  5568. return -1;
  5569. }
  5570. pl_sd->status.manner = 0;
  5571. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  5572. clif_displaymessage(sd->fd,msg_txt(1236)); // Player unmuted.
  5573. return 0;
  5574. }
  5575. /*==========================================
  5576. * @uptime by MC Cameri
  5577. *------------------------------------------*/
  5578. ACMD_FUNC(uptime)
  5579. {
  5580. unsigned long seconds = 0, day = 24*60*60, hour = 60*60,
  5581. minute = 60, days = 0, hours = 0, minutes = 0;
  5582. nullpo_retr(-1, sd);
  5583. seconds = get_uptime();
  5584. days = seconds/day;
  5585. seconds -= (seconds/day>0)?(seconds/day)*day:0;
  5586. hours = seconds/hour;
  5587. seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
  5588. minutes = seconds/minute;
  5589. seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
  5590. snprintf(atcmd_output, sizeof(atcmd_output), msg_txt(245), days, hours, minutes, seconds);
  5591. clif_displaymessage(fd, atcmd_output);
  5592. return 0;
  5593. }
  5594. /*==========================================
  5595. * @changesex <sex>
  5596. * => Changes one's sex. Argument sex can be 0 or 1, m or f, male or female.
  5597. *------------------------------------------*/
  5598. ACMD_FUNC(changesex)
  5599. {
  5600. int i;
  5601. nullpo_retr(-1, sd);
  5602. pc_resetskill(sd,4);
  5603. // to avoid any problem with equipment and invalid sex, equipment is unequiped.
  5604. for( i=0; i<EQI_MAX; i++ )
  5605. if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3);
  5606. chrif_changesex(sd);
  5607. return 0;
  5608. }
  5609. /*================================================
  5610. * @mute - Mutes a player for a set amount of time
  5611. *------------------------------------------------*/
  5612. ACMD_FUNC(mute)
  5613. {
  5614. struct map_session_data *pl_sd = NULL;
  5615. int manner;
  5616. nullpo_retr(-1, sd);
  5617. if (!message || !*message || sscanf(message, "%d %23[^\n]", &manner, atcmd_player_name) < 1) {
  5618. clif_displaymessage(fd, msg_txt(1237)); // Usage: @mute <time> <char name>
  5619. return -1;
  5620. }
  5621. if ( (pl_sd = map_nick2sd(atcmd_player_name)) == NULL )
  5622. {
  5623. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  5624. return -1;
  5625. }
  5626. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  5627. {
  5628. clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
  5629. return -1;
  5630. }
  5631. clif_manner_message(sd, 0);
  5632. clif_manner_message(pl_sd, 5);
  5633. if( pl_sd->status.manner < manner ) {
  5634. pl_sd->status.manner -= manner;
  5635. sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  5636. } else {
  5637. pl_sd->status.manner = 0;
  5638. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  5639. }
  5640. clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
  5641. return 0;
  5642. }
  5643. /*==========================================
  5644. * @refresh (like @jumpto <<yourself>>)
  5645. *------------------------------------------*/
  5646. ACMD_FUNC(refresh)
  5647. {
  5648. nullpo_retr(-1, sd);
  5649. clif_refresh(sd);
  5650. return 0;
  5651. }
  5652. /*==========================================
  5653. * @identify
  5654. * => GM's magnifier.
  5655. *------------------------------------------*/
  5656. ACMD_FUNC(identify)
  5657. {
  5658. int i,num;
  5659. nullpo_retr(-1, sd);
  5660. for(i=num=0;i<MAX_INVENTORY;i++){
  5661. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  5662. num++;
  5663. }
  5664. }
  5665. if (num > 0) {
  5666. clif_item_identify_list(sd);
  5667. } else {
  5668. clif_displaymessage(fd,msg_txt(1238)); // There are no items to appraise.
  5669. }
  5670. return 0;
  5671. }
  5672. /*==========================================
  5673. * @gmotd (Global MOTD)
  5674. * by davidsiaw :P
  5675. *------------------------------------------*/
  5676. ACMD_FUNC(gmotd)
  5677. {
  5678. char buf[CHAT_SIZE_MAX];
  5679. size_t len;
  5680. FILE* fp;
  5681. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  5682. {
  5683. while( fgets(buf, sizeof(buf), fp) )
  5684. {
  5685. if( buf[0] == '/' && buf[1] == '/' )
  5686. {
  5687. continue;
  5688. }
  5689. len = strlen(buf);
  5690. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) )
  5691. {// strip trailing EOL characters
  5692. len--;
  5693. }
  5694. if( len )
  5695. {
  5696. buf[len] = 0;
  5697. intif_broadcast(buf, len+1, 0);
  5698. }
  5699. }
  5700. fclose(fp);
  5701. }
  5702. return 0;
  5703. }
  5704. ACMD_FUNC(misceffect)
  5705. {
  5706. int effect = 0;
  5707. nullpo_retr(-1, sd);
  5708. if (!message || !*message)
  5709. return -1;
  5710. if (sscanf(message, "%d", &effect) < 1)
  5711. return -1;
  5712. clif_misceffect(&sd->bl,effect);
  5713. return 0;
  5714. }
  5715. /*==========================================
  5716. * MAIL SYSTEM
  5717. *------------------------------------------*/
  5718. ACMD_FUNC(mail)
  5719. {
  5720. nullpo_ret(sd);
  5721. mail_openmail(sd);
  5722. return 0;
  5723. }
  5724. /*==========================================
  5725. * Show Monster DB Info v 1.0
  5726. * originally by [Lupus]
  5727. *------------------------------------------*/
  5728. ACMD_FUNC(mobinfo)
  5729. {
  5730. unsigned char msize[3][7] = {"Small", "Medium", "Large"};
  5731. unsigned char mrace[12][11] = {"Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Boss", "Non-Boss"};
  5732. unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
  5733. char atcmd_output2[CHAT_SIZE_MAX];
  5734. struct item_data *item_data;
  5735. struct mob_db *mob, *mob_array[MAX_SEARCH];
  5736. int count;
  5737. int i, j, k;
  5738. memset(atcmd_output, '\0', sizeof(atcmd_output));
  5739. memset(atcmd_output2, '\0', sizeof(atcmd_output2));
  5740. if (!message || !*message) {
  5741. clif_displaymessage(fd, msg_txt(1239)); // Please enter a monster name/ID (usage: @mobinfo <monster_name_or_monster_ID>).
  5742. return -1;
  5743. }
  5744. // If monster identifier/name argument is a name
  5745. if ((i = mobdb_checkid(atoi(message))))
  5746. {
  5747. mob_array[0] = mob_db(i);
  5748. count = 1;
  5749. } else
  5750. count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  5751. if (!count) {
  5752. clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  5753. return -1;
  5754. }
  5755. if (count > MAX_SEARCH) {
  5756. sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  5757. clif_displaymessage(fd, atcmd_output);
  5758. count = MAX_SEARCH;
  5759. }
  5760. for (k = 0; k < count; k++) {
  5761. mob = mob_array[k];
  5762. // stats
  5763. if (mob->mexp)
  5764. sprintf(atcmd_output, msg_txt(1240), mob->name, mob->jname, mob->sprite, mob->vd.class_); // MVP Monster: '%s'/'%s'/'%s' (%d)
  5765. else
  5766. sprintf(atcmd_output, msg_txt(1241), mob->name, mob->jname, mob->sprite, mob->vd.class_); // Monster: '%s'/'%s'/'%s' (%d)
  5767. clif_displaymessage(fd, atcmd_output);
  5768. sprintf(atcmd_output, msg_txt(1242), mob->lv, mob->status.max_hp, mob->base_exp, mob->job_exp,MOB_HIT(mob), MOB_FLEE(mob)); // Lv:%d HP:%d Base EXP:%u Job EXP:%u HIT:%d FLEE:%d
  5769. clif_displaymessage(fd, atcmd_output);
  5770. sprintf(atcmd_output, msg_txt(1243), // DEF:%d MDEF:%d STR:%d AGI:%d VIT:%d INT:%d DEX:%d LUK:%d
  5771. mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
  5772. mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
  5773. clif_displaymessage(fd, atcmd_output);
  5774. sprintf(atcmd_output, msg_txt(1244), // ATK:%d~%d Range:%d~%d~%d Size:%s Race: %s Element: %s (Lv:%d)
  5775. mob->status.rhw.atk, mob->status.rhw.atk2, mob->status.rhw.range,
  5776. mob->range2 , mob->range3, msize[mob->status.size],
  5777. mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
  5778. clif_displaymessage(fd, atcmd_output);
  5779. // drops
  5780. clif_displaymessage(fd, msg_txt(1245)); // Drops:
  5781. strcpy(atcmd_output, " ");
  5782. j = 0;
  5783. for (i = 0; i < MAX_MOB_DROP; i++) {
  5784. int droprate;
  5785. if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL)
  5786. continue;
  5787. droprate = mob->dropitem[i].p;
  5788. if (item_data->slot)
  5789. sprintf(atcmd_output2, " - %s[%d] %02.02f%%", item_data->jname, item_data->slot, (float)droprate / 100);
  5790. else
  5791. sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)droprate / 100);
  5792. strcat(atcmd_output, atcmd_output2);
  5793. if (++j % 3 == 0) {
  5794. clif_displaymessage(fd, atcmd_output);
  5795. strcpy(atcmd_output, " ");
  5796. }
  5797. }
  5798. if (j == 0)
  5799. clif_displaymessage(fd, msg_txt(1246)); // This monster has no drops.
  5800. else if (j % 3 != 0)
  5801. clif_displaymessage(fd, atcmd_output);
  5802. // mvp
  5803. if (mob->mexp) {
  5804. sprintf(atcmd_output, msg_txt(1247), mob->mexp); // MVP Bonus EXP:%u
  5805. clif_displaymessage(fd, atcmd_output);
  5806. strcpy(atcmd_output, msg_txt(1248)); // MVP Items:
  5807. j = 0;
  5808. for (i = 0; i < MAX_MVP_DROP; i++) {
  5809. if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL)
  5810. continue;
  5811. if (mob->mvpitem[i].p > 0) {
  5812. j++;
  5813. if (j == 1)
  5814. sprintf(atcmd_output2, " %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  5815. else
  5816. sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  5817. strcat(atcmd_output, atcmd_output2);
  5818. }
  5819. }
  5820. if (j == 0)
  5821. clif_displaymessage(fd, msg_txt(1249)); // This monster has no MVP prizes.
  5822. else
  5823. clif_displaymessage(fd, atcmd_output);
  5824. }
  5825. }
  5826. return 0;
  5827. }
  5828. /*=========================================
  5829. * @showmobs by KarLaeda
  5830. * => For 15 sec displays the mobs on minimap
  5831. *------------------------------------------*/
  5832. ACMD_FUNC(showmobs)
  5833. {
  5834. char mob_name[100];
  5835. int mob_id;
  5836. int number = 0;
  5837. struct s_mapiterator* it;
  5838. nullpo_retr(-1, sd);
  5839. if(sscanf(message, "%99[^\n]", mob_name) < 0)
  5840. return -1;
  5841. if((mob_id = atoi(mob_name)) == 0)
  5842. mob_id = mobdb_searchname(mob_name);
  5843. if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  5844. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1250),mob_name); // Invalid mob id %s!
  5845. clif_displaymessage(fd, atcmd_output);
  5846. return 0;
  5847. }
  5848. if(mob_db(mob_id)->status.mode&MD_BOSS && !pc_has_permission(sd, PC_PERM_SHOW_BOSS)){ // If player group does not have access to boss mobs.
  5849. clif_displaymessage(fd, msg_txt(1251)); // Can't show boss mobs!
  5850. return 0;
  5851. }
  5852. if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  5853. strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
  5854. //strcpy(mob_name,mob_db(mob_id)->name); // --en--
  5855. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1252), // Mob Search... %s %s
  5856. mob_name, mapindex_id2name(sd->mapindex));
  5857. clif_displaymessage(fd, atcmd_output);
  5858. it = mapit_geteachmob();
  5859. for(;;)
  5860. {
  5861. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  5862. if( md == NULL )
  5863. break;// no more mobs
  5864. if( md->bl.m != sd->bl.m )
  5865. continue;
  5866. if( mob_id != -1 && md->class_ != mob_id )
  5867. continue;
  5868. if( md->special_state.ai || md->master_id )
  5869. continue; // hide slaves and player summoned mobs
  5870. if( md->spawn_timer != INVALID_TIMER )
  5871. continue; // hide mobs waiting for respawn
  5872. ++number;
  5873. clif_viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF);
  5874. }
  5875. mapit_free(it);
  5876. return 0;
  5877. }
  5878. /*==========================================
  5879. * homunculus level up [orn]
  5880. *------------------------------------------*/
  5881. ACMD_FUNC(homlevel)
  5882. {
  5883. TBL_HOM * hd;
  5884. int level = 0, i = 0;
  5885. nullpo_retr(-1, sd);
  5886. if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
  5887. clif_displaymessage(fd, msg_txt(1253)); // Please enter a level adjustment (usage: @homlevel <number of levels>).
  5888. return -1;
  5889. }
  5890. if ( !merc_is_hom_active(sd->hd) ) {
  5891. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  5892. return -1;
  5893. }
  5894. hd = sd->hd;
  5895. for (i = 1; i <= level && hd->exp_next; i++){
  5896. hd->homunculus.exp += hd->exp_next;
  5897. merc_hom_levelup(hd);
  5898. }
  5899. status_calc_homunculus(hd,0);
  5900. status_percent_heal(&hd->bl, 100, 100);
  5901. clif_specialeffect(&hd->bl,568,AREA);
  5902. return 0;
  5903. }
  5904. /*==========================================
  5905. * homunculus evolution H [orn]
  5906. *------------------------------------------*/
  5907. ACMD_FUNC(homevolution)
  5908. {
  5909. nullpo_retr(-1, sd);
  5910. if ( !merc_is_hom_active(sd->hd) ) {
  5911. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  5912. return -1;
  5913. }
  5914. if ( !merc_hom_evolution(sd->hd) ) {
  5915. clif_displaymessage(fd, msg_txt(1255)); // Your homunculus doesn't evolve.
  5916. return -1;
  5917. }
  5918. clif_homskillinfoblock(sd);
  5919. return 0;
  5920. }
  5921. /*==========================================
  5922. * call choosen homunculus [orn]
  5923. *------------------------------------------*/
  5924. ACMD_FUNC(makehomun)
  5925. {
  5926. int homunid;
  5927. nullpo_retr(-1, sd);
  5928. if ( sd->status.hom_id ) {
  5929. clif_displaymessage(fd, msg_txt(450));
  5930. return -1;
  5931. }
  5932. if (!message || !*message) {
  5933. clif_displaymessage(fd, msg_txt(1256)); // Please enter a homunculus ID (usage: @makehomun <homunculus id>).
  5934. return -1;
  5935. }
  5936. homunid = atoi(message);
  5937. if( homunid < HM_CLASS_BASE || homunid > HM_CLASS_BASE + MAX_HOMUNCULUS_CLASS - 1 )
  5938. {
  5939. clif_displaymessage(fd, msg_txt(1257)); // Invalid Homunculus ID.
  5940. return -1;
  5941. }
  5942. merc_create_homunculus_request(sd,homunid);
  5943. return 0;
  5944. }
  5945. /*==========================================
  5946. * modify homunculus intimacy [orn]
  5947. *------------------------------------------*/
  5948. ACMD_FUNC(homfriendly)
  5949. {
  5950. int friendly = 0;
  5951. nullpo_retr(-1, sd);
  5952. if ( !merc_is_hom_active(sd->hd) ) {
  5953. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  5954. return -1;
  5955. }
  5956. if (!message || !*message) {
  5957. clif_displaymessage(fd, msg_txt(1258)); // Please enter a friendly value (usage: @homfriendly <friendly value [0-1000]>).
  5958. return -1;
  5959. }
  5960. friendly = atoi(message);
  5961. friendly = cap_value(friendly, 0, 1000);
  5962. sd->hd->homunculus.intimacy = friendly * 100 ;
  5963. clif_send_homdata(sd,SP_INTIMATE,friendly);
  5964. return 0;
  5965. }
  5966. /*==========================================
  5967. * modify homunculus hunger [orn]
  5968. *------------------------------------------*/
  5969. ACMD_FUNC(homhungry)
  5970. {
  5971. int hungry = 0;
  5972. nullpo_retr(-1, sd);
  5973. if ( !merc_is_hom_active(sd->hd) ) {
  5974. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  5975. return -1;
  5976. }
  5977. if (!message || !*message) {
  5978. clif_displaymessage(fd, msg_txt(1259)); // Please enter a hunger value (usage: @homhungry <hunger value [0-100]>).
  5979. return -1;
  5980. }
  5981. hungry = atoi(message);
  5982. hungry = cap_value(hungry, 0, 100);
  5983. sd->hd->homunculus.hunger = hungry;
  5984. clif_send_homdata(sd,SP_HUNGRY,hungry);
  5985. return 0;
  5986. }
  5987. /*==========================================
  5988. * make the homunculus speak [orn]
  5989. *------------------------------------------*/
  5990. ACMD_FUNC(homtalk)
  5991. {
  5992. char mes[100],temp[100];
  5993. nullpo_retr(-1, sd);
  5994. if ( battle_config.min_chat_delay ) {
  5995. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  5996. return 0;
  5997. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  5998. }
  5999. if (sd->sc.count && //no "chatting" while muted.
  6000. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  6001. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6002. return -1;
  6003. if ( !merc_is_hom_active(sd->hd) ) {
  6004. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  6005. return -1;
  6006. }
  6007. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6008. clif_displaymessage(fd, msg_txt(1260)); // Please enter a message (usage: @homtalk <message>).
  6009. return -1;
  6010. }
  6011. snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes);
  6012. clif_message(&sd->hd->bl, temp);
  6013. return 0;
  6014. }
  6015. /*==========================================
  6016. * Show homunculus stats
  6017. *------------------------------------------*/
  6018. ACMD_FUNC(hominfo)
  6019. {
  6020. struct homun_data *hd;
  6021. struct status_data *status;
  6022. nullpo_retr(-1, sd);
  6023. if ( !merc_is_hom_active(sd->hd) ) {
  6024. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  6025. return -1;
  6026. }
  6027. hd = sd->hd;
  6028. status = status_get_status_data(&hd->bl);
  6029. clif_displaymessage(fd, msg_txt(1261)); // Homunculus stats:
  6030. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1262), // HP: %d/%d - SP: %d/%d
  6031. status->hp, status->max_hp, status->sp, status->max_sp);
  6032. clif_displaymessage(fd, atcmd_output);
  6033. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1263), // ATK: %d - MATK: %d~%d
  6034. status->rhw.atk2 +status->batk, status->matk_min, status->matk_max);
  6035. clif_displaymessage(fd, atcmd_output);
  6036. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1264), // Hungry: %d - Intimacy: %u
  6037. hd->homunculus.hunger, hd->homunculus.intimacy/100);
  6038. clif_displaymessage(fd, atcmd_output);
  6039. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6040. msg_txt(1265), // Stats: Str %d / Agi %d / Vit %d / Int %d / Dex %d / Luk %d
  6041. status->str, status->agi, status->vit,
  6042. status->int_, status->dex, status->luk);
  6043. clif_displaymessage(fd, atcmd_output);
  6044. return 0;
  6045. }
  6046. ACMD_FUNC(homstats)
  6047. {
  6048. struct homun_data *hd;
  6049. struct s_homunculus_db *db;
  6050. struct s_homunculus *hom;
  6051. int lv, min, max, evo;
  6052. nullpo_retr(-1, sd);
  6053. if ( !merc_is_hom_active(sd->hd) ) {
  6054. clif_displaymessage(fd, msg_txt(1254)); // You do not have a homunculus.
  6055. return -1;
  6056. }
  6057. hd = sd->hd;
  6058. hom = &hd->homunculus;
  6059. db = hd->homunculusDB;
  6060. lv = hom->level;
  6061. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6062. msg_txt(1266), lv, db->name); // Homunculus growth stats (Lv %d %s):
  6063. clif_displaymessage(fd, atcmd_output);
  6064. lv--; //Since the first increase is at level 2.
  6065. evo = (hom->class_ == db->evo_class);
  6066. min = db->base.HP +lv*db->gmin.HP +(evo?db->emin.HP:0);
  6067. max = db->base.HP +lv*db->gmax.HP +(evo?db->emax.HP:0);;
  6068. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1267), hom->max_hp, min, max); // Max HP: %d (%d~%d)
  6069. clif_displaymessage(fd, atcmd_output);
  6070. min = db->base.SP +lv*db->gmin.SP +(evo?db->emin.SP:0);
  6071. max = db->base.SP +lv*db->gmax.SP +(evo?db->emax.SP:0);;
  6072. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1268), hom->max_sp, min, max); // Max SP: %d (%d~%d)
  6073. clif_displaymessage(fd, atcmd_output);
  6074. min = db->base.str +lv*(db->gmin.str/10) +(evo?db->emin.str:0);
  6075. max = db->base.str +lv*(db->gmax.str/10) +(evo?db->emax.str:0);;
  6076. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1269), hom->str/10, min, max); // Str: %d (%d~%d)
  6077. clif_displaymessage(fd, atcmd_output);
  6078. min = db->base.agi +lv*(db->gmin.agi/10) +(evo?db->emin.agi:0);
  6079. max = db->base.agi +lv*(db->gmax.agi/10) +(evo?db->emax.agi:0);;
  6080. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1270), hom->agi/10, min, max); // Agi: %d (%d~%d)
  6081. clif_displaymessage(fd, atcmd_output);
  6082. min = db->base.vit +lv*(db->gmin.vit/10) +(evo?db->emin.vit:0);
  6083. max = db->base.vit +lv*(db->gmax.vit/10) +(evo?db->emax.vit:0);;
  6084. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1271), hom->vit/10, min, max); // Vit: %d (%d~%d)
  6085. clif_displaymessage(fd, atcmd_output);
  6086. min = db->base.int_ +lv*(db->gmin.int_/10) +(evo?db->emin.int_:0);
  6087. max = db->base.int_ +lv*(db->gmax.int_/10) +(evo?db->emax.int_:0);;
  6088. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1272), hom->int_/10, min, max); // Int: %d (%d~%d)
  6089. clif_displaymessage(fd, atcmd_output);
  6090. min = db->base.dex +lv*(db->gmin.dex/10) +(evo?db->emin.dex:0);
  6091. max = db->base.dex +lv*(db->gmax.dex/10) +(evo?db->emax.dex:0);;
  6092. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1273), hom->dex/10, min, max); // Dex: %d (%d~%d)
  6093. clif_displaymessage(fd, atcmd_output);
  6094. min = db->base.luk +lv*(db->gmin.luk/10) +(evo?db->emin.luk:0);
  6095. max = db->base.luk +lv*(db->gmax.luk/10) +(evo?db->emax.luk:0);;
  6096. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(1274), hom->luk/10, min, max); // Luk: %d (%d~%d)
  6097. clif_displaymessage(fd, atcmd_output);
  6098. return 0;
  6099. }
  6100. ACMD_FUNC(homshuffle)
  6101. {
  6102. nullpo_retr(-1, sd);
  6103. if(!sd->hd)
  6104. return -1; // nothing to do
  6105. if(!merc_hom_shuffle(sd->hd))
  6106. return -1;
  6107. clif_displaymessage(sd->fd, msg_txt(1275)); // Homunculus stats altered.
  6108. atcommand_homstats(fd, sd, command, message); //Print out the new stats
  6109. return 0;
  6110. }
  6111. /*==========================================
  6112. * Show Items DB Info v 1.0
  6113. * originally by [Lupus]
  6114. *------------------------------------------*/
  6115. ACMD_FUNC(iteminfo)
  6116. {
  6117. struct item_data *item_data, *item_array[MAX_SEARCH];
  6118. int i, count = 1;
  6119. if (!message || !*message) {
  6120. clif_displaymessage(fd, msg_txt(1276)); // Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>).
  6121. return -1;
  6122. }
  6123. if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  6124. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  6125. if (!count) {
  6126. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  6127. return -1;
  6128. }
  6129. if (count > MAX_SEARCH) {
  6130. sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  6131. clif_displaymessage(fd, atcmd_output);
  6132. count = MAX_SEARCH;
  6133. }
  6134. for (i = 0; i < count; i++) {
  6135. item_data = item_array[i];
  6136. sprintf(atcmd_output, msg_txt(1277), // Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
  6137. item_data->name,item_data->jname,item_data->slot,item_data->nameid,
  6138. itemdb_typename(item_data->type),
  6139. (item_data->script==NULL)? msg_txt(1278) : msg_txt(1279) // None / With script
  6140. );
  6141. clif_displaymessage(fd, atcmd_output);
  6142. sprintf(atcmd_output, msg_txt(1280), item_data->value_buy, item_data->value_sell, item_data->weight/10. ); // NPC Buy:%dz, Sell:%dz | Weight: %.1f
  6143. clif_displaymessage(fd, atcmd_output);
  6144. if (item_data->maxchance == -1)
  6145. strcpy(atcmd_output, msg_txt(1281)); // - Available in the shops only.
  6146. else if (!battle_config.atcommand_mobinfo_type && item_data->maxchance)
  6147. sprintf(atcmd_output, msg_txt(1282), (float)item_data->maxchance / 100 ); // - Maximal monsters drop chance: %02.02f%%
  6148. else
  6149. strcpy(atcmd_output, msg_txt(1283)); // - Monsters don't drop this item.
  6150. clif_displaymessage(fd, atcmd_output);
  6151. }
  6152. return 0;
  6153. }
  6154. /*==========================================
  6155. * Show who drops the item.
  6156. *------------------------------------------*/
  6157. ACMD_FUNC(whodrops)
  6158. {
  6159. struct item_data *item_data, *item_array[MAX_SEARCH];
  6160. int i,j, count = 1;
  6161. if (!message || !*message) {
  6162. clif_displaymessage(fd, msg_txt(1284)); // Please enter item name/ID (usage: @whodrops <item name/ID>).
  6163. return -1;
  6164. }
  6165. if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  6166. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  6167. if (!count) {
  6168. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  6169. return -1;
  6170. }
  6171. if (count > MAX_SEARCH) {
  6172. sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  6173. clif_displaymessage(fd, atcmd_output);
  6174. count = MAX_SEARCH;
  6175. }
  6176. for (i = 0; i < count; i++) {
  6177. item_data = item_array[i];
  6178. sprintf(atcmd_output, msg_txt(1285), item_data->jname,item_data->slot); // Item: '%s'[%d]
  6179. clif_displaymessage(fd, atcmd_output);
  6180. if (item_data->mob[0].chance == 0) {
  6181. strcpy(atcmd_output, msg_txt(1286)); // - Item is not dropped by mobs.
  6182. clif_displaymessage(fd, atcmd_output);
  6183. } else {
  6184. sprintf(atcmd_output, msg_txt(1287), MAX_SEARCH); // - Common mobs with highest drop chance (only max %d are listed):
  6185. clif_displaymessage(fd, atcmd_output);
  6186. for (j=0; j < MAX_SEARCH && item_data->mob[j].chance > 0; j++)
  6187. {
  6188. sprintf(atcmd_output, "- %s (%02.02f%%)", mob_db(item_data->mob[j].id)->jname, item_data->mob[j].chance/100.);
  6189. clif_displaymessage(fd, atcmd_output);
  6190. }
  6191. }
  6192. }
  6193. return 0;
  6194. }
  6195. ACMD_FUNC(whereis)
  6196. {
  6197. struct mob_db *mob, *mob_array[MAX_SEARCH];
  6198. int count;
  6199. int i, j, k;
  6200. if (!message || !*message) {
  6201. clif_displaymessage(fd, msg_txt(1288)); // Please enter a monster name/ID (usage: @whereis <monster_name_or_monster_ID>).
  6202. return -1;
  6203. }
  6204. // If monster identifier/name argument is a name
  6205. if ((i = mobdb_checkid(atoi(message))))
  6206. {
  6207. mob_array[0] = mob_db(i);
  6208. count = 1;
  6209. } else
  6210. count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  6211. if (!count) {
  6212. clif_displaymessage(fd, msg_txt(40)); // Invalid monster ID or name.
  6213. return -1;
  6214. }
  6215. if (count > MAX_SEARCH) {
  6216. sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, count);
  6217. clif_displaymessage(fd, atcmd_output);
  6218. count = MAX_SEARCH;
  6219. }
  6220. for (k = 0; k < count; k++) {
  6221. mob = mob_array[k];
  6222. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1289), mob->jname); // %s spawns in:
  6223. clif_displaymessage(fd, atcmd_output);
  6224. for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
  6225. {
  6226. j = map_mapindex2mapid(mob->spawn[i].mapindex);
  6227. if (j < 0) continue;
  6228. snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, mob->spawn[i].qty);
  6229. clif_displaymessage(fd, atcmd_output);
  6230. }
  6231. if (i == 0)
  6232. clif_displaymessage(fd, msg_txt(1290)); // This monster does not spawn normally.
  6233. }
  6234. return 0;
  6235. }
  6236. /*==========================================
  6237. * @adopt by [Veider]
  6238. * adopt a novice
  6239. *------------------------------------------*/
  6240. ACMD_FUNC(adopt)
  6241. {
  6242. struct map_session_data *pl_sd1, *pl_sd2, *pl_sd3;
  6243. char player1[NAME_LENGTH], player2[NAME_LENGTH], player3[NAME_LENGTH];
  6244. char output[CHAT_SIZE_MAX];
  6245. nullpo_retr(-1, sd);
  6246. if (!message || !*message || sscanf(message, "%23[^,],%23[^,],%23[^\r\n]", player1, player2, player3) < 3) {
  6247. clif_displaymessage(fd, msg_txt(1291)); // Usage: @adopt <father>,<mother>,<child>
  6248. return -1;
  6249. }
  6250. if (battle_config.etc_log)
  6251. ShowInfo(msg_txt(1292),player1,player2,player3); // Adopting: --%s--%s--%s--\n
  6252. if((pl_sd1=map_nick2sd((char *) player1)) == NULL) {
  6253. sprintf(output, msg_txt(1293), player1); // Cannot find player %s online.
  6254. clif_displaymessage(fd, output);
  6255. return -1;
  6256. }
  6257. if((pl_sd2=map_nick2sd((char *) player2)) == NULL) {
  6258. sprintf(output, msg_txt(1293), player2); // Cannot find player %s online.
  6259. clif_displaymessage(fd, output);
  6260. return -1;
  6261. }
  6262. if((pl_sd3=map_nick2sd((char *) player3)) == NULL) {
  6263. sprintf(output, msg_txt(1293), player3); // Cannot find player %s online.
  6264. clif_displaymessage(fd, output);
  6265. return -1;
  6266. }
  6267. if( !pc_adoption(pl_sd1, pl_sd2, pl_sd3) ) {
  6268. return -1;
  6269. }
  6270. clif_displaymessage(fd, msg_txt(1294)); // They are family... wish them luck.
  6271. return 0;
  6272. }
  6273. ACMD_FUNC(version)
  6274. {
  6275. const char * revision;
  6276. if ((revision = get_svn_revision()) != 0) {
  6277. sprintf(atcmd_output,msg_txt(1295),revision); // rAthena Version SVN r%s
  6278. clif_displaymessage(fd,atcmd_output);
  6279. } else
  6280. clif_displaymessage(fd,msg_txt(1296)); // Cannot determine SVN revision.
  6281. return 0;
  6282. }
  6283. /*==========================================
  6284. * @mutearea by MouseJstr
  6285. *------------------------------------------*/
  6286. static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
  6287. {
  6288. int time, id;
  6289. struct map_session_data *pl_sd = (struct map_session_data *)bl;
  6290. if (pl_sd == NULL)
  6291. return 0;
  6292. id = va_arg(ap, int);
  6293. time = va_arg(ap, int);
  6294. if (id != bl->id && !pc_get_group_level(pl_sd)) {
  6295. pl_sd->status.manner -= time;
  6296. if (pl_sd->status.manner < 0)
  6297. sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
  6298. else
  6299. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6300. }
  6301. return 0;
  6302. }
  6303. ACMD_FUNC(mutearea)
  6304. {
  6305. int time;
  6306. nullpo_ret(sd);
  6307. if (!message || !*message) {
  6308. clif_displaymessage(fd, msg_txt(1297)); // Please enter a time in minutes (usage: @mutearea/@stfu <time in minutes>).
  6309. return -1;
  6310. }
  6311. time = atoi(message);
  6312. map_foreachinarea(atcommand_mutearea_sub,sd->bl.m,
  6313. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE,
  6314. sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time);
  6315. return 0;
  6316. }
  6317. ACMD_FUNC(rates)
  6318. {
  6319. char buf[CHAT_SIZE_MAX];
  6320. nullpo_ret(sd);
  6321. memset(buf, '\0', sizeof(buf));
  6322. snprintf(buf, CHAT_SIZE_MAX, msg_txt(1298), // Experience rates: Base %.2fx / Job %.2fx
  6323. battle_config.base_exp_rate/100., battle_config.job_exp_rate/100.);
  6324. clif_displaymessage(fd, buf);
  6325. snprintf(buf, CHAT_SIZE_MAX, msg_txt(1299), // Normal Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  6326. battle_config.item_rate_common/100., battle_config.item_rate_heal/100., battle_config.item_rate_use/100., battle_config.item_rate_equip/100., battle_config.item_rate_card/100.);
  6327. clif_displaymessage(fd, buf);
  6328. snprintf(buf, CHAT_SIZE_MAX, msg_txt(1300), // Boss Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  6329. battle_config.item_rate_common_boss/100., battle_config.item_rate_heal_boss/100., battle_config.item_rate_use_boss/100., battle_config.item_rate_equip_boss/100., battle_config.item_rate_card_boss/100.);
  6330. clif_displaymessage(fd, buf);
  6331. snprintf(buf, CHAT_SIZE_MAX, msg_txt(1301), // Other Drop Rates: MvP %.2fx / Card-Based %.2fx / Treasure %.2fx
  6332. battle_config.item_rate_mvp/100., battle_config.item_rate_adddrop/100., battle_config.item_rate_treasure/100.);
  6333. clif_displaymessage(fd, buf);
  6334. return 0;
  6335. }
  6336. /*==========================================
  6337. * @me by lordalfa
  6338. * => Displays the OUTPUT string on top of the Visible players Heads.
  6339. *------------------------------------------*/
  6340. ACMD_FUNC(me)
  6341. {
  6342. char tempmes[CHAT_SIZE_MAX];
  6343. nullpo_retr(-1, sd);
  6344. memset(tempmes, '\0', sizeof(tempmes));
  6345. memset(atcmd_output, '\0', sizeof(atcmd_output));
  6346. if (sd->sc.count && //no "chatting" while muted.
  6347. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  6348. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6349. return -1;
  6350. if (!message || !*message || sscanf(message, "%199[^\n]", tempmes) < 0) {
  6351. clif_displaymessage(fd, msg_txt(1302)); // Please enter a message (usage: @me <message>).
  6352. return -1;
  6353. }
  6354. sprintf(atcmd_output, msg_txt(270), sd->status.name, tempmes); // *%s %s*
  6355. clif_disp_overhead(sd, atcmd_output);
  6356. return 0;
  6357. }
  6358. /*==========================================
  6359. * @size
  6360. * => Resize your character sprite. [Valaris]
  6361. *------------------------------------------*/
  6362. ACMD_FUNC(size)
  6363. {
  6364. int size = 0;
  6365. nullpo_retr(-1, sd);
  6366. size = cap_value(atoi(message),SZ_SMALL,SZ_BIG);
  6367. if(sd->state.size) {
  6368. sd->state.size = SZ_SMALL;
  6369. pc_setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_TELEPORT);
  6370. }
  6371. sd->state.size = size;
  6372. if( size == SZ_MEDIUM )
  6373. clif_specialeffect(&sd->bl,420,AREA);
  6374. else if( size == SZ_BIG )
  6375. clif_specialeffect(&sd->bl,422,AREA);
  6376. clif_displaymessage(fd, msg_txt(1303)); // Size change applied.
  6377. return 0;
  6378. }
  6379. ACMD_FUNC(sizeall)
  6380. {
  6381. int size;
  6382. struct map_session_data *pl_sd;
  6383. struct s_mapiterator* iter;
  6384. size = atoi(message);
  6385. size = cap_value(size,0,2);
  6386. iter = mapit_getallusers();
  6387. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) {
  6388. if( pl_sd->state.size != size ) {
  6389. if( pl_sd->state.size ) {
  6390. pl_sd->state.size = SZ_SMALL;
  6391. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  6392. }
  6393. pl_sd->state.size = size;
  6394. if( size == SZ_MEDIUM )
  6395. clif_specialeffect(&pl_sd->bl,420,AREA);
  6396. else if( size == SZ_BIG )
  6397. clif_specialeffect(&pl_sd->bl,422,AREA);
  6398. }
  6399. }
  6400. mapit_free(iter);
  6401. clif_displaymessage(fd, msg_txt(1303)); // Size change applied.
  6402. return 0;
  6403. }
  6404. ACMD_FUNC(sizeguild)
  6405. {
  6406. int size = 0, i;
  6407. char guild[NAME_LENGTH];
  6408. struct map_session_data *pl_sd;
  6409. struct guild *g;
  6410. nullpo_retr(-1, sd);
  6411. memset(guild, '\0', sizeof(guild));
  6412. if( !message || !*message || sscanf(message, "%d %23[^\n]", &size, guild) < 2 ) {
  6413. clif_displaymessage(fd, msg_txt(1304)); // Please enter guild name/ID (usage: @sizeguild <size> <guild name/ID>).
  6414. return -1;
  6415. }
  6416. if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) {
  6417. clif_displaymessage(fd, msg_txt(94)); // Incorrect name/ID, or no one from the guild is online.
  6418. return -1;
  6419. }
  6420. size = cap_value(size,SZ_SMALL,SZ_BIG);
  6421. for( i = 0; i < g->max_member; i++ ) {
  6422. if( (pl_sd = g->member[i].sd) && pl_sd->state.size != size ) {
  6423. if( pl_sd->state.size ) {
  6424. pl_sd->state.size = SZ_SMALL;
  6425. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  6426. }
  6427. pl_sd->state.size = size;
  6428. if( size == SZ_MEDIUM )
  6429. clif_specialeffect(&pl_sd->bl,420,AREA);
  6430. else if( size == SZ_BIG )
  6431. clif_specialeffect(&pl_sd->bl,422,AREA);
  6432. }
  6433. }
  6434. clif_displaymessage(fd, msg_txt(1303)); // Size change applied.
  6435. return 0;
  6436. }
  6437. /*==========================================
  6438. * @monsterignore
  6439. * => Makes monsters ignore you. [Valaris]
  6440. *------------------------------------------*/
  6441. ACMD_FUNC(monsterignore)
  6442. {
  6443. nullpo_retr(-1, sd);
  6444. if (!sd->state.monster_ignore) {
  6445. sd->state.monster_ignore = 1;
  6446. clif_displaymessage(sd->fd, msg_txt(1305)); // You are now immune to attacks.
  6447. } else {
  6448. sd->state.monster_ignore = 0;
  6449. clif_displaymessage(sd->fd, msg_txt(1306)); // Returned to normal state.
  6450. }
  6451. return 0;
  6452. }
  6453. /*==========================================
  6454. * @fakename
  6455. * => Gives your character a fake name. [Valaris]
  6456. *------------------------------------------*/
  6457. ACMD_FUNC(fakename)
  6458. {
  6459. nullpo_retr(-1, sd);
  6460. if( !message || !*message )
  6461. {
  6462. if( sd->fakename[0] )
  6463. {
  6464. sd->fakename[0] = '\0';
  6465. clif_charnameack(0, &sd->bl);
  6466. clif_displaymessage(sd->fd, msg_txt(1307)); // Returned to real name.
  6467. return 0;
  6468. }
  6469. clif_displaymessage(sd->fd, msg_txt(1308)); // You must enter a name.
  6470. return -1;
  6471. }
  6472. if( strlen(message) < 2 )
  6473. {
  6474. clif_displaymessage(sd->fd, msg_txt(1309)); // Fake name must be at least two characters.
  6475. return -1;
  6476. }
  6477. safestrncpy(sd->fakename, message, sizeof(sd->fakename));
  6478. clif_charnameack(0, &sd->bl);
  6479. clif_displaymessage(sd->fd, msg_txt(1310)); // Fake name enabled.
  6480. return 0;
  6481. }
  6482. /*==========================================
  6483. * Ragnarok Resources
  6484. *------------------------------------------*/
  6485. ACMD_FUNC(mapflag) {
  6486. #define checkflag( cmd ) if ( map[ sd->bl.m ].flag.cmd ) clif_displaymessage(sd->fd,#cmd)
  6487. #define setflag( cmd ) \
  6488. if ( strcmp( flag_name , #cmd ) == 0 && ( flag == 0 || flag == 1 ) ){\
  6489. map[ sd->bl.m ].flag.cmd = flag;\
  6490. sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s",#cmd,flag?"On":"Off");\
  6491. clif_displaymessage(sd->fd,atcmd_output);\
  6492. return 0;\
  6493. }
  6494. unsigned char flag_name[100];
  6495. int flag=9,i;
  6496. nullpo_retr(-1, sd);
  6497. memset(flag_name, '\0', sizeof(flag_name));
  6498. if (!message || !*message || (sscanf(message, "%99s %d", flag_name, &flag) < 1)) {
  6499. clif_displaymessage(sd->fd,msg_txt(1311)); // Enabled Mapflags in this map:
  6500. clif_displaymessage(sd->fd,"----------------------------------");
  6501. checkflag(autotrade); checkflag(allowks); checkflag(nomemo); checkflag(noteleport);
  6502. checkflag(noreturn); checkflag(monster_noteleport); checkflag(nosave); checkflag(nobranch);
  6503. checkflag(noexppenalty); checkflag(pvp); checkflag(pvp_noparty); checkflag(pvp_noguild);
  6504. checkflag(pvp_nightmaredrop); checkflag(pvp_nocalcrank); checkflag(gvg_castle); checkflag(gvg);
  6505. checkflag(gvg_dungeon); checkflag(gvg_noparty); checkflag(battleground);checkflag(nozenypenalty);
  6506. checkflag(notrade); checkflag(noskill); checkflag(nowarp); checkflag(nowarpto);
  6507. checkflag(noicewall); checkflag(snow); checkflag(clouds); checkflag(clouds2);
  6508. checkflag(fog); checkflag(fireworks); checkflag(sakura); checkflag(leaves);
  6509. checkflag(nogo); checkflag(nobaseexp);
  6510. checkflag(nojobexp); checkflag(nomobloot); checkflag(nomvploot); checkflag(nightenabled);
  6511. checkflag(restricted); checkflag(nodrop); checkflag(novending); checkflag(loadevent);
  6512. checkflag(nochat); checkflag(partylock); checkflag(guildlock); checkflag(src4instance);
  6513. clif_displaymessage(sd->fd," ");
  6514. clif_displaymessage(sd->fd,msg_txt(1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  6515. clif_displaymessage(sd->fd,msg_txt(1313)); // Type "@mapflag available" to list the available mapflags.
  6516. return 1;
  6517. }
  6518. for (i = 0; flag_name[i]; i++) flag_name[i] = tolower(flag_name[i]); //lowercase
  6519. setflag(autotrade); setflag(allowks); setflag(nomemo); setflag(noteleport);
  6520. setflag(noreturn); setflag(monster_noteleport);setflag(nosave); setflag(nobranch);
  6521. setflag(noexppenalty); setflag(pvp); setflag(pvp_noparty); setflag(pvp_noguild);
  6522. setflag(pvp_nightmaredrop); setflag(pvp_nocalcrank); setflag(gvg_castle); setflag(gvg);
  6523. setflag(gvg_dungeon); setflag(gvg_noparty); setflag(battleground); setflag(nozenypenalty);
  6524. setflag(notrade); setflag(noskill); setflag(nowarp); setflag(nowarpto);
  6525. setflag(noicewall); setflag(snow); setflag(clouds); setflag(clouds2);
  6526. setflag(fog); setflag(fireworks); setflag(sakura); setflag(leaves);
  6527. setflag(nogo); setflag(nobaseexp);
  6528. setflag(nojobexp); setflag(nomobloot); setflag(nomvploot); setflag(nightenabled);
  6529. setflag(restricted); setflag(nodrop); setflag(novending); setflag(loadevent);
  6530. setflag(nochat); setflag(partylock); setflag(guildlock); setflag(src4instance);
  6531. clif_displaymessage(sd->fd,msg_txt(1314)); // Invalid flag name or flag.
  6532. clif_displaymessage(sd->fd,msg_txt(1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  6533. clif_displaymessage(sd->fd,msg_txt(1315)); // Available Flags:
  6534. clif_displaymessage(sd->fd,"----------------------------------");
  6535. clif_displaymessage(sd->fd,"town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,");
  6536. clif_displaymessage(sd->fd,"nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,");
  6537. clif_displaymessage(sd->fd,"pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground,");
  6538. clif_displaymessage(sd->fd,"nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,");
  6539. clif_displaymessage(sd->fd,"fog, fireworks, sakura, leaves, nogo, nobaseexp, nojobexp, nomobloot,");
  6540. clif_displaymessage(sd->fd,"nomvploot, nightenabled, restricted, nodrop, novending, loadevent, nochat, partylock,");
  6541. clif_displaymessage(sd->fd,"guildlock, src4instance");
  6542. #undef checkflag
  6543. #undef setflag
  6544. return 0;
  6545. }
  6546. /*===================================
  6547. * Remove some messages
  6548. *-----------------------------------*/
  6549. ACMD_FUNC(showexp)
  6550. {
  6551. if (sd->state.showexp) {
  6552. sd->state.showexp = 0;
  6553. clif_displaymessage(fd, msg_txt(1316)); // Gained exp will not be shown.
  6554. return 0;
  6555. }
  6556. sd->state.showexp = 1;
  6557. clif_displaymessage(fd, msg_txt(1317)); // Gained exp is now shown.
  6558. return 0;
  6559. }
  6560. ACMD_FUNC(showzeny)
  6561. {
  6562. if (sd->state.showzeny) {
  6563. sd->state.showzeny = 0;
  6564. clif_displaymessage(fd, msg_txt(1318)); // Gained zeny will not be shown.
  6565. return 0;
  6566. }
  6567. sd->state.showzeny = 1;
  6568. clif_displaymessage(fd, msg_txt(1319)); // Gained zeny is now shown.
  6569. return 0;
  6570. }
  6571. ACMD_FUNC(showdelay)
  6572. {
  6573. if (sd->state.showdelay) {
  6574. sd->state.showdelay = 0;
  6575. clif_displaymessage(fd, msg_txt(1320)); // Skill delay failures will not be shown.
  6576. return 0;
  6577. }
  6578. sd->state.showdelay = 1;
  6579. clif_displaymessage(fd, msg_txt(1321)); // Skill delay failures are now shown.
  6580. return 0;
  6581. }
  6582. /*==========================================
  6583. * Duel organizing functions [LuzZza]
  6584. *
  6585. * @duel [limit|nick] - create a duel
  6586. * @invite <nick> - invite player
  6587. * @accept - accept invitation
  6588. * @reject - reject invitation
  6589. * @leave - leave duel
  6590. *------------------------------------------*/
  6591. ACMD_FUNC(invite)
  6592. {
  6593. unsigned int did = sd->duel_group;
  6594. struct map_session_data *target_sd = map_nick2sd((char *)message);
  6595. if(did <= 0) {
  6596. // "Duel: @invite without @duel."
  6597. clif_displaymessage(fd, msg_txt(350));
  6598. return 0;
  6599. }
  6600. if(duel_list[did].max_players_limit > 0 &&
  6601. duel_list[did].members_count >= duel_list[did].max_players_limit) {
  6602. // "Duel: Limit of players is reached."
  6603. clif_displaymessage(fd, msg_txt(351));
  6604. return 0;
  6605. }
  6606. if(target_sd == NULL) {
  6607. // "Duel: Player not found."
  6608. clif_displaymessage(fd, msg_txt(352));
  6609. return 0;
  6610. }
  6611. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  6612. // "Duel: Player already in duel."
  6613. clif_displaymessage(fd, msg_txt(353));
  6614. return 0;
  6615. }
  6616. if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
  6617. {
  6618. sprintf(atcmd_output, msg_txt(364), message);
  6619. clif_displaymessage(fd, atcmd_output);
  6620. return 0;
  6621. }
  6622. duel_invite(did, sd, target_sd);
  6623. // "Duel: Invitation has been sent."
  6624. clif_displaymessage(fd, msg_txt(354));
  6625. return 0;
  6626. }
  6627. ACMD_FUNC(duel)
  6628. {
  6629. char output[CHAT_SIZE_MAX];
  6630. unsigned int maxpl=0, newduel;
  6631. struct map_session_data *target_sd;
  6632. if(sd->duel_group > 0) {
  6633. duel_showinfo(sd->duel_group, sd);
  6634. return 0;
  6635. }
  6636. if(sd->duel_invite > 0) {
  6637. // "Duel: @duel without @reject."
  6638. clif_displaymessage(fd, msg_txt(355));
  6639. return 0;
  6640. }
  6641. if(!duel_checktime(sd)) {
  6642. // "Duel: You can take part in duel only one time per %d minutes."
  6643. sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  6644. clif_displaymessage(fd, output);
  6645. return 0;
  6646. }
  6647. if( message[0] ) {
  6648. if(sscanf(message, "%d", &maxpl) >= 1) {
  6649. if(maxpl < 2 || maxpl > 65535) {
  6650. clif_displaymessage(fd, msg_txt(357)); // "Duel: Invalid value."
  6651. return 0;
  6652. }
  6653. duel_create(sd, maxpl);
  6654. } else {
  6655. target_sd = map_nick2sd((char *)message);
  6656. if(target_sd != NULL) {
  6657. if((newduel = duel_create(sd, 2)) != -1) {
  6658. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  6659. clif_displaymessage(fd, msg_txt(353)); // "Duel: Player already in duel."
  6660. return 0;
  6661. }
  6662. duel_invite(newduel, sd, target_sd);
  6663. clif_displaymessage(fd, msg_txt(354)); // "Duel: Invitation has been sent."
  6664. }
  6665. } else {
  6666. // "Duel: Player not found."
  6667. clif_displaymessage(fd, msg_txt(352));
  6668. return 0;
  6669. }
  6670. }
  6671. } else
  6672. duel_create(sd, 0);
  6673. return 0;
  6674. }
  6675. ACMD_FUNC(leave)
  6676. {
  6677. if(sd->duel_group <= 0) {
  6678. // "Duel: @leave without @duel."
  6679. clif_displaymessage(fd, msg_txt(358));
  6680. return 0;
  6681. }
  6682. duel_leave(sd->duel_group, sd);
  6683. clif_displaymessage(fd, msg_txt(359)); // "Duel: You left the duel."
  6684. return 0;
  6685. }
  6686. ACMD_FUNC(accept)
  6687. {
  6688. char output[CHAT_SIZE_MAX];
  6689. if(!duel_checktime(sd)) {
  6690. // "Duel: You can take part in duel only one time per %d minutes."
  6691. sprintf(output, msg_txt(356), battle_config.duel_time_interval);
  6692. clif_displaymessage(fd, output);
  6693. return 0;
  6694. }
  6695. if(sd->duel_invite <= 0) {
  6696. // "Duel: @accept without invititation."
  6697. clif_displaymessage(fd, msg_txt(360));
  6698. return 0;
  6699. }
  6700. if( duel_list[sd->duel_invite].max_players_limit > 0 && duel_list[sd->duel_invite].members_count >= duel_list[sd->duel_invite].max_players_limit )
  6701. {
  6702. // "Duel: Limit of players is reached."
  6703. clif_displaymessage(fd, msg_txt(351));
  6704. return 0;
  6705. }
  6706. duel_accept(sd->duel_invite, sd);
  6707. // "Duel: Invitation has been accepted."
  6708. clif_displaymessage(fd, msg_txt(361));
  6709. return 0;
  6710. }
  6711. ACMD_FUNC(reject)
  6712. {
  6713. if(sd->duel_invite <= 0) {
  6714. // "Duel: @reject without invititation."
  6715. clif_displaymessage(fd, msg_txt(362));
  6716. return 0;
  6717. }
  6718. duel_reject(sd->duel_invite, sd);
  6719. // "Duel: Invitation has been rejected."
  6720. clif_displaymessage(fd, msg_txt(363));
  6721. return 0;
  6722. }
  6723. /*===================================
  6724. * Cash Points
  6725. *-----------------------------------*/
  6726. ACMD_FUNC(cash)
  6727. {
  6728. char output[128];
  6729. int value;
  6730. nullpo_retr(-1, sd);
  6731. if( !message || !*message || (value = atoi(message)) == 0 ) {
  6732. clif_displaymessage(fd, msg_txt(1322)); // Please enter an amount.
  6733. return -1;
  6734. }
  6735. if( !strcmpi(command+1,"cash") )
  6736. {
  6737. if( value > 0 ) {
  6738. pc_getcash(sd, value, 0);
  6739. sprintf(output, msg_txt(505), value, sd->cashPoints);
  6740. clif_disp_onlyself(sd, output, strlen(output));
  6741. } else {
  6742. pc_paycash(sd, -value, 0);
  6743. sprintf(output, msg_txt(410), value, sd->cashPoints);
  6744. clif_disp_onlyself(sd, output, strlen(output));
  6745. }
  6746. }
  6747. else
  6748. { // @points
  6749. if( value > 0 ) {
  6750. pc_getcash(sd, 0, value);
  6751. sprintf(output, msg_txt(506), value, sd->kafraPoints);
  6752. clif_disp_onlyself(sd, output, strlen(output));
  6753. } else {
  6754. pc_paycash(sd, -value, -value);
  6755. sprintf(output, msg_txt(411), -value, sd->kafraPoints);
  6756. clif_disp_onlyself(sd, output, strlen(output));
  6757. }
  6758. }
  6759. return 0;
  6760. }
  6761. // @clone/@slaveclone/@evilclone <playername> [Valaris]
  6762. ACMD_FUNC(clone)
  6763. {
  6764. int x=0,y=0,flag=0,master=0,i=0;
  6765. struct map_session_data *pl_sd=NULL;
  6766. if (!message || !*message) {
  6767. clif_displaymessage(sd->fd,msg_txt(1323)); // You must enter a player name or ID.
  6768. return 0;
  6769. }
  6770. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
  6771. clif_displaymessage(fd, msg_txt(3)); // Character not found.
  6772. return 0;
  6773. }
  6774. if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  6775. clif_displaymessage(fd, msg_txt(126)); // Cannot clone a player of higher GM level than yourself.
  6776. return 0;
  6777. }
  6778. if (strcmpi(command+1, "clone") == 0)
  6779. flag = 1;
  6780. else if (strcmpi(command+1, "slaveclone") == 0) {
  6781. flag = 2;
  6782. master = sd->bl.id;
  6783. if (battle_config.atc_slave_clone_limit
  6784. && mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
  6785. clif_displaymessage(fd, msg_txt(127)); // You've reached your slave clones limit.
  6786. return 0;
  6787. }
  6788. }
  6789. do {
  6790. x = sd->bl.x + (rnd() % 10 - 5);
  6791. y = sd->bl.y + (rnd() % 10 - 5);
  6792. } while (map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) && i++ < 10);
  6793. if (i >= 10) {
  6794. x = sd->bl.x;
  6795. y = sd->bl.y;
  6796. }
  6797. if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
  6798. clif_displaymessage(fd, msg_txt(128+flag*2)); // Evil Clone spawned. Clone spawned. Slave clone spawned.
  6799. return 0;
  6800. }
  6801. clif_displaymessage(fd, msg_txt(129+flag*2)); // Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
  6802. return 0;
  6803. }
  6804. /*===================================
  6805. * Main chat [LuzZza]
  6806. * Usage: @main <on|off|message>
  6807. *-----------------------------------*/
  6808. ACMD_FUNC(main)
  6809. {
  6810. if( message[0] ) {
  6811. if(strcmpi(message, "on") == 0) {
  6812. if(!sd->state.mainchat) {
  6813. sd->state.mainchat = 1;
  6814. clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  6815. } else {
  6816. clif_displaymessage(fd, msg_txt(381)); // Main chat already activated.
  6817. }
  6818. } else if(strcmpi(message, "off") == 0) {
  6819. if(sd->state.mainchat) {
  6820. sd->state.mainchat = 0;
  6821. clif_displaymessage(fd, msg_txt(382)); // Main chat has been disabled.
  6822. } else {
  6823. clif_displaymessage(fd, msg_txt(383)); // Main chat already disabled.
  6824. }
  6825. } else {
  6826. if(!sd->state.mainchat) {
  6827. sd->state.mainchat = 1;
  6828. clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  6829. }
  6830. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) {
  6831. clif_displaymessage(fd, msg_txt(387));
  6832. return -1;
  6833. }
  6834. if ( battle_config.min_chat_delay ) {
  6835. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  6836. return 0;
  6837. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  6838. }
  6839. // send the message using inter-server system
  6840. intif_main_message( sd, message );
  6841. }
  6842. } else {
  6843. if(sd->state.mainchat)
  6844. clif_displaymessage(fd, msg_txt(384)); // Main chat currently enabled. Usage: @main <on|off>, @main <message>.
  6845. else
  6846. clif_displaymessage(fd, msg_txt(385)); // Main chat currently disabled. Usage: @main <on|off>, @main <message>.
  6847. }
  6848. return 0;
  6849. }
  6850. /*=====================================
  6851. * Autorejecting Invites/Deals [LuzZza]
  6852. * Usage: @noask
  6853. *-------------------------------------*/
  6854. ACMD_FUNC(noask)
  6855. {
  6856. if(sd->state.noask) {
  6857. clif_displaymessage(fd, msg_txt(391)); // Autorejecting is deactivated.
  6858. sd->state.noask = 0;
  6859. } else {
  6860. clif_displaymessage(fd, msg_txt(390)); // Autorejecting is activated.
  6861. sd->state.noask = 1;
  6862. }
  6863. return 0;
  6864. }
  6865. /*=====================================
  6866. * Send a @request message to all GMs of lowest_gm_level.
  6867. * Usage: @request <petition>
  6868. *-------------------------------------*/
  6869. ACMD_FUNC(request)
  6870. {
  6871. if (!message || !*message) {
  6872. clif_displaymessage(sd->fd,msg_txt(277)); // Usage: @request <petition/message to online GMs>.
  6873. return -1;
  6874. }
  6875. sprintf(atcmd_output, msg_txt(278), message); // (@request): %s
  6876. intif_wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output);
  6877. clif_disp_onlyself(sd, atcmd_output, strlen(atcmd_output));
  6878. clif_displaymessage(sd->fd,msg_txt(279)); // @request sent.
  6879. return 0;
  6880. }
  6881. /*==========================================
  6882. * Feel (SG save map) Reset [HiddenDragon]
  6883. *------------------------------------------*/
  6884. ACMD_FUNC(feelreset)
  6885. {
  6886. pc_resetfeel(sd);
  6887. clif_displaymessage(fd, msg_txt(1324)); // Reset 'Feeling' maps.
  6888. return 0;
  6889. }
  6890. /*==========================================
  6891. * AUCTION SYSTEM
  6892. *------------------------------------------*/
  6893. ACMD_FUNC(auction)
  6894. {
  6895. nullpo_ret(sd);
  6896. clif_Auction_openwindow(sd);
  6897. return 0;
  6898. }
  6899. /*==========================================
  6900. * Kill Steal Protection
  6901. *------------------------------------------*/
  6902. ACMD_FUNC(ksprotection)
  6903. {
  6904. nullpo_retr(-1,sd);
  6905. if( sd->state.noks ) {
  6906. sd->state.noks = 0;
  6907. clif_displaymessage(fd, msg_txt(1325)); // [ K.S Protection Inactive ]
  6908. }
  6909. else
  6910. {
  6911. if( !message || !*message || !strcmpi(message, "party") )
  6912. { // Default is Party
  6913. sd->state.noks = 2;
  6914. clif_displaymessage(fd, msg_txt(1326)); // [ K.S Protection Active - Option: Party ]
  6915. }
  6916. else if( !strcmpi(message, "self") )
  6917. {
  6918. sd->state.noks = 1;
  6919. clif_displaymessage(fd, msg_txt(1327)); // [ K.S Protection Active - Option: Self ]
  6920. }
  6921. else if( !strcmpi(message, "guild") )
  6922. {
  6923. sd->state.noks = 3;
  6924. clif_displaymessage(fd, msg_txt(1328)); // [ K.S Protection Active - Option: Guild ]
  6925. }
  6926. else
  6927. clif_displaymessage(fd, msg_txt(1329)); // Usage: @noks <self|party|guild>
  6928. }
  6929. return 0;
  6930. }
  6931. /*==========================================
  6932. * Map Kill Steal Protection Setting
  6933. *------------------------------------------*/
  6934. ACMD_FUNC(allowks)
  6935. {
  6936. nullpo_retr(-1,sd);
  6937. if( map[sd->bl.m].flag.allowks ) {
  6938. map[sd->bl.m].flag.allowks = 0;
  6939. clif_displaymessage(fd, msg_txt(1330)); // [ Map K.S Protection Active ]
  6940. } else {
  6941. map[sd->bl.m].flag.allowks = 1;
  6942. clif_displaymessage(fd, msg_txt(1331)); // [ Map K.S Protection Inactive ]
  6943. }
  6944. return 0;
  6945. }
  6946. ACMD_FUNC(resetstat)
  6947. {
  6948. nullpo_retr(-1, sd);
  6949. pc_resetstate(sd);
  6950. sprintf(atcmd_output, msg_txt(207), sd->status.name);
  6951. clif_displaymessage(fd, atcmd_output);
  6952. return 0;
  6953. }
  6954. ACMD_FUNC(resetskill)
  6955. {
  6956. nullpo_retr(-1,sd);
  6957. pc_resetskill(sd,1);
  6958. sprintf(atcmd_output, msg_txt(206), sd->status.name);
  6959. clif_displaymessage(fd, atcmd_output);
  6960. return 0;
  6961. }
  6962. /*==========================================
  6963. * #storagelist: Displays the items list of a player's storage.
  6964. * #cartlist: Displays contents of target's cart.
  6965. * #itemlist: Displays contents of target's inventory.
  6966. *------------------------------------------*/
  6967. ACMD_FUNC(itemlist)
  6968. {
  6969. int i, j, count, counter;
  6970. const char* location;
  6971. const struct item* items;
  6972. int size;
  6973. StringBuf buf;
  6974. nullpo_retr(-1, sd);
  6975. if( strcmp(command+1, "storagelist") == 0 )
  6976. {
  6977. location = "storage";
  6978. items = sd->status.storage.items;
  6979. size = MAX_STORAGE;
  6980. }
  6981. else
  6982. if( strcmp(command+1, "cartlist") == 0 )
  6983. {
  6984. location = "cart";
  6985. items = sd->status.cart;
  6986. size = MAX_CART;
  6987. }
  6988. else
  6989. if( strcmp(command+1, "itemlist") == 0 )
  6990. {
  6991. location = "inventory";
  6992. items = sd->status.inventory;
  6993. size = MAX_INVENTORY;
  6994. }
  6995. else
  6996. return 1;
  6997. StringBuf_Init(&buf);
  6998. count = 0; // total slots occupied
  6999. counter = 0; // total items found
  7000. for( i = 0; i < size; ++i )
  7001. {
  7002. const struct item* it = &items[i];
  7003. struct item_data* itd;
  7004. if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL )
  7005. continue;
  7006. counter += it->amount;
  7007. count++;
  7008. if( count == 1 )
  7009. {
  7010. StringBuf_Printf(&buf, msg_txt(1332), location, sd->status.name); // ------ %s items list of '%s' ------
  7011. clif_displaymessage(fd, StringBuf_Value(&buf));
  7012. StringBuf_Clear(&buf);
  7013. }
  7014. if( it->refine )
  7015. StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid);
  7016. else
  7017. StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid);
  7018. if( it->equip )
  7019. {
  7020. char equipstr[CHAT_SIZE_MAX];
  7021. strcpy(equipstr, msg_txt(1333)); // | equipped:
  7022. if( it->equip & EQP_GARMENT )
  7023. strcat(equipstr, msg_txt(1334)); // garment,
  7024. if( it->equip & EQP_ACC_L )
  7025. strcat(equipstr, msg_txt(1335)); // left accessory,
  7026. if( it->equip & EQP_ARMOR )
  7027. strcat(equipstr, msg_txt(1336)); // body/armor,
  7028. if( (it->equip & EQP_ARMS) == EQP_HAND_R )
  7029. strcat(equipstr, msg_txt(1337)); // right hand,
  7030. if( (it->equip & EQP_ARMS) == EQP_HAND_L )
  7031. strcat(equipstr, msg_txt(1338)); // left hand,
  7032. if( (it->equip & EQP_ARMS) == EQP_ARMS )
  7033. strcat(equipstr, msg_txt(1339)); // both hands,
  7034. if( it->equip & EQP_SHOES )
  7035. strcat(equipstr, msg_txt(1340)); // feet,
  7036. if( it->equip & EQP_ACC_R )
  7037. strcat(equipstr, msg_txt(1341)); // right accessory,
  7038. if( (it->equip & EQP_HELM) == EQP_HEAD_LOW )
  7039. strcat(equipstr, msg_txt(1342)); // lower head,
  7040. if( (it->equip & EQP_HELM) == EQP_HEAD_TOP )
  7041. strcat(equipstr, msg_txt(1343)); // top head,
  7042. if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_TOP) )
  7043. strcat(equipstr, msg_txt(1344)); // lower/top head,
  7044. if( (it->equip & EQP_HELM) == EQP_HEAD_MID )
  7045. strcat(equipstr, msg_txt(1345)); // mid head,
  7046. if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_MID) )
  7047. strcat(equipstr, msg_txt(1346)); // lower/mid head,
  7048. if( (it->equip & EQP_HELM) == EQP_HELM )
  7049. strcat(equipstr, msg_txt(1347)); // lower/mid/top head,
  7050. // remove final ', '
  7051. equipstr[strlen(equipstr) - 2] = '\0';
  7052. StringBuf_AppendStr(&buf, equipstr);
  7053. }
  7054. clif_displaymessage(fd, StringBuf_Value(&buf));
  7055. StringBuf_Clear(&buf);
  7056. if( it->card[0] == CARD0_PET )
  7057. {// pet egg
  7058. if (it->card[3])
  7059. StringBuf_Printf(&buf, msg_txt(1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named)
  7060. else
  7061. StringBuf_Printf(&buf, msg_txt(1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed)
  7062. }
  7063. else
  7064. if(it->card[0] == CARD0_FORGE)
  7065. {// forged item
  7066. StringBuf_Printf(&buf, msg_txt(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)
  7067. }
  7068. else
  7069. if(it->card[0] == CARD0_CREATE)
  7070. {// created item
  7071. StringBuf_Printf(&buf, msg_txt(1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u)
  7072. }
  7073. else
  7074. {// normal item
  7075. int counter2 = 0;
  7076. for( j = 0; j < itd->slot; ++j )
  7077. {
  7078. struct item_data* card;
  7079. if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL )
  7080. continue;
  7081. counter2++;
  7082. if( counter2 == 1 )
  7083. StringBuf_AppendStr(&buf, msg_txt(1352)); // -> (card(s):
  7084. if( counter2 != 1 )
  7085. StringBuf_AppendStr(&buf, ", ");
  7086. StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid);
  7087. }
  7088. if( counter2 > 0 )
  7089. StringBuf_AppendStr(&buf, ")");
  7090. }
  7091. if( StringBuf_Length(&buf) > 0 )
  7092. clif_displaymessage(fd, StringBuf_Value(&buf));
  7093. StringBuf_Clear(&buf);
  7094. }
  7095. if( count == 0 )
  7096. StringBuf_Printf(&buf, msg_txt(1353), location); // No item found in this player's %s.
  7097. else
  7098. StringBuf_Printf(&buf, msg_txt(1354), counter, count, location); // %d item(s) found in %d %s slots.
  7099. clif_displaymessage(fd, StringBuf_Value(&buf));
  7100. StringBuf_Destroy(&buf);
  7101. return 0;
  7102. }
  7103. ACMD_FUNC(stats)
  7104. {
  7105. char job_jobname[100];
  7106. char output[CHAT_SIZE_MAX];
  7107. int i;
  7108. struct {
  7109. const char* format;
  7110. int value;
  7111. } output_table[] = {
  7112. { "Base Level - %d", 0 },
  7113. { NULL, 0 },
  7114. { "Hp - %d", 0 },
  7115. { "MaxHp - %d", 0 },
  7116. { "Sp - %d", 0 },
  7117. { "MaxSp - %d", 0 },
  7118. { "Str - %3d", 0 },
  7119. { "Agi - %3d", 0 },
  7120. { "Vit - %3d", 0 },
  7121. { "Int - %3d", 0 },
  7122. { "Dex - %3d", 0 },
  7123. { "Luk - %3d", 0 },
  7124. { "Zeny - %d", 0 },
  7125. { "Free SK Points - %d", 0 },
  7126. { "JobChangeLvl (2nd) - %d", 0 },
  7127. { "JobChangeLvl (3rd) - %d", 0 },
  7128. { NULL, 0 }
  7129. };
  7130. memset(job_jobname, '\0', sizeof(job_jobname));
  7131. memset(output, '\0', sizeof(output));
  7132. //direct array initialization with variables is not standard C compliant.
  7133. output_table[0].value = sd->status.base_level;
  7134. output_table[1].format = job_jobname;
  7135. output_table[1].value = sd->status.job_level;
  7136. output_table[2].value = sd->status.hp;
  7137. output_table[3].value = sd->status.max_hp;
  7138. output_table[4].value = sd->status.sp;
  7139. output_table[5].value = sd->status.max_sp;
  7140. output_table[6].value = sd->status.str;
  7141. output_table[7].value = sd->status.agi;
  7142. output_table[8].value = sd->status.vit;
  7143. output_table[9].value = sd->status.int_;
  7144. output_table[10].value = sd->status.dex;
  7145. output_table[11].value = sd->status.luk;
  7146. output_table[12].value = sd->status.zeny;
  7147. output_table[13].value = sd->status.skill_point;
  7148. output_table[14].value = sd->change_level_2nd;
  7149. output_table[15].value = sd->change_level_3rd;
  7150. sprintf(job_jobname, "Job - %s %s", job_name(sd->status.class_), "(level %d)");
  7151. sprintf(output, msg_txt(53), sd->status.name); // '%s' stats:
  7152. clif_displaymessage(fd, output);
  7153. for (i = 0; output_table[i].format != NULL; i++) {
  7154. sprintf(output, output_table[i].format, output_table[i].value);
  7155. clif_displaymessage(fd, output);
  7156. }
  7157. return 0;
  7158. }
  7159. ACMD_FUNC(delitem)
  7160. {
  7161. char item_name[100];
  7162. int nameid, amount = 0, total, idx;
  7163. struct item_data* id;
  7164. nullpo_retr(-1, sd);
  7165. if( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &amount) < 2 && sscanf(message, "%99s %d", item_name, &amount) < 2 ) || amount < 1 )
  7166. {
  7167. clif_displaymessage(fd, msg_txt(1355)); // Please enter an item name/ID, a quantity, and a player name (usage: #delitem <player> <item_name_or_ID> <quantity>).
  7168. return -1;
  7169. }
  7170. if( ( id = itemdb_searchname(item_name) ) != NULL || ( id = itemdb_exists(atoi(item_name)) ) != NULL )
  7171. {
  7172. nameid = id->nameid;
  7173. }
  7174. else
  7175. {
  7176. clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
  7177. return -1;
  7178. }
  7179. total = amount;
  7180. // delete items
  7181. while( amount && ( idx = pc_search_inventory(sd, nameid) ) != -1 )
  7182. {
  7183. int delamount = ( amount < sd->status.inventory[idx].amount ) ? amount : sd->status.inventory[idx].amount;
  7184. if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET )
  7185. {// delete pet
  7186. intif_delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2]));
  7187. }
  7188. pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_COMMAND);
  7189. amount-= delamount;
  7190. }
  7191. // notify target
  7192. sprintf(atcmd_output, msg_txt(113), total-amount); // %d item(s) removed by a GM.
  7193. clif_displaymessage(sd->fd, atcmd_output);
  7194. // notify source
  7195. if( amount == total )
  7196. {
  7197. clif_displaymessage(fd, msg_txt(116)); // Character does not have the item.
  7198. }
  7199. else if( amount )
  7200. {
  7201. sprintf(atcmd_output, msg_txt(115), total-amount, total-amount, total); // %d item(s) removed. Player had only %d on %d items.
  7202. clif_displaymessage(fd, atcmd_output);
  7203. }
  7204. else
  7205. {
  7206. sprintf(atcmd_output, msg_txt(114), total); // %d item(s) removed from the player.
  7207. clif_displaymessage(fd, atcmd_output);
  7208. }
  7209. return 0;
  7210. }
  7211. /*==========================================
  7212. * Custom Fonts
  7213. *------------------------------------------*/
  7214. ACMD_FUNC(font)
  7215. {
  7216. int font_id;
  7217. nullpo_retr(-1,sd);
  7218. font_id = atoi(message);
  7219. if( font_id == 0 )
  7220. {
  7221. if( sd->user_font )
  7222. {
  7223. sd->user_font = 0;
  7224. clif_displaymessage(fd, msg_txt(1356)); // Returning to normal font.
  7225. clif_font(sd);
  7226. }
  7227. else
  7228. {
  7229. clif_displaymessage(fd, msg_txt(1357)); // Use @font <1-9> to change your message font.
  7230. clif_displaymessage(fd, msg_txt(1358)); // Use 0 or no parameter to return to normal font.
  7231. }
  7232. }
  7233. else if( font_id < 0 || font_id > 9 )
  7234. clif_displaymessage(fd, msg_txt(1359)); // Invalid font. Use a value from 0 to 9.
  7235. else if( font_id != sd->user_font )
  7236. {
  7237. sd->user_font = font_id;
  7238. clif_font(sd);
  7239. clif_displaymessage(fd, msg_txt(1360)); // Font changed.
  7240. }
  7241. else
  7242. clif_displaymessage(fd, msg_txt(1361)); // Already using this font.
  7243. return 0;
  7244. }
  7245. /*==========================================
  7246. * type: 1 = commands (@), 2 = charcommands (#)
  7247. *------------------------------------------*/
  7248. static void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommandType type)
  7249. {
  7250. char line_buff[CHATBOX_SIZE];
  7251. char* cur = line_buff;
  7252. AtCommandInfo* cmd;
  7253. DBIterator *iter = db_iterator(atcommand_db);
  7254. int count = 0;
  7255. memset(line_buff,' ',CHATBOX_SIZE);
  7256. line_buff[CHATBOX_SIZE-1] = 0;
  7257. clif_displaymessage(fd, msg_txt(273)); // "Commands available:"
  7258. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  7259. unsigned int slen = 0;
  7260. switch( type ) {
  7261. case COMMAND_CHARCOMMAND:
  7262. if( cmd->char_groups[sd->group_pos] == 0 )
  7263. continue;
  7264. break;
  7265. case COMMAND_ATCOMMAND:
  7266. if( cmd->at_groups[sd->group_pos] == 0 )
  7267. continue;
  7268. break;
  7269. default:
  7270. continue;
  7271. }
  7272. slen = strlen(cmd->command);
  7273. // flush the text buffer if this command won't fit into it
  7274. if ( slen + cur - line_buff >= CHATBOX_SIZE )
  7275. {
  7276. clif_displaymessage(fd,line_buff);
  7277. cur = line_buff;
  7278. memset(line_buff,' ',CHATBOX_SIZE);
  7279. line_buff[CHATBOX_SIZE-1] = 0;
  7280. }
  7281. memcpy(cur,cmd->command,slen);
  7282. cur += slen+(10-slen%10);
  7283. count++;
  7284. }
  7285. dbi_destroy(iter);
  7286. clif_displaymessage(fd,line_buff);
  7287. sprintf(atcmd_output, msg_txt(274), count); // "%d commands found."
  7288. clif_displaymessage(fd, atcmd_output);
  7289. return;
  7290. }
  7291. /*==========================================
  7292. * @commands Lists available @ commands to you
  7293. *------------------------------------------*/
  7294. ACMD_FUNC(commands)
  7295. {
  7296. atcommand_commands_sub(sd, fd, COMMAND_ATCOMMAND);
  7297. return 0;
  7298. }
  7299. /*==========================================
  7300. * @charcommands Lists available # commands to you
  7301. *------------------------------------------*/
  7302. ACMD_FUNC(charcommands)
  7303. {
  7304. atcommand_commands_sub(sd, fd, COMMAND_CHARCOMMAND);
  7305. return 0;
  7306. }
  7307. /* for new mounts */
  7308. ACMD_FUNC(mount2) {
  7309. clif_displaymessage(sd->fd,msg_txt(1362)); // NOTICE: If you crash with mount your LUA is outdated.
  7310. if( !(sd->sc.option&OPTION_MOUNTING) ) {
  7311. clif_displaymessage(sd->fd,msg_txt(1363)); // You have mounted.
  7312. pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);
  7313. } else {
  7314. clif_displaymessage(sd->fd,msg_txt(1364)); // You have released your mount.
  7315. pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);
  7316. }
  7317. return 0;
  7318. }
  7319. ACMD_FUNC(accinfo) {
  7320. char query[NAME_LENGTH];
  7321. if (!message || !*message || strlen(message) > NAME_LENGTH ) {
  7322. clif_displaymessage(fd, msg_txt(1365)); // Usage: @accinfo/@accountinfo <account_id/char name>
  7323. clif_displaymessage(fd, msg_txt(1366)); // You may search partial name by making use of '%' in the search, ex. "@accinfo %Mario%" lists all characters whose name contains "Mario".
  7324. return -1;
  7325. }
  7326. //remove const type
  7327. safestrncpy(query, message, NAME_LENGTH);
  7328. intif_request_accinfo( sd->fd, sd->bl.id, sd->group_id, query );
  7329. return 0;
  7330. }
  7331. /* [Ind] */
  7332. ACMD_FUNC(set) {
  7333. char reg[32], val[128];
  7334. struct script_data* data;
  7335. int toset = 0;
  7336. bool is_str = false;
  7337. if( !message || !*message || (toset = sscanf(message, "%32s %128[^\n]s", reg, val)) < 1 ) {
  7338. clif_displaymessage(fd, msg_txt(1367)); // Usage: @set <variable name> <value>
  7339. clif_displaymessage(fd, msg_txt(1368)); // Usage: ex. "@set PoringCharVar 50"
  7340. clif_displaymessage(fd, msg_txt(1369)); // Usage: ex. "@set PoringCharVarSTR$ Super Duper String"
  7341. clif_displaymessage(fd, msg_txt(1370)); // Usage: ex. "@set PoringCharVarSTR$" outputs its value, Super Duper String.
  7342. return -1;
  7343. }
  7344. /* disabled variable types (they require a proper script state to function, so allowing them would crash the server) */
  7345. if( reg[0] == '.' ) {
  7346. clif_displaymessage(fd, msg_txt(1371)); // NPC variables may not be used with @set.
  7347. return -1;
  7348. } else if( reg[0] == '\'' ) {
  7349. clif_displaymessage(fd, msg_txt(1372)); // Instance variables may not be used with @set.
  7350. return -1;
  7351. }
  7352. is_str = ( reg[strlen(reg) - 1] == '$' ) ? true : false;
  7353. if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
  7354. if( is_str )
  7355. set_var(sd, reg, (void*) val);
  7356. else
  7357. set_var(sd, reg, (void*)__64BPRTSIZE((int)(atoi(val))));
  7358. }
  7359. CREATE(data, struct script_data,1);
  7360. if( is_str ) {// string variable
  7361. switch( reg[0] ) {
  7362. case '@':
  7363. data->u.str = pc_readregstr(sd, add_str(reg));
  7364. break;
  7365. case '$':
  7366. data->u.str = mapreg_readregstr(add_str(reg));
  7367. break;
  7368. case '#':
  7369. if( reg[1] == '#' )
  7370. data->u.str = pc_readaccountreg2str(sd, reg);// global
  7371. else
  7372. data->u.str = pc_readaccountregstr(sd, reg);// local
  7373. break;
  7374. default:
  7375. data->u.str = pc_readglobalreg_str(sd, reg);
  7376. break;
  7377. }
  7378. if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string
  7379. data->type = C_CONSTSTR;
  7380. data->u.str = "";
  7381. } else {// duplicate string
  7382. data->type = C_STR;
  7383. data->u.str = aStrdup(data->u.str);
  7384. }
  7385. } else {// integer variable
  7386. data->type = C_INT;
  7387. switch( reg[0] ) {
  7388. case '@':
  7389. data->u.num = pc_readreg(sd, add_str(reg));
  7390. break;
  7391. case '$':
  7392. data->u.num = mapreg_readreg(add_str(reg));
  7393. break;
  7394. case '#':
  7395. if( reg[1] == '#' )
  7396. data->u.num = pc_readaccountreg2(sd, reg);// global
  7397. else
  7398. data->u.num = pc_readaccountreg(sd, reg);// local
  7399. break;
  7400. default:
  7401. data->u.num = pc_readglobalreg(sd, reg);
  7402. break;
  7403. }
  7404. }
  7405. switch( data->type ) {
  7406. case C_INT:
  7407. sprintf(atcmd_output,msg_txt(1373),reg,data->u.num); // %s value is now :%d
  7408. break;
  7409. case C_STR:
  7410. sprintf(atcmd_output,msg_txt(1374),reg,data->u.str); // %s value is now :%s
  7411. break;
  7412. case C_CONSTSTR:
  7413. sprintf(atcmd_output,msg_txt(1375),reg); // %s is empty
  7414. break;
  7415. default:
  7416. sprintf(atcmd_output,msg_txt(1376),reg,data->type); // %s data type is not supported :%u
  7417. break;
  7418. }
  7419. clif_displaymessage(fd, atcmd_output);
  7420. aFree(data);
  7421. return 0;
  7422. }
  7423. ACMD_FUNC(reloadquestdb) {
  7424. do_reload_quest();
  7425. clif_displaymessage(fd, msg_txt(1377)); // Quest database has been reloaded.
  7426. return 0;
  7427. }
  7428. ACMD_FUNC(addperm) {
  7429. int perm_size = ARRAYLENGTH(pc_g_permission_name);
  7430. bool add = (strcmpi(command+1, "addperm") == 0) ? true : false;
  7431. int i;
  7432. if( !message || !*message ) {
  7433. sprintf(atcmd_output, msg_txt(1378),command); // Usage: %s <permission_name>
  7434. clif_displaymessage(fd, atcmd_output);
  7435. clif_displaymessage(fd, msg_txt(1379)); // -- Permission List
  7436. for( i = 0; i < perm_size; i++ ) {
  7437. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7438. clif_displaymessage(fd, atcmd_output);
  7439. }
  7440. return -1;
  7441. }
  7442. ARR_FIND(0, perm_size, i, strcmpi(pc_g_permission_name[i].name, message) == 0);
  7443. if( i == perm_size ) {
  7444. sprintf(atcmd_output,msg_txt(1380),message); // '%s' is not a known permission.
  7445. clif_displaymessage(fd, atcmd_output);
  7446. clif_displaymessage(fd, msg_txt(1379)); // -- Permission List
  7447. for( i = 0; i < perm_size; i++ ) {
  7448. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7449. clif_displaymessage(fd, atcmd_output);
  7450. }
  7451. return -1;
  7452. }
  7453. if( add && (sd->permissions&pc_g_permission_name[i].permission) ) {
  7454. sprintf(atcmd_output, msg_txt(1381),sd->status.name,pc_g_permission_name[i].name); // User '%s' already possesses the '%s' permission.
  7455. clif_displaymessage(fd, atcmd_output);
  7456. return -1;
  7457. } else if ( !add && !(sd->permissions&pc_g_permission_name[i].permission) ) {
  7458. sprintf(atcmd_output, msg_txt(1382),sd->status.name,pc_g_permission_name[i].name); // User '%s' doesn't possess the '%s' permission.
  7459. clif_displaymessage(fd, atcmd_output);
  7460. sprintf(atcmd_output,msg_txt(1383),sd->status.name); // -- User '%s' Permissions
  7461. clif_displaymessage(fd, atcmd_output);
  7462. for( i = 0; i < perm_size; i++ ) {
  7463. if( sd->permissions&pc_g_permission_name[i].permission ) {
  7464. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7465. clif_displaymessage(fd, atcmd_output);
  7466. }
  7467. }
  7468. return -1;
  7469. }
  7470. if( add )
  7471. sd->permissions |= pc_g_permission_name[i].permission;
  7472. else
  7473. sd->permissions &=~ pc_g_permission_name[i].permission;
  7474. sprintf(atcmd_output, msg_txt(1384),sd->status.name); // User '%s' permissions updated successfully. The changes are temporary.
  7475. clif_displaymessage(fd, atcmd_output);
  7476. return 0;
  7477. }
  7478. ACMD_FUNC(unloadnpcfile) {
  7479. if( !message || !*message ) {
  7480. clif_displaymessage(fd, msg_txt(1385)); // Usage: @unloadnpcfile <file name>
  7481. return -1;
  7482. }
  7483. if( npc_unloadfile(message) )
  7484. clif_displaymessage(fd, msg_txt(1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
  7485. else {
  7486. clif_displaymessage(fd, msg_txt(1387)); // File not found.
  7487. return -1;
  7488. }
  7489. return 0;
  7490. }
  7491. ACMD_FUNC(cart) {
  7492. #define MC_CART_MDFY(x) \
  7493. sd->status.skill[MC_PUSHCART].id = x?MC_PUSHCART:0; \
  7494. sd->status.skill[MC_PUSHCART].lv = x?1:0; \
  7495. sd->status.skill[MC_PUSHCART].flag = x?1:0;
  7496. int val = atoi(message);
  7497. bool need_skill = pc_checkskill(sd, MC_PUSHCART) ? false : true;
  7498. if( !message || !*message || val < 0 || val > MAX_CARTS ) {
  7499. sprintf(atcmd_output, msg_txt(1390),command,MAX_CARTS); // Unknown Cart (usage: %s <0-%d>).
  7500. clif_displaymessage(fd, atcmd_output);
  7501. return -1;
  7502. }
  7503. if( val == 0 && !pc_iscarton(sd) ) {
  7504. clif_displaymessage(fd, msg_txt(1391)); // You do not possess a cart to be removed
  7505. return -1;
  7506. }
  7507. if( need_skill ) {
  7508. MC_CART_MDFY(1);
  7509. }
  7510. if( pc_setcart(sd, val) ) {
  7511. if( need_skill ) {
  7512. MC_CART_MDFY(0);
  7513. }
  7514. return -1;/* @cart failed */
  7515. }
  7516. if( need_skill ) {
  7517. MC_CART_MDFY(0);
  7518. }
  7519. clif_displaymessage(fd, msg_txt(1392)); // Cart Added
  7520. return 0;
  7521. #undef MC_CART_MDFY
  7522. }
  7523. /**
  7524. * Fills the reference of available commands in atcommand DBMap
  7525. **/
  7526. #define ACMD_DEF(x) { #x, atcommand_ ## x, NULL, NULL }
  7527. #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x, NULL, NULL }
  7528. void atcommand_basecommands(void) {
  7529. /**
  7530. * Command reference list, place the base of your commands here
  7531. **/
  7532. AtCommandInfo atcommand_base[] = {
  7533. ACMD_DEF2("warp", mapmove),
  7534. ACMD_DEF(where),
  7535. ACMD_DEF(jumpto),
  7536. ACMD_DEF(jump),
  7537. ACMD_DEF(who),
  7538. ACMD_DEF2("who2", who),
  7539. ACMD_DEF2("who3", who),
  7540. ACMD_DEF2("whomap", who),
  7541. ACMD_DEF2("whomap2", who),
  7542. ACMD_DEF2("whomap3", who),
  7543. ACMD_DEF(whogm),
  7544. ACMD_DEF(save),
  7545. ACMD_DEF(load),
  7546. ACMD_DEF(speed),
  7547. ACMD_DEF(storage),
  7548. ACMD_DEF(guildstorage),
  7549. ACMD_DEF(option),
  7550. ACMD_DEF(hide), // + /hide
  7551. ACMD_DEF(jobchange),
  7552. ACMD_DEF(kill),
  7553. ACMD_DEF(alive),
  7554. ACMD_DEF(kami),
  7555. ACMD_DEF2("kamib", kami),
  7556. ACMD_DEF2("kamic", kami),
  7557. ACMD_DEF2("lkami", kami),
  7558. ACMD_DEF(heal),
  7559. ACMD_DEF(item),
  7560. ACMD_DEF(item2),
  7561. ACMD_DEF(itemreset),
  7562. ACMD_DEF2("blvl", baselevelup),
  7563. ACMD_DEF2("jlvl", joblevelup),
  7564. ACMD_DEF(help),
  7565. ACMD_DEF(pvpoff),
  7566. ACMD_DEF(pvpon),
  7567. ACMD_DEF(gvgoff),
  7568. ACMD_DEF(gvgon),
  7569. ACMD_DEF(model),
  7570. ACMD_DEF(go),
  7571. ACMD_DEF(monster),
  7572. ACMD_DEF2("monstersmall", monster),
  7573. ACMD_DEF2("monsterbig", monster),
  7574. ACMD_DEF(killmonster),
  7575. ACMD_DEF2("killmonster2", killmonster),
  7576. ACMD_DEF(refine),
  7577. ACMD_DEF(produce),
  7578. ACMD_DEF(memo),
  7579. ACMD_DEF(gat),
  7580. ACMD_DEF(displaystatus),
  7581. ACMD_DEF2("stpoint", statuspoint),
  7582. ACMD_DEF2("skpoint", skillpoint),
  7583. ACMD_DEF(zeny),
  7584. ACMD_DEF2("str", param),
  7585. ACMD_DEF2("agi", param),
  7586. ACMD_DEF2("vit", param),
  7587. ACMD_DEF2("int", param),
  7588. ACMD_DEF2("dex", param),
  7589. ACMD_DEF2("luk", param),
  7590. ACMD_DEF2("glvl", guildlevelup),
  7591. ACMD_DEF(makeegg),
  7592. ACMD_DEF(hatch),
  7593. ACMD_DEF(petfriendly),
  7594. ACMD_DEF(pethungry),
  7595. ACMD_DEF(petrename),
  7596. ACMD_DEF(recall), // + /recall
  7597. ACMD_DEF(night),
  7598. ACMD_DEF(day),
  7599. ACMD_DEF(doom),
  7600. ACMD_DEF(doommap),
  7601. ACMD_DEF(raise),
  7602. ACMD_DEF(raisemap),
  7603. ACMD_DEF(kick), // + right click menu for GM "(name) force to quit"
  7604. ACMD_DEF(kickall),
  7605. ACMD_DEF(allskill),
  7606. ACMD_DEF(questskill),
  7607. ACMD_DEF(lostskill),
  7608. ACMD_DEF(spiritball),
  7609. ACMD_DEF(party),
  7610. ACMD_DEF(guild),
  7611. ACMD_DEF(agitstart),
  7612. ACMD_DEF(agitend),
  7613. ACMD_DEF(mapexit),
  7614. ACMD_DEF(idsearch),
  7615. ACMD_DEF(broadcast), // + /b and /nb
  7616. ACMD_DEF(localbroadcast), // + /lb and /nlb
  7617. ACMD_DEF(recallall),
  7618. ACMD_DEF(reloaditemdb),
  7619. ACMD_DEF(reloadmobdb),
  7620. ACMD_DEF(reloadskilldb),
  7621. ACMD_DEF(reloadscript),
  7622. ACMD_DEF(reloadatcommand),
  7623. ACMD_DEF(reloadbattleconf),
  7624. ACMD_DEF(reloadstatusdb),
  7625. ACMD_DEF(reloadpcdb),
  7626. ACMD_DEF(reloadmotd),
  7627. ACMD_DEF(mapinfo),
  7628. ACMD_DEF(dye),
  7629. ACMD_DEF2("hairstyle", hair_style),
  7630. ACMD_DEF2("haircolor", hair_color),
  7631. ACMD_DEF2("allstats", stat_all),
  7632. ACMD_DEF2("block", char_block),
  7633. ACMD_DEF2("ban", char_ban),
  7634. ACMD_DEF2("unblock", char_unblock),
  7635. ACMD_DEF2("unban", char_unban),
  7636. ACMD_DEF2("mount", mount_peco),
  7637. ACMD_DEF(guildspy),
  7638. ACMD_DEF(partyspy),
  7639. ACMD_DEF(repairall),
  7640. ACMD_DEF(guildrecall),
  7641. ACMD_DEF(partyrecall),
  7642. ACMD_DEF(nuke),
  7643. ACMD_DEF(shownpc),
  7644. ACMD_DEF(hidenpc),
  7645. ACMD_DEF(loadnpc),
  7646. ACMD_DEF(unloadnpc),
  7647. ACMD_DEF2("time", servertime),
  7648. ACMD_DEF(jail),
  7649. ACMD_DEF(unjail),
  7650. ACMD_DEF(jailfor),
  7651. ACMD_DEF(jailtime),
  7652. ACMD_DEF(disguise),
  7653. ACMD_DEF(undisguise),
  7654. ACMD_DEF(email),
  7655. ACMD_DEF(effect),
  7656. ACMD_DEF(follow),
  7657. ACMD_DEF(addwarp),
  7658. ACMD_DEF(skillon),
  7659. ACMD_DEF(skilloff),
  7660. ACMD_DEF(killer),
  7661. ACMD_DEF(npcmove),
  7662. ACMD_DEF(killable),
  7663. ACMD_DEF(dropall),
  7664. ACMD_DEF(storeall),
  7665. ACMD_DEF(skillid),
  7666. ACMD_DEF(useskill),
  7667. ACMD_DEF(displayskill),
  7668. ACMD_DEF(snow),
  7669. ACMD_DEF(sakura),
  7670. ACMD_DEF(clouds),
  7671. ACMD_DEF(clouds2),
  7672. ACMD_DEF(fog),
  7673. ACMD_DEF(fireworks),
  7674. ACMD_DEF(leaves),
  7675. ACMD_DEF(summon),
  7676. ACMD_DEF(adjgroup),
  7677. ACMD_DEF(trade),
  7678. ACMD_DEF(send),
  7679. ACMD_DEF(setbattleflag),
  7680. ACMD_DEF(unmute),
  7681. ACMD_DEF(clearweather),
  7682. ACMD_DEF(uptime),
  7683. ACMD_DEF(changesex),
  7684. ACMD_DEF(mute),
  7685. ACMD_DEF(refresh),
  7686. ACMD_DEF(identify),
  7687. ACMD_DEF(gmotd),
  7688. ACMD_DEF(misceffect),
  7689. ACMD_DEF(mobsearch),
  7690. ACMD_DEF(cleanmap),
  7691. ACMD_DEF(npctalk),
  7692. ACMD_DEF(pettalk),
  7693. ACMD_DEF(users),
  7694. ACMD_DEF(reset),
  7695. ACMD_DEF(skilltree),
  7696. ACMD_DEF(marry),
  7697. ACMD_DEF(divorce),
  7698. ACMD_DEF(sound),
  7699. ACMD_DEF(undisguiseall),
  7700. ACMD_DEF(disguiseall),
  7701. ACMD_DEF(changelook),
  7702. ACMD_DEF(autoloot),
  7703. ACMD_DEF2("alootid", autolootitem),
  7704. ACMD_DEF(mobinfo),
  7705. ACMD_DEF(exp),
  7706. ACMD_DEF(adopt),
  7707. ACMD_DEF(version),
  7708. ACMD_DEF(mutearea),
  7709. ACMD_DEF(rates),
  7710. ACMD_DEF(iteminfo),
  7711. ACMD_DEF(whodrops),
  7712. ACMD_DEF(whereis),
  7713. ACMD_DEF(mapflag),
  7714. ACMD_DEF(me),
  7715. ACMD_DEF(monsterignore),
  7716. ACMD_DEF(fakename),
  7717. ACMD_DEF(size),
  7718. ACMD_DEF(showexp),
  7719. ACMD_DEF(showzeny),
  7720. ACMD_DEF(showdelay),
  7721. ACMD_DEF(autotrade),
  7722. ACMD_DEF(changegm),
  7723. ACMD_DEF(changeleader),
  7724. ACMD_DEF(partyoption),
  7725. ACMD_DEF(invite),
  7726. ACMD_DEF(duel),
  7727. ACMD_DEF(leave),
  7728. ACMD_DEF(accept),
  7729. ACMD_DEF(reject),
  7730. ACMD_DEF(main),
  7731. ACMD_DEF(clone),
  7732. ACMD_DEF2("slaveclone", clone),
  7733. ACMD_DEF2("evilclone", clone),
  7734. ACMD_DEF(tonpc),
  7735. ACMD_DEF(commands),
  7736. ACMD_DEF(noask),
  7737. ACMD_DEF(request),
  7738. ACMD_DEF(homlevel),
  7739. ACMD_DEF(homevolution),
  7740. ACMD_DEF(makehomun),
  7741. ACMD_DEF(homfriendly),
  7742. ACMD_DEF(homhungry),
  7743. ACMD_DEF(homtalk),
  7744. ACMD_DEF(hominfo),
  7745. ACMD_DEF(homstats),
  7746. ACMD_DEF(homshuffle),
  7747. ACMD_DEF(showmobs),
  7748. ACMD_DEF(feelreset),
  7749. ACMD_DEF(auction),
  7750. ACMD_DEF(mail),
  7751. ACMD_DEF2("noks", ksprotection),
  7752. ACMD_DEF(allowks),
  7753. ACMD_DEF(cash),
  7754. ACMD_DEF2("points", cash),
  7755. ACMD_DEF(agitstart2),
  7756. ACMD_DEF(agitend2),
  7757. ACMD_DEF2("skreset", resetskill),
  7758. ACMD_DEF2("streset", resetstat),
  7759. ACMD_DEF2("storagelist", itemlist),
  7760. ACMD_DEF2("cartlist", itemlist),
  7761. ACMD_DEF2("itemlist", itemlist),
  7762. ACMD_DEF(stats),
  7763. ACMD_DEF(delitem),
  7764. ACMD_DEF(charcommands),
  7765. ACMD_DEF(font),
  7766. ACMD_DEF(accinfo),
  7767. ACMD_DEF(set),
  7768. ACMD_DEF(reloadquestdb),
  7769. ACMD_DEF(undisguiseguild),
  7770. ACMD_DEF(disguiseguild),
  7771. ACMD_DEF(sizeall),
  7772. ACMD_DEF(sizeguild),
  7773. ACMD_DEF(addperm),
  7774. ACMD_DEF2("rmvperm", addperm),
  7775. ACMD_DEF(unloadnpcfile),
  7776. ACMD_DEF(cart),
  7777. ACMD_DEF(mount2)
  7778. };
  7779. AtCommandInfo* atcommand;
  7780. int i;
  7781. for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
  7782. if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK
  7783. ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
  7784. continue;
  7785. }
  7786. CREATE(atcommand, AtCommandInfo, 1);
  7787. safestrncpy(atcommand->command, atcommand_base[i].command, sizeof(atcommand->command));
  7788. atcommand->func = atcommand_base[i].func;
  7789. strdb_put(atcommand_db, atcommand->command, atcommand);
  7790. }
  7791. return;
  7792. }
  7793. /*==========================================
  7794. * Command lookup functions
  7795. *------------------------------------------*/
  7796. bool atcommand_exists(const char* name)
  7797. {
  7798. return strdb_exists(atcommand_db, name);
  7799. }
  7800. static AtCommandInfo* get_atcommandinfo_byname(const char *name)
  7801. {
  7802. if (strdb_exists(atcommand_db, name))
  7803. return (AtCommandInfo*)strdb_get(atcommand_db, name);
  7804. return NULL;
  7805. }
  7806. static const char* atcommand_checkalias(const char *aliasname)
  7807. {
  7808. AliasInfo *alias_info = NULL;
  7809. if ((alias_info = (AliasInfo*)strdb_get(atcommand_alias_db, aliasname)) != NULL)
  7810. return alias_info->command->command;
  7811. return aliasname;
  7812. }
  7813. /// AtCommand suggestion
  7814. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand) {
  7815. DBIterator* atcommand_iter;
  7816. DBIterator* alias_iter;
  7817. AtCommandInfo* command_info = NULL;
  7818. AliasInfo* alias_info = NULL;
  7819. AtCommandType type = atcommand ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND;
  7820. char* full_match[MAX_SUGGESTIONS];
  7821. char* suggestions[MAX_SUGGESTIONS];
  7822. char* match;
  7823. int prefix_count = 0, full_count = 0;
  7824. bool can_use;
  7825. if (!battle_config.atcommand_suggestions_enabled)
  7826. return;
  7827. atcommand_iter = db_iterator(atcommand_db);
  7828. alias_iter = db_iterator(atcommand_alias_db);
  7829. // Build the matches
  7830. for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter); command_info = dbi_next(atcommand_iter)) {
  7831. match = strstr(command_info->command, name);
  7832. can_use = pc_can_use_command(sd, command_info->command, type);
  7833. if ( prefix_count < MAX_SUGGESTIONS && match == command_info->command && can_use ) {
  7834. suggestions[prefix_count] = command_info->command;
  7835. ++prefix_count;
  7836. }
  7837. if ( full_count < MAX_SUGGESTIONS && match != NULL && match != command_info->command && can_use ) {
  7838. full_match[full_count] = command_info->command;
  7839. ++full_count;
  7840. }
  7841. }
  7842. for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter); alias_info = dbi_next(alias_iter)) {
  7843. match = strstr(alias_info->alias, name);
  7844. can_use = pc_can_use_command(sd, alias_info->command->command, type);
  7845. if ( prefix_count < MAX_SUGGESTIONS && match == alias_info->alias && can_use) {
  7846. suggestions[prefix_count] = alias_info->alias;
  7847. ++prefix_count;
  7848. }
  7849. if ( full_count < MAX_SUGGESTIONS && match != NULL && match != alias_info->alias && can_use ) {
  7850. full_match[full_count] = alias_info->alias;
  7851. ++full_count;
  7852. }
  7853. }
  7854. if ((full_count+prefix_count) > 0) {
  7855. char buffer[512];
  7856. int i;
  7857. // Merge full match and prefix match results
  7858. if (prefix_count < MAX_SUGGESTIONS) {
  7859. memmove(&suggestions[prefix_count], full_match, sizeof(char*) * (MAX_SUGGESTIONS-prefix_count));
  7860. prefix_count = min(prefix_count+full_count, MAX_SUGGESTIONS);
  7861. }
  7862. // Build the suggestion string
  7863. strcpy(buffer, msg_txt(205));
  7864. strcat(buffer,"\n");
  7865. for(i=0; i < prefix_count; ++i) {
  7866. strcat(buffer,suggestions[i]);
  7867. strcat(buffer," ");
  7868. }
  7869. clif_displaymessage(sd->fd, buffer);
  7870. }
  7871. dbi_destroy(atcommand_iter);
  7872. dbi_destroy(alias_iter);
  7873. }
  7874. /// Executes an at-command.
  7875. bool is_atcommand(const int fd, struct map_session_data* sd, const char* message, int type)
  7876. {
  7877. char charname[NAME_LENGTH], params[100];
  7878. char charname2[NAME_LENGTH], params2[100];
  7879. char command[100];
  7880. char output[CHAT_SIZE_MAX];
  7881. //Reconstructed message
  7882. char atcmd_msg[CHAT_SIZE_MAX];
  7883. TBL_PC * ssd = NULL; //sd for target
  7884. AtCommandInfo * info;
  7885. nullpo_retr(false, sd);
  7886. //Shouldn't happen
  7887. if ( !message || !*message )
  7888. return false;
  7889. //Block NOCHAT but do not display it as a normal message
  7890. if ( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCOMMAND )
  7891. return true;
  7892. // skip 10/11-langtype's codepage indicator, if detected
  7893. if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand_symbol || message[3] == charcommand_symbol) )
  7894. message += 3;
  7895. //Should display as a normal message
  7896. if ( *message != atcommand_symbol && *message != charcommand_symbol )
  7897. return false;
  7898. // type value 0 = server invoked: bypass restrictions
  7899. // 1 = player invoked
  7900. if ( type == 1) {
  7901. //Commands are disabled on maps flagged as 'nocommand'
  7902. if ( map[sd->bl.m].nocommand && pc_get_group_level(sd) < map[sd->bl.m].nocommand ) {
  7903. clif_displaymessage(fd, msg_txt(143));
  7904. return false;
  7905. }
  7906. }
  7907. if (*message == charcommand_symbol) {
  7908. do {
  7909. int x, y, z;
  7910. //Checks to see if #command has a name or a name + parameters.
  7911. x = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params);
  7912. y = sscanf(message, "%99s %23s %99[^\n]", command, charname2, params2);
  7913. //z always has the value of the scan that was successful
  7914. z = ( x > 1 ) ? x : y;
  7915. //#command + name means the sufficient target was used and anything else after
  7916. //can be looked at by the actual command function since most scan to see if the
  7917. //right parameters are used.
  7918. if ( x > 2 ) {
  7919. sprintf(atcmd_msg, "%s %s", command, params);
  7920. break;
  7921. }
  7922. else if ( y > 2 ) {
  7923. sprintf(atcmd_msg, "%s %s", command, params2);
  7924. break;
  7925. }
  7926. //Regardless of what style the #command is used, if it's correct, it will always have
  7927. //this value if there is no parameter. Send it as just the #command
  7928. else if ( z == 2 ) {
  7929. sprintf(atcmd_msg, "%s", command);
  7930. break;
  7931. }
  7932. if( !pc_get_group_level(sd) ) {
  7933. if( x >= 1 || y >= 1 ) { /* we have command */
  7934. info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  7935. if( !info || info->char_groups[sd->group_pos] == 0 ) /* if we can't use or doesn't exist: don't even display the command failed message */
  7936. return false;
  7937. } else
  7938. return false;/* display as normal message */
  7939. }
  7940. sprintf(output, msg_txt(1388), charcommand_symbol); // Charcommand failed (usage: %c<command> <char name> <parameters>).
  7941. clif_displaymessage(fd, output);
  7942. return true;
  7943. } while(0);
  7944. }
  7945. else if (*message == atcommand_symbol) {
  7946. //atcmd_msg is constructed above differently for charcommands
  7947. //it's copied from message if not a charcommand so it can
  7948. //pass through the rest of the code compatible with both symbols
  7949. sprintf(atcmd_msg, "%s", message);
  7950. }
  7951. //Clearing these to be used once more.
  7952. memset(command, '\0', sizeof(command));
  7953. memset(params, '\0', sizeof(params));
  7954. //check to see if any params exist within this command
  7955. if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 )
  7956. params[0] = '\0';
  7957. // @commands (script based)
  7958. if(type == 1 && atcmd_binding_count > 0) {
  7959. struct atcmd_binding_data * binding;
  7960. // Check if the command initiated is a character command
  7961. if (*message == charcommand_symbol &&
  7962. (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  7963. sprintf(output, msg_txt(1389), command); // %s failed. Player not found.
  7964. clif_displaymessage(fd, output);
  7965. return true;
  7966. }
  7967. // Get atcommand binding
  7968. binding = get_atcommandbind_byname(command);
  7969. // Check if the binding isn't NULL and there is a NPC event, level of usage met, et cetera
  7970. if( binding != NULL && binding->npc_event[0] &&
  7971. ((*atcmd_msg == atcommand_symbol && pc_get_group_level(sd) >= binding->level) ||
  7972. (*atcmd_msg == charcommand_symbol && pc_get_group_level(sd) >= binding->level2)))
  7973. {
  7974. // Check if self or character invoking; if self == character invoked, then self invoke.
  7975. bool invokeFlag = ((*atcmd_msg == atcommand_symbol) ? 1 : 0);
  7976. npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
  7977. return true;
  7978. }
  7979. }
  7980. //Grab the command information and check for the proper GM level required to use it or if the command exists
  7981. info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  7982. if (info == NULL) {
  7983. if( pc_get_group_level(sd) ) { // TODO: remove or replace with proper permission
  7984. sprintf(output, msg_txt(153), command); // "%s is Unknown Command."
  7985. clif_displaymessage(fd, output);
  7986. atcommand_get_suggestions(sd, command + 1, *message == atcommand_symbol);
  7987. return true;
  7988. } else
  7989. return false;
  7990. }
  7991. // type == 1 : player invoked
  7992. if (type == 1) {
  7993. if ((*command == atcommand_symbol && info->at_groups[sd->group_pos] == 0) ||
  7994. (*command == charcommand_symbol && info->char_groups[sd->group_pos] == 0) ) {
  7995. return false;
  7996. }
  7997. if( pc_isdead(sd) && pc_has_permission(sd,PC_PERM_DISABLE_CMD_DEAD) ) {
  7998. clif_displaymessage(fd, msg_txt(1393)); // You can't use commands while dead
  7999. return true;
  8000. }
  8001. }
  8002. // Check if target is valid only if confirmed that player can use command.
  8003. if (*message == charcommand_symbol &&
  8004. (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  8005. sprintf(output, msg_txt(1389), command); // %s failed. Player not found.
  8006. clif_displaymessage(fd, output);
  8007. return true;
  8008. }
  8009. //Attempt to use the command
  8010. if ( (info->func(fd, (*atcmd_msg == atcommand_symbol) ? sd : ssd, command, params) != 0) )
  8011. {
  8012. sprintf(output,msg_txt(154), command); // %s failed.
  8013. clif_displaymessage(fd, output);
  8014. return true;
  8015. }
  8016. //Log only if successful.
  8017. if ( *atcmd_msg == atcommand_symbol )
  8018. log_atcommand(sd, atcmd_msg);
  8019. else if ( *atcmd_msg == charcommand_symbol )
  8020. log_atcommand(sd, message);
  8021. return true;
  8022. }
  8023. /*==========================================
  8024. *
  8025. *------------------------------------------*/
  8026. static void atcommand_config_read(const char* config_filename)
  8027. {
  8028. config_setting_t *aliases = NULL, *help = NULL;
  8029. const char *symbol = NULL;
  8030. int num_aliases = 0;
  8031. if (conf_read_file(&atcommand_config, config_filename))
  8032. return;
  8033. // Command symbols
  8034. if (config_lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) {
  8035. if (ISPRINT(*symbol) && // no control characters
  8036. *symbol != '/' && // symbol of client commands
  8037. *symbol != '%' && // symbol of party chat
  8038. *symbol != '$' && // symbol of guild chat
  8039. *symbol != charcommand_symbol)
  8040. atcommand_symbol = *symbol;
  8041. }
  8042. if (config_lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) {
  8043. if (ISPRINT(*symbol) && // no control characters
  8044. *symbol != '/' && // symbol of client commands
  8045. *symbol != '%' && // symbol of party chat
  8046. *symbol != '$' && // symbol of guild chat
  8047. *symbol != atcommand_symbol)
  8048. charcommand_symbol = *symbol;
  8049. }
  8050. // Command aliases
  8051. aliases = config_lookup(&atcommand_config, "aliases");
  8052. if (aliases != NULL) {
  8053. int i = 0;
  8054. int count = config_setting_length(aliases);
  8055. for (i = 0; i < count; ++i) {
  8056. config_setting_t *command = NULL;
  8057. const char *commandname = NULL;
  8058. int j = 0, alias_count = 0;
  8059. AtCommandInfo *commandinfo = NULL;
  8060. command = config_setting_get_elem(aliases, i);
  8061. if (config_setting_type(command) != CONFIG_TYPE_ARRAY)
  8062. continue;
  8063. commandname = config_setting_name(command);
  8064. if (!atcommand_exists(commandname)) {
  8065. ShowConfigWarning(command, "atcommand_config_read: can not set alias for non-existent command %s", commandname);
  8066. continue;
  8067. }
  8068. commandinfo = get_atcommandinfo_byname(commandname);
  8069. alias_count = config_setting_length(command);
  8070. for (j = 0; j < alias_count; ++j) {
  8071. const char *alias = config_setting_get_string_elem(command, j);
  8072. if (alias != NULL) {
  8073. AliasInfo *alias_info;
  8074. if (strdb_exists(atcommand_alias_db, alias)) {
  8075. ShowConfigWarning(command, "atcommand_config_read: alias %s already exists", alias);
  8076. continue;
  8077. }
  8078. CREATE(alias_info, AliasInfo, 1);
  8079. alias_info->command = commandinfo;
  8080. safestrncpy(alias_info->alias, alias, sizeof(alias_info->alias));
  8081. strdb_put(atcommand_alias_db, alias, alias_info);
  8082. ++num_aliases;
  8083. }
  8084. }
  8085. }
  8086. }
  8087. // Commands help
  8088. // We only check if all commands exist
  8089. help = config_lookup(&atcommand_config, "help");
  8090. if (help != NULL) {
  8091. int count = config_setting_length(help);
  8092. int i;
  8093. for (i = 0; i < count; ++i) {
  8094. config_setting_t *command = NULL;
  8095. const char *commandname = NULL;
  8096. command = config_setting_get_elem(help, i);
  8097. commandname = config_setting_name(command);
  8098. if (!atcommand_exists(commandname))
  8099. ShowConfigWarning(command, "atcommand_config_read: command %s does not exist", commandname);
  8100. }
  8101. }
  8102. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename);
  8103. return;
  8104. }
  8105. void atcommand_db_load_groups(int* group_ids) {
  8106. DBIterator *iter = db_iterator(atcommand_db);
  8107. AtCommandInfo* cmd;
  8108. int i;
  8109. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8110. cmd->at_groups = aMalloc( pc_group_max * sizeof(char) );
  8111. cmd->char_groups = aMalloc( pc_group_max * sizeof(char) );
  8112. for(i = 0; i < pc_group_max; i++) {
  8113. if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_ATCOMMAND ) )
  8114. cmd->at_groups[i] = 1;
  8115. else
  8116. cmd->at_groups[i] = 0;
  8117. if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_CHARCOMMAND ) )
  8118. cmd->char_groups[i] = 1;
  8119. else
  8120. cmd->char_groups[i] = 0;
  8121. }
  8122. }
  8123. dbi_destroy(iter);
  8124. return;
  8125. }
  8126. void atcommand_db_clear(void) {
  8127. if (atcommand_db != NULL) {
  8128. DBIterator *iter = db_iterator(atcommand_db);
  8129. AtCommandInfo* cmd;
  8130. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8131. aFree(cmd->at_groups);
  8132. aFree(cmd->char_groups);
  8133. }
  8134. dbi_destroy(iter);
  8135. db_destroy(atcommand_db);
  8136. }
  8137. if (atcommand_alias_db != NULL)
  8138. db_destroy(atcommand_alias_db);
  8139. config_destroy(&atcommand_config);
  8140. }
  8141. void atcommand_doload(void) {
  8142. atcommand_db_clear();
  8143. atcommand_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  8144. atcommand_alias_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  8145. atcommand_basecommands(); //fills initial atcommand_db with known commands
  8146. atcommand_config_read(ATCOMMAND_CONF_FILENAME);
  8147. }
  8148. void do_init_atcommand(void) {
  8149. atcommand_doload();
  8150. }
  8151. void do_final_atcommand(void) {
  8152. atcommand_db_clear();
  8153. }