cmds.c 122 KB

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