cmds.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206
  1. /*
  2. * cmds.c -- handles:
  3. * commands from a user via dcc
  4. * (split in 3, this portion contains no-irc commands)
  5. *
  6. */
  7. #include "main.h"
  8. #include "tandem.h"
  9. #include "modules.h"
  10. #include "help.h"
  11. #include "bg.h"
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <pwd.h>
  15. #include <sys/types.h>
  16. #ifdef HAVE_UNAME
  17. #include <sys/utsname.h>
  18. #endif
  19. extern struct chanset_t *chanset;
  20. extern struct dcc_t *dcc;
  21. extern struct userrec *userlist;
  22. extern tcl_timer_t *timer, *utimer;
  23. extern int dcc_total, remote_boots, backgrd,
  24. do_restart, conmask, must_be_owner,
  25. strict_host, quiet_save, cfg_count,
  26. server_lag, egg_numver, localhub;
  27. extern unsigned long otraffic_irc, otraffic_irc_today,
  28. itraffic_irc, itraffic_irc_today,
  29. otraffic_bn, otraffic_bn_today,
  30. itraffic_bn, itraffic_bn_today,
  31. otraffic_dcc, otraffic_dcc_today,
  32. itraffic_dcc, itraffic_dcc_today,
  33. otraffic_trans, otraffic_trans_today,
  34. itraffic_trans, itraffic_trans_today,
  35. otraffic_unknown, otraffic_unknown_today,
  36. itraffic_unknown, itraffic_unknown_today;
  37. extern Tcl_Interp *interp;
  38. extern char botnetnick[], origbotname[], ver[], network[],
  39. owner[], quit_msg[], dcc_prefix[], pid_file[],
  40. botname[], *binname, version[], egg_version[];
  41. extern time_t now, online_since, buildts;
  42. extern module_entry *module_list;
  43. extern struct cfg_entry CFG_MOTD, **cfg;
  44. extern tand_t *tandbot;
  45. static char *btos(unsigned long);
  46. mycmds cmds[500]; //the list of dcc cmds for help system
  47. int cmdi = 0;
  48. #ifdef HUB
  49. static void tell_who(struct userrec *u, int idx, int chan)
  50. {
  51. int i, k, ok = 0, atr = u ? u->flags : 0;
  52. int nicklen;
  53. char format[81];
  54. char s[1024]; /* temp fix - 1.4 has a better one */
  55. if (!chan)
  56. dprintf(idx, "%s (* = %s, + = %s, @ = %s)\n",
  57. BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
  58. else {
  59. simple_sprintf(s, "assoc %d", chan);
  60. if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
  61. dprintf(idx, "%s %s%d: (* = %s, + = %s, @ = %s)\n",
  62. BOT_PEOPLEONCHAN,
  63. (chan < GLOBAL_CHANS) ? "" : "*",
  64. chan % GLOBAL_CHANS,
  65. MISC_OWNER, MISC_MASTER, MISC_OP);
  66. else
  67. dprintf(idx, "%s '%s' (%s%d): (* = %s, + = %s, @ = %s)\n",
  68. BOT_PEOPLEONCHAN, interp->result,
  69. (chan < GLOBAL_CHANS) ? "" : "*",
  70. chan % GLOBAL_CHANS,
  71. MISC_OWNER, MISC_MASTER, MISC_OP);
  72. }
  73. /* calculate max nicklen */
  74. nicklen = 0;
  75. for (i = 0; i < dcc_total; i++) {
  76. if(strlen(dcc[i].nick) > nicklen)
  77. nicklen = strlen(dcc[i].nick);
  78. }
  79. if(nicklen < 9) nicklen = 9;
  80. for (i = 0; i < dcc_total; i++)
  81. if (dcc[i].type == &DCC_CHAT)
  82. if (dcc[i].u.chat->channel == chan) {
  83. if (atr & USER_OWNER) {
  84. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us %%s", nicklen);
  85. sprintf(s, format,
  86. dcc[i].sock, (geticon(i) == '-' ? ' ' : geticon(i)),
  87. dcc[i].nick, dcc[i].host);
  88. } else {
  89. egg_snprintf(format, sizeof format, " %%c%%-%us %%s", nicklen);
  90. sprintf(s, format,
  91. (geticon(i) == '-' ? ' ' : geticon(i)),
  92. dcc[i].nick, dcc[i].host);
  93. }
  94. if (atr & USER_MASTER) {
  95. if (dcc[i].u.chat->con_flags)
  96. sprintf(&s[strlen(s)], " (con:%s)",
  97. masktype(dcc[i].u.chat->con_flags));
  98. }
  99. if (now - dcc[i].timeval > 300) {
  100. unsigned long days, hrs, mins;
  101. days = (now - dcc[i].timeval) / 86400;
  102. hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
  103. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  104. if (days > 0)
  105. sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
  106. else if (hrs > 0)
  107. sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
  108. else
  109. sprintf(&s[strlen(s)], " (idle %lum)", mins);
  110. }
  111. dprintf(idx, "%s\n", s);
  112. if (dcc[i].u.chat->away != NULL)
  113. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  114. }
  115. for (i = 0; i < dcc_total; i++)
  116. if (dcc[i].type == &DCC_BOT) {
  117. if (!ok) {
  118. ok = 1;
  119. dprintf(idx, STR("Bots connected:\n"));
  120. }
  121. #ifdef S_UTCTIME
  122. egg_strftime(s, 14, "%d %b %H:%M %Z", gmtime(&dcc[i].timeval));
  123. #else /* !S_UTCTIME */
  124. egg_strftime(s, 14, "%d %b %H:%M %Z", localtime(&dcc[i].timeval));
  125. #endif /* S_UTCTIME */
  126. if (atr & USER_OWNER) {
  127. egg_snprintf(format, sizeof format, " [%%.2lu] %%s%%c%%-%us (%%s) %%s\n",
  128. nicklen);
  129. dprintf(idx, format,
  130. dcc[i].sock, dcc[i].status & STAT_CALLED ? "<-" : "->",
  131. dcc[i].status & STAT_SHARE ? '+' : ' ',
  132. dcc[i].nick, s, dcc[i].u.bot->version);
  133. } else {
  134. egg_snprintf(format, sizeof format, " %%s%%c%%-%us (%%s) %%s\n", nicklen);
  135. dprintf(idx, format,
  136. dcc[i].status & STAT_CALLED ? "<-" : "->",
  137. dcc[i].status & STAT_SHARE ? '+' : ' ',
  138. dcc[i].nick, s, dcc[i].u.bot->version);
  139. }
  140. }
  141. ok = 0;
  142. for (i = 0; i < dcc_total; i++) {
  143. if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
  144. if (!ok) {
  145. ok = 1;
  146. dprintf(idx, STR("Other people on the bot:\n"));
  147. }
  148. if (atr & USER_OWNER) {
  149. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us ", nicklen);
  150. sprintf(s, format, dcc[i].sock,
  151. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  152. } else {
  153. egg_snprintf(format, sizeof format, " %%c%%-%us ", nicklen);
  154. sprintf(s, format,
  155. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  156. }
  157. if (atr & USER_MASTER) {
  158. if (dcc[i].u.chat->channel < 0)
  159. strcat(s, "(-OFF-) ");
  160. else if (!dcc[i].u.chat->channel)
  161. strcat(s, "(party) ");
  162. else
  163. sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
  164. }
  165. strcat(s, dcc[i].host);
  166. if (atr & USER_MASTER) {
  167. if (dcc[i].u.chat->con_flags)
  168. sprintf(&s[strlen(s)], " (con:%s)",
  169. masktype(dcc[i].u.chat->con_flags));
  170. }
  171. if (now - dcc[i].timeval > 300) {
  172. k = (now - dcc[i].timeval) / 60;
  173. if (k < 60)
  174. sprintf(&s[strlen(s)], " (idle %dm)", k);
  175. else
  176. sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
  177. }
  178. dprintf(idx, "%s\n", s);
  179. if (dcc[i].u.chat->away != NULL)
  180. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  181. }
  182. if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
  183. (dcc[i].type != &DCC_CHAT)) {
  184. if (!ok) {
  185. ok = 1;
  186. dprintf(idx, STR("Other people on the bot:\n"));
  187. }
  188. if (atr & USER_OWNER) {
  189. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us (files) %%s",
  190. nicklen);
  191. sprintf(s, format,
  192. dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
  193. dcc[i].nick, dcc[i].host);
  194. } else {
  195. egg_snprintf(format, sizeof format, " %%c%%-%us (files) %%s", nicklen);
  196. sprintf(s, format,
  197. dcc[i].status & STAT_CHAT ? '+' : ' ',
  198. dcc[i].nick, dcc[i].host);
  199. }
  200. dprintf(idx, "%s\n", s);
  201. }
  202. }
  203. }
  204. static void cmd_botinfo(struct userrec *u, int idx, char *par)
  205. {
  206. char s[512], s2[32];
  207. struct chanset_t *chan;
  208. time_t now2;
  209. int hr, min;
  210. putlog(LOG_CMDS, "*", STR("#%s# botinfo"), dcc[idx].nick);
  211. now2 = now - online_since;
  212. s2[0] = 0;
  213. if (now2 > 86400) {
  214. int days = now2 / 86400;
  215. /* Days */
  216. sprintf(s2, "%d day", days);
  217. if (days >= 2)
  218. strcat(s2, "s");
  219. strcat(s2, ", ");
  220. now2 -= days * 86400;
  221. }
  222. hr = (time_t) ((int) now2 / 3600);
  223. now2 -= (hr * 3600);
  224. min = (time_t) ((int) now2 / 60);
  225. sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
  226. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  227. botnet_send_infoq(-1, s);
  228. s[0] = 0;
  229. if (module_find("server", 0, 0)) {
  230. for (chan = chanset; chan; chan = chan->next) {
  231. if (!channel_secret(chan)) {
  232. if ((strlen(s) + strlen(chan->dname) + strlen(network)
  233. + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
  234. strcat(s,"++ ");
  235. break; /* yeesh! */
  236. }
  237. strcat(s, chan->dname);
  238. strcat(s, ", ");
  239. }
  240. }
  241. if (s[0]) {
  242. s[strlen(s) - 2] = 0;
  243. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  244. ver, network, s, s2);
  245. } else
  246. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  247. ver, network, BOT_NOCHANNELS, s2);
  248. } else
  249. dprintf(idx, STR("*** [%s] %s <NO_IRC> [UP %s]\n"), botnetnick, ver, s2);
  250. }
  251. #endif /* HUB */
  252. static void cmd_whom(struct userrec *u, int idx, char *par)
  253. {
  254. if (par[0] == '*') {
  255. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  256. answer_local_whom(idx, -1);
  257. return;
  258. } else if (dcc[idx].u.chat->channel < 0) {
  259. dprintf(idx, STR("You have chat turned off.\n"));
  260. return;
  261. }
  262. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  263. if (!par[0]) {
  264. answer_local_whom(idx, dcc[idx].u.chat->channel);
  265. } else {
  266. int chan = -1;
  267. if ((par[0] < '0') || (par[0] > '9')) {
  268. Tcl_SetVar(interp, "chan", par, 0);
  269. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  270. interp->result[0]) {
  271. chan = atoi(interp->result);
  272. }
  273. if (chan <= 0) {
  274. dprintf(idx, STR("No such channel exists.\n"));
  275. return;
  276. }
  277. } else
  278. chan = atoi(par);
  279. if ((chan < 0) || (chan > 99999)) {
  280. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  281. return;
  282. }
  283. answer_local_whom(idx, chan);
  284. }
  285. }
  286. #ifdef HUB
  287. static void cmd_config(struct userrec *u, int idx, char *par)
  288. {
  289. /*
  290. .config
  291. Usage + available entry list
  292. .config name
  293. Show current value + description
  294. .config name value
  295. Set
  296. */
  297. char *name;
  298. struct cfg_entry *cfgent = NULL;
  299. int cnt, i;
  300. putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
  301. if (!par[0]) {
  302. char *outbuf = nmalloc(1);
  303. outbuf[0] = 0;
  304. dprintf(idx, STR("Usage: config [name [value|-]]\n"));
  305. dprintf(idx, STR("Defined config entry names:\n"));
  306. cnt = 0;
  307. for (i = 0; i < cfg_count; i++) {
  308. if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->describe)) {
  309. if (!cnt) {
  310. outbuf = nrealloc(outbuf, 2 + 1);
  311. sprintf(outbuf, " ");
  312. }
  313. outbuf = nrealloc(outbuf, strlen(outbuf) + strlen(cfg[i]->name) + 1 + 1);
  314. sprintf(outbuf, STR("%s%s "), outbuf, cfg[i]->name);
  315. cnt++;
  316. if (cnt == 10) {
  317. dprintf(idx, "%s\n", outbuf);
  318. cnt = 0;
  319. }
  320. }
  321. }
  322. if (cnt)
  323. dprintf(idx, "%s\n", outbuf);
  324. if (outbuf)
  325. nfree(outbuf);
  326. return;
  327. }
  328. name = newsplit(&par);
  329. for (i = 0; !cfgent && (i < cfg_count); i++)
  330. if (!strcmp(cfg[i]->name, name))
  331. cfgent=cfg[i];
  332. if (!cfgent || !cfgent->describe) {
  333. dprintf(idx, STR("No such config entry\n"));
  334. return;
  335. }
  336. if (!par[0]) {
  337. cfgent->describe(cfgent, idx);
  338. if (!cfgent->gdata)
  339. dprintf(idx, STR("No current value\n"));
  340. else {
  341. dprintf(idx, STR("Currently: %s\n"), cfgent->gdata);
  342. }
  343. return;
  344. }
  345. if (strlen(par) >= 2048) {
  346. dprintf(idx, STR("Value can't be longer than 2048 chars"));
  347. return;
  348. }
  349. set_cfg_str(NULL, cfgent->name, par);
  350. if (!cfgent->gdata)
  351. dprintf(idx, STR("Now: (not set)\n"));
  352. else {
  353. dprintf(idx, STR("Now: %s\n"), cfgent->gdata);
  354. }
  355. #ifdef HUB
  356. write_userfile(idx);
  357. #endif /* HUB */
  358. }
  359. static void cmd_botconfig(struct userrec *u, int idx, char *par)
  360. {
  361. struct userrec *u2;
  362. char *p;
  363. struct xtra_key *k;
  364. struct cfg_entry *cfgent;
  365. int i, cnt;
  366. /* botconfig bot [name [value]] */
  367. putlog(LOG_CMDS, "*", STR("#%s# botconfig %s"), dcc[idx].nick, par);
  368. if (!par[0]) {
  369. dprintf(idx, STR("Usage: botconfig bot [name [value|-]]\n"));
  370. cnt=0;
  371. for (i=0; i < cfg_count; i++) {
  372. if (cfg[i]->flags & CFGF_LOCAL) {
  373. dprintf(idx, STR("%s "), cfg[i]->name);
  374. cnt++;
  375. if (cnt == 10) {
  376. dprintf(idx, "\n");
  377. cnt=0;
  378. }
  379. }
  380. }
  381. if (cnt > 0)
  382. dprintf(idx, "\n");
  383. return;
  384. }
  385. p = newsplit(&par);
  386. u2 = get_user_by_handle(userlist, p);
  387. if (!u2) {
  388. dprintf(idx, STR("No such user.\n"));
  389. return;
  390. }
  391. if (!(u2->flags & USER_BOT)) {
  392. dprintf(idx, STR("%s isn't a bot.\n"), p);
  393. return;
  394. }
  395. if (!par[0]) {
  396. for (i = 0; i < cfg_count; i++) {
  397. if ((cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe)) {
  398. k = get_user(&USERENTRY_CONFIG, u2);
  399. while (k && strcmp(k->key, cfg[i]->name))
  400. k=k->next;
  401. if (k)
  402. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  403. else
  404. dprintf(idx, STR(" %s: (not set)\n"), cfg[i]->name);
  405. }
  406. }
  407. return;
  408. }
  409. p = newsplit(&par);
  410. cfgent=NULL;
  411. for (i = 0; !cfgent && (i < cfg_count); i++)
  412. if (!strcmp(cfg[i]->name, p) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
  413. cfgent=cfg[i];
  414. if (!cfgent) {
  415. dprintf(idx, STR("No such configuration value\n"));
  416. return;
  417. }
  418. if (par[0]) {
  419. char tmp[100];
  420. set_cfg_str(u2->handle, cfgent->name, (strcmp(par, "-")) ? par : NULL);
  421. egg_snprintf(tmp, sizeof tmp, "%s %s", cfgent->name, par);
  422. update_mod(u2->handle, dcc[idx].nick, "botconfig", tmp);
  423. dprintf(idx, STR("Now: "));
  424. #ifdef HUB
  425. write_userfile(idx);
  426. #endif /* HUB */
  427. } else {
  428. if (cfgent->describe)
  429. cfgent->describe(cfgent, idx);
  430. }
  431. k = get_user(&USERENTRY_CONFIG, u2);
  432. while (k && strcmp(k->key, cfgent->name))
  433. k = k->next;
  434. if (k)
  435. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  436. else
  437. dprintf(idx, STR(" %s: (not set)\n"), cfgent->name);
  438. }
  439. #ifdef S_DCCPASS
  440. static void cmd_cmdpass(struct userrec *u, int idx, char *par)
  441. {
  442. struct tcl_bind_mask_b *hm;
  443. char *cmd = NULL, *pass = NULL;
  444. int i, l = 0;
  445. /* cmdpass [command [newpass]] */
  446. cmd = newsplit(&par);
  447. putlog(LOG_CMDS, "*", STR("#%s# cmdpass %s ..."), dcc[idx].nick, cmd[0] ? cmd : "");
  448. pass = newsplit(&par);
  449. if (!cmd[0] || par[0]) {
  450. dprintf(idx, STR("Usage: %scmdpass <command> [password]\n"), dcc_prefix);
  451. dprintf(idx, STR(" if no password is specified, the commands password is reset\n"));
  452. return;
  453. }
  454. for (i = 0; cmd[i]; i++)
  455. cmd[i] = tolower(cmd[i]);
  456. if (!egg_strcasecmp(cmd, "op")) l++;
  457. else if (!egg_strcasecmp(cmd, "act")) l++;
  458. else if (!egg_strcasecmp(cmd, "adduser")) l++;
  459. else if (!egg_strcasecmp(cmd, "channel")) l++;
  460. else if (!egg_strcasecmp(cmd, "deluser")) l++;
  461. else if (!egg_strcasecmp(cmd, "deop")) l++;
  462. else if (!egg_strcasecmp(cmd, "devoice")) l++;
  463. else if (!egg_strcasecmp(cmd, "getkey")) l++;
  464. else if (!egg_strcasecmp(cmd, "find")) l++;
  465. else if (!egg_strcasecmp(cmd, "invite")) l++;
  466. else if (!egg_strcasecmp(cmd, "kick")) l++;
  467. else if (!egg_strcasecmp(cmd, "kickban")) l++;
  468. else if (!egg_strcasecmp(cmd, "mdop")) l++;
  469. else if (!egg_strcasecmp(cmd, "msg")) l++;
  470. else if (!egg_strcasecmp(cmd, "reset")) l++;
  471. else if (!egg_strcasecmp(cmd, "resetbans")) l++;
  472. else if (!egg_strcasecmp(cmd, "resetexempts")) l++;
  473. else if (!egg_strcasecmp(cmd, "resetinvites")) l++;
  474. else if (!egg_strcasecmp(cmd, "say")) l++;
  475. else if (!egg_strcasecmp(cmd, "topic")) l++;
  476. else if (!egg_strcasecmp(cmd, "voice")) l++;
  477. else if (!egg_strcasecmp(cmd, "clearqueue")) l++;
  478. else if (!egg_strcasecmp(cmd, "dump")) l++;
  479. else if (!egg_strcasecmp(cmd, "jump")) l++;
  480. else if (!egg_strcasecmp(cmd, "servers")) l++;
  481. else if (!egg_strcasecmp(cmd, "authed")) l++;
  482. if (!l) {
  483. for (hm = H_dcc->first; hm; hm = hm->next)
  484. if (!egg_strcasecmp(cmd, hm->mask))
  485. break;
  486. if (!hm) {
  487. dprintf(idx, STR("No such DCC command\n"));
  488. return;
  489. }
  490. }
  491. if (pass[0]) {
  492. char epass[36], tmp[256];
  493. if (!isowner(u->handle) && has_cmd_pass(cmd)) {
  494. putlog(LOG_MISC, "*", STR("%s attempted to change command password for %s - not perm owner"), dcc[idx].nick, cmd);
  495. dprintf(idx, STR("Perm owners only.\n"));
  496. return;
  497. }
  498. encrypt_pass(pass, epass);
  499. sprintf(tmp, STR("%s %s"), cmd, epass);
  500. if (has_cmd_pass(cmd))
  501. dprintf(idx, STR("Changed command password for %s\n"), cmd);
  502. else
  503. dprintf(idx, STR("Set command password for %s to '%s'\n"), cmd, pass);
  504. set_cmd_pass(tmp, 1);
  505. } else {
  506. if (!isowner(u->handle)) {
  507. putlog(LOG_MISC, "*", STR("%s attempted to remove command password for %s - not perm owner"), dcc[idx].nick, cmd);
  508. dprintf(idx, STR("Perm owners only.\n"));
  509. return;
  510. }
  511. set_cmd_pass(cmd, 1);
  512. dprintf(idx, STR("Removed command password for %s\n"), cmd);
  513. }
  514. #ifdef HUB
  515. write_userfile(idx);
  516. #endif /* HUB */
  517. }
  518. #endif /* S_DCCPASS */
  519. static void cmd_lagged(struct userrec *u, int idx, char *par)
  520. {
  521. /* Lists botnet lag to *directly connected* bots */
  522. int i;
  523. putlog(LOG_CMDS, "*", STR("#%s# lagged %s"), u->handle, par);
  524. for (i = 0; i < dcc_total; i++) {
  525. if (dcc[i].type == &DCC_BOT) {
  526. dprintf(idx, STR("%9s - %i seconds\n"), dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
  527. }
  528. }
  529. }
  530. #endif /* HUB */
  531. static void cmd_me(struct userrec *u, int idx, char *par)
  532. {
  533. int i;
  534. if (dcc[idx].u.chat->channel < 0) {
  535. dprintf(idx, STR("You have chat turned off.\n"));
  536. return;
  537. }
  538. if (!par[0]) {
  539. dprintf(idx, STR("Usage: me <action>\n"));
  540. return;
  541. }
  542. if (dcc[idx].u.chat->away != NULL)
  543. not_away(idx);
  544. for (i = 0; i < dcc_total; i++)
  545. if ((dcc[i].type->flags & DCT_CHAT) &&
  546. (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
  547. ((i != idx) || (dcc[i].status & STAT_ECHO)))
  548. dprintf(i, "* %s %s\n", dcc[idx].nick, par);
  549. botnet_send_act(idx, botnetnick, dcc[idx].nick,
  550. dcc[idx].u.chat->channel, par);
  551. check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
  552. }
  553. static void cmd_motd(struct userrec *u, int idx, char *par)
  554. {
  555. putlog(LOG_CMDS, "*", STR("#%s# motd %s"), dcc[idx].nick, par);
  556. if (par[0] && (u->flags & USER_MASTER)) {
  557. char *s;
  558. s = nmalloc(strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
  559. sprintf(s, STR("%s %lu %s"), dcc[idx].nick, now, par);
  560. set_cfg_str(NULL, "motd", s);
  561. nfree(s);
  562. dprintf(idx, STR("Motd set\n"));
  563. #ifdef HUB
  564. write_userfile(idx);
  565. #endif /* HUB */
  566. } else {
  567. show_motd(idx);
  568. }
  569. }
  570. static void cmd_about(struct userrec *u, int idx, char *par)
  571. {
  572. char c[80];
  573. putlog(LOG_CMDS, "*", STR("#%s# about"), dcc[idx].nick);
  574. dprintf(idx, STR("Wraith botpack by bryan\n"));
  575. egg_strftime(c, sizeof c, "%c %Z", gmtime(&buildts));
  576. dprintf(idx, STR("Version: %s (%d) \n"), egg_version, egg_numver);
  577. dprintf(idx, STR("Build: %s (%lu)\n"), c, buildts);
  578. dprintf(idx, STR("(written from a base of Eggdrop 1.6.12)\n"));
  579. dprintf(idx, STR("..with credits and thanks to the following:\n"));
  580. dprintf(idx, STR(" \n"));
  581. dprintf(idx, STR(" * Eggdrop team for developing such a great bot to code off of.\n"));
  582. dprintf(idx, STR(" * $bEinride$b and $bievil$b for taking eggdrop1.4.3 and making their very effecient botpack Ghost.\n"));
  583. dprintf(idx, STR(" * $bryguy$b for beta testing, providing code, finding bugs, and providing input.\n"));
  584. dprintf(idx, STR(" * $bSFC$b for providing compile shells, continuous input, feature suggestions, and testing.\n"));
  585. dprintf(idx, STR(" * $bxmage$b for beta testing.\n"));
  586. dprintf(idx, STR(" * $bpasswd$b for beta testing, and his dedication to finding bugs.\n"));
  587. dprintf(idx, STR(" * $bpgpkeys$b for finding bugs, and providing input.\n"));
  588. dprintf(idx, STR(" * $bqFox$b for providing an mIRC $md5() alias, not requiring a dll or >6.03\n"));
  589. dprintf(idx, STR(" * $bSith_Lord$b helping test ipv6 on the bot (admin@elitepackets.com)\n"));
  590. dprintf(idx, STR(" * $bExcelsior$b for finding a bug on BSD with the ipv6, and for celdrop which inspired many features.\n"));
  591. dprintf(idx, STR(" * $bsyt$b for giving me inspiration to code a more secure bot.\n"));
  592. dprintf(idx, STR(" * $Blackjac$b for helping with the bx auth script with his Sentinel script.\n"));
  593. dprintf(idx, STR(" * $bMystikal$b for various bugs\n"));
  594. dprintf(idx, STR(" \n"));
  595. dprintf(idx, STR("The following botpacks gave me inspiration and ideas (no code):\n"));
  596. dprintf(idx, STR(" * $uawptic$u by $blordoptic$b\n"));
  597. dprintf(idx, STR(" * $uoptikz$u by $bryguy$b and $blordoptic$b\n"));
  598. dprintf(idx, STR(" * $uceldrop$u by $bexcelsior$b\n"));
  599. dprintf(idx, STR(" * $ugenocide$u by $Crazi$b, $bDor$b, $bpsychoid$b, and $bAce24$b\n"));
  600. dprintf(idx, STR(" * $utfbot$u by $bwarknite$b and $bloslinux$b\n"));
  601. }
  602. static void cmd_away(struct userrec *u, int idx, char *par)
  603. {
  604. if (strlen(par) > 60)
  605. par[60] = 0;
  606. set_away(idx, par);
  607. }
  608. static void cmd_back(struct userrec *u, int idx, char *par)
  609. {
  610. not_away(idx);
  611. }
  612. static void cmd_newpass(struct userrec *u, int idx, char *par)
  613. {
  614. char *new, pass[16];
  615. putlog(LOG_CMDS, "*", STR("#%s# newpass..."), dcc[idx].nick);
  616. if (!par[0]) {
  617. dprintf(idx, STR("Usage: newpass <newpassword>\n"));
  618. return;
  619. }
  620. new = newsplit(&par);
  621. if (!strcmp(new, "rand")) {
  622. make_rand_str(pass, 15);
  623. } else {
  624. if (strlen(new) < 6) {
  625. dprintf(idx, STR("Please use at least 6 characters.\n"));
  626. return;
  627. } else {
  628. sprintf(pass, "%s", new);
  629. }
  630. }
  631. if (strlen(pass) > 15)
  632. pass[15] = 0;
  633. if (!goodpass(pass, idx, NULL))
  634. return;
  635. set_user(&USERENTRY_PASS, u, pass);
  636. dprintf(idx, STR("Changed your password to: %s\n"), pass);
  637. #ifdef HUB
  638. write_userfile(idx);
  639. #endif /* HUB */
  640. }
  641. static void cmd_secpass(struct userrec *u, int idx, char *par)
  642. {
  643. char *new, pass[16];
  644. putlog(LOG_CMDS, "*", STR("#%s# secpass..."), dcc[idx].nick);
  645. if (!par[0]) {
  646. dprintf(idx, STR("Usage: secpass <newsecpass>\nIf you use \"rand\" as the secpass, a random pass will be chosen.\n"));
  647. return;
  648. }
  649. new = newsplit(&par);
  650. if (!strcmp(new, "rand")) {
  651. make_rand_str(pass, 15);
  652. } else {
  653. if (strlen(new) < 6) {
  654. dprintf(idx, STR("Please use at least 6 characters.\n"));
  655. return;
  656. } else {
  657. sprintf(pass, "%s", new);
  658. }
  659. }
  660. if (strlen(pass) > 15)
  661. pass[15] = 0;
  662. set_user(&USERENTRY_SECPASS, u, pass);
  663. dprintf(idx, STR("Changed your secpass to: %s.\n"), pass);
  664. #ifdef HUB
  665. write_userfile(idx);
  666. #endif /* HUB */
  667. }
  668. #ifdef HUB
  669. static void cmd_bots(struct userrec *u, int idx, char *par)
  670. {
  671. putlog(LOG_CMDS, "*", STR("#%s# bots"), dcc[idx].nick);
  672. tell_bots(idx);
  673. }
  674. static void cmd_downbots(struct userrec *u, int idx, char *par)
  675. {
  676. struct userrec *u2;
  677. int cnt = 0, tot = 0;
  678. char work[128] = "";
  679. putlog(LOG_CMDS, "*", STR("#%s# downbots"), dcc[idx].nick);
  680. for (u2 = userlist; u2; u2 = u2->next) {
  681. if (u2->flags & USER_BOT) {
  682. if (egg_strcasecmp(u2->handle, botnetnick)) {
  683. if (nextbot(u2->handle) == -1) {
  684. strcat(work, u2->handle);
  685. cnt++;
  686. tot++;
  687. if (cnt == 10) {
  688. dprintf(idx, STR("Down bots: %s\n"), work);
  689. work[0] = 0;
  690. cnt = 0;
  691. } else
  692. strcat(work, " ");
  693. }
  694. }
  695. }
  696. }
  697. if (work[0])
  698. dprintf(idx, STR("Down bots: %s\n"), work);
  699. dprintf(idx, STR("(Total down: %d)\n"), tot);
  700. }
  701. static void cmd_bottree(struct userrec *u, int idx, char *par)
  702. {
  703. putlog(LOG_CMDS, "*", STR("#%s# bottree"), dcc[idx].nick);
  704. tell_bottree(idx, 0);
  705. }
  706. static void cmd_vbottree(struct userrec *u, int idx, char *par)
  707. {
  708. putlog(LOG_CMDS, "*", STR("#%s# vbottree"), dcc[idx].nick);
  709. tell_bottree(idx, 1);
  710. }
  711. #endif /* HUB */
  712. int my_cmp (const mycmds *c1, const mycmds *c2)
  713. {
  714. return strcmp (c1->name, c2->name);
  715. }
  716. static void cmd_nohelp(struct userrec *u, int idx, char *par)
  717. {
  718. int i;
  719. char *buf = nmalloc(1);
  720. buf[0] = 0;
  721. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  722. for (i = 0; i < cmdi; i++) {
  723. int o, found = 0;
  724. for (o = 0; (help[o].cmd) && (help[o].desc); o++)
  725. if (!egg_strcasecmp(help[o].cmd, cmds[i].name)) found++;
  726. if (!found) {
  727. buf = nrealloc(buf, strlen(buf) + 2 + strlen(cmds[i].name) + 1);
  728. strcat(buf, cmds[i].name);
  729. strcat(buf, ", ");
  730. }
  731. }
  732. buf[strlen(buf) - 1] = 0;
  733. dumplots(idx, "", buf);
  734. }
  735. static void cmd_help(struct userrec *u, int idx, char *par)
  736. {
  737. char flg[100];
  738. int fnd = 0, done = 0, nowild = 0;
  739. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  740. char *fcats, temp[100], buf[2046], match[20];
  741. egg_snprintf(temp, sizeof temp, "a|- a|a n|- n|n m|- m|m mo|o m|o i|- o|o o|- p|- -|-");
  742. fcats = temp;
  743. putlog(LOG_CMDS, "*", STR("#%s# help %s"), dcc[idx].nick, par);
  744. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  745. build_flags(flg, &fr, NULL);
  746. if (!par[0]) {
  747. sprintf(match, "*");
  748. } else {
  749. if (!strchr(par, '*') && !strchr(par, '?'))
  750. nowild++;
  751. sprintf(match, "%s", newsplit(&par));
  752. }
  753. if (!nowild)
  754. dprintf(idx, STR("Showing help topics matching '%s' for flags: (%s)\n"), match, flg);
  755. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  756. buf[0] = 0;
  757. /* even if we have nowild, we loop to conserve code/space */
  758. while (!done) {
  759. int i = 0, end = 0, first = 1, n, hi;
  760. char *flag;
  761. flag = newsplit(&fcats);
  762. if (!flag[0])
  763. done = 1;
  764. for (n = 0; n < cmdi; n++) { /* loop each command */
  765. if (!flagrec_ok(&cmds[n].flags, &fr) || !wild_match(match, cmds[n].name))
  766. continue;
  767. fnd++;
  768. if (nowild) {
  769. flg[0] = 0;
  770. build_flags(flg, &(cmds[n].flags), NULL);
  771. dprintf(idx, STR("Showing you help for '%s' (%s):\n"), match, flg);
  772. for (hi = 0; (help[hi].cmd) && (help[hi].desc); hi++) {
  773. if (!egg_strcasecmp(match, help[hi].cmd)) {
  774. if (help[hi].garble)
  775. showhelp(idx, &fr, degarble(help[hi].garble, help[hi].desc));
  776. else
  777. showhelp(idx, &fr, help[hi].desc);
  778. }
  779. }
  780. done = 1;
  781. break;
  782. } else {
  783. flg[0] = 0;
  784. build_flags(flg, &(cmds[n].flags), NULL);
  785. if (!strcmp(flg, flag)) {
  786. if (first) {
  787. dprintf(idx, "%s\n", buf[0] ? buf : "");
  788. dprintf(idx, STR("# DCC (%s)\n"), flag);
  789. sprintf(buf, " ");
  790. }
  791. if (end && !first) {
  792. dprintf(idx, "%s\n", buf[0] ? buf : "");
  793. /* we dumped the buf to dprintf, now start a new one... */
  794. sprintf(buf, " ");
  795. }
  796. sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmds[n].name);
  797. first = 0;
  798. end = 0;
  799. i++;
  800. }
  801. if (i >= 5) {
  802. end = 1;
  803. i = 0;
  804. }
  805. }
  806. }
  807. }
  808. if (buf && buf[0])
  809. dprintf(idx, "%s\n", buf);
  810. if (fnd)
  811. dprintf(idx, STR("--End help listing\n"));
  812. if (!strcmp(match, "*")) {
  813. dprintf(idx, STR("For individual command help, type: %shelp <command>\n"), dcc_prefix);
  814. } else if (!fnd) {
  815. dprintf(idx, STR("No match for '%s'.\n"), match);
  816. }
  817. dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to possibly see more commands.\n"), dcc_prefix);
  818. }
  819. static void cmd_addlog(struct userrec *u, int idx, char *par)
  820. {
  821. putlog(LOG_CMDS, "*", STR("#%s# addlog %s"), dcc[idx].nick, par);
  822. putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
  823. if (!par[0]) {
  824. dprintf(idx, STR("Usage: addlog <message>\n"));
  825. return;
  826. }
  827. dprintf(idx, STR("Placed entry in the log file.\n"));
  828. }
  829. #ifdef HUB
  830. static void cmd_who(struct userrec *u, int idx, char *par)
  831. {
  832. int i;
  833. if (par[0]) {
  834. if (dcc[idx].u.chat->channel < 0) {
  835. dprintf(idx, STR("You have chat turned off.\n"));
  836. return;
  837. }
  838. putlog(LOG_CMDS, "*", STR("#%s# who %s"), dcc[idx].nick, par);
  839. if (!egg_strcasecmp(par, botnetnick))
  840. tell_who(u, idx, dcc[idx].u.chat->channel);
  841. else {
  842. i = nextbot(par);
  843. if (i < 0) {
  844. dprintf(idx, STR("That bot isn't connected.\n"));
  845. } else if (dcc[idx].u.chat->channel > 99999)
  846. dprintf(idx, STR("You are on a local channel.\n"));
  847. else {
  848. char s[40];
  849. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
  850. dcc[idx].nick, botnetnick);
  851. botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
  852. }
  853. }
  854. } else {
  855. putlog(LOG_CMDS, "*", STR("#%s# who"), dcc[idx].nick);
  856. if (dcc[idx].u.chat->channel < 0)
  857. tell_who(u, idx, 0);
  858. else
  859. tell_who(u, idx, dcc[idx].u.chat->channel);
  860. }
  861. }
  862. #endif /* HUB */
  863. static void cmd_whois(struct userrec *u, int idx, char *par)
  864. {
  865. if (!par[0]) {
  866. dprintf(idx, STR("Usage: whois <handle>\n"));
  867. return;
  868. }
  869. putlog(LOG_CMDS, "*", STR("#%s# whois %s"), dcc[idx].nick, par);
  870. tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
  871. }
  872. static void cmd_match(struct userrec *u, int idx, char *par)
  873. {
  874. int start = 1, limit = 20;
  875. char *s, *s1, *chname;
  876. if (!par[0]) {
  877. dprintf(idx, STR("Usage: match <nick/host> [[skip] count]\n"));
  878. return;
  879. }
  880. putlog(LOG_CMDS, "*", STR("#%s# match %s"), dcc[idx].nick, par);
  881. s = newsplit(&par);
  882. if (strchr(CHANMETA, par[0]) != NULL)
  883. chname = newsplit(&par);
  884. else
  885. chname = "";
  886. if (atoi(par) > 0) {
  887. s1 = newsplit(&par);
  888. if (atoi(par) > 0) {
  889. start = atoi(s1);
  890. limit = atoi(par);
  891. } else
  892. limit = atoi(s1);
  893. }
  894. tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
  895. chname);
  896. }
  897. static void cmd_update(struct userrec *u, int idx, char *par)
  898. {
  899. putlog(LOG_CMDS, "*", STR("#%s# update %s"), dcc[idx].nick, par);
  900. #ifdef LEAF
  901. if (!localhub)
  902. dprintf(idx, STR("Please use this command on the first listed in the conf for this user@box\n"));
  903. #endif /* LEAF */
  904. if (!par[0])
  905. dprintf(idx, STR("Usage: update <binname>\n"));
  906. updatebin(idx, par, 0);
  907. }
  908. static void cmd_uptime(struct userrec *u, int idx, char *par)
  909. {
  910. putlog(LOG_CMDS, "*", STR("#%s# uptime"), dcc[idx].nick);
  911. tell_verbose_uptime(idx);
  912. }
  913. static void cmd_userlist(struct userrec *u, int idx, char *par)
  914. {
  915. int cnt = 0, tt = 0;
  916. putlog(LOG_CMDS, "*", STR("#%s# userlist"), dcc[idx].nick);
  917. for (u=userlist;u;u=u->next) {
  918. if ((u->flags & USER_BOT) && (u->flags & USER_CHANHUB)) {
  919. if (cnt)
  920. dprintf(idx, ", ");
  921. else
  922. dprintf(idx, STR("Chathubs: "));
  923. dprintf(idx, u->handle);
  924. cnt++;
  925. tt++;
  926. if (cnt == 15) {
  927. dprintf(idx, "\n");
  928. cnt=0;
  929. }
  930. }
  931. }
  932. if (cnt)
  933. dprintf(idx, "\n");
  934. cnt=0;
  935. #ifdef HUB
  936. for (u=userlist;u;u=u->next) {
  937. if (!(u->flags & USER_BOT) && (u->flags & USER_ADMIN)) {
  938. if (cnt)
  939. dprintf(idx, ", ");
  940. else
  941. dprintf(idx, STR("Admins : "));
  942. dprintf(idx, u->handle);
  943. cnt++;
  944. tt++;
  945. if (cnt == 15) {
  946. dprintf(idx, "\n");
  947. cnt=0;
  948. }
  949. }
  950. }
  951. if (cnt)
  952. dprintf(idx, "\n");
  953. cnt=0;
  954. for (u=userlist;u;u=u->next) {
  955. if (!(u->flags & (USER_BOT | USER_ADMIN)) && (u->flags & USER_OWNER)) {
  956. if (cnt)
  957. dprintf(idx, ", ");
  958. else
  959. dprintf(idx, STR("Owners : "));
  960. dprintf(idx, u->handle);
  961. cnt++;
  962. tt++;
  963. if (cnt == 15) {
  964. dprintf(idx, "\n");
  965. cnt=0;
  966. }
  967. }
  968. }
  969. if (cnt)
  970. dprintf(idx, "\n");
  971. cnt=0;
  972. for (u=userlist;u;u=u->next) {
  973. if (!(u->flags & (USER_BOT | USER_OWNER)) && (u->flags & USER_MASTER)) {
  974. if (cnt)
  975. dprintf(idx, ", ");
  976. else
  977. dprintf(idx, STR("Masters : "));
  978. dprintf(idx, u->handle);
  979. cnt++;
  980. tt++;
  981. if (cnt == 15) {
  982. dprintf(idx, "\n");
  983. cnt=0;
  984. }
  985. }
  986. }
  987. if (cnt)
  988. dprintf(idx, "\n");
  989. cnt=0;
  990. #endif /* HUB */
  991. for (u=userlist;u;u=u->next) {
  992. #ifdef HUB
  993. if (!(u->flags & (USER_BOT | USER_MASTER)) && (u->flags & USER_OP)) {
  994. #else /* !HUB */
  995. if (!(u->flags & USER_BOT) && (u->flags & USER_OP)) {
  996. #endif /* HUB */
  997. if (cnt)
  998. dprintf(idx, ", ");
  999. else
  1000. dprintf(idx, STR("Ops : "));
  1001. dprintf(idx, u->handle);
  1002. cnt++;
  1003. tt++;
  1004. if (cnt == 15) {
  1005. dprintf(idx, "\n");
  1006. cnt=0;
  1007. }
  1008. }
  1009. }
  1010. if (cnt)
  1011. dprintf(idx, "\n");
  1012. cnt=0;
  1013. for (u=userlist;u;u=u->next) {
  1014. if (!(u->flags & (USER_BOT | USER_OP))) {
  1015. if (cnt)
  1016. dprintf(idx, ", ");
  1017. else
  1018. dprintf(idx, STR("Users : "));
  1019. dprintf(idx, u->handle);
  1020. cnt++;
  1021. tt++;
  1022. if (cnt==15) {
  1023. dprintf(idx, "\n");
  1024. cnt=0;
  1025. }
  1026. }
  1027. }
  1028. if (cnt)
  1029. dprintf(idx, "\n");
  1030. cnt=0;
  1031. dprintf(idx, STR("Total users: %d\n"), tt);
  1032. }
  1033. static void cmd_channels(struct userrec *u, int idx, char *par) {
  1034. putlog(LOG_CMDS, "*", STR("#%s# channels %s"), dcc[idx].nick, par);
  1035. if (par[0] && (u->flags & USER_MASTER)) {
  1036. struct userrec *user;
  1037. user = get_user_by_handle(userlist, par);
  1038. if (user)
  1039. show_channels(idx, par);
  1040. else
  1041. dprintf(idx, STR("There is no user by that name.\n"));
  1042. } else
  1043. show_channels(idx, NULL);
  1044. if ((u->flags & USER_MASTER) && !(par && par[0]))
  1045. dprintf(idx, STR("You can also %schannels <user>\n"), dcc_prefix);
  1046. }
  1047. static void cmd_status(struct userrec *u, int idx, char *par)
  1048. {
  1049. int atr = u ? u->flags : 0;
  1050. if (!egg_strcasecmp(par, "all")) {
  1051. if (!(atr & USER_MASTER)) {
  1052. dprintf(idx, STR("You do not have Bot Master privileges.\n"));
  1053. return;
  1054. }
  1055. putlog(LOG_CMDS, "*", STR("#%s# status all"), dcc[idx].nick);
  1056. tell_verbose_status(idx);
  1057. tell_mem_status_dcc(idx);
  1058. dprintf(idx, "\n");
  1059. tell_settings(idx);
  1060. do_module_report(idx, 1, NULL);
  1061. } else {
  1062. putlog(LOG_CMDS, "*", STR("#%s# status"), dcc[idx].nick);
  1063. tell_verbose_status(idx);
  1064. tell_mem_status_dcc(idx);
  1065. do_module_report(idx, 0, NULL);
  1066. }
  1067. }
  1068. #ifdef HUB
  1069. static void cmd_dccstat(struct userrec *u, int idx, char *par)
  1070. {
  1071. putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
  1072. tell_dcc(idx);
  1073. }
  1074. #endif /* HUB */
  1075. static void cmd_boot(struct userrec *u, int idx, char *par)
  1076. {
  1077. int i, ok = 0;
  1078. char *who;
  1079. struct userrec *u2;
  1080. if (!par[0]) {
  1081. dprintf(idx, STR("Usage: boot nick[@bot]\n"));
  1082. return;
  1083. }
  1084. who = newsplit(&par);
  1085. if (strchr(who, '@') != NULL) {
  1086. char whonick[HANDLEN + 1];
  1087. splitcn(whonick, who, '@', HANDLEN + 1);
  1088. if (!egg_strcasecmp(who, botnetnick)) {
  1089. cmd_boot(u, idx, whonick);
  1090. return;
  1091. }
  1092. if (remote_boots > 0) {
  1093. i = nextbot(who);
  1094. if (i < 0) {
  1095. dprintf(idx, STR("No such bot connected.\n"));
  1096. return;
  1097. }
  1098. botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
  1099. who, par[0] ? par : dcc[idx].nick);
  1100. putlog(LOG_BOTS, "*", STR("#%s# boot %s@%s (%s)"), dcc[idx].nick, whonick,
  1101. who, par[0] ? par : dcc[idx].nick);
  1102. } else
  1103. dprintf(idx, STR("Remote boots are disabled here.\n"));
  1104. return;
  1105. }
  1106. for (i = 0; i < dcc_total; i++)
  1107. if (!egg_strcasecmp(dcc[i].nick, who)
  1108. && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
  1109. u2 = get_user_by_handle(userlist, dcc[i].nick);
  1110. if (u2 && (u2->flags & USER_OWNER)
  1111. && egg_strcasecmp(dcc[idx].nick, who)) {
  1112. dprintf(idx, STR("You can't boot a bot owner.\n"));
  1113. return;
  1114. }
  1115. if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
  1116. dprintf(idx, STR("You can't boot a bot master.\n"));
  1117. return;
  1118. }
  1119. dprintf(idx, STR("Booted %s from the party line.\n"), dcc[i].nick);
  1120. putlog(LOG_CMDS, "*", STR("#%s# boot %s %s"), dcc[idx].nick, who, par);
  1121. do_boot(i, dcc[idx].nick, par);
  1122. ok = 1;
  1123. }
  1124. if (!ok)
  1125. dprintf(idx, STR("Who? No such person on the party line.\n"));
  1126. }
  1127. static void cmd_console(struct userrec *u, int idx, char *par)
  1128. {
  1129. char *nick, s[2], s1[512];
  1130. int dest = 0, i, ok = 0, pls, md;
  1131. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1132. module_entry *me;
  1133. struct chanset_t *chan;
  1134. if (!par[0]) {
  1135. dprintf(idx, STR("Your console is %s: %s (%s).\n"),
  1136. dcc[idx].u.chat->con_chan,
  1137. masktype(dcc[idx].u.chat->con_flags),
  1138. maskname(dcc[idx].u.chat->con_flags));
  1139. return;
  1140. }
  1141. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  1142. strcpy(s1, par);
  1143. nick = newsplit(&par);
  1144. /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
  1145. * he doesn't use IRCnet ++rtc.
  1146. */
  1147. if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
  1148. for (i = 0; i < dcc_total; i++)
  1149. if (!egg_strcasecmp(nick, dcc[i].nick) &&
  1150. (dcc[i].type == &DCC_CHAT) && (!ok)) {
  1151. ok = 1;
  1152. dest = i;
  1153. }
  1154. if (!ok) {
  1155. dprintf(idx, STR("No such user on the party line!\n"));
  1156. return;
  1157. }
  1158. nick[0] = 0;
  1159. } else
  1160. dest = idx;
  1161. if (!nick[0])
  1162. nick = newsplit(&par);
  1163. /* Consider modeless channels, starting with '+' */
  1164. if ((nick [0] == '+' && findchan_by_dname(nick)) ||
  1165. (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
  1166. chan = findchan_by_dname(nick);
  1167. if (strcmp(nick, "*") && !chan) {
  1168. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1169. return;
  1170. }
  1171. get_user_flagrec(u, &fr, nick);
  1172. if (strcmp(nick, "*") && private(fr, findchan_by_dname(nick), PRIV_OP)) {
  1173. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1174. return;
  1175. }
  1176. if (!chk_op(fr, findchan_by_dname(nick))) {
  1177. dprintf(idx, STR("You don't have op or master access to channel %s.\n"), nick);
  1178. return;
  1179. }
  1180. strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
  1181. nick[0] = 0;
  1182. if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
  1183. /* Consoling to another channel for self */
  1184. dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
  1185. }
  1186. if (!nick[0])
  1187. nick = newsplit(&par);
  1188. pls = 1;
  1189. if (nick[0]) {
  1190. if ((nick[0] != '+') && (nick[0] != '-'))
  1191. dcc[dest].u.chat->con_flags = 0;
  1192. for (; *nick; nick++) {
  1193. if (*nick == '+')
  1194. pls = 1;
  1195. else if (*nick == '-')
  1196. pls = 0;
  1197. else {
  1198. s[0] = *nick;
  1199. s[1] = 0;
  1200. md = logmodes(s);
  1201. if ((dest == idx) && !glob_master(fr) && pls) {
  1202. if (chan_master(fr))
  1203. md &= ~(LOG_FILES | LOG_DEBUG);
  1204. else
  1205. md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_WALL |
  1206. LOG_DEBUG);
  1207. }
  1208. if (!glob_owner(fr) && pls)
  1209. md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE | LOG_ERRORS | LOG_GETIN | LOG_WARN);
  1210. if (!glob_master(fr) && pls)
  1211. md &= ~LOG_BOTS;
  1212. if (pls)
  1213. dcc[dest].u.chat->con_flags |= md;
  1214. else
  1215. dcc[dest].u.chat->con_flags &= ~md;
  1216. }
  1217. }
  1218. }
  1219. putlog(LOG_CMDS, "*", STR("#%s# console %s"), dcc[idx].nick, s1);
  1220. if (dest == idx) {
  1221. dprintf(idx, STR("Set your console to %s: %s (%s).\n"),
  1222. dcc[idx].u.chat->con_chan,
  1223. masktype(dcc[idx].u.chat->con_flags),
  1224. maskname(dcc[idx].u.chat->con_flags));
  1225. } else {
  1226. dprintf(idx, STR("Set console of %s to %s: %s (%s).\n"), dcc[dest].nick,
  1227. dcc[dest].u.chat->con_chan,
  1228. masktype(dcc[dest].u.chat->con_flags),
  1229. maskname(dcc[dest].u.chat->con_flags));
  1230. dprintf(dest, STR("%s set your console to %s: %s (%s).\n"), dcc[idx].nick,
  1231. dcc[dest].u.chat->con_chan,
  1232. masktype(dcc[dest].u.chat->con_flags),
  1233. maskname(dcc[dest].u.chat->con_flags));
  1234. }
  1235. /* New style autosave -- drummer,07/25/1999*/
  1236. if ((me = module_find("console", 0, 0))) {
  1237. Function *func = me->funcs;
  1238. (func[CONSOLE_DOSTORE]) (dest);
  1239. }
  1240. }
  1241. void test_colors(int);
  1242. static void cmd_date(struct userrec *u, int idx, char *par)
  1243. {
  1244. char date[50], utctime[50], ltime[50];
  1245. ltime[0] = utctime[0] = 0;
  1246. putlog(LOG_CMDS, "*", "#%s# date", dcc[idx].nick);
  1247. egg_strftime(date, sizeof date, "%c %Z", localtime(&now));
  1248. #ifndef S_UTCTIME
  1249. sprintf(ltime, "<-- This time is used on the bot.");
  1250. #endif /* !S_UTCTIME */
  1251. dprintf(idx, "%s %s\n", date, (ltime && ltime[0]) ? ltime : "");
  1252. egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
  1253. #ifdef S_UTCTIME
  1254. sprintf(utctime, "<-- This time is used on the bot.");
  1255. #endif /* S_UTCTIME */
  1256. dprintf(idx, "%s %s\n", date, (utctime && utctime[0]) ? utctime : "");
  1257. }
  1258. #ifdef HUB
  1259. static void cmd_chhandle(struct userrec *u, int idx, char *par)
  1260. {
  1261. char hand[HANDLEN + 1], newhand[HANDLEN + 1];
  1262. int i, atr = u ? u->flags : 0, atr2;
  1263. struct userrec *u2;
  1264. strncpyz(hand, newsplit(&par), sizeof hand);
  1265. strncpyz(newhand, newsplit(&par), sizeof newhand);
  1266. if (!hand[0] || !newhand[0]) {
  1267. dprintf(idx, STR("Usage: chhandle <oldhandle> <newhandle>\n"));
  1268. return;
  1269. }
  1270. for (i = 0; i < strlen(newhand); i++)
  1271. if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
  1272. newhand[i] = '?';
  1273. if (strchr(BADHANDCHARS, newhand[0]) != NULL)
  1274. dprintf(idx, STR("Bizarre quantum forces prevent nicknames from starting with '%c'.\n"),
  1275. newhand[0]);
  1276. else if (get_user_by_handle(userlist, newhand) &&
  1277. egg_strcasecmp(hand, newhand))
  1278. dprintf(idx, STR("Somebody is already using %s.\n"), newhand);
  1279. else {
  1280. u2 = get_user_by_handle(userlist, hand);
  1281. atr2 = u2 ? u2->flags : 0;
  1282. if (!(atr & USER_MASTER) && !(atr2 & USER_BOT))
  1283. dprintf(idx, STR("You can't change handles for non-bots.\n"));
  1284. else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
  1285. dprintf(idx, STR("You can't change share bot's nick.\n"));
  1286. else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
  1287. egg_strcasecmp(dcc[idx].nick, hand))
  1288. dprintf(idx, STR("You can't change a bot owner's handle.\n"));
  1289. else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
  1290. dprintf(idx, STR("You can't change a permanent bot owner's handle.\n"));
  1291. else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
  1292. nextbot(hand) != -1))
  1293. dprintf(idx, STR("Hey! That's MY name!\n"));
  1294. else if (change_handle(u2, newhand)) {
  1295. putlog(LOG_CMDS, "*", STR("#%s# chhandle %s %s"), dcc[idx].nick,
  1296. hand, newhand);
  1297. dprintf(idx, STR("Changed.\n"));
  1298. } else
  1299. dprintf(idx, STR("Failed.\n"));
  1300. #ifdef HUB
  1301. write_userfile(idx);
  1302. #endif /* HUB */
  1303. }
  1304. }
  1305. #endif /* HUB */
  1306. static void cmd_handle(struct userrec *u, int idx, char *par)
  1307. {
  1308. char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
  1309. int i;
  1310. strncpyz(newhandle, newsplit(&par), sizeof newhandle);
  1311. if (!newhandle[0]) {
  1312. dprintf(idx, STR("Usage: handle <new-handle>\n"));
  1313. return;
  1314. }
  1315. for (i = 0; i < strlen(newhandle); i++)
  1316. if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
  1317. newhandle[i] = '?';
  1318. if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
  1319. dprintf(idx, STR("Bizarre quantum forces prevent handle from starting with '%c'.\n"),
  1320. newhandle[0]);
  1321. } else if (get_user_by_handle(userlist, newhandle) &&
  1322. egg_strcasecmp(dcc[idx].nick, newhandle)) {
  1323. dprintf(idx, STR("Somebody is already using %s.\n"), newhandle);
  1324. } else if (!egg_strcasecmp(newhandle, botnetnick)) {
  1325. dprintf(idx, STR("Hey! That's MY name!\n"));
  1326. } else {
  1327. strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
  1328. if (change_handle(u, newhandle)) {
  1329. putlog(LOG_CMDS, "*", STR("#%s# handle %s"), oldhandle, newhandle);
  1330. dprintf(idx, STR("Okay, changed.\n"));
  1331. } else
  1332. dprintf(idx, STR("Failed.\n"));
  1333. #ifdef HUB
  1334. write_userfile(idx);
  1335. #endif /* HUB */
  1336. }
  1337. }
  1338. #ifdef HUB
  1339. static void cmd_chpass(struct userrec *u, int idx, char *par)
  1340. {
  1341. char *handle, *new, pass[16];
  1342. int atr = u ? u->flags : 0, l;
  1343. if (!par[0])
  1344. dprintf(idx, STR("Usage: chpass <handle> [password]\n"));
  1345. else {
  1346. handle = newsplit(&par);
  1347. u = get_user_by_handle(userlist, handle);
  1348. if (!u)
  1349. dprintf(idx, STR("No such user.\n"));
  1350. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1351. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1352. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1353. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1354. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1355. egg_strcasecmp(handle, dcc[idx].nick))
  1356. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1357. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1358. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1359. else if (!par[0]) {
  1360. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [nothing]"), dcc[idx].nick,
  1361. handle);
  1362. set_user(&USERENTRY_PASS, u, NULL);
  1363. dprintf(idx, STR("Removed password.\n"));
  1364. } else {
  1365. int good = 0;
  1366. l = strlen(new = newsplit(&par));
  1367. if (l > 15)
  1368. new[15] = 0;
  1369. if (!strcmp(new, "rand")) {
  1370. make_rand_str(pass, 15);
  1371. good = 1;
  1372. } else {
  1373. if (goodpass(new, idx, NULL)) {
  1374. sprintf(pass, "%s", new);
  1375. good = 1;
  1376. }
  1377. }
  1378. if (strlen(pass) > 15)
  1379. pass[15] = 0;
  1380. if (good) {
  1381. set_user(&USERENTRY_PASS, u, pass);
  1382. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick, handle);
  1383. dprintf(idx, STR("Password for '%s' changed to: %s\n"), handle, pass);
  1384. #ifdef HUB
  1385. write_userfile(idx);
  1386. #endif /* HUB */
  1387. }
  1388. }
  1389. }
  1390. }
  1391. static void cmd_chsecpass(struct userrec *u, int idx, char *par)
  1392. {
  1393. char *handle, *new, pass[16];
  1394. int atr = u ? u->flags : 0, l;
  1395. if (!par[0])
  1396. dprintf(idx, STR("Usage: chsecpass <handle> [secpass/rand]\n"));
  1397. else {
  1398. handle = newsplit(&par);
  1399. u = get_user_by_handle(userlist, handle);
  1400. if (!u)
  1401. dprintf(idx, STR("No such user.\n"));
  1402. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1403. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1404. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1405. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1406. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1407. egg_strcasecmp(handle, dcc[idx].nick))
  1408. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1409. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1410. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1411. else if (!par[0]) {
  1412. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [nothing]"), dcc[idx].nick,
  1413. handle);
  1414. set_user(&USERENTRY_SECPASS, u, NULL);
  1415. dprintf(idx, STR("Removed secpass.\n"));
  1416. } else {
  1417. l = strlen(new = newsplit(&par));
  1418. if (l > 15)
  1419. new[15] = 0;
  1420. if (!strcmp(new, "rand")) {
  1421. make_rand_str(pass, 15);
  1422. } else {
  1423. if (strlen(new) < 6) {
  1424. dprintf(idx, STR("Please use at least 6 characters.\n"));
  1425. return;
  1426. } else {
  1427. sprintf(pass, "%s", new);
  1428. }
  1429. }
  1430. if (strlen(pass) > 15)
  1431. pass[15] = 0;
  1432. set_user(&USERENTRY_SECPASS, u, pass);
  1433. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [something]"), dcc[idx].nick, handle);
  1434. dprintf(idx, STR("Secpass for '%s' changed to: %s\n"), handle, pass);
  1435. #ifdef HUB
  1436. write_userfile(idx);
  1437. #endif /* HUB */
  1438. }
  1439. }
  1440. }
  1441. static void cmd_botcmd(struct userrec *u, int idx, char *par)
  1442. {
  1443. tand_t *tbot;
  1444. int cnt = 0, rleaf = (-1), tbots = 0;
  1445. char *botm = NULL, *cmd = NULL;
  1446. botm = newsplit(&par);
  1447. cmd = newsplit(&par);
  1448. if (!botm[0] || !cmd[0]) {
  1449. dprintf(idx, STR("Usage: botcmd <bot> <cmd> [params]\n"));
  1450. return;
  1451. }
  1452. /* the rest of the cmd will be logged remotely */
  1453. putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);
  1454. if (!strcmp(botm, "*") && (!strcmp(botm, "di") || !strcmp(botm, "die"))) {
  1455. dprintf(idx, STR("Not a good idea.\n"));
  1456. return;
  1457. }
  1458. if (!strcmp(botm, "?")) {
  1459. for (tbot = tandbot; tbot; tbot = tbot->next)
  1460. if (bot_hublevel(get_user_by_handle(userlist, tbot->bot)))
  1461. tbots++;
  1462. rleaf = random() % tbots;
  1463. }
  1464. for (tbot = tandbot; tbot; tbot = tbot->next) {
  1465. if ((rleaf != (-1) && cnt == rleaf) || ((rleaf == (-1) && wild_match(botm, tbot->bot)))) {
  1466. send_remote_simul(idx, tbot->bot, cmd, par ? par : "");
  1467. }
  1468. cnt++;
  1469. }
  1470. if (!cnt) {
  1471. dprintf(idx, STR("No bot matching '%s' linked\n"), botm);
  1472. return;
  1473. }
  1474. }
  1475. static void cmd_hublevel(struct userrec *u, int idx, char *par)
  1476. {
  1477. char *handle, *level;
  1478. struct bot_addr *bi, *obi;
  1479. struct userrec *u1;
  1480. putlog(LOG_CMDS, "*", STR("#%s# hublevel %s"), dcc[idx].nick, par);
  1481. if (!par[0]) {
  1482. dprintf(idx, STR("Usage: hublevel <bot> <level>\n"));
  1483. return;
  1484. }
  1485. handle = newsplit(&par);
  1486. level = newsplit(&par);
  1487. u1 = get_user_by_handle(userlist, handle);
  1488. if (!u1 || !(u1->flags & USER_BOT)) {
  1489. dprintf(idx, STR("Useful only for bots.\n"));
  1490. return;
  1491. }
  1492. dprintf(idx, STR("Changed bot's hublevel.\n"));
  1493. obi = get_user(&USERENTRY_BOTADDR, u1);
  1494. bi = user_malloc(sizeof(struct bot_addr));
  1495. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1496. strcpy(bi->uplink, obi->uplink);
  1497. bi->address = user_malloc(strlen(obi->address) + 1);
  1498. strcpy(bi->address, obi->address);
  1499. bi->telnet_port = obi->telnet_port;
  1500. bi->relay_port = obi->relay_port;
  1501. bi->hublevel = atoi(level);
  1502. set_user(&USERENTRY_BOTADDR, u1, bi);
  1503. #ifdef HUB
  1504. write_userfile(idx);
  1505. #endif /* HUB */
  1506. }
  1507. static void cmd_uplink(struct userrec *u, int idx, char *par)
  1508. {
  1509. char *handle, *uplink;
  1510. struct bot_addr *bi, *obi;
  1511. struct userrec *u1;
  1512. putlog(LOG_CMDS, "*", STR("#%s# uplink %s"), dcc[idx].nick, par);
  1513. if (!par[0]) {
  1514. dprintf(idx, STR("Usage: uplink <bot> [uplink]\n"));
  1515. return;
  1516. }
  1517. handle = newsplit(&par);
  1518. uplink = newsplit(&par);
  1519. if (!uplink)
  1520. uplink = "";
  1521. u1 = get_user_by_handle(userlist, handle);
  1522. if (!u1 || !(u1->flags & USER_BOT)) {
  1523. dprintf(idx, STR("Useful only for bots.\n"));
  1524. return;
  1525. }
  1526. if (uplink && uplink[0])
  1527. dprintf(idx, STR("Changed bot's uplink.\n"));
  1528. else
  1529. dprintf(idx, STR("Cleared bot's uplink.\n"));
  1530. obi = get_user(&USERENTRY_BOTADDR, u1);
  1531. bi = user_malloc(sizeof(struct bot_addr));
  1532. bi->uplink = user_malloc(strlen(uplink) + 1);
  1533. strcpy(bi->uplink, uplink);
  1534. bi->address = user_malloc(strlen(obi->address) + 1);
  1535. strcpy(bi->address, obi->address);
  1536. bi->telnet_port = obi->telnet_port;
  1537. bi->relay_port = obi->relay_port;
  1538. bi->hublevel = obi->hublevel;
  1539. set_user(&USERENTRY_BOTADDR, u1, bi);
  1540. #ifdef HUB
  1541. write_userfile(idx);
  1542. #endif /* HUB */
  1543. }
  1544. static void cmd_chaddr(struct userrec *u, int idx, char *par)
  1545. {
  1546. int telnet_port = 3333, relay_port = 3333;
  1547. #ifdef USE_IPV6
  1548. char *handle, *addr, *p, *q, *r;
  1549. #else
  1550. char *handle, *addr, *p, *q;
  1551. #endif /* USE_IPV6 */
  1552. struct bot_addr *bi, *obi;
  1553. struct userrec *u1;
  1554. handle = newsplit(&par);
  1555. if (!par[0]) {
  1556. dprintf(idx, STR("Usage: chaddr <bot> <address[:telnet-port[/relay-port]]>\n"));
  1557. return;
  1558. }
  1559. addr = newsplit(&par);
  1560. if (strlen(addr) > UHOSTMAX)
  1561. addr[UHOSTMAX] = 0;
  1562. u1 = get_user_by_handle(userlist, handle);
  1563. if (!u1 || !(u1->flags & USER_BOT)) {
  1564. dprintf(idx, STR("This command is only useful for tandem bots.\n"));
  1565. return;
  1566. }
  1567. if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
  1568. dprintf(idx, STR("You can't change a share bot's address.\n"));
  1569. return;
  1570. }
  1571. putlog(LOG_CMDS, "*", STR("#%s# chaddr %s %s"), dcc[idx].nick, handle, addr);
  1572. dprintf(idx, STR("Changed bot's address.\n"));
  1573. obi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1574. bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1575. if (bi) {
  1576. telnet_port = bi->telnet_port;
  1577. relay_port = bi->relay_port;
  1578. }
  1579. bi = user_malloc(sizeof(struct bot_addr));
  1580. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1581. strcpy(bi->uplink, obi->uplink);
  1582. bi->hublevel = obi->hublevel;
  1583. q = strchr(addr, ':');
  1584. if (!q) {
  1585. bi->address = user_malloc(strlen(addr) + 1);
  1586. strcpy(bi->address, addr);
  1587. bi->telnet_port = telnet_port;
  1588. bi->relay_port = relay_port;
  1589. } else {
  1590. #ifdef USE_IPV6
  1591. r = strchr(addr, '[');
  1592. if (r) { /* ipv6 notation [3ffe:80c0:225::] */
  1593. *addr++;
  1594. r = strchr(addr, ']');
  1595. bi->address = user_malloc(r - addr + 1);
  1596. strncpyz(bi->address, addr, r - addr + 1);
  1597. addr = r;
  1598. *addr++;
  1599. } else {
  1600. bi->address = user_malloc(q - addr + 1);
  1601. strncpyz(bi->address, addr, q - addr + 1);
  1602. }
  1603. q = strchr(addr, ':');
  1604. if (q) {
  1605. p = q + 1;
  1606. bi->telnet_port = atoi(p);
  1607. q = strchr(p, '/');
  1608. if (!q) {
  1609. bi->relay_port = telnet_port;
  1610. } else {
  1611. bi->relay_port = atoi(q + 1);
  1612. }
  1613. }
  1614. #else /* !USE_IPV6 */
  1615. bi->address = user_malloc(q - addr + 1);
  1616. strncpyz(bi->address, addr, q - addr + 1);
  1617. p = q + 1;
  1618. bi->telnet_port = atoi(p);
  1619. q = strchr(p, '/');
  1620. if (!q)
  1621. bi->relay_port = bi->telnet_port;
  1622. else
  1623. bi->relay_port = atoi(q + 1);
  1624. #endif /* USE_IPV6 */
  1625. }
  1626. set_user(&USERENTRY_BOTADDR, u1, bi);
  1627. #ifdef HUB
  1628. write_userfile(idx);
  1629. #endif /* HUB */
  1630. }
  1631. #endif /* HUB */
  1632. static void cmd_comment(struct userrec *u, int idx, char *par)
  1633. {
  1634. char *handle;
  1635. struct userrec *u1;
  1636. handle = newsplit(&par);
  1637. if (!par[0]) {
  1638. dprintf(idx, STR("Usage: comment <handle> <newcomment/none>\n"));
  1639. return;
  1640. }
  1641. u1 = get_user_by_handle(userlist, handle);
  1642. if (!u1) {
  1643. dprintf(idx, STR("No such user!\n"));
  1644. return;
  1645. }
  1646. if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
  1647. egg_strcasecmp(handle, dcc[idx].nick)) {
  1648. dprintf(idx, STR("You can't change comment on a bot owner.\n"));
  1649. return;
  1650. }
  1651. putlog(LOG_CMDS, "*", STR("#%s# comment %s %s"), dcc[idx].nick, handle, par);
  1652. if (!egg_strcasecmp(par, "none")) {
  1653. dprintf(idx, STR("Okay, comment blanked.\n"));
  1654. set_user(&USERENTRY_COMMENT, u1, NULL);
  1655. return;
  1656. }
  1657. dprintf(idx, STR("Changed comment.\n"));
  1658. update_mod(handle, dcc[idx].nick, "comment", NULL);
  1659. set_user(&USERENTRY_COMMENT, u1, par);
  1660. #ifdef HUB
  1661. write_userfile(idx);
  1662. #endif /* HUB */
  1663. }
  1664. static void cmd_randstring(struct userrec *u, int idx, char *par)
  1665. {
  1666. int len;
  1667. char *rand;
  1668. if (!par[0]) {
  1669. dprintf(idx, "Usage: randstring <len>\n");
  1670. return;
  1671. }
  1672. putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
  1673. len = atoi(par);
  1674. if (len < 301) {
  1675. rand = nmalloc(len + 1);
  1676. make_rand_str(rand, len);
  1677. dprintf(idx, STR("string: %s\n"), rand);
  1678. nfree(rand);
  1679. } else
  1680. dprintf(idx, "Too long, must be <= 300\n");
  1681. }
  1682. static void cmd_restart(struct userrec *u, int idx, char *par)
  1683. {
  1684. putlog(LOG_CMDS, "*", STR("#%s# restart"), dcc[idx].nick);
  1685. #ifdef HUB
  1686. write_userfile(idx);
  1687. #endif /* HUB */
  1688. #ifdef LEAF
  1689. {
  1690. module_entry *me;
  1691. if ((me = module_find("server", 0, 0))) {
  1692. Function *func = me->funcs;
  1693. (func[SERVER_NUKESERVER]) ("Restarting...");
  1694. }
  1695. }
  1696. #endif /* LEAF */
  1697. botnet_send_chat(-1, botnetnick, "Restarting...");
  1698. botnet_send_bye();
  1699. fatal("Restarting...", 1);
  1700. usleep(2000 * 500);
  1701. bg_send_quit(BG_ABORT);
  1702. unlink(pid_file); //if this fails it is ok, cron will restart the bot, *hopefully*
  1703. system(binname); //start new bot.
  1704. exit(0);
  1705. }
  1706. #ifdef HUB
  1707. static void cmd_reload(struct userrec *u, int idx, char *par)
  1708. {
  1709. putlog(LOG_CMDS, "*", STR("#%s# reload"), dcc[idx].nick);
  1710. dprintf(idx, STR("Reloading user file...\n"));
  1711. reload();
  1712. }
  1713. #endif /* HUB */
  1714. static void cmd_die(struct userrec *u, int idx, char *par)
  1715. {
  1716. char s1[1024], s2[1024];
  1717. putlog(LOG_CMDS, "*", STR("#%s# die %s"), dcc[idx].nick, par);
  1718. if (par[0]) {
  1719. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (%s: %s)"), dcc[idx].nick, par);
  1720. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (%s)"), dcc[idx].nick, dcc[idx].host, par);
  1721. strncpyz(quit_msg, par, 1024);
  1722. } else {
  1723. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (Authorized by %s)"), dcc[idx].nick);
  1724. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (request)"), dcc[idx].nick, dcc[idx].host);
  1725. strncpyz(quit_msg, dcc[idx].nick, 1024);
  1726. }
  1727. kill_bot(s1, s2);
  1728. }
  1729. static void cmd_debug(struct userrec *u, int idx, char *par)
  1730. {
  1731. putlog(LOG_CMDS, "*", STR("#%s# debug"), dcc[idx].nick);
  1732. debug_mem_to_dcc(idx);
  1733. }
  1734. static void cmd_simul(struct userrec *u, int idx, char *par)
  1735. {
  1736. char *nick;
  1737. int i, ok = 0;
  1738. nick = newsplit(&par);
  1739. if (!par[0]) {
  1740. dprintf(idx, STR("Usage: simul <hand> <text>\n"));
  1741. return;
  1742. }
  1743. if (isowner(nick)) {
  1744. dprintf(idx, STR("Unable to '.simul' permanent owners.\n"));
  1745. return;
  1746. }
  1747. for (i = 0; i < dcc_total; i++)
  1748. if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
  1749. (dcc[i].type->flags & DCT_SIMUL)) {
  1750. putlog(LOG_CMDS, "*", STR("#%s# simul %s %s"), dcc[idx].nick, nick, par);
  1751. if (dcc[i].type && dcc[i].type->activity) {
  1752. dcc[i].type->activity(i, par, strlen(par));
  1753. ok = 1;
  1754. }
  1755. }
  1756. if (!ok)
  1757. dprintf(idx, STR("No such user on the party line.\n"));
  1758. }
  1759. #ifdef HUB
  1760. static void cmd_link(struct userrec *u, int idx, char *par)
  1761. {
  1762. char *s;
  1763. int i;
  1764. if (!par[0]) {
  1765. dprintf(idx, STR("Usage: link [some-bot] <new-bot>\n"));
  1766. return;
  1767. }
  1768. putlog(LOG_CMDS, "*", STR("#%s# link %s"), dcc[idx].nick, par);
  1769. s = newsplit(&par);
  1770. if (!par[0] || !egg_strcasecmp(par, botnetnick))
  1771. botlink(dcc[idx].nick, idx, s);
  1772. else {
  1773. char x[40];
  1774. i = nextbot(s);
  1775. if (i < 0) {
  1776. dprintf(idx, STR("No such bot online.\n"));
  1777. return;
  1778. }
  1779. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1780. botnet_send_link(i, x, s, par);
  1781. }
  1782. }
  1783. #endif /* HUB */
  1784. static void cmd_unlink(struct userrec *u, int idx, char *par)
  1785. {
  1786. int i;
  1787. char *bot;
  1788. if (!par[0]) {
  1789. dprintf(idx, STR("Usage: unlink <bot> [reason]\n"));
  1790. return;
  1791. }
  1792. putlog(LOG_CMDS, "*", STR("#%s# unlink %s"), dcc[idx].nick, par);
  1793. bot = newsplit(&par);
  1794. i = nextbot(bot);
  1795. if (i < 0) {
  1796. botunlink(idx, bot, par);
  1797. return;
  1798. }
  1799. /* If we're directly connected to that bot, just do it
  1800. * (is nike gunna sue?)
  1801. */
  1802. if (!egg_strcasecmp(dcc[i].nick, bot))
  1803. botunlink(idx, bot, par);
  1804. else {
  1805. char x[40];
  1806. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1807. botnet_send_unlink(i, x, lastbot(bot), bot, par);
  1808. }
  1809. }
  1810. static void cmd_relay(struct userrec *u, int idx, char *par)
  1811. {
  1812. if (!par[0]) {
  1813. dprintf(idx, STR("Usage: relay <bot>\n"));
  1814. return;
  1815. }
  1816. putlog(LOG_CMDS, "*", STR("#%s# relay %s"), dcc[idx].nick, par);
  1817. tandem_relay(idx, par, 0);
  1818. }
  1819. #ifdef HUB
  1820. static void cmd_save(struct userrec *u, int idx, char *par)
  1821. {
  1822. char buf[100], i = 0;
  1823. putlog(LOG_CMDS, "*", STR("#%s# save"), dcc[idx].nick);
  1824. sprintf(buf, "Saving user file...");
  1825. i = write_userfile(-1);
  1826. if (i == 0)
  1827. strcat(buf, "success.");
  1828. else if (i == 1)
  1829. strcat(buf, "failed: No userlist.");
  1830. else if (i == 2)
  1831. strcat(buf, "failed: Cannot open userfile for writing.");
  1832. else if (i == 3)
  1833. strcat(buf, "failed: Problem writing users/chans (see debug).");
  1834. else /* This can't happen. */
  1835. strcat(buf, "failed: Unforseen error");
  1836. buf[99] = 0;
  1837. dprintf(idx, "%s\n", buf);
  1838. }
  1839. static void cmd_backup(struct userrec *u, int idx, char *par)
  1840. {
  1841. putlog(LOG_CMDS, "*", STR("#%s# backup"), dcc[idx].nick);
  1842. dprintf(idx, STR("Backing up the channel & user files...\n"));
  1843. #ifdef HUB
  1844. write_userfile(idx);
  1845. backup_userfile();
  1846. #endif /* HUB */
  1847. }
  1848. static void cmd_trace(struct userrec *u, int idx, char *par)
  1849. {
  1850. int i;
  1851. char x[NOTENAMELEN + 11], y[11];
  1852. if (!par[0]) {
  1853. dprintf(idx, STR("Usage: trace <bot>\n"));
  1854. return;
  1855. }
  1856. if (!egg_strcasecmp(par, botnetnick)) {
  1857. dprintf(idx, STR("That's me! Hiya! :)\n"));
  1858. return;
  1859. }
  1860. i = nextbot(par);
  1861. if (i < 0) {
  1862. dprintf(idx, STR("Unreachable bot.\n"));
  1863. return;
  1864. }
  1865. putlog(LOG_CMDS, "*", STR("#%s# trace %s"), dcc[idx].nick, par);
  1866. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1867. simple_sprintf(y, ":%d", now);
  1868. botnet_send_trace(i, x, par, y);
  1869. }
  1870. static void cmd_binds(struct userrec *u, int idx, char *par)
  1871. {
  1872. putlog(LOG_CMDS, "*", STR("#%s# binds %s"), dcc[idx].nick, par);
  1873. tell_binds(idx, par);
  1874. }
  1875. #endif /* HUB */
  1876. /* After messing with someone's user flags, make sure the dcc-chat flags
  1877. * are set correctly.
  1878. */
  1879. int check_dcc_attrs(struct userrec *u, int oatr)
  1880. {
  1881. int i, stat;
  1882. if (!u)
  1883. return 0;
  1884. /* Make sure default owners are +a */
  1885. if (isowner(u->handle)) {
  1886. u->flags = sanity_check(u->flags | USER_ADMIN);
  1887. }
  1888. for (i = 0; i < dcc_total; i++) {
  1889. if ((dcc[i].type->flags & DCT_MASTER) &&
  1890. (!egg_strcasecmp(u->handle, dcc[i].nick))) {
  1891. stat = dcc[i].status;
  1892. if ((dcc[i].type == &DCC_CHAT) &&
  1893. ((u->flags & (USER_OP | USER_MASTER | USER_OWNER))
  1894. != (oatr & (USER_OP | USER_MASTER | USER_OWNER)))) {
  1895. botnet_send_join_idx(i, -1);
  1896. }
  1897. if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
  1898. struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1899. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
  1900. LOG_FILES | LOG_WALL | LOG_DEBUG);
  1901. get_user_flagrec(u, &fr, NULL);
  1902. if (!chan_master(fr))
  1903. dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
  1904. dprintf(i, STR("*** POOF! ***\n"));
  1905. dprintf(i, STR("You are no longer a master on this bot.\n"));
  1906. }
  1907. if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
  1908. dcc[i].u.chat->con_flags |= conmask;
  1909. dprintf(i, STR("*** POOF! ***\n"));
  1910. dprintf(i, STR("You are now a master on this bot.\n"));
  1911. }
  1912. if (!(oatr & USER_PARTY) && (u->flags & USER_PARTY) && dcc[i].u.chat->channel < 0) {
  1913. dprintf(i, "-+- POOF! -+-\n");
  1914. dprintf(i, STR("You now have party line chat access.\n"));
  1915. dprintf(i, STR("To rejoin the partyline, type: %schat on\n"), dcc_prefix);
  1916. }
  1917. if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
  1918. dprintf(i, STR("@@@ POOF! @@@\n"));
  1919. dprintf(i, STR("You are now an OWNER of this bot.\n"));
  1920. }
  1921. if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
  1922. dprintf(i, STR("@@@ POOF! @@@\n"));
  1923. dprintf(i, STR("You are no longer an owner of this bot.\n"));
  1924. }
  1925. if (!(u->flags & USER_PARTY) && dcc[i].u.chat->channel >= 0) { //who cares about old flags, they shouldnt be here anyway.
  1926. dprintf(i, STR("-+- POOF! -+-\n"));
  1927. dprintf(i, STR("You no longer have party line chat access.\n"));
  1928. dprintf(i, STR("Leaving chat mode...\n"));
  1929. chanout_but(-1, dcc[i].u.chat->channel, STR("*** %s left the party line - no chat access.\n"), dcc[i].nick);
  1930. if (dcc[i].u.chat->channel < 100000)
  1931. botnet_send_part_idx(i, "");
  1932. dcc[i].u.chat->channel = (-1);
  1933. }
  1934. if (!(oatr & USER_ADMIN) && (u->flags & USER_ADMIN)) {
  1935. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1936. dprintf(i, STR("You are now an ADMIN of this bot.\n"));
  1937. }
  1938. if ((oatr & USER_ADMIN) && !(u->flags & USER_ADMIN)) {
  1939. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1940. dprintf(i, STR("You are no longer an admin of this bot.\n"));
  1941. }
  1942. if ((stat & STAT_PARTY) && (u->flags & USER_OP))
  1943. stat &= ~STAT_PARTY;
  1944. if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
  1945. !(u->flags & USER_MASTER))
  1946. stat |= STAT_PARTY;
  1947. if (stat & STAT_CHAT) {
  1948. #ifdef HUB
  1949. if (!(u->flags & USER_HUBA))
  1950. stat &= ~STAT_CHAT;
  1951. #endif /* HUB */
  1952. if (ischanhub() && !(u->flags & USER_CHUBA))
  1953. stat &= ~STAT_CHAT;
  1954. }
  1955. if ((u->flags & USER_PARTY))
  1956. stat |= STAT_CHAT;
  1957. dcc[i].status = stat;
  1958. /* Check if they no longer have access to wherever they are.
  1959. */
  1960. #ifdef HUB
  1961. if (!(u->flags & (USER_HUBA))) {
  1962. /* no hub access, drop them. */
  1963. dprintf(i, STR("-+- POOF! -+-\n"));
  1964. dprintf(i, STR("You no longer have hub access.\n\n"));
  1965. do_boot(i, botnetnick, STR("No hub access.\n\n"));
  1966. }
  1967. #else /* !HUB */
  1968. if (ischanhub() && !(u->flags & (USER_CHUBA))) {
  1969. /* no chanhub access, drop them. */
  1970. dprintf(i, STR("-+- POOF! -+-\n"));
  1971. dprintf(i, STR("You no longer have chathub access.\n\n"));
  1972. do_boot(i, botnetnick, STR("No chathub access.\n\n"));
  1973. }
  1974. #endif /* HUB */
  1975. }
  1976. if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1977. if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
  1978. dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
  1979. if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
  1980. dcc[i].status |= STAT_LEAF;
  1981. }
  1982. }
  1983. return u->flags;
  1984. }
  1985. int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags, int ochatr)
  1986. {
  1987. int i, found = 0, atr = u ? u->flags : 0;
  1988. struct chanset_t *chan;
  1989. if (!u)
  1990. return 0;
  1991. for (i = 0; i < dcc_total; i++) {
  1992. if ((dcc[i].type->flags & DCT_MASTER) &&
  1993. !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1994. if ((dcc[i].type == &DCC_CHAT) &&
  1995. ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
  1996. != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
  1997. botnet_send_join_idx(i, -1);
  1998. if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
  1999. if (!(atr & USER_MASTER))
  2000. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
  2001. dprintf(i, STR("*** POOF! ***\n"));
  2002. dprintf(i, STR("You are no longer a master on %s.\n"), chname);
  2003. }
  2004. if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
  2005. dcc[i].u.chat->con_flags |= conmask;
  2006. if (!(atr & USER_MASTER))
  2007. dcc[i].u.chat->con_flags &=
  2008. ~(LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
  2009. dprintf(i, STR("*** POOF! ***\n"));
  2010. dprintf(i, STR("You are now a master on %s.\n"), chname);
  2011. }
  2012. if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
  2013. dprintf(i, STR("@@@ POOF! @@@\n"));
  2014. dprintf(i, STR("You are now an OWNER of %s.\n"), chname);
  2015. }
  2016. if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
  2017. dprintf(i, STR("@@@ POOF! @@@\n"));
  2018. dprintf(i, STR("You are no longer an owner of %s.\n"), chname);
  2019. }
  2020. if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2021. (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
  2022. ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2023. (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
  2024. struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
  2025. for (chan = chanset; chan && !found; chan = chan->next) {
  2026. get_user_flagrec(u, &fr, chan->dname);
  2027. if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
  2028. found = 1;
  2029. }
  2030. if (!chan)
  2031. chan = chanset;
  2032. if (chan)
  2033. strcpy(dcc[i].u.chat->con_chan, chan->dname);
  2034. else
  2035. strcpy(dcc[i].u.chat->con_chan, "*");
  2036. }
  2037. }
  2038. }
  2039. return chflags;
  2040. }
  2041. static void cmd_chattr(struct userrec *u, int idx, char *par)
  2042. {
  2043. char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
  2044. struct chanset_t *chan = NULL;
  2045. struct userrec *u2;
  2046. struct flag_record pls = {0, 0, 0, 0, 0, 0},
  2047. mns = {0, 0, 0, 0, 0, 0},
  2048. user = {0, 0, 0, 0, 0, 0},
  2049. ouser = {0, 0, 0, 0, 0, 0};
  2050. module_entry *me;
  2051. int fl = -1, of = 0, ocf = 0;
  2052. if (!par[0]) {
  2053. dprintf(idx, STR("Usage: chattr <handle> [changes] [channel]\n"));
  2054. return;
  2055. }
  2056. hand = newsplit(&par);
  2057. u2 = get_user_by_handle(userlist, hand);
  2058. if (!u2) {
  2059. dprintf(idx, STR("No such user!\n"));
  2060. return;
  2061. }
  2062. /* Parse args */
  2063. if (par[0]) {
  2064. arg = newsplit(&par);
  2065. if (par[0]) {
  2066. /* .chattr <handle> <changes> <channel> */
  2067. chg = arg;
  2068. arg = newsplit(&par);
  2069. chan = findchan_by_dname(arg);
  2070. } else {
  2071. chan = findchan_by_dname(arg);
  2072. /* Consider modeless channels, starting with '+' */
  2073. if (!(arg[0] == '+' && chan) &&
  2074. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  2075. /* .chattr <handle> <changes> */
  2076. chg = arg;
  2077. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  2078. arg = NULL;
  2079. }
  2080. /* .chattr <handle> <channel>: nothing to do... */
  2081. }
  2082. }
  2083. /* arg: pointer to channel name, NULL if none specified
  2084. * chan: pointer to channel structure, NULL if none found or none specified
  2085. * chg: pointer to changes, NULL if none specified
  2086. */
  2087. Assert(!(!arg && chan));
  2088. if (arg && !chan) {
  2089. dprintf(idx, STR("No channel record for %s.\n"), arg);
  2090. return;
  2091. }
  2092. if (chg) {
  2093. if (!arg && strpbrk(chg, "&|")) {
  2094. /* .chattr <handle> *[&|]*: use console channel if found... */
  2095. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  2096. arg = NULL;
  2097. else
  2098. chan = findchan_by_dname(arg);
  2099. if (arg && !chan) {
  2100. dprintf (idx, STR("Invalid console channel %s.\n"), arg);
  2101. return;
  2102. }
  2103. } else if (arg && !strpbrk(chg, "&|")) {
  2104. tmpchg = nmalloc(strlen(chg) + 2);
  2105. strcpy(tmpchg, "|");
  2106. strcat(tmpchg, chg);
  2107. chg = tmpchg;
  2108. }
  2109. }
  2110. par = arg;
  2111. user.match = FR_GLOBAL;
  2112. if (chan)
  2113. user.match |= FR_CHAN;
  2114. get_user_flagrec(u, &user, chan ? chan->dname : 0);
  2115. get_user_flagrec(u2, &ouser, chan ? chan->dname : 0);
  2116. if (chan && !glob_master(user) && !chan_master(user)) {
  2117. dprintf(idx, STR("You do not have channel master privileges for channel %s.\n"),
  2118. par);
  2119. if (tmpchg)
  2120. nfree(tmpchg);
  2121. return;
  2122. }
  2123. if (chan && private(user, chan, PRIV_OP)) {
  2124. dprintf(idx, STR("You do not have access to change flags for %s\n"), chan->dname);
  2125. if (tmpchg)
  2126. nfree(tmpchg);
  2127. return;
  2128. }
  2129. user.match &= fl;
  2130. if (chg) {
  2131. pls.match = user.match;
  2132. break_down_flags(chg, &pls, &mns);
  2133. /* No-one can change these flags on-the-fly */
  2134. pls.global &= ~(USER_BOT);
  2135. mns.global &= ~(USER_BOT);
  2136. if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
  2137. dprintf(idx, STR("Only a hub can be set as the updatehub.\n"));
  2138. pls.global &= ~(USER_UPDATEHUB);
  2139. }
  2140. /* strip out +p without +i or +j */
  2141. if (((pls.global & USER_PARTY) && !(pls.global & USER_CHUBA) && !(pls.global & USER_HUBA)) && (!glob_huba(ouser) && !glob_chuba(ouser))) {
  2142. dprintf(idx, "Global flag +p requires either chathub or hub access first.\n");
  2143. pls.global &= ~USER_PARTY;
  2144. }
  2145. if (!isowner(u->handle)) {
  2146. if (pls.global & USER_HUBA)
  2147. putlog(LOG_MISC, "*", STR("%s attempted to give %s hub connect access"), dcc[idx].nick, u2->handle);
  2148. if (mns.global & USER_HUBA)
  2149. putlog(LOG_MISC, "*", STR("%s attempted to take away hub connect access from %s"), dcc[idx].nick, u2->handle);
  2150. if (pls.global & USER_UPDATEHUB)
  2151. putlog(LOG_MISC, "*", STR("%s attempted to make %s the updatehub"), dcc[idx].nick, u2->handle);
  2152. if (mns.global & USER_UPDATEHUB)
  2153. putlog(LOG_MISC, "*", STR("%s attempted to take away updatehub status from %s"), dcc[idx].nick, u2->handle);
  2154. if (pls.global & USER_ADMIN)
  2155. putlog(LOG_MISC, "*", STR("%s attempted to give %s admin access"), dcc[idx].nick, u2->handle);
  2156. if (mns.global & USER_ADMIN)
  2157. putlog(LOG_MISC, "*", STR("%s attempted to take away admin access from %s"), dcc[idx].nick, u2->handle);
  2158. if (pls.global & USER_OWNER)
  2159. putlog(LOG_MISC, "*", STR("%s attempted to give owner to %s"), dcc[idx].nick, u2->handle);
  2160. if (mns.global & USER_OWNER)
  2161. putlog(LOG_MISC, "*", STR("%s attempted to take owner away from %s"), dcc[idx].nick, u2->handle);
  2162. pls.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2163. mns.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2164. pls.chan &= ~(USER_ADMIN | USER_UPDATEHUB);
  2165. }
  2166. if (chan) {
  2167. pls.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2168. mns.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2169. }
  2170. if (!glob_owner(user) && !isowner(u->handle)) {
  2171. pls.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2172. mns.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2173. if (chan) {
  2174. pls.chan &= ~USER_OWNER;
  2175. mns.chan &= ~USER_OWNER;
  2176. }
  2177. }
  2178. if (chan && !chan_owner(user) && !glob_owner(user) && !isowner(u->handle)) {
  2179. pls.chan &= ~USER_MASTER;
  2180. mns.chan &= ~USER_MASTER;
  2181. if (!chan_master(user) && !glob_master(user)) {
  2182. pls.chan = 0;
  2183. mns.chan = 0;
  2184. }
  2185. }
  2186. #ifdef LEAF
  2187. pls.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2188. mns.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2189. #endif /* LEAF */
  2190. get_user_flagrec(u2, &user, par);
  2191. if (user.match & FR_GLOBAL) {
  2192. of = user.global;
  2193. user.global = sanity_check((user.global |pls.global) &~mns.global);
  2194. user.udef_global = (user.udef_global | pls.udef_global)
  2195. & ~mns.udef_global;
  2196. }
  2197. if (chan) {
  2198. ocf = user.chan;
  2199. user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
  2200. user.global);
  2201. user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
  2202. }
  2203. set_user_flagrec(u2, &user, par);
  2204. }
  2205. if (chan) {
  2206. char tmp[100];
  2207. putlog(LOG_CMDS, "*", STR("#%s# (%s) chattr %s %s"), dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
  2208. egg_snprintf(tmp, sizeof tmp, "chattr %s", chg);
  2209. update_mod(hand, dcc[idx].nick, tmp, chan->dname);
  2210. } else {
  2211. putlog(LOG_CMDS, "*", STR("#%s# chattr %s %s"), dcc[idx].nick, hand, chg ? chg : "");
  2212. update_mod(hand, dcc[idx].nick, "chattr", chg);
  2213. }
  2214. /* Get current flags and display them */
  2215. if (user.match & FR_GLOBAL) {
  2216. user.match = FR_GLOBAL;
  2217. if (chg)
  2218. check_dcc_attrs(u2, of);
  2219. get_user_flagrec(u2, &user, NULL);
  2220. build_flags(work, &user, NULL);
  2221. if (work[0] != '-')
  2222. dprintf(idx, STR("Global flags for %s are now +%s.\n"), hand, work);
  2223. else
  2224. dprintf(idx, STR("No global flags for %s.\n"), hand);
  2225. }
  2226. if (chan) {
  2227. user.match = FR_CHAN;
  2228. get_user_flagrec(u2, &user, par);
  2229. user.chan &= ~BOT_SHARE;
  2230. if (chg)
  2231. check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
  2232. build_flags(work, &user, NULL);
  2233. if (work[0] != '-')
  2234. dprintf(idx, STR("Channel flags for %s on %s are now +%s.\n"), hand,
  2235. chan->dname, work);
  2236. else
  2237. dprintf(idx, STR("No flags for %s on %s.\n"), hand, chan->dname);
  2238. }
  2239. if (chg && (me = module_find("irc", 0, 0))) {
  2240. Function *func = me->funcs;
  2241. (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
  2242. }
  2243. if (tmpchg)
  2244. nfree(tmpchg);
  2245. #ifdef HUB
  2246. write_userfile(idx);
  2247. #endif /* HUB */
  2248. }
  2249. static void cmd_chat(struct userrec *u, int idx, char *par)
  2250. {
  2251. char *arg;
  2252. int newchan, oldchan;
  2253. module_entry *me;
  2254. if (!(u->flags & USER_PARTY)) {
  2255. dprintf(idx, STR("You don't have partyline access\n"));
  2256. return;
  2257. }
  2258. arg = newsplit(&par);
  2259. if (!egg_strcasecmp(arg, "off")) {
  2260. /* Turn chat off */
  2261. if (dcc[idx].u.chat->channel < 0) {
  2262. dprintf(idx, STR("You weren't in chat anyway!\n"));
  2263. return;
  2264. } else {
  2265. dprintf(idx, STR("Leaving chat mode...\n"));
  2266. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  2267. dcc[idx].u.chat->channel);
  2268. chanout_but(-1, dcc[idx].u.chat->channel,
  2269. "*** %s left the party line.\n",
  2270. dcc[idx].nick);
  2271. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2272. botnet_send_part_idx(idx, "");
  2273. }
  2274. dcc[idx].u.chat->channel = (-1);
  2275. } else {
  2276. if (arg[0] == '*') {
  2277. if (((arg[1] < '0') || (arg[1] > '9'))) {
  2278. if (!arg[1])
  2279. newchan = 0;
  2280. else {
  2281. Tcl_SetVar(interp, "chan", arg, 0);
  2282. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2283. interp->result[0])
  2284. newchan = atoi(interp->result);
  2285. else
  2286. newchan = -1;
  2287. }
  2288. if (newchan < 0) {
  2289. dprintf(idx, STR("No channel exists by that name.\n"));
  2290. return;
  2291. }
  2292. } else
  2293. newchan = GLOBAL_CHANS + atoi(arg + 1);
  2294. if (newchan < GLOBAL_CHANS || newchan > 199999) {
  2295. dprintf(idx, STR("Channel number out of range: local channels must be *0-*99999.\n"));
  2296. return;
  2297. }
  2298. } else {
  2299. if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
  2300. if (!egg_strcasecmp(arg, "on"))
  2301. newchan = 0;
  2302. else {
  2303. Tcl_SetVar(interp, "chan", arg, 0);
  2304. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2305. interp->result[0])
  2306. newchan = atoi(interp->result);
  2307. else
  2308. newchan = -1;
  2309. }
  2310. if (newchan < 0) {
  2311. dprintf(idx, STR("No channel exists by that name.\n"));
  2312. return;
  2313. }
  2314. } else
  2315. newchan = atoi(arg);
  2316. if ((newchan < 0) || (newchan > 99999)) {
  2317. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  2318. return;
  2319. }
  2320. }
  2321. /* If coming back from being off the party line, make sure they're
  2322. * not away.
  2323. */
  2324. if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
  2325. not_away(idx);
  2326. if (dcc[idx].u.chat->channel == newchan) {
  2327. if (!newchan) {
  2328. dprintf(idx, STR("You're already on the party line!\n"));
  2329. return;
  2330. } else {
  2331. dprintf(idx, STR("You're already on channel %s%d!\n"),
  2332. (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
  2333. return;
  2334. }
  2335. } else {
  2336. oldchan = dcc[idx].u.chat->channel;
  2337. if (oldchan >= 0)
  2338. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
  2339. if (!oldchan) {
  2340. chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
  2341. } else if (oldchan > 0) {
  2342. chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
  2343. }
  2344. dcc[idx].u.chat->channel = newchan;
  2345. if (!newchan) {
  2346. dprintf(idx, STR("Entering the party line...\n"));
  2347. chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
  2348. } else {
  2349. dprintf(idx, STR("Joining channel '%s'...\n"), arg);
  2350. chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
  2351. }
  2352. check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
  2353. dcc[idx].sock, dcc[idx].host);
  2354. if (newchan < GLOBAL_CHANS)
  2355. botnet_send_join_idx(idx, oldchan);
  2356. else if (oldchan < GLOBAL_CHANS)
  2357. botnet_send_part_idx(idx, "");
  2358. }
  2359. }
  2360. /* New style autosave here too -- rtc, 09/28/1999*/
  2361. if ((me = module_find("console", 0, 0))) {
  2362. Function *func = me->funcs;
  2363. (func[CONSOLE_DOSTORE]) (idx);
  2364. }
  2365. }
  2366. int exec_str(int idx, char *cmd) {
  2367. char *out, *err, *p, *np;
  2368. if (shell_exec(cmd, NULL, &out, &err)) {
  2369. if (out) {
  2370. dprintf(idx, STR("Result:\n"));
  2371. p=out;
  2372. while (p && p[0]) {
  2373. np=strchr(p, '\n');
  2374. if (np)
  2375. *np++=0;
  2376. dprintf(idx, STR("%s\n"), p);
  2377. p=np;
  2378. }
  2379. dprintf(idx, "\n");
  2380. nfree(out);
  2381. }
  2382. if (err) {
  2383. dprintf(idx, STR("Errors:\n"));
  2384. p=err;
  2385. while (p && p[0]) {
  2386. np=strchr(p, '\n');
  2387. if (np)
  2388. *np++=0;
  2389. dprintf(idx, STR("%s\n"), p);
  2390. p=np;
  2391. }
  2392. dprintf(idx, "\n");
  2393. nfree(err);
  2394. }
  2395. return 1;
  2396. }
  2397. return 0;
  2398. }
  2399. static void cmd_exec(struct userrec *u, int idx, char *par) {
  2400. putlog(LOG_CMDS, "*", STR("#%s# exec %s"), dcc[idx].nick, par);
  2401. #ifdef LEAF
  2402. if (!isowner(u->handle)) {
  2403. putlog(LOG_WARN, "*", STR("%s attempted 'exec' %s"), dcc[idx].nick, par);
  2404. dprintf(idx, STR("exec is only available to permanent owners on leaf bots\n"));
  2405. return;
  2406. }
  2407. #endif /* LEAF */
  2408. if (exec_str(idx, par))
  2409. dprintf(idx, STR("Exec completed\n"));
  2410. else
  2411. dprintf(idx, STR("Exec failed\n"));
  2412. }
  2413. static void cmd_w(struct userrec *u, int idx, char *par) {
  2414. putlog(LOG_CMDS, "*", STR("#%s# w"), dcc[idx].nick);
  2415. if (!exec_str(idx, "w"))
  2416. dprintf(idx, STR("Exec failed\n"));
  2417. }
  2418. static void cmd_ps(struct userrec *u, int idx, char *par) {
  2419. char * buf;
  2420. putlog(LOG_CMDS, "*", STR("#%s# ps %s"), dcc[idx].nick, par);
  2421. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2422. putlog(LOG_WARN, "*", STR("%s attempted 'ps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2423. dprintf(idx, STR("No."));
  2424. return;
  2425. }
  2426. buf=nmalloc(strlen(par)+4);
  2427. sprintf(buf, STR("ps %s"), par);
  2428. if (!exec_str(idx, buf))
  2429. dprintf(idx, STR("Exec failed\n"));
  2430. nfree(buf);
  2431. }
  2432. static void cmd_last(struct userrec *u, int idx, char *par) {
  2433. char user[20], buf[30];
  2434. struct passwd *pw;
  2435. putlog(LOG_CMDS, "*", STR("#%s# last %s"), dcc[idx].nick, par);
  2436. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2437. putlog(LOG_WARN, "*", STR("%s attempted 'last' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2438. dprintf(idx, STR("No."));
  2439. return;
  2440. }
  2441. if (par[0]) {
  2442. strncpyz(user, par, sizeof(user));
  2443. } else {
  2444. pw = getpwuid(geteuid());
  2445. if (!pw)
  2446. return;
  2447. strncpyz(user, pw->pw_name, sizeof(user));
  2448. }
  2449. if (!user[0]) {
  2450. dprintf(idx, STR("Can't determine user id for process\n"));
  2451. return;
  2452. }
  2453. sprintf(buf, STR("last %s"), user);
  2454. if (!exec_str(idx, buf))
  2455. dprintf(idx, STR("Failed to execute /bin/sh last\n"));
  2456. }
  2457. static void cmd_echo(struct userrec *u, int idx, char *par)
  2458. {
  2459. module_entry *me;
  2460. if (!par[0]) {
  2461. dprintf(idx, STR("Echo is currently %s.\n"), dcc[idx].status & STAT_ECHO ?
  2462. "on" : "off");
  2463. return;
  2464. }
  2465. if (!egg_strcasecmp(par, "on")) {
  2466. dprintf(idx, STR("Echo turned on.\n"));
  2467. dcc[idx].status |= STAT_ECHO;
  2468. } else if (!egg_strcasecmp(par, "off")) {
  2469. dprintf(idx, STR("Echo turned off.\n"));
  2470. dcc[idx].status &= ~STAT_ECHO;
  2471. } else {
  2472. dprintf(idx, STR("Usage: echo <on/off>\n"));
  2473. return;
  2474. }
  2475. /* New style autosave here too -- rtc, 09/28/1999*/
  2476. if ((me = module_find("console", 0, 0))) {
  2477. Function *func = me->funcs;
  2478. (func[CONSOLE_DOSTORE]) (idx);
  2479. }
  2480. }
  2481. static void cmd_color(struct userrec *u, int idx, char *par)
  2482. {
  2483. module_entry *me;
  2484. char *of;
  2485. putlog(LOG_CMDS, "*", STR("#%s# color %s"), dcc[idx].nick, par);
  2486. if (!par[0]) {
  2487. dprintf(idx, STR("Usage: color <on/off>\n"));
  2488. if (dcc[idx].status & STAT_COLOR)
  2489. dprintf(idx, STR("Color is currently on.\n"));
  2490. else
  2491. dprintf(idx, STR("Color is currently off.\n"));
  2492. return;
  2493. }
  2494. of = newsplit(&par);
  2495. if (!egg_strcasecmp(of, "on")) {
  2496. dcc[idx].status |= STAT_COLOR;
  2497. } else if (!egg_strcasecmp(of, "off")) {
  2498. dcc[idx].status &= ~(STAT_COLOR);
  2499. dprintf(idx, STR("Color turned off.\n"));
  2500. } else {
  2501. return;
  2502. }
  2503. if ((me = module_find("console", 0, 0))) {
  2504. Function *func = me->funcs;
  2505. (func[CONSOLE_DOSTORE]) (idx);
  2506. }
  2507. }
  2508. int stripmodes(char *s)
  2509. {
  2510. int res = 0;
  2511. for (; *s; s++)
  2512. switch (tolower(*s)) {
  2513. case 'b':
  2514. res |= STRIP_BOLD;
  2515. break;
  2516. case 'c':
  2517. res |= STRIP_COLOR;
  2518. break;
  2519. case 'r':
  2520. res |= STRIP_REV;
  2521. break;
  2522. case 'u':
  2523. res |= STRIP_UNDER;
  2524. break;
  2525. case 'a':
  2526. res |= STRIP_ANSI;
  2527. break;
  2528. case 'g':
  2529. res |= STRIP_BELLS;
  2530. break;
  2531. case '*':
  2532. res |= STRIP_ALL;
  2533. break;
  2534. }
  2535. return res;
  2536. }
  2537. char *stripmasktype(int x)
  2538. {
  2539. static char s[20];
  2540. char *p = s;
  2541. if (x & STRIP_BOLD)
  2542. *p++ = 'b';
  2543. if (x & STRIP_COLOR)
  2544. *p++ = 'c';
  2545. if (x & STRIP_REV)
  2546. *p++ = 'r';
  2547. if (x & STRIP_UNDER)
  2548. *p++ = 'u';
  2549. if (x & STRIP_ANSI)
  2550. *p++ = 'a';
  2551. if (x & STRIP_BELLS)
  2552. *p++ = 'g';
  2553. if (p == s)
  2554. *p++ = '-';
  2555. *p = 0;
  2556. return s;
  2557. }
  2558. static char *stripmaskname(int x)
  2559. {
  2560. static char s[161];
  2561. int i = 0;
  2562. s[i] = 0;
  2563. if (x & STRIP_BOLD)
  2564. i += my_strcpy(s + i, "bold, ");
  2565. if (x & STRIP_COLOR)
  2566. i += my_strcpy(s + i, "color, ");
  2567. if (x & STRIP_REV)
  2568. i += my_strcpy(s + i, "reverse, ");
  2569. if (x & STRIP_UNDER)
  2570. i += my_strcpy(s + i, "underline, ");
  2571. if (x & STRIP_ANSI)
  2572. i += my_strcpy(s + i, "ansi, ");
  2573. if (x & STRIP_BELLS)
  2574. i += my_strcpy(s + i, "bells, ");
  2575. if (!i)
  2576. strcpy(s, "none");
  2577. else
  2578. s[i - 2] = 0;
  2579. return s;
  2580. }
  2581. static void cmd_strip(struct userrec *u, int idx, char *par)
  2582. {
  2583. char *nick, *changes, *c, s[2];
  2584. int dest = 0, i, pls, md, ok = 0;
  2585. module_entry *me;
  2586. if (!par[0]) {
  2587. dprintf(idx, STR("Your current strip settings are: %s (%s).\n"),
  2588. stripmasktype(dcc[idx].u.chat->strip_flags),
  2589. stripmaskname(dcc[idx].u.chat->strip_flags));
  2590. return;
  2591. }
  2592. nick = newsplit(&par);
  2593. if ((nick[0] != '+') && (nick[0] != '-') && u &&
  2594. (u->flags & USER_MASTER)) {
  2595. for (i = 0; i < dcc_total; i++)
  2596. if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
  2597. !ok) {
  2598. ok = 1;
  2599. dest = i;
  2600. }
  2601. if (!ok) {
  2602. dprintf(idx, STR("No such user on the party line!\n"));
  2603. return;
  2604. }
  2605. changes = par;
  2606. } else {
  2607. changes = nick;
  2608. nick = "";
  2609. dest = idx;
  2610. }
  2611. c = changes;
  2612. if ((c[0] != '+') && (c[0] != '-'))
  2613. dcc[dest].u.chat->strip_flags = 0;
  2614. s[1] = 0;
  2615. for (pls = 1; *c; c++) {
  2616. switch (*c) {
  2617. case '+':
  2618. pls = 1;
  2619. break;
  2620. case '-':
  2621. pls = 0;
  2622. break;
  2623. default:
  2624. s[0] = *c;
  2625. md = stripmodes(s);
  2626. if (pls == 1)
  2627. dcc[dest].u.chat->strip_flags |= md;
  2628. else
  2629. dcc[dest].u.chat->strip_flags &= ~md;
  2630. }
  2631. }
  2632. if (nick[0])
  2633. putlog(LOG_CMDS, "*", STR("#%s# strip %s %s"), dcc[idx].nick, nick, changes);
  2634. else
  2635. putlog(LOG_CMDS, "*", STR("#%s# strip %s"), dcc[idx].nick, changes);
  2636. if (dest == idx) {
  2637. dprintf(idx, STR("Your strip settings are: %s (%s).\n"),
  2638. stripmasktype(dcc[idx].u.chat->strip_flags),
  2639. stripmaskname(dcc[idx].u.chat->strip_flags));
  2640. } else {
  2641. dprintf(idx, STR("Strip setting for %s: %s (%s).\n"), dcc[dest].nick,
  2642. stripmasktype(dcc[dest].u.chat->strip_flags),
  2643. stripmaskname(dcc[dest].u.chat->strip_flags));
  2644. dprintf(dest, STR("%s set your strip settings to: %s (%s).\n"), dcc[idx].nick,
  2645. stripmasktype(dcc[dest].u.chat->strip_flags),
  2646. stripmaskname(dcc[dest].u.chat->strip_flags));
  2647. }
  2648. /* Set highlight flag here so user is able to control stripping of
  2649. * bold also as intended -- dw 27/12/1999
  2650. */
  2651. /* New style autosave here too -- rtc, 09/28/1999*/
  2652. if ((me = module_find("console", 0, 0))) {
  2653. Function *func = me->funcs;
  2654. (func[CONSOLE_DOSTORE]) (dest);
  2655. }
  2656. }
  2657. static void cmd_su(struct userrec *u, int idx, char *par)
  2658. {
  2659. int atr = u ? u->flags : 0;
  2660. int ok;
  2661. struct flag_record fr = {FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
  2662. u = get_user_by_handle(userlist, par);
  2663. if (!par[0])
  2664. dprintf(idx, STR("Usage: su <user>\n"));
  2665. else if (!u)
  2666. dprintf(idx, STR("No such user.\n"));
  2667. else if (u->flags & USER_BOT)
  2668. dprintf(idx, STR("You can't su to a bot... then again, why would you wanna?\n"));
  2669. else if (dcc[idx].u.chat->su_nick)
  2670. dprintf(idx, STR("You cannot currently double .su; try .su'ing directly.\n"));
  2671. else {
  2672. get_user_flagrec(u, &fr, NULL);
  2673. ok = 1;
  2674. #ifdef HUB
  2675. if (!glob_huba(fr))
  2676. ok = 0;
  2677. #else /* !HUB */
  2678. if (ischanhub() && !glob_chuba(fr))
  2679. ok = 0;
  2680. #endif /* LEAF */
  2681. if (!ok)
  2682. dprintf(idx, STR("No party line access permitted for %s.\n"), par);
  2683. else {
  2684. correct_handle(par);
  2685. putlog(LOG_CMDS, "*", STR("#%s# su %s"), dcc[idx].nick, par);
  2686. if (!(atr & USER_OWNER) ||
  2687. ((u->flags & USER_OWNER) && (isowner(par)) &&
  2688. !(isowner(dcc[idx].nick)))) {
  2689. /* This check is only important for non-owners */
  2690. if (u_pass_match(u, "-")) {
  2691. dprintf(idx, STR("No password set for user. You may not .su to them.\n"));
  2692. return;
  2693. }
  2694. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2695. botnet_send_part_idx(idx, "");
  2696. chanout_but(-1, dcc[idx].u.chat->channel,
  2697. "*** %s left the party line.\n", dcc[idx].nick);
  2698. /* Store the old nick in the away section, for weenies who can't get
  2699. * their password right ;)
  2700. */
  2701. if (dcc[idx].u.chat->away != NULL)
  2702. nfree(dcc[idx].u.chat->away);
  2703. dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2704. strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
  2705. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2706. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2707. dcc[idx].user = u;
  2708. strcpy(dcc[idx].nick, par);
  2709. /* Display password prompt and turn off echo (send IAC WILL ECHO). */
  2710. dprintf(idx, STR("Enter password for %s%s\n"), par,
  2711. (dcc[idx].status & STAT_TELNET) ? TLN_IAC_C TLN_WILL_C
  2712. TLN_ECHO_C : "");
  2713. dcc[idx].type = &DCC_CHAT_PASS;
  2714. } else if (atr & USER_OWNER) {
  2715. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2716. botnet_send_part_idx(idx, "");
  2717. chanout_but(-1, dcc[idx].u.chat->channel,
  2718. "*** %s left the party line.\n", dcc[idx].nick);
  2719. dprintf(idx, STR("Setting your username to %s.\n"), par);
  2720. if (atr & USER_MASTER)
  2721. dcc[idx].u.chat->con_flags = conmask;
  2722. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2723. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2724. dcc[idx].user = u;
  2725. strcpy(dcc[idx].nick, par);
  2726. dcc_chatter(idx);
  2727. }
  2728. }
  2729. }
  2730. }
  2731. static void cmd_fixcodes(struct userrec *u, int idx, char *par)
  2732. {
  2733. if (dcc[idx].status & STAT_TELNET) {
  2734. dcc[idx].status |= STAT_ECHO;
  2735. dcc[idx].status &= ~STAT_TELNET;
  2736. dprintf(idx, STR("Turned off telnet codes.\n"));
  2737. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet off)"), dcc[idx].nick);
  2738. } else {
  2739. dcc[idx].status |= STAT_TELNET;
  2740. dcc[idx].status &= ~STAT_ECHO;
  2741. dprintf(idx, STR("Turned on telnet codes.\n"));
  2742. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet on)"), dcc[idx].nick);
  2743. }
  2744. }
  2745. static void cmd_page(struct userrec *u, int idx, char *par)
  2746. {
  2747. int a;
  2748. module_entry *me;
  2749. if (!par[0]) {
  2750. if (dcc[idx].status & STAT_PAGE) {
  2751. dprintf(idx, STR("Currently paging outputs to %d lines.\n"),
  2752. dcc[idx].u.chat->max_line);
  2753. } else
  2754. dprintf(idx, STR("You don't have paging on.\n"));
  2755. return;
  2756. }
  2757. a = atoi(par);
  2758. if ((!a && !par[0]) || !egg_strcasecmp(par, "off")) {
  2759. dcc[idx].status &= ~STAT_PAGE;
  2760. dcc[idx].u.chat->max_line = 0x7ffffff; /* flush_lines needs this */
  2761. while (dcc[idx].u.chat->buffer)
  2762. flush_lines(idx, dcc[idx].u.chat);
  2763. dprintf(idx, STR("Paging turned off.\n"));
  2764. putlog(LOG_CMDS, "*", STR("#%s# page off"), dcc[idx].nick);
  2765. } else if (a > 0) {
  2766. dprintf(idx, STR("Paging turned on, stopping every %d line%s.\n"), a,
  2767. (a != 1) ? "s" : "");
  2768. dcc[idx].status |= STAT_PAGE;
  2769. dcc[idx].u.chat->max_line = a;
  2770. dcc[idx].u.chat->line_count = 0;
  2771. dcc[idx].u.chat->current_lines = 0;
  2772. putlog(LOG_CMDS, "*", STR("#%s# page %d"), dcc[idx].nick, a);
  2773. } else {
  2774. dprintf(idx, STR("Usage: page <off or #>\n"));
  2775. return;
  2776. }
  2777. /* New style autosave here too -- rtc, 09/28/1999*/
  2778. if ((me = module_find("console", 0, 0))) {
  2779. Function *func = me->funcs;
  2780. (func[CONSOLE_DOSTORE]) (idx);
  2781. }
  2782. }
  2783. /* Evaluate a Tcl command, send output to a dcc user.
  2784. */
  2785. #ifdef S_TCLCMDS
  2786. static void cmd_tcl(struct userrec *u, int idx, char *msg)
  2787. {
  2788. int code;
  2789. #ifdef S_PERMONLY
  2790. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2791. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2792. return;
  2793. }
  2794. #endif /* S_PERMONLY */
  2795. putlog(LOG_CMDS, "*", STR("#%s# tcl %s"), dcc[idx].nick, msg);
  2796. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2797. code = Tcl_GlobalEval(interp, msg);
  2798. if (code == TCL_OK)
  2799. dumplots(idx, STR("Tcl: "), interp->result);
  2800. else
  2801. dumplots(idx, STR("Tcl error: "), interp->result);
  2802. }
  2803. #endif /* S_TCLCMDS */
  2804. #ifdef HUB
  2805. #ifdef S_TCLCMDS
  2806. static void cmd_nettcl(struct userrec *u, int idx, char *msg)
  2807. {
  2808. int code;
  2809. char buf[2000];
  2810. #ifdef S_PERMONLY
  2811. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2812. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2813. return;
  2814. }
  2815. #endif /* S_PERMONLY */
  2816. putlog(LOG_CMDS, "*", STR("#%s# nettcl %s"), dcc[idx].nick, msg);
  2817. egg_snprintf(buf, sizeof buf, "mt %d %s", idx, msg);
  2818. putallbots(buf);
  2819. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2820. code = Tcl_GlobalEval(interp, msg);
  2821. if (code == TCL_OK)
  2822. dumplots(idx, STR("Tcl: "), interp->result);
  2823. else
  2824. dumplots(idx, STR("Tcl error: "), interp->result);
  2825. }
  2826. #endif /* S_TCLCMDS */
  2827. static void cmd_newleaf(struct userrec *u, int idx, char *par)
  2828. {
  2829. char *handle,
  2830. *host;
  2831. struct userrec *u1;
  2832. struct bot_addr *bi;
  2833. putlog(LOG_CMDS, "*", STR("#%s# newleaf %s"), dcc[idx].nick, par);
  2834. if (!par[0]) {
  2835. dprintf(idx, STR("Usage: newleaf <handle> [host] [anotherhost]\n"));
  2836. dprintf(idx, STR(" Leafs can't link unless you specify a *!ident@ip hostmask\n"));
  2837. } else {
  2838. handle = newsplit(&par);
  2839. if (strlen(handle) > HANDLEN)
  2840. handle[HANDLEN] = 0;
  2841. if (get_user_by_handle(userlist, handle))
  2842. dprintf(idx, STR("Already got a %s user/bot\n"), handle);
  2843. else if (strchr(BADHANDCHARS, handle[0]) != NULL)
  2844. dprintf(idx, STR("You can't start a botnick with '%c'.\n"), handle[0]);
  2845. else {
  2846. char tmp[81];
  2847. userlist = adduser(userlist, handle, STR("none"), "-", USER_BOT | USER_OP);
  2848. u1 = get_user_by_handle(userlist, handle);
  2849. bi = user_malloc(sizeof(struct bot_addr));
  2850. bi->uplink = user_malloc(strlen(botnetnick) + 1);
  2851. /* strcpy(bi->uplink, botnetnick); */
  2852. strcpy(bi->uplink, "");
  2853. bi->address = user_malloc(1);
  2854. bi->address[0] = 0;
  2855. bi->telnet_port = 3333;
  2856. bi->relay_port = 3333;
  2857. bi->hublevel = 0;
  2858. set_user(&USERENTRY_BOTADDR, u1, bi);
  2859. host = newsplit(&par);
  2860. while ((host) && (host[0])) {
  2861. addhost_by_handle(handle, host);
  2862. host = newsplit(&par);
  2863. }
  2864. /* set_user(&USERENTRY_PASS, u1, SALT2); */
  2865. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  2866. set_user(&USERENTRY_ADDED, u1, tmp);
  2867. dprintf(idx, STR("Added new leaf: %s\n"), handle);
  2868. #ifdef HUB
  2869. write_userfile(idx);
  2870. #endif /* HUB */
  2871. }
  2872. }
  2873. }
  2874. static void cmd_nopass(struct userrec *u, int idx, char *par)
  2875. {
  2876. int cnt = 0;
  2877. struct userrec *cu;
  2878. char *users = nmalloc(1);
  2879. putlog(LOG_CMDS, "*", "#%s# nopass %s", dcc[idx].nick, (par && par[0]) ? par : "");
  2880. users[0] = 0;
  2881. for (cu = userlist; cu; cu = cu->next) {
  2882. if (!(cu->flags & USER_BOT)) {
  2883. if (u_pass_match(cu, "-")) {
  2884. cnt++;
  2885. users = nrealloc(users, strlen(users) + strlen(cu->handle) + 1 + 1);
  2886. strcat(users, cu->handle);
  2887. strcat(users, " ");
  2888. }
  2889. }
  2890. }
  2891. if (!cnt)
  2892. dprintf(idx, "All users have passwords set.\n");
  2893. else
  2894. dprintf(idx, "Users without passwords: %s\n", users);
  2895. nfree(users);
  2896. }
  2897. #endif /* HUB */
  2898. static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
  2899. {
  2900. char *who;
  2901. char s[UHOSTLEN];
  2902. unsigned long int expire_time = 0;
  2903. if (!par[0]) {
  2904. dprintf(idx, STR("Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n"));
  2905. return;
  2906. }
  2907. who = newsplit(&par);
  2908. if (par[0] == '%') {
  2909. char *p, *p_expire;
  2910. unsigned long int expire_foo;
  2911. p = newsplit(&par);
  2912. p_expire = p + 1;
  2913. while (*(++p) != 0) {
  2914. switch (tolower(*p)) {
  2915. case 'd':
  2916. *p = 0;
  2917. expire_foo = strtol(p_expire, NULL, 10);
  2918. if (expire_foo > 365)
  2919. expire_foo = 365;
  2920. expire_time += 86400 * expire_foo;
  2921. p_expire = p + 1;
  2922. break;
  2923. case 'h':
  2924. *p = 0;
  2925. expire_foo = strtol(p_expire, NULL, 10);
  2926. if (expire_foo > 8760)
  2927. expire_foo = 8760;
  2928. expire_time += 3600 * expire_foo;
  2929. p_expire = p + 1;
  2930. break;
  2931. case 'm':
  2932. *p = 0;
  2933. expire_foo = strtol(p_expire, NULL, 10);
  2934. if (expire_foo > 525600)
  2935. expire_foo = 525600;
  2936. expire_time += 60 * expire_foo;
  2937. p_expire = p + 1;
  2938. }
  2939. }
  2940. }
  2941. if (!par[0])
  2942. par = "requested";
  2943. else if (strlen(par) > 65)
  2944. par[65] = 0;
  2945. if (strlen(who) > UHOSTMAX - 4)
  2946. who[UHOSTMAX - 4] = 0;
  2947. /* Fix missing ! or @ BEFORE continuing */
  2948. if (!strchr(who, '!')) {
  2949. if (!strchr(who, '@'))
  2950. simple_sprintf(s, "%s!*@*", who);
  2951. else
  2952. simple_sprintf(s, "*!%s", who);
  2953. } else if (!strchr(who, '@'))
  2954. simple_sprintf(s, "%s@*", who);
  2955. else
  2956. strcpy(s, who);
  2957. if (match_ignore(s))
  2958. dprintf(idx, STR("That already matches an existing ignore.\n"));
  2959. else {
  2960. dprintf(idx, STR("Now ignoring: %s (%s)\n"), s, par);
  2961. addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
  2962. putlog(LOG_CMDS, "*", STR("#%s# +ignore %s %s"), dcc[idx].nick, s, par);
  2963. #ifdef HUB
  2964. write_userfile(idx);
  2965. #endif /* HUB */
  2966. }
  2967. }
  2968. static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
  2969. {
  2970. char buf[UHOSTLEN];
  2971. if (!par[0]) {
  2972. dprintf(idx, STR("Usage: -ignore <hostmask | ignore #>\n"));
  2973. return;
  2974. }
  2975. strncpyz(buf, par, sizeof buf);
  2976. if (delignore(buf)) {
  2977. putlog(LOG_CMDS, "*", STR("#%s# -ignore %s"), dcc[idx].nick, buf);
  2978. dprintf(idx, STR("No longer ignoring: %s\n"), buf);
  2979. #ifdef HUB
  2980. write_userfile(idx);
  2981. #endif /* HUB */
  2982. } else
  2983. dprintf(idx, STR("That ignore cannot be found.\n"));
  2984. }
  2985. static void cmd_ignores(struct userrec *u, int idx, char *par)
  2986. {
  2987. putlog(LOG_CMDS, "*", STR("#%s# ignores %s"), dcc[idx].nick, par);
  2988. tell_ignores(idx, par);
  2989. }
  2990. static void cmd_pls_user(struct userrec *u, int idx, char *par)
  2991. {
  2992. char *handle, *host;
  2993. putlog(LOG_CMDS, "*", STR("#%s# +user %s"), dcc[idx].nick, par);
  2994. if (!par[0]) {
  2995. dprintf(idx, STR("Usage: +user <handle> [hostmask]\n"));
  2996. return;
  2997. }
  2998. handle = newsplit(&par);
  2999. host = newsplit(&par);
  3000. if (strlen(handle) > HANDLEN)
  3001. handle[HANDLEN] = 0;
  3002. if (get_user_by_handle(userlist, handle))
  3003. dprintf(idx, STR("Someone already exists by that name.\n"));
  3004. else if (strchr(BADNICKCHARS, handle[0]) != NULL)
  3005. dprintf(idx, STR("You can't start a nick with '%c'.\n"), handle[0]);
  3006. else if (!egg_strcasecmp(handle, botnetnick))
  3007. dprintf(idx, STR("Hey! That's MY name!\n"));
  3008. else {
  3009. struct userrec *u2;
  3010. char tmp[50], s[16], s2[17];
  3011. userlist = adduser(userlist, handle, host, "-", USER_DEFAULT);
  3012. u2 = get_user_by_handle(userlist, handle);
  3013. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  3014. set_user(&USERENTRY_ADDED, u2, tmp);
  3015. dprintf(idx, STR("Added %s (%s) with no flags.\n"), handle, host);
  3016. while (par[0]) {
  3017. host=newsplit(&par);
  3018. set_user(&USERENTRY_HOSTS, u2, host);
  3019. dprintf(idx, STR("Added host %s to %s.\n"), host, handle);
  3020. }
  3021. make_rand_str(s, 15);
  3022. set_user(&USERENTRY_PASS, u2, s);
  3023. make_rand_str(s2, 16);
  3024. set_user(&USERENTRY_SECPASS, u2, s2);
  3025. dprintf(idx, STR("%s's initial password set to \002%s\002\n"), handle, s);
  3026. dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), handle, s2);
  3027. #ifdef HUB
  3028. write_userfile(idx);
  3029. #endif /* HUB */
  3030. }
  3031. }
  3032. static void cmd_mns_user(struct userrec *u, int idx, char *par)
  3033. {
  3034. int idx2;
  3035. char *handle;
  3036. struct userrec *u2;
  3037. module_entry *me;
  3038. putlog(LOG_CMDS, "*", STR("#%s# -user %s"), dcc[idx].nick, par);
  3039. if (!par[0]) {
  3040. dprintf(idx, STR("Usage: -user <hand>\n"));
  3041. return;
  3042. }
  3043. handle = newsplit(&par);
  3044. u2 = get_user_by_handle(userlist, handle);
  3045. if (!u2 || !u) {
  3046. dprintf(idx, STR("No such user!\n"));
  3047. return;
  3048. }
  3049. if (isowner(u2->handle)) {
  3050. dprintf(idx, STR("You can't remove a permanent bot owner!\n"));
  3051. return;
  3052. }
  3053. if ((u2->flags & USER_ADMIN) && !(isowner(u->handle))) {
  3054. dprintf(idx, STR("You can't remove an admin!\n"));
  3055. return;
  3056. }
  3057. if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  3058. dprintf(idx, STR("You can't remove a bot owner!\n"));
  3059. return;
  3060. }
  3061. if (u2->flags & USER_BOT) {
  3062. if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
  3063. dprintf(idx, STR("You can't remove share bots.\n"));
  3064. return;
  3065. }
  3066. for (idx2 = 0; idx2 < dcc_total; idx2++)
  3067. if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
  3068. !egg_strcasecmp(dcc[idx2].nick, handle))
  3069. break;
  3070. if (idx2 != dcc_total) {
  3071. dprintf(idx, STR("You can't remove a directly linked bot.\n"));
  3072. return;
  3073. }
  3074. }
  3075. if (!(u->flags & USER_MASTER) &&
  3076. !(u2->flags & USER_BOT)) {
  3077. dprintf(idx, STR("You can't remove users who aren't bots!\n"));
  3078. return;
  3079. }
  3080. if ((me = module_find("irc", 0, 0))) {
  3081. Function *func = me->funcs;
  3082. (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
  3083. }
  3084. if (deluser(handle)) {
  3085. dprintf(idx, STR("Deleted %s.\n"), handle);
  3086. #ifdef HUB
  3087. write_userfile(idx);
  3088. #endif /* HUB */
  3089. } else
  3090. dprintf(idx, STR("Failed.\n"));
  3091. }
  3092. static void cmd_pls_host(struct userrec *u, int idx, char *par)
  3093. {
  3094. char *handle, *host;
  3095. struct userrec *u2;
  3096. struct list_type *q;
  3097. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3098. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3099. module_entry *me;
  3100. putlog(LOG_CMDS, "*", STR("#%s# +host %s"), dcc[idx].nick, par);
  3101. if (!par[0]) {
  3102. dprintf(idx, STR("Usage: +host [handle] <newhostmask>\n"));
  3103. return;
  3104. }
  3105. handle = newsplit(&par);
  3106. if (par[0]) {
  3107. host = newsplit(&par);
  3108. u2 = get_user_by_handle(userlist, handle);
  3109. } else {
  3110. host = handle;
  3111. handle = dcc[idx].nick;
  3112. u2 = u;
  3113. }
  3114. if (!u2 || !u) {
  3115. dprintf(idx, STR("No such user.\n"));
  3116. return;
  3117. }
  3118. get_user_flagrec(u, &fr, NULL);
  3119. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3120. get_user_flagrec(u2, &fr2, NULL);
  3121. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3122. dprintf(idx, STR("You can't add hostmasks to non-bots.\n"));
  3123. return;
  3124. }
  3125. if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
  3126. dprintf(idx, STR("You can't add hostmasks to share bots.\n"));
  3127. return;
  3128. }
  3129. if (glob_admin(fr2) && !isowner(u->handle)) {
  3130. dprintf(idx, STR("You can't add hostmasks to an admin.\n"));
  3131. return;
  3132. }
  3133. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3134. dprintf(idx, STR("You can't add hostmasks to a bot owner/master.\n"));
  3135. return;
  3136. }
  3137. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3138. !glob_owner(fr) && !chan_owner(fr)) {
  3139. dprintf(idx, STR("You can't add hostmasks to a channel owner/master.\n"));
  3140. return;
  3141. }
  3142. if (!glob_master(fr) && !chan_master(fr)) {
  3143. dprintf(idx, STR("Permission denied.\n"));
  3144. return;
  3145. }
  3146. }
  3147. if (!chan_master(fr) && get_user_by_host(host)) {
  3148. dprintf(idx, STR("You cannot add a host matching another user!\n"));
  3149. return;
  3150. }
  3151. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  3152. if (!egg_strcasecmp(q->extra, host)) {
  3153. dprintf(idx, STR("That hostmask is already there.\n"));
  3154. return;
  3155. }
  3156. addhost_by_handle(handle, host);
  3157. update_mod(handle, dcc[idx].nick, "+host", host);
  3158. dprintf(idx, STR("Added '%s' to %s.\n"), host, handle);
  3159. if ((me = module_find("irc", 0, 0))) {
  3160. Function *func = me->funcs;
  3161. (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
  3162. }
  3163. #ifdef HUB
  3164. write_userfile(idx);
  3165. #endif /* HUB */
  3166. }
  3167. static void cmd_mns_host(struct userrec *u, int idx, char *par)
  3168. {
  3169. char *handle, *host;
  3170. struct userrec *u2;
  3171. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3172. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3173. module_entry *me;
  3174. putlog(LOG_CMDS, "*", STR("#%s# -host %s"), dcc[idx].nick, par);
  3175. if (!par[0]) {
  3176. dprintf(idx, STR("Usage: -host [handle] <hostmask>\n"));
  3177. return;
  3178. }
  3179. handle = newsplit(&par);
  3180. if (par[0]) {
  3181. host = newsplit(&par);
  3182. u2 = get_user_by_handle(userlist, handle);
  3183. } else {
  3184. host = handle;
  3185. handle = dcc[idx].nick;
  3186. u2 = u;
  3187. }
  3188. if (!u2 || !u) {
  3189. dprintf(idx, STR("No such user.\n"));
  3190. return;
  3191. }
  3192. get_user_flagrec(u, &fr, NULL);
  3193. get_user_flagrec(u2, &fr2, NULL);
  3194. /* check to see if user is +d or +k and don't let them remove hosts */
  3195. if (glob_deop(fr) || glob_kick(fr) || chan_deop(fr) || chan_kick (fr)) {
  3196. dprintf(idx, STR("You can't remove hostmasks while having the +d or +k flag.\n"));
  3197. return;
  3198. }
  3199. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3200. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3201. dprintf(idx, STR("You can't remove hostmasks from non-bots.\n"));
  3202. return;
  3203. }
  3204. if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
  3205. dprintf(idx, STR("You can't remove hostmasks from a share bot.\n"));
  3206. return;
  3207. }
  3208. if (glob_admin(fr2) && !isowner(u->handle)) {
  3209. dprintf(idx, STR("You can't remove hostmasks from an admin.\n"));
  3210. return;
  3211. }
  3212. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3213. dprintf(idx, STR("You can't remove hostmasks from a bot owner/master.\n"));
  3214. return;
  3215. }
  3216. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3217. !glob_owner(fr) && !chan_owner(fr)) {
  3218. dprintf(idx, STR("You can't remove hostmasks from a channel owner/master.\n"));
  3219. return;
  3220. }
  3221. if (!glob_master(fr) && !chan_master(fr)) {
  3222. dprintf(idx, STR("Permission denied.\n"));
  3223. return;
  3224. }
  3225. }
  3226. if (delhost_by_handle(handle, host)) {
  3227. dprintf(idx, STR("Removed '%s' from %s.\n"), host, handle);
  3228. update_mod(handle, dcc[idx].nick, "-host", host);
  3229. if ((me = module_find("irc", 0, 0))) {
  3230. Function *func = me->funcs;
  3231. (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
  3232. }
  3233. #ifdef HUB
  3234. write_userfile(idx);
  3235. #endif /* HUB */
  3236. } else
  3237. dprintf(idx, STR("Failed.\n"));
  3238. }
  3239. /* netserver */
  3240. static void cmd_netserver(struct userrec * u, int idx, char * par) {
  3241. putlog(LOG_CMDS, "*", STR("#%s# netserver"), dcc[idx].nick);
  3242. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("cursrv"));
  3243. }
  3244. static void cmd_botserver(struct userrec * u, int idx, char * par) {
  3245. putlog(LOG_CMDS, "*", STR("#%s# botserver %s"), dcc[idx].nick, par);
  3246. if (!par || !par[0]) {
  3247. dprintf(idx, STR("Usage: botserver <bot>\n"));
  3248. return;
  3249. }
  3250. if (nextbot(par)<0) {
  3251. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3252. }
  3253. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("cursrv"));
  3254. }
  3255. void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
  3256. #ifdef LEAF
  3257. char tmp[2048], cursrvname[500];
  3258. int server_online = 0;
  3259. module_entry *me;
  3260. if ((me = module_find("server", 0, 0))) {
  3261. Function *func = me->funcs;
  3262. server_online = (*(int *)(func[25]));
  3263. sprintf(cursrvname, "%s", ((char *)(func[41])));
  3264. }
  3265. if (server_online)
  3266. sprintf(tmp, "Currently: %-40s Lag: %d", cursrvname, server_lag);
  3267. // sprintf(tmp, STR("%-20s %d)"), cursrvname, server_lag);
  3268. else
  3269. sprintf(tmp, "Currently: none");
  3270. // sprintf(tmp, STR("%-20s"), "none");
  3271. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3272. #endif /* LEAF */
  3273. }
  3274. #ifdef HUB
  3275. /* netversion */
  3276. static void cmd_netversion(struct userrec * u, int idx, char * par) {
  3277. putlog(LOG_CMDS, "*", STR("#%s# netversion"), dcc[idx].nick);
  3278. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("ver"));
  3279. }
  3280. static void cmd_botversion(struct userrec * u, int idx, char * par) {
  3281. putlog(LOG_CMDS, "*", STR("#%s# botversion %s"), dcc[idx].nick, par);
  3282. if (!par || !par[0]) {
  3283. dprintf(idx, STR("Usage: botversion <bot>\n"));
  3284. return;
  3285. }
  3286. if (nextbot(par)<0) {
  3287. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3288. }
  3289. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("ver"));
  3290. }
  3291. #endif /* HUB */
  3292. void rcmd_ver(char * fbot, char * fhand, char * fidx) {
  3293. char tmp[2048];
  3294. #ifdef HAVE_UNAME
  3295. struct utsname un;
  3296. #endif /* HAVE_UNAME */
  3297. sprintf(tmp, STR("%s "), version);
  3298. #ifdef HAVE_UNAME
  3299. if (uname(&un) < 0) {
  3300. #endif /* HAVE_UNAME */
  3301. strcat(tmp, STR("(unknown OS)"));
  3302. #ifdef HAVE_UNAME
  3303. } else {
  3304. sprintf(tmp + strlen(tmp), STR("%s %s (%s)"), un.sysname, un.release, un.machine);
  3305. }
  3306. #endif /* HAVE_UNAME */
  3307. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3308. }
  3309. /* netnick, botnick */
  3310. static void cmd_netnick (struct userrec *u, int idx, char *par) {
  3311. putlog(LOG_CMDS, "*", STR("#%s# netnick"), dcc[idx].nick);
  3312. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("curnick"));
  3313. }
  3314. static void cmd_botnick(struct userrec * u, int idx, char * par) {
  3315. putlog(LOG_CMDS, "*", STR("#%s# botnick %s"), dcc[idx].nick, par);
  3316. if (!par || !par[0]) {
  3317. dprintf(idx, STR("Usage: botnick <bot>\n"));
  3318. return;
  3319. }
  3320. if (nextbot(par)<0) {
  3321. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3322. }
  3323. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("curnick"));
  3324. }
  3325. void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
  3326. #ifdef LEAF
  3327. char tmp[1024];
  3328. int server_online = 0;
  3329. module_entry *me;
  3330. if ((me = module_find("server", 0, 0))) {
  3331. Function *func = me->funcs;
  3332. server_online = (*(int *)(func[25]));
  3333. }
  3334. tmp[0] = 0;
  3335. if (server_online)
  3336. sprintf(tmp, STR("Currently: %-20s "), botname);
  3337. if (strncmp(botname, origbotname, strlen(botname)))
  3338. sprintf(tmp, STR("%sWant: %s"), tmp, origbotname);
  3339. if (!server_online)
  3340. sprintf(tmp, STR("%s(not online)"), tmp);
  3341. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3342. #endif /* LEAF */
  3343. }
  3344. /* netmsg, botmsg */
  3345. static void cmd_botmsg(struct userrec * u, int idx, char * par) {
  3346. char * tnick, * tbot;
  3347. char tmp[1024];
  3348. putlog(LOG_CMDS, "*", STR("#%s# botmsg %s"), dcc[idx].nick, par);
  3349. tbot=newsplit(&par);
  3350. tnick=newsplit(&par);
  3351. if (!par[0]) {
  3352. dprintf(idx, STR("Usage: botmsg <bot> <nick|#channel> <message>\n"));
  3353. return;
  3354. }
  3355. if (nextbot(tbot)<0) {
  3356. dprintf(idx, STR("No such bot linked\n"));
  3357. return;
  3358. }
  3359. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3360. botnet_send_cmd(botnetnick, tbot, u->handle, idx, tmp);
  3361. }
  3362. static void cmd_netmsg(struct userrec * u, int idx, char * par) {
  3363. char * tnick;
  3364. char tmp[1024];
  3365. putlog(LOG_CMDS, "*", STR("#%s# netmsg %s"), dcc[idx].nick, par);
  3366. tnick=newsplit(&par);
  3367. if (!par[0]) {
  3368. dprintf(idx, STR("Usage: netmsg <nick|#channel> <message>\n"));
  3369. return;
  3370. }
  3371. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3372. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3373. }
  3374. void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, char * par) {
  3375. #ifdef LEAF
  3376. char buf[1024], *nick;
  3377. nick=newsplit(&par);
  3378. dprintf(DP_SERVER, STR("PRIVMSG %s :%s\n"), nick, par);
  3379. if (!strcmp(tobot, botnetnick)) {
  3380. sprintf(buf, STR("Sent message to %s"), nick);
  3381. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, buf);
  3382. }
  3383. #endif /* LEAF */
  3384. }
  3385. #ifdef HUB
  3386. /* netlag */
  3387. static void cmd_netlag(struct userrec * u, int idx, char * par) {
  3388. struct timeval tv;
  3389. time_t tm;
  3390. char tmp[64];
  3391. putlog(LOG_CMDS, "*", STR("#%s# netlag"), dcc[idx].nick);
  3392. gettimeofday(&tv, NULL);
  3393. tm = (tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000);
  3394. sprintf(tmp, STR("ping %lu"), tm);
  3395. dprintf(idx, STR("Sent ping to all linked bots\n"));
  3396. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3397. }
  3398. #endif /* HUB */
  3399. void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
  3400. char tmp[64];
  3401. sprintf(tmp, STR("pong %s"), par);
  3402. botnet_send_cmd(botnetnick, frombot, fromhand, atoi(fromidx), tmp);
  3403. }
  3404. void rcmd_pong(char *frombot, char *fromhand, char *fromidx, char *par) {
  3405. int i=atoi(fromidx);
  3406. if ((i>=0) && (i<dcc_total) && (dcc[i].type==&DCC_CHAT) && (!strcmp(dcc[i].nick, fromhand))) {
  3407. struct timeval tv;
  3408. time_t tm;
  3409. gettimeofday(&tv, NULL);
  3410. tm = ((tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000)) - atoi(par);
  3411. dprintf(i, STR("Pong from %s: %i.%i seconds\n"), frombot, (tm / 100), (tm % 100));
  3412. }
  3413. }
  3414. /* exec commands */
  3415. #ifdef HUB
  3416. static void cmd_netw(struct userrec * u, int idx, char * par) {
  3417. char tmp[128];
  3418. putlog(LOG_CMDS, "*", STR("#%s# netw"), dcc[idx].nick);
  3419. strcpy(tmp, STR("exec w"));
  3420. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, tmp);
  3421. }
  3422. static void cmd_netps(struct userrec * u, int idx, char * par) {
  3423. char buf[1024];
  3424. putlog(LOG_CMDS, "*", STR("#%s# netps %s"), dcc[idx].nick, par);
  3425. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3426. putlog(LOG_WARN, "*", STR("%s attempted 'netps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3427. dprintf(idx, STR("No."));
  3428. return;
  3429. }
  3430. sprintf(buf, STR("exec ps %s"), par);
  3431. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3432. }
  3433. static void cmd_netlast(struct userrec * u, int idx, char * par) {
  3434. char buf[1024];
  3435. putlog(LOG_CMDS, "*", STR("#%s# netlast %s"), dcc[idx].nick, par);
  3436. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3437. putlog(LOG_WARN, "*", STR("%s attempted 'netlast' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3438. dprintf(idx, STR("No."));
  3439. return;
  3440. }
  3441. sprintf(buf, STR("exec last %s"), par);
  3442. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3443. }
  3444. #endif /* HUB */
  3445. void crontab_show(struct userrec * u, int idx) {
  3446. dprintf(idx, STR("Showing current crontab:\n"));
  3447. if (!exec_str(idx, STR("crontab -l | grep -v \"^#\"")))
  3448. dprintf(idx, STR("Exec failed"));
  3449. }
  3450. void crontab_del() {
  3451. char * tmpfile, *p, buf[2048];
  3452. tmpfile=nmalloc(strlen(binname)+100);
  3453. strcpy(tmpfile, binname);
  3454. if (!(p=strrchr(tmpfile, '/')))
  3455. return;
  3456. p++;
  3457. strcpy(p, STR(".ctb"));
  3458. sprintf(buf, STR("crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s"), binname, tmpfile);
  3459. if (shell_exec(buf, NULL, NULL, NULL)) {
  3460. sprintf(buf, STR("crontab %s"), tmpfile);
  3461. shell_exec(buf, NULL, NULL, NULL);
  3462. }
  3463. unlink(tmpfile);
  3464. }
  3465. static void cmd_crontab(struct userrec *u, int idx, char *par) {
  3466. char * code;
  3467. int i;
  3468. putlog(LOG_CMDS, "*", STR("#%s# crontab %s"), dcc[idx].nick, par);
  3469. if (!par[0]) {
  3470. dprintf(idx, STR("Usage: crontab <status|delete|show|new> [interval]\n"));
  3471. return;
  3472. }
  3473. code=newsplit(&par);
  3474. if (!strcmp(code, STR("status"))) {
  3475. i=crontab_exists();
  3476. if (!i)
  3477. dprintf(idx, STR("No crontab\n"));
  3478. else if (i==1)
  3479. dprintf(idx, STR("Crontabbed\n"));
  3480. else
  3481. dprintf(idx, STR("Error checking crontab status\n"));
  3482. } else if (!strcmp(code, STR("show"))) {
  3483. crontab_show(u, idx);
  3484. } else if (!strcmp(code, STR("delete"))) {
  3485. crontab_del();
  3486. i=crontab_exists();
  3487. if (!i)
  3488. dprintf(idx, STR("No crontab\n"));
  3489. else if (i==1)
  3490. dprintf(idx, STR("Crontabbed\n"));
  3491. else
  3492. dprintf(idx, STR("Error checking crontab status\n"));
  3493. } else if (!strcmp(code, STR("new"))) {
  3494. i=atoi(par);
  3495. if ((i<=0) || (i>60))
  3496. i=10;
  3497. crontab_create(i);
  3498. i=crontab_exists();
  3499. if (!i)
  3500. dprintf(idx, STR("No crontab\n"));
  3501. else if (i==1)
  3502. dprintf(idx, STR("Crontabbed\n"));
  3503. else
  3504. dprintf(idx, STR("Error checking crontab status\n"));
  3505. } else {
  3506. dprintf(idx, STR("Usage: crontab status|delete|show|new [interval]\n"));
  3507. }
  3508. }
  3509. #ifdef HUB
  3510. static void cmd_netcrontab(struct userrec * u, int idx, char * par) {
  3511. char buf[1024], *cmd;
  3512. putlog(LOG_CMDS, "*", STR("#%s# netcrontab %s"), dcc[idx].nick, par);
  3513. cmd=newsplit(&par);
  3514. if ((strcmp(cmd, STR("status")) && strcmp(cmd, STR("show")) && strcmp(cmd, STR("delete")) && strcmp(cmd, STR("new")))) {
  3515. dprintf(idx, STR("Usage: netcrontab <status|delete|show|new> [interval]\n"));
  3516. return;
  3517. }
  3518. egg_snprintf(buf, sizeof buf, STR("exec crontab %s %s"), cmd, par);
  3519. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3520. }
  3521. #endif /* HUB */
  3522. void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
  3523. char * cmd, scmd[512], *out, *err;
  3524. struct passwd *pw;
  3525. cmd=newsplit(&par);
  3526. scmd[0]=0;
  3527. if (!strcmp(cmd, "w")) {
  3528. strcpy(scmd, "w");
  3529. } else if (!strcmp(cmd, STR("last"))) {
  3530. char user[20];
  3531. if (par[0]) {
  3532. strncpyz(user, par, sizeof(user));
  3533. } else {
  3534. pw = getpwuid(geteuid());
  3535. if (!pw) return;
  3536. strncpyz(user, pw->pw_name, sizeof(user));
  3537. }
  3538. if (!user[0]) {
  3539. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Can't determine user id for process"));
  3540. return;
  3541. }
  3542. sprintf(scmd, STR("last %s"), user);
  3543. } else if (!strcmp(cmd, STR("ps"))) {
  3544. sprintf(scmd, STR("ps %s"), par);
  3545. } else if (!strcmp(cmd, STR("raw"))) {
  3546. sprintf(scmd, STR("%s"), par);
  3547. } else if (!strcmp(cmd, STR("kill"))) {
  3548. sprintf(scmd, STR("kill %s"), par);
  3549. } else if (!strcmp(cmd, STR("crontab"))) {
  3550. char * code=newsplit(&par);
  3551. scmd[0]=0;
  3552. if (!strcmp(code, STR("show"))) {
  3553. strcpy(scmd, STR("crontab -l | grep -v \"^#\""));
  3554. } else if (!strcmp(code, STR("delete"))) {
  3555. crontab_del();
  3556. } else if (!strcmp(code, STR("new"))) {
  3557. int i=atoi(par);
  3558. if ((i<=0) || (i>60))
  3559. i=10;
  3560. crontab_create(i);
  3561. }
  3562. if (!scmd[0]) {
  3563. char s[200];
  3564. int i;
  3565. i=crontab_exists();
  3566. if (!i)
  3567. sprintf(s, STR("No crontab"));
  3568. else if (i==1)
  3569. sprintf(s, STR("Crontabbed"));
  3570. else
  3571. sprintf(s, STR("Error checking crontab status"));
  3572. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, s);
  3573. }
  3574. }
  3575. if (!scmd[0])
  3576. return;
  3577. if (shell_exec(scmd, NULL, &out, &err)) {
  3578. if (out) {
  3579. char * p, * np;
  3580. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Result:"));
  3581. p=out;
  3582. while (p && p[0]) {
  3583. np=strchr(p, '\n');
  3584. if (np)
  3585. *np++=0;
  3586. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3587. p=np;
  3588. }
  3589. nfree(out);
  3590. }
  3591. if (err) {
  3592. char * p, * np;
  3593. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Errors:"));
  3594. p=err;
  3595. while (p && p[0]) {
  3596. np=strchr(p, '\n');
  3597. if (np)
  3598. *np++=0;
  3599. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3600. p=np;
  3601. }
  3602. nfree(err);
  3603. }
  3604. } else {
  3605. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("exec failed"));
  3606. }
  3607. }
  3608. static void cmd_botjump(struct userrec * u, int idx, char * par) {
  3609. char *tbot, buf[1024];
  3610. putlog(LOG_CMDS, "*", STR("#%s# botjump %s"), dcc[idx].nick, par);
  3611. tbot=newsplit(&par);
  3612. if (!tbot[0]) {
  3613. dprintf(idx, STR("Usage: botjump <bot> [server [port [pass]]]\n"));
  3614. return;
  3615. }
  3616. if (nextbot(tbot)<0) {
  3617. dprintf(idx, STR("No such linked bot\n"));
  3618. return;
  3619. }
  3620. sprintf(buf, STR("jump %s"), par);
  3621. botnet_send_cmd(botnetnick, tbot, dcc[idx].nick, idx, buf);
  3622. }
  3623. void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
  3624. #ifdef LEAF
  3625. char * other;
  3626. module_entry *me;
  3627. Function *func;
  3628. int port, default_port = 0;
  3629. if (!(me = module_find("server", 0, 0)) )
  3630. return;
  3631. func = me->funcs;
  3632. default_port = (*(int *)(func[24]));
  3633. if (par[0]) {
  3634. other = newsplit(&par);
  3635. port = atoi(newsplit(&par));
  3636. if (!port)
  3637. port = default_port;
  3638. strncpyz(((char *)(func[20])), other, 120); //newserver
  3639. (*(int *)(func[21])) = port; //newserverport
  3640. strncpyz(((char *)(func[22])), par, 120); //newserverpass
  3641. }
  3642. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Jumping..."));
  3643. (*(int *)(func[23])) = 0; //cycle_time
  3644. (func[SERVER_NUKESERVER]) ("jumping...");
  3645. #endif /* LEAF */
  3646. }
  3647. /* "Remotable" commands */
  3648. void gotremotecmd (char * forbot, char * frombot, char * fromhand, char * fromidx, char * cmd) {
  3649. char * par = cmd;
  3650. cmd=newsplit(&par);
  3651. if (!strcmp(cmd, STR("exec"))) {
  3652. rcmd_exec(frombot, fromhand, fromidx, par);
  3653. } else if (!strcmp(cmd, STR("curnick"))) {
  3654. rcmd_curnick(frombot, fromhand, fromidx);
  3655. } else if (!strcmp(cmd, STR("cursrv"))) {
  3656. rcmd_cursrv(frombot, fromhand, fromidx);
  3657. } else if (!strcmp(cmd, STR("jump"))) {
  3658. rcmd_jump(frombot, fromhand, fromidx, par);
  3659. } else if (!strcmp(cmd, STR("msg"))) {
  3660. rcmd_msg(forbot, frombot, fromhand, fromidx, par);
  3661. } else if (!strcmp(cmd, STR("ver"))) {
  3662. rcmd_ver(frombot, fromhand, fromidx);
  3663. } else if (!strcmp(cmd, STR("ping"))) {
  3664. rcmd_ping(frombot, fromhand, fromidx, par);
  3665. } else if (!strcmp(cmd, STR("pong"))) {
  3666. rcmd_pong(frombot, fromhand, fromidx, par);
  3667. } else if (!strcmp(cmd, STR("die"))) {
  3668. exit(0);
  3669. } else {
  3670. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Unrecognized remote command"));
  3671. }
  3672. }
  3673. void gotremotereply (char *frombot, char *tohand, char *toidx, char *ln) {
  3674. int idx = atoi(toidx);
  3675. if ((idx >= 0) && (idx < dcc_total) && (dcc[idx].type == &DCC_CHAT) && (!strcmp(dcc[idx].nick, tohand))) {
  3676. char *buf = nmalloc(strlen(frombot) + 2 + 1);
  3677. sprintf(buf, "(%s)", frombot);
  3678. dprintf(idx, STR("%-13s %s\n"), buf, ln);
  3679. nfree(buf);
  3680. }
  3681. }
  3682. static void cmd_traffic(struct userrec *u, int idx, char *par)
  3683. {
  3684. unsigned long itmp, itmp2;
  3685. dprintf(idx, STR("Traffic since last restart\n"));
  3686. dprintf(idx, "==========================\n");
  3687. if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
  3688. itraffic_irc_today > 0) {
  3689. dprintf(idx, "IRC:\n");
  3690. dprintf(idx, " out: %s", btos(otraffic_irc + otraffic_irc_today));
  3691. dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
  3692. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_irc_today));
  3693. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
  3694. }
  3695. if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
  3696. itraffic_bn_today > 0) {
  3697. dprintf(idx, STR("Botnet:\n"));
  3698. dprintf(idx, " out: %s", btos(otraffic_bn + otraffic_bn_today));
  3699. dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
  3700. dprintf(idx, " in: %s", btos(itraffic_bn + itraffic_bn_today));
  3701. dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
  3702. }
  3703. if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
  3704. itraffic_dcc_today > 0) {
  3705. dprintf(idx, STR("Partyline:\n"));
  3706. itmp = otraffic_dcc + otraffic_dcc_today;
  3707. itmp2 = otraffic_dcc_today;
  3708. dprintf(idx, " out: %s", btos(itmp));
  3709. dprintf(idx, " (%s today)\n", btos(itmp2));
  3710. dprintf(idx, " in: %s", btos(itraffic_dcc + itraffic_dcc_today));
  3711. dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
  3712. }
  3713. if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
  3714. itraffic_trans_today > 0) {
  3715. dprintf(idx, STR("Transfer.mod:\n"));
  3716. dprintf(idx, " out: %s", btos(otraffic_trans + otraffic_trans_today));
  3717. dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
  3718. dprintf(idx, " in: %s", btos(itraffic_trans + itraffic_trans_today));
  3719. dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
  3720. }
  3721. if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
  3722. dprintf(idx, "Misc:\n");
  3723. dprintf(idx, " out: %s", btos(otraffic_unknown + otraffic_unknown_today));
  3724. dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
  3725. dprintf(idx, " in: %s", btos(itraffic_unknown + itraffic_unknown_today));
  3726. dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
  3727. }
  3728. dprintf(idx, "---\n");
  3729. dprintf(idx, "Total:\n");
  3730. itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans
  3731. + otraffic_unknown + otraffic_irc_today + otraffic_bn_today
  3732. + otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
  3733. itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
  3734. + otraffic_trans_today + otraffic_unknown_today;
  3735. dprintf(idx, " out: %s", btos(itmp));
  3736. dprintf(idx, " (%s today)\n", btos(itmp2));
  3737. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc
  3738. + itraffic_trans + itraffic_unknown + itraffic_irc_today
  3739. + itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today
  3740. + itraffic_unknown_today));
  3741. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today
  3742. + itraffic_dcc_today + itraffic_trans_today
  3743. + itraffic_unknown_today));
  3744. putlog(LOG_CMDS, "*", STR("#%s# traffic"), dcc[idx].nick);
  3745. }
  3746. static char traffictxt[20];
  3747. static char *btos(unsigned long bytes)
  3748. {
  3749. char unit[10];
  3750. float xbytes;
  3751. sprintf(unit, "Bytes");
  3752. xbytes = bytes;
  3753. if (xbytes > 1024.0) {
  3754. sprintf(unit, "KBytes");
  3755. xbytes = xbytes / 1024.0;
  3756. }
  3757. if (xbytes > 1024.0) {
  3758. sprintf(unit, "MBytes");
  3759. xbytes = xbytes / 1024.0;
  3760. }
  3761. if (xbytes > 1024.0) {
  3762. sprintf(unit, "GBytes");
  3763. xbytes = xbytes / 1024.0;
  3764. }
  3765. if (xbytes > 1024.0) {
  3766. sprintf(unit, "TBytes");
  3767. xbytes = xbytes / 1024.0;
  3768. }
  3769. if (bytes > 1024)
  3770. sprintf(traffictxt, "%.2f %s", xbytes, unit);
  3771. else
  3772. sprintf(traffictxt, "%lu Bytes", bytes);
  3773. return traffictxt;
  3774. }
  3775. static void cmd_whoami(struct userrec *u, int idx, char *par)
  3776. {
  3777. putlog(LOG_CMDS, "*", STR("#%s# whoami"), dcc[idx].nick);
  3778. dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
  3779. }
  3780. /* DCC CHAT COMMANDS
  3781. */
  3782. /* Function call should be:
  3783. * int cmd_whatever(idx,"parameters");
  3784. * As with msg commands, function is responsible for any logging.
  3785. */
  3786. cmd_t C_dcc[] =
  3787. {
  3788. {"+host", "m|m", (Function) cmd_pls_host, NULL},
  3789. {"+ignore", "m", (Function) cmd_pls_ignore, NULL},
  3790. {"+user", "m", (Function) cmd_pls_user, NULL},
  3791. #ifdef HUB
  3792. {"-bot", "a", (Function) cmd_mns_user, NULL},
  3793. #endif /* HUB */
  3794. {"-host", "", (Function) cmd_mns_host, NULL},
  3795. {"-ignore", "m", (Function) cmd_mns_ignore, NULL},
  3796. {"-user", "m", (Function) cmd_mns_user, NULL},
  3797. {"addlog", "mo|o", (Function) cmd_addlog, NULL},
  3798. /* {"putlog", "mo|o", (Function) cmd_addlog, NULL}, */
  3799. {"about", "", (Function) cmd_about, NULL},
  3800. {"away", "", (Function) cmd_away, NULL},
  3801. {"back", "", (Function) cmd_back, NULL},
  3802. #ifdef HUB
  3803. {"backup", "m|m", (Function) cmd_backup, NULL},
  3804. {"binds", "a", (Function) cmd_binds, NULL},
  3805. {"boot", "m", (Function) cmd_boot, NULL},
  3806. {"botconfig", "n", (Function) cmd_botconfig, NULL},
  3807. {"botinfo", "", (Function) cmd_botinfo, NULL},
  3808. {"bots", "m", (Function) cmd_bots, NULL},
  3809. {"downbots", "m", (Function) cmd_downbots, NULL},
  3810. {"bottree", "n", (Function) cmd_bottree, NULL},
  3811. {"chaddr", "a", (Function) cmd_chaddr, NULL},
  3812. #endif /* HUB */
  3813. {"chat", "", (Function) cmd_chat, NULL},
  3814. {"chattr", "m|m", (Function) cmd_chattr, NULL},
  3815. #ifdef HUB
  3816. {"chhandle", "m", (Function) cmd_chhandle, NULL},
  3817. {"chnick", "m", (Function) cmd_chhandle, NULL, 1},
  3818. {"chpass", "m", (Function) cmd_chpass, NULL},
  3819. {"chsecpass", "n", (Function) cmd_chsecpass, NULL},
  3820. #ifdef S_DCCPASS
  3821. {"cmdpass", "a", (Function) cmd_cmdpass, NULL},
  3822. #endif /* S_DCCPASS */
  3823. #endif /* HUB */
  3824. {"color", "", (Function) cmd_color, NULL},
  3825. {"comment", "m|m", (Function) cmd_comment, NULL},
  3826. #ifdef HUB
  3827. {"config", "n", (Function) cmd_config, NULL},
  3828. #endif /* HUB */
  3829. {"console", "-|-", (Function) cmd_console, NULL},
  3830. {"date", "", (Function) cmd_date, NULL},
  3831. #ifdef HUB
  3832. {"dccstat", "a", (Function) cmd_dccstat, NULL},
  3833. #endif /* HUB */
  3834. {"debug", "a", (Function) cmd_debug, NULL},
  3835. {"die", "n", (Function) cmd_die, NULL},
  3836. {"echo", "", (Function) cmd_echo, NULL},
  3837. {"fixcodes", "", (Function) cmd_fixcodes, NULL},
  3838. {"handle", "", (Function) cmd_handle, NULL},
  3839. {"nohelp", "-|-", (Function) cmd_nohelp, NULL, 1},
  3840. {"help", "-|-", (Function) cmd_help, NULL},
  3841. {"ignores", "m", (Function) cmd_ignores, NULL},
  3842. #ifdef HUB
  3843. {"link", "n", (Function) cmd_link, NULL},
  3844. #endif /* HUB */
  3845. {"match", "m|m", (Function) cmd_match, NULL},
  3846. {"me", "", (Function) cmd_me, NULL},
  3847. {"motd", "", (Function) cmd_motd, NULL},
  3848. #ifdef HUB
  3849. #ifdef S_TCLCMDS
  3850. {"nettcl", "a", (Function) cmd_nettcl, NULL},
  3851. #endif /* S_TCLCMDS */
  3852. {"newleaf", "n", (Function) cmd_newleaf, NULL},
  3853. {"nopass", "m", (Function) cmd_nopass, NULL},
  3854. #endif /* HUB */
  3855. {"newpass", "", (Function) cmd_newpass, NULL},
  3856. {"secpass", "", (Function) cmd_secpass, NULL},
  3857. {"nick", "", (Function) cmd_handle, NULL, 1},
  3858. {"page", "", (Function) cmd_page, NULL},
  3859. {"quit", "", (Function) NULL, NULL},
  3860. {"relay", "i", (Function) cmd_relay, NULL},
  3861. #ifdef HUB
  3862. {"reload", "m|m", (Function) cmd_reload, NULL},
  3863. #endif /* HUB */
  3864. {"restart", "m", (Function) cmd_restart, NULL},
  3865. #ifdef HUB
  3866. {"save", "m|m", (Function) cmd_save, NULL},
  3867. #endif /* HUB */
  3868. {"simul", "a", (Function) cmd_simul, NULL},
  3869. {"status", "m|m", (Function) cmd_status, NULL},
  3870. {"strip", "", (Function) cmd_strip, NULL},
  3871. {"su", "a", (Function) cmd_su, NULL},
  3872. #ifdef S_TCLCMDS
  3873. {"tcl", "a", (Function) cmd_tcl, NULL},
  3874. #endif /* S_TCLCMDS */
  3875. #ifdef HUB
  3876. {"trace", "n", (Function) cmd_trace, NULL},
  3877. #endif /* HUB */
  3878. {"traffic", "m", (Function) cmd_traffic, NULL},
  3879. {"unlink", "m", (Function) cmd_unlink, NULL},
  3880. {"update", "a", (Function) cmd_update, NULL},
  3881. #ifdef HUB
  3882. {"netcrontab", "a", (Function) cmd_netcrontab, NULL},
  3883. #endif /* HUB */
  3884. {"uptime", "m|m", (Function) cmd_uptime, NULL},
  3885. {"crontab", "a", (Function) cmd_crontab, NULL},
  3886. #ifdef HUB
  3887. {"vbottree", "n", (Function) cmd_vbottree, NULL},
  3888. {"who", "n", (Function) cmd_who, NULL},
  3889. #endif /* HUB */
  3890. {"whois", "", (Function) cmd_whois, NULL},
  3891. {"whom", "", (Function) cmd_whom, NULL},
  3892. {"whoami", "", (Function) cmd_whoami, NULL},
  3893. {"botjump", "m", (Function) cmd_botjump, NULL},
  3894. {"botmsg", "o", (Function) cmd_botmsg, NULL},
  3895. {"netmsg", "n", (Function) cmd_netmsg, NULL},
  3896. {"botnick", "m", (Function) cmd_botnick, NULL},
  3897. {"netnick", "m", (Function) cmd_netnick, NULL},
  3898. #ifdef HUB
  3899. {"netw", "n", (Function) cmd_netw, NULL},
  3900. {"netps", "n", (Function) cmd_netps, NULL},
  3901. {"netlast", "n", (Function) cmd_netlast, NULL},
  3902. {"netlag", "m", (Function) cmd_netlag, NULL},
  3903. #endif /* HUB */
  3904. {"botserver", "m", (Function) cmd_botserver, NULL},
  3905. {"netserver", "m", (Function) cmd_netserver, NULL},
  3906. #ifdef HUB
  3907. {"botversion", "o", (Function) cmd_botversion, NULL},
  3908. {"netversion", "o", (Function) cmd_netversion, NULL},
  3909. #endif /* HUB */
  3910. {"userlist", "m", (Function) cmd_userlist, NULL},
  3911. {"ps", "n", (Function) cmd_ps, NULL},
  3912. {"last", "n", (Function) cmd_last, NULL},
  3913. {"exec", "a", (Function) cmd_exec, NULL},
  3914. {"w", "n", (Function) cmd_w, NULL},
  3915. {"channels", "", (Function) cmd_channels, NULL},
  3916. {"randstring", "", (Function) cmd_randstring, NULL},
  3917. #ifdef HUB
  3918. {"botcmd", "i", (Function) cmd_botcmd, NULL},
  3919. {"bc", "i", (Function) cmd_botcmd, NULL},
  3920. {"hublevel", "a", (Function) cmd_hublevel, NULL},
  3921. {"lagged", "m", (Function) cmd_lagged, NULL},
  3922. {"uplink", "a", (Function) cmd_uplink, NULL},
  3923. #endif /* HUB */
  3924. {NULL, NULL, NULL, NULL}
  3925. };