atcommand.c 288 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816
  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. typedef struct AtCommandInfo AtCommandInfo;
  51. typedef struct AliasInfo AliasInfo;
  52. int atcmd_binding_count = 0;
  53. struct AtCommandInfo {
  54. char command[ATCOMMAND_LENGTH];
  55. AtCommandFunc func;
  56. char* at_groups;/* quick @commands "can-use" lookup */
  57. char* char_groups;/* quick @charcommands "can-use" lookup */
  58. };
  59. struct AliasInfo {
  60. AtCommandInfo *command;
  61. char alias[ATCOMMAND_LENGTH];
  62. };
  63. char atcommand_symbol = '@'; // first char of the commands
  64. char charcommand_symbol = '#';
  65. static DBMap* atcommand_db = NULL; //name -> AtCommandInfo
  66. static DBMap* atcommand_alias_db = NULL; //alias -> AtCommandInfo
  67. static config_t atcommand_config;
  68. static char atcmd_output[CHAT_SIZE_MAX];
  69. static char atcmd_player_name[NAME_LENGTH];
  70. static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help
  71. static const char* atcommand_checkalias(const char *aliasname); // @help
  72. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help
  73. // @commands (script-based)
  74. struct atcmd_binding_data* get_atcommandbind_byname(const char* name) {
  75. int i = 0;
  76. if( *name == atcommand_symbol || *name == charcommand_symbol )
  77. name++; // for backwards compatibility
  78. ARR_FIND( 0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, name) == 0 );
  79. return ( i < atcmd_binding_count ) ? atcmd_binding[i] : NULL;
  80. }
  81. /**
  82. * retrieves the help string associated with a given command.
  83. *
  84. * @param name the name of the command to retrieve help information for
  85. * @return the string associated with the command, or NULL
  86. */
  87. static const char* atcommand_help_string(const char* command)
  88. {
  89. const char* str = NULL;
  90. config_setting_t* info;
  91. if( *command == atcommand_symbol || *command == charcommand_symbol )
  92. {// remove the prefix symbol for the raw name of the command
  93. command ++;
  94. }
  95. // convert alias to the real command name
  96. command = atcommand_checkalias(command);
  97. // attept to find the first default help command
  98. info = config_lookup(&atcommand_config, "help");
  99. if( info == NULL )
  100. {// failed to find the help property in the configuration file
  101. return NULL;
  102. }
  103. if( !config_setting_lookup_string( info, command, &str ) )
  104. {// failed to find the matching help string
  105. return NULL;
  106. }
  107. // push the result from the method
  108. return str;
  109. }
  110. /*==========================================
  111. * @send (used for testing packet sends from the client)
  112. *------------------------------------------*/
  113. ACMD_FUNC(send)
  114. {
  115. int len=0,off,end,type;
  116. long num;
  117. // read message type as hex number (without the 0x)
  118. if(!message || !*message ||
  119. !((sscanf(message, "len %x", &type)==1 && (len=1))
  120. || sscanf(message, "%x", &type)==1) )
  121. {
  122. int i;
  123. for (i = 900; i <= 903; ++i)
  124. clif_displaymessage(fd, msg_txt(sd,i));
  125. return -1;
  126. }
  127. #define PARSE_ERROR(error,p) \
  128. {\
  129. clif_displaymessage(fd, (error));\
  130. sprintf(atcmd_output, ">%s", (p));\
  131. clif_displaymessage(fd, atcmd_output);\
  132. }
  133. //define PARSE_ERROR
  134. #define CHECK_EOS(p) \
  135. if(*(p) == 0){\
  136. clif_displaymessage(fd, "Unexpected end of string");\
  137. return -1;\
  138. }
  139. //define CHECK_EOS
  140. #define SKIP_VALUE(p) \
  141. {\
  142. while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
  143. while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
  144. }
  145. //define SKIP_VALUE
  146. #define GET_VALUE(p,num) \
  147. {\
  148. if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
  149. PARSE_ERROR("Invalid number in:",(p));\
  150. return -1;\
  151. }\
  152. }
  153. //define GET_VALUE
  154. if (type > 0 && type < MAX_PACKET_DB) {
  155. if(len)
  156. {// show packet length
  157. sprintf(atcmd_output, msg_txt(sd,904), type, packet_db[sd->packet_ver][type].len); // Packet 0x%x length: %d
  158. clif_displaymessage(fd, atcmd_output);
  159. return 0;
  160. }
  161. len=packet_db[sd->packet_ver][type].len;
  162. off=2;
  163. if(len == 0)
  164. {// unknown packet - ERROR
  165. sprintf(atcmd_output, msg_txt(sd,905), type); // Unknown packet: 0x%x
  166. clif_displaymessage(fd, atcmd_output);
  167. return -1;
  168. } else if(len == -1)
  169. {// dynamic packet
  170. len=SHRT_MAX-4; // maximum length
  171. off=4;
  172. }
  173. WFIFOHEAD(fd, len);
  174. WFIFOW(fd,0)=TOW(type);
  175. // parse packet contents
  176. SKIP_VALUE(message);
  177. while(*message != 0 && off < len){
  178. if(ISDIGIT(*message) || *message == '-' || *message == '+')
  179. {// default (byte)
  180. GET_VALUE(message,num);
  181. WFIFOB(fd,off)=TOB(num);
  182. ++off;
  183. } else if(TOUPPER(*message) == 'B')
  184. {// byte
  185. ++message;
  186. GET_VALUE(message,num);
  187. WFIFOB(fd,off)=TOB(num);
  188. ++off;
  189. } else if(TOUPPER(*message) == 'W')
  190. {// word (2 bytes)
  191. ++message;
  192. GET_VALUE(message,num);
  193. WFIFOW(fd,off)=TOW(num);
  194. off+=2;
  195. } else if(TOUPPER(*message) == 'L')
  196. {// long word (4 bytes)
  197. ++message;
  198. GET_VALUE(message,num);
  199. WFIFOL(fd,off)=TOL(num);
  200. off+=4;
  201. } else if(TOUPPER(*message) == 'S')
  202. {// string - escapes are valid
  203. // get string length - num <= 0 means not fixed length (default)
  204. ++message;
  205. if(*message == '"'){
  206. num=0;
  207. } else {
  208. GET_VALUE(message,num);
  209. while(*message != '"')
  210. {// find start of string
  211. if(*message == 0 || ISSPACE(*message)){
  212. PARSE_ERROR(msg_txt(sd,906),message); // Not a string:
  213. return -1;
  214. }
  215. ++message;
  216. }
  217. }
  218. // parse string
  219. ++message;
  220. CHECK_EOS(message);
  221. end=(num<=0? 0: min(off+((int)num),len));
  222. for(; *message != '"' && (off < end || end == 0); ++off){
  223. if(*message == '\\'){
  224. ++message;
  225. CHECK_EOS(message);
  226. switch(*message){
  227. case 'a': num=0x07; break; // Bell
  228. case 'b': num=0x08; break; // Backspace
  229. case 't': num=0x09; break; // Horizontal tab
  230. case 'n': num=0x0A; break; // Line feed
  231. case 'v': num=0x0B; break; // Vertical tab
  232. case 'f': num=0x0C; break; // Form feed
  233. case 'r': num=0x0D; break; // Carriage return
  234. case 'e': num=0x1B; break; // Escape
  235. default: num=*message; break;
  236. case 'x': // Hexadecimal
  237. {
  238. ++message;
  239. CHECK_EOS(message);
  240. if(!ISXDIGIT(*message)){
  241. PARSE_ERROR(msg_txt(sd,907),message); // Not a hexadecimal digit:
  242. return -1;
  243. }
  244. num=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  245. if(ISXDIGIT(*message)){
  246. ++message;
  247. CHECK_EOS(message);
  248. num<<=8;
  249. num+=(ISDIGIT(*message)?*message-'0':TOLOWER(*message)-'a'+10);
  250. }
  251. WFIFOB(fd,off)=TOB(num);
  252. ++message;
  253. CHECK_EOS(message);
  254. continue;
  255. }
  256. case '0':
  257. case '1':
  258. case '2':
  259. case '3':
  260. case '4':
  261. case '5':
  262. case '6':
  263. case '7': // Octal
  264. {
  265. num=*message-'0'; // 1st octal digit
  266. ++message;
  267. CHECK_EOS(message);
  268. if(ISDIGIT(*message) && *message < '8'){
  269. num<<=3;
  270. num+=*message-'0'; // 2nd octal digit
  271. ++message;
  272. CHECK_EOS(message);
  273. if(ISDIGIT(*message) && *message < '8'){
  274. num<<=3;
  275. num+=*message-'0'; // 3rd octal digit
  276. ++message;
  277. CHECK_EOS(message);
  278. }
  279. }
  280. WFIFOB(fd,off)=TOB(num);
  281. continue;
  282. }
  283. }
  284. } else
  285. num=*message;
  286. WFIFOB(fd,off)=TOB(num);
  287. ++message;
  288. CHECK_EOS(message);
  289. }//for
  290. while(*message != '"')
  291. {// ignore extra characters
  292. ++message;
  293. CHECK_EOS(message);
  294. }
  295. // terminate the string
  296. if(off < end)
  297. {// fill the rest with 0's
  298. memset(WFIFOP(fd,off),0,end-off);
  299. off=end;
  300. }
  301. } else
  302. {// unknown
  303. PARSE_ERROR(msg_txt(sd,908),message); // Unknown type of value in:
  304. return -1;
  305. }
  306. SKIP_VALUE(message);
  307. }
  308. if(packet_db[sd->packet_ver][type].len == -1)
  309. {// send dynamic packet
  310. WFIFOW(fd,2)=TOW(off);
  311. WFIFOSET(fd,off);
  312. } else
  313. {// send static packet
  314. if(off < len)
  315. memset(WFIFOP(fd,off),0,len-off);
  316. WFIFOSET(fd,len);
  317. }
  318. } else {
  319. clif_displaymessage(fd, msg_txt(sd,259)); // Invalid packet
  320. return -1;
  321. }
  322. sprintf (atcmd_output, msg_txt(sd,258), type, type); // Sent packet 0x%x (%d)
  323. clif_displaymessage(fd, atcmd_output);
  324. return 0;
  325. #undef PARSE_ERROR
  326. #undef CHECK_EOS
  327. #undef SKIP_VALUE
  328. #undef GET_VALUE
  329. }
  330. /*==========================================
  331. * @rura, @warp, @mapmove
  332. *------------------------------------------*/
  333. ACMD_FUNC(mapmove)
  334. {
  335. char map_name[MAP_NAME_LENGTH_EXT];
  336. unsigned short mapindex;
  337. short x = 0, y = 0;
  338. int16 m = -1;
  339. nullpo_retr(-1, sd);
  340. memset(map_name, '\0', sizeof(map_name));
  341. if (!message || !*message ||
  342. (sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 &&
  343. sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) {
  344. clif_displaymessage(fd, msg_txt(sd,909)); // Please enter a map (usage: @warp/@rura/@mapmove <mapname> <x> <y>).
  345. return -1;
  346. }
  347. mapindex = mapindex_name2id(map_name);
  348. if (mapindex)
  349. m = map_mapindex2mapid(mapindex);
  350. if (!mapindex) { // m < 0 means on different server! [Kevin]
  351. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  352. return -1;
  353. }
  354. if ((x || y) && map_getcell(m, x, y, CELL_CHKNOPASS))
  355. { //This is to prevent the pc_setpos call from printing an error.
  356. clif_displaymessage(fd, msg_txt(sd,2));
  357. if (!map_search_freecell(NULL, m, &x, &y, 10, 10, 1))
  358. x = y = 0; //Invalid cell, use random spot.
  359. }
  360. if (map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  361. clif_displaymessage(fd, msg_txt(sd,247));
  362. return -1;
  363. }
  364. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  365. clif_displaymessage(fd, msg_txt(sd,248));
  366. return -1;
  367. }
  368. if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) {
  369. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  370. return -1;
  371. }
  372. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  373. return 0;
  374. }
  375. /*==========================================
  376. * Displays where a character is. Corrected version by Silent. [Skotlex]
  377. *------------------------------------------*/
  378. ACMD_FUNC(where)
  379. {
  380. struct map_session_data* pl_sd;
  381. nullpo_retr(-1, sd);
  382. memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  383. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  384. clif_displaymessage(fd, msg_txt(sd,910)); // Please enter a player name (usage: @where <char name>).
  385. return -1;
  386. }
  387. pl_sd = map_nick2sd(atcmd_player_name);
  388. if (pl_sd == NULL ||
  389. strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 ||
  390. (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))
  391. ) {
  392. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  393. return -1;
  394. }
  395. 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);
  396. clif_displaymessage(fd, atcmd_output);
  397. return 0;
  398. }
  399. /*==========================================
  400. *
  401. *------------------------------------------*/
  402. ACMD_FUNC(jumpto)
  403. {
  404. struct map_session_data *pl_sd = NULL;
  405. nullpo_retr(-1, sd);
  406. if (!message || !*message) {
  407. clif_displaymessage(fd, msg_txt(sd,911)); // Please enter a player name (usage: @jumpto/@warpto/@goto <char name/ID>).
  408. return -1;
  409. }
  410. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  411. {
  412. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  413. return -1;
  414. }
  415. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  416. {
  417. clif_displaymessage(fd, msg_txt(sd,247)); // You are not authorized to warp to this map.
  418. return -1;
  419. }
  420. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  421. {
  422. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  423. return -1;
  424. }
  425. if( pc_isdead(sd) )
  426. {
  427. clif_displaymessage(fd, msg_txt(sd,664));
  428. return -1;
  429. }
  430. pc_setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  431. sprintf(atcmd_output, msg_txt(sd,4), pl_sd->status.name); // Jumped to %s
  432. clif_displaymessage(fd, atcmd_output);
  433. return 0;
  434. }
  435. /*==========================================
  436. *
  437. *------------------------------------------*/
  438. ACMD_FUNC(jump)
  439. {
  440. short x = 0, y = 0;
  441. nullpo_retr(-1, sd);
  442. memset(atcmd_output, '\0', sizeof(atcmd_output));
  443. sscanf(message, "%hd %hd", &x, &y);
  444. if (map[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  445. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  446. return -1;
  447. }
  448. if( pc_isdead(sd) )
  449. {
  450. clif_displaymessage(fd, msg_txt(sd,664));
  451. return -1;
  452. }
  453. if ((x || y) && map_getcell(sd->bl.m, x, y, CELL_CHKNOPASS))
  454. { //This is to prevent the pc_setpos call from printing an error.
  455. clif_displaymessage(fd, msg_txt(sd,2));
  456. if (!map_search_freecell(NULL, sd->bl.m, &x, &y, 10, 10, 1))
  457. x = y = 0; //Invalid cell, use random spot.
  458. }
  459. pc_setpos(sd, sd->mapindex, x, y, CLR_TELEPORT);
  460. sprintf(atcmd_output, msg_txt(sd,5), sd->bl.x, sd->bl.y); // Jumped to %d %d
  461. clif_displaymessage(fd, atcmd_output);
  462. return 0;
  463. }
  464. /*==========================================
  465. * Display list of online characters with
  466. * various info.
  467. *------------------------------------------*/
  468. ACMD_FUNC(who)
  469. {
  470. struct map_session_data *pl_sd = NULL;
  471. struct s_mapiterator *iter = NULL;
  472. char map_name[MAP_NAME_LENGTH_EXT] = "";
  473. char player_name[NAME_LENGTH] = "";
  474. int count = 0;
  475. int level = 0;
  476. StringBuf buf;
  477. /**
  478. * 1 = @who : Player name, [Title], [Party name], [Guild name]
  479. * 2 = @who2 : Player name, [Title], BLvl, JLvl, Job
  480. * 3 = @who3 : [CID/AID] Player name [Title], Map, X, Y
  481. */
  482. int display_type = 1;
  483. int map_id = -1;
  484. nullpo_retr(-1, sd);
  485. if (strstr(command, "map") != NULL) {
  486. if (sscanf(message, "%15s %23s", map_name, player_name) < 1 || (map_id = map_mapname2mapid(map_name)) < 0)
  487. map_id = sd->bl.m;
  488. } else {
  489. sscanf(message, "%23s", player_name);
  490. }
  491. if (strstr(command, "2") != NULL)
  492. display_type = 2;
  493. else if (strstr(command, "3") != NULL)
  494. display_type = 3;
  495. level = pc_get_group_level(sd);
  496. StringBuf_Init(&buf);
  497. iter = mapit_getallusers();
  498. for (pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter)) {
  499. 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
  500. if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive
  501. || (map_id >= 0 && pl_sd->bl.m != map_id))
  502. continue;
  503. switch (display_type) {
  504. case 2: {
  505. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  506. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  507. StringBuf_Printf(&buf, msg_txt(sd,344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  508. StringBuf_Printf(&buf, msg_txt(sd,347), pl_sd->status.base_level, pl_sd->status.job_level,
  509. job_name(pl_sd->status.class_)); // "| Lv:%d/%d | Job: %s"
  510. break;
  511. }
  512. case 3: {
  513. if (pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID))
  514. StringBuf_Printf(&buf, msg_txt(sd,912), pl_sd->status.char_id, pl_sd->status.account_id); // "(CID:%d/AID:%d) "
  515. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  516. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  517. StringBuf_Printf(&buf, msg_txt(sd,344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  518. StringBuf_Printf(&buf, msg_txt(sd,348), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); // "| Location: %s %d %d"
  519. break;
  520. }
  521. default: {
  522. struct party_data *p = party_search(pl_sd->status.party_id);
  523. struct guild *g = pl_sd->guild;
  524. StringBuf_Printf(&buf, msg_txt(sd,343), pl_sd->status.name); // "Name: %s "
  525. if (pc_get_group_id(pl_sd) > 0) // Player title, if exists
  526. StringBuf_Printf(&buf, msg_txt(sd,344), pc_group_id2name(pc_get_group_id(pl_sd))); // "(%s) "
  527. if (p != NULL)
  528. StringBuf_Printf(&buf, msg_txt(sd,345), p->party.name); // " | Party: '%s'"
  529. if (g != NULL)
  530. StringBuf_Printf(&buf, msg_txt(sd,346), g->name); // " | Guild: '%s'"
  531. break;
  532. }
  533. }
  534. clif_displaymessage(fd, StringBuf_Value(&buf));
  535. StringBuf_Clear(&buf);
  536. count++;
  537. }
  538. }
  539. mapit_free(iter);
  540. if (map_id < 0) {
  541. if (count == 0)
  542. StringBuf_Printf(&buf, msg_txt(sd,28)); // No player found.
  543. else if (count == 1)
  544. StringBuf_Printf(&buf, msg_txt(sd,29)); // 1 player found.
  545. else
  546. StringBuf_Printf(&buf, msg_txt(sd,30), count); // %d players found.
  547. } else {
  548. if (count == 0)
  549. StringBuf_Printf(&buf, msg_txt(sd,54), map[map_id].name); // No player found in map '%s'.
  550. else if (count == 1)
  551. StringBuf_Printf(&buf, msg_txt(sd,55), map[map_id].name); // 1 player found in map '%s'.
  552. else
  553. StringBuf_Printf(&buf, msg_txt(sd,56), count, map[map_id].name); // %d players found in map '%s'.
  554. }
  555. clif_displaymessage(fd, StringBuf_Value(&buf));
  556. StringBuf_Destroy(&buf);
  557. return 0;
  558. }
  559. /*==========================================
  560. *
  561. *------------------------------------------*/
  562. ACMD_FUNC(whogm)
  563. {
  564. struct map_session_data* pl_sd;
  565. struct s_mapiterator* iter;
  566. int j, count;
  567. int pl_level, level;
  568. char match_text[CHAT_SIZE_MAX];
  569. char player_name[NAME_LENGTH];
  570. struct guild *g;
  571. struct party_data *p;
  572. nullpo_retr(-1, sd);
  573. memset(atcmd_output, '\0', sizeof(atcmd_output));
  574. memset(match_text, '\0', sizeof(match_text));
  575. memset(player_name, '\0', sizeof(player_name));
  576. if (sscanf(message, "%199[^\n]", match_text) < 1)
  577. strcpy(match_text, "");
  578. for (j = 0; match_text[j]; j++)
  579. match_text[j] = TOLOWER(match_text[j]);
  580. count = 0;
  581. level = pc_get_group_level(sd);
  582. iter = mapit_getallusers();
  583. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  584. {
  585. pl_level = pc_get_group_level(pl_sd);
  586. if (!pl_level)
  587. continue;
  588. if (match_text[0])
  589. {
  590. memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
  591. for (j = 0; player_name[j]; j++)
  592. player_name[j] = TOLOWER(player_name[j]);
  593. // search with no case sensitive
  594. if (strstr(player_name, match_text) == NULL)
  595. continue;
  596. }
  597. if (pl_level > level) {
  598. if (pl_sd->sc.option & OPTION_INVISIBLE)
  599. continue;
  600. sprintf(atcmd_output, msg_txt(sd,913), pl_sd->status.name); // Name: %s (GM)
  601. clif_displaymessage(fd, atcmd_output);
  602. count++;
  603. continue;
  604. }
  605. sprintf(atcmd_output, msg_txt(sd,914), // Name: %s (GM:%d) | Location: %s %d %d
  606. pl_sd->status.name, pl_level,
  607. mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
  608. clif_displaymessage(fd, atcmd_output);
  609. sprintf(atcmd_output, msg_txt(sd,915), // BLvl: %d | Job: %s (Lvl: %d)
  610. pl_sd->status.base_level,
  611. job_name(pl_sd->status.class_), pl_sd->status.job_level);
  612. clif_displaymessage(fd, atcmd_output);
  613. p = party_search(pl_sd->status.party_id);
  614. g = pl_sd->guild;
  615. sprintf(atcmd_output,msg_txt(sd,916), // Party: '%s' | Guild: '%s'
  616. p?p->party.name:msg_txt(sd,917), g?g->name:msg_txt(sd,917)); // None.
  617. clif_displaymessage(fd, atcmd_output);
  618. count++;
  619. }
  620. mapit_free(iter);
  621. if (count == 0)
  622. clif_displaymessage(fd, msg_txt(sd,150)); // No GM found.
  623. else if (count == 1)
  624. clif_displaymessage(fd, msg_txt(sd,151)); // 1 GM found.
  625. else {
  626. sprintf(atcmd_output, msg_txt(sd,152), count); // %d GMs found.
  627. clif_displaymessage(fd, atcmd_output);
  628. }
  629. return 0;
  630. }
  631. /*==========================================
  632. *
  633. *------------------------------------------*/
  634. ACMD_FUNC(save)
  635. {
  636. nullpo_retr(-1, sd);
  637. pc_setsavepoint(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  638. if (sd->status.pet_id > 0 && sd->pd)
  639. intif_save_petdata(sd->status.account_id, &sd->pd->pet);
  640. chrif_save(sd,0);
  641. clif_displaymessage(fd, msg_txt(sd,6)); // Your save point has been changed.
  642. return 0;
  643. }
  644. /*==========================================
  645. *
  646. *------------------------------------------*/
  647. ACMD_FUNC(load)
  648. {
  649. int16 m;
  650. nullpo_retr(-1, sd);
  651. m = map_mapindex2mapid(sd->status.save_point.map);
  652. if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  653. clif_displaymessage(fd, msg_txt(sd,249)); // You are not authorized to warp to your save map.
  654. return -1;
  655. }
  656. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  657. clif_displaymessage(fd, msg_txt(sd,248)); // You are not authorized to warp from your current map.
  658. return -1;
  659. }
  660. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_OUTSIGHT);
  661. clif_displaymessage(fd, msg_txt(sd,7)); // Warping to save point..
  662. return 0;
  663. }
  664. /*==========================================
  665. *
  666. *------------------------------------------*/
  667. ACMD_FUNC(speed)
  668. {
  669. int speed;
  670. nullpo_retr(-1, sd);
  671. memset(atcmd_output, '\0', sizeof(atcmd_output));
  672. if (!message || !*message || sscanf(message, "%d", &speed) < 1) {
  673. sprintf(atcmd_output, msg_txt(sd,918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>).
  674. clif_displaymessage(fd, atcmd_output);
  675. return -1;
  676. }
  677. if (speed < 0) {
  678. sd->base_status.speed = DEFAULT_WALK_SPEED;
  679. sd->state.permanent_speed = 0; // Remove lock when set back to default speed.
  680. } else {
  681. sd->base_status.speed = cap_value(speed, MIN_WALK_SPEED, MAX_WALK_SPEED);
  682. sd->state.permanent_speed = 1; // Set lock when set to non-default speed.
  683. }
  684. status_calc_bl(&sd->bl, SCB_SPEED);
  685. clif_displaymessage(fd, msg_txt(sd,8)); // Speed changed.
  686. return 0;
  687. }
  688. /*==========================================
  689. *
  690. *------------------------------------------*/
  691. ACMD_FUNC(storage)
  692. {
  693. nullpo_retr(-1, sd);
  694. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag)
  695. return -1;
  696. if (storage_storageopen(sd) == 1)
  697. { //Already open.
  698. clif_displaymessage(fd, msg_txt(sd,250));
  699. return -1;
  700. }
  701. clif_displaymessage(fd, msg_txt(sd,919)); // Storage opened.
  702. return 0;
  703. }
  704. /*==========================================
  705. *
  706. *------------------------------------------*/
  707. ACMD_FUNC(guildstorage)
  708. {
  709. nullpo_retr(-1, sd);
  710. if (!sd->status.guild_id) {
  711. clif_displaymessage(fd, msg_txt(sd,252));
  712. return -1;
  713. }
  714. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  715. return -1;
  716. if (sd->state.storage_flag == 1) {
  717. clif_displaymessage(fd, msg_txt(sd,250));
  718. return -1;
  719. }
  720. if (sd->state.storage_flag == 2) {
  721. clif_displaymessage(fd, msg_txt(sd,251));
  722. return -1;
  723. }
  724. storage_guild_storageopen(sd);
  725. clif_displaymessage(fd, msg_txt(sd,920)); // Guild storage opened.
  726. return 0;
  727. }
  728. /*==========================================
  729. *
  730. *------------------------------------------*/
  731. ACMD_FUNC(option)
  732. {
  733. int param1 = 0, param2 = 0, param3 = 0;
  734. nullpo_retr(-1, sd);
  735. if (!message || !*message || sscanf(message, "%d %d %d", &param1, &param2, &param3) < 1 || param1 < 0 || param2 < 0 || param3 < 0)
  736. {// failed to match the parameters so inform the user of the options
  737. const char* text;
  738. // attempt to find the setting information for this command
  739. text = atcommand_help_string( command );
  740. // notify the user of the requirement to enter an option
  741. clif_displaymessage(fd, msg_txt(sd,921)); // Please enter at least one option.
  742. if( text )
  743. {// send the help text associated with this command
  744. clif_displaymessage( fd, text );
  745. }
  746. return -1;
  747. }
  748. sd->sc.opt1 = param1;
  749. sd->sc.opt2 = param2;
  750. pc_setoption(sd, param3);
  751. clif_displaymessage(fd, msg_txt(sd,9)); // Options changed.
  752. return 0;
  753. }
  754. /*==========================================
  755. *
  756. *------------------------------------------*/
  757. ACMD_FUNC(hide)
  758. {
  759. nullpo_retr(-1, sd);
  760. if (sd->sc.option & OPTION_INVISIBLE) {
  761. sd->sc.option &= ~OPTION_INVISIBLE;
  762. if (sd->disguise)
  763. status_set_viewdata(&sd->bl, sd->disguise);
  764. else
  765. status_set_viewdata(&sd->bl, sd->status.class_);
  766. clif_displaymessage(fd, msg_txt(sd,10)); // Invisible: Off
  767. // increment the number of pvp players on the map
  768. map[sd->bl.m].users_pvp++;
  769. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank )
  770. {// register the player for ranking calculations
  771. sd->pvp_timer = add_timer( gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0 );
  772. }
  773. //bugreport:2266
  774. map_foreachinmovearea(clif_insight, &sd->bl, AREA_SIZE, sd->bl.x, sd->bl.y, BL_ALL, &sd->bl);
  775. } else {
  776. sd->sc.option |= OPTION_INVISIBLE;
  777. sd->vd.class_ = INVISIBLE_CLASS;
  778. clif_displaymessage(fd, msg_txt(sd,11)); // Invisible: On
  779. // decrement the number of pvp players on the map
  780. map[sd->bl.m].users_pvp--;
  781. if( map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.pvp_nocalcrank && sd->pvp_timer != INVALID_TIMER )
  782. {// unregister the player for ranking
  783. delete_timer( sd->pvp_timer, pc_calc_pvprank_timer );
  784. sd->pvp_timer = INVALID_TIMER;
  785. }
  786. }
  787. clif_changeoption(&sd->bl);
  788. return 0;
  789. }
  790. /*==========================================
  791. * Changes a character's class
  792. *------------------------------------------*/
  793. ACMD_FUNC(jobchange)
  794. {
  795. int job = 0, upper = 0;
  796. const char* text;
  797. nullpo_retr(-1, sd);
  798. if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1) {
  799. int i;
  800. bool found = false;
  801. upper = 0;
  802. // Normal Jobs
  803. for( i = JOB_NOVICE; i < JOB_MAX_BASIC && !found; i++ ){
  804. if (strncmpi(message, job_name(i), 16) == 0) {
  805. job = i;
  806. found = true;
  807. }
  808. }
  809. // High Jobs, Babys and Third
  810. for( i = JOB_NOVICE_HIGH; i < JOB_MAX && !found; i++ ){
  811. if (strncmpi(message, job_name(i), 16) == 0) {
  812. job = i;
  813. found = true;
  814. }
  815. }
  816. if (!found) {
  817. text = atcommand_help_string(command);
  818. if (text)
  819. clif_displaymessage(fd, text);
  820. return -1;
  821. }
  822. }
  823. if (job == JOB_KNIGHT2 || job == JOB_CRUSADER2 || job == JOB_WEDDING || job == JOB_XMAS || job == JOB_SUMMER || job == JOB_HANBOK
  824. || job == JOB_LORD_KNIGHT2 || job == JOB_PALADIN2 || job == JOB_BABY_KNIGHT2 || job == JOB_BABY_CRUSADER2 || job == JOB_STAR_GLADIATOR2
  825. || (job >= JOB_RUNE_KNIGHT2 && job <= JOB_MECHANIC_T2) || (job >= JOB_BABY_RUNE2 && job <= JOB_BABY_MECHANIC2)
  826. ){ // Deny direct transformation into dummy jobs
  827. clif_displaymessage(fd, msg_txt(sd,923)); //"You can not change to this job by command."
  828. return 0;
  829. }
  830. if (pcdb_checkid(job))
  831. {
  832. if (pc_jobchange(sd, job, upper) == 0)
  833. clif_displaymessage(fd, msg_txt(sd,12)); // Your job has been changed.
  834. else {
  835. clif_displaymessage(fd, msg_txt(sd,155)); // You are unable to change your job.
  836. return -1;
  837. }
  838. } else {
  839. text = atcommand_help_string(command);
  840. if (text)
  841. clif_displaymessage(fd, text);
  842. return -1;
  843. }
  844. return 0;
  845. }
  846. /*==========================================
  847. *
  848. *------------------------------------------*/
  849. ACMD_FUNC(kill)
  850. {
  851. nullpo_retr(-1, sd);
  852. status_kill(&sd->bl);
  853. clif_displaymessage(sd->fd, msg_txt(sd,13)); // A pity! You've died.
  854. if (fd != sd->fd)
  855. clif_displaymessage(fd, msg_txt(sd,14)); // Character killed.
  856. return 0;
  857. }
  858. /*==========================================
  859. *
  860. *------------------------------------------*/
  861. ACMD_FUNC(alive)
  862. {
  863. nullpo_retr(-1, sd);
  864. if (!status_revive(&sd->bl, 100, 100))
  865. {
  866. clif_displaymessage(fd, msg_txt(sd,667));
  867. return -1;
  868. }
  869. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  870. clif_displaymessage(fd, msg_txt(sd,16)); // You've been revived! It's a miracle!
  871. return 0;
  872. }
  873. /*==========================================
  874. * +kamic [LuzZza]
  875. *------------------------------------------*/
  876. ACMD_FUNC(kami)
  877. {
  878. unsigned long color=0;
  879. nullpo_retr(-1, sd);
  880. memset(atcmd_output, '\0', sizeof(atcmd_output));
  881. if(*(command + 5) != 'c' && *(command + 5) != 'C') {
  882. if (!message || !*message) {
  883. clif_displaymessage(fd, msg_txt(sd,980)); // Please enter a message (usage: @kami <message>).
  884. return -1;
  885. }
  886. sscanf(message, "%199[^\n]", atcmd_output);
  887. if (strstr(command, "l") != NULL)
  888. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  889. else
  890. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(command + 5) == 'b' || *(command + 5) == 'B') ? 0x10 : 0);
  891. } else {
  892. if(!message || !*message || (sscanf(message, "%lx %199[^\n]", &color, atcmd_output) < 2)) {
  893. clif_displaymessage(fd, msg_txt(sd,981)); // Please enter color and message (usage: @kamic <color> <message>).
  894. return -1;
  895. }
  896. if(color > 0xFFFFFF) {
  897. clif_displaymessage(fd, msg_txt(sd,982)); // Invalid color.
  898. return -1;
  899. }
  900. intif_broadcast2(atcmd_output, strlen(atcmd_output) + 1, color, 0x190, 12, 0, 0);
  901. }
  902. return 0;
  903. }
  904. /*==========================================
  905. *
  906. *------------------------------------------*/
  907. ACMD_FUNC(heal)
  908. {
  909. int hp = 0, sp = 0; // [Valaris] thanks to fov
  910. nullpo_retr(-1, sd);
  911. sscanf(message, "%d %d", &hp, &sp);
  912. // some overflow checks
  913. if( hp == INT_MIN ) hp++;
  914. if( sp == INT_MIN ) sp++;
  915. if ( hp == 0 && sp == 0 ) {
  916. if (!status_percent_heal(&sd->bl, 100, 100))
  917. clif_displaymessage(fd, msg_txt(sd,157)); // HP and SP have already been recovered.
  918. else
  919. clif_displaymessage(fd, msg_txt(sd,17)); // HP, SP recovered.
  920. return 0;
  921. }
  922. if ( hp > 0 && sp >= 0 ) {
  923. if(!status_heal(&sd->bl, hp, sp, 0))
  924. clif_displaymessage(fd, msg_txt(sd,157)); // HP and SP are already with the good value.
  925. else
  926. clif_displaymessage(fd, msg_txt(sd,17)); // HP, SP recovered.
  927. return 0;
  928. }
  929. if ( hp < 0 && sp <= 0 ) {
  930. status_damage(NULL, &sd->bl, -hp, -sp, 0, 0);
  931. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  932. clif_displaymessage(fd, msg_txt(sd,156)); // HP or/and SP modified.
  933. return 0;
  934. }
  935. //Opposing signs.
  936. if ( hp ) {
  937. if (hp > 0)
  938. status_heal(&sd->bl, hp, 0, 0);
  939. else {
  940. status_damage(NULL, &sd->bl, -hp, 0, 0, 0);
  941. clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0);
  942. }
  943. }
  944. if ( sp ) {
  945. if (sp > 0)
  946. status_heal(&sd->bl, 0, sp, 0);
  947. else
  948. status_damage(NULL, &sd->bl, 0, -sp, 0, 0);
  949. }
  950. clif_displaymessage(fd, msg_txt(sd,156)); // HP or/and SP modified.
  951. return 0;
  952. }
  953. /*==========================================
  954. * @item command (usage: @item <name/id_of_item> <quantity>) (modified by [Yor] for pet_egg)
  955. *------------------------------------------*/
  956. ACMD_FUNC(item)
  957. {
  958. char item_name[100];
  959. int number = 0, item_id, flag = 0;
  960. struct item item_tmp;
  961. struct item_data *item_data;
  962. int get_count, i;
  963. nullpo_retr(-1, sd);
  964. memset(item_name, '\0', sizeof(item_name));
  965. if (!message || !*message || (
  966. sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 &&
  967. sscanf(message, "%99s %d", item_name, &number) < 1
  968. )) {
  969. clif_displaymessage(fd, msg_txt(sd,983)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity>).
  970. return -1;
  971. }
  972. if (number <= 0)
  973. number = 1;
  974. if ((item_data = itemdb_searchname(item_name)) == NULL &&
  975. (item_data = itemdb_exists(atoi(item_name))) == NULL)
  976. {
  977. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  978. return -1;
  979. }
  980. item_id = item_data->nameid;
  981. get_count = number;
  982. //Check if it's stackable.
  983. if (!itemdb_isstackable2(item_data))
  984. get_count = 1;
  985. for (i = 0; i < number; i += get_count) {
  986. // if not pet egg
  987. if (!pet_create_egg(sd, item_id)) {
  988. memset(&item_tmp, 0, sizeof(item_tmp));
  989. item_tmp.nameid = item_id;
  990. item_tmp.identify = 1;
  991. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  992. clif_additem(sd, 0, 0, flag);
  993. }
  994. }
  995. if (flag == 0)
  996. clif_displaymessage(fd, msg_txt(sd,18)); // Item created.
  997. return 0;
  998. }
  999. /*==========================================
  1000. *
  1001. *------------------------------------------*/
  1002. ACMD_FUNC(item2)
  1003. {
  1004. struct item item_tmp;
  1005. struct item_data *item_data;
  1006. char item_name[100];
  1007. int item_id, number = 0;
  1008. int identify = 0, refine = 0, attr = 0;
  1009. int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  1010. nullpo_retr(-1, sd);
  1011. memset(item_name, '\0', sizeof(item_name));
  1012. if (!message || !*message || (
  1013. sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
  1014. sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
  1015. )) {
  1016. clif_displaymessage(fd, msg_txt(sd,984)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity>
  1017. clif_displaymessage(fd, msg_txt(sd,985)); // <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4>).
  1018. return -1;
  1019. }
  1020. if (number <= 0)
  1021. number = 1;
  1022. item_id = 0;
  1023. if ((item_data = itemdb_searchname(item_name)) != NULL ||
  1024. (item_data = itemdb_exists(atoi(item_name))) != NULL)
  1025. item_id = item_data->nameid;
  1026. if (item_id > 500) {
  1027. int flag = 0;
  1028. int loop, get_count, i;
  1029. loop = 1;
  1030. get_count = number;
  1031. if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR ||
  1032. item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) {
  1033. loop = number;
  1034. get_count = 1;
  1035. if (item_data->type == IT_PETEGG) {
  1036. identify = 1;
  1037. refine = 0;
  1038. }
  1039. if (item_data->type == IT_PETARMOR)
  1040. refine = 0;
  1041. if (refine > MAX_REFINE)
  1042. refine = MAX_REFINE;
  1043. } else {
  1044. identify = 1;
  1045. refine = attr = 0;
  1046. }
  1047. for (i = 0; i < loop; i++) {
  1048. memset(&item_tmp, 0, sizeof(item_tmp));
  1049. item_tmp.nameid = item_id;
  1050. item_tmp.identify = identify;
  1051. item_tmp.refine = refine;
  1052. item_tmp.attribute = attr;
  1053. item_tmp.card[0] = c1;
  1054. item_tmp.card[1] = c2;
  1055. item_tmp.card[2] = c3;
  1056. item_tmp.card[3] = c4;
  1057. if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
  1058. clif_additem(sd, 0, 0, flag);
  1059. }
  1060. if (flag == 0)
  1061. clif_displaymessage(fd, msg_txt(sd,18)); // Item created.
  1062. } else {
  1063. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  1064. return -1;
  1065. }
  1066. return 0;
  1067. }
  1068. /*==========================================
  1069. *
  1070. *------------------------------------------*/
  1071. ACMD_FUNC(itemreset)
  1072. {
  1073. int i;
  1074. nullpo_retr(-1, sd);
  1075. for (i = 0; i < MAX_INVENTORY; i++) {
  1076. if (sd->status.inventory[i].amount && sd->status.inventory[i].equip == 0) {
  1077. pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_COMMAND);
  1078. }
  1079. }
  1080. clif_displaymessage(fd, msg_txt(sd,20)); // All of your items have been removed.
  1081. return 0;
  1082. }
  1083. /*==========================================
  1084. * Atcommand @lvlup
  1085. *------------------------------------------*/
  1086. ACMD_FUNC(baselevelup)
  1087. {
  1088. int level=0, i=0, status_point=0;
  1089. nullpo_retr(-1, sd);
  1090. level = atoi(message);
  1091. if (!message || !*message || !level) {
  1092. clif_displaymessage(fd, msg_txt(sd,986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup <number of levels>).
  1093. return -1;
  1094. }
  1095. if (level > 0) {
  1096. if (sd->status.base_level >= pc_maxbaselv(sd)) { // check for max level by Valaris
  1097. clif_displaymessage(fd, msg_txt(sd,47)); // Base level can't go any higher.
  1098. return -1;
  1099. } // End Addition
  1100. if ((unsigned int)level > pc_maxbaselv(sd) || (unsigned int)level > pc_maxbaselv(sd) - sd->status.base_level) // fix positiv overflow
  1101. level = pc_maxbaselv(sd) - sd->status.base_level;
  1102. for (i = 0; i < level; i++)
  1103. status_point += pc_gets_status_point(sd->status.base_level + i);
  1104. sd->status.status_point += status_point;
  1105. sd->status.base_level += (unsigned int)level;
  1106. status_percent_heal(&sd->bl, 100, 100);
  1107. clif_misceffect(&sd->bl, 0);
  1108. clif_displaymessage(fd, msg_txt(sd,21)); // Base level raised.
  1109. } else {
  1110. if (sd->status.base_level == 1) {
  1111. clif_displaymessage(fd, msg_txt(sd,158)); // Base level can't go any lower.
  1112. return -1;
  1113. }
  1114. level*=-1;
  1115. if ((unsigned int)level >= sd->status.base_level)
  1116. level = sd->status.base_level-1;
  1117. for (i = 0; i > -level; i--)
  1118. status_point += pc_gets_status_point(sd->status.base_level + i - 1);
  1119. if (sd->status.status_point < status_point)
  1120. pc_resetstate(sd);
  1121. if (sd->status.status_point < status_point)
  1122. sd->status.status_point = 0;
  1123. else
  1124. sd->status.status_point -= status_point;
  1125. sd->status.base_level -= (unsigned int)level;
  1126. clif_displaymessage(fd, msg_txt(sd,22)); // Base level lowered.
  1127. }
  1128. sd->status.base_exp = 0;
  1129. clif_updatestatus(sd, SP_STATUSPOINT);
  1130. clif_updatestatus(sd, SP_BASELEVEL);
  1131. clif_updatestatus(sd, SP_BASEEXP);
  1132. clif_updatestatus(sd, SP_NEXTBASEEXP);
  1133. status_calc_pc(sd, 0);
  1134. pc_baselevelchanged(sd);
  1135. if(sd->status.party_id)
  1136. party_send_levelup(sd);
  1137. return 0;
  1138. }
  1139. /*==========================================
  1140. *
  1141. *------------------------------------------*/
  1142. ACMD_FUNC(joblevelup)
  1143. {
  1144. int level=0;
  1145. nullpo_retr(-1, sd);
  1146. level = atoi(message);
  1147. if (!message || !*message || !level) {
  1148. clif_displaymessage(fd, msg_txt(sd,987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup <number of levels>).
  1149. return -1;
  1150. }
  1151. if (level > 0) {
  1152. if (sd->status.job_level >= pc_maxjoblv(sd)) {
  1153. clif_displaymessage(fd, msg_txt(sd,23)); // Job level can't go any higher.
  1154. return -1;
  1155. }
  1156. if ((unsigned int)level > pc_maxjoblv(sd) || (unsigned int)level > pc_maxjoblv(sd) - sd->status.job_level) // fix positiv overflow
  1157. level = pc_maxjoblv(sd) - sd->status.job_level;
  1158. sd->status.job_level += (unsigned int)level;
  1159. sd->status.skill_point += level;
  1160. clif_misceffect(&sd->bl, 1);
  1161. clif_displaymessage(fd, msg_txt(sd,24)); // Job level raised.
  1162. } else {
  1163. if (sd->status.job_level == 1) {
  1164. clif_displaymessage(fd, msg_txt(sd,159)); // Job level can't go any lower.
  1165. return -1;
  1166. }
  1167. level *=-1;
  1168. if ((unsigned int)level >= sd->status.job_level) // fix negativ overflow
  1169. level = sd->status.job_level-1;
  1170. sd->status.job_level -= (unsigned int)level;
  1171. if (sd->status.skill_point < level)
  1172. pc_resetskill(sd,0); //Reset skills since we need to substract more points.
  1173. if (sd->status.skill_point < level)
  1174. sd->status.skill_point = 0;
  1175. else
  1176. sd->status.skill_point -= level;
  1177. clif_displaymessage(fd, msg_txt(sd,25)); // Job level lowered.
  1178. }
  1179. sd->status.job_exp = 0;
  1180. clif_updatestatus(sd, SP_JOBLEVEL);
  1181. clif_updatestatus(sd, SP_JOBEXP);
  1182. clif_updatestatus(sd, SP_NEXTJOBEXP);
  1183. clif_updatestatus(sd, SP_SKILLPOINT);
  1184. status_calc_pc(sd, 0);
  1185. return 0;
  1186. }
  1187. /*==========================================
  1188. * @help
  1189. *------------------------------------------*/
  1190. ACMD_FUNC(help)
  1191. {
  1192. config_setting_t *help;
  1193. const char *text = NULL;
  1194. const char *command_name = NULL;
  1195. char *default_command = "help";
  1196. nullpo_retr(-1, sd);
  1197. help = config_lookup(&atcommand_config, "help");
  1198. if (help == NULL) {
  1199. clif_displaymessage(fd, msg_txt(sd,27)); // "Commands help is not available."
  1200. return -1;
  1201. }
  1202. if (!message || !*message) {
  1203. command_name = default_command; // If no command_name specified, display help for @help.
  1204. } else {
  1205. if (*message == atcommand_symbol || *message == charcommand_symbol)
  1206. ++message;
  1207. command_name = atcommand_checkalias(message);
  1208. }
  1209. if (!pc_can_use_command(sd, command_name, COMMAND_ATCOMMAND)) {
  1210. sprintf(atcmd_output, msg_txt(sd,153), message); // "%s is Unknown Command"
  1211. clif_displaymessage(fd, atcmd_output);
  1212. atcommand_get_suggestions(sd, command_name, true);
  1213. return -1;
  1214. }
  1215. if (!config_setting_lookup_string(help, command_name, &text)) {
  1216. sprintf(atcmd_output, msg_txt(sd,988), atcommand_symbol, command_name); // There is no help for %c%s.
  1217. clif_displaymessage(fd, atcmd_output);
  1218. atcommand_get_suggestions(sd, command_name, true);
  1219. return -1;
  1220. }
  1221. sprintf(atcmd_output, msg_txt(sd,989), atcommand_symbol, command_name); // Help for command %c%s:
  1222. clif_displaymessage(fd, atcmd_output);
  1223. { // Display aliases
  1224. DBIterator* iter;
  1225. AtCommandInfo *command_info;
  1226. AliasInfo *alias_info = NULL;
  1227. StringBuf buf;
  1228. bool has_aliases = false;
  1229. StringBuf_Init(&buf);
  1230. StringBuf_AppendStr(&buf, msg_txt(sd,990)); // Available aliases:
  1231. command_info = get_atcommandinfo_byname(command_name);
  1232. iter = db_iterator(atcommand_alias_db);
  1233. for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) {
  1234. if (alias_info->command == command_info) {
  1235. StringBuf_Printf(&buf, " %s", alias_info->alias);
  1236. has_aliases = true;
  1237. }
  1238. }
  1239. dbi_destroy(iter);
  1240. if (has_aliases)
  1241. clif_displaymessage(fd, StringBuf_Value(&buf));
  1242. StringBuf_Destroy(&buf);
  1243. }
  1244. // Display help contents
  1245. clif_displaymessage(fd, text);
  1246. return 0;
  1247. }
  1248. // helper function, used in foreach calls to stop auto-attack timers
  1249. // parameter: '0' - everyone, 'id' - only those attacking someone with that id
  1250. static int atcommand_stopattack(struct block_list *bl,va_list ap)
  1251. {
  1252. struct unit_data *ud = unit_bl2ud(bl);
  1253. int id = va_arg(ap, int);
  1254. if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target))
  1255. {
  1256. unit_stop_attack(bl);
  1257. return 1;
  1258. }
  1259. return 0;
  1260. }
  1261. /*==========================================
  1262. *
  1263. *------------------------------------------*/
  1264. static int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
  1265. {
  1266. TBL_PC* sd = (TBL_PC*)bl;
  1267. clif_pvpset(sd, 0, 0, 2);
  1268. if (sd->pvp_timer != INVALID_TIMER) {
  1269. delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
  1270. sd->pvp_timer = INVALID_TIMER;
  1271. }
  1272. return 0;
  1273. }
  1274. ACMD_FUNC(pvpoff)
  1275. {
  1276. nullpo_retr(-1, sd);
  1277. if (!map[sd->bl.m].flag.pvp) {
  1278. clif_displaymessage(fd, msg_txt(sd,160)); // PvP is already Off.
  1279. return -1;
  1280. }
  1281. map[sd->bl.m].flag.pvp = 0;
  1282. if (!battle_config.pk_mode)
  1283. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1284. map_foreachinmap(atcommand_pvpoff_sub,sd->bl.m, BL_PC);
  1285. map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1286. clif_displaymessage(fd, msg_txt(sd,31)); // PvP: Off.
  1287. return 0;
  1288. }
  1289. /*==========================================
  1290. *
  1291. *------------------------------------------*/
  1292. static int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
  1293. {
  1294. TBL_PC* sd = (TBL_PC*)bl;
  1295. if (sd->pvp_timer == INVALID_TIMER) {
  1296. sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
  1297. sd->pvp_rank = 0;
  1298. sd->pvp_lastusers = 0;
  1299. sd->pvp_point = 5;
  1300. sd->pvp_won = 0;
  1301. sd->pvp_lost = 0;
  1302. }
  1303. return 0;
  1304. }
  1305. ACMD_FUNC(pvpon)
  1306. {
  1307. nullpo_retr(-1, sd);
  1308. if (map[sd->bl.m].flag.pvp) {
  1309. clif_displaymessage(fd, msg_txt(sd,161)); // PvP is already On.
  1310. return -1;
  1311. }
  1312. map[sd->bl.m].flag.pvp = 1;
  1313. if (!battle_config.pk_mode)
  1314. {// display pvp circle and rank
  1315. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_FREEPVPZONE);
  1316. map_foreachinmap(atcommand_pvpon_sub,sd->bl.m, BL_PC);
  1317. }
  1318. clif_displaymessage(fd, msg_txt(sd,32)); // PvP: On.
  1319. return 0;
  1320. }
  1321. /*==========================================
  1322. *
  1323. *------------------------------------------*/
  1324. ACMD_FUNC(gvgoff)
  1325. {
  1326. nullpo_retr(-1, sd);
  1327. if (!map[sd->bl.m].flag.gvg) {
  1328. clif_displaymessage(fd, msg_txt(sd,162)); // GvG is already Off.
  1329. return -1;
  1330. }
  1331. map[sd->bl.m].flag.gvg = 0;
  1332. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_NOTHING);
  1333. map_foreachinmap(atcommand_stopattack,sd->bl.m, BL_CHAR, 0);
  1334. clif_displaymessage(fd, msg_txt(sd,33)); // GvG: Off.
  1335. return 0;
  1336. }
  1337. /*==========================================
  1338. *
  1339. *------------------------------------------*/
  1340. ACMD_FUNC(gvgon)
  1341. {
  1342. nullpo_retr(-1, sd);
  1343. if (map[sd->bl.m].flag.gvg) {
  1344. clif_displaymessage(fd, msg_txt(sd,163)); // GvG is already On.
  1345. return -1;
  1346. }
  1347. map[sd->bl.m].flag.gvg = 1;
  1348. clif_map_property_mapall(sd->bl.m, MAPPROPERTY_AGITZONE);
  1349. clif_displaymessage(fd, msg_txt(sd,34)); // GvG: On.
  1350. return 0;
  1351. }
  1352. /*==========================================
  1353. *
  1354. *------------------------------------------*/
  1355. ACMD_FUNC(model)
  1356. {
  1357. int hair_style = 0, hair_color = 0, cloth_color = 0;
  1358. nullpo_retr(-1, sd);
  1359. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1360. if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) {
  1361. sprintf(atcmd_output, msg_txt(sd,991), // Please enter at least one value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).
  1362. MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
  1363. clif_displaymessage(fd, atcmd_output);
  1364. return -1;
  1365. }
  1366. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE &&
  1367. hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR &&
  1368. cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1369. pc_changelook(sd, LOOK_HAIR, hair_style);
  1370. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1371. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1372. clif_displaymessage(fd, msg_txt(sd,36)); // Appearence changed.
  1373. } else {
  1374. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1375. return -1;
  1376. }
  1377. return 0;
  1378. }
  1379. /*==========================================
  1380. * @dye && @ccolor
  1381. *------------------------------------------*/
  1382. ACMD_FUNC(dye)
  1383. {
  1384. int cloth_color = 0;
  1385. nullpo_retr(-1, sd);
  1386. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1387. if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) {
  1388. sprintf(atcmd_output, msg_txt(sd,992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).
  1389. clif_displaymessage(fd, atcmd_output);
  1390. return -1;
  1391. }
  1392. if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) {
  1393. pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color);
  1394. clif_displaymessage(fd, msg_txt(sd,36)); // Appearence changed.
  1395. } else {
  1396. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1397. return -1;
  1398. }
  1399. return 0;
  1400. }
  1401. /*==========================================
  1402. * @hairstyle && @hstyle
  1403. *------------------------------------------*/
  1404. ACMD_FUNC(hair_style)
  1405. {
  1406. int hair_style = 0;
  1407. nullpo_retr(-1, sd);
  1408. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1409. if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) {
  1410. sprintf(atcmd_output, msg_txt(sd,993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).
  1411. clif_displaymessage(fd, atcmd_output);
  1412. return -1;
  1413. }
  1414. if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) {
  1415. pc_changelook(sd, LOOK_HAIR, hair_style);
  1416. clif_displaymessage(fd, msg_txt(sd,36)); // Appearence changed.
  1417. } else {
  1418. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1419. return -1;
  1420. }
  1421. return 0;
  1422. }
  1423. /*==========================================
  1424. * @haircolor && @hcolor
  1425. *------------------------------------------*/
  1426. ACMD_FUNC(hair_color)
  1427. {
  1428. int hair_color = 0;
  1429. nullpo_retr(-1, sd);
  1430. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1431. if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) {
  1432. sprintf(atcmd_output, msg_txt(sd,994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).
  1433. clif_displaymessage(fd, atcmd_output);
  1434. return -1;
  1435. }
  1436. if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) {
  1437. pc_changelook(sd, LOOK_HAIR_COLOR, hair_color);
  1438. clif_displaymessage(fd, msg_txt(sd,36)); // Appearence changed.
  1439. } else {
  1440. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  1441. return -1;
  1442. }
  1443. return 0;
  1444. }
  1445. /*==========================================
  1446. * @go [city_number or city_name] - Updated by Harbin
  1447. *------------------------------------------*/
  1448. ACMD_FUNC(go)
  1449. {
  1450. int i;
  1451. int town;
  1452. char map_name[MAP_NAME_LENGTH];
  1453. int16 m;
  1454. const struct {
  1455. char map[MAP_NAME_LENGTH];
  1456. int x, y;
  1457. } data[] = {
  1458. { MAP_PRONTERA, 156, 191 }, // 0=Prontera
  1459. { MAP_MORROC, 156, 93 }, // 1=Morroc
  1460. { MAP_GEFFEN, 119, 59 }, // 2=Geffen
  1461. { MAP_PAYON, 162, 233 }, // 3=Payon
  1462. { MAP_ALBERTA, 192, 147 }, // 4=Alberta
  1463. #ifdef RENEWAL
  1464. { MAP_IZLUDE, 128, 146 }, // 5=Izlude (Renewal)
  1465. #else
  1466. { MAP_IZLUDE, 128, 114 }, // 5=Izlude
  1467. #endif
  1468. { MAP_ALDEBARAN, 140, 131 }, // 6=Al de Baran
  1469. { MAP_LUTIE, 147, 134 }, // 7=Lutie
  1470. { MAP_COMODO, 209, 143 }, // 8=Comodo
  1471. { MAP_YUNO, 157, 51 }, // 9=Yuno
  1472. { MAP_AMATSU, 198, 84 }, // 10=Amatsu
  1473. { MAP_GONRYUN, 160, 120 }, // 11=Gonryun
  1474. { MAP_UMBALA, 89, 157 }, // 12=Umbala
  1475. { MAP_NIFLHEIM, 21, 153 }, // 13=Niflheim
  1476. { MAP_LOUYANG, 217, 40 }, // 14=Louyang
  1477. { MAP_NOVICE, 53, 111 }, // 15=Training Grounds
  1478. { MAP_JAIL, 23, 61 }, // 16=Prison
  1479. { MAP_JAWAII, 249, 127 }, // 17=Jawaii
  1480. { MAP_AYOTHAYA, 151, 117 }, // 18=Ayothaya
  1481. { MAP_EINBROCH, 64, 200 }, // 19=Einbroch
  1482. { MAP_LIGHTHALZEN, 158, 92 }, // 20=Lighthalzen
  1483. { MAP_EINBECH, 70, 95 }, // 21=Einbech
  1484. { MAP_HUGEL, 96, 145 }, // 22=Hugel
  1485. { MAP_RACHEL, 130, 110 }, // 23=Rachel
  1486. { MAP_VEINS, 216, 123 }, // 24=Veins
  1487. { MAP_MOSCOVIA, 223, 184 }, // 25=Moscovia
  1488. { MAP_MIDCAMP, 180, 240 }, // 26=Midgard Camp
  1489. { MAP_MANUK, 282, 138 }, // 27=Manuk
  1490. { MAP_SPLENDIDE, 197, 176 }, // 28=Splendide
  1491. { MAP_BRASILIS, 182, 239 }, // 29=Brasilis
  1492. { MAP_DICASTES, 198, 187 }, // 30=El Dicastes
  1493. { MAP_MORA, 44, 151 }, // 31=Mora
  1494. { MAP_DEWATA, 200, 180 }, // 32=Dewata
  1495. { MAP_MALANGDO, 140, 114 }, // 33=Malangdo Island
  1496. { MAP_MALAYA, 242, 211 }, // 34=Malaya Port
  1497. { MAP_ECLAGE, 110, 39 }, // 35=Eclage
  1498. };
  1499. nullpo_retr(-1, sd);
  1500. if( map[sd->bl.m].flag.nogo && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE) ) {
  1501. clif_displaymessage(sd->fd,msg_txt(sd,995)); // You cannot use @go on this map.
  1502. return 0;
  1503. }
  1504. memset(map_name, '\0', sizeof(map_name));
  1505. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1506. // get the number
  1507. town = atoi(message);
  1508. if (!message || !*message || sscanf(message, "%11s", map_name) < 1 || town < 0 || town >= ARRAYLENGTH(data))
  1509. {// no value matched so send the list of locations
  1510. const char* text;
  1511. // attempt to find the text help string
  1512. text = atcommand_help_string( command );
  1513. clif_displaymessage(fd, msg_txt(sd,38)); // Invalid location number, or name.
  1514. if( text )
  1515. {// send the text to the client
  1516. clif_displaymessage( fd, text );
  1517. }
  1518. return -1;
  1519. }
  1520. // get possible name of the city
  1521. map_name[MAP_NAME_LENGTH-1] = '\0';
  1522. for (i = 0; map_name[i]; i++)
  1523. map_name[i] = TOLOWER(map_name[i]);
  1524. // try to identify the map name
  1525. if (strncmp(map_name, "prontera", 3) == 0) {
  1526. town = 0;
  1527. } else if (strncmp(map_name, "morocc", 4) == 0 ||
  1528. strncmp(map_name, "morroc", 4) == 0) {
  1529. town = 1;
  1530. } else if (strncmp(map_name, "geffen", 3) == 0) {
  1531. town = 2;
  1532. } else if (strncmp(map_name, "payon", 3) == 0) {
  1533. town = 3;
  1534. } else if (strncmp(map_name, "alberta", 3) == 0) {
  1535. town = 4;
  1536. } else if (strncmp(map_name, "izlude", 3) == 0) {
  1537. town = 5;
  1538. } else if (strncmp(map_name, "aldebaran", 3) == 0) {
  1539. town = 6;
  1540. } else if (strncmp(map_name, "lutie", 3) == 0 ||
  1541. strcmp(map_name, "christmas") == 0 ||
  1542. strncmp(map_name, "xmas", 3) == 0 ||
  1543. strncmp(map_name, "x-mas", 3) == 0) {
  1544. town = 7;
  1545. } else if (strncmp(map_name, "comodo", 3) == 0) {
  1546. town = 8;
  1547. } else if (strncmp(map_name, "juno", 3) == 0 ||
  1548. strncmp(map_name, "yuno", 3) == 0) {
  1549. town = 9;
  1550. } else if (strncmp(map_name, "amatsu", 3) == 0) {
  1551. town = 10;
  1552. } else if (strncmp(map_name, "kunlun", 3) == 0 ||
  1553. strncmp(map_name, "gonryun", 3) == 0) {
  1554. town = 11;
  1555. } else if (strncmp(map_name, "umbala", 3) == 0) {
  1556. town = 12;
  1557. } else if (strncmp(map_name, "niflheim", 3) == 0) {
  1558. town = 13;
  1559. } else if (strncmp(map_name, "louyang", 3) == 0) {
  1560. town = 14;
  1561. } else if (strncmp(map_name, "new_1-1", 3) == 0 ||
  1562. strncmp(map_name, "startpoint", 3) == 0 ||
  1563. strncmp(map_name, "beginning", 3) == 0) {
  1564. town = 15;
  1565. } else if (strncmp(map_name, "sec_pri", 3) == 0 ||
  1566. strncmp(map_name, "prison", 3) == 0 ||
  1567. strncmp(map_name, "jail", 3) == 0) {
  1568. town = 16;
  1569. } else if (strncmp(map_name, "jawaii", 3) == 0) {
  1570. town = 17;
  1571. } else if (strncmp(map_name, "ayothaya", 3) == 0) {
  1572. town = 18;
  1573. } else if (strncmp(map_name, "einbroch", 5) == 0) {
  1574. town = 19;
  1575. } else if (strncmp(map_name, "lighthalzen", 3) == 0) {
  1576. town = 20;
  1577. } else if (strncmp(map_name, "einbech", 5) == 0) {
  1578. town = 21;
  1579. } else if (strncmp(map_name, "hugel", 3) == 0) {
  1580. town = 22;
  1581. } else if (strncmp(map_name, "rachel", 3) == 0) {
  1582. town = 23;
  1583. } else if (strncmp(map_name, "veins", 3) == 0) {
  1584. town = 24;
  1585. } else if (strncmp(map_name, "moscovia", 3) == 0) {
  1586. town = 25;
  1587. } else if (strncmp(map_name, "mid_camp", 3) == 0) {
  1588. town = 26;
  1589. } else if (strncmp(map_name, "manuk", 3) == 0) {
  1590. town = 27;
  1591. } else if (strncmp(map_name, "splendide", 3) == 0) {
  1592. town = 28;
  1593. } else if (strncmp(map_name, "brasilis", 3) == 0) {
  1594. town = 29;
  1595. } else if (strncmp(map_name, "dicastes01", 3) == 0) {
  1596. town = 30;
  1597. } else if (strcmp(map_name, "mora") == 0) {
  1598. town = 31;
  1599. } else if (strncmp(map_name, "dewata", 3) == 0) {
  1600. town = 32;
  1601. } else if (strncmp(map_name, "malangdo", 5) == 0) {
  1602. town = 33;
  1603. } else if (strncmp(map_name, "malaya", 5) == 0) {
  1604. town = 34;
  1605. } else if (strncmp(map_name, "eclage", 3) == 0) {
  1606. town = 35;
  1607. }
  1608. if (town >= 0 && town < ARRAYLENGTH(data))
  1609. {
  1610. m = map_mapname2mapid(data[town].map);
  1611. if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1612. clif_displaymessage(fd, msg_txt(sd,247));
  1613. return -1;
  1614. }
  1615. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  1616. clif_displaymessage(fd, msg_txt(sd,248));
  1617. return -1;
  1618. }
  1619. if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) {
  1620. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  1621. } else {
  1622. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  1623. return -1;
  1624. }
  1625. } else { // if you arrive here, you have an error in town variable when reading of names
  1626. clif_displaymessage(fd, msg_txt(sd,38)); // Invalid location number or name.
  1627. return -1;
  1628. }
  1629. return 0;
  1630. }
  1631. /*==========================================
  1632. *
  1633. *------------------------------------------*/
  1634. ACMD_FUNC(monster)
  1635. {
  1636. char name[NAME_LENGTH];
  1637. char monster[NAME_LENGTH];
  1638. char eventname[EVENT_NAME_LENGTH] = "";
  1639. int mob_id;
  1640. int number = 0;
  1641. int count;
  1642. int i, k, range;
  1643. short mx, my;
  1644. unsigned int size;
  1645. nullpo_retr(-1, sd);
  1646. memset(name, '\0', sizeof(name));
  1647. memset(monster, '\0', sizeof(monster));
  1648. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1649. if (!message || !*message) {
  1650. clif_displaymessage(fd, msg_txt(sd,80)); // Give the display name or monster name/id please.
  1651. return -1;
  1652. }
  1653. if (sscanf(message, "\"%23[^\"]\" %23s %d", name, monster, &number) > 1 ||
  1654. sscanf(message, "%23s \"%23[^\"]\" %d", monster, name, &number) > 1) {
  1655. //All data can be left as it is.
  1656. } else if ((count=sscanf(message, "%23s %d %23s", monster, &number, name)) > 1) {
  1657. //Here, it is possible name was not given and we are using monster for it.
  1658. if (count < 3) //Blank mob's name.
  1659. name[0] = '\0';
  1660. } else if (sscanf(message, "%23s %23s %d", name, monster, &number) > 1) {
  1661. //All data can be left as it is.
  1662. } else if (sscanf(message, "%23s", monster) > 0) {
  1663. //As before, name may be already filled.
  1664. name[0] = '\0';
  1665. } else {
  1666. clif_displaymessage(fd, msg_txt(sd,80)); // Give a display name and monster name/id please.
  1667. return -1;
  1668. }
  1669. if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
  1670. mob_id = mobdb_checkid(atoi(monster));
  1671. if (mob_id == 0) {
  1672. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  1673. return -1;
  1674. }
  1675. if (mob_id == MOBID_EMPERIUM) {
  1676. clif_displaymessage(fd, msg_txt(sd,83)); // Monster 'Emperium' cannot be spawned.
  1677. return -1;
  1678. }
  1679. if (number <= 0)
  1680. number = 1;
  1681. if( !name[0] )
  1682. strcpy(name, "--ja--");
  1683. // 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
  1684. if (battle_config.atc_spawn_quantity_limit && number > battle_config.atc_spawn_quantity_limit)
  1685. number = battle_config.atc_spawn_quantity_limit;
  1686. if (strcmp(command+1, "monstersmall") == 0)
  1687. size = SZ_MEDIUM; // This is just gorgeous [mkbu95]
  1688. else if (strcmp(command+1, "monsterbig") == 0)
  1689. size = SZ_BIG;
  1690. else
  1691. size = SZ_SMALL;
  1692. if (battle_config.etc_log)
  1693. 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);
  1694. count = 0;
  1695. range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
  1696. for (i = 0; i < number; i++) {
  1697. map_search_freecell(&sd->bl, 0, &mx, &my, range, range, 0);
  1698. k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE);
  1699. count += (k != 0) ? 1 : 0;
  1700. }
  1701. if (count != 0)
  1702. if (number == count)
  1703. clif_displaymessage(fd, msg_txt(sd,39)); // All monster summoned!
  1704. else {
  1705. sprintf(atcmd_output, msg_txt(sd,240), count); // %d monster(s) summoned!
  1706. clif_displaymessage(fd, atcmd_output);
  1707. }
  1708. else {
  1709. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  1710. return -1;
  1711. }
  1712. return 0;
  1713. }
  1714. /*==========================================
  1715. *
  1716. *------------------------------------------*/
  1717. static int atkillmonster_sub(struct block_list *bl, va_list ap)
  1718. {
  1719. struct mob_data *md;
  1720. int flag;
  1721. nullpo_ret(md=(struct mob_data *)bl);
  1722. flag = va_arg(ap, int);
  1723. if (md->guardian_data)
  1724. return 0; //Do not touch WoE mobs!
  1725. if (flag)
  1726. status_zap(bl,md->status.hp, 0);
  1727. else
  1728. status_kill(bl);
  1729. return 1;
  1730. }
  1731. ACMD_FUNC(killmonster)
  1732. {
  1733. int map_id, drop_flag;
  1734. char map_name[MAP_NAME_LENGTH_EXT];
  1735. nullpo_retr(-1, sd);
  1736. memset(map_name, '\0', sizeof(map_name));
  1737. if (!message || !*message || sscanf(message, "%15s", map_name) < 1)
  1738. map_id = sd->bl.m;
  1739. else {
  1740. if ((map_id = map_mapname2mapid(map_name)) < 0)
  1741. map_id = sd->bl.m;
  1742. }
  1743. drop_flag = strcmp(command+1, "killmonster2");
  1744. map_foreachinmap(atkillmonster_sub, map_id, BL_MOB, -drop_flag);
  1745. clif_displaymessage(fd, msg_txt(sd,165)); // All monsters killed!
  1746. return 0;
  1747. }
  1748. /*==========================================
  1749. *
  1750. *------------------------------------------*/
  1751. ACMD_FUNC(refine)
  1752. {
  1753. int i,j, position = 0, refine = 0, current_position, final_refine;
  1754. int count;
  1755. nullpo_retr(-1, sd);
  1756. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1757. if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) {
  1758. clif_displaymessage(fd, msg_txt(sd,996)); // Please enter a position and an amount (usage: @refine <equip position> <+/- amount>).
  1759. sprintf(atcmd_output, msg_txt(sd,997), EQP_HEAD_LOW); // %d: Lower Headgear
  1760. clif_displaymessage(fd, atcmd_output);
  1761. sprintf(atcmd_output, msg_txt(sd,998), EQP_HAND_R); // %d: Right Hand
  1762. clif_displaymessage(fd, atcmd_output);
  1763. sprintf(atcmd_output, msg_txt(sd,999), EQP_GARMENT); // %d: Garment
  1764. clif_displaymessage(fd, atcmd_output);
  1765. sprintf(atcmd_output, msg_txt(sd,1000), EQP_ACC_L); // %d: Left Accessory
  1766. clif_displaymessage(fd, atcmd_output);
  1767. sprintf(atcmd_output, msg_txt(sd,1001), EQP_ARMOR); // %d: Body Armor
  1768. clif_displaymessage(fd, atcmd_output);
  1769. sprintf(atcmd_output, msg_txt(sd,1002), EQP_HAND_L); // %d: Left Hand
  1770. clif_displaymessage(fd, atcmd_output);
  1771. sprintf(atcmd_output, msg_txt(sd,1003), EQP_SHOES); // %d: Shoes
  1772. clif_displaymessage(fd, atcmd_output);
  1773. sprintf(atcmd_output, msg_txt(sd,1004), EQP_ACC_R); // %d: Right Accessory
  1774. clif_displaymessage(fd, atcmd_output);
  1775. sprintf(atcmd_output, msg_txt(sd,1005), EQP_HEAD_TOP); // %d: Top Headgear
  1776. clif_displaymessage(fd, atcmd_output);
  1777. sprintf(atcmd_output, msg_txt(sd,1006), EQP_HEAD_MID); // %d: Mid Headgear
  1778. clif_displaymessage(fd, atcmd_output);
  1779. return -1;
  1780. }
  1781. refine = cap_value(refine, -MAX_REFINE, MAX_REFINE);
  1782. count = 0;
  1783. for (j = 0; j < EQI_MAX-1; j++) {
  1784. if ((i = sd->equip_index[j]) < 0)
  1785. continue;
  1786. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == i)
  1787. continue;
  1788. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == i)
  1789. continue;
  1790. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == i || sd->equip_index[EQI_HEAD_LOW] == i))
  1791. continue;
  1792. if(position && !(sd->status.inventory[i].equip & position))
  1793. continue;
  1794. final_refine = cap_value(sd->status.inventory[i].refine + refine, 0, MAX_REFINE);
  1795. if (sd->status.inventory[i].refine != final_refine) {
  1796. sd->status.inventory[i].refine = final_refine;
  1797. current_position = sd->status.inventory[i].equip;
  1798. pc_unequipitem(sd, i, 3);
  1799. clif_refine(fd, 0, i, sd->status.inventory[i].refine);
  1800. clif_delitem(sd, i, 1, 3);
  1801. clif_additem(sd, i, 1, 0);
  1802. pc_equipitem(sd, i, current_position);
  1803. clif_misceffect(&sd->bl, 3);
  1804. count++;
  1805. }
  1806. }
  1807. if (count == 0)
  1808. clif_displaymessage(fd, msg_txt(sd,166)); // No item has been refined.
  1809. else if (count == 1)
  1810. clif_displaymessage(fd, msg_txt(sd,167)); // 1 item has been refined.
  1811. else {
  1812. sprintf(atcmd_output, msg_txt(sd,168), count); // %d items have been refined.
  1813. clif_displaymessage(fd, atcmd_output);
  1814. }
  1815. return 0;
  1816. }
  1817. /*==========================================
  1818. *
  1819. *------------------------------------------*/
  1820. ACMD_FUNC(produce)
  1821. {
  1822. char item_name[100];
  1823. int item_id, attribute = 0, star = 0;
  1824. struct item_data *item_data;
  1825. struct item tmp_item;
  1826. nullpo_retr(-1, sd);
  1827. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1828. memset(item_name, '\0', sizeof(item_name));
  1829. if (!message || !*message || (
  1830. sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 &&
  1831. sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1
  1832. )) {
  1833. clif_displaymessage(fd, msg_txt(sd,1007)); // Please enter at least one item name/ID (usage: @produce <equip name/ID> <element> <# of very's>).
  1834. return -1;
  1835. }
  1836. if ( (item_data = itemdb_searchname(item_name)) == NULL &&
  1837. (item_data = itemdb_exists(atoi(item_name))) == NULL ) {
  1838. clif_displaymessage(fd, msg_txt(sd,170)); //This item is not an equipment.
  1839. return -1;
  1840. }
  1841. item_id = item_data->nameid;
  1842. if (itemdb_isequip2(item_data)) {
  1843. int flag = 0;
  1844. if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
  1845. attribute = ATTRIBUTE_NORMAL;
  1846. if (star < MIN_STAR || star > MAX_STAR)
  1847. star = 0;
  1848. memset(&tmp_item, 0, sizeof tmp_item);
  1849. tmp_item.nameid = item_id;
  1850. tmp_item.amount = 1;
  1851. tmp_item.identify = 1;
  1852. tmp_item.card[0] = CARD0_FORGE;
  1853. tmp_item.card[1] = item_data->type==IT_WEAPON?
  1854. ((star*5) << 8) + attribute:0;
  1855. tmp_item.card[2] = GetWord(sd->status.char_id, 0);
  1856. tmp_item.card[3] = GetWord(sd->status.char_id, 1);
  1857. clif_produceeffect(sd, 0, item_id);
  1858. clif_misceffect(&sd->bl, 3);
  1859. if ((flag = pc_additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
  1860. clif_additem(sd, 0, 0, flag);
  1861. } else {
  1862. sprintf(atcmd_output, msg_txt(sd,169), item_id, item_data->name); // The item (%d: '%s') is not equipable.
  1863. clif_displaymessage(fd, atcmd_output);
  1864. return -1;
  1865. }
  1866. return 0;
  1867. }
  1868. /*==========================================
  1869. *
  1870. *------------------------------------------*/
  1871. ACMD_FUNC(memo)
  1872. {
  1873. int position = 0;
  1874. nullpo_retr(-1, sd);
  1875. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1876. if( !message || !*message || sscanf(message, "%d", &position) < 1 )
  1877. {
  1878. int i;
  1879. clif_displaymessage(sd->fd, msg_txt(sd,668));
  1880. for( i = 0; i < MAX_MEMOPOINTS; i++ )
  1881. {
  1882. if( sd->status.memo_point[i].map )
  1883. 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);
  1884. else
  1885. sprintf(atcmd_output, msg_txt(sd,171), i); // %d - void
  1886. clif_displaymessage(sd->fd, atcmd_output);
  1887. }
  1888. return 0;
  1889. }
  1890. if( position < 0 || position >= MAX_MEMOPOINTS )
  1891. {
  1892. sprintf(atcmd_output, msg_txt(sd,1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo <memo_position:%d-%d>).
  1893. clif_displaymessage(fd, atcmd_output);
  1894. return -1;
  1895. }
  1896. pc_memo(sd, position);
  1897. return 0;
  1898. }
  1899. /*==========================================
  1900. *
  1901. *------------------------------------------*/
  1902. ACMD_FUNC(gat)
  1903. {
  1904. int y;
  1905. nullpo_retr(-1, sd);
  1906. memset(atcmd_output, '\0', sizeof(atcmd_output));
  1907. for (y = 2; y >= -2; y--) {
  1908. sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
  1909. map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
  1910. map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE),
  1911. map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE),
  1912. map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y, CELL_GETTYPE),
  1913. map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y, CELL_GETTYPE),
  1914. map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y, CELL_GETTYPE));
  1915. clif_displaymessage(fd, atcmd_output);
  1916. }
  1917. return 0;
  1918. }
  1919. /*==========================================
  1920. *
  1921. *------------------------------------------*/
  1922. ACMD_FUNC(displaystatus)
  1923. {
  1924. int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0;
  1925. nullpo_retr(-1, sd);
  1926. if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) {
  1927. clif_displaymessage(fd, msg_txt(sd,1009)); // Please enter a status type/flag (usage: @displaystatus <status type> <flag> <tick> {<val1> {<val2> {<val3>}}}).
  1928. return -1;
  1929. }
  1930. if (i < 2) flag = 1;
  1931. if (i < 3) tick = 0;
  1932. clif_status_change(&sd->bl, type, flag, tick, val1, val2, val3);
  1933. return 0;
  1934. }
  1935. /*==========================================
  1936. * @stpoint (Rewritten by [Yor])
  1937. *------------------------------------------*/
  1938. ACMD_FUNC(statuspoint)
  1939. {
  1940. int point;
  1941. unsigned int new_status_point;
  1942. if (!message || !*message || (point = atoi(message)) == 0) {
  1943. clif_displaymessage(fd, msg_txt(sd,1010)); // Please enter a number (usage: @stpoint <number of points>).
  1944. return -1;
  1945. }
  1946. if(point < 0)
  1947. {
  1948. if(sd->status.status_point < (unsigned int)(-point))
  1949. {
  1950. new_status_point = 0;
  1951. }
  1952. else
  1953. {
  1954. new_status_point = sd->status.status_point + point;
  1955. }
  1956. }
  1957. else if(UINT_MAX - sd->status.status_point < (unsigned int)point)
  1958. {
  1959. new_status_point = UINT_MAX;
  1960. }
  1961. else
  1962. {
  1963. new_status_point = sd->status.status_point + point;
  1964. }
  1965. if (new_status_point != sd->status.status_point) {
  1966. sd->status.status_point = new_status_point;
  1967. clif_updatestatus(sd, SP_STATUSPOINT);
  1968. clif_displaymessage(fd, msg_txt(sd,174)); // Number of status points changed.
  1969. } else {
  1970. if (point < 0)
  1971. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  1972. else
  1973. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  1974. return -1;
  1975. }
  1976. return 0;
  1977. }
  1978. /*==========================================
  1979. * @skpoint (Rewritten by [Yor])
  1980. *------------------------------------------*/
  1981. ACMD_FUNC(skillpoint)
  1982. {
  1983. int point;
  1984. unsigned int new_skill_point;
  1985. nullpo_retr(-1, sd);
  1986. if (!message || !*message || (point = atoi(message)) == 0) {
  1987. clif_displaymessage(fd, msg_txt(sd,1011)); // Please enter a number (usage: @skpoint <number of points>).
  1988. return -1;
  1989. }
  1990. if(point < 0)
  1991. {
  1992. if(sd->status.skill_point < (unsigned int)(-point))
  1993. {
  1994. new_skill_point = 0;
  1995. }
  1996. else
  1997. {
  1998. new_skill_point = sd->status.skill_point + point;
  1999. }
  2000. }
  2001. else if(UINT_MAX - sd->status.skill_point < (unsigned int)point)
  2002. {
  2003. new_skill_point = UINT_MAX;
  2004. }
  2005. else
  2006. {
  2007. new_skill_point = sd->status.skill_point + point;
  2008. }
  2009. if (new_skill_point != sd->status.skill_point) {
  2010. sd->status.skill_point = new_skill_point;
  2011. clif_updatestatus(sd, SP_SKILLPOINT);
  2012. clif_displaymessage(fd, msg_txt(sd,175)); // Number of skill points changed.
  2013. } else {
  2014. if (point < 0)
  2015. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2016. else
  2017. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2018. return -1;
  2019. }
  2020. return 0;
  2021. }
  2022. /*==========================================
  2023. * @zeny
  2024. *------------------------------------------*/
  2025. ACMD_FUNC(zeny)
  2026. {
  2027. int zeny=0, ret=-1;
  2028. nullpo_retr(-1, sd);
  2029. if (!message || !*message || (zeny = atoi(message)) == 0) {
  2030. clif_displaymessage(fd, msg_txt(sd,1012)); // Please enter an amount (usage: @zeny <amount>).
  2031. return -1;
  2032. }
  2033. if(zeny > 0){
  2034. if((ret=pc_getzeny(sd,zeny,LOG_TYPE_COMMAND,NULL)) == 1)
  2035. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2036. }
  2037. else {
  2038. if( sd->status.zeny < -zeny ) zeny = -sd->status.zeny;
  2039. if((ret=pc_payzeny(sd,-zeny,LOG_TYPE_COMMAND,NULL)) == 1)
  2040. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2041. }
  2042. if(!ret) clif_displaymessage(fd, msg_txt(sd,176)); //ret=0 mean cmd success
  2043. return 0;
  2044. }
  2045. /*==========================================
  2046. *
  2047. *------------------------------------------*/
  2048. ACMD_FUNC(param)
  2049. {
  2050. int i, value = 0, new_value, max;
  2051. const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" };
  2052. short* status[6];
  2053. //we don't use direct initialization because it isn't part of the c standard.
  2054. nullpo_retr(-1, sd);
  2055. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2056. if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2057. clif_displaymessage(fd, msg_txt(sd,1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2058. return -1;
  2059. }
  2060. ARR_FIND( 0, ARRAYLENGTH(param), i, strcmpi(command+1, param[i]) == 0 );
  2061. if( i == ARRAYLENGTH(param) || i > MAX_STATUS_TYPE) { // normally impossible...
  2062. clif_displaymessage(fd, msg_txt(sd,1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>).
  2063. return -1;
  2064. }
  2065. status[0] = &sd->status.str;
  2066. status[1] = &sd->status.agi;
  2067. status[2] = &sd->status.vit;
  2068. status[3] = &sd->status.int_;
  2069. status[4] = &sd->status.dex;
  2070. status[5] = &sd->status.luk;
  2071. if( battle_config.atcommand_max_stat_bypass )
  2072. max = SHRT_MAX;
  2073. else
  2074. max = pc_maxparameter(sd);
  2075. if(value < 0 && *status[i] <= -value) {
  2076. new_value = 1;
  2077. } else if(max - *status[i] < value) {
  2078. new_value = max;
  2079. } else {
  2080. new_value = *status[i] + value;
  2081. }
  2082. if (new_value != *status[i]) {
  2083. *status[i] = new_value;
  2084. clif_updatestatus(sd, SP_STR + i);
  2085. clif_updatestatus(sd, SP_USTR + i);
  2086. status_calc_pc(sd, 0);
  2087. clif_displaymessage(fd, msg_txt(sd,42)); // Stat changed.
  2088. } else {
  2089. if (value < 0)
  2090. clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  2091. else
  2092. clif_displaymessage(fd, msg_txt(sd,149)); // Unable to increase the number/value.
  2093. return -1;
  2094. }
  2095. return 0;
  2096. }
  2097. /*==========================================
  2098. * Stat all by fritz (rewritten by [Yor])
  2099. *------------------------------------------*/
  2100. ACMD_FUNC(stat_all)
  2101. {
  2102. int index, count, value, max, new_value;
  2103. short* status[6];
  2104. //we don't use direct initialization because it isn't part of the c standard.
  2105. nullpo_retr(-1, sd);
  2106. status[0] = &sd->status.str;
  2107. status[1] = &sd->status.agi;
  2108. status[2] = &sd->status.vit;
  2109. status[3] = &sd->status.int_;
  2110. status[4] = &sd->status.dex;
  2111. status[5] = &sd->status.luk;
  2112. if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) {
  2113. value = pc_maxparameter(sd);
  2114. max = pc_maxparameter(sd);
  2115. } else {
  2116. if( battle_config.atcommand_max_stat_bypass )
  2117. max = SHRT_MAX;
  2118. else
  2119. max = pc_maxparameter(sd);
  2120. }
  2121. count = 0;
  2122. for (index = 0; index < ARRAYLENGTH(status); index++) {
  2123. if (value > 0 && *status[index] > max - value)
  2124. new_value = max;
  2125. else if (value < 0 && *status[index] <= -value)
  2126. new_value = 1;
  2127. else
  2128. new_value = *status[index] +value;
  2129. if (new_value != (int)*status[index]) {
  2130. *status[index] = new_value;
  2131. clif_updatestatus(sd, SP_STR + index);
  2132. clif_updatestatus(sd, SP_USTR + index);
  2133. count++;
  2134. }
  2135. }
  2136. if (count > 0) { // if at least 1 stat modified
  2137. status_calc_pc(sd, 0);
  2138. clif_displaymessage(fd, msg_txt(sd,84)); // All stats changed!
  2139. } else {
  2140. if (value < 0)
  2141. clif_displaymessage(fd, msg_txt(sd,177)); // You cannot decrease that stat anymore.
  2142. else
  2143. clif_displaymessage(fd, msg_txt(sd,178)); // You cannot increase that stat anymore.
  2144. return -1;
  2145. }
  2146. return 0;
  2147. }
  2148. /*==========================================
  2149. *
  2150. *------------------------------------------*/
  2151. ACMD_FUNC(guildlevelup)
  2152. {
  2153. int level = 0;
  2154. short added_level;
  2155. struct guild *guild_info;
  2156. nullpo_retr(-1, sd);
  2157. if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) {
  2158. clif_displaymessage(fd, msg_txt(sd,1014)); // Please enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>).
  2159. return -1;
  2160. }
  2161. if (sd->status.guild_id <= 0 || (guild_info = sd->guild) == NULL) {
  2162. clif_displaymessage(fd, msg_txt(sd,43)); // You're not in a guild.
  2163. return -1;
  2164. }
  2165. //if (strcmp(sd->status.name, guild_info->master) != 0) {
  2166. // clif_displaymessage(fd, msg_txt(sd,44)); // You're not the master of your guild.
  2167. // return -1;
  2168. //}
  2169. added_level = (short)level;
  2170. if (level > 0 && (level > MAX_GUILDLEVEL || added_level > ((short)MAX_GUILDLEVEL - guild_info->guild_lv))) // fix positiv overflow
  2171. added_level = (short)MAX_GUILDLEVEL - guild_info->guild_lv;
  2172. else if (level < 0 && (level < -MAX_GUILDLEVEL || added_level < (1 - guild_info->guild_lv))) // fix negativ overflow
  2173. added_level = 1 - guild_info->guild_lv;
  2174. if (added_level != 0) {
  2175. intif_guild_change_basicinfo(guild_info->guild_id, GBI_GUILDLV, &added_level, sizeof(added_level));
  2176. clif_displaymessage(fd, msg_txt(sd,179)); // Guild level changed.
  2177. } else {
  2178. clif_displaymessage(fd, msg_txt(sd,45)); // Guild level change failed.
  2179. return -1;
  2180. }
  2181. return 0;
  2182. }
  2183. /*==========================================
  2184. *
  2185. *------------------------------------------*/
  2186. ACMD_FUNC(makeegg)
  2187. {
  2188. struct item_data *item_data;
  2189. int id, pet_id;
  2190. nullpo_retr(-1, sd);
  2191. if (!message || !*message) {
  2192. clif_displaymessage(fd, msg_txt(sd,1015)); // Please enter a monster/egg name/ID (usage: @makeegg <pet>).
  2193. return -1;
  2194. }
  2195. if ((item_data = itemdb_searchname(message)) != NULL) // for egg name
  2196. id = item_data->nameid;
  2197. else
  2198. if ((id = mobdb_searchname(message)) != 0) // for monster name
  2199. ;
  2200. else
  2201. id = atoi(message);
  2202. pet_id = search_petDB_index(id, PET_CLASS);
  2203. if (pet_id < 0)
  2204. pet_id = search_petDB_index(id, PET_EGG);
  2205. if (pet_id >= 0) {
  2206. sd->catch_target_class = pet_db[pet_id].class_;
  2207. intif_create_pet(
  2208. sd->status.account_id, sd->status.char_id,
  2209. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  2210. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  2211. 100, 0, 1, pet_db[pet_id].jname);
  2212. } else {
  2213. clif_displaymessage(fd, msg_txt(sd,180)); // The monster/egg name/id doesn't exist.
  2214. return -1;
  2215. }
  2216. return 0;
  2217. }
  2218. /*==========================================
  2219. *
  2220. *------------------------------------------*/
  2221. ACMD_FUNC(hatch)
  2222. {
  2223. nullpo_retr(-1, sd);
  2224. if (sd->status.pet_id <= 0)
  2225. clif_sendegg(sd);
  2226. else {
  2227. clif_displaymessage(fd, msg_txt(sd,181)); // You already have a pet.
  2228. return -1;
  2229. }
  2230. return 0;
  2231. }
  2232. /*==========================================
  2233. *
  2234. *------------------------------------------*/
  2235. ACMD_FUNC(petfriendly)
  2236. {
  2237. int friendly;
  2238. struct pet_data *pd;
  2239. nullpo_retr(-1, sd);
  2240. if (!message || !*message || (friendly = atoi(message)) < 0) {
  2241. clif_displaymessage(fd, msg_txt(sd,1016)); // Please enter a valid value (usage: @petfriendly <0-1000>).
  2242. return -1;
  2243. }
  2244. pd = sd->pd;
  2245. if (!pd) {
  2246. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2247. return -1;
  2248. }
  2249. if (friendly < 0 || friendly > 1000)
  2250. {
  2251. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  2252. return -1;
  2253. }
  2254. if (friendly == pd->pet.intimate) {
  2255. clif_displaymessage(fd, msg_txt(sd,183)); // Pet intimacy is already at maximum.
  2256. return -1;
  2257. }
  2258. pet_set_intimate(pd, friendly);
  2259. clif_send_petstatus(sd);
  2260. clif_displaymessage(fd, msg_txt(sd,182)); // Pet intimacy changed.
  2261. return 0;
  2262. }
  2263. /*==========================================
  2264. *
  2265. *------------------------------------------*/
  2266. ACMD_FUNC(pethungry)
  2267. {
  2268. int hungry;
  2269. struct pet_data *pd;
  2270. nullpo_retr(-1, sd);
  2271. if (!message || !*message || (hungry = atoi(message)) < 0) {
  2272. clif_displaymessage(fd, msg_txt(sd,1017)); // Please enter a valid number (usage: @pethungry <0-100>).
  2273. return -1;
  2274. }
  2275. pd = sd->pd;
  2276. if (!sd->status.pet_id || !pd) {
  2277. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2278. return -1;
  2279. }
  2280. if (hungry < 0 || hungry > 100) {
  2281. clif_displaymessage(fd, msg_txt(sd,37)); // An invalid number was specified.
  2282. return -1;
  2283. }
  2284. if (hungry == pd->pet.hungry) {
  2285. clif_displaymessage(fd, msg_txt(sd,186)); // Pet hunger is already at maximum.
  2286. return -1;
  2287. }
  2288. pd->pet.hungry = hungry;
  2289. clif_send_petstatus(sd);
  2290. clif_displaymessage(fd, msg_txt(sd,185)); // Pet hunger changed.
  2291. return 0;
  2292. }
  2293. /*==========================================
  2294. *
  2295. *------------------------------------------*/
  2296. ACMD_FUNC(petrename)
  2297. {
  2298. struct pet_data *pd;
  2299. nullpo_retr(-1, sd);
  2300. if (!sd->status.pet_id || !sd->pd) {
  2301. clif_displaymessage(fd, msg_txt(sd,184)); // Sorry, but you have no pet.
  2302. return -1;
  2303. }
  2304. pd = sd->pd;
  2305. if (!pd->pet.rename_flag) {
  2306. clif_displaymessage(fd, msg_txt(sd,188)); // You can already rename your pet.
  2307. return -1;
  2308. }
  2309. pd->pet.rename_flag = 0;
  2310. intif_save_petdata(sd->status.account_id, &pd->pet);
  2311. clif_send_petstatus(sd);
  2312. clif_displaymessage(fd, msg_txt(sd,187)); // You can now rename your pet.
  2313. return 0;
  2314. }
  2315. /*==========================================
  2316. *
  2317. *------------------------------------------*/
  2318. ACMD_FUNC(recall) {
  2319. struct map_session_data *pl_sd = NULL;
  2320. nullpo_retr(-1, sd);
  2321. if (!message || !*message) {
  2322. clif_displaymessage(fd, msg_txt(sd,1018)); // Please enter a player name (usage: @recall <char name/ID>).
  2323. return -1;
  2324. }
  2325. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2326. {
  2327. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  2328. return -1;
  2329. }
  2330. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  2331. {
  2332. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level doesn't authorize you to preform this action on the specified player.
  2333. return -1;
  2334. }
  2335. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2336. clif_displaymessage(fd, msg_txt(sd,1019)); // You are not authorized to warp someone to this map.
  2337. return -1;
  2338. }
  2339. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2340. clif_displaymessage(fd, msg_txt(sd,1020)); // You are not authorized to warp this player from their map.
  2341. return -1;
  2342. }
  2343. if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y) {
  2344. return -1;
  2345. }
  2346. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  2347. sprintf(atcmd_output, msg_txt(sd,46), pl_sd->status.name); // %s recalled!
  2348. clif_displaymessage(fd, atcmd_output);
  2349. return 0;
  2350. }
  2351. /*==========================================
  2352. * charblock command (usage: charblock <player_name>)
  2353. * This command do a definitiv ban on a player
  2354. *------------------------------------------*/
  2355. ACMD_FUNC(char_block)
  2356. {
  2357. nullpo_retr(-1, sd);
  2358. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2359. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2360. clif_displaymessage(fd, msg_txt(sd,1021)); // Please enter a player name (usage: @charblock/@block <char name>).
  2361. return -1;
  2362. }
  2363. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  2364. clif_displaymessage(fd, msg_txt(sd,88)); // Character name sent to char-server to ask it.
  2365. return 0;
  2366. }
  2367. /*==========================================
  2368. * charban command (usage: charban <time> <player_name>)
  2369. * This command do a limited ban on a player
  2370. * Time is done as follows:
  2371. * Adjustment value (-1, 1, +1, etc...)
  2372. * Modified element:
  2373. * a or y: year
  2374. * m: month
  2375. * j or d: day
  2376. * h: hour
  2377. * mn: minute
  2378. * s: second
  2379. * <example> @ban +1m-2mn1s-6y test_player
  2380. * this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time.
  2381. *------------------------------------------*/
  2382. ACMD_FUNC(char_ban)
  2383. {
  2384. char * modif_p;
  2385. int year, month, day, hour, minute, second, value;
  2386. time_t timestamp;
  2387. struct tm *tmtime;
  2388. nullpo_retr(-1, sd);
  2389. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2390. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2391. if (!message || !*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) {
  2392. clif_displaymessage(fd, msg_txt(sd,1022)); // Please enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish <time> <char name>).
  2393. return -1;
  2394. }
  2395. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  2396. modif_p = atcmd_output;
  2397. year = month = day = hour = minute = second = 0;
  2398. while (modif_p[0] != '\0') {
  2399. value = atoi(modif_p);
  2400. if (value == 0)
  2401. modif_p++;
  2402. else {
  2403. if (modif_p[0] == '-' || modif_p[0] == '+')
  2404. modif_p++;
  2405. while (modif_p[0] >= '0' && modif_p[0] <= '9')
  2406. modif_p++;
  2407. if (modif_p[0] == 's') {
  2408. second = value;
  2409. modif_p++;
  2410. } else if (modif_p[0] == 'n') {
  2411. minute = value;
  2412. modif_p++;
  2413. } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  2414. minute = value;
  2415. modif_p = modif_p + 2;
  2416. } else if (modif_p[0] == 'h') {
  2417. hour = value;
  2418. modif_p++;
  2419. } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  2420. day = value;
  2421. modif_p++;
  2422. } else if (modif_p[0] == 'm') {
  2423. month = value;
  2424. modif_p++;
  2425. } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  2426. year = value;
  2427. modif_p++;
  2428. } else if (modif_p[0] != '\0') {
  2429. modif_p++;
  2430. }
  2431. }
  2432. }
  2433. if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0) {
  2434. clif_displaymessage(fd, msg_txt(sd,85)); // Invalid time for ban command.
  2435. return -1;
  2436. }
  2437. /**
  2438. * We now check if you can adjust the ban to negative (and if this is the case)
  2439. **/
  2440. timestamp = time(NULL);
  2441. tmtime = localtime(&timestamp);
  2442. tmtime->tm_year = tmtime->tm_year + year;
  2443. tmtime->tm_mon = tmtime->tm_mon + month;
  2444. tmtime->tm_mday = tmtime->tm_mday + day;
  2445. tmtime->tm_hour = tmtime->tm_hour + hour;
  2446. tmtime->tm_min = tmtime->tm_min + minute;
  2447. tmtime->tm_sec = tmtime->tm_sec + second;
  2448. timestamp = mktime(tmtime);
  2449. if( timestamp <= time(NULL) && !pc_can_use_command(sd, "unban", COMMAND_ATCOMMAND) ) {
  2450. clif_displaymessage(fd,msg_txt(sd,1023)); // You are not allowed to reduce the length of a ban.
  2451. return -1;
  2452. }
  2453. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 2, year, month, day, hour, minute, second); // type: 2 - ban
  2454. clif_displaymessage(fd, msg_txt(sd,88)); // Character name sent to char-server to ask it.
  2455. return 0;
  2456. }
  2457. /*==========================================
  2458. * charunblock command (usage: charunblock <player_name>)
  2459. *------------------------------------------*/
  2460. ACMD_FUNC(char_unblock)
  2461. {
  2462. nullpo_retr(-1, sd);
  2463. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2464. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2465. clif_displaymessage(fd, msg_txt(sd,1024)); // Please enter a player name (usage: @charunblock <char name>).
  2466. return -1;
  2467. }
  2468. // send answer to login server via char-server
  2469. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 3, 0, 0, 0, 0, 0, 0); // type: 3 - unblock
  2470. clif_displaymessage(fd, msg_txt(sd,88)); // Character name sent to char-server to ask it.
  2471. return 0;
  2472. }
  2473. /*==========================================
  2474. * charunban command (usage: charunban <player_name>)
  2475. *------------------------------------------*/
  2476. ACMD_FUNC(char_unban)
  2477. {
  2478. nullpo_retr(-1, sd);
  2479. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2480. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  2481. clif_displaymessage(fd, msg_txt(sd,1025)); // Please enter a player name (usage: @charunban <char name>).
  2482. return -1;
  2483. }
  2484. // send answer to login server via char-server
  2485. chrif_char_ask_name(sd->status.account_id, atcmd_player_name, 4, 0, 0, 0, 0, 0, 0); // type: 4 - unban
  2486. clif_displaymessage(fd, msg_txt(sd,88)); // Character name sent to char-server to ask it.
  2487. return 0;
  2488. }
  2489. /*==========================================
  2490. *
  2491. *------------------------------------------*/
  2492. ACMD_FUNC(night)
  2493. {
  2494. nullpo_retr(-1, sd);
  2495. if (night_flag != 1) {
  2496. map_night_timer(night_timer_tid, 0, 0, 1);
  2497. } else {
  2498. clif_displaymessage(fd, msg_txt(sd,89)); // Night mode is already enabled.
  2499. return -1;
  2500. }
  2501. return 0;
  2502. }
  2503. /*==========================================
  2504. *
  2505. *------------------------------------------*/
  2506. ACMD_FUNC(day)
  2507. {
  2508. nullpo_retr(-1, sd);
  2509. if (night_flag != 0) {
  2510. map_day_timer(day_timer_tid, 0, 0, 1);
  2511. } else {
  2512. clif_displaymessage(fd, msg_txt(sd,90)); // Day mode is already enabled.
  2513. return -1;
  2514. }
  2515. return 0;
  2516. }
  2517. /*==========================================
  2518. *
  2519. *------------------------------------------*/
  2520. ACMD_FUNC(doom)
  2521. {
  2522. struct map_session_data* pl_sd;
  2523. struct s_mapiterator* iter;
  2524. nullpo_retr(-1, sd);
  2525. iter = mapit_getallusers();
  2526. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2527. {
  2528. if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2529. {
  2530. status_kill(&pl_sd->bl);
  2531. clif_specialeffect(&pl_sd->bl,450,AREA);
  2532. clif_displaymessage(pl_sd->fd, msg_txt(sd,61)); // The holy messenger has given judgement.
  2533. }
  2534. }
  2535. mapit_free(iter);
  2536. clif_displaymessage(fd, msg_txt(sd,62)); // Judgement was made.
  2537. return 0;
  2538. }
  2539. /*==========================================
  2540. *
  2541. *------------------------------------------*/
  2542. ACMD_FUNC(doommap)
  2543. {
  2544. struct map_session_data* pl_sd;
  2545. struct s_mapiterator* iter;
  2546. nullpo_retr(-1, sd);
  2547. iter = mapit_getallusers();
  2548. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2549. {
  2550. if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2551. {
  2552. status_kill(&pl_sd->bl);
  2553. clif_specialeffect(&pl_sd->bl,450,AREA);
  2554. clif_displaymessage(pl_sd->fd, msg_txt(sd,61)); // The holy messenger has given judgement.
  2555. }
  2556. }
  2557. mapit_free(iter);
  2558. clif_displaymessage(fd, msg_txt(sd,62)); // Judgement was made.
  2559. return 0;
  2560. }
  2561. /*==========================================
  2562. *
  2563. *------------------------------------------*/
  2564. static void atcommand_raise_sub(struct map_session_data* sd) {
  2565. status_revive(&sd->bl, 100, 100);
  2566. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  2567. clif_displaymessage(sd->fd, msg_txt(sd,63)); // Mercy has been shown.
  2568. }
  2569. /*==========================================
  2570. *
  2571. *------------------------------------------*/
  2572. ACMD_FUNC(raise)
  2573. {
  2574. struct map_session_data* pl_sd;
  2575. struct s_mapiterator* iter;
  2576. nullpo_retr(-1, sd);
  2577. iter = mapit_getallusers();
  2578. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2579. if( pc_isdead(pl_sd) )
  2580. atcommand_raise_sub(pl_sd);
  2581. mapit_free(iter);
  2582. clif_displaymessage(fd, msg_txt(sd,64)); // Mercy has been granted.
  2583. return 0;
  2584. }
  2585. /*==========================================
  2586. *
  2587. *------------------------------------------*/
  2588. ACMD_FUNC(raisemap)
  2589. {
  2590. struct map_session_data* pl_sd;
  2591. struct s_mapiterator* iter;
  2592. nullpo_retr(-1, sd);
  2593. iter = mapit_getallusers();
  2594. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2595. if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) )
  2596. atcommand_raise_sub(pl_sd);
  2597. mapit_free(iter);
  2598. clif_displaymessage(fd, msg_txt(sd,64)); // Mercy has been granted.
  2599. return 0;
  2600. }
  2601. /*==========================================
  2602. *
  2603. *------------------------------------------*/
  2604. ACMD_FUNC(kick)
  2605. {
  2606. struct map_session_data *pl_sd;
  2607. nullpo_retr(-1, sd);
  2608. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  2609. if (!message || !*message) {
  2610. clif_displaymessage(fd, msg_txt(sd,1026)); // Please enter a player name (usage: @kick <char name/ID>).
  2611. return -1;
  2612. }
  2613. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
  2614. {
  2615. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  2616. return -1;
  2617. }
  2618. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  2619. {
  2620. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  2621. return -1;
  2622. }
  2623. clif_GM_kick(sd, pl_sd);
  2624. return 0;
  2625. }
  2626. /*==========================================
  2627. *
  2628. *------------------------------------------*/
  2629. ACMD_FUNC(kickall)
  2630. {
  2631. struct map_session_data* pl_sd;
  2632. struct s_mapiterator* iter;
  2633. nullpo_retr(-1, sd);
  2634. iter = mapit_getallusers();
  2635. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2636. {
  2637. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level
  2638. if (sd->status.account_id != pl_sd->status.account_id)
  2639. clif_GM_kick(NULL, pl_sd);
  2640. }
  2641. }
  2642. mapit_free(iter);
  2643. clif_displaymessage(fd, msg_txt(sd,195)); // All players have been kicked!
  2644. return 0;
  2645. }
  2646. /*==========================================
  2647. *
  2648. *------------------------------------------*/
  2649. ACMD_FUNC(allskill)
  2650. {
  2651. nullpo_retr(-1, sd);
  2652. pc_allskillup(sd); // all skills
  2653. sd->status.skill_point = 0; // 0 skill points
  2654. clif_updatestatus(sd, SP_SKILLPOINT); // update
  2655. clif_displaymessage(fd, msg_txt(sd,76)); // All skills have been added to your skill tree.
  2656. return 0;
  2657. }
  2658. /*==========================================
  2659. *
  2660. *------------------------------------------*/
  2661. ACMD_FUNC(questskill)
  2662. {
  2663. uint16 skill_id;
  2664. nullpo_retr(-1, sd);
  2665. if (!message || !*message || (skill_id = atoi(message)) <= 0)
  2666. {// also send a list of skills applicable to this command
  2667. const char* text;
  2668. // attempt to find the text corresponding to this command
  2669. text = atcommand_help_string( command );
  2670. // send the error message as always
  2671. clif_displaymessage(fd, msg_txt(sd,1027)); // Please enter a quest skill number.
  2672. if( text )
  2673. {// send the skill ID list associated with this command
  2674. clif_displaymessage( fd, text );
  2675. }
  2676. return -1;
  2677. }
  2678. if (skill_id >= MAX_SKILL_DB) {
  2679. clif_displaymessage(fd, msg_txt(sd,198)); // This skill number doesn't exist.
  2680. return -1;
  2681. }
  2682. if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  2683. clif_displaymessage(fd, msg_txt(sd,197)); // This skill number doesn't exist or isn't a quest skill.
  2684. return -1;
  2685. }
  2686. if (pc_checkskill(sd, skill_id) > 0) {
  2687. clif_displaymessage(fd, msg_txt(sd,196)); // You already have this quest skill.
  2688. return -1;
  2689. }
  2690. pc_skill(sd, skill_id, 1, 0);
  2691. clif_displaymessage(fd, msg_txt(sd,70)); // You have learned the skill.
  2692. return 0;
  2693. }
  2694. /*==========================================
  2695. *
  2696. *------------------------------------------*/
  2697. ACMD_FUNC(lostskill)
  2698. {
  2699. uint16 skill_id;
  2700. nullpo_retr(-1, sd);
  2701. if (!message || !*message || (skill_id = atoi(message)) <= 0)
  2702. {// also send a list of skills applicable to this command
  2703. const char* text;
  2704. // attempt to find the text corresponding to this command
  2705. text = atcommand_help_string( command );
  2706. // send the error message as always
  2707. clif_displaymessage(fd, msg_txt(sd,1027)); // Please enter a quest skill number.
  2708. if( text )
  2709. {// send the skill ID list associated with this command
  2710. clif_displaymessage( fd, text );
  2711. }
  2712. return -1;
  2713. }
  2714. if (skill_id >= MAX_SKILL) {
  2715. clif_displaymessage(fd, msg_txt(sd,198)); // This skill number doesn't exist.
  2716. return -1;
  2717. }
  2718. if (!(skill_get_inf2(skill_id) & INF2_QUEST_SKILL)) {
  2719. clif_displaymessage(fd, msg_txt(sd,197)); // This skill number doesn't exist or isn't a quest skill.
  2720. return -1;
  2721. }
  2722. if (pc_checkskill(sd, skill_id) == 0) {
  2723. clif_displaymessage(fd, msg_txt(sd,201)); // You don't have this quest skill.
  2724. return -1;
  2725. }
  2726. sd->status.skill[skill_id].lv = 0;
  2727. sd->status.skill[skill_id].flag = SKILL_FLAG_PERMANENT;
  2728. clif_deleteskill(sd,skill_id);
  2729. clif_displaymessage(fd, msg_txt(sd,71)); // You have forgotten the skill.
  2730. return 0;
  2731. }
  2732. /*==========================================
  2733. *
  2734. *------------------------------------------*/
  2735. ACMD_FUNC(spiritball)
  2736. {
  2737. int max_spiritballs;
  2738. int number;
  2739. nullpo_retr(-1, sd);
  2740. max_spiritballs = min(ARRAYLENGTH(sd->spirit_timer), 0x7FFF);
  2741. if( !message || !*message || (number = atoi(message)) < 0 || number > max_spiritballs )
  2742. {
  2743. char msg[CHAT_SIZE_MAX];
  2744. safesnprintf(msg, sizeof(msg), msg_txt(sd,1028), max_spiritballs); // Please enter a party name (usage: @party <party_name>).
  2745. clif_displaymessage(fd, msg);
  2746. return -1;
  2747. }
  2748. if( sd->spiritball > 0 )
  2749. pc_delspiritball(sd, sd->spiritball, 1);
  2750. sd->spiritball = number;
  2751. clif_spiritball(&sd->bl);
  2752. // no message, player can look the difference
  2753. return 0;
  2754. }
  2755. /*==========================================
  2756. *
  2757. *------------------------------------------*/
  2758. ACMD_FUNC(party)
  2759. {
  2760. char party[NAME_LENGTH];
  2761. nullpo_retr(-1, sd);
  2762. memset(party, '\0', sizeof(party));
  2763. if (!message || !*message || sscanf(message, "%23[^\n]", party) < 1) {
  2764. clif_displaymessage(fd, msg_txt(sd,1029)); // Please enter a party name (usage: @party <party_name>).
  2765. return -1;
  2766. }
  2767. party_create(sd, party, 0, 0);
  2768. return 0;
  2769. }
  2770. /*==========================================
  2771. *
  2772. *------------------------------------------*/
  2773. ACMD_FUNC(guild)
  2774. {
  2775. char guild[NAME_LENGTH];
  2776. int prev;
  2777. nullpo_retr(-1, sd);
  2778. memset(guild, '\0', sizeof(guild));
  2779. if (!message || !*message || sscanf(message, "%23[^\n]", guild) < 1) {
  2780. clif_displaymessage(fd, msg_txt(sd,1030)); // Please enter a guild name (usage: @guild <guild_name>).
  2781. return -1;
  2782. }
  2783. prev = battle_config.guild_emperium_check;
  2784. battle_config.guild_emperium_check = 0;
  2785. guild_create(sd, guild);
  2786. battle_config.guild_emperium_check = prev;
  2787. return 0;
  2788. }
  2789. ACMD_FUNC(breakguild)
  2790. {
  2791. nullpo_retr(-1, sd);
  2792. if (sd->status.guild_id) { // Check if the player has a guild
  2793. struct guild *g;
  2794. g = sd->guild; // Search the guild
  2795. if (g) { // Check if guild was found
  2796. if (sd->state.gmaster_flag) { // Check if player is guild master
  2797. int ret = 0;
  2798. ret = guild_break(sd, g->name); // Break guild
  2799. if (ret) { // Check if anything went wrong
  2800. return 0; // Guild was broken
  2801. } else {
  2802. return -1; // Something went wrong
  2803. }
  2804. } else { // Not guild master
  2805. clif_displaymessage(fd, msg_txt(sd,1181)); // You need to be a Guild Master to use this command.
  2806. return -1;
  2807. }
  2808. } else { // Guild was not found. HOW?
  2809. clif_displaymessage(fd, msg_txt(sd,252)); // You are not in a guild.
  2810. return -1;
  2811. }
  2812. } else { // Player does not have a guild
  2813. clif_displaymessage(fd, msg_txt(sd,252)); // You are not in a guild.
  2814. return -1;
  2815. }
  2816. return 0;
  2817. }
  2818. /*==========================================
  2819. *
  2820. *------------------------------------------*/
  2821. ACMD_FUNC(agitstart)
  2822. {
  2823. nullpo_retr(-1, sd);
  2824. if (agit_flag == 1) {
  2825. clif_displaymessage(fd, msg_txt(sd,73)); // War of Emperium is currently in progress.
  2826. return -1;
  2827. }
  2828. agit_flag = 1;
  2829. guild_agit_start();
  2830. clif_displaymessage(fd, msg_txt(sd,72)); // War of Emperium has been initiated.
  2831. return 0;
  2832. }
  2833. /*==========================================
  2834. *
  2835. *------------------------------------------*/
  2836. ACMD_FUNC(agitstart2)
  2837. {
  2838. nullpo_retr(-1, sd);
  2839. if (agit2_flag == 1) {
  2840. clif_displaymessage(fd, msg_txt(sd,404)); // "War of Emperium SE is currently in progress."
  2841. return -1;
  2842. }
  2843. agit2_flag = 1;
  2844. guild_agit2_start();
  2845. clif_displaymessage(fd, msg_txt(sd,403)); // "War of Emperium SE has been initiated."
  2846. return 0;
  2847. }
  2848. /*==========================================
  2849. *
  2850. *------------------------------------------*/
  2851. ACMD_FUNC(agitend)
  2852. {
  2853. nullpo_retr(-1, sd);
  2854. if (agit_flag == 0) {
  2855. clif_displaymessage(fd, msg_txt(sd,75)); // War of Emperium is currently not in progress.
  2856. return -1;
  2857. }
  2858. agit_flag = 0;
  2859. guild_agit_end();
  2860. clif_displaymessage(fd, msg_txt(sd,74)); // War of Emperium has been ended.
  2861. return 0;
  2862. }
  2863. /*==========================================
  2864. *
  2865. *------------------------------------------*/
  2866. ACMD_FUNC(agitend2)
  2867. {
  2868. nullpo_retr(-1, sd);
  2869. if (agit2_flag == 0) {
  2870. clif_displaymessage(fd, msg_txt(sd,406)); // "War of Emperium SE is currently not in progress."
  2871. return -1;
  2872. }
  2873. agit2_flag = 0;
  2874. guild_agit2_end();
  2875. clif_displaymessage(fd, msg_txt(sd,405)); // "War of Emperium SE has been ended."
  2876. return 0;
  2877. }
  2878. /*==========================================
  2879. * @mapexit - shuts down the map server
  2880. *------------------------------------------*/
  2881. ACMD_FUNC(mapexit)
  2882. {
  2883. nullpo_retr(-1, sd);
  2884. do_shutdown();
  2885. return 0;
  2886. }
  2887. /*==========================================
  2888. * idsearch <part_of_name>: revrited by [Yor]
  2889. *------------------------------------------*/
  2890. ACMD_FUNC(idsearch)
  2891. {
  2892. char item_name[100];
  2893. unsigned int i, match;
  2894. struct item_data *item_array[MAX_SEARCH];
  2895. nullpo_retr(-1, sd);
  2896. memset(item_name, '\0', sizeof(item_name));
  2897. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2898. if (!message || !*message || sscanf(message, "%99s", item_name) < 0) {
  2899. clif_displaymessage(fd, msg_txt(sd,1031)); // Please enter part of an item name (usage: @idsearch <part_of_item_name>).
  2900. return -1;
  2901. }
  2902. sprintf(atcmd_output, msg_txt(sd,77), item_name); // The reference result of '%s' (name: id):
  2903. clif_displaymessage(fd, atcmd_output);
  2904. match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name);
  2905. if (match > MAX_SEARCH) {
  2906. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH, match);
  2907. clif_displaymessage(fd, atcmd_output);
  2908. match = MAX_SEARCH;
  2909. }
  2910. for(i = 0; i < match; i++) {
  2911. sprintf(atcmd_output, msg_txt(sd,78), item_array[i]->jname, item_array[i]->nameid); // %s: %d
  2912. clif_displaymessage(fd, atcmd_output);
  2913. }
  2914. sprintf(atcmd_output, msg_txt(sd,79), match); // It is %d affair above.
  2915. clif_displaymessage(fd, atcmd_output);
  2916. return 0;
  2917. }
  2918. /*==========================================
  2919. * Recall All Characters Online To Your Location
  2920. *------------------------------------------*/
  2921. ACMD_FUNC(recallall)
  2922. {
  2923. struct map_session_data* pl_sd;
  2924. struct s_mapiterator* iter;
  2925. int count;
  2926. nullpo_retr(-1, sd);
  2927. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2928. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2929. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp somenone to your current map.
  2930. return -1;
  2931. }
  2932. count = 0;
  2933. iter = mapit_getallusers();
  2934. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2935. {
  2936. if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd))
  2937. {
  2938. if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y)
  2939. continue; // Don't waste time warping the character to the same place.
  2940. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  2941. count++;
  2942. else {
  2943. if (pc_isdead(pl_sd)) { //Wake them up
  2944. pc_setstand(pl_sd);
  2945. pc_setrestartvalue(pl_sd,1);
  2946. }
  2947. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  2948. }
  2949. }
  2950. }
  2951. mapit_free(iter);
  2952. clif_displaymessage(fd, msg_txt(sd,92)); // All characters recalled!
  2953. if (count) {
  2954. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  2955. clif_displaymessage(fd, atcmd_output);
  2956. }
  2957. return 0;
  2958. }
  2959. /*==========================================
  2960. * Recall online characters of a guild to your location
  2961. *------------------------------------------*/
  2962. ACMD_FUNC(guildrecall)
  2963. {
  2964. struct map_session_data* pl_sd;
  2965. struct s_mapiterator* iter;
  2966. int count;
  2967. char guild_name[NAME_LENGTH];
  2968. struct guild *g;
  2969. nullpo_retr(-1, sd);
  2970. memset(guild_name, '\0', sizeof(guild_name));
  2971. memset(atcmd_output, '\0', sizeof(atcmd_output));
  2972. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  2973. clif_displaymessage(fd, msg_txt(sd,1034)); // Please enter a guild name/ID (usage: @guildrecall <guild_name/ID>).
  2974. return -1;
  2975. }
  2976. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  2977. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp somenone to your current map.
  2978. return -1;
  2979. }
  2980. if ((g = guild_searchname(guild_name)) == NULL && // name first to avoid error when name begin with a number
  2981. (g = guild_search(atoi(message))) == NULL)
  2982. {
  2983. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  2984. return -1;
  2985. }
  2986. count = 0;
  2987. iter = mapit_getallusers();
  2988. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  2989. {
  2990. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id)
  2991. {
  2992. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y))
  2993. continue; // Skip GMs greater than you... or chars already on the cell
  2994. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  2995. count++;
  2996. else
  2997. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  2998. }
  2999. }
  3000. mapit_free(iter);
  3001. sprintf(atcmd_output, msg_txt(sd,93), g->name); // All online characters of the %s guild have been recalled to your position.
  3002. clif_displaymessage(fd, atcmd_output);
  3003. if (count) {
  3004. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3005. clif_displaymessage(fd, atcmd_output);
  3006. }
  3007. return 0;
  3008. }
  3009. /*==========================================
  3010. * Recall online characters of a party to your location
  3011. *------------------------------------------*/
  3012. ACMD_FUNC(partyrecall)
  3013. {
  3014. struct map_session_data* pl_sd;
  3015. struct s_mapiterator* iter;
  3016. char party_name[NAME_LENGTH];
  3017. struct party_data *p;
  3018. int count;
  3019. nullpo_retr(-1, sd);
  3020. memset(party_name, '\0', sizeof(party_name));
  3021. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3022. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3023. clif_displaymessage(fd, msg_txt(sd,1035)); // Please enter a party name/ID (usage: @partyrecall <party_name/ID>).
  3024. return -1;
  3025. }
  3026. if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
  3027. clif_displaymessage(fd, msg_txt(sd,1032)); // You are not authorized to warp somenone to your current map.
  3028. return -1;
  3029. }
  3030. if ((p = party_searchname(party_name)) == NULL && // name first to avoid error when name begin with a number
  3031. (p = party_search(atoi(message))) == NULL)
  3032. {
  3033. clif_displaymessage(fd, msg_txt(sd,96)); // Incorrect name or ID, or no one from the party is online.
  3034. return -1;
  3035. }
  3036. count = 0;
  3037. iter = mapit_getallusers();
  3038. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3039. {
  3040. if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id)
  3041. {
  3042. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y))
  3043. continue; // Skip GMs greater than you... or chars already on the cell
  3044. if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
  3045. count++;
  3046. else
  3047. pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
  3048. }
  3049. }
  3050. mapit_free(iter);
  3051. sprintf(atcmd_output, msg_txt(sd,95), p->party.name); // All online characters of the %s party have been recalled to your position.
  3052. clif_displaymessage(fd, atcmd_output);
  3053. if (count) {
  3054. sprintf(atcmd_output, msg_txt(sd,1033), count); // Because you are not authorized to warp from some maps, %d player(s) have not been recalled.
  3055. clif_displaymessage(fd, atcmd_output);
  3056. }
  3057. return 0;
  3058. }
  3059. /*==========================================
  3060. *
  3061. *------------------------------------------*/
  3062. ACMD_FUNC(reloaditemdb)
  3063. {
  3064. nullpo_retr(-1, sd);
  3065. itemdb_reload();
  3066. clif_displaymessage(fd, msg_txt(sd,97)); // Item database has been reloaded.
  3067. return 0;
  3068. }
  3069. /*==========================================
  3070. *
  3071. *------------------------------------------*/
  3072. ACMD_FUNC(reloadmobdb)
  3073. {
  3074. nullpo_retr(-1, sd);
  3075. mob_reload();
  3076. read_petdb();
  3077. merc_reload();
  3078. read_mercenarydb();
  3079. read_mercenary_skilldb();
  3080. reload_elementaldb();
  3081. clif_displaymessage(fd, msg_txt(sd,98)); // Monster database has been reloaded.
  3082. return 0;
  3083. }
  3084. /*==========================================
  3085. *
  3086. *------------------------------------------*/
  3087. ACMD_FUNC(reloadskilldb)
  3088. {
  3089. nullpo_retr(-1, sd);
  3090. skill_reload();
  3091. merc_skill_reload();
  3092. reload_elemental_skilldb();
  3093. read_mercenary_skilldb();
  3094. clif_displaymessage(fd, msg_txt(sd,99)); // Skill database has been reloaded.
  3095. return 0;
  3096. }
  3097. /*==========================================
  3098. * @reloadatcommand - reloads atcommand_athena.conf groups.conf
  3099. *------------------------------------------*/
  3100. void atcommand_doload();
  3101. ACMD_FUNC(reloadatcommand) {
  3102. config_t run_test;
  3103. if (conf_read_file(&run_test, "conf/groups.conf")) {
  3104. clif_displaymessage(fd, msg_txt(sd,1036)); // Error reading groups.conf, reload failed.
  3105. return -1;
  3106. }
  3107. config_destroy(&run_test);
  3108. if (conf_read_file(&run_test, ATCOMMAND_CONF_FILENAME)) {
  3109. clif_displaymessage(fd, msg_txt(sd,1037)); // Error reading atcommand_athena.conf, reload failed.
  3110. return -1;
  3111. }
  3112. config_destroy(&run_test);
  3113. atcommand_doload();
  3114. pc_groups_reload();
  3115. clif_displaymessage(fd, msg_txt(sd,254));
  3116. return 0;
  3117. }
  3118. /*==========================================
  3119. * @reloadbattleconf - reloads battle_athena.conf
  3120. *------------------------------------------*/
  3121. ACMD_FUNC(reloadbattleconf)
  3122. {
  3123. struct Battle_Config prev_config;
  3124. memcpy(&prev_config, &battle_config, sizeof(prev_config));
  3125. battle_config_read(BATTLE_CONF_FILENAME);
  3126. if( prev_config.item_rate_mvp != battle_config.item_rate_mvp
  3127. || prev_config.item_rate_common != battle_config.item_rate_common
  3128. || prev_config.item_rate_common_boss != battle_config.item_rate_common_boss
  3129. || prev_config.item_rate_card != battle_config.item_rate_card
  3130. || prev_config.item_rate_card_boss != battle_config.item_rate_card_boss
  3131. || prev_config.item_rate_equip != battle_config.item_rate_equip
  3132. || prev_config.item_rate_equip_boss != battle_config.item_rate_equip_boss
  3133. || prev_config.item_rate_heal != battle_config.item_rate_heal
  3134. || prev_config.item_rate_heal_boss != battle_config.item_rate_heal_boss
  3135. || prev_config.item_rate_use != battle_config.item_rate_use
  3136. || prev_config.item_rate_use_boss != battle_config.item_rate_use_boss
  3137. || prev_config.item_rate_treasure != battle_config.item_rate_treasure
  3138. || prev_config.item_rate_adddrop != battle_config.item_rate_adddrop
  3139. || prev_config.logarithmic_drops != battle_config.logarithmic_drops
  3140. || prev_config.item_drop_common_min != battle_config.item_drop_common_min
  3141. || prev_config.item_drop_common_max != battle_config.item_drop_common_max
  3142. || prev_config.item_drop_card_min != battle_config.item_drop_card_min
  3143. || prev_config.item_drop_card_max != battle_config.item_drop_card_max
  3144. || prev_config.item_drop_equip_min != battle_config.item_drop_equip_min
  3145. || prev_config.item_drop_equip_max != battle_config.item_drop_equip_max
  3146. || prev_config.item_drop_mvp_min != battle_config.item_drop_mvp_min
  3147. || prev_config.item_drop_mvp_max != battle_config.item_drop_mvp_max
  3148. || prev_config.item_drop_heal_min != battle_config.item_drop_heal_min
  3149. || prev_config.item_drop_heal_max != battle_config.item_drop_heal_max
  3150. || prev_config.item_drop_use_min != battle_config.item_drop_use_min
  3151. || prev_config.item_drop_use_max != battle_config.item_drop_use_max
  3152. || prev_config.item_drop_treasure_min != battle_config.item_drop_treasure_min
  3153. || prev_config.item_drop_treasure_max != battle_config.item_drop_treasure_max
  3154. || prev_config.base_exp_rate != battle_config.base_exp_rate
  3155. || prev_config.job_exp_rate != battle_config.job_exp_rate
  3156. )
  3157. { // Exp or Drop rates changed.
  3158. mob_reload(); //Needed as well so rate changes take effect.
  3159. chrif_ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
  3160. }
  3161. clif_displaymessage(fd, msg_txt(sd,255));
  3162. return 0;
  3163. }
  3164. /*==========================================
  3165. * @reloadstatusdb - reloads job_db1.txt job_db2.txt job_db2-2.txt refine_db.txt size_fix.txt
  3166. *------------------------------------------*/
  3167. ACMD_FUNC(reloadstatusdb)
  3168. {
  3169. status_readdb();
  3170. clif_displaymessage(fd, msg_txt(sd,256));
  3171. return 0;
  3172. }
  3173. /*==========================================
  3174. * @reloadpcdb - reloads exp.txt skill_tree.txt attr_fix.txt statpoint.txt
  3175. *------------------------------------------*/
  3176. ACMD_FUNC(reloadpcdb)
  3177. {
  3178. pc_readdb();
  3179. clif_displaymessage(fd, msg_txt(sd,257));
  3180. return 0;
  3181. }
  3182. /*==========================================
  3183. * @reloadmotd - reloads motd.txt
  3184. *------------------------------------------*/
  3185. ACMD_FUNC(reloadmotd)
  3186. {
  3187. pc_read_motd();
  3188. clif_displaymessage(fd, msg_txt(sd,268));
  3189. return 0;
  3190. }
  3191. /*==========================================
  3192. * @reloadscript - reloads all scripts (npcs, warps, mob spawns, ...)
  3193. *------------------------------------------*/
  3194. ACMD_FUNC(reloadscript)
  3195. {
  3196. nullpo_retr(-1, sd);
  3197. //atcommand_broadcast( fd, sd, "@broadcast", "Server is reloading scripts..." );
  3198. //atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
  3199. flush_fifos();
  3200. map_reloadnpc(true); // reload config files seeking for npcs
  3201. script_reload();
  3202. npc_reload();
  3203. clif_displaymessage(fd, msg_txt(sd,100)); // Scripts have been reloaded.
  3204. return 0;
  3205. }
  3206. /*==========================================
  3207. * @mapinfo [0-3] <map name> by MC_Cameri
  3208. * => Shows information about the map [map name]
  3209. * 0 = no additional information
  3210. * 1 = Show users in that map and their location
  3211. * 2 = Shows NPCs in that map
  3212. * 3 = Shows the chats in that map
  3213. *------------------------------------------*/
  3214. ACMD_FUNC(mapinfo) {
  3215. struct map_session_data* pl_sd;
  3216. struct s_mapiterator* iter;
  3217. struct npc_data *nd = NULL;
  3218. struct chat_data *cd = NULL;
  3219. char direction[12];
  3220. int i, m_id, chat_num = 0, list = 0, vend_num = 0;
  3221. unsigned short m_index;
  3222. char mapname[24];
  3223. nullpo_retr(-1, sd);
  3224. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3225. memset(mapname, '\0', sizeof(mapname));
  3226. memset(direction, '\0', sizeof(direction));
  3227. sscanf(message, "%d %23[^\n]", &list, mapname);
  3228. if (list < 0 || list > 3) {
  3229. clif_displaymessage(fd, msg_txt(sd,1038)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3230. return -1;
  3231. }
  3232. if (mapname[0] == '\0') {
  3233. safestrncpy(mapname, mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  3234. m_id = map_mapindex2mapid(sd->mapindex);
  3235. } else {
  3236. m_id = map_mapname2mapid(mapname);
  3237. }
  3238. if (m_id < 0) {
  3239. clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
  3240. return -1;
  3241. }
  3242. m_index = mapindex_name2id(mapname); //This one shouldn't fail since the previous seek did not.
  3243. clif_displaymessage(fd, msg_txt(sd,1039)); // ------ Map Info ------
  3244. // count chats (for initial message)
  3245. chat_num = 0;
  3246. iter = mapit_getallusers();
  3247. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) {
  3248. if( pl_sd->mapindex == m_index ) {
  3249. if( pl_sd->state.vending )
  3250. vend_num++;
  3251. else if( (cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL && cd->usersd[0] == pl_sd )
  3252. chat_num++;
  3253. }
  3254. }
  3255. mapit_free(iter);
  3256. sprintf(atcmd_output, msg_txt(sd,1040), mapname, map[m_id].users, map[m_id].npc_num, chat_num, vend_num); // Map: %s | Players: %d | NPCs: %d | Chats: %d | Vendings: %d
  3257. clif_displaymessage(fd, atcmd_output);
  3258. clif_displaymessage(fd, msg_txt(sd,1041)); // ------ Map Flags ------
  3259. if (map[m_id].flag.town)
  3260. clif_displaymessage(fd, msg_txt(sd,1042)); // Town Map
  3261. if (battle_config.autotrade_mapflag == map[m_id].flag.autotrade)
  3262. clif_displaymessage(fd, msg_txt(sd,1043)); // Autotrade Enabled
  3263. else
  3264. clif_displaymessage(fd, msg_txt(sd,1044)); // Autotrade Disabled
  3265. if (map[m_id].flag.battleground)
  3266. clif_displaymessage(fd, msg_txt(sd,1045)); // Battlegrounds ON
  3267. strcpy(atcmd_output,msg_txt(sd,1046)); // PvP Flags:
  3268. if (map[m_id].flag.pvp)
  3269. strcat(atcmd_output, msg_txt(sd,1047)); // Pvp ON |
  3270. if (map[m_id].flag.pvp_noguild)
  3271. strcat(atcmd_output, msg_txt(sd,1048)); // NoGuild |
  3272. if (map[m_id].flag.pvp_noparty)
  3273. strcat(atcmd_output, msg_txt(sd,1049)); // NoParty |
  3274. if (map[m_id].flag.pvp_nightmaredrop)
  3275. strcat(atcmd_output, msg_txt(sd,1050)); // NightmareDrop |
  3276. if (map[m_id].flag.pvp_nocalcrank)
  3277. strcat(atcmd_output, msg_txt(sd,1051)); // NoCalcRank |
  3278. clif_displaymessage(fd, atcmd_output);
  3279. strcpy(atcmd_output,msg_txt(sd,1052)); // GvG Flags:
  3280. if (map[m_id].flag.gvg)
  3281. strcat(atcmd_output, msg_txt(sd,1053)); // GvG ON |
  3282. if (map[m_id].flag.gvg_dungeon)
  3283. strcat(atcmd_output, msg_txt(sd,1054)); // GvG Dungeon |
  3284. if (map[m_id].flag.gvg_castle)
  3285. strcat(atcmd_output, msg_txt(sd,1055)); // GvG Castle |
  3286. if (map[m_id].flag.gvg_noparty)
  3287. strcat(atcmd_output, msg_txt(sd,1056)); // NoParty |
  3288. clif_displaymessage(fd, atcmd_output);
  3289. strcpy(atcmd_output,msg_txt(sd,1057)); // Teleport Flags:
  3290. if (map[m_id].flag.noteleport)
  3291. strcat(atcmd_output, msg_txt(sd,1058)); // NoTeleport |
  3292. if (map[m_id].flag.monster_noteleport)
  3293. strcat(atcmd_output, msg_txt(sd,1059)); // Monster NoTeleport |
  3294. if (map[m_id].flag.nowarp)
  3295. strcat(atcmd_output, msg_txt(sd,1060)); // NoWarp |
  3296. if (map[m_id].flag.nowarpto)
  3297. strcat(atcmd_output, msg_txt(sd,1061)); // NoWarpTo |
  3298. if (map[m_id].flag.noreturn)
  3299. strcat(atcmd_output, msg_txt(sd,1062)); // NoReturn |
  3300. if (map[m_id].flag.nogo)
  3301. strcat(atcmd_output, msg_txt(sd,1063)); // NoGo |
  3302. if (map[m_id].flag.nomemo)
  3303. strcat(atcmd_output, msg_txt(sd,1064)); // NoMemo |
  3304. clif_displaymessage(fd, atcmd_output);
  3305. sprintf(atcmd_output, msg_txt(sd,1065), // No Exp Penalty: %s | No Zeny Penalty: %s
  3306. (map[m_id].flag.noexppenalty) ? msg_txt(sd,1066) : msg_txt(sd,1067), (map[m_id].flag.nozenypenalty) ? msg_txt(sd,1066) : msg_txt(sd,1067)); // On / Off
  3307. clif_displaymessage(fd, atcmd_output);
  3308. if (map[m_id].flag.nosave) {
  3309. if (!map[m_id].save.map)
  3310. clif_displaymessage(fd, msg_txt(sd,1068)); // No Save (Return to last Save Point)
  3311. else if (map[m_id].save.x == -1 || map[m_id].save.y == -1 ) {
  3312. sprintf(atcmd_output, msg_txt(sd,1069), mapindex_id2name(map[m_id].save.map)); // No Save, Save Point: %s,Random
  3313. clif_displaymessage(fd, atcmd_output);
  3314. }
  3315. else {
  3316. sprintf(atcmd_output, msg_txt(sd,1070), // No Save, Save Point: %s,%d,%d
  3317. mapindex_id2name(map[m_id].save.map),map[m_id].save.x,map[m_id].save.y);
  3318. clif_displaymessage(fd, atcmd_output);
  3319. }
  3320. }
  3321. strcpy(atcmd_output,msg_txt(sd,1071)); // Weather Flags:
  3322. if (map[m_id].flag.snow)
  3323. strcat(atcmd_output, msg_txt(sd,1072)); // Snow |
  3324. if (map[m_id].flag.fog)
  3325. strcat(atcmd_output, msg_txt(sd,1073)); // Fog |
  3326. if (map[m_id].flag.sakura)
  3327. strcat(atcmd_output, msg_txt(sd,1074)); // Sakura |
  3328. if (map[m_id].flag.clouds)
  3329. strcat(atcmd_output, msg_txt(sd,1075)); // Clouds |
  3330. if (map[m_id].flag.clouds2)
  3331. strcat(atcmd_output, msg_txt(sd,1076)); // Clouds2 |
  3332. if (map[m_id].flag.fireworks)
  3333. strcat(atcmd_output, msg_txt(sd,1077)); // Fireworks |
  3334. if (map[m_id].flag.leaves)
  3335. strcat(atcmd_output, msg_txt(sd,1078)); // Leaves |
  3336. if (map[m_id].flag.nightenabled)
  3337. strcat(atcmd_output, msg_txt(sd,1080)); // Displays Night |
  3338. clif_displaymessage(fd, atcmd_output);
  3339. strcpy(atcmd_output,msg_txt(sd,1081)); // Other Flags:
  3340. if (map[m_id].flag.nobranch)
  3341. strcat(atcmd_output, msg_txt(sd,1082)); // NoBranch |
  3342. if (map[m_id].flag.notrade)
  3343. strcat(atcmd_output, msg_txt(sd,1083)); // NoTrade |
  3344. if (map[m_id].flag.novending)
  3345. strcat(atcmd_output, msg_txt(sd,1084)); // NoVending |
  3346. if (map[m_id].flag.nodrop)
  3347. strcat(atcmd_output, msg_txt(sd,1085)); // NoDrop |
  3348. if (map[m_id].flag.noskill)
  3349. strcat(atcmd_output, msg_txt(sd,1086)); // NoSkill |
  3350. if (map[m_id].flag.noicewall)
  3351. strcat(atcmd_output, msg_txt(sd,1087)); // NoIcewall |
  3352. if (map[m_id].flag.allowks)
  3353. strcat(atcmd_output, msg_txt(sd,1088)); // AllowKS |
  3354. if (map[m_id].flag.reset)
  3355. strcat(atcmd_output, msg_txt(sd,1089)); // Reset |
  3356. clif_displaymessage(fd, atcmd_output);
  3357. strcpy(atcmd_output,msg_txt(sd,1090)); // Other Flags:
  3358. if (map[m_id].nocommand)
  3359. strcat(atcmd_output, msg_txt(sd,1091)); // NoCommand |
  3360. if (map[m_id].flag.nobaseexp)
  3361. strcat(atcmd_output, msg_txt(sd,1092)); // NoBaseEXP |
  3362. if (map[m_id].flag.nojobexp)
  3363. strcat(atcmd_output, msg_txt(sd,1093)); // NoJobEXP |
  3364. if (map[m_id].flag.nomobloot)
  3365. strcat(atcmd_output, msg_txt(sd,1094)); // NoMobLoot |
  3366. if (map[m_id].flag.nomvploot)
  3367. strcat(atcmd_output, msg_txt(sd,1095)); // NoMVPLoot |
  3368. if (map[m_id].flag.partylock)
  3369. strcat(atcmd_output, msg_txt(sd,1096)); // PartyLock |
  3370. if (map[m_id].flag.guildlock)
  3371. strcat(atcmd_output, msg_txt(sd,1097)); // GuildLock |
  3372. clif_displaymessage(fd, atcmd_output);
  3373. switch (list) {
  3374. case 0:
  3375. // Do nothing. It's list 0, no additional display.
  3376. break;
  3377. case 1:
  3378. clif_displaymessage(fd, msg_txt(sd,1098)); // ----- Players in Map -----
  3379. iter = mapit_getallusers();
  3380. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3381. {
  3382. if (pl_sd->mapindex == m_index) {
  3383. sprintf(atcmd_output, msg_txt(sd,1099), // Player '%s' (session #%d) | Location: %d,%d
  3384. pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y);
  3385. clif_displaymessage(fd, atcmd_output);
  3386. }
  3387. }
  3388. mapit_free(iter);
  3389. break;
  3390. case 2:
  3391. clif_displaymessage(fd, msg_txt(sd,1100)); // ----- NPCs in Map -----
  3392. for (i = 0; i < map[m_id].npc_num;)
  3393. {
  3394. nd = map[m_id].npc[i];
  3395. switch(nd->ud.dir) {
  3396. case 0: strcpy(direction, msg_txt(sd,1101)); break; // North
  3397. case 1: strcpy(direction, msg_txt(sd,1102)); break; // North West
  3398. case 2: strcpy(direction, msg_txt(sd,1103)); break; // West
  3399. case 3: strcpy(direction, msg_txt(sd,1104)); break; // South West
  3400. case 4: strcpy(direction, msg_txt(sd,1105)); break; // South
  3401. case 5: strcpy(direction, msg_txt(sd,1106)); break; // South East
  3402. case 6: strcpy(direction, msg_txt(sd,1107)); break; // East
  3403. case 7: strcpy(direction, msg_txt(sd,1108)); break; // North East
  3404. case 9: strcpy(direction, msg_txt(sd,1109)); break; // North
  3405. default: strcpy(direction, msg_txt(sd,1110)); break; // Unknown
  3406. }
  3407. if(strcmp(nd->name,nd->exname) == 0)
  3408. sprintf(atcmd_output, msg_txt(sd,1111), // NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d
  3409. ++i, nd->name, direction, nd->class_, nd->bl.x, nd->bl.y);
  3410. else
  3411. sprintf(atcmd_output, msg_txt(sd,1112), // NPC %d: %s::%s | Direction: %s | Sprite: %d | Location: %d %d
  3412. ++i, nd->name, nd->exname, direction, nd->class_, nd->bl.x, nd->bl.y);
  3413. clif_displaymessage(fd, atcmd_output);
  3414. }
  3415. break;
  3416. case 3:
  3417. clif_displaymessage(fd, msg_txt(sd,1113)); // ----- Chats in Map -----
  3418. iter = mapit_getallusers();
  3419. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  3420. {
  3421. if ((cd = (struct chat_data*)map_id2bl(pl_sd->chatID)) != NULL &&
  3422. pl_sd->mapindex == m_index &&
  3423. cd->usersd[0] == pl_sd)
  3424. {
  3425. sprintf(atcmd_output, msg_txt(sd,1114), // Chat: %s | Player: %s | Location: %d %d
  3426. cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y);
  3427. clif_displaymessage(fd, atcmd_output);
  3428. sprintf(atcmd_output, msg_txt(sd,1115), // Users: %d/%d | Password: %s | Public: %s
  3429. cd->users, cd->limit, cd->pass, (cd->pub) ? msg_txt(sd,1116) : msg_txt(sd,1117)); // Yes / No
  3430. clif_displaymessage(fd, atcmd_output);
  3431. }
  3432. }
  3433. mapit_free(iter);
  3434. break;
  3435. default: // normally impossible to arrive here
  3436. clif_displaymessage(fd, msg_txt(sd,1118)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
  3437. return -1;
  3438. break;
  3439. }
  3440. return 0;
  3441. }
  3442. /*==========================================
  3443. *
  3444. *------------------------------------------*/
  3445. ACMD_FUNC(mount_peco)
  3446. {
  3447. nullpo_retr(-1, sd);
  3448. if (sd->disguise) {
  3449. clif_displaymessage(fd, msg_txt(sd,212)); // Cannot mount while in disguise.
  3450. return -1;
  3451. }
  3452. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RUNE_KNIGHT && pc_checkskill(sd,RK_DRAGONTRAINING) > 0 ) {
  3453. if( !(sd->sc.option&OPTION_DRAGON1) ) {
  3454. clif_displaymessage(sd->fd,msg_txt(sd,1119)); // You have mounted your Dragon.
  3455. pc_setoption(sd, sd->sc.option|OPTION_DRAGON1);
  3456. } else {
  3457. clif_displaymessage(sd->fd,msg_txt(sd,1120)); // You have released your Dragon.
  3458. pc_setoption(sd, sd->sc.option&~OPTION_DRAGON1);
  3459. }
  3460. return 0;
  3461. }
  3462. if( (sd->class_&MAPID_THIRDMASK) == MAPID_RANGER && pc_checkskill(sd,RA_WUGRIDER) > 0 ) {
  3463. if( !pc_isridingwug(sd) ) {
  3464. clif_displaymessage(sd->fd,msg_txt(sd,1121)); // You have mounted your Warg.
  3465. pc_setoption(sd, sd->sc.option|OPTION_WUGRIDER);
  3466. } else {
  3467. clif_displaymessage(sd->fd,msg_txt(sd,1122)); // You have released your Warg.
  3468. pc_setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
  3469. }
  3470. return 0;
  3471. }
  3472. if( (sd->class_&MAPID_THIRDMASK) == MAPID_MECHANIC ) {
  3473. if( !pc_ismadogear(sd) ) {
  3474. clif_displaymessage(sd->fd,msg_txt(sd,1123)); // You have mounted your Mado Gear.
  3475. pc_setoption(sd, sd->sc.option|OPTION_MADOGEAR);
  3476. } else {
  3477. clif_displaymessage(sd->fd,msg_txt(sd,1124)); // You have released your Mado Gear.
  3478. pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR);
  3479. }
  3480. return 0;
  3481. }
  3482. if (!pc_isriding(sd)) { // if actually no peco
  3483. if (!pc_checkskill(sd, KN_RIDING)) {
  3484. clif_displaymessage(fd, msg_txt(sd,213)); // You can not mount a Peco Peco with your current job.
  3485. return -1;
  3486. }
  3487. pc_setoption(sd, sd->sc.option | OPTION_RIDING);
  3488. clif_displaymessage(fd, msg_txt(sd,102)); // You have mounted a Peco Peco.
  3489. } else {//Dismount
  3490. pc_setoption(sd, sd->sc.option & ~OPTION_RIDING);
  3491. clif_displaymessage(fd, msg_txt(sd,214)); // You have released your Peco Peco.
  3492. }
  3493. return 0;
  3494. }
  3495. /*==========================================
  3496. *Spy Commands by Syrus22
  3497. *------------------------------------------*/
  3498. ACMD_FUNC(guildspy)
  3499. {
  3500. char guild_name[NAME_LENGTH];
  3501. struct guild *g;
  3502. nullpo_retr(-1, sd);
  3503. memset(guild_name, '\0', sizeof(guild_name));
  3504. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3505. if (!enable_spy)
  3506. {
  3507. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
  3508. return -1;
  3509. }
  3510. if (!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  3511. clif_displaymessage(fd, msg_txt(sd,1126)); // Please enter a guild name/ID (usage: @guildspy <guild_name/ID>).
  3512. return -1;
  3513. }
  3514. if ((g = guild_searchname(guild_name)) != NULL || // name first to avoid error when name begin with a number
  3515. (g = guild_search(atoi(message))) != NULL) {
  3516. if (sd->guildspy == g->guild_id) {
  3517. sd->guildspy = 0;
  3518. sprintf(atcmd_output, msg_txt(sd,103), g->name); // No longer spying on the %s guild.
  3519. clif_displaymessage(fd, atcmd_output);
  3520. } else {
  3521. sd->guildspy = g->guild_id;
  3522. sprintf(atcmd_output, msg_txt(sd,104), g->name); // Spying on the %s guild.
  3523. clif_displaymessage(fd, atcmd_output);
  3524. }
  3525. } else {
  3526. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the specified guild is online.
  3527. return -1;
  3528. }
  3529. return 0;
  3530. }
  3531. /*==========================================
  3532. *
  3533. *------------------------------------------*/
  3534. ACMD_FUNC(partyspy)
  3535. {
  3536. char party_name[NAME_LENGTH];
  3537. struct party_data *p;
  3538. nullpo_retr(-1, sd);
  3539. memset(party_name, '\0', sizeof(party_name));
  3540. memset(atcmd_output, '\0', sizeof(atcmd_output));
  3541. if (!enable_spy)
  3542. {
  3543. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
  3544. return -1;
  3545. }
  3546. if (!message || !*message || sscanf(message, "%23[^\n]", party_name) < 1) {
  3547. clif_displaymessage(fd, msg_txt(sd,1127)); // Please enter a party name/ID (usage: @partyspy <party_name/ID>).
  3548. return -1;
  3549. }
  3550. if ((p = party_searchname(party_name)) != NULL || // name first to avoid error when name begin with a number
  3551. (p = party_search(atoi(message))) != NULL) {
  3552. if (sd->partyspy == p->party.party_id) {
  3553. sd->partyspy = 0;
  3554. sprintf(atcmd_output, msg_txt(sd,105), p->party.name); // No longer spying on the %s party.
  3555. clif_displaymessage(fd, atcmd_output);
  3556. } else {
  3557. sd->partyspy = p->party.party_id;
  3558. sprintf(atcmd_output, msg_txt(sd,106), p->party.name); // Spying on the %s party.
  3559. clif_displaymessage(fd, atcmd_output);
  3560. }
  3561. } else {
  3562. clif_displaymessage(fd, msg_txt(sd,96)); // Incorrect name/ID, or no one from the specified party is online.
  3563. return -1;
  3564. }
  3565. return 0;
  3566. }
  3567. /*==========================================
  3568. * @repairall [Valaris]
  3569. *------------------------------------------*/
  3570. ACMD_FUNC(repairall)
  3571. {
  3572. int count, i;
  3573. nullpo_retr(-1, sd);
  3574. count = 0;
  3575. for (i = 0; i < MAX_INVENTORY; i++) {
  3576. if (sd->status.inventory[i].nameid && sd->status.inventory[i].attribute == 1) {
  3577. sd->status.inventory[i].attribute = 0;
  3578. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  3579. count++;
  3580. }
  3581. }
  3582. if (count > 0) {
  3583. clif_misceffect(&sd->bl, 3);
  3584. clif_equiplist(sd);
  3585. clif_displaymessage(fd, msg_txt(sd,107)); // All items have been repaired.
  3586. } else {
  3587. clif_displaymessage(fd, msg_txt(sd,108)); // No item need to be repaired.
  3588. return -1;
  3589. }
  3590. return 0;
  3591. }
  3592. /*==========================================
  3593. * @nuke [Valaris]
  3594. *------------------------------------------*/
  3595. ACMD_FUNC(nuke)
  3596. {
  3597. struct map_session_data *pl_sd;
  3598. nullpo_retr(-1, sd);
  3599. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3600. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3601. clif_displaymessage(fd, msg_txt(sd,1128)); // Please enter a player name (usage: @nuke <char name>).
  3602. return -1;
  3603. }
  3604. if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) {
  3605. if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level
  3606. skill_castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, gettick(), 0);
  3607. clif_displaymessage(fd, msg_txt(sd,109)); // Player has been nuked!
  3608. } else {
  3609. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  3610. return -1;
  3611. }
  3612. } else {
  3613. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  3614. return -1;
  3615. }
  3616. return 0;
  3617. }
  3618. /*==========================================
  3619. * @tonpc
  3620. *------------------------------------------*/
  3621. ACMD_FUNC(tonpc)
  3622. {
  3623. char npcname[NAME_LENGTH+1];
  3624. struct npc_data *nd;
  3625. nullpo_retr(-1, sd);
  3626. memset(npcname, 0, sizeof(npcname));
  3627. if (!message || !*message || sscanf(message, "%23[^\n]", npcname) < 1) {
  3628. clif_displaymessage(fd, msg_txt(sd,1129)); // Please enter a NPC name (usage: @tonpc <NPC_name>).
  3629. return -1;
  3630. }
  3631. if ((nd = npc_name2id(npcname)) != NULL) {
  3632. if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
  3633. clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
  3634. else
  3635. return -1;
  3636. } else {
  3637. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  3638. return -1;
  3639. }
  3640. return 0;
  3641. }
  3642. /*==========================================
  3643. *
  3644. *------------------------------------------*/
  3645. ACMD_FUNC(shownpc)
  3646. {
  3647. char NPCname[NAME_LENGTH+1];
  3648. nullpo_retr(-1, sd);
  3649. memset(NPCname, '\0', sizeof(NPCname));
  3650. if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  3651. clif_displaymessage(fd, msg_txt(sd,1130)); // Please enter a NPC name (usage: @enablenpc <NPC_name>).
  3652. return -1;
  3653. }
  3654. if (npc_name2id(NPCname) != NULL) {
  3655. npc_enable(NPCname, 1);
  3656. clif_displaymessage(fd, msg_txt(sd,110)); // Npc Enabled.
  3657. } else {
  3658. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  3659. return -1;
  3660. }
  3661. return 0;
  3662. }
  3663. /*==========================================
  3664. *
  3665. *------------------------------------------*/
  3666. ACMD_FUNC(hidenpc)
  3667. {
  3668. char NPCname[NAME_LENGTH+1];
  3669. nullpo_retr(-1, sd);
  3670. memset(NPCname, '\0', sizeof(NPCname));
  3671. if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
  3672. clif_displaymessage(fd, msg_txt(sd,1131)); // Please enter a NPC name (usage: @hidenpc <NPC_name>).
  3673. return -1;
  3674. }
  3675. if (npc_name2id(NPCname) == NULL) {
  3676. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  3677. return -1;
  3678. }
  3679. npc_enable(NPCname, 0);
  3680. clif_displaymessage(fd, msg_txt(sd,112)); // Npc Disabled.
  3681. return 0;
  3682. }
  3683. ACMD_FUNC(loadnpc)
  3684. {
  3685. FILE *fp;
  3686. if (!message || !*message) {
  3687. clif_displaymessage(fd, msg_txt(sd,1132)); // Please enter a script file name (usage: @loadnpc <file name>).
  3688. return -1;
  3689. }
  3690. // check if script file exists
  3691. if ((fp = fopen(message, "r")) == NULL) {
  3692. clif_displaymessage(fd, msg_txt(sd,261));
  3693. return -1;
  3694. }
  3695. fclose(fp);
  3696. // add to list of script sources and run it
  3697. npc_addsrcfile(message);
  3698. npc_parsesrcfile(message,true);
  3699. npc_read_event_script();
  3700. clif_displaymessage(fd, msg_txt(sd,262));
  3701. return 0;
  3702. }
  3703. ACMD_FUNC(unloadnpc)
  3704. {
  3705. struct npc_data *nd;
  3706. char NPCname[NAME_LENGTH+1];
  3707. nullpo_retr(-1, sd);
  3708. memset(NPCname, '\0', sizeof(NPCname));
  3709. if (!message || !*message || sscanf(message, "%24[^\n]", NPCname) < 1) {
  3710. clif_displaymessage(fd, msg_txt(sd,1133)); // Please enter a NPC name (usage: @npcoff <NPC_name>).
  3711. return -1;
  3712. }
  3713. if ((nd = npc_name2id(NPCname)) == NULL) {
  3714. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  3715. return -1;
  3716. }
  3717. npc_unload_duplicates(nd);
  3718. npc_unload(nd,true);
  3719. npc_read_event_script();
  3720. clif_displaymessage(fd, msg_txt(sd,112)); // Npc Disabled.
  3721. return 0;
  3722. }
  3723. /*==========================================
  3724. * time in txt for time command (by [Yor])
  3725. *------------------------------------------*/
  3726. char* txt_time(unsigned int duration)
  3727. {
  3728. int days, hours, minutes, seconds;
  3729. char temp[CHAT_SIZE_MAX];
  3730. static char temp1[CHAT_SIZE_MAX];
  3731. memset(temp, '\0', sizeof(temp));
  3732. memset(temp1, '\0', sizeof(temp1));
  3733. days = duration / (60 * 60 * 24);
  3734. duration = duration - (60 * 60 * 24 * days);
  3735. hours = duration / (60 * 60);
  3736. duration = duration - (60 * 60 * hours);
  3737. minutes = duration / 60;
  3738. seconds = duration - (60 * minutes);
  3739. if (days == 1)
  3740. sprintf(temp, msg_txt(NULL,219), days); // %d day
  3741. else if (days > 1)
  3742. sprintf(temp, msg_txt(NULL,220), days); // %d days
  3743. if (hours == 1)
  3744. sprintf(temp1, msg_txt(NULL,221), temp, hours); // %s %d hour
  3745. else if (hours > 1)
  3746. sprintf(temp1, msg_txt(NULL,222), temp, hours); // %s %d hours
  3747. if (minutes < 2)
  3748. sprintf(temp, msg_txt(NULL,223), temp1, minutes); // %s %d minute
  3749. else
  3750. sprintf(temp, msg_txt(NULL,224), temp1, minutes); // %s %d minutes
  3751. if (seconds == 1)
  3752. sprintf(temp1, msg_txt(NULL,225), temp, seconds); // %s and %d second
  3753. else if (seconds > 1)
  3754. sprintf(temp1, msg_txt(NULL,226), temp, seconds); // %s and %d seconds
  3755. return temp1;
  3756. }
  3757. /*==========================================
  3758. * @time/@date/@serverdate/@servertime: Display the date/time of the server (by [Yor]
  3759. * Calculation management of GM modification (@day/@night GM commands) is done
  3760. *------------------------------------------*/
  3761. ACMD_FUNC(servertime)
  3762. {
  3763. const struct TimerData * timer_data;
  3764. const struct TimerData * timer_data2;
  3765. time_t time_server; // variable for number of seconds (used with time() function)
  3766. struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
  3767. char temp[CHAT_SIZE_MAX];
  3768. nullpo_retr(-1, sd);
  3769. memset(temp, '\0', sizeof(temp));
  3770. time(&time_server); // get time in seconds since 1/1/1970
  3771. datetime = localtime(&time_server); // convert seconds in structure
  3772. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  3773. strftime(temp, sizeof(temp)-1, msg_txt(sd,230), datetime); // Server time (normal time): %A, %B %d %Y %X.
  3774. clif_displaymessage(fd, temp);
  3775. if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
  3776. if (night_flag == 0)
  3777. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
  3778. else
  3779. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  3780. } else if (battle_config.night_duration == 0)
  3781. if (night_flag == 1) { // we start with night
  3782. timer_data = get_timer(day_timer_tid);
  3783. sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in night for %s.
  3784. clif_displaymessage(fd, temp);
  3785. clif_displaymessage(fd, msg_txt(sd,234)); // Game time: After, the game will be in permanent daylight.
  3786. } else
  3787. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
  3788. else if (battle_config.day_duration == 0)
  3789. if (night_flag == 0) { // we start with day
  3790. timer_data = get_timer(night_timer_tid);
  3791. sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  3792. clif_displaymessage(fd, temp);
  3793. clif_displaymessage(fd, msg_txt(sd,236)); // Game time: After, the game will be in permanent night.
  3794. } else
  3795. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
  3796. else {
  3797. if (night_flag == 0) {
  3798. timer_data = get_timer(night_timer_tid);
  3799. timer_data2 = get_timer(day_timer_tid);
  3800. sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is actualy in daylight for %s.
  3801. clif_displaymessage(fd, temp);
  3802. if (DIFF_TICK(timer_data->tick, timer_data2->tick) > 0)
  3803. sprintf(temp, msg_txt(sd,237), txt_time(DIFF_TICK(timer_data->interval,DIFF_TICK(timer_data->tick,timer_data2->tick)) / 1000)); // Game time: After, the game will be in night for %s.
  3804. else
  3805. sprintf(temp, msg_txt(sd,237), txt_time(DIFF_TICK(timer_data2->tick,timer_data->tick)/1000)); // Game time: After, the game will be in night for %s.
  3806. clif_displaymessage(fd, temp);
  3807. sprintf(temp, msg_txt(sd,238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  3808. clif_displaymessage(fd, temp);
  3809. } else {
  3810. timer_data = get_timer(day_timer_tid);
  3811. timer_data2 = get_timer(night_timer_tid);
  3812. sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick()) / 1000)); // Game time: The game is actualy in night for %s.
  3813. clif_displaymessage(fd, temp);
  3814. if (DIFF_TICK(timer_data->tick,timer_data2->tick) > 0)
  3815. sprintf(temp, msg_txt(sd,239), txt_time((timer_data->interval - DIFF_TICK(timer_data->tick, timer_data2->tick)) / 1000)); // Game time: After, the game will be in daylight for %s.
  3816. else
  3817. sprintf(temp, msg_txt(sd,239), txt_time(DIFF_TICK(timer_data2->tick, timer_data->tick) / 1000)); // Game time: After, the game will be in daylight for %s.
  3818. clif_displaymessage(fd, temp);
  3819. sprintf(temp, msg_txt(sd,238), txt_time(timer_data->interval / 1000)); // Game time: A day cycle has a normal duration of %s.
  3820. clif_displaymessage(fd, temp);
  3821. }
  3822. }
  3823. return 0;
  3824. }
  3825. //Added by Coltaro
  3826. //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...).
  3827. //Well, using time_t could still work but for some reason that looks like more coding x_x
  3828. static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute)
  3829. {
  3830. const int factor_year = 518400; //12*30*24*60 = 518400
  3831. const int factor_month = 43200; //30*24*60 = 43200
  3832. const int factor_day = 1440; //24*60 = 1440
  3833. const int factor_hour = 60;
  3834. *year = jailtime/factor_year;
  3835. jailtime -= *year*factor_year;
  3836. *month = jailtime/factor_month;
  3837. jailtime -= *month*factor_month;
  3838. *day = jailtime/factor_day;
  3839. jailtime -= *day*factor_day;
  3840. *hour = jailtime/factor_hour;
  3841. jailtime -= *hour*factor_hour;
  3842. *minute = jailtime;
  3843. *year = *year > 0? *year : 0;
  3844. *month = *month > 0? *month : 0;
  3845. *day = *day > 0? *day : 0;
  3846. *hour = *hour > 0? *hour : 0;
  3847. *minute = *minute > 0? *minute : 0;
  3848. return;
  3849. }
  3850. /*==========================================
  3851. * @jail <char_name> by [Yor]
  3852. * Special warp! No check with nowarp and nowarpto flag
  3853. *------------------------------------------*/
  3854. ACMD_FUNC(jail)
  3855. {
  3856. struct map_session_data *pl_sd;
  3857. int x, y;
  3858. unsigned short m_index;
  3859. nullpo_retr(-1, sd);
  3860. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3861. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3862. clif_displaymessage(fd, msg_txt(sd,1134)); // Please enter a player name (usage: @jail <char_name>).
  3863. return -1;
  3864. }
  3865. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  3866. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  3867. return -1;
  3868. }
  3869. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd))
  3870. { // you can jail only lower or same GM
  3871. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  3872. return -1;
  3873. }
  3874. if (pl_sd->sc.data[SC_JAILED])
  3875. {
  3876. clif_displaymessage(fd, msg_txt(sd,118)); // Player warped in jails.
  3877. return -1;
  3878. }
  3879. switch(rnd() % 2) { //Jail Locations
  3880. case 0:
  3881. m_index = mapindex_name2id(MAP_JAIL);
  3882. x = 24;
  3883. y = 75;
  3884. break;
  3885. default:
  3886. m_index = mapindex_name2id(MAP_JAIL);
  3887. x = 49;
  3888. y = 75;
  3889. break;
  3890. }
  3891. //Duration of INT_MAX to specify infinity.
  3892. sc_start4(NULL,&pl_sd->bl,SC_JAILED,100,INT_MAX,m_index,x,y,1000);
  3893. clif_displaymessage(pl_sd->fd, msg_txt(sd,117)); // GM has send you in jails.
  3894. clif_displaymessage(fd, msg_txt(sd,118)); // Player warped in jails.
  3895. return 0;
  3896. }
  3897. /*==========================================
  3898. * @unjail/@discharge <char_name> by [Yor]
  3899. * Special warp! No check with nowarp and nowarpto flag
  3900. *------------------------------------------*/
  3901. ACMD_FUNC(unjail)
  3902. {
  3903. struct map_session_data *pl_sd;
  3904. memset(atcmd_player_name, '\0', sizeof(atcmd_player_name));
  3905. if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
  3906. clif_displaymessage(fd, msg_txt(sd,1135)); // Please enter a player name (usage: @unjail/@discharge <char_name>).
  3907. return -1;
  3908. }
  3909. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  3910. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  3911. return -1;
  3912. }
  3913. if (pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { // you can jail only lower or same GM
  3914. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  3915. return -1;
  3916. }
  3917. if (!pl_sd->sc.data[SC_JAILED])
  3918. {
  3919. clif_displaymessage(fd, msg_txt(sd,119)); // This player is not in jails.
  3920. return -1;
  3921. }
  3922. //Reset jail time to 1 sec.
  3923. sc_start(NULL,&pl_sd->bl,SC_JAILED,100,1,1000);
  3924. clif_displaymessage(pl_sd->fd, msg_txt(sd,120)); // A GM has discharged you from jail.
  3925. clif_displaymessage(fd, msg_txt(sd,121)); // Player unjailed.
  3926. return 0;
  3927. }
  3928. ACMD_FUNC(jailfor)
  3929. {
  3930. struct map_session_data *pl_sd = NULL;
  3931. int year, month, day, hour, minute, value;
  3932. char * modif_p;
  3933. int jailtime = 0,x,y;
  3934. short m_index = 0;
  3935. nullpo_retr(-1, sd);
  3936. if (!message || !*message || sscanf(message, "%255s %23[^\n]",atcmd_output,atcmd_player_name) < 2) {
  3937. clif_displaymessage(fd, msg_txt(sd,400)); //Usage: @jailfor <time> <character name>
  3938. return -1;
  3939. }
  3940. atcmd_output[sizeof(atcmd_output)-1] = '\0';
  3941. modif_p = atcmd_output;
  3942. year = month = day = hour = minute = 0;
  3943. while (modif_p[0] != '\0') {
  3944. value = atoi(modif_p);
  3945. if (value == 0)
  3946. modif_p++;
  3947. else {
  3948. if (modif_p[0] == '-' || modif_p[0] == '+')
  3949. modif_p++;
  3950. while (modif_p[0] >= '0' && modif_p[0] <= '9')
  3951. modif_p++;
  3952. if (modif_p[0] == 'n') {
  3953. minute = value;
  3954. modif_p++;
  3955. } else if (modif_p[0] == 'm' && modif_p[1] == 'n') {
  3956. minute = value;
  3957. modif_p = modif_p + 2;
  3958. } else if (modif_p[0] == 'h') {
  3959. hour = value;
  3960. modif_p++;
  3961. } else if (modif_p[0] == 'd' || modif_p[0] == 'j') {
  3962. day = value;
  3963. modif_p++;
  3964. } else if (modif_p[0] == 'm') {
  3965. month = value;
  3966. modif_p++;
  3967. } else if (modif_p[0] == 'y' || modif_p[0] == 'a') {
  3968. year = value;
  3969. modif_p++;
  3970. } else if (modif_p[0] != '\0') {
  3971. modif_p++;
  3972. }
  3973. }
  3974. }
  3975. if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0) {
  3976. clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
  3977. return -1;
  3978. }
  3979. if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
  3980. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  3981. return -1;
  3982. }
  3983. if (pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  3984. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  3985. return -1;
  3986. }
  3987. jailtime = year*12*30*24*60 + month*30*24*60 + day*24*60 + hour*60 + minute; //In minutes
  3988. if(jailtime==0) {
  3989. clif_displaymessage(fd, msg_txt(sd,1136)); // Invalid time for jail command.
  3990. return -1;
  3991. }
  3992. //Added by Coltaro
  3993. if(pl_sd->sc.data[SC_JAILED] &&
  3994. pl_sd->sc.data[SC_JAILED]->val1 != INT_MAX)
  3995. { //Update the player's jail time
  3996. jailtime += pl_sd->sc.data[SC_JAILED]->val1;
  3997. if (jailtime <= 0) {
  3998. jailtime = 0;
  3999. clif_displaymessage(pl_sd->fd, msg_txt(sd,120)); // GM has discharge you.
  4000. clif_displaymessage(fd, msg_txt(sd,121)); // Player unjailed
  4001. } else {
  4002. get_jail_time(jailtime,&year,&month,&day,&hour,&minute);
  4003. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1137),year,month,day,hour,minute); //%s in jail for %d years, %d months, %d days, %d hours and %d minutes
  4004. clif_displaymessage(pl_sd->fd, atcmd_output);
  4005. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1138),year,month,day,hour,minute); //This player is now in jail for %d years, %d months, %d days, %d hours and %d minutes
  4006. clif_displaymessage(fd, atcmd_output);
  4007. }
  4008. } else if (jailtime < 0) {
  4009. clif_displaymessage(fd, msg_txt(sd,1136));
  4010. return -1;
  4011. }
  4012. //Jail locations, add more as you wish.
  4013. switch(rnd()%2)
  4014. {
  4015. case 1: //Jail #1
  4016. m_index = mapindex_name2id(MAP_JAIL);
  4017. x = 49; y = 75;
  4018. break;
  4019. default: //Default Jail
  4020. m_index = mapindex_name2id(MAP_JAIL);
  4021. x = 24; y = 75;
  4022. break;
  4023. }
  4024. sc_start4(NULL,&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).
  4025. return 0;
  4026. }
  4027. //By Coltaro
  4028. ACMD_FUNC(jailtime)
  4029. {
  4030. int year, month, day, hour, minute;
  4031. nullpo_retr(-1, sd);
  4032. if (!sd->sc.data[SC_JAILED]) {
  4033. clif_displaymessage(fd, msg_txt(sd,1139)); // You are not in jail.
  4034. return -1;
  4035. }
  4036. if (sd->sc.data[SC_JAILED]->val1 == INT_MAX) {
  4037. clif_displaymessage(fd, msg_txt(sd,1140)); // You have been jailed indefinitely.
  4038. return 0;
  4039. }
  4040. if (sd->sc.data[SC_JAILED]->val1 <= 0) { // Was not jailed with @jailfor (maybe @jail? or warped there? or got recalled?)
  4041. clif_displaymessage(fd, msg_txt(sd,1141)); // You have been jailed for an unknown amount of time.
  4042. return -1;
  4043. }
  4044. //Get remaining jail time
  4045. get_jail_time(sd->sc.data[SC_JAILED]->val1,&year,&month,&day,&hour,&minute);
  4046. sprintf(atcmd_output,msg_txt(sd,402),msg_txt(sd,1142),year,month,day,hour,minute); // You will remain in jail for %d years, %d months, %d days, %d hours and %d minutes
  4047. clif_displaymessage(fd, atcmd_output);
  4048. return 0;
  4049. }
  4050. /*==========================================
  4051. * @disguise <mob_id> by [Valaris] (simplified by [Yor])
  4052. *------------------------------------------*/
  4053. ACMD_FUNC(disguise)
  4054. {
  4055. int id = 0;
  4056. nullpo_retr(-1, sd);
  4057. if (!message || !*message) {
  4058. clif_displaymessage(fd, msg_txt(sd,1143)); // Please enter a Monster/NPC name/ID (usage: @disguise <name/ID>).
  4059. return -1;
  4060. }
  4061. if ((id = atoi(message)) > 0)
  4062. { //Acquired an ID
  4063. if (!mobdb_checkid(id) && !npcdb_checkid(id))
  4064. id = 0; //Invalid id for either mobs or npcs.
  4065. } else { //Acquired a Name
  4066. if ((id = mobdb_searchname(message)) == 0)
  4067. {
  4068. struct npc_data* nd = npc_name2id(message);
  4069. if (nd != NULL)
  4070. id = nd->class_;
  4071. }
  4072. }
  4073. if (id == 0)
  4074. {
  4075. clif_displaymessage(fd, msg_txt(sd,123)); // Invalid Monster/NPC name/ID specified.
  4076. return -1;
  4077. }
  4078. if(pc_isriding(sd))
  4079. {
  4080. clif_displaymessage(fd, msg_txt(sd,1144)); // Character cannot be disguised while mounted.
  4081. return -1;
  4082. }
  4083. pc_disguise(sd, id);
  4084. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4085. return 0;
  4086. }
  4087. /*==========================================
  4088. * DisguiseAll
  4089. *------------------------------------------*/
  4090. ACMD_FUNC(disguiseall)
  4091. {
  4092. int mob_id=0;
  4093. struct map_session_data *pl_sd;
  4094. struct s_mapiterator* iter;
  4095. nullpo_retr(-1, sd);
  4096. if (!message || !*message) {
  4097. clif_displaymessage(fd, msg_txt(sd,1145)); // Please enter a Monster/NPC name/ID (usage: @disguiseall <name/ID>).
  4098. return -1;
  4099. }
  4100. if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
  4101. mob_id = atoi(message);
  4102. if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
  4103. clif_displaymessage(fd, msg_txt(sd,123)); // Monster/NPC name/id not found.
  4104. return -1;
  4105. }
  4106. iter = mapit_getallusers();
  4107. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4108. pc_disguise(pl_sd, mob_id);
  4109. mapit_free(iter);
  4110. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4111. return 0;
  4112. }
  4113. /*==========================================
  4114. * DisguiseGuild
  4115. *------------------------------------------*/
  4116. ACMD_FUNC(disguiseguild)
  4117. {
  4118. int id = 0, i;
  4119. char monster[NAME_LENGTH], guild[NAME_LENGTH];
  4120. struct map_session_data *pl_sd;
  4121. struct guild *g;
  4122. memset(monster, '\0', sizeof(monster));
  4123. memset(guild, '\0', sizeof(guild));
  4124. if( !message || !*message || sscanf(message, "%23[^,], %23[^\r\n]", monster, guild) < 2 ) {
  4125. clif_displaymessage(fd, msg_txt(sd,1146)); // Please enter a mob name/ID and guild name/ID (usage: @disguiseguild <mob name/ID>, <guild name/ID>).
  4126. return -1;
  4127. }
  4128. if( (id = atoi(monster)) > 0 ) {
  4129. if( !mobdb_checkid(id) && !npcdb_checkid(id) )
  4130. id = 0;
  4131. } else {
  4132. if( (id = mobdb_searchname(monster)) == 0 ) {
  4133. struct npc_data* nd = npc_name2id(monster);
  4134. if( nd != NULL )
  4135. id = nd->class_;
  4136. }
  4137. }
  4138. if( id == 0 ) {
  4139. clif_displaymessage(fd, msg_txt(sd,123)); // Monster/NPC name/id hasn't been found.
  4140. return -1;
  4141. }
  4142. if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) {
  4143. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  4144. return -1;
  4145. }
  4146. for( i = 0; i < g->max_member; i++ )
  4147. if( (pl_sd = g->member[i].sd) && !pc_isriding(pl_sd) )
  4148. pc_disguise(pl_sd, id);
  4149. clif_displaymessage(fd, msg_txt(sd,122)); // Disguise applied.
  4150. return 0;
  4151. }
  4152. /*==========================================
  4153. * @undisguise by [Yor]
  4154. *------------------------------------------*/
  4155. ACMD_FUNC(undisguise)
  4156. {
  4157. nullpo_retr(-1, sd);
  4158. if (sd->disguise) {
  4159. pc_disguise(sd, 0);
  4160. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4161. } else {
  4162. clif_displaymessage(fd, msg_txt(sd,125)); // You're not disguised.
  4163. return -1;
  4164. }
  4165. return 0;
  4166. }
  4167. /*==========================================
  4168. * UndisguiseAll
  4169. *------------------------------------------*/
  4170. ACMD_FUNC(undisguiseall)
  4171. {
  4172. struct map_session_data *pl_sd;
  4173. struct s_mapiterator* iter;
  4174. nullpo_retr(-1, sd);
  4175. iter = mapit_getallusers();
  4176. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  4177. if( pl_sd->disguise )
  4178. pc_disguise(pl_sd, 0);
  4179. mapit_free(iter);
  4180. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4181. return 0;
  4182. }
  4183. /*==========================================
  4184. * UndisguiseGuild
  4185. *------------------------------------------*/
  4186. ACMD_FUNC(undisguiseguild)
  4187. {
  4188. char guild_name[NAME_LENGTH];
  4189. struct map_session_data *pl_sd;
  4190. struct guild *g;
  4191. int i;
  4192. nullpo_retr(-1, sd);
  4193. memset(guild_name, '\0', sizeof(guild_name));
  4194. if(!message || !*message || sscanf(message, "%23[^\n]", guild_name) < 1) {
  4195. clif_displaymessage(fd, msg_txt(sd,1147)); // Please enter guild name/ID (usage: @undisguiseguild <guild name/ID>).
  4196. return -1;
  4197. }
  4198. if( (g = guild_searchname(guild_name)) == NULL && (g = guild_search(atoi(message))) == NULL ) {
  4199. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  4200. return -1;
  4201. }
  4202. for(i = 0; i < g->max_member; i++)
  4203. if( (pl_sd = g->member[i].sd) && pl_sd->disguise )
  4204. pc_disguise(pl_sd, 0);
  4205. clif_displaymessage(fd, msg_txt(sd,124)); // Undisguise applied.
  4206. return 0;
  4207. }
  4208. /*==========================================
  4209. * @exp by [Skotlex]
  4210. *------------------------------------------*/
  4211. ACMD_FUNC(exp)
  4212. {
  4213. char output[CHAT_SIZE_MAX];
  4214. double nextb, nextj;
  4215. nullpo_retr(-1, sd);
  4216. memset(output, '\0', sizeof(output));
  4217. nextb = pc_nextbaseexp(sd);
  4218. if (nextb)
  4219. nextb = sd->status.base_exp*100.0/nextb;
  4220. nextj = pc_nextjobexp(sd);
  4221. if (nextj)
  4222. nextj = sd->status.job_exp*100.0/nextj;
  4223. sprintf(output, msg_txt(sd,1148), sd->status.base_level, nextb, sd->status.job_level, nextj); // Base Level: %d (%.3f%%) | Job Level: %d (%.3f%%)
  4224. clif_displaymessage(fd, output);
  4225. return 0;
  4226. }
  4227. /*==========================================
  4228. * @broadcast by [Valaris]
  4229. *------------------------------------------*/
  4230. ACMD_FUNC(broadcast)
  4231. {
  4232. nullpo_retr(-1, sd);
  4233. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4234. if (!message || !*message) {
  4235. clif_displaymessage(fd, msg_txt(sd,1149)); // Please enter a message (usage: @broadcast <message>).
  4236. return -1;
  4237. }
  4238. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4239. intif_broadcast(atcmd_output, strlen(atcmd_output) + 1, 0);
  4240. return 0;
  4241. }
  4242. /*==========================================
  4243. * @localbroadcast by [Valaris]
  4244. *------------------------------------------*/
  4245. ACMD_FUNC(localbroadcast)
  4246. {
  4247. nullpo_retr(-1, sd);
  4248. memset(atcmd_output, '\0', sizeof(atcmd_output));
  4249. if (!message || !*message) {
  4250. clif_displaymessage(fd, msg_txt(sd,1150)); // Please enter a message (usage: @localbroadcast <message>).
  4251. return -1;
  4252. }
  4253. sprintf(atcmd_output, "%s: %s", sd->status.name, message);
  4254. clif_broadcast(&sd->bl, atcmd_output, strlen(atcmd_output) + 1, 0, ALL_SAMEMAP);
  4255. return 0;
  4256. }
  4257. /*==========================================
  4258. * @email <actual@email> <new@email> by [Yor]
  4259. *------------------------------------------*/
  4260. ACMD_FUNC(email)
  4261. {
  4262. char actual_email[100];
  4263. char new_email[100];
  4264. nullpo_retr(-1, sd);
  4265. memset(actual_email, '\0', sizeof(actual_email));
  4266. memset(new_email, '\0', sizeof(new_email));
  4267. if (!message || !*message || sscanf(message, "%99s %99s", actual_email, new_email) < 2) {
  4268. clif_displaymessage(fd, msg_txt(sd,1151)); // Please enter 2 emails (usage: @email <actual@email> <new@email>).
  4269. return -1;
  4270. }
  4271. if (e_mail_check(actual_email) == 0) {
  4272. clif_displaymessage(fd, msg_txt(sd,144)); // Invalid actual email. If you have default e-mail, give a@a.com.
  4273. return -1;
  4274. } else if (e_mail_check(new_email) == 0) {
  4275. clif_displaymessage(fd, msg_txt(sd,145)); // Invalid new email. Please enter a real e-mail.
  4276. return -1;
  4277. } else if (strcmpi(new_email, "a@a.com") == 0) {
  4278. clif_displaymessage(fd, msg_txt(sd,146)); // New email must be a real e-mail.
  4279. return -1;
  4280. } else if (strcmpi(actual_email, new_email) == 0) {
  4281. clif_displaymessage(fd, msg_txt(sd,147)); // New email must be different of the actual e-mail.
  4282. return -1;
  4283. }
  4284. chrif_changeemail(sd->status.account_id, actual_email, new_email);
  4285. clif_displaymessage(fd, msg_txt(sd,148)); // Information sended to login-server via char-server.
  4286. return 0;
  4287. }
  4288. /*==========================================
  4289. *@effect
  4290. *------------------------------------------*/
  4291. ACMD_FUNC(effect)
  4292. {
  4293. int type = 0, flag = 0;
  4294. nullpo_retr(-1, sd);
  4295. if (!message || !*message || sscanf(message, "%d", &type) < 1) {
  4296. clif_displaymessage(fd, msg_txt(sd,1152)); // Please enter an effect number (usage: @effect <effect number>).
  4297. return -1;
  4298. }
  4299. clif_specialeffect(&sd->bl, type, (send_target)flag);
  4300. clif_displaymessage(fd, msg_txt(sd,229)); // Your effect has changed.
  4301. return 0;
  4302. }
  4303. /*==========================================
  4304. * @killer by MouseJstr
  4305. * enable killing players even when not in pvp
  4306. *------------------------------------------*/
  4307. ACMD_FUNC(killer)
  4308. {
  4309. nullpo_retr(-1, sd);
  4310. sd->state.killer = !sd->state.killer;
  4311. if(sd->state.killer)
  4312. clif_displaymessage(fd, msg_txt(sd,241));
  4313. else {
  4314. clif_displaymessage(fd, msg_txt(sd,292));
  4315. pc_stop_attack(sd);
  4316. }
  4317. return 0;
  4318. }
  4319. /*==========================================
  4320. * @killable by MouseJstr
  4321. * enable other people killing you
  4322. *------------------------------------------*/
  4323. ACMD_FUNC(killable)
  4324. {
  4325. nullpo_retr(-1, sd);
  4326. sd->state.killable = !sd->state.killable;
  4327. if(sd->state.killable)
  4328. clif_displaymessage(fd, msg_txt(sd,242));
  4329. else {
  4330. clif_displaymessage(fd, msg_txt(sd,288));
  4331. map_foreachinrange(atcommand_stopattack,&sd->bl, AREA_SIZE, BL_CHAR, sd->bl.id);
  4332. }
  4333. return 0;
  4334. }
  4335. /*==========================================
  4336. * @skillon by MouseJstr
  4337. * turn skills on for the map
  4338. *------------------------------------------*/
  4339. ACMD_FUNC(skillon)
  4340. {
  4341. nullpo_retr(-1, sd);
  4342. map[sd->bl.m].flag.noskill = 0;
  4343. clif_displaymessage(fd, msg_txt(sd,244));
  4344. return 0;
  4345. }
  4346. /*==========================================
  4347. * @skilloff by MouseJstr
  4348. * Turn skills off on the map
  4349. *------------------------------------------*/
  4350. ACMD_FUNC(skilloff)
  4351. {
  4352. nullpo_retr(-1, sd);
  4353. map[sd->bl.m].flag.noskill = 1;
  4354. clif_displaymessage(fd, msg_txt(sd,243));
  4355. return 0;
  4356. }
  4357. /*==========================================
  4358. * @npcmove by MouseJstr
  4359. * move a npc
  4360. *------------------------------------------*/
  4361. ACMD_FUNC(npcmove)
  4362. {
  4363. int x = 0, y = 0, m;
  4364. struct npc_data *nd = 0;
  4365. nullpo_retr(-1, sd);
  4366. memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
  4367. if (!message || !*message || sscanf(message, "%d %d %23[^\n]", &x, &y, atcmd_player_name) < 3) {
  4368. clif_displaymessage(fd, msg_txt(sd,1153)); // Usage: @npcmove <X> <Y> <npc_name>
  4369. return -1;
  4370. }
  4371. if ((nd = npc_name2id(atcmd_player_name)) == NULL)
  4372. {
  4373. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist.
  4374. return -1;
  4375. }
  4376. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  4377. {
  4378. clif_displaymessage(fd, msg_txt(sd,1154)); // NPC is not on this map.
  4379. return -1; //Not on a map.
  4380. }
  4381. x = cap_value(x, 0, map[m].xs-1);
  4382. y = cap_value(y, 0, map[m].ys-1);
  4383. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  4384. map_moveblock(&nd->bl, x, y, gettick());
  4385. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  4386. clif_displaymessage(fd, msg_txt(sd,1155)); // NPC moved.
  4387. return 0;
  4388. }
  4389. /*==========================================
  4390. * @addwarp by MouseJstr
  4391. * Create a new static warp point.
  4392. *------------------------------------------*/
  4393. ACMD_FUNC(addwarp)
  4394. {
  4395. char mapname[32], warpname[NAME_LENGTH+1];
  4396. int x,y;
  4397. unsigned short m;
  4398. struct npc_data* nd;
  4399. nullpo_retr(-1, sd);
  4400. memset(warpname, '\0', sizeof(warpname));
  4401. if (!message || !*message || sscanf(message, "%31s %d %d %23[^\n]", mapname, &x, &y, warpname) < 4) {
  4402. clif_displaymessage(fd, msg_txt(sd,1156)); // Usage: @addwarp <mapname> <X> <Y> <npc name>
  4403. return -1;
  4404. }
  4405. m = mapindex_name2id(mapname);
  4406. if( m == 0 )
  4407. {
  4408. sprintf(atcmd_output, msg_txt(sd,1157), mapname); // Unknown map '%s'.
  4409. clif_displaymessage(fd, atcmd_output);
  4410. return -1;
  4411. }
  4412. nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
  4413. if( nd == NULL )
  4414. return -1;
  4415. sprintf(atcmd_output, msg_txt(sd,1158), nd->exname); // New warp NPC '%s' created.
  4416. clif_displaymessage(fd, atcmd_output);
  4417. return 0;
  4418. }
  4419. /*==========================================
  4420. * @follow by [MouseJstr]
  4421. * Follow a player .. staying no more then 5 spaces away
  4422. *------------------------------------------*/
  4423. ACMD_FUNC(follow)
  4424. {
  4425. struct map_session_data *pl_sd = NULL;
  4426. nullpo_retr(-1, sd);
  4427. if (!message || !*message) {
  4428. if (sd->followtarget == -1)
  4429. return -1;
  4430. pc_stop_following (sd);
  4431. clif_displaymessage(fd, msg_txt(sd,1159)); // Follow mode OFF.
  4432. return 0;
  4433. }
  4434. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  4435. {
  4436. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4437. return -1;
  4438. }
  4439. if (sd->followtarget == pl_sd->bl.id) {
  4440. pc_stop_following (sd);
  4441. clif_displaymessage(fd, msg_txt(sd,1159)); // Follow mode OFF.
  4442. } else {
  4443. pc_follow(sd, pl_sd->bl.id);
  4444. clif_displaymessage(fd, msg_txt(sd,1160)); // Follow mode ON.
  4445. }
  4446. return 0;
  4447. }
  4448. /*==========================================
  4449. * @dropall by [MouseJstr]
  4450. * Drop all your possession on the ground
  4451. *------------------------------------------*/
  4452. ACMD_FUNC(dropall)
  4453. {
  4454. int i;
  4455. nullpo_retr(-1, sd);
  4456. for (i = 0; i < MAX_INVENTORY; i++) {
  4457. if (sd->status.inventory[i].amount) {
  4458. if(sd->status.inventory[i].equip != 0)
  4459. pc_unequipitem(sd, i, 3);
  4460. pc_dropitem(sd, i, sd->status.inventory[i].amount);
  4461. }
  4462. }
  4463. return 0;
  4464. }
  4465. /*==========================================
  4466. * @storeall by [MouseJstr]
  4467. * Put everything into storage
  4468. *------------------------------------------*/
  4469. ACMD_FUNC(storeall)
  4470. {
  4471. int i;
  4472. nullpo_retr(-1, sd);
  4473. if (sd->state.storage_flag != 1)
  4474. { //Open storage.
  4475. if( storage_storageopen(sd) == 1 ) {
  4476. clif_displaymessage(fd, msg_txt(sd,1161)); // You currently cannot open your storage.
  4477. return -1;
  4478. }
  4479. }
  4480. for (i = 0; i < MAX_INVENTORY; i++) {
  4481. if (sd->status.inventory[i].amount) {
  4482. if(sd->status.inventory[i].equip != 0)
  4483. pc_unequipitem(sd, i, 3);
  4484. storage_storageadd(sd, i, sd->status.inventory[i].amount);
  4485. }
  4486. }
  4487. storage_storageclose(sd);
  4488. clif_displaymessage(fd, msg_txt(sd,1162)); // All items stored.
  4489. return 0;
  4490. }
  4491. ACMD_FUNC(clearstorage)
  4492. {
  4493. int i, j;
  4494. nullpo_retr(-1, sd);
  4495. if (sd->state.storage_flag == 1) {
  4496. clif_displaymessage(fd, msg_txt(sd,250));
  4497. return -1;
  4498. }
  4499. j = sd->status.storage.storage_amount;
  4500. for (i = 0; i < j; ++i) {
  4501. storage_delitem(sd, i, sd->status.storage.items[i].amount);
  4502. }
  4503. storage_storageclose(sd);
  4504. clif_displaymessage(fd, msg_txt(sd,1394)); // Your storage was cleaned.
  4505. return 0;
  4506. }
  4507. ACMD_FUNC(cleargstorage)
  4508. {
  4509. int i, j;
  4510. struct guild *g;
  4511. struct guild_storage *gstorage;
  4512. nullpo_retr(-1, sd);
  4513. g = sd->guild;
  4514. if (g == NULL) {
  4515. clif_displaymessage(fd, msg_txt(sd,43));
  4516. return -1;
  4517. }
  4518. if (sd->state.storage_flag == 1) {
  4519. clif_displaymessage(fd, msg_txt(sd,250));
  4520. return -1;
  4521. }
  4522. if (sd->state.storage_flag == 2) {
  4523. clif_displaymessage(fd, msg_txt(sd,251));
  4524. return -1;
  4525. }
  4526. gstorage = guild2storage2(sd->status.guild_id);
  4527. if (gstorage == NULL) {// Doesn't have opened @gstorage yet, so we skip the deletion since *shouldn't* have any item there.
  4528. return -1;
  4529. }
  4530. j = gstorage->storage_amount;
  4531. gstorage->lock = 1; // Lock @gstorage: do not allow any item to be retrieved or stored from any guild member
  4532. for (i = 0; i < j; ++i) {
  4533. guild_storage_delitem(sd, gstorage, i, gstorage->items[i].amount);
  4534. }
  4535. storage_guild_storageclose(sd);
  4536. gstorage->lock = 0; // Cleaning done, release lock
  4537. clif_displaymessage(fd, msg_txt(sd,1395)); // Your guild storage was cleaned.
  4538. return 0;
  4539. }
  4540. ACMD_FUNC(clearcart)
  4541. {
  4542. int i;
  4543. nullpo_retr(-1, sd);
  4544. if (pc_iscarton(sd) == 0) {
  4545. clif_displaymessage(fd, msg_txt(sd,1396)); // You do not have a cart to be cleaned.
  4546. return -1;
  4547. }
  4548. if (sd->state.vending == 1) { //Somehow...
  4549. return -1;
  4550. }
  4551. for( i = 0; i < MAX_CART; i++ )
  4552. if(sd->status.cart[i].nameid > 0)
  4553. pc_cart_delitem(sd, i, sd->status.cart[i].amount, 1, LOG_TYPE_OTHER);
  4554. clif_clearcart(fd);
  4555. clif_updatestatus(sd,SP_CARTINFO);
  4556. clif_displaymessage(fd, msg_txt(sd,1397)); // Your cart was cleaned.
  4557. return 0;
  4558. }
  4559. /*==========================================
  4560. * @skillid by [MouseJstr]
  4561. * lookup a skill by name
  4562. *------------------------------------------*/
  4563. #define MAX_SKILLID_PARTIAL_RESULTS 5
  4564. #define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 // "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33)
  4565. ACMD_FUNC(skillid) {
  4566. int skillen, idx, i, found = 0;
  4567. DBIterator* iter;
  4568. DBKey key;
  4569. DBData *data;
  4570. char partials[MAX_SKILLID_PARTIAL_RESULTS][MAX_SKILLID_PARTIAL_RESULTS_LEN];
  4571. nullpo_retr(-1, sd);
  4572. if (!message || !*message) {
  4573. clif_displaymessage(fd, msg_txt(sd,1163)); // Please enter a skill name to look up (usage: @skillid <skill name>).
  4574. return -1;
  4575. }
  4576. skillen = strlen(message);
  4577. iter = db_iterator(skilldb_name2id);
  4578. for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
  4579. idx = skill_get_index(db_data2i(data));
  4580. if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0) {
  4581. sprintf(atcmd_output, msg_txt(sd,1164), db_data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s)
  4582. clif_displaymessage(fd, atcmd_output);
  4583. } else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(key.str,message) || stristr(skill_db[idx].desc,message) ) ) {
  4584. snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(sd,1164), db_data2i(data), skill_db[idx].desc, key.str);
  4585. }
  4586. }
  4587. dbi_destroy(iter);
  4588. if( found ) {
  4589. sprintf(atcmd_output, msg_txt(sd,1398), found); // -- Displaying first %d partial matches
  4590. clif_displaymessage(fd, atcmd_output);
  4591. }
  4592. for(i = 0; i < found; i++) { /* partials */
  4593. clif_displaymessage(fd, partials[i]);
  4594. }
  4595. return 0;
  4596. }
  4597. /*==========================================
  4598. * @useskill by [MouseJstr]
  4599. * A way of using skills without having to find them in the skills menu
  4600. *------------------------------------------*/
  4601. ACMD_FUNC(useskill)
  4602. {
  4603. struct map_session_data *pl_sd = NULL;
  4604. struct block_list *bl;
  4605. uint16 skill_id;
  4606. uint16 skill_lv;
  4607. char target[100];
  4608. nullpo_retr(-1, sd);
  4609. if(!message || !*message || sscanf(message, "%hu %hu %23[^\n]", &skill_id, &skill_lv, target) != 3) {
  4610. clif_displaymessage(fd, msg_txt(sd,1165)); // Usage: @useskill <skill ID> <skill level> <target>
  4611. return -1;
  4612. }
  4613. if(!strcmp(target,"self")) pl_sd = sd; //quick keyword
  4614. else if ( (pl_sd = map_nick2sd(target)) == NULL ){
  4615. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4616. return -1;
  4617. }
  4618. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  4619. {
  4620. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  4621. return -1;
  4622. }
  4623. if (skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE+MAX_HOMUNSKILL
  4624. && sd->hd && merc_is_hom_active(sd->hd)) // (If used with @useskill, put the homunc as dest)
  4625. bl = &sd->hd->bl;
  4626. else
  4627. bl = &sd->bl;
  4628. if (skill_get_inf(skill_id)&INF_GROUND_SKILL)
  4629. unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skill_id, skill_lv);
  4630. else
  4631. unit_skilluse_id(bl, pl_sd->bl.id, skill_id, skill_lv);
  4632. return 0;
  4633. }
  4634. /*==========================================
  4635. * @displayskill by [Skotlex]
  4636. * Debug command to locate new skill IDs. It sends the
  4637. * three possible skill-effect packets to the area.
  4638. *------------------------------------------*/
  4639. ACMD_FUNC(displayskill)
  4640. {
  4641. struct status_data * status;
  4642. unsigned int tick;
  4643. uint16 skill_id;
  4644. uint16 skill_lv = 1;
  4645. nullpo_retr(-1, sd);
  4646. if (!message || !*message || sscanf(message, "%hu %hu", &skill_id, &skill_lv) < 1)
  4647. {
  4648. clif_displaymessage(fd, msg_txt(sd,1166)); // Usage: @displayskill <skill ID> {<skill level>}
  4649. return -1;
  4650. }
  4651. status = status_get_status_data(&sd->bl);
  4652. tick = gettick();
  4653. clif_skill_damage(&sd->bl,&sd->bl, tick, status->amotion, status->dmotion, 1, 1, skill_id, skill_lv, 5);
  4654. clif_skill_nodamage(&sd->bl, &sd->bl, skill_id, skill_lv, 1);
  4655. clif_skill_poseffect(&sd->bl, skill_id, skill_lv, sd->bl.x, sd->bl.y, tick);
  4656. return 0;
  4657. }
  4658. /*==========================================
  4659. * @skilltree by [MouseJstr]
  4660. * prints the skill tree for a player required to get to a skill
  4661. *------------------------------------------*/
  4662. ACMD_FUNC(skilltree)
  4663. {
  4664. struct map_session_data *pl_sd = NULL;
  4665. uint16 skill_id;
  4666. int meets, j, c=0;
  4667. char target[NAME_LENGTH];
  4668. struct skill_tree_entry *ent;
  4669. nullpo_retr(-1, sd);
  4670. if(!message || !*message || sscanf(message, "%hu %23[^\r\n]", &skill_id, target) != 2) {
  4671. clif_displaymessage(fd, msg_txt(sd,1167)); // Usage: @skilltree <skill ID> <target>
  4672. return -1;
  4673. }
  4674. if ( (pl_sd = map_nick2sd(target)) == NULL )
  4675. {
  4676. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  4677. return -1;
  4678. }
  4679. c = pc_calc_skilltree_normalize_job(pl_sd);
  4680. c = pc_mapid2jobid(c, pl_sd->status.sex);
  4681. sprintf(atcmd_output, msg_txt(sd,1168), job_name(c), pc_checkskill(pl_sd, NV_BASIC)); // Player is using %s skill tree (%d basic points).
  4682. clif_displaymessage(fd, atcmd_output);
  4683. ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[c][j].id == 0 || skill_tree[c][j].id == skill_id );
  4684. if( j == MAX_SKILL_TREE || skill_tree[c][j].id == 0 )
  4685. {
  4686. clif_displaymessage(fd, msg_txt(sd,1169)); // The player cannot use that skill.
  4687. return 0;
  4688. }
  4689. ent = &skill_tree[c][j];
  4690. meets = 1;
  4691. for(j=0;j<MAX_PC_SKILL_REQUIRE;j++)
  4692. {
  4693. if( ent->need[j].id && pc_checkskill(sd,ent->need[j].id) < ent->need[j].lv)
  4694. {
  4695. sprintf(atcmd_output, msg_txt(sd,1170), ent->need[j].lv, skill_db[ent->need[j].id].desc); // Player requires level %d of skill %s.
  4696. clif_displaymessage(fd, atcmd_output);
  4697. meets = 0;
  4698. }
  4699. }
  4700. if (meets == 1) {
  4701. clif_displaymessage(fd, msg_txt(sd,1171)); // The player meets all the requirements for that skill.
  4702. }
  4703. return 0;
  4704. }
  4705. // Hand a ring with partners name on it to this char
  4706. void getring (struct map_session_data* sd)
  4707. {
  4708. int flag, item_id;
  4709. struct item item_tmp;
  4710. item_id = (sd->status.sex) ? WEDDING_RING_M : WEDDING_RING_F;
  4711. memset(&item_tmp, 0, sizeof(item_tmp));
  4712. item_tmp.nameid = item_id;
  4713. item_tmp.identify = 1;
  4714. item_tmp.card[0] = 255;
  4715. item_tmp.card[2] = sd->status.partner_id;
  4716. item_tmp.card[3] = sd->status.partner_id >> 16;
  4717. if((flag = pc_additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
  4718. clif_additem(sd,0,0,flag);
  4719. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
  4720. }
  4721. }
  4722. /*==========================================
  4723. * @marry by [MouseJstr], fixed by Lupus
  4724. * Marry two players
  4725. *------------------------------------------*/
  4726. ACMD_FUNC(marry)
  4727. {
  4728. struct map_session_data *pl_sd = NULL;
  4729. char player_name[NAME_LENGTH] = "";
  4730. nullpo_retr(-1, sd);
  4731. if (!message || !*message || sscanf(message, "%23s", player_name) != 1) {
  4732. clif_displaymessage(fd, msg_txt(sd,1172)); // Usage: @marry <char name>
  4733. return -1;
  4734. }
  4735. if ((pl_sd = map_nick2sd(player_name)) == NULL) {
  4736. clif_displaymessage(fd, msg_txt(sd,3));
  4737. return -1;
  4738. }
  4739. if (pc_marriage(sd, pl_sd) == 0) {
  4740. clif_displaymessage(fd, msg_txt(sd,1173)); // They are married... wish them well.
  4741. clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus]
  4742. getring(sd); // Auto-give named rings (Aru)
  4743. getring(pl_sd);
  4744. return 0;
  4745. }
  4746. clif_displaymessage(fd, msg_txt(sd,1174)); // The two cannot wed because one is either a baby or already married.
  4747. return -1;
  4748. }
  4749. /*==========================================
  4750. * @divorce by [MouseJstr], fixed by [Lupus]
  4751. * divorce two players
  4752. *------------------------------------------*/
  4753. ACMD_FUNC(divorce)
  4754. {
  4755. nullpo_retr(-1, sd);
  4756. if (pc_divorce(sd) != 0) {
  4757. sprintf(atcmd_output, msg_txt(sd,1175), sd->status.name); // '%s' is not married.
  4758. clif_displaymessage(fd, atcmd_output);
  4759. return -1;
  4760. }
  4761. sprintf(atcmd_output, msg_txt(sd,1176), sd->status.name); // '%s' and his/her partner are now divorced.
  4762. clif_displaymessage(fd, atcmd_output);
  4763. return 0;
  4764. }
  4765. /*==========================================
  4766. * @changelook by [Celest]
  4767. *------------------------------------------*/
  4768. ACMD_FUNC(changelook)
  4769. {
  4770. int i, j = 0, k = 0;
  4771. int pos[7] = { LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HEAD_BOTTOM,LOOK_WEAPON,LOOK_SHIELD,LOOK_SHOES,LOOK_ROBE };
  4772. if((i = sscanf(message, "%d %d", &j, &k)) < 1) {
  4773. clif_displaymessage(fd, msg_txt(sd,1177)); // Usage: @changelook {<position>} <view id>
  4774. clif_displaymessage(fd, msg_txt(sd,1178)); // Position: 1-Top 2-Middle 3-Bottom 4-Weapon 5-Shield 6-Shoes 7-Robe
  4775. return -1;
  4776. } else if ( i == 2 ) {
  4777. if (j < 1 || j > 7)
  4778. j = 1;
  4779. j = pos[j - 1];
  4780. } else if( i == 1 ) { // position not defined, use HEAD_TOP as default
  4781. k = j; // swap
  4782. j = LOOK_HEAD_TOP;
  4783. }
  4784. clif_changelook(&sd->bl,j,k);
  4785. return 0;
  4786. }
  4787. /*==========================================
  4788. * @autotrade by durf [Lupus] [Paradox924X]
  4789. * Turns on/off Autotrade for a specific player
  4790. *------------------------------------------*/
  4791. ACMD_FUNC(autotrade) {
  4792. int i;
  4793. nullpo_retr(-1, sd);
  4794. if( map[sd->bl.m].flag.autotrade != battle_config.autotrade_mapflag ) {
  4795. clif_displaymessage(fd, msg_txt(sd,1179)); // Autotrade is not allowed on this map.
  4796. return -1;
  4797. }
  4798. if( pc_isdead(sd) ) {
  4799. clif_displaymessage(fd, msg_txt(sd,1180)); // You cannot autotrade when dead.
  4800. return -1;
  4801. }
  4802. if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying
  4803. clif_displaymessage(fd, msg_txt(sd,549)); // "You should have a shop open to use @autotrade."
  4804. return -1;
  4805. }
  4806. sd->state.autotrade = 1;
  4807. if( battle_config.at_timeout ) {
  4808. int timeout = atoi(message);
  4809. status_change_start(NULL,&sd->bl, SC_AUTOTRADE, 10000, 0, 0, 0, 0, ((timeout > 0) ? min(timeout,battle_config.at_timeout) : battle_config.at_timeout) * 60000, 0);
  4810. }
  4811. // Leave all chat channels.
  4812. if( raChSys.ally && sd->status.guild_id ) {
  4813. struct guild *g = sd->guild, *sg;
  4814. if( g ) {
  4815. if( idb_exists(((struct raChSysCh *)g->channel)->users, sd->status.char_id) )
  4816. clif_chsys_left((struct raChSysCh *)g->channel,sd);
  4817. for (i = 0; i < MAX_GUILDALLIANCE; i++) {
  4818. if( g->alliance[i].guild_id && (sg = guild_search(g->alliance[i].guild_id) ) ) {
  4819. if( idb_exists(((struct raChSysCh *)sg->channel)->users, sd->status.char_id) )
  4820. clif_chsys_left((struct raChSysCh *)sg->channel,sd);
  4821. break;
  4822. }
  4823. }
  4824. }
  4825. }
  4826. if( sd->channel_count ) { //quit all chan
  4827. uint8 count = sd->channel_count;
  4828. for( i = 0; i < count; i++ ) {
  4829. if( sd->channels[i] != NULL )
  4830. clif_chsys_left(sd->channels[i],sd);
  4831. }
  4832. }
  4833. clif_authfail_fd(sd->fd, 15);
  4834. return 0;
  4835. }
  4836. /*==========================================
  4837. * @changegm by durf (changed by Lupus)
  4838. * Changes Master of your Guild to a specified guild member
  4839. *------------------------------------------*/
  4840. ACMD_FUNC(changegm)
  4841. {
  4842. struct guild *g;
  4843. struct map_session_data *pl_sd;
  4844. nullpo_retr(-1, sd);
  4845. if (sd->status.guild_id == 0 || (g = sd->guild) == NULL || strcmp(g->master,sd->status.name)) {
  4846. clif_displaymessage(fd, msg_txt(sd,1181)); // You need to be a Guild Master to use this command.
  4847. return -1;
  4848. }
  4849. if( map[sd->bl.m].flag.guildlock || map[sd->bl.m].flag.gvg_castle ) {
  4850. clif_displaymessage(fd, msg_txt(sd,1182)); // You cannot change guild leaders on this map.
  4851. return -1;
  4852. }
  4853. if( !message[0] ) {
  4854. clif_displaymessage(fd, msg_txt(sd,1183)); // Usage: @changegm <guild_member_name>
  4855. return -1;
  4856. }
  4857. if((pl_sd=map_nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
  4858. clif_displaymessage(fd, msg_txt(sd,1184)); // Target character must be online and be a guild member.
  4859. return -1;
  4860. }
  4861. guild_gm_change(sd->status.guild_id, pl_sd);
  4862. return 0;
  4863. }
  4864. /*==========================================
  4865. * @changeleader by Skotlex
  4866. * Changes the leader of a party.
  4867. *------------------------------------------*/
  4868. ACMD_FUNC(changeleader)
  4869. {
  4870. nullpo_retr(-1, sd);
  4871. if( !message[0] )
  4872. {
  4873. clif_displaymessage(fd, msg_txt(sd,1185)); // Usage: @changeleader <party_member_name>
  4874. return -1;
  4875. }
  4876. if (party_changeleader(sd, map_nick2sd((char *) message)))
  4877. return 0;
  4878. return -1;
  4879. }
  4880. /*==========================================
  4881. * @partyoption by Skotlex
  4882. * Used to change the item share setting of a party.
  4883. *------------------------------------------*/
  4884. ACMD_FUNC(partyoption)
  4885. {
  4886. struct party_data *p;
  4887. int mi, option;
  4888. char w1[16], w2[16];
  4889. nullpo_retr(-1, sd);
  4890. if (sd->status.party_id == 0 || (p = party_search(sd->status.party_id)) == NULL)
  4891. {
  4892. clif_displaymessage(fd, msg_txt(sd,282));
  4893. return -1;
  4894. }
  4895. ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd );
  4896. if (mi == MAX_PARTY)
  4897. return -1; //Shouldn't happen
  4898. if (!p->party.member[mi].leader)
  4899. {
  4900. clif_displaymessage(fd, msg_txt(sd,282));
  4901. return -1;
  4902. }
  4903. if(!message || !*message || sscanf(message, "%15s %15s", w1, w2) < 2)
  4904. {
  4905. clif_displaymessage(fd, msg_txt(sd,1186)); // Usage: @partyoption <pickup share: yes/no> <item distribution: yes/no>
  4906. return -1;
  4907. }
  4908. option = (config_switch(w1)?1:0)|(config_switch(w2)?2:0);
  4909. //Change item share type.
  4910. if (option != p->party.item)
  4911. party_changeoption(sd, p->party.exp, option);
  4912. else
  4913. clif_displaymessage(fd, msg_txt(sd,286));
  4914. return 0;
  4915. }
  4916. /*==========================================
  4917. * @autoloot by Upa-Kun
  4918. * Turns on/off AutoLoot for a specific player
  4919. *------------------------------------------*/
  4920. ACMD_FUNC(autoloot)
  4921. {
  4922. int rate;
  4923. nullpo_retr(-1, sd);
  4924. // autoloot command without value
  4925. if(!message || !*message)
  4926. {
  4927. if (sd->state.autoloot)
  4928. rate = 0;
  4929. else
  4930. rate = 10000;
  4931. } else {
  4932. double drate;
  4933. drate = atof(message);
  4934. rate = (int)(drate*100);
  4935. }
  4936. if (rate < 0) rate = 0;
  4937. if (rate > 10000) rate = 10000;
  4938. sd->state.autoloot = rate;
  4939. if (sd->state.autoloot) {
  4940. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1187),((double)sd->state.autoloot)/100.); // Autolooting items with drop rates of %0.02f%% and below.
  4941. clif_displaymessage(fd, atcmd_output);
  4942. }else
  4943. clif_displaymessage(fd, msg_txt(sd,1188)); // Autoloot is now off.
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * @alootid
  4948. *------------------------------------------*/
  4949. ACMD_FUNC(autolootitem)
  4950. {
  4951. struct item_data *item_data = NULL;
  4952. int i;
  4953. int action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
  4954. if (message && *message) {
  4955. if (message[0] == '+') {
  4956. message++;
  4957. action = 1;
  4958. }
  4959. else if (message[0] == '-') {
  4960. message++;
  4961. action = 2;
  4962. }
  4963. else if (!strcmp(message,"reset"))
  4964. action = 4;
  4965. }
  4966. if (action < 3) // add or remove
  4967. {
  4968. if ((item_data = itemdb_exists(atoi(message))) == NULL)
  4969. item_data = itemdb_searchname(message);
  4970. if (!item_data) {
  4971. // No items founds in the DB with Id or Name
  4972. clif_displaymessage(fd, msg_txt(sd,1189)); // Item not found.
  4973. return -1;
  4974. }
  4975. }
  4976. switch(action) {
  4977. case 1:
  4978. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  4979. if (i != AUTOLOOTITEM_SIZE) {
  4980. clif_displaymessage(fd, msg_txt(sd,1190)); // You're already autolooting this item.
  4981. return -1;
  4982. }
  4983. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == 0);
  4984. if (i == AUTOLOOTITEM_SIZE) {
  4985. clif_displaymessage(fd, msg_txt(sd,1191)); // Your autolootitem list is full. Remove some items first with @autolootid -<item name or ID>.
  4986. return -1;
  4987. }
  4988. sd->state.autolootid[i] = item_data->nameid; // Autoloot Activated
  4989. sprintf(atcmd_output, msg_txt(sd,1192), item_data->name, item_data->jname, item_data->nameid); // Autolooting item: '%s'/'%s' {%d}
  4990. clif_displaymessage(fd, atcmd_output);
  4991. sd->state.autolooting = 1;
  4992. break;
  4993. case 2:
  4994. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] == item_data->nameid);
  4995. if (i == AUTOLOOTITEM_SIZE) {
  4996. clif_displaymessage(fd, msg_txt(sd,1193)); // You're currently not autolooting this item.
  4997. return -1;
  4998. }
  4999. sd->state.autolootid[i] = 0;
  5000. sprintf(atcmd_output, msg_txt(sd,1194), item_data->name, item_data->jname, item_data->nameid); // Removed item: '%s'/'%s' {%d} from your autolootitem list.
  5001. clif_displaymessage(fd, atcmd_output);
  5002. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5003. if (i == AUTOLOOTITEM_SIZE) {
  5004. sd->state.autolooting = 0;
  5005. }
  5006. break;
  5007. case 3:
  5008. sprintf(atcmd_output, msg_txt(sd,1195), AUTOLOOTITEM_SIZE); // You can have %d items on your autolootitem list.
  5009. clif_displaymessage(fd, atcmd_output);
  5010. clif_displaymessage(fd, msg_txt(sd,1196)); // To add an item to the list, use "@alootid +<item name or ID>". To remove an item, use "@alootid -<item name or ID>".
  5011. clif_displaymessage(fd, msg_txt(sd,1197)); // "@alootid reset" will clear your autolootitem list.
  5012. ARR_FIND(0, AUTOLOOTITEM_SIZE, i, sd->state.autolootid[i] != 0);
  5013. if (i == AUTOLOOTITEM_SIZE) {
  5014. clif_displaymessage(fd, msg_txt(sd,1198)); // Your autolootitem list is empty.
  5015. } else {
  5016. clif_displaymessage(fd, msg_txt(sd,1199)); // Items on your autolootitem list:
  5017. for(i = 0; i < AUTOLOOTITEM_SIZE; i++)
  5018. {
  5019. if (sd->state.autolootid[i] == 0)
  5020. continue;
  5021. if (!(item_data = itemdb_exists(sd->state.autolootid[i]))) {
  5022. 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);
  5023. continue;
  5024. }
  5025. sprintf(atcmd_output, "'%s'/'%s' {%d}", item_data->name, item_data->jname, item_data->nameid);
  5026. clif_displaymessage(fd, atcmd_output);
  5027. }
  5028. }
  5029. break;
  5030. case 4:
  5031. memset(sd->state.autolootid, 0, sizeof(sd->state.autolootid));
  5032. clif_displaymessage(fd, msg_txt(sd,1200)); // Your autolootitem list has been reset.
  5033. sd->state.autolooting = 0;
  5034. break;
  5035. }
  5036. return 0;
  5037. }
  5038. /**
  5039. * No longer available, keeping here just in case it's back someday. [Ind]
  5040. **/
  5041. /*==========================================
  5042. * It is made to rain.
  5043. *------------------------------------------*/
  5044. //ACMD_FUNC(rain)
  5045. //{
  5046. // nullpo_retr(-1, sd);
  5047. // if (map[sd->bl.m].flag.rain) {
  5048. // map[sd->bl.m].flag.rain=0;
  5049. // clif_weather(sd->bl.m);
  5050. // clif_displaymessage(fd, msg_txt(sd,1201)); // The rain has stopped.
  5051. // } else {
  5052. // map[sd->bl.m].flag.rain=1;
  5053. // clif_weather(sd->bl.m);
  5054. // clif_displaymessage(fd, msg_txt(sd,1202)); // It has started to rain.
  5055. // }
  5056. // return 0;
  5057. //}
  5058. /*==========================================
  5059. * It is made to snow.
  5060. *------------------------------------------*/
  5061. ACMD_FUNC(snow)
  5062. {
  5063. nullpo_retr(-1, sd);
  5064. if (map[sd->bl.m].flag.snow) {
  5065. map[sd->bl.m].flag.snow=0;
  5066. clif_weather(sd->bl.m);
  5067. clif_displaymessage(fd, msg_txt(sd,1203)); // Snow has stopped falling.
  5068. } else {
  5069. map[sd->bl.m].flag.snow=1;
  5070. clif_weather(sd->bl.m);
  5071. clif_displaymessage(fd, msg_txt(sd,1204)); // It has started to snow.
  5072. }
  5073. return 0;
  5074. }
  5075. /*==========================================
  5076. * Cherry tree snowstorm is made to fall. (Sakura)
  5077. *------------------------------------------*/
  5078. ACMD_FUNC(sakura)
  5079. {
  5080. nullpo_retr(-1, sd);
  5081. if (map[sd->bl.m].flag.sakura) {
  5082. map[sd->bl.m].flag.sakura=0;
  5083. clif_weather(sd->bl.m);
  5084. clif_displaymessage(fd, msg_txt(sd,1205)); // Cherry tree leaves no longer fall.
  5085. } else {
  5086. map[sd->bl.m].flag.sakura=1;
  5087. clif_weather(sd->bl.m);
  5088. clif_displaymessage(fd, msg_txt(sd,1206)); // Cherry tree leaves have begun to fall.
  5089. }
  5090. return 0;
  5091. }
  5092. /*==========================================
  5093. * Clouds appear.
  5094. *------------------------------------------*/
  5095. ACMD_FUNC(clouds)
  5096. {
  5097. nullpo_retr(-1, sd);
  5098. if (map[sd->bl.m].flag.clouds) {
  5099. map[sd->bl.m].flag.clouds=0;
  5100. clif_weather(sd->bl.m);
  5101. clif_displaymessage(fd, msg_txt(sd,1207)); // The clouds has disappear.
  5102. } else {
  5103. map[sd->bl.m].flag.clouds=1;
  5104. clif_weather(sd->bl.m);
  5105. clif_displaymessage(fd, msg_txt(sd,1208)); // Clouds appear.
  5106. }
  5107. return 0;
  5108. }
  5109. /*==========================================
  5110. * Different type of clouds using effect 516
  5111. *------------------------------------------*/
  5112. ACMD_FUNC(clouds2)
  5113. {
  5114. nullpo_retr(-1, sd);
  5115. if (map[sd->bl.m].flag.clouds2) {
  5116. map[sd->bl.m].flag.clouds2=0;
  5117. clif_weather(sd->bl.m);
  5118. clif_displaymessage(fd, msg_txt(sd,1209)); // The alternative clouds disappear.
  5119. } else {
  5120. map[sd->bl.m].flag.clouds2=1;
  5121. clif_weather(sd->bl.m);
  5122. clif_displaymessage(fd, msg_txt(sd,1210)); // Alternative clouds appear.
  5123. }
  5124. return 0;
  5125. }
  5126. /*==========================================
  5127. * Fog hangs over.
  5128. *------------------------------------------*/
  5129. ACMD_FUNC(fog)
  5130. {
  5131. nullpo_retr(-1, sd);
  5132. if (map[sd->bl.m].flag.fog) {
  5133. map[sd->bl.m].flag.fog=0;
  5134. clif_weather(sd->bl.m);
  5135. clif_displaymessage(fd, msg_txt(sd,1211)); // The fog has gone.
  5136. } else {
  5137. map[sd->bl.m].flag.fog=1;
  5138. clif_weather(sd->bl.m);
  5139. clif_displaymessage(fd, msg_txt(sd,1212)); // Fog hangs over.
  5140. }
  5141. return 0;
  5142. }
  5143. /*==========================================
  5144. * Fallen leaves fall.
  5145. *------------------------------------------*/
  5146. ACMD_FUNC(leaves)
  5147. {
  5148. nullpo_retr(-1, sd);
  5149. if (map[sd->bl.m].flag.leaves) {
  5150. map[sd->bl.m].flag.leaves=0;
  5151. clif_weather(sd->bl.m);
  5152. clif_displaymessage(fd, msg_txt(sd,1213)); // Leaves no longer fall.
  5153. } else {
  5154. map[sd->bl.m].flag.leaves=1;
  5155. clif_weather(sd->bl.m);
  5156. clif_displaymessage(fd, msg_txt(sd,1214)); // Fallen leaves fall.
  5157. }
  5158. return 0;
  5159. }
  5160. /*==========================================
  5161. * Fireworks appear.
  5162. *------------------------------------------*/
  5163. ACMD_FUNC(fireworks)
  5164. {
  5165. nullpo_retr(-1, sd);
  5166. if (map[sd->bl.m].flag.fireworks) {
  5167. map[sd->bl.m].flag.fireworks=0;
  5168. clif_weather(sd->bl.m);
  5169. clif_displaymessage(fd, msg_txt(sd,1215)); // Fireworks have ended.
  5170. } else {
  5171. map[sd->bl.m].flag.fireworks=1;
  5172. clif_weather(sd->bl.m);
  5173. clif_displaymessage(fd, msg_txt(sd,1216)); // Fireworks have launched.
  5174. }
  5175. return 0;
  5176. }
  5177. /*==========================================
  5178. * Clearing Weather Effects by Dexity
  5179. *------------------------------------------*/
  5180. ACMD_FUNC(clearweather)
  5181. {
  5182. nullpo_retr(-1, sd);
  5183. /**
  5184. * No longer available, keeping here just in case it's back someday. [Ind]
  5185. **/
  5186. //map[sd->bl.m].flag.rain=0;
  5187. map[sd->bl.m].flag.snow=0;
  5188. map[sd->bl.m].flag.sakura=0;
  5189. map[sd->bl.m].flag.clouds=0;
  5190. map[sd->bl.m].flag.clouds2=0;
  5191. map[sd->bl.m].flag.fog=0;
  5192. map[sd->bl.m].flag.fireworks=0;
  5193. map[sd->bl.m].flag.leaves=0;
  5194. clif_weather(sd->bl.m);
  5195. clif_displaymessage(fd, msg_txt(sd,291));
  5196. return 0;
  5197. }
  5198. /*===============================================================
  5199. * Sound Command - plays a sound for everyone around! [Codemaster]
  5200. *---------------------------------------------------------------*/
  5201. ACMD_FUNC(sound)
  5202. {
  5203. char sound_file[100];
  5204. memset(sound_file, '\0', sizeof(sound_file));
  5205. if(!message || !*message || sscanf(message, "%99[^\n]", sound_file) < 1) {
  5206. clif_displaymessage(fd, msg_txt(sd,1217)); // Please enter a sound filename (usage: @sound <filename>).
  5207. return -1;
  5208. }
  5209. if(strstr(sound_file, ".wav") == NULL)
  5210. strcat(sound_file, ".wav");
  5211. clif_soundeffectall(&sd->bl, sound_file, 0, AREA);
  5212. return 0;
  5213. }
  5214. /*==========================================
  5215. * MOB Search
  5216. *------------------------------------------*/
  5217. ACMD_FUNC(mobsearch)
  5218. {
  5219. char mob_name[100];
  5220. int mob_id;
  5221. int number = 0;
  5222. struct s_mapiterator* it;
  5223. nullpo_retr(-1, sd);
  5224. if (!message || !*message || sscanf(message, "%99[^\n]", mob_name) < 1) {
  5225. clif_displaymessage(fd, msg_txt(sd,1218)); // Please enter a monster name (usage: @mobsearch <monster name>).
  5226. return -1;
  5227. }
  5228. if ((mob_id = atoi(mob_name)) == 0)
  5229. mob_id = mobdb_searchname(mob_name);
  5230. if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  5231. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1219),mob_name); // Invalid mob ID %s!
  5232. clif_displaymessage(fd, atcmd_output);
  5233. return -1;
  5234. }
  5235. if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  5236. strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
  5237. // strcpy(mob_name,mob_db(mob_id)->name); // --en--
  5238. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s
  5239. clif_displaymessage(fd, atcmd_output);
  5240. it = mapit_geteachmob();
  5241. for(;;)
  5242. {
  5243. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  5244. if( md == NULL )
  5245. break;// no more mobs
  5246. if( md->bl.m != sd->bl.m )
  5247. continue;
  5248. if( mob_id != -1 && md->class_ != mob_id )
  5249. continue;
  5250. ++number;
  5251. if( md->spawn_timer == INVALID_TIMER )
  5252. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%3d:%3d] %s", number, md->bl.x, md->bl.y, md->name);
  5253. else
  5254. snprintf(atcmd_output, sizeof(atcmd_output), "%2d[%s] %s", number, "dead", md->name);
  5255. clif_displaymessage(fd, atcmd_output);
  5256. }
  5257. mapit_free(it);
  5258. return 0;
  5259. }
  5260. /*==========================================
  5261. * @cleanmap - cleans items on the ground
  5262. * @cleanarea - cleans items on the ground within an specified area
  5263. *------------------------------------------*/
  5264. static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap)
  5265. {
  5266. nullpo_ret(bl);
  5267. map_clearflooritem(bl);
  5268. return 0;
  5269. }
  5270. ACMD_FUNC(cleanmap)
  5271. {
  5272. map_foreachinmap(atcommand_cleanfloor_sub, sd->bl.m, BL_ITEM);
  5273. clif_displaymessage(fd, msg_txt(sd,1221)); // All dropped items have been cleaned up.
  5274. return 0;
  5275. }
  5276. ACMD_FUNC(cleanarea)
  5277. {
  5278. int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
  5279. if (!message || !*message || sscanf(message, "%d %d %d %d", &x0, &y0, &x1, &y1) < 1) {
  5280. map_foreachinarea(atcommand_cleanfloor_sub, sd->bl.m, sd->bl.x - (AREA_SIZE * 2), sd->bl.y - (AREA_SIZE * 2), sd->bl.x + (AREA_SIZE * 2), sd->bl.y + (AREA_SIZE * 2), BL_ITEM);
  5281. }
  5282. else if (sscanf(message, "%d %d %d %d", &x0, &y0, &x1, &y1) == 1) {
  5283. map_foreachinarea(atcommand_cleanfloor_sub, sd->bl.m, sd->bl.x - x0, sd->bl.y - x0, sd->bl.x + x0, sd->bl.y + x0, BL_ITEM);
  5284. }
  5285. else if (sscanf(message, "%d %d %d %d", &x0, &y0, &x1, &y1) == 4) {
  5286. map_foreachinarea(atcommand_cleanfloor_sub, sd->bl.m, x0, y0, x1, y1, BL_ITEM);
  5287. }
  5288. clif_displaymessage(fd, msg_txt(sd,1221)); // All dropped items have been cleaned up.
  5289. return 0;
  5290. }
  5291. /*==========================================
  5292. * make a NPC/PET talk
  5293. * @npctalkc [SnakeDrak]
  5294. *------------------------------------------*/
  5295. ACMD_FUNC(npctalk)
  5296. {
  5297. char name[NAME_LENGTH],mes[100],temp[100];
  5298. struct npc_data *nd;
  5299. bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
  5300. unsigned long color=0;
  5301. if (sd->sc.count && //no "chatting" while muted.
  5302. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  5303. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  5304. return -1;
  5305. if(!ifcolor) {
  5306. if (!message || !*message || sscanf(message, "%23[^,], %99[^\n]", name, mes) < 2) {
  5307. clif_displaymessage(fd, msg_txt(sd,1222)); // Please enter the correct parameters (usage: @npctalk <npc name>, <message>).
  5308. return -1;
  5309. }
  5310. }
  5311. else {
  5312. if (!message || !*message || sscanf(message, "%lx %23[^,], %99[^\n]", &color, name, mes) < 3) {
  5313. clif_displaymessage(fd, msg_txt(sd,1223)); // Please enter the correct parameters (usage: @npctalkc <color> <npc name>, <message>).
  5314. return -1;
  5315. }
  5316. }
  5317. if (!(nd = npc_name2id(name))) {
  5318. clif_displaymessage(fd, msg_txt(sd,111)); // This NPC doesn't exist
  5319. return -1;
  5320. }
  5321. strtok(name, "#"); // discard extra name identifier if present
  5322. snprintf(temp, sizeof(temp), "%s : %s", name, mes);
  5323. if(ifcolor) clif_messagecolor(&nd->bl,color,temp);
  5324. else clif_disp_overhead(&nd->bl, temp);
  5325. return 0;
  5326. }
  5327. ACMD_FUNC(pettalk)
  5328. {
  5329. char mes[100],temp[100];
  5330. struct pet_data *pd;
  5331. nullpo_retr(-1, sd);
  5332. if ( battle_config.min_chat_delay ) {
  5333. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  5334. return 0;
  5335. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  5336. }
  5337. if(!sd->status.pet_id || !(pd=sd->pd))
  5338. {
  5339. clif_displaymessage(fd, msg_txt(sd,184));
  5340. return -1;
  5341. }
  5342. if (sd->sc.count && //no "chatting" while muted.
  5343. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  5344. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  5345. return -1;
  5346. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  5347. clif_displaymessage(fd, msg_txt(sd,1224)); // Please enter a message (usage: @pettalk <message>).
  5348. return -1;
  5349. }
  5350. if (message[0] == '/')
  5351. {// pet emotion processing
  5352. const char* emo[] = {
  5353. "/!", "/?", "/ho", "/lv", "/swt", "/ic", "/an", "/ag", "/$", "/...",
  5354. "/scissors", "/rock", "/paper", "/korea", "/lv2", "/thx", "/wah", "/sry", "/heh", "/swt2",
  5355. "/hmm", "/no1", "/??", "/omg", "/O", "/X", "/hlp", "/go", "/sob", "/gg",
  5356. "/kis", "/kis2", "/pif", "/ok", "-?-", "/indonesia", "/bzz", "/rice", "/awsm", "/meh",
  5357. "/shy", "/pat", "/mp", "/slur", "/com", "/yawn", "/grat", "/hp", "/philippines", "/malaysia",
  5358. "/singapore", "/brazil", "/fsh", "/spin", "/sigh", "/dum", "/crwd", "/desp", "/dice", "-dice2",
  5359. "-dice3", "-dice4", "-dice5", "-dice6", "/india", "/love", "/russia", "-?-", "/mobile", "/mail",
  5360. "/chinese", "/antenna1", "/antenna2", "/antenna3", "/hum", "/abs", "/oops", "/spit", "/ene", "/panic",
  5361. "/whisp"
  5362. };
  5363. int i;
  5364. ARR_FIND( 0, ARRAYLENGTH(emo), i, stricmp(message, emo[i]) == 0 );
  5365. if( i == E_DICE1 ) i = rnd()%6 + E_DICE1; // randomize /dice
  5366. if( i < ARRAYLENGTH(emo) )
  5367. {
  5368. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  5369. sd->emotionlasttime = time(NULL);
  5370. return 0;
  5371. }
  5372. sd->emotionlasttime = time(NULL);
  5373. clif_emotion(&pd->bl, i);
  5374. return 0;
  5375. }
  5376. }
  5377. snprintf(temp, sizeof temp ,"%s : %s", pd->pet.name, mes);
  5378. clif_disp_overhead(&pd->bl, temp);
  5379. return 0;
  5380. }
  5381. /// @users - displays the number of players present on each map (and percentage)
  5382. /// #users displays on the target user instead of self
  5383. ACMD_FUNC(users)
  5384. {
  5385. char buf[CHAT_SIZE_MAX];
  5386. int i;
  5387. int users[MAX_MAPINDEX];
  5388. int users_all;
  5389. struct s_mapiterator* iter;
  5390. memset(users, 0, sizeof(users));
  5391. users_all = 0;
  5392. // count users on each map
  5393. iter = mapit_getallusers();
  5394. for(;;)
  5395. {
  5396. struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter);
  5397. if( sd2 == NULL )
  5398. break;// no more users
  5399. if( sd2->mapindex >= MAX_MAPINDEX )
  5400. continue;// invalid mapindex
  5401. if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
  5402. if( users_all < INT_MAX ) ++users_all;
  5403. }
  5404. mapit_free(iter);
  5405. // display results for each map
  5406. for( i = 0; i < MAX_MAPINDEX; ++i )
  5407. {
  5408. if( users[i] == 0 )
  5409. continue;// empty
  5410. safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
  5411. clif_displaymessage(sd->fd, buf);
  5412. }
  5413. // display overall count
  5414. safesnprintf(buf, sizeof(buf), "all: %d", users_all);
  5415. clif_displaymessage(sd->fd, buf);
  5416. return 0;
  5417. }
  5418. /*==========================================
  5419. *
  5420. *------------------------------------------*/
  5421. ACMD_FUNC(reset)
  5422. {
  5423. pc_resetstate(sd);
  5424. pc_resetskill(sd,1);
  5425. sprintf(atcmd_output, msg_txt(sd,208), sd->status.name); // '%s' skill and stats points reseted!
  5426. clif_displaymessage(fd, atcmd_output);
  5427. return 0;
  5428. }
  5429. /*==========================================
  5430. *
  5431. *------------------------------------------*/
  5432. ACMD_FUNC(summon)
  5433. {
  5434. char name[NAME_LENGTH];
  5435. int mob_id = 0;
  5436. int duration = 0;
  5437. struct mob_data *md;
  5438. unsigned int tick=gettick();
  5439. nullpo_retr(-1, sd);
  5440. if (!message || !*message || sscanf(message, "%23s %d", name, &duration) < 1)
  5441. {
  5442. clif_displaymessage(fd, msg_txt(sd,1225)); // Please enter a monster name (usage: @summon <monster name> {duration}).
  5443. return -1;
  5444. }
  5445. if (duration < 1)
  5446. duration =1;
  5447. else if (duration > 60)
  5448. duration =60;
  5449. if ((mob_id = atoi(name)) == 0)
  5450. mob_id = mobdb_searchname(name);
  5451. if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
  5452. {
  5453. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  5454. return -1;
  5455. }
  5456. md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE);
  5457. if(!md)
  5458. return -1;
  5459. md->master_id=sd->bl.id;
  5460. md->special_state.ai=1;
  5461. md->deletetimer=add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
  5462. clif_specialeffect(&md->bl,344,AREA);
  5463. mob_spawn(md);
  5464. sc_start4(NULL,&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  5465. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
  5466. clif_displaymessage(fd, msg_txt(sd,39)); // All monster summoned!
  5467. return 0;
  5468. }
  5469. /*==========================================
  5470. * @adjgroup
  5471. * Temporarily move player to another group
  5472. * Useful during beta testing to allow players to use GM commands for short periods of time
  5473. *------------------------------------------*/
  5474. ACMD_FUNC(adjgroup)
  5475. {
  5476. int new_group = 0;
  5477. nullpo_retr(-1, sd);
  5478. if (!message || !*message || sscanf(message, "%d", &new_group) != 1) {
  5479. clif_displaymessage(fd, msg_txt(sd,1226)); // Usage: @adjgroup <group_id>
  5480. return -1;
  5481. }
  5482. if (!pc_group_exists(new_group)) {
  5483. clif_displaymessage(fd, msg_txt(sd,1227)); // Specified group does not exist.
  5484. return -1;
  5485. }
  5486. sd->group_id = new_group;
  5487. pc_group_pc_load(sd);/* update cache */
  5488. clif_displaymessage(fd, msg_txt(sd,1228)); // Group changed successfully.
  5489. clif_displaymessage(sd->fd, msg_txt(sd,1229)); // Your group has changed.
  5490. return 0;
  5491. }
  5492. /*==========================================
  5493. * @trade by [MouseJstr]
  5494. * Open a trade window with a remote player
  5495. *------------------------------------------*/
  5496. ACMD_FUNC(trade)
  5497. {
  5498. struct map_session_data *pl_sd = NULL;
  5499. nullpo_retr(-1, sd);
  5500. if (!message || !*message) {
  5501. clif_displaymessage(fd, msg_txt(sd,1230)); // Please enter a player name (usage: @trade <char name>).
  5502. return -1;
  5503. }
  5504. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5505. {
  5506. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5507. return -1;
  5508. }
  5509. trade_traderequest(sd, pl_sd);
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. * @setbattleflag by [MouseJstr]
  5514. * set a battle_config flag without having to reboot
  5515. *------------------------------------------*/
  5516. ACMD_FUNC(setbattleflag)
  5517. {
  5518. char flag[128], value[128];
  5519. nullpo_retr(-1, sd);
  5520. if (!message || !*message || sscanf(message, "%127s %127s", flag, value) != 2) {
  5521. clif_displaymessage(fd, msg_txt(sd,1231)); // Usage: @setbattleflag <flag> <value>
  5522. return -1;
  5523. }
  5524. if (battle_set_value(flag, value) == 0)
  5525. {
  5526. clif_displaymessage(fd, msg_txt(sd,1232)); // Unknown battle_config flag.
  5527. return -1;
  5528. }
  5529. clif_displaymessage(fd, msg_txt(sd,1233)); // Set battle_config as requested.
  5530. return 0;
  5531. }
  5532. /*==========================================
  5533. * @unmute [Valaris]
  5534. *------------------------------------------*/
  5535. ACMD_FUNC(unmute)
  5536. {
  5537. struct map_session_data *pl_sd = NULL;
  5538. nullpo_retr(-1, sd);
  5539. if (!message || !*message) {
  5540. clif_displaymessage(fd, msg_txt(sd,1234)); // Please enter a player name (usage: @unmute <char name>).
  5541. return -1;
  5542. }
  5543. if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
  5544. {
  5545. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5546. return -1;
  5547. }
  5548. if(!pl_sd->sc.data[SC_NOCHAT]) {
  5549. clif_displaymessage(sd->fd,msg_txt(sd,1235)); // Player is not muted.
  5550. return -1;
  5551. }
  5552. pl_sd->status.manner = 0;
  5553. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  5554. clif_displaymessage(sd->fd,msg_txt(sd,1236)); // Player unmuted.
  5555. return 0;
  5556. }
  5557. /*==========================================
  5558. * @uptime by MC Cameri
  5559. *------------------------------------------*/
  5560. ACMD_FUNC(uptime)
  5561. {
  5562. unsigned long seconds = 0, day = 24*60*60, hour = 60*60,
  5563. minute = 60, days = 0, hours = 0, minutes = 0;
  5564. nullpo_retr(-1, sd);
  5565. seconds = get_uptime();
  5566. days = seconds/day;
  5567. seconds -= (seconds/day>0)?(seconds/day)*day:0;
  5568. hours = seconds/hour;
  5569. seconds -= (seconds/hour>0)?(seconds/hour)*hour:0;
  5570. minutes = seconds/minute;
  5571. seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
  5572. snprintf(atcmd_output, sizeof(atcmd_output), msg_txt(sd,245), days, hours, minutes, seconds);
  5573. clif_displaymessage(fd, atcmd_output);
  5574. return 0;
  5575. }
  5576. /*==========================================
  5577. * @changesex <sex>
  5578. * => Changes one's sex. Argument sex can be 0 or 1, m or f, male or female.
  5579. *------------------------------------------*/
  5580. ACMD_FUNC(changesex)
  5581. {
  5582. int i;
  5583. nullpo_retr(-1, sd);
  5584. pc_resetskill(sd,4);
  5585. // to avoid any problem with equipment and invalid sex, equipment is unequiped.
  5586. for( i=0; i<EQI_MAX; i++ )
  5587. if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3);
  5588. chrif_changesex(sd);
  5589. return 0;
  5590. }
  5591. /*================================================
  5592. * @mute - Mutes a player for a set amount of time
  5593. *------------------------------------------------*/
  5594. ACMD_FUNC(mute)
  5595. {
  5596. struct map_session_data *pl_sd = NULL;
  5597. int manner;
  5598. nullpo_retr(-1, sd);
  5599. if (!message || !*message || sscanf(message, "%d %23[^\n]", &manner, atcmd_player_name) < 1) {
  5600. clif_displaymessage(fd, msg_txt(sd,1237)); // Usage: @mute <time> <char name>
  5601. return -1;
  5602. }
  5603. if ( (pl_sd = map_nick2sd(atcmd_player_name)) == NULL )
  5604. {
  5605. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  5606. return -1;
  5607. }
  5608. if ( pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  5609. {
  5610. clif_displaymessage(fd, msg_txt(sd,81)); // Your GM level don't authorise you to do this action on this player.
  5611. return -1;
  5612. }
  5613. clif_manner_message(sd, 0);
  5614. clif_manner_message(pl_sd, 5);
  5615. if( pl_sd->status.manner < manner ) {
  5616. pl_sd->status.manner -= manner;
  5617. sc_start(NULL,&pl_sd->bl,SC_NOCHAT,100,0,0);
  5618. } else {
  5619. pl_sd->status.manner = 0;
  5620. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  5621. }
  5622. clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
  5623. return 0;
  5624. }
  5625. /*==========================================
  5626. * @refresh (like @jumpto <<yourself>>)
  5627. *------------------------------------------*/
  5628. ACMD_FUNC(refresh)
  5629. {
  5630. nullpo_retr(-1, sd);
  5631. clif_refresh(sd);
  5632. return 0;
  5633. }
  5634. ACMD_FUNC(refreshall)
  5635. {
  5636. struct map_session_data* iter_sd;
  5637. struct s_mapiterator* iter;
  5638. nullpo_retr(-1, sd);
  5639. iter = mapit_getallusers();
  5640. for (iter_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); iter_sd = (TBL_PC*)mapit_next(iter))
  5641. clif_refresh(iter_sd);
  5642. mapit_free(iter);
  5643. return 0;
  5644. }
  5645. /*==========================================
  5646. * @identify
  5647. * => GM's magnifier.
  5648. *------------------------------------------*/
  5649. ACMD_FUNC(identify)
  5650. {
  5651. int i,num;
  5652. nullpo_retr(-1, sd);
  5653. for(i=num=0;i<MAX_INVENTORY;i++){
  5654. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  5655. num++;
  5656. }
  5657. }
  5658. if (num > 0) {
  5659. clif_item_identify_list(sd);
  5660. } else {
  5661. clif_displaymessage(fd,msg_txt(sd,1238)); // There are no items to appraise.
  5662. }
  5663. return 0;
  5664. }
  5665. /*==========================================
  5666. * @gmotd (Global MOTD)
  5667. * by davidsiaw :P
  5668. *------------------------------------------*/
  5669. ACMD_FUNC(gmotd)
  5670. {
  5671. FILE* fp;
  5672. if( ( fp = fopen(motd_txt, "r") ) != NULL )
  5673. {
  5674. char buf[CHAT_SIZE_MAX];
  5675. size_t len;
  5676. while( fgets(buf, sizeof(buf), fp) )
  5677. {
  5678. if( buf[0] == '/' && buf[1] == '/' )
  5679. {
  5680. continue;
  5681. }
  5682. len = strlen(buf);
  5683. while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) )
  5684. {// strip trailing EOL characters
  5685. len--;
  5686. }
  5687. if( len )
  5688. {
  5689. buf[len] = 0;
  5690. intif_broadcast(buf, len+1, 0);
  5691. }
  5692. }
  5693. fclose(fp);
  5694. }
  5695. return 0;
  5696. }
  5697. ACMD_FUNC(misceffect)
  5698. {
  5699. int effect = 0;
  5700. nullpo_retr(-1, sd);
  5701. if (!message || !*message)
  5702. return -1;
  5703. if (sscanf(message, "%d", &effect) < 1)
  5704. return -1;
  5705. clif_misceffect(&sd->bl,effect);
  5706. return 0;
  5707. }
  5708. /*==========================================
  5709. * MAIL SYSTEM
  5710. *------------------------------------------*/
  5711. ACMD_FUNC(mail)
  5712. {
  5713. nullpo_ret(sd);
  5714. mail_openmail(sd);
  5715. return 0;
  5716. }
  5717. /*==========================================
  5718. * Show Monster DB Info v 1.0
  5719. * originally by [Lupus]
  5720. *------------------------------------------*/
  5721. ACMD_FUNC(mobinfo)
  5722. {
  5723. unsigned char msize[3][7] = {"Small", "Medium", "Large"};
  5724. unsigned char mrace[12][11] = {"Formless", "Undead", "Beast", "Plant", "Insect", "Fish", "Demon", "Demi-Human", "Angel", "Dragon", "Boss", "Non-Boss"};
  5725. unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
  5726. char atcmd_output2[CHAT_SIZE_MAX];
  5727. struct item_data *item_data;
  5728. struct mob_db *mob, *mob_array[MAX_SEARCH];
  5729. int count;
  5730. int i, j, k;
  5731. unsigned int base_exp, job_exp;
  5732. memset(atcmd_output, '\0', sizeof(atcmd_output));
  5733. memset(atcmd_output2, '\0', sizeof(atcmd_output2));
  5734. if (!message || !*message) {
  5735. clif_displaymessage(fd, msg_txt(sd,1239)); // Please enter a monster name/ID (usage: @mobinfo <monster_name_or_monster_ID>).
  5736. return -1;
  5737. }
  5738. // If monster identifier/name argument is a name
  5739. if ((i = mobdb_checkid(atoi(message))))
  5740. {
  5741. mob_array[0] = mob_db(i);
  5742. count = 1;
  5743. } else
  5744. count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  5745. if (!count) {
  5746. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  5747. return -1;
  5748. }
  5749. if (count > MAX_SEARCH) {
  5750. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH, count);
  5751. clif_displaymessage(fd, atcmd_output);
  5752. count = MAX_SEARCH;
  5753. }
  5754. for (k = 0; k < count; k++) {
  5755. mob = mob_array[k];
  5756. base_exp = mob->base_exp;
  5757. job_exp = mob->job_exp;
  5758. #ifdef RENEWAL_EXP
  5759. if( battle_config.atcommand_mobinfo_type ) {
  5760. base_exp = base_exp * pc_level_penalty_mod(sd, mob->lv, mob->status.race, mob->status.mode, 1) / 100;
  5761. job_exp = job_exp * pc_level_penalty_mod(sd, mob->lv, mob->status.race, mob->status.mode, 1) / 100;
  5762. }
  5763. #endif
  5764. // stats
  5765. if (mob->mexp)
  5766. sprintf(atcmd_output, msg_txt(sd,1240), mob->name, mob->jname, mob->sprite, mob->vd.class_); // MVP Monster: '%s'/'%s'/'%s' (%d)
  5767. else
  5768. sprintf(atcmd_output, msg_txt(sd,1241), mob->name, mob->jname, mob->sprite, mob->vd.class_); // Monster: '%s'/'%s'/'%s' (%d)
  5769. clif_displaymessage(fd, atcmd_output);
  5770. sprintf(atcmd_output, msg_txt(sd,1242), mob->lv, mob->status.max_hp, base_exp, job_exp, MOB_HIT(mob), MOB_FLEE(mob)); // Lv:%d HP:%d Base EXP:%u Job EXP:%u HIT:%d FLEE:%d
  5771. clif_displaymessage(fd, atcmd_output);
  5772. sprintf(atcmd_output, msg_txt(sd,1243), // DEF:%d MDEF:%d STR:%d AGI:%d VIT:%d INT:%d DEX:%d LUK:%d
  5773. mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
  5774. mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
  5775. clif_displaymessage(fd, atcmd_output);
  5776. sprintf(atcmd_output, msg_txt(sd,1244), // ATK:%d~%d Range:%d~%d~%d Size:%s Race: %s Element: %s (Lv:%d)
  5777. mob->status.rhw.atk, mob->status.rhw.atk2, mob->status.rhw.range,
  5778. mob->range2 , mob->range3, msize[mob->status.size],
  5779. mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
  5780. clif_displaymessage(fd, atcmd_output);
  5781. // drops
  5782. clif_displaymessage(fd, msg_txt(sd,1245)); // Drops:
  5783. strcpy(atcmd_output, " ");
  5784. j = 0;
  5785. for (i = 0; i < MAX_MOB_DROP; i++) {
  5786. int droprate;
  5787. if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL)
  5788. continue;
  5789. droprate = mob->dropitem[i].p;
  5790. #ifdef RENEWAL_DROP
  5791. if( battle_config.atcommand_mobinfo_type )
  5792. droprate = droprate * pc_level_penalty_mod(sd, mob->lv, mob->status.race, mob->status.mode, 2) / 100;
  5793. #endif
  5794. if (item_data->slot)
  5795. sprintf(atcmd_output2, " - %s[%d] %02.02f%%", item_data->jname, item_data->slot, (float)droprate / 100);
  5796. else
  5797. sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)droprate / 100);
  5798. strcat(atcmd_output, atcmd_output2);
  5799. if (++j % 3 == 0) {
  5800. clif_displaymessage(fd, atcmd_output);
  5801. strcpy(atcmd_output, " ");
  5802. }
  5803. }
  5804. if (j == 0)
  5805. clif_displaymessage(fd, msg_txt(sd,1246)); // This monster has no drops.
  5806. else if (j % 3 != 0)
  5807. clif_displaymessage(fd, atcmd_output);
  5808. // mvp
  5809. if (mob->mexp) {
  5810. sprintf(atcmd_output, msg_txt(sd,1247), mob->mexp); // MVP Bonus EXP:%u
  5811. clif_displaymessage(fd, atcmd_output);
  5812. strcpy(atcmd_output, msg_txt(sd,1248)); // MVP Items:
  5813. j = 0;
  5814. for (i = 0; i < MAX_MVP_DROP; i++) {
  5815. if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL)
  5816. continue;
  5817. if (mob->mvpitem[i].p > 0) {
  5818. j++;
  5819. if (j == 1)
  5820. sprintf(atcmd_output2, " %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  5821. else
  5822. sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
  5823. strcat(atcmd_output, atcmd_output2);
  5824. }
  5825. }
  5826. if (j == 0)
  5827. clif_displaymessage(fd, msg_txt(sd,1249)); // This monster has no MVP prizes.
  5828. else
  5829. clif_displaymessage(fd, atcmd_output);
  5830. }
  5831. }
  5832. return 0;
  5833. }
  5834. /*=========================================
  5835. * @showmobs by KarLaeda
  5836. * => For 15 sec displays the mobs on minimap
  5837. *------------------------------------------*/
  5838. ACMD_FUNC(showmobs)
  5839. {
  5840. char mob_name[100];
  5841. int mob_id;
  5842. int number = 0;
  5843. struct s_mapiterator* it;
  5844. nullpo_retr(-1, sd);
  5845. if(sscanf(message, "%99[^\n]", mob_name) < 0)
  5846. return -1;
  5847. if((mob_id = atoi(mob_name)) == 0)
  5848. mob_id = mobdb_searchname(mob_name);
  5849. if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
  5850. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1250),mob_name); // Invalid mob id %s!
  5851. clif_displaymessage(fd, atcmd_output);
  5852. return 0;
  5853. }
  5854. 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.
  5855. clif_displaymessage(fd, msg_txt(sd,1251)); // Can't show boss mobs!
  5856. return 0;
  5857. }
  5858. if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
  5859. strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
  5860. //strcpy(mob_name,mob_db(mob_id)->name); // --en--
  5861. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1252), // Mob Search... %s %s
  5862. mob_name, mapindex_id2name(sd->mapindex));
  5863. clif_displaymessage(fd, atcmd_output);
  5864. it = mapit_geteachmob();
  5865. for(;;)
  5866. {
  5867. TBL_MOB* md = (TBL_MOB*)mapit_next(it);
  5868. if( md == NULL )
  5869. break;// no more mobs
  5870. if( md->bl.m != sd->bl.m )
  5871. continue;
  5872. if( mob_id != -1 && md->class_ != mob_id )
  5873. continue;
  5874. if( md->special_state.ai || md->master_id )
  5875. continue; // hide slaves and player summoned mobs
  5876. if( md->spawn_timer != INVALID_TIMER )
  5877. continue; // hide mobs waiting for respawn
  5878. ++number;
  5879. clif_viewpoint(sd, 1, 0, md->bl.x, md->bl.y, number, 0xFFFFFF);
  5880. }
  5881. mapit_free(it);
  5882. return 0;
  5883. }
  5884. /*==========================================
  5885. * homunculus level up [orn]
  5886. *------------------------------------------*/
  5887. ACMD_FUNC(homlevel)
  5888. {
  5889. TBL_HOM * hd;
  5890. int level = 0, i = 0;
  5891. nullpo_retr(-1, sd);
  5892. if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
  5893. clif_displaymessage(fd, msg_txt(sd,1253)); // Please enter a level adjustment (usage: @homlevel <number of levels>).
  5894. return -1;
  5895. }
  5896. if ( !merc_is_hom_active(sd->hd) ) {
  5897. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  5898. return -1;
  5899. }
  5900. hd = sd->hd;
  5901. for (i = 1; i <= level && hd->exp_next; i++){
  5902. hd->homunculus.exp += hd->exp_next;
  5903. if( !merc_hom_levelup(hd) ){
  5904. break;
  5905. }
  5906. }
  5907. status_calc_homunculus(hd,0);
  5908. status_percent_heal(&hd->bl, 100, 100);
  5909. clif_specialeffect(&hd->bl,568,AREA);
  5910. return 0;
  5911. }
  5912. /*==========================================
  5913. * homunculus evolution H [orn]
  5914. *------------------------------------------*/
  5915. ACMD_FUNC(homevolution)
  5916. {
  5917. nullpo_retr(-1, sd);
  5918. if ( !merc_is_hom_active(sd->hd) ) {
  5919. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  5920. return -1;
  5921. }
  5922. if ( !merc_hom_evolution(sd->hd) ) {
  5923. clif_displaymessage(fd, msg_txt(sd,1255)); // Your homunculus doesn't evolve.
  5924. return -1;
  5925. }
  5926. clif_homskillinfoblock(sd);
  5927. return 0;
  5928. }
  5929. ACMD_FUNC(hommutate)
  5930. {
  5931. int homun_id, m_class = 0, m_id;
  5932. nullpo_retr(-1, sd);
  5933. if (!merc_is_hom_active(sd->hd)) {
  5934. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  5935. return -1;
  5936. }
  5937. if (!message || !*message) {
  5938. homun_id = 6048 + (rnd() % 4);
  5939. } else {
  5940. homun_id = atoi(message);
  5941. }
  5942. m_class = hom_class2mapid(sd->hd->homunculus.class_);
  5943. m_id = hom_class2mapid(homun_id);
  5944. if (m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99) {
  5945. hom_mutate(sd->hd, homun_id);
  5946. } else {
  5947. clif_emotion(&sd->hd->bl, E_SWT);
  5948. }
  5949. return 0;
  5950. }
  5951. /*==========================================
  5952. * call choosen homunculus [orn]
  5953. *------------------------------------------*/
  5954. ACMD_FUNC(makehomun)
  5955. {
  5956. int homunid;
  5957. nullpo_retr(-1, sd);
  5958. if ( sd->status.hom_id ) {
  5959. clif_displaymessage(fd, msg_txt(sd,450));
  5960. return -1;
  5961. }
  5962. if (!message || !*message) {
  5963. clif_displaymessage(fd, msg_txt(sd,1256)); // Please enter a homunculus ID (usage: @makehomun <homunculus id>).
  5964. return -1;
  5965. }
  5966. homunid = atoi(message);
  5967. if( homunid < HM_CLASS_BASE || homunid > HM_CLASS_BASE + MAX_HOMUNCULUS_CLASS - 1 )
  5968. {
  5969. clif_displaymessage(fd, msg_txt(sd,1257)); // Invalid Homunculus ID.
  5970. return -1;
  5971. }
  5972. merc_create_homunculus_request(sd,homunid);
  5973. return 0;
  5974. }
  5975. /*==========================================
  5976. * modify homunculus intimacy [orn]
  5977. *------------------------------------------*/
  5978. ACMD_FUNC(homfriendly)
  5979. {
  5980. int friendly = 0;
  5981. nullpo_retr(-1, sd);
  5982. if ( !merc_is_hom_active(sd->hd) ) {
  5983. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  5984. return -1;
  5985. }
  5986. if (!message || !*message) {
  5987. clif_displaymessage(fd, msg_txt(sd,1258)); // Please enter a friendly value (usage: @homfriendly <friendly value [0-1000]>).
  5988. return -1;
  5989. }
  5990. friendly = atoi(message);
  5991. friendly = cap_value(friendly, 0, 1000);
  5992. sd->hd->homunculus.intimacy = friendly * 100 ;
  5993. clif_send_homdata(sd,SP_INTIMATE,friendly);
  5994. return 0;
  5995. }
  5996. /*==========================================
  5997. * modify homunculus hunger [orn]
  5998. *------------------------------------------*/
  5999. ACMD_FUNC(homhungry)
  6000. {
  6001. int hungry = 0;
  6002. nullpo_retr(-1, sd);
  6003. if ( !merc_is_hom_active(sd->hd) ) {
  6004. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6005. return -1;
  6006. }
  6007. if (!message || !*message) {
  6008. clif_displaymessage(fd, msg_txt(sd,1259)); // Please enter a hunger value (usage: @homhungry <hunger value [0-100]>).
  6009. return -1;
  6010. }
  6011. hungry = atoi(message);
  6012. hungry = cap_value(hungry, 0, 100);
  6013. sd->hd->homunculus.hunger = hungry;
  6014. clif_send_homdata(sd,SP_HUNGRY,hungry);
  6015. return 0;
  6016. }
  6017. /*==========================================
  6018. * make the homunculus speak [orn]
  6019. *------------------------------------------*/
  6020. ACMD_FUNC(homtalk)
  6021. {
  6022. char mes[100],temp[100];
  6023. nullpo_retr(-1, sd);
  6024. if ( battle_config.min_chat_delay ) {
  6025. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  6026. return 0;
  6027. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  6028. }
  6029. if (sd->sc.count && //no "chatting" while muted.
  6030. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  6031. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6032. return -1;
  6033. if ( !merc_is_hom_active(sd->hd) ) {
  6034. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6035. return -1;
  6036. }
  6037. if (!message || !*message || sscanf(message, "%99[^\n]", mes) < 1) {
  6038. clif_displaymessage(fd, msg_txt(sd,1260)); // Please enter a message (usage: @homtalk <message>).
  6039. return -1;
  6040. }
  6041. snprintf(temp, sizeof temp ,"%s : %s", sd->hd->homunculus.name, mes);
  6042. clif_disp_overhead(&sd->hd->bl, temp);
  6043. return 0;
  6044. }
  6045. /*==========================================
  6046. * Show homunculus stats
  6047. *------------------------------------------*/
  6048. ACMD_FUNC(hominfo)
  6049. {
  6050. struct homun_data *hd;
  6051. struct status_data *status;
  6052. nullpo_retr(-1, sd);
  6053. if ( !merc_is_hom_active(sd->hd) ) {
  6054. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6055. return -1;
  6056. }
  6057. hd = sd->hd;
  6058. status = status_get_status_data(&hd->bl);
  6059. clif_displaymessage(fd, msg_txt(sd,1261)); // Homunculus stats:
  6060. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1262), // HP: %d/%d - SP: %d/%d
  6061. status->hp, status->max_hp, status->sp, status->max_sp);
  6062. clif_displaymessage(fd, atcmd_output);
  6063. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1263), // ATK: %d - MATK: %d~%d
  6064. status->rhw.atk2 +status->batk, status->matk_min, status->matk_max);
  6065. clif_displaymessage(fd, atcmd_output);
  6066. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1264), // Hungry: %d - Intimacy: %u
  6067. hd->homunculus.hunger, hd->homunculus.intimacy/100);
  6068. clif_displaymessage(fd, atcmd_output);
  6069. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6070. msg_txt(sd,1265), // Stats: Str %d / Agi %d / Vit %d / Int %d / Dex %d / Luk %d
  6071. status->str, status->agi, status->vit,
  6072. status->int_, status->dex, status->luk);
  6073. clif_displaymessage(fd, atcmd_output);
  6074. return 0;
  6075. }
  6076. ACMD_FUNC(homstats)
  6077. {
  6078. struct homun_data *hd;
  6079. struct s_homunculus_db *db;
  6080. struct s_homunculus *hom;
  6081. int lv, min, max, evo;
  6082. nullpo_retr(-1, sd);
  6083. if ( !merc_is_hom_active(sd->hd) ) {
  6084. clif_displaymessage(fd, msg_txt(sd,1254)); // You do not have a homunculus.
  6085. return -1;
  6086. }
  6087. hd = sd->hd;
  6088. hom = &hd->homunculus;
  6089. db = hd->homunculusDB;
  6090. lv = hom->level;
  6091. snprintf(atcmd_output, sizeof(atcmd_output) ,
  6092. msg_txt(sd,1266), lv, db->name); // Homunculus growth stats (Lv %d %s):
  6093. clif_displaymessage(fd, atcmd_output);
  6094. lv--; //Since the first increase is at level 2.
  6095. evo = (hom->class_ == db->evo_class);
  6096. min = db->base.HP +lv*db->gmin.HP +(evo?db->emin.HP:0);
  6097. max = db->base.HP +lv*db->gmax.HP +(evo?db->emax.HP:0);;
  6098. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1267), hom->max_hp, min, max); // Max HP: %d (%d~%d)
  6099. clif_displaymessage(fd, atcmd_output);
  6100. min = db->base.SP +lv*db->gmin.SP +(evo?db->emin.SP:0);
  6101. max = db->base.SP +lv*db->gmax.SP +(evo?db->emax.SP:0);;
  6102. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1268), hom->max_sp, min, max); // Max SP: %d (%d~%d)
  6103. clif_displaymessage(fd, atcmd_output);
  6104. min = db->base.str +lv*(db->gmin.str/10) +(evo?db->emin.str:0);
  6105. max = db->base.str +lv*(db->gmax.str/10) +(evo?db->emax.str:0);;
  6106. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1269), hom->str/10, min, max); // Str: %d (%d~%d)
  6107. clif_displaymessage(fd, atcmd_output);
  6108. min = db->base.agi +lv*(db->gmin.agi/10) +(evo?db->emin.agi:0);
  6109. max = db->base.agi +lv*(db->gmax.agi/10) +(evo?db->emax.agi:0);;
  6110. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1270), hom->agi/10, min, max); // Agi: %d (%d~%d)
  6111. clif_displaymessage(fd, atcmd_output);
  6112. min = db->base.vit +lv*(db->gmin.vit/10) +(evo?db->emin.vit:0);
  6113. max = db->base.vit +lv*(db->gmax.vit/10) +(evo?db->emax.vit:0);;
  6114. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1271), hom->vit/10, min, max); // Vit: %d (%d~%d)
  6115. clif_displaymessage(fd, atcmd_output);
  6116. min = db->base.int_ +lv*(db->gmin.int_/10) +(evo?db->emin.int_:0);
  6117. max = db->base.int_ +lv*(db->gmax.int_/10) +(evo?db->emax.int_:0);;
  6118. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1272), hom->int_/10, min, max); // Int: %d (%d~%d)
  6119. clif_displaymessage(fd, atcmd_output);
  6120. min = db->base.dex +lv*(db->gmin.dex/10) +(evo?db->emin.dex:0);
  6121. max = db->base.dex +lv*(db->gmax.dex/10) +(evo?db->emax.dex:0);;
  6122. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1273), hom->dex/10, min, max); // Dex: %d (%d~%d)
  6123. clif_displaymessage(fd, atcmd_output);
  6124. min = db->base.luk +lv*(db->gmin.luk/10) +(evo?db->emin.luk:0);
  6125. max = db->base.luk +lv*(db->gmax.luk/10) +(evo?db->emax.luk:0);;
  6126. snprintf(atcmd_output, sizeof(atcmd_output) ,msg_txt(sd,1274), hom->luk/10, min, max); // Luk: %d (%d~%d)
  6127. clif_displaymessage(fd, atcmd_output);
  6128. return 0;
  6129. }
  6130. ACMD_FUNC(homshuffle)
  6131. {
  6132. nullpo_retr(-1, sd);
  6133. if(!sd->hd)
  6134. return -1; // nothing to do
  6135. if(!merc_hom_shuffle(sd->hd))
  6136. return -1;
  6137. clif_displaymessage(sd->fd, msg_txt(sd,1275)); // Homunculus stats altered.
  6138. atcommand_homstats(fd, sd, command, message); //Print out the new stats
  6139. return 0;
  6140. }
  6141. /*==========================================
  6142. * Show Items DB Info v 1.0
  6143. * originally by [Lupus]
  6144. *------------------------------------------*/
  6145. ACMD_FUNC(iteminfo)
  6146. {
  6147. struct item_data *item_data, *item_array[MAX_SEARCH];
  6148. int i, count = 1;
  6149. if (!message || !*message) {
  6150. clif_displaymessage(fd, msg_txt(sd,1276)); // Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>).
  6151. return -1;
  6152. }
  6153. if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  6154. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  6155. if (!count) {
  6156. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  6157. return -1;
  6158. }
  6159. if (count > MAX_SEARCH) {
  6160. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  6161. clif_displaymessage(fd, atcmd_output);
  6162. count = MAX_SEARCH;
  6163. }
  6164. for (i = 0; i < count; i++) {
  6165. item_data = item_array[i];
  6166. sprintf(atcmd_output, msg_txt(sd,1277), // Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
  6167. item_data->name,item_data->jname,item_data->slot,item_data->nameid,
  6168. itemdb_typename(item_data->type),
  6169. (item_data->script==NULL)? msg_txt(sd,1278) : msg_txt(sd,1279) // None / With script
  6170. );
  6171. clif_displaymessage(fd, atcmd_output);
  6172. sprintf(atcmd_output, msg_txt(sd,1280), item_data->value_buy, item_data->value_sell, item_data->weight/10. ); // NPC Buy:%dz, Sell:%dz | Weight: %.1f
  6173. clif_displaymessage(fd, atcmd_output);
  6174. if (item_data->maxchance == -1)
  6175. strcpy(atcmd_output, msg_txt(sd,1281)); // - Available in the shops only.
  6176. else if (!battle_config.atcommand_mobinfo_type && item_data->maxchance)
  6177. sprintf(atcmd_output, msg_txt(sd,1282), (float)item_data->maxchance / 100 ); // - Maximal monsters drop chance: %02.02f%%
  6178. else
  6179. strcpy(atcmd_output, msg_txt(sd,1283)); // - Monsters don't drop this item.
  6180. clif_displaymessage(fd, atcmd_output);
  6181. }
  6182. return 0;
  6183. }
  6184. /*==========================================
  6185. * Show who drops the item.
  6186. *------------------------------------------*/
  6187. ACMD_FUNC(whodrops)
  6188. {
  6189. struct item_data *item_data, *item_array[MAX_SEARCH];
  6190. int i,j, count = 1;
  6191. if (!message || !*message) {
  6192. clif_displaymessage(fd, msg_txt(sd,1284)); // Please enter item name/ID (usage: @whodrops <item name/ID>).
  6193. return -1;
  6194. }
  6195. if ((item_array[0] = itemdb_exists(atoi(message))) == NULL)
  6196. count = itemdb_searchname_array(item_array, MAX_SEARCH, message);
  6197. if (!count) {
  6198. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  6199. return -1;
  6200. }
  6201. if (count > MAX_SEARCH) {
  6202. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH, count); // Displaying first %d out of %d matches
  6203. clif_displaymessage(fd, atcmd_output);
  6204. count = MAX_SEARCH;
  6205. }
  6206. for (i = 0; i < count; i++) {
  6207. item_data = item_array[i];
  6208. sprintf(atcmd_output, msg_txt(sd,1285), item_data->jname,item_data->slot); // Item: '%s'[%d]
  6209. clif_displaymessage(fd, atcmd_output);
  6210. if (item_data->mob[0].chance == 0) {
  6211. strcpy(atcmd_output, msg_txt(sd,1286)); // - Item is not dropped by mobs.
  6212. clif_displaymessage(fd, atcmd_output);
  6213. } else {
  6214. sprintf(atcmd_output, msg_txt(sd,1287), MAX_SEARCH); // - Common mobs with highest drop chance (only max %d are listed):
  6215. clif_displaymessage(fd, atcmd_output);
  6216. for (j=0; j < MAX_SEARCH && item_data->mob[j].chance > 0; j++)
  6217. {
  6218. int dropchance = item_data->mob[j].chance;
  6219. #ifdef RENEWAL_DROP
  6220. if( battle_config.atcommand_mobinfo_type )
  6221. dropchance = dropchance * pc_level_penalty_mod(sd, mob_db(item_data->mob[j].id)->lv, mob_db(item_data->mob[j].id)->status.race, mob_db(item_data->mob[j].id)->status.mode, 2) / 100;
  6222. #endif
  6223. sprintf(atcmd_output, "- %s (%02.02f%%)", mob_db(item_data->mob[j].id)->jname, dropchance/100.);
  6224. clif_displaymessage(fd, atcmd_output);
  6225. }
  6226. }
  6227. }
  6228. return 0;
  6229. }
  6230. ACMD_FUNC(whereis)
  6231. {
  6232. struct mob_db *mob, *mob_array[MAX_SEARCH];
  6233. int count;
  6234. int i, j, k;
  6235. if (!message || !*message) {
  6236. clif_displaymessage(fd, msg_txt(sd,1288)); // Please enter a monster name/ID (usage: @whereis <monster_name_or_monster_ID>).
  6237. return -1;
  6238. }
  6239. // If monster identifier/name argument is a name
  6240. if ((i = mobdb_checkid(atoi(message))))
  6241. {
  6242. mob_array[0] = mob_db(i);
  6243. count = 1;
  6244. } else
  6245. count = mobdb_searchname_array(mob_array, MAX_SEARCH, message);
  6246. if (!count) {
  6247. clif_displaymessage(fd, msg_txt(sd,40)); // Invalid monster ID or name.
  6248. return -1;
  6249. }
  6250. if (count > MAX_SEARCH) {
  6251. sprintf(atcmd_output, msg_txt(sd,269), MAX_SEARCH, count);
  6252. clif_displaymessage(fd, atcmd_output);
  6253. count = MAX_SEARCH;
  6254. }
  6255. for (k = 0; k < count; k++) {
  6256. mob = mob_array[k];
  6257. snprintf(atcmd_output, sizeof atcmd_output, msg_txt(sd,1289), mob->jname); // %s spawns in:
  6258. clif_displaymessage(fd, atcmd_output);
  6259. for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
  6260. {
  6261. j = map_mapindex2mapid(mob->spawn[i].mapindex);
  6262. if (j < 0) continue;
  6263. snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, mob->spawn[i].qty);
  6264. clif_displaymessage(fd, atcmd_output);
  6265. }
  6266. if (i == 0)
  6267. clif_displaymessage(fd, msg_txt(sd,1290)); // This monster does not spawn normally.
  6268. }
  6269. return 0;
  6270. }
  6271. ACMD_FUNC(version)
  6272. {
  6273. const char * revision;
  6274. if ((revision = get_svn_revision()) != 0) {
  6275. sprintf(atcmd_output,msg_txt(sd,1295),revision); // rAthena Version SVN r%s
  6276. clif_displaymessage(fd,atcmd_output);
  6277. } else
  6278. clif_displaymessage(fd,msg_txt(sd,1296)); // Cannot determine SVN revision.
  6279. return 0;
  6280. }
  6281. /*==========================================
  6282. * @mutearea by MouseJstr
  6283. *------------------------------------------*/
  6284. static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
  6285. {
  6286. int time, id;
  6287. struct map_session_data *pl_sd = (struct map_session_data *)bl;
  6288. if (pl_sd == NULL)
  6289. return 0;
  6290. id = va_arg(ap, int);
  6291. time = va_arg(ap, int);
  6292. if (id != bl->id && !pc_get_group_level(pl_sd)) {
  6293. pl_sd->status.manner -= time;
  6294. if (pl_sd->status.manner < 0)
  6295. sc_start(NULL,&pl_sd->bl,SC_NOCHAT,100,0,0);
  6296. else
  6297. status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
  6298. }
  6299. return 0;
  6300. }
  6301. ACMD_FUNC(mutearea)
  6302. {
  6303. int time;
  6304. nullpo_ret(sd);
  6305. if (!message || !*message) {
  6306. clif_displaymessage(fd, msg_txt(sd,1297)); // Please enter a time in minutes (usage: @mutearea/@stfu <time in minutes>).
  6307. return -1;
  6308. }
  6309. time = atoi(message);
  6310. map_foreachinarea(atcommand_mutearea_sub,sd->bl.m,
  6311. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE,
  6312. sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd->bl.id, time);
  6313. return 0;
  6314. }
  6315. ACMD_FUNC(rates)
  6316. {
  6317. char buf[CHAT_SIZE_MAX];
  6318. nullpo_ret(sd);
  6319. memset(buf, '\0', sizeof(buf));
  6320. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1298), // Experience rates: Base %.2fx / Job %.2fx
  6321. battle_config.base_exp_rate/100., battle_config.job_exp_rate/100.);
  6322. clif_displaymessage(fd, buf);
  6323. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1299), // Normal Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  6324. 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.);
  6325. clif_displaymessage(fd, buf);
  6326. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1300), // Boss Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx
  6327. 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.);
  6328. clif_displaymessage(fd, buf);
  6329. snprintf(buf, CHAT_SIZE_MAX, msg_txt(sd,1301), // Other Drop Rates: MvP %.2fx / Card-Based %.2fx / Treasure %.2fx
  6330. battle_config.item_rate_mvp/100., battle_config.item_rate_adddrop/100., battle_config.item_rate_treasure/100.);
  6331. clif_displaymessage(fd, buf);
  6332. return 0;
  6333. }
  6334. /*==========================================
  6335. * @me by lordalfa
  6336. * => Displays the OUTPUT string on top of the Visible players Heads.
  6337. *------------------------------------------*/
  6338. ACMD_FUNC(me)
  6339. {
  6340. char tempmes[CHAT_SIZE_MAX];
  6341. nullpo_retr(-1, sd);
  6342. memset(tempmes, '\0', sizeof(tempmes));
  6343. memset(atcmd_output, '\0', sizeof(atcmd_output));
  6344. if (sd->sc.count && //no "chatting" while muted.
  6345. (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] ||
  6346. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT)))
  6347. return -1;
  6348. if (!message || !*message || sscanf(message, "%199[^\n]", tempmes) < 0) {
  6349. clif_displaymessage(fd, msg_txt(sd,1302)); // Please enter a message (usage: @me <message>).
  6350. return -1;
  6351. }
  6352. sprintf(atcmd_output, msg_txt(sd,270), sd->status.name, tempmes); // *%s %s*
  6353. clif_disp_overhead(&sd->bl, atcmd_output);
  6354. return 0;
  6355. }
  6356. /*==========================================
  6357. * @size
  6358. * => Resize your character sprite. [Valaris]
  6359. *------------------------------------------*/
  6360. ACMD_FUNC(size)
  6361. {
  6362. int size = 0;
  6363. nullpo_retr(-1, sd);
  6364. size = cap_value(atoi(message),SZ_SMALL,SZ_BIG);
  6365. if(sd->state.size) {
  6366. sd->state.size = SZ_SMALL;
  6367. pc_setpos(sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_TELEPORT);
  6368. }
  6369. sd->state.size = size;
  6370. if( size == SZ_MEDIUM )
  6371. clif_specialeffect(&sd->bl,420,AREA);
  6372. else if( size == SZ_BIG )
  6373. clif_specialeffect(&sd->bl,422,AREA);
  6374. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  6375. return 0;
  6376. }
  6377. ACMD_FUNC(sizeall)
  6378. {
  6379. int size;
  6380. struct map_session_data *pl_sd;
  6381. struct s_mapiterator* iter;
  6382. size = atoi(message);
  6383. size = cap_value(size,0,2);
  6384. iter = mapit_getallusers();
  6385. for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ) {
  6386. if( pl_sd->state.size != size ) {
  6387. if( pl_sd->state.size ) {
  6388. pl_sd->state.size = SZ_SMALL;
  6389. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  6390. }
  6391. pl_sd->state.size = size;
  6392. if( size == SZ_MEDIUM )
  6393. clif_specialeffect(&pl_sd->bl,420,AREA);
  6394. else if( size == SZ_BIG )
  6395. clif_specialeffect(&pl_sd->bl,422,AREA);
  6396. }
  6397. }
  6398. mapit_free(iter);
  6399. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  6400. return 0;
  6401. }
  6402. ACMD_FUNC(sizeguild)
  6403. {
  6404. int size = 0, i;
  6405. char guild[NAME_LENGTH];
  6406. struct map_session_data *pl_sd;
  6407. struct guild *g;
  6408. nullpo_retr(-1, sd);
  6409. memset(guild, '\0', sizeof(guild));
  6410. if( !message || !*message || sscanf(message, "%d %23[^\n]", &size, guild) < 2 ) {
  6411. clif_displaymessage(fd, msg_txt(sd,1304)); // Please enter guild name/ID (usage: @sizeguild <size> <guild name/ID>).
  6412. return -1;
  6413. }
  6414. if( (g = guild_searchname(guild)) == NULL && (g = guild_search(atoi(guild))) == NULL ) {
  6415. clif_displaymessage(fd, msg_txt(sd,94)); // Incorrect name/ID, or no one from the guild is online.
  6416. return -1;
  6417. }
  6418. size = cap_value(size,SZ_SMALL,SZ_BIG);
  6419. for( i = 0; i < g->max_member; i++ ) {
  6420. if( (pl_sd = g->member[i].sd) && pl_sd->state.size != size ) {
  6421. if( pl_sd->state.size ) {
  6422. pl_sd->state.size = SZ_SMALL;
  6423. pc_setpos(pl_sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT);
  6424. }
  6425. pl_sd->state.size = size;
  6426. if( size == SZ_MEDIUM )
  6427. clif_specialeffect(&pl_sd->bl,420,AREA);
  6428. else if( size == SZ_BIG )
  6429. clif_specialeffect(&pl_sd->bl,422,AREA);
  6430. }
  6431. }
  6432. clif_displaymessage(fd, msg_txt(sd,1303)); // Size change applied.
  6433. return 0;
  6434. }
  6435. /*==========================================
  6436. * @monsterignore
  6437. * => Makes monsters ignore you. [Valaris]
  6438. *------------------------------------------*/
  6439. ACMD_FUNC(monsterignore)
  6440. {
  6441. nullpo_retr(-1, sd);
  6442. if (!sd->state.monster_ignore) {
  6443. sd->state.monster_ignore = 1;
  6444. clif_displaymessage(sd->fd, msg_txt(sd,1305)); // You are now immune to attacks.
  6445. } else {
  6446. sd->state.monster_ignore = 0;
  6447. clif_displaymessage(sd->fd, msg_txt(sd,1306)); // Returned to normal state.
  6448. }
  6449. return 0;
  6450. }
  6451. /*==========================================
  6452. * @fakename
  6453. * => Gives your character a fake name. [Valaris]
  6454. *------------------------------------------*/
  6455. ACMD_FUNC(fakename)
  6456. {
  6457. nullpo_retr(-1, sd);
  6458. if( !message || !*message )
  6459. {
  6460. if( sd->fakename[0] )
  6461. {
  6462. sd->fakename[0] = '\0';
  6463. clif_charnameack(0, &sd->bl);
  6464. clif_displaymessage(sd->fd, msg_txt(sd,1307)); // Returned to real name.
  6465. return 0;
  6466. }
  6467. clif_displaymessage(sd->fd, msg_txt(sd,1308)); // You must enter a name.
  6468. return -1;
  6469. }
  6470. if( strlen(message) < 2 )
  6471. {
  6472. clif_displaymessage(sd->fd, msg_txt(sd,1309)); // Fake name must be at least two characters.
  6473. return -1;
  6474. }
  6475. safestrncpy(sd->fakename, message, sizeof(sd->fakename));
  6476. clif_charnameack(0, &sd->bl);
  6477. clif_displaymessage(sd->fd, msg_txt(sd,1310)); // Fake name enabled.
  6478. return 0;
  6479. }
  6480. /*==========================================
  6481. * Ragnarok Resources
  6482. *------------------------------------------*/
  6483. ACMD_FUNC(mapflag) {
  6484. #define checkflag( cmd ) if ( map[ sd->bl.m ].flag.cmd ) clif_displaymessage(sd->fd,#cmd)
  6485. #define setflag( cmd ) \
  6486. if ( strcmp( flag_name , #cmd ) == 0 ){\
  6487. map[ sd->bl.m ].flag.cmd = flag;\
  6488. sprintf(atcmd_output,"[ @mapflag ] %s flag has been set to %s value = %hd",#cmd,flag?"On":"Off",flag);\
  6489. clif_displaymessage(sd->fd,atcmd_output);\
  6490. return 0;\
  6491. }
  6492. char flag_name[100];
  6493. short flag=0,i;
  6494. nullpo_retr(-1, sd);
  6495. memset(flag_name, '\0', sizeof(flag_name));
  6496. if (!message || !*message || (sscanf(message, "%99s %hd", flag_name, &flag) < 1)) {
  6497. clif_displaymessage(sd->fd,msg_txt(sd,1311)); // Enabled Mapflags in this map:
  6498. clif_displaymessage(sd->fd,"----------------------------------");
  6499. checkflag(autotrade); checkflag(allowks); checkflag(nomemo); checkflag(noteleport);
  6500. checkflag(noreturn); checkflag(monster_noteleport); checkflag(nosave); checkflag(nobranch);
  6501. checkflag(noexppenalty); checkflag(pvp); checkflag(pvp_noparty); checkflag(pvp_noguild);
  6502. checkflag(pvp_nightmaredrop); checkflag(pvp_nocalcrank); checkflag(gvg_castle); checkflag(gvg);
  6503. checkflag(gvg_dungeon); checkflag(gvg_noparty); checkflag(battleground);checkflag(nozenypenalty);
  6504. checkflag(notrade); checkflag(noskill); checkflag(nowarp); checkflag(nowarpto);
  6505. checkflag(noicewall); checkflag(snow); checkflag(clouds); checkflag(clouds2);
  6506. checkflag(fog); checkflag(fireworks); checkflag(sakura); checkflag(leaves);
  6507. checkflag(nogo); checkflag(nobaseexp);
  6508. checkflag(nojobexp); checkflag(nomobloot); checkflag(nomvploot); checkflag(nightenabled);
  6509. checkflag(restricted); checkflag(nodrop); checkflag(novending); checkflag(loadevent);
  6510. checkflag(nochat); checkflag(partylock); checkflag(guildlock); checkflag(src4instance);
  6511. clif_displaymessage(sd->fd," ");
  6512. clif_displaymessage(sd->fd,msg_txt(sd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  6513. clif_displaymessage(sd->fd,msg_txt(sd,1313)); // Type "@mapflag available" to list the available mapflags.
  6514. return 1;
  6515. }
  6516. for (i = 0; flag_name[i]; i++) flag_name[i] = (char)tolower(flag_name[i]); //lowercase
  6517. setflag(autotrade); setflag(allowks); setflag(nomemo); setflag(noteleport);
  6518. setflag(noreturn); setflag(monster_noteleport);setflag(nosave); setflag(nobranch);
  6519. setflag(noexppenalty); setflag(pvp); setflag(pvp_noparty); setflag(pvp_noguild);
  6520. setflag(pvp_nightmaredrop); setflag(pvp_nocalcrank); setflag(gvg_castle); setflag(gvg);
  6521. setflag(gvg_dungeon); setflag(gvg_noparty); setflag(battleground); setflag(nozenypenalty);
  6522. setflag(notrade); setflag(noskill); setflag(nowarp); setflag(nowarpto);
  6523. setflag(noicewall); setflag(snow); setflag(clouds); setflag(clouds2);
  6524. setflag(fog); setflag(fireworks); setflag(sakura); setflag(leaves);
  6525. setflag(nogo); setflag(nobaseexp);
  6526. setflag(nojobexp); setflag(nomobloot); setflag(nomvploot); setflag(nightenabled);
  6527. setflag(restricted); setflag(nodrop); setflag(novending); setflag(loadevent);
  6528. setflag(nochat); setflag(partylock); setflag(guildlock); setflag(src4instance);
  6529. clif_displaymessage(sd->fd,msg_txt(sd,1314)); // Invalid flag name or flag.
  6530. clif_displaymessage(sd->fd,msg_txt(sd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
  6531. clif_displaymessage(sd->fd,msg_txt(sd,1315)); // Available Flags:
  6532. clif_displaymessage(sd->fd,"----------------------------------");
  6533. clif_displaymessage(sd->fd,"town, autotrade, allowks, nomemo, noteleport, noreturn, monster_noteleport, nosave,");
  6534. clif_displaymessage(sd->fd,"nobranch, noexppenalty, pvp, pvp_noparty, pvp_noguild, pvp_nightmaredrop,");
  6535. clif_displaymessage(sd->fd,"pvp_nocalcrank, gvg_castle, gvg, gvg_dungeon, gvg_noparty, battleground,");
  6536. clif_displaymessage(sd->fd,"nozenypenalty, notrade, noskill, nowarp, nowarpto, noicewall, snow, clouds, clouds2,");
  6537. clif_displaymessage(sd->fd,"fog, fireworks, sakura, leaves, nogo, nobaseexp, nojobexp, nomobloot,");
  6538. clif_displaymessage(sd->fd,"nomvploot, nightenabled, restricted, nodrop, novending, loadevent, nochat, partylock,");
  6539. clif_displaymessage(sd->fd,"guildlock, src4instance");
  6540. #undef checkflag
  6541. #undef setflag
  6542. return 0;
  6543. }
  6544. /*===================================
  6545. * Remove some messages
  6546. *-----------------------------------*/
  6547. ACMD_FUNC(showexp)
  6548. {
  6549. if (sd->state.showexp) {
  6550. sd->state.showexp = 0;
  6551. clif_displaymessage(fd, msg_txt(sd,1316)); // Gained exp will not be shown.
  6552. return 0;
  6553. }
  6554. sd->state.showexp = 1;
  6555. clif_displaymessage(fd, msg_txt(sd,1317)); // Gained exp is now shown.
  6556. return 0;
  6557. }
  6558. ACMD_FUNC(showzeny)
  6559. {
  6560. if (sd->state.showzeny) {
  6561. sd->state.showzeny = 0;
  6562. clif_displaymessage(fd, msg_txt(sd,1318)); // Gained zeny will not be shown.
  6563. return 0;
  6564. }
  6565. sd->state.showzeny = 1;
  6566. clif_displaymessage(fd, msg_txt(sd,1319)); // Gained zeny is now shown.
  6567. return 0;
  6568. }
  6569. ACMD_FUNC(showdelay)
  6570. {
  6571. if (sd->state.showdelay) {
  6572. sd->state.showdelay = 0;
  6573. clif_displaymessage(fd, msg_txt(sd,1320)); // Skill delay failures will not be shown.
  6574. return 0;
  6575. }
  6576. sd->state.showdelay = 1;
  6577. clif_displaymessage(fd, msg_txt(sd,1321)); // Skill delay failures are now shown.
  6578. return 0;
  6579. }
  6580. /*==========================================
  6581. * Duel organizing functions [LuzZza]
  6582. *
  6583. * @duel [limit|nick] - create a duel
  6584. * @invite <nick> - invite player
  6585. * @accept - accept invitation
  6586. * @reject - reject invitation
  6587. * @leave - leave duel
  6588. *------------------------------------------*/
  6589. ACMD_FUNC(invite)
  6590. {
  6591. unsigned int did = sd->duel_group;
  6592. struct map_session_data *target_sd = map_nick2sd((char *)message);
  6593. if(did == 0) {
  6594. // "Duel: @invite without @duel."
  6595. clif_displaymessage(fd, msg_txt(sd,350));
  6596. return 0;
  6597. }
  6598. if(duel_list[did].max_players_limit > 0 &&
  6599. duel_list[did].members_count >= duel_list[did].max_players_limit) {
  6600. // "Duel: Limit of players is reached."
  6601. clif_displaymessage(fd, msg_txt(sd,351));
  6602. return 0;
  6603. }
  6604. if(target_sd == NULL) {
  6605. // "Duel: Player not found."
  6606. clif_displaymessage(fd, msg_txt(sd,352));
  6607. return 0;
  6608. }
  6609. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  6610. // "Duel: Player already in duel."
  6611. clif_displaymessage(fd, msg_txt(sd,353));
  6612. return 0;
  6613. }
  6614. if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
  6615. {
  6616. sprintf(atcmd_output, msg_txt(sd,364), message);
  6617. clif_displaymessage(fd, atcmd_output);
  6618. return 0;
  6619. }
  6620. duel_invite(did, sd, target_sd);
  6621. // "Duel: Invitation has been sent."
  6622. clif_displaymessage(fd, msg_txt(sd,354));
  6623. return 0;
  6624. }
  6625. ACMD_FUNC(duel)
  6626. {
  6627. unsigned int maxpl = 0;
  6628. if(sd->duel_group > 0) {
  6629. duel_showinfo(sd->duel_group, sd);
  6630. return 0;
  6631. }
  6632. if(sd->duel_invite > 0) {
  6633. // "Duel: @duel without @reject."
  6634. clif_displaymessage(fd, msg_txt(sd,355));
  6635. return 0;
  6636. }
  6637. if(!duel_checktime(sd)) {
  6638. char output[CHAT_SIZE_MAX];
  6639. // "Duel: You can take part in duel only one time per %d minutes."
  6640. sprintf(output, msg_txt(sd,356), battle_config.duel_time_interval);
  6641. clif_displaymessage(fd, output);
  6642. return 0;
  6643. }
  6644. if( message[0] ) {
  6645. if(sscanf(message, "%d", &maxpl) >= 1) {
  6646. if(maxpl < 2 || maxpl > 65535) {
  6647. clif_displaymessage(fd, msg_txt(sd,357)); // "Duel: Invalid value."
  6648. return 0;
  6649. }
  6650. duel_create(sd, maxpl);
  6651. } else {
  6652. struct map_session_data *target_sd;
  6653. target_sd = map_nick2sd((char *)message);
  6654. if(target_sd != NULL) {
  6655. unsigned int maxpl=0, newduel;
  6656. if((newduel = duel_create(sd, 2)) != -1) {
  6657. if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
  6658. clif_displaymessage(fd, msg_txt(sd,353)); // "Duel: Player already in duel."
  6659. return 0;
  6660. }
  6661. duel_invite(newduel, sd, target_sd);
  6662. clif_displaymessage(fd, msg_txt(sd,354)); // "Duel: Invitation has been sent."
  6663. }
  6664. } else {
  6665. // "Duel: Player not found."
  6666. clif_displaymessage(fd, msg_txt(sd,352));
  6667. return 0;
  6668. }
  6669. }
  6670. } else
  6671. duel_create(sd, 0);
  6672. return 0;
  6673. }
  6674. ACMD_FUNC(leave)
  6675. {
  6676. if(sd->duel_group <= 0) {
  6677. // "Duel: @leave without @duel."
  6678. clif_displaymessage(fd, msg_txt(sd,358));
  6679. return 0;
  6680. }
  6681. duel_leave(sd->duel_group, sd);
  6682. clif_displaymessage(fd, msg_txt(sd,359)); // "Duel: You left the duel."
  6683. return 0;
  6684. }
  6685. ACMD_FUNC(accept)
  6686. {
  6687. if(!duel_checktime(sd)) {
  6688. char output[CHAT_SIZE_MAX];
  6689. // "Duel: You can take part in duel only one time per %d minutes."
  6690. sprintf(output, msg_txt(sd,356), battle_config.duel_time_interval);
  6691. clif_displaymessage(fd, output);
  6692. return 0;
  6693. }
  6694. if(sd->duel_invite <= 0) {
  6695. // "Duel: @accept without invititation."
  6696. clif_displaymessage(fd, msg_txt(sd,360));
  6697. return 0;
  6698. }
  6699. 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 )
  6700. {
  6701. // "Duel: Limit of players is reached."
  6702. clif_displaymessage(fd, msg_txt(sd,351));
  6703. return 0;
  6704. }
  6705. duel_accept(sd->duel_invite, sd);
  6706. // "Duel: Invitation has been accepted."
  6707. clif_displaymessage(fd, msg_txt(sd,361));
  6708. return 0;
  6709. }
  6710. ACMD_FUNC(reject)
  6711. {
  6712. if(sd->duel_invite <= 0) {
  6713. // "Duel: @reject without invititation."
  6714. clif_displaymessage(fd, msg_txt(sd,362));
  6715. return 0;
  6716. }
  6717. duel_reject(sd->duel_invite, sd);
  6718. // "Duel: Invitation has been rejected."
  6719. clif_displaymessage(fd, msg_txt(sd,363));
  6720. return 0;
  6721. }
  6722. /*===================================
  6723. * Cash Points
  6724. *-----------------------------------*/
  6725. ACMD_FUNC(cash)
  6726. {
  6727. char output[128];
  6728. int value;
  6729. int ret=0;
  6730. nullpo_retr(-1, sd);
  6731. if( !message || !*message || (value = atoi(message)) == 0 ) {
  6732. clif_displaymessage(fd, msg_txt(sd,1322)); // Please enter an amount.
  6733. return -1;
  6734. }
  6735. if( !strcmpi(command+1,"cash") )
  6736. {
  6737. if( value > 0 ) {
  6738. if( (ret=pc_getcash(sd, value, 0, LOG_TYPE_COMMAND)) >= 0){
  6739. // If this option is set, the message is already sent by pc function
  6740. if( !battle_config.cashshop_show_points ){
  6741. sprintf(output, msg_txt(sd,505), ret, sd->cashPoints);
  6742. clif_disp_onlyself(sd, output, strlen(output));
  6743. }
  6744. }
  6745. else clif_displaymessage(fd, msg_txt(sd,149)); // Unable to decrease the number/value.
  6746. } else {
  6747. if( (ret=pc_paycash(sd, -value, 0, LOG_TYPE_COMMAND)) >= 0){
  6748. // If this option is set, the message is already sent by pc function
  6749. if( !battle_config.cashshop_show_points ){
  6750. sprintf(output, msg_txt(sd,410), ret, sd->cashPoints);
  6751. clif_disp_onlyself(sd, output, strlen(output));
  6752. }
  6753. }
  6754. else clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  6755. }
  6756. }
  6757. else
  6758. { // @points
  6759. if( value > 0 ) {
  6760. if( (ret=pc_getcash(sd, 0, value, LOG_TYPE_COMMAND)) >= 0){
  6761. sprintf(output, msg_txt(sd,506), ret, sd->kafraPoints);
  6762. clif_disp_onlyself(sd, output, strlen(output));
  6763. }
  6764. else clif_displaymessage(fd, msg_txt(sd,149)); // Unable to decrease the number/value.
  6765. } else {
  6766. if( (ret=pc_paycash(sd, -value, -value, LOG_TYPE_COMMAND)) >= 0){
  6767. sprintf(output, msg_txt(sd,411), ret, sd->kafraPoints);
  6768. clif_disp_onlyself(sd, output, strlen(output));
  6769. }
  6770. else clif_displaymessage(fd, msg_txt(sd,41)); // Unable to decrease the number/value.
  6771. }
  6772. }
  6773. return 0;
  6774. }
  6775. // @clone/@slaveclone/@evilclone <playername> [Valaris]
  6776. ACMD_FUNC(clone)
  6777. {
  6778. int x=0,y=0,flag=0,master=0,i=0;
  6779. struct map_session_data *pl_sd=NULL;
  6780. if (!message || !*message) {
  6781. clif_displaymessage(sd->fd,msg_txt(sd,1323)); // You must enter a player name or ID.
  6782. return 0;
  6783. }
  6784. if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
  6785. clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
  6786. return 0;
  6787. }
  6788. if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
  6789. clif_displaymessage(fd, msg_txt(sd,126)); // Cannot clone a player of higher GM level than yourself.
  6790. return 0;
  6791. }
  6792. if (strcmpi(command+1, "clone") == 0)
  6793. flag = 1;
  6794. else if (strcmpi(command+1, "slaveclone") == 0) {
  6795. flag = 2;
  6796. if(pc_isdead(sd)){
  6797. clif_displaymessage(fd, msg_txt(sd,129+flag*2));
  6798. return 0;
  6799. }
  6800. master = sd->bl.id;
  6801. if (battle_config.atc_slave_clone_limit
  6802. && mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
  6803. clif_displaymessage(fd, msg_txt(sd,127)); // You've reached your slave clones limit.
  6804. return 0;
  6805. }
  6806. }
  6807. do {
  6808. x = sd->bl.x + (rnd() % 10 - 5);
  6809. y = sd->bl.y + (rnd() % 10 - 5);
  6810. } while (map_getcell(sd->bl.m,x,y,CELL_CHKNOPASS) && i++ < 10);
  6811. if (i >= 10) {
  6812. x = sd->bl.x;
  6813. y = sd->bl.y;
  6814. }
  6815. if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
  6816. clif_displaymessage(fd, msg_txt(sd,128+flag*2)); // Evil Clone spawned. Clone spawned. Slave clone spawned.
  6817. return 0;
  6818. }
  6819. clif_displaymessage(fd, msg_txt(sd,129+flag*2)); // Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
  6820. return 0;
  6821. }
  6822. /*=====================================
  6823. * Autorejecting Invites/Deals [LuzZza]
  6824. * Usage: @noask
  6825. *-------------------------------------*/
  6826. ACMD_FUNC(noask)
  6827. {
  6828. if(sd->state.noask) {
  6829. clif_displaymessage(fd, msg_txt(sd,391)); // Autorejecting is deactivated.
  6830. sd->state.noask = 0;
  6831. } else {
  6832. clif_displaymessage(fd, msg_txt(sd,390)); // Autorejecting is activated.
  6833. sd->state.noask = 1;
  6834. }
  6835. return 0;
  6836. }
  6837. /*=====================================
  6838. * Send a @request message to all GMs of lowest_gm_level.
  6839. * Usage: @request <petition>
  6840. *-------------------------------------*/
  6841. ACMD_FUNC(request)
  6842. {
  6843. if (!message || !*message) {
  6844. clif_displaymessage(sd->fd,msg_txt(sd,277)); // Usage: @request <petition/message to online GMs>.
  6845. return -1;
  6846. }
  6847. sprintf(atcmd_output, msg_txt(sd,278), message); // (@request): %s
  6848. intif_wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output);
  6849. clif_disp_onlyself(sd, atcmd_output, strlen(atcmd_output));
  6850. clif_displaymessage(sd->fd,msg_txt(sd,279)); // @request sent.
  6851. return 0;
  6852. }
  6853. /*==========================================
  6854. * Feel (SG save map) Reset [HiddenDragon]
  6855. *------------------------------------------*/
  6856. ACMD_FUNC(feelreset)
  6857. {
  6858. pc_resetfeel(sd);
  6859. clif_displaymessage(fd, msg_txt(sd,1324)); // Reset 'Feeling' maps.
  6860. return 0;
  6861. }
  6862. /*==========================================
  6863. * AUCTION SYSTEM
  6864. *------------------------------------------*/
  6865. ACMD_FUNC(auction)
  6866. {
  6867. nullpo_ret(sd);
  6868. clif_Auction_openwindow(sd);
  6869. return 0;
  6870. }
  6871. /*==========================================
  6872. * Kill Steal Protection
  6873. *------------------------------------------*/
  6874. ACMD_FUNC(ksprotection)
  6875. {
  6876. nullpo_retr(-1,sd);
  6877. if( sd->state.noks ) {
  6878. sd->state.noks = 0;
  6879. clif_displaymessage(fd, msg_txt(sd,1325)); // [ K.S Protection Inactive ]
  6880. }
  6881. else
  6882. {
  6883. if( !message || !*message || !strcmpi(message, "party") )
  6884. { // Default is Party
  6885. sd->state.noks = 2;
  6886. clif_displaymessage(fd, msg_txt(sd,1326)); // [ K.S Protection Active - Option: Party ]
  6887. }
  6888. else if( !strcmpi(message, "self") )
  6889. {
  6890. sd->state.noks = 1;
  6891. clif_displaymessage(fd, msg_txt(sd,1327)); // [ K.S Protection Active - Option: Self ]
  6892. }
  6893. else if( !strcmpi(message, "guild") )
  6894. {
  6895. sd->state.noks = 3;
  6896. clif_displaymessage(fd, msg_txt(sd,1328)); // [ K.S Protection Active - Option: Guild ]
  6897. }
  6898. else
  6899. clif_displaymessage(fd, msg_txt(sd,1329)); // Usage: @noks <self|party|guild>
  6900. }
  6901. return 0;
  6902. }
  6903. /*==========================================
  6904. * Map Kill Steal Protection Setting
  6905. *------------------------------------------*/
  6906. ACMD_FUNC(allowks)
  6907. {
  6908. nullpo_retr(-1,sd);
  6909. if( map[sd->bl.m].flag.allowks ) {
  6910. map[sd->bl.m].flag.allowks = 0;
  6911. clif_displaymessage(fd, msg_txt(sd,1330)); // [ Map K.S Protection Active ]
  6912. } else {
  6913. map[sd->bl.m].flag.allowks = 1;
  6914. clif_displaymessage(fd, msg_txt(sd,1331)); // [ Map K.S Protection Inactive ]
  6915. }
  6916. return 0;
  6917. }
  6918. ACMD_FUNC(resetstat)
  6919. {
  6920. nullpo_retr(-1, sd);
  6921. pc_resetstate(sd);
  6922. sprintf(atcmd_output, msg_txt(sd,207), sd->status.name);
  6923. clif_displaymessage(fd, atcmd_output);
  6924. return 0;
  6925. }
  6926. ACMD_FUNC(resetskill)
  6927. {
  6928. nullpo_retr(-1,sd);
  6929. pc_resetskill(sd,1);
  6930. sprintf(atcmd_output, msg_txt(sd,206), sd->status.name);
  6931. clif_displaymessage(fd, atcmd_output);
  6932. return 0;
  6933. }
  6934. /*==========================================
  6935. * #storagelist: Displays the items list of a player's storage.
  6936. * #cartlist: Displays contents of target's cart.
  6937. * #itemlist: Displays contents of target's inventory.
  6938. *------------------------------------------*/
  6939. ACMD_FUNC(itemlist)
  6940. {
  6941. int i, j, count, counter;
  6942. const char* location;
  6943. const struct item* items;
  6944. int size;
  6945. StringBuf buf;
  6946. nullpo_retr(-1, sd);
  6947. if( strcmp(command+1, "storagelist") == 0 )
  6948. {
  6949. location = "storage";
  6950. items = sd->status.storage.items;
  6951. size = MAX_STORAGE;
  6952. }
  6953. else
  6954. if( strcmp(command+1, "cartlist") == 0 )
  6955. {
  6956. location = "cart";
  6957. items = sd->status.cart;
  6958. size = MAX_CART;
  6959. }
  6960. else
  6961. if( strcmp(command+1, "itemlist") == 0 )
  6962. {
  6963. location = "inventory";
  6964. items = sd->status.inventory;
  6965. size = MAX_INVENTORY;
  6966. }
  6967. else
  6968. return 1;
  6969. StringBuf_Init(&buf);
  6970. count = 0; // total slots occupied
  6971. counter = 0; // total items found
  6972. for( i = 0; i < size; ++i )
  6973. {
  6974. const struct item* it = &items[i];
  6975. struct item_data* itd;
  6976. if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL )
  6977. continue;
  6978. counter += it->amount;
  6979. count++;
  6980. if( count == 1 )
  6981. {
  6982. StringBuf_Printf(&buf, msg_txt(sd,1332), location, sd->status.name); // ------ %s items list of '%s' ------
  6983. clif_displaymessage(fd, StringBuf_Value(&buf));
  6984. StringBuf_Clear(&buf);
  6985. }
  6986. if( it->refine )
  6987. StringBuf_Printf(&buf, "%d %s %+d (%s, id: %d)", it->amount, itd->jname, it->refine, itd->name, it->nameid);
  6988. else
  6989. StringBuf_Printf(&buf, "%d %s (%s, id: %d)", it->amount, itd->jname, itd->name, it->nameid);
  6990. if( it->equip )
  6991. {
  6992. char equipstr[CHAT_SIZE_MAX];
  6993. strcpy(equipstr, msg_txt(sd,1333)); // | equipped:
  6994. if( it->equip & EQP_GARMENT )
  6995. strcat(equipstr, msg_txt(sd,1334)); // garment,
  6996. if( it->equip & EQP_ACC_L )
  6997. strcat(equipstr, msg_txt(sd,1335)); // left accessory,
  6998. if( it->equip & EQP_ARMOR )
  6999. strcat(equipstr, msg_txt(sd,1336)); // body/armor,
  7000. if( (it->equip & EQP_ARMS) == EQP_HAND_R )
  7001. strcat(equipstr, msg_txt(sd,1337)); // right hand,
  7002. if( (it->equip & EQP_ARMS) == EQP_HAND_L )
  7003. strcat(equipstr, msg_txt(sd,1338)); // left hand,
  7004. if( (it->equip & EQP_ARMS) == EQP_ARMS )
  7005. strcat(equipstr, msg_txt(sd,1339)); // both hands,
  7006. if( it->equip & EQP_SHOES )
  7007. strcat(equipstr, msg_txt(sd,1340)); // feet,
  7008. if( it->equip & EQP_ACC_R )
  7009. strcat(equipstr, msg_txt(sd,1341)); // right accessory,
  7010. if( (it->equip & EQP_HELM) == EQP_HEAD_LOW )
  7011. strcat(equipstr, msg_txt(sd,1342)); // lower head,
  7012. if( (it->equip & EQP_HELM) == EQP_HEAD_TOP )
  7013. strcat(equipstr, msg_txt(sd,1343)); // top head,
  7014. if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_TOP) )
  7015. strcat(equipstr, msg_txt(sd,1344)); // lower/top head,
  7016. if( (it->equip & EQP_HELM) == EQP_HEAD_MID )
  7017. strcat(equipstr, msg_txt(sd,1345)); // mid head,
  7018. if( (it->equip & EQP_HELM) == (EQP_HEAD_LOW|EQP_HEAD_MID) )
  7019. strcat(equipstr, msg_txt(sd,1346)); // lower/mid head,
  7020. if( (it->equip & EQP_HELM) == EQP_HELM )
  7021. strcat(equipstr, msg_txt(sd,1347)); // lower/mid/top head,
  7022. // remove final ', '
  7023. equipstr[strlen(equipstr) - 2] = '\0';
  7024. StringBuf_AppendStr(&buf, equipstr);
  7025. }
  7026. clif_displaymessage(fd, StringBuf_Value(&buf));
  7027. StringBuf_Clear(&buf);
  7028. if( it->card[0] == CARD0_PET )
  7029. {// pet egg
  7030. if (it->card[3])
  7031. StringBuf_Printf(&buf, msg_txt(sd,1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named)
  7032. else
  7033. StringBuf_Printf(&buf, msg_txt(sd,1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed)
  7034. }
  7035. else
  7036. if(it->card[0] == CARD0_FORGE)
  7037. {// forged item
  7038. StringBuf_Printf(&buf, msg_txt(sd,1350), (unsigned int)MakeDWord(it->card[2], it->card[3]), it->card[1]>>8, it->card[1]&0x0f); // -> (crafted item, creator id: %u, star crumbs %d, element %d)
  7039. }
  7040. else
  7041. if(it->card[0] == CARD0_CREATE)
  7042. {// created item
  7043. StringBuf_Printf(&buf, msg_txt(sd,1351), (unsigned int)MakeDWord(it->card[2], it->card[3])); // -> (produced item, creator id: %u)
  7044. }
  7045. else
  7046. {// normal item
  7047. int counter2 = 0;
  7048. for( j = 0; j < itd->slot; ++j )
  7049. {
  7050. struct item_data* card;
  7051. if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL )
  7052. continue;
  7053. counter2++;
  7054. if( counter2 == 1 )
  7055. StringBuf_AppendStr(&buf, msg_txt(sd,1352)); // -> (card(s):
  7056. if( counter2 != 1 )
  7057. StringBuf_AppendStr(&buf, ", ");
  7058. StringBuf_Printf(&buf, "#%d %s (id: %d)", counter2, card->jname, card->nameid);
  7059. }
  7060. if( counter2 > 0 )
  7061. StringBuf_AppendStr(&buf, ")");
  7062. }
  7063. if( StringBuf_Length(&buf) > 0 )
  7064. clif_displaymessage(fd, StringBuf_Value(&buf));
  7065. StringBuf_Clear(&buf);
  7066. }
  7067. if( count == 0 )
  7068. StringBuf_Printf(&buf, msg_txt(sd,1353), location); // No item found in this player's %s.
  7069. else
  7070. StringBuf_Printf(&buf, msg_txt(sd,1354), counter, count, location); // %d item(s) found in %d %s slots.
  7071. clif_displaymessage(fd, StringBuf_Value(&buf));
  7072. StringBuf_Destroy(&buf);
  7073. return 0;
  7074. }
  7075. ACMD_FUNC(stats)
  7076. {
  7077. char job_jobname[100];
  7078. char output[CHAT_SIZE_MAX];
  7079. int i;
  7080. struct {
  7081. const char* format;
  7082. int value;
  7083. } output_table[] = {
  7084. { "Base Level - %d", 0 },
  7085. { NULL, 0 },
  7086. { "Hp - %d", 0 },
  7087. { "MaxHp - %d", 0 },
  7088. { "Sp - %d", 0 },
  7089. { "MaxSp - %d", 0 },
  7090. { "Str - %3d", 0 },
  7091. { "Agi - %3d", 0 },
  7092. { "Vit - %3d", 0 },
  7093. { "Int - %3d", 0 },
  7094. { "Dex - %3d", 0 },
  7095. { "Luk - %3d", 0 },
  7096. { "Zeny - %d", 0 },
  7097. { "Free SK Points - %d", 0 },
  7098. { "JobChangeLvl (2nd) - %d", 0 },
  7099. { "JobChangeLvl (3rd) - %d", 0 },
  7100. { NULL, 0 }
  7101. };
  7102. memset(job_jobname, '\0', sizeof(job_jobname));
  7103. memset(output, '\0', sizeof(output));
  7104. //direct array initialization with variables is not standard C compliant.
  7105. output_table[0].value = sd->status.base_level;
  7106. output_table[1].format = job_jobname;
  7107. output_table[1].value = sd->status.job_level;
  7108. output_table[2].value = sd->status.hp;
  7109. output_table[3].value = sd->status.max_hp;
  7110. output_table[4].value = sd->status.sp;
  7111. output_table[5].value = sd->status.max_sp;
  7112. output_table[6].value = sd->status.str;
  7113. output_table[7].value = sd->status.agi;
  7114. output_table[8].value = sd->status.vit;
  7115. output_table[9].value = sd->status.int_;
  7116. output_table[10].value = sd->status.dex;
  7117. output_table[11].value = sd->status.luk;
  7118. output_table[12].value = sd->status.zeny;
  7119. output_table[13].value = sd->status.skill_point;
  7120. output_table[14].value = sd->change_level_2nd;
  7121. output_table[15].value = sd->change_level_3rd;
  7122. sprintf(job_jobname, "Job - %s %s", job_name(sd->status.class_), "(level %d)");
  7123. sprintf(output, msg_txt(sd,53), sd->status.name); // '%s' stats:
  7124. clif_displaymessage(fd, output);
  7125. for (i = 0; output_table[i].format != NULL; i++) {
  7126. sprintf(output, output_table[i].format, output_table[i].value);
  7127. clif_displaymessage(fd, output);
  7128. }
  7129. return 0;
  7130. }
  7131. ACMD_FUNC(delitem)
  7132. {
  7133. char item_name[100];
  7134. int nameid, amount = 0, total, idx;
  7135. struct item_data* id;
  7136. nullpo_retr(-1, sd);
  7137. if( !message || !*message || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &amount) < 2 && sscanf(message, "%99s %d", item_name, &amount) < 2 ) || amount < 1 )
  7138. {
  7139. clif_displaymessage(fd, msg_txt(sd,1355)); // Please enter an item name/ID, a quantity, and a player name (usage: #delitem <player> <item_name_or_ID> <quantity>).
  7140. return -1;
  7141. }
  7142. if( ( id = itemdb_searchname(item_name) ) != NULL || ( id = itemdb_exists(atoi(item_name)) ) != NULL )
  7143. {
  7144. nameid = id->nameid;
  7145. }
  7146. else
  7147. {
  7148. clif_displaymessage(fd, msg_txt(sd,19)); // Invalid item ID or name.
  7149. return -1;
  7150. }
  7151. total = amount;
  7152. // delete items
  7153. while( amount && ( idx = pc_search_inventory(sd, nameid) ) != -1 )
  7154. {
  7155. int delamount = ( amount < sd->status.inventory[idx].amount ) ? amount : sd->status.inventory[idx].amount;
  7156. if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET )
  7157. {// delete pet
  7158. intif_delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2]));
  7159. }
  7160. pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_COMMAND);
  7161. amount-= delamount;
  7162. }
  7163. // notify target
  7164. sprintf(atcmd_output, msg_txt(sd,113), total-amount); // %d item(s) removed by a GM.
  7165. clif_displaymessage(sd->fd, atcmd_output);
  7166. // notify source
  7167. if( amount == total )
  7168. {
  7169. clif_displaymessage(fd, msg_txt(sd,116)); // Character does not have the item.
  7170. }
  7171. else if( amount )
  7172. {
  7173. sprintf(atcmd_output, msg_txt(sd,115), total-amount, total-amount, total); // %d item(s) removed. Player had only %d on %d items.
  7174. clif_displaymessage(fd, atcmd_output);
  7175. }
  7176. else
  7177. {
  7178. sprintf(atcmd_output, msg_txt(sd,114), total); // %d item(s) removed from the player.
  7179. clif_displaymessage(fd, atcmd_output);
  7180. }
  7181. return 0;
  7182. }
  7183. /*==========================================
  7184. * Custom Fonts
  7185. *------------------------------------------*/
  7186. ACMD_FUNC(font)
  7187. {
  7188. int font_id;
  7189. nullpo_retr(-1,sd);
  7190. font_id = atoi(message);
  7191. if( font_id == 0 )
  7192. {
  7193. if( sd->user_font )
  7194. {
  7195. sd->user_font = 0;
  7196. clif_displaymessage(fd, msg_txt(sd,1356)); // Returning to normal font.
  7197. clif_font(sd);
  7198. }
  7199. else
  7200. {
  7201. clif_displaymessage(fd, msg_txt(sd,1357)); // Use @font <1-9> to change your message font.
  7202. clif_displaymessage(fd, msg_txt(sd,1358)); // Use 0 or no parameter to return to normal font.
  7203. }
  7204. }
  7205. else if( font_id < 0 || font_id > 9 )
  7206. clif_displaymessage(fd, msg_txt(sd,1359)); // Invalid font. Use a value from 0 to 9.
  7207. else if( font_id != sd->user_font )
  7208. {
  7209. sd->user_font = font_id;
  7210. clif_font(sd);
  7211. clif_displaymessage(fd, msg_txt(sd,1360)); // Font changed.
  7212. }
  7213. else
  7214. clif_displaymessage(fd, msg_txt(sd,1361)); // Already using this font.
  7215. return 0;
  7216. }
  7217. /*==========================================
  7218. * type: 1 = commands (@), 2 = charcommands (#)
  7219. *------------------------------------------*/
  7220. static void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommandType type)
  7221. {
  7222. char line_buff[CHATBOX_SIZE];
  7223. char* cur = line_buff;
  7224. AtCommandInfo* cmd;
  7225. DBIterator *iter = db_iterator(atcommand_db);
  7226. int count = 0;
  7227. memset(line_buff,' ',CHATBOX_SIZE);
  7228. line_buff[CHATBOX_SIZE-1] = 0;
  7229. clif_displaymessage(fd, msg_txt(sd,273)); // "Commands available:"
  7230. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  7231. unsigned int slen = 0;
  7232. switch( type ) {
  7233. case COMMAND_CHARCOMMAND:
  7234. if( cmd->char_groups[sd->group_pos] == 0 )
  7235. continue;
  7236. break;
  7237. case COMMAND_ATCOMMAND:
  7238. if( cmd->at_groups[sd->group_pos] == 0 )
  7239. continue;
  7240. break;
  7241. default:
  7242. continue;
  7243. }
  7244. slen = strlen(cmd->command);
  7245. // flush the text buffer if this command won't fit into it
  7246. if ( slen + cur - line_buff >= CHATBOX_SIZE )
  7247. {
  7248. clif_displaymessage(fd,line_buff);
  7249. cur = line_buff;
  7250. memset(line_buff,' ',CHATBOX_SIZE);
  7251. line_buff[CHATBOX_SIZE-1] = 0;
  7252. }
  7253. memcpy(cur,cmd->command,slen);
  7254. cur += slen+(10-slen%10);
  7255. count++;
  7256. }
  7257. dbi_destroy(iter);
  7258. clif_displaymessage(fd,line_buff);
  7259. sprintf(atcmd_output, msg_txt(sd,274), count); // "%d commands found."
  7260. clif_displaymessage(fd, atcmd_output);
  7261. return;
  7262. }
  7263. /*==========================================
  7264. * @commands Lists available @ commands to you
  7265. *------------------------------------------*/
  7266. ACMD_FUNC(commands)
  7267. {
  7268. atcommand_commands_sub(sd, fd, COMMAND_ATCOMMAND);
  7269. return 0;
  7270. }
  7271. /*==========================================
  7272. * @charcommands Lists available # commands to you
  7273. *------------------------------------------*/
  7274. ACMD_FUNC(charcommands)
  7275. {
  7276. atcommand_commands_sub(sd, fd, COMMAND_CHARCOMMAND);
  7277. return 0;
  7278. }
  7279. /* for new mounts */
  7280. ACMD_FUNC(mount2) {
  7281. clif_displaymessage(sd->fd,msg_txt(sd,1362)); // NOTICE: If you crash with mount your LUA is outdated.
  7282. if( !(sd->sc.option&OPTION_MOUNTING) ) {
  7283. clif_displaymessage(sd->fd,msg_txt(sd,1363)); // You have mounted.
  7284. pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);
  7285. } else {
  7286. clif_displaymessage(sd->fd,msg_txt(sd,1364)); // You have released your mount.
  7287. pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);
  7288. }
  7289. return 0;
  7290. }
  7291. ACMD_FUNC(accinfo) {
  7292. char query[NAME_LENGTH];
  7293. if (!message || !*message || strlen(message) > NAME_LENGTH ) {
  7294. clif_displaymessage(fd, msg_txt(sd,1365)); // Usage: @accinfo/@accountinfo <account_id/char name>
  7295. clif_displaymessage(fd, msg_txt(sd,1366)); // You may search partial name by making use of '%' in the search, ex. "@accinfo %Mario%" lists all characters whose name contains "Mario".
  7296. return -1;
  7297. }
  7298. //remove const type
  7299. safestrncpy(query, message, NAME_LENGTH);
  7300. intif_request_accinfo( sd->fd, sd->bl.id, pc_get_group_level(sd), query );
  7301. return 0;
  7302. }
  7303. /* [Ind] */
  7304. ACMD_FUNC(set) {
  7305. char reg[32], val[128];
  7306. struct script_data* data;
  7307. int toset = 0, len;
  7308. bool is_str = false;
  7309. if( !message || !*message || (toset = sscanf(message, "%31s %128[^\n]s", reg, val)) < 1 ) {
  7310. clif_displaymessage(fd, msg_txt(sd,1367)); // Usage: @set <variable name> <value>
  7311. clif_displaymessage(fd, msg_txt(sd,1368)); // Usage: ex. "@set PoringCharVar 50"
  7312. clif_displaymessage(fd, msg_txt(sd,1369)); // Usage: ex. "@set PoringCharVarSTR$ Super Duper String"
  7313. clif_displaymessage(fd, msg_txt(sd,1370)); // Usage: ex. "@set PoringCharVarSTR$" outputs its value, Super Duper String.
  7314. return -1;
  7315. }
  7316. /* disabled variable types (they require a proper script state to function, so allowing them would crash the server) */
  7317. if( reg[0] == '.' ) {
  7318. clif_displaymessage(fd, msg_txt(sd,1371)); // NPC variables may not be used with @set.
  7319. return -1;
  7320. } else if( reg[0] == '\'' ) {
  7321. clif_displaymessage(fd, msg_txt(sd,1372)); // Instance variables may not be used with @set.
  7322. return -1;
  7323. }
  7324. is_str = ( reg[strlen(reg) - 1] == '$' ) ? true : false;
  7325. if( ( len = strlen(val) ) > 1 ) {
  7326. if( val[0] == '"' && val[len-1] == '"') {
  7327. val[len-1] = '\0'; //Strip quotes.
  7328. memmove(val, val+1, len-1);
  7329. }
  7330. }
  7331. if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
  7332. if( is_str )
  7333. set_var(sd, reg, (void*) val);
  7334. else
  7335. set_var(sd, reg, (void*)__64BPRTSIZE((atoi(val))));
  7336. }
  7337. CREATE(data, struct script_data,1);
  7338. if( is_str ) {// string variable
  7339. switch( reg[0] ) {
  7340. case '@':
  7341. data->u.str = pc_readregstr(sd, add_str(reg));
  7342. break;
  7343. case '$':
  7344. data->u.str = mapreg_readregstr(add_str(reg));
  7345. break;
  7346. case '#':
  7347. if( reg[1] == '#' )
  7348. data->u.str = pc_readaccountreg2str(sd, reg);// global
  7349. else
  7350. data->u.str = pc_readaccountregstr(sd, reg);// local
  7351. break;
  7352. default:
  7353. data->u.str = pc_readglobalreg_str(sd, reg);
  7354. break;
  7355. }
  7356. if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string
  7357. data->type = C_CONSTSTR;
  7358. data->u.str = "";
  7359. } else {// duplicate string
  7360. data->type = C_STR;
  7361. data->u.str = aStrdup(data->u.str);
  7362. }
  7363. } else {// integer variable
  7364. data->type = C_INT;
  7365. switch( reg[0] ) {
  7366. case '@':
  7367. data->u.num = pc_readreg(sd, add_str(reg));
  7368. break;
  7369. case '$':
  7370. data->u.num = mapreg_readreg(add_str(reg));
  7371. break;
  7372. case '#':
  7373. if( reg[1] == '#' )
  7374. data->u.num = pc_readaccountreg2(sd, reg);// global
  7375. else
  7376. data->u.num = pc_readaccountreg(sd, reg);// local
  7377. break;
  7378. default:
  7379. data->u.num = pc_readglobalreg(sd, reg);
  7380. break;
  7381. }
  7382. }
  7383. switch( data->type ) {
  7384. case C_INT:
  7385. sprintf(atcmd_output,msg_txt(sd,1373),reg,data->u.num); // %s value is now :%d
  7386. break;
  7387. case C_STR:
  7388. sprintf(atcmd_output,msg_txt(sd,1374),reg,data->u.str); // %s value is now :%s
  7389. break;
  7390. case C_CONSTSTR:
  7391. sprintf(atcmd_output,msg_txt(sd,1375),reg); // %s is empty
  7392. break;
  7393. default:
  7394. sprintf(atcmd_output,msg_txt(sd,1376),reg,data->type); // %s data type is not supported :%u
  7395. break;
  7396. }
  7397. clif_displaymessage(fd, atcmd_output);
  7398. aFree(data);
  7399. return 0;
  7400. }
  7401. ACMD_FUNC(reloadquestdb) {
  7402. do_reload_quest();
  7403. clif_displaymessage(fd, msg_txt(sd,1377)); // Quest database has been reloaded.
  7404. return 0;
  7405. }
  7406. ACMD_FUNC(addperm) {
  7407. int perm_size = ARRAYLENGTH(pc_g_permission_name);
  7408. bool add = (strcmpi(command+1, "addperm") == 0) ? true : false;
  7409. int i;
  7410. if( !message || !*message ) {
  7411. sprintf(atcmd_output, msg_txt(sd,1378),command); // Usage: %s <permission_name>
  7412. clif_displaymessage(fd, atcmd_output);
  7413. clif_displaymessage(fd, msg_txt(sd,1379)); // -- Permission List
  7414. for( i = 0; i < perm_size; i++ ) {
  7415. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7416. clif_displaymessage(fd, atcmd_output);
  7417. }
  7418. return -1;
  7419. }
  7420. ARR_FIND(0, perm_size, i, strcmpi(pc_g_permission_name[i].name, message) == 0);
  7421. if( i == perm_size ) {
  7422. sprintf(atcmd_output,msg_txt(sd,1380),message); // '%s' is not a known permission.
  7423. clif_displaymessage(fd, atcmd_output);
  7424. clif_displaymessage(fd, msg_txt(sd,1379)); // -- Permission List
  7425. for( i = 0; i < perm_size; i++ ) {
  7426. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7427. clif_displaymessage(fd, atcmd_output);
  7428. }
  7429. return -1;
  7430. }
  7431. if( add && (sd->permissions&pc_g_permission_name[i].permission) ) {
  7432. sprintf(atcmd_output, msg_txt(sd,1381),sd->status.name,pc_g_permission_name[i].name); // User '%s' already possesses the '%s' permission.
  7433. clif_displaymessage(fd, atcmd_output);
  7434. return -1;
  7435. } else if ( !add && !(sd->permissions&pc_g_permission_name[i].permission) ) {
  7436. sprintf(atcmd_output, msg_txt(sd,1382),sd->status.name,pc_g_permission_name[i].name); // User '%s' doesn't possess the '%s' permission.
  7437. clif_displaymessage(fd, atcmd_output);
  7438. sprintf(atcmd_output,msg_txt(sd,1383),sd->status.name); // -- User '%s' Permissions
  7439. clif_displaymessage(fd, atcmd_output);
  7440. for( i = 0; i < perm_size; i++ ) {
  7441. if( sd->permissions&pc_g_permission_name[i].permission ) {
  7442. sprintf(atcmd_output,"- %s",pc_g_permission_name[i].name);
  7443. clif_displaymessage(fd, atcmd_output);
  7444. }
  7445. }
  7446. return -1;
  7447. }
  7448. if( add )
  7449. sd->permissions |= pc_g_permission_name[i].permission;
  7450. else
  7451. sd->permissions &=~ pc_g_permission_name[i].permission;
  7452. sprintf(atcmd_output, msg_txt(sd,1384),sd->status.name); // User '%s' permissions updated successfully. The changes are temporary.
  7453. clif_displaymessage(fd, atcmd_output);
  7454. return 0;
  7455. }
  7456. ACMD_FUNC(unloadnpcfile) {
  7457. if( !message || !*message ) {
  7458. clif_displaymessage(fd, msg_txt(sd,1385)); // Usage: @unloadnpcfile <file name>
  7459. return -1;
  7460. }
  7461. if( npc_unloadfile(message) )
  7462. clif_displaymessage(fd, msg_txt(sd,1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
  7463. else {
  7464. clif_displaymessage(fd, msg_txt(sd,1387)); // File not found.
  7465. return -1;
  7466. }
  7467. return 0;
  7468. }
  7469. ACMD_FUNC(cart) {
  7470. #define MC_CART_MDFY(x) \
  7471. sd->status.skill[MC_PUSHCART].id = x?MC_PUSHCART:0; \
  7472. sd->status.skill[MC_PUSHCART].lv = x?1:0; \
  7473. sd->status.skill[MC_PUSHCART].flag = x?SKILL_FLAG_TEMPORARY:SKILL_FLAG_PERMANENT;
  7474. int val = atoi(message);
  7475. bool need_skill = pc_checkskill(sd, MC_PUSHCART) ? false : true;
  7476. if( !message || !*message || val < 0 || val > MAX_CARTS ) {
  7477. sprintf(atcmd_output, msg_txt(sd,1390),command,MAX_CARTS); // Unknown Cart (usage: %s <0-%d>).
  7478. clif_displaymessage(fd, atcmd_output);
  7479. return -1;
  7480. }
  7481. if( val == 0 && !pc_iscarton(sd) ) {
  7482. clif_displaymessage(fd, msg_txt(sd,1391)); // You do not possess a cart to be removed
  7483. return -1;
  7484. }
  7485. if( need_skill ) {
  7486. MC_CART_MDFY(1);
  7487. }
  7488. if( pc_setcart(sd, val) ) {
  7489. if( need_skill ) {
  7490. MC_CART_MDFY(0);
  7491. }
  7492. return -1;/* @cart failed */
  7493. }
  7494. if( need_skill ) {
  7495. MC_CART_MDFY(0);
  7496. }
  7497. clif_displaymessage(fd, msg_txt(sd,1392)); // Cart Added
  7498. return 0;
  7499. #undef MC_CART_MDFY
  7500. }
  7501. /* Channel System [Ind] */
  7502. ACMD_FUNC(join) {
  7503. struct raChSysCh *channel;
  7504. char name[RACHSYS_NAME_LENGTH], pass[RACHSYS_NAME_LENGTH];
  7505. DBMap* channel_db = clif_get_channel_db();
  7506. if( !message || !*message || sscanf(message, "%s %s", name, pass) < 1 ) {
  7507. sprintf(atcmd_output, msg_txt(sd,1399),command); // Unknown Channel (usage: %s <#channel_name>)
  7508. clif_displaymessage(fd, atcmd_output);
  7509. return -1;
  7510. }
  7511. if( raChSys.local && strcmpi(name + 1, raChSys.local_name) == 0 ) {
  7512. if( !map[sd->bl.m].channel ) {
  7513. clif_chsys_mjoin(sd);
  7514. return 0;
  7515. } else
  7516. channel = map[sd->bl.m].channel;
  7517. } else if( raChSys.ally && sd->status.guild_id && strcmpi(name + 1, raChSys.ally_name) == 0 ) {
  7518. struct guild *g = sd->guild;
  7519. if( !g ) return -1;/* unlikely, but we wont let it crash anyway. */
  7520. channel = (struct raChSysCh *)g->channel;
  7521. } else if( !( channel = strdb_get(channel_db, name + 1) ) ) {
  7522. sprintf(atcmd_output, msg_txt(sd,1400),name,command); // Unknown Channel '%s' (usage: %s <#channel_name>)
  7523. clif_displaymessage(fd, atcmd_output);
  7524. return -1;
  7525. }
  7526. if( idb_exists(channel->users, sd->status.char_id) ) {
  7527. sprintf(atcmd_output, msg_txt(sd,1434),name); // You're already in the '%s' channel.
  7528. clif_displaymessage(fd, atcmd_output);
  7529. return -1;
  7530. }
  7531. if( channel->pass[0] != '\0' && strcmp(channel->pass,pass) != 0 ) {
  7532. if( pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) {
  7533. sd->stealth = true;
  7534. } else {
  7535. sprintf(atcmd_output, msg_txt(sd,1401),name,command); // '%s' Channel is password protected (usage: %s <#channel_name> <password>)
  7536. clif_displaymessage(fd, atcmd_output);
  7537. return -1;
  7538. }
  7539. }
  7540. if( !( channel->opt & raChSys_OPT_ANNOUNCE_JOIN ) ) {
  7541. sprintf(atcmd_output, msg_txt(sd,1403),name); // You're now in the '%s' channel.
  7542. clif_displaymessage(fd, atcmd_output);
  7543. }
  7544. clif_chsys_join(channel,sd);
  7545. return 0;
  7546. }
  7547. static inline void atcmd_channel_help(struct map_session_data *sd, const char *command, bool can_create) {
  7548. int fd = sd->fd;
  7549. clif_displaymessage(fd, msg_txt(sd,1414));// ---- Available options:
  7550. if( can_create ) {
  7551. sprintf(atcmd_output, msg_txt(sd,1415),command);// * %s create <#channel_name> <channel_password>
  7552. clif_displaymessage(fd, atcmd_output);
  7553. clif_displaymessage(fd, msg_txt(sd,1416));// -- Creates a new channel.
  7554. }
  7555. sprintf(atcmd_output, msg_txt(sd,1417),command);// * %s list
  7556. clif_displaymessage(fd, atcmd_output);
  7557. clif_displaymessage(fd, msg_txt(sd,1418));// -- Lists all public channels.
  7558. if( can_create ) {
  7559. sprintf(atcmd_output, msg_txt(sd,1419),command);// * %s list colors
  7560. clif_displaymessage(fd, atcmd_output);
  7561. clif_displaymessage(fd, msg_txt(sd,1420));// -- Lists all available colors for custom channels.
  7562. sprintf(atcmd_output, msg_txt(sd,1421),command);// * %s setcolor <#channel_name> <color_name>
  7563. clif_displaymessage(fd, atcmd_output);
  7564. clif_displaymessage(fd, msg_txt(sd,1422));// -- Changes channel text to the specified color (channel owners only).
  7565. }
  7566. sprintf(atcmd_output, msg_txt(sd,1423),command);// * %s leave <#channel_name>
  7567. clif_displaymessage(fd, atcmd_output);
  7568. clif_displaymessage(fd, msg_txt(sd,1424));// -- Leaves the specified channel.
  7569. sprintf(atcmd_output, msg_txt(sd,1427),command);// * %s bindto <#channel_name>
  7570. clif_displaymessage(fd, atcmd_output);
  7571. clif_displaymessage(fd, msg_txt(sd,1428));// -- Binds your global chat to the specified channel, sending all global messages to that channel.
  7572. sprintf(atcmd_output, msg_txt(sd,1429),command);// * %s unbind
  7573. clif_displaymessage(fd, atcmd_output);
  7574. clif_displaymessage(fd, msg_txt(sd,1430));// -- Unbinds your global chat from the attached channel, if any.
  7575. sprintf(atcmd_output, msg_txt(sd,1404),command); // %s failed.
  7576. clif_displaymessage(fd, atcmd_output);
  7577. }
  7578. ACMD_FUNC(channel) {
  7579. struct raChSysCh *channel;
  7580. char key[RACHSYS_NAME_LENGTH], sub1[RACHSYS_NAME_LENGTH], sub2[RACHSYS_NAME_LENGTH], sub3[RACHSYS_NAME_LENGTH];
  7581. unsigned char k = 0;
  7582. DBMap* channel_db = clif_get_channel_db();
  7583. sub1[0] = sub2[0] = sub3[0] = '\0';
  7584. if( !message || !*message || sscanf(message, "%s %s %s %s", key, sub1, sub2, sub3) < 1 ) {
  7585. atcmd_channel_help(sd,command,( raChSys.allow_user_channel_creation || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ));
  7586. return 0;
  7587. }
  7588. if( strcmpi(key,"create") == 0 && ( raChSys.allow_user_channel_creation || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) ) {
  7589. if( sub1[0] != '#' ) {
  7590. clif_displaymessage(fd, msg_txt(sd,1405));// Channel name must start with '#'.
  7591. return -1;
  7592. } else if ( strlen(sub1) < 3 || strlen(sub1) > RACHSYS_NAME_LENGTH ) {
  7593. sprintf(atcmd_output, msg_txt(sd,1406), RACHSYS_NAME_LENGTH);// Channel length must be between 3 and %d.
  7594. clif_displaymessage(fd, atcmd_output);
  7595. return -1;
  7596. } else if ( sub3[0] != '\0' ) {
  7597. clif_displaymessage(fd, msg_txt(sd,1408)); // Channel password may not contain spaces.
  7598. return -1;
  7599. }
  7600. if( strcmpi(sub1 + 1,raChSys.local_name) == 0 || strcmpi(sub1 + 1,raChSys.ally_name) == 0 || strdb_exists(channel_db, sub1 + 1) ) {
  7601. sprintf(atcmd_output, msg_txt(sd,1407), sub1);// Channel '%s' is not available.
  7602. clif_displaymessage(fd, atcmd_output);
  7603. return -1;
  7604. }
  7605. CREATE( channel, struct raChSysCh, 1 );
  7606. clif_chsys_create(channel,sub1 + 1,sub2,0);
  7607. channel->owner = sd->status.char_id;
  7608. channel->type = raChSys_PRIVATE;
  7609. if( !( channel->opt & raChSys_OPT_ANNOUNCE_JOIN ) ) {
  7610. sprintf(atcmd_output, msg_txt(sd,1403),sub1); // You're now in the '%s' channel.
  7611. clif_displaymessage(fd, atcmd_output);
  7612. }
  7613. clif_chsys_join(channel,sd);
  7614. } else if ( strcmpi(key,"list") == 0 ) {
  7615. if( sub1[0] != '\0' && strcmpi(sub1,"colors") == 0 ) {
  7616. char mout[40];
  7617. for( k = 0; k < raChSys.colors_count; k++ ) {
  7618. unsigned short msg_len = 1;
  7619. msg_len += sprintf(mout, "[ %s list colors ] : %s",command,raChSys.colors_name[k]);
  7620. WFIFOHEAD(fd,msg_len + 12);
  7621. WFIFOW(fd,0) = 0x2C1;
  7622. WFIFOW(fd,2) = msg_len + 12;
  7623. WFIFOL(fd,4) = 0;
  7624. WFIFOL(fd,8) = raChSys.colors[k];
  7625. safestrncpy((char*)WFIFOP(fd,12), mout, msg_len);
  7626. WFIFOSET(fd, msg_len + 12);
  7627. }
  7628. } else {
  7629. DBIterator *iter = db_iterator(channel_db);
  7630. bool show_all = pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ? true : false;
  7631. clif_displaymessage(fd, msg_txt(sd,1410)); // ---- Public Channels ----
  7632. if( raChSys.local ) {
  7633. sprintf(atcmd_output, msg_txt(sd,1409), raChSys.local_name, map[sd->bl.m].channel ? db_size(map[sd->bl.m].channel->users) : 0);// - #%s ( %d users )
  7634. clif_displaymessage(fd, atcmd_output);
  7635. }
  7636. if( raChSys.ally && sd->status.guild_id ) {
  7637. struct guild *g = sd->guild;
  7638. if( !g ) return -1;
  7639. sprintf(atcmd_output, msg_txt(sd,1409), raChSys.ally_name, db_size(((struct raChSysCh *)g->channel)->users));// - #%s ( %d users )
  7640. clif_displaymessage(fd, atcmd_output);
  7641. }
  7642. for(channel = dbi_first(iter); dbi_exists(iter); channel = dbi_next(iter)) {
  7643. if( show_all || channel->type == raChSys_PUBLIC ) {
  7644. sprintf(atcmd_output, msg_txt(sd,1409), channel->name, db_size(channel->users));// - #%s (%d users)
  7645. clif_displaymessage(fd, atcmd_output);
  7646. }
  7647. }
  7648. dbi_destroy(iter);
  7649. }
  7650. } else if ( strcmpi(key,"setcolor") == 0 ) {
  7651. if( sub1[0] != '#' ) {
  7652. clif_displaymessage(fd, msg_txt(sd,1405));// Channel name must start with '#'.
  7653. return -1;
  7654. }
  7655. if( !(channel = strdb_get(channel_db, sub1 + 1)) ) {
  7656. sprintf(atcmd_output, msg_txt(sd,1407), sub1);// Channel '%s' is not available.
  7657. clif_displaymessage(fd, atcmd_output);
  7658. return -1;
  7659. }
  7660. if( channel->owner != sd->status.char_id && !pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) {
  7661. sprintf(atcmd_output, msg_txt(sd,1412), sub1);// You're not the owner of channel '%s'.
  7662. clif_displaymessage(fd, atcmd_output);
  7663. return -1;
  7664. }
  7665. for( k = 0; k < raChSys.colors_count; k++ ) {
  7666. if( strcmpi(sub2,raChSys.colors_name[k]) == 0 )
  7667. break;
  7668. }
  7669. if( k == raChSys.colors_count ) {
  7670. sprintf(atcmd_output, msg_txt(sd,1411), sub2);// Unknown color '%s'.
  7671. clif_displaymessage(fd, atcmd_output);
  7672. return -1;
  7673. }
  7674. channel->color = k;
  7675. sprintf(atcmd_output, msg_txt(sd,1413),sub1,raChSys.colors_name[k]);// '%s' channel color updated to '%s'.
  7676. clif_displaymessage(fd, atcmd_output);
  7677. } else if ( strcmpi(key,"leave") == 0 ) {
  7678. if( sub1[0] != '#' ) {
  7679. clif_displaymessage(fd, msg_txt(sd,1405));// Channel name must start with '#'.
  7680. return -1;
  7681. }
  7682. ARR_FIND(0, sd->channel_count, k, strcmpi(sub1+1,sd->channels[k]->name) == 0);
  7683. if( k == sd->channel_count ) {
  7684. sprintf(atcmd_output, msg_txt(sd,1425),sub1);// You're not part of the '%s' channel.
  7685. clif_displaymessage(fd, atcmd_output);
  7686. return -1;
  7687. }
  7688. clif_chsys_left(sd->channels[k],sd);
  7689. sprintf(atcmd_output, msg_txt(sd,1426),sub1); // You've left the '%s' channel.
  7690. clif_displaymessage(fd, atcmd_output);
  7691. } else if ( strcmpi(key,"bindto") == 0 ) {
  7692. if( sub1[0] != '#' ) {
  7693. clif_displaymessage(fd, msg_txt(sd,1405));// Channel name must start with '#'.
  7694. return -1;
  7695. }
  7696. ARR_FIND(0, sd->channel_count, k, strcmpi(sub1+1,sd->channels[k]->name) == 0);
  7697. if( k == sd->channel_count ) {
  7698. sprintf(atcmd_output, msg_txt(sd,1425),sub1);// You're not part of the '%s' channel.
  7699. clif_displaymessage(fd, atcmd_output);
  7700. return -1;
  7701. }
  7702. sd->gcbind = sd->channels[k];
  7703. sprintf(atcmd_output, msg_txt(sd,1431),sub1); // Your global chat is now binded to the '%s' channel.
  7704. clif_displaymessage(fd, atcmd_output);
  7705. } else if ( strcmpi(key,"unbind") == 0 ) {
  7706. if( sd->gcbind == NULL ) {
  7707. clif_displaymessage(fd, msg_txt(sd,1432));// Your global chat is not binded to any channel.
  7708. return -1;
  7709. }
  7710. sprintf(atcmd_output, msg_txt(sd,1433),sd->gcbind->name); // Your global chat is now unbinded from the '#%s' channel.
  7711. clif_displaymessage(fd, atcmd_output);
  7712. sd->gcbind = NULL;
  7713. } else {
  7714. atcmd_channel_help(sd,command,( raChSys.allow_user_channel_creation || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ));
  7715. }
  7716. return 0;
  7717. }
  7718. ACMD_FUNC(fontcolor) {
  7719. unsigned char k;
  7720. if( !message || !*message ) {
  7721. char mout[40];
  7722. for( k = 0; k < raChSys.colors_count; k++ ) {
  7723. unsigned short msg_len = 1;
  7724. msg_len += sprintf(mout, "[ %s ] : %s",command,raChSys.colors_name[k]);
  7725. WFIFOHEAD(fd,msg_len + 12);
  7726. WFIFOW(fd,0) = 0x2C1;
  7727. WFIFOW(fd,2) = msg_len + 12;
  7728. WFIFOL(fd,4) = 0;
  7729. WFIFOL(fd,8) = raChSys.colors[k];
  7730. safestrncpy((char*)WFIFOP(fd,12), mout, msg_len);
  7731. WFIFOSET(fd, msg_len + 12);
  7732. }
  7733. return -1;
  7734. }
  7735. if( message[0] == '0' ) {
  7736. sd->fontcolor = 0;
  7737. pc_disguise(sd,0);
  7738. return 0;
  7739. }
  7740. for( k = 0; k < raChSys.colors_count; k++ ) {
  7741. if( strcmpi(message,raChSys.colors_name[k]) == 0 )
  7742. break;
  7743. }
  7744. if( k == raChSys.colors_count ) {
  7745. sprintf(atcmd_output, msg_txt(sd,1411), message);// Unknown color '%s'.
  7746. clif_displaymessage(fd, atcmd_output);
  7747. return -1;
  7748. }
  7749. sd->fontcolor = k + 1;
  7750. pc_disguise(sd,sd->status.class_);
  7751. return 0;
  7752. }
  7753. ACMD_FUNC(langtype){
  7754. char langtype[8];
  7755. int lang=-1;
  7756. memset(langtype, '\0', sizeof(langtype));
  7757. if(sscanf(message, "%3s", langtype) < 1){
  7758. clif_displaymessage(fd,msg_txt(sd,460));
  7759. }
  7760. lang = msg_langstr2langtype(langtype); //switch langstr to associate langtype
  7761. if( msg_checklangtype(lang,false) == 1 ){ //verify it's enable and affect it
  7762. char output[100];
  7763. pc_setaccountreg(sd, "#langtype", lang); //for login/char
  7764. sd->langtype = lang;
  7765. sprintf(output,msg_txt(sd,461),langtype,lang); //for debug
  7766. clif_displaymessage(fd,output); //"English is now set as default language"
  7767. }
  7768. else {
  7769. int i=0, test=0; char output[512]; //shoud be fine for 50 lang
  7770. clif_displaymessage(fd,msg_txt(sd,462));
  7771. clif_displaymessage(fd,msg_txt(sd,464));
  7772. while(test!=-1){ //out of range
  7773. test = msg_checklangtype(i,false);
  7774. if(test == 1)
  7775. sprintf(output,"%s%s => %d\n",output,msg_langtype2langstr(i),i);
  7776. i++;
  7777. }
  7778. clif_displaymessage(fd,output);
  7779. }
  7780. return 0;
  7781. }
  7782. ACMD_FUNC(reloadmsgconf){
  7783. map_msg_reload();
  7784. clif_displaymessage(fd, msg_txt(sd,463));
  7785. return 0;
  7786. }
  7787. /**
  7788. * Fills the reference of available commands in atcommand DBMap
  7789. **/
  7790. #define ACMD_DEF(x) { #x, atcommand_ ## x, NULL, NULL }
  7791. #define ACMD_DEF2(x2, x) { x2, atcommand_ ## x, NULL, NULL }
  7792. void atcommand_basecommands(void) {
  7793. /**
  7794. * Command reference list, place the base of your commands here
  7795. **/
  7796. AtCommandInfo atcommand_base[] = {
  7797. ACMD_DEF2("warp", mapmove),
  7798. ACMD_DEF(where),
  7799. ACMD_DEF(jumpto),
  7800. ACMD_DEF(jump),
  7801. ACMD_DEF(who),
  7802. ACMD_DEF2("who2", who),
  7803. ACMD_DEF2("who3", who),
  7804. ACMD_DEF2("whomap", who),
  7805. ACMD_DEF2("whomap2", who),
  7806. ACMD_DEF2("whomap3", who),
  7807. ACMD_DEF(whogm),
  7808. ACMD_DEF(save),
  7809. ACMD_DEF(load),
  7810. ACMD_DEF(speed),
  7811. ACMD_DEF(storage),
  7812. ACMD_DEF(guildstorage),
  7813. ACMD_DEF(option),
  7814. ACMD_DEF(hide), // + /hide
  7815. ACMD_DEF(jobchange),
  7816. ACMD_DEF(kill),
  7817. ACMD_DEF(alive),
  7818. ACMD_DEF(kami),
  7819. ACMD_DEF2("kamib", kami),
  7820. ACMD_DEF2("kamic", kami),
  7821. ACMD_DEF2("lkami", kami),
  7822. ACMD_DEF(heal),
  7823. ACMD_DEF(item),
  7824. ACMD_DEF(item2),
  7825. ACMD_DEF(itemreset),
  7826. ACMD_DEF(clearstorage),
  7827. ACMD_DEF(cleargstorage),
  7828. ACMD_DEF(clearcart),
  7829. ACMD_DEF2("blvl", baselevelup),
  7830. ACMD_DEF2("jlvl", joblevelup),
  7831. ACMD_DEF(help),
  7832. ACMD_DEF(pvpoff),
  7833. ACMD_DEF(pvpon),
  7834. ACMD_DEF(gvgoff),
  7835. ACMD_DEF(gvgon),
  7836. ACMD_DEF(model),
  7837. ACMD_DEF(go),
  7838. ACMD_DEF(monster),
  7839. ACMD_DEF2("monstersmall", monster),
  7840. ACMD_DEF2("monsterbig", monster),
  7841. ACMD_DEF(killmonster),
  7842. ACMD_DEF2("killmonster2", killmonster),
  7843. ACMD_DEF(refine),
  7844. ACMD_DEF(produce),
  7845. ACMD_DEF(memo),
  7846. ACMD_DEF(gat),
  7847. ACMD_DEF(displaystatus),
  7848. ACMD_DEF2("stpoint", statuspoint),
  7849. ACMD_DEF2("skpoint", skillpoint),
  7850. ACMD_DEF(zeny),
  7851. ACMD_DEF2("str", param),
  7852. ACMD_DEF2("agi", param),
  7853. ACMD_DEF2("vit", param),
  7854. ACMD_DEF2("int", param),
  7855. ACMD_DEF2("dex", param),
  7856. ACMD_DEF2("luk", param),
  7857. ACMD_DEF2("glvl", guildlevelup),
  7858. ACMD_DEF(makeegg),
  7859. ACMD_DEF(hatch),
  7860. ACMD_DEF(petfriendly),
  7861. ACMD_DEF(pethungry),
  7862. ACMD_DEF(petrename),
  7863. ACMD_DEF(recall), // + /recall
  7864. ACMD_DEF(night),
  7865. ACMD_DEF(day),
  7866. ACMD_DEF(doom),
  7867. ACMD_DEF(doommap),
  7868. ACMD_DEF(raise),
  7869. ACMD_DEF(raisemap),
  7870. ACMD_DEF(kick), // + right click menu for GM "(name) force to quit"
  7871. ACMD_DEF(kickall),
  7872. ACMD_DEF(allskill),
  7873. ACMD_DEF(questskill),
  7874. ACMD_DEF(lostskill),
  7875. ACMD_DEF(spiritball),
  7876. ACMD_DEF(party),
  7877. ACMD_DEF(guild),
  7878. ACMD_DEF(breakguild),
  7879. ACMD_DEF(agitstart),
  7880. ACMD_DEF(agitend),
  7881. ACMD_DEF(mapexit),
  7882. ACMD_DEF(idsearch),
  7883. ACMD_DEF(broadcast), // + /b and /nb
  7884. ACMD_DEF(localbroadcast), // + /lb and /nlb
  7885. ACMD_DEF(recallall),
  7886. ACMD_DEF(reloaditemdb),
  7887. ACMD_DEF(reloadmobdb),
  7888. ACMD_DEF(reloadskilldb),
  7889. ACMD_DEF(reloadscript),
  7890. ACMD_DEF(reloadatcommand),
  7891. ACMD_DEF(reloadbattleconf),
  7892. ACMD_DEF(reloadstatusdb),
  7893. ACMD_DEF(reloadpcdb),
  7894. ACMD_DEF(reloadmotd),
  7895. ACMD_DEF(mapinfo),
  7896. ACMD_DEF(dye),
  7897. ACMD_DEF2("hairstyle", hair_style),
  7898. ACMD_DEF2("haircolor", hair_color),
  7899. ACMD_DEF2("allstats", stat_all),
  7900. ACMD_DEF2("block", char_block),
  7901. ACMD_DEF2("ban", char_ban),
  7902. ACMD_DEF2("unblock", char_unblock),
  7903. ACMD_DEF2("unban", char_unban),
  7904. ACMD_DEF2("mount", mount_peco),
  7905. ACMD_DEF(guildspy),
  7906. ACMD_DEF(partyspy),
  7907. ACMD_DEF(repairall),
  7908. ACMD_DEF(guildrecall),
  7909. ACMD_DEF(partyrecall),
  7910. ACMD_DEF(nuke),
  7911. ACMD_DEF(shownpc),
  7912. ACMD_DEF(hidenpc),
  7913. ACMD_DEF(loadnpc),
  7914. ACMD_DEF(unloadnpc),
  7915. ACMD_DEF2("time", servertime),
  7916. ACMD_DEF(jail),
  7917. ACMD_DEF(unjail),
  7918. ACMD_DEF(jailfor),
  7919. ACMD_DEF(jailtime),
  7920. ACMD_DEF(disguise),
  7921. ACMD_DEF(undisguise),
  7922. ACMD_DEF(email),
  7923. ACMD_DEF(effect),
  7924. ACMD_DEF(follow),
  7925. ACMD_DEF(addwarp),
  7926. ACMD_DEF(skillon),
  7927. ACMD_DEF(skilloff),
  7928. ACMD_DEF(killer),
  7929. ACMD_DEF(npcmove),
  7930. ACMD_DEF(killable),
  7931. ACMD_DEF(dropall),
  7932. ACMD_DEF(storeall),
  7933. ACMD_DEF(skillid),
  7934. ACMD_DEF(useskill),
  7935. ACMD_DEF(displayskill),
  7936. ACMD_DEF(snow),
  7937. ACMD_DEF(sakura),
  7938. ACMD_DEF(clouds),
  7939. ACMD_DEF(clouds2),
  7940. ACMD_DEF(fog),
  7941. ACMD_DEF(fireworks),
  7942. ACMD_DEF(leaves),
  7943. ACMD_DEF(summon),
  7944. ACMD_DEF(adjgroup),
  7945. ACMD_DEF(trade),
  7946. ACMD_DEF(send),
  7947. ACMD_DEF(setbattleflag),
  7948. ACMD_DEF(unmute),
  7949. ACMD_DEF(clearweather),
  7950. ACMD_DEF(uptime),
  7951. ACMD_DEF(changesex),
  7952. ACMD_DEF(mute),
  7953. ACMD_DEF(refresh),
  7954. ACMD_DEF(refreshall),
  7955. ACMD_DEF(identify),
  7956. ACMD_DEF(gmotd),
  7957. ACMD_DEF(misceffect),
  7958. ACMD_DEF(mobsearch),
  7959. ACMD_DEF(cleanmap),
  7960. ACMD_DEF(cleanarea),
  7961. ACMD_DEF(npctalk),
  7962. ACMD_DEF(pettalk),
  7963. ACMD_DEF(users),
  7964. ACMD_DEF(reset),
  7965. ACMD_DEF(skilltree),
  7966. ACMD_DEF(marry),
  7967. ACMD_DEF(divorce),
  7968. ACMD_DEF(sound),
  7969. ACMD_DEF(undisguiseall),
  7970. ACMD_DEF(disguiseall),
  7971. ACMD_DEF(changelook),
  7972. ACMD_DEF(autoloot),
  7973. ACMD_DEF2("alootid", autolootitem),
  7974. ACMD_DEF(mobinfo),
  7975. ACMD_DEF(exp),
  7976. ACMD_DEF(version),
  7977. ACMD_DEF(mutearea),
  7978. ACMD_DEF(rates),
  7979. ACMD_DEF(iteminfo),
  7980. ACMD_DEF(whodrops),
  7981. ACMD_DEF(whereis),
  7982. ACMD_DEF(mapflag),
  7983. ACMD_DEF(me),
  7984. ACMD_DEF(monsterignore),
  7985. ACMD_DEF(fakename),
  7986. ACMD_DEF(size),
  7987. ACMD_DEF(showexp),
  7988. ACMD_DEF(showzeny),
  7989. ACMD_DEF(showdelay),
  7990. ACMD_DEF(autotrade),
  7991. ACMD_DEF(changegm),
  7992. ACMD_DEF(changeleader),
  7993. ACMD_DEF(partyoption),
  7994. ACMD_DEF(invite),
  7995. ACMD_DEF(duel),
  7996. ACMD_DEF(leave),
  7997. ACMD_DEF(accept),
  7998. ACMD_DEF(reject),
  7999. ACMD_DEF(clone),
  8000. ACMD_DEF2("slaveclone", clone),
  8001. ACMD_DEF2("evilclone", clone),
  8002. ACMD_DEF(tonpc),
  8003. ACMD_DEF(commands),
  8004. ACMD_DEF(noask),
  8005. ACMD_DEF(request),
  8006. ACMD_DEF(homlevel),
  8007. ACMD_DEF(homevolution),
  8008. ACMD_DEF(hommutate),
  8009. ACMD_DEF(makehomun),
  8010. ACMD_DEF(homfriendly),
  8011. ACMD_DEF(homhungry),
  8012. ACMD_DEF(homtalk),
  8013. ACMD_DEF(hominfo),
  8014. ACMD_DEF(homstats),
  8015. ACMD_DEF(homshuffle),
  8016. ACMD_DEF(showmobs),
  8017. ACMD_DEF(feelreset),
  8018. ACMD_DEF(auction),
  8019. ACMD_DEF(mail),
  8020. ACMD_DEF2("noks", ksprotection),
  8021. ACMD_DEF(allowks),
  8022. ACMD_DEF(cash),
  8023. ACMD_DEF2("points", cash),
  8024. ACMD_DEF(agitstart2),
  8025. ACMD_DEF(agitend2),
  8026. ACMD_DEF2("skreset", resetskill),
  8027. ACMD_DEF2("streset", resetstat),
  8028. ACMD_DEF2("storagelist", itemlist),
  8029. ACMD_DEF2("cartlist", itemlist),
  8030. ACMD_DEF2("itemlist", itemlist),
  8031. ACMD_DEF(stats),
  8032. ACMD_DEF(delitem),
  8033. ACMD_DEF(charcommands),
  8034. ACMD_DEF(font),
  8035. ACMD_DEF(accinfo),
  8036. ACMD_DEF(set),
  8037. ACMD_DEF(reloadquestdb),
  8038. ACMD_DEF(undisguiseguild),
  8039. ACMD_DEF(disguiseguild),
  8040. ACMD_DEF(sizeall),
  8041. ACMD_DEF(sizeguild),
  8042. ACMD_DEF(addperm),
  8043. ACMD_DEF2("rmvperm", addperm),
  8044. ACMD_DEF(unloadnpcfile),
  8045. ACMD_DEF(cart),
  8046. ACMD_DEF(mount2),
  8047. ACMD_DEF(join),
  8048. ACMD_DEF(channel),
  8049. ACMD_DEF(fontcolor),
  8050. ACMD_DEF(langtype),
  8051. ACMD_DEF(reloadmsgconf)
  8052. };
  8053. AtCommandInfo* atcommand;
  8054. int i;
  8055. for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) {
  8056. if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK
  8057. ShowDebug("atcommand_basecommands: duplicate ACMD_DEF for '%s'.\n", atcommand_base[i].command);
  8058. continue;
  8059. }
  8060. CREATE(atcommand, AtCommandInfo, 1);
  8061. safestrncpy(atcommand->command, atcommand_base[i].command, sizeof(atcommand->command));
  8062. atcommand->func = atcommand_base[i].func;
  8063. strdb_put(atcommand_db, atcommand->command, atcommand);
  8064. }
  8065. return;
  8066. }
  8067. /*==========================================
  8068. * Command lookup functions
  8069. *------------------------------------------*/
  8070. bool atcommand_exists(const char* name)
  8071. {
  8072. return strdb_exists(atcommand_db, name);
  8073. }
  8074. static AtCommandInfo* get_atcommandinfo_byname(const char *name)
  8075. {
  8076. if (strdb_exists(atcommand_db, name))
  8077. return (AtCommandInfo*)strdb_get(atcommand_db, name);
  8078. return NULL;
  8079. }
  8080. static const char* atcommand_checkalias(const char *aliasname)
  8081. {
  8082. AliasInfo *alias_info = NULL;
  8083. if ((alias_info = (AliasInfo*)strdb_get(atcommand_alias_db, aliasname)) != NULL)
  8084. return alias_info->command->command;
  8085. return aliasname;
  8086. }
  8087. /// AtCommand suggestion
  8088. static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand) {
  8089. DBIterator* atcommand_iter;
  8090. DBIterator* alias_iter;
  8091. AtCommandInfo* command_info = NULL;
  8092. AliasInfo* alias_info = NULL;
  8093. AtCommandType type = atcommand ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND;
  8094. char* full_match[MAX_SUGGESTIONS];
  8095. char* suggestions[MAX_SUGGESTIONS];
  8096. char* match;
  8097. int prefix_count = 0, full_count = 0;
  8098. bool can_use;
  8099. if (!battle_config.atcommand_suggestions_enabled)
  8100. return;
  8101. atcommand_iter = db_iterator(atcommand_db);
  8102. alias_iter = db_iterator(atcommand_alias_db);
  8103. // Build the matches
  8104. for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter); command_info = dbi_next(atcommand_iter)) {
  8105. match = strstr(command_info->command, name);
  8106. can_use = pc_can_use_command(sd, command_info->command, type);
  8107. if ( prefix_count < MAX_SUGGESTIONS && match == command_info->command && can_use ) {
  8108. suggestions[prefix_count] = command_info->command;
  8109. ++prefix_count;
  8110. }
  8111. if ( full_count < MAX_SUGGESTIONS && match != NULL && match != command_info->command && can_use ) {
  8112. full_match[full_count] = command_info->command;
  8113. ++full_count;
  8114. }
  8115. }
  8116. for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter); alias_info = dbi_next(alias_iter)) {
  8117. match = strstr(alias_info->alias, name);
  8118. can_use = pc_can_use_command(sd, alias_info->command->command, type);
  8119. if ( prefix_count < MAX_SUGGESTIONS && match == alias_info->alias && can_use) {
  8120. suggestions[prefix_count] = alias_info->alias;
  8121. ++prefix_count;
  8122. }
  8123. if ( full_count < MAX_SUGGESTIONS && match != NULL && match != alias_info->alias && can_use ) {
  8124. full_match[full_count] = alias_info->alias;
  8125. ++full_count;
  8126. }
  8127. }
  8128. if ((full_count+prefix_count) > 0) {
  8129. char buffer[512];
  8130. int i;
  8131. // Merge full match and prefix match results
  8132. if (prefix_count < MAX_SUGGESTIONS) {
  8133. memmove(&suggestions[prefix_count], full_match, sizeof(char*) * (MAX_SUGGESTIONS-prefix_count));
  8134. prefix_count = min(prefix_count+full_count, MAX_SUGGESTIONS);
  8135. }
  8136. // Build the suggestion string
  8137. strcpy(buffer, msg_txt(sd,205));
  8138. strcat(buffer,"\n");
  8139. for(i=0; i < prefix_count; ++i) {
  8140. strcat(buffer,suggestions[i]);
  8141. strcat(buffer," ");
  8142. }
  8143. clif_displaymessage(sd->fd, buffer);
  8144. }
  8145. dbi_destroy(atcommand_iter);
  8146. dbi_destroy(alias_iter);
  8147. }
  8148. /// Executes an at-command.
  8149. bool is_atcommand(const int fd, struct map_session_data* sd, const char* message, int type)
  8150. {
  8151. char charname[NAME_LENGTH], params[100];
  8152. char charname2[NAME_LENGTH], params2[100];
  8153. char command[100];
  8154. char output[CHAT_SIZE_MAX];
  8155. //Reconstructed message
  8156. char atcmd_msg[CHAT_SIZE_MAX];
  8157. TBL_PC * ssd = NULL; //sd for target
  8158. AtCommandInfo * info;
  8159. nullpo_retr(false, sd);
  8160. //Shouldn't happen
  8161. if ( !message || !*message )
  8162. return false;
  8163. //Block NOCHAT but do not display it as a normal message
  8164. if ( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCOMMAND )
  8165. return true;
  8166. // skip 10/11-langtype's codepage indicator, if detected
  8167. if ( message[0] == '|' && strlen(message) >= 4 && (message[3] == atcommand_symbol || message[3] == charcommand_symbol) )
  8168. message += 3;
  8169. //Should display as a normal message
  8170. if ( *message != atcommand_symbol && *message != charcommand_symbol )
  8171. return false;
  8172. // type value 0 = server invoked: bypass restrictions
  8173. // 1 = player invoked
  8174. if ( type == 1) {
  8175. //Commands are disabled on maps flagged as 'nocommand'
  8176. if ( map[sd->bl.m].nocommand && pc_get_group_level(sd) < map[sd->bl.m].nocommand ) {
  8177. clif_displaymessage(fd, msg_txt(sd,143));
  8178. return false;
  8179. }
  8180. }
  8181. if (*message == charcommand_symbol) {
  8182. do {
  8183. int x, y, z;
  8184. //Checks to see if #command has a name or a name + parameters.
  8185. x = sscanf(message, "%99s \"%23[^\"]\" %99[^\n]", command, charname, params);
  8186. y = sscanf(message, "%99s %23s %99[^\n]", command, charname2, params2);
  8187. //z always has the value of the scan that was successful
  8188. z = ( x > 1 ) ? x : y;
  8189. //#command + name means the sufficient target was used and anything else after
  8190. //can be looked at by the actual command function since most scan to see if the
  8191. //right parameters are used.
  8192. if ( x > 2 ) {
  8193. sprintf(atcmd_msg, "%s %s", command, params);
  8194. break;
  8195. }
  8196. else if ( y > 2 ) {
  8197. sprintf(atcmd_msg, "%s %s", command, params2);
  8198. break;
  8199. }
  8200. //Regardless of what style the #command is used, if it's correct, it will always have
  8201. //this value if there is no parameter. Send it as just the #command
  8202. else if ( z == 2 ) {
  8203. sprintf(atcmd_msg, "%s", command);
  8204. break;
  8205. }
  8206. if( !pc_get_group_level(sd) ) {
  8207. if( x >= 1 || y >= 1 ) { /* we have command */
  8208. info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  8209. 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 */
  8210. return false;
  8211. } else
  8212. return false;/* display as normal message */
  8213. }
  8214. sprintf(output, msg_txt(sd,1388), charcommand_symbol); // Charcommand failed (usage: %c<command> <char name> <parameters>).
  8215. clif_displaymessage(fd, output);
  8216. return true;
  8217. } while(0);
  8218. }
  8219. else if (*message == atcommand_symbol) {
  8220. //atcmd_msg is constructed above differently for charcommands
  8221. //it's copied from message if not a charcommand so it can
  8222. //pass through the rest of the code compatible with both symbols
  8223. sprintf(atcmd_msg, "%s", message);
  8224. }
  8225. //Clearing these to be used once more.
  8226. memset(command, '\0', sizeof(command));
  8227. memset(params, '\0', sizeof(params));
  8228. //check to see if any params exist within this command
  8229. if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 )
  8230. params[0] = '\0';
  8231. // @commands (script based)
  8232. if(type == 1 && atcmd_binding_count > 0) {
  8233. struct atcmd_binding_data * binding;
  8234. // Check if the command initiated is a character command
  8235. if (*message == charcommand_symbol &&
  8236. (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  8237. sprintf(output, msg_txt(sd,1389), command); // %s failed. Player not found.
  8238. clif_displaymessage(fd, output);
  8239. return true;
  8240. }
  8241. // Get atcommand binding
  8242. binding = get_atcommandbind_byname(command);
  8243. // Check if the binding isn't NULL and there is a NPC event, level of usage met, et cetera
  8244. if( binding != NULL && binding->npc_event[0] &&
  8245. ((*atcmd_msg == atcommand_symbol && pc_get_group_level(sd) >= binding->level) ||
  8246. (*atcmd_msg == charcommand_symbol && pc_get_group_level(sd) >= binding->level2)))
  8247. {
  8248. // Check if self or character invoking; if self == character invoked, then self invoke.
  8249. bool invokeFlag = ((*atcmd_msg == atcommand_symbol) ? 1 : 0);
  8250. npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
  8251. return true;
  8252. }
  8253. }
  8254. //Grab the command information and check for the proper GM level required to use it or if the command exists
  8255. info = get_atcommandinfo_byname(atcommand_checkalias(command + 1));
  8256. if (info == NULL) {
  8257. if( pc_get_group_level(sd) ) { // TODO: remove or replace with proper permission
  8258. sprintf(output, msg_txt(sd,153), command); // "%s is Unknown Command."
  8259. clif_displaymessage(fd, output);
  8260. atcommand_get_suggestions(sd, command + 1, *message == atcommand_symbol);
  8261. return true;
  8262. } else
  8263. return false;
  8264. }
  8265. // type == 1 : player invoked
  8266. if (type == 1) {
  8267. if ((*command == atcommand_symbol && info->at_groups[sd->group_pos] == 0) ||
  8268. (*command == charcommand_symbol && info->char_groups[sd->group_pos] == 0) ) {
  8269. return false;
  8270. }
  8271. if( pc_isdead(sd) && pc_has_permission(sd,PC_PERM_DISABLE_CMD_DEAD) ) {
  8272. clif_displaymessage(fd, msg_txt(sd,1393)); // You can't use commands while dead
  8273. return true;
  8274. }
  8275. }
  8276. // Check if target is valid only if confirmed that player can use command.
  8277. if (*message == charcommand_symbol &&
  8278. (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) {
  8279. sprintf(output, msg_txt(sd,1389), command); // %s failed. Player not found.
  8280. clif_displaymessage(fd, output);
  8281. return true;
  8282. }
  8283. //Attempt to use the command
  8284. if ( (info->func(fd, (*atcmd_msg == atcommand_symbol) ? sd : ssd, command, params) != 0) )
  8285. {
  8286. sprintf(output,msg_txt(sd,154), command); // %s failed.
  8287. clif_displaymessage(fd, output);
  8288. return true;
  8289. }
  8290. //Log only if successful.
  8291. if ( *atcmd_msg == atcommand_symbol )
  8292. log_atcommand(sd, atcmd_msg);
  8293. else if ( *atcmd_msg == charcommand_symbol )
  8294. log_atcommand(sd, message);
  8295. return true;
  8296. }
  8297. /*==========================================
  8298. *
  8299. *------------------------------------------*/
  8300. static void atcommand_config_read(const char* config_filename)
  8301. {
  8302. config_setting_t *aliases = NULL, *help = NULL;
  8303. const char *symbol = NULL;
  8304. int num_aliases = 0;
  8305. if (conf_read_file(&atcommand_config, config_filename))
  8306. return;
  8307. // Command symbols
  8308. if (config_lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) {
  8309. if (ISPRINT(*symbol) && // no control characters
  8310. *symbol != '/' && // symbol of client commands
  8311. *symbol != '%' && // symbol of party chat
  8312. *symbol != '$' && // symbol of guild chat
  8313. *symbol != charcommand_symbol)
  8314. atcommand_symbol = *symbol;
  8315. }
  8316. if (config_lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) {
  8317. if (ISPRINT(*symbol) && // no control characters
  8318. *symbol != '/' && // symbol of client commands
  8319. *symbol != '%' && // symbol of party chat
  8320. *symbol != '$' && // symbol of guild chat
  8321. *symbol != atcommand_symbol)
  8322. charcommand_symbol = *symbol;
  8323. }
  8324. // Command aliases
  8325. aliases = config_lookup(&atcommand_config, "aliases");
  8326. if (aliases != NULL) {
  8327. int i = 0;
  8328. int count = config_setting_length(aliases);
  8329. for (i = 0; i < count; ++i) {
  8330. config_setting_t *command;
  8331. const char *commandname = NULL;
  8332. int j = 0, alias_count = 0;
  8333. AtCommandInfo *commandinfo = NULL;
  8334. command = config_setting_get_elem(aliases, i);
  8335. if (config_setting_type(command) != CONFIG_TYPE_ARRAY)
  8336. continue;
  8337. commandname = config_setting_name(command);
  8338. if (!atcommand_exists(commandname)) {
  8339. ShowConfigWarning(command, "atcommand_config_read: can not set alias for non-existent command %s", commandname);
  8340. continue;
  8341. }
  8342. commandinfo = get_atcommandinfo_byname(commandname);
  8343. alias_count = config_setting_length(command);
  8344. for (j = 0; j < alias_count; ++j) {
  8345. const char *alias = config_setting_get_string_elem(command, j);
  8346. if (alias != NULL) {
  8347. AliasInfo *alias_info;
  8348. if (strdb_exists(atcommand_alias_db, alias)) {
  8349. ShowConfigWarning(command, "atcommand_config_read: alias %s already exists", alias);
  8350. continue;
  8351. }
  8352. CREATE(alias_info, AliasInfo, 1);
  8353. alias_info->command = commandinfo;
  8354. safestrncpy(alias_info->alias, alias, sizeof(alias_info->alias));
  8355. strdb_put(atcommand_alias_db, alias, alias_info);
  8356. ++num_aliases;
  8357. }
  8358. }
  8359. }
  8360. }
  8361. // Commands help
  8362. // We only check if all commands exist
  8363. help = config_lookup(&atcommand_config, "help");
  8364. if (help != NULL) {
  8365. int count = config_setting_length(help);
  8366. int i;
  8367. for (i = 0; i < count; ++i) {
  8368. config_setting_t *command;
  8369. const char *commandname;
  8370. command = config_setting_get_elem(help, i);
  8371. commandname = config_setting_name(command);
  8372. if (!atcommand_exists(commandname))
  8373. ShowConfigWarning(command, "atcommand_config_read: command %s does not exist", commandname);
  8374. }
  8375. }
  8376. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename);
  8377. return;
  8378. }
  8379. void atcommand_db_load_groups(int* group_ids) {
  8380. DBIterator *iter = db_iterator(atcommand_db);
  8381. AtCommandInfo* cmd;
  8382. int i;
  8383. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8384. cmd->at_groups = aMalloc( pc_group_max * sizeof(char) );
  8385. cmd->char_groups = aMalloc( pc_group_max * sizeof(char) );
  8386. for(i = 0; i < pc_group_max; i++) {
  8387. if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_ATCOMMAND ) )
  8388. cmd->at_groups[i] = 1;
  8389. else
  8390. cmd->at_groups[i] = 0;
  8391. if( pc_group_can_use_command(group_ids[i], cmd->command, COMMAND_CHARCOMMAND ) )
  8392. cmd->char_groups[i] = 1;
  8393. else
  8394. cmd->char_groups[i] = 0;
  8395. }
  8396. }
  8397. dbi_destroy(iter);
  8398. return;
  8399. }
  8400. void atcommand_db_clear(void) {
  8401. if (atcommand_db != NULL) {
  8402. DBIterator *iter = db_iterator(atcommand_db);
  8403. AtCommandInfo* cmd;
  8404. for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
  8405. aFree(cmd->at_groups);
  8406. aFree(cmd->char_groups);
  8407. }
  8408. dbi_destroy(iter);
  8409. db_destroy(atcommand_db);
  8410. }
  8411. if (atcommand_alias_db != NULL)
  8412. db_destroy(atcommand_alias_db);
  8413. config_destroy(&atcommand_config);
  8414. }
  8415. void atcommand_doload(void) {
  8416. atcommand_db_clear();
  8417. atcommand_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  8418. atcommand_alias_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH);
  8419. atcommand_basecommands(); //fills initial atcommand_db with known commands
  8420. atcommand_config_read(ATCOMMAND_CONF_FILENAME);
  8421. }
  8422. void do_init_atcommand(void) {
  8423. atcommand_doload();
  8424. }
  8425. void do_final_atcommand(void) {
  8426. atcommand_db_clear();
  8427. }