cmds.c 124 KB

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