cmds.c 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171
  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 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("..with credits and thanks to the following:\n"));
  579. dprintf(idx, STR("(written from a base of Eggdrop 1.6.12)\n\n"));
  580. dprintf(idx, STR("Eggdrop team for developing such a great bot to code off of.\n"));
  581. dprintf(idx, STR("Einride and ievil for taking eggdrop1.4.3 and making their very effecient botpack Ghost.\n"));
  582. dprintf(idx, STR("SFC for providing compile shells, continuous input, feature suggestions, and testing.\n"));
  583. dprintf(idx, STR("xmage for beta testing.\n"));
  584. dprintf(idx, STR("ryguy for beta testing, providing code, finding bugs, and providing input.\n"));
  585. dprintf(idx, STR("passwd for beta testing, and his dedication to finding bugs.\n"));
  586. dprintf(idx, STR("pgpkeys for suggestions.\n"));
  587. dprintf(idx, STR("qFox for providing an mIRC $md5() alias, not requiring a dll or >6.03\n"));
  588. dprintf(idx, STR("Sith_Lord helping test ipv6 on the bot (admin@elitepackets.com)\n"));
  589. dprintf(idx, STR("Excelsior for finding a bug on BSD with the ipv6.\n"));
  590. dprintf(idx, STR("syt for giving me inspiration to code a more secure bot.\n\n\n"));
  591. dprintf(idx, STR("Mystikal for finding various bugs.\n"));
  592. dprintf(idx, STR("Blackjac for helping with the bx auth script with his Sentinel script.\n"));
  593. dprintf(idx, STR("The following botpacks gave me inspiration and ideas (no code):\n"));
  594. dprintf(idx, STR("awptic by lordoptic\n"));
  595. dprintf(idx, STR("optikz by ryguy and lordoptic\n"));
  596. dprintf(idx, STR("celdrop by excelsior\n"));
  597. dprintf(idx, STR("genocide by various\n"));
  598. dprintf(idx, STR("tfbot by warknight and loslinux\n"));
  599. }
  600. static void cmd_away(struct userrec *u, int idx, char *par)
  601. {
  602. if (strlen(par) > 60)
  603. par[60] = 0;
  604. set_away(idx, par);
  605. }
  606. static void cmd_back(struct userrec *u, int idx, char *par)
  607. {
  608. not_away(idx);
  609. }
  610. static void cmd_newpass(struct userrec *u, int idx, char *par)
  611. {
  612. char *new, pass[16];
  613. putlog(LOG_CMDS, "*", STR("#%s# newpass..."), dcc[idx].nick);
  614. if (!par[0]) {
  615. dprintf(idx, STR("Usage: newpass <newpassword>\n"));
  616. return;
  617. }
  618. new = newsplit(&par);
  619. if (!strcmp(new, "rand")) {
  620. make_rand_str(pass, 15);
  621. } else {
  622. if (strlen(new) < 6) {
  623. dprintf(idx, STR("Please use at least 6 characters.\n"));
  624. return;
  625. } else {
  626. sprintf(pass, "%s", new);
  627. }
  628. }
  629. if (strlen(pass) > 15)
  630. pass[15] = 0;
  631. if (!goodpass(pass, idx, NULL))
  632. return;
  633. set_user(&USERENTRY_PASS, u, pass);
  634. dprintf(idx, STR("Changed your password to: %s\n"), pass);
  635. #ifdef HUB
  636. write_userfile(idx);
  637. #endif /* HUB */
  638. }
  639. static void cmd_secpass(struct userrec *u, int idx, char *par)
  640. {
  641. char *new, pass[17];
  642. putlog(LOG_CMDS, "*", STR("#%s# secpass..."), dcc[idx].nick);
  643. if (!par[0]) {
  644. dprintf(idx, STR("Usage: secpass <newsecpass>\nIf you use \"rand\" as the secpass, a random pass will be chosen.\n"));
  645. return;
  646. }
  647. new = newsplit(&par);
  648. if (!strcmp(new, "rand")) {
  649. make_rand_str(pass, 16);
  650. } else {
  651. if (strlen(new) < 6) {
  652. dprintf(idx, STR("Please use at least 6 characters.\n"));
  653. return;
  654. } else {
  655. sprintf(pass, "%s", new);
  656. }
  657. }
  658. if (strlen(pass) > 16)
  659. pass[16] = 0;
  660. set_user(&USERENTRY_SECPASS, u, pass);
  661. dprintf(idx, STR("Changed your secpass to: %s.\n"), pass);
  662. #ifdef HUB
  663. write_userfile(idx);
  664. #endif /* HUB */
  665. }
  666. #ifdef HUB
  667. static void cmd_bots(struct userrec *u, int idx, char *par)
  668. {
  669. putlog(LOG_CMDS, "*", STR("#%s# bots"), dcc[idx].nick);
  670. tell_bots(idx);
  671. }
  672. static void cmd_downbots(struct userrec *u, int idx, char *par)
  673. {
  674. struct userrec *u2;
  675. int cnt = 0, tot = 0;
  676. char work[128] = "";
  677. putlog(LOG_CMDS, "*", STR("#%s# downbots"), dcc[idx].nick);
  678. for (u2 = userlist; u2; u2 = u2->next) {
  679. if (u2->flags & USER_BOT) {
  680. if (egg_strcasecmp(u2->handle, botnetnick)) {
  681. if (nextbot(u2->handle) == -1) {
  682. strcat(work, u2->handle);
  683. cnt++;
  684. tot++;
  685. if (cnt == 10) {
  686. dprintf(idx, STR("Down bots: %s\n"), work);
  687. work[0] = 0;
  688. cnt = 0;
  689. } else
  690. strcat(work, " ");
  691. }
  692. }
  693. }
  694. }
  695. if (work[0])
  696. dprintf(idx, STR("Down bots: %s\n"), work);
  697. dprintf(idx, STR("(Total down: %d)\n"), tot);
  698. }
  699. static void cmd_bottree(struct userrec *u, int idx, char *par)
  700. {
  701. putlog(LOG_CMDS, "*", STR("#%s# bottree"), dcc[idx].nick);
  702. tell_bottree(idx, 0);
  703. }
  704. static void cmd_vbottree(struct userrec *u, int idx, char *par)
  705. {
  706. putlog(LOG_CMDS, "*", STR("#%s# vbottree"), dcc[idx].nick);
  707. tell_bottree(idx, 1);
  708. }
  709. #endif /* HUB */
  710. int my_cmp (const mycmds *c1, const mycmds *c2)
  711. {
  712. return strcmp (c1->name, c2->name);
  713. }
  714. static void cmd_nohelp(struct userrec *u, int idx, char *par)
  715. {
  716. int i;
  717. char *buf = nmalloc(1);
  718. buf[0] = 0;
  719. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  720. for (i = 0; i < cmdi; i++) {
  721. int o, found = 0;
  722. for (o = 0; (help[o].cmd) && (help[o].desc); o++)
  723. if (!egg_strcasecmp(help[o].cmd, cmds[i].name)) found++;
  724. if (!found) {
  725. buf = nrealloc(buf, strlen(buf) + 2 + strlen(cmds[i].name) + 1);
  726. strcat(buf, cmds[i].name);
  727. strcat(buf, ", ");
  728. }
  729. }
  730. buf[strlen(buf) - 1] = 0;
  731. dumplots(idx, "", buf);
  732. }
  733. static void cmd_help(struct userrec *u, int idx, char *par)
  734. {
  735. char flg[100];
  736. int fnd = 0, done = 0, nowild = 0;
  737. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  738. char *fcats, temp[100], buf[2046], match[20];
  739. egg_snprintf(temp, sizeof temp, "a|- a|a n|- n|n m|- m|m mo|o m|o i|- o|o o|- p|- -|-");
  740. fcats = temp;
  741. putlog(LOG_CMDS, "*", STR("#%s# help %s"), dcc[idx].nick, par);
  742. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  743. build_flags(flg, &fr, NULL);
  744. if (!par[0]) {
  745. sprintf(match, "*");
  746. } else {
  747. if (!strchr(par, '*') && !strchr(par, '?'))
  748. nowild++;
  749. sprintf(match, "%s", newsplit(&par));
  750. }
  751. if (!nowild)
  752. dprintf(idx, STR("Showing help topics matching '%s' for flags: (%s)\n"), match, flg);
  753. qsort(cmds, cmdi, sizeof(mycmds), (int (*)()) &my_cmp);
  754. buf[0] = 0;
  755. /* even if we have nowild, we loop to conserve code/space */
  756. while (!done) {
  757. int i = 0, end = 0, first = 1, n, hi;
  758. char *flag;
  759. flag = newsplit(&fcats);
  760. if (!flag[0])
  761. done = 1;
  762. for (n = 0; n < cmdi; n++) { /* loop each command */
  763. if (!flagrec_ok(&cmds[n].flags, &fr) || !wild_match(match, cmds[n].name))
  764. continue;
  765. fnd++;
  766. if (nowild) {
  767. flg[0] = 0;
  768. build_flags(flg, &(cmds[n].flags), NULL);
  769. dprintf(idx, STR("Showing you help for '%s' (%s):\n"), match, flg);
  770. for (hi = 0; (help[hi].cmd) && (help[hi].desc); hi++) {
  771. if (!egg_strcasecmp(match, help[hi].cmd)) {
  772. if (help[hi].garble)
  773. showhelp(idx, &fr, degarble(help[hi].garble, help[hi].desc));
  774. else
  775. showhelp(idx, &fr, help[hi].desc);
  776. }
  777. }
  778. done = 1;
  779. break;
  780. } else {
  781. flg[0] = 0;
  782. build_flags(flg, &(cmds[n].flags), NULL);
  783. if (!strcmp(flg, flag)) {
  784. if (first) {
  785. dprintf(idx, "%s\n", buf[0] ? buf : "");
  786. dprintf(idx, STR("# DCC (%s)\n"), flag);
  787. sprintf(buf, " ");
  788. }
  789. if (end && !first) {
  790. dprintf(idx, "%s\n", buf[0] ? buf : "");
  791. /* we dumped the buf to dprintf, now start a new one... */
  792. sprintf(buf, " ");
  793. }
  794. sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmds[n].name);
  795. first = 0;
  796. end = 0;
  797. i++;
  798. }
  799. if (i >= 5) {
  800. end = 1;
  801. i = 0;
  802. }
  803. }
  804. }
  805. }
  806. if (buf && buf[0])
  807. dprintf(idx, "%s\n", buf);
  808. if (fnd)
  809. dprintf(idx, STR("--End help listing\n"));
  810. if (!strcmp(match, "*")) {
  811. dprintf(idx, STR("For individual command help, type: %shelp <command>\n"), dcc_prefix);
  812. } else if (!fnd) {
  813. dprintf(idx, STR("No match for '%s'.\n"), match);
  814. }
  815. dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to possibly see more commands.\n"), dcc_prefix);
  816. }
  817. static void cmd_addlog(struct userrec *u, int idx, char *par)
  818. {
  819. putlog(LOG_CMDS, "*", STR("#%s# addlog %s"), dcc[idx].nick, par);
  820. putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
  821. if (!par[0]) {
  822. dprintf(idx, STR("Usage: addlog <message>\n"));
  823. return;
  824. }
  825. dprintf(idx, STR("Placed entry in the log file.\n"));
  826. }
  827. #ifdef HUB
  828. static void cmd_who(struct userrec *u, int idx, char *par)
  829. {
  830. int i;
  831. if (par[0]) {
  832. if (dcc[idx].u.chat->channel < 0) {
  833. dprintf(idx, STR("You have chat turned off.\n"));
  834. return;
  835. }
  836. putlog(LOG_CMDS, "*", STR("#%s# who %s"), dcc[idx].nick, par);
  837. if (!egg_strcasecmp(par, botnetnick))
  838. tell_who(u, idx, dcc[idx].u.chat->channel);
  839. else {
  840. i = nextbot(par);
  841. if (i < 0) {
  842. dprintf(idx, STR("That bot isn't connected.\n"));
  843. } else if (dcc[idx].u.chat->channel > 99999)
  844. dprintf(idx, STR("You are on a local channel.\n"));
  845. else {
  846. char s[40];
  847. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
  848. dcc[idx].nick, botnetnick);
  849. botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
  850. }
  851. }
  852. } else {
  853. putlog(LOG_CMDS, "*", STR("#%s# who"), dcc[idx].nick);
  854. if (dcc[idx].u.chat->channel < 0)
  855. tell_who(u, idx, 0);
  856. else
  857. tell_who(u, idx, dcc[idx].u.chat->channel);
  858. }
  859. }
  860. #endif /* HUB */
  861. static void cmd_whois(struct userrec *u, int idx, char *par)
  862. {
  863. if (!par[0]) {
  864. dprintf(idx, STR("Usage: whois <handle>\n"));
  865. return;
  866. }
  867. putlog(LOG_CMDS, "*", STR("#%s# whois %s"), dcc[idx].nick, par);
  868. tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
  869. }
  870. static void cmd_match(struct userrec *u, int idx, char *par)
  871. {
  872. int start = 1, limit = 20;
  873. char *s, *s1, *chname;
  874. if (!par[0]) {
  875. dprintf(idx, STR("Usage: match <nick/host> [[skip] count]\n"));
  876. return;
  877. }
  878. putlog(LOG_CMDS, "*", STR("#%s# match %s"), dcc[idx].nick, par);
  879. s = newsplit(&par);
  880. if (strchr(CHANMETA, par[0]) != NULL)
  881. chname = newsplit(&par);
  882. else
  883. chname = "";
  884. if (atoi(par) > 0) {
  885. s1 = newsplit(&par);
  886. if (atoi(par) > 0) {
  887. start = atoi(s1);
  888. limit = atoi(par);
  889. } else
  890. limit = atoi(s1);
  891. }
  892. tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
  893. chname);
  894. }
  895. static void cmd_update(struct userrec *u, int idx, char *par)
  896. {
  897. putlog(LOG_CMDS, "*", STR("#%s# update %s"), dcc[idx].nick, par);
  898. #ifdef LEAF
  899. if (!localhub)
  900. dprintf(idx, STR("Please use this command on the first listed in the conf for this user@box\n"));
  901. #endif /* LEAF */
  902. if (!par[0])
  903. dprintf(idx, STR("Usage: update <binname>\n"));
  904. updatebin(idx, par, 0);
  905. }
  906. static void cmd_uptime(struct userrec *u, int idx, char *par)
  907. {
  908. putlog(LOG_CMDS, "*", STR("#%s# uptime"), dcc[idx].nick);
  909. tell_verbose_uptime(idx);
  910. }
  911. static void cmd_userlist(struct userrec *u, int idx, char *par)
  912. {
  913. int cnt = 0, tt = 0;
  914. putlog(LOG_CMDS, "*", STR("#%s# userlist"), dcc[idx].nick);
  915. for (u=userlist;u;u=u->next) {
  916. if ((u->flags & USER_BOT) && (u->flags & USER_CHANHUB)) {
  917. if (cnt)
  918. dprintf(idx, ", ");
  919. else
  920. dprintf(idx, STR("Chathubs: "));
  921. dprintf(idx, u->handle);
  922. cnt++;
  923. tt++;
  924. if (cnt == 15) {
  925. dprintf(idx, "\n");
  926. cnt=0;
  927. }
  928. }
  929. }
  930. if (cnt)
  931. dprintf(idx, "\n");
  932. cnt=0;
  933. #ifdef HUB
  934. for (u=userlist;u;u=u->next) {
  935. if (!(u->flags & USER_BOT) && (u->flags & USER_ADMIN)) {
  936. if (cnt)
  937. dprintf(idx, ", ");
  938. else
  939. dprintf(idx, STR("Admins : "));
  940. dprintf(idx, u->handle);
  941. cnt++;
  942. tt++;
  943. if (cnt == 15) {
  944. dprintf(idx, "\n");
  945. cnt=0;
  946. }
  947. }
  948. }
  949. if (cnt)
  950. dprintf(idx, "\n");
  951. cnt=0;
  952. for (u=userlist;u;u=u->next) {
  953. if (!(u->flags & (USER_BOT | USER_ADMIN)) && (u->flags & USER_OWNER)) {
  954. if (cnt)
  955. dprintf(idx, ", ");
  956. else
  957. dprintf(idx, STR("Owners : "));
  958. dprintf(idx, u->handle);
  959. cnt++;
  960. tt++;
  961. if (cnt == 15) {
  962. dprintf(idx, "\n");
  963. cnt=0;
  964. }
  965. }
  966. }
  967. if (cnt)
  968. dprintf(idx, "\n");
  969. cnt=0;
  970. for (u=userlist;u;u=u->next) {
  971. if (!(u->flags & (USER_BOT | USER_OWNER)) && (u->flags & USER_MASTER)) {
  972. if (cnt)
  973. dprintf(idx, ", ");
  974. else
  975. dprintf(idx, STR("Masters : "));
  976. dprintf(idx, u->handle);
  977. cnt++;
  978. tt++;
  979. if (cnt == 15) {
  980. dprintf(idx, "\n");
  981. cnt=0;
  982. }
  983. }
  984. }
  985. if (cnt)
  986. dprintf(idx, "\n");
  987. cnt=0;
  988. #endif /* HUB */
  989. for (u=userlist;u;u=u->next) {
  990. #ifdef HUB
  991. if (!(u->flags & (USER_BOT | USER_MASTER)) && (u->flags & USER_OP)) {
  992. #else /* !HUB */
  993. if (!(u->flags & USER_BOT) && (u->flags & USER_OP)) {
  994. #endif /* HUB */
  995. if (cnt)
  996. dprintf(idx, ", ");
  997. else
  998. dprintf(idx, STR("Ops : "));
  999. dprintf(idx, u->handle);
  1000. cnt++;
  1001. tt++;
  1002. if (cnt == 15) {
  1003. dprintf(idx, "\n");
  1004. cnt=0;
  1005. }
  1006. }
  1007. }
  1008. if (cnt)
  1009. dprintf(idx, "\n");
  1010. cnt=0;
  1011. for (u=userlist;u;u=u->next) {
  1012. if (!(u->flags & (USER_BOT | USER_OP))) {
  1013. if (cnt)
  1014. dprintf(idx, ", ");
  1015. else
  1016. dprintf(idx, STR("Users : "));
  1017. dprintf(idx, u->handle);
  1018. cnt++;
  1019. tt++;
  1020. if (cnt==15) {
  1021. dprintf(idx, "\n");
  1022. cnt=0;
  1023. }
  1024. }
  1025. }
  1026. if (cnt)
  1027. dprintf(idx, "\n");
  1028. cnt=0;
  1029. dprintf(idx, STR("Total users: %d\n"), tt);
  1030. }
  1031. static void cmd_channels(struct userrec *u, int idx, char *par) {
  1032. putlog(LOG_CMDS, "*", STR("#%s# channels %s"), dcc[idx].nick, par);
  1033. if (par[0] && (u->flags & USER_MASTER)) {
  1034. struct userrec *user;
  1035. user = get_user_by_handle(userlist, par);
  1036. if (user)
  1037. show_channels(idx, par);
  1038. else
  1039. dprintf(idx, STR("There is no user by that name.\n"));
  1040. } else
  1041. show_channels(idx, NULL);
  1042. if ((u->flags & USER_MASTER))
  1043. dprintf(idx, STR("You can also %schannels <user>\n"), dcc_prefix);
  1044. }
  1045. static void cmd_status(struct userrec *u, int idx, char *par)
  1046. {
  1047. int atr = u ? u->flags : 0;
  1048. if (!egg_strcasecmp(par, "all")) {
  1049. if (!(atr & USER_MASTER)) {
  1050. dprintf(idx, STR("You do not have Bot Master privileges.\n"));
  1051. return;
  1052. }
  1053. putlog(LOG_CMDS, "*", STR("#%s# status all"), dcc[idx].nick);
  1054. tell_verbose_status(idx);
  1055. tell_mem_status_dcc(idx);
  1056. dprintf(idx, "\n");
  1057. tell_settings(idx);
  1058. do_module_report(idx, 1, NULL);
  1059. } else {
  1060. putlog(LOG_CMDS, "*", STR("#%s# status"), dcc[idx].nick);
  1061. tell_verbose_status(idx);
  1062. tell_mem_status_dcc(idx);
  1063. do_module_report(idx, 0, NULL);
  1064. }
  1065. }
  1066. #ifdef HUB
  1067. static void cmd_dccstat(struct userrec *u, int idx, char *par)
  1068. {
  1069. putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
  1070. tell_dcc(idx);
  1071. }
  1072. #endif /* HUB */
  1073. static void cmd_boot(struct userrec *u, int idx, char *par)
  1074. {
  1075. int i, ok = 0;
  1076. char *who;
  1077. struct userrec *u2;
  1078. if (!par[0]) {
  1079. dprintf(idx, STR("Usage: boot nick[@bot]\n"));
  1080. return;
  1081. }
  1082. who = newsplit(&par);
  1083. if (strchr(who, '@') != NULL) {
  1084. char whonick[HANDLEN + 1];
  1085. splitcn(whonick, who, '@', HANDLEN + 1);
  1086. if (!egg_strcasecmp(who, botnetnick)) {
  1087. cmd_boot(u, idx, whonick);
  1088. return;
  1089. }
  1090. if (remote_boots > 0) {
  1091. i = nextbot(who);
  1092. if (i < 0) {
  1093. dprintf(idx, STR("No such bot connected.\n"));
  1094. return;
  1095. }
  1096. botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
  1097. who, par[0] ? par : dcc[idx].nick);
  1098. putlog(LOG_BOTS, "*", STR("#%s# boot %s@%s (%s)"), dcc[idx].nick, whonick,
  1099. who, par[0] ? par : dcc[idx].nick);
  1100. } else
  1101. dprintf(idx, STR("Remote boots are disabled here.\n"));
  1102. return;
  1103. }
  1104. for (i = 0; i < dcc_total; i++)
  1105. if (!egg_strcasecmp(dcc[i].nick, who)
  1106. && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
  1107. u2 = get_user_by_handle(userlist, dcc[i].nick);
  1108. if (u2 && (u2->flags & USER_OWNER)
  1109. && egg_strcasecmp(dcc[idx].nick, who)) {
  1110. dprintf(idx, STR("You can't boot a bot owner.\n"));
  1111. return;
  1112. }
  1113. if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
  1114. dprintf(idx, STR("You can't boot a bot master.\n"));
  1115. return;
  1116. }
  1117. dprintf(idx, STR("Booted %s from the party line.\n"), dcc[i].nick);
  1118. putlog(LOG_CMDS, "*", STR("#%s# boot %s %s"), dcc[idx].nick, who, par);
  1119. do_boot(i, dcc[idx].nick, par);
  1120. ok = 1;
  1121. }
  1122. if (!ok)
  1123. dprintf(idx, STR("Who? No such person on the party line.\n"));
  1124. }
  1125. static void cmd_console(struct userrec *u, int idx, char *par)
  1126. {
  1127. char *nick, s[2], s1[512];
  1128. int dest = 0, i, ok = 0, pls, md;
  1129. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1130. module_entry *me;
  1131. struct chanset_t *chan;
  1132. if (!par[0]) {
  1133. dprintf(idx, STR("Your console is %s: %s (%s).\n"),
  1134. dcc[idx].u.chat->con_chan,
  1135. masktype(dcc[idx].u.chat->con_flags),
  1136. maskname(dcc[idx].u.chat->con_flags));
  1137. return;
  1138. }
  1139. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  1140. strcpy(s1, par);
  1141. nick = newsplit(&par);
  1142. /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
  1143. * he doesn't use IRCnet ++rtc.
  1144. */
  1145. if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
  1146. for (i = 0; i < dcc_total; i++)
  1147. if (!egg_strcasecmp(nick, dcc[i].nick) &&
  1148. (dcc[i].type == &DCC_CHAT) && (!ok)) {
  1149. ok = 1;
  1150. dest = i;
  1151. }
  1152. if (!ok) {
  1153. dprintf(idx, STR("No such user on the party line!\n"));
  1154. return;
  1155. }
  1156. nick[0] = 0;
  1157. } else
  1158. dest = idx;
  1159. if (!nick[0])
  1160. nick = newsplit(&par);
  1161. /* Consider modeless channels, starting with '+' */
  1162. if ((nick [0] == '+' && findchan_by_dname(nick)) ||
  1163. (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
  1164. chan = findchan_by_dname(nick);
  1165. if (strcmp(nick, "*") && !chan) {
  1166. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1167. return;
  1168. }
  1169. get_user_flagrec(u, &fr, nick);
  1170. if (private(fr, findchan_by_dname(nick), PRIV_OP)) {
  1171. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1172. return;
  1173. }
  1174. if (!chk_op(fr, findchan_by_dname(nick))) {
  1175. dprintf(idx, STR("You don't have op or master access to channel %s.\n"), nick);
  1176. return;
  1177. }
  1178. strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
  1179. nick[0] = 0;
  1180. if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
  1181. /* Consoling to another channel for self */
  1182. dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
  1183. }
  1184. if (!nick[0])
  1185. nick = newsplit(&par);
  1186. pls = 1;
  1187. if (nick[0]) {
  1188. if ((nick[0] != '+') && (nick[0] != '-'))
  1189. dcc[dest].u.chat->con_flags = 0;
  1190. for (; *nick; nick++) {
  1191. if (*nick == '+')
  1192. pls = 1;
  1193. else if (*nick == '-')
  1194. pls = 0;
  1195. else {
  1196. s[0] = *nick;
  1197. s[1] = 0;
  1198. md = logmodes(s);
  1199. if ((dest == idx) && !glob_master(fr) && pls) {
  1200. if (chan_master(fr))
  1201. md &= ~(LOG_FILES | LOG_DEBUG);
  1202. else
  1203. md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_WALL |
  1204. LOG_DEBUG);
  1205. }
  1206. if (!glob_owner(fr) && pls)
  1207. md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE | LOG_ERRORS | LOG_GETIN | LOG_WARN);
  1208. if (!glob_master(fr) && pls)
  1209. md &= ~LOG_BOTS;
  1210. if (pls)
  1211. dcc[dest].u.chat->con_flags |= md;
  1212. else
  1213. dcc[dest].u.chat->con_flags &= ~md;
  1214. }
  1215. }
  1216. }
  1217. putlog(LOG_CMDS, "*", STR("#%s# console %s"), dcc[idx].nick, s1);
  1218. if (dest == idx) {
  1219. dprintf(idx, STR("Set your console to %s: %s (%s).\n"),
  1220. dcc[idx].u.chat->con_chan,
  1221. masktype(dcc[idx].u.chat->con_flags),
  1222. maskname(dcc[idx].u.chat->con_flags));
  1223. } else {
  1224. dprintf(idx, STR("Set console of %s to %s: %s (%s).\n"), dcc[dest].nick,
  1225. dcc[dest].u.chat->con_chan,
  1226. masktype(dcc[dest].u.chat->con_flags),
  1227. maskname(dcc[dest].u.chat->con_flags));
  1228. dprintf(dest, STR("%s set your console to %s: %s (%s).\n"), dcc[idx].nick,
  1229. dcc[dest].u.chat->con_chan,
  1230. masktype(dcc[dest].u.chat->con_flags),
  1231. maskname(dcc[dest].u.chat->con_flags));
  1232. }
  1233. /* New style autosave -- drummer,07/25/1999*/
  1234. if ((me = module_find("console", 0, 0))) {
  1235. Function *func = me->funcs;
  1236. (func[CONSOLE_DOSTORE]) (dest);
  1237. }
  1238. }
  1239. static void cmd_date(struct userrec *u, int idx, char *par)
  1240. {
  1241. char date[50], utctime[50], ltime[50];
  1242. putlog(LOG_CMDS, "*", "#%s# date", dcc[idx].nick);
  1243. egg_strftime(date, sizeof date, "%c %Z", localtime(&now));
  1244. #ifndef S_UTCTIME
  1245. sprintf(ltime, "<-- This time is used on the bot.");
  1246. #endif /* !S_UTCTIME */
  1247. dprintf(idx, "%s %s\n", date, ltime[0] ? ltime : "");
  1248. egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
  1249. #ifdef S_UTCTIME
  1250. sprintf(utctime, "<-- This time is used on the bot.");
  1251. #endif /* S_UTCTIME */
  1252. dprintf(idx, "%s %s\n", date, utctime[0] ? utctime : "");
  1253. }
  1254. #ifdef HUB
  1255. static void cmd_chhandle(struct userrec *u, int idx, char *par)
  1256. {
  1257. char hand[HANDLEN + 1], newhand[HANDLEN + 1];
  1258. int i, atr = u ? u->flags : 0, atr2;
  1259. struct userrec *u2;
  1260. strncpyz(hand, newsplit(&par), sizeof hand);
  1261. strncpyz(newhand, newsplit(&par), sizeof newhand);
  1262. if (!hand[0] || !newhand[0]) {
  1263. dprintf(idx, STR("Usage: chhandle <oldhandle> <newhandle>\n"));
  1264. return;
  1265. }
  1266. for (i = 0; i < strlen(newhand); i++)
  1267. if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
  1268. newhand[i] = '?';
  1269. if (strchr(BADHANDCHARS, newhand[0]) != NULL)
  1270. dprintf(idx, STR("Bizarre quantum forces prevent nicknames from starting with '%c'.\n"),
  1271. newhand[0]);
  1272. else if (get_user_by_handle(userlist, newhand) &&
  1273. egg_strcasecmp(hand, newhand))
  1274. dprintf(idx, STR("Somebody is already using %s.\n"), newhand);
  1275. else {
  1276. u2 = get_user_by_handle(userlist, hand);
  1277. atr2 = u2 ? u2->flags : 0;
  1278. if (!(atr & USER_MASTER) && !(atr2 & USER_BOT))
  1279. dprintf(idx, STR("You can't change handles for non-bots.\n"));
  1280. else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
  1281. dprintf(idx, STR("You can't change share bot's nick.\n"));
  1282. else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
  1283. egg_strcasecmp(dcc[idx].nick, hand))
  1284. dprintf(idx, STR("You can't change a bot owner's handle.\n"));
  1285. else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
  1286. dprintf(idx, STR("You can't change a permanent bot owner's handle.\n"));
  1287. else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
  1288. nextbot(hand) != -1))
  1289. dprintf(idx, STR("Hey! That's MY name!\n"));
  1290. else if (change_handle(u2, newhand)) {
  1291. putlog(LOG_CMDS, "*", STR("#%s# chhandle %s %s"), dcc[idx].nick,
  1292. hand, newhand);
  1293. dprintf(idx, STR("Changed.\n"));
  1294. } else
  1295. dprintf(idx, STR("Failed.\n"));
  1296. #ifdef HUB
  1297. write_userfile(idx);
  1298. #endif /* HUB */
  1299. }
  1300. }
  1301. #endif /* HUB */
  1302. static void cmd_handle(struct userrec *u, int idx, char *par)
  1303. {
  1304. char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
  1305. int i;
  1306. strncpyz(newhandle, newsplit(&par), sizeof newhandle);
  1307. if (!newhandle[0]) {
  1308. dprintf(idx, STR("Usage: handle <new-handle>\n"));
  1309. return;
  1310. }
  1311. for (i = 0; i < strlen(newhandle); i++)
  1312. if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
  1313. newhandle[i] = '?';
  1314. if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
  1315. dprintf(idx, STR("Bizarre quantum forces prevent handle from starting with '%c'.\n"),
  1316. newhandle[0]);
  1317. } else if (get_user_by_handle(userlist, newhandle) &&
  1318. egg_strcasecmp(dcc[idx].nick, newhandle)) {
  1319. dprintf(idx, STR("Somebody is already using %s.\n"), newhandle);
  1320. } else if (!egg_strcasecmp(newhandle, botnetnick)) {
  1321. dprintf(idx, STR("Hey! That's MY name!\n"));
  1322. } else {
  1323. strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
  1324. if (change_handle(u, newhandle)) {
  1325. putlog(LOG_CMDS, "*", STR("#%s# handle %s"), oldhandle, newhandle);
  1326. dprintf(idx, STR("Okay, changed.\n"));
  1327. } else
  1328. dprintf(idx, STR("Failed.\n"));
  1329. #ifdef HUB
  1330. write_userfile(idx);
  1331. #endif /* HUB */
  1332. }
  1333. }
  1334. #ifdef HUB
  1335. static void cmd_chpass(struct userrec *u, int idx, char *par)
  1336. {
  1337. char *handle, *new, pass[16];
  1338. int atr = u ? u->flags : 0, l;
  1339. if (!par[0])
  1340. dprintf(idx, STR("Usage: chpass <handle> [password]\n"));
  1341. else {
  1342. handle = newsplit(&par);
  1343. u = get_user_by_handle(userlist, handle);
  1344. if (!u)
  1345. dprintf(idx, STR("No such user.\n"));
  1346. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1347. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1348. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1349. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1350. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1351. egg_strcasecmp(handle, dcc[idx].nick))
  1352. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1353. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1354. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1355. else if (!par[0]) {
  1356. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [nothing]"), dcc[idx].nick,
  1357. handle);
  1358. set_user(&USERENTRY_PASS, u, NULL);
  1359. dprintf(idx, STR("Removed password.\n"));
  1360. } else {
  1361. int good = 0;
  1362. l = strlen(new = newsplit(&par));
  1363. if (l > 15)
  1364. new[15] = 0;
  1365. if (!strcmp(new, "rand")) {
  1366. make_rand_str(pass, 15);
  1367. good = 1;
  1368. } else {
  1369. if (goodpass(new, idx, NULL)) {
  1370. sprintf(pass, "%s", new);
  1371. good = 1;
  1372. }
  1373. }
  1374. if (strlen(pass) > 15)
  1375. pass[15] = 0;
  1376. if (good) {
  1377. set_user(&USERENTRY_PASS, u, pass);
  1378. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick, handle);
  1379. dprintf(idx, STR("Password for '%s' changed to: %s\n"), handle, pass);
  1380. #ifdef HUB
  1381. write_userfile(idx);
  1382. #endif /* HUB */
  1383. }
  1384. }
  1385. }
  1386. }
  1387. static void cmd_chsecpass(struct userrec *u, int idx, char *par)
  1388. {
  1389. char *handle, *new, pass[17];
  1390. int atr = u ? u->flags : 0, l;
  1391. if (!par[0])
  1392. dprintf(idx, STR("Usage: chsecpass <handle> [secpass/rand]\n"));
  1393. else {
  1394. handle = newsplit(&par);
  1395. u = get_user_by_handle(userlist, handle);
  1396. if (!u)
  1397. dprintf(idx, STR("No such user.\n"));
  1398. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1399. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1400. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1401. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1402. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1403. egg_strcasecmp(handle, dcc[idx].nick))
  1404. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1405. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1406. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1407. else if (!par[0]) {
  1408. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [nothing]"), dcc[idx].nick,
  1409. handle);
  1410. set_user(&USERENTRY_SECPASS, u, NULL);
  1411. dprintf(idx, STR("Removed secpass.\n"));
  1412. } else {
  1413. l = strlen(new = newsplit(&par));
  1414. if (l > 16)
  1415. new[16] = 0;
  1416. if (!strcmp(new, "rand")) {
  1417. make_rand_str(pass, 16);
  1418. } else {
  1419. if (strlen(new) < 6) {
  1420. dprintf(idx, STR("Please use at least 6 characters.\n"));
  1421. return;
  1422. } else {
  1423. sprintf(pass, "%s", new);
  1424. }
  1425. }
  1426. if (strlen(pass) > 16)
  1427. pass[16] = 0;
  1428. set_user(&USERENTRY_SECPASS, u, pass);
  1429. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [something]"), dcc[idx].nick, handle);
  1430. dprintf(idx, STR("Secpass for '%s' changed to: %s\n"), handle, pass);
  1431. #ifdef HUB
  1432. write_userfile(idx);
  1433. #endif /* HUB */
  1434. }
  1435. }
  1436. }
  1437. static void cmd_botcmd(struct userrec *u, int idx, char *par)
  1438. {
  1439. tand_t *tbot;
  1440. int cnt = 0;
  1441. char *botm = NULL, *cmd = NULL;
  1442. botm = newsplit(&par);
  1443. cmd = newsplit(&par);
  1444. if (!botm[0] || !cmd[0]) {
  1445. dprintf(idx, STR("Usage: botcmd bot cmd params\n"));
  1446. return;
  1447. }
  1448. /* the rest of the cmd will be logged remotely */
  1449. putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);
  1450. if (!strcmp(botm, "*") && (!strcmp(botm, "di") || !strcmp(botm, "die"))) {
  1451. dprintf(idx, STR("Not a good idea.\n"));
  1452. return;
  1453. }
  1454. for (tbot = tandbot; tbot; tbot = tbot->next) {
  1455. if (wild_match(botm, tbot->bot)) {
  1456. cnt++;
  1457. send_remote_simul(idx, tbot->bot, cmd, par ? par : "");
  1458. }
  1459. }
  1460. if (!cnt) {
  1461. dprintf(idx, STR("No bot matching '%s' linked\n"), botm);
  1462. return;
  1463. }
  1464. }
  1465. static void cmd_hublevel(struct userrec *u, int idx, char *par)
  1466. {
  1467. char *handle, *level;
  1468. struct bot_addr *bi, *obi;
  1469. struct userrec *u1;
  1470. putlog(LOG_CMDS, "*", STR("#%s# hublevel %s"), dcc[idx].nick, par);
  1471. if (!par[0]) {
  1472. dprintf(idx, STR("Usage: hublevel <bot> <level>\n"));
  1473. return;
  1474. }
  1475. handle = newsplit(&par);
  1476. level = newsplit(&par);
  1477. u1 = get_user_by_handle(userlist, handle);
  1478. if (!u1 || !(u1->flags & USER_BOT)) {
  1479. dprintf(idx, STR("Useful only for bots.\n"));
  1480. return;
  1481. }
  1482. dprintf(idx, STR("Changed bot's hublevel.\n"));
  1483. obi = get_user(&USERENTRY_BOTADDR, u1);
  1484. bi = user_malloc(sizeof(struct bot_addr));
  1485. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1486. strcpy(bi->uplink, obi->uplink);
  1487. bi->address = user_malloc(strlen(obi->address) + 1);
  1488. strcpy(bi->address, obi->address);
  1489. bi->telnet_port = obi->telnet_port;
  1490. bi->relay_port = obi->relay_port;
  1491. bi->hublevel = atoi(level);
  1492. set_user(&USERENTRY_BOTADDR, u1, bi);
  1493. #ifdef HUB
  1494. write_userfile(idx);
  1495. #endif /* HUB */
  1496. }
  1497. static void cmd_uplink(struct userrec *u, int idx, char *par)
  1498. {
  1499. char *handle, *uplink;
  1500. struct bot_addr *bi, *obi;
  1501. struct userrec *u1;
  1502. putlog(LOG_CMDS, "*", STR("#%s# uplink %s"), dcc[idx].nick, par);
  1503. if (!par[0]) {
  1504. dprintf(idx, STR("Usage: uplink <bot> [uplink]\n"));
  1505. return;
  1506. }
  1507. handle = newsplit(&par);
  1508. uplink = newsplit(&par);
  1509. if (!uplink)
  1510. uplink = "";
  1511. u1 = get_user_by_handle(userlist, handle);
  1512. if (!u1 || !(u1->flags & USER_BOT)) {
  1513. dprintf(idx, STR("Useful only for bots.\n"));
  1514. return;
  1515. }
  1516. dprintf(idx, STR("Changed bot's uplink.\n"));
  1517. obi = get_user(&USERENTRY_BOTADDR, u1);
  1518. bi = user_malloc(sizeof(struct bot_addr));
  1519. bi->uplink = user_malloc(strlen(uplink) + 1);
  1520. strcpy(bi->uplink, uplink);
  1521. bi->address = user_malloc(strlen(obi->address) + 1);
  1522. strcpy(bi->address, obi->address);
  1523. bi->telnet_port = obi->telnet_port;
  1524. bi->relay_port = obi->relay_port;
  1525. bi->hublevel = obi->hublevel;
  1526. set_user(&USERENTRY_BOTADDR, u1, bi);
  1527. #ifdef HUB
  1528. write_userfile(idx);
  1529. #endif /* HUB */
  1530. }
  1531. static void cmd_chaddr(struct userrec *u, int idx, char *par)
  1532. {
  1533. int telnet_port = 3333, relay_port = 3333;
  1534. #ifdef USE_IPV6
  1535. char *handle, *addr, *p, *q, *r;
  1536. #else
  1537. char *handle, *addr, *p, *q;
  1538. #endif /* USE_IPV6 */
  1539. struct bot_addr *bi, *obi;
  1540. struct userrec *u1;
  1541. handle = newsplit(&par);
  1542. if (!par[0]) {
  1543. dprintf(idx, STR("Usage: chaddr <bot> <address[:telnet-port[/relay-port]]>\n"));
  1544. return;
  1545. }
  1546. addr = newsplit(&par);
  1547. if (strlen(addr) > UHOSTMAX)
  1548. addr[UHOSTMAX] = 0;
  1549. u1 = get_user_by_handle(userlist, handle);
  1550. if (!u1 || !(u1->flags & USER_BOT)) {
  1551. dprintf(idx, STR("This command is only useful for tandem bots.\n"));
  1552. return;
  1553. }
  1554. if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
  1555. dprintf(idx, STR("You can't change a share bot's address.\n"));
  1556. return;
  1557. }
  1558. putlog(LOG_CMDS, "*", STR("#%s# chaddr %s %s"), dcc[idx].nick, handle, addr);
  1559. dprintf(idx, STR("Changed bot's address.\n"));
  1560. obi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1561. bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1562. if (bi) {
  1563. telnet_port = bi->telnet_port;
  1564. relay_port = bi->relay_port;
  1565. }
  1566. bi = user_malloc(sizeof(struct bot_addr));
  1567. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1568. strcpy(bi->uplink, obi->uplink);
  1569. bi->hublevel = obi->hublevel;
  1570. q = strchr(addr, ':');
  1571. if (!q) {
  1572. bi->address = user_malloc(strlen(addr) + 1);
  1573. strcpy(bi->address, addr);
  1574. bi->telnet_port = telnet_port;
  1575. bi->relay_port = relay_port;
  1576. } else {
  1577. #ifdef USE_IPV6
  1578. r = strchr(addr, '[');
  1579. if (r) { /* ipv6 notation [3ffe:80c0:225::] */
  1580. *addr++;
  1581. r = strchr(addr, ']');
  1582. bi->address = user_malloc(r - addr + 1);
  1583. strncpyz(bi->address, addr, r - addr + 1);
  1584. addr = r;
  1585. *addr++;
  1586. } else {
  1587. bi->address = user_malloc(q - addr + 1);
  1588. strncpyz(bi->address, addr, q - addr + 1);
  1589. }
  1590. q = strchr(addr, ':');
  1591. if (q) {
  1592. p = q + 1;
  1593. bi->telnet_port = atoi(p);
  1594. q = strchr(p, '/');
  1595. if (!q) {
  1596. bi->relay_port = telnet_port;
  1597. } else {
  1598. bi->relay_port = atoi(q + 1);
  1599. }
  1600. }
  1601. #else /* !USE_IPV6 */
  1602. bi->address = user_malloc(q - addr + 1);
  1603. strncpyz(bi->address, addr, q - addr + 1);
  1604. p = q + 1;
  1605. bi->telnet_port = atoi(p);
  1606. q = strchr(p, '/');
  1607. if (!q)
  1608. bi->relay_port = bi->telnet_port;
  1609. else
  1610. bi->relay_port = atoi(q + 1);
  1611. #endif /* USE_IPV6 */
  1612. }
  1613. set_user(&USERENTRY_BOTADDR, u1, bi);
  1614. #ifdef HUB
  1615. write_userfile(idx);
  1616. #endif /* HUB */
  1617. }
  1618. #endif /* HUB */
  1619. static void cmd_comment(struct userrec *u, int idx, char *par)
  1620. {
  1621. char *handle;
  1622. struct userrec *u1;
  1623. handle = newsplit(&par);
  1624. if (!par[0]) {
  1625. dprintf(idx, STR("Usage: comment <handle> <newcomment/none>\n"));
  1626. return;
  1627. }
  1628. u1 = get_user_by_handle(userlist, handle);
  1629. if (!u1) {
  1630. dprintf(idx, STR("No such user!\n"));
  1631. return;
  1632. }
  1633. if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
  1634. egg_strcasecmp(handle, dcc[idx].nick)) {
  1635. dprintf(idx, STR("You can't change comment on a bot owner.\n"));
  1636. return;
  1637. }
  1638. putlog(LOG_CMDS, "*", STR("#%s# comment %s %s"), dcc[idx].nick, handle, par);
  1639. if (!egg_strcasecmp(par, "none")) {
  1640. dprintf(idx, STR("Okay, comment blanked.\n"));
  1641. set_user(&USERENTRY_COMMENT, u1, NULL);
  1642. return;
  1643. }
  1644. dprintf(idx, STR("Changed comment.\n"));
  1645. update_mod(handle, dcc[idx].nick, "comment", NULL);
  1646. set_user(&USERENTRY_COMMENT, u1, par);
  1647. #ifdef HUB
  1648. write_userfile(idx);
  1649. #endif /* HUB */
  1650. }
  1651. static void cmd_randstring(struct userrec *u, int idx, char *par)
  1652. {
  1653. int len;
  1654. char *rand;
  1655. if (!par[0]) {
  1656. dprintf(idx, "Usage: randstring <len>\n");
  1657. return;
  1658. }
  1659. putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
  1660. len = atoi(par);
  1661. rand = nmalloc(len + 1);
  1662. make_rand_str(rand, len);
  1663. dprintf(idx, STR("string: %s\n"), rand);
  1664. nfree(rand);
  1665. }
  1666. static void cmd_restart(struct userrec *u, int idx, char *par)
  1667. {
  1668. putlog(LOG_CMDS, "*", STR("#%s# restart"), dcc[idx].nick);
  1669. #ifdef HUB
  1670. write_userfile(idx);
  1671. #endif /* HUB */
  1672. #ifdef LEAF
  1673. {
  1674. module_entry *me;
  1675. if ((me = module_find("server", 0, 0))) {
  1676. Function *func = me->funcs;
  1677. (func[SERVER_NUKESERVER]) ("Restarting...");
  1678. }
  1679. }
  1680. #endif /* LEAF */
  1681. botnet_send_chat(-1, botnetnick, "Restarting...");
  1682. botnet_send_bye();
  1683. fatal("Restarting...", 1);
  1684. usleep(2000 * 500);
  1685. bg_send_quit(BG_ABORT);
  1686. unlink(pid_file); //if this fails it is ok, cron will restart the bot, *hopefully*
  1687. system(binname); //start new bot.
  1688. exit(0);
  1689. }
  1690. #ifdef HUB
  1691. static void cmd_reload(struct userrec *u, int idx, char *par)
  1692. {
  1693. putlog(LOG_CMDS, "*", STR("#%s# reload"), dcc[idx].nick);
  1694. dprintf(idx, STR("Reloading user file...\n"));
  1695. reload();
  1696. }
  1697. #endif /* HUB */
  1698. static void cmd_die(struct userrec *u, int idx, char *par)
  1699. {
  1700. char s1[1024], s2[1024];
  1701. putlog(LOG_CMDS, "*", STR("#%s# die %s"), dcc[idx].nick, par);
  1702. if (par[0]) {
  1703. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (%s: %s)"), dcc[idx].nick, par);
  1704. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (%s)"), dcc[idx].nick, dcc[idx].host, par);
  1705. strncpyz(quit_msg, par, 1024);
  1706. } else {
  1707. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (Authorized by %s)"), dcc[idx].nick);
  1708. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (request)"), dcc[idx].nick, dcc[idx].host);
  1709. strncpyz(quit_msg, dcc[idx].nick, 1024);
  1710. }
  1711. kill_bot(s1, s2);
  1712. }
  1713. static void cmd_debug(struct userrec *u, int idx, char *par)
  1714. {
  1715. putlog(LOG_CMDS, "*", STR("#%s# debug"), dcc[idx].nick);
  1716. debug_mem_to_dcc(idx);
  1717. }
  1718. static void cmd_simul(struct userrec *u, int idx, char *par)
  1719. {
  1720. char *nick;
  1721. int i, ok = 0;
  1722. nick = newsplit(&par);
  1723. if (!par[0]) {
  1724. dprintf(idx, STR("Usage: simul <hand> <text>\n"));
  1725. return;
  1726. }
  1727. if (isowner(nick)) {
  1728. dprintf(idx, STR("Unable to '.simul' permanent owners.\n"));
  1729. return;
  1730. }
  1731. for (i = 0; i < dcc_total; i++)
  1732. if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
  1733. (dcc[i].type->flags & DCT_SIMUL)) {
  1734. putlog(LOG_CMDS, "*", STR("#%s# simul %s %s"), dcc[idx].nick, nick, par);
  1735. if (dcc[i].type && dcc[i].type->activity) {
  1736. dcc[i].type->activity(i, par, strlen(par));
  1737. ok = 1;
  1738. }
  1739. }
  1740. if (!ok)
  1741. dprintf(idx, STR("No such user on the party line.\n"));
  1742. }
  1743. #ifdef HUB
  1744. static void cmd_link(struct userrec *u, int idx, char *par)
  1745. {
  1746. char *s;
  1747. int i;
  1748. if (!par[0]) {
  1749. dprintf(idx, STR("Usage: link [some-bot] <new-bot>\n"));
  1750. return;
  1751. }
  1752. putlog(LOG_CMDS, "*", STR("#%s# link %s"), dcc[idx].nick, par);
  1753. s = newsplit(&par);
  1754. if (!par[0] || !egg_strcasecmp(par, botnetnick))
  1755. botlink(dcc[idx].nick, idx, s);
  1756. else {
  1757. char x[40];
  1758. i = nextbot(s);
  1759. if (i < 0) {
  1760. dprintf(idx, STR("No such bot online.\n"));
  1761. return;
  1762. }
  1763. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1764. botnet_send_link(i, x, s, par);
  1765. }
  1766. }
  1767. #endif /* HUB */
  1768. static void cmd_unlink(struct userrec *u, int idx, char *par)
  1769. {
  1770. int i;
  1771. char *bot;
  1772. if (!par[0]) {
  1773. dprintf(idx, STR("Usage: unlink <bot> [reason]\n"));
  1774. return;
  1775. }
  1776. putlog(LOG_CMDS, "*", STR("#%s# unlink %s"), dcc[idx].nick, par);
  1777. bot = newsplit(&par);
  1778. i = nextbot(bot);
  1779. if (i < 0) {
  1780. botunlink(idx, bot, par);
  1781. return;
  1782. }
  1783. /* If we're directly connected to that bot, just do it
  1784. * (is nike gunna sue?)
  1785. */
  1786. if (!egg_strcasecmp(dcc[i].nick, bot))
  1787. botunlink(idx, bot, par);
  1788. else {
  1789. char x[40];
  1790. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1791. botnet_send_unlink(i, x, lastbot(bot), bot, par);
  1792. }
  1793. }
  1794. static void cmd_relay(struct userrec *u, int idx, char *par)
  1795. {
  1796. if (!par[0]) {
  1797. dprintf(idx, STR("Usage: relay <bot>\n"));
  1798. return;
  1799. }
  1800. putlog(LOG_CMDS, "*", STR("#%s# relay %s"), dcc[idx].nick, par);
  1801. tandem_relay(idx, par, 0);
  1802. }
  1803. #ifdef HUB
  1804. static void cmd_save(struct userrec *u, int idx, char *par)
  1805. {
  1806. char buf[100], i = 0;
  1807. putlog(LOG_CMDS, "*", STR("#%s# save"), dcc[idx].nick);
  1808. sprintf(buf, "Saving user file...");
  1809. i = write_userfile(-1);
  1810. if (i == 0)
  1811. strcat(buf, "success.");
  1812. else if (i == 1)
  1813. strcat(buf, "failed: No userlist.");
  1814. else if (i == 2)
  1815. strcat(buf, "failed: Cannot open userfile for writing.");
  1816. else if (i == 3)
  1817. strcat(buf, "failed: Problem writing users/chans (see debug).");
  1818. else /* This can't happen. */
  1819. strcat(buf, "failed: Unforseen error");
  1820. buf[99] = 0;
  1821. dprintf(idx, "%s\n", buf);
  1822. }
  1823. static void cmd_backup(struct userrec *u, int idx, char *par)
  1824. {
  1825. putlog(LOG_CMDS, "*", STR("#%s# backup"), dcc[idx].nick);
  1826. dprintf(idx, STR("Backing up the channel & user files...\n"));
  1827. #ifdef HUB
  1828. write_userfile(idx);
  1829. #endif /* HUB */
  1830. call_hook(HOOK_BACKUP);
  1831. }
  1832. static void cmd_trace(struct userrec *u, int idx, char *par)
  1833. {
  1834. int i;
  1835. char x[NOTENAMELEN + 11], y[11];
  1836. if (!par[0]) {
  1837. dprintf(idx, STR("Usage: trace <bot>\n"));
  1838. return;
  1839. }
  1840. if (!egg_strcasecmp(par, botnetnick)) {
  1841. dprintf(idx, STR("That's me! Hiya! :)\n"));
  1842. return;
  1843. }
  1844. i = nextbot(par);
  1845. if (i < 0) {
  1846. dprintf(idx, STR("Unreachable bot.\n"));
  1847. return;
  1848. }
  1849. putlog(LOG_CMDS, "*", STR("#%s# trace %s"), dcc[idx].nick, par);
  1850. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1851. simple_sprintf(y, ":%d", now);
  1852. botnet_send_trace(i, x, par, y);
  1853. }
  1854. static void cmd_binds(struct userrec *u, int idx, char *par)
  1855. {
  1856. putlog(LOG_CMDS, "*", STR("#%s# binds %s"), dcc[idx].nick, par);
  1857. tell_binds(idx, par);
  1858. }
  1859. #endif /* HUB */
  1860. /* After messing with someone's user flags, make sure the dcc-chat flags
  1861. * are set correctly.
  1862. */
  1863. int check_dcc_attrs(struct userrec *u, int oatr)
  1864. {
  1865. int i, stat;
  1866. if (!u)
  1867. return 0;
  1868. /* Make sure default owners are +a */
  1869. if (isowner(u->handle)) {
  1870. u->flags = sanity_check(u->flags | USER_ADMIN);
  1871. }
  1872. for (i = 0; i < dcc_total; i++) {
  1873. if ((dcc[i].type->flags & DCT_MASTER) &&
  1874. (!egg_strcasecmp(u->handle, dcc[i].nick))) {
  1875. stat = dcc[i].status;
  1876. if ((dcc[i].type == &DCC_CHAT) &&
  1877. ((u->flags & (USER_OP | USER_MASTER | USER_OWNER))
  1878. != (oatr & (USER_OP | USER_MASTER | USER_OWNER)))) {
  1879. botnet_send_join_idx(i, -1);
  1880. }
  1881. if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
  1882. struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1883. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
  1884. LOG_FILES | LOG_WALL | LOG_DEBUG);
  1885. get_user_flagrec(u, &fr, NULL);
  1886. if (!chan_master(fr))
  1887. dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
  1888. dprintf(i, STR("*** POOF! ***\n"));
  1889. dprintf(i, STR("You are no longer a master on this bot.\n"));
  1890. }
  1891. if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
  1892. dcc[i].u.chat->con_flags |= conmask;
  1893. dprintf(i, STR("*** POOF! ***\n"));
  1894. dprintf(i, STR("You are now a master on this bot.\n"));
  1895. }
  1896. if (!(oatr & USER_PARTY) && (u->flags & USER_PARTY) && dcc[i].u.chat->channel < 0) {
  1897. dprintf(i, "-+- POOF! -+-\n");
  1898. dprintf(i, STR("You now have party line chat access.\n"));
  1899. dprintf(i, STR("To rejoin the partyline, type: %schat on\n"), dcc_prefix);
  1900. }
  1901. if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
  1902. dprintf(i, STR("@@@ POOF! @@@\n"));
  1903. dprintf(i, STR("You are now an OWNER of this bot.\n"));
  1904. }
  1905. if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
  1906. dprintf(i, STR("@@@ POOF! @@@\n"));
  1907. dprintf(i, STR("You are no longer an owner of this bot.\n"));
  1908. }
  1909. if (!(u->flags & USER_PARTY) && dcc[i].u.chat->channel >= 0) { //who cares about old flags, they shouldnt be here anyway.
  1910. dprintf(i, STR("-+- POOF! -+-\n"));
  1911. dprintf(i, STR("You no longer have party line chat access.\n"));
  1912. dprintf(i, STR("Leaving chat mode...\n"));
  1913. chanout_but(-1, dcc[i].u.chat->channel, STR("*** %s left the party line - no chat access.\n"), dcc[i].nick);
  1914. if (dcc[i].u.chat->channel < 100000)
  1915. botnet_send_part_idx(i, "");
  1916. dcc[i].u.chat->channel = (-1);
  1917. }
  1918. if (!(oatr & USER_ADMIN) && (u->flags & USER_ADMIN)) {
  1919. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1920. dprintf(i, STR("You are now an ADMIN of this bot.\n"));
  1921. }
  1922. if ((oatr & USER_ADMIN) && !(u->flags & USER_ADMIN)) {
  1923. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1924. dprintf(i, STR("You are no longer an admin of this bot.\n"));
  1925. }
  1926. if ((stat & STAT_PARTY) && (u->flags & USER_OP))
  1927. stat &= ~STAT_PARTY;
  1928. if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
  1929. !(u->flags & USER_MASTER))
  1930. stat |= STAT_PARTY;
  1931. if (stat & STAT_CHAT) {
  1932. #ifdef HUB
  1933. if (!(u->flags & USER_HUBA))
  1934. stat &= ~STAT_CHAT;
  1935. #endif /* HUB */
  1936. if (ischanhub() && !(u->flags & USER_CHUBA))
  1937. stat &= ~STAT_CHAT;
  1938. }
  1939. if ((u->flags & USER_PARTY))
  1940. stat |= STAT_CHAT;
  1941. dcc[i].status = stat;
  1942. /* Check if they no longer have access to wherever they are.
  1943. */
  1944. #ifdef HUB
  1945. if (!(u->flags & (USER_HUBA))) {
  1946. /* no hub access, drop them. */
  1947. dprintf(i, STR("-+- POOF! -+-\n"));
  1948. dprintf(i, STR("You no longer have hub access.\n\n"));
  1949. do_boot(i, botnetnick, STR("No hub access.\n\n"));
  1950. }
  1951. #else /* !HUB */
  1952. if (ischanhub() && !(u->flags & (USER_CHUBA))) {
  1953. /* no chanhub access, drop them. */
  1954. dprintf(i, STR("-+- POOF! -+-\n"));
  1955. dprintf(i, STR("You no longer have chathub access.\n\n"));
  1956. do_boot(i, botnetnick, STR("No chathub access.\n\n"));
  1957. }
  1958. #endif /* HUB */
  1959. }
  1960. if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1961. if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
  1962. dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
  1963. if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
  1964. dcc[i].status |= STAT_LEAF;
  1965. }
  1966. }
  1967. return u->flags;
  1968. }
  1969. int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags, int ochatr)
  1970. {
  1971. int i, found = 0, atr = u ? u->flags : 0;
  1972. struct chanset_t *chan;
  1973. if (!u)
  1974. return 0;
  1975. for (i = 0; i < dcc_total; i++) {
  1976. if ((dcc[i].type->flags & DCT_MASTER) &&
  1977. !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1978. if ((dcc[i].type == &DCC_CHAT) &&
  1979. ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
  1980. != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
  1981. botnet_send_join_idx(i, -1);
  1982. if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
  1983. if (!(atr & USER_MASTER))
  1984. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
  1985. dprintf(i, STR("*** POOF! ***\n"));
  1986. dprintf(i, STR("You are no longer a master on %s.\n"), chname);
  1987. }
  1988. if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
  1989. dcc[i].u.chat->con_flags |= conmask;
  1990. if (!(atr & USER_MASTER))
  1991. dcc[i].u.chat->con_flags &=
  1992. ~(LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
  1993. dprintf(i, STR("*** POOF! ***\n"));
  1994. dprintf(i, STR("You are now a master on %s.\n"), chname);
  1995. }
  1996. if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
  1997. dprintf(i, STR("@@@ POOF! @@@\n"));
  1998. dprintf(i, STR("You are now an OWNER of %s.\n"), chname);
  1999. }
  2000. if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
  2001. dprintf(i, STR("@@@ POOF! @@@\n"));
  2002. dprintf(i, STR("You are no longer an owner of %s.\n"), chname);
  2003. }
  2004. if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2005. (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
  2006. ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
  2007. (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
  2008. struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
  2009. for (chan = chanset; chan && !found; chan = chan->next) {
  2010. get_user_flagrec(u, &fr, chan->dname);
  2011. if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
  2012. found = 1;
  2013. }
  2014. if (!chan)
  2015. chan = chanset;
  2016. if (chan)
  2017. strcpy(dcc[i].u.chat->con_chan, chan->dname);
  2018. else
  2019. strcpy(dcc[i].u.chat->con_chan, "*");
  2020. }
  2021. }
  2022. }
  2023. return chflags;
  2024. }
  2025. static void cmd_chattr(struct userrec *u, int idx, char *par)
  2026. {
  2027. char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
  2028. struct chanset_t *chan = NULL;
  2029. struct userrec *u2;
  2030. struct flag_record pls = {0, 0, 0, 0, 0, 0},
  2031. mns = {0, 0, 0, 0, 0, 0},
  2032. user = {0, 0, 0, 0, 0, 0},
  2033. ouser = {0, 0, 0, 0, 0, 0};
  2034. module_entry *me;
  2035. int fl = -1, of = 0, ocf = 0;
  2036. if (!par[0]) {
  2037. dprintf(idx, STR("Usage: chattr <handle> [changes] [channel]\n"));
  2038. return;
  2039. }
  2040. hand = newsplit(&par);
  2041. u2 = get_user_by_handle(userlist, hand);
  2042. if (!u2) {
  2043. dprintf(idx, STR("No such user!\n"));
  2044. return;
  2045. }
  2046. /* Parse args */
  2047. if (par[0]) {
  2048. arg = newsplit(&par);
  2049. if (par[0]) {
  2050. /* .chattr <handle> <changes> <channel> */
  2051. chg = arg;
  2052. arg = newsplit(&par);
  2053. chan = findchan_by_dname(arg);
  2054. } else {
  2055. chan = findchan_by_dname(arg);
  2056. /* Consider modeless channels, starting with '+' */
  2057. if (!(arg[0] == '+' && chan) &&
  2058. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  2059. /* .chattr <handle> <changes> */
  2060. chg = arg;
  2061. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  2062. arg = NULL;
  2063. }
  2064. /* .chattr <handle> <channel>: nothing to do... */
  2065. }
  2066. }
  2067. /* arg: pointer to channel name, NULL if none specified
  2068. * chan: pointer to channel structure, NULL if none found or none specified
  2069. * chg: pointer to changes, NULL if none specified
  2070. */
  2071. Assert(!(!arg && chan));
  2072. if (arg && !chan) {
  2073. dprintf(idx, STR("No channel record for %s.\n"), arg);
  2074. return;
  2075. }
  2076. if (chg) {
  2077. if (!arg && strpbrk(chg, "&|")) {
  2078. /* .chattr <handle> *[&|]*: use console channel if found... */
  2079. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  2080. arg = NULL;
  2081. else
  2082. chan = findchan_by_dname(arg);
  2083. if (arg && !chan) {
  2084. dprintf (idx, STR("Invalid console channel %s.\n"), arg);
  2085. return;
  2086. }
  2087. } else if (arg && !strpbrk(chg, "&|")) {
  2088. tmpchg = nmalloc(strlen(chg) + 2);
  2089. strcpy(tmpchg, "|");
  2090. strcat(tmpchg, chg);
  2091. chg = tmpchg;
  2092. }
  2093. }
  2094. par = arg;
  2095. user.match = FR_GLOBAL;
  2096. if (chan)
  2097. user.match |= FR_CHAN;
  2098. get_user_flagrec(u, &user, chan ? chan->dname : 0);
  2099. get_user_flagrec(u2, &ouser, chan ? chan->dname : 0);
  2100. if (chan && !glob_master(user) && !chan_master(user)) {
  2101. dprintf(idx, STR("You do not have channel master privileges for channel %s.\n"),
  2102. par);
  2103. if (tmpchg)
  2104. nfree(tmpchg);
  2105. return;
  2106. }
  2107. if (chan && private(user, chan, PRIV_OP)) {
  2108. dprintf(idx, STR("You do not have access to change flags for %s\n"), chan->dname);
  2109. if (tmpchg)
  2110. nfree(tmpchg);
  2111. return;
  2112. }
  2113. user.match &= fl;
  2114. if (chg) {
  2115. pls.match = user.match;
  2116. break_down_flags(chg, &pls, &mns);
  2117. /* No-one can change these flags on-the-fly */
  2118. pls.global &= ~(USER_BOT);
  2119. mns.global &= ~(USER_BOT);
  2120. if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
  2121. dprintf(idx, STR("Only a hub can be set as the updatehub.\n"));
  2122. pls.global &= ~(USER_UPDATEHUB);
  2123. }
  2124. /* strip out +p without +i or +j */
  2125. if (((pls.global & USER_PARTY) && !(pls.global & USER_CHUBA) && !(pls.global & USER_HUBA)) && (!glob_huba(ouser) && !glob_chuba(ouser))) {
  2126. dprintf(idx, "Global flag +p requires either chathub or hub access first.\n");
  2127. pls.global &= ~USER_PARTY;
  2128. }
  2129. if (!isowner(u->handle)) {
  2130. if (pls.global & USER_HUBA)
  2131. putlog(LOG_MISC, "*", STR("%s attempted to give %s hub connect access"), dcc[idx].nick, u2->handle);
  2132. if (mns.global & USER_HUBA)
  2133. putlog(LOG_MISC, "*", STR("%s attempted to take away hub connect access from %s"), dcc[idx].nick, u2->handle);
  2134. if (pls.global & USER_UPDATEHUB)
  2135. putlog(LOG_MISC, "*", STR("%s attempted to make %s the updatehub"), dcc[idx].nick, u2->handle);
  2136. if (mns.global & USER_UPDATEHUB)
  2137. putlog(LOG_MISC, "*", STR("%s attempted to take away updatehub status from %s"), dcc[idx].nick, u2->handle);
  2138. if (pls.global & USER_ADMIN)
  2139. putlog(LOG_MISC, "*", STR("%s attempted to give %s admin access"), dcc[idx].nick, u2->handle);
  2140. if (mns.global & USER_ADMIN)
  2141. putlog(LOG_MISC, "*", STR("%s attempted to take away admin access from %s"), dcc[idx].nick, u2->handle);
  2142. if (pls.global & USER_OWNER)
  2143. putlog(LOG_MISC, "*", STR("%s attempted to give owner to %s"), dcc[idx].nick, u2->handle);
  2144. if (mns.global & USER_OWNER)
  2145. putlog(LOG_MISC, "*", STR("%s attempted to take owner away from %s"), dcc[idx].nick, u2->handle);
  2146. pls.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2147. mns.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2148. pls.chan &= ~(USER_ADMIN | USER_UPDATEHUB);
  2149. }
  2150. if (chan) {
  2151. pls.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2152. mns.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2153. }
  2154. if (!glob_owner(user) && !isowner(u->handle)) {
  2155. pls.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2156. mns.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2157. if (chan) {
  2158. pls.chan &= ~USER_OWNER;
  2159. mns.chan &= ~USER_OWNER;
  2160. }
  2161. }
  2162. if (chan && !chan_owner(user) && !glob_owner(user) && !isowner(u->handle)) {
  2163. pls.chan &= ~USER_MASTER;
  2164. mns.chan &= ~USER_MASTER;
  2165. if (!chan_master(user) && !glob_master(user)) {
  2166. pls.chan = 0;
  2167. mns.chan = 0;
  2168. }
  2169. }
  2170. #ifdef LEAF
  2171. pls.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2172. mns.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2173. #endif /* LEAF */
  2174. get_user_flagrec(u2, &user, par);
  2175. if (user.match & FR_GLOBAL) {
  2176. of = user.global;
  2177. user.global = sanity_check((user.global |pls.global) &~mns.global);
  2178. user.udef_global = (user.udef_global | pls.udef_global)
  2179. & ~mns.udef_global;
  2180. }
  2181. if (chan) {
  2182. ocf = user.chan;
  2183. user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
  2184. user.global);
  2185. user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
  2186. }
  2187. set_user_flagrec(u2, &user, par);
  2188. }
  2189. if (chan) {
  2190. char tmp[100];
  2191. putlog(LOG_CMDS, "*", STR("#%s# (%s) chattr %s %s"), dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
  2192. egg_snprintf(tmp, sizeof tmp, "chattr %s", chg);
  2193. update_mod(hand, dcc[idx].nick, tmp, chan->dname);
  2194. } else {
  2195. putlog(LOG_CMDS, "*", STR("#%s# chattr %s %s"), dcc[idx].nick, hand, chg ? chg : "");
  2196. update_mod(hand, dcc[idx].nick, "chattr", chg);
  2197. }
  2198. /* Get current flags and display them */
  2199. if (user.match & FR_GLOBAL) {
  2200. user.match = FR_GLOBAL;
  2201. if (chg)
  2202. check_dcc_attrs(u2, of);
  2203. get_user_flagrec(u2, &user, NULL);
  2204. build_flags(work, &user, NULL);
  2205. if (work[0] != '-')
  2206. dprintf(idx, STR("Global flags for %s are now +%s.\n"), hand, work);
  2207. else
  2208. dprintf(idx, STR("No global flags for %s.\n"), hand);
  2209. }
  2210. if (chan) {
  2211. user.match = FR_CHAN;
  2212. get_user_flagrec(u2, &user, par);
  2213. user.chan &= ~BOT_SHARE;
  2214. if (chg)
  2215. check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
  2216. build_flags(work, &user, NULL);
  2217. if (work[0] != '-')
  2218. dprintf(idx, STR("Channel flags for %s on %s are now +%s.\n"), hand,
  2219. chan->dname, work);
  2220. else
  2221. dprintf(idx, STR("No flags for %s on %s.\n"), hand, chan->dname);
  2222. }
  2223. if (chg && (me = module_find("irc", 0, 0))) {
  2224. Function *func = me->funcs;
  2225. (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
  2226. }
  2227. if (tmpchg)
  2228. nfree(tmpchg);
  2229. #ifdef HUB
  2230. write_userfile(idx);
  2231. #endif /* HUB */
  2232. }
  2233. static void cmd_chat(struct userrec *u, int idx, char *par)
  2234. {
  2235. char *arg;
  2236. int newchan, oldchan;
  2237. module_entry *me;
  2238. if (!(u->flags & USER_PARTY)) {
  2239. dprintf(idx, STR("You don't have partyline access\n"));
  2240. return;
  2241. }
  2242. arg = newsplit(&par);
  2243. if (!egg_strcasecmp(arg, "off")) {
  2244. /* Turn chat off */
  2245. if (dcc[idx].u.chat->channel < 0) {
  2246. dprintf(idx, STR("You weren't in chat anyway!\n"));
  2247. return;
  2248. } else {
  2249. dprintf(idx, STR("Leaving chat mode...\n"));
  2250. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  2251. dcc[idx].u.chat->channel);
  2252. chanout_but(-1, dcc[idx].u.chat->channel,
  2253. "*** %s left the party line.\n",
  2254. dcc[idx].nick);
  2255. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2256. botnet_send_part_idx(idx, "");
  2257. }
  2258. dcc[idx].u.chat->channel = (-1);
  2259. } else {
  2260. if (arg[0] == '*') {
  2261. if (((arg[1] < '0') || (arg[1] > '9'))) {
  2262. if (!arg[1])
  2263. newchan = 0;
  2264. else {
  2265. Tcl_SetVar(interp, "chan", arg, 0);
  2266. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2267. interp->result[0])
  2268. newchan = atoi(interp->result);
  2269. else
  2270. newchan = -1;
  2271. }
  2272. if (newchan < 0) {
  2273. dprintf(idx, STR("No channel exists by that name.\n"));
  2274. return;
  2275. }
  2276. } else
  2277. newchan = GLOBAL_CHANS + atoi(arg + 1);
  2278. if (newchan < GLOBAL_CHANS || newchan > 199999) {
  2279. dprintf(idx, STR("Channel number out of range: local channels must be *0-*99999.\n"));
  2280. return;
  2281. }
  2282. } else {
  2283. if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
  2284. if (!egg_strcasecmp(arg, "on"))
  2285. newchan = 0;
  2286. else {
  2287. Tcl_SetVar(interp, "chan", arg, 0);
  2288. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2289. interp->result[0])
  2290. newchan = atoi(interp->result);
  2291. else
  2292. newchan = -1;
  2293. }
  2294. if (newchan < 0) {
  2295. dprintf(idx, STR("No channel exists by that name.\n"));
  2296. return;
  2297. }
  2298. } else
  2299. newchan = atoi(arg);
  2300. if ((newchan < 0) || (newchan > 99999)) {
  2301. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  2302. return;
  2303. }
  2304. }
  2305. /* If coming back from being off the party line, make sure they're
  2306. * not away.
  2307. */
  2308. if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
  2309. not_away(idx);
  2310. if (dcc[idx].u.chat->channel == newchan) {
  2311. if (!newchan) {
  2312. dprintf(idx, STR("You're already on the party line!\n"));
  2313. return;
  2314. } else {
  2315. dprintf(idx, STR("You're already on channel %s%d!\n"),
  2316. (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
  2317. return;
  2318. }
  2319. } else {
  2320. oldchan = dcc[idx].u.chat->channel;
  2321. if (oldchan >= 0)
  2322. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
  2323. if (!oldchan) {
  2324. chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
  2325. } else if (oldchan > 0) {
  2326. chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
  2327. }
  2328. dcc[idx].u.chat->channel = newchan;
  2329. if (!newchan) {
  2330. dprintf(idx, STR("Entering the party line...\n"));
  2331. chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
  2332. } else {
  2333. dprintf(idx, STR("Joining channel '%s'...\n"), arg);
  2334. chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
  2335. }
  2336. check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
  2337. dcc[idx].sock, dcc[idx].host);
  2338. if (newchan < GLOBAL_CHANS)
  2339. botnet_send_join_idx(idx, oldchan);
  2340. else if (oldchan < GLOBAL_CHANS)
  2341. botnet_send_part_idx(idx, "");
  2342. }
  2343. }
  2344. /* New style autosave here too -- rtc, 09/28/1999*/
  2345. if ((me = module_find("console", 0, 0))) {
  2346. Function *func = me->funcs;
  2347. (func[CONSOLE_DOSTORE]) (idx);
  2348. }
  2349. }
  2350. int exec_str(int idx, char *cmd) {
  2351. char *out, *err, *p, *np;
  2352. if (shell_exec(cmd, NULL, &out, &err)) {
  2353. if (out) {
  2354. dprintf(idx, STR("Result:\n"));
  2355. p=out;
  2356. while (p && p[0]) {
  2357. np=strchr(p, '\n');
  2358. if (np)
  2359. *np++=0;
  2360. dprintf(idx, STR("%s\n"), p);
  2361. p=np;
  2362. }
  2363. dprintf(idx, "\n");
  2364. nfree(out);
  2365. }
  2366. if (err) {
  2367. dprintf(idx, STR("Errors:\n"));
  2368. p=err;
  2369. while (p && p[0]) {
  2370. np=strchr(p, '\n');
  2371. if (np)
  2372. *np++=0;
  2373. dprintf(idx, STR("%s\n"), p);
  2374. p=np;
  2375. }
  2376. dprintf(idx, "\n");
  2377. nfree(err);
  2378. }
  2379. return 1;
  2380. }
  2381. return 0;
  2382. }
  2383. static void cmd_exec(struct userrec *u, int idx, char *par) {
  2384. putlog(LOG_CMDS, "*", STR("#%s# exec %s"), dcc[idx].nick, par);
  2385. #ifdef LEAF
  2386. if (!isowner(u->handle)) {
  2387. putlog(LOG_WARN, "*", STR("%s attempted 'exec' %s"), dcc[idx].nick, par);
  2388. dprintf(idx, STR("exec is only available to permanent owners on leaf bots\n"));
  2389. return;
  2390. }
  2391. #endif /* LEAF */
  2392. if (exec_str(idx, par))
  2393. dprintf(idx, STR("Exec completed\n"));
  2394. else
  2395. dprintf(idx, STR("Exec failed\n"));
  2396. }
  2397. static void cmd_w(struct userrec *u, int idx, char *par) {
  2398. putlog(LOG_CMDS, "*", STR("#%s# w"), dcc[idx].nick);
  2399. if (!exec_str(idx, "w"))
  2400. dprintf(idx, STR("Exec failed\n"));
  2401. }
  2402. static void cmd_ps(struct userrec *u, int idx, char *par) {
  2403. char * buf;
  2404. putlog(LOG_CMDS, "*", STR("#%s# ps %s"), dcc[idx].nick, par);
  2405. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2406. putlog(LOG_WARN, "*", STR("%s attempted 'ps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2407. dprintf(idx, STR("No."));
  2408. return;
  2409. }
  2410. buf=nmalloc(strlen(par)+4);
  2411. sprintf(buf, STR("ps %s"), par);
  2412. if (!exec_str(idx, buf))
  2413. dprintf(idx, STR("Exec failed\n"));
  2414. nfree(buf);
  2415. }
  2416. static void cmd_last(struct userrec *u, int idx, char *par) {
  2417. char user[20], buf[30];
  2418. struct passwd *pw;
  2419. putlog(LOG_CMDS, "*", STR("#%s# last %s"), dcc[idx].nick, par);
  2420. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2421. putlog(LOG_WARN, "*", STR("%s attempted 'last' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2422. dprintf(idx, STR("No."));
  2423. return;
  2424. }
  2425. if (par[0]) {
  2426. strncpyz(user, par, sizeof(user));
  2427. } else {
  2428. pw = getpwuid(geteuid());
  2429. if (!pw)
  2430. return;
  2431. strncpyz(user, pw->pw_name, sizeof(user));
  2432. }
  2433. if (!user[0]) {
  2434. dprintf(idx, STR("Can't determine user id for process\n"));
  2435. return;
  2436. }
  2437. sprintf(buf, STR("last %s"), user);
  2438. if (!exec_str(idx, buf))
  2439. dprintf(idx, STR("Failed to execute /bin/sh last\n"));
  2440. }
  2441. static void cmd_echo(struct userrec *u, int idx, char *par)
  2442. {
  2443. module_entry *me;
  2444. if (!par[0]) {
  2445. dprintf(idx, STR("Echo is currently %s.\n"), dcc[idx].status & STAT_ECHO ?
  2446. "on" : "off");
  2447. return;
  2448. }
  2449. if (!egg_strcasecmp(par, "on")) {
  2450. dprintf(idx, STR("Echo turned on.\n"));
  2451. dcc[idx].status |= STAT_ECHO;
  2452. } else if (!egg_strcasecmp(par, "off")) {
  2453. dprintf(idx, STR("Echo turned off.\n"));
  2454. dcc[idx].status &= ~STAT_ECHO;
  2455. } else {
  2456. dprintf(idx, STR("Usage: echo <on/off>\n"));
  2457. return;
  2458. }
  2459. /* New style autosave here too -- rtc, 09/28/1999*/
  2460. if ((me = module_find("console", 0, 0))) {
  2461. Function *func = me->funcs;
  2462. (func[CONSOLE_DOSTORE]) (idx);
  2463. }
  2464. }
  2465. static void cmd_color(struct userrec *u, int idx, char *par)
  2466. {
  2467. module_entry *me;
  2468. char *type, *of;
  2469. putlog(LOG_CMDS, "*", STR("#%s# color %s"), dcc[idx].nick, par);
  2470. if (!par[0]) {
  2471. dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
  2472. if (dcc[idx].status & STAT_COLOR)
  2473. dprintf(idx, STR("Color is currently on (%s).\n"), dcc[idx].status & STAT_COLORM ? "mIRC" : "ANSI");
  2474. else
  2475. dprintf(idx, STR("Color is currently off.\n"));
  2476. return;
  2477. }
  2478. of = newsplit(&par);
  2479. type = newsplit(&par);
  2480. if (!egg_strcasecmp(of, "on")) {
  2481. if (!type) {
  2482. dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
  2483. return;
  2484. }
  2485. if (!egg_strcasecmp(type, "mirc")) {
  2486. dcc[idx].status &= ~STAT_COLORA;
  2487. dcc[idx].status |= (STAT_COLOR | STAT_COLORM);
  2488. dprintf(idx, STR("Color turned on (mIRC).\n"));
  2489. } else if (!egg_strcasecmp(type, "ansi")) {
  2490. dcc[idx].status &= ~STAT_COLORM;
  2491. dcc[idx].status |= (STAT_COLOR | STAT_COLORA);
  2492. dprintf(idx, STR("Color turned on (ANSI).\n"));
  2493. } else {
  2494. return;
  2495. }
  2496. } else if (!egg_strcasecmp(of, "off")) {
  2497. dcc[idx].status &= ~(STAT_COLOR | STAT_COLORM | STAT_COLORA);
  2498. dprintf(idx, STR("Color turned off.\n"));
  2499. } else {
  2500. return;
  2501. }
  2502. /* New style autosave here too -- rtc, 09/28/1999*/
  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. userlist = adduser(userlist, handle, STR("none"), "-", USER_BOT | USER_OP);
  2847. u1 = get_user_by_handle(userlist, handle);
  2848. bi = user_malloc(sizeof(struct bot_addr));
  2849. bi->uplink = user_malloc(strlen(botnetnick) + 1);
  2850. /* strcpy(bi->uplink, botnetnick); */
  2851. strcpy(bi->uplink, "");
  2852. bi->address = user_malloc(1);
  2853. bi->address[0] = 0;
  2854. bi->telnet_port = 3333;
  2855. bi->relay_port = 3333;
  2856. bi->hublevel = 0;
  2857. set_user(&USERENTRY_BOTADDR, u1, bi);
  2858. host = newsplit(&par);
  2859. while ((host) && (host[0])) {
  2860. addhost_by_handle(handle, host);
  2861. host = newsplit(&par);
  2862. }
  2863. /* set_user(&USERENTRY_PASS, u1, SALT2); */
  2864. dprintf(idx, STR("Added new leaf: %s\n"), handle);
  2865. #ifdef HUB
  2866. write_userfile(idx);
  2867. #endif /* HUB */
  2868. }
  2869. }
  2870. }
  2871. #endif /* HUB */
  2872. static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
  2873. {
  2874. char *who;
  2875. char s[UHOSTLEN];
  2876. unsigned long int expire_time = 0;
  2877. if (!par[0]) {
  2878. dprintf(idx, STR("Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n"));
  2879. return;
  2880. }
  2881. who = newsplit(&par);
  2882. if (par[0] == '%') {
  2883. char *p, *p_expire;
  2884. unsigned long int expire_foo;
  2885. p = newsplit(&par);
  2886. p_expire = p + 1;
  2887. while (*(++p) != 0) {
  2888. switch (tolower(*p)) {
  2889. case 'd':
  2890. *p = 0;
  2891. expire_foo = strtol(p_expire, NULL, 10);
  2892. if (expire_foo > 365)
  2893. expire_foo = 365;
  2894. expire_time += 86400 * expire_foo;
  2895. p_expire = p + 1;
  2896. break;
  2897. case 'h':
  2898. *p = 0;
  2899. expire_foo = strtol(p_expire, NULL, 10);
  2900. if (expire_foo > 8760)
  2901. expire_foo = 8760;
  2902. expire_time += 3600 * expire_foo;
  2903. p_expire = p + 1;
  2904. break;
  2905. case 'm':
  2906. *p = 0;
  2907. expire_foo = strtol(p_expire, NULL, 10);
  2908. if (expire_foo > 525600)
  2909. expire_foo = 525600;
  2910. expire_time += 60 * expire_foo;
  2911. p_expire = p + 1;
  2912. }
  2913. }
  2914. }
  2915. if (!par[0])
  2916. par = "requested";
  2917. else if (strlen(par) > 65)
  2918. par[65] = 0;
  2919. if (strlen(who) > UHOSTMAX - 4)
  2920. who[UHOSTMAX - 4] = 0;
  2921. /* Fix missing ! or @ BEFORE continuing */
  2922. if (!strchr(who, '!')) {
  2923. if (!strchr(who, '@'))
  2924. simple_sprintf(s, "%s!*@*", who);
  2925. else
  2926. simple_sprintf(s, "*!%s", who);
  2927. } else if (!strchr(who, '@'))
  2928. simple_sprintf(s, "%s@*", who);
  2929. else
  2930. strcpy(s, who);
  2931. if (match_ignore(s))
  2932. dprintf(idx, STR("That already matches an existing ignore.\n"));
  2933. else {
  2934. dprintf(idx, STR("Now ignoring: %s (%s)\n"), s, par);
  2935. addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
  2936. putlog(LOG_CMDS, "*", STR("#%s# +ignore %s %s"), dcc[idx].nick, s, par);
  2937. #ifdef HUB
  2938. write_userfile(idx);
  2939. #endif /* HUB */
  2940. }
  2941. }
  2942. static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
  2943. {
  2944. char buf[UHOSTLEN];
  2945. if (!par[0]) {
  2946. dprintf(idx, STR("Usage: -ignore <hostmask | ignore #>\n"));
  2947. return;
  2948. }
  2949. strncpyz(buf, par, sizeof buf);
  2950. if (delignore(buf)) {
  2951. putlog(LOG_CMDS, "*", STR("#%s# -ignore %s"), dcc[idx].nick, buf);
  2952. dprintf(idx, STR("No longer ignoring: %s\n"), buf);
  2953. #ifdef HUB
  2954. write_userfile(idx);
  2955. #endif /* HUB */
  2956. } else
  2957. dprintf(idx, STR("That ignore cannot be found.\n"));
  2958. }
  2959. static void cmd_ignores(struct userrec *u, int idx, char *par)
  2960. {
  2961. putlog(LOG_CMDS, "*", STR("#%s# ignores %s"), dcc[idx].nick, par);
  2962. tell_ignores(idx, par);
  2963. }
  2964. static void cmd_pls_user(struct userrec *u, int idx, char *par)
  2965. {
  2966. char *handle, *host;
  2967. putlog(LOG_CMDS, "*", STR("#%s# +user %s"), dcc[idx].nick, par);
  2968. if (!par[0]) {
  2969. dprintf(idx, STR("Usage: +user <handle> [hostmask]\n"));
  2970. return;
  2971. }
  2972. handle = newsplit(&par);
  2973. host = newsplit(&par);
  2974. if (strlen(handle) > HANDLEN)
  2975. handle[HANDLEN] = 0;
  2976. if (get_user_by_handle(userlist, handle))
  2977. dprintf(idx, STR("Someone already exists by that name.\n"));
  2978. else if (strchr(BADNICKCHARS, handle[0]) != NULL)
  2979. dprintf(idx, STR("You can't start a nick with '%c'.\n"), handle[0]);
  2980. else if (!egg_strcasecmp(handle, botnetnick))
  2981. dprintf(idx, STR("Hey! That's MY name!\n"));
  2982. else {
  2983. struct userrec *u2;
  2984. char tmp[50], s[16], s2[17];
  2985. userlist = adduser(userlist, handle, host, "-", USER_DEFAULT);
  2986. u2 = get_user_by_handle(userlist, handle);
  2987. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  2988. set_user(&USERENTRY_ADDED, u2, tmp);
  2989. dprintf(idx, STR("Added %s (%s) with no flags.\n"), handle, host);
  2990. while (par[0]) {
  2991. host=newsplit(&par);
  2992. set_user(&USERENTRY_HOSTS, u2, host);
  2993. dprintf(idx, STR("Added host %s to %s.\n"), host, handle);
  2994. }
  2995. make_rand_str(s, 15);
  2996. set_user(&USERENTRY_PASS, u2, s);
  2997. make_rand_str(s2, 16);
  2998. set_user(&USERENTRY_SECPASS, u2, s2);
  2999. dprintf(idx, STR("%s's initial password set to \002%s\002\n"), handle, s);
  3000. dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), handle, s2);
  3001. #ifdef HUB
  3002. write_userfile(idx);
  3003. #endif /* HUB */
  3004. }
  3005. }
  3006. static void cmd_mns_user(struct userrec *u, int idx, char *par)
  3007. {
  3008. int idx2;
  3009. char *handle;
  3010. struct userrec *u2;
  3011. module_entry *me;
  3012. putlog(LOG_CMDS, "*", STR("#%s# -user %s"), dcc[idx].nick, par);
  3013. if (!par[0]) {
  3014. dprintf(idx, STR("Usage: -user <hand>\n"));
  3015. return;
  3016. }
  3017. handle = newsplit(&par);
  3018. u2 = get_user_by_handle(userlist, handle);
  3019. if (!u2 || !u) {
  3020. dprintf(idx, STR("No such user!\n"));
  3021. return;
  3022. }
  3023. if (isowner(u2->handle)) {
  3024. dprintf(idx, STR("You can't remove a permanent bot owner!\n"));
  3025. return;
  3026. }
  3027. if ((u2->flags & USER_ADMIN) && !(isowner(u->handle))) {
  3028. dprintf(idx, STR("You can't remove an admin!\n"));
  3029. return;
  3030. }
  3031. if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  3032. dprintf(idx, STR("You can't remove a bot owner!\n"));
  3033. return;
  3034. }
  3035. if (u2->flags & USER_BOT) {
  3036. if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
  3037. dprintf(idx, STR("You can't remove share bots.\n"));
  3038. return;
  3039. }
  3040. for (idx2 = 0; idx2 < dcc_total; idx2++)
  3041. if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
  3042. !egg_strcasecmp(dcc[idx2].nick, handle))
  3043. break;
  3044. if (idx2 != dcc_total) {
  3045. dprintf(idx, STR("You can't remove a directly linked bot.\n"));
  3046. return;
  3047. }
  3048. }
  3049. if (!(u->flags & USER_MASTER) &&
  3050. !(u2->flags & USER_BOT)) {
  3051. dprintf(idx, STR("You can't remove users who aren't bots!\n"));
  3052. return;
  3053. }
  3054. if ((me = module_find("irc", 0, 0))) {
  3055. Function *func = me->funcs;
  3056. (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
  3057. }
  3058. if (deluser(handle)) {
  3059. dprintf(idx, STR("Deleted %s.\n"), handle);
  3060. #ifdef HUB
  3061. write_userfile(idx);
  3062. #endif /* HUB */
  3063. } else
  3064. dprintf(idx, STR("Failed.\n"));
  3065. }
  3066. static void cmd_pls_host(struct userrec *u, int idx, char *par)
  3067. {
  3068. char *handle, *host;
  3069. struct userrec *u2;
  3070. struct list_type *q;
  3071. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3072. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3073. module_entry *me;
  3074. putlog(LOG_CMDS, "*", STR("#%s# +host %s"), dcc[idx].nick, par);
  3075. if (!par[0]) {
  3076. dprintf(idx, STR("Usage: +host [handle] <newhostmask>\n"));
  3077. return;
  3078. }
  3079. handle = newsplit(&par);
  3080. if (par[0]) {
  3081. host = newsplit(&par);
  3082. u2 = get_user_by_handle(userlist, handle);
  3083. } else {
  3084. host = handle;
  3085. handle = dcc[idx].nick;
  3086. u2 = u;
  3087. }
  3088. if (!u2 || !u) {
  3089. dprintf(idx, STR("No such user.\n"));
  3090. return;
  3091. }
  3092. get_user_flagrec(u, &fr, NULL);
  3093. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3094. get_user_flagrec(u2, &fr2, NULL);
  3095. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3096. dprintf(idx, STR("You can't add hostmasks to non-bots.\n"));
  3097. return;
  3098. }
  3099. if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
  3100. dprintf(idx, STR("You can't add hostmasks to share bots.\n"));
  3101. return;
  3102. }
  3103. if (glob_admin(fr2) && !isowner(u->handle)) {
  3104. dprintf(idx, STR("You can't add hostmasks to an admin.\n"));
  3105. return;
  3106. }
  3107. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3108. dprintf(idx, STR("You can't add hostmasks to a bot owner/master.\n"));
  3109. return;
  3110. }
  3111. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3112. !glob_owner(fr) && !chan_owner(fr)) {
  3113. dprintf(idx, STR("You can't add hostmasks to a channel owner/master.\n"));
  3114. return;
  3115. }
  3116. if (!glob_master(fr) && !chan_master(fr)) {
  3117. dprintf(idx, STR("Permission denied.\n"));
  3118. return;
  3119. }
  3120. }
  3121. if (!chan_master(fr) && get_user_by_host(host)) {
  3122. dprintf(idx, STR("You cannot add a host matching another user!\n"));
  3123. return;
  3124. }
  3125. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  3126. if (!egg_strcasecmp(q->extra, host)) {
  3127. dprintf(idx, STR("That hostmask is already there.\n"));
  3128. return;
  3129. }
  3130. addhost_by_handle(handle, host);
  3131. update_mod(handle, dcc[idx].nick, "+host", host);
  3132. dprintf(idx, STR("Added '%s' to %s.\n"), host, handle);
  3133. if ((me = module_find("irc", 0, 0))) {
  3134. Function *func = me->funcs;
  3135. (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
  3136. }
  3137. #ifdef HUB
  3138. write_userfile(idx);
  3139. #endif /* HUB */
  3140. }
  3141. static void cmd_mns_host(struct userrec *u, int idx, char *par)
  3142. {
  3143. char *handle, *host;
  3144. struct userrec *u2;
  3145. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3146. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3147. module_entry *me;
  3148. putlog(LOG_CMDS, "*", STR("#%s# -host %s"), dcc[idx].nick, par);
  3149. if (!par[0]) {
  3150. dprintf(idx, STR("Usage: -host [handle] <hostmask>\n"));
  3151. return;
  3152. }
  3153. handle = newsplit(&par);
  3154. if (par[0]) {
  3155. host = newsplit(&par);
  3156. u2 = get_user_by_handle(userlist, handle);
  3157. } else {
  3158. host = handle;
  3159. handle = dcc[idx].nick;
  3160. u2 = u;
  3161. }
  3162. if (!u2 || !u) {
  3163. dprintf(idx, STR("No such user.\n"));
  3164. return;
  3165. }
  3166. get_user_flagrec(u, &fr, NULL);
  3167. get_user_flagrec(u2, &fr2, NULL);
  3168. /* check to see if user is +d or +k and don't let them remove hosts */
  3169. if (glob_deop(fr) || glob_kick(fr) || chan_deop(fr) || chan_kick (fr)) {
  3170. dprintf(idx, STR("You can't remove hostmasks while having the +d or +k flag.\n"));
  3171. return;
  3172. }
  3173. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3174. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3175. dprintf(idx, STR("You can't remove hostmasks from non-bots.\n"));
  3176. return;
  3177. }
  3178. if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
  3179. dprintf(idx, STR("You can't remove hostmasks from a share bot.\n"));
  3180. return;
  3181. }
  3182. if (glob_admin(fr2) && !isowner(u->handle)) {
  3183. dprintf(idx, STR("You can't remove hostmasks from an admin.\n"));
  3184. return;
  3185. }
  3186. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3187. dprintf(idx, STR("You can't remove hostmasks from a bot owner/master.\n"));
  3188. return;
  3189. }
  3190. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3191. !glob_owner(fr) && !chan_owner(fr)) {
  3192. dprintf(idx, STR("You can't remove hostmasks from a channel owner/master.\n"));
  3193. return;
  3194. }
  3195. if (!glob_master(fr) && !chan_master(fr)) {
  3196. dprintf(idx, STR("Permission denied.\n"));
  3197. return;
  3198. }
  3199. }
  3200. if (delhost_by_handle(handle, host)) {
  3201. dprintf(idx, STR("Removed '%s' from %s.\n"), host, handle);
  3202. update_mod(handle, dcc[idx].nick, "-host", host);
  3203. if ((me = module_find("irc", 0, 0))) {
  3204. Function *func = me->funcs;
  3205. (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
  3206. }
  3207. #ifdef HUB
  3208. write_userfile(idx);
  3209. #endif /* HUB */
  3210. } else
  3211. dprintf(idx, STR("Failed.\n"));
  3212. }
  3213. /* netserver */
  3214. static void cmd_netserver(struct userrec * u, int idx, char * par) {
  3215. putlog(LOG_CMDS, "*", STR("#%s# netserver"), dcc[idx].nick);
  3216. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("cursrv"));
  3217. }
  3218. static void cmd_botserver(struct userrec * u, int idx, char * par) {
  3219. putlog(LOG_CMDS, "*", STR("#%s# botserver %s"), dcc[idx].nick, par);
  3220. if (!par || !par[0]) {
  3221. dprintf(idx, STR("Usage: botserver <bot>\n"));
  3222. return;
  3223. }
  3224. if (nextbot(par)<0) {
  3225. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3226. }
  3227. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("cursrv"));
  3228. }
  3229. void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
  3230. #ifdef LEAF
  3231. char tmp[2048], cursrvname[500];
  3232. int server_online = 0;
  3233. module_entry *me;
  3234. if ((me = module_find("server", 0, 0))) {
  3235. Function *func = me->funcs;
  3236. server_online = (*(int *)(func[25]));
  3237. sprintf(cursrvname, "%s", ((char *)(func[41])));
  3238. }
  3239. if (server_online)
  3240. sprintf(tmp, "Currently: %-40s Lag: %d", cursrvname, server_lag);
  3241. // sprintf(tmp, STR("%-20s %d)"), cursrvname, server_lag);
  3242. else
  3243. sprintf(tmp, "Currently: none");
  3244. // sprintf(tmp, STR("%-20s"), "none");
  3245. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3246. #endif /* LEAF */
  3247. }
  3248. /* netversion */
  3249. static void cmd_netversion(struct userrec * u, int idx, char * par) {
  3250. putlog(LOG_CMDS, "*", STR("#%s# netversion"), dcc[idx].nick);
  3251. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("ver"));
  3252. }
  3253. static void cmd_botversion(struct userrec * u, int idx, char * par) {
  3254. putlog(LOG_CMDS, "*", STR("#%s# botversion %s"), dcc[idx].nick, par);
  3255. if (!par || !par[0]) {
  3256. dprintf(idx, STR("Usage: botversion <bot>\n"));
  3257. return;
  3258. }
  3259. if (nextbot(par)<0) {
  3260. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3261. }
  3262. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("ver"));
  3263. }
  3264. void rcmd_ver(char * fbot, char * fhand, char * fidx) {
  3265. char tmp[2048];
  3266. #ifdef HAVE_UNAME
  3267. struct utsname un;
  3268. #endif /* HAVE_UNAME */
  3269. sprintf(tmp, STR("%s "), version);
  3270. #ifdef HAVE_UNAME
  3271. if (uname(&un) < 0) {
  3272. #endif /* HAVE_UNAME */
  3273. strcat(tmp, STR("(unknown OS)"));
  3274. #ifdef HAVE_UNAME
  3275. } else {
  3276. sprintf(tmp + strlen(tmp), STR("%s %s (%s)"), un.sysname, un.release, un.machine);
  3277. }
  3278. #endif /* HAVE_UNAME */
  3279. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3280. }
  3281. /* netnick, botnick */
  3282. static void cmd_netnick (struct userrec *u, int idx, char *par) {
  3283. putlog(LOG_CMDS, "*", STR("#%s# netnick"), dcc[idx].nick);
  3284. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("curnick"));
  3285. }
  3286. static void cmd_botnick(struct userrec * u, int idx, char * par) {
  3287. putlog(LOG_CMDS, "*", STR("#%s# botnick %s"), dcc[idx].nick, par);
  3288. if (!par || !par[0]) {
  3289. dprintf(idx, STR("Usage: botnick <bot>\n"));
  3290. return;
  3291. }
  3292. if (nextbot(par)<0) {
  3293. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3294. }
  3295. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("curnick"));
  3296. }
  3297. void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
  3298. #ifdef LEAF
  3299. char tmp[1024];
  3300. int server_online = 0;
  3301. module_entry *me;
  3302. if ((me = module_find("server", 0, 0))) {
  3303. Function *func = me->funcs;
  3304. server_online = (*(int *)(func[25]));
  3305. }
  3306. tmp[0] = 0;
  3307. if (server_online)
  3308. sprintf(tmp, STR("Currently: %-20s "), botname);
  3309. if (strncmp(botname, origbotname, strlen(botname)))
  3310. sprintf(tmp, STR("%sWant: %s"), tmp, origbotname);
  3311. if (!server_online)
  3312. sprintf(tmp, STR("%s(not online)"), tmp);
  3313. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3314. #endif /* LEAF */
  3315. }
  3316. /* netmsg, botmsg */
  3317. static void cmd_botmsg(struct userrec * u, int idx, char * par) {
  3318. char * tnick, * tbot;
  3319. char tmp[1024];
  3320. putlog(LOG_CMDS, "*", STR("#%s# botmsg %s"), dcc[idx].nick, par);
  3321. tbot=newsplit(&par);
  3322. tnick=newsplit(&par);
  3323. if (!par[0]) {
  3324. dprintf(idx, STR("Usage: botmsg <bot> <nick|#channel> <message>\n"));
  3325. return;
  3326. }
  3327. if (nextbot(tbot)<0) {
  3328. dprintf(idx, STR("No such bot linked\n"));
  3329. return;
  3330. }
  3331. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3332. botnet_send_cmd(botnetnick, tbot, u->handle, idx, tmp);
  3333. }
  3334. static void cmd_netmsg(struct userrec * u, int idx, char * par) {
  3335. char * tnick;
  3336. char tmp[1024];
  3337. putlog(LOG_CMDS, "*", STR("#%s# netmsg %s"), dcc[idx].nick, par);
  3338. tnick=newsplit(&par);
  3339. if (!par[0]) {
  3340. dprintf(idx, STR("Usage: netmsg <nick|#channel> <message>\n"));
  3341. return;
  3342. }
  3343. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3344. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3345. }
  3346. void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, char * par) {
  3347. #ifdef LEAF
  3348. char buf[1024], *nick;
  3349. nick=newsplit(&par);
  3350. dprintf(DP_SERVER, STR("PRIVMSG %s :%s\n"), nick, par);
  3351. if (!strcmp(tobot, botnetnick)) {
  3352. sprintf(buf, STR("Sent message to %s"), nick);
  3353. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, buf);
  3354. }
  3355. #endif /* LEAF */
  3356. }
  3357. #ifdef HUB
  3358. /* netlag */
  3359. static void cmd_netlag(struct userrec * u, int idx, char * par) {
  3360. struct timeval tv;
  3361. time_t tm;
  3362. char tmp[64];
  3363. putlog(LOG_CMDS, "*", STR("#%s# netlag"), dcc[idx].nick);
  3364. gettimeofday(&tv, NULL);
  3365. tm = (tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000);
  3366. sprintf(tmp, STR("ping %lu"), tm);
  3367. dprintf(idx, STR("Sent ping to all linked bots\n"));
  3368. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3369. }
  3370. #endif /* HUB */
  3371. void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
  3372. char tmp[64];
  3373. sprintf(tmp, STR("pong %s"), par);
  3374. botnet_send_cmd(botnetnick, frombot, fromhand, atoi(fromidx), tmp);
  3375. }
  3376. void rcmd_pong(char *frombot, char *fromhand, char *fromidx, char *par) {
  3377. int i=atoi(fromidx);
  3378. if ((i>=0) && (i<dcc_total) && (dcc[i].type==&DCC_CHAT) && (!strcmp(dcc[i].nick, fromhand))) {
  3379. struct timeval tv;
  3380. time_t tm;
  3381. gettimeofday(&tv, NULL);
  3382. tm = ((tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000)) - atoi(par);
  3383. dprintf(i, STR("Pong from %s: %i.%i seconds\n"), frombot, (tm / 100), (tm % 100));
  3384. }
  3385. }
  3386. /* exec commands */
  3387. #ifdef HUB
  3388. static void cmd_netw(struct userrec * u, int idx, char * par) {
  3389. char tmp[128];
  3390. putlog(LOG_CMDS, "*", STR("#%s# netw"), dcc[idx].nick);
  3391. strcpy(tmp, STR("exec w"));
  3392. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, tmp);
  3393. }
  3394. static void cmd_netps(struct userrec * u, int idx, char * par) {
  3395. char buf[1024];
  3396. putlog(LOG_CMDS, "*", STR("#%s# netps %s"), dcc[idx].nick, par);
  3397. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3398. putlog(LOG_WARN, "*", STR("%s attempted 'netps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3399. dprintf(idx, STR("No."));
  3400. return;
  3401. }
  3402. sprintf(buf, STR("exec ps %s"), par);
  3403. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3404. }
  3405. static void cmd_netlast(struct userrec * u, int idx, char * par) {
  3406. char buf[1024];
  3407. putlog(LOG_CMDS, "*", STR("#%s# netlast %s"), dcc[idx].nick, par);
  3408. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3409. putlog(LOG_WARN, "*", STR("%s attempted 'netlast' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3410. dprintf(idx, STR("No."));
  3411. return;
  3412. }
  3413. sprintf(buf, STR("exec last %s"), par);
  3414. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3415. }
  3416. #endif /* HUB */
  3417. void crontab_show(struct userrec * u, int idx) {
  3418. dprintf(idx, STR("Showing current crontab:\n"));
  3419. if (!exec_str(idx, STR("crontab -l | grep -v \"^#\"")))
  3420. dprintf(idx, STR("Exec failed"));
  3421. }
  3422. void crontab_del() {
  3423. char * tmpfile, *p, buf[2048];
  3424. tmpfile=nmalloc(strlen(binname)+100);
  3425. strcpy(tmpfile, binname);
  3426. if (!(p=strrchr(tmpfile, '/')))
  3427. return;
  3428. p++;
  3429. strcpy(p, STR(".ctb"));
  3430. sprintf(buf, STR("crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s"), binname, tmpfile);
  3431. if (shell_exec(buf, NULL, NULL, NULL)) {
  3432. sprintf(buf, STR("crontab %s"), tmpfile);
  3433. shell_exec(buf, NULL, NULL, NULL);
  3434. }
  3435. unlink(tmpfile);
  3436. }
  3437. static void cmd_crontab(struct userrec *u, int idx, char *par) {
  3438. char * code;
  3439. int i;
  3440. putlog(LOG_CMDS, "*", STR("#%s# crontab %s"), dcc[idx].nick, par);
  3441. if (!par[0]) {
  3442. dprintf(idx, STR("Usage: crontab <status|delete|show|new> [interval]\n"));
  3443. return;
  3444. }
  3445. code=newsplit(&par);
  3446. if (!strcmp(code, STR("status"))) {
  3447. i=crontab_exists();
  3448. if (!i)
  3449. dprintf(idx, STR("No crontab\n"));
  3450. else if (i==1)
  3451. dprintf(idx, STR("Crontabbed\n"));
  3452. else
  3453. dprintf(idx, STR("Error checking crontab status\n"));
  3454. } else if (!strcmp(code, STR("show"))) {
  3455. crontab_show(u, idx);
  3456. } else if (!strcmp(code, STR("delete"))) {
  3457. crontab_del();
  3458. i=crontab_exists();
  3459. if (!i)
  3460. dprintf(idx, STR("No crontab\n"));
  3461. else if (i==1)
  3462. dprintf(idx, STR("Crontabbed\n"));
  3463. else
  3464. dprintf(idx, STR("Error checking crontab status\n"));
  3465. } else if (!strcmp(code, STR("new"))) {
  3466. i=atoi(par);
  3467. if ((i<=0) || (i>60))
  3468. i=10;
  3469. crontab_create(i);
  3470. i=crontab_exists();
  3471. if (!i)
  3472. dprintf(idx, STR("No crontab\n"));
  3473. else if (i==1)
  3474. dprintf(idx, STR("Crontabbed\n"));
  3475. else
  3476. dprintf(idx, STR("Error checking crontab status\n"));
  3477. } else {
  3478. dprintf(idx, STR("Usage: crontab status|delete|show|new [interval]\n"));
  3479. }
  3480. }
  3481. #ifdef HUB
  3482. static void cmd_netcrontab(struct userrec * u, int idx, char * par) {
  3483. char buf[1024], *cmd;
  3484. putlog(LOG_CMDS, "*", STR("#%s# netcrontab %s"), dcc[idx].nick, par);
  3485. cmd=newsplit(&par);
  3486. if ((strcmp(cmd, STR("status")) && strcmp(cmd, STR("show")) && strcmp(cmd, STR("delete")) && strcmp(cmd, STR("new")))) {
  3487. dprintf(idx, STR("Usage: netcrontab <status|delete|show|new> [interval]\n"));
  3488. return;
  3489. }
  3490. egg_snprintf(buf, sizeof buf, STR("exec crontab %s %s"), cmd, par);
  3491. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3492. }
  3493. #endif /* HUB */
  3494. void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
  3495. char * cmd, scmd[512], *out, *err;
  3496. struct passwd *pw;
  3497. cmd=newsplit(&par);
  3498. scmd[0]=0;
  3499. if (!strcmp(cmd, "w")) {
  3500. strcpy(scmd, "w");
  3501. } else if (!strcmp(cmd, STR("last"))) {
  3502. char user[20];
  3503. if (par[0]) {
  3504. strncpyz(user, par, sizeof(user));
  3505. } else {
  3506. pw = getpwuid(geteuid());
  3507. if (!pw) return;
  3508. strncpyz(user, pw->pw_name, sizeof(user));
  3509. }
  3510. if (!user[0]) {
  3511. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Can't determine user id for process"));
  3512. return;
  3513. }
  3514. sprintf(scmd, STR("last %s"), user);
  3515. } else if (!strcmp(cmd, STR("ps"))) {
  3516. sprintf(scmd, STR("ps %s"), par);
  3517. } else if (!strcmp(cmd, STR("raw"))) {
  3518. sprintf(scmd, STR("%s"), par);
  3519. } else if (!strcmp(cmd, STR("kill"))) {
  3520. sprintf(scmd, STR("kill %s"), par);
  3521. } else if (!strcmp(cmd, STR("crontab"))) {
  3522. char * code=newsplit(&par);
  3523. scmd[0]=0;
  3524. if (!strcmp(code, STR("show"))) {
  3525. strcpy(scmd, STR("crontab -l | grep -v \"^#\""));
  3526. } else if (!strcmp(code, STR("delete"))) {
  3527. crontab_del();
  3528. } else if (!strcmp(code, STR("new"))) {
  3529. int i=atoi(par);
  3530. if ((i<=0) || (i>60))
  3531. i=10;
  3532. crontab_create(i);
  3533. }
  3534. if (!scmd[0]) {
  3535. char s[200];
  3536. int i;
  3537. i=crontab_exists();
  3538. if (!i)
  3539. sprintf(s, STR("No crontab"));
  3540. else if (i==1)
  3541. sprintf(s, STR("Crontabbed"));
  3542. else
  3543. sprintf(s, STR("Error checking crontab status"));
  3544. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, s);
  3545. }
  3546. }
  3547. if (!scmd[0])
  3548. return;
  3549. if (shell_exec(scmd, NULL, &out, &err)) {
  3550. if (out) {
  3551. char * p, * np;
  3552. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Result:"));
  3553. p=out;
  3554. while (p && p[0]) {
  3555. np=strchr(p, '\n');
  3556. if (np)
  3557. *np++=0;
  3558. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3559. p=np;
  3560. }
  3561. nfree(out);
  3562. }
  3563. if (err) {
  3564. char * p, * np;
  3565. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Errors:"));
  3566. p=err;
  3567. while (p && p[0]) {
  3568. np=strchr(p, '\n');
  3569. if (np)
  3570. *np++=0;
  3571. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3572. p=np;
  3573. }
  3574. nfree(err);
  3575. }
  3576. } else {
  3577. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("exec failed"));
  3578. }
  3579. }
  3580. static void cmd_botjump(struct userrec * u, int idx, char * par) {
  3581. char *tbot, buf[1024];
  3582. putlog(LOG_CMDS, "*", STR("#%s# botjump %s"), dcc[idx].nick, par);
  3583. tbot=newsplit(&par);
  3584. if (!tbot[0]) {
  3585. dprintf(idx, STR("Usage: botjump <bot> [server [port [pass]]]\n"));
  3586. return;
  3587. }
  3588. if (nextbot(tbot)<0) {
  3589. dprintf(idx, STR("No such linked bot\n"));
  3590. return;
  3591. }
  3592. sprintf(buf, STR("jump %s"), par);
  3593. botnet_send_cmd(botnetnick, tbot, dcc[idx].nick, idx, buf);
  3594. }
  3595. void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
  3596. #ifdef LEAF
  3597. char * other;
  3598. module_entry *me;
  3599. Function *func;
  3600. int port, default_port = 0;
  3601. if (!(me = module_find("server", 0, 0)) )
  3602. return;
  3603. func = me->funcs;
  3604. default_port = (*(int *)(func[24]));
  3605. if (par[0]) {
  3606. other = newsplit(&par);
  3607. port = atoi(newsplit(&par));
  3608. if (!port)
  3609. port = default_port;
  3610. strncpyz(((char *)(func[20])), other, 120); //newserver
  3611. (*(int *)(func[21])) = port; //newserverport
  3612. strncpyz(((char *)(func[22])), par, 120); //newserverpass
  3613. }
  3614. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Jumping..."));
  3615. (*(int *)(func[23])) = 0; //cycle_time
  3616. (func[SERVER_NUKESERVER]) ("jumping...");
  3617. #endif /* LEAF */
  3618. }
  3619. /* "Remotable" commands */
  3620. void gotremotecmd (char * forbot, char * frombot, char * fromhand, char * fromidx, char * cmd) {
  3621. char * par = cmd;
  3622. cmd=newsplit(&par);
  3623. if (!strcmp(cmd, STR("exec"))) {
  3624. rcmd_exec(frombot, fromhand, fromidx, par);
  3625. } else if (!strcmp(cmd, STR("curnick"))) {
  3626. rcmd_curnick(frombot, fromhand, fromidx);
  3627. } else if (!strcmp(cmd, STR("cursrv"))) {
  3628. rcmd_cursrv(frombot, fromhand, fromidx);
  3629. } else if (!strcmp(cmd, STR("jump"))) {
  3630. rcmd_jump(frombot, fromhand, fromidx, par);
  3631. } else if (!strcmp(cmd, STR("msg"))) {
  3632. rcmd_msg(forbot, frombot, fromhand, fromidx, par);
  3633. } else if (!strcmp(cmd, STR("ver"))) {
  3634. rcmd_ver(frombot, fromhand, fromidx);
  3635. } else if (!strcmp(cmd, STR("ping"))) {
  3636. rcmd_ping(frombot, fromhand, fromidx, par);
  3637. } else if (!strcmp(cmd, STR("pong"))) {
  3638. rcmd_pong(frombot, fromhand, fromidx, par);
  3639. } else if (!strcmp(cmd, STR("die"))) {
  3640. exit(0);
  3641. } else {
  3642. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Unrecognized remote command"));
  3643. }
  3644. }
  3645. void gotremotereply (char *frombot, char *tohand, char *toidx, char *ln) {
  3646. int idx = atoi(toidx);
  3647. if ((idx >= 0) && (idx < dcc_total) && (dcc[idx].type == &DCC_CHAT) && (!strcmp(dcc[idx].nick, tohand))) {
  3648. char *buf = nmalloc(strlen(frombot) + 2 + 1);
  3649. sprintf(buf, "(%s)", frombot);
  3650. dprintf(idx, STR("%-13s %s\n"), buf, ln);
  3651. nfree(buf);
  3652. }
  3653. }
  3654. static void cmd_traffic(struct userrec *u, int idx, char *par)
  3655. {
  3656. unsigned long itmp, itmp2;
  3657. dprintf(idx, STR("Traffic since last restart\n"));
  3658. dprintf(idx, "==========================\n");
  3659. if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
  3660. itraffic_irc_today > 0) {
  3661. dprintf(idx, "IRC:\n");
  3662. dprintf(idx, " out: %s", btos(otraffic_irc + otraffic_irc_today));
  3663. dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
  3664. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_irc_today));
  3665. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
  3666. }
  3667. if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
  3668. itraffic_bn_today > 0) {
  3669. dprintf(idx, STR("Botnet:\n"));
  3670. dprintf(idx, " out: %s", btos(otraffic_bn + otraffic_bn_today));
  3671. dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
  3672. dprintf(idx, " in: %s", btos(itraffic_bn + itraffic_bn_today));
  3673. dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
  3674. }
  3675. if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
  3676. itraffic_dcc_today > 0) {
  3677. dprintf(idx, STR("Partyline:\n"));
  3678. itmp = otraffic_dcc + otraffic_dcc_today;
  3679. itmp2 = otraffic_dcc_today;
  3680. dprintf(idx, " out: %s", btos(itmp));
  3681. dprintf(idx, " (%s today)\n", btos(itmp2));
  3682. dprintf(idx, " in: %s", btos(itraffic_dcc + itraffic_dcc_today));
  3683. dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
  3684. }
  3685. if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
  3686. itraffic_trans_today > 0) {
  3687. dprintf(idx, STR("Transfer.mod:\n"));
  3688. dprintf(idx, " out: %s", btos(otraffic_trans + otraffic_trans_today));
  3689. dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
  3690. dprintf(idx, " in: %s", btos(itraffic_trans + itraffic_trans_today));
  3691. dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
  3692. }
  3693. if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
  3694. dprintf(idx, "Misc:\n");
  3695. dprintf(idx, " out: %s", btos(otraffic_unknown + otraffic_unknown_today));
  3696. dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
  3697. dprintf(idx, " in: %s", btos(itraffic_unknown + itraffic_unknown_today));
  3698. dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
  3699. }
  3700. dprintf(idx, "---\n");
  3701. dprintf(idx, "Total:\n");
  3702. itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans
  3703. + otraffic_unknown + otraffic_irc_today + otraffic_bn_today
  3704. + otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
  3705. itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
  3706. + otraffic_trans_today + otraffic_unknown_today;
  3707. dprintf(idx, " out: %s", btos(itmp));
  3708. dprintf(idx, " (%s today)\n", btos(itmp2));
  3709. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc
  3710. + itraffic_trans + itraffic_unknown + itraffic_irc_today
  3711. + itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today
  3712. + itraffic_unknown_today));
  3713. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today
  3714. + itraffic_dcc_today + itraffic_trans_today
  3715. + itraffic_unknown_today));
  3716. putlog(LOG_CMDS, "*", STR("#%s# traffic"), dcc[idx].nick);
  3717. }
  3718. static char traffictxt[20];
  3719. static char *btos(unsigned long bytes)
  3720. {
  3721. char unit[10];
  3722. float xbytes;
  3723. sprintf(unit, "Bytes");
  3724. xbytes = bytes;
  3725. if (xbytes > 1024.0) {
  3726. sprintf(unit, "KBytes");
  3727. xbytes = xbytes / 1024.0;
  3728. }
  3729. if (xbytes > 1024.0) {
  3730. sprintf(unit, "MBytes");
  3731. xbytes = xbytes / 1024.0;
  3732. }
  3733. if (xbytes > 1024.0) {
  3734. sprintf(unit, "GBytes");
  3735. xbytes = xbytes / 1024.0;
  3736. }
  3737. if (xbytes > 1024.0) {
  3738. sprintf(unit, "TBytes");
  3739. xbytes = xbytes / 1024.0;
  3740. }
  3741. if (bytes > 1024)
  3742. sprintf(traffictxt, "%.2f %s", xbytes, unit);
  3743. else
  3744. sprintf(traffictxt, "%lu Bytes", bytes);
  3745. return traffictxt;
  3746. }
  3747. static void cmd_whoami(struct userrec *u, int idx, char *par)
  3748. {
  3749. dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
  3750. putlog(LOG_CMDS, "*", STR("#%s# whoami"), dcc[idx].nick);
  3751. }
  3752. /* DCC CHAT COMMANDS
  3753. */
  3754. /* Function call should be:
  3755. * int cmd_whatever(idx,"parameters");
  3756. * As with msg commands, function is responsible for any logging.
  3757. */
  3758. cmd_t C_dcc[] =
  3759. {
  3760. {"+host", "m|m", (Function) cmd_pls_host, NULL},
  3761. {"+ignore", "m", (Function) cmd_pls_ignore, NULL},
  3762. {"+user", "m", (Function) cmd_pls_user, NULL},
  3763. #ifdef HUB
  3764. {"-bot", "a", (Function) cmd_mns_user, NULL},
  3765. #endif /* HUB */
  3766. {"-host", "", (Function) cmd_mns_host, NULL},
  3767. {"-ignore", "m", (Function) cmd_mns_ignore, NULL},
  3768. {"-user", "m", (Function) cmd_mns_user, NULL},
  3769. {"addlog", "mo|o", (Function) cmd_addlog, NULL},
  3770. /* {"putlog", "mo|o", (Function) cmd_addlog, NULL}, */
  3771. {"about", "", (Function) cmd_about, NULL},
  3772. {"away", "", (Function) cmd_away, NULL},
  3773. {"back", "", (Function) cmd_back, NULL},
  3774. #ifdef HUB
  3775. {"backup", "m|m", (Function) cmd_backup, NULL},
  3776. {"binds", "a", (Function) cmd_binds, NULL},
  3777. {"boot", "m", (Function) cmd_boot, NULL},
  3778. {"botconfig", "n", (Function) cmd_botconfig, NULL},
  3779. {"botinfo", "", (Function) cmd_botinfo, NULL},
  3780. {"bots", "m", (Function) cmd_bots, NULL},
  3781. {"downbots", "m", (Function) cmd_downbots, NULL},
  3782. {"bottree", "n", (Function) cmd_bottree, NULL},
  3783. {"chaddr", "a", (Function) cmd_chaddr, NULL},
  3784. #endif /* HUB */
  3785. {"chat", "", (Function) cmd_chat, NULL},
  3786. {"chattr", "m|m", (Function) cmd_chattr, NULL},
  3787. #ifdef HUB
  3788. {"chhandle", "m", (Function) cmd_chhandle, NULL},
  3789. {"chnick", "m", (Function) cmd_chhandle, NULL, 1},
  3790. {"chpass", "m", (Function) cmd_chpass, NULL},
  3791. {"chsecpass", "n", (Function) cmd_chsecpass, NULL},
  3792. #ifdef S_DCCPASS
  3793. {"cmdpass", "a", (Function) cmd_cmdpass, NULL},
  3794. #endif /* S_DCCPASS */
  3795. #endif /* HUB */
  3796. {"color", "", (Function) cmd_color, NULL},
  3797. {"comment", "m|m", (Function) cmd_comment, NULL},
  3798. #ifdef HUB
  3799. {"config", "n", (Function) cmd_config, NULL},
  3800. #endif /* HUB */
  3801. {"console", "-|-", (Function) cmd_console, NULL},
  3802. {"date", "", (Function) cmd_date, NULL},
  3803. #ifdef HUB
  3804. {"dccstat", "a", (Function) cmd_dccstat, NULL},
  3805. #endif /* HUB */
  3806. {"debug", "a", (Function) cmd_debug, NULL},
  3807. {"die", "n", (Function) cmd_die, NULL},
  3808. {"echo", "", (Function) cmd_echo, NULL},
  3809. {"fixcodes", "", (Function) cmd_fixcodes, NULL},
  3810. {"handle", "", (Function) cmd_handle, NULL},
  3811. {"nohelp", "-|-", (Function) cmd_nohelp, NULL, 1},
  3812. {"help", "-|-", (Function) cmd_help, NULL},
  3813. {"ignores", "m", (Function) cmd_ignores, NULL},
  3814. #ifdef HUB
  3815. {"link", "n", (Function) cmd_link, NULL},
  3816. #endif /* HUB */
  3817. {"match", "m|m", (Function) cmd_match, NULL},
  3818. {"me", "", (Function) cmd_me, NULL},
  3819. {"motd", "", (Function) cmd_motd, NULL},
  3820. #ifdef HUB
  3821. #ifdef S_TCLCMDS
  3822. {"nettcl", "a", (Function) cmd_nettcl, NULL},
  3823. #endif /* S_TCLCMDS */
  3824. {"newleaf", "n", (Function) cmd_newleaf, NULL},
  3825. #endif /* HUB */
  3826. {"newpass", "", (Function) cmd_newpass, NULL},
  3827. {"secpass", "", (Function) cmd_secpass, NULL},
  3828. {"nick", "", (Function) cmd_handle, NULL, 1},
  3829. {"page", "", (Function) cmd_page, NULL},
  3830. {"quit", "", (Function) NULL, NULL},
  3831. {"relay", "i", (Function) cmd_relay, NULL},
  3832. #ifdef HUB
  3833. {"reload", "m|m", (Function) cmd_reload, NULL},
  3834. #endif /* HUB */
  3835. {"restart", "m", (Function) cmd_restart, NULL},
  3836. #ifdef HUB
  3837. {"save", "m|m", (Function) cmd_save, NULL},
  3838. #endif /* HUB */
  3839. {"simul", "a", (Function) cmd_simul, NULL},
  3840. {"status", "m|m", (Function) cmd_status, NULL},
  3841. {"strip", "", (Function) cmd_strip, NULL},
  3842. {"su", "a", (Function) cmd_su, NULL},
  3843. #ifdef S_TCLCMDS
  3844. {"tcl", "a", (Function) cmd_tcl, NULL},
  3845. #endif /* S_TCLCMDS */
  3846. #ifdef HUB
  3847. {"trace", "n", (Function) cmd_trace, NULL},
  3848. #endif /* HUB */
  3849. {"traffic", "m", (Function) cmd_traffic, NULL},
  3850. {"unlink", "m", (Function) cmd_unlink, NULL},
  3851. {"update", "a", (Function) cmd_update, NULL},
  3852. #ifdef HUB
  3853. {"netcrontab", "a", (Function) cmd_netcrontab, NULL},
  3854. #endif /* HUB */
  3855. {"uptime", "m|m", (Function) cmd_uptime, NULL},
  3856. {"crontab", "a", (Function) cmd_crontab, NULL},
  3857. #ifdef HUB
  3858. {"vbottree", "n", (Function) cmd_vbottree, NULL},
  3859. {"who", "n", (Function) cmd_who, NULL},
  3860. #endif /* HUB */
  3861. {"whois", "", (Function) cmd_whois, NULL},
  3862. {"whom", "", (Function) cmd_whom, NULL},
  3863. {"whoami", "", (Function) cmd_whoami, NULL},
  3864. {"botjump", "m", (Function) cmd_botjump, NULL},
  3865. {"botmsg", "o", (Function) cmd_botmsg, NULL},
  3866. {"netmsg", "n", (Function) cmd_netmsg, NULL},
  3867. {"botnick", "m", (Function) cmd_botnick, NULL},
  3868. {"netnick", "m", (Function) cmd_netnick, NULL},
  3869. #ifdef HUB
  3870. {"netw", "n", (Function) cmd_netw, NULL},
  3871. {"netps", "n", (Function) cmd_netps, NULL},
  3872. {"netlast", "n", (Function) cmd_netlast, NULL},
  3873. {"netlag", "m", (Function) cmd_netlag, NULL},
  3874. #endif /* HUB */
  3875. {"botserver", "m", (Function) cmd_botserver, NULL},
  3876. {"netserver", "m", (Function) cmd_netserver, NULL},
  3877. {"botversion", "o", (Function) cmd_botversion, NULL},
  3878. {"netversion", "o", (Function) cmd_netversion, NULL},
  3879. {"userlist", "m", (Function) cmd_userlist, NULL},
  3880. {"ps", "n", (Function) cmd_ps, NULL},
  3881. {"last", "n", (Function) cmd_last, NULL},
  3882. {"exec", "a", (Function) cmd_exec, NULL},
  3883. {"w", "n", (Function) cmd_w, NULL},
  3884. {"channels", "", (Function) cmd_channels, NULL},
  3885. {"randstring", "", (Function) cmd_randstring, NULL},
  3886. #ifdef HUB
  3887. {"botcmd", "i", (Function) cmd_botcmd, NULL},
  3888. {"bc", "i", (Function) cmd_botcmd, NULL},
  3889. {"hublevel", "a", (Function) cmd_hublevel, NULL},
  3890. {"lagged", "m", (Function) cmd_lagged, NULL},
  3891. {"uplink", "a", (Function) cmd_uplink, NULL},
  3892. #endif /* HUB */
  3893. {NULL, NULL, NULL, NULL}
  3894. };